Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 2 | /* |
| 3 | * scsi_pm.c Copyright (C) 2010 Alan Stern |
| 4 | * |
| 5 | * SCSI dynamic Power Management |
| 6 | * Initial version: Alan Stern <stern@rowland.harvard.edu> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/pm_runtime.h> |
Paul Gortmaker | 0970366 | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 10 | #include <linux/export.h> |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 11 | #include <linux/async.h> |
Bart Van Assche | bca6b06 | 2018-09-26 14:01:03 -0700 | [diff] [blame] | 12 | #include <linux/blk-pm.h> |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 13 | |
| 14 | #include <scsi/scsi.h> |
| 15 | #include <scsi/scsi_device.h> |
| 16 | #include <scsi/scsi_driver.h> |
| 17 | #include <scsi/scsi_host.h> |
| 18 | |
| 19 | #include "scsi_priv.h" |
| 20 | |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 21 | #ifdef CONFIG_PM_SLEEP |
| 22 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 23 | static int do_scsi_suspend(struct device *dev, const struct dev_pm_ops *pm) |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 24 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 25 | return pm && pm->suspend ? pm->suspend(dev) : 0; |
| 26 | } |
| 27 | |
| 28 | static int do_scsi_freeze(struct device *dev, const struct dev_pm_ops *pm) |
| 29 | { |
| 30 | return pm && pm->freeze ? pm->freeze(dev) : 0; |
| 31 | } |
| 32 | |
| 33 | static int do_scsi_poweroff(struct device *dev, const struct dev_pm_ops *pm) |
| 34 | { |
| 35 | return pm && pm->poweroff ? pm->poweroff(dev) : 0; |
| 36 | } |
| 37 | |
| 38 | static int do_scsi_resume(struct device *dev, const struct dev_pm_ops *pm) |
| 39 | { |
| 40 | return pm && pm->resume ? pm->resume(dev) : 0; |
| 41 | } |
| 42 | |
| 43 | static int do_scsi_thaw(struct device *dev, const struct dev_pm_ops *pm) |
| 44 | { |
| 45 | return pm && pm->thaw ? pm->thaw(dev) : 0; |
| 46 | } |
| 47 | |
| 48 | static int do_scsi_restore(struct device *dev, const struct dev_pm_ops *pm) |
| 49 | { |
| 50 | return pm && pm->restore ? pm->restore(dev) : 0; |
| 51 | } |
| 52 | |
| 53 | static int scsi_dev_type_suspend(struct device *dev, |
| 54 | int (*cb)(struct device *, const struct dev_pm_ops *)) |
| 55 | { |
| 56 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 57 | int err; |
| 58 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 59 | /* flush pending in-flight resume operations, suspend is synchronous */ |
| 60 | async_synchronize_full_domain(&scsi_sd_pm_domain); |
| 61 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 62 | err = scsi_device_quiesce(to_scsi_device(dev)); |
| 63 | if (err == 0) { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 64 | err = cb(dev, pm); |
| 65 | if (err) |
| 66 | scsi_device_resume(to_scsi_device(dev)); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 67 | } |
| 68 | dev_dbg(dev, "scsi suspend: %d\n", err); |
| 69 | return err; |
| 70 | } |
| 71 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 72 | static int scsi_dev_type_resume(struct device *dev, |
| 73 | int (*cb)(struct device *, const struct dev_pm_ops *)) |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 74 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 75 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 76 | int err = 0; |
| 77 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 78 | err = cb(dev, pm); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 79 | scsi_device_resume(to_scsi_device(dev)); |
| 80 | dev_dbg(dev, "scsi resume: %d\n", err); |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 81 | |
| 82 | if (err == 0) { |
Can Guo | 05d18ae | 2020-05-05 21:55:35 -0700 | [diff] [blame] | 83 | bool was_runtime_suspended; |
| 84 | |
| 85 | was_runtime_suspended = pm_runtime_suspended(dev); |
| 86 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 87 | pm_runtime_disable(dev); |
Stanley Chu | 3f7e62b | 2019-01-03 22:08:05 +0800 | [diff] [blame] | 88 | err = pm_runtime_set_active(dev); |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 89 | pm_runtime_enable(dev); |
Stanley Chu | 3f7e62b | 2019-01-03 22:08:05 +0800 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Forcibly set runtime PM status of request queue to "active" |
| 93 | * to make sure we can again get requests from the queue |
| 94 | * (see also blk_pm_peek_request()). |
| 95 | * |
| 96 | * The resume hook will correct runtime PM status of the disk. |
| 97 | */ |
| 98 | if (!err && scsi_is_sdev_device(dev)) { |
| 99 | struct scsi_device *sdev = to_scsi_device(dev); |
Can Guo | 05d18ae | 2020-05-05 21:55:35 -0700 | [diff] [blame] | 100 | if (was_runtime_suspended) |
| 101 | blk_post_runtime_resume(sdev->request_queue, 0); |
| 102 | else |
| 103 | blk_set_runtime_active(sdev->request_queue); |
Stanley Chu | 3f7e62b | 2019-01-03 22:08:05 +0800 | [diff] [blame] | 104 | } |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 107 | return err; |
| 108 | } |
| 109 | |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 110 | static int |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 111 | scsi_bus_suspend_common(struct device *dev, |
| 112 | int (*cb)(struct device *, const struct dev_pm_ops *)) |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 113 | { |
| 114 | int err = 0; |
| 115 | |
Lin Ming | 2864051 | 2011-12-05 09:20:25 +0800 | [diff] [blame] | 116 | if (scsi_is_sdev_device(dev)) { |
| 117 | /* |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 118 | * All the high-level SCSI drivers that implement runtime |
| 119 | * PM treat runtime suspend, system suspend, and system |
Oliver Neukum | 9589791 | 2013-09-16 13:28:15 +0200 | [diff] [blame] | 120 | * hibernate nearly identically. In all cases the requirements |
| 121 | * for runtime suspension are stricter. |
Lin Ming | 2864051 | 2011-12-05 09:20:25 +0800 | [diff] [blame] | 122 | */ |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 123 | if (pm_runtime_suspended(dev)) |
| 124 | return 0; |
Lin Ming | 2864051 | 2011-12-05 09:20:25 +0800 | [diff] [blame] | 125 | |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 126 | err = scsi_dev_type_suspend(dev, cb); |
Lin Ming | 2864051 | 2011-12-05 09:20:25 +0800 | [diff] [blame] | 127 | } |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 128 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 129 | return err; |
| 130 | } |
| 131 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 132 | static void async_sdev_resume(void *dev, async_cookie_t cookie) |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 133 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 134 | scsi_dev_type_resume(dev, do_scsi_resume); |
| 135 | } |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 136 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 137 | static void async_sdev_thaw(void *dev, async_cookie_t cookie) |
| 138 | { |
| 139 | scsi_dev_type_resume(dev, do_scsi_thaw); |
| 140 | } |
Aaron Lu | 6334790 | 2012-11-09 15:27:52 +0800 | [diff] [blame] | 141 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 142 | static void async_sdev_restore(void *dev, async_cookie_t cookie) |
| 143 | { |
| 144 | scsi_dev_type_resume(dev, do_scsi_restore); |
| 145 | } |
| 146 | |
| 147 | static int scsi_bus_resume_common(struct device *dev, |
| 148 | int (*cb)(struct device *, const struct dev_pm_ops *)) |
| 149 | { |
| 150 | async_func_t fn; |
| 151 | |
| 152 | if (!scsi_is_sdev_device(dev)) |
| 153 | fn = NULL; |
| 154 | else if (cb == do_scsi_resume) |
| 155 | fn = async_sdev_resume; |
| 156 | else if (cb == do_scsi_thaw) |
| 157 | fn = async_sdev_thaw; |
| 158 | else if (cb == do_scsi_restore) |
| 159 | fn = async_sdev_restore; |
| 160 | else |
| 161 | fn = NULL; |
| 162 | |
| 163 | if (fn) { |
| 164 | async_schedule_domain(fn, dev, &scsi_sd_pm_domain); |
| 165 | |
| 166 | /* |
| 167 | * If a user has disabled async probing a likely reason |
| 168 | * is due to a storage enclosure that does not inject |
| 169 | * staggered spin-ups. For safety, make resume |
| 170 | * synchronous as well in that case. |
| 171 | */ |
| 172 | if (strncmp(scsi_scan_type, "async", 5) != 0) |
| 173 | async_synchronize_full_domain(&scsi_sd_pm_domain); |
| 174 | } else { |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 175 | pm_runtime_disable(dev); |
| 176 | pm_runtime_set_active(dev); |
| 177 | pm_runtime_enable(dev); |
| 178 | } |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 179 | return 0; |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 182 | static int scsi_bus_prepare(struct device *dev) |
| 183 | { |
Bart Van Assche | f049cf1 | 2019-04-30 14:39:18 -0700 | [diff] [blame] | 184 | if (scsi_is_host_device(dev)) { |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 185 | /* Wait until async scanning is finished */ |
| 186 | scsi_complete_async_scans(); |
| 187 | } |
| 188 | return 0; |
| 189 | } |
| 190 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 191 | static int scsi_bus_suspend(struct device *dev) |
| 192 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 193 | return scsi_bus_suspend_common(dev, do_scsi_suspend); |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int scsi_bus_resume(struct device *dev) |
| 197 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 198 | return scsi_bus_resume_common(dev, do_scsi_resume); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static int scsi_bus_freeze(struct device *dev) |
| 202 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 203 | return scsi_bus_suspend_common(dev, do_scsi_freeze); |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static int scsi_bus_thaw(struct device *dev) |
| 207 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 208 | return scsi_bus_resume_common(dev, do_scsi_thaw); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static int scsi_bus_poweroff(struct device *dev) |
| 212 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 213 | return scsi_bus_suspend_common(dev, do_scsi_poweroff); |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static int scsi_bus_restore(struct device *dev) |
| 217 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 218 | return scsi_bus_resume_common(dev, do_scsi_restore); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | #else /* CONFIG_PM_SLEEP */ |
| 222 | |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 223 | #define scsi_bus_prepare NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 224 | #define scsi_bus_suspend NULL |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 225 | #define scsi_bus_resume NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 226 | #define scsi_bus_freeze NULL |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 227 | #define scsi_bus_thaw NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 228 | #define scsi_bus_poweroff NULL |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 229 | #define scsi_bus_restore NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 230 | |
| 231 | #endif /* CONFIG_PM_SLEEP */ |
| 232 | |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 233 | static int sdev_runtime_suspend(struct device *dev) |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 234 | { |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 235 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
| 236 | struct scsi_device *sdev = to_scsi_device(dev); |
Alan Stern | 49718f0 | 2015-08-17 11:02:42 -0400 | [diff] [blame] | 237 | int err = 0; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 238 | |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 239 | err = blk_pre_runtime_suspend(sdev->request_queue); |
| 240 | if (err) |
| 241 | return err; |
| 242 | if (pm && pm->runtime_suspend) |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 243 | err = pm->runtime_suspend(dev); |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 244 | blk_post_runtime_suspend(sdev->request_queue, err); |
| 245 | |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 246 | return err; |
| 247 | } |
| 248 | |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 249 | static int scsi_runtime_suspend(struct device *dev) |
| 250 | { |
| 251 | int err = 0; |
| 252 | |
| 253 | dev_dbg(dev, "scsi_runtime_suspend\n"); |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 254 | if (scsi_is_sdev_device(dev)) |
| 255 | err = sdev_runtime_suspend(dev); |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 256 | |
| 257 | /* Insert hooks here for targets, hosts, and transport classes */ |
| 258 | |
| 259 | return err; |
| 260 | } |
| 261 | |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 262 | static int sdev_runtime_resume(struct device *dev) |
| 263 | { |
| 264 | struct scsi_device *sdev = to_scsi_device(dev); |
| 265 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 266 | int err = 0; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 267 | |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 268 | blk_pre_runtime_resume(sdev->request_queue); |
| 269 | if (pm && pm->runtime_resume) |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 270 | err = pm->runtime_resume(dev); |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 271 | blk_post_runtime_resume(sdev->request_queue, err); |
| 272 | |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 273 | return err; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 274 | } |
| 275 | |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 276 | static int scsi_runtime_resume(struct device *dev) |
| 277 | { |
| 278 | int err = 0; |
| 279 | |
| 280 | dev_dbg(dev, "scsi_runtime_resume\n"); |
| 281 | if (scsi_is_sdev_device(dev)) |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 282 | err = sdev_runtime_resume(dev); |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 283 | |
| 284 | /* Insert hooks here for targets, hosts, and transport classes */ |
| 285 | |
| 286 | return err; |
| 287 | } |
| 288 | |
| 289 | static int scsi_runtime_idle(struct device *dev) |
| 290 | { |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 291 | dev_dbg(dev, "scsi_runtime_idle\n"); |
| 292 | |
| 293 | /* Insert hooks here for targets, hosts, and transport classes */ |
| 294 | |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 295 | if (scsi_is_sdev_device(dev)) { |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 296 | pm_runtime_mark_last_busy(dev); |
| 297 | pm_runtime_autosuspend(dev); |
| 298 | return -EBUSY; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 299 | } |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 300 | |
Rafael J. Wysocki | 45f0a85 | 2013-06-03 21:49:52 +0200 | [diff] [blame] | 301 | return 0; |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | int scsi_autopm_get_device(struct scsi_device *sdev) |
| 305 | { |
| 306 | int err; |
| 307 | |
| 308 | err = pm_runtime_get_sync(&sdev->sdev_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 309 | if (err < 0 && err !=-EACCES) |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 310 | pm_runtime_put_sync(&sdev->sdev_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 311 | else |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 312 | err = 0; |
| 313 | return err; |
| 314 | } |
| 315 | EXPORT_SYMBOL_GPL(scsi_autopm_get_device); |
| 316 | |
| 317 | void scsi_autopm_put_device(struct scsi_device *sdev) |
| 318 | { |
| 319 | pm_runtime_put_sync(&sdev->sdev_gendev); |
| 320 | } |
| 321 | EXPORT_SYMBOL_GPL(scsi_autopm_put_device); |
| 322 | |
| 323 | void scsi_autopm_get_target(struct scsi_target *starget) |
| 324 | { |
| 325 | pm_runtime_get_sync(&starget->dev); |
| 326 | } |
| 327 | |
| 328 | void scsi_autopm_put_target(struct scsi_target *starget) |
| 329 | { |
| 330 | pm_runtime_put_sync(&starget->dev); |
| 331 | } |
| 332 | |
| 333 | int scsi_autopm_get_host(struct Scsi_Host *shost) |
| 334 | { |
| 335 | int err; |
| 336 | |
| 337 | err = pm_runtime_get_sync(&shost->shost_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 338 | if (err < 0 && err !=-EACCES) |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 339 | pm_runtime_put_sync(&shost->shost_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 340 | else |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 341 | err = 0; |
| 342 | return err; |
| 343 | } |
| 344 | |
| 345 | void scsi_autopm_put_host(struct Scsi_Host *shost) |
| 346 | { |
| 347 | pm_runtime_put_sync(&shost->shost_gendev); |
| 348 | } |
| 349 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 350 | const struct dev_pm_ops scsi_bus_pm_ops = { |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 351 | .prepare = scsi_bus_prepare, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 352 | .suspend = scsi_bus_suspend, |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 353 | .resume = scsi_bus_resume, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 354 | .freeze = scsi_bus_freeze, |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 355 | .thaw = scsi_bus_thaw, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 356 | .poweroff = scsi_bus_poweroff, |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 357 | .restore = scsi_bus_restore, |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 358 | .runtime_suspend = scsi_runtime_suspend, |
| 359 | .runtime_resume = scsi_runtime_resume, |
| 360 | .runtime_idle = scsi_runtime_idle, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 361 | }; |