1
2
3
4
5
6
7
8
9
10#ifndef __LINUX_LIBATA_H__
11#define __LINUX_LIBATA_H__
12
13#include <linux/delay.h>
14#include <linux/jiffies.h>
15#include <linux/interrupt.h>
16#include <linux/dma-mapping.h>
17#include <linux/scatterlist.h>
18#include <linux/io.h>
19#include <linux/ata.h>
20#include <linux/workqueue.h>
21#include <scsi/scsi_host.h>
22#include <linux/acpi.h>
23#include <linux/cdrom.h>
24#include <linux/sched.h>
25#include <linux/async.h>
26
27
28
29
30
31#ifdef CONFIG_ATA_NONSTANDARD
32#include <asm/libata-portmap.h>
33#else
34#define ATA_PRIMARY_IRQ(dev) 14
35#define ATA_SECONDARY_IRQ(dev) 15
36#endif
37
38
39
40
41
42#undef ATA_DEBUG
43#undef ATA_VERBOSE_DEBUG
44#undef ATA_IRQ_TRAP
45#undef ATA_NDEBUG
46
47
48
49#ifdef ATA_DEBUG
50#define DPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
51#ifdef ATA_VERBOSE_DEBUG
52#define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
53#else
54#define VPRINTK(fmt, args...)
55#endif
56#else
57#define DPRINTK(fmt, args...)
58#define VPRINTK(fmt, args...)
59#endif
60
61#define ata_print_version_once(dev, version) \
62({ \
63 static bool __print_once; \
64 \
65 if (!__print_once) { \
66 __print_once = true; \
67 ata_print_version(dev, version); \
68 } \
69})
70
71
72#define HAVE_LIBATA_MSG 1
73
74enum {
75 ATA_MSG_DRV = 0x0001,
76 ATA_MSG_INFO = 0x0002,
77 ATA_MSG_PROBE = 0x0004,
78 ATA_MSG_WARN = 0x0008,
79 ATA_MSG_MALLOC = 0x0010,
80 ATA_MSG_CTL = 0x0020,
81 ATA_MSG_INTR = 0x0040,
82 ATA_MSG_ERR = 0x0080,
83};
84
85#define ata_msg_drv(p) ((p)->msg_enable & ATA_MSG_DRV)
86#define ata_msg_info(p) ((p)->msg_enable & ATA_MSG_INFO)
87#define ata_msg_probe(p) ((p)->msg_enable & ATA_MSG_PROBE)
88#define ata_msg_warn(p) ((p)->msg_enable & ATA_MSG_WARN)
89#define ata_msg_malloc(p) ((p)->msg_enable & ATA_MSG_MALLOC)
90#define ata_msg_ctl(p) ((p)->msg_enable & ATA_MSG_CTL)
91#define ata_msg_intr(p) ((p)->msg_enable & ATA_MSG_INTR)
92#define ata_msg_err(p) ((p)->msg_enable & ATA_MSG_ERR)
93
94static inline u32 ata_msg_init(int dval, int default_msg_enable_bits)
95{
96 if (dval < 0 || dval >= (sizeof(u32) * 8))
97 return default_msg_enable_bits;
98 if (!dval)
99 return 0;
100 return (1 << dval) - 1;
101}
102
103
104#define ATA_TAG_POISON 0xfafbfcfdU
105
106enum {
107
108 LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
109 LIBATA_DUMB_MAX_PRD = ATA_MAX_PRD / 4,
110 ATA_DEF_QUEUE = 1,
111 ATA_MAX_QUEUE = 32,
112 ATA_TAG_INTERNAL = ATA_MAX_QUEUE,
113 ATA_SHORT_PAUSE = 16,
114
115 ATAPI_MAX_DRAIN = 16 << 10,
116
117 ATA_ALL_DEVICES = (1 << ATA_MAX_DEVICES) - 1,
118
119 ATA_SHT_EMULATED = 1,
120 ATA_SHT_THIS_ID = -1,
121
122
123 ATA_TFLAG_LBA48 = (1 << 0),
124 ATA_TFLAG_ISADDR = (1 << 1),
125 ATA_TFLAG_DEVICE = (1 << 2),
126 ATA_TFLAG_WRITE = (1 << 3),
127 ATA_TFLAG_LBA = (1 << 4),
128 ATA_TFLAG_FUA = (1 << 5),
129 ATA_TFLAG_POLLING = (1 << 6),
130
131
132 ATA_DFLAG_LBA = (1 << 0),
133 ATA_DFLAG_LBA48 = (1 << 1),
134 ATA_DFLAG_CDB_INTR = (1 << 2),
135 ATA_DFLAG_NCQ = (1 << 3),
136 ATA_DFLAG_FLUSH_EXT = (1 << 4),
137 ATA_DFLAG_ACPI_PENDING = (1 << 5),
138 ATA_DFLAG_ACPI_FAILED = (1 << 6),
139 ATA_DFLAG_AN = (1 << 7),
140 ATA_DFLAG_TRUSTED = (1 << 8),
141 ATA_DFLAG_DMADIR = (1 << 10),
142 ATA_DFLAG_CFG_MASK = (1 << 12) - 1,
143
144 ATA_DFLAG_PIO = (1 << 12),
145 ATA_DFLAG_NCQ_OFF = (1 << 13),
146 ATA_DFLAG_SLEEPING = (1 << 15),
147 ATA_DFLAG_DUBIOUS_XFER = (1 << 16),
148 ATA_DFLAG_NO_UNLOAD = (1 << 17),
149 ATA_DFLAG_UNLOCK_HPA = (1 << 18),
150 ATA_DFLAG_NCQ_SEND_RECV = (1 << 19),
151 ATA_DFLAG_NCQ_PRIO = (1 << 20),
152 ATA_DFLAG_NCQ_PRIO_ENABLE = (1 << 21),
153 ATA_DFLAG_INIT_MASK = (1 << 24) - 1,
154
155 ATA_DFLAG_DETACH = (1 << 24),
156 ATA_DFLAG_DETACHED = (1 << 25),
157
158 ATA_DFLAG_DA = (1 << 26),
159 ATA_DFLAG_DEVSLP = (1 << 27),
160 ATA_DFLAG_ACPI_DISABLED = (1 << 28),
161 ATA_DFLAG_D_SENSE = (1 << 29),
162 ATA_DFLAG_ZAC = (1 << 30),
163
164 ATA_DFLAG_FEATURES_MASK = ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \
165 ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \
166 ATA_DFLAG_NCQ_PRIO,
167
168 ATA_DEV_UNKNOWN = 0,
169 ATA_DEV_ATA = 1,
170 ATA_DEV_ATA_UNSUP = 2,
171 ATA_DEV_ATAPI = 3,
172 ATA_DEV_ATAPI_UNSUP = 4,
173 ATA_DEV_PMP = 5,
174 ATA_DEV_PMP_UNSUP = 6,
175 ATA_DEV_SEMB = 7,
176 ATA_DEV_SEMB_UNSUP = 8,
177 ATA_DEV_ZAC = 9,
178 ATA_DEV_ZAC_UNSUP = 10,
179 ATA_DEV_NONE = 11,
180
181
182
183 ATA_LFLAG_NO_HRST = (1 << 1),
184 ATA_LFLAG_NO_SRST = (1 << 2),
185 ATA_LFLAG_ASSUME_ATA = (1 << 3),
186 ATA_LFLAG_ASSUME_SEMB = (1 << 4),
187 ATA_LFLAG_ASSUME_CLASS = ATA_LFLAG_ASSUME_ATA | ATA_LFLAG_ASSUME_SEMB,
188 ATA_LFLAG_NO_RETRY = (1 << 5),
189 ATA_LFLAG_DISABLED = (1 << 6),
190 ATA_LFLAG_SW_ACTIVITY = (1 << 7),
191 ATA_LFLAG_NO_LPM = (1 << 8),
192 ATA_LFLAG_RST_ONCE = (1 << 9),
193 ATA_LFLAG_CHANGED = (1 << 10),
194 ATA_LFLAG_NO_DB_DELAY = (1 << 11),
195
196
197 ATA_FLAG_SLAVE_POSS = (1 << 0),
198
199 ATA_FLAG_SATA = (1 << 1),
200 ATA_FLAG_NO_LPM = (1 << 2),
201 ATA_FLAG_NO_LOG_PAGE = (1 << 5),
202 ATA_FLAG_NO_ATAPI = (1 << 6),
203 ATA_FLAG_PIO_DMA = (1 << 7),
204 ATA_FLAG_PIO_LBA48 = (1 << 8),
205 ATA_FLAG_PIO_POLLING = (1 << 9),
206
207 ATA_FLAG_NCQ = (1 << 10),
208 ATA_FLAG_NO_POWEROFF_SPINDOWN = (1 << 11),
209 ATA_FLAG_NO_HIBERNATE_SPINDOWN = (1 << 12),
210 ATA_FLAG_DEBUGMSG = (1 << 13),
211 ATA_FLAG_FPDMA_AA = (1 << 14),
212 ATA_FLAG_IGN_SIMPLEX = (1 << 15),
213 ATA_FLAG_NO_IORDY = (1 << 16),
214 ATA_FLAG_ACPI_SATA = (1 << 17),
215 ATA_FLAG_AN = (1 << 18),
216 ATA_FLAG_PMP = (1 << 19),
217 ATA_FLAG_FPDMA_AUX = (1 << 20),
218 ATA_FLAG_EM = (1 << 21),
219
220 ATA_FLAG_SW_ACTIVITY = (1 << 22),
221
222 ATA_FLAG_NO_DIPM = (1 << 23),
223 ATA_FLAG_SAS_HOST = (1 << 24),
224
225
226
227
228
229 ATA_PFLAG_EH_PENDING = (1 << 0),
230 ATA_PFLAG_EH_IN_PROGRESS = (1 << 1),
231 ATA_PFLAG_FROZEN = (1 << 2),
232 ATA_PFLAG_RECOVERED = (1 << 3),
233 ATA_PFLAG_LOADING = (1 << 4),
234 ATA_PFLAG_SCSI_HOTPLUG = (1 << 6),
235 ATA_PFLAG_INITIALIZING = (1 << 7),
236 ATA_PFLAG_RESETTING = (1 << 8),
237 ATA_PFLAG_UNLOADING = (1 << 9),
238 ATA_PFLAG_UNLOADED = (1 << 10),
239
240 ATA_PFLAG_SUSPENDED = (1 << 17),
241 ATA_PFLAG_PM_PENDING = (1 << 18),
242 ATA_PFLAG_INIT_GTM_VALID = (1 << 19),
243
244 ATA_PFLAG_PIO32 = (1 << 20),
245 ATA_PFLAG_PIO32CHANGE = (1 << 21),
246 ATA_PFLAG_EXTERNAL = (1 << 22),
247
248
249 ATA_QCFLAG_ACTIVE = (1 << 0),
250 ATA_QCFLAG_DMAMAP = (1 << 1),
251 ATA_QCFLAG_IO = (1 << 3),
252 ATA_QCFLAG_RESULT_TF = (1 << 4),
253 ATA_QCFLAG_CLEAR_EXCL = (1 << 5),
254 ATA_QCFLAG_QUIET = (1 << 6),
255 ATA_QCFLAG_RETRY = (1 << 7),
256
257 ATA_QCFLAG_FAILED = (1 << 16),
258 ATA_QCFLAG_SENSE_VALID = (1 << 17),
259 ATA_QCFLAG_EH_SCHEDULED = (1 << 18),
260
261
262 ATA_HOST_SIMPLEX = (1 << 0),
263 ATA_HOST_STARTED = (1 << 1),
264 ATA_HOST_PARALLEL_SCAN = (1 << 2),
265 ATA_HOST_IGNORE_ATA = (1 << 3),
266
267
268
269
270 ATA_TMOUT_BOOT = 30000,
271 ATA_TMOUT_BOOT_QUICK = 7000,
272 ATA_TMOUT_INTERNAL_QUICK = 5000,
273 ATA_TMOUT_MAX_PARK = 30000,
274
275
276
277
278
279
280 ATA_TMOUT_FF_WAIT_LONG = 2000,
281 ATA_TMOUT_FF_WAIT = 800,
282
283
284
285
286
287
288
289
290
291
292
293 ATA_WAIT_AFTER_RESET = 150,
294
295
296
297
298
299
300 ATA_TMOUT_PMP_SRST_WAIT = 5000,
301
302
303
304
305
306 ATA_TMOUT_SPURIOUS_PHY = 10000,
307
308
309 BUS_UNKNOWN = 0,
310 BUS_DMA = 1,
311 BUS_IDLE = 2,
312 BUS_NOINTR = 3,
313 BUS_NODATA = 4,
314 BUS_TIMER = 5,
315 BUS_PIO = 6,
316 BUS_EDD = 7,
317 BUS_IDENTIFY = 8,
318 BUS_PACKET = 9,
319
320
321 PORT_UNKNOWN = 0,
322 PORT_ENABLED = 1,
323 PORT_DISABLED = 2,
324
325
326
327
328 ATA_NR_PIO_MODES = 7,
329 ATA_NR_MWDMA_MODES = 5,
330 ATA_NR_UDMA_MODES = 8,
331
332 ATA_SHIFT_PIO = 0,
333 ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES,
334 ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES,
335 ATA_SHIFT_PRIO = 6,
336
337 ATA_PRIO_HIGH = 2,
338
339 ATA_DMA_PAD_SZ = 4,
340
341
342 ATA_ERING_SIZE = 32,
343
344
345 ATA_DEFER_LINK = 1,
346 ATA_DEFER_PORT = 2,
347
348
349 ATA_EH_DESC_LEN = 80,
350
351
352 ATA_EH_REVALIDATE = (1 << 0),
353 ATA_EH_SOFTRESET = (1 << 1),
354 ATA_EH_HARDRESET = (1 << 2),
355 ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
356 ATA_EH_ENABLE_LINK = (1 << 3),
357 ATA_EH_PARK = (1 << 5),
358
359 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK,
360 ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET |
361 ATA_EH_ENABLE_LINK,
362
363
364 ATA_EHI_HOTPLUGGED = (1 << 0),
365 ATA_EHI_NO_AUTOPSY = (1 << 2),
366 ATA_EHI_QUIET = (1 << 3),
367 ATA_EHI_NO_RECOVERY = (1 << 4),
368
369 ATA_EHI_DID_SOFTRESET = (1 << 16),
370 ATA_EHI_DID_HARDRESET = (1 << 17),
371 ATA_EHI_PRINTINFO = (1 << 18),
372 ATA_EHI_SETMODE = (1 << 19),
373 ATA_EHI_POST_SETMODE = (1 << 20),
374
375 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
376
377
378 ATA_EHI_TO_SLAVE_MASK = ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET,
379
380
381 ATA_EH_MAX_TRIES = 5,
382
383
384 ATA_LINK_RESUME_TRIES = 5,
385
386
387 ATA_PROBE_MAX_TRIES = 3,
388 ATA_EH_DEV_TRIES = 3,
389 ATA_EH_PMP_TRIES = 5,
390 ATA_EH_PMP_LINK_TRIES = 3,
391
392 SATA_PMP_RW_TIMEOUT = 3000,
393
394
395
396
397 ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 6,
398
399
400
401
402 ATA_HORKAGE_DIAGNOSTIC = (1 << 0),
403 ATA_HORKAGE_NODMA = (1 << 1),
404 ATA_HORKAGE_NONCQ = (1 << 2),
405 ATA_HORKAGE_MAX_SEC_128 = (1 << 3),
406 ATA_HORKAGE_BROKEN_HPA = (1 << 4),
407 ATA_HORKAGE_DISABLE = (1 << 5),
408 ATA_HORKAGE_HPA_SIZE = (1 << 6),
409 ATA_HORKAGE_IVB = (1 << 8),
410 ATA_HORKAGE_STUCK_ERR = (1 << 9),
411 ATA_HORKAGE_BRIDGE_OK = (1 << 10),
412 ATA_HORKAGE_ATAPI_MOD16_DMA = (1 << 11),
413
414 ATA_HORKAGE_FIRMWARE_WARN = (1 << 12),
415 ATA_HORKAGE_1_5_GBPS = (1 << 13),
416 ATA_HORKAGE_NOSETXFER = (1 << 14),
417 ATA_HORKAGE_BROKEN_FPDMA_AA = (1 << 15),
418 ATA_HORKAGE_DUMP_ID = (1 << 16),
419 ATA_HORKAGE_MAX_SEC_LBA48 = (1 << 17),
420 ATA_HORKAGE_ATAPI_DMADIR = (1 << 18),
421 ATA_HORKAGE_NO_NCQ_TRIM = (1 << 19),
422 ATA_HORKAGE_NOLPM = (1 << 20),
423 ATA_HORKAGE_WD_BROKEN_LPM = (1 << 21),
424 ATA_HORKAGE_ZERO_AFTER_TRIM = (1 << 22),
425 ATA_HORKAGE_NO_DMA_LOG = (1 << 23),
426 ATA_HORKAGE_NOTRIM = (1 << 24),
427 ATA_HORKAGE_MAX_SEC_1024 = (1 << 25),
428 ATA_HORKAGE_MAX_TRIM_128M = (1 << 26),
429 ATA_HORKAGE_NO_NCQ_ON_ATI = (1 << 27),
430
431
432
433 ATA_DMA_MASK_ATA = (1 << 0),
434 ATA_DMA_MASK_ATAPI = (1 << 1),
435 ATA_DMA_MASK_CFA = (1 << 2),
436
437
438 ATAPI_READ = 0,
439 ATAPI_WRITE = 1,
440 ATAPI_READ_CD = 2,
441 ATAPI_PASS_THRU = 3,
442 ATAPI_MISC = 4,
443
444
445 ATA_TIMING_SETUP = (1 << 0),
446 ATA_TIMING_ACT8B = (1 << 1),
447 ATA_TIMING_REC8B = (1 << 2),
448 ATA_TIMING_CYC8B = (1 << 3),
449 ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B |
450 ATA_TIMING_CYC8B,
451 ATA_TIMING_ACTIVE = (1 << 4),
452 ATA_TIMING_RECOVER = (1 << 5),
453 ATA_TIMING_DMACK_HOLD = (1 << 6),
454 ATA_TIMING_CYCLE = (1 << 7),
455 ATA_TIMING_UDMA = (1 << 8),
456 ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
457 ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
458 ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
459 ATA_TIMING_DMACK_HOLD | ATA_TIMING_CYCLE |
460 ATA_TIMING_UDMA,
461
462
463 ATA_ACPI_FILTER_SETXFER = 1 << 0,
464 ATA_ACPI_FILTER_LOCK = 1 << 1,
465 ATA_ACPI_FILTER_DIPM = 1 << 2,
466 ATA_ACPI_FILTER_FPDMA_OFFSET = 1 << 3,
467 ATA_ACPI_FILTER_FPDMA_AA = 1 << 4,
468
469 ATA_ACPI_FILTER_DEFAULT = ATA_ACPI_FILTER_SETXFER |
470 ATA_ACPI_FILTER_LOCK |
471 ATA_ACPI_FILTER_DIPM,
472};
473
474enum ata_xfer_mask {
475 ATA_MASK_PIO = ((1LU << ATA_NR_PIO_MODES) - 1)
476 << ATA_SHIFT_PIO,
477 ATA_MASK_MWDMA = ((1LU << ATA_NR_MWDMA_MODES) - 1)
478 << ATA_SHIFT_MWDMA,
479 ATA_MASK_UDMA = ((1LU << ATA_NR_UDMA_MODES) - 1)
480 << ATA_SHIFT_UDMA,
481};
482
483enum hsm_task_states {
484 HSM_ST_IDLE,
485 HSM_ST_FIRST,
486
487 HSM_ST,
488 HSM_ST_LAST,
489 HSM_ST_ERR,
490};
491
492enum ata_completion_errors {
493 AC_ERR_OK = 0,
494 AC_ERR_DEV = (1 << 0),
495 AC_ERR_HSM = (1 << 1),
496 AC_ERR_TIMEOUT = (1 << 2),
497 AC_ERR_MEDIA = (1 << 3),
498 AC_ERR_ATA_BUS = (1 << 4),
499 AC_ERR_HOST_BUS = (1 << 5),
500 AC_ERR_SYSTEM = (1 << 6),
501 AC_ERR_INVALID = (1 << 7),
502 AC_ERR_OTHER = (1 << 8),
503 AC_ERR_NODEV_HINT = (1 << 9),
504 AC_ERR_NCQ = (1 << 10),
505};
506
507
508
509
510
511enum ata_lpm_policy {
512 ATA_LPM_UNKNOWN,
513 ATA_LPM_MAX_POWER,
514 ATA_LPM_MED_POWER,
515 ATA_LPM_MED_POWER_WITH_DIPM,
516 ATA_LPM_MIN_POWER_WITH_PARTIAL,
517 ATA_LPM_MIN_POWER,
518};
519
520enum ata_lpm_hints {
521 ATA_LPM_EMPTY = (1 << 0),
522 ATA_LPM_HIPM = (1 << 1),
523 ATA_LPM_WAKE_ONLY = (1 << 2),
524};
525
526
527struct scsi_device;
528struct ata_port_operations;
529struct ata_port;
530struct ata_link;
531struct ata_queued_cmd;
532
533
534typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
535typedef int (*ata_prereset_fn_t)(struct ata_link *link, unsigned long deadline);
536typedef int (*ata_reset_fn_t)(struct ata_link *link, unsigned int *classes,
537 unsigned long deadline);
538typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
539
540extern struct device_attribute dev_attr_unload_heads;
541#ifdef CONFIG_SATA_HOST
542extern struct device_attribute dev_attr_link_power_management_policy;
543extern struct device_attribute dev_attr_ncq_prio_supported;
544extern struct device_attribute dev_attr_ncq_prio_enable;
545extern struct device_attribute dev_attr_em_message_type;
546extern struct device_attribute dev_attr_em_message;
547extern struct device_attribute dev_attr_sw_activity;
548#endif
549
550enum sw_activity {
551 OFF,
552 BLINK_ON,
553 BLINK_OFF,
554};
555
556struct ata_taskfile {
557 unsigned long flags;
558 u8 protocol;
559
560 u8 ctl;
561
562 u8 hob_feature;
563 u8 hob_nsect;
564 u8 hob_lbal;
565 u8 hob_lbam;
566 u8 hob_lbah;
567
568 u8 feature;
569 u8 nsect;
570 u8 lbal;
571 u8 lbam;
572 u8 lbah;
573
574 u8 device;
575
576 u8 command;
577
578 u32 auxiliary;
579
580
581};
582
583#ifdef CONFIG_ATA_SFF
584struct ata_ioports {
585 void __iomem *cmd_addr;
586 void __iomem *data_addr;
587 void __iomem *error_addr;
588 void __iomem *feature_addr;
589 void __iomem *nsect_addr;
590 void __iomem *lbal_addr;
591 void __iomem *lbam_addr;
592 void __iomem *lbah_addr;
593 void __iomem *device_addr;
594 void __iomem *status_addr;
595 void __iomem *command_addr;
596 void __iomem *altstatus_addr;
597 void __iomem *ctl_addr;
598#ifdef CONFIG_ATA_BMDMA
599 void __iomem *bmdma_addr;
600#endif
601 void __iomem *scr_addr;
602};
603#endif
604
605struct ata_host {
606 spinlock_t lock;
607 struct device *dev;
608 void __iomem * const *iomap;
609 unsigned int n_ports;
610 unsigned int n_tags;
611 void *private_data;
612 struct ata_port_operations *ops;
613 unsigned long flags;
614 struct kref kref;
615
616 struct mutex eh_mutex;
617 struct task_struct *eh_owner;
618
619 struct ata_port *simplex_claimed;
620 struct ata_port *ports[];
621};
622
623struct ata_queued_cmd {
624 struct ata_port *ap;
625 struct ata_device *dev;
626
627 struct scsi_cmnd *scsicmd;
628 void (*scsidone)(struct scsi_cmnd *);
629
630 struct ata_taskfile tf;
631 u8 cdb[ATAPI_CDB_LEN];
632
633 unsigned long flags;
634 unsigned int tag;
635 unsigned int hw_tag;
636 unsigned int n_elem;
637 unsigned int orig_n_elem;
638
639 int dma_dir;
640
641 unsigned int sect_size;
642
643 unsigned int nbytes;
644 unsigned int extrabytes;
645 unsigned int curbytes;
646
647 struct scatterlist sgent;
648
649 struct scatterlist *sg;
650
651 struct scatterlist *cursg;
652 unsigned int cursg_ofs;
653
654 unsigned int err_mask;
655 struct ata_taskfile result_tf;
656 ata_qc_cb_t complete_fn;
657
658 void *private_data;
659 void *lldd_task;
660};
661
662struct ata_port_stats {
663 unsigned long unhandled_irq;
664 unsigned long idle_irq;
665 unsigned long rw_reqbuf;
666};
667
668struct ata_ering_entry {
669 unsigned int eflags;
670 unsigned int err_mask;
671 u64 timestamp;
672};
673
674struct ata_ering {
675 int cursor;
676 struct ata_ering_entry ring[ATA_ERING_SIZE];
677};
678
679struct ata_device {
680 struct ata_link *link;
681 unsigned int devno;
682 unsigned int horkage;
683 unsigned long flags;
684 struct scsi_device *sdev;
685 void *private_data;
686#ifdef CONFIG_ATA_ACPI
687 union acpi_object *gtf_cache;
688 unsigned int gtf_filter;
689#endif
690#ifdef CONFIG_SATA_ZPODD
691 void *zpodd;
692#endif
693 struct device tdev;
694
695 u64 n_sectors;
696 u64 n_native_sectors;
697 unsigned int class;
698 unsigned long unpark_deadline;
699
700 u8 pio_mode;
701 u8 dma_mode;
702 u8 xfer_mode;
703 unsigned int xfer_shift;
704
705 unsigned int multi_count;
706
707 unsigned int max_sectors;
708 unsigned int cdb_len;
709
710
711 unsigned long pio_mask;
712 unsigned long mwdma_mask;
713 unsigned long udma_mask;
714
715
716 u16 cylinders;
717 u16 heads;
718 u16 sectors;
719
720 union {
721 u16 id[ATA_ID_WORDS];
722 u32 gscr[SATA_PMP_GSCR_DWORDS];
723 } ____cacheline_aligned;
724
725
726 u8 devslp_timing[ATA_LOG_DEVSLP_SIZE];
727
728
729 u8 ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_SIZE];
730 u8 ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_SIZE];
731
732
733 u32 zac_zoned_cap;
734 u32 zac_zones_optimal_open;
735 u32 zac_zones_optimal_nonseq;
736 u32 zac_zones_max_open;
737
738
739 int spdn_cnt;
740
741 struct ata_ering ering;
742};
743
744
745
746
747#define ATA_DEVICE_CLEAR_BEGIN offsetof(struct ata_device, n_sectors)
748#define ATA_DEVICE_CLEAR_END offsetof(struct ata_device, ering)
749
750struct ata_eh_info {
751 struct ata_device *dev;
752 u32 serror;
753 unsigned int err_mask;
754 unsigned int action;
755 unsigned int dev_action[ATA_MAX_DEVICES];
756 unsigned int flags;
757
758 unsigned int probe_mask;
759
760 char desc[ATA_EH_DESC_LEN];
761 int desc_len;
762};
763
764struct ata_eh_context {
765 struct ata_eh_info i;
766 int tries[ATA_MAX_DEVICES];
767 int cmd_timeout_idx[ATA_MAX_DEVICES]
768 [ATA_EH_CMD_TIMEOUT_TABLE_SIZE];
769 unsigned int classes[ATA_MAX_DEVICES];
770 unsigned int did_probe_mask;
771 unsigned int unloaded_mask;
772 unsigned int saved_ncq_enabled;
773 u8 saved_xfer_mode[ATA_MAX_DEVICES];
774
775 unsigned long last_reset;
776};
777
778struct ata_acpi_drive
779{
780 u32 pio;
781 u32 dma;
782} __packed;
783
784struct ata_acpi_gtm {
785 struct ata_acpi_drive drive[2];
786 u32 flags;
787} __packed;
788
789struct ata_link {
790 struct ata_port *ap;
791 int pmp;
792
793 struct device tdev;
794 unsigned int active_tag;
795 u32 sactive;
796
797 unsigned int flags;
798
799 u32 saved_scontrol;
800 unsigned int hw_sata_spd_limit;
801 unsigned int sata_spd_limit;
802 unsigned int sata_spd;
803 enum ata_lpm_policy lpm_policy;
804
805
806 struct ata_eh_info eh_info;
807
808 struct ata_eh_context eh_context;
809
810 struct ata_device device[ATA_MAX_DEVICES];
811
812 unsigned long last_lpm_change;
813};
814#define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
815#define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
816
817struct ata_port {
818 struct Scsi_Host *scsi_host;
819 struct ata_port_operations *ops;
820 spinlock_t *lock;
821
822
823 unsigned long flags;
824
825 unsigned int pflags;
826 unsigned int print_id;
827 unsigned int local_port_no;
828 unsigned int port_no;
829
830#ifdef CONFIG_ATA_SFF
831 struct ata_ioports ioaddr;
832 u8 ctl;
833 u8 last_ctl;
834 struct ata_link* sff_pio_task_link;
835 struct delayed_work sff_pio_task;
836#ifdef CONFIG_ATA_BMDMA
837 struct ata_bmdma_prd *bmdma_prd;
838 dma_addr_t bmdma_prd_dma;
839#endif
840#endif
841
842 unsigned int pio_mask;
843 unsigned int mwdma_mask;
844 unsigned int udma_mask;
845 unsigned int cbl;
846
847 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE + 1];
848 unsigned long sas_tag_allocated;
849 u64 qc_active;
850 int nr_active_links;
851 unsigned int sas_last_tag;
852
853 struct ata_link link;
854 struct ata_link *slave_link;
855
856 int nr_pmp_links;
857 struct ata_link *pmp_link;
858 struct ata_link *excl_link;
859
860 struct ata_port_stats stats;
861 struct ata_host *host;
862 struct device *dev;
863 struct device tdev;
864
865 struct mutex scsi_scan_mutex;
866 struct delayed_work hotplug_task;
867 struct work_struct scsi_rescan_task;
868
869 unsigned int hsm_task_state;
870
871 u32 msg_enable;
872 struct list_head eh_done_q;
873 wait_queue_head_t eh_wait_q;
874 int eh_tries;
875 struct completion park_req_pending;
876
877 pm_message_t pm_mesg;
878 enum ata_lpm_policy target_lpm_policy;
879
880 struct timer_list fastdrain_timer;
881 unsigned long fastdrain_cnt;
882
883 async_cookie_t cookie;
884
885 int em_message_type;
886 void *private_data;
887
888#ifdef CONFIG_ATA_ACPI
889 struct ata_acpi_gtm __acpi_init_gtm;
890#endif
891
892 u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
893};
894
895
896
897
898
899
900#define ATA_OP_NULL (void *)(unsigned long)(-ENOENT)
901
902struct ata_port_operations {
903
904
905
906 int (*qc_defer)(struct ata_queued_cmd *qc);
907 int (*check_atapi_dma)(struct ata_queued_cmd *qc);
908 enum ata_completion_errors (*qc_prep)(struct ata_queued_cmd *qc);
909 unsigned int (*qc_issue)(struct ata_queued_cmd *qc);
910 bool (*qc_fill_rtf)(struct ata_queued_cmd *qc);
911
912
913
914
915 int (*cable_detect)(struct ata_port *ap);
916 unsigned long (*mode_filter)(struct ata_device *dev, unsigned long xfer_mask);
917 void (*set_piomode)(struct ata_port *ap, struct ata_device *dev);
918 void (*set_dmamode)(struct ata_port *ap, struct ata_device *dev);
919 int (*set_mode)(struct ata_link *link, struct ata_device **r_failed_dev);
920 unsigned int (*read_id)(struct ata_device *dev, struct ata_taskfile *tf, u16 *id);
921
922 void (*dev_config)(struct ata_device *dev);
923
924 void (*freeze)(struct ata_port *ap);
925 void (*thaw)(struct ata_port *ap);
926 ata_prereset_fn_t prereset;
927 ata_reset_fn_t softreset;
928 ata_reset_fn_t hardreset;
929 ata_postreset_fn_t postreset;
930 ata_prereset_fn_t pmp_prereset;
931 ata_reset_fn_t pmp_softreset;
932 ata_reset_fn_t pmp_hardreset;
933 ata_postreset_fn_t pmp_postreset;
934 void (*error_handler)(struct ata_port *ap);
935 void (*lost_interrupt)(struct ata_port *ap);
936 void (*post_internal_cmd)(struct ata_queued_cmd *qc);
937 void (*sched_eh)(struct ata_port *ap);
938 void (*end_eh)(struct ata_port *ap);
939
940
941
942
943 int (*scr_read)(struct ata_link *link, unsigned int sc_reg, u32 *val);
944 int (*scr_write)(struct ata_link *link, unsigned int sc_reg, u32 val);
945 void (*pmp_attach)(struct ata_port *ap);
946 void (*pmp_detach)(struct ata_port *ap);
947 int (*set_lpm)(struct ata_link *link, enum ata_lpm_policy policy,
948 unsigned hints);
949
950
951
952
953 int (*port_suspend)(struct ata_port *ap, pm_message_t mesg);
954 int (*port_resume)(struct ata_port *ap);
955 int (*port_start)(struct ata_port *ap);
956 void (*port_stop)(struct ata_port *ap);
957 void (*host_stop)(struct ata_host *host);
958
959#ifdef CONFIG_ATA_SFF
960
961
962
963 void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
964 void (*sff_set_devctl)(struct ata_port *ap, u8 ctl);
965 u8 (*sff_check_status)(struct ata_port *ap);
966 u8 (*sff_check_altstatus)(struct ata_port *ap);
967 void (*sff_tf_load)(struct ata_port *ap, const struct ata_taskfile *tf);
968 void (*sff_tf_read)(struct ata_port *ap, struct ata_taskfile *tf);
969 void (*sff_exec_command)(struct ata_port *ap,
970 const struct ata_taskfile *tf);
971 unsigned int (*sff_data_xfer)(struct ata_queued_cmd *qc,
972 unsigned char *buf, unsigned int buflen, int rw);
973 void (*sff_irq_on)(struct ata_port *);
974 bool (*sff_irq_check)(struct ata_port *);
975 void (*sff_irq_clear)(struct ata_port *);
976 void (*sff_drain_fifo)(struct ata_queued_cmd *qc);
977
978#ifdef CONFIG_ATA_BMDMA
979 void (*bmdma_setup)(struct ata_queued_cmd *qc);
980 void (*bmdma_start)(struct ata_queued_cmd *qc);
981 void (*bmdma_stop)(struct ata_queued_cmd *qc);
982 u8 (*bmdma_status)(struct ata_port *ap);
983#endif
984#endif
985
986 ssize_t (*em_show)(struct ata_port *ap, char *buf);
987 ssize_t (*em_store)(struct ata_port *ap, const char *message,
988 size_t size);
989 ssize_t (*sw_activity_show)(struct ata_device *dev, char *buf);
990 ssize_t (*sw_activity_store)(struct ata_device *dev,
991 enum sw_activity val);
992 ssize_t (*transmit_led_message)(struct ata_port *ap, u32 state,
993 ssize_t size);
994
995
996
997
998 void (*phy_reset)(struct ata_port *ap);
999 void (*eng_timeout)(struct ata_port *ap);
1000
1001
1002
1003
1004
1005 const struct ata_port_operations *inherits;
1006};
1007
1008struct ata_port_info {
1009 unsigned long flags;
1010 unsigned long link_flags;
1011 unsigned long pio_mask;
1012 unsigned long mwdma_mask;
1013 unsigned long udma_mask;
1014 struct ata_port_operations *port_ops;
1015 void *private_data;
1016};
1017
1018struct ata_timing {
1019 unsigned short mode;
1020 unsigned short setup;
1021 unsigned short act8b;
1022 unsigned short rec8b;
1023 unsigned short cyc8b;
1024 unsigned short active;
1025 unsigned short recover;
1026 unsigned short dmack_hold;
1027 unsigned short cycle;
1028 unsigned short udma;
1029};
1030
1031
1032
1033
1034extern struct ata_port_operations ata_dummy_port_ops;
1035extern const struct ata_port_info ata_dummy_port_info;
1036
1037static inline bool ata_is_atapi(u8 prot)
1038{
1039 return prot & ATA_PROT_FLAG_ATAPI;
1040}
1041
1042static inline bool ata_is_pio(u8 prot)
1043{
1044 return prot & ATA_PROT_FLAG_PIO;
1045}
1046
1047static inline bool ata_is_dma(u8 prot)
1048{
1049 return prot & ATA_PROT_FLAG_DMA;
1050}
1051
1052static inline bool ata_is_ncq(u8 prot)
1053{
1054 return prot & ATA_PROT_FLAG_NCQ;
1055}
1056
1057static inline bool ata_is_data(u8 prot)
1058{
1059 return prot & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA);
1060}
1061
1062static inline int is_multi_taskfile(struct ata_taskfile *tf)
1063{
1064 return (tf->command == ATA_CMD_READ_MULTI) ||
1065 (tf->command == ATA_CMD_WRITE_MULTI) ||
1066 (tf->command == ATA_CMD_READ_MULTI_EXT) ||
1067 (tf->command == ATA_CMD_WRITE_MULTI_EXT) ||
1068 (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
1069}
1070
1071static inline int ata_port_is_dummy(struct ata_port *ap)
1072{
1073 return ap->ops == &ata_dummy_port_ops;
1074}
1075
1076extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
1077extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
1078 int (*check_ready)(struct ata_link *link));
1079extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
1080 unsigned long deadline);
1081extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
1082
1083extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
1084extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
1085 const struct ata_port_info * const * ppi, int n_ports);
1086extern void ata_host_get(struct ata_host *host);
1087extern void ata_host_put(struct ata_host *host);
1088extern int ata_host_start(struct ata_host *host);
1089extern int ata_host_register(struct ata_host *host,
1090 struct scsi_host_template *sht);
1091extern int ata_host_activate(struct ata_host *host, int irq,
1092 irq_handler_t irq_handler, unsigned long irq_flags,
1093 struct scsi_host_template *sht);
1094extern void ata_host_detach(struct ata_host *host);
1095extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
1096extern int ata_scsi_detect(struct scsi_host_template *sht);
1097extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
1098 void __user *arg);
1099#ifdef CONFIG_COMPAT
1100#define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
1101#else
1102#define ATA_SCSI_COMPAT_IOCTL
1103#endif
1104extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
1105#if IS_REACHABLE(CONFIG_ATA)
1106bool ata_scsi_dma_need_drain(struct request *rq);
1107#else
1108#define ata_scsi_dma_need_drain NULL
1109#endif
1110extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
1111 unsigned int cmd, void __user *arg);
1112extern bool ata_link_online(struct ata_link *link);
1113extern bool ata_link_offline(struct ata_link *link);
1114#ifdef CONFIG_PM
1115extern int ata_host_suspend(struct ata_host *host, pm_message_t mesg);
1116extern void ata_host_resume(struct ata_host *host);
1117extern void ata_sas_port_suspend(struct ata_port *ap);
1118extern void ata_sas_port_resume(struct ata_port *ap);
1119#else
1120static inline void ata_sas_port_suspend(struct ata_port *ap)
1121{
1122}
1123static inline void ata_sas_port_resume(struct ata_port *ap)
1124{
1125}
1126#endif
1127extern int ata_ratelimit(void);
1128extern void ata_msleep(struct ata_port *ap, unsigned int msecs);
1129extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
1130 u32 val, unsigned long interval, unsigned long timeout);
1131extern int atapi_cmd_type(u8 opcode);
1132extern unsigned long ata_pack_xfermask(unsigned long pio_mask,
1133 unsigned long mwdma_mask, unsigned long udma_mask);
1134extern void ata_unpack_xfermask(unsigned long xfer_mask,
1135 unsigned long *pio_mask, unsigned long *mwdma_mask,
1136 unsigned long *udma_mask);
1137extern u8 ata_xfer_mask2mode(unsigned long xfer_mask);
1138extern unsigned long ata_xfer_mode2mask(u8 xfer_mode);
1139extern int ata_xfer_mode2shift(unsigned long xfer_mode);
1140extern const char *ata_mode_string(unsigned long xfer_mask);
1141extern unsigned long ata_id_xfermask(const u16 *id);
1142extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
1143extern enum ata_completion_errors ata_noop_qc_prep(struct ata_queued_cmd *qc);
1144extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
1145 unsigned int n_elem);
1146extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
1147extern void ata_dev_disable(struct ata_device *adev);
1148extern void ata_id_string(const u16 *id, unsigned char *s,
1149 unsigned int ofs, unsigned int len);
1150extern void ata_id_c_string(const u16 *id, unsigned char *s,
1151 unsigned int ofs, unsigned int len);
1152extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
1153 struct ata_taskfile *tf, u16 *id);
1154extern void ata_qc_complete(struct ata_queued_cmd *qc);
1155extern u64 ata_qc_get_active(struct ata_port *ap);
1156extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
1157extern int ata_std_bios_param(struct scsi_device *sdev,
1158 struct block_device *bdev,
1159 sector_t capacity, int geom[]);
1160extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev);
1161extern int ata_scsi_slave_config(struct scsi_device *sdev);
1162extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
1163extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
1164 int queue_depth);
1165extern int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1166 int queue_depth);
1167extern struct ata_device *ata_dev_pair(struct ata_device *adev);
1168extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
1169extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
1170extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
1171
1172
1173
1174
1175#ifdef CONFIG_SATA_HOST
1176extern const unsigned long sata_deb_timing_normal[];
1177extern const unsigned long sata_deb_timing_hotplug[];
1178extern const unsigned long sata_deb_timing_long[];
1179
1180static inline const unsigned long *
1181sata_ehc_deb_timing(struct ata_eh_context *ehc)
1182{
1183 if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
1184 return sata_deb_timing_hotplug;
1185 else
1186 return sata_deb_timing_normal;
1187}
1188
1189extern int sata_scr_valid(struct ata_link *link);
1190extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
1191extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
1192extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
1193extern int sata_set_spd(struct ata_link *link);
1194extern int sata_link_hardreset(struct ata_link *link,
1195 const unsigned long *timing, unsigned long deadline,
1196 bool *online, int (*check_ready)(struct ata_link *));
1197extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
1198 unsigned long deadline);
1199extern void ata_eh_analyze_ncq_error(struct ata_link *link);
1200#else
1201static inline const unsigned long *
1202sata_ehc_deb_timing(struct ata_eh_context *ehc)
1203{
1204 return NULL;
1205}
1206static inline int sata_scr_valid(struct ata_link *link) { return 0; }
1207static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
1208{
1209 return -EOPNOTSUPP;
1210}
1211static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
1212{
1213 return -EOPNOTSUPP;
1214}
1215static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
1216{
1217 return -EOPNOTSUPP;
1218}
1219static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
1220static inline int sata_link_hardreset(struct ata_link *link,
1221 const unsigned long *timing,
1222 unsigned long deadline,
1223 bool *online,
1224 int (*check_ready)(struct ata_link *))
1225{
1226 if (online)
1227 *online = false;
1228 return -EOPNOTSUPP;
1229}
1230static inline int sata_link_resume(struct ata_link *link,
1231 const unsigned long *params,
1232 unsigned long deadline)
1233{
1234 return -EOPNOTSUPP;
1235}
1236static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
1237#endif
1238extern int sata_link_debounce(struct ata_link *link,
1239 const unsigned long *params, unsigned long deadline);
1240extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
1241 bool spm_wakeup);
1242extern int ata_slave_link_init(struct ata_port *ap);
1243extern void ata_sas_port_destroy(struct ata_port *);
1244extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
1245 struct ata_port_info *, struct Scsi_Host *);
1246extern void ata_sas_async_probe(struct ata_port *ap);
1247extern int ata_sas_sync_probe(struct ata_port *ap);
1248extern int ata_sas_port_init(struct ata_port *);
1249extern int ata_sas_port_start(struct ata_port *ap);
1250extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
1251extern void ata_sas_tport_delete(struct ata_port *ap);
1252extern void ata_sas_port_stop(struct ata_port *ap);
1253extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
1254extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
1255extern void ata_tf_to_fis(const struct ata_taskfile *tf,
1256 u8 pmp, int is_cmd, u8 *fis);
1257extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
1258extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
1259extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
1260extern int sata_async_notification(struct ata_port *ap);
1261
1262extern int ata_cable_40wire(struct ata_port *ap);
1263extern int ata_cable_80wire(struct ata_port *ap);
1264extern int ata_cable_sata(struct ata_port *ap);
1265extern int ata_cable_ignore(struct ata_port *ap);
1266extern int ata_cable_unknown(struct ata_port *ap);
1267
1268
1269extern unsigned int ata_pio_need_iordy(const struct ata_device *);
1270extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
1271
1272
1273#ifdef CONFIG_PCI
1274struct pci_dev;
1275
1276struct pci_bits {
1277 unsigned int reg;
1278 unsigned int width;
1279 unsigned long mask;
1280 unsigned long val;
1281};
1282
1283extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
1284extern void ata_pci_shutdown_one(struct pci_dev *pdev);
1285extern void ata_pci_remove_one(struct pci_dev *pdev);
1286
1287#ifdef CONFIG_PM
1288extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
1289extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
1290extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
1291extern int ata_pci_device_resume(struct pci_dev *pdev);
1292#endif
1293#endif
1294
1295struct platform_device;
1296
1297extern int ata_platform_remove_one(struct platform_device *pdev);
1298
1299
1300
1301
1302#ifdef CONFIG_ATA_ACPI
1303static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1304{
1305 if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID)
1306 return &ap->__acpi_init_gtm;
1307 return NULL;
1308}
1309int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
1310int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
1311unsigned long ata_acpi_gtm_xfermask(struct ata_device *dev,
1312 const struct ata_acpi_gtm *gtm);
1313int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
1314#else
1315static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1316{
1317 return NULL;
1318}
1319
1320static inline int ata_acpi_stm(const struct ata_port *ap,
1321 struct ata_acpi_gtm *stm)
1322{
1323 return -ENOSYS;
1324}
1325
1326static inline int ata_acpi_gtm(const struct ata_port *ap,
1327 struct ata_acpi_gtm *stm)
1328{
1329 return -ENOSYS;
1330}
1331
1332static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
1333 const struct ata_acpi_gtm *gtm)
1334{
1335 return 0;
1336}
1337
1338static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
1339 const struct ata_acpi_gtm *gtm)
1340{
1341 return 0;
1342}
1343#endif
1344
1345
1346
1347
1348extern void ata_port_schedule_eh(struct ata_port *ap);
1349extern void ata_port_wait_eh(struct ata_port *ap);
1350extern int ata_link_abort(struct ata_link *link);
1351extern int ata_port_abort(struct ata_port *ap);
1352extern int ata_port_freeze(struct ata_port *ap);
1353
1354extern void ata_eh_freeze_port(struct ata_port *ap);
1355extern void ata_eh_thaw_port(struct ata_port *ap);
1356
1357extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
1358extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1359
1360extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1361 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1362 ata_postreset_fn_t postreset);
1363extern void ata_std_error_handler(struct ata_port *ap);
1364extern void ata_std_sched_eh(struct ata_port *ap);
1365extern void ata_std_end_eh(struct ata_port *ap);
1366extern int ata_link_nr_enabled(struct ata_link *link);
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389extern const struct ata_port_operations ata_base_port_ops;
1390extern const struct ata_port_operations sata_port_ops;
1391extern struct device_attribute *ata_common_sdev_attrs[];
1392
1393
1394
1395
1396
1397
1398
1399#define __ATA_BASE_SHT(drv_name) \
1400 .module = THIS_MODULE, \
1401 .name = drv_name, \
1402 .ioctl = ata_scsi_ioctl, \
1403 ATA_SCSI_COMPAT_IOCTL \
1404 .queuecommand = ata_scsi_queuecmd, \
1405 .dma_need_drain = ata_scsi_dma_need_drain, \
1406 .this_id = ATA_SHT_THIS_ID, \
1407 .emulated = ATA_SHT_EMULATED, \
1408 .proc_name = drv_name, \
1409 .slave_destroy = ata_scsi_slave_destroy, \
1410 .bios_param = ata_std_bios_param, \
1411 .unlock_native_capacity = ata_scsi_unlock_native_capacity
1412
1413#define ATA_SUBBASE_SHT(drv_name) \
1414 __ATA_BASE_SHT(drv_name), \
1415 .can_queue = ATA_DEF_QUEUE, \
1416 .tag_alloc_policy = BLK_TAG_ALLOC_RR, \
1417 .slave_configure = ata_scsi_slave_config
1418
1419#define ATA_BASE_SHT(drv_name) \
1420 ATA_SUBBASE_SHT(drv_name), \
1421 .sdev_attrs = ata_common_sdev_attrs
1422
1423#ifdef CONFIG_SATA_HOST
1424extern struct device_attribute *ata_ncq_sdev_attrs[];
1425
1426#define ATA_NCQ_SHT(drv_name) \
1427 ATA_SUBBASE_SHT(drv_name), \
1428 .sdev_attrs = ata_ncq_sdev_attrs, \
1429 .change_queue_depth = ata_scsi_change_queue_depth
1430#endif
1431
1432
1433
1434
1435#ifdef CONFIG_SATA_PMP
1436static inline bool sata_pmp_supported(struct ata_port *ap)
1437{
1438 return ap->flags & ATA_FLAG_PMP;
1439}
1440
1441static inline bool sata_pmp_attached(struct ata_port *ap)
1442{
1443 return ap->nr_pmp_links != 0;
1444}
1445
1446static inline bool ata_is_host_link(const struct ata_link *link)
1447{
1448 return link == &link->ap->link || link == link->ap->slave_link;
1449}
1450#else
1451static inline bool sata_pmp_supported(struct ata_port *ap)
1452{
1453 return false;
1454}
1455
1456static inline bool sata_pmp_attached(struct ata_port *ap)
1457{
1458 return false;
1459}
1460
1461static inline bool ata_is_host_link(const struct ata_link *link)
1462{
1463 return true;
1464}
1465#endif
1466
1467static inline int sata_srst_pmp(struct ata_link *link)
1468{
1469 if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
1470 return SATA_PMP_CTRL_PORT;
1471 return link->pmp;
1472}
1473
1474
1475
1476
1477__printf(3, 4)
1478void ata_port_printk(const struct ata_port *ap, const char *level,
1479 const char *fmt, ...);
1480__printf(3, 4)
1481void ata_link_printk(const struct ata_link *link, const char *level,
1482 const char *fmt, ...);
1483__printf(3, 4)
1484void ata_dev_printk(const struct ata_device *dev, const char *level,
1485 const char *fmt, ...);
1486
1487#define ata_port_err(ap, fmt, ...) \
1488 ata_port_printk(ap, KERN_ERR, fmt, ##__VA_ARGS__)
1489#define ata_port_warn(ap, fmt, ...) \
1490 ata_port_printk(ap, KERN_WARNING, fmt, ##__VA_ARGS__)
1491#define ata_port_notice(ap, fmt, ...) \
1492 ata_port_printk(ap, KERN_NOTICE, fmt, ##__VA_ARGS__)
1493#define ata_port_info(ap, fmt, ...) \
1494 ata_port_printk(ap, KERN_INFO, fmt, ##__VA_ARGS__)
1495#define ata_port_dbg(ap, fmt, ...) \
1496 ata_port_printk(ap, KERN_DEBUG, fmt, ##__VA_ARGS__)
1497
1498#define ata_link_err(link, fmt, ...) \
1499 ata_link_printk(link, KERN_ERR, fmt, ##__VA_ARGS__)
1500#define ata_link_warn(link, fmt, ...) \
1501 ata_link_printk(link, KERN_WARNING, fmt, ##__VA_ARGS__)
1502#define ata_link_notice(link, fmt, ...) \
1503 ata_link_printk(link, KERN_NOTICE, fmt, ##__VA_ARGS__)
1504#define ata_link_info(link, fmt, ...) \
1505 ata_link_printk(link, KERN_INFO, fmt, ##__VA_ARGS__)
1506#define ata_link_dbg(link, fmt, ...) \
1507 ata_link_printk(link, KERN_DEBUG, fmt, ##__VA_ARGS__)
1508
1509#define ata_dev_err(dev, fmt, ...) \
1510 ata_dev_printk(dev, KERN_ERR, fmt, ##__VA_ARGS__)
1511#define ata_dev_warn(dev, fmt, ...) \
1512 ata_dev_printk(dev, KERN_WARNING, fmt, ##__VA_ARGS__)
1513#define ata_dev_notice(dev, fmt, ...) \
1514 ata_dev_printk(dev, KERN_NOTICE, fmt, ##__VA_ARGS__)
1515#define ata_dev_info(dev, fmt, ...) \
1516 ata_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__)
1517#define ata_dev_dbg(dev, fmt, ...) \
1518 ata_dev_printk(dev, KERN_DEBUG, fmt, ##__VA_ARGS__)
1519
1520void ata_print_version(const struct device *dev, const char *version);
1521
1522
1523
1524
1525extern __printf(2, 3)
1526void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1527extern __printf(2, 3)
1528void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1529extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
1530
1531static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
1532{
1533 ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1;
1534 ehi->flags |= ATA_EHI_HOTPLUGGED;
1535 ehi->action |= ATA_EH_RESET | ATA_EH_ENABLE_LINK;
1536 ehi->err_mask |= AC_ERR_ATA_BUS;
1537}
1538
1539
1540
1541
1542extern __printf(2, 3)
1543void ata_port_desc(struct ata_port *ap, const char *fmt, ...);
1544#ifdef CONFIG_PCI
1545extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
1546 const char *name);
1547#endif
1548
1549static inline bool ata_tag_internal(unsigned int tag)
1550{
1551 return tag == ATA_TAG_INTERNAL;
1552}
1553
1554static inline bool ata_tag_valid(unsigned int tag)
1555{
1556 return tag < ATA_MAX_QUEUE || ata_tag_internal(tag);
1557}
1558
1559#define __ata_qc_for_each(ap, qc, tag, max_tag, fn) \
1560 for ((tag) = 0; (tag) < (max_tag) && \
1561 ({ qc = fn((ap), (tag)); 1; }); (tag)++) \
1562
1563
1564
1565
1566
1567#define ata_qc_for_each_raw(ap, qc, tag) \
1568 __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, __ata_qc_from_tag)
1569
1570
1571
1572
1573#define ata_qc_for_each(ap, qc, tag) \
1574 __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, ata_qc_from_tag)
1575
1576
1577
1578
1579#define ata_qc_for_each_with_internal(ap, qc, tag) \
1580 __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE + 1, ata_qc_from_tag)
1581
1582
1583
1584
1585static inline unsigned int ata_class_enabled(unsigned int class)
1586{
1587 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI ||
1588 class == ATA_DEV_PMP || class == ATA_DEV_SEMB ||
1589 class == ATA_DEV_ZAC;
1590}
1591
1592static inline unsigned int ata_class_disabled(unsigned int class)
1593{
1594 return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP ||
1595 class == ATA_DEV_PMP_UNSUP || class == ATA_DEV_SEMB_UNSUP ||
1596 class == ATA_DEV_ZAC_UNSUP;
1597}
1598
1599static inline unsigned int ata_class_absent(unsigned int class)
1600{
1601 return !ata_class_enabled(class) && !ata_class_disabled(class);
1602}
1603
1604static inline unsigned int ata_dev_enabled(const struct ata_device *dev)
1605{
1606 return ata_class_enabled(dev->class);
1607}
1608
1609static inline unsigned int ata_dev_disabled(const struct ata_device *dev)
1610{
1611 return ata_class_disabled(dev->class);
1612}
1613
1614static inline unsigned int ata_dev_absent(const struct ata_device *dev)
1615{
1616 return ata_class_absent(dev->class);
1617}
1618
1619
1620
1621
1622static inline int ata_link_max_devices(const struct ata_link *link)
1623{
1624 if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS)
1625 return 2;
1626 return 1;
1627}
1628
1629static inline int ata_link_active(struct ata_link *link)
1630{
1631 return ata_tag_valid(link->active_tag) || link->sactive;
1632}
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646enum ata_link_iter_mode {
1647 ATA_LITER_EDGE,
1648
1649 ATA_LITER_HOST_FIRST,
1650 ATA_LITER_PMP_FIRST,
1651
1652};
1653
1654enum ata_dev_iter_mode {
1655 ATA_DITER_ENABLED,
1656 ATA_DITER_ENABLED_REVERSE,
1657 ATA_DITER_ALL,
1658 ATA_DITER_ALL_REVERSE,
1659};
1660
1661extern struct ata_link *ata_link_next(struct ata_link *link,
1662 struct ata_port *ap,
1663 enum ata_link_iter_mode mode);
1664
1665extern struct ata_device *ata_dev_next(struct ata_device *dev,
1666 struct ata_link *link,
1667 enum ata_dev_iter_mode mode);
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683#define ata_for_each_link(link, ap, mode) \
1684 for ((link) = ata_link_next(NULL, (ap), ATA_LITER_##mode); (link); \
1685 (link) = ata_link_next((link), (ap), ATA_LITER_##mode))
1686
1687#define ata_for_each_dev(dev, link, mode) \
1688 for ((dev) = ata_dev_next(NULL, (link), ATA_DITER_##mode); (dev); \
1689 (dev) = ata_dev_next((dev), (link), ATA_DITER_##mode))
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701static inline int ata_ncq_enabled(struct ata_device *dev)
1702{
1703 if (!IS_ENABLED(CONFIG_SATA_HOST))
1704 return 0;
1705 return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
1706 ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
1707}
1708
1709static inline bool ata_fpdma_dsm_supported(struct ata_device *dev)
1710{
1711 return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
1712 (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &
1713 ATA_LOG_NCQ_SEND_RECV_DSM_TRIM);
1714}
1715
1716static inline bool ata_fpdma_read_log_supported(struct ata_device *dev)
1717{
1718 return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
1719 (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET] &
1720 ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED);
1721}
1722
1723static inline bool ata_fpdma_zac_mgmt_in_supported(struct ata_device *dev)
1724{
1725 return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
1726 (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET] &
1727 ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED);
1728}
1729
1730static inline bool ata_fpdma_zac_mgmt_out_supported(struct ata_device *dev)
1731{
1732 return (dev->ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OFFSET] &
1733 ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OUT);
1734}
1735
1736static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
1737{
1738 qc->tf.ctl |= ATA_NIEN;
1739}
1740
1741static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
1742 unsigned int tag)
1743{
1744 if (ata_tag_valid(tag))
1745 return &ap->qcmd[tag];
1746 return NULL;
1747}
1748
1749static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
1750 unsigned int tag)
1751{
1752 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1753
1754 if (unlikely(!qc) || !ap->ops->error_handler)
1755 return qc;
1756
1757 if ((qc->flags & (ATA_QCFLAG_ACTIVE |
1758 ATA_QCFLAG_FAILED)) == ATA_QCFLAG_ACTIVE)
1759 return qc;
1760
1761 return NULL;
1762}
1763
1764static inline unsigned int ata_qc_raw_nbytes(struct ata_queued_cmd *qc)
1765{
1766 return qc->nbytes - min(qc->extrabytes, qc->nbytes);
1767}
1768
1769static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
1770{
1771 memset(tf, 0, sizeof(*tf));
1772
1773#ifdef CONFIG_ATA_SFF
1774 tf->ctl = dev->link->ap->ctl;
1775#else
1776 tf->ctl = ATA_DEVCTL_OBS;
1777#endif
1778 if (dev->devno == 0)
1779 tf->device = ATA_DEVICE_OBS;
1780 else
1781 tf->device = ATA_DEVICE_OBS | ATA_DEV1;
1782}
1783
1784static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
1785{
1786 qc->dma_dir = DMA_NONE;
1787 qc->sg = NULL;
1788 qc->flags = 0;
1789 qc->cursg = NULL;
1790 qc->cursg_ofs = 0;
1791 qc->nbytes = qc->extrabytes = qc->curbytes = 0;
1792 qc->n_elem = 0;
1793 qc->err_mask = 0;
1794 qc->sect_size = ATA_SECT_SIZE;
1795
1796 ata_tf_init(qc->dev, &qc->tf);
1797
1798
1799 qc->result_tf.command = ATA_DRDY;
1800 qc->result_tf.feature = 0;
1801}
1802
1803static inline int ata_try_flush_cache(const struct ata_device *dev)
1804{
1805 return ata_id_wcache_enabled(dev->id) ||
1806 ata_id_has_flush(dev->id) ||
1807 ata_id_has_flush_ext(dev->id);
1808}
1809
1810static inline unsigned int ac_err_mask(u8 status)
1811{
1812 if (status & (ATA_BUSY | ATA_DRQ))
1813 return AC_ERR_HSM;
1814 if (status & (ATA_ERR | ATA_DF))
1815 return AC_ERR_DEV;
1816 return 0;
1817}
1818
1819static inline unsigned int __ac_err_mask(u8 status)
1820{
1821 unsigned int mask = ac_err_mask(status);
1822 if (mask == 0)
1823 return AC_ERR_OTHER;
1824 return mask;
1825}
1826
1827static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
1828{
1829 return *(struct ata_port **)&host->hostdata[0];
1830}
1831
1832static inline int ata_check_ready(u8 status)
1833{
1834 if (!(status & ATA_BUSY))
1835 return 1;
1836
1837
1838 if (status == 0xff)
1839 return -ENODEV;
1840
1841 return 0;
1842}
1843
1844static inline unsigned long ata_deadline(unsigned long from_jiffies,
1845 unsigned long timeout_msecs)
1846{
1847 return from_jiffies + msecs_to_jiffies(timeout_msecs);
1848}
1849
1850
1851
1852
1853
1854static inline int ata_using_mwdma(struct ata_device *adev)
1855{
1856 if (adev->dma_mode >= XFER_MW_DMA_0 && adev->dma_mode <= XFER_MW_DMA_4)
1857 return 1;
1858 return 0;
1859}
1860
1861static inline int ata_using_udma(struct ata_device *adev)
1862{
1863 if (adev->dma_mode >= XFER_UDMA_0 && adev->dma_mode <= XFER_UDMA_7)
1864 return 1;
1865 return 0;
1866}
1867
1868static inline int ata_dma_enabled(struct ata_device *adev)
1869{
1870 return (adev->dma_mode == 0xFF ? 0 : 1);
1871}
1872
1873
1874
1875
1876extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
1877extern int ata_timing_compute(struct ata_device *, unsigned short,
1878 struct ata_timing *, int, int);
1879extern void ata_timing_merge(const struct ata_timing *,
1880 const struct ata_timing *, struct ata_timing *,
1881 unsigned int);
1882
1883
1884
1885
1886#ifdef CONFIG_SATA_PMP
1887
1888extern const struct ata_port_operations sata_pmp_port_ops;
1889
1890extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
1891extern void sata_pmp_error_handler(struct ata_port *ap);
1892
1893#else
1894
1895#define sata_pmp_port_ops sata_port_ops
1896#define sata_pmp_qc_defer_cmd_switch ata_std_qc_defer
1897#define sata_pmp_error_handler ata_std_error_handler
1898
1899#endif
1900
1901
1902
1903
1904
1905#ifdef CONFIG_ATA_SFF
1906
1907extern const struct ata_port_operations ata_sff_port_ops;
1908extern const struct ata_port_operations ata_bmdma32_port_ops;
1909
1910
1911#define ATA_PIO_SHT(drv_name) \
1912 ATA_BASE_SHT(drv_name), \
1913 .sg_tablesize = LIBATA_MAX_PRD, \
1914 .dma_boundary = ATA_DMA_BOUNDARY
1915
1916extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device);
1917extern u8 ata_sff_check_status(struct ata_port *ap);
1918extern void ata_sff_pause(struct ata_port *ap);
1919extern void ata_sff_dma_pause(struct ata_port *ap);
1920extern int ata_sff_busy_sleep(struct ata_port *ap,
1921 unsigned long timeout_pat, unsigned long timeout);
1922extern int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline);
1923extern void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
1924extern void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
1925extern void ata_sff_exec_command(struct ata_port *ap,
1926 const struct ata_taskfile *tf);
1927extern unsigned int ata_sff_data_xfer(struct ata_queued_cmd *qc,
1928 unsigned char *buf, unsigned int buflen, int rw);
1929extern unsigned int ata_sff_data_xfer32(struct ata_queued_cmd *qc,
1930 unsigned char *buf, unsigned int buflen, int rw);
1931extern void ata_sff_irq_on(struct ata_port *ap);
1932extern void ata_sff_irq_clear(struct ata_port *ap);
1933extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
1934 u8 status, int in_wq);
1935extern void ata_sff_queue_work(struct work_struct *work);
1936extern void ata_sff_queue_delayed_work(struct delayed_work *dwork,
1937 unsigned long delay);
1938extern void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay);
1939extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
1940extern bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
1941extern unsigned int ata_sff_port_intr(struct ata_port *ap,
1942 struct ata_queued_cmd *qc);
1943extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance);
1944extern void ata_sff_lost_interrupt(struct ata_port *ap);
1945extern void ata_sff_freeze(struct ata_port *ap);
1946extern void ata_sff_thaw(struct ata_port *ap);
1947extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline);
1948extern unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
1949 u8 *r_err);
1950extern int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
1951 unsigned long deadline);
1952extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
1953 unsigned long deadline);
1954extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
1955 unsigned long deadline);
1956extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
1957extern void ata_sff_drain_fifo(struct ata_queued_cmd *qc);
1958extern void ata_sff_error_handler(struct ata_port *ap);
1959extern void ata_sff_std_ports(struct ata_ioports *ioaddr);
1960#ifdef CONFIG_PCI
1961extern int ata_pci_sff_init_host(struct ata_host *host);
1962extern int ata_pci_sff_prepare_host(struct pci_dev *pdev,
1963 const struct ata_port_info * const * ppi,
1964 struct ata_host **r_host);
1965extern int ata_pci_sff_activate_host(struct ata_host *host,
1966 irq_handler_t irq_handler,
1967 struct scsi_host_template *sht);
1968extern int ata_pci_sff_init_one(struct pci_dev *pdev,
1969 const struct ata_port_info * const * ppi,
1970 struct scsi_host_template *sht, void *host_priv, int hflags);
1971#endif
1972
1973#ifdef CONFIG_ATA_BMDMA
1974
1975extern const struct ata_port_operations ata_bmdma_port_ops;
1976
1977#define ATA_BMDMA_SHT(drv_name) \
1978 ATA_BASE_SHT(drv_name), \
1979 .sg_tablesize = LIBATA_MAX_PRD, \
1980 .dma_boundary = ATA_DMA_BOUNDARY
1981
1982extern enum ata_completion_errors ata_bmdma_qc_prep(struct ata_queued_cmd *qc);
1983extern unsigned int ata_bmdma_qc_issue(struct ata_queued_cmd *qc);
1984extern enum ata_completion_errors ata_bmdma_dumb_qc_prep(struct ata_queued_cmd *qc);
1985extern unsigned int ata_bmdma_port_intr(struct ata_port *ap,
1986 struct ata_queued_cmd *qc);
1987extern irqreturn_t ata_bmdma_interrupt(int irq, void *dev_instance);
1988extern void ata_bmdma_error_handler(struct ata_port *ap);
1989extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
1990extern void ata_bmdma_irq_clear(struct ata_port *ap);
1991extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
1992extern void ata_bmdma_start(struct ata_queued_cmd *qc);
1993extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
1994extern u8 ata_bmdma_status(struct ata_port *ap);
1995extern int ata_bmdma_port_start(struct ata_port *ap);
1996extern int ata_bmdma_port_start32(struct ata_port *ap);
1997
1998#ifdef CONFIG_PCI
1999extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
2000extern void ata_pci_bmdma_init(struct ata_host *host);
2001extern int ata_pci_bmdma_prepare_host(struct pci_dev *pdev,
2002 const struct ata_port_info * const * ppi,
2003 struct ata_host **r_host);
2004extern int ata_pci_bmdma_init_one(struct pci_dev *pdev,
2005 const struct ata_port_info * const * ppi,
2006 struct scsi_host_template *sht,
2007 void *host_priv, int hflags);
2008#endif
2009#endif
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024static inline u8 ata_sff_busy_wait(struct ata_port *ap, unsigned int bits,
2025 unsigned int max)
2026{
2027 u8 status;
2028
2029 do {
2030 udelay(10);
2031 status = ap->ops->sff_check_status(ap);
2032 max--;
2033 } while (status != 0xff && (status & bits) && (max > 0));
2034
2035 return status;
2036}
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048static inline u8 ata_wait_idle(struct ata_port *ap)
2049{
2050 u8 status = ata_sff_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
2051
2052#ifdef ATA_DEBUG
2053 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
2054 ata_port_printk(ap, KERN_DEBUG, "abnormal Status 0x%X\n",
2055 status);
2056#endif
2057
2058 return status;
2059}
2060#endif
2061
2062#endif
2063