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.h733
1 files changed, 439 insertions, 294 deletions
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 37ee881c42ac..d1dfe872ee30 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -122,6 +122,8 @@ enum {
122 122
123 ATAPI_MAX_DRAIN = 16 << 10, 123 ATAPI_MAX_DRAIN = 16 << 10,
124 124
125 ATA_ALL_DEVICES = (1 << ATA_MAX_DEVICES) - 1,
126
125 ATA_SHT_EMULATED = 1, 127 ATA_SHT_EMULATED = 1,
126 ATA_SHT_CMD_PER_LUN = 1, 128 ATA_SHT_CMD_PER_LUN = 1,
127 ATA_SHT_THIS_ID = -1, 129 ATA_SHT_THIS_ID = -1,
@@ -163,9 +165,6 @@ enum {
163 ATA_DEV_NONE = 9, /* no device */ 165 ATA_DEV_NONE = 9, /* no device */
164 166
165 /* struct ata_link flags */ 167 /* struct ata_link flags */
166 ATA_LFLAG_HRST_TO_RESUME = (1 << 0), /* hardreset to resume link */
167 ATA_LFLAG_SKIP_D2H_BSY = (1 << 1), /* can't wait for the first D2H
168 * Register FIS clearing BSY */
169 ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */ 168 ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
170 ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */ 169 ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
171 ATA_LFLAG_ASSUME_SEMB = (1 << 4), /* assume SEMB class */ 170 ATA_LFLAG_ASSUME_SEMB = (1 << 4), /* assume SEMB class */
@@ -225,6 +224,7 @@ enum {
225 ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */ 224 ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
226 ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */ 225 ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */
227 ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */ 226 ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */
227 ATA_QCFLAG_RETRY = (1 << 7), /* retry after failure */
228 228
229 ATA_QCFLAG_FAILED = (1 << 16), /* cmd failed and is owned by EH */ 229 ATA_QCFLAG_FAILED = (1 << 16), /* cmd failed and is owned by EH */
230 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */ 230 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
@@ -249,6 +249,25 @@ enum {
249 */ 249 */
250 ATA_TMOUT_FF_WAIT = 4 * HZ / 5, 250 ATA_TMOUT_FF_WAIT = 4 * HZ / 5,
251 251
252 /* Spec mandates to wait for ">= 2ms" before checking status
253 * after reset. We wait 150ms, because that was the magic
254 * delay used for ATAPI devices in Hale Landis's ATADRVR, for
255 * the period of time between when the ATA command register is
256 * written, and then status is checked. Because waiting for
257 * "a while" before checking status is fine, post SRST, we
258 * perform this magic delay here as well.
259 *
260 * Old drivers/ide uses the 2mS rule and then waits for ready.
261 */
262 ATA_WAIT_AFTER_RESET_MSECS = 150,
263
264 /* If PMP is supported, we have to do follow-up SRST. As some
265 * PMPs don't send D2H Reg FIS after hardreset, LLDs are
266 * advised to wait only for the following duration before
267 * doing SRST.
268 */
269 ATA_TMOUT_PMP_SRST_WAIT = 1 * HZ,
270
252 /* ATA bus states */ 271 /* ATA bus states */
253 BUS_UNKNOWN = 0, 272 BUS_UNKNOWN = 0,
254 BUS_DMA = 1, 273 BUS_DMA = 1,
@@ -292,17 +311,16 @@ enum {
292 311
293 /* reset / recovery action types */ 312 /* reset / recovery action types */
294 ATA_EH_REVALIDATE = (1 << 0), 313 ATA_EH_REVALIDATE = (1 << 0),
295 ATA_EH_SOFTRESET = (1 << 1), 314 ATA_EH_SOFTRESET = (1 << 1), /* meaningful only in ->prereset */
296 ATA_EH_HARDRESET = (1 << 2), 315 ATA_EH_HARDRESET = (1 << 2), /* meaningful only in ->prereset */
316 ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
297 ATA_EH_ENABLE_LINK = (1 << 3), 317 ATA_EH_ENABLE_LINK = (1 << 3),
298 ATA_EH_LPM = (1 << 4), /* link power management action */ 318 ATA_EH_LPM = (1 << 4), /* link power management action */
299 319
300 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
301 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE, 320 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE,
302 321
303 /* ata_eh_info->flags */ 322 /* ata_eh_info->flags */
304 ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */ 323 ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
305 ATA_EHI_RESUME_LINK = (1 << 1), /* resume link (reset modifier) */
306 ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */ 324 ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */
307 ATA_EHI_QUIET = (1 << 3), /* be quiet */ 325 ATA_EHI_QUIET = (1 << 3), /* be quiet */
308 326
@@ -313,7 +331,6 @@ enum {
313 ATA_EHI_POST_SETMODE = (1 << 20), /* revaildating after setmode */ 331 ATA_EHI_POST_SETMODE = (1 << 20), /* revaildating after setmode */
314 332
315 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET, 333 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
316 ATA_EHI_RESET_MODIFIER_MASK = ATA_EHI_RESUME_LINK,
317 334
318 /* max tries if error condition is still set after ->error_handler */ 335 /* max tries if error condition is still set after ->error_handler */
319 ATA_EH_MAX_TRIES = 5, 336 ATA_EH_MAX_TRIES = 5,
@@ -352,6 +369,22 @@ enum {
352 ATAPI_READ_CD = 2, /* READ CD [MSF] */ 369 ATAPI_READ_CD = 2, /* READ CD [MSF] */
353 ATAPI_PASS_THRU = 3, /* SAT pass-thru */ 370 ATAPI_PASS_THRU = 3, /* SAT pass-thru */
354 ATAPI_MISC = 4, /* the rest */ 371 ATAPI_MISC = 4, /* the rest */
372
373 /* Timing constants */
374 ATA_TIMING_SETUP = (1 << 0),
375 ATA_TIMING_ACT8B = (1 << 1),
376 ATA_TIMING_REC8B = (1 << 2),
377 ATA_TIMING_CYC8B = (1 << 3),
378 ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B |
379 ATA_TIMING_CYC8B,
380 ATA_TIMING_ACTIVE = (1 << 4),
381 ATA_TIMING_RECOVER = (1 << 5),
382 ATA_TIMING_CYCLE = (1 << 6),
383 ATA_TIMING_UDMA = (1 << 7),
384 ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
385 ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
386 ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
387 ATA_TIMING_CYCLE | ATA_TIMING_UDMA,
355}; 388};
356 389
357enum ata_xfer_mask { 390enum ata_xfer_mask {
@@ -410,8 +443,9 @@ enum link_pm {
410 MAX_PERFORMANCE, 443 MAX_PERFORMANCE,
411 MEDIUM_POWER, 444 MEDIUM_POWER,
412}; 445};
413extern struct class_device_attribute class_device_attr_link_power_management_policy; 446extern struct device_attribute dev_attr_link_power_management_policy;
414 447
448#ifdef CONFIG_ATA_SFF
415struct ata_ioports { 449struct ata_ioports {
416 void __iomem *cmd_addr; 450 void __iomem *cmd_addr;
417 void __iomem *data_addr; 451 void __iomem *data_addr;
@@ -429,6 +463,7 @@ struct ata_ioports {
429 void __iomem *bmdma_addr; 463 void __iomem *bmdma_addr;
430 void __iomem *scr_addr; 464 void __iomem *scr_addr;
431}; 465};
466#endif /* CONFIG_ATA_SFF */
432 467
433struct ata_host { 468struct ata_host {
434 spinlock_t lock; 469 spinlock_t lock;
@@ -436,7 +471,7 @@ struct ata_host {
436 void __iomem * const *iomap; 471 void __iomem * const *iomap;
437 unsigned int n_ports; 472 unsigned int n_ports;
438 void *private_data; 473 void *private_data;
439 const struct ata_port_operations *ops; 474 struct ata_port_operations *ops;
440 unsigned long flags; 475 unsigned long flags;
441#ifdef CONFIG_ATA_ACPI 476#ifdef CONFIG_ATA_ACPI
442 acpi_handle acpi_handle; 477 acpi_handle acpi_handle;
@@ -513,11 +548,6 @@ struct ata_device {
513 u64 n_sectors; /* size of device, if ATA */ 548 u64 n_sectors; /* size of device, if ATA */
514 unsigned int class; /* ATA_DEV_xxx */ 549 unsigned int class; /* ATA_DEV_xxx */
515 550
516 union {
517 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
518 u32 gscr[SATA_PMP_GSCR_DWORDS]; /* PMP GSCR block */
519 };
520
521 u8 pio_mode; 551 u8 pio_mode;
522 u8 dma_mode; 552 u8 dma_mode;
523 u8 xfer_mode; 553 u8 xfer_mode;
@@ -539,8 +569,13 @@ struct ata_device {
539 u16 sectors; /* Number of sectors per track */ 569 u16 sectors; /* Number of sectors per track */
540 570
541 /* error history */ 571 /* error history */
542 struct ata_ering ering;
543 int spdn_cnt; 572 int spdn_cnt;
573 struct ata_ering ering;
574
575 union {
576 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
577 u32 gscr[SATA_PMP_GSCR_DWORDS]; /* PMP GSCR block */
578 };
544}; 579};
545 580
546/* Offset into struct ata_device. Fields above it are maintained 581/* Offset into struct ata_device. Fields above it are maintained
@@ -605,7 +640,7 @@ struct ata_link {
605 640
606struct ata_port { 641struct ata_port {
607 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */ 642 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
608 const struct ata_port_operations *ops; 643 struct ata_port_operations *ops;
609 spinlock_t *lock; 644 spinlock_t *lock;
610 unsigned long flags; /* ATA_FLAG_xxx */ 645 unsigned long flags; /* ATA_FLAG_xxx */
611 unsigned int pflags; /* ATA_PFLAG_xxx */ 646 unsigned int pflags; /* ATA_PFLAG_xxx */
@@ -615,7 +650,9 @@ struct ata_port {
615 struct ata_prd *prd; /* our SG list */ 650 struct ata_prd *prd; /* our SG list */
616 dma_addr_t prd_dma; /* and its DMA mapping */ 651 dma_addr_t prd_dma; /* and its DMA mapping */
617 652
653#ifdef CONFIG_ATA_SFF
618 struct ata_ioports ioaddr; /* ATA cmd/ctl/dma register blocks */ 654 struct ata_ioports ioaddr; /* ATA cmd/ctl/dma register blocks */
655#endif /* CONFIG_ATA_SFF */
619 656
620 u8 ctl; /* cache of ATA control register */ 657 u8 ctl; /* cache of ATA control register */
621 u8 last_ctl; /* Cache last written value */ 658 u8 last_ctl; /* Cache last written value */
@@ -667,81 +704,108 @@ struct ata_port {
667 u8 sector_buf[ATA_SECT_SIZE]; /* owned by EH */ 704 u8 sector_buf[ATA_SECT_SIZE]; /* owned by EH */
668}; 705};
669 706
670struct ata_port_operations { 707/* The following initializer overrides a method to NULL whether one of
671 void (*dev_config) (struct ata_device *); 708 * its parent has the method defined or not. This is equivalent to
672 709 * ERR_PTR(-ENOENT). Unfortunately, ERR_PTR doesn't render a constant
673 void (*set_piomode) (struct ata_port *, struct ata_device *); 710 * expression and thus can't be used as an initializer.
674 void (*set_dmamode) (struct ata_port *, struct ata_device *); 711 */
675 unsigned long (*mode_filter) (struct ata_device *, unsigned long); 712#define ATA_OP_NULL (void *)(unsigned long)(-ENOENT)
676
677 void (*tf_load) (struct ata_port *ap, const struct ata_taskfile *tf);
678 void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
679
680 void (*exec_command)(struct ata_port *ap, const struct ata_taskfile *tf);
681 u8 (*check_status)(struct ata_port *ap);
682 u8 (*check_altstatus)(struct ata_port *ap);
683 void (*dev_select)(struct ata_port *ap, unsigned int device);
684
685 void (*phy_reset) (struct ata_port *ap); /* obsolete */
686 int (*set_mode) (struct ata_link *link, struct ata_device **r_failed_dev);
687
688 int (*cable_detect) (struct ata_port *ap);
689
690 int (*check_atapi_dma) (struct ata_queued_cmd *qc);
691
692 void (*bmdma_setup) (struct ata_queued_cmd *qc);
693 void (*bmdma_start) (struct ata_queued_cmd *qc);
694
695 unsigned int (*data_xfer) (struct ata_device *dev, unsigned char *buf,
696 unsigned int buflen, int rw);
697
698 int (*qc_defer) (struct ata_queued_cmd *qc);
699 void (*qc_prep) (struct ata_queued_cmd *qc);
700 unsigned int (*qc_issue) (struct ata_queued_cmd *qc);
701
702 /* port multiplier */
703 void (*pmp_attach) (struct ata_port *ap);
704 void (*pmp_detach) (struct ata_port *ap);
705 713
706 /* Error handlers. ->error_handler overrides ->eng_timeout and 714struct ata_port_operations {
707 * indicates that new-style EH is in place. 715 /*
716 * Command execution
708 */ 717 */
709 void (*eng_timeout) (struct ata_port *ap); /* obsolete */ 718 int (*qc_defer)(struct ata_queued_cmd *qc);
710 719 int (*check_atapi_dma)(struct ata_queued_cmd *qc);
711 void (*freeze) (struct ata_port *ap); 720 void (*qc_prep)(struct ata_queued_cmd *qc);
712 void (*thaw) (struct ata_port *ap); 721 unsigned int (*qc_issue)(struct ata_queued_cmd *qc);
713 void (*error_handler) (struct ata_port *ap); 722 bool (*qc_fill_rtf)(struct ata_queued_cmd *qc);
714 void (*post_internal_cmd) (struct ata_queued_cmd *qc); 723
715 724 /*
716 irq_handler_t irq_handler; 725 * Configuration and exception handling
717 void (*irq_clear) (struct ata_port *); 726 */
718 u8 (*irq_on) (struct ata_port *); 727 int (*cable_detect)(struct ata_port *ap);
719 728 unsigned long (*mode_filter)(struct ata_device *dev, unsigned long xfer_mask);
720 int (*scr_read) (struct ata_port *ap, unsigned int sc_reg, u32 *val); 729 void (*set_piomode)(struct ata_port *ap, struct ata_device *dev);
721 int (*scr_write) (struct ata_port *ap, unsigned int sc_reg, u32 val); 730 void (*set_dmamode)(struct ata_port *ap, struct ata_device *dev);
731 int (*set_mode)(struct ata_link *link, struct ata_device **r_failed_dev);
732
733 void (*dev_config)(struct ata_device *dev);
734
735 void (*freeze)(struct ata_port *ap);
736 void (*thaw)(struct ata_port *ap);
737 ata_prereset_fn_t prereset;
738 ata_reset_fn_t softreset;
739 ata_reset_fn_t hardreset;
740 ata_postreset_fn_t postreset;
741 ata_prereset_fn_t pmp_prereset;
742 ata_reset_fn_t pmp_softreset;
743 ata_reset_fn_t pmp_hardreset;
744 ata_postreset_fn_t pmp_postreset;
745 void (*error_handler)(struct ata_port *ap);
746 void (*post_internal_cmd)(struct ata_queued_cmd *qc);
747
748 /*
749 * Optional features
750 */
751 int (*scr_read)(struct ata_port *ap, unsigned int sc_reg, u32 *val);
752 int (*scr_write)(struct ata_port *ap, unsigned int sc_reg, u32 val);
753 void (*pmp_attach)(struct ata_port *ap);
754 void (*pmp_detach)(struct ata_port *ap);
755 int (*enable_pm)(struct ata_port *ap, enum link_pm policy);
756 void (*disable_pm)(struct ata_port *ap);
757
758 /*
759 * Start, stop, suspend and resume
760 */
761 int (*port_suspend)(struct ata_port *ap, pm_message_t mesg);
762 int (*port_resume)(struct ata_port *ap);
763 int (*port_start)(struct ata_port *ap);
764 void (*port_stop)(struct ata_port *ap);
765 void (*host_stop)(struct ata_host *host);
766
767#ifdef CONFIG_ATA_SFF
768 /*
769 * SFF / taskfile oriented ops
770 */
771 void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
772 u8 (*sff_check_status)(struct ata_port *ap);
773 u8 (*sff_check_altstatus)(struct ata_port *ap);
774 void (*sff_tf_load)(struct ata_port *ap, const struct ata_taskfile *tf);
775 void (*sff_tf_read)(struct ata_port *ap, struct ata_taskfile *tf);
776 void (*sff_exec_command)(struct ata_port *ap,
777 const struct ata_taskfile *tf);
778 unsigned int (*sff_data_xfer)(struct ata_device *dev,
779 unsigned char *buf, unsigned int buflen, int rw);
780 u8 (*sff_irq_on)(struct ata_port *);
781 void (*sff_irq_clear)(struct ata_port *);
722 782
723 int (*port_suspend) (struct ata_port *ap, pm_message_t mesg); 783 void (*bmdma_setup)(struct ata_queued_cmd *qc);
724 int (*port_resume) (struct ata_port *ap); 784 void (*bmdma_start)(struct ata_queued_cmd *qc);
725 int (*enable_pm) (struct ata_port *ap, enum link_pm policy); 785 void (*bmdma_stop)(struct ata_queued_cmd *qc);
726 void (*disable_pm) (struct ata_port *ap); 786 u8 (*bmdma_status)(struct ata_port *ap);
727 int (*port_start) (struct ata_port *ap); 787#endif /* CONFIG_ATA_SFF */
728 void (*port_stop) (struct ata_port *ap);
729 788
730 void (*host_stop) (struct ata_host *host); 789 /*
790 * Obsolete
791 */
792 void (*phy_reset)(struct ata_port *ap);
793 void (*eng_timeout)(struct ata_port *ap);
731 794
732 void (*bmdma_stop) (struct ata_queued_cmd *qc); 795 /*
733 u8 (*bmdma_status) (struct ata_port *ap); 796 * ->inherits must be the last field and all the preceding
797 * fields must be pointers.
798 */
799 const struct ata_port_operations *inherits;
734}; 800};
735 801
736struct ata_port_info { 802struct ata_port_info {
737 struct scsi_host_template *sht;
738 unsigned long flags; 803 unsigned long flags;
739 unsigned long link_flags; 804 unsigned long link_flags;
740 unsigned long pio_mask; 805 unsigned long pio_mask;
741 unsigned long mwdma_mask; 806 unsigned long mwdma_mask;
742 unsigned long udma_mask; 807 unsigned long udma_mask;
743 const struct ata_port_operations *port_ops; 808 struct ata_port_operations *port_ops;
744 irq_handler_t irq_handler;
745 void *private_data; 809 void *private_data;
746}; 810};
747 811
@@ -759,11 +823,14 @@ struct ata_timing {
759 823
760#define FIT(v, vmin, vmax) max_t(short, min_t(short, v, vmax), vmin) 824#define FIT(v, vmin, vmax) max_t(short, min_t(short, v, vmax), vmin)
761 825
826/*
827 * Core layer - drivers/ata/libata-core.c
828 */
762extern const unsigned long sata_deb_timing_normal[]; 829extern const unsigned long sata_deb_timing_normal[];
763extern const unsigned long sata_deb_timing_hotplug[]; 830extern const unsigned long sata_deb_timing_hotplug[];
764extern const unsigned long sata_deb_timing_long[]; 831extern const unsigned long sata_deb_timing_long[];
765 832
766extern const struct ata_port_operations ata_dummy_port_ops; 833extern struct ata_port_operations ata_dummy_port_ops;
767extern const struct ata_port_info ata_dummy_port_info; 834extern const struct ata_port_info ata_dummy_port_info;
768 835
769static inline const unsigned long * 836static inline const unsigned long *
@@ -780,24 +847,22 @@ static inline int ata_port_is_dummy(struct ata_port *ap)
780 return ap->ops == &ata_dummy_port_ops; 847 return ap->ops == &ata_dummy_port_ops;
781} 848}
782 849
783extern void sata_print_link_status(struct ata_link *link);
784extern void ata_port_probe(struct ata_port *); 850extern void ata_port_probe(struct ata_port *);
785extern void ata_bus_reset(struct ata_port *ap);
786extern int sata_set_spd(struct ata_link *link); 851extern int sata_set_spd(struct ata_link *link);
852extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
853extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
854 int (*check_ready)(struct ata_link *link));
787extern int sata_link_debounce(struct ata_link *link, 855extern int sata_link_debounce(struct ata_link *link,
788 const unsigned long *params, unsigned long deadline); 856 const unsigned long *params, unsigned long deadline);
789extern int sata_link_resume(struct ata_link *link, const unsigned long *params, 857extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
790 unsigned long deadline); 858 unsigned long deadline);
791extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
792extern int ata_std_softreset(struct ata_link *link, unsigned int *classes,
793 unsigned long deadline);
794extern int sata_link_hardreset(struct ata_link *link, 859extern int sata_link_hardreset(struct ata_link *link,
795 const unsigned long *timing, unsigned long deadline); 860 const unsigned long *timing, unsigned long deadline,
861 bool *online, int (*check_ready)(struct ata_link *));
796extern int sata_std_hardreset(struct ata_link *link, unsigned int *class, 862extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
797 unsigned long deadline); 863 unsigned long deadline);
798extern void ata_std_postreset(struct ata_link *link, unsigned int *classes); 864extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
799extern void ata_port_disable(struct ata_port *); 865extern void ata_port_disable(struct ata_port *);
800extern void ata_std_ports(struct ata_ioports *ioaddr);
801 866
802extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports); 867extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
803extern struct ata_host *ata_host_alloc_pinfo(struct device *dev, 868extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
@@ -810,7 +875,7 @@ extern int ata_host_activate(struct ata_host *host, int irq,
810 struct scsi_host_template *sht); 875 struct scsi_host_template *sht);
811extern void ata_host_detach(struct ata_host *host); 876extern void ata_host_detach(struct ata_host *host);
812extern void ata_host_init(struct ata_host *, struct device *, 877extern void ata_host_init(struct ata_host *, struct device *,
813 unsigned long, const struct ata_port_operations *); 878 unsigned long, struct ata_port_operations *);
814extern int ata_scsi_detect(struct scsi_host_template *sht); 879extern int ata_scsi_detect(struct scsi_host_template *sht);
815extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 880extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
816extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); 881extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
@@ -823,7 +888,6 @@ extern void ata_sas_port_stop(struct ata_port *ap);
823extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *); 888extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
824extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), 889extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
825 struct ata_port *ap); 890 struct ata_port *ap);
826extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
827extern int sata_scr_valid(struct ata_link *link); 891extern int sata_scr_valid(struct ata_link *link);
828extern int sata_scr_read(struct ata_link *link, int reg, u32 *val); 892extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
829extern int sata_scr_write(struct ata_link *link, int reg, u32 val); 893extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
@@ -835,21 +899,9 @@ extern int ata_host_suspend(struct ata_host *host, pm_message_t mesg);
835extern void ata_host_resume(struct ata_host *host); 899extern void ata_host_resume(struct ata_host *host);
836#endif 900#endif
837extern int ata_ratelimit(void); 901extern int ata_ratelimit(void);
838extern int ata_busy_sleep(struct ata_port *ap,
839 unsigned long timeout_pat, unsigned long timeout);
840extern void ata_wait_after_reset(struct ata_port *ap, unsigned long deadline);
841extern int ata_wait_ready(struct ata_port *ap, unsigned long deadline);
842extern u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, 902extern u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
843 unsigned long interval_msec, 903 unsigned long interval_msec,
844 unsigned long timeout_msec); 904 unsigned long timeout_msec);
845extern unsigned int ata_dev_try_classify(struct ata_device *dev, int present,
846 u8 *r_err);
847
848/*
849 * Default driver ops implementations
850 */
851extern void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
852extern void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
853extern int atapi_cmd_type(u8 opcode); 905extern int atapi_cmd_type(u8 opcode);
854extern void ata_tf_to_fis(const struct ata_taskfile *tf, 906extern void ata_tf_to_fis(const struct ata_taskfile *tf,
855 u8 pmp, int is_cmd, u8 *fis); 907 u8 pmp, int is_cmd, u8 *fis);
@@ -864,23 +916,9 @@ extern unsigned long ata_xfer_mode2mask(u8 xfer_mode);
864extern int ata_xfer_mode2shift(unsigned long xfer_mode); 916extern int ata_xfer_mode2shift(unsigned long xfer_mode);
865extern const char *ata_mode_string(unsigned long xfer_mask); 917extern const char *ata_mode_string(unsigned long xfer_mask);
866extern unsigned long ata_id_xfermask(const u16 *id); 918extern unsigned long ata_id_xfermask(const u16 *id);
867extern void ata_noop_dev_select(struct ata_port *ap, unsigned int device);
868extern void ata_std_dev_select(struct ata_port *ap, unsigned int device);
869extern u8 ata_check_status(struct ata_port *ap);
870extern u8 ata_altstatus(struct ata_port *ap);
871extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf);
872extern int ata_port_start(struct ata_port *ap); 919extern int ata_port_start(struct ata_port *ap);
873extern int ata_sff_port_start(struct ata_port *ap);
874extern irqreturn_t ata_interrupt(int irq, void *dev_instance);
875extern unsigned int ata_data_xfer(struct ata_device *dev,
876 unsigned char *buf, unsigned int buflen, int rw);
877extern unsigned int ata_data_xfer_noirq(struct ata_device *dev,
878 unsigned char *buf, unsigned int buflen, int rw);
879extern int ata_std_qc_defer(struct ata_queued_cmd *qc); 920extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
880extern void ata_dumb_qc_prep(struct ata_queued_cmd *qc);
881extern void ata_qc_prep(struct ata_queued_cmd *qc);
882extern void ata_noop_qc_prep(struct ata_queued_cmd *qc); 921extern void ata_noop_qc_prep(struct ata_queued_cmd *qc);
883extern unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc);
884extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, 922extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
885 unsigned int n_elem); 923 unsigned int n_elem);
886extern unsigned int ata_dev_classify(const struct ata_taskfile *tf); 924extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
@@ -889,24 +927,8 @@ extern void ata_id_string(const u16 *id, unsigned char *s,
889 unsigned int ofs, unsigned int len); 927 unsigned int ofs, unsigned int len);
890extern void ata_id_c_string(const u16 *id, unsigned char *s, 928extern void ata_id_c_string(const u16 *id, unsigned char *s,
891 unsigned int ofs, unsigned int len); 929 unsigned int ofs, unsigned int len);
892extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
893extern void ata_bmdma_start(struct ata_queued_cmd *qc);
894extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
895extern u8 ata_bmdma_status(struct ata_port *ap);
896extern void ata_bmdma_irq_clear(struct ata_port *ap);
897extern void ata_bmdma_freeze(struct ata_port *ap);
898extern void ata_bmdma_thaw(struct ata_port *ap);
899extern void ata_bmdma_drive_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
900 ata_reset_fn_t softreset,
901 ata_reset_fn_t hardreset,
902 ata_postreset_fn_t postreset);
903extern void ata_bmdma_error_handler(struct ata_port *ap);
904extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
905extern int ata_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
906 u8 status, int in_wq);
907extern void ata_qc_complete(struct ata_queued_cmd *qc); 930extern void ata_qc_complete(struct ata_queued_cmd *qc);
908extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active, 931extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active);
909 void (*finish_qc)(struct ata_queued_cmd *));
910extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd, 932extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
911 void (*done)(struct scsi_cmnd *)); 933 void (*done)(struct scsi_cmnd *));
912extern int ata_std_bios_param(struct scsi_device *sdev, 934extern int ata_std_bios_param(struct scsi_device *sdev,
@@ -918,7 +940,6 @@ extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
918 int queue_depth); 940 int queue_depth);
919extern struct ata_device *ata_dev_pair(struct ata_device *adev); 941extern struct ata_device *ata_dev_pair(struct ata_device *adev);
920extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev); 942extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
921extern u8 ata_irq_on(struct ata_port *ap);
922 943
923extern int ata_cable_40wire(struct ata_port *ap); 944extern int ata_cable_40wire(struct ata_port *ap);
924extern int ata_cable_80wire(struct ata_port *ap); 945extern int ata_cable_80wire(struct ata_port *ap);
@@ -926,10 +947,7 @@ extern int ata_cable_sata(struct ata_port *ap);
926extern int ata_cable_ignore(struct ata_port *ap); 947extern int ata_cable_ignore(struct ata_port *ap);
927extern int ata_cable_unknown(struct ata_port *ap); 948extern int ata_cable_unknown(struct ata_port *ap);
928 949
929/* 950/* Timing helpers */
930 * Timing helpers
931 */
932
933extern unsigned int ata_pio_need_iordy(const struct ata_device *); 951extern unsigned int ata_pio_need_iordy(const struct ata_device *);
934extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode); 952extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
935extern int ata_timing_compute(struct ata_device *, unsigned short, 953extern int ata_timing_compute(struct ata_device *, unsigned short,
@@ -939,24 +957,31 @@ extern void ata_timing_merge(const struct ata_timing *,
939 unsigned int); 957 unsigned int);
940extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle); 958extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
941 959
942enum { 960/* PCI */
943 ATA_TIMING_SETUP = (1 << 0), 961#ifdef CONFIG_PCI
944 ATA_TIMING_ACT8B = (1 << 1), 962struct pci_dev;
945 ATA_TIMING_REC8B = (1 << 2), 963
946 ATA_TIMING_CYC8B = (1 << 3), 964struct pci_bits {
947 ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B | 965 unsigned int reg; /* PCI config register to read */
948 ATA_TIMING_CYC8B, 966 unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */
949 ATA_TIMING_ACTIVE = (1 << 4), 967 unsigned long mask;
950 ATA_TIMING_RECOVER = (1 << 5), 968 unsigned long val;
951 ATA_TIMING_CYCLE = (1 << 6),
952 ATA_TIMING_UDMA = (1 << 7),
953 ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
954 ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
955 ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
956 ATA_TIMING_CYCLE | ATA_TIMING_UDMA,
957}; 969};
958 970
959/* libata-acpi.c */ 971extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
972extern void ata_pci_remove_one(struct pci_dev *pdev);
973
974#ifdef CONFIG_PM
975extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
976extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
977extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
978extern int ata_pci_device_resume(struct pci_dev *pdev);
979#endif /* CONFIG_PM */
980#endif /* CONFIG_PCI */
981
982/*
983 * ACPI - drivers/ata/libata-acpi.c
984 */
960#ifdef CONFIG_ATA_ACPI 985#ifdef CONFIG_ATA_ACPI
961static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap) 986static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
962{ 987{
@@ -1000,56 +1025,8 @@ static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
1000} 1025}
1001#endif 1026#endif
1002 1027
1003#ifdef CONFIG_PCI
1004struct pci_dev;
1005
1006extern int ata_pci_init_one(struct pci_dev *pdev,
1007 const struct ata_port_info * const * ppi);
1008extern void ata_pci_remove_one(struct pci_dev *pdev);
1009#ifdef CONFIG_PM
1010extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
1011extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
1012extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
1013extern int ata_pci_device_resume(struct pci_dev *pdev);
1014#endif
1015extern int ata_pci_clear_simplex(struct pci_dev *pdev);
1016
1017struct pci_bits {
1018 unsigned int reg; /* PCI config register to read */
1019 unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */
1020 unsigned long mask;
1021 unsigned long val;
1022};
1023
1024extern int ata_pci_init_sff_host(struct ata_host *host);
1025extern int ata_pci_init_bmdma(struct ata_host *host);
1026extern int ata_pci_prepare_sff_host(struct pci_dev *pdev,
1027 const struct ata_port_info * const * ppi,
1028 struct ata_host **r_host);
1029extern int ata_pci_activate_sff_host(struct ata_host *host,
1030 irq_handler_t irq_handler,
1031 struct scsi_host_template *sht);
1032extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
1033extern unsigned long ata_pci_default_filter(struct ata_device *dev,
1034 unsigned long xfer_mask);
1035#endif /* CONFIG_PCI */
1036
1037/* 1028/*
1038 * PMP 1029 * EH - drivers/ata/libata-eh.c
1039 */
1040extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
1041extern int sata_pmp_std_prereset(struct ata_link *link, unsigned long deadline);
1042extern int sata_pmp_std_hardreset(struct ata_link *link, unsigned int *class,
1043 unsigned long deadline);
1044extern void sata_pmp_std_postreset(struct ata_link *link, unsigned int *class);
1045extern void sata_pmp_do_eh(struct ata_port *ap,
1046 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
1047 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset,
1048 ata_prereset_fn_t pmp_prereset, ata_reset_fn_t pmp_softreset,
1049 ata_reset_fn_t pmp_hardreset, ata_postreset_fn_t pmp_postreset);
1050
1051/*
1052 * EH
1053 */ 1030 */
1054extern void ata_port_schedule_eh(struct ata_port *ap); 1031extern void ata_port_schedule_eh(struct ata_port *ap);
1055extern int ata_link_abort(struct ata_link *link); 1032extern int ata_link_abort(struct ata_link *link);
@@ -1066,6 +1043,92 @@ extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1066extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset, 1043extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1067 ata_reset_fn_t softreset, ata_reset_fn_t hardreset, 1044 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1068 ata_postreset_fn_t postreset); 1045 ata_postreset_fn_t postreset);
1046extern void ata_std_error_handler(struct ata_port *ap);
1047
1048/*
1049 * Base operations to inherit from and initializers for sht
1050 *
1051 * Operations
1052 *
1053 * base : Common to all libata drivers.
1054 * sata : SATA controllers w/ native interface.
1055 * pmp : SATA controllers w/ PMP support.
1056 * sff : SFF ATA controllers w/o BMDMA support.
1057 * bmdma : SFF ATA controllers w/ BMDMA support.
1058 *
1059 * sht initializers
1060 *
1061 * BASE : Common to all libata drivers. The user must set
1062 * sg_tablesize and dma_boundary.
1063 * PIO : SFF ATA controllers w/ only PIO support.
1064 * BMDMA : SFF ATA controllers w/ BMDMA support. sg_tablesize and
1065 * dma_boundary are set to BMDMA limits.
1066 * NCQ : SATA controllers supporting NCQ. The user must set
1067 * sg_tablesize, dma_boundary and can_queue.
1068 */
1069extern const struct ata_port_operations ata_base_port_ops;
1070extern const struct ata_port_operations sata_port_ops;
1071
1072#define ATA_BASE_SHT(drv_name) \
1073 .module = THIS_MODULE, \
1074 .name = drv_name, \
1075 .ioctl = ata_scsi_ioctl, \
1076 .queuecommand = ata_scsi_queuecmd, \
1077 .can_queue = ATA_DEF_QUEUE, \
1078 .this_id = ATA_SHT_THIS_ID, \
1079 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, \
1080 .emulated = ATA_SHT_EMULATED, \
1081 .use_clustering = ATA_SHT_USE_CLUSTERING, \
1082 .proc_name = drv_name, \
1083 .slave_configure = ata_scsi_slave_config, \
1084 .slave_destroy = ata_scsi_slave_destroy, \
1085 .bios_param = ata_std_bios_param
1086
1087#define ATA_NCQ_SHT(drv_name) \
1088 ATA_BASE_SHT(drv_name), \
1089 .change_queue_depth = ata_scsi_change_queue_depth
1090
1091/*
1092 * PMP helpers
1093 */
1094#ifdef CONFIG_SATA_PMP
1095static inline bool sata_pmp_supported(struct ata_port *ap)
1096{
1097 return ap->flags & ATA_FLAG_PMP;
1098}
1099
1100static inline bool sata_pmp_attached(struct ata_port *ap)
1101{
1102 return ap->nr_pmp_links != 0;
1103}
1104
1105static inline int ata_is_host_link(const struct ata_link *link)
1106{
1107 return link == &link->ap->link;
1108}
1109#else /* CONFIG_SATA_PMP */
1110static inline bool sata_pmp_supported(struct ata_port *ap)
1111{
1112 return false;
1113}
1114
1115static inline bool sata_pmp_attached(struct ata_port *ap)
1116{
1117 return false;
1118}
1119
1120static inline int ata_is_host_link(const struct ata_link *link)
1121{
1122 return 1;
1123}
1124#endif /* CONFIG_SATA_PMP */
1125
1126static inline int sata_srst_pmp(struct ata_link *link)
1127{
1128 if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
1129 return SATA_PMP_CTRL_PORT;
1130 return link->pmp;
1131}
1069 1132
1070/* 1133/*
1071 * printk helpers 1134 * printk helpers
@@ -1074,7 +1137,7 @@ extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1074 printk("%sata%u: "fmt, lv, (ap)->print_id , ##args) 1137 printk("%sata%u: "fmt, lv, (ap)->print_id , ##args)
1075 1138
1076#define ata_link_printk(link, lv, fmt, args...) do { \ 1139#define ata_link_printk(link, lv, fmt, args...) do { \
1077 if ((link)->ap->nr_pmp_links) \ 1140 if (sata_pmp_attached((link)->ap)) \
1078 printk("%sata%u.%02u: "fmt, lv, (link)->ap->print_id, \ 1141 printk("%sata%u.%02u: "fmt, lv, (link)->ap->print_id, \
1079 (link)->pmp , ##args); \ 1142 (link)->pmp , ##args); \
1080 else \ 1143 else \
@@ -1094,18 +1157,11 @@ extern void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
1094 __attribute__ ((format (printf, 2, 3))); 1157 __attribute__ ((format (printf, 2, 3)));
1095extern void ata_ehi_clear_desc(struct ata_eh_info *ehi); 1158extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
1096 1159
1097static inline void ata_ehi_schedule_probe(struct ata_eh_info *ehi)
1098{
1099 ehi->flags |= ATA_EHI_RESUME_LINK;
1100 ehi->action |= ATA_EH_SOFTRESET;
1101 ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1;
1102}
1103
1104static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi) 1160static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
1105{ 1161{
1106 ata_ehi_schedule_probe(ehi); 1162 ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1;
1107 ehi->flags |= ATA_EHI_HOTPLUGGED; 1163 ehi->flags |= ATA_EHI_HOTPLUGGED;
1108 ehi->action |= ATA_EH_ENABLE_LINK; 1164 ehi->action |= ATA_EH_RESET | ATA_EH_ENABLE_LINK;
1109 ehi->err_mask |= AC_ERR_ATA_BUS; 1165 ehi->err_mask |= AC_ERR_ATA_BUS;
1110} 1166}
1111 1167
@@ -1126,7 +1182,7 @@ static inline unsigned int ata_tag_valid(unsigned int tag)
1126 1182
1127static inline unsigned int ata_tag_internal(unsigned int tag) 1183static inline unsigned int ata_tag_internal(unsigned int tag)
1128{ 1184{
1129 return tag == ATA_MAX_QUEUE - 1; 1185 return tag == ATA_TAG_INTERNAL;
1130} 1186}
1131 1187
1132/* 1188/*
@@ -1167,11 +1223,6 @@ static inline unsigned int ata_dev_absent(const struct ata_device *dev)
1167/* 1223/*
1168 * link helpers 1224 * link helpers
1169 */ 1225 */
1170static inline int ata_is_host_link(const struct ata_link *link)
1171{
1172 return link == &link->ap->link;
1173}
1174
1175static inline int ata_link_max_devices(const struct ata_link *link) 1226static inline int ata_link_max_devices(const struct ata_link *link)
1176{ 1227{
1177 if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS) 1228 if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS)
@@ -1186,7 +1237,7 @@ static inline int ata_link_active(struct ata_link *link)
1186 1237
1187static inline struct ata_link *ata_port_first_link(struct ata_port *ap) 1238static inline struct ata_link *ata_port_first_link(struct ata_port *ap)
1188{ 1239{
1189 if (ap->nr_pmp_links) 1240 if (sata_pmp_attached(ap))
1190 return ap->pmp_link; 1241 return ap->pmp_link;
1191 return &ap->link; 1242 return &ap->link;
1192} 1243}
@@ -1195,8 +1246,8 @@ static inline struct ata_link *ata_port_next_link(struct ata_link *link)
1195{ 1246{
1196 struct ata_port *ap = link->ap; 1247 struct ata_port *ap = link->ap;
1197 1248
1198 if (link == &ap->link) { 1249 if (ata_is_host_link(link)) {
1199 if (!ap->nr_pmp_links) 1250 if (!sata_pmp_attached(ap))
1200 return NULL; 1251 return NULL;
1201 return ap->pmp_link; 1252 return ap->pmp_link;
1202 } 1253 }
@@ -1222,11 +1273,6 @@ static inline struct ata_link *ata_port_next_link(struct ata_link *link)
1222 for ((dev) = (link)->device + ata_link_max_devices(link) - 1; \ 1273 for ((dev) = (link)->device + ata_link_max_devices(link) - 1; \
1223 (dev) >= (link)->device || ((dev) = NULL); (dev)--) 1274 (dev) >= (link)->device || ((dev) = NULL); (dev)--)
1224 1275
1225static inline u8 ata_chk_status(struct ata_port *ap)
1226{
1227 return ap->ops->check_status(ap);
1228}
1229
1230/** 1276/**
1231 * ata_ncq_enabled - Test whether NCQ is enabled 1277 * ata_ncq_enabled - Test whether NCQ is enabled
1232 * @dev: ATA device to test for 1278 * @dev: ATA device to test for
@@ -1243,74 +1289,6 @@ static inline int ata_ncq_enabled(struct ata_device *dev)
1243 ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ; 1289 ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
1244} 1290}
1245 1291
1246/**
1247 * ata_pause - Flush writes and pause 400 nanoseconds.
1248 * @ap: Port to wait for.
1249 *
1250 * LOCKING:
1251 * Inherited from caller.
1252 */
1253
1254static inline void ata_pause(struct ata_port *ap)
1255{
1256 ata_altstatus(ap);
1257 ndelay(400);
1258}
1259
1260
1261/**
1262 * ata_busy_wait - Wait for a port status register
1263 * @ap: Port to wait for.
1264 * @bits: bits that must be clear
1265 * @max: number of 10uS waits to perform
1266 *
1267 * Waits up to max*10 microseconds for the selected bits in the port's
1268 * status register to be cleared.
1269 * Returns final value of status register.
1270 *
1271 * LOCKING:
1272 * Inherited from caller.
1273 */
1274
1275static inline u8 ata_busy_wait(struct ata_port *ap, unsigned int bits,
1276 unsigned int max)
1277{
1278 u8 status;
1279
1280 do {
1281 udelay(10);
1282 status = ata_chk_status(ap);
1283 max--;
1284 } while (status != 0xff && (status & bits) && (max > 0));
1285
1286 return status;
1287}
1288
1289
1290/**
1291 * ata_wait_idle - Wait for a port to be idle.
1292 * @ap: Port to wait for.
1293 *
1294 * Waits up to 10ms for port's BUSY and DRQ signals to clear.
1295 * Returns final value of status register.
1296 *
1297 * LOCKING:
1298 * Inherited from caller.
1299 */
1300
1301static inline u8 ata_wait_idle(struct ata_port *ap)
1302{
1303 u8 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
1304
1305#ifdef ATA_DEBUG
1306 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
1307 ata_port_printk(ap, KERN_DEBUG, "abnormal Status 0x%X\n",
1308 status);
1309#endif
1310
1311 return status;
1312}
1313
1314static inline void ata_qc_set_polling(struct ata_queued_cmd *qc) 1292static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
1315{ 1293{
1316 qc->tf.ctl |= ATA_NIEN; 1294 qc->tf.ctl |= ATA_NIEN;
@@ -1403,4 +1381,171 @@ static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
1403 return *(struct ata_port **)&host->hostdata[0]; 1381 return *(struct ata_port **)&host->hostdata[0];
1404} 1382}
1405 1383
1384
1385/**************************************************************************
1386 * PMP - drivers/ata/libata-pmp.c
1387 */
1388#ifdef CONFIG_SATA_PMP
1389
1390extern const struct ata_port_operations sata_pmp_port_ops;
1391
1392extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
1393extern void sata_pmp_error_handler(struct ata_port *ap);
1394
1395#else /* CONFIG_SATA_PMP */
1396
1397#define sata_pmp_port_ops sata_port_ops
1398#define sata_pmp_qc_defer_cmd_switch ata_std_qc_defer
1399#define sata_pmp_error_handler ata_std_error_handler
1400
1401#endif /* CONFIG_SATA_PMP */
1402
1403
1404/**************************************************************************
1405 * SFF - drivers/ata/libata-sff.c
1406 */
1407#ifdef CONFIG_ATA_SFF
1408
1409extern const struct ata_port_operations ata_sff_port_ops;
1410extern const struct ata_port_operations ata_bmdma_port_ops;
1411
1412/* PIO only, sg_tablesize and dma_boundary limits can be removed */
1413#define ATA_PIO_SHT(drv_name) \
1414 ATA_BASE_SHT(drv_name), \
1415 .sg_tablesize = LIBATA_MAX_PRD, \
1416 .dma_boundary = ATA_DMA_BOUNDARY
1417
1418#define ATA_BMDMA_SHT(drv_name) \
1419 ATA_BASE_SHT(drv_name), \
1420 .sg_tablesize = LIBATA_MAX_PRD, \
1421 .dma_boundary = ATA_DMA_BOUNDARY
1422
1423extern void ata_sff_qc_prep(struct ata_queued_cmd *qc);
1424extern void ata_sff_dumb_qc_prep(struct ata_queued_cmd *qc);
1425extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device);
1426extern u8 ata_sff_check_status(struct ata_port *ap);
1427extern u8 ata_sff_altstatus(struct ata_port *ap);
1428extern int ata_sff_busy_sleep(struct ata_port *ap,
1429 unsigned long timeout_pat, unsigned long timeout);
1430extern int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline);
1431extern void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
1432extern void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
1433extern void ata_sff_exec_command(struct ata_port *ap,
1434 const struct ata_taskfile *tf);
1435extern unsigned int ata_sff_data_xfer(struct ata_device *dev,
1436 unsigned char *buf, unsigned int buflen, int rw);
1437extern unsigned int ata_sff_data_xfer_noirq(struct ata_device *dev,
1438 unsigned char *buf, unsigned int buflen, int rw);
1439extern u8 ata_sff_irq_on(struct ata_port *ap);
1440extern void ata_sff_irq_clear(struct ata_port *ap);
1441extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
1442 u8 status, int in_wq);
1443extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
1444extern bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
1445extern unsigned int ata_sff_host_intr(struct ata_port *ap,
1446 struct ata_queued_cmd *qc);
1447extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance);
1448extern void ata_sff_freeze(struct ata_port *ap);
1449extern void ata_sff_thaw(struct ata_port *ap);
1450extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline);
1451extern unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
1452 u8 *r_err);
1453extern int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
1454 unsigned long deadline);
1455extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
1456 unsigned long deadline);
1457extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
1458 unsigned long deadline);
1459extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
1460extern void ata_sff_error_handler(struct ata_port *ap);
1461extern void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc);
1462extern int ata_sff_port_start(struct ata_port *ap);
1463extern void ata_sff_std_ports(struct ata_ioports *ioaddr);
1464extern unsigned long ata_bmdma_mode_filter(struct ata_device *dev,
1465 unsigned long xfer_mask);
1466extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
1467extern void ata_bmdma_start(struct ata_queued_cmd *qc);
1468extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
1469extern u8 ata_bmdma_status(struct ata_port *ap);
1470extern void ata_bus_reset(struct ata_port *ap);
1471
1472#ifdef CONFIG_PCI
1473extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
1474extern int ata_pci_bmdma_init(struct ata_host *host);
1475extern int ata_pci_sff_init_host(struct ata_host *host);
1476extern int ata_pci_sff_prepare_host(struct pci_dev *pdev,
1477 const struct ata_port_info * const * ppi,
1478 struct ata_host **r_host);
1479extern int ata_pci_sff_activate_host(struct ata_host *host,
1480 irq_handler_t irq_handler,
1481 struct scsi_host_template *sht);
1482extern int ata_pci_sff_init_one(struct pci_dev *pdev,
1483 const struct ata_port_info * const * ppi,
1484 struct scsi_host_template *sht, void *host_priv);
1485#endif /* CONFIG_PCI */
1486
1487/**
1488 * ata_sff_pause - Flush writes and pause 400 nanoseconds.
1489 * @ap: Port to wait for.
1490 *
1491 * LOCKING:
1492 * Inherited from caller.
1493 */
1494static inline void ata_sff_pause(struct ata_port *ap)
1495{
1496 ata_sff_altstatus(ap);
1497 ndelay(400);
1498}
1499
1500/**
1501 * ata_sff_busy_wait - Wait for a port status register
1502 * @ap: Port to wait for.
1503 * @bits: bits that must be clear
1504 * @max: number of 10uS waits to perform
1505 *
1506 * Waits up to max*10 microseconds for the selected bits in the port's
1507 * status register to be cleared.
1508 * Returns final value of status register.
1509 *
1510 * LOCKING:
1511 * Inherited from caller.
1512 */
1513static inline u8 ata_sff_busy_wait(struct ata_port *ap, unsigned int bits,
1514 unsigned int max)
1515{
1516 u8 status;
1517
1518 do {
1519 udelay(10);
1520 status = ap->ops->sff_check_status(ap);
1521 max--;
1522 } while (status != 0xff && (status & bits) && (max > 0));
1523
1524 return status;
1525}
1526
1527/**
1528 * ata_wait_idle - Wait for a port to be idle.
1529 * @ap: Port to wait for.
1530 *
1531 * Waits up to 10ms for port's BUSY and DRQ signals to clear.
1532 * Returns final value of status register.
1533 *
1534 * LOCKING:
1535 * Inherited from caller.
1536 */
1537static inline u8 ata_wait_idle(struct ata_port *ap)
1538{
1539 u8 status = ata_sff_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
1540
1541#ifdef ATA_DEBUG
1542 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
1543 ata_port_printk(ap, KERN_DEBUG, "abnormal Status 0x%X\n",
1544 status);
1545#endif
1546
1547 return status;
1548}
1549#endif /* CONFIG_ATA_SFF */
1550
1406#endif /* __LINUX_LIBATA_H__ */ 1551#endif /* __LINUX_LIBATA_H__ */