Skip to content

Commit 297b8a0

Browse files
James BottomleyJames Bottomley
authored andcommitted
Merge branch 'postmerge' into for-linus
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
2 parents 832e77b + 6df339a commit 297b8a0

File tree

4 files changed

+93
-38
lines changed

4 files changed

+93
-38
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,10 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
276276
}
277277
EXPORT_SYMBOL(scsi_execute);
278278

279-
280-
int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
279+
int scsi_execute_req_flags(struct scsi_device *sdev, const unsigned char *cmd,
281280
int data_direction, void *buffer, unsigned bufflen,
282281
struct scsi_sense_hdr *sshdr, int timeout, int retries,
283-
int *resid)
282+
int *resid, int flags)
284283
{
285284
char *sense = NULL;
286285
int result;
@@ -291,14 +290,14 @@ int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
291290
return DRIVER_ERROR << 24;
292291
}
293292
result = scsi_execute(sdev, cmd, data_direction, buffer, bufflen,
294-
sense, timeout, retries, 0, resid);
293+
sense, timeout, retries, flags, resid);
295294
if (sshdr)
296295
scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, sshdr);
297296

298297
kfree(sense);
299298
return result;
300299
}
301-
EXPORT_SYMBOL(scsi_execute_req);
300+
EXPORT_SYMBOL(scsi_execute_req_flags);
302301

303302
/*
304303
* Function: scsi_init_cmd_errh()

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: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,10 +1136,6 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
11361136

11371137
sdev = sdkp->device;
11381138

1139-
retval = scsi_autopm_get_device(sdev);
1140-
if (retval)
1141-
goto error_autopm;
1142-
11431139
/*
11441140
* If the device is in error recovery, wait until it is done.
11451141
* If the device is offline, then disallow any access to it.
@@ -1184,8 +1180,6 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
11841180
return 0;
11851181

11861182
error_out:
1187-
scsi_autopm_put_device(sdev);
1188-
error_autopm:
11891183
scsi_disk_put(sdkp);
11901184
return retval;
11911185
}
@@ -1220,7 +1214,6 @@ static void sd_release(struct gendisk *disk, fmode_t mode)
12201214
* XXX is followed by a "rmmod sd_mod"?
12211215
*/
12221216

1223-
scsi_autopm_put_device(sdev);
12241217
scsi_disk_put(sdkp);
12251218
}
12261219

@@ -1381,14 +1374,9 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
13811374
retval = -ENODEV;
13821375

13831376
if (scsi_block_when_processing_errors(sdp)) {
1384-
retval = scsi_autopm_get_device(sdp);
1385-
if (retval)
1386-
goto out;
1387-
13881377
sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
13891378
retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
13901379
sshdr);
1391-
scsi_autopm_put_device(sdp);
13921380
}
13931381

13941382
/* failed to execute TUR, assume media not present */
@@ -1438,8 +1426,9 @@ static int sd_sync_cache(struct scsi_disk *sdkp)
14381426
* Leave the rest of the command zero to indicate
14391427
* flush everything.
14401428
*/
1441-
res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr,
1442-
SD_FLUSH_TIMEOUT, SD_MAX_RETRIES, NULL);
1429+
res = scsi_execute_req_flags(sdp, cmd, DMA_NONE, NULL, 0,
1430+
&sshdr, SD_FLUSH_TIMEOUT,
1431+
SD_MAX_RETRIES, NULL, REQ_PM);
14431432
if (res == 0)
14441433
break;
14451434
}
@@ -2857,6 +2846,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
28572846

28582847
sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n",
28592848
sdp->removable ? "removable " : "");
2849+
blk_pm_runtime_init(sdp->request_queue, dev);
28602850
scsi_autopm_put_device(sdp);
28612851
put_device(&sdkp->dev);
28622852
}
@@ -3040,8 +3030,8 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
30403030
if (!scsi_device_online(sdp))
30413031
return -ENODEV;
30423032

3043-
res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr,
3044-
SD_TIMEOUT, SD_MAX_RETRIES, NULL);
3033+
res = scsi_execute_req_flags(sdp, cmd, DMA_NONE, NULL, 0, &sshdr,
3034+
SD_TIMEOUT, SD_MAX_RETRIES, NULL, REQ_PM);
30453035
if (res) {
30463036
sd_printk(KERN_WARNING, sdkp, "START_STOP FAILED\n");
30473037
sd_print_result(sdkp, res);

include/scsi/scsi_device.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,18 @@ extern int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
394394
int data_direction, void *buffer, unsigned bufflen,
395395
unsigned char *sense, int timeout, int retries,
396396
int flag, int *resid);
397-
extern int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
398-
int data_direction, void *buffer, unsigned bufflen,
399-
struct scsi_sense_hdr *, int timeout, int retries,
400-
int *resid);
397+
extern int scsi_execute_req_flags(struct scsi_device *sdev,
398+
const unsigned char *cmd, int data_direction, void *buffer,
399+
unsigned bufflen, struct scsi_sense_hdr *sshdr, int timeout,
400+
int retries, int *resid, int flags);
401+
static inline int scsi_execute_req(struct scsi_device *sdev,
402+
const unsigned char *cmd, int data_direction, void *buffer,
403+
unsigned bufflen, struct scsi_sense_hdr *sshdr, int timeout,
404+
int retries, int *resid)
405+
{
406+
return scsi_execute_req_flags(sdev, cmd, data_direction, buffer,
407+
bufflen, sshdr, timeout, retries, resid, 0);
408+
}
401409
extern void sdev_disable_disk_events(struct scsi_device *sdev);
402410
extern void sdev_enable_disk_events(struct scsi_device *sdev);
403411

0 commit comments

Comments
 (0)