Skip to content

Commit 6df339a

Browse files
Lin MingJames Bottomley
authored andcommitted
[SCSI] sd: change to auto suspend mode
Uses block layer runtime pm helper functions in scsi_runtime_suspend/resume for devices that take advantage of it. Remove scsi_autopm_* from sd open/release path and check_events path. Signed-off-by: Lin Ming <ming.m.lin@intel.com> Signed-off-by: Aaron Lu <aaron.lu@intel.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
1 parent 9b21493 commit 6df339a

File tree

2 files changed

+72
-25
lines changed

2 files changed

+72
-25
lines changed

drivers/scsi/scsi_pm.c

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,33 +144,83 @@ static int scsi_bus_restore(struct device *dev)
144144

145145
#ifdef CONFIG_PM_RUNTIME
146146

147+
static int sdev_blk_runtime_suspend(struct scsi_device *sdev,
148+
int (*cb)(struct device *))
149+
{
150+
int err;
151+
152+
err = blk_pre_runtime_suspend(sdev->request_queue);
153+
if (err)
154+
return err;
155+
if (cb)
156+
err = cb(&sdev->sdev_gendev);
157+
blk_post_runtime_suspend(sdev->request_queue, err);
158+
159+
return err;
160+
}
161+
162+
static int sdev_runtime_suspend(struct device *dev)
163+
{
164+
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
165+
int (*cb)(struct device *) = pm ? pm->runtime_suspend : NULL;
166+
struct scsi_device *sdev = to_scsi_device(dev);
167+
int err;
168+
169+
if (sdev->request_queue->dev)
170+
return sdev_blk_runtime_suspend(sdev, cb);
171+
172+
err = scsi_dev_type_suspend(dev, cb);
173+
if (err == -EAGAIN)
174+
pm_schedule_suspend(dev, jiffies_to_msecs(
175+
round_jiffies_up_relative(HZ/10)));
176+
return err;
177+
}
178+
147179
static int scsi_runtime_suspend(struct device *dev)
148180
{
149181
int err = 0;
150-
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
151182

152183
dev_dbg(dev, "scsi_runtime_suspend\n");
153-
if (scsi_is_sdev_device(dev)) {
154-
err = scsi_dev_type_suspend(dev,
155-
pm ? pm->runtime_suspend : NULL);
156-
if (err == -EAGAIN)
157-
pm_schedule_suspend(dev, jiffies_to_msecs(
158-
round_jiffies_up_relative(HZ/10)));
159-
}
184+
if (scsi_is_sdev_device(dev))
185+
err = sdev_runtime_suspend(dev);
160186

161187
/* Insert hooks here for targets, hosts, and transport classes */
162188

163189
return err;
164190
}
165191

166-
static int scsi_runtime_resume(struct device *dev)
192+
static int sdev_blk_runtime_resume(struct scsi_device *sdev,
193+
int (*cb)(struct device *))
167194
{
168195
int err = 0;
196+
197+
blk_pre_runtime_resume(sdev->request_queue);
198+
if (cb)
199+
err = cb(&sdev->sdev_gendev);
200+
blk_post_runtime_resume(sdev->request_queue, err);
201+
202+
return err;
203+
}
204+
205+
static int sdev_runtime_resume(struct device *dev)
206+
{
207+
struct scsi_device *sdev = to_scsi_device(dev);
169208
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
209+
int (*cb)(struct device *) = pm ? pm->runtime_resume : NULL;
210+
211+
if (sdev->request_queue->dev)
212+
return sdev_blk_runtime_resume(sdev, cb);
213+
else
214+
return scsi_dev_type_resume(dev, cb);
215+
}
216+
217+
static int scsi_runtime_resume(struct device *dev)
218+
{
219+
int err = 0;
170220

171221
dev_dbg(dev, "scsi_runtime_resume\n");
172222
if (scsi_is_sdev_device(dev))
173-
err = scsi_dev_type_resume(dev, pm ? pm->runtime_resume : NULL);
223+
err = sdev_runtime_resume(dev);
174224

175225
/* Insert hooks here for targets, hosts, and transport classes */
176226

@@ -185,10 +235,18 @@ static int scsi_runtime_idle(struct device *dev)
185235

186236
/* Insert hooks here for targets, hosts, and transport classes */
187237

188-
if (scsi_is_sdev_device(dev))
189-
err = pm_schedule_suspend(dev, 100);
190-
else
238+
if (scsi_is_sdev_device(dev)) {
239+
struct scsi_device *sdev = to_scsi_device(dev);
240+
241+
if (sdev->request_queue->dev) {
242+
pm_runtime_mark_last_busy(dev);
243+
err = pm_runtime_autosuspend(dev);
244+
} else {
245+
err = pm_runtime_suspend(dev);
246+
}
247+
} else {
191248
err = pm_runtime_suspend(dev);
249+
}
192250
return err;
193251
}
194252

drivers/scsi/sd.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,6 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
11211121

11221122
sdev = sdkp->device;
11231123

1124-
retval = scsi_autopm_get_device(sdev);
1125-
if (retval)
1126-
goto error_autopm;
1127-
11281124
/*
11291125
* If the device is in error recovery, wait until it is done.
11301126
* If the device is offline, then disallow any access to it.
@@ -1169,8 +1165,6 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
11691165
return 0;
11701166

11711167
error_out:
1172-
scsi_autopm_put_device(sdev);
1173-
error_autopm:
11741168
scsi_disk_put(sdkp);
11751169
return retval;
11761170
}
@@ -1205,7 +1199,6 @@ static int sd_release(struct gendisk *disk, fmode_t mode)
12051199
* XXX is followed by a "rmmod sd_mod"?
12061200
*/
12071201

1208-
scsi_autopm_put_device(sdev);
12091202
scsi_disk_put(sdkp);
12101203
return 0;
12111204
}
@@ -1367,14 +1360,9 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
13671360
retval = -ENODEV;
13681361

13691362
if (scsi_block_when_processing_errors(sdp)) {
1370-
retval = scsi_autopm_get_device(sdp);
1371-
if (retval)
1372-
goto out;
1373-
13741363
sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
13751364
retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
13761365
sshdr);
1377-
scsi_autopm_put_device(sdp);
13781366
}
13791367

13801368
/* failed to execute TUR, assume media not present */
@@ -2839,6 +2827,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
28392827

28402828
sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n",
28412829
sdp->removable ? "removable " : "");
2830+
blk_pm_runtime_init(sdp->request_queue, dev);
28422831
scsi_autopm_put_device(sdp);
28432832
put_device(&sdkp->dev);
28442833
}

0 commit comments

Comments
 (0)