hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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 */
....@@ -551,12 +533,14 @@
551533 unsigned long deadline);
552534 typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
553535
554
-extern struct device_attribute dev_attr_link_power_management_policy;
555536 extern struct device_attribute dev_attr_unload_heads;
537
+#ifdef CONFIG_SATA_HOST
538
+extern struct device_attribute dev_attr_link_power_management_policy;
556539 extern struct device_attribute dev_attr_ncq_prio_enable;
557540 extern struct device_attribute dev_attr_em_message_type;
558541 extern struct device_attribute dev_attr_em_message;
559542 extern struct device_attribute dev_attr_sw_activity;
543
+#endif
560544
561545 enum sw_activity {
562546 OFF,
....@@ -628,7 +612,7 @@
628612 struct task_struct *eh_owner;
629613
630614 struct ata_port *simplex_claimed; /* channel owning the DMA */
631
- struct ata_port *ports[0];
615
+ struct ata_port *ports[];
632616 };
633617
634618 struct ata_queued_cmd {
....@@ -1042,10 +1026,6 @@
10421026 /*
10431027 * Core layer - drivers/ata/libata-core.c
10441028 */
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
-
10491029 extern struct ata_port_operations ata_dummy_port_ops;
10501030 extern const struct ata_port_info ata_dummy_port_info;
10511031
....@@ -1083,33 +1063,14 @@
10831063 (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
10841064 }
10851065
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
-
10951066 static inline int ata_port_is_dummy(struct ata_port *ap)
10961067 {
10971068 return ap->ops == &ata_dummy_port_ops;
10981069 }
10991070
1100
-extern int sata_set_spd(struct ata_link *link);
11011071 extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
11021072 extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
11031073 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 *));
11131074 extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
11141075 unsigned long deadline);
11151076 extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
....@@ -1117,7 +1078,6 @@
11171078 extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
11181079 extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
11191080 const struct ata_port_info * const * ppi, int n_ports);
1120
-extern int ata_slave_link_init(struct ata_port *ap);
11211081 extern void ata_host_get(struct ata_host *host);
11221082 extern void ata_host_put(struct ata_host *host);
11231083 extern int ata_host_start(struct ata_host *host);
....@@ -1129,26 +1089,21 @@
11291089 extern void ata_host_detach(struct ata_host *host);
11301090 extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
11311091 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);
1092
+extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
1093
+ void __user *arg);
1094
+#ifdef CONFIG_COMPAT
1095
+#define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
1096
+#else
1097
+#define ATA_SCSI_COMPAT_IOCTL /* empty */
1098
+#endif
11331099 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
1100
+#if IS_REACHABLE(CONFIG_ATA)
1101
+bool ata_scsi_dma_need_drain(struct request *rq);
1102
+#else
1103
+#define ata_scsi_dma_need_drain NULL
1104
+#endif
11341105 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);
1106
+ unsigned int cmd, void __user *arg);
11521107 extern bool ata_link_online(struct ata_link *link);
11531108 extern bool ata_link_offline(struct ata_link *link);
11541109 #ifdef CONFIG_PM
....@@ -1169,9 +1124,6 @@
11691124 extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
11701125 u32 val, unsigned long interval, unsigned long timeout);
11711126 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);
11751127 extern unsigned long ata_pack_xfermask(unsigned long pio_mask,
11761128 unsigned long mwdma_mask, unsigned long udma_mask);
11771129 extern void ata_unpack_xfermask(unsigned long xfer_mask,
....@@ -1195,7 +1147,6 @@
11951147 extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
11961148 struct ata_taskfile *tf, u16 *id);
11971149 extern void ata_qc_complete(struct ata_queued_cmd *qc);
1198
-extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
11991150 extern u64 ata_qc_get_active(struct ata_port *ap);
12001151 extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
12011152 extern int ata_std_bios_param(struct scsi_device *sdev,
....@@ -1212,7 +1163,96 @@
12121163 extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
12131164 extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
12141165 extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
1166
+
1167
+/*
1168
+ * SATA specific code - drivers/ata/libata-sata.c
1169
+ */
1170
+#ifdef CONFIG_SATA_HOST
1171
+extern const unsigned long sata_deb_timing_normal[];
1172
+extern const unsigned long sata_deb_timing_hotplug[];
1173
+extern const unsigned long sata_deb_timing_long[];
1174
+
1175
+static inline const unsigned long *
1176
+sata_ehc_deb_timing(struct ata_eh_context *ehc)
1177
+{
1178
+ if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
1179
+ return sata_deb_timing_hotplug;
1180
+ else
1181
+ return sata_deb_timing_normal;
1182
+}
1183
+
1184
+extern int sata_scr_valid(struct ata_link *link);
1185
+extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
1186
+extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
1187
+extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
1188
+extern int sata_set_spd(struct ata_link *link);
1189
+extern int sata_link_hardreset(struct ata_link *link,
1190
+ const unsigned long *timing, unsigned long deadline,
1191
+ bool *online, int (*check_ready)(struct ata_link *));
1192
+extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
1193
+ unsigned long deadline);
1194
+extern void ata_eh_analyze_ncq_error(struct ata_link *link);
1195
+#else
1196
+static inline const unsigned long *
1197
+sata_ehc_deb_timing(struct ata_eh_context *ehc)
1198
+{
1199
+ return NULL;
1200
+}
1201
+static inline int sata_scr_valid(struct ata_link *link) { return 0; }
1202
+static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
1203
+{
1204
+ return -EOPNOTSUPP;
1205
+}
1206
+static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
1207
+{
1208
+ return -EOPNOTSUPP;
1209
+}
1210
+static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
1211
+{
1212
+ return -EOPNOTSUPP;
1213
+}
1214
+static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
1215
+static inline int sata_link_hardreset(struct ata_link *link,
1216
+ const unsigned long *timing,
1217
+ unsigned long deadline,
1218
+ bool *online,
1219
+ int (*check_ready)(struct ata_link *))
1220
+{
1221
+ if (online)
1222
+ *online = false;
1223
+ return -EOPNOTSUPP;
1224
+}
1225
+static inline int sata_link_resume(struct ata_link *link,
1226
+ const unsigned long *params,
1227
+ unsigned long deadline)
1228
+{
1229
+ return -EOPNOTSUPP;
1230
+}
1231
+static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
1232
+#endif
1233
+extern int sata_link_debounce(struct ata_link *link,
1234
+ const unsigned long *params, unsigned long deadline);
1235
+extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
1236
+ bool spm_wakeup);
1237
+extern int ata_slave_link_init(struct ata_port *ap);
1238
+extern void ata_sas_port_destroy(struct ata_port *);
1239
+extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
1240
+ struct ata_port_info *, struct Scsi_Host *);
1241
+extern void ata_sas_async_probe(struct ata_port *ap);
1242
+extern int ata_sas_sync_probe(struct ata_port *ap);
1243
+extern int ata_sas_port_init(struct ata_port *);
1244
+extern int ata_sas_port_start(struct ata_port *ap);
1245
+extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
1246
+extern void ata_sas_tport_delete(struct ata_port *ap);
1247
+extern void ata_sas_port_stop(struct ata_port *ap);
1248
+extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
1249
+extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
1250
+extern void ata_tf_to_fis(const struct ata_taskfile *tf,
1251
+ u8 pmp, int is_cmd, u8 *fis);
1252
+extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
1253
+extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
12151254 extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
1255
+extern int sata_async_notification(struct ata_port *ap);
12161256
12171257 extern int ata_cable_40wire(struct ata_port *ap);
12181258 extern int ata_cable_80wire(struct ata_port *ap);
....@@ -1222,12 +1262,6 @@
12221262
12231263 /* Timing helpers */
12241264 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);
12311265 extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
12321266
12331267 /* PCI */
....@@ -1311,14 +1345,12 @@
13111345 extern int ata_link_abort(struct ata_link *link);
13121346 extern int ata_port_abort(struct ata_port *ap);
13131347 extern int ata_port_freeze(struct ata_port *ap);
1314
-extern int sata_async_notification(struct ata_port *ap);
13151348
13161349 extern void ata_eh_freeze_port(struct ata_port *ap);
13171350 extern void ata_eh_thaw_port(struct ata_port *ap);
13181351
13191352 extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
13201353 extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1321
-extern void ata_eh_analyze_ncq_error(struct ata_link *link);
13221354
13231355 extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
13241356 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
....@@ -1359,26 +1391,35 @@
13591391 * edge driver's module reference, otherwise the driver can be unloaded
13601392 * even if the scsi_device is being accessed.
13611393 */
1362
-#define ATA_BASE_SHT(drv_name) \
1394
+#define __ATA_BASE_SHT(drv_name) \
13631395 .module = THIS_MODULE, \
13641396 .name = drv_name, \
13651397 .ioctl = ata_scsi_ioctl, \
1398
+ ATA_SCSI_COMPAT_IOCTL \
13661399 .queuecommand = ata_scsi_queuecmd, \
1400
+ .dma_need_drain = ata_scsi_dma_need_drain, \
13671401 .can_queue = ATA_DEF_QUEUE, \
13681402 .tag_alloc_policy = BLK_TAG_ALLOC_RR, \
13691403 .this_id = ATA_SHT_THIS_ID, \
13701404 .emulated = ATA_SHT_EMULATED, \
1371
- .use_clustering = ATA_SHT_USE_CLUSTERING, \
13721405 .proc_name = drv_name, \
13731406 .slave_configure = ata_scsi_slave_config, \
13741407 .slave_destroy = ata_scsi_slave_destroy, \
13751408 .bios_param = ata_std_bios_param, \
1376
- .unlock_native_capacity = ata_scsi_unlock_native_capacity, \
1409
+ .unlock_native_capacity = ata_scsi_unlock_native_capacity
1410
+
1411
+#define ATA_BASE_SHT(drv_name) \
1412
+ __ATA_BASE_SHT(drv_name), \
13771413 .sdev_attrs = ata_common_sdev_attrs
13781414
1415
+#ifdef CONFIG_SATA_HOST
1416
+extern struct device_attribute *ata_ncq_sdev_attrs[];
1417
+
13791418 #define ATA_NCQ_SHT(drv_name) \
1380
- ATA_BASE_SHT(drv_name), \
1419
+ __ATA_BASE_SHT(drv_name), \
1420
+ .sdev_attrs = ata_ncq_sdev_attrs, \
13811421 .change_queue_depth = ata_scsi_change_queue_depth
1422
+#endif
13821423
13831424 /*
13841425 * PMP helpers
....@@ -1651,6 +1692,8 @@
16511692 */
16521693 static inline int ata_ncq_enabled(struct ata_device *dev)
16531694 {
1695
+ if (!IS_ENABLED(CONFIG_SATA_HOST))
1696
+ return 0;
16541697 return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
16551698 ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
16561699 }
....@@ -1820,6 +1863,16 @@
18201863 }
18211864
18221865 /**************************************************************************
1866
+ * PATA timings - drivers/ata/libata-pata-timings.c
1867
+ */
1868
+extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
1869
+extern int ata_timing_compute(struct ata_device *, unsigned short,
1870
+ struct ata_timing *, int, int);
1871
+extern void ata_timing_merge(const struct ata_timing *,
1872
+ const struct ata_timing *, struct ata_timing *,
1873
+ unsigned int);
1874
+
1875
+/**************************************************************************
18231876 * PMP - drivers/ata/libata-pmp.c
18241877 */
18251878 #ifdef CONFIG_SATA_PMP