Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'ata-6.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata

Pull ATA fixes from Damien Le Moal:
"A larger than usual set of fixes for 6.6-rc4 due to the unexpected
number of fixes needed to address ATA disks suspend/resume issues.

In more detail:

- Add missing additionalProperties on child nodes to the pata-common
DT bindings (Rob)

- Fix handling of the REPORT SUPPORTED OPERATION CODES command to
ignore reserved bits (Niklas)

- Increase port multiplier soft reset timeout to accomodate slow
devices and avoid issues on wakeup (Matthias)

- A couple of minor code fixes to avoid compilation warnings in
libata-core and libata-eh (me)

- Many patches from me to address suspend/resume issues, and in
particular a potential deadlock on resume due to the SCSI disk
driver resume operation not being synchronized with libata EH port
resume handling.

This is addressed by changing the scsi disk driver disk start/stop
control to allow libata to execute disk suspend (spin down) and
resume (spin up) on its own during system suspend/resume. Runtime
suspend/resume control remains with the SCSI disk driver.

Other fixes include:
- Fix libata power management request issuing to avoid races
- Establish a link between ATA ports and SCSI devices to order PM
operations
- Fix device removal to avoid issues with driver rmmod removal
- Fix synchronization of libata device rescan and SCSI disk resume
operation
- Remove libsas PM operations as suspend/resume is handled
directly by the sas controller resume
- Fix the SCSI disk driver to not issue commands to suspended
disks, thus avoiding potential system lock-up on resume"

* tag 'ata-6.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata:
ata: libata-eh: Fix compilation warning in ata_eh_link_report()
ata: libata-core: Fix compilation warning in ata_dev_config_ncq()
scsi: sd: Do not issue commands to suspended disks on shutdown
ata: libata-core: Do not register PM operations for SAS ports
ata: libata-scsi: Fix delayed scsi_rescan_device() execution
scsi: Do not attempt to rescan suspended devices
ata: libata-scsi: Disable scsi device manage_system_start_stop
scsi: sd: Differentiate system and runtime start/stop management
ata: libata-scsi: link ata port and scsi device
ata: libata-core: Fix port and device removal
ata: libata-core: Fix ata_port_request_pm() locking
ata: libata-sata: increase PMP SRST timeout to 10s
ata: libata-scsi: ignore reserved bits for REPORT SUPPORTED OPERATION CODES
dt-bindings: ata: pata-common: Add missing additionalProperties on child nodes

+381 -79
+1
Documentation/devicetree/bindings/ata/pata-common.yaml
··· 38 38 ID number 0 and the slave drive will have ID number 1. The PATA port 39 39 nodes will be named "ide-port". 40 40 type: object 41 + additionalProperties: false 41 42 42 43 properties: 43 44 reg:
+140 -15
drivers/ata/libata-core.c
··· 1973 1973 } 1974 1974 1975 1975 /** 1976 + * ata_dev_power_set_standby - Set a device power mode to standby 1977 + * @dev: target device 1978 + * 1979 + * Issue a STANDBY IMMEDIATE command to set a device power mode to standby. 1980 + * For an HDD device, this spins down the disks. 1981 + * 1982 + * LOCKING: 1983 + * Kernel thread context (may sleep). 1984 + */ 1985 + void ata_dev_power_set_standby(struct ata_device *dev) 1986 + { 1987 + unsigned long ap_flags = dev->link->ap->flags; 1988 + struct ata_taskfile tf; 1989 + unsigned int err_mask; 1990 + 1991 + /* Issue STANDBY IMMEDIATE command only if supported by the device */ 1992 + if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) 1993 + return; 1994 + 1995 + /* 1996 + * Some odd clown BIOSes issue spindown on power off (ACPI S4 or S5) 1997 + * causing some drives to spin up and down again. For these, do nothing 1998 + * if we are being called on shutdown. 1999 + */ 2000 + if ((ap_flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) && 2001 + system_state == SYSTEM_POWER_OFF) 2002 + return; 2003 + 2004 + if ((ap_flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && 2005 + system_entering_hibernation()) 2006 + return; 2007 + 2008 + ata_tf_init(dev, &tf); 2009 + tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; 2010 + tf.protocol = ATA_PROT_NODATA; 2011 + tf.command = ATA_CMD_STANDBYNOW1; 2012 + 2013 + ata_dev_notice(dev, "Entering standby power mode\n"); 2014 + 2015 + err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); 2016 + if (err_mask) 2017 + ata_dev_err(dev, "STANDBY IMMEDIATE failed (err_mask=0x%x)\n", 2018 + err_mask); 2019 + } 2020 + 2021 + /** 2022 + * ata_dev_power_set_active - Set a device power mode to active 2023 + * @dev: target device 2024 + * 2025 + * Issue a VERIFY command to enter to ensure that the device is in the 2026 + * active power mode. For a spun-down HDD (standby or idle power mode), 2027 + * the VERIFY command will complete after the disk spins up. 2028 + * 2029 + * LOCKING: 2030 + * Kernel thread context (may sleep). 2031 + */ 2032 + void ata_dev_power_set_active(struct ata_device *dev) 2033 + { 2034 + struct ata_taskfile tf; 2035 + unsigned int err_mask; 2036 + 2037 + /* 2038 + * Issue READ VERIFY SECTORS command for 1 sector at lba=0 only 2039 + * if supported by the device. 2040 + */ 2041 + if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) 2042 + return; 2043 + 2044 + ata_tf_init(dev, &tf); 2045 + tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; 2046 + tf.protocol = ATA_PROT_NODATA; 2047 + tf.command = ATA_CMD_VERIFY; 2048 + tf.nsect = 1; 2049 + if (dev->flags & ATA_DFLAG_LBA) { 2050 + tf.flags |= ATA_TFLAG_LBA; 2051 + tf.device |= ATA_LBA; 2052 + } else { 2053 + /* CHS */ 2054 + tf.lbal = 0x1; /* sect */ 2055 + } 2056 + 2057 + ata_dev_notice(dev, "Entering active power mode\n"); 2058 + 2059 + err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); 2060 + if (err_mask) 2061 + ata_dev_err(dev, "VERIFY failed (err_mask=0x%x)\n", 2062 + err_mask); 2063 + } 2064 + 2065 + /** 1976 2066 * ata_read_log_page - read a specific log page 1977 2067 * @dev: target device 1978 2068 * @log: log to read ··· 2619 2529 { 2620 2530 const u16 *id = dev->id; 2621 2531 const char *lba_desc; 2622 - char ncq_desc[24]; 2532 + char ncq_desc[32]; 2623 2533 int ret; 2624 2534 2625 2535 dev->flags |= ATA_DFLAG_LBA; ··· 5127 5037 struct ata_link *link; 5128 5038 unsigned long flags; 5129 5039 5130 - /* Previous resume operation might still be in 5131 - * progress. Wait for PM_PENDING to clear. 5132 - */ 5133 - if (ap->pflags & ATA_PFLAG_PM_PENDING) { 5134 - ata_port_wait_eh(ap); 5135 - WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); 5136 - } 5137 - 5138 - /* request PM ops to EH */ 5139 5040 spin_lock_irqsave(ap->lock, flags); 5140 5041 5042 + /* 5043 + * A previous PM operation might still be in progress. Wait for 5044 + * ATA_PFLAG_PM_PENDING to clear. 5045 + */ 5046 + if (ap->pflags & ATA_PFLAG_PM_PENDING) { 5047 + spin_unlock_irqrestore(ap->lock, flags); 5048 + ata_port_wait_eh(ap); 5049 + spin_lock_irqsave(ap->lock, flags); 5050 + } 5051 + 5052 + /* Request PM operation to EH */ 5141 5053 ap->pm_mesg = mesg; 5142 5054 ap->pflags |= ATA_PFLAG_PM_PENDING; 5143 5055 ata_for_each_link(link, ap, HOST_FIRST) { ··· 5151 5059 5152 5060 spin_unlock_irqrestore(ap->lock, flags); 5153 5061 5154 - if (!async) { 5062 + if (!async) 5155 5063 ata_port_wait_eh(ap); 5156 - WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); 5157 - } 5158 5064 } 5159 5065 5160 5066 /* ··· 5168 5078 5169 5079 static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg) 5170 5080 { 5081 + /* 5082 + * We are about to suspend the port, so we do not care about 5083 + * scsi_rescan_device() calls scheduled by previous resume operations. 5084 + * The next resume will schedule the rescan again. So cancel any rescan 5085 + * that is not done yet. 5086 + */ 5087 + cancel_delayed_work_sync(&ap->scsi_rescan_task); 5088 + 5171 5089 ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, false); 5172 5090 } 5173 5091 5174 5092 static void ata_port_suspend_async(struct ata_port *ap, pm_message_t mesg) 5175 5093 { 5094 + /* 5095 + * We are about to suspend the port, so we do not care about 5096 + * scsi_rescan_device() calls scheduled by previous resume operations. 5097 + * The next resume will schedule the rescan again. So cancel any rescan 5098 + * that is not done yet. 5099 + */ 5100 + cancel_delayed_work_sync(&ap->scsi_rescan_task); 5101 + 5176 5102 ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, true); 5177 5103 } 5178 5104 ··· 5335 5229 #endif 5336 5230 5337 5231 const struct device_type ata_port_type = { 5338 - .name = "ata_port", 5232 + .name = ATA_PORT_TYPE_NAME, 5339 5233 #ifdef CONFIG_PM 5340 5234 .pm = &ata_port_pm_ops, 5341 5235 #endif ··· 6054 5948 struct ata_link *link; 6055 5949 struct ata_device *dev; 6056 5950 6057 - /* tell EH we're leaving & flush EH */ 5951 + /* Wait for any ongoing EH */ 5952 + ata_port_wait_eh(ap); 5953 + 5954 + mutex_lock(&ap->scsi_scan_mutex); 6058 5955 spin_lock_irqsave(ap->lock, flags); 5956 + 5957 + /* Remove scsi devices */ 5958 + ata_for_each_link(link, ap, HOST_FIRST) { 5959 + ata_for_each_dev(dev, link, ALL) { 5960 + if (dev->sdev) { 5961 + spin_unlock_irqrestore(ap->lock, flags); 5962 + scsi_remove_device(dev->sdev); 5963 + spin_lock_irqsave(ap->lock, flags); 5964 + dev->sdev = NULL; 5965 + } 5966 + } 5967 + } 5968 + 5969 + /* Tell EH to disable all devices */ 6059 5970 ap->pflags |= ATA_PFLAG_UNLOADING; 6060 5971 ata_port_schedule_eh(ap); 5972 + 6061 5973 spin_unlock_irqrestore(ap->lock, flags); 5974 + mutex_unlock(&ap->scsi_scan_mutex); 6062 5975 6063 5976 /* wait till EH commits suicide */ 6064 5977 ata_port_wait_eh(ap);
+46 -2
drivers/ata/libata-eh.c
··· 147 147 .timeouts = ata_eh_other_timeouts, }, 148 148 { .commands = CMDS(ATA_CMD_FLUSH, ATA_CMD_FLUSH_EXT), 149 149 .timeouts = ata_eh_flush_timeouts }, 150 + { .commands = CMDS(ATA_CMD_VERIFY), 151 + .timeouts = ata_eh_reset_timeouts }, 150 152 }; 151 153 #undef CMDS 152 154 ··· 500 498 struct ata_device *dev; 501 499 unsigned long flags; 502 500 503 - /* Restore SControl IPM and SPD for the next driver and 501 + /* 502 + * Unless we are restarting, transition all enabled devices to 503 + * standby power mode. 504 + */ 505 + if (system_state != SYSTEM_RESTART) { 506 + ata_for_each_link(link, ap, PMP_FIRST) { 507 + ata_for_each_dev(dev, link, ENABLED) 508 + ata_dev_power_set_standby(dev); 509 + } 510 + } 511 + 512 + /* 513 + * Restore SControl IPM and SPD for the next driver and 504 514 * disable attached devices. 505 515 */ 506 516 ata_for_each_link(link, ap, PMP_FIRST) { ··· 698 684 ehc->saved_xfer_mode[devno] = dev->xfer_mode; 699 685 if (ata_ncq_enabled(dev)) 700 686 ehc->saved_ncq_enabled |= 1 << devno; 687 + 688 + /* If we are resuming, wake up the device */ 689 + if (ap->pflags & ATA_PFLAG_RESUMING) 690 + ehc->i.dev_action[devno] |= ATA_EH_SET_ACTIVE; 701 691 } 702 692 } 703 693 ··· 760 742 761 743 /* clean up */ 762 744 spin_lock_irqsave(ap->lock, flags); 745 + 746 + ap->pflags &= ~ATA_PFLAG_RESUMING; 763 747 764 748 if (ap->pflags & ATA_PFLAG_LOADING) 765 749 ap->pflags &= ~ATA_PFLAG_LOADING; ··· 1237 1217 struct ata_port *ap = link->ap; 1238 1218 struct ata_eh_context *ehc = &link->eh_context; 1239 1219 unsigned long flags; 1220 + 1221 + /* 1222 + * If the device is still enabled, transition it to standby power mode 1223 + * (i.e. spin down HDDs). 1224 + */ 1225 + if (ata_dev_enabled(dev)) 1226 + ata_dev_power_set_standby(dev); 1240 1227 1241 1228 ata_dev_disable(dev); 1242 1229 ··· 2332 2305 struct ata_eh_context *ehc = &link->eh_context; 2333 2306 struct ata_queued_cmd *qc; 2334 2307 const char *frozen, *desc; 2335 - char tries_buf[6] = ""; 2308 + char tries_buf[16] = ""; 2336 2309 int tag, nr_failed = 0; 2337 2310 2338 2311 if (ehc->i.flags & ATA_EHI_QUIET) ··· 3042 3015 3043 3016 if (ehc->i.flags & ATA_EHI_DID_RESET) 3044 3017 readid_flags |= ATA_READID_POSTRESET; 3018 + 3019 + /* 3020 + * When resuming, before executing any command, make sure to 3021 + * transition the device to the active power mode. 3022 + */ 3023 + if ((action & ATA_EH_SET_ACTIVE) && ata_dev_enabled(dev)) { 3024 + ata_dev_power_set_active(dev); 3025 + ata_eh_done(link, dev, ATA_EH_SET_ACTIVE); 3026 + } 3045 3027 3046 3028 if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { 3047 3029 WARN_ON(dev->class == ATA_DEV_PMP); ··· 4025 3989 unsigned long flags; 4026 3990 int rc = 0; 4027 3991 struct ata_device *dev; 3992 + struct ata_link *link; 4028 3993 4029 3994 /* are we suspending? */ 4030 3995 spin_lock_irqsave(ap->lock, flags); ··· 4037 4000 spin_unlock_irqrestore(ap->lock, flags); 4038 4001 4039 4002 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); 4003 + 4004 + /* Set all devices attached to the port in standby mode */ 4005 + ata_for_each_link(link, ap, HOST_FIRST) { 4006 + ata_for_each_dev(dev, link, ENABLED) 4007 + ata_dev_power_set_standby(dev); 4008 + } 4040 4009 4041 4010 /* 4042 4011 * If we have a ZPODD attached, check its zero ··· 4126 4083 /* update the flags */ 4127 4084 spin_lock_irqsave(ap->lock, flags); 4128 4085 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); 4086 + ap->pflags |= ATA_PFLAG_RESUMING; 4129 4087 spin_unlock_irqrestore(ap->lock, flags); 4130 4088 } 4131 4089 #endif /* CONFIG_PM */
+64 -33
drivers/ata/libata-scsi.c
··· 1050 1050 } 1051 1051 } else { 1052 1052 sdev->sector_size = ata_id_logical_sector_size(dev->id); 1053 + 1053 1054 /* 1054 - * Stop the drive on suspend but do not issue START STOP UNIT 1055 - * on resume as this is not necessary and may fail: the device 1056 - * will be woken up by ata_port_pm_resume() with a port reset 1057 - * and device revalidation. 1055 + * Ask the sd driver to issue START STOP UNIT on runtime suspend 1056 + * and resume only. For system level suspend/resume, devices 1057 + * power state is handled directly by libata EH. 1058 1058 */ 1059 - sdev->manage_start_stop = 1; 1060 - sdev->no_start_on_resume = 1; 1059 + sdev->manage_runtime_start_stop = true; 1061 1060 } 1062 1061 1063 1062 /* ··· 1089 1090 } 1090 1091 1091 1092 /** 1093 + * ata_scsi_slave_alloc - Early setup of SCSI device 1094 + * @sdev: SCSI device to examine 1095 + * 1096 + * This is called from scsi_alloc_sdev() when the scsi device 1097 + * associated with an ATA device is scanned on a port. 1098 + * 1099 + * LOCKING: 1100 + * Defined by SCSI layer. We don't really care. 1101 + */ 1102 + 1103 + int ata_scsi_slave_alloc(struct scsi_device *sdev) 1104 + { 1105 + struct ata_port *ap = ata_shost_to_port(sdev->host); 1106 + struct device_link *link; 1107 + 1108 + ata_scsi_sdev_config(sdev); 1109 + 1110 + /* 1111 + * Create a link from the ata_port device to the scsi device to ensure 1112 + * that PM does suspend/resume in the correct order: the scsi device is 1113 + * consumer (child) and the ata port the supplier (parent). 1114 + */ 1115 + link = device_link_add(&sdev->sdev_gendev, &ap->tdev, 1116 + DL_FLAG_STATELESS | 1117 + DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE); 1118 + if (!link) { 1119 + ata_port_err(ap, "Failed to create link to scsi device %s\n", 1120 + dev_name(&sdev->sdev_gendev)); 1121 + return -ENODEV; 1122 + } 1123 + 1124 + return 0; 1125 + } 1126 + EXPORT_SYMBOL_GPL(ata_scsi_slave_alloc); 1127 + 1128 + /** 1092 1129 * ata_scsi_slave_config - Set SCSI device attributes 1093 1130 * @sdev: SCSI device to examine 1094 1131 * ··· 1140 1105 { 1141 1106 struct ata_port *ap = ata_shost_to_port(sdev->host); 1142 1107 struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); 1143 - int rc = 0; 1144 - 1145 - ata_scsi_sdev_config(sdev); 1146 1108 1147 1109 if (dev) 1148 - rc = ata_scsi_dev_config(sdev, dev); 1110 + return ata_scsi_dev_config(sdev, dev); 1149 1111 1150 - return rc; 1112 + return 0; 1151 1113 } 1152 1114 EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 1153 1115 ··· 1167 1135 struct ata_port *ap = ata_shost_to_port(sdev->host); 1168 1136 unsigned long flags; 1169 1137 struct ata_device *dev; 1138 + 1139 + device_link_remove(&sdev->sdev_gendev, &ap->tdev); 1170 1140 1171 1141 spin_lock_irqsave(ap->lock, flags); 1172 1142 dev = __ata_scsi_find_dev(ap, sdev); ··· 1229 1195 } 1230 1196 1231 1197 if (cdb[4] & 0x1) { 1232 - tf->nsect = 1; /* 1 sector, lba=0 */ 1198 + tf->nsect = 1; /* 1 sector, lba=0 */ 1233 1199 1234 1200 if (qc->dev->flags & ATA_DFLAG_LBA) { 1235 1201 tf->flags |= ATA_TFLAG_LBA; ··· 1245 1211 tf->lbah = 0x0; /* cyl high */ 1246 1212 } 1247 1213 1248 - tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ 1214 + tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ 1249 1215 } else { 1250 1216 /* Some odd clown BIOSen issue spindown on power off (ACPI S4 1251 1217 * or S5) causing some drives to spin up and down again. ··· 1255 1221 goto skip; 1256 1222 1257 1223 if ((qc->ap->flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && 1258 - system_entering_hibernation()) 1224 + system_entering_hibernation()) 1259 1225 goto skip; 1260 1226 1261 1227 /* Issue ATA STANDBY IMMEDIATE command */ ··· 4349 4315 break; 4350 4316 4351 4317 case MAINTENANCE_IN: 4352 - if (scsicmd[1] == MI_REPORT_SUPPORTED_OPERATION_CODES) 4318 + if ((scsicmd[1] & 0x1f) == MI_REPORT_SUPPORTED_OPERATION_CODES) 4353 4319 ata_scsi_rbuf_fill(&args, ata_scsiop_maint_in); 4354 4320 else 4355 4321 ata_scsi_set_invalid_field(dev, cmd, 1, 0xff); ··· 4759 4725 struct ata_link *link; 4760 4726 struct ata_device *dev; 4761 4727 unsigned long flags; 4762 - bool delay_rescan = false; 4728 + int ret = 0; 4763 4729 4764 4730 mutex_lock(&ap->scsi_scan_mutex); 4765 4731 spin_lock_irqsave(ap->lock, flags); ··· 4768 4734 ata_for_each_dev(dev, link, ENABLED) { 4769 4735 struct scsi_device *sdev = dev->sdev; 4770 4736 4737 + /* 4738 + * If the port was suspended before this was scheduled, 4739 + * bail out. 4740 + */ 4741 + if (ap->pflags & ATA_PFLAG_SUSPENDED) 4742 + goto unlock; 4743 + 4771 4744 if (!sdev) 4772 4745 continue; 4773 4746 if (scsi_device_get(sdev)) 4774 4747 continue; 4775 4748 4776 - /* 4777 - * If the rescan work was scheduled because of a resume 4778 - * event, the port is already fully resumed, but the 4779 - * SCSI device may not yet be fully resumed. In such 4780 - * case, executing scsi_rescan_device() may cause a 4781 - * deadlock with the PM code on device_lock(). Prevent 4782 - * this by giving up and retrying rescan after a short 4783 - * delay. 4784 - */ 4785 - delay_rescan = sdev->sdev_gendev.power.is_suspended; 4786 - if (delay_rescan) { 4787 - scsi_device_put(sdev); 4788 - break; 4789 - } 4790 - 4791 4749 spin_unlock_irqrestore(ap->lock, flags); 4792 - scsi_rescan_device(sdev); 4750 + ret = scsi_rescan_device(sdev); 4793 4751 scsi_device_put(sdev); 4794 4752 spin_lock_irqsave(ap->lock, flags); 4753 + 4754 + if (ret) 4755 + goto unlock; 4795 4756 } 4796 4757 } 4797 4758 4759 + unlock: 4798 4760 spin_unlock_irqrestore(ap->lock, flags); 4799 4761 mutex_unlock(&ap->scsi_scan_mutex); 4800 4762 4801 - if (delay_rescan) 4763 + /* Reschedule with a delay if scsi_rescan_device() returned an error */ 4764 + if (ret) 4802 4765 schedule_delayed_work(&ap->scsi_rescan_task, 4803 4766 msecs_to_jiffies(5)); 4804 4767 }
+8 -1
drivers/ata/libata-transport.c
··· 266 266 put_device(dev); 267 267 } 268 268 269 + static const struct device_type ata_port_sas_type = { 270 + .name = ATA_PORT_TYPE_NAME, 271 + }; 272 + 269 273 /** ata_tport_add - initialize a transport ATA port structure 270 274 * 271 275 * @parent: parent device ··· 287 283 struct device *dev = &ap->tdev; 288 284 289 285 device_initialize(dev); 290 - dev->type = &ata_port_type; 286 + if (ap->flags & ATA_FLAG_SAS_HOST) 287 + dev->type = &ata_port_sas_type; 288 + else 289 + dev->type = &ata_port_type; 291 290 292 291 dev->parent = parent; 293 292 ata_host_get(ap->host);
+4
drivers/ata/libata.h
··· 30 30 ATA_DNXFER_QUIET = (1 << 31), 31 31 }; 32 32 33 + #define ATA_PORT_TYPE_NAME "ata_port" 34 + 33 35 extern atomic_t ata_print_id; 34 36 extern int atapi_passthru16; 35 37 extern int libata_fua; ··· 62 60 extern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class, 63 61 unsigned int readid_flags); 64 62 extern int ata_dev_configure(struct ata_device *dev); 63 + extern void ata_dev_power_set_standby(struct ata_device *dev); 64 + extern void ata_dev_power_set_active(struct ata_device *dev); 65 65 extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); 66 66 extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); 67 67 extern unsigned int ata_dev_set_feature(struct ata_device *dev,
+6 -3
drivers/firewire/sbp2.c
··· 81 81 * 82 82 * - power condition 83 83 * Set the power condition field in the START STOP UNIT commands sent by 84 - * sd_mod on suspend, resume, and shutdown (if manage_start_stop is on). 84 + * sd_mod on suspend, resume, and shutdown (if manage_system_start_stop or 85 + * manage_runtime_start_stop is on). 85 86 * Some disks need this to spin down or to resume properly. 86 87 * 87 88 * - override internal blacklist ··· 1518 1517 1519 1518 sdev->use_10_for_rw = 1; 1520 1519 1521 - if (sbp2_param_exclusive_login) 1522 - sdev->manage_start_stop = 1; 1520 + if (sbp2_param_exclusive_login) { 1521 + sdev->manage_system_start_stop = true; 1522 + sdev->manage_runtime_start_stop = true; 1523 + } 1523 1524 1524 1525 if (sdev->type == TYPE_ROM) 1525 1526 sdev->use_10_for_ms = 1;
+17 -1
drivers/scsi/scsi_scan.c
··· 1619 1619 } 1620 1620 EXPORT_SYMBOL(scsi_add_device); 1621 1621 1622 - void scsi_rescan_device(struct scsi_device *sdev) 1622 + int scsi_rescan_device(struct scsi_device *sdev) 1623 1623 { 1624 1624 struct device *dev = &sdev->sdev_gendev; 1625 + int ret = 0; 1625 1626 1626 1627 device_lock(dev); 1628 + 1629 + /* 1630 + * Bail out if the device is not running. Otherwise, the rescan may 1631 + * block waiting for commands to be executed, with us holding the 1632 + * device lock. This can result in a potential deadlock in the power 1633 + * management core code when system resume is on-going. 1634 + */ 1635 + if (sdev->sdev_state != SDEV_RUNNING) { 1636 + ret = -EWOULDBLOCK; 1637 + goto unlock; 1638 + } 1627 1639 1628 1640 scsi_attach_vpd(sdev); 1629 1641 scsi_cdl_check(sdev); ··· 1650 1638 drv->rescan(dev); 1651 1639 module_put(dev->driver->owner); 1652 1640 } 1641 + 1642 + unlock: 1653 1643 device_unlock(dev); 1644 + 1645 + return ret; 1654 1646 } 1655 1647 EXPORT_SYMBOL(scsi_rescan_device); 1656 1648
+82 -19
drivers/scsi/sd.c
··· 201 201 } 202 202 203 203 static ssize_t 204 - manage_start_stop_show(struct device *dev, struct device_attribute *attr, 205 - char *buf) 204 + manage_start_stop_show(struct device *dev, 205 + struct device_attribute *attr, char *buf) 206 206 { 207 207 struct scsi_disk *sdkp = to_scsi_disk(dev); 208 208 struct scsi_device *sdp = sdkp->device; 209 209 210 - return sprintf(buf, "%u\n", sdp->manage_start_stop); 210 + return sysfs_emit(buf, "%u\n", 211 + sdp->manage_system_start_stop && 212 + sdp->manage_runtime_start_stop); 213 + } 214 + static DEVICE_ATTR_RO(manage_start_stop); 215 + 216 + static ssize_t 217 + manage_system_start_stop_show(struct device *dev, 218 + struct device_attribute *attr, char *buf) 219 + { 220 + struct scsi_disk *sdkp = to_scsi_disk(dev); 221 + struct scsi_device *sdp = sdkp->device; 222 + 223 + return sysfs_emit(buf, "%u\n", sdp->manage_system_start_stop); 211 224 } 212 225 213 226 static ssize_t 214 - manage_start_stop_store(struct device *dev, struct device_attribute *attr, 215 - const char *buf, size_t count) 227 + manage_system_start_stop_store(struct device *dev, 228 + struct device_attribute *attr, 229 + const char *buf, size_t count) 216 230 { 217 231 struct scsi_disk *sdkp = to_scsi_disk(dev); 218 232 struct scsi_device *sdp = sdkp->device; ··· 238 224 if (kstrtobool(buf, &v)) 239 225 return -EINVAL; 240 226 241 - sdp->manage_start_stop = v; 227 + sdp->manage_system_start_stop = v; 242 228 243 229 return count; 244 230 } 245 - static DEVICE_ATTR_RW(manage_start_stop); 231 + static DEVICE_ATTR_RW(manage_system_start_stop); 232 + 233 + static ssize_t 234 + manage_runtime_start_stop_show(struct device *dev, 235 + struct device_attribute *attr, char *buf) 236 + { 237 + struct scsi_disk *sdkp = to_scsi_disk(dev); 238 + struct scsi_device *sdp = sdkp->device; 239 + 240 + return sysfs_emit(buf, "%u\n", sdp->manage_runtime_start_stop); 241 + } 242 + 243 + static ssize_t 244 + manage_runtime_start_stop_store(struct device *dev, 245 + struct device_attribute *attr, 246 + const char *buf, size_t count) 247 + { 248 + struct scsi_disk *sdkp = to_scsi_disk(dev); 249 + struct scsi_device *sdp = sdkp->device; 250 + bool v; 251 + 252 + if (!capable(CAP_SYS_ADMIN)) 253 + return -EACCES; 254 + 255 + if (kstrtobool(buf, &v)) 256 + return -EINVAL; 257 + 258 + sdp->manage_runtime_start_stop = v; 259 + 260 + return count; 261 + } 262 + static DEVICE_ATTR_RW(manage_runtime_start_stop); 246 263 247 264 static ssize_t 248 265 allow_restart_show(struct device *dev, struct device_attribute *attr, char *buf) ··· 605 560 &dev_attr_FUA.attr, 606 561 &dev_attr_allow_restart.attr, 607 562 &dev_attr_manage_start_stop.attr, 563 + &dev_attr_manage_system_start_stop.attr, 564 + &dev_attr_manage_runtime_start_stop.attr, 608 565 &dev_attr_protection_type.attr, 609 566 &dev_attr_protection_mode.attr, 610 567 &dev_attr_app_tag_own.attr, ··· 3741 3694 3742 3695 device_del(&sdkp->disk_dev); 3743 3696 del_gendisk(sdkp->disk); 3744 - sd_shutdown(dev); 3697 + if (!sdkp->suspended) 3698 + sd_shutdown(dev); 3745 3699 3746 3700 put_disk(sdkp->disk); 3747 3701 return 0; ··· 3819 3771 sd_sync_cache(sdkp, NULL); 3820 3772 } 3821 3773 3822 - if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) { 3774 + if (system_state != SYSTEM_RESTART && 3775 + sdkp->device->manage_system_start_stop) { 3823 3776 sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); 3824 3777 sd_start_stop_device(sdkp, 0); 3825 3778 } 3826 3779 } 3827 3780 3828 - static int sd_suspend_common(struct device *dev, bool ignore_stop_errors) 3781 + static inline bool sd_do_start_stop(struct scsi_device *sdev, bool runtime) 3782 + { 3783 + return (sdev->manage_system_start_stop && !runtime) || 3784 + (sdev->manage_runtime_start_stop && runtime); 3785 + } 3786 + 3787 + static int sd_suspend_common(struct device *dev, bool runtime) 3829 3788 { 3830 3789 struct scsi_disk *sdkp = dev_get_drvdata(dev); 3831 3790 struct scsi_sense_hdr sshdr; ··· 3864 3809 } 3865 3810 } 3866 3811 3867 - if (sdkp->device->manage_start_stop) { 3812 + if (sd_do_start_stop(sdkp->device, runtime)) { 3868 3813 if (!sdkp->device->silence_suspend) 3869 3814 sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); 3870 3815 /* an error is not worth aborting a system sleep */ 3871 3816 ret = sd_start_stop_device(sdkp, 0); 3872 - if (ignore_stop_errors) 3817 + if (!runtime) 3873 3818 ret = 0; 3874 3819 } 3820 + 3821 + if (!ret) 3822 + sdkp->suspended = true; 3875 3823 3876 3824 return ret; 3877 3825 } ··· 3884 3826 if (pm_runtime_suspended(dev)) 3885 3827 return 0; 3886 3828 3887 - return sd_suspend_common(dev, true); 3829 + return sd_suspend_common(dev, false); 3888 3830 } 3889 3831 3890 3832 static int sd_suspend_runtime(struct device *dev) 3891 3833 { 3892 - return sd_suspend_common(dev, false); 3834 + return sd_suspend_common(dev, true); 3893 3835 } 3894 3836 3895 - static int sd_resume(struct device *dev) 3837 + static int sd_resume(struct device *dev, bool runtime) 3896 3838 { 3897 3839 struct scsi_disk *sdkp = dev_get_drvdata(dev); 3898 3840 int ret = 0; ··· 3900 3842 if (!sdkp) /* E.g.: runtime resume at the start of sd_probe() */ 3901 3843 return 0; 3902 3844 3903 - if (!sdkp->device->manage_start_stop) 3845 + if (!sd_do_start_stop(sdkp->device, runtime)) { 3846 + sdkp->suspended = false; 3904 3847 return 0; 3848 + } 3905 3849 3906 3850 if (!sdkp->device->no_start_on_resume) { 3907 3851 sd_printk(KERN_NOTICE, sdkp, "Starting disk\n"); 3908 3852 ret = sd_start_stop_device(sdkp, 1); 3909 3853 } 3910 3854 3911 - if (!ret) 3855 + if (!ret) { 3912 3856 opal_unlock_from_suspend(sdkp->opal_dev); 3857 + sdkp->suspended = false; 3858 + } 3859 + 3913 3860 return ret; 3914 3861 } 3915 3862 ··· 3923 3860 if (pm_runtime_suspended(dev)) 3924 3861 return 0; 3925 3862 3926 - return sd_resume(dev); 3863 + return sd_resume(dev, false); 3927 3864 } 3928 3865 3929 3866 static int sd_resume_runtime(struct device *dev) ··· 3950 3887 "Failed to clear sense data\n"); 3951 3888 } 3952 3889 3953 - return sd_resume(dev); 3890 + return sd_resume(dev, true); 3954 3891 } 3955 3892 3956 3893 static const struct dev_pm_ops sd_pm_ops = {
+1
drivers/scsi/sd.h
··· 131 131 u8 provisioning_mode; 132 132 u8 zeroing_mode; 133 133 u8 nr_actuators; /* Number of actuators */ 134 + bool suspended; /* Disk is suspended (stopped) */ 134 135 unsigned ATO : 1; /* state of disk ATO bit */ 135 136 unsigned cache_override : 1; /* temp override of WCE,RCD */ 136 137 unsigned WCE : 1; /* state of disk WCE bit */
+7 -3
include/linux/libata.h
··· 192 192 ATA_PFLAG_UNLOADING = (1 << 9), /* driver is being unloaded */ 193 193 ATA_PFLAG_UNLOADED = (1 << 10), /* driver is unloaded */ 194 194 195 + ATA_PFLAG_RESUMING = (1 << 16), /* port is being resumed */ 195 196 ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */ 196 197 ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */ 197 198 ATA_PFLAG_INIT_GTM_VALID = (1 << 19), /* initial gtm data valid */ ··· 260 259 * advised to wait only for the following duration before 261 260 * doing SRST. 262 261 */ 263 - ATA_TMOUT_PMP_SRST_WAIT = 5000, 262 + ATA_TMOUT_PMP_SRST_WAIT = 10000, 264 263 265 264 /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might 266 265 * be a spurious PHY event, so ignore the first PHY event that ··· 319 318 ATA_EH_ENABLE_LINK = (1 << 3), 320 319 ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */ 321 320 ATA_EH_GET_SUCCESS_SENSE = (1 << 6), /* Get sense data for successful cmd */ 321 + ATA_EH_SET_ACTIVE = (1 << 7), /* Set a device to active power mode */ 322 322 323 323 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK | 324 - ATA_EH_GET_SUCCESS_SENSE, 324 + ATA_EH_GET_SUCCESS_SENSE | ATA_EH_SET_ACTIVE, 325 325 ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET | 326 326 ATA_EH_ENABLE_LINK, 327 327 ··· 359 357 /* This should match the actual table size of 360 358 * ata_eh_cmd_timeout_table in libata-eh.c. 361 359 */ 362 - ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 7, 360 + ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 8, 363 361 364 362 /* Horkage types. May be set by libata or controller on drives 365 363 (some horkage may be drive/controller pair dependent */ ··· 1150 1148 struct block_device *bdev, 1151 1149 sector_t capacity, int geom[]); 1152 1150 extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev); 1151 + extern int ata_scsi_slave_alloc(struct scsi_device *sdev); 1153 1152 extern int ata_scsi_slave_config(struct scsi_device *sdev); 1154 1153 extern void ata_scsi_slave_destroy(struct scsi_device *sdev); 1155 1154 extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, ··· 1399 1396 .this_id = ATA_SHT_THIS_ID, \ 1400 1397 .emulated = ATA_SHT_EMULATED, \ 1401 1398 .proc_name = drv_name, \ 1399 + .slave_alloc = ata_scsi_slave_alloc, \ 1402 1400 .slave_destroy = ata_scsi_slave_destroy, \ 1403 1401 .bios_param = ata_std_bios_param, \ 1404 1402 .unlock_native_capacity = ata_scsi_unlock_native_capacity,\
+4 -1
include/scsi/scsi_device.h
··· 161 161 * pass settings from slave_alloc to scsi 162 162 * core. */ 163 163 unsigned int eh_timeout; /* Error handling timeout */ 164 + 165 + bool manage_system_start_stop; /* Let HLD (sd) manage system start/stop */ 166 + bool manage_runtime_start_stop; /* Let HLD (sd) manage runtime start/stop */ 167 + 164 168 unsigned removable:1; 165 169 unsigned changed:1; /* Data invalid due to media change */ 166 170 unsigned busy:1; /* Used to prevent races */ ··· 197 193 unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */ 198 194 unsigned no_start_on_add:1; /* do not issue start on add */ 199 195 unsigned allow_restart:1; /* issue START_UNIT in error handler */ 200 - unsigned manage_start_stop:1; /* Let HLD (sd) manage start/stop */ 201 196 unsigned no_start_on_resume:1; /* Do not issue START_STOP_UNIT on resume */ 202 197 unsigned start_stop_pwr_cond:1; /* Set power cond. in START_STOP_UNIT */ 203 198 unsigned no_uld_attach:1; /* disable connecting to upper level drivers */
+1 -1
include/scsi/scsi_host.h
··· 764 764 #define scsi_template_proc_dir(sht) NULL 765 765 #endif 766 766 extern void scsi_scan_host(struct Scsi_Host *); 767 - extern void scsi_rescan_device(struct scsi_device *); 767 + extern int scsi_rescan_device(struct scsi_device *sdev); 768 768 extern void scsi_remove_host(struct Scsi_Host *); 769 769 extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *); 770 770 extern int scsi_host_busy(struct Scsi_Host *shost);