diff options
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r-- | drivers/scsi/sd.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 3dda77c31f50..49a94ae3225b 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -147,6 +147,20 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf, | |||
147 | return count; | 147 | return count; |
148 | } | 148 | } |
149 | 149 | ||
150 | static ssize_t sd_store_manage_start_stop(struct class_device *cdev, | ||
151 | const char *buf, size_t count) | ||
152 | { | ||
153 | struct scsi_disk *sdkp = to_scsi_disk(cdev); | ||
154 | struct scsi_device *sdp = sdkp->device; | ||
155 | |||
156 | if (!capable(CAP_SYS_ADMIN)) | ||
157 | return -EACCES; | ||
158 | |||
159 | sdp->manage_start_stop = simple_strtoul(buf, NULL, 10); | ||
160 | |||
161 | return count; | ||
162 | } | ||
163 | |||
150 | static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf, | 164 | static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf, |
151 | size_t count) | 165 | size_t count) |
152 | { | 166 | { |
@@ -179,6 +193,14 @@ static ssize_t sd_show_fua(struct class_device *cdev, char *buf) | |||
179 | return snprintf(buf, 20, "%u\n", sdkp->DPOFUA); | 193 | return snprintf(buf, 20, "%u\n", sdkp->DPOFUA); |
180 | } | 194 | } |
181 | 195 | ||
196 | static ssize_t sd_show_manage_start_stop(struct class_device *cdev, char *buf) | ||
197 | { | ||
198 | struct scsi_disk *sdkp = to_scsi_disk(cdev); | ||
199 | struct scsi_device *sdp = sdkp->device; | ||
200 | |||
201 | return snprintf(buf, 20, "%u\n", sdp->manage_start_stop); | ||
202 | } | ||
203 | |||
182 | static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf) | 204 | static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf) |
183 | { | 205 | { |
184 | struct scsi_disk *sdkp = to_scsi_disk(cdev); | 206 | struct scsi_disk *sdkp = to_scsi_disk(cdev); |
@@ -192,6 +214,8 @@ static struct class_device_attribute sd_disk_attrs[] = { | |||
192 | __ATTR(FUA, S_IRUGO, sd_show_fua, NULL), | 214 | __ATTR(FUA, S_IRUGO, sd_show_fua, NULL), |
193 | __ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart, | 215 | __ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart, |
194 | sd_store_allow_restart), | 216 | sd_store_allow_restart), |
217 | __ATTR(manage_start_stop, S_IRUGO|S_IWUSR, sd_show_manage_start_stop, | ||
218 | sd_store_manage_start_stop), | ||
195 | __ATTR_NULL, | 219 | __ATTR_NULL, |
196 | }; | 220 | }; |
197 | 221 | ||
@@ -208,6 +232,8 @@ static struct scsi_driver sd_template = { | |||
208 | .name = "sd", | 232 | .name = "sd", |
209 | .probe = sd_probe, | 233 | .probe = sd_probe, |
210 | .remove = sd_remove, | 234 | .remove = sd_remove, |
235 | .suspend = sd_suspend, | ||
236 | .resume = sd_resume, | ||
211 | .shutdown = sd_shutdown, | 237 | .shutdown = sd_shutdown, |
212 | }, | 238 | }, |
213 | .rescan = sd_rescan, | 239 | .rescan = sd_rescan, |
@@ -1707,6 +1733,32 @@ static void scsi_disk_release(struct class_device *cdev) | |||
1707 | kfree(sdkp); | 1733 | kfree(sdkp); |
1708 | } | 1734 | } |
1709 | 1735 | ||
1736 | static int sd_start_stop_device(struct scsi_device *sdp, int start) | ||
1737 | { | ||
1738 | unsigned char cmd[6] = { START_STOP }; /* START_VALID */ | ||
1739 | struct scsi_sense_hdr sshdr; | ||
1740 | int res; | ||
1741 | |||
1742 | if (start) | ||
1743 | cmd[4] |= 1; /* START */ | ||
1744 | |||
1745 | if (!scsi_device_online(sdp)) | ||
1746 | return -ENODEV; | ||
1747 | |||
1748 | res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr, | ||
1749 | SD_TIMEOUT, SD_MAX_RETRIES); | ||
1750 | if (res) { | ||
1751 | printk(KERN_WARNING "FAILED\n status = %x, message = %02x, " | ||
1752 | "host = %d, driver = %02x\n ", | ||
1753 | status_byte(res), msg_byte(res), | ||
1754 | host_byte(res), driver_byte(res)); | ||
1755 | if (driver_byte(res) & DRIVER_SENSE) | ||
1756 | scsi_print_sense_hdr("sd", &sshdr); | ||
1757 | } | ||
1758 | |||
1759 | return res; | ||
1760 | } | ||
1761 | |||
1710 | /* | 1762 | /* |
1711 | * Send a SYNCHRONIZE CACHE instruction down to the device through | 1763 | * Send a SYNCHRONIZE CACHE instruction down to the device through |
1712 | * the normal SCSI command structure. Wait for the command to | 1764 | * the normal SCSI command structure. Wait for the command to |
@@ -1714,6 +1766,7 @@ static void scsi_disk_release(struct class_device *cdev) | |||
1714 | */ | 1766 | */ |
1715 | static void sd_shutdown(struct device *dev) | 1767 | static void sd_shutdown(struct device *dev) |
1716 | { | 1768 | { |
1769 | struct scsi_device *sdp = to_scsi_device(dev); | ||
1717 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); | 1770 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); |
1718 | 1771 | ||
1719 | if (!sdkp) | 1772 | if (!sdkp) |
@@ -1723,9 +1776,57 @@ static void sd_shutdown(struct device *dev) | |||
1723 | sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); | 1776 | sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); |
1724 | sd_sync_cache(sdkp); | 1777 | sd_sync_cache(sdkp); |
1725 | } | 1778 | } |
1779 | |||
1780 | if (system_state != SYSTEM_RESTART && sdp->manage_start_stop) { | ||
1781 | printk(KERN_NOTICE "Stopping disk %s: \n", | ||
1782 | sdkp->disk->disk_name); | ||
1783 | sd_start_stop_device(sdp, 0); | ||
1784 | } | ||
1785 | |||
1726 | scsi_disk_put(sdkp); | 1786 | scsi_disk_put(sdkp); |
1727 | } | 1787 | } |
1728 | 1788 | ||
1789 | static int sd_suspend(struct device *dev, pm_message_t mesg) | ||
1790 | { | ||
1791 | struct scsi_device *sdp = to_scsi_device(dev); | ||
1792 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); | ||
1793 | int ret; | ||
1794 | |||
1795 | if (!sdkp) | ||
1796 | return 0; /* this can happen */ | ||
1797 | |||
1798 | if (sdkp->WCE) { | ||
1799 | printk(KERN_NOTICE "Synchronizing SCSI cache for disk %s: \n", | ||
1800 | sdkp->disk->disk_name); | ||
1801 | ret = sd_sync_cache(sdkp); | ||
1802 | if (ret) | ||
1803 | return ret; | ||
1804 | } | ||
1805 | |||
1806 | if (mesg.event == PM_EVENT_SUSPEND && sdp->manage_start_stop) { | ||
1807 | printk(KERN_NOTICE "Stopping disk %s: \n", | ||
1808 | sdkp->disk->disk_name); | ||
1809 | ret = sd_start_stop_device(sdp, 0); | ||
1810 | if (ret) | ||
1811 | return ret; | ||
1812 | } | ||
1813 | |||
1814 | return 0; | ||
1815 | } | ||
1816 | |||
1817 | static int sd_resume(struct device *dev) | ||
1818 | { | ||
1819 | struct scsi_device *sdp = to_scsi_device(dev); | ||
1820 | struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); | ||
1821 | |||
1822 | if (!sdp->manage_start_stop) | ||
1823 | return 0; | ||
1824 | |||
1825 | printk(KERN_NOTICE "Starting disk %s: \n", sdkp->disk->disk_name); | ||
1826 | |||
1827 | return sd_start_stop_device(sdp, 1); | ||
1828 | } | ||
1829 | |||
1729 | /** | 1830 | /** |
1730 | * init_sd - entry point for this driver (both when built in or when | 1831 | * init_sd - entry point for this driver (both when built in or when |
1731 | * a module). | 1832 | * a module). |