diff options
Diffstat (limited to 'drivers/scsi/libata-core.c')
| -rw-r--r-- | drivers/scsi/libata-core.c | 289 |
1 files changed, 185 insertions, 104 deletions
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 } */ |
| 64 | const unsigned long sata_deb_timing_boot[] = { 5, 100, 2000 }; | 64 | const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; |
| 65 | const unsigned long sata_deb_timing_eh[] = { 25, 500, 2000 }; | 65 | const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 }; |
| 66 | const unsigned long sata_deb_timing_before_fsrst[] = { 100, 2000, 5000 }; | 66 | const unsigned long sata_deb_timing_long[] = { 100, 2000, 5000 }; |
| 67 | 67 | ||
| 68 | static unsigned int ata_dev_init_params(struct ata_device *dev, | 68 | static 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 | ||
| 1328 | static 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) | |||
| 2615 | int ata_std_prereset(struct ata_port *ap) | 2625 | int 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 | */ |
| 2725 | int sata_std_hardreset(struct ata_port *ap, unsigned int *class) | 2731 | int 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 | ||
| 5004 | static int ata_standby_drive(struct ata_device *dev) | 5012 | static 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 | ||
| 5018 | static 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 | */ |
| 5041 | int ata_device_resume(struct ata_device *dev) | 5074 | int 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 | */ |
| 5071 | int ata_device_suspend(struct ata_device *dev, pm_message_t state) | 5121 | void 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 | ||
| 5726 | int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state) | 5770 | void 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 | ||
| 5734 | int ata_pci_device_resume(struct pci_dev *pdev) | 5780 | void 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 | |||
| 5788 | int 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 | |||
| 5810 | int 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 | ||
| 5845 | EXPORT_SYMBOL_GPL(sata_deb_timing_boot); | 5924 | EXPORT_SYMBOL_GPL(sata_deb_timing_normal); |
| 5846 | EXPORT_SYMBOL_GPL(sata_deb_timing_eh); | 5925 | EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug); |
| 5847 | EXPORT_SYMBOL_GPL(sata_deb_timing_before_fsrst); | 5926 | EXPORT_SYMBOL_GPL(sata_deb_timing_long); |
| 5848 | EXPORT_SYMBOL_GPL(ata_std_bios_param); | 5927 | EXPORT_SYMBOL_GPL(ata_std_bios_param); |
| 5849 | EXPORT_SYMBOL_GPL(ata_std_ports); | 5928 | EXPORT_SYMBOL_GPL(ata_std_ports); |
| 5850 | EXPORT_SYMBOL_GPL(ata_device_add); | 5929 | EXPORT_SYMBOL_GPL(ata_device_add); |
| @@ -5916,6 +5995,8 @@ EXPORT_SYMBOL_GPL(sata_scr_write); | |||
| 5916 | EXPORT_SYMBOL_GPL(sata_scr_write_flush); | 5995 | EXPORT_SYMBOL_GPL(sata_scr_write_flush); |
| 5917 | EXPORT_SYMBOL_GPL(ata_port_online); | 5996 | EXPORT_SYMBOL_GPL(ata_port_online); |
| 5918 | EXPORT_SYMBOL_GPL(ata_port_offline); | 5997 | EXPORT_SYMBOL_GPL(ata_port_offline); |
| 5998 | EXPORT_SYMBOL_GPL(ata_host_set_suspend); | ||
| 5999 | EXPORT_SYMBOL_GPL(ata_host_set_resume); | ||
| 5919 | EXPORT_SYMBOL_GPL(ata_id_string); | 6000 | EXPORT_SYMBOL_GPL(ata_id_string); |
| 5920 | EXPORT_SYMBOL_GPL(ata_id_c_string); | 6001 | EXPORT_SYMBOL_GPL(ata_id_c_string); |
| 5921 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); | 6002 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
| @@ -5930,14 +6011,14 @@ EXPORT_SYMBOL_GPL(ata_pci_host_stop); | |||
| 5930 | EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); | 6011 | EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); |
| 5931 | EXPORT_SYMBOL_GPL(ata_pci_init_one); | 6012 | EXPORT_SYMBOL_GPL(ata_pci_init_one); |
| 5932 | EXPORT_SYMBOL_GPL(ata_pci_remove_one); | 6013 | EXPORT_SYMBOL_GPL(ata_pci_remove_one); |
| 6014 | EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend); | ||
| 6015 | EXPORT_SYMBOL_GPL(ata_pci_device_do_resume); | ||
| 5933 | EXPORT_SYMBOL_GPL(ata_pci_device_suspend); | 6016 | EXPORT_SYMBOL_GPL(ata_pci_device_suspend); |
| 5934 | EXPORT_SYMBOL_GPL(ata_pci_device_resume); | 6017 | EXPORT_SYMBOL_GPL(ata_pci_device_resume); |
| 5935 | EXPORT_SYMBOL_GPL(ata_pci_default_filter); | 6018 | EXPORT_SYMBOL_GPL(ata_pci_default_filter); |
| 5936 | EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); | 6019 | EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); |
| 5937 | #endif /* CONFIG_PCI */ | 6020 | #endif /* CONFIG_PCI */ |
| 5938 | 6021 | ||
| 5939 | EXPORT_SYMBOL_GPL(ata_device_suspend); | ||
| 5940 | EXPORT_SYMBOL_GPL(ata_device_resume); | ||
| 5941 | EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); | 6022 | EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); |
| 5942 | EXPORT_SYMBOL_GPL(ata_scsi_device_resume); | 6023 | EXPORT_SYMBOL_GPL(ata_scsi_device_resume); |
| 5943 | 6024 | ||
