aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/Kconfig9
-rw-r--r--drivers/ata/ahci.c54
-rw-r--r--drivers/ata/ata_piix.c195
-rw-r--r--drivers/ata/libata-core.c367
-rw-r--r--drivers/ata/libata-eh.c403
-rw-r--r--drivers/ata/libata-scsi.c148
-rw-r--r--drivers/ata/libata-sff.c5
-rw-r--r--drivers/ata/libata.h6
-rw-r--r--drivers/ata/pata_acpi.c2
-rw-r--r--drivers/ata/pata_ali.c3
-rw-r--r--drivers/ata/pata_at32.c4
-rw-r--r--drivers/ata/pata_atiixp.c2
-rw-r--r--drivers/ata/pata_bf54x.c34
-rw-r--r--drivers/ata/pata_cs5530.c6
-rw-r--r--drivers/ata/pata_it821x.c270
-rw-r--r--drivers/ata/pata_marvell.c51
-rw-r--r--drivers/ata/pata_oldpiix.c2
-rw-r--r--drivers/ata/pata_sc1200.c6
-rw-r--r--drivers/ata/pata_sil680.c5
-rw-r--r--drivers/ata/pata_via.c27
-rw-r--r--drivers/ata/sata_fsl.c26
-rw-r--r--drivers/ata/sata_inic162x.c11
-rw-r--r--drivers/ata/sata_mv.c68
-rw-r--r--drivers/ata/sata_nv.c43
-rw-r--r--drivers/ata/sata_promise.c16
-rw-r--r--drivers/ata/sata_qstor.c12
-rw-r--r--drivers/ata/sata_sil.c16
-rw-r--r--drivers/ata/sata_sil24.c12
-rw-r--r--drivers/ata/sata_sis.c28
-rw-r--r--drivers/ata/sata_svw.c10
-rw-r--r--drivers/ata/sata_uli.c24
-rw-r--r--drivers/ata/sata_via.c24
-rw-r--r--drivers/ata/sata_vsc.c10
33 files changed, 1378 insertions, 521 deletions
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index ae8494944c45..78fbec8ceda0 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -7,7 +7,6 @@ menuconfig ATA
7 depends on HAS_IOMEM 7 depends on HAS_IOMEM
8 depends on BLOCK 8 depends on BLOCK
9 depends on !(M32R || M68K) || BROKEN 9 depends on !(M32R || M68K) || BROKEN
10 depends on !SUN4 || BROKEN
11 select SCSI 10 select SCSI
12 ---help--- 11 ---help---
13 If you want to use a ATA hard disk, ATA tape drive, ATA CD-ROM or 12 If you want to use a ATA hard disk, ATA tape drive, ATA CD-ROM or
@@ -448,8 +447,10 @@ config PATA_MARVELL
448 tristate "Marvell PATA support via legacy mode" 447 tristate "Marvell PATA support via legacy mode"
449 depends on PCI 448 depends on PCI
450 help 449 help
451 This option enables limited support for the Marvell 88SE6145 ATA 450 This option enables limited support for the Marvell 88SE61xx ATA
452 controller. 451 controllers. If you wish to use only the SATA ports then select
452 the AHCI driver alone. If you wish to the use the PATA port or
453 both SATA and PATA include this driver.
453 454
454 If unsure, say N. 455 If unsure, say N.
455 456
@@ -661,7 +662,7 @@ config HAVE_PATA_PLATFORM
661 662
662config PATA_PLATFORM 663config PATA_PLATFORM
663 tristate "Generic platform device PATA support" 664 tristate "Generic platform device PATA support"
664 depends on EMBEDDED || ARCH_RPC || PPC || HAVE_PATA_PLATFORM 665 depends on EMBEDDED || PPC || HAVE_PATA_PLATFORM
665 help 666 help
666 This option enables support for generic directly connected ATA 667 This option enables support for generic directly connected ATA
667 devices commonly found on embedded systems. 668 devices commonly found on embedded systems.
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index ef3e5522e1a4..aeadd00411a1 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -267,8 +267,8 @@ struct ahci_port_priv {
267 * per PM slot */ 267 * per PM slot */
268}; 268};
269 269
270static int ahci_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 270static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
271static int ahci_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 271static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
272static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 272static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
273static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc); 273static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
274static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc); 274static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc);
@@ -316,6 +316,7 @@ static struct device_attribute *ahci_shost_attrs[] = {
316 316
317static struct device_attribute *ahci_sdev_attrs[] = { 317static struct device_attribute *ahci_sdev_attrs[] = {
318 &dev_attr_sw_activity, 318 &dev_attr_sw_activity,
319 &dev_attr_unload_heads,
319 NULL 320 NULL
320}; 321};
321 322
@@ -420,7 +421,7 @@ static const struct ata_port_info ahci_port_info[] = {
420 /* board_ahci_mv */ 421 /* board_ahci_mv */
421 { 422 {
422 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI | 423 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI |
423 AHCI_HFLAG_MV_PATA), 424 AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP),
424 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 425 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
425 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA, 426 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
426 .pio_mask = 0x1f, /* pio0-4 */ 427 .pio_mask = 0x1f, /* pio0-4 */
@@ -486,6 +487,10 @@ static const struct pci_device_id ahci_pci_tbl[] = {
486 { PCI_VDEVICE(INTEL, 0x502b), board_ahci }, /* Tolapai */ 487 { PCI_VDEVICE(INTEL, 0x502b), board_ahci }, /* Tolapai */
487 { PCI_VDEVICE(INTEL, 0x3a05), board_ahci }, /* ICH10 */ 488 { PCI_VDEVICE(INTEL, 0x3a05), board_ahci }, /* ICH10 */
488 { PCI_VDEVICE(INTEL, 0x3a25), board_ahci }, /* ICH10 */ 489 { PCI_VDEVICE(INTEL, 0x3a25), board_ahci }, /* ICH10 */
490 { PCI_VDEVICE(INTEL, 0x3b24), board_ahci }, /* PCH RAID */
491 { PCI_VDEVICE(INTEL, 0x3b25), board_ahci }, /* PCH RAID */
492 { PCI_VDEVICE(INTEL, 0x3b2b), board_ahci }, /* PCH RAID */
493 { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH RAID */
489 494
490 /* JMicron 360/1/3/5/6, match class to avoid IDE function */ 495 /* JMicron 360/1/3/5/6, match class to avoid IDE function */
491 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 496 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
@@ -575,9 +580,9 @@ static const struct pci_device_id ahci_pci_tbl[] = {
575 { PCI_VDEVICE(NVIDIA, 0x0bc7), board_ahci }, /* MCP7B */ 580 { PCI_VDEVICE(NVIDIA, 0x0bc7), board_ahci }, /* MCP7B */
576 581
577 /* SiS */ 582 /* SiS */
578 { PCI_VDEVICE(SI, 0x1184), board_ahci_nopmp }, /* SiS 966 */ 583 { PCI_VDEVICE(SI, 0x1184), board_ahci }, /* SiS 966 */
579 { PCI_VDEVICE(SI, 0x1185), board_ahci_nopmp }, /* SiS 968 */ 584 { PCI_VDEVICE(SI, 0x1185), board_ahci }, /* SiS 968 */
580 { PCI_VDEVICE(SI, 0x0186), board_ahci_nopmp }, /* SiS 968 */ 585 { PCI_VDEVICE(SI, 0x0186), board_ahci }, /* SiS 968 */
581 586
582 /* Marvell */ 587 /* Marvell */
583 { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */ 588 { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */
@@ -608,6 +613,15 @@ module_param(ahci_em_messages, int, 0444);
608MODULE_PARM_DESC(ahci_em_messages, 613MODULE_PARM_DESC(ahci_em_messages,
609 "Set AHCI Enclosure Management Message type (0 = disabled, 1 = LED"); 614 "Set AHCI Enclosure Management Message type (0 = disabled, 1 = LED");
610 615
616#if defined(CONFIG_PATA_MARVELL) || defined(CONFIG_PATA_MARVELL_MODULE)
617static int marvell_enable;
618#else
619static int marvell_enable = 1;
620#endif
621module_param(marvell_enable, int, 0644);
622MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)");
623
624
611static inline int ahci_nr_ports(u32 cap) 625static inline int ahci_nr_ports(u32 cap)
612{ 626{
613 return (cap & 0x1f) + 1; 627 return (cap & 0x1f) + 1;
@@ -730,6 +744,8 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
730 "MV_AHCI HACK: port_map %x -> %x\n", 744 "MV_AHCI HACK: port_map %x -> %x\n",
731 port_map, 745 port_map,
732 port_map & mv); 746 port_map & mv);
747 dev_printk(KERN_ERR, &pdev->dev,
748 "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
733 749
734 port_map &= mv; 750 port_map &= mv;
735 } 751 }
@@ -805,10 +821,10 @@ static unsigned ahci_scr_offset(struct ata_port *ap, unsigned int sc_reg)
805 return 0; 821 return 0;
806} 822}
807 823
808static int ahci_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 824static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
809{ 825{
810 void __iomem *port_mmio = ahci_port_base(ap); 826 void __iomem *port_mmio = ahci_port_base(link->ap);
811 int offset = ahci_scr_offset(ap, sc_reg); 827 int offset = ahci_scr_offset(link->ap, sc_reg);
812 828
813 if (offset) { 829 if (offset) {
814 *val = readl(port_mmio + offset); 830 *val = readl(port_mmio + offset);
@@ -817,10 +833,10 @@ static int ahci_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
817 return -EINVAL; 833 return -EINVAL;
818} 834}
819 835
820static int ahci_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 836static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
821{ 837{
822 void __iomem *port_mmio = ahci_port_base(ap); 838 void __iomem *port_mmio = ahci_port_base(link->ap);
823 int offset = ahci_scr_offset(ap, sc_reg); 839 int offset = ahci_scr_offset(link->ap, sc_reg);
824 840
825 if (offset) { 841 if (offset) {
826 writel(val, port_mmio + offset); 842 writel(val, port_mmio + offset);
@@ -958,7 +974,7 @@ static void ahci_disable_alpm(struct ata_port *ap)
958 writel(PORT_IRQ_PHYRDY, port_mmio + PORT_IRQ_STAT); 974 writel(PORT_IRQ_PHYRDY, port_mmio + PORT_IRQ_STAT);
959 975
960 /* go ahead and clean out PhyRdy Change from Serror too */ 976 /* go ahead and clean out PhyRdy Change from Serror too */
961 ahci_scr_write(ap, SCR_ERROR, ((1 << 16) | (1 << 18))); 977 ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18)));
962 978
963 /* 979 /*
964 * Clear flag to indicate that we should ignore all PhyRdy 980 * Clear flag to indicate that we should ignore all PhyRdy
@@ -1922,8 +1938,8 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1922 ata_ehi_push_desc(host_ehi, "irq_stat 0x%08x", irq_stat); 1938 ata_ehi_push_desc(host_ehi, "irq_stat 0x%08x", irq_stat);
1923 1939
1924 /* AHCI needs SError cleared; otherwise, it might lock up */ 1940 /* AHCI needs SError cleared; otherwise, it might lock up */
1925 ahci_scr_read(ap, SCR_ERROR, &serror); 1941 ahci_scr_read(&ap->link, SCR_ERROR, &serror);
1926 ahci_scr_write(ap, SCR_ERROR, serror); 1942 ahci_scr_write(&ap->link, SCR_ERROR, serror);
1927 host_ehi->serror |= serror; 1943 host_ehi->serror |= serror;
1928 1944
1929 /* some controllers set IRQ_IF_ERR on device errors, ignore it */ 1945 /* some controllers set IRQ_IF_ERR on device errors, ignore it */
@@ -2012,7 +2028,7 @@ static void ahci_port_intr(struct ata_port *ap)
2012 if ((hpriv->flags & AHCI_HFLAG_NO_HOTPLUG) && 2028 if ((hpriv->flags & AHCI_HFLAG_NO_HOTPLUG) &&
2013 (status & PORT_IRQ_PHYRDY)) { 2029 (status & PORT_IRQ_PHYRDY)) {
2014 status &= ~PORT_IRQ_PHYRDY; 2030 status &= ~PORT_IRQ_PHYRDY;
2015 ahci_scr_write(ap, SCR_ERROR, ((1 << 16) | (1 << 18))); 2031 ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18)));
2016 } 2032 }
2017 2033
2018 if (unlikely(status & PORT_IRQ_ERROR)) { 2034 if (unlikely(status & PORT_IRQ_ERROR)) {
@@ -2531,6 +2547,12 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2531 if (!printed_version++) 2547 if (!printed_version++)
2532 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 2548 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
2533 2549
2550 /* The AHCI driver can only drive the SATA ports, the PATA driver
2551 can drive them all so if both drivers are selected make sure
2552 AHCI stays out of the way */
2553 if (pdev->vendor == PCI_VENDOR_ID_MARVELL && !marvell_enable)
2554 return -ENODEV;
2555
2534 /* acquire resources */ 2556 /* acquire resources */
2535 rc = pcim_enable_device(pdev); 2557 rc = pcim_enable_device(pdev);
2536 if (rc) 2558 if (rc)
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index a90ae03f56b2..e9e32ed6b1a3 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -165,8 +165,10 @@ static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev);
165static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev); 165static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev);
166static int ich_pata_cable_detect(struct ata_port *ap); 166static int ich_pata_cable_detect(struct ata_port *ap);
167static u8 piix_vmw_bmdma_status(struct ata_port *ap); 167static u8 piix_vmw_bmdma_status(struct ata_port *ap);
168static int piix_sidpr_scr_read(struct ata_port *ap, unsigned int reg, u32 *val); 168static int piix_sidpr_scr_read(struct ata_link *link,
169static int piix_sidpr_scr_write(struct ata_port *ap, unsigned int reg, u32 val); 169 unsigned int reg, u32 *val);
170static int piix_sidpr_scr_write(struct ata_link *link,
171 unsigned int reg, u32 val);
170#ifdef CONFIG_PM 172#ifdef CONFIG_PM
171static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); 173static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
172static int piix_pci_device_resume(struct pci_dev *pdev); 174static int piix_pci_device_resume(struct pci_dev *pdev);
@@ -250,6 +252,7 @@ static const struct pci_device_id piix_pci_tbl[] = {
250 /* Mobile SATA Controller IDE (ICH8M), Apple */ 252 /* Mobile SATA Controller IDE (ICH8M), Apple */
251 { 0x8086, 0x2828, 0x106b, 0x00a0, 0, 0, ich8m_apple_sata }, 253 { 0x8086, 0x2828, 0x106b, 0x00a0, 0, 0, ich8m_apple_sata },
252 { 0x8086, 0x2828, 0x106b, 0x00a1, 0, 0, ich8m_apple_sata }, 254 { 0x8086, 0x2828, 0x106b, 0x00a1, 0, 0, ich8m_apple_sata },
255 { 0x8086, 0x2828, 0x106b, 0x00a3, 0, 0, ich8m_apple_sata },
253 /* Mobile SATA Controller IDE (ICH8M) */ 256 /* Mobile SATA Controller IDE (ICH8M) */
254 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata }, 257 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
255 /* SATA Controller IDE (ICH9) */ 258 /* SATA Controller IDE (ICH9) */
@@ -274,7 +277,18 @@ static const struct pci_device_id piix_pci_tbl[] = {
274 { 0x8086, 0x3a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata }, 277 { 0x8086, 0x3a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
275 /* SATA Controller IDE (ICH10) */ 278 /* SATA Controller IDE (ICH10) */
276 { 0x8086, 0x3a26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, 279 { 0x8086, 0x3a26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
277 280 /* SATA Controller IDE (PCH) */
281 { 0x8086, 0x3b20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
282 /* SATA Controller IDE (PCH) */
283 { 0x8086, 0x3b21, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
284 /* SATA Controller IDE (PCH) */
285 { 0x8086, 0x3b26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
286 /* SATA Controller IDE (PCH) */
287 { 0x8086, 0x3b28, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
288 /* SATA Controller IDE (PCH) */
289 { 0x8086, 0x3b2d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
290 /* SATA Controller IDE (PCH) */
291 { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
278 { } /* terminate list */ 292 { } /* terminate list */
279}; 293};
280 294
@@ -573,6 +587,7 @@ static const struct ich_laptop ich_laptop[] = {
573 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */ 587 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
574 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 588 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
575 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */ 589 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
590 { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */
576 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */ 591 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */
577 { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */ 592 { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */
578 { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */ 593 { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
@@ -876,23 +891,9 @@ static void ich_set_dmamode(struct ata_port *ap, struct ata_device *adev)
876 * Serial ATA Index/Data Pair Superset Registers access 891 * Serial ATA Index/Data Pair Superset Registers access
877 * 892 *
878 * Beginning from ICH8, there's a sane way to access SCRs using index 893 * Beginning from ICH8, there's a sane way to access SCRs using index
879 * and data register pair located at BAR5. This creates an 894 * and data register pair located at BAR5 which means that we have
880 * interesting problem of mapping two SCRs to one port. 895 * separate SCRs for master and slave. This is handled using libata
881 * 896 * slave_link facility.
882 * Although they have separate SCRs, the master and slave aren't
883 * independent enough to be treated as separate links - e.g. softreset
884 * resets both. Also, there's no protocol defined for hard resetting
885 * singled device sharing the virtual port (no defined way to acquire
886 * device signature). This is worked around by merging the SCR values
887 * into one sensible value and requesting follow-up SRST after
888 * hardreset.
889 *
890 * SCR merging is perfomed in nibbles which is the unit contents in
891 * SCRs are organized. If two values are equal, the value is used.
892 * When they differ, merge table which lists precedence of possible
893 * values is consulted and the first match or the last entry when
894 * nothing matches is used. When there's no merge table for the
895 * specific nibble, value from the first port is used.
896 */ 897 */
897static const int piix_sidx_map[] = { 898static const int piix_sidx_map[] = {
898 [SCR_STATUS] = 0, 899 [SCR_STATUS] = 0,
@@ -900,120 +901,38 @@ static const int piix_sidx_map[] = {
900 [SCR_CONTROL] = 1, 901 [SCR_CONTROL] = 1,
901}; 902};
902 903
903static void piix_sidpr_sel(struct ata_device *dev, unsigned int reg) 904static void piix_sidpr_sel(struct ata_link *link, unsigned int reg)
904{ 905{
905 struct ata_port *ap = dev->link->ap; 906 struct ata_port *ap = link->ap;
906 struct piix_host_priv *hpriv = ap->host->private_data; 907 struct piix_host_priv *hpriv = ap->host->private_data;
907 908
908 iowrite32(((ap->port_no * 2 + dev->devno) << 8) | piix_sidx_map[reg], 909 iowrite32(((ap->port_no * 2 + link->pmp) << 8) | piix_sidx_map[reg],
909 hpriv->sidpr + PIIX_SIDPR_IDX); 910 hpriv->sidpr + PIIX_SIDPR_IDX);
910} 911}
911 912
912static int piix_sidpr_read(struct ata_device *dev, unsigned int reg) 913static int piix_sidpr_scr_read(struct ata_link *link,
913{ 914 unsigned int reg, u32 *val)
914 struct piix_host_priv *hpriv = dev->link->ap->host->private_data;
915
916 piix_sidpr_sel(dev, reg);
917 return ioread32(hpriv->sidpr + PIIX_SIDPR_DATA);
918}
919
920static void piix_sidpr_write(struct ata_device *dev, unsigned int reg, u32 val)
921{ 915{
922 struct piix_host_priv *hpriv = dev->link->ap->host->private_data; 916 struct piix_host_priv *hpriv = link->ap->host->private_data;
923
924 piix_sidpr_sel(dev, reg);
925 iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA);
926}
927
928static u32 piix_merge_scr(u32 val0, u32 val1, const int * const *merge_tbl)
929{
930 u32 val = 0;
931 int i, mi;
932
933 for (i = 0, mi = 0; i < 32 / 4; i++) {
934 u8 c0 = (val0 >> (i * 4)) & 0xf;
935 u8 c1 = (val1 >> (i * 4)) & 0xf;
936 u8 merged = c0;
937 const int *cur;
938
939 /* if no merge preference, assume the first value */
940 cur = merge_tbl[mi];
941 if (!cur)
942 goto done;
943 mi++;
944
945 /* if two values equal, use it */
946 if (c0 == c1)
947 goto done;
948
949 /* choose the first match or the last from the merge table */
950 while (*cur != -1) {
951 if (c0 == *cur || c1 == *cur)
952 break;
953 cur++;
954 }
955 if (*cur == -1)
956 cur--;
957 merged = *cur;
958 done:
959 val |= merged << (i * 4);
960 }
961
962 return val;
963}
964
965static int piix_sidpr_scr_read(struct ata_port *ap, unsigned int reg, u32 *val)
966{
967 const int * const sstatus_merge_tbl[] = {
968 /* DET */ (const int []){ 1, 3, 0, 4, 3, -1 },
969 /* SPD */ (const int []){ 2, 1, 0, -1 },
970 /* IPM */ (const int []){ 6, 2, 1, 0, -1 },
971 NULL,
972 };
973 const int * const scontrol_merge_tbl[] = {
974 /* DET */ (const int []){ 1, 0, 4, 0, -1 },
975 /* SPD */ (const int []){ 0, 2, 1, 0, -1 },
976 /* IPM */ (const int []){ 0, 1, 2, 3, 0, -1 },
977 NULL,
978 };
979 u32 v0, v1;
980 917
981 if (reg >= ARRAY_SIZE(piix_sidx_map)) 918 if (reg >= ARRAY_SIZE(piix_sidx_map))
982 return -EINVAL; 919 return -EINVAL;
983 920
984 if (!(ap->flags & ATA_FLAG_SLAVE_POSS)) { 921 piix_sidpr_sel(link, reg);
985 *val = piix_sidpr_read(&ap->link.device[0], reg); 922 *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA);
986 return 0;
987 }
988
989 v0 = piix_sidpr_read(&ap->link.device[0], reg);
990 v1 = piix_sidpr_read(&ap->link.device[1], reg);
991
992 switch (reg) {
993 case SCR_STATUS:
994 *val = piix_merge_scr(v0, v1, sstatus_merge_tbl);
995 break;
996 case SCR_ERROR:
997 *val = v0 | v1;
998 break;
999 case SCR_CONTROL:
1000 *val = piix_merge_scr(v0, v1, scontrol_merge_tbl);
1001 break;
1002 }
1003
1004 return 0; 923 return 0;
1005} 924}
1006 925
1007static int piix_sidpr_scr_write(struct ata_port *ap, unsigned int reg, u32 val) 926static int piix_sidpr_scr_write(struct ata_link *link,
927 unsigned int reg, u32 val)
1008{ 928{
929 struct piix_host_priv *hpriv = link->ap->host->private_data;
930
1009 if (reg >= ARRAY_SIZE(piix_sidx_map)) 931 if (reg >= ARRAY_SIZE(piix_sidx_map))
1010 return -EINVAL; 932 return -EINVAL;
1011 933
1012 piix_sidpr_write(&ap->link.device[0], reg, val); 934 piix_sidpr_sel(link, reg);
1013 935 iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA);
1014 if (ap->flags & ATA_FLAG_SLAVE_POSS)
1015 piix_sidpr_write(&ap->link.device[1], reg, val);
1016
1017 return 0; 936 return 0;
1018} 937}
1019 938
@@ -1354,28 +1273,28 @@ static const int *__devinit piix_init_sata_map(struct pci_dev *pdev,
1354 return map; 1273 return map;
1355} 1274}
1356 1275
1357static void __devinit piix_init_sidpr(struct ata_host *host) 1276static int __devinit piix_init_sidpr(struct ata_host *host)
1358{ 1277{
1359 struct pci_dev *pdev = to_pci_dev(host->dev); 1278 struct pci_dev *pdev = to_pci_dev(host->dev);
1360 struct piix_host_priv *hpriv = host->private_data; 1279 struct piix_host_priv *hpriv = host->private_data;
1361 struct ata_device *dev0 = &host->ports[0]->link.device[0]; 1280 struct ata_link *link0 = &host->ports[0]->link;
1362 u32 scontrol; 1281 u32 scontrol;
1363 int i; 1282 int i, rc;
1364 1283
1365 /* check for availability */ 1284 /* check for availability */
1366 for (i = 0; i < 4; i++) 1285 for (i = 0; i < 4; i++)
1367 if (hpriv->map[i] == IDE) 1286 if (hpriv->map[i] == IDE)
1368 return; 1287 return 0;
1369 1288
1370 if (!(host->ports[0]->flags & PIIX_FLAG_SIDPR)) 1289 if (!(host->ports[0]->flags & PIIX_FLAG_SIDPR))
1371 return; 1290 return 0;
1372 1291
1373 if (pci_resource_start(pdev, PIIX_SIDPR_BAR) == 0 || 1292 if (pci_resource_start(pdev, PIIX_SIDPR_BAR) == 0 ||
1374 pci_resource_len(pdev, PIIX_SIDPR_BAR) != PIIX_SIDPR_LEN) 1293 pci_resource_len(pdev, PIIX_SIDPR_BAR) != PIIX_SIDPR_LEN)
1375 return; 1294 return 0;
1376 1295
1377 if (pcim_iomap_regions(pdev, 1 << PIIX_SIDPR_BAR, DRV_NAME)) 1296 if (pcim_iomap_regions(pdev, 1 << PIIX_SIDPR_BAR, DRV_NAME))
1378 return; 1297 return 0;
1379 1298
1380 hpriv->sidpr = pcim_iomap_table(pdev)[PIIX_SIDPR_BAR]; 1299 hpriv->sidpr = pcim_iomap_table(pdev)[PIIX_SIDPR_BAR];
1381 1300
@@ -1383,7 +1302,7 @@ static void __devinit piix_init_sidpr(struct ata_host *host)
1383 * Give it a test drive by inhibiting power save modes which 1302 * Give it a test drive by inhibiting power save modes which
1384 * we'll do anyway. 1303 * we'll do anyway.
1385 */ 1304 */
1386 scontrol = piix_sidpr_read(dev0, SCR_CONTROL); 1305 piix_sidpr_scr_read(link0, SCR_CONTROL, &scontrol);
1387 1306
1388 /* if IPM is already 3, SCR access is probably working. Don't 1307 /* if IPM is already 3, SCR access is probably working. Don't
1389 * un-inhibit power save modes as BIOS might have inhibited 1308 * un-inhibit power save modes as BIOS might have inhibited
@@ -1391,18 +1310,30 @@ static void __devinit piix_init_sidpr(struct ata_host *host)
1391 */ 1310 */
1392 if ((scontrol & 0xf00) != 0x300) { 1311 if ((scontrol & 0xf00) != 0x300) {
1393 scontrol |= 0x300; 1312 scontrol |= 0x300;
1394 piix_sidpr_write(dev0, SCR_CONTROL, scontrol); 1313 piix_sidpr_scr_write(link0, SCR_CONTROL, scontrol);
1395 scontrol = piix_sidpr_read(dev0, SCR_CONTROL); 1314 piix_sidpr_scr_read(link0, SCR_CONTROL, &scontrol);
1396 1315
1397 if ((scontrol & 0xf00) != 0x300) { 1316 if ((scontrol & 0xf00) != 0x300) {
1398 dev_printk(KERN_INFO, host->dev, "SCR access via " 1317 dev_printk(KERN_INFO, host->dev, "SCR access via "
1399 "SIDPR is available but doesn't work\n"); 1318 "SIDPR is available but doesn't work\n");
1400 return; 1319 return 0;
1401 } 1320 }
1402 } 1321 }
1403 1322
1404 host->ports[0]->ops = &piix_sidpr_sata_ops; 1323 /* okay, SCRs available, set ops and ask libata for slave_link */
1405 host->ports[1]->ops = &piix_sidpr_sata_ops; 1324 for (i = 0; i < 2; i++) {
1325 struct ata_port *ap = host->ports[i];
1326
1327 ap->ops = &piix_sidpr_sata_ops;
1328
1329 if (ap->flags & ATA_FLAG_SLAVE_POSS) {
1330 rc = ata_slave_link_init(ap);
1331 if (rc)
1332 return rc;
1333 }
1334 }
1335
1336 return 0;
1406} 1337}
1407 1338
1408static void piix_iocfg_bit18_quirk(struct pci_dev *pdev) 1339static void piix_iocfg_bit18_quirk(struct pci_dev *pdev)
@@ -1490,7 +1421,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1490 * off. 1421 * off.
1491 */ 1422 */
1492 if (pdev->vendor == PCI_VENDOR_ID_INTEL && pdev->device == 0x2652) { 1423 if (pdev->vendor == PCI_VENDOR_ID_INTEL && pdev->device == 0x2652) {
1493 int rc = piix_disable_ahci(pdev); 1424 rc = piix_disable_ahci(pdev);
1494 if (rc) 1425 if (rc)
1495 return rc; 1426 return rc;
1496 } 1427 }
@@ -1512,7 +1443,9 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1512 /* initialize controller */ 1443 /* initialize controller */
1513 if (port_flags & ATA_FLAG_SATA) { 1444 if (port_flags & ATA_FLAG_SATA) {
1514 piix_init_pcs(host, piix_map_db_table[ent->driver_data]); 1445 piix_init_pcs(host, piix_map_db_table[ent->driver_data]);
1515 piix_init_sidpr(host); 1446 rc = piix_init_sidpr(host);
1447 if (rc)
1448 return rc;
1516 } 1449 }
1517 1450
1518 /* apply IOCFG bit18 quirk */ 1451 /* apply IOCFG bit18 quirk */
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 9bef1a84fe3f..1ee9499bd343 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -104,6 +104,7 @@ struct ata_force_param {
104 unsigned long xfer_mask; 104 unsigned long xfer_mask;
105 unsigned int horkage_on; 105 unsigned int horkage_on;
106 unsigned int horkage_off; 106 unsigned int horkage_off;
107 unsigned int lflags;
107}; 108};
108 109
109struct ata_force_ent { 110struct ata_force_ent {
@@ -120,7 +121,7 @@ static char ata_force_param_buf[PAGE_SIZE] __initdata;
120module_param_string(force, ata_force_param_buf, sizeof(ata_force_param_buf), 0); 121module_param_string(force, ata_force_param_buf, sizeof(ata_force_param_buf), 0);
121MODULE_PARM_DESC(force, "Force ATA configurations including cable type, link speed and transfer mode (see Documentation/kernel-parameters.txt for details)"); 122MODULE_PARM_DESC(force, "Force ATA configurations including cable type, link speed and transfer mode (see Documentation/kernel-parameters.txt for details)");
122 123
123int atapi_enabled = 1; 124static int atapi_enabled = 1;
124module_param(atapi_enabled, int, 0444); 125module_param(atapi_enabled, int, 0444);
125MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); 126MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)");
126 127
@@ -162,6 +163,67 @@ MODULE_LICENSE("GPL");
162MODULE_VERSION(DRV_VERSION); 163MODULE_VERSION(DRV_VERSION);
163 164
164 165
166/*
167 * Iterator helpers. Don't use directly.
168 *
169 * LOCKING:
170 * Host lock or EH context.
171 */
172struct ata_link *__ata_port_next_link(struct ata_port *ap,
173 struct ata_link *link, bool dev_only)
174{
175 /* NULL link indicates start of iteration */
176 if (!link) {
177 if (dev_only && sata_pmp_attached(ap))
178 return ap->pmp_link;
179 return &ap->link;
180 }
181
182 /* we just iterated over the host master link, what's next? */
183 if (link == &ap->link) {
184 if (!sata_pmp_attached(ap)) {
185 if (unlikely(ap->slave_link) && !dev_only)
186 return ap->slave_link;
187 return NULL;
188 }
189 return ap->pmp_link;
190 }
191
192 /* slave_link excludes PMP */
193 if (unlikely(link == ap->slave_link))
194 return NULL;
195
196 /* iterate to the next PMP link */
197 if (++link < ap->pmp_link + ap->nr_pmp_links)
198 return link;
199 return NULL;
200}
201
202/**
203 * ata_dev_phys_link - find physical link for a device
204 * @dev: ATA device to look up physical link for
205 *
206 * Look up physical link which @dev is attached to. Note that
207 * this is different from @dev->link only when @dev is on slave
208 * link. For all other cases, it's the same as @dev->link.
209 *
210 * LOCKING:
211 * Don't care.
212 *
213 * RETURNS:
214 * Pointer to the found physical link.
215 */
216struct ata_link *ata_dev_phys_link(struct ata_device *dev)
217{
218 struct ata_port *ap = dev->link->ap;
219
220 if (!ap->slave_link)
221 return dev->link;
222 if (!dev->devno)
223 return &ap->link;
224 return ap->slave_link;
225}
226
165/** 227/**
166 * ata_force_cbl - force cable type according to libata.force 228 * ata_force_cbl - force cable type according to libata.force
167 * @ap: ATA port of interest 229 * @ap: ATA port of interest
@@ -196,28 +258,29 @@ void ata_force_cbl(struct ata_port *ap)
196} 258}
197 259
198/** 260/**
199 * ata_force_spd_limit - force SATA spd limit according to libata.force 261 * ata_force_link_limits - force link limits according to libata.force
200 * @link: ATA link of interest 262 * @link: ATA link of interest
201 * 263 *
202 * Force SATA spd limit according to libata.force and whine about 264 * Force link flags and SATA spd limit according to libata.force
203 * it. When only the port part is specified (e.g. 1:), the limit 265 * and whine about it. When only the port part is specified
204 * applies to all links connected to both the host link and all 266 * (e.g. 1:), the limit applies to all links connected to both
205 * fan-out ports connected via PMP. If the device part is 267 * the host link and all fan-out ports connected via PMP. If the
206 * specified as 0 (e.g. 1.00:), it specifies the first fan-out 268 * device part is specified as 0 (e.g. 1.00:), it specifies the
207 * link not the host link. Device number 15 always points to the 269 * first fan-out link not the host link. Device number 15 always
208 * host link whether PMP is attached or not. 270 * points to the host link whether PMP is attached or not. If the
271 * controller has slave link, device number 16 points to it.
209 * 272 *
210 * LOCKING: 273 * LOCKING:
211 * EH context. 274 * EH context.
212 */ 275 */
213static void ata_force_spd_limit(struct ata_link *link) 276static void ata_force_link_limits(struct ata_link *link)
214{ 277{
215 int linkno, i; 278 bool did_spd = false;
279 int linkno = link->pmp;
280 int i;
216 281
217 if (ata_is_host_link(link)) 282 if (ata_is_host_link(link))
218 linkno = 15; 283 linkno += 15;
219 else
220 linkno = link->pmp;
221 284
222 for (i = ata_force_tbl_size - 1; i >= 0; i--) { 285 for (i = ata_force_tbl_size - 1; i >= 0; i--) {
223 const struct ata_force_ent *fe = &ata_force_tbl[i]; 286 const struct ata_force_ent *fe = &ata_force_tbl[i];
@@ -228,13 +291,22 @@ static void ata_force_spd_limit(struct ata_link *link)
228 if (fe->device != -1 && fe->device != linkno) 291 if (fe->device != -1 && fe->device != linkno)
229 continue; 292 continue;
230 293
231 if (!fe->param.spd_limit) 294 /* only honor the first spd limit */
232 continue; 295 if (!did_spd && fe->param.spd_limit) {
296 link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1;
297 ata_link_printk(link, KERN_NOTICE,
298 "FORCE: PHY spd limit set to %s\n",
299 fe->param.name);
300 did_spd = true;
301 }
233 302
234 link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1; 303 /* let lflags stack */
235 ata_link_printk(link, KERN_NOTICE, 304 if (fe->param.lflags) {
236 "FORCE: PHY spd limit set to %s\n", fe->param.name); 305 link->flags |= fe->param.lflags;
237 return; 306 ata_link_printk(link, KERN_NOTICE,
307 "FORCE: link flag 0x%x forced -> 0x%x\n",
308 fe->param.lflags, link->flags);
309 }
238 } 310 }
239} 311}
240 312
@@ -255,9 +327,9 @@ static void ata_force_xfermask(struct ata_device *dev)
255 int alt_devno = devno; 327 int alt_devno = devno;
256 int i; 328 int i;
257 329
258 /* allow n.15 for the first device attached to host port */ 330 /* allow n.15/16 for devices attached to host port */
259 if (ata_is_host_link(dev->link) && devno == 0) 331 if (ata_is_host_link(dev->link))
260 alt_devno = 15; 332 alt_devno += 15;
261 333
262 for (i = ata_force_tbl_size - 1; i >= 0; i--) { 334 for (i = ata_force_tbl_size - 1; i >= 0; i--) {
263 const struct ata_force_ent *fe = &ata_force_tbl[i]; 335 const struct ata_force_ent *fe = &ata_force_tbl[i];
@@ -309,9 +381,9 @@ static void ata_force_horkage(struct ata_device *dev)
309 int alt_devno = devno; 381 int alt_devno = devno;
310 int i; 382 int i;
311 383
312 /* allow n.15 for the first device attached to host port */ 384 /* allow n.15/16 for devices attached to host port */
313 if (ata_is_host_link(dev->link) && devno == 0) 385 if (ata_is_host_link(dev->link))
314 alt_devno = 15; 386 alt_devno += 15;
315 387
316 for (i = 0; i < ata_force_tbl_size; i++) { 388 for (i = 0; i < ata_force_tbl_size; i++) {
317 const struct ata_force_ent *fe = &ata_force_tbl[i]; 389 const struct ata_force_ent *fe = &ata_force_tbl[i];
@@ -1132,6 +1204,8 @@ void ata_id_string(const u16 *id, unsigned char *s,
1132{ 1204{
1133 unsigned int c; 1205 unsigned int c;
1134 1206
1207 BUG_ON(len & 1);
1208
1135 while (len > 0) { 1209 while (len > 0) {
1136 c = id[ofs] >> 8; 1210 c = id[ofs] >> 8;
1137 *s = c; 1211 *s = c;
@@ -1165,8 +1239,6 @@ void ata_id_c_string(const u16 *id, unsigned char *s,
1165{ 1239{
1166 unsigned char *p; 1240 unsigned char *p;
1167 1241
1168 WARN_ON(!(len & 1));
1169
1170 ata_id_string(id, s, ofs, len - 1); 1242 ata_id_string(id, s, ofs, len - 1);
1171 1243
1172 p = s + strnlen(s, len - 1); 1244 p = s + strnlen(s, len - 1);
@@ -1886,6 +1958,23 @@ static u32 ata_pio_mask_no_iordy(const struct ata_device *adev)
1886} 1958}
1887 1959
1888/** 1960/**
1961 * ata_do_dev_read_id - default ID read method
1962 * @dev: device
1963 * @tf: proposed taskfile
1964 * @id: data buffer
1965 *
1966 * Issue the identify taskfile and hand back the buffer containing
1967 * identify data. For some RAID controllers and for pre ATA devices
1968 * this function is wrapped or replaced by the driver
1969 */
1970unsigned int ata_do_dev_read_id(struct ata_device *dev,
1971 struct ata_taskfile *tf, u16 *id)
1972{
1973 return ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE,
1974 id, sizeof(id[0]) * ATA_ID_WORDS, 0);
1975}
1976
1977/**
1889 * ata_dev_read_id - Read ID data from the specified device 1978 * ata_dev_read_id - Read ID data from the specified device
1890 * @dev: target device 1979 * @dev: target device
1891 * @p_class: pointer to class of the target device (may be changed) 1980 * @p_class: pointer to class of the target device (may be changed)
@@ -1920,7 +2009,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1920 if (ata_msg_ctl(ap)) 2009 if (ata_msg_ctl(ap))
1921 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __func__); 2010 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __func__);
1922 2011
1923 retry: 2012retry:
1924 ata_tf_init(dev, &tf); 2013 ata_tf_init(dev, &tf);
1925 2014
1926 switch (class) { 2015 switch (class) {
@@ -1948,8 +2037,11 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1948 */ 2037 */
1949 tf.flags |= ATA_TFLAG_POLLING; 2038 tf.flags |= ATA_TFLAG_POLLING;
1950 2039
1951 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, 2040 if (ap->ops->read_id)
1952 id, sizeof(id[0]) * ATA_ID_WORDS, 0); 2041 err_mask = ap->ops->read_id(dev, &tf, id);
2042 else
2043 err_mask = ata_do_dev_read_id(dev, &tf, id);
2044
1953 if (err_mask) { 2045 if (err_mask) {
1954 if (err_mask & AC_ERR_NODEV_HINT) { 2046 if (err_mask & AC_ERR_NODEV_HINT) {
1955 ata_dev_printk(dev, KERN_DEBUG, 2047 ata_dev_printk(dev, KERN_DEBUG,
@@ -2142,6 +2234,16 @@ int ata_dev_configure(struct ata_device *dev)
2142 return 0; 2234 return 0;
2143 } 2235 }
2144 2236
2237 if ((!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) &&
2238 dev->class == ATA_DEV_ATAPI) {
2239 ata_dev_printk(dev, KERN_WARNING,
2240 "WARNING: ATAPI is %s, device ignored.\n",
2241 atapi_enabled ? "not supported with this driver"
2242 : "disabled");
2243 ata_dev_disable(dev);
2244 return 0;
2245 }
2246
2145 /* let ACPI work its magic */ 2247 /* let ACPI work its magic */
2146 rc = ata_acpi_on_devcfg(dev); 2248 rc = ata_acpi_on_devcfg(dev);
2147 if (rc) 2249 if (rc)
@@ -2640,7 +2742,7 @@ static void sata_print_link_status(struct ata_link *link)
2640 return; 2742 return;
2641 sata_scr_read(link, SCR_CONTROL, &scontrol); 2743 sata_scr_read(link, SCR_CONTROL, &scontrol);
2642 2744
2643 if (ata_link_online(link)) { 2745 if (ata_phys_link_online(link)) {
2644 tmp = (sstatus >> 4) & 0xf; 2746 tmp = (sstatus >> 4) & 0xf;
2645 ata_link_printk(link, KERN_INFO, 2747 ata_link_printk(link, KERN_INFO,
2646 "SATA link up %s (SStatus %X SControl %X)\n", 2748 "SATA link up %s (SStatus %X SControl %X)\n",
@@ -3247,7 +3349,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3247 dev->dma_mode = ata_xfer_mask2mode(dma_mask); 3349 dev->dma_mode = ata_xfer_mask2mode(dma_mask);
3248 3350
3249 found = 1; 3351 found = 1;
3250 if (dev->dma_mode != 0xff) 3352 if (ata_dma_enabled(dev))
3251 used_dma = 1; 3353 used_dma = 1;
3252 } 3354 }
3253 if (!found) 3355 if (!found)
@@ -3272,7 +3374,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3272 3374
3273 /* step 3: set host DMA timings */ 3375 /* step 3: set host DMA timings */
3274 ata_link_for_each_dev(dev, link) { 3376 ata_link_for_each_dev(dev, link) {
3275 if (!ata_dev_enabled(dev) || dev->dma_mode == 0xff) 3377 if (!ata_dev_enabled(dev) || !ata_dma_enabled(dev))
3276 continue; 3378 continue;
3277 3379
3278 dev->xfer_mode = dev->dma_mode; 3380 dev->xfer_mode = dev->dma_mode;
@@ -3331,6 +3433,12 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
3331 unsigned long nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT); 3433 unsigned long nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT);
3332 int warned = 0; 3434 int warned = 0;
3333 3435
3436 /* Slave readiness can't be tested separately from master. On
3437 * M/S emulation configuration, this function should be called
3438 * only on the master and it will handle both master and slave.
3439 */
3440 WARN_ON(link == link->ap->slave_link);
3441
3334 if (time_after(nodev_deadline, deadline)) 3442 if (time_after(nodev_deadline, deadline))
3335 nodev_deadline = deadline; 3443 nodev_deadline = deadline;
3336 3444
@@ -3552,7 +3660,7 @@ int ata_std_prereset(struct ata_link *link, unsigned long deadline)
3552 } 3660 }
3553 3661
3554 /* no point in trying softreset on offline link */ 3662 /* no point in trying softreset on offline link */
3555 if (ata_link_offline(link)) 3663 if (ata_phys_link_offline(link))
3556 ehc->i.action &= ~ATA_EH_SOFTRESET; 3664 ehc->i.action &= ~ATA_EH_SOFTRESET;
3557 3665
3558 return 0; 3666 return 0;
@@ -3630,7 +3738,7 @@ int sata_link_hardreset(struct ata_link *link, const unsigned long *timing,
3630 if (rc) 3738 if (rc)
3631 goto out; 3739 goto out;
3632 /* if link is offline nothing more to do */ 3740 /* if link is offline nothing more to do */
3633 if (ata_link_offline(link)) 3741 if (ata_phys_link_offline(link))
3634 goto out; 3742 goto out;
3635 3743
3636 /* Link is online. From this point, -ENODEV too is an error. */ 3744 /* Link is online. From this point, -ENODEV too is an error. */
@@ -4827,10 +4935,8 @@ int sata_scr_valid(struct ata_link *link)
4827int sata_scr_read(struct ata_link *link, int reg, u32 *val) 4935int sata_scr_read(struct ata_link *link, int reg, u32 *val)
4828{ 4936{
4829 if (ata_is_host_link(link)) { 4937 if (ata_is_host_link(link)) {
4830 struct ata_port *ap = link->ap;
4831
4832 if (sata_scr_valid(link)) 4938 if (sata_scr_valid(link))
4833 return ap->ops->scr_read(ap, reg, val); 4939 return link->ap->ops->scr_read(link, reg, val);
4834 return -EOPNOTSUPP; 4940 return -EOPNOTSUPP;
4835 } 4941 }
4836 4942
@@ -4856,10 +4962,8 @@ int sata_scr_read(struct ata_link *link, int reg, u32 *val)
4856int sata_scr_write(struct ata_link *link, int reg, u32 val) 4962int sata_scr_write(struct ata_link *link, int reg, u32 val)
4857{ 4963{
4858 if (ata_is_host_link(link)) { 4964 if (ata_is_host_link(link)) {
4859 struct ata_port *ap = link->ap;
4860
4861 if (sata_scr_valid(link)) 4965 if (sata_scr_valid(link))
4862 return ap->ops->scr_write(ap, reg, val); 4966 return link->ap->ops->scr_write(link, reg, val);
4863 return -EOPNOTSUPP; 4967 return -EOPNOTSUPP;
4864 } 4968 }
4865 4969
@@ -4884,13 +4988,12 @@ int sata_scr_write(struct ata_link *link, int reg, u32 val)
4884int sata_scr_write_flush(struct ata_link *link, int reg, u32 val) 4988int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
4885{ 4989{
4886 if (ata_is_host_link(link)) { 4990 if (ata_is_host_link(link)) {
4887 struct ata_port *ap = link->ap;
4888 int rc; 4991 int rc;
4889 4992
4890 if (sata_scr_valid(link)) { 4993 if (sata_scr_valid(link)) {
4891 rc = ap->ops->scr_write(ap, reg, val); 4994 rc = link->ap->ops->scr_write(link, reg, val);
4892 if (rc == 0) 4995 if (rc == 0)
4893 rc = ap->ops->scr_read(ap, reg, &val); 4996 rc = link->ap->ops->scr_read(link, reg, &val);
4894 return rc; 4997 return rc;
4895 } 4998 }
4896 return -EOPNOTSUPP; 4999 return -EOPNOTSUPP;
@@ -4900,7 +5003,7 @@ int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
4900} 5003}
4901 5004
4902/** 5005/**
4903 * ata_link_online - test whether the given link is online 5006 * ata_phys_link_online - test whether the given link is online
4904 * @link: ATA link to test 5007 * @link: ATA link to test
4905 * 5008 *
4906 * Test whether @link is online. Note that this function returns 5009 * Test whether @link is online. Note that this function returns
@@ -4911,20 +5014,20 @@ int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
4911 * None. 5014 * None.
4912 * 5015 *
4913 * RETURNS: 5016 * RETURNS:
4914 * 1 if the port online status is available and online. 5017 * True if the port online status is available and online.
4915 */ 5018 */
4916int ata_link_online(struct ata_link *link) 5019bool ata_phys_link_online(struct ata_link *link)
4917{ 5020{
4918 u32 sstatus; 5021 u32 sstatus;
4919 5022
4920 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && 5023 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 &&
4921 (sstatus & 0xf) == 0x3) 5024 (sstatus & 0xf) == 0x3)
4922 return 1; 5025 return true;
4923 return 0; 5026 return false;
4924} 5027}
4925 5028
4926/** 5029/**
4927 * ata_link_offline - test whether the given link is offline 5030 * ata_phys_link_offline - test whether the given link is offline
4928 * @link: ATA link to test 5031 * @link: ATA link to test
4929 * 5032 *
4930 * Test whether @link is offline. Note that this function 5033 * Test whether @link is offline. Note that this function
@@ -4935,16 +5038,68 @@ int ata_link_online(struct ata_link *link)
4935 * None. 5038 * None.
4936 * 5039 *
4937 * RETURNS: 5040 * RETURNS:
4938 * 1 if the port offline status is available and offline. 5041 * True if the port offline status is available and offline.
4939 */ 5042 */
4940int ata_link_offline(struct ata_link *link) 5043bool ata_phys_link_offline(struct ata_link *link)
4941{ 5044{
4942 u32 sstatus; 5045 u32 sstatus;
4943 5046
4944 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && 5047 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 &&
4945 (sstatus & 0xf) != 0x3) 5048 (sstatus & 0xf) != 0x3)
4946 return 1; 5049 return true;
4947 return 0; 5050 return false;
5051}
5052
5053/**
5054 * ata_link_online - test whether the given link is online
5055 * @link: ATA link to test
5056 *
5057 * Test whether @link is online. This is identical to
5058 * ata_phys_link_online() when there's no slave link. When
5059 * there's a slave link, this function should only be called on
5060 * the master link and will return true if any of M/S links is
5061 * online.
5062 *
5063 * LOCKING:
5064 * None.
5065 *
5066 * RETURNS:
5067 * True if the port online status is available and online.
5068 */
5069bool ata_link_online(struct ata_link *link)
5070{
5071 struct ata_link *slave = link->ap->slave_link;
5072
5073 WARN_ON(link == slave); /* shouldn't be called on slave link */
5074
5075 return ata_phys_link_online(link) ||
5076 (slave && ata_phys_link_online(slave));
5077}
5078
5079/**
5080 * ata_link_offline - test whether the given link is offline
5081 * @link: ATA link to test
5082 *
5083 * Test whether @link is offline. This is identical to
5084 * ata_phys_link_offline() when there's no slave link. When
5085 * there's a slave link, this function should only be called on
5086 * the master link and will return true if both M/S links are
5087 * offline.
5088 *
5089 * LOCKING:
5090 * None.
5091 *
5092 * RETURNS:
5093 * True if the port offline status is available and offline.
5094 */
5095bool ata_link_offline(struct ata_link *link)
5096{
5097 struct ata_link *slave = link->ap->slave_link;
5098
5099 WARN_ON(link == slave); /* shouldn't be called on slave link */
5100
5101 return ata_phys_link_offline(link) &&
5102 (!slave || ata_phys_link_offline(slave));
4948} 5103}
4949 5104
4950#ifdef CONFIG_PM 5105#ifdef CONFIG_PM
@@ -5086,11 +5241,11 @@ int ata_port_start(struct ata_port *ap)
5086 */ 5241 */
5087void ata_dev_init(struct ata_device *dev) 5242void ata_dev_init(struct ata_device *dev)
5088{ 5243{
5089 struct ata_link *link = dev->link; 5244 struct ata_link *link = ata_dev_phys_link(dev);
5090 struct ata_port *ap = link->ap; 5245 struct ata_port *ap = link->ap;
5091 unsigned long flags; 5246 unsigned long flags;
5092 5247
5093 /* SATA spd limit is bound to the first device */ 5248 /* SATA spd limit is bound to the attached device, reset together */
5094 link->sata_spd_limit = link->hw_sata_spd_limit; 5249 link->sata_spd_limit = link->hw_sata_spd_limit;
5095 link->sata_spd = 0; 5250 link->sata_spd = 0;
5096 5251
@@ -5158,19 +5313,18 @@ void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
5158 */ 5313 */
5159int sata_link_init_spd(struct ata_link *link) 5314int sata_link_init_spd(struct ata_link *link)
5160{ 5315{
5161 u32 scontrol;
5162 u8 spd; 5316 u8 spd;
5163 int rc; 5317 int rc;
5164 5318
5165 rc = sata_scr_read(link, SCR_CONTROL, &scontrol); 5319 rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol);
5166 if (rc) 5320 if (rc)
5167 return rc; 5321 return rc;
5168 5322
5169 spd = (scontrol >> 4) & 0xf; 5323 spd = (link->saved_scontrol >> 4) & 0xf;
5170 if (spd) 5324 if (spd)
5171 link->hw_sata_spd_limit &= (1 << spd) - 1; 5325 link->hw_sata_spd_limit &= (1 << spd) - 1;
5172 5326
5173 ata_force_spd_limit(link); 5327 ata_force_link_limits(link);
5174 5328
5175 link->sata_spd_limit = link->hw_sata_spd_limit; 5329 link->sata_spd_limit = link->hw_sata_spd_limit;
5176 5330
@@ -5224,6 +5378,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
5224 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); 5378 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
5225 INIT_LIST_HEAD(&ap->eh_done_q); 5379 INIT_LIST_HEAD(&ap->eh_done_q);
5226 init_waitqueue_head(&ap->eh_wait_q); 5380 init_waitqueue_head(&ap->eh_wait_q);
5381 init_completion(&ap->park_req_pending);
5227 init_timer_deferrable(&ap->fastdrain_timer); 5382 init_timer_deferrable(&ap->fastdrain_timer);
5228 ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; 5383 ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn;
5229 ap->fastdrain_timer.data = (unsigned long)ap; 5384 ap->fastdrain_timer.data = (unsigned long)ap;
@@ -5254,6 +5409,7 @@ static void ata_host_release(struct device *gendev, void *res)
5254 scsi_host_put(ap->scsi_host); 5409 scsi_host_put(ap->scsi_host);
5255 5410
5256 kfree(ap->pmp_link); 5411 kfree(ap->pmp_link);
5412 kfree(ap->slave_link);
5257 kfree(ap); 5413 kfree(ap);
5258 host->ports[i] = NULL; 5414 host->ports[i] = NULL;
5259 } 5415 }
@@ -5374,6 +5530,68 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,
5374 return host; 5530 return host;
5375} 5531}
5376 5532
5533/**
5534 * ata_slave_link_init - initialize slave link
5535 * @ap: port to initialize slave link for
5536 *
5537 * Create and initialize slave link for @ap. This enables slave
5538 * link handling on the port.
5539 *
5540 * In libata, a port contains links and a link contains devices.
5541 * There is single host link but if a PMP is attached to it,
5542 * there can be multiple fan-out links. On SATA, there's usually
5543 * a single device connected to a link but PATA and SATA
5544 * controllers emulating TF based interface can have two - master
5545 * and slave.
5546 *
5547 * However, there are a few controllers which don't fit into this
5548 * abstraction too well - SATA controllers which emulate TF
5549 * interface with both master and slave devices but also have
5550 * separate SCR register sets for each device. These controllers
5551 * need separate links for physical link handling
5552 * (e.g. onlineness, link speed) but should be treated like a
5553 * traditional M/S controller for everything else (e.g. command
5554 * issue, softreset).
5555 *
5556 * slave_link is libata's way of handling this class of
5557 * controllers without impacting core layer too much. For
5558 * anything other than physical link handling, the default host
5559 * link is used for both master and slave. For physical link
5560 * handling, separate @ap->slave_link is used. All dirty details
5561 * are implemented inside libata core layer. From LLD's POV, the
5562 * only difference is that prereset, hardreset and postreset are
5563 * called once more for the slave link, so the reset sequence
5564 * looks like the following.
5565 *
5566 * prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
5567 * softreset(M) -> postreset(M) -> postreset(S)
5568 *
5569 * Note that softreset is called only for the master. Softreset
5570 * resets both M/S by definition, so SRST on master should handle
5571 * both (the standard method will work just fine).
5572 *
5573 * LOCKING:
5574 * Should be called before host is registered.
5575 *
5576 * RETURNS:
5577 * 0 on success, -errno on failure.
5578 */
5579int ata_slave_link_init(struct ata_port *ap)
5580{
5581 struct ata_link *link;
5582
5583 WARN_ON(ap->slave_link);
5584 WARN_ON(ap->flags & ATA_FLAG_PMP);
5585
5586 link = kzalloc(sizeof(*link), GFP_KERNEL);
5587 if (!link)
5588 return -ENOMEM;
5589
5590 ata_link_init(ap, link, 1);
5591 ap->slave_link = link;
5592 return 0;
5593}
5594
5377static void ata_host_stop(struct device *gendev, void *res) 5595static void ata_host_stop(struct device *gendev, void *res)
5378{ 5596{
5379 struct ata_host *host = dev_get_drvdata(gendev); 5597 struct ata_host *host = dev_get_drvdata(gendev);
@@ -5600,6 +5818,8 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
5600 5818
5601 /* init sata_spd_limit to the current value */ 5819 /* init sata_spd_limit to the current value */
5602 sata_link_init_spd(&ap->link); 5820 sata_link_init_spd(&ap->link);
5821 if (ap->slave_link)
5822 sata_link_init_spd(ap->slave_link);
5603 5823
5604 /* print per-port info to dmesg */ 5824 /* print per-port info to dmesg */
5605 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, 5825 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
@@ -5753,9 +5973,10 @@ static void ata_port_detach(struct ata_port *ap)
5753 ata_port_wait_eh(ap); 5973 ata_port_wait_eh(ap);
5754 5974
5755 /* EH is now guaranteed to see UNLOADING - EH context belongs 5975 /* EH is now guaranteed to see UNLOADING - EH context belongs
5756 * to us. Disable all existing devices. 5976 * to us. Restore SControl and disable all existing devices.
5757 */ 5977 */
5758 ata_port_for_each_link(link, ap) { 5978 __ata_port_for_each_link(link, ap) {
5979 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol);
5759 ata_link_for_each_dev(dev, link) 5980 ata_link_for_each_dev(dev, link)
5760 ata_dev_disable(dev); 5981 ata_dev_disable(dev);
5761 } 5982 }
@@ -5961,6 +6182,9 @@ static int __init ata_parse_force_one(char **cur,
5961 { "udma133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, 6182 { "udma133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) },
5962 { "udma/133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, 6183 { "udma/133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) },
5963 { "udma7", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 7) }, 6184 { "udma7", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 7) },
6185 { "nohrst", .lflags = ATA_LFLAG_NO_HRST },
6186 { "nosrst", .lflags = ATA_LFLAG_NO_SRST },
6187 { "norst", .lflags = ATA_LFLAG_NO_HRST | ATA_LFLAG_NO_SRST },
5964 }; 6188 };
5965 char *start = *cur, *p = *cur; 6189 char *start = *cur, *p = *cur;
5966 char *id, *val, *endp; 6190 char *id, *val, *endp;
@@ -6088,16 +6312,20 @@ static int __init ata_init(void)
6088 6312
6089 ata_wq = create_workqueue("ata"); 6313 ata_wq = create_workqueue("ata");
6090 if (!ata_wq) 6314 if (!ata_wq)
6091 return -ENOMEM; 6315 goto free_force_tbl;
6092 6316
6093 ata_aux_wq = create_singlethread_workqueue("ata_aux"); 6317 ata_aux_wq = create_singlethread_workqueue("ata_aux");
6094 if (!ata_aux_wq) { 6318 if (!ata_aux_wq)
6095 destroy_workqueue(ata_wq); 6319 goto free_wq;
6096 return -ENOMEM;
6097 }
6098 6320
6099 printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); 6321 printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n");
6100 return 0; 6322 return 0;
6323
6324free_wq:
6325 destroy_workqueue(ata_wq);
6326free_force_tbl:
6327 kfree(ata_force_tbl);
6328 return -ENOMEM;
6101} 6329}
6102 6330
6103static void __exit ata_exit(void) 6331static void __exit ata_exit(void)
@@ -6212,10 +6440,12 @@ EXPORT_SYMBOL_GPL(ata_base_port_ops);
6212EXPORT_SYMBOL_GPL(sata_port_ops); 6440EXPORT_SYMBOL_GPL(sata_port_ops);
6213EXPORT_SYMBOL_GPL(ata_dummy_port_ops); 6441EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
6214EXPORT_SYMBOL_GPL(ata_dummy_port_info); 6442EXPORT_SYMBOL_GPL(ata_dummy_port_info);
6443EXPORT_SYMBOL_GPL(__ata_port_next_link);
6215EXPORT_SYMBOL_GPL(ata_std_bios_param); 6444EXPORT_SYMBOL_GPL(ata_std_bios_param);
6216EXPORT_SYMBOL_GPL(ata_host_init); 6445EXPORT_SYMBOL_GPL(ata_host_init);
6217EXPORT_SYMBOL_GPL(ata_host_alloc); 6446EXPORT_SYMBOL_GPL(ata_host_alloc);
6218EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo); 6447EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
6448EXPORT_SYMBOL_GPL(ata_slave_link_init);
6219EXPORT_SYMBOL_GPL(ata_host_start); 6449EXPORT_SYMBOL_GPL(ata_host_start);
6220EXPORT_SYMBOL_GPL(ata_host_register); 6450EXPORT_SYMBOL_GPL(ata_host_register);
6221EXPORT_SYMBOL_GPL(ata_host_activate); 6451EXPORT_SYMBOL_GPL(ata_host_activate);
@@ -6269,6 +6499,7 @@ EXPORT_SYMBOL_GPL(ata_host_resume);
6269#endif /* CONFIG_PM */ 6499#endif /* CONFIG_PM */
6270EXPORT_SYMBOL_GPL(ata_id_string); 6500EXPORT_SYMBOL_GPL(ata_id_string);
6271EXPORT_SYMBOL_GPL(ata_id_c_string); 6501EXPORT_SYMBOL_GPL(ata_id_c_string);
6502EXPORT_SYMBOL_GPL(ata_do_dev_read_id);
6272EXPORT_SYMBOL_GPL(ata_scsi_simulate); 6503EXPORT_SYMBOL_GPL(ata_scsi_simulate);
6273 6504
6274EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 6505EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 58bdc538d229..a93247cc395a 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -33,6 +33,7 @@
33 */ 33 */
34 34
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/blkdev.h>
36#include <linux/pci.h> 37#include <linux/pci.h>
37#include <scsi/scsi.h> 38#include <scsi/scsi.h>
38#include <scsi/scsi_host.h> 39#include <scsi/scsi_host.h>
@@ -79,6 +80,8 @@ enum {
79 */ 80 */
80 ATA_EH_PRERESET_TIMEOUT = 10000, 81 ATA_EH_PRERESET_TIMEOUT = 10000,
81 ATA_EH_FASTDRAIN_INTERVAL = 3000, 82 ATA_EH_FASTDRAIN_INTERVAL = 3000,
83
84 ATA_EH_UA_TRIES = 5,
82}; 85};
83 86
84/* The following table determines how we sequence resets. Each entry 87/* The following table determines how we sequence resets. Each entry
@@ -457,29 +460,29 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
457 * RETURNS: 460 * RETURNS:
458 * EH_HANDLED or EH_NOT_HANDLED 461 * EH_HANDLED or EH_NOT_HANDLED
459 */ 462 */
460enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd) 463enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
461{ 464{
462 struct Scsi_Host *host = cmd->device->host; 465 struct Scsi_Host *host = cmd->device->host;
463 struct ata_port *ap = ata_shost_to_port(host); 466 struct ata_port *ap = ata_shost_to_port(host);
464 unsigned long flags; 467 unsigned long flags;
465 struct ata_queued_cmd *qc; 468 struct ata_queued_cmd *qc;
466 enum scsi_eh_timer_return ret; 469 enum blk_eh_timer_return ret;
467 470
468 DPRINTK("ENTER\n"); 471 DPRINTK("ENTER\n");
469 472
470 if (ap->ops->error_handler) { 473 if (ap->ops->error_handler) {
471 ret = EH_NOT_HANDLED; 474 ret = BLK_EH_NOT_HANDLED;
472 goto out; 475 goto out;
473 } 476 }
474 477
475 ret = EH_HANDLED; 478 ret = BLK_EH_HANDLED;
476 spin_lock_irqsave(ap->lock, flags); 479 spin_lock_irqsave(ap->lock, flags);
477 qc = ata_qc_from_tag(ap, ap->link.active_tag); 480 qc = ata_qc_from_tag(ap, ap->link.active_tag);
478 if (qc) { 481 if (qc) {
479 WARN_ON(qc->scsicmd != cmd); 482 WARN_ON(qc->scsicmd != cmd);
480 qc->flags |= ATA_QCFLAG_EH_SCHEDULED; 483 qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
481 qc->err_mask |= AC_ERR_TIMEOUT; 484 qc->err_mask |= AC_ERR_TIMEOUT;
482 ret = EH_NOT_HANDLED; 485 ret = BLK_EH_NOT_HANDLED;
483 } 486 }
484 spin_unlock_irqrestore(ap->lock, flags); 487 spin_unlock_irqrestore(ap->lock, flags);
485 488
@@ -831,7 +834,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
831 * Note that ATA_QCFLAG_FAILED is unconditionally set after 834 * Note that ATA_QCFLAG_FAILED is unconditionally set after
832 * this function completes. 835 * this function completes.
833 */ 836 */
834 scsi_req_abort_cmd(qc->scsicmd); 837 blk_abort_request(qc->scsicmd->request);
835} 838}
836 839
837/** 840/**
@@ -1357,6 +1360,37 @@ static int ata_eh_read_log_10h(struct ata_device *dev,
1357} 1360}
1358 1361
1359/** 1362/**
1363 * atapi_eh_tur - perform ATAPI TEST_UNIT_READY
1364 * @dev: target ATAPI device
1365 * @r_sense_key: out parameter for sense_key
1366 *
1367 * Perform ATAPI TEST_UNIT_READY.
1368 *
1369 * LOCKING:
1370 * EH context (may sleep).
1371 *
1372 * RETURNS:
1373 * 0 on success, AC_ERR_* mask on failure.
1374 */
1375static unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
1376{
1377 u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 };
1378 struct ata_taskfile tf;
1379 unsigned int err_mask;
1380
1381 ata_tf_init(dev, &tf);
1382
1383 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1384 tf.command = ATA_CMD_PACKET;
1385 tf.protocol = ATAPI_PROT_NODATA;
1386
1387 err_mask = ata_exec_internal(dev, &tf, cdb, DMA_NONE, NULL, 0, 0);
1388 if (err_mask == AC_ERR_DEV)
1389 *r_sense_key = tf.feature >> 4;
1390 return err_mask;
1391}
1392
1393/**
1360 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE 1394 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
1361 * @dev: device to perform REQUEST_SENSE to 1395 * @dev: device to perform REQUEST_SENSE to
1362 * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) 1396 * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
@@ -1756,7 +1790,7 @@ static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
1756static unsigned int ata_eh_speed_down(struct ata_device *dev, 1790static unsigned int ata_eh_speed_down(struct ata_device *dev,
1757 unsigned int eflags, unsigned int err_mask) 1791 unsigned int eflags, unsigned int err_mask)
1758{ 1792{
1759 struct ata_link *link = dev->link; 1793 struct ata_link *link = ata_dev_phys_link(dev);
1760 int xfer_ok = 0; 1794 int xfer_ok = 0;
1761 unsigned int verdict; 1795 unsigned int verdict;
1762 unsigned int action = 0; 1796 unsigned int action = 0;
@@ -1880,7 +1914,8 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1880 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { 1914 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
1881 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); 1915 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1882 1916
1883 if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link) 1917 if (!(qc->flags & ATA_QCFLAG_FAILED) ||
1918 ata_dev_phys_link(qc->dev) != link)
1884 continue; 1919 continue;
1885 1920
1886 /* inherit upper level err_mask */ 1921 /* inherit upper level err_mask */
@@ -1967,6 +2002,23 @@ void ata_eh_autopsy(struct ata_port *ap)
1967 ata_port_for_each_link(link, ap) 2002 ata_port_for_each_link(link, ap)
1968 ata_eh_link_autopsy(link); 2003 ata_eh_link_autopsy(link);
1969 2004
2005 /* Handle the frigging slave link. Autopsy is done similarly
2006 * but actions and flags are transferred over to the master
2007 * link and handled from there.
2008 */
2009 if (ap->slave_link) {
2010 struct ata_eh_context *mehc = &ap->link.eh_context;
2011 struct ata_eh_context *sehc = &ap->slave_link->eh_context;
2012
2013 ata_eh_link_autopsy(ap->slave_link);
2014
2015 ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS);
2016 mehc->i.action |= sehc->i.action;
2017 mehc->i.dev_action[1] |= sehc->i.dev_action[1];
2018 mehc->i.flags |= sehc->i.flags;
2019 ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS);
2020 }
2021
1970 /* Autopsy of fanout ports can affect host link autopsy. 2022 /* Autopsy of fanout ports can affect host link autopsy.
1971 * Perform host link autopsy last. 2023 * Perform host link autopsy last.
1972 */ 2024 */
@@ -2001,7 +2053,8 @@ static void ata_eh_link_report(struct ata_link *link)
2001 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { 2053 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
2002 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); 2054 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
2003 2055
2004 if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link || 2056 if (!(qc->flags & ATA_QCFLAG_FAILED) ||
2057 ata_dev_phys_link(qc->dev) != link ||
2005 ((qc->flags & ATA_QCFLAG_QUIET) && 2058 ((qc->flags & ATA_QCFLAG_QUIET) &&
2006 qc->err_mask == AC_ERR_DEV)) 2059 qc->err_mask == AC_ERR_DEV))
2007 continue; 2060 continue;
@@ -2040,7 +2093,7 @@ static void ata_eh_link_report(struct ata_link *link)
2040 } 2093 }
2041 2094
2042 if (ehc->i.serror) 2095 if (ehc->i.serror)
2043 ata_port_printk(ap, KERN_ERR, 2096 ata_link_printk(link, KERN_ERR,
2044 "SError: { %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s}\n", 2097 "SError: { %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s}\n",
2045 ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "", 2098 ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "",
2046 ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "", 2099 ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "",
@@ -2068,7 +2121,7 @@ static void ata_eh_link_report(struct ata_link *link)
2068 char cdb_buf[70] = ""; 2121 char cdb_buf[70] = "";
2069 2122
2070 if (!(qc->flags & ATA_QCFLAG_FAILED) || 2123 if (!(qc->flags & ATA_QCFLAG_FAILED) ||
2071 qc->dev->link != link || !qc->err_mask) 2124 ata_dev_phys_link(qc->dev) != link || !qc->err_mask)
2072 continue; 2125 continue;
2073 2126
2074 if (qc->dma_dir != DMA_NONE) { 2127 if (qc->dma_dir != DMA_NONE) {
@@ -2160,29 +2213,25 @@ void ata_eh_report(struct ata_port *ap)
2160} 2213}
2161 2214
2162static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset, 2215static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
2163 unsigned int *classes, unsigned long deadline) 2216 unsigned int *classes, unsigned long deadline,
2217 bool clear_classes)
2164{ 2218{
2165 struct ata_device *dev; 2219 struct ata_device *dev;
2166 2220
2167 ata_link_for_each_dev(dev, link) 2221 if (clear_classes)
2168 classes[dev->devno] = ATA_DEV_UNKNOWN; 2222 ata_link_for_each_dev(dev, link)
2223 classes[dev->devno] = ATA_DEV_UNKNOWN;
2169 2224
2170 return reset(link, classes, deadline); 2225 return reset(link, classes, deadline);
2171} 2226}
2172 2227
2173static int ata_eh_followup_srst_needed(struct ata_link *link, 2228static int ata_eh_followup_srst_needed(struct ata_link *link,
2174 int rc, int classify, 2229 int rc, const unsigned int *classes)
2175 const unsigned int *classes)
2176{ 2230{
2177 if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link)) 2231 if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link))
2178 return 0; 2232 return 0;
2179 if (rc == -EAGAIN) { 2233 if (rc == -EAGAIN)
2180 if (classify) 2234 return 1;
2181 return 1;
2182 rc = 0;
2183 }
2184 if (rc != 0)
2185 return 0;
2186 if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) 2235 if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
2187 return 1; 2236 return 1;
2188 return 0; 2237 return 0;
@@ -2193,23 +2242,30 @@ int ata_eh_reset(struct ata_link *link, int classify,
2193 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset) 2242 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
2194{ 2243{
2195 struct ata_port *ap = link->ap; 2244 struct ata_port *ap = link->ap;
2245 struct ata_link *slave = ap->slave_link;
2196 struct ata_eh_context *ehc = &link->eh_context; 2246 struct ata_eh_context *ehc = &link->eh_context;
2247 struct ata_eh_context *sehc = &slave->eh_context;
2197 unsigned int *classes = ehc->classes; 2248 unsigned int *classes = ehc->classes;
2198 unsigned int lflags = link->flags; 2249 unsigned int lflags = link->flags;
2199 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); 2250 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
2200 int max_tries = 0, try = 0; 2251 int max_tries = 0, try = 0;
2252 struct ata_link *failed_link;
2201 struct ata_device *dev; 2253 struct ata_device *dev;
2202 unsigned long deadline, now; 2254 unsigned long deadline, now;
2203 ata_reset_fn_t reset; 2255 ata_reset_fn_t reset;
2204 unsigned long flags; 2256 unsigned long flags;
2205 u32 sstatus; 2257 u32 sstatus;
2206 int nr_known, rc; 2258 int nr_unknown, rc;
2207 2259
2208 /* 2260 /*
2209 * Prepare to reset 2261 * Prepare to reset
2210 */ 2262 */
2211 while (ata_eh_reset_timeouts[max_tries] != ULONG_MAX) 2263 while (ata_eh_reset_timeouts[max_tries] != ULONG_MAX)
2212 max_tries++; 2264 max_tries++;
2265 if (link->flags & ATA_LFLAG_NO_HRST)
2266 hardreset = NULL;
2267 if (link->flags & ATA_LFLAG_NO_SRST)
2268 softreset = NULL;
2213 2269
2214 now = jiffies; 2270 now = jiffies;
2215 deadline = ata_deadline(ehc->last_reset, ATA_EH_RESET_COOL_DOWN); 2271 deadline = ata_deadline(ehc->last_reset, ATA_EH_RESET_COOL_DOWN);
@@ -2247,15 +2303,37 @@ int ata_eh_reset(struct ata_link *link, int classify,
2247 ehc->i.action &= ~ATA_EH_RESET; 2303 ehc->i.action &= ~ATA_EH_RESET;
2248 if (hardreset) { 2304 if (hardreset) {
2249 reset = hardreset; 2305 reset = hardreset;
2250 ehc->i.action = ATA_EH_HARDRESET; 2306 ehc->i.action |= ATA_EH_HARDRESET;
2251 } else if (softreset) { 2307 } else if (softreset) {
2252 reset = softreset; 2308 reset = softreset;
2253 ehc->i.action = ATA_EH_SOFTRESET; 2309 ehc->i.action |= ATA_EH_SOFTRESET;
2254 } 2310 }
2255 2311
2256 if (prereset) { 2312 if (prereset) {
2257 rc = prereset(link, 2313 unsigned long deadline = ata_deadline(jiffies,
2258 ata_deadline(jiffies, ATA_EH_PRERESET_TIMEOUT)); 2314 ATA_EH_PRERESET_TIMEOUT);
2315
2316 if (slave) {
2317 sehc->i.action &= ~ATA_EH_RESET;
2318 sehc->i.action |= ehc->i.action;
2319 }
2320
2321 rc = prereset(link, deadline);
2322
2323 /* If present, do prereset on slave link too. Reset
2324 * is skipped iff both master and slave links report
2325 * -ENOENT or clear ATA_EH_RESET.
2326 */
2327 if (slave && (rc == 0 || rc == -ENOENT)) {
2328 int tmp;
2329
2330 tmp = prereset(slave, deadline);
2331 if (tmp != -ENOENT)
2332 rc = tmp;
2333
2334 ehc->i.action |= sehc->i.action;
2335 }
2336
2259 if (rc) { 2337 if (rc) {
2260 if (rc == -ENOENT) { 2338 if (rc == -ENOENT) {
2261 ata_link_printk(link, KERN_DEBUG, 2339 ata_link_printk(link, KERN_DEBUG,
@@ -2304,28 +2382,52 @@ int ata_eh_reset(struct ata_link *link, int classify,
2304 else 2382 else
2305 ehc->i.flags |= ATA_EHI_DID_SOFTRESET; 2383 ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
2306 2384
2307 rc = ata_do_reset(link, reset, classes, deadline); 2385 rc = ata_do_reset(link, reset, classes, deadline, true);
2386 if (rc && rc != -EAGAIN) {
2387 failed_link = link;
2388 goto fail;
2389 }
2390
2391 /* hardreset slave link if existent */
2392 if (slave && reset == hardreset) {
2393 int tmp;
2308 2394
2395 if (verbose)
2396 ata_link_printk(slave, KERN_INFO,
2397 "hard resetting link\n");
2398
2399 ata_eh_about_to_do(slave, NULL, ATA_EH_RESET);
2400 tmp = ata_do_reset(slave, reset, classes, deadline,
2401 false);
2402 switch (tmp) {
2403 case -EAGAIN:
2404 rc = -EAGAIN;
2405 case 0:
2406 break;
2407 default:
2408 failed_link = slave;
2409 rc = tmp;
2410 goto fail;
2411 }
2412 }
2413
2414 /* perform follow-up SRST if necessary */
2309 if (reset == hardreset && 2415 if (reset == hardreset &&
2310 ata_eh_followup_srst_needed(link, rc, classify, classes)) { 2416 ata_eh_followup_srst_needed(link, rc, classes)) {
2311 /* okay, let's do follow-up softreset */
2312 reset = softreset; 2417 reset = softreset;
2313 2418
2314 if (!reset) { 2419 if (!reset) {
2315 ata_link_printk(link, KERN_ERR, 2420 ata_link_printk(link, KERN_ERR,
2316 "follow-up softreset required " 2421 "follow-up softreset required "
2317 "but no softreset avaliable\n"); 2422 "but no softreset avaliable\n");
2423 failed_link = link;
2318 rc = -EINVAL; 2424 rc = -EINVAL;
2319 goto fail; 2425 goto fail;
2320 } 2426 }
2321 2427
2322 ata_eh_about_to_do(link, NULL, ATA_EH_RESET); 2428 ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
2323 rc = ata_do_reset(link, reset, classes, deadline); 2429 rc = ata_do_reset(link, reset, classes, deadline, true);
2324 } 2430 }
2325
2326 /* -EAGAIN can happen if we skipped followup SRST */
2327 if (rc && rc != -EAGAIN)
2328 goto fail;
2329 } else { 2431 } else {
2330 if (verbose) 2432 if (verbose)
2331 ata_link_printk(link, KERN_INFO, "no reset method " 2433 ata_link_printk(link, KERN_INFO, "no reset method "
@@ -2345,7 +2447,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2345 dev->pio_mode = XFER_PIO_0; 2447 dev->pio_mode = XFER_PIO_0;
2346 dev->flags &= ~ATA_DFLAG_SLEEPING; 2448 dev->flags &= ~ATA_DFLAG_SLEEPING;
2347 2449
2348 if (ata_link_offline(link)) 2450 if (ata_phys_link_offline(ata_dev_phys_link(dev)))
2349 continue; 2451 continue;
2350 2452
2351 /* apply class override */ 2453 /* apply class override */
@@ -2358,6 +2460,8 @@ int ata_eh_reset(struct ata_link *link, int classify,
2358 /* record current link speed */ 2460 /* record current link speed */
2359 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0) 2461 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
2360 link->sata_spd = (sstatus >> 4) & 0xf; 2462 link->sata_spd = (sstatus >> 4) & 0xf;
2463 if (slave && sata_scr_read(slave, SCR_STATUS, &sstatus) == 0)
2464 slave->sata_spd = (sstatus >> 4) & 0xf;
2361 2465
2362 /* thaw the port */ 2466 /* thaw the port */
2363 if (ata_is_host_link(link)) 2467 if (ata_is_host_link(link))
@@ -2370,12 +2474,17 @@ int ata_eh_reset(struct ata_link *link, int classify,
2370 * reset and here. This race is mediated by cross checking 2474 * reset and here. This race is mediated by cross checking
2371 * link onlineness and classification result later. 2475 * link onlineness and classification result later.
2372 */ 2476 */
2373 if (postreset) 2477 if (postreset) {
2374 postreset(link, classes); 2478 postreset(link, classes);
2479 if (slave)
2480 postreset(slave, classes);
2481 }
2375 2482
2376 /* clear cached SError */ 2483 /* clear cached SError */
2377 spin_lock_irqsave(link->ap->lock, flags); 2484 spin_lock_irqsave(link->ap->lock, flags);
2378 link->eh_info.serror = 0; 2485 link->eh_info.serror = 0;
2486 if (slave)
2487 slave->eh_info.serror = 0;
2379 spin_unlock_irqrestore(link->ap->lock, flags); 2488 spin_unlock_irqrestore(link->ap->lock, flags);
2380 2489
2381 /* Make sure onlineness and classification result correspond. 2490 /* Make sure onlineness and classification result correspond.
@@ -2385,19 +2494,21 @@ int ata_eh_reset(struct ata_link *link, int classify,
2385 * link onlineness and classification result, those conditions 2494 * link onlineness and classification result, those conditions
2386 * can be reliably detected and retried. 2495 * can be reliably detected and retried.
2387 */ 2496 */
2388 nr_known = 0; 2497 nr_unknown = 0;
2389 ata_link_for_each_dev(dev, link) { 2498 ata_link_for_each_dev(dev, link) {
2390 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */ 2499 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */
2391 if (classes[dev->devno] == ATA_DEV_UNKNOWN) 2500 if (classes[dev->devno] == ATA_DEV_UNKNOWN) {
2392 classes[dev->devno] = ATA_DEV_NONE; 2501 classes[dev->devno] = ATA_DEV_NONE;
2393 else 2502 if (ata_phys_link_online(ata_dev_phys_link(dev)))
2394 nr_known++; 2503 nr_unknown++;
2504 }
2395 } 2505 }
2396 2506
2397 if (classify && !nr_known && ata_link_online(link)) { 2507 if (classify && nr_unknown) {
2398 if (try < max_tries) { 2508 if (try < max_tries) {
2399 ata_link_printk(link, KERN_WARNING, "link online but " 2509 ata_link_printk(link, KERN_WARNING, "link online but "
2400 "device misclassified, retrying\n"); 2510 "device misclassified, retrying\n");
2511 failed_link = link;
2401 rc = -EAGAIN; 2512 rc = -EAGAIN;
2402 goto fail; 2513 goto fail;
2403 } 2514 }
@@ -2408,6 +2519,8 @@ int ata_eh_reset(struct ata_link *link, int classify,
2408 2519
2409 /* reset successful, schedule revalidation */ 2520 /* reset successful, schedule revalidation */
2410 ata_eh_done(link, NULL, ATA_EH_RESET); 2521 ata_eh_done(link, NULL, ATA_EH_RESET);
2522 if (slave)
2523 ata_eh_done(slave, NULL, ATA_EH_RESET);
2411 ehc->last_reset = jiffies; 2524 ehc->last_reset = jiffies;
2412 ehc->i.action |= ATA_EH_REVALIDATE; 2525 ehc->i.action |= ATA_EH_REVALIDATE;
2413 2526
@@ -2415,6 +2528,8 @@ int ata_eh_reset(struct ata_link *link, int classify,
2415 out: 2528 out:
2416 /* clear hotplug flag */ 2529 /* clear hotplug flag */
2417 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; 2530 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
2531 if (slave)
2532 sehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
2418 2533
2419 spin_lock_irqsave(ap->lock, flags); 2534 spin_lock_irqsave(ap->lock, flags);
2420 ap->pflags &= ~ATA_PFLAG_RESETTING; 2535 ap->pflags &= ~ATA_PFLAG_RESETTING;
@@ -2435,7 +2550,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2435 if (time_before(now, deadline)) { 2550 if (time_before(now, deadline)) {
2436 unsigned long delta = deadline - now; 2551 unsigned long delta = deadline - now;
2437 2552
2438 ata_link_printk(link, KERN_WARNING, 2553 ata_link_printk(failed_link, KERN_WARNING,
2439 "reset failed (errno=%d), retrying in %u secs\n", 2554 "reset failed (errno=%d), retrying in %u secs\n",
2440 rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); 2555 rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000));
2441 2556
@@ -2443,13 +2558,92 @@ int ata_eh_reset(struct ata_link *link, int classify,
2443 delta = schedule_timeout_uninterruptible(delta); 2558 delta = schedule_timeout_uninterruptible(delta);
2444 } 2559 }
2445 2560
2446 if (rc == -EPIPE || try == max_tries - 1) 2561 if (try == max_tries - 1) {
2447 sata_down_spd_limit(link); 2562 sata_down_spd_limit(link);
2563 if (slave)
2564 sata_down_spd_limit(slave);
2565 } else if (rc == -EPIPE)
2566 sata_down_spd_limit(failed_link);
2567
2448 if (hardreset) 2568 if (hardreset)
2449 reset = hardreset; 2569 reset = hardreset;
2450 goto retry; 2570 goto retry;
2451} 2571}
2452 2572
2573static inline void ata_eh_pull_park_action(struct ata_port *ap)
2574{
2575 struct ata_link *link;
2576 struct ata_device *dev;
2577 unsigned long flags;
2578
2579 /*
2580 * This function can be thought of as an extended version of
2581 * ata_eh_about_to_do() specially crafted to accommodate the
2582 * requirements of ATA_EH_PARK handling. Since the EH thread
2583 * does not leave the do {} while () loop in ata_eh_recover as
2584 * long as the timeout for a park request to *one* device on
2585 * the port has not expired, and since we still want to pick
2586 * up park requests to other devices on the same port or
2587 * timeout updates for the same device, we have to pull
2588 * ATA_EH_PARK actions from eh_info into eh_context.i
2589 * ourselves at the beginning of each pass over the loop.
2590 *
2591 * Additionally, all write accesses to &ap->park_req_pending
2592 * through INIT_COMPLETION() (see below) or complete_all()
2593 * (see ata_scsi_park_store()) are protected by the host lock.
2594 * As a result we have that park_req_pending.done is zero on
2595 * exit from this function, i.e. when ATA_EH_PARK actions for
2596 * *all* devices on port ap have been pulled into the
2597 * respective eh_context structs. If, and only if,
2598 * park_req_pending.done is non-zero by the time we reach
2599 * wait_for_completion_timeout(), another ATA_EH_PARK action
2600 * has been scheduled for at least one of the devices on port
2601 * ap and we have to cycle over the do {} while () loop in
2602 * ata_eh_recover() again.
2603 */
2604
2605 spin_lock_irqsave(ap->lock, flags);
2606 INIT_COMPLETION(ap->park_req_pending);
2607 ata_port_for_each_link(link, ap) {
2608 ata_link_for_each_dev(dev, link) {
2609 struct ata_eh_info *ehi = &link->eh_info;
2610
2611 link->eh_context.i.dev_action[dev->devno] |=
2612 ehi->dev_action[dev->devno] & ATA_EH_PARK;
2613 ata_eh_clear_action(link, dev, ehi, ATA_EH_PARK);
2614 }
2615 }
2616 spin_unlock_irqrestore(ap->lock, flags);
2617}
2618
2619static void ata_eh_park_issue_cmd(struct ata_device *dev, int park)
2620{
2621 struct ata_eh_context *ehc = &dev->link->eh_context;
2622 struct ata_taskfile tf;
2623 unsigned int err_mask;
2624
2625 ata_tf_init(dev, &tf);
2626 if (park) {
2627 ehc->unloaded_mask |= 1 << dev->devno;
2628 tf.command = ATA_CMD_IDLEIMMEDIATE;
2629 tf.feature = 0x44;
2630 tf.lbal = 0x4c;
2631 tf.lbam = 0x4e;
2632 tf.lbah = 0x55;
2633 } else {
2634 ehc->unloaded_mask &= ~(1 << dev->devno);
2635 tf.command = ATA_CMD_CHK_POWER;
2636 }
2637
2638 tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
2639 tf.protocol |= ATA_PROT_NODATA;
2640 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
2641 if (park && (err_mask || tf.lbal != 0xc4)) {
2642 ata_dev_printk(dev, KERN_ERR, "head unload failed!\n");
2643 ehc->unloaded_mask &= ~(1 << dev->devno);
2644 }
2645}
2646
2453static int ata_eh_revalidate_and_attach(struct ata_link *link, 2647static int ata_eh_revalidate_and_attach(struct ata_link *link,
2454 struct ata_device **r_failed_dev) 2648 struct ata_device **r_failed_dev)
2455{ 2649{
@@ -2476,7 +2670,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
2476 if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { 2670 if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
2477 WARN_ON(dev->class == ATA_DEV_PMP); 2671 WARN_ON(dev->class == ATA_DEV_PMP);
2478 2672
2479 if (ata_link_offline(link)) { 2673 if (ata_phys_link_offline(ata_dev_phys_link(dev))) {
2480 rc = -EIO; 2674 rc = -EIO;
2481 goto err; 2675 goto err;
2482 } 2676 }
@@ -2614,6 +2808,53 @@ int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
2614 return rc; 2808 return rc;
2615} 2809}
2616 2810
2811/**
2812 * atapi_eh_clear_ua - Clear ATAPI UNIT ATTENTION after reset
2813 * @dev: ATAPI device to clear UA for
2814 *
2815 * Resets and other operations can make an ATAPI device raise
2816 * UNIT ATTENTION which causes the next operation to fail. This
2817 * function clears UA.
2818 *
2819 * LOCKING:
2820 * EH context (may sleep).
2821 *
2822 * RETURNS:
2823 * 0 on success, -errno on failure.
2824 */
2825static int atapi_eh_clear_ua(struct ata_device *dev)
2826{
2827 int i;
2828
2829 for (i = 0; i < ATA_EH_UA_TRIES; i++) {
2830 u8 sense_buffer[SCSI_SENSE_BUFFERSIZE];
2831 u8 sense_key = 0;
2832 unsigned int err_mask;
2833
2834 err_mask = atapi_eh_tur(dev, &sense_key);
2835 if (err_mask != 0 && err_mask != AC_ERR_DEV) {
2836 ata_dev_printk(dev, KERN_WARNING, "TEST_UNIT_READY "
2837 "failed (err_mask=0x%x)\n", err_mask);
2838 return -EIO;
2839 }
2840
2841 if (!err_mask || sense_key != UNIT_ATTENTION)
2842 return 0;
2843
2844 err_mask = atapi_eh_request_sense(dev, sense_buffer, sense_key);
2845 if (err_mask) {
2846 ata_dev_printk(dev, KERN_WARNING, "failed to clear "
2847 "UNIT ATTENTION (err_mask=0x%x)\n", err_mask);
2848 return -EIO;
2849 }
2850 }
2851
2852 ata_dev_printk(dev, KERN_WARNING,
2853 "UNIT ATTENTION persists after %d tries\n", ATA_EH_UA_TRIES);
2854
2855 return 0;
2856}
2857
2617static int ata_link_nr_enabled(struct ata_link *link) 2858static int ata_link_nr_enabled(struct ata_link *link)
2618{ 2859{
2619 struct ata_device *dev; 2860 struct ata_device *dev;
@@ -2701,7 +2942,7 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2701 /* This is the last chance, better to slow 2942 /* This is the last chance, better to slow
2702 * down than lose it. 2943 * down than lose it.
2703 */ 2944 */
2704 sata_down_spd_limit(dev->link); 2945 sata_down_spd_limit(ata_dev_phys_link(dev));
2705 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); 2946 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
2706 } 2947 }
2707 } 2948 }
@@ -2711,7 +2952,7 @@ static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2711 ata_dev_disable(dev); 2952 ata_dev_disable(dev);
2712 2953
2713 /* detach if offline */ 2954 /* detach if offline */
2714 if (ata_link_offline(dev->link)) 2955 if (ata_phys_link_offline(ata_dev_phys_link(dev)))
2715 ata_eh_detach_dev(dev); 2956 ata_eh_detach_dev(dev);
2716 2957
2717 /* schedule probe if necessary */ 2958 /* schedule probe if necessary */
@@ -2759,7 +3000,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2759 struct ata_device *dev; 3000 struct ata_device *dev;
2760 int nr_failed_devs; 3001 int nr_failed_devs;
2761 int rc; 3002 int rc;
2762 unsigned long flags; 3003 unsigned long flags, deadline;
2763 3004
2764 DPRINTK("ENTER\n"); 3005 DPRINTK("ENTER\n");
2765 3006
@@ -2833,6 +3074,56 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2833 } 3074 }
2834 } 3075 }
2835 3076
3077 do {
3078 unsigned long now;
3079
3080 /*
3081 * clears ATA_EH_PARK in eh_info and resets
3082 * ap->park_req_pending
3083 */
3084 ata_eh_pull_park_action(ap);
3085
3086 deadline = jiffies;
3087 ata_port_for_each_link(link, ap) {
3088 ata_link_for_each_dev(dev, link) {
3089 struct ata_eh_context *ehc = &link->eh_context;
3090 unsigned long tmp;
3091
3092 if (dev->class != ATA_DEV_ATA)
3093 continue;
3094 if (!(ehc->i.dev_action[dev->devno] &
3095 ATA_EH_PARK))
3096 continue;
3097 tmp = dev->unpark_deadline;
3098 if (time_before(deadline, tmp))
3099 deadline = tmp;
3100 else if (time_before_eq(tmp, jiffies))
3101 continue;
3102 if (ehc->unloaded_mask & (1 << dev->devno))
3103 continue;
3104
3105 ata_eh_park_issue_cmd(dev, 1);
3106 }
3107 }
3108
3109 now = jiffies;
3110 if (time_before_eq(deadline, now))
3111 break;
3112
3113 deadline = wait_for_completion_timeout(&ap->park_req_pending,
3114 deadline - now);
3115 } while (deadline);
3116 ata_port_for_each_link(link, ap) {
3117 ata_link_for_each_dev(dev, link) {
3118 if (!(link->eh_context.unloaded_mask &
3119 (1 << dev->devno)))
3120 continue;
3121
3122 ata_eh_park_issue_cmd(dev, 0);
3123 ata_eh_done(link, dev, ATA_EH_PARK);
3124 }
3125 }
3126
2836 /* the rest */ 3127 /* the rest */
2837 ata_port_for_each_link(link, ap) { 3128 ata_port_for_each_link(link, ap) {
2838 struct ata_eh_context *ehc = &link->eh_context; 3129 struct ata_eh_context *ehc = &link->eh_context;
@@ -2856,6 +3147,20 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2856 ehc->i.flags &= ~ATA_EHI_SETMODE; 3147 ehc->i.flags &= ~ATA_EHI_SETMODE;
2857 } 3148 }
2858 3149
3150 /* If reset has been issued, clear UA to avoid
3151 * disrupting the current users of the device.
3152 */
3153 if (ehc->i.flags & ATA_EHI_DID_RESET) {
3154 ata_link_for_each_dev(dev, link) {
3155 if (dev->class != ATA_DEV_ATAPI)
3156 continue;
3157 rc = atapi_eh_clear_ua(dev);
3158 if (rc)
3159 goto dev_fail;
3160 }
3161 }
3162
3163 /* configure link power saving */
2859 if (ehc->i.action & ATA_EH_LPM) 3164 if (ehc->i.action & ATA_EH_LPM)
2860 ata_link_for_each_dev(dev, link) 3165 ata_link_for_each_dev(dev, link)
2861 ata_dev_enable_pm(dev, ap->pm_policy); 3166 ata_dev_enable_pm(dev, ap->pm_policy);
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index f3b4b15a8dc4..5d312dc9be9f 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -183,6 +183,105 @@ DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR,
183 ata_scsi_lpm_show, ata_scsi_lpm_put); 183 ata_scsi_lpm_show, ata_scsi_lpm_put);
184EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy); 184EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy);
185 185
186static ssize_t ata_scsi_park_show(struct device *device,
187 struct device_attribute *attr, char *buf)
188{
189 struct scsi_device *sdev = to_scsi_device(device);
190 struct ata_port *ap;
191 struct ata_link *link;
192 struct ata_device *dev;
193 unsigned long flags;
194 unsigned int uninitialized_var(msecs);
195 int rc = 0;
196
197 ap = ata_shost_to_port(sdev->host);
198
199 spin_lock_irqsave(ap->lock, flags);
200 dev = ata_scsi_find_dev(ap, sdev);
201 if (!dev) {
202 rc = -ENODEV;
203 goto unlock;
204 }
205 if (dev->flags & ATA_DFLAG_NO_UNLOAD) {
206 rc = -EOPNOTSUPP;
207 goto unlock;
208 }
209
210 link = dev->link;
211 if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS &&
212 link->eh_context.unloaded_mask & (1 << dev->devno) &&
213 time_after(dev->unpark_deadline, jiffies))
214 msecs = jiffies_to_msecs(dev->unpark_deadline - jiffies);
215 else
216 msecs = 0;
217
218unlock:
219 spin_unlock_irq(ap->lock);
220
221 return rc ? rc : snprintf(buf, 20, "%u\n", msecs);
222}
223
224static ssize_t ata_scsi_park_store(struct device *device,
225 struct device_attribute *attr,
226 const char *buf, size_t len)
227{
228 struct scsi_device *sdev = to_scsi_device(device);
229 struct ata_port *ap;
230 struct ata_device *dev;
231 long int input;
232 unsigned long flags;
233 int rc;
234
235 rc = strict_strtol(buf, 10, &input);
236 if (rc || input < -2)
237 return -EINVAL;
238 if (input > ATA_TMOUT_MAX_PARK) {
239 rc = -EOVERFLOW;
240 input = ATA_TMOUT_MAX_PARK;
241 }
242
243 ap = ata_shost_to_port(sdev->host);
244
245 spin_lock_irqsave(ap->lock, flags);
246 dev = ata_scsi_find_dev(ap, sdev);
247 if (unlikely(!dev)) {
248 rc = -ENODEV;
249 goto unlock;
250 }
251 if (dev->class != ATA_DEV_ATA) {
252 rc = -EOPNOTSUPP;
253 goto unlock;
254 }
255
256 if (input >= 0) {
257 if (dev->flags & ATA_DFLAG_NO_UNLOAD) {
258 rc = -EOPNOTSUPP;
259 goto unlock;
260 }
261
262 dev->unpark_deadline = ata_deadline(jiffies, input);
263 dev->link->eh_info.dev_action[dev->devno] |= ATA_EH_PARK;
264 ata_port_schedule_eh(ap);
265 complete(&ap->park_req_pending);
266 } else {
267 switch (input) {
268 case -1:
269 dev->flags &= ~ATA_DFLAG_NO_UNLOAD;
270 break;
271 case -2:
272 dev->flags |= ATA_DFLAG_NO_UNLOAD;
273 break;
274 }
275 }
276unlock:
277 spin_unlock_irqrestore(ap->lock, flags);
278
279 return rc ? rc : len;
280}
281DEVICE_ATTR(unload_heads, S_IRUGO | S_IWUSR,
282 ata_scsi_park_show, ata_scsi_park_store);
283EXPORT_SYMBOL_GPL(dev_attr_unload_heads);
284
186static void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq) 285static void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq)
187{ 286{
188 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; 287 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
@@ -269,6 +368,12 @@ DEVICE_ATTR(sw_activity, S_IWUGO | S_IRUGO, ata_scsi_activity_show,
269 ata_scsi_activity_store); 368 ata_scsi_activity_store);
270EXPORT_SYMBOL_GPL(dev_attr_sw_activity); 369EXPORT_SYMBOL_GPL(dev_attr_sw_activity);
271 370
371struct device_attribute *ata_common_sdev_attrs[] = {
372 &dev_attr_unload_heads,
373 NULL
374};
375EXPORT_SYMBOL_GPL(ata_common_sdev_attrs);
376
272static void ata_scsi_invalid_field(struct scsi_cmnd *cmd, 377static void ata_scsi_invalid_field(struct scsi_cmnd *cmd,
273 void (*done)(struct scsi_cmnd *)) 378 void (*done)(struct scsi_cmnd *))
274{ 379{
@@ -398,7 +503,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
398 scsi_cmd[0] = ATA_16; 503 scsi_cmd[0] = ATA_16;
399 504
400 scsi_cmd[4] = args[2]; 505 scsi_cmd[4] = args[2];
401 if (args[0] == WIN_SMART) { /* hack -- ide driver does this too... */ 506 if (args[0] == ATA_CMD_SMART) { /* hack -- ide driver does this too */
402 scsi_cmd[6] = args[3]; 507 scsi_cmd[6] = args[3];
403 scsi_cmd[8] = args[1]; 508 scsi_cmd[8] = args[1];
404 scsi_cmd[10] = 0x4f; 509 scsi_cmd[10] = 0x4f;
@@ -954,6 +1059,9 @@ static int atapi_drain_needed(struct request *rq)
954static int ata_scsi_dev_config(struct scsi_device *sdev, 1059static int ata_scsi_dev_config(struct scsi_device *sdev,
955 struct ata_device *dev) 1060 struct ata_device *dev)
956{ 1061{
1062 if (!ata_id_has_unload(dev->id))
1063 dev->flags |= ATA_DFLAG_NO_UNLOAD;
1064
957 /* configure max sectors */ 1065 /* configure max sectors */
958 blk_queue_max_sectors(sdev->request_queue, dev->max_sectors); 1066 blk_queue_max_sectors(sdev->request_queue, dev->max_sectors);
959 1067
@@ -977,6 +1085,10 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
977 1085
978 blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN); 1086 blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN);
979 } else { 1087 } else {
1088 if (ata_id_is_ssd(dev->id))
1089 queue_flag_set_unlocked(QUEUE_FLAG_NONROT,
1090 sdev->request_queue);
1091
980 /* ATA devices must be sector aligned */ 1092 /* ATA devices must be sector aligned */
981 blk_queue_update_dma_alignment(sdev->request_queue, 1093 blk_queue_update_dma_alignment(sdev->request_queue,
982 ATA_SECT_SIZE - 1); 1094 ATA_SECT_SIZE - 1);
@@ -2551,36 +2663,6 @@ static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap,
2551} 2663}
2552 2664
2553/** 2665/**
2554 * ata_scsi_dev_enabled - determine if device is enabled
2555 * @dev: ATA device
2556 *
2557 * Determine if commands should be sent to the specified device.
2558 *
2559 * LOCKING:
2560 * spin_lock_irqsave(host lock)
2561 *
2562 * RETURNS:
2563 * 0 if commands are not allowed / 1 if commands are allowed
2564 */
2565
2566static int ata_scsi_dev_enabled(struct ata_device *dev)
2567{
2568 if (unlikely(!ata_dev_enabled(dev)))
2569 return 0;
2570
2571 if (!atapi_enabled || (dev->link->ap->flags & ATA_FLAG_NO_ATAPI)) {
2572 if (unlikely(dev->class == ATA_DEV_ATAPI)) {
2573 ata_dev_printk(dev, KERN_WARNING,
2574 "WARNING: ATAPI is %s, device ignored.\n",
2575 atapi_enabled ? "not supported with this driver" : "disabled");
2576 return 0;
2577 }
2578 }
2579
2580 return 1;
2581}
2582
2583/**
2584 * ata_scsi_find_dev - lookup ata_device from scsi_cmnd 2666 * ata_scsi_find_dev - lookup ata_device from scsi_cmnd
2585 * @ap: ATA port to which the device is attached 2667 * @ap: ATA port to which the device is attached
2586 * @scsidev: SCSI device from which we derive the ATA device 2668 * @scsidev: SCSI device from which we derive the ATA device
@@ -2601,7 +2683,7 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
2601{ 2683{
2602 struct ata_device *dev = __ata_scsi_find_dev(ap, scsidev); 2684 struct ata_device *dev = __ata_scsi_find_dev(ap, scsidev);
2603 2685
2604 if (unlikely(!dev || !ata_scsi_dev_enabled(dev))) 2686 if (unlikely(!dev || !ata_dev_enabled(dev)))
2605 return NULL; 2687 return NULL;
2606 2688
2607 return dev; 2689 return dev;
@@ -3622,7 +3704,7 @@ int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
3622 3704
3623 ata_scsi_dump_cdb(ap, cmd); 3705 ata_scsi_dump_cdb(ap, cmd);
3624 3706
3625 if (likely(ata_scsi_dev_enabled(ap->link.device))) 3707 if (likely(ata_dev_enabled(ap->link.device)))
3626 rc = __ata_scsi_queuecmd(cmd, done, ap->link.device); 3708 rc = __ata_scsi_queuecmd(cmd, done, ap->link.device);
3627 else { 3709 else {
3628 cmd->result = (DID_BAD_TARGET << 16); 3710 cmd->result = (DID_BAD_TARGET << 16);
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 304fdc6f1dc2..2a4c516894f0 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -1315,11 +1315,6 @@ fsm_start:
1315 break; 1315 break;
1316 1316
1317 case HSM_ST_ERR: 1317 case HSM_ST_ERR:
1318 /* make sure qc->err_mask is available to
1319 * know what's wrong and recover
1320 */
1321 WARN_ON(!(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)));
1322
1323 ap->hsm_task_state = HSM_ST_IDLE; 1318 ap->hsm_task_state = HSM_ST_IDLE;
1324 1319
1325 /* complete taskfile transaction */ 1320 /* complete taskfile transaction */
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index f6f9c28ec7f8..fe2839e58774 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -66,11 +66,11 @@ enum {
66 66
67extern unsigned int ata_print_id; 67extern unsigned int ata_print_id;
68extern struct workqueue_struct *ata_aux_wq; 68extern struct workqueue_struct *ata_aux_wq;
69extern int atapi_enabled;
70extern int atapi_passthru16; 69extern int atapi_passthru16;
71extern int libata_fua; 70extern int libata_fua;
72extern int libata_noacpi; 71extern int libata_noacpi;
73extern int libata_allow_tpm; 72extern int libata_allow_tpm;
73extern struct ata_link *ata_dev_phys_link(struct ata_device *dev);
74extern void ata_force_cbl(struct ata_port *ap); 74extern void ata_force_cbl(struct ata_port *ap);
75extern u64 ata_tf_to_lba(const struct ata_taskfile *tf); 75extern u64 ata_tf_to_lba(const struct ata_taskfile *tf);
76extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf); 76extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
@@ -108,6 +108,8 @@ extern void ata_qc_issue(struct ata_queued_cmd *qc);
108extern void __ata_qc_complete(struct ata_queued_cmd *qc); 108extern void __ata_qc_complete(struct ata_queued_cmd *qc);
109extern int atapi_check_dma(struct ata_queued_cmd *qc); 109extern int atapi_check_dma(struct ata_queued_cmd *qc);
110extern void swap_buf_le16(u16 *buf, unsigned int buf_words); 110extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
111extern bool ata_phys_link_online(struct ata_link *link);
112extern bool ata_phys_link_offline(struct ata_link *link);
111extern void ata_dev_init(struct ata_device *dev); 113extern void ata_dev_init(struct ata_device *dev);
112extern void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp); 114extern void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp);
113extern int sata_link_init_spd(struct ata_link *link); 115extern int sata_link_init_spd(struct ata_link *link);
@@ -153,7 +155,7 @@ extern int ata_bus_probe(struct ata_port *ap);
153/* libata-eh.c */ 155/* libata-eh.c */
154extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd); 156extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd);
155extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd); 157extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd);
156extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); 158extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
157extern void ata_scsi_error(struct Scsi_Host *host); 159extern void ata_scsi_error(struct Scsi_Host *host);
158extern void ata_port_wait_eh(struct ata_port *ap); 160extern void ata_port_wait_eh(struct ata_port *ap);
159extern void ata_eh_fastdrain_timerfn(unsigned long arg); 161extern void ata_eh_fastdrain_timerfn(unsigned long arg);
diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
index fbe605711554..eb919c16a03e 100644
--- a/drivers/ata/pata_acpi.c
+++ b/drivers/ata/pata_acpi.c
@@ -181,7 +181,7 @@ static unsigned int pacpi_qc_issue(struct ata_queued_cmd *qc)
181 181
182 if (adev != acpi->last) { 182 if (adev != acpi->last) {
183 pacpi_set_piomode(ap, adev); 183 pacpi_set_piomode(ap, adev);
184 if (adev->dma_mode) 184 if (ata_dma_enabled(adev))
185 pacpi_set_dmamode(ap, adev); 185 pacpi_set_dmamode(ap, adev);
186 acpi->last = adev; 186 acpi->last = adev;
187 } 187 }
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 0f3e659db99a..5ca70fa1f587 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -550,8 +550,9 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
550 pci_read_config_byte(isa_bridge, 0x5E, &tmp); 550 pci_read_config_byte(isa_bridge, 0x5E, &tmp);
551 if ((tmp & 0x1E) == 0x12) 551 if ((tmp & 0x1E) == 0x12)
552 ppi[0] = &info_20_udma; 552 ppi[0] = &info_20_udma;
553 pci_dev_put(isa_bridge);
554 } 553 }
554 pci_dev_put(isa_bridge);
555
555 return ata_pci_sff_init_one(pdev, ppi, &ali_sht, NULL); 556 return ata_pci_sff_init_one(pdev, ppi, &ali_sht, NULL);
556} 557}
557 558
diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
index 82fb6e273169..ab61095093b9 100644
--- a/drivers/ata/pata_at32.c
+++ b/drivers/ata/pata_at32.c
@@ -24,8 +24,8 @@
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/io.h> 25#include <linux/io.h>
26 26
27#include <asm/arch/board.h> 27#include <mach/board.h>
28#include <asm/arch/smc.h> 28#include <mach/smc.h>
29 29
30#define DRV_NAME "pata_at32" 30#define DRV_NAME "pata_at32"
31#define DRV_VERSION "0.0.3" 31#define DRV_VERSION "0.0.3"
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index d7de7baf58a8..e8a0d99d7356 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -183,7 +183,7 @@ static void atiixp_bmdma_start(struct ata_queued_cmd *qc)
183 u16 tmp16; 183 u16 tmp16;
184 184
185 pci_read_config_word(pdev, ATIIXP_IDE_UDMA_CONTROL, &tmp16); 185 pci_read_config_word(pdev, ATIIXP_IDE_UDMA_CONTROL, &tmp16);
186 if (adev->dma_mode >= XFER_UDMA_0) 186 if (ata_using_udma(adev))
187 tmp16 |= (1 << dn); 187 tmp16 |= (1 << dn);
188 else 188 else
189 tmp16 &= ~(1 << dn); 189 tmp16 &= ~(1 << dn);
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
index d3932901a3b3..1266924c11f9 100644
--- a/drivers/ata/pata_bf54x.c
+++ b/drivers/ata/pata_bf54x.c
@@ -1632,6 +1632,8 @@ static int __devinit bfin_atapi_probe(struct platform_device *pdev)
1632 return -ENODEV; 1632 return -ENODEV;
1633 } 1633 }
1634 1634
1635 dev_set_drvdata(&pdev->dev, host);
1636
1635 return 0; 1637 return 0;
1636} 1638}
1637 1639
@@ -1648,6 +1650,7 @@ static int __devexit bfin_atapi_remove(struct platform_device *pdev)
1648 struct ata_host *host = dev_get_drvdata(dev); 1650 struct ata_host *host = dev_get_drvdata(dev);
1649 1651
1650 ata_host_detach(host); 1652 ata_host_detach(host);
1653 dev_set_drvdata(&pdev->dev, NULL);
1651 1654
1652 peripheral_free_list(atapi_io_port); 1655 peripheral_free_list(atapi_io_port);
1653 1656
@@ -1655,27 +1658,44 @@ static int __devexit bfin_atapi_remove(struct platform_device *pdev)
1655} 1658}
1656 1659
1657#ifdef CONFIG_PM 1660#ifdef CONFIG_PM
1658int bfin_atapi_suspend(struct platform_device *pdev, pm_message_t state) 1661static int bfin_atapi_suspend(struct platform_device *pdev, pm_message_t state)
1659{ 1662{
1660 return 0; 1663 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1664 if (host)
1665 return ata_host_suspend(host, state);
1666 else
1667 return 0;
1661} 1668}
1662 1669
1663int bfin_atapi_resume(struct platform_device *pdev) 1670static int bfin_atapi_resume(struct platform_device *pdev)
1664{ 1671{
1672 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1673 int ret;
1674
1675 if (host) {
1676 ret = bfin_reset_controller(host);
1677 if (ret) {
1678 printk(KERN_ERR DRV_NAME ": Error during HW init\n");
1679 return ret;
1680 }
1681 ata_host_resume(host);
1682 }
1683
1665 return 0; 1684 return 0;
1666} 1685}
1686#else
1687#define bfin_atapi_suspend NULL
1688#define bfin_atapi_resume NULL
1667#endif 1689#endif
1668 1690
1669static struct platform_driver bfin_atapi_driver = { 1691static struct platform_driver bfin_atapi_driver = {
1670 .probe = bfin_atapi_probe, 1692 .probe = bfin_atapi_probe,
1671 .remove = __devexit_p(bfin_atapi_remove), 1693 .remove = __devexit_p(bfin_atapi_remove),
1694 .suspend = bfin_atapi_suspend,
1695 .resume = bfin_atapi_resume,
1672 .driver = { 1696 .driver = {
1673 .name = DRV_NAME, 1697 .name = DRV_NAME,
1674 .owner = THIS_MODULE, 1698 .owner = THIS_MODULE,
1675#ifdef CONFIG_PM
1676 .suspend = bfin_atapi_suspend,
1677 .resume = bfin_atapi_resume,
1678#endif
1679 }, 1699 },
1680}; 1700};
1681 1701
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index 744beebaaf49..0c4b271a9d5a 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -149,10 +149,10 @@ static unsigned int cs5530_qc_issue(struct ata_queued_cmd *qc)
149 struct ata_device *prev = ap->private_data; 149 struct ata_device *prev = ap->private_data;
150 150
151 /* See if the DMA settings could be wrong */ 151 /* See if the DMA settings could be wrong */
152 if (adev->dma_mode != 0 && adev != prev && prev != NULL) { 152 if (ata_dma_enabled(adev) && adev != prev && prev != NULL) {
153 /* Maybe, but do the channels match MWDMA/UDMA ? */ 153 /* Maybe, but do the channels match MWDMA/UDMA ? */
154 if ((adev->dma_mode >= XFER_UDMA_0 && prev->dma_mode < XFER_UDMA_0) || 154 if ((ata_using_udma(adev) && !ata_using_udma(prev)) ||
155 (adev->dma_mode < XFER_UDMA_0 && prev->dma_mode >= XFER_UDMA_0)) 155 (ata_using_udma(prev) && !ata_using_udma(adev)))
156 /* Switch the mode bits */ 156 /* Switch the mode bits */
157 cs5530_set_dmamode(ap, adev); 157 cs5530_set_dmamode(ap, adev);
158 } 158 }
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index e10816931b2f..0221c9a46769 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -80,7 +80,7 @@
80 80
81 81
82#define DRV_NAME "pata_it821x" 82#define DRV_NAME "pata_it821x"
83#define DRV_VERSION "0.3.8" 83#define DRV_VERSION "0.4.0"
84 84
85struct it821x_dev 85struct it821x_dev
86{ 86{
@@ -425,6 +425,8 @@ static unsigned int it821x_smart_qc_issue(struct ata_queued_cmd *qc)
425 case ATA_CMD_WRITE_MULTI: 425 case ATA_CMD_WRITE_MULTI:
426 case ATA_CMD_WRITE_MULTI_EXT: 426 case ATA_CMD_WRITE_MULTI_EXT:
427 case ATA_CMD_ID_ATA: 427 case ATA_CMD_ID_ATA:
428 case ATA_CMD_INIT_DEV_PARAMS:
429 case 0xFC: /* Internal 'report rebuild state' */
428 /* Arguably should just no-op this one */ 430 /* Arguably should just no-op this one */
429 case ATA_CMD_SET_FEATURES: 431 case ATA_CMD_SET_FEATURES:
430 return ata_sff_qc_issue(qc); 432 return ata_sff_qc_issue(qc);
@@ -509,7 +511,7 @@ static void it821x_dev_config(struct ata_device *adev)
509 511
510 if (strstr(model_num, "Integrated Technology Express")) { 512 if (strstr(model_num, "Integrated Technology Express")) {
511 /* RAID mode */ 513 /* RAID mode */
512 printk(KERN_INFO "IT821x %sRAID%d volume", 514 ata_dev_printk(adev, KERN_INFO, "%sRAID%d volume",
513 adev->id[147]?"Bootable ":"", 515 adev->id[147]?"Bootable ":"",
514 adev->id[129]); 516 adev->id[129]);
515 if (adev->id[129] != 1) 517 if (adev->id[129] != 1)
@@ -519,37 +521,51 @@ static void it821x_dev_config(struct ata_device *adev)
519 /* This is a controller firmware triggered funny, don't 521 /* This is a controller firmware triggered funny, don't
520 report the drive faulty! */ 522 report the drive faulty! */
521 adev->horkage &= ~ATA_HORKAGE_DIAGNOSTIC; 523 adev->horkage &= ~ATA_HORKAGE_DIAGNOSTIC;
524 /* No HPA in 'smart' mode */
525 adev->horkage |= ATA_HORKAGE_BROKEN_HPA;
522} 526}
523 527
524/** 528/**
525 * it821x_ident_hack - Hack identify data up 529 * it821x_read_id - Hack identify data up
526 * @ap: Port 530 * @adev: device to read
531 * @tf: proposed taskfile
532 * @id: buffer for returned ident data
527 * 533 *
528 * Walk the devices on this firmware driven port and slightly 534 * Query the devices on this firmware driven port and slightly
529 * mash the identify data to stop us and common tools trying to 535 * mash the identify data to stop us and common tools trying to
530 * use features not firmware supported. The firmware itself does 536 * use features not firmware supported. The firmware itself does
531 * some masking (eg SMART) but not enough. 537 * some masking (eg SMART) but not enough.
532 *
533 * This is a bit of an abuse of the cable method, but it is the
534 * only method called at the right time. We could modify the libata
535 * core specifically for ident hacking but while we have one offender
536 * it seems better to keep the fallout localised.
537 */ 538 */
538 539
539static int it821x_ident_hack(struct ata_port *ap) 540static unsigned int it821x_read_id(struct ata_device *adev,
541 struct ata_taskfile *tf, u16 *id)
540{ 542{
541 struct ata_device *adev; 543 unsigned int err_mask;
542 ata_link_for_each_dev(adev, &ap->link) { 544 unsigned char model_num[ATA_ID_PROD_LEN + 1];
543 if (ata_dev_enabled(adev)) { 545
544 adev->id[84] &= ~(1 << 6); /* No FUA */ 546 err_mask = ata_do_dev_read_id(adev, tf, id);
545 adev->id[85] &= ~(1 << 10); /* No HPA */ 547 if (err_mask)
546 adev->id[76] = 0; /* No NCQ/AN etc */ 548 return err_mask;
547 } 549 ata_id_c_string(id, model_num, ATA_ID_PROD, sizeof(model_num));
550
551 id[83] &= ~(1 << 12); /* Cache flush is firmware handled */
552 id[83] &= ~(1 << 13); /* Ditto for LBA48 flushes */
553 id[84] &= ~(1 << 6); /* No FUA */
554 id[85] &= ~(1 << 10); /* No HPA */
555 id[76] = 0; /* No NCQ/AN etc */
556
557 if (strstr(model_num, "Integrated Technology Express")) {
558 /* Set feature bits the firmware neglects */
559 id[49] |= 0x0300; /* LBA, DMA */
560 id[82] |= 0x0400; /* LBA48 */
561 id[83] &= 0x7FFF;
562 id[83] |= 0x4000; /* Word 83 is valid */
563 id[86] |= 0x0400; /* LBA48 on */
564 id[ATA_ID_MAJOR_VER] |= 0x1F;
548 } 565 }
549 return ata_cable_unknown(ap); 566 return err_mask;
550} 567}
551 568
552
553/** 569/**
554 * it821x_check_atapi_dma - ATAPI DMA handler 570 * it821x_check_atapi_dma - ATAPI DMA handler
555 * @qc: Command we are about to issue 571 * @qc: Command we are about to issue
@@ -577,6 +593,136 @@ static int it821x_check_atapi_dma(struct ata_queued_cmd *qc)
577 return 0; 593 return 0;
578} 594}
579 595
596/**
597 * it821x_display_disk - display disk setup
598 * @n: Device number
599 * @buf: Buffer block from firmware
600 *
601 * Produce a nice informative display of the device setup as provided
602 * by the firmware.
603 */
604
605static void it821x_display_disk(int n, u8 *buf)
606{
607 unsigned char id[41];
608 int mode = 0;
609 char *mtype = "";
610 char mbuf[8];
611 char *cbl = "(40 wire cable)";
612
613 static const char *types[5] = {
614 "RAID0", "RAID1" "RAID 0+1", "JBOD", "DISK"
615 };
616
617 if (buf[52] > 4) /* No Disk */
618 return;
619
620 ata_id_c_string((u16 *)buf, id, 0, 41);
621
622 if (buf[51]) {
623 mode = ffs(buf[51]);
624 mtype = "UDMA";
625 } else if (buf[49]) {
626 mode = ffs(buf[49]);
627 mtype = "MWDMA";
628 }
629
630 if (buf[76])
631 cbl = "";
632
633 if (mode)
634 snprintf(mbuf, 8, "%5s%d", mtype, mode - 1);
635 else
636 strcpy(mbuf, "PIO");
637 if (buf[52] == 4)
638 printk(KERN_INFO "%d: %-6s %-8s %s %s\n",
639 n, mbuf, types[buf[52]], id, cbl);
640 else
641 printk(KERN_INFO "%d: %-6s %-8s Volume: %1d %s %s\n",
642 n, mbuf, types[buf[52]], buf[53], id, cbl);
643 if (buf[125] < 100)
644 printk(KERN_INFO "%d: Rebuilding: %d%%\n", n, buf[125]);
645}
646
647/**
648 * it821x_firmware_command - issue firmware command
649 * @ap: IT821x port to interrogate
650 * @cmd: command
651 * @len: length
652 *
653 * Issue firmware commands expecting data back from the controller. We
654 * use this to issue commands that do not go via the normal paths. Other
655 * commands such as 0xFC can be issued normally.
656 */
657
658static u8 *it821x_firmware_command(struct ata_port *ap, u8 cmd, int len)
659{
660 u8 status;
661 int n = 0;
662 u16 *buf = kmalloc(len, GFP_KERNEL);
663 if (buf == NULL) {
664 printk(KERN_ERR "it821x_firmware_command: Out of memory\n");
665 return NULL;
666 }
667 /* This isn't quite a normal ATA command as we are talking to the
668 firmware not the drives */
669 ap->ctl |= ATA_NIEN;
670 iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
671 ata_wait_idle(ap);
672 iowrite8(ATA_DEVICE_OBS, ap->ioaddr.device_addr);
673 iowrite8(cmd, ap->ioaddr.command_addr);
674 udelay(1);
675 /* This should be almost immediate but a little paranoia goes a long
676 way. */
677 while(n++ < 10) {
678 status = ioread8(ap->ioaddr.status_addr);
679 if (status & ATA_ERR) {
680 kfree(buf);
681 printk(KERN_ERR "it821x_firmware_command: rejected\n");
682 return NULL;
683 }
684 if (status & ATA_DRQ) {
685 ioread16_rep(ap->ioaddr.data_addr, buf, len/2);
686 return (u8 *)buf;
687 }
688 mdelay(1);
689 }
690 kfree(buf);
691 printk(KERN_ERR "it821x_firmware_command: timeout\n");
692 return NULL;
693}
694
695/**
696 * it821x_probe_firmware - firmware reporting/setup
697 * @ap: IT821x port being probed
698 *
699 * Probe the firmware of the controller by issuing firmware command
700 * 0xFA and analysing the returned data.
701 */
702
703static void it821x_probe_firmware(struct ata_port *ap)
704{
705 u8 *buf;
706 int i;
707
708 /* This is a bit ugly as we can't just issue a task file to a device
709 as this is controller magic */
710
711 buf = it821x_firmware_command(ap, 0xFA, 512);
712
713 if (buf != NULL) {
714 printk(KERN_INFO "pata_it821x: Firmware %02X/%02X/%02X%02X\n",
715 buf[505],
716 buf[506],
717 buf[507],
718 buf[508]);
719 for (i = 0; i < 4; i++)
720 it821x_display_disk(i, buf + 128 * i);
721 kfree(buf);
722 }
723}
724
725
580 726
581/** 727/**
582 * it821x_port_start - port setup 728 * it821x_port_start - port setup
@@ -610,6 +756,8 @@ static int it821x_port_start(struct ata_port *ap)
610 /* Long I/O's although allowed in LBA48 space cause the 756 /* Long I/O's although allowed in LBA48 space cause the
611 onboard firmware to enter the twighlight zone */ 757 onboard firmware to enter the twighlight zone */
612 /* No ATAPI DMA in this mode either */ 758 /* No ATAPI DMA in this mode either */
759 if (ap->port_no == 0)
760 it821x_probe_firmware(ap);
613 } 761 }
614 /* Pull the current clocks from 0x50 */ 762 /* Pull the current clocks from 0x50 */
615 if (conf & (1 << (1 + ap->port_no))) 763 if (conf & (1 << (1 + ap->port_no)))
@@ -631,6 +779,25 @@ static int it821x_port_start(struct ata_port *ap)
631 return 0; 779 return 0;
632} 780}
633 781
782/**
783 * it821x_rdc_cable - Cable detect for RDC1010
784 * @ap: port we are checking
785 *
786 * Return the RDC1010 cable type. Unlike the IT821x we know how to do
787 * this and can do host side cable detect
788 */
789
790static int it821x_rdc_cable(struct ata_port *ap)
791{
792 u16 r40;
793 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
794
795 pci_read_config_word(pdev, 0x40, &r40);
796 if (r40 & (1 << (2 + ap->port_no)))
797 return ATA_CBL_PATA40;
798 return ATA_CBL_PATA80;
799}
800
634static struct scsi_host_template it821x_sht = { 801static struct scsi_host_template it821x_sht = {
635 ATA_BMDMA_SHT(DRV_NAME), 802 ATA_BMDMA_SHT(DRV_NAME),
636}; 803};
@@ -641,9 +808,10 @@ static struct ata_port_operations it821x_smart_port_ops = {
641 .check_atapi_dma= it821x_check_atapi_dma, 808 .check_atapi_dma= it821x_check_atapi_dma,
642 .qc_issue = it821x_smart_qc_issue, 809 .qc_issue = it821x_smart_qc_issue,
643 810
644 .cable_detect = it821x_ident_hack, 811 .cable_detect = ata_cable_80wire,
645 .set_mode = it821x_smart_set_mode, 812 .set_mode = it821x_smart_set_mode,
646 .dev_config = it821x_dev_config, 813 .dev_config = it821x_dev_config,
814 .read_id = it821x_read_id,
647 815
648 .port_start = it821x_port_start, 816 .port_start = it821x_port_start,
649}; 817};
@@ -664,8 +832,29 @@ static struct ata_port_operations it821x_passthru_port_ops = {
664 .port_start = it821x_port_start, 832 .port_start = it821x_port_start,
665}; 833};
666 834
835static struct ata_port_operations it821x_rdc_port_ops = {
836 .inherits = &ata_bmdma_port_ops,
837
838 .check_atapi_dma= it821x_check_atapi_dma,
839 .sff_dev_select = it821x_passthru_dev_select,
840 .bmdma_start = it821x_passthru_bmdma_start,
841 .bmdma_stop = it821x_passthru_bmdma_stop,
842 .qc_issue = it821x_passthru_qc_issue,
843
844 .cable_detect = it821x_rdc_cable,
845 .set_piomode = it821x_passthru_set_piomode,
846 .set_dmamode = it821x_passthru_set_dmamode,
847
848 .port_start = it821x_port_start,
849};
850
667static void it821x_disable_raid(struct pci_dev *pdev) 851static void it821x_disable_raid(struct pci_dev *pdev)
668{ 852{
853 /* Neither the RDC nor the IT8211 */
854 if (pdev->vendor != PCI_VENDOR_ID_ITE ||
855 pdev->device != PCI_DEVICE_ID_ITE_8212)
856 return;
857
669 /* Reset local CPU, and set BIOS not ready */ 858 /* Reset local CPU, and set BIOS not ready */
670 pci_write_config_byte(pdev, 0x5E, 0x01); 859 pci_write_config_byte(pdev, 0x5E, 0x01);
671 860
@@ -690,6 +879,7 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
690 .flags = ATA_FLAG_SLAVE_POSS, 879 .flags = ATA_FLAG_SLAVE_POSS,
691 .pio_mask = 0x1f, 880 .pio_mask = 0x1f,
692 .mwdma_mask = 0x07, 881 .mwdma_mask = 0x07,
882 .udma_mask = ATA_UDMA6,
693 .port_ops = &it821x_smart_port_ops 883 .port_ops = &it821x_smart_port_ops
694 }; 884 };
695 static const struct ata_port_info info_passthru = { 885 static const struct ata_port_info info_passthru = {
@@ -699,6 +889,13 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
699 .udma_mask = ATA_UDMA6, 889 .udma_mask = ATA_UDMA6,
700 .port_ops = &it821x_passthru_port_ops 890 .port_ops = &it821x_passthru_port_ops
701 }; 891 };
892 static const struct ata_port_info info_rdc = {
893 .flags = ATA_FLAG_SLAVE_POSS,
894 .pio_mask = 0x1f,
895 .mwdma_mask = 0x07,
896 /* No UDMA */
897 .port_ops = &it821x_rdc_port_ops
898 };
702 899
703 const struct ata_port_info *ppi[] = { NULL, NULL }; 900 const struct ata_port_info *ppi[] = { NULL, NULL };
704 static char *mode[2] = { "pass through", "smart" }; 901 static char *mode[2] = { "pass through", "smart" };
@@ -707,21 +904,25 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
707 rc = pcim_enable_device(pdev); 904 rc = pcim_enable_device(pdev);
708 if (rc) 905 if (rc)
709 return rc; 906 return rc;
907
908 if (pdev->vendor == PCI_VENDOR_ID_RDC) {
909 ppi[0] = &info_rdc;
910 } else {
911 /* Force the card into bypass mode if so requested */
912 if (it8212_noraid) {
913 printk(KERN_INFO DRV_NAME ": forcing bypass mode.\n");
914 it821x_disable_raid(pdev);
915 }
916 pci_read_config_byte(pdev, 0x50, &conf);
917 conf &= 1;
710 918
711 /* Force the card into bypass mode if so requested */ 919 printk(KERN_INFO DRV_NAME": controller in %s mode.\n",
712 if (it8212_noraid) { 920 mode[conf]);
713 printk(KERN_INFO DRV_NAME ": forcing bypass mode.\n"); 921 if (conf == 0)
714 it821x_disable_raid(pdev); 922 ppi[0] = &info_passthru;
923 else
924 ppi[0] = &info_smart;
715 } 925 }
716 pci_read_config_byte(pdev, 0x50, &conf);
717 conf &= 1;
718
719 printk(KERN_INFO DRV_NAME ": controller in %s mode.\n", mode[conf]);
720 if (conf == 0)
721 ppi[0] = &info_passthru;
722 else
723 ppi[0] = &info_smart;
724
725 return ata_pci_sff_init_one(pdev, ppi, &it821x_sht, NULL); 926 return ata_pci_sff_init_one(pdev, ppi, &it821x_sht, NULL);
726} 927}
727 928
@@ -745,6 +946,7 @@ static int it821x_reinit_one(struct pci_dev *pdev)
745static const struct pci_device_id it821x[] = { 946static const struct pci_device_id it821x[] = {
746 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), }, 947 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), },
747 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8212), }, 948 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8212), },
949 { PCI_VDEVICE(RDC, 0x1010), },
748 950
749 { }, 951 { },
750}; 952};
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index 24a011b25024..0d87eec84966 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -20,29 +20,30 @@
20#include <linux/ata.h> 20#include <linux/ata.h>
21 21
22#define DRV_NAME "pata_marvell" 22#define DRV_NAME "pata_marvell"
23#define DRV_VERSION "0.1.4" 23#define DRV_VERSION "0.1.6"
24 24
25/** 25/**
26 * marvell_pre_reset - check for 40/80 pin 26 * marvell_pata_active - check if PATA is active
27 * @link: link 27 * @pdev: PCI device
28 * @deadline: deadline jiffies for the operation
29 * 28 *
30 * Perform the PATA port setup we need. 29 * Returns 1 if the PATA port may be active. We know how to check this
30 * for the 6145 but not the other devices
31 */ 31 */
32 32
33static int marvell_pre_reset(struct ata_link *link, unsigned long deadline) 33static int marvell_pata_active(struct pci_dev *pdev)
34{ 34{
35 struct ata_port *ap = link->ap; 35 int i;
36 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
37 u32 devices; 36 u32 devices;
38 void __iomem *barp; 37 void __iomem *barp;
39 int i;
40 38
41 /* Check if our port is enabled */ 39 /* We don't yet know how to do this for other devices */
40 if (pdev->device != 0x6145)
41 return 1;
42 42
43 barp = pci_iomap(pdev, 5, 0x10); 43 barp = pci_iomap(pdev, 5, 0x10);
44 if (barp == NULL) 44 if (barp == NULL)
45 return -ENOMEM; 45 return -ENOMEM;
46
46 printk("BAR5:"); 47 printk("BAR5:");
47 for(i = 0; i <= 0x0F; i++) 48 for(i = 0; i <= 0x0F; i++)
48 printk("%02X:%02X ", i, ioread8(barp + i)); 49 printk("%02X:%02X ", i, ioread8(barp + i));
@@ -51,9 +52,27 @@ static int marvell_pre_reset(struct ata_link *link, unsigned long deadline)
51 devices = ioread32(barp + 0x0C); 52 devices = ioread32(barp + 0x0C);
52 pci_iounmap(pdev, barp); 53 pci_iounmap(pdev, barp);
53 54
54 if ((pdev->device == 0x6145) && (ap->port_no == 0) && 55 if (devices & 0x10)
55 (!(devices & 0x10))) /* PATA enable ? */ 56 return 1;
56 return -ENOENT; 57 return 0;
58}
59
60/**
61 * marvell_pre_reset - check for 40/80 pin
62 * @link: link
63 * @deadline: deadline jiffies for the operation
64 *
65 * Perform the PATA port setup we need.
66 */
67
68static int marvell_pre_reset(struct ata_link *link, unsigned long deadline)
69{
70 struct ata_port *ap = link->ap;
71 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
72
73 if (pdev->device == 0x6145 && ap->port_no == 0 &&
74 !marvell_pata_active(pdev)) /* PATA enable ? */
75 return -ENOENT;
57 76
58 return ata_sff_prereset(link, deadline); 77 return ata_sff_prereset(link, deadline);
59} 78}
@@ -128,6 +147,12 @@ static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *i
128 if (pdev->device == 0x6101) 147 if (pdev->device == 0x6101)
129 ppi[1] = &ata_dummy_port_info; 148 ppi[1] = &ata_dummy_port_info;
130 149
150#if defined(CONFIG_AHCI) || defined(CONFIG_AHCI_MODULE)
151 if (!marvell_pata_active(pdev)) {
152 printk(KERN_INFO DRV_NAME ": PATA port not active, deferring to AHCI driver.\n");
153 return -ENODEV;
154 }
155#endif
131 return ata_pci_sff_init_one(pdev, ppi, &marvell_sht, NULL); 156 return ata_pci_sff_init_one(pdev, ppi, &marvell_sht, NULL);
132} 157}
133 158
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index e678af383d13..df64f2443001 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -198,7 +198,7 @@ static unsigned int oldpiix_qc_issue(struct ata_queued_cmd *qc)
198 198
199 if (adev != ap->private_data) { 199 if (adev != ap->private_data) {
200 oldpiix_set_piomode(ap, adev); 200 oldpiix_set_piomode(ap, adev);
201 if (adev->dma_mode) 201 if (ata_dma_enabled(adev))
202 oldpiix_set_dmamode(ap, adev); 202 oldpiix_set_dmamode(ap, adev);
203 } 203 }
204 return ata_sff_qc_issue(qc); 204 return ata_sff_qc_issue(qc);
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index cbab397e3db7..0278fd2b8fb1 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -167,10 +167,10 @@ static unsigned int sc1200_qc_issue(struct ata_queued_cmd *qc)
167 struct ata_device *prev = ap->private_data; 167 struct ata_device *prev = ap->private_data;
168 168
169 /* See if the DMA settings could be wrong */ 169 /* See if the DMA settings could be wrong */
170 if (adev->dma_mode != 0 && adev != prev && prev != NULL) { 170 if (ata_dma_enabled(adev) && adev != prev && prev != NULL) {
171 /* Maybe, but do the channels match MWDMA/UDMA ? */ 171 /* Maybe, but do the channels match MWDMA/UDMA ? */
172 if ((adev->dma_mode >= XFER_UDMA_0 && prev->dma_mode < XFER_UDMA_0) || 172 if ((ata_using_udma(adev) && !ata_using_udma(prev)) ||
173 (adev->dma_mode < XFER_UDMA_0 && prev->dma_mode >= XFER_UDMA_0)) 173 (ata_using_udma(prev) && !ata_using_udma(adev)))
174 /* Switch the mode bits */ 174 /* Switch the mode bits */
175 sc1200_set_dmamode(ap, adev); 175 sc1200_set_dmamode(ap, adev);
176 } 176 }
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 720b8645f58a..a598bb36aafc 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -230,7 +230,7 @@ static u8 sil680_init_chip(struct pci_dev *pdev, int *try_mmio)
230 tmpbyte & 1, tmpbyte & 0x30); 230 tmpbyte & 1, tmpbyte & 0x30);
231 231
232 *try_mmio = 0; 232 *try_mmio = 0;
233#ifdef CONFIG_PPC_MERGE 233#ifdef CONFIG_PPC
234 if (machine_is(cell)) 234 if (machine_is(cell))
235 *try_mmio = (tmpbyte & 1) || pci_resource_start(pdev, 5); 235 *try_mmio = (tmpbyte & 1) || pci_resource_start(pdev, 5);
236#endif 236#endif
@@ -322,9 +322,6 @@ static int __devinit sil680_init_one(struct pci_dev *pdev,
322 /* Try to acquire MMIO resources and fallback to PIO if 322 /* Try to acquire MMIO resources and fallback to PIO if
323 * that fails 323 * that fails
324 */ 324 */
325 rc = pcim_enable_device(pdev);
326 if (rc)
327 return rc;
328 rc = pcim_iomap_regions(pdev, 1 << SIL680_MMIO_BAR, DRV_NAME); 325 rc = pcim_iomap_regions(pdev, 1 << SIL680_MMIO_BAR, DRV_NAME);
329 if (rc) 326 if (rc)
330 goto use_ioports; 327 goto use_ioports;
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index 708ed144ede9..8fdb2ce73210 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -98,7 +98,8 @@ static const struct via_isa_bridge {
98 u8 rev_max; 98 u8 rev_max;
99 u16 flags; 99 u16 flags;
100} via_isa_bridges[] = { 100} via_isa_bridges[] = {
101 { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 101 { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, VIA_UDMA_133 |
102 VIA_BAD_AST | VIA_SATA_PATA },
102 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 103 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
103 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 104 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
104 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_SATA_PATA }, 105 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_SATA_PATA },
@@ -322,6 +323,29 @@ static void via_set_dmamode(struct ata_port *ap, struct ata_device *adev)
322 via_do_set_mode(ap, adev, adev->dma_mode, tclock[mode], set_ast, udma[mode]); 323 via_do_set_mode(ap, adev, adev->dma_mode, tclock[mode], set_ast, udma[mode]);
323} 324}
324 325
326/**
327 * via_tf_load - send taskfile registers to host controller
328 * @ap: Port to which output is sent
329 * @tf: ATA taskfile register set
330 *
331 * Outputs ATA taskfile to standard ATA host controller.
332 *
333 * Note: This is to fix the internal bug of via chipsets, which
334 * will reset the device register after changing the IEN bit on
335 * ctl register
336 */
337static void via_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
338{
339 struct ata_taskfile tmp_tf;
340
341 if (ap->ctl != ap->last_ctl && !(tf->flags & ATA_TFLAG_DEVICE)) {
342 tmp_tf = *tf;
343 tmp_tf.flags |= ATA_TFLAG_DEVICE;
344 tf = &tmp_tf;
345 }
346 ata_sff_tf_load(ap, tf);
347}
348
325static struct scsi_host_template via_sht = { 349static struct scsi_host_template via_sht = {
326 ATA_BMDMA_SHT(DRV_NAME), 350 ATA_BMDMA_SHT(DRV_NAME),
327}; 351};
@@ -332,6 +356,7 @@ static struct ata_port_operations via_port_ops = {
332 .set_piomode = via_set_piomode, 356 .set_piomode = via_set_piomode,
333 .set_dmamode = via_set_dmamode, 357 .set_dmamode = via_set_dmamode,
334 .prereset = via_pre_reset, 358 .prereset = via_pre_reset,
359 .sff_tf_load = via_tf_load,
335}; 360};
336 361
337static struct ata_port_operations via_port_ops_noirq = { 362static struct ata_port_operations via_port_ops_noirq = {
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 3924e7209a44..1a56db92ff7a 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -469,10 +469,10 @@ static bool sata_fsl_qc_fill_rtf(struct ata_queued_cmd *qc)
469 return true; 469 return true;
470} 470}
471 471
472static int sata_fsl_scr_write(struct ata_port *ap, unsigned int sc_reg_in, 472static int sata_fsl_scr_write(struct ata_link *link,
473 u32 val) 473 unsigned int sc_reg_in, u32 val)
474{ 474{
475 struct sata_fsl_host_priv *host_priv = ap->host->private_data; 475 struct sata_fsl_host_priv *host_priv = link->ap->host->private_data;
476 void __iomem *ssr_base = host_priv->ssr_base; 476 void __iomem *ssr_base = host_priv->ssr_base;
477 unsigned int sc_reg; 477 unsigned int sc_reg;
478 478
@@ -493,10 +493,10 @@ static int sata_fsl_scr_write(struct ata_port *ap, unsigned int sc_reg_in,
493 return 0; 493 return 0;
494} 494}
495 495
496static int sata_fsl_scr_read(struct ata_port *ap, unsigned int sc_reg_in, 496static int sata_fsl_scr_read(struct ata_link *link,
497 u32 *val) 497 unsigned int sc_reg_in, u32 *val)
498{ 498{
499 struct sata_fsl_host_priv *host_priv = ap->host->private_data; 499 struct sata_fsl_host_priv *host_priv = link->ap->host->private_data;
500 void __iomem *ssr_base = host_priv->ssr_base; 500 void __iomem *ssr_base = host_priv->ssr_base;
501 unsigned int sc_reg; 501 unsigned int sc_reg;
502 502
@@ -645,12 +645,12 @@ static int sata_fsl_port_start(struct ata_port *ap)
645 * Workaround for 8315DS board 3gbps link-up issue, 645 * Workaround for 8315DS board 3gbps link-up issue,
646 * currently limit SATA port to GEN1 speed 646 * currently limit SATA port to GEN1 speed
647 */ 647 */
648 sata_fsl_scr_read(ap, SCR_CONTROL, &temp); 648 sata_fsl_scr_read(&ap->link, SCR_CONTROL, &temp);
649 temp &= ~(0xF << 4); 649 temp &= ~(0xF << 4);
650 temp |= (0x1 << 4); 650 temp |= (0x1 << 4);
651 sata_fsl_scr_write(ap, SCR_CONTROL, temp); 651 sata_fsl_scr_write(&ap->link, SCR_CONTROL, temp);
652 652
653 sata_fsl_scr_read(ap, SCR_CONTROL, &temp); 653 sata_fsl_scr_read(&ap->link, SCR_CONTROL, &temp);
654 dev_printk(KERN_WARNING, dev, "scr_control, speed limited to %x\n", 654 dev_printk(KERN_WARNING, dev, "scr_control, speed limited to %x\n",
655 temp); 655 temp);
656#endif 656#endif
@@ -868,7 +868,7 @@ issue_srst:
868 ioread32(CQ + hcr_base), 868 ioread32(CQ + hcr_base),
869 ioread32(CA + hcr_base), ioread32(CC + hcr_base)); 869 ioread32(CA + hcr_base), ioread32(CC + hcr_base));
870 870
871 sata_fsl_scr_read(ap, SCR_ERROR, &Serror); 871 sata_fsl_scr_read(&ap->link, SCR_ERROR, &Serror);
872 872
873 DPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS)); 873 DPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS));
874 DPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL)); 874 DPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));
@@ -972,9 +972,9 @@ static void sata_fsl_error_intr(struct ata_port *ap)
972 * Handle & Clear SError 972 * Handle & Clear SError
973 */ 973 */
974 974
975 sata_fsl_scr_read(ap, SCR_ERROR, &SError); 975 sata_fsl_scr_read(&ap->link, SCR_ERROR, &SError);
976 if (unlikely(SError & 0xFFFF0000)) { 976 if (unlikely(SError & 0xFFFF0000)) {
977 sata_fsl_scr_write(ap, SCR_ERROR, SError); 977 sata_fsl_scr_write(&ap->link, SCR_ERROR, SError);
978 } 978 }
979 979
980 DPRINTK("error_intr,hStat=0x%x,CE=0x%x,DE =0x%x,SErr=0x%x\n", 980 DPRINTK("error_intr,hStat=0x%x,CE=0x%x,DE =0x%x,SErr=0x%x\n",
@@ -1091,7 +1091,7 @@ static void sata_fsl_host_intr(struct ata_port *ap)
1091 1091
1092 hstatus = ioread32(hcr_base + HSTATUS); 1092 hstatus = ioread32(hcr_base + HSTATUS);
1093 1093
1094 sata_fsl_scr_read(ap, SCR_ERROR, &SError); 1094 sata_fsl_scr_read(&ap->link, SCR_ERROR, &SError);
1095 1095
1096 if (unlikely(SError & 0xFFFF0000)) { 1096 if (unlikely(SError & 0xFFFF0000)) {
1097 DPRINTK("serror @host_intr : 0x%x\n", SError); 1097 DPRINTK("serror @host_intr : 0x%x\n", SError);
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index 3ead02fe379e..fbbd87c96f10 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -96,6 +96,7 @@ enum {
96 PORT_SCR = 0x20, 96 PORT_SCR = 0x20,
97 97
98 /* HOST_CTL bits */ 98 /* HOST_CTL bits */
99 HCTL_LEDEN = (1 << 3), /* enable LED operation */
99 HCTL_IRQOFF = (1 << 8), /* global IRQ off */ 100 HCTL_IRQOFF = (1 << 8), /* global IRQ off */
100 HCTL_FTHD0 = (1 << 10), /* fifo threshold 0 */ 101 HCTL_FTHD0 = (1 << 10), /* fifo threshold 0 */
101 HCTL_FTHD1 = (1 << 11), /* fifo threshold 1*/ 102 HCTL_FTHD1 = (1 << 11), /* fifo threshold 1*/
@@ -268,9 +269,9 @@ static void inic_reset_port(void __iomem *port_base)
268 writeb(0xff, port_base + PORT_IRQ_STAT); 269 writeb(0xff, port_base + PORT_IRQ_STAT);
269} 270}
270 271
271static int inic_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val) 272static int inic_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val)
272{ 273{
273 void __iomem *scr_addr = inic_port_base(ap) + PORT_SCR; 274 void __iomem *scr_addr = inic_port_base(link->ap) + PORT_SCR;
274 void __iomem *addr; 275 void __iomem *addr;
275 276
276 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) 277 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map)))
@@ -285,9 +286,9 @@ static int inic_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val)
285 return 0; 286 return 0;
286} 287}
287 288
288static int inic_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) 289static int inic_scr_write(struct ata_link *link, unsigned sc_reg, u32 val)
289{ 290{
290 void __iomem *scr_addr = inic_port_base(ap) + PORT_SCR; 291 void __iomem *scr_addr = inic_port_base(link->ap) + PORT_SCR;
291 292
292 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) 293 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map)))
293 return -EINVAL; 294 return -EINVAL;
@@ -540,7 +541,7 @@ static unsigned int inic_qc_issue(struct ata_queued_cmd *qc)
540 void __iomem *port_base = inic_port_base(ap); 541 void __iomem *port_base = inic_port_base(ap);
541 542
542 /* fire up the ADMA engine */ 543 /* fire up the ADMA engine */
543 writew(HCTL_FTHD0, port_base + HOST_CTL); 544 writew(HCTL_FTHD0 | HCTL_LEDEN, port_base + HOST_CTL);
544 writew(IDMA_CTL_GO, port_base + PORT_IDMA_CTL); 545 writew(IDMA_CTL_GO, port_base + PORT_IDMA_CTL);
545 writeb(0, port_base + PORT_CPB_PTQFIFO); 546 writeb(0, port_base + PORT_CPB_PTQFIFO);
546 547
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index ad169ffbc4cb..2b24ae58b52e 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -493,10 +493,10 @@ struct mv_hw_ops {
493 void (*reset_bus)(struct ata_host *host, void __iomem *mmio); 493 void (*reset_bus)(struct ata_host *host, void __iomem *mmio);
494}; 494};
495 495
496static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 496static int mv_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val);
497static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 497static int mv_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val);
498static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 498static int mv5_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val);
499static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 499static int mv5_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val);
500static int mv_port_start(struct ata_port *ap); 500static int mv_port_start(struct ata_port *ap);
501static void mv_port_stop(struct ata_port *ap); 501static void mv_port_stop(struct ata_port *ap);
502static int mv_qc_defer(struct ata_queued_cmd *qc); 502static int mv_qc_defer(struct ata_queued_cmd *qc);
@@ -667,7 +667,8 @@ static const struct pci_device_id mv_pci_tbl[] = {
667 { PCI_VDEVICE(MARVELL, 0x5041), chip_504x }, 667 { PCI_VDEVICE(MARVELL, 0x5041), chip_504x },
668 { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 }, 668 { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 },
669 { PCI_VDEVICE(MARVELL, 0x5081), chip_508x }, 669 { PCI_VDEVICE(MARVELL, 0x5081), chip_508x },
670 /* RocketRAID 1740/174x have different identifiers */ 670 /* RocketRAID 1720/174x have different identifiers */
671 { PCI_VDEVICE(TTI, 0x1720), chip_6042 },
671 { PCI_VDEVICE(TTI, 0x1740), chip_508x }, 672 { PCI_VDEVICE(TTI, 0x1740), chip_508x },
672 { PCI_VDEVICE(TTI, 0x1742), chip_508x }, 673 { PCI_VDEVICE(TTI, 0x1742), chip_508x },
673 674
@@ -1069,23 +1070,23 @@ static unsigned int mv_scr_offset(unsigned int sc_reg_in)
1069 return ofs; 1070 return ofs;
1070} 1071}
1071 1072
1072static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 1073static int mv_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val)
1073{ 1074{
1074 unsigned int ofs = mv_scr_offset(sc_reg_in); 1075 unsigned int ofs = mv_scr_offset(sc_reg_in);
1075 1076
1076 if (ofs != 0xffffffffU) { 1077 if (ofs != 0xffffffffU) {
1077 *val = readl(mv_ap_base(ap) + ofs); 1078 *val = readl(mv_ap_base(link->ap) + ofs);
1078 return 0; 1079 return 0;
1079 } else 1080 } else
1080 return -EINVAL; 1081 return -EINVAL;
1081} 1082}
1082 1083
1083static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1084static int mv_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val)
1084{ 1085{
1085 unsigned int ofs = mv_scr_offset(sc_reg_in); 1086 unsigned int ofs = mv_scr_offset(sc_reg_in);
1086 1087
1087 if (ofs != 0xffffffffU) { 1088 if (ofs != 0xffffffffU) {
1088 writelfl(val, mv_ap_base(ap) + ofs); 1089 writelfl(val, mv_ap_base(link->ap) + ofs);
1089 return 0; 1090 return 0;
1090 } else 1091 } else
1091 return -EINVAL; 1092 return -EINVAL;
@@ -1134,30 +1135,16 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
1134 if (ap->nr_active_links == 0) 1135 if (ap->nr_active_links == 0)
1135 return 0; 1136 return 0;
1136 1137
1137 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 1138 /*
1138 /* 1139 * The port is operating in host queuing mode (EDMA) with NCQ
1139 * The port is operating in host queuing mode (EDMA). 1140 * enabled, allow multiple NCQ commands. EDMA also allows
1140 * It can accomodate a new qc if the qc protocol 1141 * queueing multiple DMA commands but libata core currently
1141 * is compatible with the current host queue mode. 1142 * doesn't allow it.
1142 */ 1143 */
1143 if (pp->pp_flags & MV_PP_FLAG_NCQ_EN) { 1144 if ((pp->pp_flags & MV_PP_FLAG_EDMA_EN) &&
1144 /* 1145 (pp->pp_flags & MV_PP_FLAG_NCQ_EN) && ata_is_ncq(qc->tf.protocol))
1145 * The host queue (EDMA) is in NCQ mode. 1146 return 0;
1146 * If the new qc is also an NCQ command, 1147
1147 * then allow the new qc.
1148 */
1149 if (qc->tf.protocol == ATA_PROT_NCQ)
1150 return 0;
1151 } else {
1152 /*
1153 * The host queue (EDMA) is in non-NCQ, DMA mode.
1154 * If the new qc is also a non-NCQ, DMA command,
1155 * then allow the new qc.
1156 */
1157 if (qc->tf.protocol == ATA_PROT_DMA)
1158 return 0;
1159 }
1160 }
1161 return ATA_DEFER_PORT; 1148 return ATA_DEFER_PORT;
1162} 1149}
1163 1150
@@ -2264,11 +2251,11 @@ static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
2264 return ofs; 2251 return ofs;
2265} 2252}
2266 2253
2267static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 2254static int mv5_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val)
2268{ 2255{
2269 struct mv_host_priv *hpriv = ap->host->private_data; 2256 struct mv_host_priv *hpriv = link->ap->host->private_data;
2270 void __iomem *mmio = hpriv->base; 2257 void __iomem *mmio = hpriv->base;
2271 void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 2258 void __iomem *addr = mv5_phy_base(mmio, link->ap->port_no);
2272 unsigned int ofs = mv5_scr_offset(sc_reg_in); 2259 unsigned int ofs = mv5_scr_offset(sc_reg_in);
2273 2260
2274 if (ofs != 0xffffffffU) { 2261 if (ofs != 0xffffffffU) {
@@ -2278,11 +2265,11 @@ static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
2278 return -EINVAL; 2265 return -EINVAL;
2279} 2266}
2280 2267
2281static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 2268static int mv5_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val)
2282{ 2269{
2283 struct mv_host_priv *hpriv = ap->host->private_data; 2270 struct mv_host_priv *hpriv = link->ap->host->private_data;
2284 void __iomem *mmio = hpriv->base; 2271 void __iomem *mmio = hpriv->base;
2285 void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 2272 void __iomem *addr = mv5_phy_base(mmio, link->ap->port_no);
2286 unsigned int ofs = mv5_scr_offset(sc_reg_in); 2273 unsigned int ofs = mv5_scr_offset(sc_reg_in);
2287 2274
2288 if (ofs != 0xffffffffU) { 2275 if (ofs != 0xffffffffU) {
@@ -3036,7 +3023,8 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
3036 break; 3023 break;
3037 case chip_soc: 3024 case chip_soc:
3038 hpriv->ops = &mv_soc_ops; 3025 hpriv->ops = &mv_soc_ops;
3039 hp_flags |= MV_HP_FLAG_SOC | MV_HP_ERRATA_60X1C0; 3026 hp_flags |= MV_HP_FLAG_SOC | MV_HP_GEN_IIE |
3027 MV_HP_ERRATA_60X1C0;
3040 break; 3028 break;
3041 3029
3042 default: 3030 default:
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 858f70610eda..fae3841de0d8 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -302,8 +302,8 @@ static void nv_ck804_host_stop(struct ata_host *host);
302static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance); 302static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance);
303static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance); 303static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance);
304static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance); 304static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance);
305static int nv_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 305static int nv_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
306static int nv_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 306static int nv_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
307 307
308static void nv_nf2_freeze(struct ata_port *ap); 308static void nv_nf2_freeze(struct ata_port *ap);
309static void nv_nf2_thaw(struct ata_port *ap); 309static void nv_nf2_thaw(struct ata_port *ap);
@@ -405,28 +405,45 @@ static struct scsi_host_template nv_swncq_sht = {
405 .slave_configure = nv_swncq_slave_config, 405 .slave_configure = nv_swncq_slave_config,
406}; 406};
407 407
408static struct ata_port_operations nv_generic_ops = { 408/* OSDL bz3352 reports that some nv controllers can't determine device
409 * signature reliably and nv_hardreset is implemented to work around
410 * the problem. This was reported on nf3 and it's unclear whether any
411 * other controllers are affected. However, the workaround has been
412 * applied to all variants and there isn't much to gain by trying to
413 * find out exactly which ones are affected at this point especially
414 * because NV has moved over to ahci for newer controllers.
415 */
416static struct ata_port_operations nv_common_ops = {
409 .inherits = &ata_bmdma_port_ops, 417 .inherits = &ata_bmdma_port_ops,
410 .hardreset = nv_hardreset, 418 .hardreset = nv_hardreset,
411 .scr_read = nv_scr_read, 419 .scr_read = nv_scr_read,
412 .scr_write = nv_scr_write, 420 .scr_write = nv_scr_write,
413}; 421};
414 422
423/* OSDL bz11195 reports that link doesn't come online after hardreset
424 * on generic nv's and there have been several other similar reports
425 * on linux-ide. Disable hardreset for generic nv's.
426 */
427static struct ata_port_operations nv_generic_ops = {
428 .inherits = &nv_common_ops,
429 .hardreset = ATA_OP_NULL,
430};
431
415static struct ata_port_operations nv_nf2_ops = { 432static struct ata_port_operations nv_nf2_ops = {
416 .inherits = &nv_generic_ops, 433 .inherits = &nv_common_ops,
417 .freeze = nv_nf2_freeze, 434 .freeze = nv_nf2_freeze,
418 .thaw = nv_nf2_thaw, 435 .thaw = nv_nf2_thaw,
419}; 436};
420 437
421static struct ata_port_operations nv_ck804_ops = { 438static struct ata_port_operations nv_ck804_ops = {
422 .inherits = &nv_generic_ops, 439 .inherits = &nv_common_ops,
423 .freeze = nv_ck804_freeze, 440 .freeze = nv_ck804_freeze,
424 .thaw = nv_ck804_thaw, 441 .thaw = nv_ck804_thaw,
425 .host_stop = nv_ck804_host_stop, 442 .host_stop = nv_ck804_host_stop,
426}; 443};
427 444
428static struct ata_port_operations nv_adma_ops = { 445static struct ata_port_operations nv_adma_ops = {
429 .inherits = &nv_generic_ops, 446 .inherits = &nv_common_ops,
430 447
431 .check_atapi_dma = nv_adma_check_atapi_dma, 448 .check_atapi_dma = nv_adma_check_atapi_dma,
432 .sff_tf_read = nv_adma_tf_read, 449 .sff_tf_read = nv_adma_tf_read,
@@ -450,7 +467,7 @@ static struct ata_port_operations nv_adma_ops = {
450}; 467};
451 468
452static struct ata_port_operations nv_swncq_ops = { 469static struct ata_port_operations nv_swncq_ops = {
453 .inherits = &nv_generic_ops, 470 .inherits = &nv_common_ops,
454 471
455 .qc_defer = ata_std_qc_defer, 472 .qc_defer = ata_std_qc_defer,
456 .qc_prep = nv_swncq_qc_prep, 473 .qc_prep = nv_swncq_qc_prep,
@@ -1494,21 +1511,21 @@ static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance)
1494 return ret; 1511 return ret;
1495} 1512}
1496 1513
1497static int nv_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 1514static int nv_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
1498{ 1515{
1499 if (sc_reg > SCR_CONTROL) 1516 if (sc_reg > SCR_CONTROL)
1500 return -EINVAL; 1517 return -EINVAL;
1501 1518
1502 *val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4)); 1519 *val = ioread32(link->ap->ioaddr.scr_addr + (sc_reg * 4));
1503 return 0; 1520 return 0;
1504} 1521}
1505 1522
1506static int nv_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 1523static int nv_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
1507{ 1524{
1508 if (sc_reg > SCR_CONTROL) 1525 if (sc_reg > SCR_CONTROL)
1509 return -EINVAL; 1526 return -EINVAL;
1510 1527
1511 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 1528 iowrite32(val, link->ap->ioaddr.scr_addr + (sc_reg * 4));
1512 return 0; 1529 return 0;
1513} 1530}
1514 1531
@@ -2201,9 +2218,9 @@ static void nv_swncq_host_interrupt(struct ata_port *ap, u16 fis)
2201 if (!pp->qc_active) 2218 if (!pp->qc_active)
2202 return; 2219 return;
2203 2220
2204 if (ap->ops->scr_read(ap, SCR_ERROR, &serror)) 2221 if (ap->ops->scr_read(&ap->link, SCR_ERROR, &serror))
2205 return; 2222 return;
2206 ap->ops->scr_write(ap, SCR_ERROR, serror); 2223 ap->ops->scr_write(&ap->link, SCR_ERROR, serror);
2207 2224
2208 if (ata_stat & ATA_ERR) { 2225 if (ata_stat & ATA_ERR) {
2209 ata_ehi_clear_desc(ehi); 2226 ata_ehi_clear_desc(ehi);
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index 030665ba76b7..750d8cdc00cd 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -137,8 +137,8 @@ struct pdc_port_priv {
137 dma_addr_t pkt_dma; 137 dma_addr_t pkt_dma;
138}; 138};
139 139
140static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 140static int pdc_sata_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
141static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 141static int pdc_sata_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
142static int pdc_ata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 142static int pdc_ata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
143static int pdc_common_port_start(struct ata_port *ap); 143static int pdc_common_port_start(struct ata_port *ap);
144static int pdc_sata_port_start(struct ata_port *ap); 144static int pdc_sata_port_start(struct ata_port *ap);
@@ -386,19 +386,21 @@ static int pdc_sata_cable_detect(struct ata_port *ap)
386 return ATA_CBL_SATA; 386 return ATA_CBL_SATA;
387} 387}
388 388
389static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 389static int pdc_sata_scr_read(struct ata_link *link,
390 unsigned int sc_reg, u32 *val)
390{ 391{
391 if (sc_reg > SCR_CONTROL) 392 if (sc_reg > SCR_CONTROL)
392 return -EINVAL; 393 return -EINVAL;
393 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 394 *val = readl(link->ap->ioaddr.scr_addr + (sc_reg * 4));
394 return 0; 395 return 0;
395} 396}
396 397
397static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 398static int pdc_sata_scr_write(struct ata_link *link,
399 unsigned int sc_reg, u32 val)
398{ 400{
399 if (sc_reg > SCR_CONTROL) 401 if (sc_reg > SCR_CONTROL)
400 return -EINVAL; 402 return -EINVAL;
401 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 403 writel(val, link->ap->ioaddr.scr_addr + (sc_reg * 4));
402 return 0; 404 return 0;
403} 405}
404 406
@@ -731,7 +733,7 @@ static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
731 if (sata_scr_valid(&ap->link)) { 733 if (sata_scr_valid(&ap->link)) {
732 u32 serror; 734 u32 serror;
733 735
734 pdc_sata_scr_read(ap, SCR_ERROR, &serror); 736 pdc_sata_scr_read(&ap->link, SCR_ERROR, &serror);
735 ehi->serror |= serror; 737 ehi->serror |= serror;
736 } 738 }
737 739
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index 1600107047cf..a000c86ac859 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -111,8 +111,8 @@ struct qs_port_priv {
111 qs_state_t state; 111 qs_state_t state;
112}; 112};
113 113
114static int qs_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 114static int qs_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
115static int qs_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 115static int qs_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
116static int qs_ata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 116static int qs_ata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
117static int qs_port_start(struct ata_port *ap); 117static int qs_port_start(struct ata_port *ap);
118static void qs_host_stop(struct ata_host *host); 118static void qs_host_stop(struct ata_host *host);
@@ -242,11 +242,11 @@ static int qs_prereset(struct ata_link *link, unsigned long deadline)
242 return ata_sff_prereset(link, deadline); 242 return ata_sff_prereset(link, deadline);
243} 243}
244 244
245static int qs_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 245static int qs_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
246{ 246{
247 if (sc_reg > SCR_CONTROL) 247 if (sc_reg > SCR_CONTROL)
248 return -EINVAL; 248 return -EINVAL;
249 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 8)); 249 *val = readl(link->ap->ioaddr.scr_addr + (sc_reg * 8));
250 return 0; 250 return 0;
251} 251}
252 252
@@ -256,11 +256,11 @@ static void qs_error_handler(struct ata_port *ap)
256 ata_std_error_handler(ap); 256 ata_std_error_handler(ap);
257} 257}
258 258
259static int qs_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 259static int qs_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
260{ 260{
261 if (sc_reg > SCR_CONTROL) 261 if (sc_reg > SCR_CONTROL)
262 return -EINVAL; 262 return -EINVAL;
263 writel(val, ap->ioaddr.scr_addr + (sc_reg * 8)); 263 writel(val, link->ap->ioaddr.scr_addr + (sc_reg * 8));
264 return 0; 264 return 0;
265} 265}
266 266
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 88bf4212590f..031d7b7dee34 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -115,8 +115,8 @@ static int sil_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
115static int sil_pci_device_resume(struct pci_dev *pdev); 115static int sil_pci_device_resume(struct pci_dev *pdev);
116#endif 116#endif
117static void sil_dev_config(struct ata_device *dev); 117static void sil_dev_config(struct ata_device *dev);
118static int sil_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 118static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
119static int sil_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 119static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
120static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed); 120static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed);
121static void sil_freeze(struct ata_port *ap); 121static void sil_freeze(struct ata_port *ap);
122static void sil_thaw(struct ata_port *ap); 122static void sil_thaw(struct ata_port *ap);
@@ -317,9 +317,9 @@ static inline void __iomem *sil_scr_addr(struct ata_port *ap,
317 return NULL; 317 return NULL;
318} 318}
319 319
320static int sil_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 320static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
321{ 321{
322 void __iomem *mmio = sil_scr_addr(ap, sc_reg); 322 void __iomem *mmio = sil_scr_addr(link->ap, sc_reg);
323 323
324 if (mmio) { 324 if (mmio) {
325 *val = readl(mmio); 325 *val = readl(mmio);
@@ -328,9 +328,9 @@ static int sil_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
328 return -EINVAL; 328 return -EINVAL;
329} 329}
330 330
331static int sil_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 331static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
332{ 332{
333 void __iomem *mmio = sil_scr_addr(ap, sc_reg); 333 void __iomem *mmio = sil_scr_addr(link->ap, sc_reg);
334 334
335 if (mmio) { 335 if (mmio) {
336 writel(val, mmio); 336 writel(val, mmio);
@@ -352,8 +352,8 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
352 * controllers continue to assert IRQ as long as 352 * controllers continue to assert IRQ as long as
353 * SError bits are pending. Clear SError immediately. 353 * SError bits are pending. Clear SError immediately.
354 */ 354 */
355 sil_scr_read(ap, SCR_ERROR, &serror); 355 sil_scr_read(&ap->link, SCR_ERROR, &serror);
356 sil_scr_write(ap, SCR_ERROR, serror); 356 sil_scr_write(&ap->link, SCR_ERROR, serror);
357 357
358 /* Sometimes spurious interrupts occur, double check 358 /* Sometimes spurious interrupts occur, double check
359 * it's PHYRDY CHG. 359 * it's PHYRDY CHG.
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 84ffcc26a74b..4621807a1a6a 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -340,8 +340,8 @@ struct sil24_port_priv {
340}; 340};
341 341
342static void sil24_dev_config(struct ata_device *dev); 342static void sil24_dev_config(struct ata_device *dev);
343static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val); 343static int sil24_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val);
344static int sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); 344static int sil24_scr_write(struct ata_link *link, unsigned sc_reg, u32 val);
345static int sil24_qc_defer(struct ata_queued_cmd *qc); 345static int sil24_qc_defer(struct ata_queued_cmd *qc);
346static void sil24_qc_prep(struct ata_queued_cmd *qc); 346static void sil24_qc_prep(struct ata_queued_cmd *qc);
347static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc); 347static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
@@ -504,9 +504,9 @@ static int sil24_scr_map[] = {
504 [SCR_ACTIVE] = 3, 504 [SCR_ACTIVE] = 3,
505}; 505};
506 506
507static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val) 507static int sil24_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val)
508{ 508{
509 void __iomem *scr_addr = sil24_port_base(ap) + PORT_SCONTROL; 509 void __iomem *scr_addr = sil24_port_base(link->ap) + PORT_SCONTROL;
510 510
511 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 511 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
512 void __iomem *addr; 512 void __iomem *addr;
@@ -517,9 +517,9 @@ static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val)
517 return -EINVAL; 517 return -EINVAL;
518} 518}
519 519
520static int sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) 520static int sil24_scr_write(struct ata_link *link, unsigned sc_reg, u32 val)
521{ 521{
522 void __iomem *scr_addr = sil24_port_base(ap) + PORT_SCONTROL; 522 void __iomem *scr_addr = sil24_port_base(link->ap) + PORT_SCONTROL;
523 523
524 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 524 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
525 void __iomem *addr; 525 void __iomem *addr;
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 1010b3069bd5..9c43b4e7c4a6 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -64,8 +64,8 @@ enum {
64}; 64};
65 65
66static int sis_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 66static int sis_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
67static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 67static int sis_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
68static int sis_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 68static int sis_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
69 69
70static const struct pci_device_id sis_pci_tbl[] = { 70static const struct pci_device_id sis_pci_tbl[] = {
71 { PCI_VDEVICE(SI, 0x0180), sis_180 }, /* SiS 964/180 */ 71 { PCI_VDEVICE(SI, 0x0180), sis_180 }, /* SiS 964/180 */
@@ -134,10 +134,11 @@ static unsigned int get_scr_cfg_addr(struct ata_port *ap, unsigned int sc_reg)
134 return addr; 134 return addr;
135} 135}
136 136
137static u32 sis_scr_cfg_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 137static u32 sis_scr_cfg_read(struct ata_link *link,
138 unsigned int sc_reg, u32 *val)
138{ 139{
139 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 140 struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
140 unsigned int cfg_addr = get_scr_cfg_addr(ap, sc_reg); 141 unsigned int cfg_addr = get_scr_cfg_addr(link->ap, sc_reg);
141 u32 val2 = 0; 142 u32 val2 = 0;
142 u8 pmr; 143 u8 pmr;
143 144
@@ -158,10 +159,11 @@ static u32 sis_scr_cfg_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
158 return 0; 159 return 0;
159} 160}
160 161
161static int sis_scr_cfg_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 162static int sis_scr_cfg_write(struct ata_link *link,
163 unsigned int sc_reg, u32 val)
162{ 164{
163 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 165 struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
164 unsigned int cfg_addr = get_scr_cfg_addr(ap, sc_reg); 166 unsigned int cfg_addr = get_scr_cfg_addr(link->ap, sc_reg);
165 u8 pmr; 167 u8 pmr;
166 168
167 if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */ 169 if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */
@@ -178,8 +180,9 @@ static int sis_scr_cfg_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
178 return 0; 180 return 0;
179} 181}
180 182
181static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 183static int sis_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
182{ 184{
185 struct ata_port *ap = link->ap;
183 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 186 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
184 u8 pmr; 187 u8 pmr;
185 188
@@ -187,7 +190,7 @@ static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
187 return -EINVAL; 190 return -EINVAL;
188 191
189 if (ap->flags & SIS_FLAG_CFGSCR) 192 if (ap->flags & SIS_FLAG_CFGSCR)
190 return sis_scr_cfg_read(ap, sc_reg, val); 193 return sis_scr_cfg_read(link, sc_reg, val);
191 194
192 pci_read_config_byte(pdev, SIS_PMR, &pmr); 195 pci_read_config_byte(pdev, SIS_PMR, &pmr);
193 196
@@ -202,8 +205,9 @@ static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
202 return 0; 205 return 0;
203} 206}
204 207
205static int sis_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 208static int sis_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
206{ 209{
210 struct ata_port *ap = link->ap;
207 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 211 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
208 u8 pmr; 212 u8 pmr;
209 213
@@ -213,7 +217,7 @@ static int sis_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
213 pci_read_config_byte(pdev, SIS_PMR, &pmr); 217 pci_read_config_byte(pdev, SIS_PMR, &pmr);
214 218
215 if (ap->flags & SIS_FLAG_CFGSCR) 219 if (ap->flags & SIS_FLAG_CFGSCR)
216 return sis_scr_cfg_write(ap, sc_reg, val); 220 return sis_scr_cfg_write(link, sc_reg, val);
217 else { 221 else {
218 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 222 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4));
219 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || 223 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) ||
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index fb13b82aacba..609d147813ae 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -123,20 +123,22 @@ static int k2_sata_check_atapi_dma(struct ata_queued_cmd *qc)
123 } 123 }
124} 124}
125 125
126static int k2_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 126static int k2_sata_scr_read(struct ata_link *link,
127 unsigned int sc_reg, u32 *val)
127{ 128{
128 if (sc_reg > SCR_CONTROL) 129 if (sc_reg > SCR_CONTROL)
129 return -EINVAL; 130 return -EINVAL;
130 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 131 *val = readl(link->ap->ioaddr.scr_addr + (sc_reg * 4));
131 return 0; 132 return 0;
132} 133}
133 134
134 135
135static int k2_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 136static int k2_sata_scr_write(struct ata_link *link,
137 unsigned int sc_reg, u32 val)
136{ 138{
137 if (sc_reg > SCR_CONTROL) 139 if (sc_reg > SCR_CONTROL)
138 return -EINVAL; 140 return -EINVAL;
139 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 141 writel(val, link->ap->ioaddr.scr_addr + (sc_reg * 4));
140 return 0; 142 return 0;
141} 143}
142 144
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index db529b849948..019575bb3e08 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -57,8 +57,8 @@ struct uli_priv {
57}; 57};
58 58
59static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 59static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
60static int uli_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 60static int uli_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
61static int uli_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 61static int uli_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
62 62
63static const struct pci_device_id uli_pci_tbl[] = { 63static const struct pci_device_id uli_pci_tbl[] = {
64 { PCI_VDEVICE(AL, 0x5289), uli_5289 }, 64 { PCI_VDEVICE(AL, 0x5289), uli_5289 },
@@ -107,39 +107,39 @@ static unsigned int get_scr_cfg_addr(struct ata_port *ap, unsigned int sc_reg)
107 return hpriv->scr_cfg_addr[ap->port_no] + (4 * sc_reg); 107 return hpriv->scr_cfg_addr[ap->port_no] + (4 * sc_reg);
108} 108}
109 109
110static u32 uli_scr_cfg_read(struct ata_port *ap, unsigned int sc_reg) 110static u32 uli_scr_cfg_read(struct ata_link *link, unsigned int sc_reg)
111{ 111{
112 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 112 struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
113 unsigned int cfg_addr = get_scr_cfg_addr(ap, sc_reg); 113 unsigned int cfg_addr = get_scr_cfg_addr(link->ap, sc_reg);
114 u32 val; 114 u32 val;
115 115
116 pci_read_config_dword(pdev, cfg_addr, &val); 116 pci_read_config_dword(pdev, cfg_addr, &val);
117 return val; 117 return val;
118} 118}
119 119
120static void uli_scr_cfg_write(struct ata_port *ap, unsigned int scr, u32 val) 120static void uli_scr_cfg_write(struct ata_link *link, unsigned int scr, u32 val)
121{ 121{
122 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 122 struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
123 unsigned int cfg_addr = get_scr_cfg_addr(ap, scr); 123 unsigned int cfg_addr = get_scr_cfg_addr(link->ap, scr);
124 124
125 pci_write_config_dword(pdev, cfg_addr, val); 125 pci_write_config_dword(pdev, cfg_addr, val);
126} 126}
127 127
128static int uli_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 128static int uli_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
129{ 129{
130 if (sc_reg > SCR_CONTROL) 130 if (sc_reg > SCR_CONTROL)
131 return -EINVAL; 131 return -EINVAL;
132 132
133 *val = uli_scr_cfg_read(ap, sc_reg); 133 *val = uli_scr_cfg_read(link, sc_reg);
134 return 0; 134 return 0;
135} 135}
136 136
137static int uli_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 137static int uli_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
138{ 138{
139 if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0 139 if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0
140 return -EINVAL; 140 return -EINVAL;
141 141
142 uli_scr_cfg_write(ap, sc_reg, val); 142 uli_scr_cfg_write(link, sc_reg, val);
143 return 0; 143 return 0;
144} 144}
145 145
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 96deeb354e16..1cfa74535d91 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -68,8 +68,8 @@ enum {
68}; 68};
69 69
70static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 70static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
71static int svia_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); 71static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
72static int svia_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); 72static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
73static void svia_noop_freeze(struct ata_port *ap); 73static void svia_noop_freeze(struct ata_port *ap);
74static int vt6420_prereset(struct ata_link *link, unsigned long deadline); 74static int vt6420_prereset(struct ata_link *link, unsigned long deadline);
75static int vt6421_pata_cable_detect(struct ata_port *ap); 75static int vt6421_pata_cable_detect(struct ata_port *ap);
@@ -152,19 +152,19 @@ MODULE_LICENSE("GPL");
152MODULE_DEVICE_TABLE(pci, svia_pci_tbl); 152MODULE_DEVICE_TABLE(pci, svia_pci_tbl);
153MODULE_VERSION(DRV_VERSION); 153MODULE_VERSION(DRV_VERSION);
154 154
155static int svia_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 155static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
156{ 156{
157 if (sc_reg > SCR_CONTROL) 157 if (sc_reg > SCR_CONTROL)
158 return -EINVAL; 158 return -EINVAL;
159 *val = ioread32(ap->ioaddr.scr_addr + (4 * sc_reg)); 159 *val = ioread32(link->ap->ioaddr.scr_addr + (4 * sc_reg));
160 return 0; 160 return 0;
161} 161}
162 162
163static int svia_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 163static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
164{ 164{
165 if (sc_reg > SCR_CONTROL) 165 if (sc_reg > SCR_CONTROL)
166 return -EINVAL; 166 return -EINVAL;
167 iowrite32(val, ap->ioaddr.scr_addr + (4 * sc_reg)); 167 iowrite32(val, link->ap->ioaddr.scr_addr + (4 * sc_reg));
168 return 0; 168 return 0;
169} 169}
170 170
@@ -210,20 +210,20 @@ static int vt6420_prereset(struct ata_link *link, unsigned long deadline)
210 goto skip_scr; 210 goto skip_scr;
211 211
212 /* Resume phy. This is the old SATA resume sequence */ 212 /* Resume phy. This is the old SATA resume sequence */
213 svia_scr_write(ap, SCR_CONTROL, 0x300); 213 svia_scr_write(link, SCR_CONTROL, 0x300);
214 svia_scr_read(ap, SCR_CONTROL, &scontrol); /* flush */ 214 svia_scr_read(link, SCR_CONTROL, &scontrol); /* flush */
215 215
216 /* wait for phy to become ready, if necessary */ 216 /* wait for phy to become ready, if necessary */
217 do { 217 do {
218 msleep(200); 218 msleep(200);
219 svia_scr_read(ap, SCR_STATUS, &sstatus); 219 svia_scr_read(link, SCR_STATUS, &sstatus);
220 if ((sstatus & 0xf) != 1) 220 if ((sstatus & 0xf) != 1)
221 break; 221 break;
222 } while (time_before(jiffies, timeout)); 222 } while (time_before(jiffies, timeout));
223 223
224 /* open code sata_print_link_status() */ 224 /* open code sata_print_link_status() */
225 svia_scr_read(ap, SCR_STATUS, &sstatus); 225 svia_scr_read(link, SCR_STATUS, &sstatus);
226 svia_scr_read(ap, SCR_CONTROL, &scontrol); 226 svia_scr_read(link, SCR_CONTROL, &scontrol);
227 227
228 online = (sstatus & 0xf) == 0x3; 228 online = (sstatus & 0xf) == 0x3;
229 229
@@ -232,7 +232,7 @@ static int vt6420_prereset(struct ata_link *link, unsigned long deadline)
232 online ? "up" : "down", sstatus, scontrol); 232 online ? "up" : "down", sstatus, scontrol);
233 233
234 /* SStatus is read one more time */ 234 /* SStatus is read one more time */
235 svia_scr_read(ap, SCR_STATUS, &sstatus); 235 svia_scr_read(link, SCR_STATUS, &sstatus);
236 236
237 if (!online) { 237 if (!online) {
238 /* tell EH to bail */ 238 /* tell EH to bail */
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index f3d635c0a2e9..c57cdff9e6bd 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -98,20 +98,22 @@ enum {
98 VSC_SATA_INT_PHY_CHANGE), 98 VSC_SATA_INT_PHY_CHANGE),
99}; 99};
100 100
101static int vsc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) 101static int vsc_sata_scr_read(struct ata_link *link,
102 unsigned int sc_reg, u32 *val)
102{ 103{
103 if (sc_reg > SCR_CONTROL) 104 if (sc_reg > SCR_CONTROL)
104 return -EINVAL; 105 return -EINVAL;
105 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 106 *val = readl(link->ap->ioaddr.scr_addr + (sc_reg * 4));
106 return 0; 107 return 0;
107} 108}
108 109
109 110
110static int vsc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) 111static int vsc_sata_scr_write(struct ata_link *link,
112 unsigned int sc_reg, u32 val)
111{ 113{
112 if (sc_reg > SCR_CONTROL) 114 if (sc_reg > SCR_CONTROL)
113 return -EINVAL; 115 return -EINVAL;
114 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 116 writel(val, link->ap->ioaddr.scr_addr + (sc_reg * 4));
115 return 0; 117 return 0;
116} 118}
117 119