hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/libata.h
....@@ -1,26 +1,10 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Copyright 2003-2005 Red Hat, Inc. All rights reserved.
34 * Copyright 2003-2005 Jeff Garzik
45 *
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2, or (at your option)
9
- * any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; see the file COPYING. If not, write to
18
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
- *
20
- *
216 * libata documentation is available via 'make {ps|pdf}docs',
227 * as Documentation/driver-api/libata.rst
23
- *
248 */
259
2610 #ifndef __LINUX_LIBATA_H__
....@@ -73,8 +57,6 @@
7357 #define DPRINTK(fmt, args...)
7458 #define VPRINTK(fmt, args...)
7559 #endif /* ATA_DEBUG */
76
-
77
-#define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
7860
7961 #define ata_print_version_once(dev, version) \
8062 ({ \
....@@ -136,7 +118,6 @@
136118
137119 ATA_SHT_EMULATED = 1,
138120 ATA_SHT_THIS_ID = -1,
139
- ATA_SHT_USE_CLUSTERING = 1,
140121
141122 /* struct ata_taskfile flags */
142123 ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */
....@@ -194,6 +175,7 @@
194175 ATA_DEV_NONE = 11, /* no device */
195176
196177 /* struct ata_link flags */
178
+ /* NOTE: struct ata_force_param currently stores lflags in u16 */
197179 ATA_LFLAG_NO_HRST = (1 << 1), /* avoid hardreset */
198180 ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
199181 ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
....@@ -205,7 +187,7 @@
205187 ATA_LFLAG_NO_LPM = (1 << 8), /* disable LPM on this link */
206188 ATA_LFLAG_RST_ONCE = (1 << 9), /* limit recovery to one reset */
207189 ATA_LFLAG_CHANGED = (1 << 10), /* LPM state changed on this link */
208
- ATA_LFLAG_NO_DB_DELAY = (1 << 11), /* no debounce delay on link resume */
190
+ ATA_LFLAG_NO_DEBOUNCE_DELAY = (1 << 11), /* no debounce delay on link resume */
209191
210192 /* struct ata_port flags */
211193 ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
....@@ -278,6 +260,10 @@
278260 ATA_HOST_PARALLEL_SCAN = (1 << 2), /* Ports on this host can be scanned in parallel */
279261 ATA_HOST_IGNORE_ATA = (1 << 3), /* Ignore ATA devices on this host. */
280262
263
+ ATA_HOST_NO_PART = (1 << 4), /* Host does not support partial */
264
+ ATA_HOST_NO_SSC = (1 << 5), /* Host does not support slumber */
265
+ ATA_HOST_NO_DEVSLP = (1 << 6), /* Host does not support devslp */
266
+
281267 /* bits 24:31 of host->flags are reserved for LLD specific flags */
282268
283269 /* various lengths of time */
....@@ -311,7 +297,7 @@
311297 * advised to wait only for the following duration before
312298 * doing SRST.
313299 */
314
- ATA_TMOUT_PMP_SRST_WAIT = 5000,
300
+ ATA_TMOUT_PMP_SRST_WAIT = 10000,
315301
316302 /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might
317303 * be a spurious PHY event, so ignore the first PHY event that
....@@ -551,12 +537,14 @@
551537 unsigned long deadline);
552538 typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
553539
554
-extern struct device_attribute dev_attr_link_power_management_policy;
555540 extern struct device_attribute dev_attr_unload_heads;
541
+#ifdef CONFIG_SATA_HOST
542
+extern struct device_attribute dev_attr_link_power_management_policy;
556543 extern struct device_attribute dev_attr_ncq_prio_enable;
557544 extern struct device_attribute dev_attr_em_message_type;
558545 extern struct device_attribute dev_attr_em_message;
559546 extern struct device_attribute dev_attr_sw_activity;
547
+#endif
560548
561549 enum sw_activity {
562550 OFF,
....@@ -628,7 +616,7 @@
628616 struct task_struct *eh_owner;
629617
630618 struct ata_port *simplex_claimed; /* channel owning the DMA */
631
- struct ata_port *ports[0];
619
+ struct ata_port *ports[];
632620 };
633621
634622 struct ata_queued_cmd {
....@@ -1042,10 +1030,6 @@
10421030 /*
10431031 * Core layer - drivers/ata/libata-core.c
10441032 */
1045
-extern const unsigned long sata_deb_timing_normal[];
1046
-extern const unsigned long sata_deb_timing_hotplug[];
1047
-extern const unsigned long sata_deb_timing_long[];
1048
-
10491033 extern struct ata_port_operations ata_dummy_port_ops;
10501034 extern const struct ata_port_info ata_dummy_port_info;
10511035
....@@ -1083,33 +1067,14 @@
10831067 (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
10841068 }
10851069
1086
-static inline const unsigned long *
1087
-sata_ehc_deb_timing(struct ata_eh_context *ehc)
1088
-{
1089
- if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
1090
- return sata_deb_timing_hotplug;
1091
- else
1092
- return sata_deb_timing_normal;
1093
-}
1094
-
10951070 static inline int ata_port_is_dummy(struct ata_port *ap)
10961071 {
10971072 return ap->ops == &ata_dummy_port_ops;
10981073 }
10991074
1100
-extern int sata_set_spd(struct ata_link *link);
11011075 extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
11021076 extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
11031077 int (*check_ready)(struct ata_link *link));
1104
-extern int sata_link_debounce(struct ata_link *link,
1105
- const unsigned long *params, unsigned long deadline);
1106
-extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
1107
- unsigned long deadline);
1108
-extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
1109
- bool spm_wakeup);
1110
-extern int sata_link_hardreset(struct ata_link *link,
1111
- const unsigned long *timing, unsigned long deadline,
1112
- bool *online, int (*check_ready)(struct ata_link *));
11131078 extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
11141079 unsigned long deadline);
11151080 extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
....@@ -1117,7 +1082,6 @@
11171082 extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
11181083 extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
11191084 const struct ata_port_info * const * ppi, int n_ports);
1120
-extern int ata_slave_link_init(struct ata_port *ap);
11211085 extern void ata_host_get(struct ata_host *host);
11221086 extern void ata_host_put(struct ata_host *host);
11231087 extern int ata_host_start(struct ata_host *host);
....@@ -1129,26 +1093,21 @@
11291093 extern void ata_host_detach(struct ata_host *host);
11301094 extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
11311095 extern int ata_scsi_detect(struct scsi_host_template *sht);
1132
-extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
1096
+extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
1097
+ void __user *arg);
1098
+#ifdef CONFIG_COMPAT
1099
+#define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
1100
+#else
1101
+#define ATA_SCSI_COMPAT_IOCTL /* empty */
1102
+#endif
11331103 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
1104
+#if IS_REACHABLE(CONFIG_ATA)
1105
+bool ata_scsi_dma_need_drain(struct request *rq);
1106
+#else
1107
+#define ata_scsi_dma_need_drain NULL
1108
+#endif
11341109 extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
1135
- int cmd, void __user *arg);
1136
-extern void ata_sas_port_destroy(struct ata_port *);
1137
-extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
1138
- struct ata_port_info *, struct Scsi_Host *);
1139
-extern void ata_sas_async_probe(struct ata_port *ap);
1140
-extern int ata_sas_sync_probe(struct ata_port *ap);
1141
-extern int ata_sas_port_init(struct ata_port *);
1142
-extern int ata_sas_port_start(struct ata_port *ap);
1143
-extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
1144
-extern void ata_sas_tport_delete(struct ata_port *ap);
1145
-extern void ata_sas_port_stop(struct ata_port *ap);
1146
-extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
1147
-extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
1148
-extern int sata_scr_valid(struct ata_link *link);
1149
-extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
1150
-extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
1151
-extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
1110
+ unsigned int cmd, void __user *arg);
11521111 extern bool ata_link_online(struct ata_link *link);
11531112 extern bool ata_link_offline(struct ata_link *link);
11541113 #ifdef CONFIG_PM
....@@ -1169,9 +1128,6 @@
11691128 extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
11701129 u32 val, unsigned long interval, unsigned long timeout);
11711130 extern int atapi_cmd_type(u8 opcode);
1172
-extern void ata_tf_to_fis(const struct ata_taskfile *tf,
1173
- u8 pmp, int is_cmd, u8 *fis);
1174
-extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
11751131 extern unsigned long ata_pack_xfermask(unsigned long pio_mask,
11761132 unsigned long mwdma_mask, unsigned long udma_mask);
11771133 extern void ata_unpack_xfermask(unsigned long xfer_mask,
....@@ -1195,7 +1151,6 @@
11951151 extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
11961152 struct ata_taskfile *tf, u16 *id);
11971153 extern void ata_qc_complete(struct ata_queued_cmd *qc);
1198
-extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
11991154 extern u64 ata_qc_get_active(struct ata_port *ap);
12001155 extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
12011156 extern int ata_std_bios_param(struct scsi_device *sdev,
....@@ -1212,7 +1167,96 @@
12121167 extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
12131168 extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
12141169 extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
1170
+
1171
+/*
1172
+ * SATA specific code - drivers/ata/libata-sata.c
1173
+ */
1174
+#ifdef CONFIG_SATA_HOST
1175
+extern const unsigned long sata_deb_timing_normal[];
1176
+extern const unsigned long sata_deb_timing_hotplug[];
1177
+extern const unsigned long sata_deb_timing_long[];
1178
+
1179
+static inline const unsigned long *
1180
+sata_ehc_deb_timing(struct ata_eh_context *ehc)
1181
+{
1182
+ if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
1183
+ return sata_deb_timing_hotplug;
1184
+ else
1185
+ return sata_deb_timing_normal;
1186
+}
1187
+
1188
+extern int sata_scr_valid(struct ata_link *link);
1189
+extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
1190
+extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
1191
+extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
1192
+extern int sata_set_spd(struct ata_link *link);
1193
+extern int sata_link_hardreset(struct ata_link *link,
1194
+ const unsigned long *timing, unsigned long deadline,
1195
+ bool *online, int (*check_ready)(struct ata_link *));
1196
+extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
1197
+ unsigned long deadline);
1198
+extern void ata_eh_analyze_ncq_error(struct ata_link *link);
1199
+#else
1200
+static inline const unsigned long *
1201
+sata_ehc_deb_timing(struct ata_eh_context *ehc)
1202
+{
1203
+ return NULL;
1204
+}
1205
+static inline int sata_scr_valid(struct ata_link *link) { return 0; }
1206
+static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
1207
+{
1208
+ return -EOPNOTSUPP;
1209
+}
1210
+static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
1211
+{
1212
+ return -EOPNOTSUPP;
1213
+}
1214
+static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
1215
+{
1216
+ return -EOPNOTSUPP;
1217
+}
1218
+static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
1219
+static inline int sata_link_hardreset(struct ata_link *link,
1220
+ const unsigned long *timing,
1221
+ unsigned long deadline,
1222
+ bool *online,
1223
+ int (*check_ready)(struct ata_link *))
1224
+{
1225
+ if (online)
1226
+ *online = false;
1227
+ return -EOPNOTSUPP;
1228
+}
1229
+static inline int sata_link_resume(struct ata_link *link,
1230
+ const unsigned long *params,
1231
+ unsigned long deadline)
1232
+{
1233
+ return -EOPNOTSUPP;
1234
+}
1235
+static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
1236
+#endif
1237
+extern int sata_link_debounce(struct ata_link *link,
1238
+ const unsigned long *params, unsigned long deadline);
1239
+extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
1240
+ bool spm_wakeup);
1241
+extern int ata_slave_link_init(struct ata_port *ap);
1242
+extern void ata_sas_port_destroy(struct ata_port *);
1243
+extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
1244
+ struct ata_port_info *, struct Scsi_Host *);
1245
+extern void ata_sas_async_probe(struct ata_port *ap);
1246
+extern int ata_sas_sync_probe(struct ata_port *ap);
1247
+extern int ata_sas_port_init(struct ata_port *);
1248
+extern int ata_sas_port_start(struct ata_port *ap);
1249
+extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
1250
+extern void ata_sas_tport_delete(struct ata_port *ap);
1251
+extern void ata_sas_port_stop(struct ata_port *ap);
1252
+extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
1253
+extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
1254
+extern void ata_tf_to_fis(const struct ata_taskfile *tf,
1255
+ u8 pmp, int is_cmd, u8 *fis);
1256
+extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
1257
+extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
12151258 extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
1259
+extern int sata_async_notification(struct ata_port *ap);
12161260
12171261 extern int ata_cable_40wire(struct ata_port *ap);
12181262 extern int ata_cable_80wire(struct ata_port *ap);
....@@ -1222,12 +1266,6 @@
12221266
12231267 /* Timing helpers */
12241268 extern unsigned int ata_pio_need_iordy(const struct ata_device *);
1225
-extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
1226
-extern int ata_timing_compute(struct ata_device *, unsigned short,
1227
- struct ata_timing *, int, int);
1228
-extern void ata_timing_merge(const struct ata_timing *,
1229
- const struct ata_timing *, struct ata_timing *,
1230
- unsigned int);
12311269 extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
12321270
12331271 /* PCI */
....@@ -1311,14 +1349,12 @@
13111349 extern int ata_link_abort(struct ata_link *link);
13121350 extern int ata_port_abort(struct ata_port *ap);
13131351 extern int ata_port_freeze(struct ata_port *ap);
1314
-extern int sata_async_notification(struct ata_port *ap);
13151352
13161353 extern void ata_eh_freeze_port(struct ata_port *ap);
13171354 extern void ata_eh_thaw_port(struct ata_port *ap);
13181355
13191356 extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
13201357 extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1321
-extern void ata_eh_analyze_ncq_error(struct ata_link *link);
13221358
13231359 extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
13241360 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
....@@ -1359,26 +1395,35 @@
13591395 * edge driver's module reference, otherwise the driver can be unloaded
13601396 * even if the scsi_device is being accessed.
13611397 */
1362
-#define ATA_BASE_SHT(drv_name) \
1398
+#define __ATA_BASE_SHT(drv_name) \
13631399 .module = THIS_MODULE, \
13641400 .name = drv_name, \
13651401 .ioctl = ata_scsi_ioctl, \
1402
+ ATA_SCSI_COMPAT_IOCTL \
13661403 .queuecommand = ata_scsi_queuecmd, \
1404
+ .dma_need_drain = ata_scsi_dma_need_drain, \
13671405 .can_queue = ATA_DEF_QUEUE, \
13681406 .tag_alloc_policy = BLK_TAG_ALLOC_RR, \
13691407 .this_id = ATA_SHT_THIS_ID, \
13701408 .emulated = ATA_SHT_EMULATED, \
1371
- .use_clustering = ATA_SHT_USE_CLUSTERING, \
13721409 .proc_name = drv_name, \
13731410 .slave_configure = ata_scsi_slave_config, \
13741411 .slave_destroy = ata_scsi_slave_destroy, \
13751412 .bios_param = ata_std_bios_param, \
1376
- .unlock_native_capacity = ata_scsi_unlock_native_capacity, \
1413
+ .unlock_native_capacity = ata_scsi_unlock_native_capacity
1414
+
1415
+#define ATA_BASE_SHT(drv_name) \
1416
+ __ATA_BASE_SHT(drv_name), \
13771417 .sdev_attrs = ata_common_sdev_attrs
13781418
1419
+#ifdef CONFIG_SATA_HOST
1420
+extern struct device_attribute *ata_ncq_sdev_attrs[];
1421
+
13791422 #define ATA_NCQ_SHT(drv_name) \
1380
- ATA_BASE_SHT(drv_name), \
1423
+ __ATA_BASE_SHT(drv_name), \
1424
+ .sdev_attrs = ata_ncq_sdev_attrs, \
13811425 .change_queue_depth = ata_scsi_change_queue_depth
1426
+#endif
13821427
13831428 /*
13841429 * PMP helpers
....@@ -1651,6 +1696,8 @@
16511696 */
16521697 static inline int ata_ncq_enabled(struct ata_device *dev)
16531698 {
1699
+ if (!IS_ENABLED(CONFIG_SATA_HOST))
1700
+ return 0;
16541701 return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
16551702 ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
16561703 }
....@@ -1820,6 +1867,16 @@
18201867 }
18211868
18221869 /**************************************************************************
1870
+ * PATA timings - drivers/ata/libata-pata-timings.c
1871
+ */
1872
+extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
1873
+extern int ata_timing_compute(struct ata_device *, unsigned short,
1874
+ struct ata_timing *, int, int);
1875
+extern void ata_timing_merge(const struct ata_timing *,
1876
+ const struct ata_timing *, struct ata_timing *,
1877
+ unsigned int);
1878
+
1879
+/**************************************************************************
18231880 * PMP - drivers/ata/libata-pmp.c
18241881 */
18251882 #ifdef CONFIG_SATA_PMP