diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-21 22:03:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-21 22:03:38 -0400 |
commit | e10117d36ef758da0690c95ecffc09d5dd7da479 (patch) | |
tree | f2bb867cfc33f24d9c6bbb36dd189869e62ecce2 /drivers/ata | |
parent | f3270b16e00f0614fa418dcc50883da5949375b4 (diff) | |
parent | 89692c03226a066a017048cf7fbacbaa645f0e79 (diff) |
Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/libata-dev
* 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/libata-dev: (26 commits)
include/linux/libata.h: fix typo
pata_bf54x: fix return type of bfin_set_devctl
Drivers: ata: Makefile: replace the use of <module>-objs with <module>-y
libahci: fix result_tf handling after an ATA PIO data-in command
pata_sl82c105: implement sff_irq_check() method
pata_sil680: implement sff_irq_check() method
pata_pdc202xx_old: implement sff_irq_check() method
pata_cmd640: implement sff_irq_check() method
ata_piix: Add device ID for ICH4-L
pata_sil680: make sil680_sff_exec_command() 'static'
ata: Intel IDE-R support
libata: reorder ata_queued_cmd to remove alignment padding on 64 bit builds
libata: Signal that our SATL supports WRITE SAME(16) with UNMAP
ata_piix: remove SIDPR locking
libata: implement cross-port EH exclusion
libata: add @ap to ata_wait_register() and introduce ata_msleep()
ata_piix: implement LPM support
libata: implement LPM support for port multipliers
libata: reimplement link power management
libata: implement sata_link_scr_lpm() and make ata_dev_set_feature() global
...
Diffstat (limited to 'drivers/ata')
28 files changed, 1634 insertions, 601 deletions
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile index d5df04a395ca..c501af5b12b9 100644 --- a/drivers/ata/Makefile +++ b/drivers/ata/Makefile | |||
@@ -99,7 +99,7 @@ obj-$(CONFIG_ATA_GENERIC) += ata_generic.o | |||
99 | # Should be last libata driver | 99 | # Should be last libata driver |
100 | obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o | 100 | obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o |
101 | 101 | ||
102 | libata-objs := libata-core.o libata-scsi.o libata-eh.o | 102 | libata-y := libata-core.o libata-scsi.o libata-eh.o libata-transport.o |
103 | libata-$(CONFIG_ATA_SFF) += libata-sff.o | 103 | libata-$(CONFIG_ATA_SFF) += libata-sff.o |
104 | libata-$(CONFIG_SATA_PMP) += libata-pmp.o | 104 | libata-$(CONFIG_SATA_PMP) += libata-pmp.o |
105 | libata-$(CONFIG_ATA_ACPI) += libata-acpi.o | 105 | libata-$(CONFIG_ATA_ACPI) += libata-acpi.o |
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 99d0e5a51148..328826381a2d 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c | |||
@@ -1208,9 +1208,6 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1208 | ata_port_pbar_desc(ap, AHCI_PCI_BAR, | 1208 | ata_port_pbar_desc(ap, AHCI_PCI_BAR, |
1209 | 0x100 + ap->port_no * 0x80, "port"); | 1209 | 0x100 + ap->port_no * 0x80, "port"); |
1210 | 1210 | ||
1211 | /* set initial link pm policy */ | ||
1212 | ap->pm_policy = NOT_AVAILABLE; | ||
1213 | |||
1214 | /* set enclosure management message type */ | 1211 | /* set enclosure management message type */ |
1215 | if (ap->flags & ATA_FLAG_EM) | 1212 | if (ap->flags & ATA_FLAG_EM) |
1216 | ap->em_message_type = hpriv->em_msg_type; | 1213 | ap->em_message_type = hpriv->em_msg_type; |
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h index e5fdeebf9ef0..329cbbb91284 100644 --- a/drivers/ata/ahci.h +++ b/drivers/ata/ahci.h | |||
@@ -72,6 +72,7 @@ enum { | |||
72 | AHCI_CMD_RESET = (1 << 8), | 72 | AHCI_CMD_RESET = (1 << 8), |
73 | AHCI_CMD_CLR_BUSY = (1 << 10), | 73 | AHCI_CMD_CLR_BUSY = (1 << 10), |
74 | 74 | ||
75 | RX_FIS_PIO_SETUP = 0x20, /* offset of PIO Setup FIS data */ | ||
75 | RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ | 76 | RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ |
76 | RX_FIS_SDB = 0x58, /* offset of SDB FIS data */ | 77 | RX_FIS_SDB = 0x58, /* offset of SDB FIS data */ |
77 | RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */ | 78 | RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */ |
@@ -201,7 +202,6 @@ enum { | |||
201 | AHCI_HFLAG_MV_PATA = (1 << 4), /* PATA port */ | 202 | AHCI_HFLAG_MV_PATA = (1 << 4), /* PATA port */ |
202 | AHCI_HFLAG_NO_MSI = (1 << 5), /* no PCI MSI */ | 203 | AHCI_HFLAG_NO_MSI = (1 << 5), /* no PCI MSI */ |
203 | AHCI_HFLAG_NO_PMP = (1 << 6), /* no PMP */ | 204 | AHCI_HFLAG_NO_PMP = (1 << 6), /* no PMP */ |
204 | AHCI_HFLAG_NO_HOTPLUG = (1 << 7), /* ignore PxSERR.DIAG.N */ | ||
205 | AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */ | 205 | AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */ |
206 | AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */ | 206 | AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */ |
207 | AHCI_HFLAG_NO_SUSPEND = (1 << 10), /* don't suspend */ | 207 | AHCI_HFLAG_NO_SUSPEND = (1 << 10), /* don't suspend */ |
@@ -216,7 +216,7 @@ enum { | |||
216 | AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | | 216 | AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | |
217 | ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | | 217 | ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | |
218 | ATA_FLAG_ACPI_SATA | ATA_FLAG_AN | | 218 | ATA_FLAG_ACPI_SATA | ATA_FLAG_AN | |
219 | ATA_FLAG_IPM, | 219 | ATA_FLAG_LPM, |
220 | 220 | ||
221 | ICH_MAP = 0x90, /* ICH MAP register */ | 221 | ICH_MAP = 0x90, /* ICH MAP register */ |
222 | 222 | ||
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c index 84b643270e7a..6fef1fa75c54 100644 --- a/drivers/ata/ahci_platform.c +++ b/drivers/ata/ahci_platform.c | |||
@@ -129,9 +129,6 @@ static int __init ahci_probe(struct platform_device *pdev) | |||
129 | ata_port_desc(ap, "mmio %pR", mem); | 129 | ata_port_desc(ap, "mmio %pR", mem); |
130 | ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); | 130 | ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); |
131 | 131 | ||
132 | /* set initial link pm policy */ | ||
133 | ap->pm_policy = NOT_AVAILABLE; | ||
134 | |||
135 | /* set enclosure management message type */ | 132 | /* set enclosure management message type */ |
136 | if (ap->flags & ATA_FLAG_EM) | 133 | if (ap->flags & ATA_FLAG_EM) |
137 | ap->em_message_type = hpriv->em_msg_type; | 134 | ap->em_message_type = hpriv->em_msg_type; |
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c index cc5f7726bde7..6981f7680a00 100644 --- a/drivers/ata/ata_generic.c +++ b/drivers/ata/ata_generic.c | |||
@@ -35,6 +35,7 @@ | |||
35 | enum { | 35 | enum { |
36 | ATA_GEN_CLASS_MATCH = (1 << 0), | 36 | ATA_GEN_CLASS_MATCH = (1 << 0), |
37 | ATA_GEN_FORCE_DMA = (1 << 1), | 37 | ATA_GEN_FORCE_DMA = (1 << 1), |
38 | ATA_GEN_INTEL_IDER = (1 << 2), | ||
38 | }; | 39 | }; |
39 | 40 | ||
40 | /** | 41 | /** |
@@ -109,6 +110,49 @@ static struct ata_port_operations generic_port_ops = { | |||
109 | static int all_generic_ide; /* Set to claim all devices */ | 110 | static int all_generic_ide; /* Set to claim all devices */ |
110 | 111 | ||
111 | /** | 112 | /** |
113 | * is_intel_ider - identify intel IDE-R devices | ||
114 | * @dev: PCI device | ||
115 | * | ||
116 | * Distinguish Intel IDE-R controller devices from other Intel IDE | ||
117 | * devices. IDE-R devices have no timing registers and are in | ||
118 | * most respects virtual. They should be driven by the ata_generic | ||
119 | * driver. | ||
120 | * | ||
121 | * IDE-R devices have PCI offset 0xF8.L as zero, later Intel ATA has | ||
122 | * it non zero. All Intel ATA has 0x40 writable (timing), but it is | ||
123 | * not writable on IDE-R devices (this is guaranteed). | ||
124 | */ | ||
125 | |||
126 | static int is_intel_ider(struct pci_dev *dev) | ||
127 | { | ||
128 | /* For Intel IDE the value at 0xF8 is only zero on IDE-R | ||
129 | interfaces */ | ||
130 | u32 r; | ||
131 | u16 t; | ||
132 | |||
133 | /* Check the manufacturing ID, it will be zero for IDE-R */ | ||
134 | pci_read_config_dword(dev, 0xF8, &r); | ||
135 | /* Not IDE-R: punt so that ata_(old)piix gets it */ | ||
136 | if (r != 0) | ||
137 | return 0; | ||
138 | /* 0xF8 will also be zero on some early Intel IDE devices | ||
139 | but they will have a sane timing register */ | ||
140 | pci_read_config_word(dev, 0x40, &t); | ||
141 | if (t != 0) | ||
142 | return 0; | ||
143 | /* Finally check if the timing register is writable so that | ||
144 | we eliminate any early devices hot-docked in a docking | ||
145 | station */ | ||
146 | pci_write_config_word(dev, 0x40, 1); | ||
147 | pci_read_config_word(dev, 0x40, &t); | ||
148 | if (t) { | ||
149 | pci_write_config_word(dev, 0x40, 0); | ||
150 | return 0; | ||
151 | } | ||
152 | return 1; | ||
153 | } | ||
154 | |||
155 | /** | ||
112 | * ata_generic_init - attach generic IDE | 156 | * ata_generic_init - attach generic IDE |
113 | * @dev: PCI device found | 157 | * @dev: PCI device found |
114 | * @id: match entry | 158 | * @id: match entry |
@@ -134,6 +178,10 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id | |||
134 | if ((id->driver_data & ATA_GEN_CLASS_MATCH) && all_generic_ide == 0) | 178 | if ((id->driver_data & ATA_GEN_CLASS_MATCH) && all_generic_ide == 0) |
135 | return -ENODEV; | 179 | return -ENODEV; |
136 | 180 | ||
181 | if (id->driver_data & ATA_GEN_INTEL_IDER) | ||
182 | if (!is_intel_ider(dev)) | ||
183 | return -ENODEV; | ||
184 | |||
137 | /* Devices that need care */ | 185 | /* Devices that need care */ |
138 | if (dev->vendor == PCI_VENDOR_ID_UMC && | 186 | if (dev->vendor == PCI_VENDOR_ID_UMC && |
139 | dev->device == PCI_DEVICE_ID_UMC_UM8886A && | 187 | dev->device == PCI_DEVICE_ID_UMC_UM8886A && |
@@ -186,7 +234,11 @@ static struct pci_device_id ata_generic[] = { | |||
186 | { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), }, | 234 | { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), }, |
187 | { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), }, | 235 | { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), }, |
188 | { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), }, | 236 | { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), }, |
189 | #endif | 237 | #endif |
238 | /* Intel, IDE class device */ | ||
239 | { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, | ||
240 | PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, | ||
241 | .driver_data = ATA_GEN_INTEL_IDER }, | ||
190 | /* Must come last. If you add entries adjust this table appropriately */ | 242 | /* Must come last. If you add entries adjust this table appropriately */ |
191 | { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL), | 243 | { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL), |
192 | .driver_data = ATA_GEN_CLASS_MATCH }, | 244 | .driver_data = ATA_GEN_CLASS_MATCH }, |
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index d712675d0a96..6cb14ca8ee85 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c | |||
@@ -158,7 +158,6 @@ struct piix_map_db { | |||
158 | struct piix_host_priv { | 158 | struct piix_host_priv { |
159 | const int *map; | 159 | const int *map; |
160 | u32 saved_iocfg; | 160 | u32 saved_iocfg; |
161 | spinlock_t sidpr_lock; /* FIXME: remove once locking in EH is fixed */ | ||
162 | void __iomem *sidpr; | 161 | void __iomem *sidpr; |
163 | }; | 162 | }; |
164 | 163 | ||
@@ -175,6 +174,8 @@ static int piix_sidpr_scr_read(struct ata_link *link, | |||
175 | unsigned int reg, u32 *val); | 174 | unsigned int reg, u32 *val); |
176 | static int piix_sidpr_scr_write(struct ata_link *link, | 175 | static int piix_sidpr_scr_write(struct ata_link *link, |
177 | unsigned int reg, u32 val); | 176 | unsigned int reg, u32 val); |
177 | static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, | ||
178 | unsigned hints); | ||
178 | static bool piix_irq_check(struct ata_port *ap); | 179 | static bool piix_irq_check(struct ata_port *ap); |
179 | #ifdef CONFIG_PM | 180 | #ifdef CONFIG_PM |
180 | static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); | 181 | static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); |
@@ -209,6 +210,8 @@ static const struct pci_device_id piix_pci_tbl[] = { | |||
209 | { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, | 210 | { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, |
210 | /* Intel ICH3 (E7500/1) UDMA 100 */ | 211 | /* Intel ICH3 (E7500/1) UDMA 100 */ |
211 | { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, | 212 | { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, |
213 | /* Intel ICH4-L */ | ||
214 | { 0x8086, 0x24C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, | ||
212 | /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */ | 215 | /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */ |
213 | { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, | 216 | { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, |
214 | { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, | 217 | { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, |
@@ -348,11 +351,22 @@ static struct ata_port_operations ich_pata_ops = { | |||
348 | .set_dmamode = ich_set_dmamode, | 351 | .set_dmamode = ich_set_dmamode, |
349 | }; | 352 | }; |
350 | 353 | ||
354 | static struct device_attribute *piix_sidpr_shost_attrs[] = { | ||
355 | &dev_attr_link_power_management_policy, | ||
356 | NULL | ||
357 | }; | ||
358 | |||
359 | static struct scsi_host_template piix_sidpr_sht = { | ||
360 | ATA_BMDMA_SHT(DRV_NAME), | ||
361 | .shost_attrs = piix_sidpr_shost_attrs, | ||
362 | }; | ||
363 | |||
351 | static struct ata_port_operations piix_sidpr_sata_ops = { | 364 | static struct ata_port_operations piix_sidpr_sata_ops = { |
352 | .inherits = &piix_sata_ops, | 365 | .inherits = &piix_sata_ops, |
353 | .hardreset = sata_std_hardreset, | 366 | .hardreset = sata_std_hardreset, |
354 | .scr_read = piix_sidpr_scr_read, | 367 | .scr_read = piix_sidpr_scr_read, |
355 | .scr_write = piix_sidpr_scr_write, | 368 | .scr_write = piix_sidpr_scr_write, |
369 | .set_lpm = piix_sidpr_set_lpm, | ||
356 | }; | 370 | }; |
357 | 371 | ||
358 | static const struct piix_map_db ich5_map_db = { | 372 | static const struct piix_map_db ich5_map_db = { |
@@ -956,15 +970,12 @@ static int piix_sidpr_scr_read(struct ata_link *link, | |||
956 | unsigned int reg, u32 *val) | 970 | unsigned int reg, u32 *val) |
957 | { | 971 | { |
958 | struct piix_host_priv *hpriv = link->ap->host->private_data; | 972 | struct piix_host_priv *hpriv = link->ap->host->private_data; |
959 | unsigned long flags; | ||
960 | 973 | ||
961 | if (reg >= ARRAY_SIZE(piix_sidx_map)) | 974 | if (reg >= ARRAY_SIZE(piix_sidx_map)) |
962 | return -EINVAL; | 975 | return -EINVAL; |
963 | 976 | ||
964 | spin_lock_irqsave(&hpriv->sidpr_lock, flags); | ||
965 | piix_sidpr_sel(link, reg); | 977 | piix_sidpr_sel(link, reg); |
966 | *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA); | 978 | *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA); |
967 | spin_unlock_irqrestore(&hpriv->sidpr_lock, flags); | ||
968 | return 0; | 979 | return 0; |
969 | } | 980 | } |
970 | 981 | ||
@@ -972,18 +983,21 @@ static int piix_sidpr_scr_write(struct ata_link *link, | |||
972 | unsigned int reg, u32 val) | 983 | unsigned int reg, u32 val) |
973 | { | 984 | { |
974 | struct piix_host_priv *hpriv = link->ap->host->private_data; | 985 | struct piix_host_priv *hpriv = link->ap->host->private_data; |
975 | unsigned long flags; | ||
976 | 986 | ||
977 | if (reg >= ARRAY_SIZE(piix_sidx_map)) | 987 | if (reg >= ARRAY_SIZE(piix_sidx_map)) |
978 | return -EINVAL; | 988 | return -EINVAL; |
979 | 989 | ||
980 | spin_lock_irqsave(&hpriv->sidpr_lock, flags); | ||
981 | piix_sidpr_sel(link, reg); | 990 | piix_sidpr_sel(link, reg); |
982 | iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA); | 991 | iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA); |
983 | spin_unlock_irqrestore(&hpriv->sidpr_lock, flags); | ||
984 | return 0; | 992 | return 0; |
985 | } | 993 | } |
986 | 994 | ||
995 | static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, | ||
996 | unsigned hints) | ||
997 | { | ||
998 | return sata_link_scr_lpm(link, policy, false); | ||
999 | } | ||
1000 | |||
987 | static bool piix_irq_check(struct ata_port *ap) | 1001 | static bool piix_irq_check(struct ata_port *ap) |
988 | { | 1002 | { |
989 | if (unlikely(!ap->ioaddr.bmdma_addr)) | 1003 | if (unlikely(!ap->ioaddr.bmdma_addr)) |
@@ -1543,6 +1557,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev, | |||
1543 | struct device *dev = &pdev->dev; | 1557 | struct device *dev = &pdev->dev; |
1544 | struct ata_port_info port_info[2]; | 1558 | struct ata_port_info port_info[2]; |
1545 | const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] }; | 1559 | const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] }; |
1560 | struct scsi_host_template *sht = &piix_sht; | ||
1546 | unsigned long port_flags; | 1561 | unsigned long port_flags; |
1547 | struct ata_host *host; | 1562 | struct ata_host *host; |
1548 | struct piix_host_priv *hpriv; | 1563 | struct piix_host_priv *hpriv; |
@@ -1577,7 +1592,6 @@ static int __devinit piix_init_one(struct pci_dev *pdev, | |||
1577 | hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); | 1592 | hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); |
1578 | if (!hpriv) | 1593 | if (!hpriv) |
1579 | return -ENOMEM; | 1594 | return -ENOMEM; |
1580 | spin_lock_init(&hpriv->sidpr_lock); | ||
1581 | 1595 | ||
1582 | /* Save IOCFG, this will be used for cable detection, quirk | 1596 | /* Save IOCFG, this will be used for cable detection, quirk |
1583 | * detection and restoration on detach. This is necessary | 1597 | * detection and restoration on detach. This is necessary |
@@ -1612,6 +1626,8 @@ static int __devinit piix_init_one(struct pci_dev *pdev, | |||
1612 | rc = piix_init_sidpr(host); | 1626 | rc = piix_init_sidpr(host); |
1613 | if (rc) | 1627 | if (rc) |
1614 | return rc; | 1628 | return rc; |
1629 | if (host->ports[0]->ops == &piix_sidpr_sata_ops) | ||
1630 | sht = &piix_sidpr_sht; | ||
1615 | } | 1631 | } |
1616 | 1632 | ||
1617 | /* apply IOCFG bit18 quirk */ | 1633 | /* apply IOCFG bit18 quirk */ |
@@ -1638,7 +1654,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev, | |||
1638 | host->flags |= ATA_HOST_PARALLEL_SCAN; | 1654 | host->flags |= ATA_HOST_PARALLEL_SCAN; |
1639 | 1655 | ||
1640 | pci_set_master(pdev); | 1656 | pci_set_master(pdev); |
1641 | return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, &piix_sht); | 1657 | return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht); |
1642 | } | 1658 | } |
1643 | 1659 | ||
1644 | static void piix_remove_one(struct pci_dev *pdev) | 1660 | static void piix_remove_one(struct pci_dev *pdev) |
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 8eea309ea212..ebc08d65b3dd 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c | |||
@@ -56,9 +56,8 @@ MODULE_PARM_DESC(skip_host_reset, "skip global host reset (0=don't skip, 1=skip) | |||
56 | module_param_named(ignore_sss, ahci_ignore_sss, int, 0444); | 56 | module_param_named(ignore_sss, ahci_ignore_sss, int, 0444); |
57 | MODULE_PARM_DESC(ignore_sss, "Ignore staggered spinup flag (0=don't ignore, 1=ignore)"); | 57 | MODULE_PARM_DESC(ignore_sss, "Ignore staggered spinup flag (0=don't ignore, 1=ignore)"); |
58 | 58 | ||
59 | static int ahci_enable_alpm(struct ata_port *ap, | 59 | static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, |
60 | enum link_pm policy); | 60 | unsigned hints); |
61 | static void ahci_disable_alpm(struct ata_port *ap); | ||
62 | static ssize_t ahci_led_show(struct ata_port *ap, char *buf); | 61 | static ssize_t ahci_led_show(struct ata_port *ap, char *buf); |
63 | static ssize_t ahci_led_store(struct ata_port *ap, const char *buf, | 62 | static ssize_t ahci_led_store(struct ata_port *ap, const char *buf, |
64 | size_t size); | 63 | size_t size); |
@@ -164,8 +163,7 @@ struct ata_port_operations ahci_ops = { | |||
164 | .pmp_attach = ahci_pmp_attach, | 163 | .pmp_attach = ahci_pmp_attach, |
165 | .pmp_detach = ahci_pmp_detach, | 164 | .pmp_detach = ahci_pmp_detach, |
166 | 165 | ||
167 | .enable_pm = ahci_enable_alpm, | 166 | .set_lpm = ahci_set_lpm, |
168 | .disable_pm = ahci_disable_alpm, | ||
169 | .em_show = ahci_led_show, | 167 | .em_show = ahci_led_show, |
170 | .em_store = ahci_led_store, | 168 | .em_store = ahci_led_store, |
171 | .sw_activity_show = ahci_activity_show, | 169 | .sw_activity_show = ahci_activity_show, |
@@ -569,7 +567,7 @@ int ahci_stop_engine(struct ata_port *ap) | |||
569 | writel(tmp, port_mmio + PORT_CMD); | 567 | writel(tmp, port_mmio + PORT_CMD); |
570 | 568 | ||
571 | /* wait for engine to stop. This could be as long as 500 msec */ | 569 | /* wait for engine to stop. This could be as long as 500 msec */ |
572 | tmp = ata_wait_register(port_mmio + PORT_CMD, | 570 | tmp = ata_wait_register(ap, port_mmio + PORT_CMD, |
573 | PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500); | 571 | PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500); |
574 | if (tmp & PORT_CMD_LIST_ON) | 572 | if (tmp & PORT_CMD_LIST_ON) |
575 | return -EIO; | 573 | return -EIO; |
@@ -616,7 +614,7 @@ static int ahci_stop_fis_rx(struct ata_port *ap) | |||
616 | writel(tmp, port_mmio + PORT_CMD); | 614 | writel(tmp, port_mmio + PORT_CMD); |
617 | 615 | ||
618 | /* wait for completion, spec says 500ms, give it 1000 */ | 616 | /* wait for completion, spec says 500ms, give it 1000 */ |
619 | tmp = ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_FIS_ON, | 617 | tmp = ata_wait_register(ap, port_mmio + PORT_CMD, PORT_CMD_FIS_ON, |
620 | PORT_CMD_FIS_ON, 10, 1000); | 618 | PORT_CMD_FIS_ON, 10, 1000); |
621 | if (tmp & PORT_CMD_FIS_ON) | 619 | if (tmp & PORT_CMD_FIS_ON) |
622 | return -EBUSY; | 620 | return -EBUSY; |
@@ -642,127 +640,56 @@ static void ahci_power_up(struct ata_port *ap) | |||
642 | writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD); | 640 | writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD); |
643 | } | 641 | } |
644 | 642 | ||
645 | static void ahci_disable_alpm(struct ata_port *ap) | 643 | static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, |
644 | unsigned int hints) | ||
646 | { | 645 | { |
646 | struct ata_port *ap = link->ap; | ||
647 | struct ahci_host_priv *hpriv = ap->host->private_data; | 647 | struct ahci_host_priv *hpriv = ap->host->private_data; |
648 | void __iomem *port_mmio = ahci_port_base(ap); | ||
649 | u32 cmd; | ||
650 | struct ahci_port_priv *pp = ap->private_data; | 648 | struct ahci_port_priv *pp = ap->private_data; |
651 | |||
652 | /* IPM bits should be disabled by libata-core */ | ||
653 | /* get the existing command bits */ | ||
654 | cmd = readl(port_mmio + PORT_CMD); | ||
655 | |||
656 | /* disable ALPM and ASP */ | ||
657 | cmd &= ~PORT_CMD_ASP; | ||
658 | cmd &= ~PORT_CMD_ALPE; | ||
659 | |||
660 | /* force the interface back to active */ | ||
661 | cmd |= PORT_CMD_ICC_ACTIVE; | ||
662 | |||
663 | /* write out new cmd value */ | ||
664 | writel(cmd, port_mmio + PORT_CMD); | ||
665 | cmd = readl(port_mmio + PORT_CMD); | ||
666 | |||
667 | /* wait 10ms to be sure we've come out of any low power state */ | ||
668 | msleep(10); | ||
669 | |||
670 | /* clear out any PhyRdy stuff from interrupt status */ | ||
671 | writel(PORT_IRQ_PHYRDY, port_mmio + PORT_IRQ_STAT); | ||
672 | |||
673 | /* go ahead and clean out PhyRdy Change from Serror too */ | ||
674 | ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18))); | ||
675 | |||
676 | /* | ||
677 | * Clear flag to indicate that we should ignore all PhyRdy | ||
678 | * state changes | ||
679 | */ | ||
680 | hpriv->flags &= ~AHCI_HFLAG_NO_HOTPLUG; | ||
681 | |||
682 | /* | ||
683 | * Enable interrupts on Phy Ready. | ||
684 | */ | ||
685 | pp->intr_mask |= PORT_IRQ_PHYRDY; | ||
686 | writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK); | ||
687 | |||
688 | /* | ||
689 | * don't change the link pm policy - we can be called | ||
690 | * just to turn of link pm temporarily | ||
691 | */ | ||
692 | } | ||
693 | |||
694 | static int ahci_enable_alpm(struct ata_port *ap, | ||
695 | enum link_pm policy) | ||
696 | { | ||
697 | struct ahci_host_priv *hpriv = ap->host->private_data; | ||
698 | void __iomem *port_mmio = ahci_port_base(ap); | 649 | void __iomem *port_mmio = ahci_port_base(ap); |
699 | u32 cmd; | ||
700 | struct ahci_port_priv *pp = ap->private_data; | ||
701 | u32 asp; | ||
702 | 650 | ||
703 | /* Make sure the host is capable of link power management */ | 651 | if (policy != ATA_LPM_MAX_POWER) { |
704 | if (!(hpriv->cap & HOST_CAP_ALPM)) | ||
705 | return -EINVAL; | ||
706 | |||
707 | switch (policy) { | ||
708 | case MAX_PERFORMANCE: | ||
709 | case NOT_AVAILABLE: | ||
710 | /* | 652 | /* |
711 | * if we came here with NOT_AVAILABLE, | 653 | * Disable interrupts on Phy Ready. This keeps us from |
712 | * it just means this is the first time we | 654 | * getting woken up due to spurious phy ready |
713 | * have tried to enable - default to max performance, | 655 | * interrupts. |
714 | * and let the user go to lower power modes on request. | ||
715 | */ | 656 | */ |
716 | ahci_disable_alpm(ap); | 657 | pp->intr_mask &= ~PORT_IRQ_PHYRDY; |
717 | return 0; | 658 | writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK); |
718 | case MIN_POWER: | 659 | |
719 | /* configure HBA to enter SLUMBER */ | 660 | sata_link_scr_lpm(link, policy, false); |
720 | asp = PORT_CMD_ASP; | ||
721 | break; | ||
722 | case MEDIUM_POWER: | ||
723 | /* configure HBA to enter PARTIAL */ | ||
724 | asp = 0; | ||
725 | break; | ||
726 | default: | ||
727 | return -EINVAL; | ||
728 | } | 661 | } |
729 | 662 | ||
730 | /* | 663 | if (hpriv->cap & HOST_CAP_ALPM) { |
731 | * Disable interrupts on Phy Ready. This keeps us from | 664 | u32 cmd = readl(port_mmio + PORT_CMD); |
732 | * getting woken up due to spurious phy ready interrupts | ||
733 | * TBD - Hot plug should be done via polling now, is | ||
734 | * that even supported? | ||
735 | */ | ||
736 | pp->intr_mask &= ~PORT_IRQ_PHYRDY; | ||
737 | writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK); | ||
738 | 665 | ||
739 | /* | 666 | if (policy == ATA_LPM_MAX_POWER || !(hints & ATA_LPM_HIPM)) { |
740 | * Set a flag to indicate that we should ignore all PhyRdy | 667 | cmd &= ~(PORT_CMD_ASP | PORT_CMD_ALPE); |
741 | * state changes since these can happen now whenever we | 668 | cmd |= PORT_CMD_ICC_ACTIVE; |
742 | * change link state | ||
743 | */ | ||
744 | hpriv->flags |= AHCI_HFLAG_NO_HOTPLUG; | ||
745 | 669 | ||
746 | /* get the existing command bits */ | 670 | writel(cmd, port_mmio + PORT_CMD); |
747 | cmd = readl(port_mmio + PORT_CMD); | 671 | readl(port_mmio + PORT_CMD); |
748 | 672 | ||
749 | /* | 673 | /* wait 10ms to be sure we've come out of LPM state */ |
750 | * Set ASP based on Policy | 674 | ata_msleep(ap, 10); |
751 | */ | 675 | } else { |
752 | cmd |= asp; | 676 | cmd |= PORT_CMD_ALPE; |
677 | if (policy == ATA_LPM_MIN_POWER) | ||
678 | cmd |= PORT_CMD_ASP; | ||
753 | 679 | ||
754 | /* | 680 | /* write out new cmd value */ |
755 | * Setting this bit will instruct the HBA to aggressively | 681 | writel(cmd, port_mmio + PORT_CMD); |
756 | * enter a lower power link state when it's appropriate and | 682 | } |
757 | * based on the value set above for ASP | 683 | } |
758 | */ | ||
759 | cmd |= PORT_CMD_ALPE; | ||
760 | 684 | ||
761 | /* write out new cmd value */ | 685 | if (policy == ATA_LPM_MAX_POWER) { |
762 | writel(cmd, port_mmio + PORT_CMD); | 686 | sata_link_scr_lpm(link, policy, false); |
763 | cmd = readl(port_mmio + PORT_CMD); | 687 | |
688 | /* turn PHYRDY IRQ back on */ | ||
689 | pp->intr_mask |= PORT_IRQ_PHYRDY; | ||
690 | writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK); | ||
691 | } | ||
764 | 692 | ||
765 | /* IPM bits should be set by libata-core */ | ||
766 | return 0; | 693 | return 0; |
767 | } | 694 | } |
768 | 695 | ||
@@ -813,7 +740,7 @@ static void ahci_start_port(struct ata_port *ap) | |||
813 | emp->led_state, | 740 | emp->led_state, |
814 | 4); | 741 | 4); |
815 | if (rc == -EBUSY) | 742 | if (rc == -EBUSY) |
816 | msleep(1); | 743 | ata_msleep(ap, 1); |
817 | else | 744 | else |
818 | break; | 745 | break; |
819 | } | 746 | } |
@@ -872,7 +799,7 @@ int ahci_reset_controller(struct ata_host *host) | |||
872 | * reset must complete within 1 second, or | 799 | * reset must complete within 1 second, or |
873 | * the hardware should be considered fried. | 800 | * the hardware should be considered fried. |
874 | */ | 801 | */ |
875 | tmp = ata_wait_register(mmio + HOST_CTL, HOST_RESET, | 802 | tmp = ata_wait_register(NULL, mmio + HOST_CTL, HOST_RESET, |
876 | HOST_RESET, 10, 1000); | 803 | HOST_RESET, 10, 1000); |
877 | 804 | ||
878 | if (tmp & HOST_RESET) { | 805 | if (tmp & HOST_RESET) { |
@@ -1252,7 +1179,7 @@ int ahci_kick_engine(struct ata_port *ap) | |||
1252 | writel(tmp, port_mmio + PORT_CMD); | 1179 | writel(tmp, port_mmio + PORT_CMD); |
1253 | 1180 | ||
1254 | rc = 0; | 1181 | rc = 0; |
1255 | tmp = ata_wait_register(port_mmio + PORT_CMD, | 1182 | tmp = ata_wait_register(ap, port_mmio + PORT_CMD, |
1256 | PORT_CMD_CLO, PORT_CMD_CLO, 1, 500); | 1183 | PORT_CMD_CLO, PORT_CMD_CLO, 1, 500); |
1257 | if (tmp & PORT_CMD_CLO) | 1184 | if (tmp & PORT_CMD_CLO) |
1258 | rc = -EIO; | 1185 | rc = -EIO; |
@@ -1282,8 +1209,8 @@ static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp, | |||
1282 | writel(1, port_mmio + PORT_CMD_ISSUE); | 1209 | writel(1, port_mmio + PORT_CMD_ISSUE); |
1283 | 1210 | ||
1284 | if (timeout_msec) { | 1211 | if (timeout_msec) { |
1285 | tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1, | 1212 | tmp = ata_wait_register(ap, port_mmio + PORT_CMD_ISSUE, |
1286 | 1, timeout_msec); | 1213 | 0x1, 0x1, 1, timeout_msec); |
1287 | if (tmp & 0x1) { | 1214 | if (tmp & 0x1) { |
1288 | ahci_kick_engine(ap); | 1215 | ahci_kick_engine(ap); |
1289 | return -EBUSY; | 1216 | return -EBUSY; |
@@ -1330,7 +1257,7 @@ int ahci_do_softreset(struct ata_link *link, unsigned int *class, | |||
1330 | } | 1257 | } |
1331 | 1258 | ||
1332 | /* spec says at least 5us, but be generous and sleep for 1ms */ | 1259 | /* spec says at least 5us, but be generous and sleep for 1ms */ |
1333 | msleep(1); | 1260 | ata_msleep(ap, 1); |
1334 | 1261 | ||
1335 | /* issue the second D2H Register FIS */ | 1262 | /* issue the second D2H Register FIS */ |
1336 | tf.ctl &= ~ATA_SRST; | 1263 | tf.ctl &= ~ATA_SRST; |
@@ -1660,15 +1587,10 @@ static void ahci_port_intr(struct ata_port *ap) | |||
1660 | if (unlikely(resetting)) | 1587 | if (unlikely(resetting)) |
1661 | status &= ~PORT_IRQ_BAD_PMP; | 1588 | status &= ~PORT_IRQ_BAD_PMP; |
1662 | 1589 | ||
1663 | /* If we are getting PhyRdy, this is | 1590 | /* if LPM is enabled, PHYRDY doesn't mean anything */ |
1664 | * just a power state change, we should | 1591 | if (ap->link.lpm_policy > ATA_LPM_MAX_POWER) { |
1665 | * clear out this, plus the PhyRdy/Comm | ||
1666 | * Wake bits from Serror | ||
1667 | */ | ||
1668 | if ((hpriv->flags & AHCI_HFLAG_NO_HOTPLUG) && | ||
1669 | (status & PORT_IRQ_PHYRDY)) { | ||
1670 | status &= ~PORT_IRQ_PHYRDY; | 1592 | status &= ~PORT_IRQ_PHYRDY; |
1671 | ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18))); | 1593 | ahci_scr_write(&ap->link, SCR_ERROR, SERR_PHYRDY_CHG); |
1672 | } | 1594 | } |
1673 | 1595 | ||
1674 | if (unlikely(status & PORT_IRQ_ERROR)) { | 1596 | if (unlikely(status & PORT_IRQ_ERROR)) { |
@@ -1830,12 +1752,24 @@ static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc) | |||
1830 | static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc) | 1752 | static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc) |
1831 | { | 1753 | { |
1832 | struct ahci_port_priv *pp = qc->ap->private_data; | 1754 | struct ahci_port_priv *pp = qc->ap->private_data; |
1833 | u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; | 1755 | u8 *rx_fis = pp->rx_fis; |
1834 | 1756 | ||
1835 | if (pp->fbs_enabled) | 1757 | if (pp->fbs_enabled) |
1836 | d2h_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ; | 1758 | rx_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ; |
1759 | |||
1760 | /* | ||
1761 | * After a successful execution of an ATA PIO data-in command, | ||
1762 | * the device doesn't send D2H Reg FIS to update the TF and | ||
1763 | * the host should take TF and E_Status from the preceding PIO | ||
1764 | * Setup FIS. | ||
1765 | */ | ||
1766 | if (qc->tf.protocol == ATA_PROT_PIO && qc->dma_dir == DMA_FROM_DEVICE && | ||
1767 | !(qc->flags & ATA_QCFLAG_FAILED)) { | ||
1768 | ata_tf_from_fis(rx_fis + RX_FIS_PIO_SETUP, &qc->result_tf); | ||
1769 | qc->result_tf.command = (rx_fis + RX_FIS_PIO_SETUP)[15]; | ||
1770 | } else | ||
1771 | ata_tf_from_fis(rx_fis + RX_FIS_D2H_REG, &qc->result_tf); | ||
1837 | 1772 | ||
1838 | ata_tf_from_fis(d2h_fis, &qc->result_tf); | ||
1839 | return true; | 1773 | return true; |
1840 | } | 1774 | } |
1841 | 1775 | ||
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 932eaee50245..7f77c67d267c 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -68,7 +68,7 @@ | |||
68 | #include <linux/ratelimit.h> | 68 | #include <linux/ratelimit.h> |
69 | 69 | ||
70 | #include "libata.h" | 70 | #include "libata.h" |
71 | 71 | #include "libata-transport.h" | |
72 | 72 | ||
73 | /* debounce timing parameters in msecs { interval, duration, timeout } */ | 73 | /* debounce timing parameters in msecs { interval, duration, timeout } */ |
74 | const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; | 74 | const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; |
@@ -91,8 +91,6 @@ const struct ata_port_operations sata_port_ops = { | |||
91 | static unsigned int ata_dev_init_params(struct ata_device *dev, | 91 | static unsigned int ata_dev_init_params(struct ata_device *dev, |
92 | u16 heads, u16 sectors); | 92 | u16 heads, u16 sectors); |
93 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev); | 93 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev); |
94 | static unsigned int ata_dev_set_feature(struct ata_device *dev, | ||
95 | u8 enable, u8 feature); | ||
96 | static void ata_dev_xfermask(struct ata_device *dev); | 94 | static void ata_dev_xfermask(struct ata_device *dev); |
97 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev); | 95 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev); |
98 | 96 | ||
@@ -1017,7 +1015,7 @@ const char *ata_mode_string(unsigned long xfer_mask) | |||
1017 | return "<n/a>"; | 1015 | return "<n/a>"; |
1018 | } | 1016 | } |
1019 | 1017 | ||
1020 | static const char *sata_spd_string(unsigned int spd) | 1018 | const char *sata_spd_string(unsigned int spd) |
1021 | { | 1019 | { |
1022 | static const char * const spd_str[] = { | 1020 | static const char * const spd_str[] = { |
1023 | "1.5 Gbps", | 1021 | "1.5 Gbps", |
@@ -1030,182 +1028,6 @@ static const char *sata_spd_string(unsigned int spd) | |||
1030 | return spd_str[spd - 1]; | 1028 | return spd_str[spd - 1]; |
1031 | } | 1029 | } |
1032 | 1030 | ||
1033 | static int ata_dev_set_dipm(struct ata_device *dev, enum link_pm policy) | ||
1034 | { | ||
1035 | struct ata_link *link = dev->link; | ||
1036 | struct ata_port *ap = link->ap; | ||
1037 | u32 scontrol; | ||
1038 | unsigned int err_mask; | ||
1039 | int rc; | ||
1040 | |||
1041 | /* | ||
1042 | * disallow DIPM for drivers which haven't set | ||
1043 | * ATA_FLAG_IPM. This is because when DIPM is enabled, | ||
1044 | * phy ready will be set in the interrupt status on | ||
1045 | * state changes, which will cause some drivers to | ||
1046 | * think there are errors - additionally drivers will | ||
1047 | * need to disable hot plug. | ||
1048 | */ | ||
1049 | if (!(ap->flags & ATA_FLAG_IPM) || !ata_dev_enabled(dev)) { | ||
1050 | ap->pm_policy = NOT_AVAILABLE; | ||
1051 | return -EINVAL; | ||
1052 | } | ||
1053 | |||
1054 | /* | ||
1055 | * For DIPM, we will only enable it for the | ||
1056 | * min_power setting. | ||
1057 | * | ||
1058 | * Why? Because Disks are too stupid to know that | ||
1059 | * If the host rejects a request to go to SLUMBER | ||
1060 | * they should retry at PARTIAL, and instead it | ||
1061 | * just would give up. So, for medium_power to | ||
1062 | * work at all, we need to only allow HIPM. | ||
1063 | */ | ||
1064 | rc = sata_scr_read(link, SCR_CONTROL, &scontrol); | ||
1065 | if (rc) | ||
1066 | return rc; | ||
1067 | |||
1068 | switch (policy) { | ||
1069 | case MIN_POWER: | ||
1070 | /* no restrictions on IPM transitions */ | ||
1071 | scontrol &= ~(0x3 << 8); | ||
1072 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); | ||
1073 | if (rc) | ||
1074 | return rc; | ||
1075 | |||
1076 | /* enable DIPM */ | ||
1077 | if (dev->flags & ATA_DFLAG_DIPM) | ||
1078 | err_mask = ata_dev_set_feature(dev, | ||
1079 | SETFEATURES_SATA_ENABLE, SATA_DIPM); | ||
1080 | break; | ||
1081 | case MEDIUM_POWER: | ||
1082 | /* allow IPM to PARTIAL */ | ||
1083 | scontrol &= ~(0x1 << 8); | ||
1084 | scontrol |= (0x2 << 8); | ||
1085 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); | ||
1086 | if (rc) | ||
1087 | return rc; | ||
1088 | |||
1089 | /* | ||
1090 | * we don't have to disable DIPM since IPM flags | ||
1091 | * disallow transitions to SLUMBER, which effectively | ||
1092 | * disable DIPM if it does not support PARTIAL | ||
1093 | */ | ||
1094 | break; | ||
1095 | case NOT_AVAILABLE: | ||
1096 | case MAX_PERFORMANCE: | ||
1097 | /* disable all IPM transitions */ | ||
1098 | scontrol |= (0x3 << 8); | ||
1099 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); | ||
1100 | if (rc) | ||
1101 | return rc; | ||
1102 | |||
1103 | /* | ||
1104 | * we don't have to disable DIPM since IPM flags | ||
1105 | * disallow all transitions which effectively | ||
1106 | * disable DIPM anyway. | ||
1107 | */ | ||
1108 | break; | ||
1109 | } | ||
1110 | |||
1111 | /* FIXME: handle SET FEATURES failure */ | ||
1112 | (void) err_mask; | ||
1113 | |||
1114 | return 0; | ||
1115 | } | ||
1116 | |||
1117 | /** | ||
1118 | * ata_dev_enable_pm - enable SATA interface power management | ||
1119 | * @dev: device to enable power management | ||
1120 | * @policy: the link power management policy | ||
1121 | * | ||
1122 | * Enable SATA Interface power management. This will enable | ||
1123 | * Device Interface Power Management (DIPM) for min_power | ||
1124 | * policy, and then call driver specific callbacks for | ||
1125 | * enabling Host Initiated Power management. | ||
1126 | * | ||
1127 | * Locking: Caller. | ||
1128 | * Returns: -EINVAL if IPM is not supported, 0 otherwise. | ||
1129 | */ | ||
1130 | void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy) | ||
1131 | { | ||
1132 | int rc = 0; | ||
1133 | struct ata_port *ap = dev->link->ap; | ||
1134 | |||
1135 | /* set HIPM first, then DIPM */ | ||
1136 | if (ap->ops->enable_pm) | ||
1137 | rc = ap->ops->enable_pm(ap, policy); | ||
1138 | if (rc) | ||
1139 | goto enable_pm_out; | ||
1140 | rc = ata_dev_set_dipm(dev, policy); | ||
1141 | |||
1142 | enable_pm_out: | ||
1143 | if (rc) | ||
1144 | ap->pm_policy = MAX_PERFORMANCE; | ||
1145 | else | ||
1146 | ap->pm_policy = policy; | ||
1147 | return /* rc */; /* hopefully we can use 'rc' eventually */ | ||
1148 | } | ||
1149 | |||
1150 | #ifdef CONFIG_PM | ||
1151 | /** | ||
1152 | * ata_dev_disable_pm - disable SATA interface power management | ||
1153 | * @dev: device to disable power management | ||
1154 | * | ||
1155 | * Disable SATA Interface power management. This will disable | ||
1156 | * Device Interface Power Management (DIPM) without changing | ||
1157 | * policy, call driver specific callbacks for disabling Host | ||
1158 | * Initiated Power management. | ||
1159 | * | ||
1160 | * Locking: Caller. | ||
1161 | * Returns: void | ||
1162 | */ | ||
1163 | static void ata_dev_disable_pm(struct ata_device *dev) | ||
1164 | { | ||
1165 | struct ata_port *ap = dev->link->ap; | ||
1166 | |||
1167 | ata_dev_set_dipm(dev, MAX_PERFORMANCE); | ||
1168 | if (ap->ops->disable_pm) | ||
1169 | ap->ops->disable_pm(ap); | ||
1170 | } | ||
1171 | #endif /* CONFIG_PM */ | ||
1172 | |||
1173 | void ata_lpm_schedule(struct ata_port *ap, enum link_pm policy) | ||
1174 | { | ||
1175 | ap->pm_policy = policy; | ||
1176 | ap->link.eh_info.action |= ATA_EH_LPM; | ||
1177 | ap->link.eh_info.flags |= ATA_EHI_NO_AUTOPSY; | ||
1178 | ata_port_schedule_eh(ap); | ||
1179 | } | ||
1180 | |||
1181 | #ifdef CONFIG_PM | ||
1182 | static void ata_lpm_enable(struct ata_host *host) | ||
1183 | { | ||
1184 | struct ata_link *link; | ||
1185 | struct ata_port *ap; | ||
1186 | struct ata_device *dev; | ||
1187 | int i; | ||
1188 | |||
1189 | for (i = 0; i < host->n_ports; i++) { | ||
1190 | ap = host->ports[i]; | ||
1191 | ata_for_each_link(link, ap, EDGE) { | ||
1192 | ata_for_each_dev(dev, link, ALL) | ||
1193 | ata_dev_disable_pm(dev); | ||
1194 | } | ||
1195 | } | ||
1196 | } | ||
1197 | |||
1198 | static void ata_lpm_disable(struct ata_host *host) | ||
1199 | { | ||
1200 | int i; | ||
1201 | |||
1202 | for (i = 0; i < host->n_ports; i++) { | ||
1203 | struct ata_port *ap = host->ports[i]; | ||
1204 | ata_lpm_schedule(ap, ap->pm_policy); | ||
1205 | } | ||
1206 | } | ||
1207 | #endif /* CONFIG_PM */ | ||
1208 | |||
1209 | /** | 1031 | /** |
1210 | * ata_dev_classify - determine device type based on ATA-spec signature | 1032 | * ata_dev_classify - determine device type based on ATA-spec signature |
1211 | * @tf: ATA taskfile register set for device to be identified | 1033 | * @tf: ATA taskfile register set for device to be identified |
@@ -1806,8 +1628,14 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, | |||
1806 | } | 1628 | } |
1807 | } | 1629 | } |
1808 | 1630 | ||
1631 | if (ap->ops->error_handler) | ||
1632 | ata_eh_release(ap); | ||
1633 | |||
1809 | rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout)); | 1634 | rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout)); |
1810 | 1635 | ||
1636 | if (ap->ops->error_handler) | ||
1637 | ata_eh_acquire(ap); | ||
1638 | |||
1811 | ata_sff_flush_pio_task(ap); | 1639 | ata_sff_flush_pio_task(ap); |
1812 | 1640 | ||
1813 | if (!rc) { | 1641 | if (!rc) { |
@@ -2564,13 +2392,6 @@ int ata_dev_configure(struct ata_device *dev) | |||
2564 | if (dev->flags & ATA_DFLAG_LBA48) | 2392 | if (dev->flags & ATA_DFLAG_LBA48) |
2565 | dev->max_sectors = ATA_MAX_SECTORS_LBA48; | 2393 | dev->max_sectors = ATA_MAX_SECTORS_LBA48; |
2566 | 2394 | ||
2567 | if (!(dev->horkage & ATA_HORKAGE_IPM)) { | ||
2568 | if (ata_id_has_hipm(dev->id)) | ||
2569 | dev->flags |= ATA_DFLAG_HIPM; | ||
2570 | if (ata_id_has_dipm(dev->id)) | ||
2571 | dev->flags |= ATA_DFLAG_DIPM; | ||
2572 | } | ||
2573 | |||
2574 | /* Limit PATA drive on SATA cable bridge transfers to udma5, | 2395 | /* Limit PATA drive on SATA cable bridge transfers to udma5, |
2575 | 200 sectors */ | 2396 | 200 sectors */ |
2576 | if (ata_dev_knobble(dev)) { | 2397 | if (ata_dev_knobble(dev)) { |
@@ -2591,13 +2412,6 @@ int ata_dev_configure(struct ata_device *dev) | |||
2591 | dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, | 2412 | dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, |
2592 | dev->max_sectors); | 2413 | dev->max_sectors); |
2593 | 2414 | ||
2594 | if (ata_dev_blacklisted(dev) & ATA_HORKAGE_IPM) { | ||
2595 | dev->horkage |= ATA_HORKAGE_IPM; | ||
2596 | |||
2597 | /* reset link pm_policy for this port to no pm */ | ||
2598 | ap->pm_policy = MAX_PERFORMANCE; | ||
2599 | } | ||
2600 | |||
2601 | if (ap->ops->dev_config) | 2415 | if (ap->ops->dev_config) |
2602 | ap->ops->dev_config(dev); | 2416 | ap->ops->dev_config(dev); |
2603 | 2417 | ||
@@ -3596,7 +3410,7 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline, | |||
3596 | warned = 1; | 3410 | warned = 1; |
3597 | } | 3411 | } |
3598 | 3412 | ||
3599 | msleep(50); | 3413 | ata_msleep(link->ap, 50); |
3600 | } | 3414 | } |
3601 | } | 3415 | } |
3602 | 3416 | ||
@@ -3617,7 +3431,7 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline, | |||
3617 | int ata_wait_after_reset(struct ata_link *link, unsigned long deadline, | 3431 | int ata_wait_after_reset(struct ata_link *link, unsigned long deadline, |
3618 | int (*check_ready)(struct ata_link *link)) | 3432 | int (*check_ready)(struct ata_link *link)) |
3619 | { | 3433 | { |
3620 | msleep(ATA_WAIT_AFTER_RESET); | 3434 | ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); |
3621 | 3435 | ||
3622 | return ata_wait_ready(link, deadline, check_ready); | 3436 | return ata_wait_ready(link, deadline, check_ready); |
3623 | } | 3437 | } |
@@ -3628,7 +3442,7 @@ int ata_wait_after_reset(struct ata_link *link, unsigned long deadline, | |||
3628 | * @params: timing parameters { interval, duratinon, timeout } in msec | 3442 | * @params: timing parameters { interval, duratinon, timeout } in msec |
3629 | * @deadline: deadline jiffies for the operation | 3443 | * @deadline: deadline jiffies for the operation |
3630 | * | 3444 | * |
3631 | * Make sure SStatus of @link reaches stable state, determined by | 3445 | * Make sure SStatus of @link reaches stable state, determined by |
3632 | * holding the same value where DET is not 1 for @duration polled | 3446 | * holding the same value where DET is not 1 for @duration polled |
3633 | * every @interval, before @timeout. Timeout constraints the | 3447 | * every @interval, before @timeout. Timeout constraints the |
3634 | * beginning of the stable state. Because DET gets stuck at 1 on | 3448 | * beginning of the stable state. Because DET gets stuck at 1 on |
@@ -3665,7 +3479,7 @@ int sata_link_debounce(struct ata_link *link, const unsigned long *params, | |||
3665 | last_jiffies = jiffies; | 3479 | last_jiffies = jiffies; |
3666 | 3480 | ||
3667 | while (1) { | 3481 | while (1) { |
3668 | msleep(interval); | 3482 | ata_msleep(link->ap, interval); |
3669 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) | 3483 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) |
3670 | return rc; | 3484 | return rc; |
3671 | cur &= 0xf; | 3485 | cur &= 0xf; |
@@ -3730,7 +3544,7 @@ int sata_link_resume(struct ata_link *link, const unsigned long *params, | |||
3730 | * immediately after resuming. Delay 200ms before | 3544 | * immediately after resuming. Delay 200ms before |
3731 | * debouncing. | 3545 | * debouncing. |
3732 | */ | 3546 | */ |
3733 | msleep(200); | 3547 | ata_msleep(link->ap, 200); |
3734 | 3548 | ||
3735 | /* is SControl restored correctly? */ | 3549 | /* is SControl restored correctly? */ |
3736 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) | 3550 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
@@ -3760,6 +3574,72 @@ int sata_link_resume(struct ata_link *link, const unsigned long *params, | |||
3760 | } | 3574 | } |
3761 | 3575 | ||
3762 | /** | 3576 | /** |
3577 | * sata_link_scr_lpm - manipulate SControl IPM and SPM fields | ||
3578 | * @link: ATA link to manipulate SControl for | ||
3579 | * @policy: LPM policy to configure | ||
3580 | * @spm_wakeup: initiate LPM transition to active state | ||
3581 | * | ||
3582 | * Manipulate the IPM field of the SControl register of @link | ||
3583 | * according to @policy. If @policy is ATA_LPM_MAX_POWER and | ||
3584 | * @spm_wakeup is %true, the SPM field is manipulated to wake up | ||
3585 | * the link. This function also clears PHYRDY_CHG before | ||
3586 | * returning. | ||
3587 | * | ||
3588 | * LOCKING: | ||
3589 | * EH context. | ||
3590 | * | ||
3591 | * RETURNS: | ||
3592 | * 0 on succes, -errno otherwise. | ||
3593 | */ | ||
3594 | int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy, | ||
3595 | bool spm_wakeup) | ||
3596 | { | ||
3597 | struct ata_eh_context *ehc = &link->eh_context; | ||
3598 | bool woken_up = false; | ||
3599 | u32 scontrol; | ||
3600 | int rc; | ||
3601 | |||
3602 | rc = sata_scr_read(link, SCR_CONTROL, &scontrol); | ||
3603 | if (rc) | ||
3604 | return rc; | ||
3605 | |||
3606 | switch (policy) { | ||
3607 | case ATA_LPM_MAX_POWER: | ||
3608 | /* disable all LPM transitions */ | ||
3609 | scontrol |= (0x3 << 8); | ||
3610 | /* initiate transition to active state */ | ||
3611 | if (spm_wakeup) { | ||
3612 | scontrol |= (0x4 << 12); | ||
3613 | woken_up = true; | ||
3614 | } | ||
3615 | break; | ||
3616 | case ATA_LPM_MED_POWER: | ||
3617 | /* allow LPM to PARTIAL */ | ||
3618 | scontrol &= ~(0x1 << 8); | ||
3619 | scontrol |= (0x2 << 8); | ||
3620 | break; | ||
3621 | case ATA_LPM_MIN_POWER: | ||
3622 | /* no restrictions on LPM transitions */ | ||
3623 | scontrol &= ~(0x3 << 8); | ||
3624 | break; | ||
3625 | default: | ||
3626 | WARN_ON(1); | ||
3627 | } | ||
3628 | |||
3629 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); | ||
3630 | if (rc) | ||
3631 | return rc; | ||
3632 | |||
3633 | /* give the link time to transit out of LPM state */ | ||
3634 | if (woken_up) | ||
3635 | msleep(10); | ||
3636 | |||
3637 | /* clear PHYRDY_CHG from SError */ | ||
3638 | ehc->i.serror &= ~SERR_PHYRDY_CHG; | ||
3639 | return sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG); | ||
3640 | } | ||
3641 | |||
3642 | /** | ||
3763 | * ata_std_prereset - prepare for reset | 3643 | * ata_std_prereset - prepare for reset |
3764 | * @link: ATA link to be reset | 3644 | * @link: ATA link to be reset |
3765 | * @deadline: deadline jiffies for the operation | 3645 | * @deadline: deadline jiffies for the operation |
@@ -3868,7 +3748,7 @@ int sata_link_hardreset(struct ata_link *link, const unsigned long *timing, | |||
3868 | /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 | 3748 | /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 |
3869 | * 10.4.2 says at least 1 ms. | 3749 | * 10.4.2 says at least 1 ms. |
3870 | */ | 3750 | */ |
3871 | msleep(1); | 3751 | ata_msleep(link->ap, 1); |
3872 | 3752 | ||
3873 | /* bring link back */ | 3753 | /* bring link back */ |
3874 | rc = sata_link_resume(link, timing, deadline); | 3754 | rc = sata_link_resume(link, timing, deadline); |
@@ -4551,6 +4431,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev) | |||
4551 | DPRINTK("EXIT, err_mask=%x\n", err_mask); | 4431 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
4552 | return err_mask; | 4432 | return err_mask; |
4553 | } | 4433 | } |
4434 | |||
4554 | /** | 4435 | /** |
4555 | * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES | 4436 | * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES |
4556 | * @dev: Device to which command will be sent | 4437 | * @dev: Device to which command will be sent |
@@ -4566,8 +4447,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev) | |||
4566 | * RETURNS: | 4447 | * RETURNS: |
4567 | * 0 on success, AC_ERR_* mask otherwise. | 4448 | * 0 on success, AC_ERR_* mask otherwise. |
4568 | */ | 4449 | */ |
4569 | static unsigned int ata_dev_set_feature(struct ata_device *dev, u8 enable, | 4450 | unsigned int ata_dev_set_feature(struct ata_device *dev, u8 enable, u8 feature) |
4570 | u8 feature) | ||
4571 | { | 4451 | { |
4572 | struct ata_taskfile tf; | 4452 | struct ata_taskfile tf; |
4573 | unsigned int err_mask; | 4453 | unsigned int err_mask; |
@@ -4943,8 +4823,13 @@ static void ata_verify_xfer(struct ata_queued_cmd *qc) | |||
4943 | * ata_qc_complete - Complete an active ATA command | 4823 | * ata_qc_complete - Complete an active ATA command |
4944 | * @qc: Command to complete | 4824 | * @qc: Command to complete |
4945 | * | 4825 | * |
4946 | * Indicate to the mid and upper layers that an ATA | 4826 | * Indicate to the mid and upper layers that an ATA command has |
4947 | * command has completed, with either an ok or not-ok status. | 4827 | * completed, with either an ok or not-ok status. |
4828 | * | ||
4829 | * Refrain from calling this function multiple times when | ||
4830 | * successfully completing multiple NCQ commands. | ||
4831 | * ata_qc_complete_multiple() should be used instead, which will | ||
4832 | * properly update IRQ expect state. | ||
4948 | * | 4833 | * |
4949 | * LOCKING: | 4834 | * LOCKING: |
4950 | * spin_lock_irqsave(host lock) | 4835 | * spin_lock_irqsave(host lock) |
@@ -5037,6 +4922,10 @@ void ata_qc_complete(struct ata_queued_cmd *qc) | |||
5037 | * requests normally. ap->qc_active and @qc_active is compared | 4922 | * requests normally. ap->qc_active and @qc_active is compared |
5038 | * and commands are completed accordingly. | 4923 | * and commands are completed accordingly. |
5039 | * | 4924 | * |
4925 | * Always use this function when completing multiple NCQ commands | ||
4926 | * from IRQ handlers instead of calling ata_qc_complete() | ||
4927 | * multiple times to keep IRQ expect status properly in sync. | ||
4928 | * | ||
5040 | * LOCKING: | 4929 | * LOCKING: |
5041 | * spin_lock_irqsave(host lock) | 4930 | * spin_lock_irqsave(host lock) |
5042 | * | 4931 | * |
@@ -5422,12 +5311,6 @@ int ata_host_suspend(struct ata_host *host, pm_message_t mesg) | |||
5422 | int rc; | 5311 | int rc; |
5423 | 5312 | ||
5424 | /* | 5313 | /* |
5425 | * disable link pm on all ports before requesting | ||
5426 | * any pm activity | ||
5427 | */ | ||
5428 | ata_lpm_enable(host); | ||
5429 | |||
5430 | /* | ||
5431 | * On some hardware, device fails to respond after spun down | 5314 | * On some hardware, device fails to respond after spun down |
5432 | * for suspend. As the device won't be used before being | 5315 | * for suspend. As the device won't be used before being |
5433 | * resumed, we don't need to touch the device. Ask EH to skip | 5316 | * resumed, we don't need to touch the device. Ask EH to skip |
@@ -5460,9 +5343,6 @@ void ata_host_resume(struct ata_host *host) | |||
5460 | ata_host_request_pm(host, PMSG_ON, ATA_EH_RESET, | 5343 | ata_host_request_pm(host, PMSG_ON, ATA_EH_RESET, |
5461 | ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0); | 5344 | ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0); |
5462 | host->dev->power.power_state = PMSG_ON; | 5345 | host->dev->power.power_state = PMSG_ON; |
5463 | |||
5464 | /* reenable link pm */ | ||
5465 | ata_lpm_disable(host); | ||
5466 | } | 5346 | } |
5467 | #endif | 5347 | #endif |
5468 | 5348 | ||
@@ -5517,7 +5397,8 @@ void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp) | |||
5517 | int i; | 5397 | int i; |
5518 | 5398 | ||
5519 | /* clear everything except for devices */ | 5399 | /* clear everything except for devices */ |
5520 | memset(link, 0, offsetof(struct ata_link, device[0])); | 5400 | memset((void *)link + ATA_LINK_CLEAR_BEGIN, 0, |
5401 | ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN); | ||
5521 | 5402 | ||
5522 | link->ap = ap; | 5403 | link->ap = ap; |
5523 | link->pmp = pmp; | 5404 | link->pmp = pmp; |
@@ -5591,7 +5472,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host) | |||
5591 | ap = kzalloc(sizeof(*ap), GFP_KERNEL); | 5472 | ap = kzalloc(sizeof(*ap), GFP_KERNEL); |
5592 | if (!ap) | 5473 | if (!ap) |
5593 | return NULL; | 5474 | return NULL; |
5594 | 5475 | ||
5595 | ap->pflags |= ATA_PFLAG_INITIALIZING; | 5476 | ap->pflags |= ATA_PFLAG_INITIALIZING; |
5596 | ap->lock = &host->lock; | 5477 | ap->lock = &host->lock; |
5597 | ap->print_id = -1; | 5478 | ap->print_id = -1; |
@@ -5695,6 +5576,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) | |||
5695 | dev_set_drvdata(dev, host); | 5576 | dev_set_drvdata(dev, host); |
5696 | 5577 | ||
5697 | spin_lock_init(&host->lock); | 5578 | spin_lock_init(&host->lock); |
5579 | mutex_init(&host->eh_mutex); | ||
5698 | host->dev = dev; | 5580 | host->dev = dev; |
5699 | host->n_ports = max_ports; | 5581 | host->n_ports = max_ports; |
5700 | 5582 | ||
@@ -5992,6 +5874,7 @@ void ata_host_init(struct ata_host *host, struct device *dev, | |||
5992 | unsigned long flags, struct ata_port_operations *ops) | 5874 | unsigned long flags, struct ata_port_operations *ops) |
5993 | { | 5875 | { |
5994 | spin_lock_init(&host->lock); | 5876 | spin_lock_init(&host->lock); |
5877 | mutex_init(&host->eh_mutex); | ||
5995 | host->dev = dev; | 5878 | host->dev = dev; |
5996 | host->flags = flags; | 5879 | host->flags = flags; |
5997 | host->ops = ops; | 5880 | host->ops = ops; |
@@ -6022,7 +5905,7 @@ static void async_port_probe(void *data, async_cookie_t cookie) | |||
6022 | spin_lock_irqsave(ap->lock, flags); | 5905 | spin_lock_irqsave(ap->lock, flags); |
6023 | 5906 | ||
6024 | ehi->probe_mask |= ATA_ALL_DEVICES; | 5907 | ehi->probe_mask |= ATA_ALL_DEVICES; |
6025 | ehi->action |= ATA_EH_RESET | ATA_EH_LPM; | 5908 | ehi->action |= ATA_EH_RESET; |
6026 | ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; | 5909 | ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; |
6027 | 5910 | ||
6028 | ap->pflags &= ~ATA_PFLAG_INITIALIZING; | 5911 | ap->pflags &= ~ATA_PFLAG_INITIALIZING; |
@@ -6093,9 +5976,18 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht) | |||
6093 | for (i = 0; i < host->n_ports; i++) | 5976 | for (i = 0; i < host->n_ports; i++) |
6094 | host->ports[i]->print_id = ata_print_id++; | 5977 | host->ports[i]->print_id = ata_print_id++; |
6095 | 5978 | ||
5979 | |||
5980 | /* Create associated sysfs transport objects */ | ||
5981 | for (i = 0; i < host->n_ports; i++) { | ||
5982 | rc = ata_tport_add(host->dev,host->ports[i]); | ||
5983 | if (rc) { | ||
5984 | goto err_tadd; | ||
5985 | } | ||
5986 | } | ||
5987 | |||
6096 | rc = ata_scsi_add_hosts(host, sht); | 5988 | rc = ata_scsi_add_hosts(host, sht); |
6097 | if (rc) | 5989 | if (rc) |
6098 | return rc; | 5990 | goto err_tadd; |
6099 | 5991 | ||
6100 | /* associate with ACPI nodes */ | 5992 | /* associate with ACPI nodes */ |
6101 | ata_acpi_associate(host); | 5993 | ata_acpi_associate(host); |
@@ -6136,6 +6028,13 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht) | |||
6136 | } | 6028 | } |
6137 | 6029 | ||
6138 | return 0; | 6030 | return 0; |
6031 | |||
6032 | err_tadd: | ||
6033 | while (--i >= 0) { | ||
6034 | ata_tport_delete(host->ports[i]); | ||
6035 | } | ||
6036 | return rc; | ||
6037 | |||
6139 | } | 6038 | } |
6140 | 6039 | ||
6141 | /** | 6040 | /** |
@@ -6226,6 +6125,13 @@ static void ata_port_detach(struct ata_port *ap) | |||
6226 | cancel_rearming_delayed_work(&ap->hotplug_task); | 6125 | cancel_rearming_delayed_work(&ap->hotplug_task); |
6227 | 6126 | ||
6228 | skip_eh: | 6127 | skip_eh: |
6128 | if (ap->pmp_link) { | ||
6129 | int i; | ||
6130 | for (i = 0; i < SATA_PMP_MAX_PORTS; i++) | ||
6131 | ata_tlink_delete(&ap->pmp_link[i]); | ||
6132 | } | ||
6133 | ata_tport_delete(ap); | ||
6134 | |||
6229 | /* remove the associated SCSI host */ | 6135 | /* remove the associated SCSI host */ |
6230 | scsi_remove_host(ap->scsi_host); | 6136 | scsi_remove_host(ap->scsi_host); |
6231 | } | 6137 | } |
@@ -6542,7 +6448,7 @@ static void __init ata_parse_force_param(void) | |||
6542 | 6448 | ||
6543 | static int __init ata_init(void) | 6449 | static int __init ata_init(void) |
6544 | { | 6450 | { |
6545 | int rc = -ENOMEM; | 6451 | int rc; |
6546 | 6452 | ||
6547 | ata_parse_force_param(); | 6453 | ata_parse_force_param(); |
6548 | 6454 | ||
@@ -6552,12 +6458,25 @@ static int __init ata_init(void) | |||
6552 | return rc; | 6458 | return rc; |
6553 | } | 6459 | } |
6554 | 6460 | ||
6461 | libata_transport_init(); | ||
6462 | ata_scsi_transport_template = ata_attach_transport(); | ||
6463 | if (!ata_scsi_transport_template) { | ||
6464 | ata_sff_exit(); | ||
6465 | rc = -ENOMEM; | ||
6466 | goto err_out; | ||
6467 | } | ||
6468 | |||
6555 | printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); | 6469 | printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); |
6556 | return 0; | 6470 | return 0; |
6471 | |||
6472 | err_out: | ||
6473 | return rc; | ||
6557 | } | 6474 | } |
6558 | 6475 | ||
6559 | static void __exit ata_exit(void) | 6476 | static void __exit ata_exit(void) |
6560 | { | 6477 | { |
6478 | ata_release_transport(ata_scsi_transport_template); | ||
6479 | libata_transport_exit(); | ||
6561 | ata_sff_exit(); | 6480 | ata_sff_exit(); |
6562 | kfree(ata_force_tbl); | 6481 | kfree(ata_force_tbl); |
6563 | } | 6482 | } |
@@ -6573,7 +6492,35 @@ int ata_ratelimit(void) | |||
6573 | } | 6492 | } |
6574 | 6493 | ||
6575 | /** | 6494 | /** |
6495 | * ata_msleep - ATA EH owner aware msleep | ||
6496 | * @ap: ATA port to attribute the sleep to | ||
6497 | * @msecs: duration to sleep in milliseconds | ||
6498 | * | ||
6499 | * Sleeps @msecs. If the current task is owner of @ap's EH, the | ||
6500 | * ownership is released before going to sleep and reacquired | ||
6501 | * after the sleep is complete. IOW, other ports sharing the | ||
6502 | * @ap->host will be allowed to own the EH while this task is | ||
6503 | * sleeping. | ||
6504 | * | ||
6505 | * LOCKING: | ||
6506 | * Might sleep. | ||
6507 | */ | ||
6508 | void ata_msleep(struct ata_port *ap, unsigned int msecs) | ||
6509 | { | ||
6510 | bool owns_eh = ap && ap->host->eh_owner == current; | ||
6511 | |||
6512 | if (owns_eh) | ||
6513 | ata_eh_release(ap); | ||
6514 | |||
6515 | msleep(msecs); | ||
6516 | |||
6517 | if (owns_eh) | ||
6518 | ata_eh_acquire(ap); | ||
6519 | } | ||
6520 | |||
6521 | /** | ||
6576 | * ata_wait_register - wait until register value changes | 6522 | * ata_wait_register - wait until register value changes |
6523 | * @ap: ATA port to wait register for, can be NULL | ||
6577 | * @reg: IO-mapped register | 6524 | * @reg: IO-mapped register |
6578 | * @mask: Mask to apply to read register value | 6525 | * @mask: Mask to apply to read register value |
6579 | * @val: Wait condition | 6526 | * @val: Wait condition |
@@ -6595,7 +6542,7 @@ int ata_ratelimit(void) | |||
6595 | * RETURNS: | 6542 | * RETURNS: |
6596 | * The final register value. | 6543 | * The final register value. |
6597 | */ | 6544 | */ |
6598 | u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, | 6545 | u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val, |
6599 | unsigned long interval, unsigned long timeout) | 6546 | unsigned long interval, unsigned long timeout) |
6600 | { | 6547 | { |
6601 | unsigned long deadline; | 6548 | unsigned long deadline; |
@@ -6610,7 +6557,7 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, | |||
6610 | deadline = ata_deadline(jiffies, timeout); | 6557 | deadline = ata_deadline(jiffies, timeout); |
6611 | 6558 | ||
6612 | while ((tmp & mask) == val && time_before(jiffies, deadline)) { | 6559 | while ((tmp & mask) == val && time_before(jiffies, deadline)) { |
6613 | msleep(interval); | 6560 | ata_msleep(ap, interval); |
6614 | tmp = ioread32(reg); | 6561 | tmp = ioread32(reg); |
6615 | } | 6562 | } |
6616 | 6563 | ||
@@ -6686,6 +6633,7 @@ EXPORT_SYMBOL_GPL(sata_set_spd); | |||
6686 | EXPORT_SYMBOL_GPL(ata_wait_after_reset); | 6633 | EXPORT_SYMBOL_GPL(ata_wait_after_reset); |
6687 | EXPORT_SYMBOL_GPL(sata_link_debounce); | 6634 | EXPORT_SYMBOL_GPL(sata_link_debounce); |
6688 | EXPORT_SYMBOL_GPL(sata_link_resume); | 6635 | EXPORT_SYMBOL_GPL(sata_link_resume); |
6636 | EXPORT_SYMBOL_GPL(sata_link_scr_lpm); | ||
6689 | EXPORT_SYMBOL_GPL(ata_std_prereset); | 6637 | EXPORT_SYMBOL_GPL(ata_std_prereset); |
6690 | EXPORT_SYMBOL_GPL(sata_link_hardreset); | 6638 | EXPORT_SYMBOL_GPL(sata_link_hardreset); |
6691 | EXPORT_SYMBOL_GPL(sata_std_hardreset); | 6639 | EXPORT_SYMBOL_GPL(sata_std_hardreset); |
@@ -6693,6 +6641,7 @@ EXPORT_SYMBOL_GPL(ata_std_postreset); | |||
6693 | EXPORT_SYMBOL_GPL(ata_dev_classify); | 6641 | EXPORT_SYMBOL_GPL(ata_dev_classify); |
6694 | EXPORT_SYMBOL_GPL(ata_dev_pair); | 6642 | EXPORT_SYMBOL_GPL(ata_dev_pair); |
6695 | EXPORT_SYMBOL_GPL(ata_ratelimit); | 6643 | EXPORT_SYMBOL_GPL(ata_ratelimit); |
6644 | EXPORT_SYMBOL_GPL(ata_msleep); | ||
6696 | EXPORT_SYMBOL_GPL(ata_wait_register); | 6645 | EXPORT_SYMBOL_GPL(ata_wait_register); |
6697 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); | 6646 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
6698 | EXPORT_SYMBOL_GPL(ata_scsi_slave_config); | 6647 | EXPORT_SYMBOL_GPL(ata_scsi_slave_config); |
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index e48302eae55f..5e590504f3aa 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c | |||
@@ -57,6 +57,7 @@ enum { | |||
57 | /* error flags */ | 57 | /* error flags */ |
58 | ATA_EFLAG_IS_IO = (1 << 0), | 58 | ATA_EFLAG_IS_IO = (1 << 0), |
59 | ATA_EFLAG_DUBIOUS_XFER = (1 << 1), | 59 | ATA_EFLAG_DUBIOUS_XFER = (1 << 1), |
60 | ATA_EFLAG_OLD_ER = (1 << 31), | ||
60 | 61 | ||
61 | /* error categories */ | 62 | /* error categories */ |
62 | ATA_ECAT_NONE = 0, | 63 | ATA_ECAT_NONE = 0, |
@@ -396,14 +397,9 @@ static struct ata_ering_entry *ata_ering_top(struct ata_ering *ering) | |||
396 | return NULL; | 397 | return NULL; |
397 | } | 398 | } |
398 | 399 | ||
399 | static void ata_ering_clear(struct ata_ering *ering) | 400 | int ata_ering_map(struct ata_ering *ering, |
400 | { | 401 | int (*map_fn)(struct ata_ering_entry *, void *), |
401 | memset(ering, 0, sizeof(*ering)); | 402 | void *arg) |
402 | } | ||
403 | |||
404 | static int ata_ering_map(struct ata_ering *ering, | ||
405 | int (*map_fn)(struct ata_ering_entry *, void *), | ||
406 | void *arg) | ||
407 | { | 403 | { |
408 | int idx, rc = 0; | 404 | int idx, rc = 0; |
409 | struct ata_ering_entry *ent; | 405 | struct ata_ering_entry *ent; |
@@ -422,6 +418,17 @@ static int ata_ering_map(struct ata_ering *ering, | |||
422 | return rc; | 418 | return rc; |
423 | } | 419 | } |
424 | 420 | ||
421 | int ata_ering_clear_cb(struct ata_ering_entry *ent, void *void_arg) | ||
422 | { | ||
423 | ent->eflags |= ATA_EFLAG_OLD_ER; | ||
424 | return 0; | ||
425 | } | ||
426 | |||
427 | static void ata_ering_clear(struct ata_ering *ering) | ||
428 | { | ||
429 | ata_ering_map(ering, ata_ering_clear_cb, NULL); | ||
430 | } | ||
431 | |||
425 | static unsigned int ata_eh_dev_action(struct ata_device *dev) | 432 | static unsigned int ata_eh_dev_action(struct ata_device *dev) |
426 | { | 433 | { |
427 | struct ata_eh_context *ehc = &dev->link->eh_context; | 434 | struct ata_eh_context *ehc = &dev->link->eh_context; |
@@ -456,6 +463,41 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev, | |||
456 | } | 463 | } |
457 | 464 | ||
458 | /** | 465 | /** |
466 | * ata_eh_acquire - acquire EH ownership | ||
467 | * @ap: ATA port to acquire EH ownership for | ||
468 | * | ||
469 | * Acquire EH ownership for @ap. This is the basic exclusion | ||
470 | * mechanism for ports sharing a host. Only one port hanging off | ||
471 | * the same host can claim the ownership of EH. | ||
472 | * | ||
473 | * LOCKING: | ||
474 | * EH context. | ||
475 | */ | ||
476 | void ata_eh_acquire(struct ata_port *ap) | ||
477 | { | ||
478 | mutex_lock(&ap->host->eh_mutex); | ||
479 | WARN_ON_ONCE(ap->host->eh_owner); | ||
480 | ap->host->eh_owner = current; | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * ata_eh_release - release EH ownership | ||
485 | * @ap: ATA port to release EH ownership for | ||
486 | * | ||
487 | * Release EH ownership for @ap if the caller. The caller must | ||
488 | * have acquired EH ownership using ata_eh_acquire() previously. | ||
489 | * | ||
490 | * LOCKING: | ||
491 | * EH context. | ||
492 | */ | ||
493 | void ata_eh_release(struct ata_port *ap) | ||
494 | { | ||
495 | WARN_ON_ONCE(ap->host->eh_owner != current); | ||
496 | ap->host->eh_owner = NULL; | ||
497 | mutex_unlock(&ap->host->eh_mutex); | ||
498 | } | ||
499 | |||
500 | /** | ||
459 | * ata_scsi_timed_out - SCSI layer time out callback | 501 | * ata_scsi_timed_out - SCSI layer time out callback |
460 | * @cmd: timed out SCSI command | 502 | * @cmd: timed out SCSI command |
461 | * | 503 | * |
@@ -572,19 +614,19 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
572 | int nr_timedout = 0; | 614 | int nr_timedout = 0; |
573 | 615 | ||
574 | spin_lock_irqsave(ap->lock, flags); | 616 | spin_lock_irqsave(ap->lock, flags); |
575 | 617 | ||
576 | /* This must occur under the ap->lock as we don't want | 618 | /* This must occur under the ap->lock as we don't want |
577 | a polled recovery to race the real interrupt handler | 619 | a polled recovery to race the real interrupt handler |
578 | 620 | ||
579 | The lost_interrupt handler checks for any completed but | 621 | The lost_interrupt handler checks for any completed but |
580 | non-notified command and completes much like an IRQ handler. | 622 | non-notified command and completes much like an IRQ handler. |
581 | 623 | ||
582 | We then fall into the error recovery code which will treat | 624 | We then fall into the error recovery code which will treat |
583 | this as if normal completion won the race */ | 625 | this as if normal completion won the race */ |
584 | 626 | ||
585 | if (ap->ops->lost_interrupt) | 627 | if (ap->ops->lost_interrupt) |
586 | ap->ops->lost_interrupt(ap); | 628 | ap->ops->lost_interrupt(ap); |
587 | 629 | ||
588 | list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { | 630 | list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { |
589 | struct ata_queued_cmd *qc; | 631 | struct ata_queued_cmd *qc; |
590 | 632 | ||
@@ -628,15 +670,17 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
628 | ap->eh_tries = ATA_EH_MAX_TRIES; | 670 | ap->eh_tries = ATA_EH_MAX_TRIES; |
629 | } else | 671 | } else |
630 | spin_unlock_wait(ap->lock); | 672 | spin_unlock_wait(ap->lock); |
631 | 673 | ||
632 | /* If we timed raced normal completion and there is nothing to | 674 | /* If we timed raced normal completion and there is nothing to |
633 | recover nr_timedout == 0 why exactly are we doing error recovery ? */ | 675 | recover nr_timedout == 0 why exactly are we doing error recovery ? */ |
634 | 676 | ||
635 | repeat: | ||
636 | /* invoke error handler */ | 677 | /* invoke error handler */ |
637 | if (ap->ops->error_handler) { | 678 | if (ap->ops->error_handler) { |
638 | struct ata_link *link; | 679 | struct ata_link *link; |
639 | 680 | ||
681 | /* acquire EH ownership */ | ||
682 | ata_eh_acquire(ap); | ||
683 | repeat: | ||
640 | /* kill fast drain timer */ | 684 | /* kill fast drain timer */ |
641 | del_timer_sync(&ap->fastdrain_timer); | 685 | del_timer_sync(&ap->fastdrain_timer); |
642 | 686 | ||
@@ -711,6 +755,7 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
711 | host->host_eh_scheduled = 0; | 755 | host->host_eh_scheduled = 0; |
712 | 756 | ||
713 | spin_unlock_irqrestore(ap->lock, flags); | 757 | spin_unlock_irqrestore(ap->lock, flags); |
758 | ata_eh_release(ap); | ||
714 | } else { | 759 | } else { |
715 | WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); | 760 | WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); |
716 | ap->ops->eng_timeout(ap); | 761 | ap->ops->eng_timeout(ap); |
@@ -772,7 +817,7 @@ void ata_port_wait_eh(struct ata_port *ap) | |||
772 | 817 | ||
773 | /* make sure SCSI EH is complete */ | 818 | /* make sure SCSI EH is complete */ |
774 | if (scsi_host_in_recovery(ap->scsi_host)) { | 819 | if (scsi_host_in_recovery(ap->scsi_host)) { |
775 | msleep(10); | 820 | ata_msleep(ap, 10); |
776 | goto retry; | 821 | goto retry; |
777 | } | 822 | } |
778 | } | 823 | } |
@@ -1573,9 +1618,9 @@ static void ata_eh_analyze_serror(struct ata_link *link) | |||
1573 | * host links. For disabled PMP links, only N bit is | 1618 | * host links. For disabled PMP links, only N bit is |
1574 | * considered as X bit is left at 1 for link plugging. | 1619 | * considered as X bit is left at 1 for link plugging. |
1575 | */ | 1620 | */ |
1576 | hotplug_mask = 0; | 1621 | if (link->lpm_policy != ATA_LPM_MAX_POWER) |
1577 | 1622 | hotplug_mask = 0; /* hotplug doesn't work w/ LPM */ | |
1578 | if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) | 1623 | else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) |
1579 | hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG; | 1624 | hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG; |
1580 | else | 1625 | else |
1581 | hotplug_mask = SERR_PHYRDY_CHG; | 1626 | hotplug_mask = SERR_PHYRDY_CHG; |
@@ -1755,7 +1800,7 @@ static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg) | |||
1755 | struct speed_down_verdict_arg *arg = void_arg; | 1800 | struct speed_down_verdict_arg *arg = void_arg; |
1756 | int cat; | 1801 | int cat; |
1757 | 1802 | ||
1758 | if (ent->timestamp < arg->since) | 1803 | if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since)) |
1759 | return -1; | 1804 | return -1; |
1760 | 1805 | ||
1761 | cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, | 1806 | cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, |
@@ -2777,8 +2822,9 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2777 | ata_eh_done(link, NULL, ATA_EH_RESET); | 2822 | ata_eh_done(link, NULL, ATA_EH_RESET); |
2778 | if (slave) | 2823 | if (slave) |
2779 | ata_eh_done(slave, NULL, ATA_EH_RESET); | 2824 | ata_eh_done(slave, NULL, ATA_EH_RESET); |
2780 | ehc->last_reset = jiffies; /* update to completion time */ | 2825 | ehc->last_reset = jiffies; /* update to completion time */ |
2781 | ehc->i.action |= ATA_EH_REVALIDATE; | 2826 | ehc->i.action |= ATA_EH_REVALIDATE; |
2827 | link->lpm_policy = ATA_LPM_UNKNOWN; /* reset LPM state */ | ||
2782 | 2828 | ||
2783 | rc = 0; | 2829 | rc = 0; |
2784 | out: | 2830 | out: |
@@ -2810,8 +2856,10 @@ int ata_eh_reset(struct ata_link *link, int classify, | |||
2810 | "reset failed (errno=%d), retrying in %u secs\n", | 2856 | "reset failed (errno=%d), retrying in %u secs\n", |
2811 | rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); | 2857 | rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); |
2812 | 2858 | ||
2859 | ata_eh_release(ap); | ||
2813 | while (delta) | 2860 | while (delta) |
2814 | delta = schedule_timeout_uninterruptible(delta); | 2861 | delta = schedule_timeout_uninterruptible(delta); |
2862 | ata_eh_acquire(ap); | ||
2815 | } | 2863 | } |
2816 | 2864 | ||
2817 | if (try == max_tries - 1) { | 2865 | if (try == max_tries - 1) { |
@@ -3204,6 +3252,124 @@ static int ata_eh_maybe_retry_flush(struct ata_device *dev) | |||
3204 | return rc; | 3252 | return rc; |
3205 | } | 3253 | } |
3206 | 3254 | ||
3255 | /** | ||
3256 | * ata_eh_set_lpm - configure SATA interface power management | ||
3257 | * @link: link to configure power management | ||
3258 | * @policy: the link power management policy | ||
3259 | * @r_failed_dev: out parameter for failed device | ||
3260 | * | ||
3261 | * Enable SATA Interface power management. This will enable | ||
3262 | * Device Interface Power Management (DIPM) for min_power | ||
3263 | * policy, and then call driver specific callbacks for | ||
3264 | * enabling Host Initiated Power management. | ||
3265 | * | ||
3266 | * LOCKING: | ||
3267 | * EH context. | ||
3268 | * | ||
3269 | * RETURNS: | ||
3270 | * 0 on success, -errno on failure. | ||
3271 | */ | ||
3272 | static int ata_eh_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, | ||
3273 | struct ata_device **r_failed_dev) | ||
3274 | { | ||
3275 | struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL; | ||
3276 | struct ata_eh_context *ehc = &link->eh_context; | ||
3277 | struct ata_device *dev, *link_dev = NULL, *lpm_dev = NULL; | ||
3278 | unsigned int hints = ATA_LPM_EMPTY | ATA_LPM_HIPM; | ||
3279 | unsigned int err_mask; | ||
3280 | int rc; | ||
3281 | |||
3282 | /* if the link or host doesn't do LPM, noop */ | ||
3283 | if ((link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm)) | ||
3284 | return 0; | ||
3285 | |||
3286 | /* | ||
3287 | * DIPM is enabled only for MIN_POWER as some devices | ||
3288 | * misbehave when the host NACKs transition to SLUMBER. Order | ||
3289 | * device and link configurations such that the host always | ||
3290 | * allows DIPM requests. | ||
3291 | */ | ||
3292 | ata_for_each_dev(dev, link, ENABLED) { | ||
3293 | bool hipm = ata_id_has_hipm(dev->id); | ||
3294 | bool dipm = ata_id_has_dipm(dev->id); | ||
3295 | |||
3296 | /* find the first enabled and LPM enabled devices */ | ||
3297 | if (!link_dev) | ||
3298 | link_dev = dev; | ||
3299 | |||
3300 | if (!lpm_dev && (hipm || dipm)) | ||
3301 | lpm_dev = dev; | ||
3302 | |||
3303 | hints &= ~ATA_LPM_EMPTY; | ||
3304 | if (!hipm) | ||
3305 | hints &= ~ATA_LPM_HIPM; | ||
3306 | |||
3307 | /* disable DIPM before changing link config */ | ||
3308 | if (policy != ATA_LPM_MIN_POWER && dipm) { | ||
3309 | err_mask = ata_dev_set_feature(dev, | ||
3310 | SETFEATURES_SATA_DISABLE, SATA_DIPM); | ||
3311 | if (err_mask && err_mask != AC_ERR_DEV) { | ||
3312 | ata_dev_printk(dev, KERN_WARNING, | ||
3313 | "failed to disable DIPM, Emask 0x%x\n", | ||
3314 | err_mask); | ||
3315 | rc = -EIO; | ||
3316 | goto fail; | ||
3317 | } | ||
3318 | } | ||
3319 | } | ||
3320 | |||
3321 | if (ap) { | ||
3322 | rc = ap->ops->set_lpm(link, policy, hints); | ||
3323 | if (!rc && ap->slave_link) | ||
3324 | rc = ap->ops->set_lpm(ap->slave_link, policy, hints); | ||
3325 | } else | ||
3326 | rc = sata_pmp_set_lpm(link, policy, hints); | ||
3327 | |||
3328 | /* | ||
3329 | * Attribute link config failure to the first (LPM) enabled | ||
3330 | * device on the link. | ||
3331 | */ | ||
3332 | if (rc) { | ||
3333 | if (rc == -EOPNOTSUPP) { | ||
3334 | link->flags |= ATA_LFLAG_NO_LPM; | ||
3335 | return 0; | ||
3336 | } | ||
3337 | dev = lpm_dev ? lpm_dev : link_dev; | ||
3338 | goto fail; | ||
3339 | } | ||
3340 | |||
3341 | /* host config updated, enable DIPM if transitioning to MIN_POWER */ | ||
3342 | ata_for_each_dev(dev, link, ENABLED) { | ||
3343 | if (policy == ATA_LPM_MIN_POWER && ata_id_has_dipm(dev->id)) { | ||
3344 | err_mask = ata_dev_set_feature(dev, | ||
3345 | SETFEATURES_SATA_ENABLE, SATA_DIPM); | ||
3346 | if (err_mask && err_mask != AC_ERR_DEV) { | ||
3347 | ata_dev_printk(dev, KERN_WARNING, | ||
3348 | "failed to enable DIPM, Emask 0x%x\n", | ||
3349 | err_mask); | ||
3350 | rc = -EIO; | ||
3351 | goto fail; | ||
3352 | } | ||
3353 | } | ||
3354 | } | ||
3355 | |||
3356 | link->lpm_policy = policy; | ||
3357 | if (ap && ap->slave_link) | ||
3358 | ap->slave_link->lpm_policy = policy; | ||
3359 | return 0; | ||
3360 | |||
3361 | fail: | ||
3362 | /* if no device or only one more chance is left, disable LPM */ | ||
3363 | if (!dev || ehc->tries[dev->devno] <= 2) { | ||
3364 | ata_link_printk(link, KERN_WARNING, | ||
3365 | "disabling LPM on the link\n"); | ||
3366 | link->flags |= ATA_LFLAG_NO_LPM; | ||
3367 | } | ||
3368 | if (r_failed_dev) | ||
3369 | *r_failed_dev = dev; | ||
3370 | return rc; | ||
3371 | } | ||
3372 | |||
3207 | static int ata_link_nr_enabled(struct ata_link *link) | 3373 | static int ata_link_nr_enabled(struct ata_link *link) |
3208 | { | 3374 | { |
3209 | struct ata_device *dev; | 3375 | struct ata_device *dev; |
@@ -3288,6 +3454,16 @@ static int ata_eh_schedule_probe(struct ata_device *dev) | |||
3288 | ehc->saved_xfer_mode[dev->devno] = 0; | 3454 | ehc->saved_xfer_mode[dev->devno] = 0; |
3289 | ehc->saved_ncq_enabled &= ~(1 << dev->devno); | 3455 | ehc->saved_ncq_enabled &= ~(1 << dev->devno); |
3290 | 3456 | ||
3457 | /* the link maybe in a deep sleep, wake it up */ | ||
3458 | if (link->lpm_policy > ATA_LPM_MAX_POWER) { | ||
3459 | if (ata_is_host_link(link)) | ||
3460 | link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER, | ||
3461 | ATA_LPM_EMPTY); | ||
3462 | else | ||
3463 | sata_pmp_set_lpm(link, ATA_LPM_MAX_POWER, | ||
3464 | ATA_LPM_EMPTY); | ||
3465 | } | ||
3466 | |||
3291 | /* Record and count probe trials on the ering. The specific | 3467 | /* Record and count probe trials on the ering. The specific |
3292 | * error mask used is irrelevant. Because a successful device | 3468 | * error mask used is irrelevant. Because a successful device |
3293 | * detection clears the ering, this count accumulates only if | 3469 | * detection clears the ering, this count accumulates only if |
@@ -3389,8 +3565,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3389 | { | 3565 | { |
3390 | struct ata_link *link; | 3566 | struct ata_link *link; |
3391 | struct ata_device *dev; | 3567 | struct ata_device *dev; |
3392 | int nr_failed_devs; | 3568 | int rc, nr_fails; |
3393 | int rc; | ||
3394 | unsigned long flags, deadline; | 3569 | unsigned long flags, deadline; |
3395 | 3570 | ||
3396 | DPRINTK("ENTER\n"); | 3571 | DPRINTK("ENTER\n"); |
@@ -3431,7 +3606,6 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3431 | 3606 | ||
3432 | retry: | 3607 | retry: |
3433 | rc = 0; | 3608 | rc = 0; |
3434 | nr_failed_devs = 0; | ||
3435 | 3609 | ||
3436 | /* if UNLOADING, finish immediately */ | 3610 | /* if UNLOADING, finish immediately */ |
3437 | if (ap->pflags & ATA_PFLAG_UNLOADING) | 3611 | if (ap->pflags & ATA_PFLAG_UNLOADING) |
@@ -3501,8 +3675,10 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3501 | if (time_before_eq(deadline, now)) | 3675 | if (time_before_eq(deadline, now)) |
3502 | break; | 3676 | break; |
3503 | 3677 | ||
3678 | ata_eh_release(ap); | ||
3504 | deadline = wait_for_completion_timeout(&ap->park_req_pending, | 3679 | deadline = wait_for_completion_timeout(&ap->park_req_pending, |
3505 | deadline - now); | 3680 | deadline - now); |
3681 | ata_eh_acquire(ap); | ||
3506 | } while (deadline); | 3682 | } while (deadline); |
3507 | ata_for_each_link(link, ap, EDGE) { | 3683 | ata_for_each_link(link, ap, EDGE) { |
3508 | ata_for_each_dev(dev, link, ALL) { | 3684 | ata_for_each_dev(dev, link, ALL) { |
@@ -3516,13 +3692,17 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3516 | } | 3692 | } |
3517 | 3693 | ||
3518 | /* the rest */ | 3694 | /* the rest */ |
3519 | ata_for_each_link(link, ap, EDGE) { | 3695 | nr_fails = 0; |
3696 | ata_for_each_link(link, ap, PMP_FIRST) { | ||
3520 | struct ata_eh_context *ehc = &link->eh_context; | 3697 | struct ata_eh_context *ehc = &link->eh_context; |
3521 | 3698 | ||
3699 | if (sata_pmp_attached(ap) && ata_is_host_link(link)) | ||
3700 | goto config_lpm; | ||
3701 | |||
3522 | /* revalidate existing devices and attach new ones */ | 3702 | /* revalidate existing devices and attach new ones */ |
3523 | rc = ata_eh_revalidate_and_attach(link, &dev); | 3703 | rc = ata_eh_revalidate_and_attach(link, &dev); |
3524 | if (rc) | 3704 | if (rc) |
3525 | goto dev_fail; | 3705 | goto rest_fail; |
3526 | 3706 | ||
3527 | /* if PMP got attached, return, pmp EH will take care of it */ | 3707 | /* if PMP got attached, return, pmp EH will take care of it */ |
3528 | if (link->device->class == ATA_DEV_PMP) { | 3708 | if (link->device->class == ATA_DEV_PMP) { |
@@ -3534,7 +3714,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3534 | if (ehc->i.flags & ATA_EHI_SETMODE) { | 3714 | if (ehc->i.flags & ATA_EHI_SETMODE) { |
3535 | rc = ata_set_mode(link, &dev); | 3715 | rc = ata_set_mode(link, &dev); |
3536 | if (rc) | 3716 | if (rc) |
3537 | goto dev_fail; | 3717 | goto rest_fail; |
3538 | ehc->i.flags &= ~ATA_EHI_SETMODE; | 3718 | ehc->i.flags &= ~ATA_EHI_SETMODE; |
3539 | } | 3719 | } |
3540 | 3720 | ||
@@ -3547,7 +3727,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3547 | continue; | 3727 | continue; |
3548 | rc = atapi_eh_clear_ua(dev); | 3728 | rc = atapi_eh_clear_ua(dev); |
3549 | if (rc) | 3729 | if (rc) |
3550 | goto dev_fail; | 3730 | goto rest_fail; |
3551 | } | 3731 | } |
3552 | } | 3732 | } |
3553 | 3733 | ||
@@ -3557,21 +3737,25 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
3557 | continue; | 3737 | continue; |
3558 | rc = ata_eh_maybe_retry_flush(dev); | 3738 | rc = ata_eh_maybe_retry_flush(dev); |
3559 | if (rc) | 3739 | if (rc) |
3560 | goto dev_fail; | 3740 | goto rest_fail; |
3561 | } | 3741 | } |
3562 | 3742 | ||
3743 | config_lpm: | ||
3563 | /* configure link power saving */ | 3744 | /* configure link power saving */ |
3564 | if (ehc->i.action & ATA_EH_LPM) | 3745 | if (link->lpm_policy != ap->target_lpm_policy) { |
3565 | ata_for_each_dev(dev, link, ALL) | 3746 | rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev); |
3566 | ata_dev_enable_pm(dev, ap->pm_policy); | 3747 | if (rc) |
3748 | goto rest_fail; | ||
3749 | } | ||
3567 | 3750 | ||
3568 | /* this link is okay now */ | 3751 | /* this link is okay now */ |
3569 | ehc->i.flags = 0; | 3752 | ehc->i.flags = 0; |
3570 | continue; | 3753 | continue; |
3571 | 3754 | ||
3572 | dev_fail: | 3755 | rest_fail: |
3573 | nr_failed_devs++; | 3756 | nr_fails++; |
3574 | ata_eh_handle_dev_fail(dev, rc); | 3757 | if (dev) |
3758 | ata_eh_handle_dev_fail(dev, rc); | ||
3575 | 3759 | ||
3576 | if (ap->pflags & ATA_PFLAG_FROZEN) { | 3760 | if (ap->pflags & ATA_PFLAG_FROZEN) { |
3577 | /* PMP reset requires working host port. | 3761 | /* PMP reset requires working host port. |
@@ -3583,7 +3767,7 @@ dev_fail: | |||
3583 | } | 3767 | } |
3584 | } | 3768 | } |
3585 | 3769 | ||
3586 | if (nr_failed_devs) | 3770 | if (nr_fails) |
3587 | goto retry; | 3771 | goto retry; |
3588 | 3772 | ||
3589 | out: | 3773 | out: |
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c index 224faabd7b7e..3120596d4afc 100644 --- a/drivers/ata/libata-pmp.c +++ b/drivers/ata/libata-pmp.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/libata.h> | 11 | #include <linux/libata.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include "libata.h" | 13 | #include "libata.h" |
14 | #include "libata-transport.h" | ||
14 | 15 | ||
15 | const struct ata_port_operations sata_pmp_port_ops = { | 16 | const struct ata_port_operations sata_pmp_port_ops = { |
16 | .inherits = &sata_port_ops, | 17 | .inherits = &sata_port_ops, |
@@ -185,6 +186,27 @@ int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val) | |||
185 | } | 186 | } |
186 | 187 | ||
187 | /** | 188 | /** |
189 | * sata_pmp_set_lpm - configure LPM for a PMP link | ||
190 | * @link: PMP link to configure LPM for | ||
191 | * @policy: target LPM policy | ||
192 | * @hints: LPM hints | ||
193 | * | ||
194 | * Configure LPM for @link. This function will contain any PMP | ||
195 | * specific workarounds if necessary. | ||
196 | * | ||
197 | * LOCKING: | ||
198 | * EH context. | ||
199 | * | ||
200 | * RETURNS: | ||
201 | * 0 on success, -errno on failure. | ||
202 | */ | ||
203 | int sata_pmp_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, | ||
204 | unsigned hints) | ||
205 | { | ||
206 | return sata_link_scr_lpm(link, policy, true); | ||
207 | } | ||
208 | |||
209 | /** | ||
188 | * sata_pmp_read_gscr - read GSCR block of SATA PMP | 210 | * sata_pmp_read_gscr - read GSCR block of SATA PMP |
189 | * @dev: PMP device | 211 | * @dev: PMP device |
190 | * @gscr: buffer to read GSCR block into | 212 | * @gscr: buffer to read GSCR block into |
@@ -312,10 +334,10 @@ static int sata_pmp_configure(struct ata_device *dev, int print_info) | |||
312 | return rc; | 334 | return rc; |
313 | } | 335 | } |
314 | 336 | ||
315 | static int sata_pmp_init_links(struct ata_port *ap, int nr_ports) | 337 | static int sata_pmp_init_links (struct ata_port *ap, int nr_ports) |
316 | { | 338 | { |
317 | struct ata_link *pmp_link = ap->pmp_link; | 339 | struct ata_link *pmp_link = ap->pmp_link; |
318 | int i; | 340 | int i, err; |
319 | 341 | ||
320 | if (!pmp_link) { | 342 | if (!pmp_link) { |
321 | pmp_link = kzalloc(sizeof(pmp_link[0]) * SATA_PMP_MAX_PORTS, | 343 | pmp_link = kzalloc(sizeof(pmp_link[0]) * SATA_PMP_MAX_PORTS, |
@@ -327,6 +349,13 @@ static int sata_pmp_init_links(struct ata_port *ap, int nr_ports) | |||
327 | ata_link_init(ap, &pmp_link[i], i); | 349 | ata_link_init(ap, &pmp_link[i], i); |
328 | 350 | ||
329 | ap->pmp_link = pmp_link; | 351 | ap->pmp_link = pmp_link; |
352 | |||
353 | for (i = 0; i < SATA_PMP_MAX_PORTS; i++) { | ||
354 | err = ata_tlink_add(&pmp_link[i]); | ||
355 | if (err) { | ||
356 | goto err_tlink; | ||
357 | } | ||
358 | } | ||
330 | } | 359 | } |
331 | 360 | ||
332 | for (i = 0; i < nr_ports; i++) { | 361 | for (i = 0; i < nr_ports; i++) { |
@@ -339,6 +368,12 @@ static int sata_pmp_init_links(struct ata_port *ap, int nr_ports) | |||
339 | } | 368 | } |
340 | 369 | ||
341 | return 0; | 370 | return 0; |
371 | err_tlink: | ||
372 | while (--i >= 0) | ||
373 | ata_tlink_delete(&pmp_link[i]); | ||
374 | kfree(pmp_link); | ||
375 | ap->pmp_link = NULL; | ||
376 | return err; | ||
342 | } | 377 | } |
343 | 378 | ||
344 | static void sata_pmp_quirks(struct ata_port *ap) | 379 | static void sata_pmp_quirks(struct ata_port *ap) |
@@ -351,6 +386,9 @@ static void sata_pmp_quirks(struct ata_port *ap) | |||
351 | if (vendor == 0x1095 && devid == 0x3726) { | 386 | if (vendor == 0x1095 && devid == 0x3726) { |
352 | /* sil3726 quirks */ | 387 | /* sil3726 quirks */ |
353 | ata_for_each_link(link, ap, EDGE) { | 388 | ata_for_each_link(link, ap, EDGE) { |
389 | /* link reports offline after LPM */ | ||
390 | link->flags |= ATA_LFLAG_NO_LPM; | ||
391 | |||
354 | /* Class code report is unreliable and SRST | 392 | /* Class code report is unreliable and SRST |
355 | * times out under certain configurations. | 393 | * times out under certain configurations. |
356 | */ | 394 | */ |
@@ -366,6 +404,9 @@ static void sata_pmp_quirks(struct ata_port *ap) | |||
366 | } else if (vendor == 0x1095 && devid == 0x4723) { | 404 | } else if (vendor == 0x1095 && devid == 0x4723) { |
367 | /* sil4723 quirks */ | 405 | /* sil4723 quirks */ |
368 | ata_for_each_link(link, ap, EDGE) { | 406 | ata_for_each_link(link, ap, EDGE) { |
407 | /* link reports offline after LPM */ | ||
408 | link->flags |= ATA_LFLAG_NO_LPM; | ||
409 | |||
369 | /* class code report is unreliable */ | 410 | /* class code report is unreliable */ |
370 | if (link->pmp < 2) | 411 | if (link->pmp < 2) |
371 | link->flags |= ATA_LFLAG_ASSUME_ATA; | 412 | link->flags |= ATA_LFLAG_ASSUME_ATA; |
@@ -378,6 +419,9 @@ static void sata_pmp_quirks(struct ata_port *ap) | |||
378 | } else if (vendor == 0x1095 && devid == 0x4726) { | 419 | } else if (vendor == 0x1095 && devid == 0x4726) { |
379 | /* sil4726 quirks */ | 420 | /* sil4726 quirks */ |
380 | ata_for_each_link(link, ap, EDGE) { | 421 | ata_for_each_link(link, ap, EDGE) { |
422 | /* link reports offline after LPM */ | ||
423 | link->flags |= ATA_LFLAG_NO_LPM; | ||
424 | |||
381 | /* Class code report is unreliable and SRST | 425 | /* Class code report is unreliable and SRST |
382 | * times out under certain configurations. | 426 | * times out under certain configurations. |
383 | * Config device can be at port 0 or 5 and | 427 | * Config device can be at port 0 or 5 and |
@@ -938,15 +982,25 @@ static int sata_pmp_eh_recover(struct ata_port *ap) | |||
938 | if (rc) | 982 | if (rc) |
939 | goto link_fail; | 983 | goto link_fail; |
940 | 984 | ||
941 | /* Connection status might have changed while resetting other | ||
942 | * links, check SATA_PMP_GSCR_ERROR before returning. | ||
943 | */ | ||
944 | |||
945 | /* clear SNotification */ | 985 | /* clear SNotification */ |
946 | rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf); | 986 | rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf); |
947 | if (rc == 0) | 987 | if (rc == 0) |
948 | sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf); | 988 | sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf); |
949 | 989 | ||
990 | /* | ||
991 | * If LPM is active on any fan-out port, hotplug wouldn't | ||
992 | * work. Return w/ PHY event notification disabled. | ||
993 | */ | ||
994 | ata_for_each_link(link, ap, EDGE) | ||
995 | if (link->lpm_policy > ATA_LPM_MAX_POWER) | ||
996 | return 0; | ||
997 | |||
998 | /* | ||
999 | * Connection status might have changed while resetting other | ||
1000 | * links, enable notification and check SATA_PMP_GSCR_ERROR | ||
1001 | * before returning. | ||
1002 | */ | ||
1003 | |||
950 | /* enable notification */ | 1004 | /* enable notification */ |
951 | if (pmp_dev->flags & ATA_DFLAG_AN) { | 1005 | if (pmp_dev->flags & ATA_DFLAG_AN) { |
952 | gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY; | 1006 | gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY; |
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a89172c100f5..d050e073e570 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -51,8 +51,8 @@ | |||
51 | #include <asm/unaligned.h> | 51 | #include <asm/unaligned.h> |
52 | 52 | ||
53 | #include "libata.h" | 53 | #include "libata.h" |
54 | #include "libata-transport.h" | ||
54 | 55 | ||
55 | #define SECTOR_SIZE 512 | ||
56 | #define ATA_SCSI_RBUF_SIZE 4096 | 56 | #define ATA_SCSI_RBUF_SIZE 4096 |
57 | 57 | ||
58 | static DEFINE_SPINLOCK(ata_scsi_rbuf_lock); | 58 | static DEFINE_SPINLOCK(ata_scsi_rbuf_lock); |
@@ -64,9 +64,6 @@ static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap, | |||
64 | const struct scsi_device *scsidev); | 64 | const struct scsi_device *scsidev); |
65 | static struct ata_device *ata_scsi_find_dev(struct ata_port *ap, | 65 | static struct ata_device *ata_scsi_find_dev(struct ata_port *ap, |
66 | const struct scsi_device *scsidev); | 66 | const struct scsi_device *scsidev); |
67 | static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, | ||
68 | unsigned int id, unsigned int lun); | ||
69 | |||
70 | 67 | ||
71 | #define RW_RECOVERY_MPAGE 0x1 | 68 | #define RW_RECOVERY_MPAGE 0x1 |
72 | #define RW_RECOVERY_MPAGE_LEN 12 | 69 | #define RW_RECOVERY_MPAGE_LEN 12 |
@@ -106,83 +103,55 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = { | |||
106 | 0, 30 /* extended self test time, see 05-359r1 */ | 103 | 0, 30 /* extended self test time, see 05-359r1 */ |
107 | }; | 104 | }; |
108 | 105 | ||
109 | /* | 106 | static const char *ata_lpm_policy_names[] = { |
110 | * libata transport template. libata doesn't do real transport stuff. | 107 | [ATA_LPM_UNKNOWN] = "max_performance", |
111 | * It just needs the eh_timed_out hook. | 108 | [ATA_LPM_MAX_POWER] = "max_performance", |
112 | */ | 109 | [ATA_LPM_MED_POWER] = "medium_power", |
113 | static struct scsi_transport_template ata_scsi_transport_template = { | 110 | [ATA_LPM_MIN_POWER] = "min_power", |
114 | .eh_strategy_handler = ata_scsi_error, | ||
115 | .eh_timed_out = ata_scsi_timed_out, | ||
116 | .user_scan = ata_scsi_user_scan, | ||
117 | }; | ||
118 | |||
119 | |||
120 | static const struct { | ||
121 | enum link_pm value; | ||
122 | const char *name; | ||
123 | } link_pm_policy[] = { | ||
124 | { NOT_AVAILABLE, "max_performance" }, | ||
125 | { MIN_POWER, "min_power" }, | ||
126 | { MAX_PERFORMANCE, "max_performance" }, | ||
127 | { MEDIUM_POWER, "medium_power" }, | ||
128 | }; | 111 | }; |
129 | 112 | ||
130 | static const char *ata_scsi_lpm_get(enum link_pm policy) | 113 | static ssize_t ata_scsi_lpm_store(struct device *dev, |
131 | { | 114 | struct device_attribute *attr, |
132 | int i; | 115 | const char *buf, size_t count) |
133 | |||
134 | for (i = 0; i < ARRAY_SIZE(link_pm_policy); i++) | ||
135 | if (link_pm_policy[i].value == policy) | ||
136 | return link_pm_policy[i].name; | ||
137 | |||
138 | return NULL; | ||
139 | } | ||
140 | |||
141 | static ssize_t ata_scsi_lpm_put(struct device *dev, | ||
142 | struct device_attribute *attr, | ||
143 | const char *buf, size_t count) | ||
144 | { | 116 | { |
145 | struct Scsi_Host *shost = class_to_shost(dev); | 117 | struct Scsi_Host *shost = class_to_shost(dev); |
146 | struct ata_port *ap = ata_shost_to_port(shost); | 118 | struct ata_port *ap = ata_shost_to_port(shost); |
147 | enum link_pm policy = 0; | 119 | enum ata_lpm_policy policy; |
148 | int i; | 120 | unsigned long flags; |
149 | 121 | ||
150 | /* | 122 | /* UNKNOWN is internal state, iterate from MAX_POWER */ |
151 | * we are skipping array location 0 on purpose - this | 123 | for (policy = ATA_LPM_MAX_POWER; |
152 | * is because a value of NOT_AVAILABLE is displayed | 124 | policy < ARRAY_SIZE(ata_lpm_policy_names); policy++) { |
153 | * to the user as max_performance, but when the user | 125 | const char *name = ata_lpm_policy_names[policy]; |
154 | * writes "max_performance", they actually want the | 126 | |
155 | * value to match MAX_PERFORMANCE. | 127 | if (strncmp(name, buf, strlen(name)) == 0) |
156 | */ | ||
157 | for (i = 1; i < ARRAY_SIZE(link_pm_policy); i++) { | ||
158 | const int len = strlen(link_pm_policy[i].name); | ||
159 | if (strncmp(link_pm_policy[i].name, buf, len) == 0) { | ||
160 | policy = link_pm_policy[i].value; | ||
161 | break; | 128 | break; |
162 | } | ||
163 | } | 129 | } |
164 | if (!policy) | 130 | if (policy == ARRAY_SIZE(ata_lpm_policy_names)) |
165 | return -EINVAL; | 131 | return -EINVAL; |
166 | 132 | ||
167 | ata_lpm_schedule(ap, policy); | 133 | spin_lock_irqsave(ap->lock, flags); |
134 | ap->target_lpm_policy = policy; | ||
135 | ata_port_schedule_eh(ap); | ||
136 | spin_unlock_irqrestore(ap->lock, flags); | ||
137 | |||
168 | return count; | 138 | return count; |
169 | } | 139 | } |
170 | 140 | ||
171 | static ssize_t | 141 | static ssize_t ata_scsi_lpm_show(struct device *dev, |
172 | ata_scsi_lpm_show(struct device *dev, struct device_attribute *attr, char *buf) | 142 | struct device_attribute *attr, char *buf) |
173 | { | 143 | { |
174 | struct Scsi_Host *shost = class_to_shost(dev); | 144 | struct Scsi_Host *shost = class_to_shost(dev); |
175 | struct ata_port *ap = ata_shost_to_port(shost); | 145 | struct ata_port *ap = ata_shost_to_port(shost); |
176 | const char *policy = | ||
177 | ata_scsi_lpm_get(ap->pm_policy); | ||
178 | 146 | ||
179 | if (!policy) | 147 | if (ap->target_lpm_policy >= ARRAY_SIZE(ata_lpm_policy_names)) |
180 | return -EINVAL; | 148 | return -EINVAL; |
181 | 149 | ||
182 | return snprintf(buf, 23, "%s\n", policy); | 150 | return snprintf(buf, PAGE_SIZE, "%s\n", |
151 | ata_lpm_policy_names[ap->target_lpm_policy]); | ||
183 | } | 152 | } |
184 | DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, | 153 | DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, |
185 | ata_scsi_lpm_show, ata_scsi_lpm_put); | 154 | ata_scsi_lpm_show, ata_scsi_lpm_store); |
186 | EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy); | 155 | EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy); |
187 | 156 | ||
188 | static ssize_t ata_scsi_park_show(struct device *device, | 157 | static ssize_t ata_scsi_park_show(struct device *device, |
@@ -516,7 +485,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
516 | memset(scsi_cmd, 0, sizeof(scsi_cmd)); | 485 | memset(scsi_cmd, 0, sizeof(scsi_cmd)); |
517 | 486 | ||
518 | if (args[3]) { | 487 | if (args[3]) { |
519 | argsize = SECTOR_SIZE * args[3]; | 488 | argsize = ATA_SECT_SIZE * args[3]; |
520 | argbuf = kmalloc(argsize, GFP_KERNEL); | 489 | argbuf = kmalloc(argsize, GFP_KERNEL); |
521 | if (argbuf == NULL) { | 490 | if (argbuf == NULL) { |
522 | rc = -ENOMEM; | 491 | rc = -ENOMEM; |
@@ -1150,8 +1119,9 @@ static int ata_scsi_dev_config(struct scsi_device *sdev, | |||
1150 | blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN); | 1119 | blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN); |
1151 | } else { | 1120 | } else { |
1152 | /* ATA devices must be sector aligned */ | 1121 | /* ATA devices must be sector aligned */ |
1122 | sdev->sector_size = ata_id_logical_sector_size(dev->id); | ||
1153 | blk_queue_update_dma_alignment(sdev->request_queue, | 1123 | blk_queue_update_dma_alignment(sdev->request_queue, |
1154 | ATA_SECT_SIZE - 1); | 1124 | sdev->sector_size - 1); |
1155 | sdev->manage_start_stop = 1; | 1125 | sdev->manage_start_stop = 1; |
1156 | } | 1126 | } |
1157 | 1127 | ||
@@ -1166,6 +1136,7 @@ static int ata_scsi_dev_config(struct scsi_device *sdev, | |||
1166 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); | 1136 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); |
1167 | } | 1137 | } |
1168 | 1138 | ||
1139 | dev->sdev = sdev; | ||
1169 | return 0; | 1140 | return 0; |
1170 | } | 1141 | } |
1171 | 1142 | ||
@@ -1696,7 +1667,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) | |||
1696 | goto nothing_to_do; | 1667 | goto nothing_to_do; |
1697 | 1668 | ||
1698 | qc->flags |= ATA_QCFLAG_IO; | 1669 | qc->flags |= ATA_QCFLAG_IO; |
1699 | qc->nbytes = n_block * ATA_SECT_SIZE; | 1670 | qc->nbytes = n_block * scmd->device->sector_size; |
1700 | 1671 | ||
1701 | rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, | 1672 | rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, |
1702 | qc->tag); | 1673 | qc->tag); |
@@ -2001,6 +1972,7 @@ static unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf) | |||
2001 | 0x89, /* page 0x89, ata info page */ | 1972 | 0x89, /* page 0x89, ata info page */ |
2002 | 0xb0, /* page 0xb0, block limits page */ | 1973 | 0xb0, /* page 0xb0, block limits page */ |
2003 | 0xb1, /* page 0xb1, block device characteristics page */ | 1974 | 0xb1, /* page 0xb1, block device characteristics page */ |
1975 | 0xb2, /* page 0xb2, thin provisioning page */ | ||
2004 | }; | 1976 | }; |
2005 | 1977 | ||
2006 | rbuf[3] = sizeof(pages); /* number of supported VPD pages */ | 1978 | rbuf[3] = sizeof(pages); /* number of supported VPD pages */ |
@@ -2123,7 +2095,7 @@ static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf) | |||
2123 | 2095 | ||
2124 | static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) | 2096 | static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) |
2125 | { | 2097 | { |
2126 | u32 min_io_sectors; | 2098 | u16 min_io_sectors; |
2127 | 2099 | ||
2128 | rbuf[1] = 0xb0; | 2100 | rbuf[1] = 0xb0; |
2129 | rbuf[3] = 0x3c; /* required VPD size with unmap support */ | 2101 | rbuf[3] = 0x3c; /* required VPD size with unmap support */ |
@@ -2135,10 +2107,7 @@ static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) | |||
2135 | * logical than physical sector size we need to figure out what the | 2107 | * logical than physical sector size we need to figure out what the |
2136 | * latter is. | 2108 | * latter is. |
2137 | */ | 2109 | */ |
2138 | if (ata_id_has_large_logical_sectors(args->id)) | 2110 | min_io_sectors = 1 << ata_id_log2_per_physical_sector(args->id); |
2139 | min_io_sectors = ata_id_logical_per_physical_sectors(args->id); | ||
2140 | else | ||
2141 | min_io_sectors = 1; | ||
2142 | put_unaligned_be16(min_io_sectors, &rbuf[6]); | 2111 | put_unaligned_be16(min_io_sectors, &rbuf[6]); |
2143 | 2112 | ||
2144 | /* | 2113 | /* |
@@ -2172,6 +2141,16 @@ static unsigned int ata_scsiop_inq_b1(struct ata_scsi_args *args, u8 *rbuf) | |||
2172 | return 0; | 2141 | return 0; |
2173 | } | 2142 | } |
2174 | 2143 | ||
2144 | static unsigned int ata_scsiop_inq_b2(struct ata_scsi_args *args, u8 *rbuf) | ||
2145 | { | ||
2146 | /* SCSI Thin Provisioning VPD page: SBC-3 rev 22 or later */ | ||
2147 | rbuf[1] = 0xb2; | ||
2148 | rbuf[3] = 0x4; | ||
2149 | rbuf[5] = 1 << 6; /* TPWS */ | ||
2150 | |||
2151 | return 0; | ||
2152 | } | ||
2153 | |||
2175 | /** | 2154 | /** |
2176 | * ata_scsiop_noop - Command handler that simply returns success. | 2155 | * ata_scsiop_noop - Command handler that simply returns success. |
2177 | * @args: device IDENTIFY data / SCSI command of interest. | 2156 | * @args: device IDENTIFY data / SCSI command of interest. |
@@ -2397,21 +2376,13 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf) | |||
2397 | { | 2376 | { |
2398 | struct ata_device *dev = args->dev; | 2377 | struct ata_device *dev = args->dev; |
2399 | u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */ | 2378 | u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */ |
2400 | u8 log_per_phys = 0; | 2379 | u32 sector_size; /* physical sector size in bytes */ |
2401 | u16 lowest_aligned = 0; | 2380 | u8 log2_per_phys; |
2402 | u16 word_106 = dev->id[106]; | 2381 | u16 lowest_aligned; |
2403 | u16 word_209 = dev->id[209]; | 2382 | |
2404 | 2383 | sector_size = ata_id_logical_sector_size(dev->id); | |
2405 | if ((word_106 & 0xc000) == 0x4000) { | 2384 | log2_per_phys = ata_id_log2_per_physical_sector(dev->id); |
2406 | /* Number and offset of logical sectors per physical sector */ | 2385 | lowest_aligned = ata_id_logical_sector_offset(dev->id, log2_per_phys); |
2407 | if (word_106 & (1 << 13)) | ||
2408 | log_per_phys = word_106 & 0xf; | ||
2409 | if ((word_209 & 0xc000) == 0x4000) { | ||
2410 | u16 first = dev->id[209] & 0x3fff; | ||
2411 | if (first > 0) | ||
2412 | lowest_aligned = (1 << log_per_phys) - first; | ||
2413 | } | ||
2414 | } | ||
2415 | 2386 | ||
2416 | VPRINTK("ENTER\n"); | 2387 | VPRINTK("ENTER\n"); |
2417 | 2388 | ||
@@ -2426,8 +2397,10 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf) | |||
2426 | rbuf[3] = last_lba; | 2397 | rbuf[3] = last_lba; |
2427 | 2398 | ||
2428 | /* sector size */ | 2399 | /* sector size */ |
2429 | rbuf[6] = ATA_SECT_SIZE >> 8; | 2400 | rbuf[4] = sector_size >> (8 * 3); |
2430 | rbuf[7] = ATA_SECT_SIZE & 0xff; | 2401 | rbuf[5] = sector_size >> (8 * 2); |
2402 | rbuf[6] = sector_size >> (8 * 1); | ||
2403 | rbuf[7] = sector_size; | ||
2431 | } else { | 2404 | } else { |
2432 | /* sector count, 64-bit */ | 2405 | /* sector count, 64-bit */ |
2433 | rbuf[0] = last_lba >> (8 * 7); | 2406 | rbuf[0] = last_lba >> (8 * 7); |
@@ -2440,11 +2413,13 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf) | |||
2440 | rbuf[7] = last_lba; | 2413 | rbuf[7] = last_lba; |
2441 | 2414 | ||
2442 | /* sector size */ | 2415 | /* sector size */ |
2443 | rbuf[10] = ATA_SECT_SIZE >> 8; | 2416 | rbuf[ 8] = sector_size >> (8 * 3); |
2444 | rbuf[11] = ATA_SECT_SIZE & 0xff; | 2417 | rbuf[ 9] = sector_size >> (8 * 2); |
2418 | rbuf[10] = sector_size >> (8 * 1); | ||
2419 | rbuf[11] = sector_size; | ||
2445 | 2420 | ||
2446 | rbuf[12] = 0; | 2421 | rbuf[12] = 0; |
2447 | rbuf[13] = log_per_phys; | 2422 | rbuf[13] = log2_per_phys; |
2448 | rbuf[14] = (lowest_aligned >> 8) & 0x3f; | 2423 | rbuf[14] = (lowest_aligned >> 8) & 0x3f; |
2449 | rbuf[15] = lowest_aligned; | 2424 | rbuf[15] = lowest_aligned; |
2450 | 2425 | ||
@@ -2888,9 +2863,8 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) | |||
2888 | tf->device = dev->devno ? | 2863 | tf->device = dev->devno ? |
2889 | tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1; | 2864 | tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1; |
2890 | 2865 | ||
2891 | /* READ/WRITE LONG use a non-standard sect_size */ | ||
2892 | qc->sect_size = ATA_SECT_SIZE; | ||
2893 | switch (tf->command) { | 2866 | switch (tf->command) { |
2867 | /* READ/WRITE LONG use a non-standard sect_size */ | ||
2894 | case ATA_CMD_READ_LONG: | 2868 | case ATA_CMD_READ_LONG: |
2895 | case ATA_CMD_READ_LONG_ONCE: | 2869 | case ATA_CMD_READ_LONG_ONCE: |
2896 | case ATA_CMD_WRITE_LONG: | 2870 | case ATA_CMD_WRITE_LONG: |
@@ -2898,6 +2872,45 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) | |||
2898 | if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1) | 2872 | if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1) |
2899 | goto invalid_fld; | 2873 | goto invalid_fld; |
2900 | qc->sect_size = scsi_bufflen(scmd); | 2874 | qc->sect_size = scsi_bufflen(scmd); |
2875 | break; | ||
2876 | |||
2877 | /* commands using reported Logical Block size (e.g. 512 or 4K) */ | ||
2878 | case ATA_CMD_CFA_WRITE_NE: | ||
2879 | case ATA_CMD_CFA_TRANS_SECT: | ||
2880 | case ATA_CMD_CFA_WRITE_MULT_NE: | ||
2881 | /* XXX: case ATA_CMD_CFA_WRITE_SECTORS_WITHOUT_ERASE: */ | ||
2882 | case ATA_CMD_READ: | ||
2883 | case ATA_CMD_READ_EXT: | ||
2884 | case ATA_CMD_READ_QUEUED: | ||
2885 | /* XXX: case ATA_CMD_READ_QUEUED_EXT: */ | ||
2886 | case ATA_CMD_FPDMA_READ: | ||
2887 | case ATA_CMD_READ_MULTI: | ||
2888 | case ATA_CMD_READ_MULTI_EXT: | ||
2889 | case ATA_CMD_PIO_READ: | ||
2890 | case ATA_CMD_PIO_READ_EXT: | ||
2891 | case ATA_CMD_READ_STREAM_DMA_EXT: | ||
2892 | case ATA_CMD_READ_STREAM_EXT: | ||
2893 | case ATA_CMD_VERIFY: | ||
2894 | case ATA_CMD_VERIFY_EXT: | ||
2895 | case ATA_CMD_WRITE: | ||
2896 | case ATA_CMD_WRITE_EXT: | ||
2897 | case ATA_CMD_WRITE_FUA_EXT: | ||
2898 | case ATA_CMD_WRITE_QUEUED: | ||
2899 | case ATA_CMD_WRITE_QUEUED_FUA_EXT: | ||
2900 | case ATA_CMD_FPDMA_WRITE: | ||
2901 | case ATA_CMD_WRITE_MULTI: | ||
2902 | case ATA_CMD_WRITE_MULTI_EXT: | ||
2903 | case ATA_CMD_WRITE_MULTI_FUA_EXT: | ||
2904 | case ATA_CMD_PIO_WRITE: | ||
2905 | case ATA_CMD_PIO_WRITE_EXT: | ||
2906 | case ATA_CMD_WRITE_STREAM_DMA_EXT: | ||
2907 | case ATA_CMD_WRITE_STREAM_EXT: | ||
2908 | qc->sect_size = scmd->device->sector_size; | ||
2909 | break; | ||
2910 | |||
2911 | /* Everything else uses 512 byte "sectors" */ | ||
2912 | default: | ||
2913 | qc->sect_size = ATA_SECT_SIZE; | ||
2901 | } | 2914 | } |
2902 | 2915 | ||
2903 | /* | 2916 | /* |
@@ -3250,6 +3263,9 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd, | |||
3250 | case 0xb1: | 3263 | case 0xb1: |
3251 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b1); | 3264 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b1); |
3252 | break; | 3265 | break; |
3266 | case 0xb2: | ||
3267 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b2); | ||
3268 | break; | ||
3253 | default: | 3269 | default: |
3254 | ata_scsi_invalid_field(cmd, done); | 3270 | ata_scsi_invalid_field(cmd, done); |
3255 | break; | 3271 | break; |
@@ -3334,7 +3350,7 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht) | |||
3334 | *(struct ata_port **)&shost->hostdata[0] = ap; | 3350 | *(struct ata_port **)&shost->hostdata[0] = ap; |
3335 | ap->scsi_host = shost; | 3351 | ap->scsi_host = shost; |
3336 | 3352 | ||
3337 | shost->transportt = &ata_scsi_transport_template; | 3353 | shost->transportt = ata_scsi_transport_template; |
3338 | shost->unique_id = ap->print_id; | 3354 | shost->unique_id = ap->print_id; |
3339 | shost->max_id = 16; | 3355 | shost->max_id = 16; |
3340 | shost->max_lun = 1; | 3356 | shost->max_lun = 1; |
@@ -3393,6 +3409,8 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync) | |||
3393 | if (!IS_ERR(sdev)) { | 3409 | if (!IS_ERR(sdev)) { |
3394 | dev->sdev = sdev; | 3410 | dev->sdev = sdev; |
3395 | scsi_device_put(sdev); | 3411 | scsi_device_put(sdev); |
3412 | } else { | ||
3413 | dev->sdev = NULL; | ||
3396 | } | 3414 | } |
3397 | } | 3415 | } |
3398 | } | 3416 | } |
@@ -3616,8 +3634,8 @@ void ata_scsi_hotplug(struct work_struct *work) | |||
3616 | * RETURNS: | 3634 | * RETURNS: |
3617 | * Zero. | 3635 | * Zero. |
3618 | */ | 3636 | */ |
3619 | static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, | 3637 | int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, |
3620 | unsigned int id, unsigned int lun) | 3638 | unsigned int id, unsigned int lun) |
3621 | { | 3639 | { |
3622 | struct ata_port *ap = ata_shost_to_port(shost); | 3640 | struct ata_port *ap = ata_shost_to_port(shost); |
3623 | unsigned long flags; | 3641 | unsigned long flags; |
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index e30c537cce32..14d18bf81255 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c | |||
@@ -222,7 +222,7 @@ int ata_sff_busy_sleep(struct ata_port *ap, | |||
222 | timeout = ata_deadline(timer_start, tmout_pat); | 222 | timeout = ata_deadline(timer_start, tmout_pat); |
223 | while (status != 0xff && (status & ATA_BUSY) && | 223 | while (status != 0xff && (status & ATA_BUSY) && |
224 | time_before(jiffies, timeout)) { | 224 | time_before(jiffies, timeout)) { |
225 | msleep(50); | 225 | ata_msleep(ap, 50); |
226 | status = ata_sff_busy_wait(ap, ATA_BUSY, 3); | 226 | status = ata_sff_busy_wait(ap, ATA_BUSY, 3); |
227 | } | 227 | } |
228 | 228 | ||
@@ -234,7 +234,7 @@ int ata_sff_busy_sleep(struct ata_port *ap, | |||
234 | timeout = ata_deadline(timer_start, tmout); | 234 | timeout = ata_deadline(timer_start, tmout); |
235 | while (status != 0xff && (status & ATA_BUSY) && | 235 | while (status != 0xff && (status & ATA_BUSY) && |
236 | time_before(jiffies, timeout)) { | 236 | time_before(jiffies, timeout)) { |
237 | msleep(50); | 237 | ata_msleep(ap, 50); |
238 | status = ap->ops->sff_check_status(ap); | 238 | status = ap->ops->sff_check_status(ap); |
239 | } | 239 | } |
240 | 240 | ||
@@ -360,7 +360,7 @@ static void ata_dev_select(struct ata_port *ap, unsigned int device, | |||
360 | 360 | ||
361 | if (wait) { | 361 | if (wait) { |
362 | if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) | 362 | if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) |
363 | msleep(150); | 363 | ata_msleep(ap, 150); |
364 | ata_wait_idle(ap); | 364 | ata_wait_idle(ap); |
365 | } | 365 | } |
366 | } | 366 | } |
@@ -1356,7 +1356,7 @@ fsm_start: | |||
1356 | */ | 1356 | */ |
1357 | status = ata_sff_busy_wait(ap, ATA_BUSY, 5); | 1357 | status = ata_sff_busy_wait(ap, ATA_BUSY, 5); |
1358 | if (status & ATA_BUSY) { | 1358 | if (status & ATA_BUSY) { |
1359 | msleep(2); | 1359 | ata_msleep(ap, 2); |
1360 | status = ata_sff_busy_wait(ap, ATA_BUSY, 10); | 1360 | status = ata_sff_busy_wait(ap, ATA_BUSY, 10); |
1361 | if (status & ATA_BUSY) { | 1361 | if (status & ATA_BUSY) { |
1362 | ata_sff_queue_pio_task(link, ATA_SHORT_PAUSE); | 1362 | ata_sff_queue_pio_task(link, ATA_SHORT_PAUSE); |
@@ -1937,7 +1937,7 @@ int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask, | |||
1937 | unsigned int dev1 = devmask & (1 << 1); | 1937 | unsigned int dev1 = devmask & (1 << 1); |
1938 | int rc, ret = 0; | 1938 | int rc, ret = 0; |
1939 | 1939 | ||
1940 | msleep(ATA_WAIT_AFTER_RESET); | 1940 | ata_msleep(ap, ATA_WAIT_AFTER_RESET); |
1941 | 1941 | ||
1942 | /* always check readiness of the master device */ | 1942 | /* always check readiness of the master device */ |
1943 | rc = ata_sff_wait_ready(link, deadline); | 1943 | rc = ata_sff_wait_ready(link, deadline); |
@@ -1966,7 +1966,7 @@ int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask, | |||
1966 | lbal = ioread8(ioaddr->lbal_addr); | 1966 | lbal = ioread8(ioaddr->lbal_addr); |
1967 | if ((nsect == 1) && (lbal == 1)) | 1967 | if ((nsect == 1) && (lbal == 1)) |
1968 | break; | 1968 | break; |
1969 | msleep(50); /* give drive a breather */ | 1969 | ata_msleep(ap, 50); /* give drive a breather */ |
1970 | } | 1970 | } |
1971 | 1971 | ||
1972 | rc = ata_sff_wait_ready(link, deadline); | 1972 | rc = ata_sff_wait_ready(link, deadline); |
@@ -3342,7 +3342,7 @@ int __init ata_sff_init(void) | |||
3342 | return 0; | 3342 | return 0; |
3343 | } | 3343 | } |
3344 | 3344 | ||
3345 | void __exit ata_sff_exit(void) | 3345 | void ata_sff_exit(void) |
3346 | { | 3346 | { |
3347 | destroy_workqueue(ata_sff_wq); | 3347 | destroy_workqueue(ata_sff_wq); |
3348 | } | 3348 | } |
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c new file mode 100644 index 000000000000..ce9dc6207f37 --- /dev/null +++ b/drivers/ata/libata-transport.c | |||
@@ -0,0 +1,774 @@ | |||
1 | /* | ||
2 | * Copyright 2008 ioogle, Inc. All rights reserved. | ||
3 | * Released under GPL v2. | ||
4 | * | ||
5 | * Libata transport class. | ||
6 | * | ||
7 | * The ATA transport class contains common code to deal with ATA HBAs, | ||
8 | * an approximated representation of ATA topologies in the driver model, | ||
9 | * and various sysfs attributes to expose these topologies and management | ||
10 | * interfaces to user-space. | ||
11 | * | ||
12 | * There are 3 objects defined in in this class: | ||
13 | * - ata_port | ||
14 | * - ata_link | ||
15 | * - ata_device | ||
16 | * Each port has a link object. Each link can have up to two devices for PATA | ||
17 | * and generally one for SATA. | ||
18 | * If there is SATA port multiplier [PMP], 15 additional ata_link object are | ||
19 | * created. | ||
20 | * | ||
21 | * These objects are created when the ata host is initialized and when a PMP is | ||
22 | * found. They are removed only when the HBA is removed, cleaned before the | ||
23 | * error handler runs. | ||
24 | */ | ||
25 | |||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/blkdev.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <scsi/scsi_transport.h> | ||
32 | #include <linux/libata.h> | ||
33 | #include <linux/hdreg.h> | ||
34 | #include <linux/uaccess.h> | ||
35 | |||
36 | #include "libata.h" | ||
37 | #include "libata-transport.h" | ||
38 | |||
39 | #define ATA_PORT_ATTRS 2 | ||
40 | #define ATA_LINK_ATTRS 3 | ||
41 | #define ATA_DEV_ATTRS 9 | ||
42 | |||
43 | struct scsi_transport_template; | ||
44 | struct scsi_transport_template *ata_scsi_transport_template; | ||
45 | |||
46 | struct ata_internal { | ||
47 | struct scsi_transport_template t; | ||
48 | |||
49 | struct device_attribute private_port_attrs[ATA_PORT_ATTRS]; | ||
50 | struct device_attribute private_link_attrs[ATA_LINK_ATTRS]; | ||
51 | struct device_attribute private_dev_attrs[ATA_DEV_ATTRS]; | ||
52 | |||
53 | struct transport_container link_attr_cont; | ||
54 | struct transport_container dev_attr_cont; | ||
55 | |||
56 | /* | ||
57 | * The array of null terminated pointers to attributes | ||
58 | * needed by scsi_sysfs.c | ||
59 | */ | ||
60 | struct device_attribute *link_attrs[ATA_LINK_ATTRS + 1]; | ||
61 | struct device_attribute *port_attrs[ATA_PORT_ATTRS + 1]; | ||
62 | struct device_attribute *dev_attrs[ATA_DEV_ATTRS + 1]; | ||
63 | }; | ||
64 | #define to_ata_internal(tmpl) container_of(tmpl, struct ata_internal, t) | ||
65 | |||
66 | |||
67 | #define tdev_to_device(d) \ | ||
68 | container_of((d), struct ata_device, tdev) | ||
69 | #define transport_class_to_dev(dev) \ | ||
70 | tdev_to_device((dev)->parent) | ||
71 | |||
72 | #define tdev_to_link(d) \ | ||
73 | container_of((d), struct ata_link, tdev) | ||
74 | #define transport_class_to_link(dev) \ | ||
75 | tdev_to_link((dev)->parent) | ||
76 | |||
77 | #define tdev_to_port(d) \ | ||
78 | container_of((d), struct ata_port, tdev) | ||
79 | #define transport_class_to_port(dev) \ | ||
80 | tdev_to_port((dev)->parent) | ||
81 | |||
82 | |||
83 | /* Device objects are always created whit link objects */ | ||
84 | static int ata_tdev_add(struct ata_device *dev); | ||
85 | static void ata_tdev_delete(struct ata_device *dev); | ||
86 | |||
87 | |||
88 | /* | ||
89 | * Hack to allow attributes of the same name in different objects. | ||
90 | */ | ||
91 | #define ATA_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \ | ||
92 | struct device_attribute device_attr_##_prefix##_##_name = \ | ||
93 | __ATTR(_name,_mode,_show,_store) | ||
94 | |||
95 | #define ata_bitfield_name_match(title, table) \ | ||
96 | static ssize_t \ | ||
97 | get_ata_##title##_names(u32 table_key, char *buf) \ | ||
98 | { \ | ||
99 | char *prefix = ""; \ | ||
100 | ssize_t len = 0; \ | ||
101 | int i; \ | ||
102 | \ | ||
103 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ | ||
104 | if (table[i].value & table_key) { \ | ||
105 | len += sprintf(buf + len, "%s%s", \ | ||
106 | prefix, table[i].name); \ | ||
107 | prefix = ", "; \ | ||
108 | } \ | ||
109 | } \ | ||
110 | len += sprintf(buf + len, "\n"); \ | ||
111 | return len; \ | ||
112 | } | ||
113 | |||
114 | #define ata_bitfield_name_search(title, table) \ | ||
115 | static ssize_t \ | ||
116 | get_ata_##title##_names(u32 table_key, char *buf) \ | ||
117 | { \ | ||
118 | ssize_t len = 0; \ | ||
119 | int i; \ | ||
120 | \ | ||
121 | for (i = 0; i < ARRAY_SIZE(table); i++) { \ | ||
122 | if (table[i].value == table_key) { \ | ||
123 | len += sprintf(buf + len, "%s", \ | ||
124 | table[i].name); \ | ||
125 | break; \ | ||
126 | } \ | ||
127 | } \ | ||
128 | len += sprintf(buf + len, "\n"); \ | ||
129 | return len; \ | ||
130 | } | ||
131 | |||
132 | static struct { | ||
133 | u32 value; | ||
134 | char *name; | ||
135 | } ata_class_names[] = { | ||
136 | { ATA_DEV_UNKNOWN, "unknown" }, | ||
137 | { ATA_DEV_ATA, "ata" }, | ||
138 | { ATA_DEV_ATA_UNSUP, "ata" }, | ||
139 | { ATA_DEV_ATAPI, "atapi" }, | ||
140 | { ATA_DEV_ATAPI_UNSUP, "atapi" }, | ||
141 | { ATA_DEV_PMP, "pmp" }, | ||
142 | { ATA_DEV_PMP_UNSUP, "pmp" }, | ||
143 | { ATA_DEV_SEMB, "semb" }, | ||
144 | { ATA_DEV_SEMB_UNSUP, "semb" }, | ||
145 | { ATA_DEV_NONE, "none" } | ||
146 | }; | ||
147 | ata_bitfield_name_search(class, ata_class_names) | ||
148 | |||
149 | |||
150 | static struct { | ||
151 | u32 value; | ||
152 | char *name; | ||
153 | } ata_err_names[] = { | ||
154 | { AC_ERR_DEV, "DeviceError" }, | ||
155 | { AC_ERR_HSM, "HostStateMachineError" }, | ||
156 | { AC_ERR_TIMEOUT, "Timeout" }, | ||
157 | { AC_ERR_MEDIA, "MediaError" }, | ||
158 | { AC_ERR_ATA_BUS, "BusError" }, | ||
159 | { AC_ERR_HOST_BUS, "HostBusError" }, | ||
160 | { AC_ERR_SYSTEM, "SystemError" }, | ||
161 | { AC_ERR_INVALID, "InvalidArg" }, | ||
162 | { AC_ERR_OTHER, "Unknown" }, | ||
163 | { AC_ERR_NODEV_HINT, "NoDeviceHint" }, | ||
164 | { AC_ERR_NCQ, "NCQError" } | ||
165 | }; | ||
166 | ata_bitfield_name_match(err, ata_err_names) | ||
167 | |||
168 | static struct { | ||
169 | u32 value; | ||
170 | char *name; | ||
171 | } ata_xfer_names[] = { | ||
172 | { XFER_UDMA_7, "XFER_UDMA_7" }, | ||
173 | { XFER_UDMA_6, "XFER_UDMA_6" }, | ||
174 | { XFER_UDMA_5, "XFER_UDMA_5" }, | ||
175 | { XFER_UDMA_4, "XFER_UDMA_4" }, | ||
176 | { XFER_UDMA_3, "XFER_UDMA_3" }, | ||
177 | { XFER_UDMA_2, "XFER_UDMA_2" }, | ||
178 | { XFER_UDMA_1, "XFER_UDMA_1" }, | ||
179 | { XFER_UDMA_0, "XFER_UDMA_0" }, | ||
180 | { XFER_MW_DMA_4, "XFER_MW_DMA_4" }, | ||
181 | { XFER_MW_DMA_3, "XFER_MW_DMA_3" }, | ||
182 | { XFER_MW_DMA_2, "XFER_MW_DMA_2" }, | ||
183 | { XFER_MW_DMA_1, "XFER_MW_DMA_1" }, | ||
184 | { XFER_MW_DMA_0, "XFER_MW_DMA_0" }, | ||
185 | { XFER_SW_DMA_2, "XFER_SW_DMA_2" }, | ||
186 | { XFER_SW_DMA_1, "XFER_SW_DMA_1" }, | ||
187 | { XFER_SW_DMA_0, "XFER_SW_DMA_0" }, | ||
188 | { XFER_PIO_6, "XFER_PIO_6" }, | ||
189 | { XFER_PIO_5, "XFER_PIO_5" }, | ||
190 | { XFER_PIO_4, "XFER_PIO_4" }, | ||
191 | { XFER_PIO_3, "XFER_PIO_3" }, | ||
192 | { XFER_PIO_2, "XFER_PIO_2" }, | ||
193 | { XFER_PIO_1, "XFER_PIO_1" }, | ||
194 | { XFER_PIO_0, "XFER_PIO_0" }, | ||
195 | { XFER_PIO_SLOW, "XFER_PIO_SLOW" } | ||
196 | }; | ||
197 | ata_bitfield_name_match(xfer,ata_xfer_names) | ||
198 | |||
199 | /* | ||
200 | * ATA Port attributes | ||
201 | */ | ||
202 | #define ata_port_show_simple(field, name, format_string, cast) \ | ||
203 | static ssize_t \ | ||
204 | show_ata_port_##name(struct device *dev, \ | ||
205 | struct device_attribute *attr, char *buf) \ | ||
206 | { \ | ||
207 | struct ata_port *ap = transport_class_to_port(dev); \ | ||
208 | \ | ||
209 | return snprintf(buf, 20, format_string, cast ap->field); \ | ||
210 | } | ||
211 | |||
212 | #define ata_port_simple_attr(field, name, format_string, type) \ | ||
213 | ata_port_show_simple(field, name, format_string, (type)) \ | ||
214 | static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL) | ||
215 | |||
216 | ata_port_simple_attr(nr_pmp_links, nr_pmp_links, "%d\n", int); | ||
217 | ata_port_simple_attr(stats.idle_irq, idle_irq, "%ld\n", unsigned long); | ||
218 | |||
219 | static DECLARE_TRANSPORT_CLASS(ata_port_class, | ||
220 | "ata_port", NULL, NULL, NULL); | ||
221 | |||
222 | static void ata_tport_release(struct device *dev) | ||
223 | { | ||
224 | put_device(dev->parent); | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * ata_is_port -- check if a struct device represents a ATA port | ||
229 | * @dev: device to check | ||
230 | * | ||
231 | * Returns: | ||
232 | * %1 if the device represents a ATA Port, %0 else | ||
233 | */ | ||
234 | int ata_is_port(const struct device *dev) | ||
235 | { | ||
236 | return dev->release == ata_tport_release; | ||
237 | } | ||
238 | |||
239 | static int ata_tport_match(struct attribute_container *cont, | ||
240 | struct device *dev) | ||
241 | { | ||
242 | if (!ata_is_port(dev)) | ||
243 | return 0; | ||
244 | return &ata_scsi_transport_template->host_attrs.ac == cont; | ||
245 | } | ||
246 | |||
247 | /** | ||
248 | * ata_tport_delete -- remove ATA PORT | ||
249 | * @port: ATA PORT to remove | ||
250 | * | ||
251 | * Removes the specified ATA PORT. Remove the associated link as well. | ||
252 | */ | ||
253 | void ata_tport_delete(struct ata_port *ap) | ||
254 | { | ||
255 | struct device *dev = &ap->tdev; | ||
256 | |||
257 | ata_tlink_delete(&ap->link); | ||
258 | |||
259 | transport_remove_device(dev); | ||
260 | device_del(dev); | ||
261 | transport_destroy_device(dev); | ||
262 | put_device(dev); | ||
263 | } | ||
264 | |||
265 | /** ata_tport_add - initialize a transport ATA port structure | ||
266 | * | ||
267 | * @parent: parent device | ||
268 | * @ap: existing ata_port structure | ||
269 | * | ||
270 | * Initialize a ATA port structure for sysfs. It will be added to the device | ||
271 | * tree below the device specified by @parent which could be a PCI device. | ||
272 | * | ||
273 | * Returns %0 on success | ||
274 | */ | ||
275 | int ata_tport_add(struct device *parent, | ||
276 | struct ata_port *ap) | ||
277 | { | ||
278 | int error; | ||
279 | struct device *dev = &ap->tdev; | ||
280 | |||
281 | device_initialize(dev); | ||
282 | |||
283 | dev->parent = get_device(parent); | ||
284 | dev->release = ata_tport_release; | ||
285 | dev_set_name(dev, "ata%d", ap->print_id); | ||
286 | transport_setup_device(dev); | ||
287 | error = device_add(dev); | ||
288 | if (error) { | ||
289 | goto tport_err; | ||
290 | } | ||
291 | |||
292 | transport_add_device(dev); | ||
293 | transport_configure_device(dev); | ||
294 | |||
295 | error = ata_tlink_add(&ap->link); | ||
296 | if (error) { | ||
297 | goto tport_link_err; | ||
298 | } | ||
299 | return 0; | ||
300 | |||
301 | tport_link_err: | ||
302 | transport_remove_device(dev); | ||
303 | device_del(dev); | ||
304 | |||
305 | tport_err: | ||
306 | transport_destroy_device(dev); | ||
307 | put_device(dev); | ||
308 | return error; | ||
309 | } | ||
310 | |||
311 | |||
312 | /* | ||
313 | * ATA link attributes | ||
314 | */ | ||
315 | |||
316 | |||
317 | #define ata_link_show_linkspeed(field) \ | ||
318 | static ssize_t \ | ||
319 | show_ata_link_##field(struct device *dev, \ | ||
320 | struct device_attribute *attr, char *buf) \ | ||
321 | { \ | ||
322 | struct ata_link *link = transport_class_to_link(dev); \ | ||
323 | \ | ||
324 | return sprintf(buf,"%s\n", sata_spd_string(fls(link->field))); \ | ||
325 | } | ||
326 | |||
327 | #define ata_link_linkspeed_attr(field) \ | ||
328 | ata_link_show_linkspeed(field) \ | ||
329 | static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL) | ||
330 | |||
331 | ata_link_linkspeed_attr(hw_sata_spd_limit); | ||
332 | ata_link_linkspeed_attr(sata_spd_limit); | ||
333 | ata_link_linkspeed_attr(sata_spd); | ||
334 | |||
335 | |||
336 | static DECLARE_TRANSPORT_CLASS(ata_link_class, | ||
337 | "ata_link", NULL, NULL, NULL); | ||
338 | |||
339 | static void ata_tlink_release(struct device *dev) | ||
340 | { | ||
341 | put_device(dev->parent); | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * ata_is_link -- check if a struct device represents a ATA link | ||
346 | * @dev: device to check | ||
347 | * | ||
348 | * Returns: | ||
349 | * %1 if the device represents a ATA link, %0 else | ||
350 | */ | ||
351 | int ata_is_link(const struct device *dev) | ||
352 | { | ||
353 | return dev->release == ata_tlink_release; | ||
354 | } | ||
355 | |||
356 | static int ata_tlink_match(struct attribute_container *cont, | ||
357 | struct device *dev) | ||
358 | { | ||
359 | struct ata_internal* i = to_ata_internal(ata_scsi_transport_template); | ||
360 | if (!ata_is_link(dev)) | ||
361 | return 0; | ||
362 | return &i->link_attr_cont.ac == cont; | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * ata_tlink_delete -- remove ATA LINK | ||
367 | * @port: ATA LINK to remove | ||
368 | * | ||
369 | * Removes the specified ATA LINK. remove associated ATA device(s) as well. | ||
370 | */ | ||
371 | void ata_tlink_delete(struct ata_link *link) | ||
372 | { | ||
373 | struct device *dev = &link->tdev; | ||
374 | struct ata_device *ata_dev; | ||
375 | |||
376 | ata_for_each_dev(ata_dev, link, ALL) { | ||
377 | ata_tdev_delete(ata_dev); | ||
378 | } | ||
379 | |||
380 | transport_remove_device(dev); | ||
381 | device_del(dev); | ||
382 | transport_destroy_device(dev); | ||
383 | put_device(dev); | ||
384 | } | ||
385 | |||
386 | /** | ||
387 | * ata_tlink_add -- initialize a transport ATA link structure | ||
388 | * @link: allocated ata_link structure. | ||
389 | * | ||
390 | * Initialize an ATA LINK structure for sysfs. It will be added in the | ||
391 | * device tree below the ATA PORT it belongs to. | ||
392 | * | ||
393 | * Returns %0 on success | ||
394 | */ | ||
395 | int ata_tlink_add(struct ata_link *link) | ||
396 | { | ||
397 | struct device *dev = &link->tdev; | ||
398 | struct ata_port *ap = link->ap; | ||
399 | struct ata_device *ata_dev; | ||
400 | int error; | ||
401 | |||
402 | device_initialize(dev); | ||
403 | dev->parent = get_device(&ap->tdev); | ||
404 | dev->release = ata_tlink_release; | ||
405 | if (ata_is_host_link(link)) | ||
406 | dev_set_name(dev, "link%d", ap->print_id); | ||
407 | else | ||
408 | dev_set_name(dev, "link%d.%d", ap->print_id, link->pmp); | ||
409 | |||
410 | transport_setup_device(dev); | ||
411 | |||
412 | error = device_add(dev); | ||
413 | if (error) { | ||
414 | goto tlink_err; | ||
415 | } | ||
416 | |||
417 | transport_add_device(dev); | ||
418 | transport_configure_device(dev); | ||
419 | |||
420 | ata_for_each_dev(ata_dev, link, ALL) { | ||
421 | error = ata_tdev_add(ata_dev); | ||
422 | if (error) { | ||
423 | goto tlink_dev_err; | ||
424 | } | ||
425 | } | ||
426 | return 0; | ||
427 | tlink_dev_err: | ||
428 | while (--ata_dev >= link->device) { | ||
429 | ata_tdev_delete(ata_dev); | ||
430 | } | ||
431 | transport_remove_device(dev); | ||
432 | device_del(dev); | ||
433 | tlink_err: | ||
434 | transport_destroy_device(dev); | ||
435 | put_device(dev); | ||
436 | return error; | ||
437 | } | ||
438 | |||
439 | /* | ||
440 | * ATA device attributes | ||
441 | */ | ||
442 | |||
443 | #define ata_dev_show_class(title, field) \ | ||
444 | static ssize_t \ | ||
445 | show_ata_dev_##field(struct device *dev, \ | ||
446 | struct device_attribute *attr, char *buf) \ | ||
447 | { \ | ||
448 | struct ata_device *ata_dev = transport_class_to_dev(dev); \ | ||
449 | \ | ||
450 | return get_ata_##title##_names(ata_dev->field, buf); \ | ||
451 | } | ||
452 | |||
453 | #define ata_dev_attr(title, field) \ | ||
454 | ata_dev_show_class(title, field) \ | ||
455 | static DEVICE_ATTR(field, S_IRUGO, show_ata_dev_##field, NULL) | ||
456 | |||
457 | ata_dev_attr(class, class); | ||
458 | ata_dev_attr(xfer, pio_mode); | ||
459 | ata_dev_attr(xfer, dma_mode); | ||
460 | ata_dev_attr(xfer, xfer_mode); | ||
461 | |||
462 | |||
463 | #define ata_dev_show_simple(field, format_string, cast) \ | ||
464 | static ssize_t \ | ||
465 | show_ata_dev_##field(struct device *dev, \ | ||
466 | struct device_attribute *attr, char *buf) \ | ||
467 | { \ | ||
468 | struct ata_device *ata_dev = transport_class_to_dev(dev); \ | ||
469 | \ | ||
470 | return snprintf(buf, 20, format_string, cast ata_dev->field); \ | ||
471 | } | ||
472 | |||
473 | #define ata_dev_simple_attr(field, format_string, type) \ | ||
474 | ata_dev_show_simple(field, format_string, (type)) \ | ||
475 | static DEVICE_ATTR(field, S_IRUGO, \ | ||
476 | show_ata_dev_##field, NULL) | ||
477 | |||
478 | ata_dev_simple_attr(spdn_cnt, "%d\n", int); | ||
479 | |||
480 | struct ata_show_ering_arg { | ||
481 | char* buf; | ||
482 | int written; | ||
483 | }; | ||
484 | |||
485 | static int ata_show_ering(struct ata_ering_entry *ent, void *void_arg) | ||
486 | { | ||
487 | struct ata_show_ering_arg* arg = void_arg; | ||
488 | struct timespec time; | ||
489 | |||
490 | jiffies_to_timespec(ent->timestamp,&time); | ||
491 | arg->written += sprintf(arg->buf + arg->written, | ||
492 | "[%5lu.%06lu]", | ||
493 | time.tv_sec, time.tv_nsec); | ||
494 | arg->written += get_ata_err_names(ent->err_mask, | ||
495 | arg->buf + arg->written); | ||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | static ssize_t | ||
500 | show_ata_dev_ering(struct device *dev, | ||
501 | struct device_attribute *attr, char *buf) | ||
502 | { | ||
503 | struct ata_device *ata_dev = transport_class_to_dev(dev); | ||
504 | struct ata_show_ering_arg arg = { buf, 0 }; | ||
505 | |||
506 | ata_ering_map(&ata_dev->ering, ata_show_ering, &arg); | ||
507 | return arg.written; | ||
508 | } | ||
509 | |||
510 | |||
511 | static DEVICE_ATTR(ering, S_IRUGO, show_ata_dev_ering, NULL); | ||
512 | |||
513 | static ssize_t | ||
514 | show_ata_dev_id(struct device *dev, | ||
515 | struct device_attribute *attr, char *buf) | ||
516 | { | ||
517 | struct ata_device *ata_dev = transport_class_to_dev(dev); | ||
518 | int written = 0, i = 0; | ||
519 | |||
520 | if (ata_dev->class == ATA_DEV_PMP) | ||
521 | return 0; | ||
522 | for(i=0;i<ATA_ID_WORDS;i++) { | ||
523 | written += snprintf(buf+written, 20, "%04x%c", | ||
524 | ata_dev->id[i], | ||
525 | ((i+1) & 7) ? ' ' : '\n'); | ||
526 | } | ||
527 | return written; | ||
528 | } | ||
529 | |||
530 | static DEVICE_ATTR(id, S_IRUGO, show_ata_dev_id, NULL); | ||
531 | |||
532 | static ssize_t | ||
533 | show_ata_dev_gscr(struct device *dev, | ||
534 | struct device_attribute *attr, char *buf) | ||
535 | { | ||
536 | struct ata_device *ata_dev = transport_class_to_dev(dev); | ||
537 | int written = 0, i = 0; | ||
538 | |||
539 | if (ata_dev->class != ATA_DEV_PMP) | ||
540 | return 0; | ||
541 | for(i=0;i<SATA_PMP_GSCR_DWORDS;i++) { | ||
542 | written += snprintf(buf+written, 20, "%08x%c", | ||
543 | ata_dev->gscr[i], | ||
544 | ((i+1) & 3) ? ' ' : '\n'); | ||
545 | } | ||
546 | if (SATA_PMP_GSCR_DWORDS & 3) | ||
547 | buf[written-1] = '\n'; | ||
548 | return written; | ||
549 | } | ||
550 | |||
551 | static DEVICE_ATTR(gscr, S_IRUGO, show_ata_dev_gscr, NULL); | ||
552 | |||
553 | static DECLARE_TRANSPORT_CLASS(ata_dev_class, | ||
554 | "ata_device", NULL, NULL, NULL); | ||
555 | |||
556 | static void ata_tdev_release(struct device *dev) | ||
557 | { | ||
558 | put_device(dev->parent); | ||
559 | } | ||
560 | |||
561 | /** | ||
562 | * ata_is_ata_dev -- check if a struct device represents a ATA device | ||
563 | * @dev: device to check | ||
564 | * | ||
565 | * Returns: | ||
566 | * %1 if the device represents a ATA device, %0 else | ||
567 | */ | ||
568 | int ata_is_ata_dev(const struct device *dev) | ||
569 | { | ||
570 | return dev->release == ata_tdev_release; | ||
571 | } | ||
572 | |||
573 | static int ata_tdev_match(struct attribute_container *cont, | ||
574 | struct device *dev) | ||
575 | { | ||
576 | struct ata_internal* i = to_ata_internal(ata_scsi_transport_template); | ||
577 | if (!ata_is_ata_dev(dev)) | ||
578 | return 0; | ||
579 | return &i->dev_attr_cont.ac == cont; | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * ata_tdev_free -- free a ATA LINK | ||
584 | * @dev: ATA PHY to free | ||
585 | * | ||
586 | * Frees the specified ATA PHY. | ||
587 | * | ||
588 | * Note: | ||
589 | * This function must only be called on a PHY that has not | ||
590 | * successfully been added using ata_tdev_add(). | ||
591 | */ | ||
592 | static void ata_tdev_free(struct ata_device *dev) | ||
593 | { | ||
594 | transport_destroy_device(&dev->tdev); | ||
595 | put_device(&dev->tdev); | ||
596 | } | ||
597 | |||
598 | /** | ||
599 | * ata_tdev_delete -- remove ATA device | ||
600 | * @port: ATA PORT to remove | ||
601 | * | ||
602 | * Removes the specified ATA device. | ||
603 | */ | ||
604 | static void ata_tdev_delete(struct ata_device *ata_dev) | ||
605 | { | ||
606 | struct device *dev = &ata_dev->tdev; | ||
607 | |||
608 | transport_remove_device(dev); | ||
609 | device_del(dev); | ||
610 | ata_tdev_free(ata_dev); | ||
611 | } | ||
612 | |||
613 | |||
614 | /** | ||
615 | * ata_tdev_add -- initialize a transport ATA device structure. | ||
616 | * @ata_dev: ata_dev structure. | ||
617 | * | ||
618 | * Initialize an ATA device structure for sysfs. It will be added in the | ||
619 | * device tree below the ATA LINK device it belongs to. | ||
620 | * | ||
621 | * Returns %0 on success | ||
622 | */ | ||
623 | static int ata_tdev_add(struct ata_device *ata_dev) | ||
624 | { | ||
625 | struct device *dev = &ata_dev->tdev; | ||
626 | struct ata_link *link = ata_dev->link; | ||
627 | struct ata_port *ap = link->ap; | ||
628 | int error; | ||
629 | |||
630 | device_initialize(dev); | ||
631 | dev->parent = get_device(&link->tdev); | ||
632 | dev->release = ata_tdev_release; | ||
633 | if (ata_is_host_link(link)) | ||
634 | dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno); | ||
635 | else | ||
636 | dev_set_name(dev, "dev%d.%d.0", ap->print_id, link->pmp); | ||
637 | |||
638 | transport_setup_device(dev); | ||
639 | error = device_add(dev); | ||
640 | if (error) { | ||
641 | ata_tdev_free(ata_dev); | ||
642 | return error; | ||
643 | } | ||
644 | |||
645 | transport_add_device(dev); | ||
646 | transport_configure_device(dev); | ||
647 | return 0; | ||
648 | } | ||
649 | |||
650 | |||
651 | /* | ||
652 | * Setup / Teardown code | ||
653 | */ | ||
654 | |||
655 | #define SETUP_TEMPLATE(attrb, field, perm, test) \ | ||
656 | i->private_##attrb[count] = dev_attr_##field; \ | ||
657 | i->private_##attrb[count].attr.mode = perm; \ | ||
658 | i->attrb[count] = &i->private_##attrb[count]; \ | ||
659 | if (test) \ | ||
660 | count++ | ||
661 | |||
662 | #define SETUP_LINK_ATTRIBUTE(field) \ | ||
663 | SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1) | ||
664 | |||
665 | #define SETUP_PORT_ATTRIBUTE(field) \ | ||
666 | SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1) | ||
667 | |||
668 | #define SETUP_DEV_ATTRIBUTE(field) \ | ||
669 | SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1) | ||
670 | |||
671 | /** | ||
672 | * ata_attach_transport -- instantiate ATA transport template | ||
673 | */ | ||
674 | struct scsi_transport_template *ata_attach_transport(void) | ||
675 | { | ||
676 | struct ata_internal *i; | ||
677 | int count; | ||
678 | |||
679 | i = kzalloc(sizeof(struct ata_internal), GFP_KERNEL); | ||
680 | if (!i) | ||
681 | return NULL; | ||
682 | |||
683 | i->t.eh_strategy_handler = ata_scsi_error; | ||
684 | i->t.eh_timed_out = ata_scsi_timed_out; | ||
685 | i->t.user_scan = ata_scsi_user_scan; | ||
686 | |||
687 | i->t.host_attrs.ac.attrs = &i->port_attrs[0]; | ||
688 | i->t.host_attrs.ac.class = &ata_port_class.class; | ||
689 | i->t.host_attrs.ac.match = ata_tport_match; | ||
690 | transport_container_register(&i->t.host_attrs); | ||
691 | |||
692 | i->link_attr_cont.ac.class = &ata_link_class.class; | ||
693 | i->link_attr_cont.ac.attrs = &i->link_attrs[0]; | ||
694 | i->link_attr_cont.ac.match = ata_tlink_match; | ||
695 | transport_container_register(&i->link_attr_cont); | ||
696 | |||
697 | i->dev_attr_cont.ac.class = &ata_dev_class.class; | ||
698 | i->dev_attr_cont.ac.attrs = &i->dev_attrs[0]; | ||
699 | i->dev_attr_cont.ac.match = ata_tdev_match; | ||
700 | transport_container_register(&i->dev_attr_cont); | ||
701 | |||
702 | count = 0; | ||
703 | SETUP_PORT_ATTRIBUTE(nr_pmp_links); | ||
704 | SETUP_PORT_ATTRIBUTE(idle_irq); | ||
705 | BUG_ON(count > ATA_PORT_ATTRS); | ||
706 | i->port_attrs[count] = NULL; | ||
707 | |||
708 | count = 0; | ||
709 | SETUP_LINK_ATTRIBUTE(hw_sata_spd_limit); | ||
710 | SETUP_LINK_ATTRIBUTE(sata_spd_limit); | ||
711 | SETUP_LINK_ATTRIBUTE(sata_spd); | ||
712 | BUG_ON(count > ATA_LINK_ATTRS); | ||
713 | i->link_attrs[count] = NULL; | ||
714 | |||
715 | count = 0; | ||
716 | SETUP_DEV_ATTRIBUTE(class); | ||
717 | SETUP_DEV_ATTRIBUTE(pio_mode); | ||
718 | SETUP_DEV_ATTRIBUTE(dma_mode); | ||
719 | SETUP_DEV_ATTRIBUTE(xfer_mode); | ||
720 | SETUP_DEV_ATTRIBUTE(spdn_cnt); | ||
721 | SETUP_DEV_ATTRIBUTE(ering); | ||
722 | SETUP_DEV_ATTRIBUTE(id); | ||
723 | SETUP_DEV_ATTRIBUTE(gscr); | ||
724 | BUG_ON(count > ATA_DEV_ATTRS); | ||
725 | i->dev_attrs[count] = NULL; | ||
726 | |||
727 | return &i->t; | ||
728 | } | ||
729 | |||
730 | /** | ||
731 | * ata_release_transport -- release ATA transport template instance | ||
732 | * @t: transport template instance | ||
733 | */ | ||
734 | void ata_release_transport(struct scsi_transport_template *t) | ||
735 | { | ||
736 | struct ata_internal *i = to_ata_internal(t); | ||
737 | |||
738 | transport_container_unregister(&i->t.host_attrs); | ||
739 | transport_container_unregister(&i->link_attr_cont); | ||
740 | transport_container_unregister(&i->dev_attr_cont); | ||
741 | |||
742 | kfree(i); | ||
743 | } | ||
744 | |||
745 | __init int libata_transport_init(void) | ||
746 | { | ||
747 | int error; | ||
748 | |||
749 | error = transport_class_register(&ata_link_class); | ||
750 | if (error) | ||
751 | goto out_unregister_transport; | ||
752 | error = transport_class_register(&ata_port_class); | ||
753 | if (error) | ||
754 | goto out_unregister_link; | ||
755 | error = transport_class_register(&ata_dev_class); | ||
756 | if (error) | ||
757 | goto out_unregister_port; | ||
758 | return 0; | ||
759 | |||
760 | out_unregister_port: | ||
761 | transport_class_unregister(&ata_port_class); | ||
762 | out_unregister_link: | ||
763 | transport_class_unregister(&ata_link_class); | ||
764 | out_unregister_transport: | ||
765 | return error; | ||
766 | |||
767 | } | ||
768 | |||
769 | void __exit libata_transport_exit(void) | ||
770 | { | ||
771 | transport_class_unregister(&ata_link_class); | ||
772 | transport_class_unregister(&ata_port_class); | ||
773 | transport_class_unregister(&ata_dev_class); | ||
774 | } | ||
diff --git a/drivers/ata/libata-transport.h b/drivers/ata/libata-transport.h new file mode 100644 index 000000000000..2820cf864f11 --- /dev/null +++ b/drivers/ata/libata-transport.h | |||
@@ -0,0 +1,18 @@ | |||
1 | #ifndef _LIBATA_TRANSPORT_H | ||
2 | #define _LIBATA_TRANSPORT_H | ||
3 | |||
4 | |||
5 | extern struct scsi_transport_template *ata_scsi_transport_template; | ||
6 | |||
7 | int ata_tlink_add(struct ata_link *link); | ||
8 | void ata_tlink_delete(struct ata_link *link); | ||
9 | |||
10 | int ata_tport_add(struct device *parent, struct ata_port *ap); | ||
11 | void ata_tport_delete(struct ata_port *ap); | ||
12 | |||
13 | struct scsi_transport_template *ata_attach_transport(void); | ||
14 | void ata_release_transport(struct scsi_transport_template *t); | ||
15 | |||
16 | __init int libata_transport_init(void); | ||
17 | void __exit libata_transport_exit(void); | ||
18 | #endif | ||
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 9ce1ecc63e39..a9be110dbf51 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h | |||
@@ -86,6 +86,8 @@ extern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class, | |||
86 | extern int ata_dev_configure(struct ata_device *dev); | 86 | extern int ata_dev_configure(struct ata_device *dev); |
87 | extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); | 87 | extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); |
88 | extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); | 88 | extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); |
89 | extern unsigned int ata_dev_set_feature(struct ata_device *dev, | ||
90 | u8 enable, u8 feature); | ||
89 | extern void ata_sg_clean(struct ata_queued_cmd *qc); | 91 | extern void ata_sg_clean(struct ata_queued_cmd *qc); |
90 | extern void ata_qc_free(struct ata_queued_cmd *qc); | 92 | extern void ata_qc_free(struct ata_queued_cmd *qc); |
91 | extern void ata_qc_issue(struct ata_queued_cmd *qc); | 93 | extern void ata_qc_issue(struct ata_queued_cmd *qc); |
@@ -100,8 +102,7 @@ extern int sata_link_init_spd(struct ata_link *link); | |||
100 | extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); | 102 | extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); |
101 | extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); | 103 | extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); |
102 | extern struct ata_port *ata_port_alloc(struct ata_host *host); | 104 | extern struct ata_port *ata_port_alloc(struct ata_host *host); |
103 | extern void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy); | 105 | extern const char *sata_spd_string(unsigned int spd); |
104 | extern void ata_lpm_schedule(struct ata_port *ap, enum link_pm); | ||
105 | 106 | ||
106 | /* libata-acpi.c */ | 107 | /* libata-acpi.c */ |
107 | #ifdef CONFIG_ATA_ACPI | 108 | #ifdef CONFIG_ATA_ACPI |
@@ -137,10 +138,15 @@ extern void ata_scsi_hotplug(struct work_struct *work); | |||
137 | extern void ata_schedule_scsi_eh(struct Scsi_Host *shost); | 138 | extern void ata_schedule_scsi_eh(struct Scsi_Host *shost); |
138 | extern void ata_scsi_dev_rescan(struct work_struct *work); | 139 | extern void ata_scsi_dev_rescan(struct work_struct *work); |
139 | extern int ata_bus_probe(struct ata_port *ap); | 140 | extern int ata_bus_probe(struct ata_port *ap); |
141 | extern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, | ||
142 | unsigned int id, unsigned int lun); | ||
143 | |||
140 | 144 | ||
141 | /* libata-eh.c */ | 145 | /* libata-eh.c */ |
142 | extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd); | 146 | extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd); |
143 | extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd); | 147 | extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd); |
148 | extern void ata_eh_acquire(struct ata_port *ap); | ||
149 | extern void ata_eh_release(struct ata_port *ap); | ||
144 | extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); | 150 | extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); |
145 | extern void ata_scsi_error(struct Scsi_Host *host); | 151 | extern void ata_scsi_error(struct Scsi_Host *host); |
146 | extern void ata_port_wait_eh(struct ata_port *ap); | 152 | extern void ata_port_wait_eh(struct ata_port *ap); |
@@ -164,11 +170,16 @@ extern int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
164 | ata_postreset_fn_t postreset, | 170 | ata_postreset_fn_t postreset, |
165 | struct ata_link **r_failed_disk); | 171 | struct ata_link **r_failed_disk); |
166 | extern void ata_eh_finish(struct ata_port *ap); | 172 | extern void ata_eh_finish(struct ata_port *ap); |
173 | extern int ata_ering_map(struct ata_ering *ering, | ||
174 | int (*map_fn)(struct ata_ering_entry *, void *), | ||
175 | void *arg); | ||
167 | 176 | ||
168 | /* libata-pmp.c */ | 177 | /* libata-pmp.c */ |
169 | #ifdef CONFIG_SATA_PMP | 178 | #ifdef CONFIG_SATA_PMP |
170 | extern int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val); | 179 | extern int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val); |
171 | extern int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val); | 180 | extern int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val); |
181 | extern int sata_pmp_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, | ||
182 | unsigned hints); | ||
172 | extern int sata_pmp_attach(struct ata_device *dev); | 183 | extern int sata_pmp_attach(struct ata_device *dev); |
173 | #else /* CONFIG_SATA_PMP */ | 184 | #else /* CONFIG_SATA_PMP */ |
174 | static inline int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val) | 185 | static inline int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val) |
@@ -181,6 +192,12 @@ static inline int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val) | |||
181 | return -EINVAL; | 192 | return -EINVAL; |
182 | } | 193 | } |
183 | 194 | ||
195 | static inline int sata_pmp_set_lpm(struct ata_link *link, | ||
196 | enum ata_lpm_policy policy, unsigned hints) | ||
197 | { | ||
198 | return -EINVAL; | ||
199 | } | ||
200 | |||
184 | static inline int sata_pmp_attach(struct ata_device *dev) | 201 | static inline int sata_pmp_attach(struct ata_device *dev) |
185 | { | 202 | { |
186 | return -EINVAL; | 203 | return -EINVAL; |
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c index 9cae65de750e..ec2c777fcdb0 100644 --- a/drivers/ata/pata_bf54x.c +++ b/drivers/ata/pata_bf54x.c | |||
@@ -826,7 +826,7 @@ static void bfin_dev_select(struct ata_port *ap, unsigned int device) | |||
826 | * @ctl: value to write | 826 | * @ctl: value to write |
827 | */ | 827 | */ |
828 | 828 | ||
829 | static u8 bfin_set_devctl(struct ata_port *ap, u8 ctl) | 829 | static void bfin_set_devctl(struct ata_port *ap, u8 ctl) |
830 | { | 830 | { |
831 | void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr; | 831 | void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr; |
832 | write_atapi_register(base, ATA_REG_CTRL, ctl); | 832 | write_atapi_register(base, ATA_REG_CTRL, ctl); |
@@ -1046,7 +1046,7 @@ static void bfin_bus_post_reset(struct ata_port *ap, unsigned int devmask) | |||
1046 | dev1 = 0; | 1046 | dev1 = 0; |
1047 | break; | 1047 | break; |
1048 | } | 1048 | } |
1049 | msleep(50); /* give drive a breather */ | 1049 | ata_msleep(ap, 50); /* give drive a breather */ |
1050 | } | 1050 | } |
1051 | if (dev1) | 1051 | if (dev1) |
1052 | ata_sff_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); | 1052 | ata_sff_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); |
@@ -1087,7 +1087,7 @@ static unsigned int bfin_bus_softreset(struct ata_port *ap, | |||
1087 | * | 1087 | * |
1088 | * Old drivers/ide uses the 2mS rule and then waits for ready | 1088 | * Old drivers/ide uses the 2mS rule and then waits for ready |
1089 | */ | 1089 | */ |
1090 | msleep(150); | 1090 | ata_msleep(ap, 150); |
1091 | 1091 | ||
1092 | /* Before we perform post reset processing we want to see if | 1092 | /* Before we perform post reset processing we want to see if |
1093 | * the bus shows 0xFF because the odd clown forgets the D7 | 1093 | * the bus shows 0xFF because the odd clown forgets the D7 |
diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c index e5f289f59ca3..549d28dbf90d 100644 --- a/drivers/ata/pata_cmd640.c +++ b/drivers/ata/pata_cmd640.c | |||
@@ -161,6 +161,17 @@ static int cmd640_port_start(struct ata_port *ap) | |||
161 | return 0; | 161 | return 0; |
162 | } | 162 | } |
163 | 163 | ||
164 | static bool cmd640_sff_irq_check(struct ata_port *ap) | ||
165 | { | ||
166 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); | ||
167 | int irq_reg = ap->port_no ? ARTIM23 : CFR; | ||
168 | u8 irq_stat, irq_mask = ap->port_no ? 0x10 : 0x04; | ||
169 | |||
170 | pci_read_config_byte(pdev, irq_reg, &irq_stat); | ||
171 | |||
172 | return irq_stat & irq_mask; | ||
173 | } | ||
174 | |||
164 | static struct scsi_host_template cmd640_sht = { | 175 | static struct scsi_host_template cmd640_sht = { |
165 | ATA_PIO_SHT(DRV_NAME), | 176 | ATA_PIO_SHT(DRV_NAME), |
166 | }; | 177 | }; |
@@ -169,6 +180,7 @@ static struct ata_port_operations cmd640_port_ops = { | |||
169 | .inherits = &ata_sff_port_ops, | 180 | .inherits = &ata_sff_port_ops, |
170 | /* In theory xfer_noirq is not needed once we kill the prefetcher */ | 181 | /* In theory xfer_noirq is not needed once we kill the prefetcher */ |
171 | .sff_data_xfer = ata_sff_data_xfer_noirq, | 182 | .sff_data_xfer = ata_sff_data_xfer_noirq, |
183 | .sff_irq_check = cmd640_sff_irq_check, | ||
172 | .qc_issue = cmd640_qc_issue, | 184 | .qc_issue = cmd640_qc_issue, |
173 | .cable_detect = ata_cable_40wire, | 185 | .cable_detect = ata_cable_40wire, |
174 | .set_piomode = cmd640_set_piomode, | 186 | .set_piomode = cmd640_set_piomode, |
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c index c39f213e1bbc..c2ed5868dda6 100644 --- a/drivers/ata/pata_pdc202xx_old.c +++ b/drivers/ata/pata_pdc202xx_old.c | |||
@@ -44,6 +44,27 @@ static void pdc202xx_exec_command(struct ata_port *ap, | |||
44 | ndelay(400); | 44 | ndelay(400); |
45 | } | 45 | } |
46 | 46 | ||
47 | static bool pdc202xx_irq_check(struct ata_port *ap) | ||
48 | { | ||
49 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); | ||
50 | unsigned long master = pci_resource_start(pdev, 4); | ||
51 | u8 sc1d = inb(master + 0x1d); | ||
52 | |||
53 | if (ap->port_no) { | ||
54 | /* | ||
55 | * bit 7: error, bit 6: interrupting, | ||
56 | * bit 5: FIFO full, bit 4: FIFO empty | ||
57 | */ | ||
58 | return sc1d & 0x40; | ||
59 | } else { | ||
60 | /* | ||
61 | * bit 3: error, bit 2: interrupting, | ||
62 | * bit 1: FIFO full, bit 0: FIFO empty | ||
63 | */ | ||
64 | return sc1d & 0x04; | ||
65 | } | ||
66 | } | ||
67 | |||
47 | /** | 68 | /** |
48 | * pdc202xx_configure_piomode - set chip PIO timing | 69 | * pdc202xx_configure_piomode - set chip PIO timing |
49 | * @ap: ATA interface | 70 | * @ap: ATA interface |
@@ -282,6 +303,7 @@ static struct ata_port_operations pdc2024x_port_ops = { | |||
282 | .set_dmamode = pdc202xx_set_dmamode, | 303 | .set_dmamode = pdc202xx_set_dmamode, |
283 | 304 | ||
284 | .sff_exec_command = pdc202xx_exec_command, | 305 | .sff_exec_command = pdc202xx_exec_command, |
306 | .sff_irq_check = pdc202xx_irq_check, | ||
285 | }; | 307 | }; |
286 | 308 | ||
287 | static struct ata_port_operations pdc2026x_port_ops = { | 309 | static struct ata_port_operations pdc2026x_port_ops = { |
@@ -297,6 +319,7 @@ static struct ata_port_operations pdc2026x_port_ops = { | |||
297 | .port_start = pdc2026x_port_start, | 319 | .port_start = pdc2026x_port_start, |
298 | 320 | ||
299 | .sff_exec_command = pdc202xx_exec_command, | 321 | .sff_exec_command = pdc202xx_exec_command, |
322 | .sff_irq_check = pdc202xx_irq_check, | ||
300 | }; | 323 | }; |
301 | 324 | ||
302 | static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 325 | static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ata/pata_samsung_cf.c b/drivers/ata/pata_samsung_cf.c index 6f9cfb24b751..8a51d673e5b2 100644 --- a/drivers/ata/pata_samsung_cf.c +++ b/drivers/ata/pata_samsung_cf.c | |||
@@ -322,7 +322,7 @@ static int pata_s3c_wait_after_reset(struct ata_link *link, | |||
322 | { | 322 | { |
323 | int rc; | 323 | int rc; |
324 | 324 | ||
325 | msleep(ATA_WAIT_AFTER_RESET); | 325 | ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); |
326 | 326 | ||
327 | /* always check readiness of the master device */ | 327 | /* always check readiness of the master device */ |
328 | rc = ata_sff_wait_ready(link, deadline); | 328 | rc = ata_sff_wait_ready(link, deadline); |
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c index fe36966f7e34..093715c3273a 100644 --- a/drivers/ata/pata_scc.c +++ b/drivers/ata/pata_scc.c | |||
@@ -530,7 +530,7 @@ static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask, | |||
530 | * | 530 | * |
531 | * Old drivers/ide uses the 2mS rule and then waits for ready. | 531 | * Old drivers/ide uses the 2mS rule and then waits for ready. |
532 | */ | 532 | */ |
533 | msleep(150); | 533 | ata_msleep(ap, 150); |
534 | 534 | ||
535 | /* always check readiness of the master device */ | 535 | /* always check readiness of the master device */ |
536 | rc = ata_sff_wait_ready(link, deadline); | 536 | rc = ata_sff_wait_ready(link, deadline); |
@@ -559,7 +559,7 @@ static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask, | |||
559 | lbal = in_be32(ioaddr->lbal_addr); | 559 | lbal = in_be32(ioaddr->lbal_addr); |
560 | if ((nsect == 1) && (lbal == 1)) | 560 | if ((nsect == 1) && (lbal == 1)) |
561 | break; | 561 | break; |
562 | msleep(50); /* give drive a breather */ | 562 | ata_msleep(ap, 50); /* give drive a breather */ |
563 | } | 563 | } |
564 | 564 | ||
565 | rc = ata_sff_wait_ready(link, deadline); | 565 | rc = ata_sff_wait_ready(link, deadline); |
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c index d3190d7ec304..00eefbd84b33 100644 --- a/drivers/ata/pata_sil680.c +++ b/drivers/ata/pata_sil680.c | |||
@@ -202,14 +202,25 @@ static void sil680_set_dmamode(struct ata_port *ap, struct ata_device *adev) | |||
202 | * LOCKING: | 202 | * LOCKING: |
203 | * spin_lock_irqsave(host lock) | 203 | * spin_lock_irqsave(host lock) |
204 | */ | 204 | */ |
205 | void sil680_sff_exec_command(struct ata_port *ap, | 205 | static void sil680_sff_exec_command(struct ata_port *ap, |
206 | const struct ata_taskfile *tf) | 206 | const struct ata_taskfile *tf) |
207 | { | 207 | { |
208 | DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command); | 208 | DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command); |
209 | iowrite8(tf->command, ap->ioaddr.command_addr); | 209 | iowrite8(tf->command, ap->ioaddr.command_addr); |
210 | ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); | 210 | ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
211 | } | 211 | } |
212 | 212 | ||
213 | static bool sil680_sff_irq_check(struct ata_port *ap) | ||
214 | { | ||
215 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); | ||
216 | unsigned long addr = sil680_selreg(ap, 1); | ||
217 | u8 val; | ||
218 | |||
219 | pci_read_config_byte(pdev, addr, &val); | ||
220 | |||
221 | return val & 0x08; | ||
222 | } | ||
223 | |||
213 | static struct scsi_host_template sil680_sht = { | 224 | static struct scsi_host_template sil680_sht = { |
214 | ATA_BMDMA_SHT(DRV_NAME), | 225 | ATA_BMDMA_SHT(DRV_NAME), |
215 | }; | 226 | }; |
@@ -218,6 +229,7 @@ static struct scsi_host_template sil680_sht = { | |||
218 | static struct ata_port_operations sil680_port_ops = { | 229 | static struct ata_port_operations sil680_port_ops = { |
219 | .inherits = &ata_bmdma32_port_ops, | 230 | .inherits = &ata_bmdma32_port_ops, |
220 | .sff_exec_command = sil680_sff_exec_command, | 231 | .sff_exec_command = sil680_sff_exec_command, |
232 | .sff_irq_check = sil680_sff_irq_check, | ||
221 | .cable_detect = sil680_cable_detect, | 233 | .cable_detect = sil680_cable_detect, |
222 | .set_piomode = sil680_set_piomode, | 234 | .set_piomode = sil680_set_piomode, |
223 | .set_dmamode = sil680_set_dmamode, | 235 | .set_dmamode = sil680_set_dmamode, |
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c index 98548f640c8e..7f5d020ed56c 100644 --- a/drivers/ata/pata_sl82c105.c +++ b/drivers/ata/pata_sl82c105.c | |||
@@ -227,6 +227,16 @@ static int sl82c105_qc_defer(struct ata_queued_cmd *qc) | |||
227 | return 0; | 227 | return 0; |
228 | } | 228 | } |
229 | 229 | ||
230 | static bool sl82c105_sff_irq_check(struct ata_port *ap) | ||
231 | { | ||
232 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); | ||
233 | u32 val, mask = ap->port_no ? CTRL_IDE_IRQB : CTRL_IDE_IRQA; | ||
234 | |||
235 | pci_read_config_dword(pdev, 0x40, &val); | ||
236 | |||
237 | return val & mask; | ||
238 | } | ||
239 | |||
230 | static struct scsi_host_template sl82c105_sht = { | 240 | static struct scsi_host_template sl82c105_sht = { |
231 | ATA_BMDMA_SHT(DRV_NAME), | 241 | ATA_BMDMA_SHT(DRV_NAME), |
232 | }; | 242 | }; |
@@ -239,6 +249,7 @@ static struct ata_port_operations sl82c105_port_ops = { | |||
239 | .cable_detect = ata_cable_40wire, | 249 | .cable_detect = ata_cable_40wire, |
240 | .set_piomode = sl82c105_set_piomode, | 250 | .set_piomode = sl82c105_set_piomode, |
241 | .prereset = sl82c105_pre_reset, | 251 | .prereset = sl82c105_pre_reset, |
252 | .sff_irq_check = sl82c105_sff_irq_check, | ||
242 | }; | 253 | }; |
243 | 254 | ||
244 | /** | 255 | /** |
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c index 7325f77480dc..b0214d00d50b 100644 --- a/drivers/ata/sata_fsl.c +++ b/drivers/ata/sata_fsl.c | |||
@@ -678,7 +678,7 @@ static void sata_fsl_port_stop(struct ata_port *ap) | |||
678 | iowrite32(temp, hcr_base + HCONTROL); | 678 | iowrite32(temp, hcr_base + HCONTROL); |
679 | 679 | ||
680 | /* Poll for controller to go offline - should happen immediately */ | 680 | /* Poll for controller to go offline - should happen immediately */ |
681 | ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 1); | 681 | ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, ONLINE, 1, 1); |
682 | 682 | ||
683 | ap->private_data = NULL; | 683 | ap->private_data = NULL; |
684 | dma_free_coherent(dev, SATA_FSL_PORT_PRIV_DMA_SZ, | 684 | dma_free_coherent(dev, SATA_FSL_PORT_PRIV_DMA_SZ, |
@@ -729,7 +729,8 @@ try_offline_again: | |||
729 | iowrite32(temp, hcr_base + HCONTROL); | 729 | iowrite32(temp, hcr_base + HCONTROL); |
730 | 730 | ||
731 | /* Poll for controller to go offline */ | 731 | /* Poll for controller to go offline */ |
732 | temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 500); | 732 | temp = ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, ONLINE, |
733 | 1, 500); | ||
733 | 734 | ||
734 | if (temp & ONLINE) { | 735 | if (temp & ONLINE) { |
735 | ata_port_printk(ap, KERN_ERR, | 736 | ata_port_printk(ap, KERN_ERR, |
@@ -752,7 +753,7 @@ try_offline_again: | |||
752 | /* | 753 | /* |
753 | * PHY reset should remain asserted for atleast 1ms | 754 | * PHY reset should remain asserted for atleast 1ms |
754 | */ | 755 | */ |
755 | msleep(1); | 756 | ata_msleep(ap, 1); |
756 | 757 | ||
757 | /* | 758 | /* |
758 | * Now, bring the host controller online again, this can take time | 759 | * Now, bring the host controller online again, this can take time |
@@ -766,7 +767,7 @@ try_offline_again: | |||
766 | temp |= HCONTROL_PMP_ATTACHED; | 767 | temp |= HCONTROL_PMP_ATTACHED; |
767 | iowrite32(temp, hcr_base + HCONTROL); | 768 | iowrite32(temp, hcr_base + HCONTROL); |
768 | 769 | ||
769 | temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, 0, 1, 500); | 770 | temp = ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, 0, 1, 500); |
770 | 771 | ||
771 | if (!(temp & ONLINE)) { | 772 | if (!(temp & ONLINE)) { |
772 | ata_port_printk(ap, KERN_ERR, | 773 | ata_port_printk(ap, KERN_ERR, |
@@ -784,7 +785,7 @@ try_offline_again: | |||
784 | * presence | 785 | * presence |
785 | */ | 786 | */ |
786 | 787 | ||
787 | temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0, 1, 500); | 788 | temp = ata_wait_register(ap, hcr_base + HSTATUS, 0xFF, 0, 1, 500); |
788 | if ((!(temp & 0x10)) || ata_link_offline(link)) { | 789 | if ((!(temp & 0x10)) || ata_link_offline(link)) { |
789 | ata_port_printk(ap, KERN_WARNING, | 790 | ata_port_printk(ap, KERN_WARNING, |
790 | "No Device OR PHYRDY change,Hstatus = 0x%x\n", | 791 | "No Device OR PHYRDY change,Hstatus = 0x%x\n", |
@@ -797,7 +798,7 @@ try_offline_again: | |||
797 | * Wait for the first D2H from device,i.e,signature update notification | 798 | * Wait for the first D2H from device,i.e,signature update notification |
798 | */ | 799 | */ |
799 | start_jiffies = jiffies; | 800 | start_jiffies = jiffies; |
800 | temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0x10, | 801 | temp = ata_wait_register(ap, hcr_base + HSTATUS, 0xFF, 0x10, |
801 | 500, jiffies_to_msecs(deadline - start_jiffies)); | 802 | 500, jiffies_to_msecs(deadline - start_jiffies)); |
802 | 803 | ||
803 | if ((temp & 0xFF) != 0x18) { | 804 | if ((temp & 0xFF) != 0x18) { |
@@ -880,7 +881,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class, | |||
880 | iowrite32(pmp, CQPMP + hcr_base); | 881 | iowrite32(pmp, CQPMP + hcr_base); |
881 | iowrite32(1, CQ + hcr_base); | 882 | iowrite32(1, CQ + hcr_base); |
882 | 883 | ||
883 | temp = ata_wait_register(CQ + hcr_base, 0x1, 0x1, 1, 5000); | 884 | temp = ata_wait_register(ap, CQ + hcr_base, 0x1, 0x1, 1, 5000); |
884 | if (temp & 0x1) { | 885 | if (temp & 0x1) { |
885 | ata_port_printk(ap, KERN_WARNING, "ATA_SRST issue failed\n"); | 886 | ata_port_printk(ap, KERN_WARNING, "ATA_SRST issue failed\n"); |
886 | 887 | ||
@@ -896,7 +897,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class, | |||
896 | goto err; | 897 | goto err; |
897 | } | 898 | } |
898 | 899 | ||
899 | msleep(1); | 900 | ata_msleep(ap, 1); |
900 | 901 | ||
901 | /* | 902 | /* |
902 | * SATA device enters reset state after receving a Control register | 903 | * SATA device enters reset state after receving a Control register |
@@ -915,7 +916,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class, | |||
915 | if (pmp != SATA_PMP_CTRL_PORT) | 916 | if (pmp != SATA_PMP_CTRL_PORT) |
916 | iowrite32(pmp, CQPMP + hcr_base); | 917 | iowrite32(pmp, CQPMP + hcr_base); |
917 | iowrite32(1, CQ + hcr_base); | 918 | iowrite32(1, CQ + hcr_base); |
918 | msleep(150); /* ?? */ | 919 | ata_msleep(ap, 150); /* ?? */ |
919 | 920 | ||
920 | /* | 921 | /* |
921 | * The above command would have signalled an interrupt on command | 922 | * The above command would have signalled an interrupt on command |
@@ -1137,17 +1138,13 @@ static void sata_fsl_host_intr(struct ata_port *ap) | |||
1137 | ioread32(hcr_base + CE)); | 1138 | ioread32(hcr_base + CE)); |
1138 | 1139 | ||
1139 | for (i = 0; i < SATA_FSL_QUEUE_DEPTH; i++) { | 1140 | for (i = 0; i < SATA_FSL_QUEUE_DEPTH; i++) { |
1140 | if (done_mask & (1 << i)) { | 1141 | if (done_mask & (1 << i)) |
1141 | qc = ata_qc_from_tag(ap, i); | ||
1142 | if (qc) { | ||
1143 | ata_qc_complete(qc); | ||
1144 | } | ||
1145 | DPRINTK | 1142 | DPRINTK |
1146 | ("completing ncq cmd,tag=%d,CC=0x%x,CA=0x%x\n", | 1143 | ("completing ncq cmd,tag=%d,CC=0x%x,CA=0x%x\n", |
1147 | i, ioread32(hcr_base + CC), | 1144 | i, ioread32(hcr_base + CC), |
1148 | ioread32(hcr_base + CA)); | 1145 | ioread32(hcr_base + CA)); |
1149 | } | ||
1150 | } | 1146 | } |
1147 | ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask); | ||
1151 | return; | 1148 | return; |
1152 | 1149 | ||
1153 | } else if ((ap->qc_active & (1 << ATA_TAG_INTERNAL))) { | 1150 | } else if ((ap->qc_active & (1 << ATA_TAG_INTERNAL))) { |
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c index a36149ebf4a2..83a44471b189 100644 --- a/drivers/ata/sata_inic162x.c +++ b/drivers/ata/sata_inic162x.c | |||
@@ -614,7 +614,7 @@ static int inic_hardreset(struct ata_link *link, unsigned int *class, | |||
614 | 614 | ||
615 | writew(IDMA_CTL_RST_ATA, idma_ctl); | 615 | writew(IDMA_CTL_RST_ATA, idma_ctl); |
616 | readw(idma_ctl); /* flush */ | 616 | readw(idma_ctl); /* flush */ |
617 | msleep(1); | 617 | ata_msleep(ap, 1); |
618 | writew(0, idma_ctl); | 618 | writew(0, idma_ctl); |
619 | 619 | ||
620 | rc = sata_link_resume(link, timing, deadline); | 620 | rc = sata_link_resume(link, timing, deadline); |
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index a9fd9709c262..bf74a36d3cc3 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c | |||
@@ -2743,18 +2743,11 @@ static void mv_err_intr(struct ata_port *ap) | |||
2743 | } | 2743 | } |
2744 | } | 2744 | } |
2745 | 2745 | ||
2746 | static void mv_process_crpb_response(struct ata_port *ap, | 2746 | static bool mv_process_crpb_response(struct ata_port *ap, |
2747 | struct mv_crpb *response, unsigned int tag, int ncq_enabled) | 2747 | struct mv_crpb *response, unsigned int tag, int ncq_enabled) |
2748 | { | 2748 | { |
2749 | u8 ata_status; | 2749 | u8 ata_status; |
2750 | u16 edma_status = le16_to_cpu(response->flags); | 2750 | u16 edma_status = le16_to_cpu(response->flags); |
2751 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); | ||
2752 | |||
2753 | if (unlikely(!qc)) { | ||
2754 | ata_port_printk(ap, KERN_ERR, "%s: no qc for tag=%d\n", | ||
2755 | __func__, tag); | ||
2756 | return; | ||
2757 | } | ||
2758 | 2751 | ||
2759 | /* | 2752 | /* |
2760 | * edma_status from a response queue entry: | 2753 | * edma_status from a response queue entry: |
@@ -2768,13 +2761,14 @@ static void mv_process_crpb_response(struct ata_port *ap, | |||
2768 | * Error will be seen/handled by | 2761 | * Error will be seen/handled by |
2769 | * mv_err_intr(). So do nothing at all here. | 2762 | * mv_err_intr(). So do nothing at all here. |
2770 | */ | 2763 | */ |
2771 | return; | 2764 | return false; |
2772 | } | 2765 | } |
2773 | } | 2766 | } |
2774 | ata_status = edma_status >> CRPB_FLAG_STATUS_SHIFT; | 2767 | ata_status = edma_status >> CRPB_FLAG_STATUS_SHIFT; |
2775 | if (!ac_err_mask(ata_status)) | 2768 | if (!ac_err_mask(ata_status)) |
2776 | ata_qc_complete(qc); | 2769 | return true; |
2777 | /* else: leave it for mv_err_intr() */ | 2770 | /* else: leave it for mv_err_intr() */ |
2771 | return false; | ||
2778 | } | 2772 | } |
2779 | 2773 | ||
2780 | static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp) | 2774 | static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp) |
@@ -2783,6 +2777,7 @@ static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp | |||
2783 | struct mv_host_priv *hpriv = ap->host->private_data; | 2777 | struct mv_host_priv *hpriv = ap->host->private_data; |
2784 | u32 in_index; | 2778 | u32 in_index; |
2785 | bool work_done = false; | 2779 | bool work_done = false; |
2780 | u32 done_mask = 0; | ||
2786 | int ncq_enabled = (pp->pp_flags & MV_PP_FLAG_NCQ_EN); | 2781 | int ncq_enabled = (pp->pp_flags & MV_PP_FLAG_NCQ_EN); |
2787 | 2782 | ||
2788 | /* Get the hardware queue position index */ | 2783 | /* Get the hardware queue position index */ |
@@ -2803,15 +2798,19 @@ static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp | |||
2803 | /* Gen II/IIE: get command tag from CRPB entry */ | 2798 | /* Gen II/IIE: get command tag from CRPB entry */ |
2804 | tag = le16_to_cpu(response->id) & 0x1f; | 2799 | tag = le16_to_cpu(response->id) & 0x1f; |
2805 | } | 2800 | } |
2806 | mv_process_crpb_response(ap, response, tag, ncq_enabled); | 2801 | if (mv_process_crpb_response(ap, response, tag, ncq_enabled)) |
2802 | done_mask |= 1 << tag; | ||
2807 | work_done = true; | 2803 | work_done = true; |
2808 | } | 2804 | } |
2809 | 2805 | ||
2810 | /* Update the software queue position index in hardware */ | 2806 | if (work_done) { |
2811 | if (work_done) | 2807 | ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask); |
2808 | |||
2809 | /* Update the software queue position index in hardware */ | ||
2812 | writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | | 2810 | writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | |
2813 | (pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT), | 2811 | (pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT), |
2814 | port_mmio + EDMA_RSP_Q_OUT_PTR); | 2812 | port_mmio + EDMA_RSP_Q_OUT_PTR); |
2813 | } | ||
2815 | } | 2814 | } |
2816 | 2815 | ||
2817 | static void mv_port_intr(struct ata_port *ap, u32 port_cause) | 2816 | static void mv_port_intr(struct ata_port *ap, u32 port_cause) |
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c index cb89ef8d99d9..7254e255fd78 100644 --- a/drivers/ata/sata_nv.c +++ b/drivers/ata/sata_nv.c | |||
@@ -873,29 +873,11 @@ static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err) | |||
873 | ata_port_freeze(ap); | 873 | ata_port_freeze(ap); |
874 | else | 874 | else |
875 | ata_port_abort(ap); | 875 | ata_port_abort(ap); |
876 | return 1; | 876 | return -1; |
877 | } | 877 | } |
878 | 878 | ||
879 | if (likely(flags & NV_CPB_RESP_DONE)) { | 879 | if (likely(flags & NV_CPB_RESP_DONE)) |
880 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num); | 880 | return 1; |
881 | VPRINTK("CPB flags done, flags=0x%x\n", flags); | ||
882 | if (likely(qc)) { | ||
883 | DPRINTK("Completing qc from tag %d\n", cpb_num); | ||
884 | ata_qc_complete(qc); | ||
885 | } else { | ||
886 | struct ata_eh_info *ehi = &ap->link.eh_info; | ||
887 | /* Notifier bits set without a command may indicate the drive | ||
888 | is misbehaving. Raise host state machine violation on this | ||
889 | condition. */ | ||
890 | ata_port_printk(ap, KERN_ERR, | ||
891 | "notifier for tag %d with no cmd?\n", | ||
892 | cpb_num); | ||
893 | ehi->err_mask |= AC_ERR_HSM; | ||
894 | ehi->action |= ATA_EH_RESET; | ||
895 | ata_port_freeze(ap); | ||
896 | return 1; | ||
897 | } | ||
898 | } | ||
899 | return 0; | 881 | return 0; |
900 | } | 882 | } |
901 | 883 | ||
@@ -1018,6 +1000,7 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) | |||
1018 | NV_ADMA_STAT_CPBERR | | 1000 | NV_ADMA_STAT_CPBERR | |
1019 | NV_ADMA_STAT_CMD_COMPLETE)) { | 1001 | NV_ADMA_STAT_CMD_COMPLETE)) { |
1020 | u32 check_commands = notifier_clears[i]; | 1002 | u32 check_commands = notifier_clears[i]; |
1003 | u32 done_mask = 0; | ||
1021 | int pos, rc; | 1004 | int pos, rc; |
1022 | 1005 | ||
1023 | if (status & NV_ADMA_STAT_CPBERR) { | 1006 | if (status & NV_ADMA_STAT_CPBERR) { |
@@ -1034,10 +1017,13 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) | |||
1034 | pos--; | 1017 | pos--; |
1035 | rc = nv_adma_check_cpb(ap, pos, | 1018 | rc = nv_adma_check_cpb(ap, pos, |
1036 | notifier_error & (1 << pos)); | 1019 | notifier_error & (1 << pos)); |
1037 | if (unlikely(rc)) | 1020 | if (rc > 0) |
1021 | done_mask |= 1 << pos; | ||
1022 | else if (unlikely(rc < 0)) | ||
1038 | check_commands = 0; | 1023 | check_commands = 0; |
1039 | check_commands &= ~(1 << pos); | 1024 | check_commands &= ~(1 << pos); |
1040 | } | 1025 | } |
1026 | ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask); | ||
1041 | } | 1027 | } |
1042 | } | 1028 | } |
1043 | 1029 | ||
@@ -2132,7 +2118,6 @@ static int nv_swncq_sdbfis(struct ata_port *ap) | |||
2132 | struct ata_eh_info *ehi = &ap->link.eh_info; | 2118 | struct ata_eh_info *ehi = &ap->link.eh_info; |
2133 | u32 sactive; | 2119 | u32 sactive; |
2134 | u32 done_mask; | 2120 | u32 done_mask; |
2135 | int i; | ||
2136 | u8 host_stat; | 2121 | u8 host_stat; |
2137 | u8 lack_dhfis = 0; | 2122 | u8 lack_dhfis = 0; |
2138 | 2123 | ||
@@ -2152,27 +2137,11 @@ static int nv_swncq_sdbfis(struct ata_port *ap) | |||
2152 | sactive = readl(pp->sactive_block); | 2137 | sactive = readl(pp->sactive_block); |
2153 | done_mask = pp->qc_active ^ sactive; | 2138 | done_mask = pp->qc_active ^ sactive; |
2154 | 2139 | ||
2155 | if (unlikely(done_mask & sactive)) { | 2140 | pp->qc_active &= ~done_mask; |
2156 | ata_ehi_clear_desc(ehi); | 2141 | pp->dhfis_bits &= ~done_mask; |
2157 | ata_ehi_push_desc(ehi, "illegal SWNCQ:qc_active transition" | 2142 | pp->dmafis_bits &= ~done_mask; |
2158 | "(%08x->%08x)", pp->qc_active, sactive); | 2143 | pp->sdbfis_bits |= done_mask; |
2159 | ehi->err_mask |= AC_ERR_HSM; | 2144 | ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask); |
2160 | ehi->action |= ATA_EH_RESET; | ||
2161 | return -EINVAL; | ||
2162 | } | ||
2163 | for (i = 0; i < ATA_MAX_QUEUE; i++) { | ||
2164 | if (!(done_mask & (1 << i))) | ||
2165 | continue; | ||
2166 | |||
2167 | qc = ata_qc_from_tag(ap, i); | ||
2168 | if (qc) { | ||
2169 | ata_qc_complete(qc); | ||
2170 | pp->qc_active &= ~(1 << i); | ||
2171 | pp->dhfis_bits &= ~(1 << i); | ||
2172 | pp->dmafis_bits &= ~(1 << i); | ||
2173 | pp->sdbfis_bits |= (1 << i); | ||
2174 | } | ||
2175 | } | ||
2176 | 2145 | ||
2177 | if (!ap->qc_active) { | 2146 | if (!ap->qc_active) { |
2178 | DPRINTK("over\n"); | 2147 | DPRINTK("over\n"); |
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c index be7726d7686d..af41c6fd1254 100644 --- a/drivers/ata/sata_sil24.c +++ b/drivers/ata/sata_sil24.c | |||
@@ -589,9 +589,9 @@ static int sil24_init_port(struct ata_port *ap) | |||
589 | sil24_clear_pmp(ap); | 589 | sil24_clear_pmp(ap); |
590 | 590 | ||
591 | writel(PORT_CS_INIT, port + PORT_CTRL_STAT); | 591 | writel(PORT_CS_INIT, port + PORT_CTRL_STAT); |
592 | ata_wait_register(port + PORT_CTRL_STAT, | 592 | ata_wait_register(ap, port + PORT_CTRL_STAT, |
593 | PORT_CS_INIT, PORT_CS_INIT, 10, 100); | 593 | PORT_CS_INIT, PORT_CS_INIT, 10, 100); |
594 | tmp = ata_wait_register(port + PORT_CTRL_STAT, | 594 | tmp = ata_wait_register(ap, port + PORT_CTRL_STAT, |
595 | PORT_CS_RDY, 0, 10, 100); | 595 | PORT_CS_RDY, 0, 10, 100); |
596 | 596 | ||
597 | if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY) { | 597 | if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY) { |
@@ -631,7 +631,7 @@ static int sil24_exec_polled_cmd(struct ata_port *ap, int pmp, | |||
631 | writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4); | 631 | writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4); |
632 | 632 | ||
633 | irq_mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; | 633 | irq_mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; |
634 | irq_stat = ata_wait_register(port + PORT_IRQ_STAT, irq_mask, 0x0, | 634 | irq_stat = ata_wait_register(ap, port + PORT_IRQ_STAT, irq_mask, 0x0, |
635 | 10, timeout_msec); | 635 | 10, timeout_msec); |
636 | 636 | ||
637 | writel(irq_mask, port + PORT_IRQ_STAT); /* clear IRQs */ | 637 | writel(irq_mask, port + PORT_IRQ_STAT); /* clear IRQs */ |
@@ -719,9 +719,9 @@ static int sil24_hardreset(struct ata_link *link, unsigned int *class, | |||
719 | "state, performing PORT_RST\n"); | 719 | "state, performing PORT_RST\n"); |
720 | 720 | ||
721 | writel(PORT_CS_PORT_RST, port + PORT_CTRL_STAT); | 721 | writel(PORT_CS_PORT_RST, port + PORT_CTRL_STAT); |
722 | msleep(10); | 722 | ata_msleep(ap, 10); |
723 | writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); | 723 | writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); |
724 | ata_wait_register(port + PORT_CTRL_STAT, PORT_CS_RDY, 0, | 724 | ata_wait_register(ap, port + PORT_CTRL_STAT, PORT_CS_RDY, 0, |
725 | 10, 5000); | 725 | 10, 5000); |
726 | 726 | ||
727 | /* restore port configuration */ | 727 | /* restore port configuration */ |
@@ -740,7 +740,7 @@ static int sil24_hardreset(struct ata_link *link, unsigned int *class, | |||
740 | tout_msec = 5000; | 740 | tout_msec = 5000; |
741 | 741 | ||
742 | writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT); | 742 | writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT); |
743 | tmp = ata_wait_register(port + PORT_CTRL_STAT, | 743 | tmp = ata_wait_register(ap, port + PORT_CTRL_STAT, |
744 | PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10, | 744 | PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10, |
745 | tout_msec); | 745 | tout_msec); |
746 | 746 | ||
@@ -1253,7 +1253,7 @@ static void sil24_init_controller(struct ata_host *host) | |||
1253 | tmp = readl(port + PORT_CTRL_STAT); | 1253 | tmp = readl(port + PORT_CTRL_STAT); |
1254 | if (tmp & PORT_CS_PORT_RST) { | 1254 | if (tmp & PORT_CS_PORT_RST) { |
1255 | writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); | 1255 | writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); |
1256 | tmp = ata_wait_register(port + PORT_CTRL_STAT, | 1256 | tmp = ata_wait_register(NULL, port + PORT_CTRL_STAT, |
1257 | PORT_CS_PORT_RST, | 1257 | PORT_CS_PORT_RST, |
1258 | PORT_CS_PORT_RST, 10, 100); | 1258 | PORT_CS_PORT_RST, 10, 100); |
1259 | if (tmp & PORT_CS_PORT_RST) | 1259 | if (tmp & PORT_CS_PORT_RST) |
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c index 4730c42a5ee5..c21589986c69 100644 --- a/drivers/ata/sata_via.c +++ b/drivers/ata/sata_via.c | |||
@@ -349,7 +349,7 @@ static int vt6420_prereset(struct ata_link *link, unsigned long deadline) | |||
349 | 349 | ||
350 | /* wait for phy to become ready, if necessary */ | 350 | /* wait for phy to become ready, if necessary */ |
351 | do { | 351 | do { |
352 | msleep(200); | 352 | ata_msleep(link->ap, 200); |
353 | svia_scr_read(link, SCR_STATUS, &sstatus); | 353 | svia_scr_read(link, SCR_STATUS, &sstatus); |
354 | if ((sstatus & 0xf) != 1) | 354 | if ((sstatus & 0xf) != 1) |
355 | break; | 355 | break; |