aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r--drivers/scsi/libata-core.c325
1 files changed, 194 insertions, 131 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 1c960ac1617f..73dd6c8deede 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
@@ -2738,7 +2746,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
2738 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 2746 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
2739 return rc; 2747 return rc;
2740 2748
2741 scontrol = (scontrol & 0x0f0) | 0x302; 2749 scontrol = (scontrol & 0x0f0) | 0x304;
2742 2750
2743 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol))) 2751 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
2744 return rc; 2752 return rc;
@@ -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;
5077
5078 rc = ata_host_set_request_pm(host_set, mesg, 0, ATA_EHI_QUIET, 1);
5079 if (rc)
5080 goto fail;
5044 5081
5045 if (ap->flags & ATA_FLAG_SUSPENDED) { 5082 /* EH is quiescent now. Fail if we have any ready device.
5046 struct ata_device *failed_dev; 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];
5047 5088
5048 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 5089 for (j = 0; j < ATA_MAX_DEVICES; j++) {
5049 ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 200000); 5090 struct ata_device *dev = &ap->device[j];
5050 5091
5051 ap->flags &= ~ATA_FLAG_SUSPENDED; 5092 if (ata_dev_ready(dev)) {
5052 while (ata_set_mode(ap, &failed_dev)) 5093 ata_port_printk(ap, KERN_WARNING,
5053 ata_dev_disable(failed_dev); 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
5067 * 5113 *
5068 * Flush the cache on the drive, if appropriate, then issue a 5114 * Resume @host_set. Actual operation is performed by EH. This
5069 * standbynow command. 5115 * function requests EH to perform PM operations and returns.
5116 * Note that all resume operations are performed parallely.
5117 *
5118 * LOCKING:
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/**
@@ -5143,28 +5185,6 @@ void ata_host_stop (struct ata_host_set *host_set)
5143 iounmap(host_set->mmio_base); 5185 iounmap(host_set->mmio_base);
5144} 5186}
5145 5187
5146
5147/**
5148 * ata_host_remove - Unregister SCSI host structure with upper layers
5149 * @ap: Port to unregister
5150 * @do_unregister: 1 if we fully unregister, 0 to just stop the port
5151 *
5152 * LOCKING:
5153 * Inherited from caller.
5154 */
5155
5156static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister)
5157{
5158 struct Scsi_Host *sh = ap->host;
5159
5160 DPRINTK("ENTER\n");
5161
5162 if (do_unregister)
5163 scsi_remove_host(sh);
5164
5165 ap->ops->port_stop(ap);
5166}
5167
5168/** 5188/**
5169 * ata_dev_init - Initialize an ata_device structure 5189 * ata_dev_init - Initialize an ata_device structure
5170 * @dev: Device structure to initialize 5190 * @dev: Device structure to initialize
@@ -5440,6 +5460,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
5440 } 5460 }
5441 5461
5442 if (ap->ops->error_handler) { 5462 if (ap->ops->error_handler) {
5463 struct ata_eh_info *ehi = &ap->eh_info;
5443 unsigned long flags; 5464 unsigned long flags;
5444 5465
5445 ata_port_probe(ap); 5466 ata_port_probe(ap);
@@ -5447,10 +5468,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
5447 /* kick EH for boot probing */ 5468 /* kick EH for boot probing */
5448 spin_lock_irqsave(ap->lock, flags); 5469 spin_lock_irqsave(ap->lock, flags);
5449 5470
5450 ap->eh_info.probe_mask = (1 << ATA_MAX_DEVICES) - 1; 5471 ehi->probe_mask = (1 << ATA_MAX_DEVICES) - 1;
5451 ap->eh_info.action |= ATA_EH_SOFTRESET; 5472 ehi->action |= ATA_EH_SOFTRESET;
5473 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
5452 5474
5453 ap->flags |= ATA_FLAG_LOADING; 5475 ap->pflags |= ATA_PFLAG_LOADING;
5454 ata_port_schedule_eh(ap); 5476 ata_port_schedule_eh(ap);
5455 5477
5456 spin_unlock_irqrestore(ap->lock, flags); 5478 spin_unlock_irqrestore(ap->lock, flags);
@@ -5488,8 +5510,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
5488 5510
5489err_out: 5511err_out:
5490 for (i = 0; i < count; i++) { 5512 for (i = 0; i < count; i++) {
5491 ata_host_remove(host_set->ports[i], 1); 5513 struct ata_port *ap = host_set->ports[i];
5492 scsi_host_put(host_set->ports[i]->host); 5514 if (ap) {
5515 ap->ops->port_stop(ap);
5516 scsi_host_put(ap->host);
5517 }
5493 } 5518 }
5494err_free_ret: 5519err_free_ret:
5495 kfree(host_set); 5520 kfree(host_set);
@@ -5514,11 +5539,11 @@ void ata_port_detach(struct ata_port *ap)
5514 int i; 5539 int i;
5515 5540
5516 if (!ap->ops->error_handler) 5541 if (!ap->ops->error_handler)
5517 return; 5542 goto skip_eh;
5518 5543
5519 /* tell EH we're leaving & flush EH */ 5544 /* tell EH we're leaving & flush EH */
5520 spin_lock_irqsave(ap->lock, flags); 5545 spin_lock_irqsave(ap->lock, flags);
5521 ap->flags |= ATA_FLAG_UNLOADING; 5546 ap->pflags |= ATA_PFLAG_UNLOADING;
5522 spin_unlock_irqrestore(ap->lock, flags); 5547 spin_unlock_irqrestore(ap->lock, flags);
5523 5548
5524 ata_port_wait_eh(ap); 5549 ata_port_wait_eh(ap);
@@ -5550,6 +5575,7 @@ void ata_port_detach(struct ata_port *ap)
5550 cancel_delayed_work(&ap->hotplug_task); 5575 cancel_delayed_work(&ap->hotplug_task);
5551 flush_workqueue(ata_aux_wq); 5576 flush_workqueue(ata_aux_wq);
5552 5577
5578 skip_eh:
5553 /* remove the associated SCSI host */ 5579 /* remove the associated SCSI host */
5554 scsi_remove_host(ap->host); 5580 scsi_remove_host(ap->host);
5555} 5581}
@@ -5618,7 +5644,7 @@ int ata_scsi_release(struct Scsi_Host *host)
5618 DPRINTK("ENTER\n"); 5644 DPRINTK("ENTER\n");
5619 5645
5620 ap->ops->port_disable(ap); 5646 ap->ops->port_disable(ap);
5621 ata_host_remove(ap, 0); 5647 ap->ops->port_stop(ap);
5622 5648
5623 DPRINTK("EXIT\n"); 5649 DPRINTK("EXIT\n");
5624 return 1; 5650 return 1;
@@ -5723,20 +5749,55 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
5723 return (tmp == bits->val) ? 1 : 0; 5749 return (tmp == bits->val) ? 1 : 0;
5724} 5750}
5725 5751
5726int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state) 5752void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t state)
5727{ 5753{
5728 pci_save_state(pdev); 5754 pci_save_state(pdev);
5729 pci_disable_device(pdev); 5755
5730 pci_set_power_state(pdev, PCI_D3hot); 5756 if (state.event == PM_EVENT_SUSPEND) {
5731 return 0; 5757 pci_disable_device(pdev);
5758 pci_set_power_state(pdev, PCI_D3hot);
5759 }
5732} 5760}
5733 5761
5734int ata_pci_device_resume(struct pci_dev *pdev) 5762void ata_pci_device_do_resume(struct pci_dev *pdev)
5735{ 5763{
5736 pci_set_power_state(pdev, PCI_D0); 5764 pci_set_power_state(pdev, PCI_D0);
5737 pci_restore_state(pdev); 5765 pci_restore_state(pdev);
5738 pci_enable_device(pdev); 5766 pci_enable_device(pdev);
5739 pci_set_master(pdev); 5767 pci_set_master(pdev);
5768}
5769
5770int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
5771{
5772 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
5773 int rc = 0;
5774
5775 rc = ata_host_set_suspend(host_set, state);
5776 if (rc)
5777 return rc;
5778
5779 if (host_set->next) {
5780 rc = ata_host_set_suspend(host_set->next, state);
5781 if (rc) {
5782 ata_host_set_resume(host_set);
5783 return rc;
5784 }
5785 }
5786
5787 ata_pci_device_do_suspend(pdev, state);
5788
5789 return 0;
5790}
5791
5792int ata_pci_device_resume(struct pci_dev *pdev)
5793{
5794 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
5795
5796 ata_pci_device_do_resume(pdev);
5797 ata_host_set_resume(host_set);
5798 if (host_set->next)
5799 ata_host_set_resume(host_set->next);
5800
5740 return 0; 5801 return 0;
5741} 5802}
5742#endif /* CONFIG_PCI */ 5803#endif /* CONFIG_PCI */
@@ -5842,9 +5903,9 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
5842 * Do not depend on ABI/API stability. 5903 * Do not depend on ABI/API stability.
5843 */ 5904 */
5844 5905
5845EXPORT_SYMBOL_GPL(sata_deb_timing_boot); 5906EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
5846EXPORT_SYMBOL_GPL(sata_deb_timing_eh); 5907EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
5847EXPORT_SYMBOL_GPL(sata_deb_timing_before_fsrst); 5908EXPORT_SYMBOL_GPL(sata_deb_timing_long);
5848EXPORT_SYMBOL_GPL(ata_std_bios_param); 5909EXPORT_SYMBOL_GPL(ata_std_bios_param);
5849EXPORT_SYMBOL_GPL(ata_std_ports); 5910EXPORT_SYMBOL_GPL(ata_std_ports);
5850EXPORT_SYMBOL_GPL(ata_device_add); 5911EXPORT_SYMBOL_GPL(ata_device_add);
@@ -5916,6 +5977,8 @@ EXPORT_SYMBOL_GPL(sata_scr_write);
5916EXPORT_SYMBOL_GPL(sata_scr_write_flush); 5977EXPORT_SYMBOL_GPL(sata_scr_write_flush);
5917EXPORT_SYMBOL_GPL(ata_port_online); 5978EXPORT_SYMBOL_GPL(ata_port_online);
5918EXPORT_SYMBOL_GPL(ata_port_offline); 5979EXPORT_SYMBOL_GPL(ata_port_offline);
5980EXPORT_SYMBOL_GPL(ata_host_set_suspend);
5981EXPORT_SYMBOL_GPL(ata_host_set_resume);
5919EXPORT_SYMBOL_GPL(ata_id_string); 5982EXPORT_SYMBOL_GPL(ata_id_string);
5920EXPORT_SYMBOL_GPL(ata_id_c_string); 5983EXPORT_SYMBOL_GPL(ata_id_c_string);
5921EXPORT_SYMBOL_GPL(ata_scsi_simulate); 5984EXPORT_SYMBOL_GPL(ata_scsi_simulate);
@@ -5930,14 +5993,14 @@ EXPORT_SYMBOL_GPL(ata_pci_host_stop);
5930EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); 5993EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
5931EXPORT_SYMBOL_GPL(ata_pci_init_one); 5994EXPORT_SYMBOL_GPL(ata_pci_init_one);
5932EXPORT_SYMBOL_GPL(ata_pci_remove_one); 5995EXPORT_SYMBOL_GPL(ata_pci_remove_one);
5996EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
5997EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
5933EXPORT_SYMBOL_GPL(ata_pci_device_suspend); 5998EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
5934EXPORT_SYMBOL_GPL(ata_pci_device_resume); 5999EXPORT_SYMBOL_GPL(ata_pci_device_resume);
5935EXPORT_SYMBOL_GPL(ata_pci_default_filter); 6000EXPORT_SYMBOL_GPL(ata_pci_default_filter);
5936EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); 6001EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
5937#endif /* CONFIG_PCI */ 6002#endif /* CONFIG_PCI */
5938 6003
5939EXPORT_SYMBOL_GPL(ata_device_suspend);
5940EXPORT_SYMBOL_GPL(ata_device_resume);
5941EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); 6004EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
5942EXPORT_SYMBOL_GPL(ata_scsi_device_resume); 6005EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
5943 6006