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