aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-07-06 13:07:32 -0400
committerJeff Garzik <jeff@garzik.org>2006-07-06 13:07:32 -0400
commit70f05366b71c51c35c25c0b76b4318fbc26c975a (patch)
treed31230b93ba7df50d87eb11b1dba091641a9b89e /drivers
parentc0bc8721b8d0380ec69fa97578c91201201b05a9 (diff)
parent120bda20c6f64b32e8bfbdd7b34feafaa5f5332e (diff)
Merge branch 'master' into upstream
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/ahci.c17
-rw-r--r--drivers/scsi/libata-core.c289
-rw-r--r--drivers/scsi/libata-eh.c405
-rw-r--r--drivers/scsi/libata-scsi.c124
-rw-r--r--drivers/scsi/sata_sil.c105
-rw-r--r--drivers/scsi/sata_sil24.c134
-rw-r--r--drivers/scsi/sata_vsc.c2
-rw-r--r--drivers/serial/at91_serial.c5
8 files changed, 829 insertions, 252 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 15f6cd4279b7..77e7202a0eba 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -1052,7 +1052,7 @@ static void ahci_thaw(struct ata_port *ap)
1052 1052
1053static void ahci_error_handler(struct ata_port *ap) 1053static void ahci_error_handler(struct ata_port *ap)
1054{ 1054{
1055 if (!(ap->flags & ATA_FLAG_FROZEN)) { 1055 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
1056 /* restart engine */ 1056 /* restart engine */
1057 ahci_stop_engine(ap); 1057 ahci_stop_engine(ap);
1058 ahci_start_engine(ap); 1058 ahci_start_engine(ap);
@@ -1323,6 +1323,17 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1323 if (!printed_version++) 1323 if (!printed_version++)
1324 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1324 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1325 1325
1326 /* JMicron-specific fixup: make sure we're in AHCI mode */
1327 /* This is protected from races with ata_jmicron by the pci probe
1328 locking */
1329 if (pdev->vendor == PCI_VENDOR_ID_JMICRON) {
1330 /* AHCI enable, AHCI on function 0 */
1331 pci_write_config_byte(pdev, 0x41, 0xa1);
1332 /* Function 1 is the PATA controller */
1333 if (PCI_FUNC(pdev->devfn))
1334 return -ENODEV;
1335 }
1336
1326 rc = pci_enable_device(pdev); 1337 rc = pci_enable_device(pdev);
1327 if (rc) 1338 if (rc)
1328 return rc; 1339 return rc;
@@ -1378,10 +1389,6 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1378 if (have_msi) 1389 if (have_msi)
1379 hpriv->flags |= AHCI_FLAG_MSI; 1390 hpriv->flags |= AHCI_FLAG_MSI;
1380 1391
1381 /* JMicron-specific fixup: make sure we're in AHCI mode */
1382 if (pdev->vendor == 0x197b)
1383 pci_write_config_byte(pdev, 0x41, 0xa1);
1384
1385 /* initialize adapter */ 1392 /* initialize adapter */
1386 rc = ahci_host_init(probe_ent); 1393 rc = ahci_host_init(probe_ent);
1387 if (rc) 1394 if (rc)
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 1c960ac1617f..386e5f21e191 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -61,9 +61,9 @@
61#include "libata.h" 61#include "libata.h"
62 62
63/* debounce timing parameters in msecs { interval, duration, timeout } */ 63/* debounce timing parameters in msecs { interval, duration, timeout } */
64const unsigned long sata_deb_timing_boot[] = { 5, 100, 2000 }; 64const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 };
65const unsigned long sata_deb_timing_eh[] = { 25, 500, 2000 }; 65const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 };
66const unsigned long sata_deb_timing_before_fsrst[] = { 100, 2000, 5000 }; 66const unsigned long sata_deb_timing_long[] = { 100, 2000, 5000 };
67 67
68static unsigned int ata_dev_init_params(struct ata_device *dev, 68static unsigned int ata_dev_init_params(struct ata_device *dev,
69 u16 heads, u16 sectors); 69 u16 heads, u16 sectors);
@@ -907,7 +907,7 @@ void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
907{ 907{
908 int rc; 908 int rc;
909 909
910 if (ap->flags & ATA_FLAG_FLUSH_PORT_TASK) 910 if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK)
911 return; 911 return;
912 912
913 PREPARE_WORK(&ap->port_task, fn, data); 913 PREPARE_WORK(&ap->port_task, fn, data);
@@ -938,7 +938,7 @@ void ata_port_flush_task(struct ata_port *ap)
938 DPRINTK("ENTER\n"); 938 DPRINTK("ENTER\n");
939 939
940 spin_lock_irqsave(ap->lock, flags); 940 spin_lock_irqsave(ap->lock, flags);
941 ap->flags |= ATA_FLAG_FLUSH_PORT_TASK; 941 ap->pflags |= ATA_PFLAG_FLUSH_PORT_TASK;
942 spin_unlock_irqrestore(ap->lock, flags); 942 spin_unlock_irqrestore(ap->lock, flags);
943 943
944 DPRINTK("flush #1\n"); 944 DPRINTK("flush #1\n");
@@ -957,7 +957,7 @@ void ata_port_flush_task(struct ata_port *ap)
957 } 957 }
958 958
959 spin_lock_irqsave(ap->lock, flags); 959 spin_lock_irqsave(ap->lock, flags);
960 ap->flags &= ~ATA_FLAG_FLUSH_PORT_TASK; 960 ap->pflags &= ~ATA_PFLAG_FLUSH_PORT_TASK;
961 spin_unlock_irqrestore(ap->lock, flags); 961 spin_unlock_irqrestore(ap->lock, flags);
962 962
963 if (ata_msg_ctl(ap)) 963 if (ata_msg_ctl(ap))
@@ -1009,7 +1009,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
1009 spin_lock_irqsave(ap->lock, flags); 1009 spin_lock_irqsave(ap->lock, flags);
1010 1010
1011 /* no internal command while frozen */ 1011 /* no internal command while frozen */
1012 if (ap->flags & ATA_FLAG_FROZEN) { 1012 if (ap->pflags & ATA_PFLAG_FROZEN) {
1013 spin_unlock_irqrestore(ap->lock, flags); 1013 spin_unlock_irqrestore(ap->lock, flags);
1014 return AC_ERR_SYSTEM; 1014 return AC_ERR_SYSTEM;
1015 } 1015 }
@@ -1325,6 +1325,19 @@ static void ata_dev_config_ncq(struct ata_device *dev,
1325 snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth); 1325 snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth);
1326} 1326}
1327 1327
1328static void ata_set_port_max_cmd_len(struct ata_port *ap)
1329{
1330 int i;
1331
1332 if (ap->host) {
1333 ap->host->max_cmd_len = 0;
1334 for (i = 0; i < ATA_MAX_DEVICES; i++)
1335 ap->host->max_cmd_len = max_t(unsigned int,
1336 ap->host->max_cmd_len,
1337 ap->device[i].cdb_len);
1338 }
1339}
1340
1328/** 1341/**
1329 * ata_dev_configure - Configure the specified ATA/ATAPI device 1342 * ata_dev_configure - Configure the specified ATA/ATAPI device
1330 * @dev: Target device to configure 1343 * @dev: Target device to configure
@@ -1344,7 +1357,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1344 struct ata_port *ap = dev->ap; 1357 struct ata_port *ap = dev->ap;
1345 const u16 *id = dev->id; 1358 const u16 *id = dev->id;
1346 unsigned int xfer_mask; 1359 unsigned int xfer_mask;
1347 int i, rc; 1360 int rc;
1348 1361
1349 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) { 1362 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
1350 ata_dev_printk(dev, KERN_INFO, 1363 ata_dev_printk(dev, KERN_INFO,
@@ -1404,7 +1417,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1404 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); 1417 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
1405 1418
1406 /* print device info to dmesg */ 1419 /* print device info to dmesg */
1407 if (ata_msg_info(ap)) 1420 if (ata_msg_drv(ap) && print_info)
1408 ata_dev_printk(dev, KERN_INFO, "ATA-%d, " 1421 ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
1409 "max %s, %Lu sectors: %s %s\n", 1422 "max %s, %Lu sectors: %s %s\n",
1410 ata_id_major_version(id), 1423 ata_id_major_version(id),
@@ -1427,7 +1440,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1427 } 1440 }
1428 1441
1429 /* print device info to dmesg */ 1442 /* print device info to dmesg */
1430 if (ata_msg_info(ap)) 1443 if (ata_msg_drv(ap) && print_info)
1431 ata_dev_printk(dev, KERN_INFO, "ATA-%d, " 1444 ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
1432 "max %s, %Lu sectors: CHS %u/%u/%u\n", 1445 "max %s, %Lu sectors: CHS %u/%u/%u\n",
1433 ata_id_major_version(id), 1446 ata_id_major_version(id),
@@ -1439,7 +1452,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1439 1452
1440 if (dev->id[59] & 0x100) { 1453 if (dev->id[59] & 0x100) {
1441 dev->multi_count = dev->id[59] & 0xff; 1454 dev->multi_count = dev->id[59] & 0xff;
1442 if (ata_msg_info(ap)) 1455 if (ata_msg_drv(ap) && print_info)
1443 ata_dev_printk(dev, KERN_INFO, 1456 ata_dev_printk(dev, KERN_INFO,
1444 "ata%u: dev %u multi count %u\n", 1457 "ata%u: dev %u multi count %u\n",
1445 ap->id, dev->devno, dev->multi_count); 1458 ap->id, dev->devno, dev->multi_count);
@@ -1468,21 +1481,17 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
1468 } 1481 }
1469 1482
1470 /* print device info to dmesg */ 1483 /* print device info to dmesg */
1471 if (ata_msg_info(ap)) 1484 if (ata_msg_drv(ap) && print_info)
1472 ata_dev_printk(dev, KERN_INFO, "ATAPI, max %s%s\n", 1485 ata_dev_printk(dev, KERN_INFO, "ATAPI, max %s%s\n",
1473 ata_mode_string(xfer_mask), 1486 ata_mode_string(xfer_mask),
1474 cdb_intr_string); 1487 cdb_intr_string);
1475 } 1488 }
1476 1489
1477 ap->host->max_cmd_len = 0; 1490 ata_set_port_max_cmd_len(ap);
1478 for (i = 0; i < ATA_MAX_DEVICES; i++)
1479 ap->host->max_cmd_len = max_t(unsigned int,
1480 ap->host->max_cmd_len,
1481 ap->device[i].cdb_len);
1482 1491
1483 /* limit bridge transfers to udma5, 200 sectors */ 1492 /* limit bridge transfers to udma5, 200 sectors */
1484 if (ata_dev_knobble(dev)) { 1493 if (ata_dev_knobble(dev)) {
1485 if (ata_msg_info(ap)) 1494 if (ata_msg_drv(ap) && print_info)
1486 ata_dev_printk(dev, KERN_INFO, 1495 ata_dev_printk(dev, KERN_INFO,
1487 "applying bridge limits\n"); 1496 "applying bridge limits\n");
1488 dev->udma_mask &= ATA_UDMA5; 1497 dev->udma_mask &= ATA_UDMA5;
@@ -2137,7 +2146,7 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2137 * return error code and failing device on failure. 2146 * return error code and failing device on failure.
2138 */ 2147 */
2139 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2148 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2140 if (ata_dev_enabled(&ap->device[i])) { 2149 if (ata_dev_ready(&ap->device[i])) {
2141 ap->ops->set_mode(ap); 2150 ap->ops->set_mode(ap);
2142 break; 2151 break;
2143 } 2152 }
@@ -2203,7 +2212,8 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2203 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2212 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2204 dev = &ap->device[i]; 2213 dev = &ap->device[i];
2205 2214
2206 if (!ata_dev_enabled(dev)) 2215 /* don't udpate suspended devices' xfer mode */
2216 if (!ata_dev_ready(dev))
2207 continue; 2217 continue;
2208 2218
2209 rc = ata_dev_set_mode(dev); 2219 rc = ata_dev_set_mode(dev);
@@ -2579,7 +2589,7 @@ static void ata_wait_spinup(struct ata_port *ap)
2579 2589
2580 /* first, debounce phy if SATA */ 2590 /* first, debounce phy if SATA */
2581 if (ap->cbl == ATA_CBL_SATA) { 2591 if (ap->cbl == ATA_CBL_SATA) {
2582 rc = sata_phy_debounce(ap, sata_deb_timing_eh); 2592 rc = sata_phy_debounce(ap, sata_deb_timing_hotplug);
2583 2593
2584 /* if debounced successfully and offline, no need to wait */ 2594 /* if debounced successfully and offline, no need to wait */
2585 if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap)) 2595 if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap))
@@ -2615,16 +2625,17 @@ static void ata_wait_spinup(struct ata_port *ap)
2615int ata_std_prereset(struct ata_port *ap) 2625int ata_std_prereset(struct ata_port *ap)
2616{ 2626{
2617 struct ata_eh_context *ehc = &ap->eh_context; 2627 struct ata_eh_context *ehc = &ap->eh_context;
2618 const unsigned long *timing; 2628 const unsigned long *timing = sata_ehc_deb_timing(ehc);
2619 int rc; 2629 int rc;
2620 2630
2621 /* hotplug? */ 2631 /* handle link resume & hotplug spinup */
2622 if (ehc->i.flags & ATA_EHI_HOTPLUGGED) { 2632 if ((ehc->i.flags & ATA_EHI_RESUME_LINK) &&
2623 if (ap->flags & ATA_FLAG_HRST_TO_RESUME) 2633 (ap->flags & ATA_FLAG_HRST_TO_RESUME))
2624 ehc->i.action |= ATA_EH_HARDRESET; 2634 ehc->i.action |= ATA_EH_HARDRESET;
2625 if (ap->flags & ATA_FLAG_SKIP_D2H_BSY) 2635
2626 ata_wait_spinup(ap); 2636 if ((ehc->i.flags & ATA_EHI_HOTPLUGGED) &&
2627 } 2637 (ap->flags & ATA_FLAG_SKIP_D2H_BSY))
2638 ata_wait_spinup(ap);
2628 2639
2629 /* if we're about to do hardreset, nothing more to do */ 2640 /* if we're about to do hardreset, nothing more to do */
2630 if (ehc->i.action & ATA_EH_HARDRESET) 2641 if (ehc->i.action & ATA_EH_HARDRESET)
@@ -2632,11 +2643,6 @@ int ata_std_prereset(struct ata_port *ap)
2632 2643
2633 /* if SATA, resume phy */ 2644 /* if SATA, resume phy */
2634 if (ap->cbl == ATA_CBL_SATA) { 2645 if (ap->cbl == ATA_CBL_SATA) {
2635 if (ap->flags & ATA_FLAG_LOADING)
2636 timing = sata_deb_timing_boot;
2637 else
2638 timing = sata_deb_timing_eh;
2639
2640 rc = sata_phy_resume(ap, timing); 2646 rc = sata_phy_resume(ap, timing);
2641 if (rc && rc != -EOPNOTSUPP) { 2647 if (rc && rc != -EOPNOTSUPP) {
2642 /* phy resume failed */ 2648 /* phy resume failed */
@@ -2724,6 +2730,8 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
2724 */ 2730 */
2725int sata_std_hardreset(struct ata_port *ap, unsigned int *class) 2731int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2726{ 2732{
2733 struct ata_eh_context *ehc = &ap->eh_context;
2734 const unsigned long *timing = sata_ehc_deb_timing(ehc);
2727 u32 scontrol; 2735 u32 scontrol;
2728 int rc; 2736 int rc;
2729 2737
@@ -2761,7 +2769,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2761 msleep(1); 2769 msleep(1);
2762 2770
2763 /* bring phy back */ 2771 /* bring phy back */
2764 sata_phy_resume(ap, sata_deb_timing_eh); 2772 sata_phy_resume(ap, timing);
2765 2773
2766 /* TODO: phy layer with polling, timeouts, etc. */ 2774 /* TODO: phy layer with polling, timeouts, etc. */
2767 if (ata_port_offline(ap)) { 2775 if (ata_port_offline(ap)) {
@@ -4285,7 +4293,7 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
4285 unsigned int i; 4293 unsigned int i;
4286 4294
4287 /* no command while frozen */ 4295 /* no command while frozen */
4288 if (unlikely(ap->flags & ATA_FLAG_FROZEN)) 4296 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4289 return NULL; 4297 return NULL;
4290 4298
4291 /* the last tag is reserved for internal command. */ 4299 /* the last tag is reserved for internal command. */
@@ -4407,7 +4415,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
4407 * taken care of. 4415 * taken care of.
4408 */ 4416 */
4409 if (ap->ops->error_handler) { 4417 if (ap->ops->error_handler) {
4410 WARN_ON(ap->flags & ATA_FLAG_FROZEN); 4418 WARN_ON(ap->pflags & ATA_PFLAG_FROZEN);
4411 4419
4412 if (unlikely(qc->err_mask)) 4420 if (unlikely(qc->err_mask))
4413 qc->flags |= ATA_QCFLAG_FAILED; 4421 qc->flags |= ATA_QCFLAG_FAILED;
@@ -5001,86 +5009,120 @@ int ata_flush_cache(struct ata_device *dev)
5001 return 0; 5009 return 0;
5002} 5010}
5003 5011
5004static int ata_standby_drive(struct ata_device *dev) 5012static int ata_host_set_request_pm(struct ata_host_set *host_set,
5013 pm_message_t mesg, unsigned int action,
5014 unsigned int ehi_flags, int wait)
5005{ 5015{
5006 unsigned int err_mask; 5016 unsigned long flags;
5017 int i, rc;
5007 5018
5008 err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1); 5019 for (i = 0; i < host_set->n_ports; i++) {
5009 if (err_mask) { 5020 struct ata_port *ap = host_set->ports[i];
5010 ata_dev_printk(dev, KERN_ERR, "failed to standby drive "
5011 "(err_mask=0x%x)\n", err_mask);
5012 return -EIO;
5013 }
5014 5021
5015 return 0; 5022 /* Previous resume operation might still be in
5016} 5023 * progress. Wait for PM_PENDING to clear.
5024 */
5025 if (ap->pflags & ATA_PFLAG_PM_PENDING) {
5026 ata_port_wait_eh(ap);
5027 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5028 }
5017 5029
5018static int ata_start_drive(struct ata_device *dev) 5030 /* request PM ops to EH */
5019{ 5031 spin_lock_irqsave(ap->lock, flags);
5020 unsigned int err_mask;
5021 5032
5022 err_mask = ata_do_simple_cmd(dev, ATA_CMD_IDLEIMMEDIATE); 5033 ap->pm_mesg = mesg;
5023 if (err_mask) { 5034 if (wait) {
5024 ata_dev_printk(dev, KERN_ERR, "failed to start drive " 5035 rc = 0;
5025 "(err_mask=0x%x)\n", err_mask); 5036 ap->pm_result = &rc;
5026 return -EIO; 5037 }
5038
5039 ap->pflags |= ATA_PFLAG_PM_PENDING;
5040 ap->eh_info.action |= action;
5041 ap->eh_info.flags |= ehi_flags;
5042
5043 ata_port_schedule_eh(ap);
5044
5045 spin_unlock_irqrestore(ap->lock, flags);
5046
5047 /* wait and check result */
5048 if (wait) {
5049 ata_port_wait_eh(ap);
5050 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5051 if (rc)
5052 return rc;
5053 }
5027 } 5054 }
5028 5055
5029 return 0; 5056 return 0;
5030} 5057}
5031 5058
5032/** 5059/**
5033 * ata_device_resume - wakeup a previously suspended devices 5060 * ata_host_set_suspend - suspend host_set
5034 * @dev: the device to resume 5061 * @host_set: host_set to suspend
5062 * @mesg: PM message
5035 * 5063 *
5036 * Kick the drive back into action, by sending it an idle immediate 5064 * Suspend @host_set. Actual operation is performed by EH. This
5037 * command and making sure its transfer mode matches between drive 5065 * function requests EH to perform PM operations and waits for EH
5038 * and host. 5066 * to finish.
5039 * 5067 *
5068 * LOCKING:
5069 * Kernel thread context (may sleep).
5070 *
5071 * RETURNS:
5072 * 0 on success, -errno on failure.
5040 */ 5073 */
5041int ata_device_resume(struct ata_device *dev) 5074int ata_host_set_suspend(struct ata_host_set *host_set, pm_message_t mesg)
5042{ 5075{
5043 struct ata_port *ap = dev->ap; 5076 int i, j, rc;
5044 5077
5045 if (ap->flags & ATA_FLAG_SUSPENDED) { 5078 rc = ata_host_set_request_pm(host_set, mesg, 0, ATA_EHI_QUIET, 1);
5046 struct ata_device *failed_dev; 5079 if (rc)
5080 goto fail;
5047 5081
5048 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 5082 /* EH is quiescent now. Fail if we have any ready device.
5049 ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 200000); 5083 * This happens if hotplug occurs between completion of device
5084 * suspension and here.
5085 */
5086 for (i = 0; i < host_set->n_ports; i++) {
5087 struct ata_port *ap = host_set->ports[i];
5050 5088
5051 ap->flags &= ~ATA_FLAG_SUSPENDED; 5089 for (j = 0; j < ATA_MAX_DEVICES; j++) {
5052 while (ata_set_mode(ap, &failed_dev)) 5090 struct ata_device *dev = &ap->device[j];
5053 ata_dev_disable(failed_dev); 5091
5092 if (ata_dev_ready(dev)) {
5093 ata_port_printk(ap, KERN_WARNING,
5094 "suspend failed, device %d "
5095 "still active\n", dev->devno);
5096 rc = -EBUSY;
5097 goto fail;
5098 }
5099 }
5054 } 5100 }
5055 if (!ata_dev_enabled(dev))
5056 return 0;
5057 if (dev->class == ATA_DEV_ATA)
5058 ata_start_drive(dev);
5059 5101
5102 host_set->dev->power.power_state = mesg;
5060 return 0; 5103 return 0;
5104
5105 fail:
5106 ata_host_set_resume(host_set);
5107 return rc;
5061} 5108}
5062 5109
5063/** 5110/**
5064 * ata_device_suspend - prepare a device for suspend 5111 * ata_host_set_resume - resume host_set
5065 * @dev: the device to suspend 5112 * @host_set: host_set to resume
5066 * @state: target power management state 5113 *
5114 * Resume @host_set. Actual operation is performed by EH. This
5115 * function requests EH to perform PM operations and returns.
5116 * Note that all resume operations are performed parallely.
5067 * 5117 *
5068 * Flush the cache on the drive, if appropriate, then issue a 5118 * LOCKING:
5069 * standbynow command. 5119 * Kernel thread context (may sleep).
5070 */ 5120 */
5071int ata_device_suspend(struct ata_device *dev, pm_message_t state) 5121void ata_host_set_resume(struct ata_host_set *host_set)
5072{ 5122{
5073 struct ata_port *ap = dev->ap; 5123 ata_host_set_request_pm(host_set, PMSG_ON, ATA_EH_SOFTRESET,
5074 5124 ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0);
5075 if (!ata_dev_enabled(dev)) 5125 host_set->dev->power.power_state = PMSG_ON;
5076 return 0;
5077 if (dev->class == ATA_DEV_ATA)
5078 ata_flush_cache(dev);
5079
5080 if (state.event != PM_EVENT_FREEZE)
5081 ata_standby_drive(dev);
5082 ap->flags |= ATA_FLAG_SUSPENDED;
5083 return 0;
5084} 5126}
5085 5127
5086/** 5128/**
@@ -5440,6 +5482,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
5440 } 5482 }
5441 5483
5442 if (ap->ops->error_handler) { 5484 if (ap->ops->error_handler) {
5485 struct ata_eh_info *ehi = &ap->eh_info;
5443 unsigned long flags; 5486 unsigned long flags;
5444 5487
5445 ata_port_probe(ap); 5488 ata_port_probe(ap);
@@ -5447,10 +5490,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
5447 /* kick EH for boot probing */ 5490 /* kick EH for boot probing */
5448 spin_lock_irqsave(ap->lock, flags); 5491 spin_lock_irqsave(ap->lock, flags);
5449 5492
5450 ap->eh_info.probe_mask = (1 << ATA_MAX_DEVICES) - 1; 5493 ehi->probe_mask = (1 << ATA_MAX_DEVICES) - 1;
5451 ap->eh_info.action |= ATA_EH_SOFTRESET; 5494 ehi->action |= ATA_EH_SOFTRESET;
5495 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
5452 5496
5453 ap->flags |= ATA_FLAG_LOADING; 5497 ap->pflags |= ATA_PFLAG_LOADING;
5454 ata_port_schedule_eh(ap); 5498 ata_port_schedule_eh(ap);
5455 5499
5456 spin_unlock_irqrestore(ap->lock, flags); 5500 spin_unlock_irqrestore(ap->lock, flags);
@@ -5518,7 +5562,7 @@ void ata_port_detach(struct ata_port *ap)
5518 5562
5519 /* tell EH we're leaving & flush EH */ 5563 /* tell EH we're leaving & flush EH */
5520 spin_lock_irqsave(ap->lock, flags); 5564 spin_lock_irqsave(ap->lock, flags);
5521 ap->flags |= ATA_FLAG_UNLOADING; 5565 ap->pflags |= ATA_PFLAG_UNLOADING;
5522 spin_unlock_irqrestore(ap->lock, flags); 5566 spin_unlock_irqrestore(ap->lock, flags);
5523 5567
5524 ata_port_wait_eh(ap); 5568 ata_port_wait_eh(ap);
@@ -5723,20 +5767,55 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
5723 return (tmp == bits->val) ? 1 : 0; 5767 return (tmp == bits->val) ? 1 : 0;
5724} 5768}
5725 5769
5726int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state) 5770void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t state)
5727{ 5771{
5728 pci_save_state(pdev); 5772 pci_save_state(pdev);
5729 pci_disable_device(pdev); 5773
5730 pci_set_power_state(pdev, PCI_D3hot); 5774 if (state.event == PM_EVENT_SUSPEND) {
5731 return 0; 5775 pci_disable_device(pdev);
5776 pci_set_power_state(pdev, PCI_D3hot);
5777 }
5732} 5778}
5733 5779
5734int ata_pci_device_resume(struct pci_dev *pdev) 5780void ata_pci_device_do_resume(struct pci_dev *pdev)
5735{ 5781{
5736 pci_set_power_state(pdev, PCI_D0); 5782 pci_set_power_state(pdev, PCI_D0);
5737 pci_restore_state(pdev); 5783 pci_restore_state(pdev);
5738 pci_enable_device(pdev); 5784 pci_enable_device(pdev);
5739 pci_set_master(pdev); 5785 pci_set_master(pdev);
5786}
5787
5788int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
5789{
5790 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
5791 int rc = 0;
5792
5793 rc = ata_host_set_suspend(host_set, state);
5794 if (rc)
5795 return rc;
5796
5797 if (host_set->next) {
5798 rc = ata_host_set_suspend(host_set->next, state);
5799 if (rc) {
5800 ata_host_set_resume(host_set);
5801 return rc;
5802 }
5803 }
5804
5805 ata_pci_device_do_suspend(pdev, state);
5806
5807 return 0;
5808}
5809
5810int ata_pci_device_resume(struct pci_dev *pdev)
5811{
5812 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
5813
5814 ata_pci_device_do_resume(pdev);
5815 ata_host_set_resume(host_set);
5816 if (host_set->next)
5817 ata_host_set_resume(host_set->next);
5818
5740 return 0; 5819 return 0;
5741} 5820}
5742#endif /* CONFIG_PCI */ 5821#endif /* CONFIG_PCI */
@@ -5842,9 +5921,9 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
5842 * Do not depend on ABI/API stability. 5921 * Do not depend on ABI/API stability.
5843 */ 5922 */
5844 5923
5845EXPORT_SYMBOL_GPL(sata_deb_timing_boot); 5924EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
5846EXPORT_SYMBOL_GPL(sata_deb_timing_eh); 5925EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
5847EXPORT_SYMBOL_GPL(sata_deb_timing_before_fsrst); 5926EXPORT_SYMBOL_GPL(sata_deb_timing_long);
5848EXPORT_SYMBOL_GPL(ata_std_bios_param); 5927EXPORT_SYMBOL_GPL(ata_std_bios_param);
5849EXPORT_SYMBOL_GPL(ata_std_ports); 5928EXPORT_SYMBOL_GPL(ata_std_ports);
5850EXPORT_SYMBOL_GPL(ata_device_add); 5929EXPORT_SYMBOL_GPL(ata_device_add);
@@ -5916,6 +5995,8 @@ EXPORT_SYMBOL_GPL(sata_scr_write);
5916EXPORT_SYMBOL_GPL(sata_scr_write_flush); 5995EXPORT_SYMBOL_GPL(sata_scr_write_flush);
5917EXPORT_SYMBOL_GPL(ata_port_online); 5996EXPORT_SYMBOL_GPL(ata_port_online);
5918EXPORT_SYMBOL_GPL(ata_port_offline); 5997EXPORT_SYMBOL_GPL(ata_port_offline);
5998EXPORT_SYMBOL_GPL(ata_host_set_suspend);
5999EXPORT_SYMBOL_GPL(ata_host_set_resume);
5919EXPORT_SYMBOL_GPL(ata_id_string); 6000EXPORT_SYMBOL_GPL(ata_id_string);
5920EXPORT_SYMBOL_GPL(ata_id_c_string); 6001EXPORT_SYMBOL_GPL(ata_id_c_string);
5921EXPORT_SYMBOL_GPL(ata_scsi_simulate); 6002EXPORT_SYMBOL_GPL(ata_scsi_simulate);
@@ -5930,14 +6011,14 @@ EXPORT_SYMBOL_GPL(ata_pci_host_stop);
5930EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); 6011EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
5931EXPORT_SYMBOL_GPL(ata_pci_init_one); 6012EXPORT_SYMBOL_GPL(ata_pci_init_one);
5932EXPORT_SYMBOL_GPL(ata_pci_remove_one); 6013EXPORT_SYMBOL_GPL(ata_pci_remove_one);
6014EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
6015EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
5933EXPORT_SYMBOL_GPL(ata_pci_device_suspend); 6016EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
5934EXPORT_SYMBOL_GPL(ata_pci_device_resume); 6017EXPORT_SYMBOL_GPL(ata_pci_device_resume);
5935EXPORT_SYMBOL_GPL(ata_pci_default_filter); 6018EXPORT_SYMBOL_GPL(ata_pci_default_filter);
5936EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); 6019EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
5937#endif /* CONFIG_PCI */ 6020#endif /* CONFIG_PCI */
5938 6021
5939EXPORT_SYMBOL_GPL(ata_device_suspend);
5940EXPORT_SYMBOL_GPL(ata_device_resume);
5941EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); 6022EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
5942EXPORT_SYMBOL_GPL(ata_scsi_device_resume); 6023EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
5943 6024
diff --git a/drivers/scsi/libata-eh.c b/drivers/scsi/libata-eh.c
index bf5a72aca8a4..4b6aa30f4d68 100644
--- a/drivers/scsi/libata-eh.c
+++ b/drivers/scsi/libata-eh.c
@@ -47,6 +47,8 @@
47 47
48static void __ata_port_freeze(struct ata_port *ap); 48static void __ata_port_freeze(struct ata_port *ap);
49static void ata_eh_finish(struct ata_port *ap); 49static void ata_eh_finish(struct ata_port *ap);
50static void ata_eh_handle_port_suspend(struct ata_port *ap);
51static void ata_eh_handle_port_resume(struct ata_port *ap);
50 52
51static void ata_ering_record(struct ata_ering *ering, int is_io, 53static void ata_ering_record(struct ata_ering *ering, int is_io,
52 unsigned int err_mask) 54 unsigned int err_mask)
@@ -190,7 +192,6 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
190void ata_scsi_error(struct Scsi_Host *host) 192void ata_scsi_error(struct Scsi_Host *host)
191{ 193{
192 struct ata_port *ap = ata_shost_to_port(host); 194 struct ata_port *ap = ata_shost_to_port(host);
193 spinlock_t *ap_lock = ap->lock;
194 int i, repeat_cnt = ATA_EH_MAX_REPEAT; 195 int i, repeat_cnt = ATA_EH_MAX_REPEAT;
195 unsigned long flags; 196 unsigned long flags;
196 197
@@ -217,7 +218,7 @@ void ata_scsi_error(struct Scsi_Host *host)
217 struct scsi_cmnd *scmd, *tmp; 218 struct scsi_cmnd *scmd, *tmp;
218 int nr_timedout = 0; 219 int nr_timedout = 0;
219 220
220 spin_lock_irqsave(ap_lock, flags); 221 spin_lock_irqsave(ap->lock, flags);
221 222
222 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { 223 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
223 struct ata_queued_cmd *qc; 224 struct ata_queued_cmd *qc;
@@ -256,43 +257,49 @@ void ata_scsi_error(struct Scsi_Host *host)
256 if (nr_timedout) 257 if (nr_timedout)
257 __ata_port_freeze(ap); 258 __ata_port_freeze(ap);
258 259
259 spin_unlock_irqrestore(ap_lock, flags); 260 spin_unlock_irqrestore(ap->lock, flags);
260 } else 261 } else
261 spin_unlock_wait(ap_lock); 262 spin_unlock_wait(ap->lock);
262 263
263 repeat: 264 repeat:
264 /* invoke error handler */ 265 /* invoke error handler */
265 if (ap->ops->error_handler) { 266 if (ap->ops->error_handler) {
267 /* process port resume request */
268 ata_eh_handle_port_resume(ap);
269
266 /* fetch & clear EH info */ 270 /* fetch & clear EH info */
267 spin_lock_irqsave(ap_lock, flags); 271 spin_lock_irqsave(ap->lock, flags);
268 272
269 memset(&ap->eh_context, 0, sizeof(ap->eh_context)); 273 memset(&ap->eh_context, 0, sizeof(ap->eh_context));
270 ap->eh_context.i = ap->eh_info; 274 ap->eh_context.i = ap->eh_info;
271 memset(&ap->eh_info, 0, sizeof(ap->eh_info)); 275 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
272 276
273 ap->flags |= ATA_FLAG_EH_IN_PROGRESS; 277 ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
274 ap->flags &= ~ATA_FLAG_EH_PENDING; 278 ap->pflags &= ~ATA_PFLAG_EH_PENDING;
275 279
276 spin_unlock_irqrestore(ap_lock, flags); 280 spin_unlock_irqrestore(ap->lock, flags);
277 281
278 /* invoke EH. if unloading, just finish failed qcs */ 282 /* invoke EH, skip if unloading or suspended */
279 if (!(ap->flags & ATA_FLAG_UNLOADING)) 283 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED)))
280 ap->ops->error_handler(ap); 284 ap->ops->error_handler(ap);
281 else 285 else
282 ata_eh_finish(ap); 286 ata_eh_finish(ap);
283 287
288 /* process port suspend request */
289 ata_eh_handle_port_suspend(ap);
290
284 /* Exception might have happend after ->error_handler 291 /* Exception might have happend after ->error_handler
285 * recovered the port but before this point. Repeat 292 * recovered the port but before this point. Repeat
286 * EH in such case. 293 * EH in such case.
287 */ 294 */
288 spin_lock_irqsave(ap_lock, flags); 295 spin_lock_irqsave(ap->lock, flags);
289 296
290 if (ap->flags & ATA_FLAG_EH_PENDING) { 297 if (ap->pflags & ATA_PFLAG_EH_PENDING) {
291 if (--repeat_cnt) { 298 if (--repeat_cnt) {
292 ata_port_printk(ap, KERN_INFO, 299 ata_port_printk(ap, KERN_INFO,
293 "EH pending after completion, " 300 "EH pending after completion, "
294 "repeating EH (cnt=%d)\n", repeat_cnt); 301 "repeating EH (cnt=%d)\n", repeat_cnt);
295 spin_unlock_irqrestore(ap_lock, flags); 302 spin_unlock_irqrestore(ap->lock, flags);
296 goto repeat; 303 goto repeat;
297 } 304 }
298 ata_port_printk(ap, KERN_ERR, "EH pending after %d " 305 ata_port_printk(ap, KERN_ERR, "EH pending after %d "
@@ -302,14 +309,14 @@ void ata_scsi_error(struct Scsi_Host *host)
302 /* this run is complete, make sure EH info is clear */ 309 /* this run is complete, make sure EH info is clear */
303 memset(&ap->eh_info, 0, sizeof(ap->eh_info)); 310 memset(&ap->eh_info, 0, sizeof(ap->eh_info));
304 311
305 /* Clear host_eh_scheduled while holding ap_lock such 312 /* Clear host_eh_scheduled while holding ap->lock such
306 * that if exception occurs after this point but 313 * that if exception occurs after this point but
307 * before EH completion, SCSI midlayer will 314 * before EH completion, SCSI midlayer will
308 * re-initiate EH. 315 * re-initiate EH.
309 */ 316 */
310 host->host_eh_scheduled = 0; 317 host->host_eh_scheduled = 0;
311 318
312 spin_unlock_irqrestore(ap_lock, flags); 319 spin_unlock_irqrestore(ap->lock, flags);
313 } else { 320 } else {
314 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL); 321 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
315 ap->ops->eng_timeout(ap); 322 ap->ops->eng_timeout(ap);
@@ -321,24 +328,23 @@ void ata_scsi_error(struct Scsi_Host *host)
321 scsi_eh_flush_done_q(&ap->eh_done_q); 328 scsi_eh_flush_done_q(&ap->eh_done_q);
322 329
323 /* clean up */ 330 /* clean up */
324 spin_lock_irqsave(ap_lock, flags); 331 spin_lock_irqsave(ap->lock, flags);
325 332
326 if (ap->flags & ATA_FLAG_LOADING) { 333 if (ap->pflags & ATA_PFLAG_LOADING)
327 ap->flags &= ~ATA_FLAG_LOADING; 334 ap->pflags &= ~ATA_PFLAG_LOADING;
328 } else { 335 else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG)
329 if (ap->flags & ATA_FLAG_SCSI_HOTPLUG) 336 queue_work(ata_aux_wq, &ap->hotplug_task);
330 queue_work(ata_aux_wq, &ap->hotplug_task); 337
331 if (ap->flags & ATA_FLAG_RECOVERED) 338 if (ap->pflags & ATA_PFLAG_RECOVERED)
332 ata_port_printk(ap, KERN_INFO, "EH complete\n"); 339 ata_port_printk(ap, KERN_INFO, "EH complete\n");
333 }
334 340
335 ap->flags &= ~(ATA_FLAG_SCSI_HOTPLUG | ATA_FLAG_RECOVERED); 341 ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED);
336 342
337 /* tell wait_eh that we're done */ 343 /* tell wait_eh that we're done */
338 ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS; 344 ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS;
339 wake_up_all(&ap->eh_wait_q); 345 wake_up_all(&ap->eh_wait_q);
340 346
341 spin_unlock_irqrestore(ap_lock, flags); 347 spin_unlock_irqrestore(ap->lock, flags);
342 348
343 DPRINTK("EXIT\n"); 349 DPRINTK("EXIT\n");
344} 350}
@@ -360,7 +366,7 @@ void ata_port_wait_eh(struct ata_port *ap)
360 retry: 366 retry:
361 spin_lock_irqsave(ap->lock, flags); 367 spin_lock_irqsave(ap->lock, flags);
362 368
363 while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) { 369 while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) {
364 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE); 370 prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
365 spin_unlock_irqrestore(ap->lock, flags); 371 spin_unlock_irqrestore(ap->lock, flags);
366 schedule(); 372 schedule();
@@ -489,7 +495,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
489 WARN_ON(!ap->ops->error_handler); 495 WARN_ON(!ap->ops->error_handler);
490 496
491 qc->flags |= ATA_QCFLAG_FAILED; 497 qc->flags |= ATA_QCFLAG_FAILED;
492 qc->ap->flags |= ATA_FLAG_EH_PENDING; 498 qc->ap->pflags |= ATA_PFLAG_EH_PENDING;
493 499
494 /* The following will fail if timeout has already expired. 500 /* The following will fail if timeout has already expired.
495 * ata_scsi_error() takes care of such scmds on EH entry. 501 * ata_scsi_error() takes care of such scmds on EH entry.
@@ -513,7 +519,7 @@ void ata_port_schedule_eh(struct ata_port *ap)
513{ 519{
514 WARN_ON(!ap->ops->error_handler); 520 WARN_ON(!ap->ops->error_handler);
515 521
516 ap->flags |= ATA_FLAG_EH_PENDING; 522 ap->pflags |= ATA_PFLAG_EH_PENDING;
517 scsi_schedule_eh(ap->host); 523 scsi_schedule_eh(ap->host);
518 524
519 DPRINTK("port EH scheduled\n"); 525 DPRINTK("port EH scheduled\n");
@@ -578,7 +584,7 @@ static void __ata_port_freeze(struct ata_port *ap)
578 if (ap->ops->freeze) 584 if (ap->ops->freeze)
579 ap->ops->freeze(ap); 585 ap->ops->freeze(ap);
580 586
581 ap->flags |= ATA_FLAG_FROZEN; 587 ap->pflags |= ATA_PFLAG_FROZEN;
582 588
583 DPRINTK("ata%u port frozen\n", ap->id); 589 DPRINTK("ata%u port frozen\n", ap->id);
584} 590}
@@ -646,7 +652,7 @@ void ata_eh_thaw_port(struct ata_port *ap)
646 652
647 spin_lock_irqsave(ap->lock, flags); 653 spin_lock_irqsave(ap->lock, flags);
648 654
649 ap->flags &= ~ATA_FLAG_FROZEN; 655 ap->pflags &= ~ATA_PFLAG_FROZEN;
650 656
651 if (ap->ops->thaw) 657 if (ap->ops->thaw)
652 ap->ops->thaw(ap); 658 ap->ops->thaw(ap);
@@ -731,7 +737,7 @@ static void ata_eh_detach_dev(struct ata_device *dev)
731 737
732 if (ata_scsi_offline_dev(dev)) { 738 if (ata_scsi_offline_dev(dev)) {
733 dev->flags |= ATA_DFLAG_DETACHED; 739 dev->flags |= ATA_DFLAG_DETACHED;
734 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 740 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
735 } 741 }
736 742
737 /* clear per-dev EH actions */ 743 /* clear per-dev EH actions */
@@ -760,8 +766,12 @@ static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev,
760 unsigned long flags; 766 unsigned long flags;
761 767
762 spin_lock_irqsave(ap->lock, flags); 768 spin_lock_irqsave(ap->lock, flags);
769
763 ata_eh_clear_action(dev, &ap->eh_info, action); 770 ata_eh_clear_action(dev, &ap->eh_info, action);
764 ap->flags |= ATA_FLAG_RECOVERED; 771
772 if (!(ap->eh_context.i.flags & ATA_EHI_QUIET))
773 ap->pflags |= ATA_PFLAG_RECOVERED;
774
765 spin_unlock_irqrestore(ap->lock, flags); 775 spin_unlock_irqrestore(ap->lock, flags);
766} 776}
767 777
@@ -1027,7 +1037,7 @@ static void ata_eh_analyze_ncq_error(struct ata_port *ap)
1027 int tag, rc; 1037 int tag, rc;
1028 1038
1029 /* if frozen, we can't do much */ 1039 /* if frozen, we can't do much */
1030 if (ap->flags & ATA_FLAG_FROZEN) 1040 if (ap->pflags & ATA_PFLAG_FROZEN)
1031 return; 1041 return;
1032 1042
1033 /* is it NCQ device error? */ 1043 /* is it NCQ device error? */
@@ -1275,6 +1285,9 @@ static void ata_eh_autopsy(struct ata_port *ap)
1275 1285
1276 DPRINTK("ENTER\n"); 1286 DPRINTK("ENTER\n");
1277 1287
1288 if (ehc->i.flags & ATA_EHI_NO_AUTOPSY)
1289 return;
1290
1278 /* obtain and analyze SError */ 1291 /* obtain and analyze SError */
1279 rc = sata_scr_read(ap, SCR_ERROR, &serror); 1292 rc = sata_scr_read(ap, SCR_ERROR, &serror);
1280 if (rc == 0) { 1293 if (rc == 0) {
@@ -1327,7 +1340,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
1327 } 1340 }
1328 1341
1329 /* enforce default EH actions */ 1342 /* enforce default EH actions */
1330 if (ap->flags & ATA_FLAG_FROZEN || 1343 if (ap->pflags & ATA_PFLAG_FROZEN ||
1331 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT)) 1344 all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
1332 action |= ATA_EH_SOFTRESET; 1345 action |= ATA_EH_SOFTRESET;
1333 else if (all_err_mask) 1346 else if (all_err_mask)
@@ -1346,7 +1359,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
1346 1359
1347 /* record autopsy result */ 1360 /* record autopsy result */
1348 ehc->i.dev = failed_dev; 1361 ehc->i.dev = failed_dev;
1349 ehc->i.action = action; 1362 ehc->i.action |= action;
1350 1363
1351 DPRINTK("EXIT\n"); 1364 DPRINTK("EXIT\n");
1352} 1365}
@@ -1385,7 +1398,7 @@ static void ata_eh_report(struct ata_port *ap)
1385 return; 1398 return;
1386 1399
1387 frozen = ""; 1400 frozen = "";
1388 if (ap->flags & ATA_FLAG_FROZEN) 1401 if (ap->pflags & ATA_PFLAG_FROZEN)
1389 frozen = " frozen"; 1402 frozen = " frozen";
1390 1403
1391 if (ehc->i.dev) { 1404 if (ehc->i.dev) {
@@ -1465,7 +1478,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1465 struct ata_eh_context *ehc = &ap->eh_context; 1478 struct ata_eh_context *ehc = &ap->eh_context;
1466 unsigned int *classes = ehc->classes; 1479 unsigned int *classes = ehc->classes;
1467 int tries = ATA_EH_RESET_TRIES; 1480 int tries = ATA_EH_RESET_TRIES;
1468 int verbose = !(ap->flags & ATA_FLAG_LOADING); 1481 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
1469 unsigned int action; 1482 unsigned int action;
1470 ata_reset_fn_t reset; 1483 ata_reset_fn_t reset;
1471 int i, did_followup_srst, rc; 1484 int i, did_followup_srst, rc;
@@ -1605,7 +1618,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1605 dev = &ap->device[i]; 1618 dev = &ap->device[i];
1606 action = ata_eh_dev_action(dev); 1619 action = ata_eh_dev_action(dev);
1607 1620
1608 if (action & ATA_EH_REVALIDATE && ata_dev_enabled(dev)) { 1621 if (action & ATA_EH_REVALIDATE && ata_dev_ready(dev)) {
1609 if (ata_port_offline(ap)) { 1622 if (ata_port_offline(ap)) {
1610 rc = -EIO; 1623 rc = -EIO;
1611 break; 1624 break;
@@ -1636,7 +1649,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1636 } 1649 }
1637 1650
1638 spin_lock_irqsave(ap->lock, flags); 1651 spin_lock_irqsave(ap->lock, flags);
1639 ap->flags |= ATA_FLAG_SCSI_HOTPLUG; 1652 ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
1640 spin_unlock_irqrestore(ap->lock, flags); 1653 spin_unlock_irqrestore(ap->lock, flags);
1641 } 1654 }
1642 } 1655 }
@@ -1648,6 +1661,164 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1648 return rc; 1661 return rc;
1649} 1662}
1650 1663
1664/**
1665 * ata_eh_suspend - handle suspend EH action
1666 * @ap: target host port
1667 * @r_failed_dev: result parameter to indicate failing device
1668 *
1669 * Handle suspend EH action. Disk devices are spinned down and
1670 * other types of devices are just marked suspended. Once
1671 * suspended, no EH action to the device is allowed until it is
1672 * resumed.
1673 *
1674 * LOCKING:
1675 * Kernel thread context (may sleep).
1676 *
1677 * RETURNS:
1678 * 0 on success, -errno otherwise
1679 */
1680static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
1681{
1682 struct ata_device *dev;
1683 int i, rc = 0;
1684
1685 DPRINTK("ENTER\n");
1686
1687 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1688 unsigned long flags;
1689 unsigned int action, err_mask;
1690
1691 dev = &ap->device[i];
1692 action = ata_eh_dev_action(dev);
1693
1694 if (!ata_dev_enabled(dev) || !(action & ATA_EH_SUSPEND))
1695 continue;
1696
1697 WARN_ON(dev->flags & ATA_DFLAG_SUSPENDED);
1698
1699 ata_eh_about_to_do(ap, dev, ATA_EH_SUSPEND);
1700
1701 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1702 /* flush cache */
1703 rc = ata_flush_cache(dev);
1704 if (rc)
1705 break;
1706
1707 /* spin down */
1708 err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1);
1709 if (err_mask) {
1710 ata_dev_printk(dev, KERN_ERR, "failed to "
1711 "spin down (err_mask=0x%x)\n",
1712 err_mask);
1713 rc = -EIO;
1714 break;
1715 }
1716 }
1717
1718 spin_lock_irqsave(ap->lock, flags);
1719 dev->flags |= ATA_DFLAG_SUSPENDED;
1720 spin_unlock_irqrestore(ap->lock, flags);
1721
1722 ata_eh_done(ap, dev, ATA_EH_SUSPEND);
1723 }
1724
1725 if (rc)
1726 *r_failed_dev = dev;
1727
1728 DPRINTK("EXIT\n");
1729 return 0;
1730}
1731
1732/**
1733 * ata_eh_prep_resume - prep for resume EH action
1734 * @ap: target host port
1735 *
1736 * Clear SUSPENDED in preparation for scheduled resume actions.
1737 * This allows other parts of EH to access the devices being
1738 * resumed.
1739 *
1740 * LOCKING:
1741 * Kernel thread context (may sleep).
1742 */
1743static void ata_eh_prep_resume(struct ata_port *ap)
1744{
1745 struct ata_device *dev;
1746 unsigned long flags;
1747 int i;
1748
1749 DPRINTK("ENTER\n");
1750
1751 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1752 unsigned int action;
1753
1754 dev = &ap->device[i];
1755 action = ata_eh_dev_action(dev);
1756
1757 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1758 continue;
1759
1760 spin_lock_irqsave(ap->lock, flags);
1761 dev->flags &= ~ATA_DFLAG_SUSPENDED;
1762 spin_unlock_irqrestore(ap->lock, flags);
1763 }
1764
1765 DPRINTK("EXIT\n");
1766}
1767
1768/**
1769 * ata_eh_resume - handle resume EH action
1770 * @ap: target host port
1771 * @r_failed_dev: result parameter to indicate failing device
1772 *
1773 * Handle resume EH action. Target devices are already reset and
1774 * revalidated. Spinning up is the only operation left.
1775 *
1776 * LOCKING:
1777 * Kernel thread context (may sleep).
1778 *
1779 * RETURNS:
1780 * 0 on success, -errno otherwise
1781 */
1782static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
1783{
1784 struct ata_device *dev;
1785 int i, rc = 0;
1786
1787 DPRINTK("ENTER\n");
1788
1789 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1790 unsigned int action, err_mask;
1791
1792 dev = &ap->device[i];
1793 action = ata_eh_dev_action(dev);
1794
1795 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1796 continue;
1797
1798 ata_eh_about_to_do(ap, dev, ATA_EH_RESUME);
1799
1800 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1801 err_mask = ata_do_simple_cmd(dev,
1802 ATA_CMD_IDLEIMMEDIATE);
1803 if (err_mask) {
1804 ata_dev_printk(dev, KERN_ERR, "failed to "
1805 "spin up (err_mask=0x%x)\n",
1806 err_mask);
1807 rc = -EIO;
1808 break;
1809 }
1810 }
1811
1812 ata_eh_done(ap, dev, ATA_EH_RESUME);
1813 }
1814
1815 if (rc)
1816 *r_failed_dev = dev;
1817
1818 DPRINTK("EXIT\n");
1819 return 0;
1820}
1821
1651static int ata_port_nr_enabled(struct ata_port *ap) 1822static int ata_port_nr_enabled(struct ata_port *ap)
1652{ 1823{
1653 int i, cnt = 0; 1824 int i, cnt = 0;
@@ -1673,7 +1844,19 @@ static int ata_eh_skip_recovery(struct ata_port *ap)
1673 struct ata_eh_context *ehc = &ap->eh_context; 1844 struct ata_eh_context *ehc = &ap->eh_context;
1674 int i; 1845 int i;
1675 1846
1676 if (ap->flags & ATA_FLAG_FROZEN || ata_port_nr_enabled(ap)) 1847 /* skip if all possible devices are suspended */
1848 for (i = 0; i < ata_port_max_devices(ap); i++) {
1849 struct ata_device *dev = &ap->device[i];
1850
1851 if (ata_dev_absent(dev) || ata_dev_ready(dev))
1852 break;
1853 }
1854
1855 if (i == ata_port_max_devices(ap))
1856 return 1;
1857
1858 /* always thaw frozen port and recover failed devices */
1859 if (ap->pflags & ATA_PFLAG_FROZEN || ata_port_nr_enabled(ap))
1677 return 0; 1860 return 0;
1678 1861
1679 /* skip if class codes for all vacant slots are ATA_DEV_NONE */ 1862 /* skip if class codes for all vacant slots are ATA_DEV_NONE */
@@ -1744,9 +1927,12 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1744 rc = 0; 1927 rc = 0;
1745 1928
1746 /* if UNLOADING, finish immediately */ 1929 /* if UNLOADING, finish immediately */
1747 if (ap->flags & ATA_FLAG_UNLOADING) 1930 if (ap->pflags & ATA_PFLAG_UNLOADING)
1748 goto out; 1931 goto out;
1749 1932
1933 /* prep for resume */
1934 ata_eh_prep_resume(ap);
1935
1750 /* skip EH if possible. */ 1936 /* skip EH if possible. */
1751 if (ata_eh_skip_recovery(ap)) 1937 if (ata_eh_skip_recovery(ap))
1752 ehc->i.action = 0; 1938 ehc->i.action = 0;
@@ -1774,6 +1960,11 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1774 if (rc) 1960 if (rc)
1775 goto dev_fail; 1961 goto dev_fail;
1776 1962
1963 /* resume devices */
1964 rc = ata_eh_resume(ap, &dev);
1965 if (rc)
1966 goto dev_fail;
1967
1777 /* configure transfer mode if the port has been reset */ 1968 /* configure transfer mode if the port has been reset */
1778 if (ehc->i.flags & ATA_EHI_DID_RESET) { 1969 if (ehc->i.flags & ATA_EHI_DID_RESET) {
1779 rc = ata_set_mode(ap, &dev); 1970 rc = ata_set_mode(ap, &dev);
@@ -1783,6 +1974,11 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1783 } 1974 }
1784 } 1975 }
1785 1976
1977 /* suspend devices */
1978 rc = ata_eh_suspend(ap, &dev);
1979 if (rc)
1980 goto dev_fail;
1981
1786 goto out; 1982 goto out;
1787 1983
1788 dev_fail: 1984 dev_fail:
@@ -1908,11 +2104,124 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1908 ata_reset_fn_t softreset, ata_reset_fn_t hardreset, 2104 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1909 ata_postreset_fn_t postreset) 2105 ata_postreset_fn_t postreset)
1910{ 2106{
1911 if (!(ap->flags & ATA_FLAG_LOADING)) { 2107 ata_eh_autopsy(ap);
1912 ata_eh_autopsy(ap); 2108 ata_eh_report(ap);
1913 ata_eh_report(ap);
1914 }
1915
1916 ata_eh_recover(ap, prereset, softreset, hardreset, postreset); 2109 ata_eh_recover(ap, prereset, softreset, hardreset, postreset);
1917 ata_eh_finish(ap); 2110 ata_eh_finish(ap);
1918} 2111}
2112
2113/**
2114 * ata_eh_handle_port_suspend - perform port suspend operation
2115 * @ap: port to suspend
2116 *
2117 * Suspend @ap.
2118 *
2119 * LOCKING:
2120 * Kernel thread context (may sleep).
2121 */
2122static void ata_eh_handle_port_suspend(struct ata_port *ap)
2123{
2124 unsigned long flags;
2125 int rc = 0;
2126
2127 /* are we suspending? */
2128 spin_lock_irqsave(ap->lock, flags);
2129 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
2130 ap->pm_mesg.event == PM_EVENT_ON) {
2131 spin_unlock_irqrestore(ap->lock, flags);
2132 return;
2133 }
2134 spin_unlock_irqrestore(ap->lock, flags);
2135
2136 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED);
2137
2138 /* suspend */
2139 ata_eh_freeze_port(ap);
2140
2141 if (ap->ops->port_suspend)
2142 rc = ap->ops->port_suspend(ap, ap->pm_mesg);
2143
2144 /* report result */
2145 spin_lock_irqsave(ap->lock, flags);
2146
2147 ap->pflags &= ~ATA_PFLAG_PM_PENDING;
2148 if (rc == 0)
2149 ap->pflags |= ATA_PFLAG_SUSPENDED;
2150 else
2151 ata_port_schedule_eh(ap);
2152
2153 if (ap->pm_result) {
2154 *ap->pm_result = rc;
2155 ap->pm_result = NULL;
2156 }
2157
2158 spin_unlock_irqrestore(ap->lock, flags);
2159
2160 return;
2161}
2162
2163/**
2164 * ata_eh_handle_port_resume - perform port resume operation
2165 * @ap: port to resume
2166 *
2167 * Resume @ap.
2168 *
2169 * This function also waits upto one second until all devices
2170 * hanging off this port requests resume EH action. This is to
2171 * prevent invoking EH and thus reset multiple times on resume.
2172 *
2173 * On DPM resume, where some of devices might not be resumed
2174 * together, this may delay port resume upto one second, but such
2175 * DPM resumes are rare and 1 sec delay isn't too bad.
2176 *
2177 * LOCKING:
2178 * Kernel thread context (may sleep).
2179 */
2180static void ata_eh_handle_port_resume(struct ata_port *ap)
2181{
2182 unsigned long timeout;
2183 unsigned long flags;
2184 int i, rc = 0;
2185
2186 /* are we resuming? */
2187 spin_lock_irqsave(ap->lock, flags);
2188 if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
2189 ap->pm_mesg.event != PM_EVENT_ON) {
2190 spin_unlock_irqrestore(ap->lock, flags);
2191 return;
2192 }
2193 spin_unlock_irqrestore(ap->lock, flags);
2194
2195 /* spurious? */
2196 if (!(ap->pflags & ATA_PFLAG_SUSPENDED))
2197 goto done;
2198
2199 if (ap->ops->port_resume)
2200 rc = ap->ops->port_resume(ap);
2201
2202 /* give devices time to request EH */
2203 timeout = jiffies + HZ; /* 1s max */
2204 while (1) {
2205 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2206 struct ata_device *dev = &ap->device[i];
2207 unsigned int action = ata_eh_dev_action(dev);
2208
2209 if ((dev->flags & ATA_DFLAG_SUSPENDED) &&
2210 !(action & ATA_EH_RESUME))
2211 break;
2212 }
2213
2214 if (i == ATA_MAX_DEVICES || time_after(jiffies, timeout))
2215 break;
2216 msleep(10);
2217 }
2218
2219 done:
2220 spin_lock_irqsave(ap->lock, flags);
2221 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
2222 if (ap->pm_result) {
2223 *ap->pm_result = rc;
2224 ap->pm_result = NULL;
2225 }
2226 spin_unlock_irqrestore(ap->lock, flags);
2227}
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 2915bca691e8..7ced41ecde86 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -397,20 +397,129 @@ void ata_dump_status(unsigned id, struct ata_taskfile *tf)
397 } 397 }
398} 398}
399 399
400int ata_scsi_device_resume(struct scsi_device *sdev) 400/**
401 * ata_scsi_device_suspend - suspend ATA device associated with sdev
402 * @sdev: the SCSI device to suspend
403 * @state: target power management state
404 *
405 * Request suspend EH action on the ATA device associated with
406 * @sdev and wait for the operation to complete.
407 *
408 * LOCKING:
409 * Kernel thread context (may sleep).
410 *
411 * RETURNS:
412 * 0 on success, -errno otherwise.
413 */
414int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
401{ 415{
402 struct ata_port *ap = ata_shost_to_port(sdev->host); 416 struct ata_port *ap = ata_shost_to_port(sdev->host);
403 struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); 417 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
418 unsigned long flags;
419 unsigned int action;
420 int rc = 0;
421
422 if (!dev)
423 goto out;
424
425 spin_lock_irqsave(ap->lock, flags);
426
427 /* wait for the previous resume to complete */
428 while (dev->flags & ATA_DFLAG_SUSPENDED) {
429 spin_unlock_irqrestore(ap->lock, flags);
430 ata_port_wait_eh(ap);
431 spin_lock_irqsave(ap->lock, flags);
432 }
433
434 /* if @sdev is already detached, nothing to do */
435 if (sdev->sdev_state == SDEV_OFFLINE ||
436 sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
437 goto out_unlock;
438
439 /* request suspend */
440 action = ATA_EH_SUSPEND;
441 if (state.event != PM_EVENT_SUSPEND)
442 action |= ATA_EH_PM_FREEZE;
443 ap->eh_info.dev_action[dev->devno] |= action;
444 ap->eh_info.flags |= ATA_EHI_QUIET;
445 ata_port_schedule_eh(ap);
446
447 spin_unlock_irqrestore(ap->lock, flags);
448
449 /* wait for EH to do the job */
450 ata_port_wait_eh(ap);
451
452 spin_lock_irqsave(ap->lock, flags);
453
454 /* If @sdev is still attached but the associated ATA device
455 * isn't suspended, the operation failed.
456 */
457 if (sdev->sdev_state != SDEV_OFFLINE &&
458 sdev->sdev_state != SDEV_CANCEL && sdev->sdev_state != SDEV_DEL &&
459 !(dev->flags & ATA_DFLAG_SUSPENDED))
460 rc = -EIO;
404 461
405 return ata_device_resume(dev); 462 out_unlock:
463 spin_unlock_irqrestore(ap->lock, flags);
464 out:
465 if (rc == 0)
466 sdev->sdev_gendev.power.power_state = state;
467 return rc;
406} 468}
407 469
408int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) 470/**
471 * ata_scsi_device_resume - resume ATA device associated with sdev
472 * @sdev: the SCSI device to resume
473 *
474 * Request resume EH action on the ATA device associated with
475 * @sdev and return immediately. This enables parallel
476 * wakeup/spinup of devices.
477 *
478 * LOCKING:
479 * Kernel thread context (may sleep).
480 *
481 * RETURNS:
482 * 0.
483 */
484int ata_scsi_device_resume(struct scsi_device *sdev)
409{ 485{
410 struct ata_port *ap = ata_shost_to_port(sdev->host); 486 struct ata_port *ap = ata_shost_to_port(sdev->host);
411 struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); 487 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
488 struct ata_eh_info *ehi = &ap->eh_info;
489 unsigned long flags;
490 unsigned int action;
491
492 if (!dev)
493 goto out;
494
495 spin_lock_irqsave(ap->lock, flags);
496
497 /* if @sdev is already detached, nothing to do */
498 if (sdev->sdev_state == SDEV_OFFLINE ||
499 sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
500 goto out_unlock;
412 501
413 return ata_device_suspend(dev, state); 502 /* request resume */
503 action = ATA_EH_RESUME;
504 if (sdev->sdev_gendev.power.power_state.event == PM_EVENT_SUSPEND)
505 __ata_ehi_hotplugged(ehi);
506 else
507 action |= ATA_EH_PM_FREEZE | ATA_EH_SOFTRESET;
508 ehi->dev_action[dev->devno] |= action;
509
510 /* We don't want autopsy and verbose EH messages. Disable
511 * those if we're the only device on this link.
512 */
513 if (ata_port_max_devices(ap) == 1)
514 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
515
516 ata_port_schedule_eh(ap);
517
518 out_unlock:
519 spin_unlock_irqrestore(ap->lock, flags);
520 out:
521 sdev->sdev_gendev.power.power_state = PMSG_ON;
522 return 0;
414} 523}
415 524
416/** 525/**
@@ -2930,7 +3039,7 @@ void ata_scsi_hotplug(void *data)
2930 struct ata_port *ap = data; 3039 struct ata_port *ap = data;
2931 int i; 3040 int i;
2932 3041
2933 if (ap->flags & ATA_FLAG_UNLOADING) { 3042 if (ap->pflags & ATA_PFLAG_UNLOADING) {
2934 DPRINTK("ENTER/EXIT - unloading\n"); 3043 DPRINTK("ENTER/EXIT - unloading\n");
2935 return; 3044 return;
2936 } 3045 }
@@ -3011,6 +3120,7 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
3011 if (dev) { 3120 if (dev) {
3012 ap->eh_info.probe_mask |= 1 << dev->devno; 3121 ap->eh_info.probe_mask |= 1 << dev->devno;
3013 ap->eh_info.action |= ATA_EH_SOFTRESET; 3122 ap->eh_info.action |= ATA_EH_SOFTRESET;
3123 ap->eh_info.flags |= ATA_EHI_RESUME_LINK;
3014 } else 3124 } else
3015 rc = -EINVAL; 3125 rc = -EINVAL;
3016 } 3126 }
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 7aabb45c35e5..d0a85073ebf7 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -109,6 +109,7 @@ enum {
109}; 109};
110 110
111static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 111static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
112static int sil_pci_device_resume(struct pci_dev *pdev);
112static void sil_dev_config(struct ata_port *ap, struct ata_device *dev); 113static void sil_dev_config(struct ata_port *ap, struct ata_device *dev);
113static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg); 114static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg);
114static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 115static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
@@ -160,6 +161,8 @@ static struct pci_driver sil_pci_driver = {
160 .id_table = sil_pci_tbl, 161 .id_table = sil_pci_tbl,
161 .probe = sil_init_one, 162 .probe = sil_init_one,
162 .remove = ata_pci_remove_one, 163 .remove = ata_pci_remove_one,
164 .suspend = ata_pci_device_suspend,
165 .resume = sil_pci_device_resume,
163}; 166};
164 167
165static struct scsi_host_template sil_sht = { 168static struct scsi_host_template sil_sht = {
@@ -178,6 +181,8 @@ static struct scsi_host_template sil_sht = {
178 .slave_configure = ata_scsi_slave_config, 181 .slave_configure = ata_scsi_slave_config,
179 .slave_destroy = ata_scsi_slave_destroy, 182 .slave_destroy = ata_scsi_slave_destroy,
180 .bios_param = ata_std_bios_param, 183 .bios_param = ata_std_bios_param,
184 .suspend = ata_scsi_device_suspend,
185 .resume = ata_scsi_device_resume,
181}; 186};
182 187
183static const struct ata_port_operations sil_ops = { 188static const struct ata_port_operations sil_ops = {
@@ -370,7 +375,7 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
370 * during hardreset makes controllers with broken SIEN 375 * during hardreset makes controllers with broken SIEN
371 * repeat probing needlessly. 376 * repeat probing needlessly.
372 */ 377 */
373 if (!(ap->flags & ATA_FLAG_FROZEN)) { 378 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
374 ata_ehi_hotplugged(&ap->eh_info); 379 ata_ehi_hotplugged(&ap->eh_info);
375 ap->eh_info.serror |= serror; 380 ap->eh_info.serror |= serror;
376 } 381 }
@@ -561,6 +566,52 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
561 } 566 }
562} 567}
563 568
569static void sil_init_controller(struct pci_dev *pdev,
570 int n_ports, unsigned long host_flags,
571 void __iomem *mmio_base)
572{
573 u8 cls;
574 u32 tmp;
575 int i;
576
577 /* Initialize FIFO PCI bus arbitration */
578 cls = sil_get_device_cache_line(pdev);
579 if (cls) {
580 cls >>= 3;
581 cls++; /* cls = (line_size/8)+1 */
582 for (i = 0; i < n_ports; i++)
583 writew(cls << 8 | cls,
584 mmio_base + sil_port[i].fifo_cfg);
585 } else
586 dev_printk(KERN_WARNING, &pdev->dev,
587 "cache line size not set. Driver may not function\n");
588
589 /* Apply R_ERR on DMA activate FIS errata workaround */
590 if (host_flags & SIL_FLAG_RERR_ON_DMA_ACT) {
591 int cnt;
592
593 for (i = 0, cnt = 0; i < n_ports; i++) {
594 tmp = readl(mmio_base + sil_port[i].sfis_cfg);
595 if ((tmp & 0x3) != 0x01)
596 continue;
597 if (!cnt)
598 dev_printk(KERN_INFO, &pdev->dev,
599 "Applying R_ERR on DMA activate "
600 "FIS errata fix\n");
601 writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg);
602 cnt++;
603 }
604 }
605
606 if (n_ports == 4) {
607 /* flip the magic "make 4 ports work" bit */
608 tmp = readl(mmio_base + sil_port[2].bmdma);
609 if ((tmp & SIL_INTR_STEERING) == 0)
610 writel(tmp | SIL_INTR_STEERING,
611 mmio_base + sil_port[2].bmdma);
612 }
613}
614
564static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 615static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
565{ 616{
566 static int printed_version; 617 static int printed_version;
@@ -570,8 +621,6 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
570 int rc; 621 int rc;
571 unsigned int i; 622 unsigned int i;
572 int pci_dev_busy = 0; 623 int pci_dev_busy = 0;
573 u32 tmp;
574 u8 cls;
575 624
576 if (!printed_version++) 625 if (!printed_version++)
577 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 626 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
@@ -630,42 +679,8 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
630 ata_std_ports(&probe_ent->port[i]); 679 ata_std_ports(&probe_ent->port[i]);
631 } 680 }
632 681
633 /* Initialize FIFO PCI bus arbitration */ 682 sil_init_controller(pdev, probe_ent->n_ports, probe_ent->host_flags,
634 cls = sil_get_device_cache_line(pdev); 683 mmio_base);
635 if (cls) {
636 cls >>= 3;
637 cls++; /* cls = (line_size/8)+1 */
638 for (i = 0; i < probe_ent->n_ports; i++)
639 writew(cls << 8 | cls,
640 mmio_base + sil_port[i].fifo_cfg);
641 } else
642 dev_printk(KERN_WARNING, &pdev->dev,
643 "cache line size not set. Driver may not function\n");
644
645 /* Apply R_ERR on DMA activate FIS errata workaround */
646 if (probe_ent->host_flags & SIL_FLAG_RERR_ON_DMA_ACT) {
647 int cnt;
648
649 for (i = 0, cnt = 0; i < probe_ent->n_ports; i++) {
650 tmp = readl(mmio_base + sil_port[i].sfis_cfg);
651 if ((tmp & 0x3) != 0x01)
652 continue;
653 if (!cnt)
654 dev_printk(KERN_INFO, &pdev->dev,
655 "Applying R_ERR on DMA activate "
656 "FIS errata fix\n");
657 writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg);
658 cnt++;
659 }
660 }
661
662 if (ent->driver_data == sil_3114) {
663 /* flip the magic "make 4 ports work" bit */
664 tmp = readl(mmio_base + sil_port[2].bmdma);
665 if ((tmp & SIL_INTR_STEERING) == 0)
666 writel(tmp | SIL_INTR_STEERING,
667 mmio_base + sil_port[2].bmdma);
668 }
669 684
670 pci_set_master(pdev); 685 pci_set_master(pdev);
671 686
@@ -685,6 +700,18 @@ err_out:
685 return rc; 700 return rc;
686} 701}
687 702
703static int sil_pci_device_resume(struct pci_dev *pdev)
704{
705 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
706
707 ata_pci_device_do_resume(pdev);
708 sil_init_controller(pdev, host_set->n_ports, host_set->ports[0]->flags,
709 host_set->mmio_base);
710 ata_host_set_resume(host_set);
711
712 return 0;
713}
714
688static int __init sil_init(void) 715static int __init sil_init(void)
689{ 716{
690 return pci_module_init(&sil_pci_driver); 717 return pci_module_init(&sil_pci_driver);
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 07a1c6a8a414..2e0f4a4076af 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -92,6 +92,7 @@ enum {
92 HOST_CTRL_STOP = (1 << 18), /* latched PCI STOP */ 92 HOST_CTRL_STOP = (1 << 18), /* latched PCI STOP */
93 HOST_CTRL_DEVSEL = (1 << 19), /* latched PCI DEVSEL */ 93 HOST_CTRL_DEVSEL = (1 << 19), /* latched PCI DEVSEL */
94 HOST_CTRL_REQ64 = (1 << 20), /* latched PCI REQ64 */ 94 HOST_CTRL_REQ64 = (1 << 20), /* latched PCI REQ64 */
95 HOST_CTRL_GLOBAL_RST = (1 << 31), /* global reset */
95 96
96 /* 97 /*
97 * Port registers 98 * Port registers
@@ -338,6 +339,7 @@ static int sil24_port_start(struct ata_port *ap);
338static void sil24_port_stop(struct ata_port *ap); 339static void sil24_port_stop(struct ata_port *ap);
339static void sil24_host_stop(struct ata_host_set *host_set); 340static void sil24_host_stop(struct ata_host_set *host_set);
340static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 341static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
342static int sil24_pci_device_resume(struct pci_dev *pdev);
341 343
342static const struct pci_device_id sil24_pci_tbl[] = { 344static const struct pci_device_id sil24_pci_tbl[] = {
343 { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 }, 345 { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 },
@@ -353,6 +355,8 @@ static struct pci_driver sil24_pci_driver = {
353 .id_table = sil24_pci_tbl, 355 .id_table = sil24_pci_tbl,
354 .probe = sil24_init_one, 356 .probe = sil24_init_one,
355 .remove = ata_pci_remove_one, /* safe? */ 357 .remove = ata_pci_remove_one, /* safe? */
358 .suspend = ata_pci_device_suspend,
359 .resume = sil24_pci_device_resume,
356}; 360};
357 361
358static struct scsi_host_template sil24_sht = { 362static struct scsi_host_template sil24_sht = {
@@ -372,6 +376,8 @@ static struct scsi_host_template sil24_sht = {
372 .slave_configure = ata_scsi_slave_config, 376 .slave_configure = ata_scsi_slave_config,
373 .slave_destroy = ata_scsi_slave_destroy, 377 .slave_destroy = ata_scsi_slave_destroy,
374 .bios_param = ata_std_bios_param, 378 .bios_param = ata_std_bios_param,
379 .suspend = ata_scsi_device_suspend,
380 .resume = ata_scsi_device_resume,
375}; 381};
376 382
377static const struct ata_port_operations sil24_ops = { 383static const struct ata_port_operations sil24_ops = {
@@ -607,7 +613,7 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
607 /* SStatus oscillates between zero and valid status after 613 /* SStatus oscillates between zero and valid status after
608 * DEV_RST, debounce it. 614 * DEV_RST, debounce it.
609 */ 615 */
610 rc = sata_phy_debounce(ap, sata_deb_timing_before_fsrst); 616 rc = sata_phy_debounce(ap, sata_deb_timing_long);
611 if (rc) { 617 if (rc) {
612 reason = "PHY debouncing failed"; 618 reason = "PHY debouncing failed";
613 goto err; 619 goto err;
@@ -988,6 +994,64 @@ static void sil24_host_stop(struct ata_host_set *host_set)
988 kfree(hpriv); 994 kfree(hpriv);
989} 995}
990 996
997static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
998 unsigned long host_flags,
999 void __iomem *host_base,
1000 void __iomem *port_base)
1001{
1002 u32 tmp;
1003 int i;
1004
1005 /* GPIO off */
1006 writel(0, host_base + HOST_FLASH_CMD);
1007
1008 /* clear global reset & mask interrupts during initialization */
1009 writel(0, host_base + HOST_CTRL);
1010
1011 /* init ports */
1012 for (i = 0; i < n_ports; i++) {
1013 void __iomem *port = port_base + i * PORT_REGS_SIZE;
1014
1015 /* Initial PHY setting */
1016 writel(0x20c, port + PORT_PHY_CFG);
1017
1018 /* Clear port RST */
1019 tmp = readl(port + PORT_CTRL_STAT);
1020 if (tmp & PORT_CS_PORT_RST) {
1021 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
1022 tmp = ata_wait_register(port + PORT_CTRL_STAT,
1023 PORT_CS_PORT_RST,
1024 PORT_CS_PORT_RST, 10, 100);
1025 if (tmp & PORT_CS_PORT_RST)
1026 dev_printk(KERN_ERR, &pdev->dev,
1027 "failed to clear port RST\n");
1028 }
1029
1030 /* Configure IRQ WoC */
1031 if (host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
1032 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
1033 else
1034 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
1035
1036 /* Zero error counters. */
1037 writel(0x8000, port + PORT_DECODE_ERR_THRESH);
1038 writel(0x8000, port + PORT_CRC_ERR_THRESH);
1039 writel(0x8000, port + PORT_HSHK_ERR_THRESH);
1040 writel(0x0000, port + PORT_DECODE_ERR_CNT);
1041 writel(0x0000, port + PORT_CRC_ERR_CNT);
1042 writel(0x0000, port + PORT_HSHK_ERR_CNT);
1043
1044 /* Always use 64bit activation */
1045 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
1046
1047 /* Clear port multiplier enable and resume bits */
1048 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
1049 }
1050
1051 /* Turn on interrupts */
1052 writel(IRQ_STAT_4PORTS, host_base + HOST_CTRL);
1053}
1054
991static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1055static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
992{ 1056{
993 static int printed_version = 0; 1057 static int printed_version = 0;
@@ -1076,9 +1140,6 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1076 } 1140 }
1077 } 1141 }
1078 1142
1079 /* GPIO off */
1080 writel(0, host_base + HOST_FLASH_CMD);
1081
1082 /* Apply workaround for completion IRQ loss on PCI-X errata */ 1143 /* Apply workaround for completion IRQ loss on PCI-X errata */
1083 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC) { 1144 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC) {
1084 tmp = readl(host_base + HOST_CTRL); 1145 tmp = readl(host_base + HOST_CTRL);
@@ -1090,56 +1151,18 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1090 probe_ent->host_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC; 1151 probe_ent->host_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC;
1091 } 1152 }
1092 1153
1093 /* clear global reset & mask interrupts during initialization */
1094 writel(0, host_base + HOST_CTRL);
1095
1096 for (i = 0; i < probe_ent->n_ports; i++) { 1154 for (i = 0; i < probe_ent->n_ports; i++) {
1097 void __iomem *port = port_base + i * PORT_REGS_SIZE; 1155 unsigned long portu =
1098 unsigned long portu = (unsigned long)port; 1156 (unsigned long)port_base + i * PORT_REGS_SIZE;
1099 1157
1100 probe_ent->port[i].cmd_addr = portu; 1158 probe_ent->port[i].cmd_addr = portu;
1101 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL; 1159 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL;
1102 1160
1103 ata_std_ports(&probe_ent->port[i]); 1161 ata_std_ports(&probe_ent->port[i]);
1104
1105 /* Initial PHY setting */
1106 writel(0x20c, port + PORT_PHY_CFG);
1107
1108 /* Clear port RST */
1109 tmp = readl(port + PORT_CTRL_STAT);
1110 if (tmp & PORT_CS_PORT_RST) {
1111 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
1112 tmp = ata_wait_register(port + PORT_CTRL_STAT,
1113 PORT_CS_PORT_RST,
1114 PORT_CS_PORT_RST, 10, 100);
1115 if (tmp & PORT_CS_PORT_RST)
1116 dev_printk(KERN_ERR, &pdev->dev,
1117 "failed to clear port RST\n");
1118 }
1119
1120 /* Configure IRQ WoC */
1121 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
1122 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
1123 else
1124 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
1125
1126 /* Zero error counters. */
1127 writel(0x8000, port + PORT_DECODE_ERR_THRESH);
1128 writel(0x8000, port + PORT_CRC_ERR_THRESH);
1129 writel(0x8000, port + PORT_HSHK_ERR_THRESH);
1130 writel(0x0000, port + PORT_DECODE_ERR_CNT);
1131 writel(0x0000, port + PORT_CRC_ERR_CNT);
1132 writel(0x0000, port + PORT_HSHK_ERR_CNT);
1133
1134 /* Always use 64bit activation */
1135 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
1136
1137 /* Clear port multiplier enable and resume bits */
1138 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
1139 } 1162 }
1140 1163
1141 /* Turn on interrupts */ 1164 sil24_init_controller(pdev, probe_ent->n_ports, probe_ent->host_flags,
1142 writel(IRQ_STAT_4PORTS, host_base + HOST_CTRL); 1165 host_base, port_base);
1143 1166
1144 pci_set_master(pdev); 1167 pci_set_master(pdev);
1145 1168
@@ -1162,6 +1185,25 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1162 return rc; 1185 return rc;
1163} 1186}
1164 1187
1188static int sil24_pci_device_resume(struct pci_dev *pdev)
1189{
1190 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
1191 struct sil24_host_priv *hpriv = host_set->private_data;
1192
1193 ata_pci_device_do_resume(pdev);
1194
1195 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND)
1196 writel(HOST_CTRL_GLOBAL_RST, hpriv->host_base + HOST_CTRL);
1197
1198 sil24_init_controller(pdev, host_set->n_ports,
1199 host_set->ports[0]->flags,
1200 hpriv->host_base, hpriv->port_base);
1201
1202 ata_host_set_resume(host_set);
1203
1204 return 0;
1205}
1206
1165static int __init sil24_init(void) 1207static int __init sil24_init(void)
1166{ 1208{
1167 return pci_module_init(&sil24_pci_driver); 1209 return pci_module_init(&sil24_pci_driver);
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 916fe6fba756..ad37871594f5 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -297,7 +297,7 @@ static const struct ata_port_operations vsc_sata_ops = {
297 .bmdma_status = ata_bmdma_status, 297 .bmdma_status = ata_bmdma_status,
298 .qc_prep = ata_qc_prep, 298 .qc_prep = ata_qc_prep,
299 .qc_issue = ata_qc_issue_prot, 299 .qc_issue = ata_qc_issue_prot,
300 .data_xfer = ata_pio_data_xfer, 300 .data_xfer = ata_mmio_data_xfer,
301 .freeze = ata_bmdma_freeze, 301 .freeze = ata_bmdma_freeze,
302 .thaw = ata_bmdma_thaw, 302 .thaw = ata_bmdma_thaw,
303 .error_handler = ata_bmdma_error_handler, 303 .error_handler = ata_bmdma_error_handler,
diff --git a/drivers/serial/at91_serial.c b/drivers/serial/at91_serial.c
index a7d664383dae..54c6b2adf7b7 100644
--- a/drivers/serial/at91_serial.c
+++ b/drivers/serial/at91_serial.c
@@ -41,6 +41,7 @@
41#include <asm/mach/serial_at91.h> 41#include <asm/mach/serial_at91.h>
42#include <asm/arch/board.h> 42#include <asm/arch/board.h>
43#include <asm/arch/system.h> 43#include <asm/arch/system.h>
44#include <asm/arch/gpio.h>
44 45
45#if defined(CONFIG_SERIAL_AT91_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 46#if defined(CONFIG_SERIAL_AT91_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
46#define SUPPORT_SYSRQ 47#define SUPPORT_SYSRQ
@@ -140,9 +141,9 @@ static void at91_set_mctrl(struct uart_port *port, u_int mctrl)
140 */ 141 */
141 if (port->mapbase == AT91_BASE_US0) { 142 if (port->mapbase == AT91_BASE_US0) {
142 if (mctrl & TIOCM_RTS) 143 if (mctrl & TIOCM_RTS)
143 at91_sys_write(AT91_PIOA + PIO_CODR, AT91_PA21_RTS0); 144 at91_set_gpio_value(AT91_PIN_PA21, 0);
144 else 145 else
145 at91_sys_write(AT91_PIOA + PIO_SODR, AT91_PA21_RTS0); 146 at91_set_gpio_value(AT91_PIN_PA21, 1);
146 } 147 }
147 } 148 }
148 149