aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/libata.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/libata.h')
-rw-r--r--include/linux/libata.h320
1 files changed, 234 insertions, 86 deletions
diff --git a/include/linux/libata.h b/include/linux/libata.h
index a67bb9075e9b..229a9ff9f924 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -28,7 +28,6 @@
28 28
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/pci.h>
32#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
33#include <asm/scatterlist.h> 32#include <asm/scatterlist.h>
34#include <linux/io.h> 33#include <linux/io.h>
@@ -107,12 +106,6 @@ static inline u32 ata_msg_init(int dval, int default_msg_enable_bits)
107/* defines only for the constants which don't work well as enums */ 106/* defines only for the constants which don't work well as enums */
108#define ATA_TAG_POISON 0xfafbfcfdU 107#define ATA_TAG_POISON 0xfafbfcfdU
109 108
110/* move to PCI layer? */
111static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
112{
113 return &pdev->dev;
114}
115
116enum { 109enum {
117 /* various global constants */ 110 /* various global constants */
118 LIBATA_MAX_PRD = ATA_MAX_PRD / 2, 111 LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
@@ -139,11 +132,12 @@ enum {
139 ATA_DFLAG_FLUSH_EXT = (1 << 4), /* do FLUSH_EXT instead of FLUSH */ 132 ATA_DFLAG_FLUSH_EXT = (1 << 4), /* do FLUSH_EXT instead of FLUSH */
140 ATA_DFLAG_ACPI_PENDING = (1 << 5), /* ACPI resume action pending */ 133 ATA_DFLAG_ACPI_PENDING = (1 << 5), /* ACPI resume action pending */
141 ATA_DFLAG_ACPI_FAILED = (1 << 6), /* ACPI on devcfg has failed */ 134 ATA_DFLAG_ACPI_FAILED = (1 << 6), /* ACPI on devcfg has failed */
142 ATA_DFLAG_CFG_MASK = (1 << 8) - 1, 135 ATA_DFLAG_AN = (1 << 7), /* AN configured */
136 ATA_DFLAG_CFG_MASK = (1 << 12) - 1,
143 137
144 ATA_DFLAG_PIO = (1 << 8), /* device limited to PIO mode */ 138 ATA_DFLAG_PIO = (1 << 12), /* device limited to PIO mode */
145 ATA_DFLAG_NCQ_OFF = (1 << 9), /* device limited to non-NCQ mode */ 139 ATA_DFLAG_NCQ_OFF = (1 << 13), /* device limited to non-NCQ mode */
146 ATA_DFLAG_SPUNDOWN = (1 << 10), /* XXX: for spindown_compat */ 140 ATA_DFLAG_SPUNDOWN = (1 << 14), /* XXX: for spindown_compat */
147 ATA_DFLAG_INIT_MASK = (1 << 16) - 1, 141 ATA_DFLAG_INIT_MASK = (1 << 16) - 1,
148 142
149 ATA_DFLAG_DETACH = (1 << 16), 143 ATA_DFLAG_DETACH = (1 << 16),
@@ -154,7 +148,22 @@ enum {
154 ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */ 148 ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */
155 ATA_DEV_ATAPI = 3, /* ATAPI device */ 149 ATA_DEV_ATAPI = 3, /* ATAPI device */
156 ATA_DEV_ATAPI_UNSUP = 4, /* ATAPI device (unsupported) */ 150 ATA_DEV_ATAPI_UNSUP = 4, /* ATAPI device (unsupported) */
157 ATA_DEV_NONE = 5, /* no device */ 151 ATA_DEV_PMP = 5, /* SATA port multiplier */
152 ATA_DEV_PMP_UNSUP = 6, /* SATA port multiplier (unsupported) */
153 ATA_DEV_SEMB = 7, /* SEMB */
154 ATA_DEV_SEMB_UNSUP = 8, /* SEMB (unsupported) */
155 ATA_DEV_NONE = 9, /* no device */
156
157 /* struct ata_link flags */
158 ATA_LFLAG_HRST_TO_RESUME = (1 << 0), /* hardreset to resume link */
159 ATA_LFLAG_SKIP_D2H_BSY = (1 << 1), /* can't wait for the first D2H
160 * Register FIS clearing BSY */
161 ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
162 ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
163 ATA_LFLAG_ASSUME_SEMB = (1 << 4), /* assume SEMB class */
164 ATA_LFLAG_ASSUME_CLASS = ATA_LFLAG_ASSUME_ATA | ATA_LFLAG_ASSUME_SEMB,
165 ATA_LFLAG_NO_RETRY = (1 << 5), /* don't retry this link */
166 ATA_LFLAG_DISABLED = (1 << 6), /* link is disabled */
158 167
159 /* struct ata_port flags */ 168 /* struct ata_port flags */
160 ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */ 169 ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
@@ -170,13 +179,12 @@ enum {
170 ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD 179 ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD
171 * doesn't handle PIO interrupts */ 180 * doesn't handle PIO interrupts */
172 ATA_FLAG_NCQ = (1 << 10), /* host supports NCQ */ 181 ATA_FLAG_NCQ = (1 << 10), /* host supports NCQ */
173 ATA_FLAG_HRST_TO_RESUME = (1 << 11), /* hardreset to resume phy */
174 ATA_FLAG_SKIP_D2H_BSY = (1 << 12), /* can't wait for the first D2H
175 * Register FIS clearing BSY */
176 ATA_FLAG_DEBUGMSG = (1 << 13), 182 ATA_FLAG_DEBUGMSG = (1 << 13),
177 ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */ 183 ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */
178 ATA_FLAG_NO_IORDY = (1 << 16), /* controller lacks iordy */ 184 ATA_FLAG_NO_IORDY = (1 << 16), /* controller lacks iordy */
179 ATA_FLAG_ACPI_SATA = (1 << 17), /* need native SATA ACPI layout */ 185 ATA_FLAG_ACPI_SATA = (1 << 17), /* need native SATA ACPI layout */
186 ATA_FLAG_AN = (1 << 18), /* controller supports AN */
187 ATA_FLAG_PMP = (1 << 19), /* controller supports PMP */
180 188
181 /* The following flag belongs to ap->pflags but is kept in 189 /* The following flag belongs to ap->pflags but is kept in
182 * ap->flags because it's referenced in many LLDs and will be 190 * ap->flags because it's referenced in many LLDs and will be
@@ -195,6 +203,7 @@ enum {
195 ATA_PFLAG_UNLOADING = (1 << 5), /* module is unloading */ 203 ATA_PFLAG_UNLOADING = (1 << 5), /* module is unloading */
196 ATA_PFLAG_SCSI_HOTPLUG = (1 << 6), /* SCSI hotplug scheduled */ 204 ATA_PFLAG_SCSI_HOTPLUG = (1 << 6), /* SCSI hotplug scheduled */
197 ATA_PFLAG_INITIALIZING = (1 << 7), /* being initialized, don't touch */ 205 ATA_PFLAG_INITIALIZING = (1 << 7), /* being initialized, don't touch */
206 ATA_PFLAG_RESETTING = (1 << 8), /* reset in progress */
198 207
199 ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */ 208 ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */
200 ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */ 209 ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */
@@ -207,6 +216,7 @@ enum {
207 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE, 216 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE,
208 ATA_QCFLAG_IO = (1 << 3), /* standard IO command */ 217 ATA_QCFLAG_IO = (1 << 3), /* standard IO command */
209 ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */ 218 ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
219 ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */
210 220
211 ATA_QCFLAG_FAILED = (1 << 16), /* cmd failed and is owned by EH */ 221 ATA_QCFLAG_FAILED = (1 << 16), /* cmd failed and is owned by EH */
212 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */ 222 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
@@ -263,6 +273,10 @@ enum {
263 /* ering size */ 273 /* ering size */
264 ATA_ERING_SIZE = 32, 274 ATA_ERING_SIZE = 32,
265 275
276 /* return values for ->qc_defer */
277 ATA_DEFER_LINK = 1,
278 ATA_DEFER_PORT = 2,
279
266 /* desc_len for ata_eh_info and context */ 280 /* desc_len for ata_eh_info and context */
267 ATA_EH_DESC_LEN = 80, 281 ATA_EH_DESC_LEN = 80,
268 282
@@ -270,6 +284,7 @@ enum {
270 ATA_EH_REVALIDATE = (1 << 0), 284 ATA_EH_REVALIDATE = (1 << 0),
271 ATA_EH_SOFTRESET = (1 << 1), 285 ATA_EH_SOFTRESET = (1 << 1),
272 ATA_EH_HARDRESET = (1 << 2), 286 ATA_EH_HARDRESET = (1 << 2),
287 ATA_EH_ENABLE_LINK = (1 << 3),
273 288
274 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET, 289 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
275 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE, 290 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE,
@@ -289,12 +304,16 @@ enum {
289 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET, 304 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
290 ATA_EHI_RESET_MODIFIER_MASK = ATA_EHI_RESUME_LINK, 305 ATA_EHI_RESET_MODIFIER_MASK = ATA_EHI_RESUME_LINK,
291 306
292 /* max repeat if error condition is still set after ->error_handler */ 307 /* max tries if error condition is still set after ->error_handler */
293 ATA_EH_MAX_REPEAT = 5, 308 ATA_EH_MAX_TRIES = 5,
294 309
295 /* how hard are we gonna try to probe/recover devices */ 310 /* how hard are we gonna try to probe/recover devices */
296 ATA_PROBE_MAX_TRIES = 3, 311 ATA_PROBE_MAX_TRIES = 3,
297 ATA_EH_DEV_TRIES = 3, 312 ATA_EH_DEV_TRIES = 3,
313 ATA_EH_PMP_TRIES = 5,
314 ATA_EH_PMP_LINK_TRIES = 3,
315
316 SATA_PMP_SCR_TIMEOUT = 250,
298 317
299 /* Horkage types. May be set by libata or controller on drives 318 /* Horkage types. May be set by libata or controller on drives
300 (some horkage may be drive/controller pair dependant */ 319 (some horkage may be drive/controller pair dependant */
@@ -304,6 +323,14 @@ enum {
304 ATA_HORKAGE_NONCQ = (1 << 2), /* Don't use NCQ */ 323 ATA_HORKAGE_NONCQ = (1 << 2), /* Don't use NCQ */
305 ATA_HORKAGE_MAX_SEC_128 = (1 << 3), /* Limit max sects to 128 */ 324 ATA_HORKAGE_MAX_SEC_128 = (1 << 3), /* Limit max sects to 128 */
306 ATA_HORKAGE_BROKEN_HPA = (1 << 4), /* Broken HPA */ 325 ATA_HORKAGE_BROKEN_HPA = (1 << 4), /* Broken HPA */
326 ATA_HORKAGE_SKIP_PM = (1 << 5), /* Skip PM operations */
327 ATA_HORKAGE_HPA_SIZE = (1 << 6), /* native size off by one */
328
329 /* DMA mask for user DMA control: User visible values; DO NOT
330 renumber */
331 ATA_DMA_MASK_ATA = (1 << 0), /* DMA on ATA Disk */
332 ATA_DMA_MASK_ATAPI = (1 << 1), /* DMA on ATAPI */
333 ATA_DMA_MASK_CFA = (1 << 2), /* DMA on CF Card */
307}; 334};
308 335
309enum hsm_task_states { 336enum hsm_task_states {
@@ -333,14 +360,15 @@ enum ata_completion_errors {
333struct scsi_device; 360struct scsi_device;
334struct ata_port_operations; 361struct ata_port_operations;
335struct ata_port; 362struct ata_port;
363struct ata_link;
336struct ata_queued_cmd; 364struct ata_queued_cmd;
337 365
338/* typedefs */ 366/* typedefs */
339typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc); 367typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
340typedef int (*ata_prereset_fn_t)(struct ata_port *ap, unsigned long deadline); 368typedef int (*ata_prereset_fn_t)(struct ata_link *link, unsigned long deadline);
341typedef int (*ata_reset_fn_t)(struct ata_port *ap, unsigned int *classes, 369typedef int (*ata_reset_fn_t)(struct ata_link *link, unsigned int *classes,
342 unsigned long deadline); 370 unsigned long deadline);
343typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *classes); 371typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
344 372
345struct ata_ioports { 373struct ata_ioports {
346 void __iomem *cmd_addr; 374 void __iomem *cmd_addr;
@@ -363,8 +391,6 @@ struct ata_ioports {
363struct ata_host { 391struct ata_host {
364 spinlock_t lock; 392 spinlock_t lock;
365 struct device *dev; 393 struct device *dev;
366 unsigned long irq;
367 unsigned long irq2;
368 void __iomem * const *iomap; 394 void __iomem * const *iomap;
369 unsigned int n_ports; 395 unsigned int n_ports;
370 void *private_data; 396 void *private_data;
@@ -436,7 +462,7 @@ struct ata_ering {
436}; 462};
437 463
438struct ata_device { 464struct ata_device {
439 struct ata_port *ap; 465 struct ata_link *link;
440 unsigned int devno; /* 0 or 1 */ 466 unsigned int devno; /* 0 or 1 */
441 unsigned long flags; /* ATA_DFLAG_xxx */ 467 unsigned long flags; /* ATA_DFLAG_xxx */
442 unsigned int horkage; /* List of broken features */ 468 unsigned int horkage; /* List of broken features */
@@ -447,7 +473,12 @@ struct ata_device {
447 /* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ 473 /* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */
448 u64 n_sectors; /* size of device, if ATA */ 474 u64 n_sectors; /* size of device, if ATA */
449 unsigned int class; /* ATA_DEV_xxx */ 475 unsigned int class; /* ATA_DEV_xxx */
450 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */ 476
477 union {
478 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
479 u32 gscr[SATA_PMP_GSCR_DWORDS]; /* PMP GSCR block */
480 };
481
451 u8 pio_mode; 482 u8 pio_mode;
452 u8 dma_mode; 483 u8 dma_mode;
453 u8 xfer_mode; 484 u8 xfer_mode;
@@ -510,6 +541,27 @@ struct ata_acpi_gtm {
510 u32 flags; 541 u32 flags;
511} __packed; 542} __packed;
512 543
544struct ata_link {
545 struct ata_port *ap;
546 int pmp; /* port multiplier port # */
547
548 unsigned int active_tag; /* active tag on this link */
549 u32 sactive; /* active NCQ commands */
550
551 unsigned int flags; /* ATA_LFLAG_xxx */
552
553 unsigned int hw_sata_spd_limit;
554 unsigned int sata_spd_limit;
555 unsigned int sata_spd; /* current SATA PHY speed */
556
557 /* record runtime error info, protected by host_set lock */
558 struct ata_eh_info eh_info;
559 /* EH context */
560 struct ata_eh_context eh_context;
561
562 struct ata_device device[ATA_MAX_DEVICES];
563};
564
513struct ata_port { 565struct ata_port {
514 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */ 566 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
515 const struct ata_port_operations *ops; 567 const struct ata_port_operations *ops;
@@ -533,23 +585,17 @@ struct ata_port {
533 unsigned int mwdma_mask; 585 unsigned int mwdma_mask;
534 unsigned int udma_mask; 586 unsigned int udma_mask;
535 unsigned int cbl; /* cable type; ATA_CBL_xxx */ 587 unsigned int cbl; /* cable type; ATA_CBL_xxx */
536 unsigned int hw_sata_spd_limit;
537 unsigned int sata_spd_limit; /* SATA PHY speed limit */
538 unsigned int sata_spd; /* current SATA PHY speed */
539
540 /* record runtime error info, protected by host lock */
541 struct ata_eh_info eh_info;
542 /* EH context owned by EH */
543 struct ata_eh_context eh_context;
544
545 struct ata_device device[ATA_MAX_DEVICES];
546 588
547 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE]; 589 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE];
548 unsigned long qc_allocated; 590 unsigned long qc_allocated;
549 unsigned int qc_active; 591 unsigned int qc_active;
592 int nr_active_links; /* #links with active qcs */
593
594 struct ata_link link; /* host default link */
550 595
551 unsigned int active_tag; 596 int nr_pmp_links; /* nr of available PMP links */
552 u32 sactive; 597 struct ata_link *pmp_link; /* array of PMP links */
598 struct ata_link *excl_link; /* for PMP qc exclusion */
553 599
554 struct ata_port_stats stats; 600 struct ata_port_stats stats;
555 struct ata_host *host; 601 struct ata_host *host;
@@ -565,6 +611,7 @@ struct ata_port {
565 u32 msg_enable; 611 u32 msg_enable;
566 struct list_head eh_done_q; 612 struct list_head eh_done_q;
567 wait_queue_head_t eh_wait_q; 613 wait_queue_head_t eh_wait_q;
614 int eh_tries;
568 615
569 pm_message_t pm_mesg; 616 pm_message_t pm_mesg;
570 int *pm_result; 617 int *pm_result;
@@ -582,8 +629,6 @@ struct ata_port {
582}; 629};
583 630
584struct ata_port_operations { 631struct ata_port_operations {
585 void (*port_disable) (struct ata_port *);
586
587 void (*dev_config) (struct ata_device *); 632 void (*dev_config) (struct ata_device *);
588 633
589 void (*set_piomode) (struct ata_port *, struct ata_device *); 634 void (*set_piomode) (struct ata_port *, struct ata_device *);
@@ -599,7 +644,7 @@ struct ata_port_operations {
599 void (*dev_select)(struct ata_port *ap, unsigned int device); 644 void (*dev_select)(struct ata_port *ap, unsigned int device);
600 645
601 void (*phy_reset) (struct ata_port *ap); /* obsolete */ 646 void (*phy_reset) (struct ata_port *ap); /* obsolete */
602 int (*set_mode) (struct ata_port *ap, struct ata_device **r_failed_dev); 647 int (*set_mode) (struct ata_link *link, struct ata_device **r_failed_dev);
603 648
604 int (*cable_detect) (struct ata_port *ap); 649 int (*cable_detect) (struct ata_port *ap);
605 650
@@ -610,9 +655,14 @@ struct ata_port_operations {
610 655
611 void (*data_xfer) (struct ata_device *, unsigned char *, unsigned int, int); 656 void (*data_xfer) (struct ata_device *, unsigned char *, unsigned int, int);
612 657
658 int (*qc_defer) (struct ata_queued_cmd *qc);
613 void (*qc_prep) (struct ata_queued_cmd *qc); 659 void (*qc_prep) (struct ata_queued_cmd *qc);
614 unsigned int (*qc_issue) (struct ata_queued_cmd *qc); 660 unsigned int (*qc_issue) (struct ata_queued_cmd *qc);
615 661
662 /* port multiplier */
663 void (*pmp_attach) (struct ata_port *ap);
664 void (*pmp_detach) (struct ata_port *ap);
665
616 /* Error handlers. ->error_handler overrides ->eng_timeout and 666 /* Error handlers. ->error_handler overrides ->eng_timeout and
617 * indicates that new-style EH is in place. 667 * indicates that new-style EH is in place.
618 */ 668 */
@@ -626,7 +676,6 @@ struct ata_port_operations {
626 irq_handler_t irq_handler; 676 irq_handler_t irq_handler;
627 void (*irq_clear) (struct ata_port *); 677 void (*irq_clear) (struct ata_port *);
628 u8 (*irq_on) (struct ata_port *); 678 u8 (*irq_on) (struct ata_port *);
629 u8 (*irq_ack) (struct ata_port *ap, unsigned int chk_drq);
630 679
631 int (*scr_read) (struct ata_port *ap, unsigned int sc_reg, u32 *val); 680 int (*scr_read) (struct ata_port *ap, unsigned int sc_reg, u32 *val);
632 int (*scr_write) (struct ata_port *ap, unsigned int sc_reg, u32 val); 681 int (*scr_write) (struct ata_port *ap, unsigned int sc_reg, u32 val);
@@ -646,6 +695,7 @@ struct ata_port_operations {
646struct ata_port_info { 695struct ata_port_info {
647 struct scsi_host_template *sht; 696 struct scsi_host_template *sht;
648 unsigned long flags; 697 unsigned long flags;
698 unsigned long link_flags;
649 unsigned long pio_mask; 699 unsigned long pio_mask;
650 unsigned long mwdma_mask; 700 unsigned long mwdma_mask;
651 unsigned long udma_mask; 701 unsigned long udma_mask;
@@ -689,38 +739,27 @@ static inline int ata_port_is_dummy(struct ata_port *ap)
689 return ap->ops == &ata_dummy_port_ops; 739 return ap->ops == &ata_dummy_port_ops;
690} 740}
691 741
692extern void sata_print_link_status(struct ata_port *ap); 742extern void sata_print_link_status(struct ata_link *link);
693extern void ata_port_probe(struct ata_port *); 743extern void ata_port_probe(struct ata_port *);
694extern void __sata_phy_reset(struct ata_port *ap); 744extern void __sata_phy_reset(struct ata_port *ap);
695extern void sata_phy_reset(struct ata_port *ap); 745extern void sata_phy_reset(struct ata_port *ap);
696extern void ata_bus_reset(struct ata_port *ap); 746extern void ata_bus_reset(struct ata_port *ap);
697extern int sata_set_spd(struct ata_port *ap); 747extern int sata_set_spd(struct ata_link *link);
698extern int sata_phy_debounce(struct ata_port *ap, const unsigned long *param, 748extern int sata_link_debounce(struct ata_link *link,
699 unsigned long deadline); 749 const unsigned long *params, unsigned long deadline);
700extern int sata_phy_resume(struct ata_port *ap, const unsigned long *param, 750extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
701 unsigned long deadline); 751 unsigned long deadline);
702extern int ata_std_prereset(struct ata_port *ap, unsigned long deadline); 752extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
703extern int ata_std_softreset(struct ata_port *ap, unsigned int *classes, 753extern int ata_std_softreset(struct ata_link *link, unsigned int *classes,
704 unsigned long deadline); 754 unsigned long deadline);
705extern int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing, 755extern int sata_link_hardreset(struct ata_link *link,
706 unsigned long deadline); 756 const unsigned long *timing, unsigned long deadline);
707extern int sata_std_hardreset(struct ata_port *ap, unsigned int *class, 757extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
708 unsigned long deadline); 758 unsigned long deadline);
709extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes); 759extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
710extern void ata_port_disable(struct ata_port *); 760extern void ata_port_disable(struct ata_port *);
711extern void ata_std_ports(struct ata_ioports *ioaddr); 761extern void ata_std_ports(struct ata_ioports *ioaddr);
712#ifdef CONFIG_PCI 762
713extern int ata_pci_init_one (struct pci_dev *pdev,
714 const struct ata_port_info * const * ppi);
715extern void ata_pci_remove_one (struct pci_dev *pdev);
716#ifdef CONFIG_PM
717extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
718extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
719extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
720extern int ata_pci_device_resume(struct pci_dev *pdev);
721#endif
722extern int ata_pci_clear_simplex(struct pci_dev *pdev);
723#endif /* CONFIG_PCI */
724extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports); 763extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
725extern struct ata_host *ata_host_alloc_pinfo(struct device *dev, 764extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
726 const struct ata_port_info * const * ppi, int n_ports); 765 const struct ata_port_info * const * ppi, int n_ports);
@@ -746,12 +785,12 @@ extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
746extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), 785extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
747 struct ata_port *ap); 786 struct ata_port *ap);
748extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 787extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
749extern int sata_scr_valid(struct ata_port *ap); 788extern int sata_scr_valid(struct ata_link *link);
750extern int sata_scr_read(struct ata_port *ap, int reg, u32 *val); 789extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
751extern int sata_scr_write(struct ata_port *ap, int reg, u32 val); 790extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
752extern int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val); 791extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
753extern int ata_port_online(struct ata_port *ap); 792extern int ata_link_online(struct ata_link *link);
754extern int ata_port_offline(struct ata_port *ap); 793extern int ata_link_offline(struct ata_link *link);
755#ifdef CONFIG_PM 794#ifdef CONFIG_PM
756extern int ata_host_suspend(struct ata_host *host, pm_message_t mesg); 795extern int ata_host_suspend(struct ata_host *host, pm_message_t mesg);
757extern void ata_host_resume(struct ata_host *host); 796extern void ata_host_resume(struct ata_host *host);
@@ -765,7 +804,8 @@ extern void ata_port_queue_task(struct ata_port *ap, work_func_t fn,
765extern u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, 804extern u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
766 unsigned long interval_msec, 805 unsigned long interval_msec,
767 unsigned long timeout_msec); 806 unsigned long timeout_msec);
768extern unsigned int ata_dev_try_classify(struct ata_port *, unsigned int, u8 *); 807extern unsigned int ata_dev_try_classify(struct ata_device *dev, int present,
808 u8 *r_err);
769 809
770/* 810/*
771 * Default driver ops implementations 811 * Default driver ops implementations
@@ -787,6 +827,7 @@ extern void ata_data_xfer(struct ata_device *adev, unsigned char *buf,
787 unsigned int buflen, int write_data); 827 unsigned int buflen, int write_data);
788extern void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf, 828extern void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
789 unsigned int buflen, int write_data); 829 unsigned int buflen, int write_data);
830extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
790extern void ata_dumb_qc_prep(struct ata_queued_cmd *qc); 831extern void ata_dumb_qc_prep(struct ata_queued_cmd *qc);
791extern void ata_qc_prep(struct ata_queued_cmd *qc); 832extern void ata_qc_prep(struct ata_queued_cmd *qc);
792extern void ata_noop_qc_prep(struct ata_queued_cmd *qc); 833extern void ata_noop_qc_prep(struct ata_queued_cmd *qc);
@@ -830,11 +871,8 @@ extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
830extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, 871extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
831 int queue_depth); 872 int queue_depth);
832extern struct ata_device *ata_dev_pair(struct ata_device *adev); 873extern struct ata_device *ata_dev_pair(struct ata_device *adev);
833extern int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev); 874extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
834extern u8 ata_irq_on(struct ata_port *ap); 875extern u8 ata_irq_on(struct ata_port *ap);
835extern u8 ata_dummy_irq_on(struct ata_port *ap);
836extern u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq);
837extern u8 ata_dummy_irq_ack(struct ata_port *ap, unsigned int chk_drq);
838 876
839extern int ata_cable_40wire(struct ata_port *ap); 877extern int ata_cable_40wire(struct ata_port *ap);
840extern int ata_cable_80wire(struct ata_port *ap); 878extern int ata_cable_80wire(struct ata_port *ap);
@@ -869,8 +907,29 @@ enum {
869 ATA_TIMING_CYCLE | ATA_TIMING_UDMA, 907 ATA_TIMING_CYCLE | ATA_TIMING_UDMA,
870}; 908};
871 909
910/* libata-acpi.c */
911#ifdef CONFIG_ATA_ACPI
912extern int ata_acpi_cbl_80wire(struct ata_port *ap);
913int ata_acpi_stm(const struct ata_port *ap, struct ata_acpi_gtm *stm);
914int ata_acpi_gtm(const struct ata_port *ap, struct ata_acpi_gtm *stm);
915#else
916static inline int ata_acpi_cbl_80wire(struct ata_port *ap) { return 0; }
917#endif
872 918
873#ifdef CONFIG_PCI 919#ifdef CONFIG_PCI
920struct pci_dev;
921
922extern int ata_pci_init_one (struct pci_dev *pdev,
923 const struct ata_port_info * const * ppi);
924extern void ata_pci_remove_one (struct pci_dev *pdev);
925#ifdef CONFIG_PM
926extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
927extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
928extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
929extern int ata_pci_device_resume(struct pci_dev *pdev);
930#endif
931extern int ata_pci_clear_simplex(struct pci_dev *pdev);
932
874struct pci_bits { 933struct pci_bits {
875 unsigned int reg; /* PCI config register to read */ 934 unsigned int reg; /* PCI config register to read */
876 unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */ 935 unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */
@@ -888,13 +947,29 @@ extern unsigned long ata_pci_default_filter(struct ata_device *, unsigned long);
888#endif /* CONFIG_PCI */ 947#endif /* CONFIG_PCI */
889 948
890/* 949/*
950 * PMP
951 */
952extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
953extern int sata_pmp_std_prereset(struct ata_link *link, unsigned long deadline);
954extern int sata_pmp_std_hardreset(struct ata_link *link, unsigned int *class,
955 unsigned long deadline);
956extern void sata_pmp_std_postreset(struct ata_link *link, unsigned int *class);
957extern void sata_pmp_do_eh(struct ata_port *ap,
958 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
959 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset,
960 ata_prereset_fn_t pmp_prereset, ata_reset_fn_t pmp_softreset,
961 ata_reset_fn_t pmp_hardreset, ata_postreset_fn_t pmp_postreset);
962
963/*
891 * EH 964 * EH
892 */ 965 */
893extern void ata_eng_timeout(struct ata_port *ap); 966extern void ata_eng_timeout(struct ata_port *ap);
894 967
895extern void ata_port_schedule_eh(struct ata_port *ap); 968extern void ata_port_schedule_eh(struct ata_port *ap);
969extern int ata_link_abort(struct ata_link *link);
896extern int ata_port_abort(struct ata_port *ap); 970extern int ata_port_abort(struct ata_port *ap);
897extern int ata_port_freeze(struct ata_port *ap); 971extern int ata_port_freeze(struct ata_port *ap);
972extern int sata_async_notification(struct ata_port *ap);
898 973
899extern void ata_eh_freeze_port(struct ata_port *ap); 974extern void ata_eh_freeze_port(struct ata_port *ap);
900extern void ata_eh_thaw_port(struct ata_port *ap); 975extern void ata_eh_thaw_port(struct ata_port *ap);
@@ -912,14 +987,25 @@ extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
912#define ata_port_printk(ap, lv, fmt, args...) \ 987#define ata_port_printk(ap, lv, fmt, args...) \
913 printk(lv"ata%u: "fmt, (ap)->print_id , ##args) 988 printk(lv"ata%u: "fmt, (ap)->print_id , ##args)
914 989
990#define ata_link_printk(link, lv, fmt, args...) do { \
991 if ((link)->ap->nr_pmp_links) \
992 printk(lv"ata%u.%02u: "fmt, (link)->ap->print_id, \
993 (link)->pmp , ##args); \
994 else \
995 printk(lv"ata%u: "fmt, (link)->ap->print_id , ##args); \
996 } while(0)
997
915#define ata_dev_printk(dev, lv, fmt, args...) \ 998#define ata_dev_printk(dev, lv, fmt, args...) \
916 printk(lv"ata%u.%02u: "fmt, (dev)->ap->print_id, (dev)->devno , ##args) 999 printk(lv"ata%u.%02u: "fmt, (dev)->link->ap->print_id, \
1000 (dev)->link->pmp + (dev)->devno , ##args)
917 1001
918/* 1002/*
919 * ata_eh_info helpers 1003 * ata_eh_info helpers
920 */ 1004 */
921extern void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...); 1005extern void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
922extern void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...); 1006 __attribute__ ((format (printf, 2, 3)));
1007extern void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
1008 __attribute__ ((format (printf, 2, 3)));
923extern void ata_ehi_clear_desc(struct ata_eh_info *ehi); 1009extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
924 1010
925static inline void ata_ehi_schedule_probe(struct ata_eh_info *ehi) 1011static inline void ata_ehi_schedule_probe(struct ata_eh_info *ehi)
@@ -933,10 +1019,21 @@ static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
933{ 1019{
934 ata_ehi_schedule_probe(ehi); 1020 ata_ehi_schedule_probe(ehi);
935 ehi->flags |= ATA_EHI_HOTPLUGGED; 1021 ehi->flags |= ATA_EHI_HOTPLUGGED;
1022 ehi->action |= ATA_EH_ENABLE_LINK;
936 ehi->err_mask |= AC_ERR_ATA_BUS; 1023 ehi->err_mask |= AC_ERR_ATA_BUS;
937} 1024}
938 1025
939/* 1026/*
1027 * port description helpers
1028 */
1029extern void ata_port_desc(struct ata_port *ap, const char *fmt, ...)
1030 __attribute__ ((format (printf, 2, 3)));
1031#ifdef CONFIG_PCI
1032extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
1033 const char *name);
1034#endif
1035
1036/*
940 * qc helpers 1037 * qc helpers
941 */ 1038 */
942static inline int 1039static inline int
@@ -991,12 +1088,14 @@ static inline unsigned int ata_tag_internal(unsigned int tag)
991 */ 1088 */
992static inline unsigned int ata_class_enabled(unsigned int class) 1089static inline unsigned int ata_class_enabled(unsigned int class)
993{ 1090{
994 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI; 1091 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI ||
1092 class == ATA_DEV_PMP || class == ATA_DEV_SEMB;
995} 1093}
996 1094
997static inline unsigned int ata_class_disabled(unsigned int class) 1095static inline unsigned int ata_class_disabled(unsigned int class)
998{ 1096{
999 return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP; 1097 return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP ||
1098 class == ATA_DEV_PMP_UNSUP || class == ATA_DEV_SEMB_UNSUP;
1000} 1099}
1001 1100
1002static inline unsigned int ata_class_absent(unsigned int class) 1101static inline unsigned int ata_class_absent(unsigned int class)
@@ -1020,15 +1119,62 @@ static inline unsigned int ata_dev_absent(const struct ata_device *dev)
1020} 1119}
1021 1120
1022/* 1121/*
1023 * port helpers 1122 * link helpers
1024 */ 1123 */
1025static inline int ata_port_max_devices(const struct ata_port *ap) 1124static inline int ata_is_host_link(const struct ata_link *link)
1125{
1126 return link == &link->ap->link;
1127}
1128
1129static inline int ata_link_max_devices(const struct ata_link *link)
1026{ 1130{
1027 if (ap->flags & ATA_FLAG_SLAVE_POSS) 1131 if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS)
1028 return 2; 1132 return 2;
1029 return 1; 1133 return 1;
1030} 1134}
1031 1135
1136static inline int ata_link_active(struct ata_link *link)
1137{
1138 return ata_tag_valid(link->active_tag) || link->sactive;
1139}
1140
1141static inline struct ata_link *ata_port_first_link(struct ata_port *ap)
1142{
1143 if (ap->nr_pmp_links)
1144 return ap->pmp_link;
1145 return &ap->link;
1146}
1147
1148static inline struct ata_link *ata_port_next_link(struct ata_link *link)
1149{
1150 struct ata_port *ap = link->ap;
1151
1152 if (link == &ap->link) {
1153 if (!ap->nr_pmp_links)
1154 return NULL;
1155 return ap->pmp_link;
1156 }
1157
1158 if (++link - ap->pmp_link < ap->nr_pmp_links)
1159 return link;
1160 return NULL;
1161}
1162
1163#define __ata_port_for_each_link(lk, ap) \
1164 for ((lk) = &(ap)->link; (lk); (lk) = ata_port_next_link(lk))
1165
1166#define ata_port_for_each_link(link, ap) \
1167 for ((link) = ata_port_first_link(ap); (link); \
1168 (link) = ata_port_next_link(link))
1169
1170#define ata_link_for_each_dev(dev, link) \
1171 for ((dev) = (link)->device; \
1172 (dev) < (link)->device + ata_link_max_devices(link) || ((dev) = NULL); \
1173 (dev)++)
1174
1175#define ata_link_for_each_dev_reverse(dev, link) \
1176 for ((dev) = (link)->device + ata_link_max_devices(link) - 1; \
1177 (dev) >= (link)->device || ((dev) = NULL); (dev)--)
1032 1178
1033static inline u8 ata_chk_status(struct ata_port *ap) 1179static inline u8 ata_chk_status(struct ata_port *ap)
1034{ 1180{
@@ -1110,9 +1256,11 @@ static inline u8 ata_wait_idle(struct ata_port *ap)
1110{ 1256{
1111 u8 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000); 1257 u8 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
1112 1258
1259#ifdef ATA_DEBUG
1113 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ))) 1260 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
1114 DPRINTK("ATA: abnormal status 0x%X on port 0x%p\n", 1261 ata_port_printk(ap, KERN_DEBUG, "abnormal Status 0x%X\n",
1115 status, ap->ioaddr.status_addr); 1262 status);
1263#endif
1116 1264
1117 return status; 1265 return status;
1118} 1266}
@@ -1149,7 +1297,7 @@ static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
1149{ 1297{
1150 memset(tf, 0, sizeof(*tf)); 1298 memset(tf, 0, sizeof(*tf));
1151 1299
1152 tf->ctl = dev->ap->ctl; 1300 tf->ctl = dev->link->ap->ctl;
1153 if (dev->devno == 0) 1301 if (dev->devno == 0)
1154 tf->device = ATA_DEVICE_OBS; 1302 tf->device = ATA_DEVICE_OBS;
1155 else 1303 else