aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-06-13 23:52:39 -0400
committerDavid S. Miller <davem@davemloft.net>2008-06-13 23:52:39 -0400
commit4ae127d1b6c71f9240dd4245f240e6dd8fc98014 (patch)
treeb7aa27b3e0c655f4613fe2146cb57d7f69e421f6 /drivers/ata
parent875ec4333b99144e2589e900a0bcd2c25c757b27 (diff)
parent7775c9753b94fe429dc4323360d6502c95e0dd6e (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
Conflicts: drivers/net/smc911x.c
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/ahci.c137
-rw-r--r--drivers/ata/ata_piix.c2
-rw-r--r--drivers/ata/libata-acpi.c165
-rw-r--r--drivers/ata/libata-sff.c115
-rw-r--r--drivers/ata/pata_icside.c2
-rw-r--r--drivers/ata/pata_rb532_cf.c4
-rw-r--r--drivers/ata/pata_scc.c5
-rw-r--r--drivers/ata/sata_mv.c24
8 files changed, 349 insertions, 105 deletions
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 544b7d6c617c..966ab401e523 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -89,6 +89,7 @@ enum {
89 board_ahci_sb600 = 3, 89 board_ahci_sb600 = 3,
90 board_ahci_mv = 4, 90 board_ahci_mv = 4,
91 board_ahci_sb700 = 5, 91 board_ahci_sb700 = 5,
92 board_ahci_mcp65 = 6,
92 93
93 /* global controller registers */ 94 /* global controller registers */
94 HOST_CAP = 0x00, /* host capabilities */ 95 HOST_CAP = 0x00, /* host capabilities */
@@ -190,6 +191,7 @@ enum {
190 AHCI_HFLAG_NO_PMP = (1 << 6), /* no PMP */ 191 AHCI_HFLAG_NO_PMP = (1 << 6), /* no PMP */
191 AHCI_HFLAG_NO_HOTPLUG = (1 << 7), /* ignore PxSERR.DIAG.N */ 192 AHCI_HFLAG_NO_HOTPLUG = (1 << 7), /* ignore PxSERR.DIAG.N */
192 AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */ 193 AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */
194 AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */
193 195
194 /* ap->flags bits */ 196 /* ap->flags bits */
195 197
@@ -253,6 +255,8 @@ static void ahci_pmp_attach(struct ata_port *ap);
253static void ahci_pmp_detach(struct ata_port *ap); 255static void ahci_pmp_detach(struct ata_port *ap);
254static int ahci_softreset(struct ata_link *link, unsigned int *class, 256static int ahci_softreset(struct ata_link *link, unsigned int *class,
255 unsigned long deadline); 257 unsigned long deadline);
258static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
259 unsigned long deadline);
256static int ahci_hardreset(struct ata_link *link, unsigned int *class, 260static int ahci_hardreset(struct ata_link *link, unsigned int *class,
257 unsigned long deadline); 261 unsigned long deadline);
258static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class, 262static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
@@ -329,6 +333,12 @@ static struct ata_port_operations ahci_p5wdh_ops = {
329 .hardreset = ahci_p5wdh_hardreset, 333 .hardreset = ahci_p5wdh_hardreset,
330}; 334};
331 335
336static struct ata_port_operations ahci_sb600_ops = {
337 .inherits = &ahci_ops,
338 .softreset = ahci_sb600_softreset,
339 .pmp_softreset = ahci_sb600_softreset,
340};
341
332#define AHCI_HFLAGS(flags) .private_data = (void *)(flags) 342#define AHCI_HFLAGS(flags) .private_data = (void *)(flags)
333 343
334static const struct ata_port_info ahci_port_info[] = { 344static const struct ata_port_info ahci_port_info[] = {
@@ -359,11 +369,11 @@ static const struct ata_port_info ahci_port_info[] = {
359 { 369 {
360 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL | 370 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL |
361 AHCI_HFLAG_32BIT_ONLY | AHCI_HFLAG_NO_MSI | 371 AHCI_HFLAG_32BIT_ONLY | AHCI_HFLAG_NO_MSI |
362 AHCI_HFLAG_SECT255 | AHCI_HFLAG_NO_PMP), 372 AHCI_HFLAG_SECT255),
363 .flags = AHCI_FLAG_COMMON, 373 .flags = AHCI_FLAG_COMMON,
364 .pio_mask = 0x1f, /* pio0-4 */ 374 .pio_mask = 0x1f, /* pio0-4 */
365 .udma_mask = ATA_UDMA6, 375 .udma_mask = ATA_UDMA6,
366 .port_ops = &ahci_ops, 376 .port_ops = &ahci_sb600_ops,
367 }, 377 },
368 /* board_ahci_mv */ 378 /* board_ahci_mv */
369 { 379 {
@@ -377,8 +387,15 @@ static const struct ata_port_info ahci_port_info[] = {
377 }, 387 },
378 /* board_ahci_sb700 */ 388 /* board_ahci_sb700 */
379 { 389 {
380 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL | 390 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL),
381 AHCI_HFLAG_NO_PMP), 391 .flags = AHCI_FLAG_COMMON,
392 .pio_mask = 0x1f, /* pio0-4 */
393 .udma_mask = ATA_UDMA6,
394 .port_ops = &ahci_sb600_ops,
395 },
396 /* board_ahci_mcp65 */
397 {
398 AHCI_HFLAGS (AHCI_HFLAG_YES_NCQ),
382 .flags = AHCI_FLAG_COMMON, 399 .flags = AHCI_FLAG_COMMON,
383 .pio_mask = 0x1f, /* pio0-4 */ 400 .pio_mask = 0x1f, /* pio0-4 */
384 .udma_mask = ATA_UDMA6, 401 .udma_mask = ATA_UDMA6,
@@ -438,14 +455,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
438 { PCI_VDEVICE(VIA, 0x6287), board_ahci_vt8251 }, /* VIA VT8251 */ 455 { PCI_VDEVICE(VIA, 0x6287), board_ahci_vt8251 }, /* VIA VT8251 */
439 456
440 /* NVIDIA */ 457 /* NVIDIA */
441 { PCI_VDEVICE(NVIDIA, 0x044c), board_ahci }, /* MCP65 */ 458 { PCI_VDEVICE(NVIDIA, 0x044c), board_ahci_mcp65 }, /* MCP65 */
442 { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci }, /* MCP65 */ 459 { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci_mcp65 }, /* MCP65 */
443 { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci }, /* MCP65 */ 460 { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci_mcp65 }, /* MCP65 */
444 { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci }, /* MCP65 */ 461 { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci_mcp65 }, /* MCP65 */
445 { PCI_VDEVICE(NVIDIA, 0x045c), board_ahci }, /* MCP65 */ 462 { PCI_VDEVICE(NVIDIA, 0x045c), board_ahci_mcp65 }, /* MCP65 */
446 { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci }, /* MCP65 */ 463 { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci_mcp65 }, /* MCP65 */
447 { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci }, /* MCP65 */ 464 { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci_mcp65 }, /* MCP65 */
448 { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci }, /* MCP65 */ 465 { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci_mcp65 }, /* MCP65 */
449 { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci }, /* MCP67 */ 466 { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci }, /* MCP67 */
450 { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci }, /* MCP67 */ 467 { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci }, /* MCP67 */
451 { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci }, /* MCP67 */ 468 { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci }, /* MCP67 */
@@ -624,6 +641,12 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
624 cap &= ~HOST_CAP_NCQ; 641 cap &= ~HOST_CAP_NCQ;
625 } 642 }
626 643
644 if (!(cap & HOST_CAP_NCQ) && (hpriv->flags & AHCI_HFLAG_YES_NCQ)) {
645 dev_printk(KERN_INFO, &pdev->dev,
646 "controller can do NCQ, turning on CAP_NCQ\n");
647 cap |= HOST_CAP_NCQ;
648 }
649
627 if ((cap & HOST_CAP_PMP) && (hpriv->flags & AHCI_HFLAG_NO_PMP)) { 650 if ((cap & HOST_CAP_PMP) && (hpriv->flags & AHCI_HFLAG_NO_PMP)) {
628 dev_printk(KERN_INFO, &pdev->dev, 651 dev_printk(KERN_INFO, &pdev->dev,
629 "controller can't do PMP, turning off CAP_PMP\n"); 652 "controller can't do PMP, turning off CAP_PMP\n");
@@ -1262,19 +1285,11 @@ static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
1262 return 0; 1285 return 0;
1263} 1286}
1264 1287
1265static int ahci_check_ready(struct ata_link *link) 1288static int ahci_do_softreset(struct ata_link *link, unsigned int *class,
1266{ 1289 int pmp, unsigned long deadline,
1267 void __iomem *port_mmio = ahci_port_base(link->ap); 1290 int (*check_ready)(struct ata_link *link))
1268 u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
1269
1270 return ata_check_ready(status);
1271}
1272
1273static int ahci_softreset(struct ata_link *link, unsigned int *class,
1274 unsigned long deadline)
1275{ 1291{
1276 struct ata_port *ap = link->ap; 1292 struct ata_port *ap = link->ap;
1277 int pmp = sata_srst_pmp(link);
1278 const char *reason = NULL; 1293 const char *reason = NULL;
1279 unsigned long now, msecs; 1294 unsigned long now, msecs;
1280 struct ata_taskfile tf; 1295 struct ata_taskfile tf;
@@ -1312,7 +1327,7 @@ static int ahci_softreset(struct ata_link *link, unsigned int *class,
1312 ahci_exec_polled_cmd(ap, pmp, &tf, 0, 0, 0); 1327 ahci_exec_polled_cmd(ap, pmp, &tf, 0, 0, 0);
1313 1328
1314 /* wait for link to become ready */ 1329 /* wait for link to become ready */
1315 rc = ata_wait_after_reset(link, deadline, ahci_check_ready); 1330 rc = ata_wait_after_reset(link, deadline, check_ready);
1316 /* link occupied, -ENODEV too is an error */ 1331 /* link occupied, -ENODEV too is an error */
1317 if (rc) { 1332 if (rc) {
1318 reason = "device not ready"; 1333 reason = "device not ready";
@@ -1328,6 +1343,72 @@ static int ahci_softreset(struct ata_link *link, unsigned int *class,
1328 return rc; 1343 return rc;
1329} 1344}
1330 1345
1346static int ahci_check_ready(struct ata_link *link)
1347{
1348 void __iomem *port_mmio = ahci_port_base(link->ap);
1349 u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
1350
1351 return ata_check_ready(status);
1352}
1353
1354static int ahci_softreset(struct ata_link *link, unsigned int *class,
1355 unsigned long deadline)
1356{
1357 int pmp = sata_srst_pmp(link);
1358
1359 DPRINTK("ENTER\n");
1360
1361 return ahci_do_softreset(link, class, pmp, deadline, ahci_check_ready);
1362}
1363
1364static int ahci_sb600_check_ready(struct ata_link *link)
1365{
1366 void __iomem *port_mmio = ahci_port_base(link->ap);
1367 u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
1368 u32 irq_status = readl(port_mmio + PORT_IRQ_STAT);
1369
1370 /*
1371 * There is no need to check TFDATA if BAD PMP is found due to HW bug,
1372 * which can save timeout delay.
1373 */
1374 if (irq_status & PORT_IRQ_BAD_PMP)
1375 return -EIO;
1376
1377 return ata_check_ready(status);
1378}
1379
1380static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
1381 unsigned long deadline)
1382{
1383 struct ata_port *ap = link->ap;
1384 void __iomem *port_mmio = ahci_port_base(ap);
1385 int pmp = sata_srst_pmp(link);
1386 int rc;
1387 u32 irq_sts;
1388
1389 DPRINTK("ENTER\n");
1390
1391 rc = ahci_do_softreset(link, class, pmp, deadline,
1392 ahci_sb600_check_ready);
1393
1394 /*
1395 * Soft reset fails on some ATI chips with IPMS set when PMP
1396 * is enabled but SATA HDD/ODD is connected to SATA port,
1397 * do soft reset again to port 0.
1398 */
1399 if (rc == -EIO) {
1400 irq_sts = readl(port_mmio + PORT_IRQ_STAT);
1401 if (irq_sts & PORT_IRQ_BAD_PMP) {
1402 ata_link_printk(link, KERN_WARNING,
1403 "failed due to HW bug, retry pmp=0\n");
1404 rc = ahci_do_softreset(link, class, 0, deadline,
1405 ahci_check_ready);
1406 }
1407 }
1408
1409 return rc;
1410}
1411
1331static int ahci_hardreset(struct ata_link *link, unsigned int *class, 1412static int ahci_hardreset(struct ata_link *link, unsigned int *class,
1332 unsigned long deadline) 1413 unsigned long deadline)
1333{ 1414{
@@ -2118,7 +2199,8 @@ static void ahci_p5wdh_workaround(struct ata_host *host)
2118static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 2199static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2119{ 2200{
2120 static int printed_version; 2201 static int printed_version;
2121 struct ata_port_info pi = ahci_port_info[ent->driver_data]; 2202 unsigned int board_id = ent->driver_data;
2203 struct ata_port_info pi = ahci_port_info[board_id];
2122 const struct ata_port_info *ppi[] = { &pi, NULL }; 2204 const struct ata_port_info *ppi[] = { &pi, NULL };
2123 struct device *dev = &pdev->dev; 2205 struct device *dev = &pdev->dev;
2124 struct ahci_host_priv *hpriv; 2206 struct ahci_host_priv *hpriv;
@@ -2167,6 +2249,11 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2167 return -ENOMEM; 2249 return -ENOMEM;
2168 hpriv->flags |= (unsigned long)pi.private_data; 2250 hpriv->flags |= (unsigned long)pi.private_data;
2169 2251
2252 /* MCP65 revision A1 and A2 can't do MSI */
2253 if (board_id == board_ahci_mcp65 &&
2254 (pdev->revision == 0xa1 || pdev->revision == 0xa2))
2255 hpriv->flags |= AHCI_HFLAG_NO_MSI;
2256
2170 if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev)) 2257 if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev))
2171 pci_intx(pdev, 1); 2258 pci_intx(pdev, 1);
2172 2259
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 3548ee7014ca..81b7ae376951 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -574,6 +574,8 @@ static const struct ich_laptop ich_laptop[] = {
574 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 574 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
575 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */ 575 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
576 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */ 576 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on ACER Aspire 2023WLMi */
577 { 0x24CA, 0x1025, 0x003d }, /* ICH4 on ACER TM290 */
578 { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
577 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ 579 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
578 /* end marker */ 580 /* end marker */
579 { 0, } 581 { 0, }
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index dbf6ca781f66..3ff8b14420d9 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -118,12 +118,62 @@ static void ata_acpi_associate_ide_port(struct ata_port *ap)
118 ap->pflags |= ATA_PFLAG_INIT_GTM_VALID; 118 ap->pflags |= ATA_PFLAG_INIT_GTM_VALID;
119} 119}
120 120
121static void ata_acpi_handle_hotplug(struct ata_port *ap, struct ata_device 121static void ata_acpi_eject_device(acpi_handle handle)
122 *dev, u32 event) 122{
123 struct acpi_object_list arg_list;
124 union acpi_object arg;
125
126 arg_list.count = 1;
127 arg_list.pointer = &arg;
128 arg.type = ACPI_TYPE_INTEGER;
129 arg.integer.value = 1;
130
131 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_EJ0",
132 &arg_list, NULL)))
133 printk(KERN_ERR "Failed to evaluate _EJ0!\n");
134}
135
136/* @ap and @dev are the same as ata_acpi_handle_hotplug() */
137static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev)
138{
139 if (dev)
140 dev->flags |= ATA_DFLAG_DETACH;
141 else {
142 struct ata_link *tlink;
143 struct ata_device *tdev;
144
145 ata_port_for_each_link(tlink, ap)
146 ata_link_for_each_dev(tdev, tlink)
147 tdev->flags |= ATA_DFLAG_DETACH;
148 }
149
150 ata_port_schedule_eh(ap);
151}
152
153/**
154 * ata_acpi_handle_hotplug - ACPI event handler backend
155 * @ap: ATA port ACPI event occurred
156 * @dev: ATA device ACPI event occurred (can be NULL)
157 * @event: ACPI event which occurred
158 * @is_dock_event: boolean indicating whether the event was a dock one
159 *
160 * All ACPI bay / device realted events end up in this function. If
161 * the event is port-wide @dev is NULL. If the event is specific to a
162 * device, @dev points to it.
163 *
164 * Hotplug (as opposed to unplug) notification is always handled as
165 * port-wide while unplug only kills the target device on device-wide
166 * event.
167 *
168 * LOCKING:
169 * ACPI notify handler context. May sleep.
170 */
171static void ata_acpi_handle_hotplug(struct ata_port *ap, struct ata_device *dev,
172 u32 event, int is_dock_event)
123{ 173{
124 char event_string[12]; 174 char event_string[12];
125 char *envp[] = { event_string, NULL }; 175 char *envp[] = { event_string, NULL };
126 struct ata_eh_info *ehi; 176 struct ata_eh_info *ehi = &ap->link.eh_info;
127 struct kobject *kobj = NULL; 177 struct kobject *kobj = NULL;
128 int wait = 0; 178 int wait = 0;
129 unsigned long flags; 179 unsigned long flags;
@@ -131,87 +181,100 @@ static void ata_acpi_handle_hotplug(struct ata_port *ap, struct ata_device
131 unsigned long sta; 181 unsigned long sta;
132 acpi_status status; 182 acpi_status status;
133 183
134 if (!ap) 184 if (dev) {
135 ap = dev->link->ap; 185 if (dev->sdev)
136 ehi = &ap->link.eh_info; 186 kobj = &dev->sdev->sdev_gendev.kobj;
137
138 spin_lock_irqsave(ap->lock, flags);
139
140 if (dev)
141 handle = dev->acpi_handle; 187 handle = dev->acpi_handle;
142 else 188 } else {
189 kobj = &ap->dev->kobj;
143 handle = ap->acpi_handle; 190 handle = ap->acpi_handle;
191 }
144 192
145 status = acpi_get_handle(handle, "_EJ0", &tmphandle); 193 status = acpi_get_handle(handle, "_EJ0", &tmphandle);
146 if (ACPI_FAILURE(status)) { 194 if (ACPI_FAILURE(status))
147 /* This device is not ejectable */ 195 /* This device does not support hotplug */
148 spin_unlock_irqrestore(ap->lock, flags);
149 return; 196 return;
150 }
151 197
152 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 198 spin_lock_irqsave(ap->lock, flags);
153 if (ACPI_FAILURE(status)) {
154 printk ("Unable to determine bay status\n");
155 spin_unlock_irqrestore(ap->lock, flags);
156 return;
157 }
158 199
159 switch (event) { 200 switch (event) {
160 case ACPI_NOTIFY_BUS_CHECK: 201 case ACPI_NOTIFY_BUS_CHECK:
161 case ACPI_NOTIFY_DEVICE_CHECK: 202 case ACPI_NOTIFY_DEVICE_CHECK:
162 ata_ehi_push_desc(ehi, "ACPI event"); 203 ata_ehi_push_desc(ehi, "ACPI event");
163 if (!sta) { 204
164 /* Device has been unplugged */ 205 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
165 if (dev) 206 if (ACPI_FAILURE(status)) {
166 dev->flags |= ATA_DFLAG_DETACH; 207 ata_port_printk(ap, KERN_ERR,
167 else { 208 "acpi: failed to determine bay status (0x%x)\n",
168 struct ata_link *tlink; 209 status);
169 struct ata_device *tdev; 210 break;
170 211 }
171 ata_port_for_each_link(tlink, ap) { 212
172 ata_link_for_each_dev(tdev, tlink) { 213 if (sta) {
173 tdev->flags |=
174 ATA_DFLAG_DETACH;
175 }
176 }
177 }
178 ata_port_schedule_eh(ap);
179 wait = 1;
180 } else {
181 ata_ehi_hotplugged(ehi); 214 ata_ehi_hotplugged(ehi);
182 ata_port_freeze(ap); 215 ata_port_freeze(ap);
216 } else {
217 /* The device has gone - unplug it */
218 ata_acpi_detach_device(ap, dev);
219 wait = 1;
183 } 220 }
221 break;
222 case ACPI_NOTIFY_EJECT_REQUEST:
223 ata_ehi_push_desc(ehi, "ACPI event");
224
225 if (!is_dock_event)
226 break;
227
228 /* undock event - immediate unplug */
229 ata_acpi_detach_device(ap, dev);
230 wait = 1;
231 break;
184 } 232 }
185 233
234 /* make sure kobj doesn't go away while ap->lock is released */
235 kobject_get(kobj);
236
186 spin_unlock_irqrestore(ap->lock, flags); 237 spin_unlock_irqrestore(ap->lock, flags);
187 238
188 if (wait) 239 if (wait) {
189 ata_port_wait_eh(ap); 240 ata_port_wait_eh(ap);
241 ata_acpi_eject_device(handle);
242 }
190 243
191 if (dev) { 244 if (kobj && !is_dock_event) {
192 if (dev->sdev)
193 kobj = &dev->sdev->sdev_gendev.kobj;
194 } else
195 kobj = &ap->dev->kobj;
196
197 if (kobj) {
198 sprintf(event_string, "BAY_EVENT=%d", event); 245 sprintf(event_string, "BAY_EVENT=%d", event);
199 kobject_uevent_env(kobj, KOBJ_CHANGE, envp); 246 kobject_uevent_env(kobj, KOBJ_CHANGE, envp);
200 } 247 }
248
249 kobject_put(kobj);
250}
251
252static void ata_acpi_dev_notify_dock(acpi_handle handle, u32 event, void *data)
253{
254 struct ata_device *dev = data;
255
256 ata_acpi_handle_hotplug(dev->link->ap, dev, event, 1);
257}
258
259static void ata_acpi_ap_notify_dock(acpi_handle handle, u32 event, void *data)
260{
261 struct ata_port *ap = data;
262
263 ata_acpi_handle_hotplug(ap, NULL, event, 1);
201} 264}
202 265
203static void ata_acpi_dev_notify(acpi_handle handle, u32 event, void *data) 266static void ata_acpi_dev_notify(acpi_handle handle, u32 event, void *data)
204{ 267{
205 struct ata_device *dev = data; 268 struct ata_device *dev = data;
206 269
207 ata_acpi_handle_hotplug(NULL, dev, event); 270 ata_acpi_handle_hotplug(dev->link->ap, dev, event, 0);
208} 271}
209 272
210static void ata_acpi_ap_notify(acpi_handle handle, u32 event, void *data) 273static void ata_acpi_ap_notify(acpi_handle handle, u32 event, void *data)
211{ 274{
212 struct ata_port *ap = data; 275 struct ata_port *ap = data;
213 276
214 ata_acpi_handle_hotplug(ap, NULL, event); 277 ata_acpi_handle_hotplug(ap, NULL, event, 0);
215} 278}
216 279
217/** 280/**
@@ -252,7 +315,7 @@ void ata_acpi_associate(struct ata_host *host)
252 ata_acpi_ap_notify, ap); 315 ata_acpi_ap_notify, ap);
253 /* we might be on a docking station */ 316 /* we might be on a docking station */
254 register_hotplug_dock_device(ap->acpi_handle, 317 register_hotplug_dock_device(ap->acpi_handle,
255 ata_acpi_ap_notify, ap); 318 ata_acpi_ap_notify_dock, ap);
256 } 319 }
257 320
258 for (j = 0; j < ata_link_max_devices(&ap->link); j++) { 321 for (j = 0; j < ata_link_max_devices(&ap->link); j++) {
@@ -264,7 +327,7 @@ void ata_acpi_associate(struct ata_host *host)
264 ata_acpi_dev_notify, dev); 327 ata_acpi_dev_notify, dev);
265 /* we might be on a docking station */ 328 /* we might be on a docking station */
266 register_hotplug_dock_device(dev->acpi_handle, 329 register_hotplug_dock_device(dev->acpi_handle,
267 ata_acpi_dev_notify, dev); 330 ata_acpi_dev_notify_dock, dev);
268 } 331 }
269 } 332 }
270 } 333 }
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 3c2d2289f85e..215d18672a5a 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -247,7 +247,7 @@ u8 ata_sff_check_status(struct ata_port *ap)
247 * LOCKING: 247 * LOCKING:
248 * Inherited from caller. 248 * Inherited from caller.
249 */ 249 */
250u8 ata_sff_altstatus(struct ata_port *ap) 250static u8 ata_sff_altstatus(struct ata_port *ap)
251{ 251{
252 if (ap->ops->sff_check_altstatus) 252 if (ap->ops->sff_check_altstatus)
253 return ap->ops->sff_check_altstatus(ap); 253 return ap->ops->sff_check_altstatus(ap);
@@ -256,6 +256,93 @@ u8 ata_sff_altstatus(struct ata_port *ap)
256} 256}
257 257
258/** 258/**
259 * ata_sff_irq_status - Check if the device is busy
260 * @ap: port where the device is
261 *
262 * Determine if the port is currently busy. Uses altstatus
263 * if available in order to avoid clearing shared IRQ status
264 * when finding an IRQ source. Non ctl capable devices don't
265 * share interrupt lines fortunately for us.
266 *
267 * LOCKING:
268 * Inherited from caller.
269 */
270static u8 ata_sff_irq_status(struct ata_port *ap)
271{
272 u8 status;
273
274 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) {
275 status = ata_sff_altstatus(ap);
276 /* Not us: We are busy */
277 if (status & ATA_BUSY)
278 return status;
279 }
280 /* Clear INTRQ latch */
281 status = ap->ops->sff_check_status(ap);
282 return status;
283}
284
285/**
286 * ata_sff_sync - Flush writes
287 * @ap: Port to wait for.
288 *
289 * CAUTION:
290 * If we have an mmio device with no ctl and no altstatus
291 * method this will fail. No such devices are known to exist.
292 *
293 * LOCKING:
294 * Inherited from caller.
295 */
296
297static void ata_sff_sync(struct ata_port *ap)
298{
299 if (ap->ops->sff_check_altstatus)
300 ap->ops->sff_check_altstatus(ap);
301 else if (ap->ioaddr.altstatus_addr)
302 ioread8(ap->ioaddr.altstatus_addr);
303}
304
305/**
306 * ata_sff_pause - Flush writes and wait 400nS
307 * @ap: Port to pause for.
308 *
309 * CAUTION:
310 * If we have an mmio device with no ctl and no altstatus
311 * method this will fail. No such devices are known to exist.
312 *
313 * LOCKING:
314 * Inherited from caller.
315 */
316
317void ata_sff_pause(struct ata_port *ap)
318{
319 ata_sff_sync(ap);
320 ndelay(400);
321}
322
323/**
324 * ata_sff_dma_pause - Pause before commencing DMA
325 * @ap: Port to pause for.
326 *
327 * Perform I/O fencing and ensure sufficient cycle delays occur
328 * for the HDMA1:0 transition
329 */
330
331void ata_sff_dma_pause(struct ata_port *ap)
332{
333 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) {
334 /* An altstatus read will cause the needed delay without
335 messing up the IRQ status */
336 ata_sff_altstatus(ap);
337 return;
338 }
339 /* There are no DMA controllers without ctl. BUG here to ensure
340 we never violate the HDMA1:0 transition timing and risk
341 corruption. */
342 BUG();
343}
344
345/**
259 * ata_sff_busy_sleep - sleep until BSY clears, or timeout 346 * ata_sff_busy_sleep - sleep until BSY clears, or timeout
260 * @ap: port containing status register to be polled 347 * @ap: port containing status register to be polled
261 * @tmout_pat: impatience timeout 348 * @tmout_pat: impatience timeout
@@ -742,7 +829,7 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc)
742 } else 829 } else
743 ata_pio_sector(qc); 830 ata_pio_sector(qc);
744 831
745 ata_sff_altstatus(qc->ap); /* flush */ 832 ata_sff_sync(qc->ap); /* flush */
746} 833}
747 834
748/** 835/**
@@ -763,8 +850,9 @@ static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
763 WARN_ON(qc->dev->cdb_len < 12); 850 WARN_ON(qc->dev->cdb_len < 12);
764 851
765 ap->ops->sff_data_xfer(qc->dev, qc->cdb, qc->dev->cdb_len, 1); 852 ap->ops->sff_data_xfer(qc->dev, qc->cdb, qc->dev->cdb_len, 1);
766 ata_sff_altstatus(ap); /* flush */ 853 ata_sff_sync(ap);
767 854 /* FIXME: If the CDB is for DMA do we need to do the transition delay
855 or is bmdma_start guaranteed to do it ? */
768 switch (qc->tf.protocol) { 856 switch (qc->tf.protocol) {
769 case ATAPI_PROT_PIO: 857 case ATAPI_PROT_PIO:
770 ap->hsm_task_state = HSM_ST; 858 ap->hsm_task_state = HSM_ST;
@@ -905,7 +993,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
905 993
906 if (unlikely(__atapi_pio_bytes(qc, bytes))) 994 if (unlikely(__atapi_pio_bytes(qc, bytes)))
907 goto err_out; 995 goto err_out;
908 ata_sff_altstatus(ap); /* flush */ 996 ata_sff_sync(ap); /* flush */
909 997
910 return; 998 return;
911 999
@@ -1489,14 +1577,10 @@ inline unsigned int ata_sff_host_intr(struct ata_port *ap,
1489 goto idle_irq; 1577 goto idle_irq;
1490 } 1578 }
1491 1579
1492 /* check altstatus */
1493 status = ata_sff_altstatus(ap);
1494 if (status & ATA_BUSY)
1495 goto idle_irq;
1496 1580
1497 /* check main status, clearing INTRQ */ 1581 /* check main status, clearing INTRQ if needed */
1498 status = ap->ops->sff_check_status(ap); 1582 status = ata_sff_irq_status(ap);
1499 if (unlikely(status & ATA_BUSY)) 1583 if (status & ATA_BUSY)
1500 goto idle_irq; 1584 goto idle_irq;
1501 1585
1502 /* ack bmdma irq events */ 1586 /* ack bmdma irq events */
@@ -2030,7 +2114,7 @@ void ata_sff_error_handler(struct ata_port *ap)
2030 ap->ops->bmdma_stop(qc); 2114 ap->ops->bmdma_stop(qc);
2031 } 2115 }
2032 2116
2033 ata_sff_altstatus(ap); 2117 ata_sff_sync(ap); /* FIXME: We don't need this */
2034 ap->ops->sff_check_status(ap); 2118 ap->ops->sff_check_status(ap);
2035 ap->ops->sff_irq_clear(ap); 2119 ap->ops->sff_irq_clear(ap);
2036 2120
@@ -2203,7 +2287,7 @@ void ata_bmdma_stop(struct ata_queued_cmd *qc)
2203 mmio + ATA_DMA_CMD); 2287 mmio + ATA_DMA_CMD);
2204 2288
2205 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ 2289 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
2206 ata_sff_altstatus(ap); /* dummy read */ 2290 ata_sff_dma_pause(ap);
2207} 2291}
2208 2292
2209/** 2293/**
@@ -2722,7 +2806,8 @@ EXPORT_SYMBOL_GPL(ata_sff_qc_prep);
2722EXPORT_SYMBOL_GPL(ata_sff_dumb_qc_prep); 2806EXPORT_SYMBOL_GPL(ata_sff_dumb_qc_prep);
2723EXPORT_SYMBOL_GPL(ata_sff_dev_select); 2807EXPORT_SYMBOL_GPL(ata_sff_dev_select);
2724EXPORT_SYMBOL_GPL(ata_sff_check_status); 2808EXPORT_SYMBOL_GPL(ata_sff_check_status);
2725EXPORT_SYMBOL_GPL(ata_sff_altstatus); 2809EXPORT_SYMBOL_GPL(ata_sff_dma_pause);
2810EXPORT_SYMBOL_GPL(ata_sff_pause);
2726EXPORT_SYMBOL_GPL(ata_sff_busy_sleep); 2811EXPORT_SYMBOL_GPL(ata_sff_busy_sleep);
2727EXPORT_SYMBOL_GPL(ata_sff_wait_ready); 2812EXPORT_SYMBOL_GPL(ata_sff_wait_ready);
2728EXPORT_SYMBOL_GPL(ata_sff_tf_load); 2813EXPORT_SYMBOL_GPL(ata_sff_tf_load);
diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
index 17138436423d..cf9e9848f8b5 100644
--- a/drivers/ata/pata_icside.c
+++ b/drivers/ata/pata_icside.c
@@ -270,7 +270,7 @@ static void pata_icside_bmdma_stop(struct ata_queued_cmd *qc)
270 disable_dma(state->dma); 270 disable_dma(state->dma);
271 271
272 /* see ata_bmdma_stop */ 272 /* see ata_bmdma_stop */
273 ata_sff_altstatus(ap); 273 ata_sff_dma_pause(ap);
274} 274}
275 275
276static u8 pata_icside_bmdma_status(struct ata_port *ap) 276static u8 pata_icside_bmdma_status(struct ata_port *ap)
diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c
index a108d259f19d..f8b3ffc8ae9e 100644
--- a/drivers/ata/pata_rb532_cf.c
+++ b/drivers/ata/pata_rb532_cf.c
@@ -57,7 +57,9 @@ static inline void rb532_pata_finish_io(struct ata_port *ap)
57 struct ata_host *ah = ap->host; 57 struct ata_host *ah = ap->host;
58 struct rb532_cf_info *info = ah->private_data; 58 struct rb532_cf_info *info = ah->private_data;
59 59
60 ata_sff_altstatus(ap); 60 /* FIXME: Keep previous delay. If this is merely a fence then
61 ata_sff_sync might be sufficient. */
62 ata_sff_dma_pause(ap);
61 ndelay(RB500_CF_IO_DELAY); 63 ndelay(RB500_CF_IO_DELAY);
62 64
63 set_irq_type(info->irq, IRQ_TYPE_LEVEL_HIGH); 65 set_irq_type(info->irq, IRQ_TYPE_LEVEL_HIGH);
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index e965b251ca24..bbf5aa345e68 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -726,7 +726,7 @@ static void scc_bmdma_stop (struct ata_queued_cmd *qc)
726 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START); 726 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
727 727
728 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ 728 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
729 ata_sff_altstatus(ap); /* dummy read */ 729 ata_sff_dma_pause(ap); /* dummy read */
730} 730}
731 731
732/** 732/**
@@ -747,7 +747,8 @@ static u8 scc_bmdma_status (struct ata_port *ap)
747 return host_stat; 747 return host_stat;
748 748
749 /* errata A252,A308 workaround: Step4 */ 749 /* errata A252,A308 workaround: Step4 */
750 if ((ata_sff_altstatus(ap) & ATA_ERR) && (int_status & INTSTS_INTRQ)) 750 if ((scc_check_altstatus(ap) & ATA_ERR)
751 && (int_status & INTSTS_INTRQ))
751 return (host_stat | ATA_DMA_INTR); 752 return (host_stat | ATA_DMA_INTR);
752 753
753 /* errata A308 workaround Step5 */ 754 /* errata A308 workaround Step5 */
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index acf347f71a2f..60391e9a84db 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -224,6 +224,11 @@ enum {
224 224
225 PHY_MODE3 = 0x310, 225 PHY_MODE3 = 0x310,
226 PHY_MODE4 = 0x314, 226 PHY_MODE4 = 0x314,
227 PHY_MODE4_CFG_MASK = 0x00000003, /* phy internal config field */
228 PHY_MODE4_CFG_VALUE = 0x00000001, /* phy internal config field */
229 PHY_MODE4_RSVD_ZEROS = 0x5de3fffa, /* Gen2e always write zeros */
230 PHY_MODE4_RSVD_ONES = 0x00000005, /* Gen2e always write ones */
231
227 PHY_MODE2 = 0x330, 232 PHY_MODE2 = 0x330,
228 SATA_IFCTL_OFS = 0x344, 233 SATA_IFCTL_OFS = 0x344,
229 SATA_TESTCTL_OFS = 0x348, 234 SATA_TESTCTL_OFS = 0x348,
@@ -2563,17 +2568,16 @@ static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
2563 m3 &= ~0x1c; 2568 m3 &= ~0x1c;
2564 2569
2565 if (fix_phy_mode4) { 2570 if (fix_phy_mode4) {
2566 u32 m4; 2571 u32 m4 = readl(port_mmio + PHY_MODE4);
2567 2572 /*
2568 m4 = readl(port_mmio + PHY_MODE4); 2573 * Enforce reserved-bit restrictions on GenIIe devices only.
2569 2574 * For earlier chipsets, force only the internal config field
2570 /* workaround for errata FEr SATA#10 (part 1) */ 2575 * (workaround for errata FEr SATA#10 part 1).
2571 m4 = (m4 & ~(1 << 1)) | (1 << 0); 2576 */
2572
2573 /* enforce bit restrictions on GenIIe devices */
2574 if (IS_GEN_IIE(hpriv)) 2577 if (IS_GEN_IIE(hpriv))
2575 m4 = (m4 & ~0x5DE3FFFC) | (1 << 2); 2578 m4 = (m4 & ~PHY_MODE4_RSVD_ZEROS) | PHY_MODE4_RSVD_ONES;
2576 2579 else
2580 m4 = (m4 & ~PHY_MODE4_CFG_MASK) | PHY_MODE4_CFG_VALUE;
2577 writel(m4, port_mmio + PHY_MODE4); 2581 writel(m4, port_mmio + PHY_MODE4);
2578 } 2582 }
2579 /* 2583 /*