Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 1 | /* |
| 2 | * scsi_pm.c Copyright (C) 2010 Alan Stern |
| 3 | * |
| 4 | * SCSI dynamic Power Management |
| 5 | * Initial version: Alan Stern <stern@rowland.harvard.edu> |
| 6 | */ |
| 7 | |
| 8 | #include <linux/pm_runtime.h> |
Paul Gortmaker | 0970366 | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 9 | #include <linux/export.h> |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 10 | #include <linux/async.h> |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 11 | |
| 12 | #include <scsi/scsi.h> |
| 13 | #include <scsi/scsi_device.h> |
| 14 | #include <scsi/scsi_driver.h> |
| 15 | #include <scsi/scsi_host.h> |
| 16 | |
| 17 | #include "scsi_priv.h" |
| 18 | |
Subhash Jadavani | 57d6b14 | 2016-07-29 16:50:07 -0700 | [diff] [blame] | 19 | static int do_scsi_runtime_resume(struct device *dev, |
| 20 | const struct dev_pm_ops *pm); |
| 21 | |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 22 | #ifdef CONFIG_PM_SLEEP |
| 23 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 24 | 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] | 25 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 26 | return pm && pm->suspend ? pm->suspend(dev) : 0; |
| 27 | } |
| 28 | |
| 29 | static int do_scsi_freeze(struct device *dev, const struct dev_pm_ops *pm) |
| 30 | { |
| 31 | return pm && pm->freeze ? pm->freeze(dev) : 0; |
| 32 | } |
| 33 | |
| 34 | static int do_scsi_poweroff(struct device *dev, const struct dev_pm_ops *pm) |
| 35 | { |
| 36 | return pm && pm->poweroff ? pm->poweroff(dev) : 0; |
| 37 | } |
| 38 | |
| 39 | static int do_scsi_resume(struct device *dev, const struct dev_pm_ops *pm) |
| 40 | { |
| 41 | return pm && pm->resume ? pm->resume(dev) : 0; |
| 42 | } |
| 43 | |
| 44 | static int do_scsi_thaw(struct device *dev, const struct dev_pm_ops *pm) |
| 45 | { |
| 46 | return pm && pm->thaw ? pm->thaw(dev) : 0; |
| 47 | } |
| 48 | |
| 49 | static int do_scsi_restore(struct device *dev, const struct dev_pm_ops *pm) |
| 50 | { |
| 51 | return pm && pm->restore ? pm->restore(dev) : 0; |
| 52 | } |
| 53 | |
| 54 | static int scsi_dev_type_suspend(struct device *dev, |
| 55 | int (*cb)(struct device *, const struct dev_pm_ops *)) |
| 56 | { |
| 57 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 58 | int err; |
| 59 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 60 | /* flush pending in-flight resume operations, suspend is synchronous */ |
| 61 | async_synchronize_full_domain(&scsi_sd_pm_domain); |
| 62 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 63 | err = scsi_device_quiesce(to_scsi_device(dev)); |
| 64 | if (err == 0) { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 65 | err = cb(dev, pm); |
| 66 | if (err) |
| 67 | scsi_device_resume(to_scsi_device(dev)); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 68 | } |
| 69 | dev_dbg(dev, "scsi suspend: %d\n", err); |
| 70 | return err; |
| 71 | } |
| 72 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 73 | static int scsi_dev_type_resume(struct device *dev, |
| 74 | int (*cb)(struct device *, const struct dev_pm_ops *)) |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 75 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 76 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 77 | int err = 0; |
| 78 | |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 79 | err = cb(dev, pm); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 80 | scsi_device_resume(to_scsi_device(dev)); |
| 81 | dev_dbg(dev, "scsi resume: %d\n", err); |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 82 | |
Subhash Jadavani | 57d6b14 | 2016-07-29 16:50:07 -0700 | [diff] [blame] | 83 | if (err == 0 && (cb != do_scsi_runtime_resume)) { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 84 | pm_runtime_disable(dev); |
Subhash Jadavani | 57d6b14 | 2016-07-29 16:50:07 -0700 | [diff] [blame] | 85 | err = pm_runtime_set_active(dev); |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 86 | pm_runtime_enable(dev); |
Subhash Jadavani | 57d6b14 | 2016-07-29 16:50:07 -0700 | [diff] [blame] | 87 | |
| 88 | if (!err && scsi_is_sdev_device(dev)) { |
| 89 | struct scsi_device *sdev = to_scsi_device(dev); |
| 90 | |
| 91 | /* |
| 92 | * If scsi device runtime PM is managed by block layer |
| 93 | * then we should update request queue's runtime status |
| 94 | * as well. |
| 95 | */ |
| 96 | if (sdev->request_queue->dev) |
| 97 | blk_post_runtime_resume(sdev->request_queue, 0); |
| 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 | { |
| 178 | if (scsi_is_sdev_device(dev)) { |
| 179 | /* sd probing uses async_schedule. Wait until it finishes. */ |
Dan Williams | a7a20d1 | 2012-03-22 17:05:11 -0700 | [diff] [blame] | 180 | async_synchronize_full_domain(&scsi_sd_probe_domain); |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 181 | |
| 182 | } else if (scsi_is_host_device(dev)) { |
| 183 | /* Wait until async scanning is finished */ |
| 184 | scsi_complete_async_scans(); |
| 185 | } |
| 186 | return 0; |
| 187 | } |
| 188 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 189 | static int scsi_bus_suspend(struct device *dev) |
| 190 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 191 | return scsi_bus_suspend_common(dev, do_scsi_suspend); |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static int scsi_bus_resume(struct device *dev) |
| 195 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 196 | return scsi_bus_resume_common(dev, do_scsi_resume); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static int scsi_bus_freeze(struct device *dev) |
| 200 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 201 | return scsi_bus_suspend_common(dev, do_scsi_freeze); |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static int scsi_bus_thaw(struct device *dev) |
| 205 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 206 | return scsi_bus_resume_common(dev, do_scsi_thaw); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static int scsi_bus_poweroff(struct device *dev) |
| 210 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 211 | return scsi_bus_suspend_common(dev, do_scsi_poweroff); |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static int scsi_bus_restore(struct device *dev) |
| 215 | { |
Dan Williams | 3c31b52 | 2014-04-10 15:30:35 -0700 | [diff] [blame] | 216 | return scsi_bus_resume_common(dev, do_scsi_restore); |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | #else /* CONFIG_PM_SLEEP */ |
| 220 | |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 221 | #define scsi_bus_prepare NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 222 | #define scsi_bus_suspend NULL |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 223 | #define scsi_bus_resume NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 224 | #define scsi_bus_freeze NULL |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 225 | #define scsi_bus_thaw NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 226 | #define scsi_bus_poweroff NULL |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 227 | #define scsi_bus_restore NULL |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 228 | |
| 229 | #endif /* CONFIG_PM_SLEEP */ |
| 230 | |
Subhash Jadavani | 57d6b14 | 2016-07-29 16:50:07 -0700 | [diff] [blame] | 231 | static int do_scsi_runtime_suspend(struct device *dev, |
| 232 | const struct dev_pm_ops *pm) |
| 233 | { |
| 234 | return pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0; |
| 235 | } |
| 236 | |
| 237 | static int do_scsi_runtime_resume(struct device *dev, |
| 238 | const struct dev_pm_ops *pm) |
| 239 | { |
| 240 | return pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0; |
| 241 | } |
| 242 | |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 243 | static int sdev_runtime_suspend(struct device *dev) |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 244 | { |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 245 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
| 246 | struct scsi_device *sdev = to_scsi_device(dev); |
Alan Stern | 49718f0 | 2015-08-17 11:02:42 -0400 | [diff] [blame] | 247 | int err = 0; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 248 | |
Subhash Jadavani | 57d6b14 | 2016-07-29 16:50:07 -0700 | [diff] [blame] | 249 | if (!sdev->request_queue->dev) { |
| 250 | err = scsi_dev_type_suspend(dev, do_scsi_runtime_suspend); |
| 251 | if (err == -EAGAIN) |
| 252 | pm_schedule_suspend(dev, jiffies_to_msecs( |
| 253 | round_jiffies_up_relative(HZ/10))); |
| 254 | return err; |
| 255 | } |
| 256 | |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 257 | err = blk_pre_runtime_suspend(sdev->request_queue); |
| 258 | if (err) |
| 259 | return err; |
| 260 | if (pm && pm->runtime_suspend) |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 261 | err = pm->runtime_suspend(dev); |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 262 | blk_post_runtime_suspend(sdev->request_queue, err); |
| 263 | |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 264 | return err; |
| 265 | } |
| 266 | |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 267 | static int scsi_runtime_suspend(struct device *dev) |
| 268 | { |
| 269 | int err = 0; |
| 270 | |
| 271 | dev_dbg(dev, "scsi_runtime_suspend\n"); |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 272 | if (scsi_is_sdev_device(dev)) |
| 273 | err = sdev_runtime_suspend(dev); |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 274 | |
| 275 | /* Insert hooks here for targets, hosts, and transport classes */ |
| 276 | |
| 277 | return err; |
| 278 | } |
| 279 | |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 280 | static int sdev_runtime_resume(struct device *dev) |
| 281 | { |
| 282 | struct scsi_device *sdev = to_scsi_device(dev); |
| 283 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 284 | int err = 0; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 285 | |
Subhash Jadavani | 57d6b14 | 2016-07-29 16:50:07 -0700 | [diff] [blame] | 286 | if (!sdev->request_queue->dev) |
| 287 | return scsi_dev_type_resume(dev, do_scsi_runtime_resume); |
| 288 | |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 289 | blk_pre_runtime_resume(sdev->request_queue); |
| 290 | if (pm && pm->runtime_resume) |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 291 | err = pm->runtime_resume(dev); |
Ken Xue | 1c69d3b | 2015-12-01 14:45:23 +0800 | [diff] [blame] | 292 | blk_post_runtime_resume(sdev->request_queue, err); |
| 293 | |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 294 | return err; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 295 | } |
| 296 | |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 297 | static int scsi_runtime_resume(struct device *dev) |
| 298 | { |
| 299 | int err = 0; |
| 300 | |
| 301 | dev_dbg(dev, "scsi_runtime_resume\n"); |
| 302 | if (scsi_is_sdev_device(dev)) |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 303 | err = sdev_runtime_resume(dev); |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 304 | |
| 305 | /* Insert hooks here for targets, hosts, and transport classes */ |
| 306 | |
| 307 | return err; |
| 308 | } |
| 309 | |
| 310 | static int scsi_runtime_idle(struct device *dev) |
| 311 | { |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 312 | dev_dbg(dev, "scsi_runtime_idle\n"); |
| 313 | |
| 314 | /* Insert hooks here for targets, hosts, and transport classes */ |
| 315 | |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 316 | if (scsi_is_sdev_device(dev)) { |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 317 | pm_runtime_mark_last_busy(dev); |
| 318 | pm_runtime_autosuspend(dev); |
| 319 | return -EBUSY; |
Lin Ming | 6df339a | 2013-03-23 11:42:28 +0800 | [diff] [blame] | 320 | } |
Aaron Lu | 6627b38 | 2013-10-28 15:27:49 +0800 | [diff] [blame] | 321 | |
Rafael J. Wysocki | 45f0a85 | 2013-06-03 21:49:52 +0200 | [diff] [blame] | 322 | return 0; |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | int scsi_autopm_get_device(struct scsi_device *sdev) |
| 326 | { |
| 327 | int err; |
| 328 | |
| 329 | err = pm_runtime_get_sync(&sdev->sdev_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 330 | if (err < 0 && err !=-EACCES) |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 331 | pm_runtime_put_sync(&sdev->sdev_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 332 | else |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 333 | err = 0; |
| 334 | return err; |
| 335 | } |
| 336 | EXPORT_SYMBOL_GPL(scsi_autopm_get_device); |
| 337 | |
| 338 | void scsi_autopm_put_device(struct scsi_device *sdev) |
| 339 | { |
| 340 | pm_runtime_put_sync(&sdev->sdev_gendev); |
| 341 | } |
| 342 | EXPORT_SYMBOL_GPL(scsi_autopm_put_device); |
| 343 | |
| 344 | void scsi_autopm_get_target(struct scsi_target *starget) |
| 345 | { |
| 346 | pm_runtime_get_sync(&starget->dev); |
| 347 | } |
| 348 | |
| 349 | void scsi_autopm_put_target(struct scsi_target *starget) |
| 350 | { |
| 351 | pm_runtime_put_sync(&starget->dev); |
| 352 | } |
| 353 | |
| 354 | int scsi_autopm_get_host(struct Scsi_Host *shost) |
| 355 | { |
| 356 | int err; |
| 357 | |
| 358 | err = pm_runtime_get_sync(&shost->shost_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 359 | if (err < 0 && err !=-EACCES) |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 360 | pm_runtime_put_sync(&shost->shost_gendev); |
Rafael J. Wysocki | 632e270 | 2011-07-01 22:29:15 +0200 | [diff] [blame] | 361 | else |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 362 | err = 0; |
| 363 | return err; |
| 364 | } |
| 365 | |
| 366 | void scsi_autopm_put_host(struct Scsi_Host *shost) |
| 367 | { |
| 368 | pm_runtime_put_sync(&shost->shost_gendev); |
| 369 | } |
| 370 | |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 371 | const struct dev_pm_ops scsi_bus_pm_ops = { |
Alan Stern | fea6d60 | 2012-02-17 16:25:08 -0500 | [diff] [blame] | 372 | .prepare = scsi_bus_prepare, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 373 | .suspend = scsi_bus_suspend, |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 374 | .resume = scsi_bus_resume, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 375 | .freeze = scsi_bus_freeze, |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 376 | .thaw = scsi_bus_thaw, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 377 | .poweroff = scsi_bus_poweroff, |
Aaron Lu | 80d2fd4 | 2012-11-09 15:27:54 +0800 | [diff] [blame] | 378 | .restore = scsi_bus_restore, |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 379 | .runtime_suspend = scsi_runtime_suspend, |
| 380 | .runtime_resume = scsi_runtime_resume, |
| 381 | .runtime_idle = scsi_runtime_idle, |
Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame] | 382 | }; |