summaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-12-28 16:19:59 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-12-28 16:19:59 -0500
commit0e9da3fbf7d81f0f913b491c8de1ba7883d4f217 (patch)
tree2b3d25e3be60bf4ee40b4690c7bb9d6fa499ae69 /drivers/ide
parentb12a9124eeb71d766a3e3eb594ebbb3fefc66902 (diff)
parent00203ba40d40d7f33857416adfb18adaf0e40123 (diff)
Merge tag 'for-4.21/block-20181221' of git://git.kernel.dk/linux-block
Pull block updates from Jens Axboe: "This is the main pull request for block/storage for 4.21. Larger than usual, it was a busy round with lots of goodies queued up. Most notable is the removal of the old IO stack, which has been a long time coming. No new features for a while, everything coming in this week has all been fixes for things that were previously merged. This contains: - Use atomic counters instead of semaphores for mtip32xx (Arnd) - Cleanup of the mtip32xx request setup (Christoph) - Fix for circular locking dependency in loop (Jan, Tetsuo) - bcache (Coly, Guoju, Shenghui) * Optimizations for writeback caching * Various fixes and improvements - nvme (Chaitanya, Christoph, Sagi, Jay, me, Keith) * host and target support for NVMe over TCP * Error log page support * Support for separate read/write/poll queues * Much improved polling * discard OOM fallback * Tracepoint improvements - lightnvm (Hans, Hua, Igor, Matias, Javier) * Igor added packed metadata to pblk. Now drives without metadata per LBA can be used as well. * Fix from Geert on uninitialized value on chunk metadata reads. * Fixes from Hans and Javier to pblk recovery and write path. * Fix from Hua Su to fix a race condition in the pblk recovery code. * Scan optimization added to pblk recovery from Zhoujie. * Small geometry cleanup from me. - Conversion of the last few drivers that used the legacy path to blk-mq (me) - Removal of legacy IO path in SCSI (me, Christoph) - Removal of legacy IO stack and schedulers (me) - Support for much better polling, now without interrupts at all. blk-mq adds support for multiple queue maps, which enables us to have a map per type. This in turn enables nvme to have separate completion queues for polling, which can then be interrupt-less. Also means we're ready for async polled IO, which is hopefully coming in the next release. - Killing of (now) unused block exports (Christoph) - Unification of the blk-rq-qos and blk-wbt wait handling (Josef) - Support for zoned testing with null_blk (Masato) - sx8 conversion to per-host tag sets (Christoph) - IO priority improvements (Damien) - mq-deadline zoned fix (Damien) - Ref count blkcg series (Dennis) - Lots of blk-mq improvements and speedups (me) - sbitmap scalability improvements (me) - Make core inflight IO accounting per-cpu (Mikulas) - Export timeout setting in sysfs (Weiping) - Cleanup the direct issue path (Jianchao) - Export blk-wbt internals in block debugfs for easier debugging (Ming) - Lots of other fixes and improvements" * tag 'for-4.21/block-20181221' of git://git.kernel.dk/linux-block: (364 commits) kyber: use sbitmap add_wait_queue/list_del wait helpers sbitmap: add helpers for add/del wait queue handling block: save irq state in blkg_lookup_create() dm: don't reuse bio for flushes nvme-pci: trace SQ status on completions nvme-rdma: implement polling queue map nvme-fabrics: allow user to pass in nr_poll_queues nvme-fabrics: allow nvmf_connect_io_queue to poll nvme-core: optionally poll sync commands block: make request_to_qc_t public nvme-tcp: fix spelling mistake "attepmpt" -> "attempt" nvme-tcp: fix endianess annotations nvmet-tcp: fix endianess annotations nvme-pci: refactor nvme_poll_irqdisable to make sparse happy nvme-pci: only set nr_maps to 2 if poll queues are supported nvmet: use a macro for default error location nvmet: fix comparison of a u16 with -1 blk-mq: enable IO poll if .nr_queues of type poll > 0 blk-mq: change blk_mq_queue_busy() to blk_mq_queue_inflight() blk-mq: skip zero-queue maps in blk_mq_map_swqueue ...
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/ide-atapi.c27
-rw-r--r--drivers/ide/ide-cd.c179
-rw-r--r--drivers/ide/ide-devsets.c4
-rw-r--r--drivers/ide/ide-disk.c15
-rw-r--r--drivers/ide/ide-eh.c2
-rw-r--r--drivers/ide/ide-floppy.c2
-rw-r--r--drivers/ide/ide-io.c112
-rw-r--r--drivers/ide/ide-park.c8
-rw-r--r--drivers/ide/ide-pm.c46
-rw-r--r--drivers/ide/ide-probe.c69
-rw-r--r--drivers/ide/ide-tape.c2
-rw-r--r--drivers/ide/ide-taskfile.c2
12 files changed, 259 insertions, 209 deletions
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 8b2b72b93885..da58020a144e 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -94,7 +94,7 @@ int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
94 94
95 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0); 95 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0);
96 ide_req(rq)->type = ATA_PRIV_MISC; 96 ide_req(rq)->type = ATA_PRIV_MISC;
97 rq->special = (char *)pc; 97 ide_req(rq)->special = pc;
98 98
99 if (buf && bufflen) { 99 if (buf && bufflen) {
100 error = blk_rq_map_kern(drive->queue, rq, buf, bufflen, 100 error = blk_rq_map_kern(drive->queue, rq, buf, bufflen,
@@ -172,8 +172,8 @@ EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
172void ide_prep_sense(ide_drive_t *drive, struct request *rq) 172void ide_prep_sense(ide_drive_t *drive, struct request *rq)
173{ 173{
174 struct request_sense *sense = &drive->sense_data; 174 struct request_sense *sense = &drive->sense_data;
175 struct request *sense_rq = drive->sense_rq; 175 struct request *sense_rq;
176 struct scsi_request *req = scsi_req(sense_rq); 176 struct scsi_request *req;
177 unsigned int cmd_len, sense_len; 177 unsigned int cmd_len, sense_len;
178 int err; 178 int err;
179 179
@@ -196,9 +196,16 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
196 if (ata_sense_request(rq) || drive->sense_rq_armed) 196 if (ata_sense_request(rq) || drive->sense_rq_armed)
197 return; 197 return;
198 198
199 sense_rq = drive->sense_rq;
200 if (!sense_rq) {
201 sense_rq = blk_mq_alloc_request(drive->queue, REQ_OP_DRV_IN,
202 BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
203 drive->sense_rq = sense_rq;
204 }
205 req = scsi_req(sense_rq);
206
199 memset(sense, 0, sizeof(*sense)); 207 memset(sense, 0, sizeof(*sense));
200 208
201 blk_rq_init(rq->q, sense_rq);
202 scsi_req_init(req); 209 scsi_req_init(req);
203 210
204 err = blk_rq_map_kern(drive->queue, sense_rq, sense, sense_len, 211 err = blk_rq_map_kern(drive->queue, sense_rq, sense, sense_len,
@@ -207,6 +214,8 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
207 if (printk_ratelimit()) 214 if (printk_ratelimit())
208 printk(KERN_WARNING PFX "%s: failed to map sense " 215 printk(KERN_WARNING PFX "%s: failed to map sense "
209 "buffer\n", drive->name); 216 "buffer\n", drive->name);
217 blk_mq_free_request(sense_rq);
218 drive->sense_rq = NULL;
210 return; 219 return;
211 } 220 }
212 221
@@ -226,6 +235,8 @@ EXPORT_SYMBOL_GPL(ide_prep_sense);
226 235
227int ide_queue_sense_rq(ide_drive_t *drive, void *special) 236int ide_queue_sense_rq(ide_drive_t *drive, void *special)
228{ 237{
238 struct request *sense_rq = drive->sense_rq;
239
229 /* deferred failure from ide_prep_sense() */ 240 /* deferred failure from ide_prep_sense() */
230 if (!drive->sense_rq_armed) { 241 if (!drive->sense_rq_armed) {
231 printk(KERN_WARNING PFX "%s: error queuing a sense request\n", 242 printk(KERN_WARNING PFX "%s: error queuing a sense request\n",
@@ -233,12 +244,12 @@ int ide_queue_sense_rq(ide_drive_t *drive, void *special)
233 return -ENOMEM; 244 return -ENOMEM;
234 } 245 }
235 246
236 drive->sense_rq->special = special; 247 ide_req(sense_rq)->special = special;
237 drive->sense_rq_armed = false; 248 drive->sense_rq_armed = false;
238 249
239 drive->hwif->rq = NULL; 250 drive->hwif->rq = NULL;
240 251
241 elv_add_request(drive->queue, drive->sense_rq, ELEVATOR_INSERT_FRONT); 252 ide_insert_request_head(drive, sense_rq);
242 return 0; 253 return 0;
243} 254}
244EXPORT_SYMBOL_GPL(ide_queue_sense_rq); 255EXPORT_SYMBOL_GPL(ide_queue_sense_rq);
@@ -270,10 +281,8 @@ void ide_retry_pc(ide_drive_t *drive)
270 */ 281 */
271 drive->hwif->rq = NULL; 282 drive->hwif->rq = NULL;
272 ide_requeue_and_plug(drive, failed_rq); 283 ide_requeue_and_plug(drive, failed_rq);
273 if (ide_queue_sense_rq(drive, pc)) { 284 if (ide_queue_sense_rq(drive, pc))
274 blk_start_request(failed_rq);
275 ide_complete_rq(drive, BLK_STS_IOERR, blk_rq_bytes(failed_rq)); 285 ide_complete_rq(drive, BLK_STS_IOERR, blk_rq_bytes(failed_rq));
276 }
277} 286}
278EXPORT_SYMBOL_GPL(ide_retry_pc); 287EXPORT_SYMBOL_GPL(ide_retry_pc);
279 288
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index f9b59d41813f..1f03884a6808 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -211,12 +211,12 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
211static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq) 211static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq)
212{ 212{
213 /* 213 /*
214 * For ATA_PRIV_SENSE, "rq->special" points to the original 214 * For ATA_PRIV_SENSE, "ide_req(rq)->special" points to the original
215 * failed request. Also, the sense data should be read 215 * failed request. Also, the sense data should be read
216 * directly from rq which might be different from the original 216 * directly from rq which might be different from the original
217 * sense buffer if it got copied during mapping. 217 * sense buffer if it got copied during mapping.
218 */ 218 */
219 struct request *failed = (struct request *)rq->special; 219 struct request *failed = ide_req(rq)->special;
220 void *sense = bio_data(rq->bio); 220 void *sense = bio_data(rq->bio);
221 221
222 if (failed) { 222 if (failed) {
@@ -258,11 +258,22 @@ static int ide_cd_breathe(ide_drive_t *drive, struct request *rq)
258 /* 258 /*
259 * take a breather 259 * take a breather
260 */ 260 */
261 blk_delay_queue(drive->queue, 1); 261 blk_mq_requeue_request(rq, false);
262 blk_mq_delay_kick_requeue_list(drive->queue, 1);
262 return 1; 263 return 1;
263 } 264 }
264} 265}
265 266
267static void ide_cd_free_sense(ide_drive_t *drive)
268{
269 if (!drive->sense_rq)
270 return;
271
272 blk_mq_free_request(drive->sense_rq);
273 drive->sense_rq = NULL;
274 drive->sense_rq_armed = false;
275}
276
266/** 277/**
267 * Returns: 278 * Returns:
268 * 0: if the request should be continued. 279 * 0: if the request should be continued.
@@ -516,6 +527,82 @@ static bool ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
516 return false; 527 return false;
517} 528}
518 529
530/* standard prep_rq that builds 10 byte cmds */
531static bool ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
532{
533 int hard_sect = queue_logical_block_size(q);
534 long block = (long)blk_rq_pos(rq) / (hard_sect >> 9);
535 unsigned long blocks = blk_rq_sectors(rq) / (hard_sect >> 9);
536 struct scsi_request *req = scsi_req(rq);
537
538 if (rq_data_dir(rq) == READ)
539 req->cmd[0] = GPCMD_READ_10;
540 else
541 req->cmd[0] = GPCMD_WRITE_10;
542
543 /*
544 * fill in lba
545 */
546 req->cmd[2] = (block >> 24) & 0xff;
547 req->cmd[3] = (block >> 16) & 0xff;
548 req->cmd[4] = (block >> 8) & 0xff;
549 req->cmd[5] = block & 0xff;
550
551 /*
552 * and transfer length
553 */
554 req->cmd[7] = (blocks >> 8) & 0xff;
555 req->cmd[8] = blocks & 0xff;
556 req->cmd_len = 10;
557 return true;
558}
559
560/*
561 * Most of the SCSI commands are supported directly by ATAPI devices.
562 * This transform handles the few exceptions.
563 */
564static bool ide_cdrom_prep_pc(struct request *rq)
565{
566 u8 *c = scsi_req(rq)->cmd;
567
568 /* transform 6-byte read/write commands to the 10-byte version */
569 if (c[0] == READ_6 || c[0] == WRITE_6) {
570 c[8] = c[4];
571 c[5] = c[3];
572 c[4] = c[2];
573 c[3] = c[1] & 0x1f;
574 c[2] = 0;
575 c[1] &= 0xe0;
576 c[0] += (READ_10 - READ_6);
577 scsi_req(rq)->cmd_len = 10;
578 return true;
579 }
580
581 /*
582 * it's silly to pretend we understand 6-byte sense commands, just
583 * reject with ILLEGAL_REQUEST and the caller should take the
584 * appropriate action
585 */
586 if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) {
587 scsi_req(rq)->result = ILLEGAL_REQUEST;
588 return false;
589 }
590
591 return true;
592}
593
594static bool ide_cdrom_prep_rq(ide_drive_t *drive, struct request *rq)
595{
596 if (!blk_rq_is_passthrough(rq)) {
597 scsi_req_init(scsi_req(rq));
598
599 return ide_cdrom_prep_fs(drive->queue, rq);
600 } else if (blk_rq_is_scsi(rq))
601 return ide_cdrom_prep_pc(rq);
602
603 return true;
604}
605
519static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 606static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
520{ 607{
521 ide_hwif_t *hwif = drive->hwif; 608 ide_hwif_t *hwif = drive->hwif;
@@ -675,7 +762,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
675out_end: 762out_end:
676 if (blk_rq_is_scsi(rq) && rc == 0) { 763 if (blk_rq_is_scsi(rq) && rc == 0) {
677 scsi_req(rq)->resid_len = 0; 764 scsi_req(rq)->resid_len = 0;
678 blk_end_request_all(rq, BLK_STS_OK); 765 blk_mq_end_request(rq, BLK_STS_OK);
679 hwif->rq = NULL; 766 hwif->rq = NULL;
680 } else { 767 } else {
681 if (sense && uptodate) 768 if (sense && uptodate)
@@ -705,6 +792,8 @@ out_end:
705 if (sense && rc == 2) 792 if (sense && rc == 2)
706 ide_error(drive, "request sense failure", stat); 793 ide_error(drive, "request sense failure", stat);
707 } 794 }
795
796 ide_cd_free_sense(drive);
708 return ide_stopped; 797 return ide_stopped;
709} 798}
710 799
@@ -729,7 +818,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
729 * We may be retrying this request after an error. Fix up any 818 * We may be retrying this request after an error. Fix up any
730 * weirdness which might be present in the request packet. 819 * weirdness which might be present in the request packet.
731 */ 820 */
732 q->prep_rq_fn(q, rq); 821 ide_cdrom_prep_rq(drive, rq);
733 } 822 }
734 823
735 /* fs requests *must* be hardware frame aligned */ 824 /* fs requests *must* be hardware frame aligned */
@@ -1323,82 +1412,6 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1323 return nslots; 1412 return nslots;
1324} 1413}
1325 1414
1326/* standard prep_rq_fn that builds 10 byte cmds */
1327static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
1328{
1329 int hard_sect = queue_logical_block_size(q);
1330 long block = (long)blk_rq_pos(rq) / (hard_sect >> 9);
1331 unsigned long blocks = blk_rq_sectors(rq) / (hard_sect >> 9);
1332 struct scsi_request *req = scsi_req(rq);
1333
1334 q->initialize_rq_fn(rq);
1335
1336 if (rq_data_dir(rq) == READ)
1337 req->cmd[0] = GPCMD_READ_10;
1338 else
1339 req->cmd[0] = GPCMD_WRITE_10;
1340
1341 /*
1342 * fill in lba
1343 */
1344 req->cmd[2] = (block >> 24) & 0xff;
1345 req->cmd[3] = (block >> 16) & 0xff;
1346 req->cmd[4] = (block >> 8) & 0xff;
1347 req->cmd[5] = block & 0xff;
1348
1349 /*
1350 * and transfer length
1351 */
1352 req->cmd[7] = (blocks >> 8) & 0xff;
1353 req->cmd[8] = blocks & 0xff;
1354 req->cmd_len = 10;
1355 return BLKPREP_OK;
1356}
1357
1358/*
1359 * Most of the SCSI commands are supported directly by ATAPI devices.
1360 * This transform handles the few exceptions.
1361 */
1362static int ide_cdrom_prep_pc(struct request *rq)
1363{
1364 u8 *c = scsi_req(rq)->cmd;
1365
1366 /* transform 6-byte read/write commands to the 10-byte version */
1367 if (c[0] == READ_6 || c[0] == WRITE_6) {
1368 c[8] = c[4];
1369 c[5] = c[3];
1370 c[4] = c[2];
1371 c[3] = c[1] & 0x1f;
1372 c[2] = 0;
1373 c[1] &= 0xe0;
1374 c[0] += (READ_10 - READ_6);
1375 scsi_req(rq)->cmd_len = 10;
1376 return BLKPREP_OK;
1377 }
1378
1379 /*
1380 * it's silly to pretend we understand 6-byte sense commands, just
1381 * reject with ILLEGAL_REQUEST and the caller should take the
1382 * appropriate action
1383 */
1384 if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) {
1385 scsi_req(rq)->result = ILLEGAL_REQUEST;
1386 return BLKPREP_KILL;
1387 }
1388
1389 return BLKPREP_OK;
1390}
1391
1392static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq)
1393{
1394 if (!blk_rq_is_passthrough(rq))
1395 return ide_cdrom_prep_fs(q, rq);
1396 else if (blk_rq_is_scsi(rq))
1397 return ide_cdrom_prep_pc(rq);
1398
1399 return 0;
1400}
1401
1402struct cd_list_entry { 1415struct cd_list_entry {
1403 const char *id_model; 1416 const char *id_model;
1404 const char *id_firmware; 1417 const char *id_firmware;
@@ -1508,7 +1521,7 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1508 1521
1509 ide_debug_log(IDE_DBG_PROBE, "enter"); 1522 ide_debug_log(IDE_DBG_PROBE, "enter");
1510 1523
1511 blk_queue_prep_rq(q, ide_cdrom_prep_fn); 1524 drive->prep_rq = ide_cdrom_prep_rq;
1512 blk_queue_dma_alignment(q, 31); 1525 blk_queue_dma_alignment(q, 31);
1513 blk_queue_update_dma_pad(q, 15); 1526 blk_queue_update_dma_pad(q, 15);
1514 1527
@@ -1569,7 +1582,7 @@ static void ide_cd_release(struct device *dev)
1569 if (devinfo->handle == drive) 1582 if (devinfo->handle == drive)
1570 unregister_cdrom(devinfo); 1583 unregister_cdrom(devinfo);
1571 drive->driver_data = NULL; 1584 drive->driver_data = NULL;
1572 blk_queue_prep_rq(drive->queue, NULL); 1585 drive->prep_rq = NULL;
1573 g->private_data = NULL; 1586 g->private_data = NULL;
1574 put_disk(g); 1587 put_disk(g);
1575 kfree(info); 1588 kfree(info);
diff --git a/drivers/ide/ide-devsets.c b/drivers/ide/ide-devsets.c
index f4f8afdf8bbe..f2f93ed40356 100644
--- a/drivers/ide/ide-devsets.c
+++ b/drivers/ide/ide-devsets.c
@@ -171,7 +171,7 @@ int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
171 scsi_req(rq)->cmd_len = 5; 171 scsi_req(rq)->cmd_len = 5;
172 scsi_req(rq)->cmd[0] = REQ_DEVSET_EXEC; 172 scsi_req(rq)->cmd[0] = REQ_DEVSET_EXEC;
173 *(int *)&scsi_req(rq)->cmd[1] = arg; 173 *(int *)&scsi_req(rq)->cmd[1] = arg;
174 rq->special = setting->set; 174 ide_req(rq)->special = setting->set;
175 175
176 blk_execute_rq(q, NULL, rq, 0); 176 blk_execute_rq(q, NULL, rq, 0);
177 ret = scsi_req(rq)->result; 177 ret = scsi_req(rq)->result;
@@ -182,7 +182,7 @@ int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
182 182
183ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq) 183ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq)
184{ 184{
185 int err, (*setfunc)(ide_drive_t *, int) = rq->special; 185 int err, (*setfunc)(ide_drive_t *, int) = ide_req(rq)->special;
186 186
187 err = setfunc(drive, *(int *)&scsi_req(rq)->cmd[1]); 187 err = setfunc(drive, *(int *)&scsi_req(rq)->cmd[1]);
188 if (err) 188 if (err)
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index e3b4e659082d..197912af5c2f 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -427,16 +427,15 @@ static void ide_disk_unlock_native_capacity(ide_drive_t *drive)
427 drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */ 427 drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */
428} 428}
429 429
430static int idedisk_prep_fn(struct request_queue *q, struct request *rq) 430static bool idedisk_prep_rq(ide_drive_t *drive, struct request *rq)
431{ 431{
432 ide_drive_t *drive = q->queuedata;
433 struct ide_cmd *cmd; 432 struct ide_cmd *cmd;
434 433
435 if (req_op(rq) != REQ_OP_FLUSH) 434 if (req_op(rq) != REQ_OP_FLUSH)
436 return BLKPREP_OK; 435 return true;
437 436
438 if (rq->special) { 437 if (ide_req(rq)->special) {
439 cmd = rq->special; 438 cmd = ide_req(rq)->special;
440 memset(cmd, 0, sizeof(*cmd)); 439 memset(cmd, 0, sizeof(*cmd));
441 } else { 440 } else {
442 cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC); 441 cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
@@ -456,10 +455,10 @@ static int idedisk_prep_fn(struct request_queue *q, struct request *rq)
456 rq->cmd_flags &= ~REQ_OP_MASK; 455 rq->cmd_flags &= ~REQ_OP_MASK;
457 rq->cmd_flags |= REQ_OP_DRV_OUT; 456 rq->cmd_flags |= REQ_OP_DRV_OUT;
458 ide_req(rq)->type = ATA_PRIV_TASKFILE; 457 ide_req(rq)->type = ATA_PRIV_TASKFILE;
459 rq->special = cmd; 458 ide_req(rq)->special = cmd;
460 cmd->rq = rq; 459 cmd->rq = rq;
461 460
462 return BLKPREP_OK; 461 return true;
463} 462}
464 463
465ide_devset_get(multcount, mult_count); 464ide_devset_get(multcount, mult_count);
@@ -548,7 +547,7 @@ static void update_flush(ide_drive_t *drive)
548 547
549 if (barrier) { 548 if (barrier) {
550 wc = true; 549 wc = true;
551 blk_queue_prep_rq(drive->queue, idedisk_prep_fn); 550 drive->prep_rq = idedisk_prep_rq;
552 } 551 }
553 } 552 }
554 553
diff --git a/drivers/ide/ide-eh.c b/drivers/ide/ide-eh.c
index 47d5f3379748..e1323e058454 100644
--- a/drivers/ide/ide-eh.c
+++ b/drivers/ide/ide-eh.c
@@ -125,7 +125,7 @@ ide_startstop_t ide_error(ide_drive_t *drive, const char *msg, u8 stat)
125 /* retry only "normal" I/O: */ 125 /* retry only "normal" I/O: */
126 if (blk_rq_is_passthrough(rq)) { 126 if (blk_rq_is_passthrough(rq)) {
127 if (ata_taskfile_request(rq)) { 127 if (ata_taskfile_request(rq)) {
128 struct ide_cmd *cmd = rq->special; 128 struct ide_cmd *cmd = ide_req(rq)->special;
129 129
130 if (cmd) 130 if (cmd)
131 ide_complete_cmd(drive, cmd, stat, err); 131 ide_complete_cmd(drive, cmd, stat, err);
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index a8df300f949c..780d33ccc5d8 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -276,7 +276,7 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
276 switch (ide_req(rq)->type) { 276 switch (ide_req(rq)->type) {
277 case ATA_PRIV_MISC: 277 case ATA_PRIV_MISC:
278 case ATA_PRIV_SENSE: 278 case ATA_PRIV_SENSE:
279 pc = (struct ide_atapi_pc *)rq->special; 279 pc = (struct ide_atapi_pc *)ide_req(rq)->special;
280 break; 280 break;
281 default: 281 default:
282 BUG(); 282 BUG();
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 0d93e0cfbeaf..8445b484ae69 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -67,7 +67,15 @@ int ide_end_rq(ide_drive_t *drive, struct request *rq, blk_status_t error,
67 ide_dma_on(drive); 67 ide_dma_on(drive);
68 } 68 }
69 69
70 return blk_end_request(rq, error, nr_bytes); 70 if (!blk_update_request(rq, error, nr_bytes)) {
71 if (rq == drive->sense_rq)
72 drive->sense_rq = NULL;
73
74 __blk_mq_end_request(rq, error);
75 return 0;
76 }
77
78 return 1;
71} 79}
72EXPORT_SYMBOL_GPL(ide_end_rq); 80EXPORT_SYMBOL_GPL(ide_end_rq);
73 81
@@ -103,7 +111,7 @@ void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
103 } 111 }
104 112
105 if (rq && ata_taskfile_request(rq)) { 113 if (rq && ata_taskfile_request(rq)) {
106 struct ide_cmd *orig_cmd = rq->special; 114 struct ide_cmd *orig_cmd = ide_req(rq)->special;
107 115
108 if (cmd->tf_flags & IDE_TFLAG_DYN) 116 if (cmd->tf_flags & IDE_TFLAG_DYN)
109 kfree(orig_cmd); 117 kfree(orig_cmd);
@@ -253,7 +261,7 @@ EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
253static ide_startstop_t execute_drive_cmd (ide_drive_t *drive, 261static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
254 struct request *rq) 262 struct request *rq)
255{ 263{
256 struct ide_cmd *cmd = rq->special; 264 struct ide_cmd *cmd = ide_req(rq)->special;
257 265
258 if (cmd) { 266 if (cmd) {
259 if (cmd->protocol == ATA_PROT_PIO) { 267 if (cmd->protocol == ATA_PROT_PIO) {
@@ -307,8 +315,6 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
307{ 315{
308 ide_startstop_t startstop; 316 ide_startstop_t startstop;
309 317
310 BUG_ON(!(rq->rq_flags & RQF_STARTED));
311
312#ifdef DEBUG 318#ifdef DEBUG
313 printk("%s: start_request: current=0x%08lx\n", 319 printk("%s: start_request: current=0x%08lx\n",
314 drive->hwif->name, (unsigned long) rq); 320 drive->hwif->name, (unsigned long) rq);
@@ -320,6 +326,9 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
320 goto kill_rq; 326 goto kill_rq;
321 } 327 }
322 328
329 if (drive->prep_rq && !drive->prep_rq(drive, rq))
330 return ide_stopped;
331
323 if (ata_pm_request(rq)) 332 if (ata_pm_request(rq))
324 ide_check_pm_state(drive, rq); 333 ide_check_pm_state(drive, rq);
325 334
@@ -343,7 +352,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
343 if (ata_taskfile_request(rq)) 352 if (ata_taskfile_request(rq))
344 return execute_drive_cmd(drive, rq); 353 return execute_drive_cmd(drive, rq);
345 else if (ata_pm_request(rq)) { 354 else if (ata_pm_request(rq)) {
346 struct ide_pm_state *pm = rq->special; 355 struct ide_pm_state *pm = ide_req(rq)->special;
347#ifdef DEBUG_PM 356#ifdef DEBUG_PM
348 printk("%s: start_power_step(step: %d)\n", 357 printk("%s: start_power_step(step: %d)\n",
349 drive->name, pm->pm_step); 358 drive->name, pm->pm_step);
@@ -430,44 +439,42 @@ static inline void ide_unlock_host(struct ide_host *host)
430 } 439 }
431} 440}
432 441
433static void __ide_requeue_and_plug(struct request_queue *q, struct request *rq)
434{
435 if (rq)
436 blk_requeue_request(q, rq);
437 if (rq || blk_peek_request(q)) {
438 /* Use 3ms as that was the old plug delay */
439 blk_delay_queue(q, 3);
440 }
441}
442
443void ide_requeue_and_plug(ide_drive_t *drive, struct request *rq) 442void ide_requeue_and_plug(ide_drive_t *drive, struct request *rq)
444{ 443{
445 struct request_queue *q = drive->queue; 444 struct request_queue *q = drive->queue;
446 unsigned long flags;
447 445
448 spin_lock_irqsave(q->queue_lock, flags); 446 /* Use 3ms as that was the old plug delay */
449 __ide_requeue_and_plug(q, rq); 447 if (rq) {
450 spin_unlock_irqrestore(q->queue_lock, flags); 448 blk_mq_requeue_request(rq, false);
449 blk_mq_delay_kick_requeue_list(q, 3);
450 } else
451 blk_mq_delay_run_hw_queue(q->queue_hw_ctx[0], 3);
451} 452}
452 453
453/* 454/*
454 * Issue a new request to a device. 455 * Issue a new request to a device.
455 */ 456 */
456void do_ide_request(struct request_queue *q) 457blk_status_t ide_queue_rq(struct blk_mq_hw_ctx *hctx,
458 const struct blk_mq_queue_data *bd)
457{ 459{
458 ide_drive_t *drive = q->queuedata; 460 ide_drive_t *drive = hctx->queue->queuedata;
459 ide_hwif_t *hwif = drive->hwif; 461 ide_hwif_t *hwif = drive->hwif;
460 struct ide_host *host = hwif->host; 462 struct ide_host *host = hwif->host;
461 struct request *rq = NULL; 463 struct request *rq = bd->rq;
462 ide_startstop_t startstop; 464 ide_startstop_t startstop;
463 465
464 spin_unlock_irq(q->queue_lock); 466 if (!blk_rq_is_passthrough(rq) && !(rq->rq_flags & RQF_DONTPREP)) {
467 rq->rq_flags |= RQF_DONTPREP;
468 ide_req(rq)->special = NULL;
469 }
465 470
466 /* HLD do_request() callback might sleep, make sure it's okay */ 471 /* HLD do_request() callback might sleep, make sure it's okay */
467 might_sleep(); 472 might_sleep();
468 473
469 if (ide_lock_host(host, hwif)) 474 if (ide_lock_host(host, hwif))
470 goto plug_device_2; 475 return BLK_STS_DEV_RESOURCE;
476
477 blk_mq_start_request(rq);
471 478
472 spin_lock_irq(&hwif->lock); 479 spin_lock_irq(&hwif->lock);
473 480
@@ -503,21 +510,16 @@ repeat:
503 hwif->cur_dev = drive; 510 hwif->cur_dev = drive;
504 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED); 511 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
505 512
506 spin_unlock_irq(&hwif->lock);
507 spin_lock_irq(q->queue_lock);
508 /* 513 /*
509 * we know that the queue isn't empty, but this can happen 514 * we know that the queue isn't empty, but this can happen
510 * if the q->prep_rq_fn() decides to kill a request 515 * if ->prep_rq() decides to kill a request
511 */ 516 */
512 if (!rq)
513 rq = blk_fetch_request(drive->queue);
514
515 spin_unlock_irq(q->queue_lock);
516 spin_lock_irq(&hwif->lock);
517
518 if (!rq) { 517 if (!rq) {
519 ide_unlock_port(hwif); 518 rq = bd->rq;
520 goto out; 519 if (!rq) {
520 ide_unlock_port(hwif);
521 goto out;
522 }
521 } 523 }
522 524
523 /* 525 /*
@@ -551,23 +553,24 @@ repeat:
551 if (startstop == ide_stopped) { 553 if (startstop == ide_stopped) {
552 rq = hwif->rq; 554 rq = hwif->rq;
553 hwif->rq = NULL; 555 hwif->rq = NULL;
554 goto repeat; 556 if (rq)
557 goto repeat;
558 ide_unlock_port(hwif);
559 goto out;
555 } 560 }
556 } else 561 } else {
557 goto plug_device; 562plug_device:
563 spin_unlock_irq(&hwif->lock);
564 ide_unlock_host(host);
565 ide_requeue_and_plug(drive, rq);
566 return BLK_STS_OK;
567 }
568
558out: 569out:
559 spin_unlock_irq(&hwif->lock); 570 spin_unlock_irq(&hwif->lock);
560 if (rq == NULL) 571 if (rq == NULL)
561 ide_unlock_host(host); 572 ide_unlock_host(host);
562 spin_lock_irq(q->queue_lock); 573 return BLK_STS_OK;
563 return;
564
565plug_device:
566 spin_unlock_irq(&hwif->lock);
567 ide_unlock_host(host);
568plug_device_2:
569 spin_lock_irq(q->queue_lock);
570 __ide_requeue_and_plug(q, rq);
571} 574}
572 575
573static int drive_is_ready(ide_drive_t *drive) 576static int drive_is_ready(ide_drive_t *drive)
@@ -887,3 +890,16 @@ void ide_pad_transfer(ide_drive_t *drive, int write, int len)
887 } 890 }
888} 891}
889EXPORT_SYMBOL_GPL(ide_pad_transfer); 892EXPORT_SYMBOL_GPL(ide_pad_transfer);
893
894void ide_insert_request_head(ide_drive_t *drive, struct request *rq)
895{
896 ide_hwif_t *hwif = drive->hwif;
897 unsigned long flags;
898
899 spin_lock_irqsave(&hwif->lock, flags);
900 list_add_tail(&rq->queuelist, &drive->rq_list);
901 spin_unlock_irqrestore(&hwif->lock, flags);
902
903 kblockd_schedule_work(&drive->rq_work);
904}
905EXPORT_SYMBOL_GPL(ide_insert_request_head);
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
index 622f0edb3945..102aa3bc3e7f 100644
--- a/drivers/ide/ide-park.c
+++ b/drivers/ide/ide-park.c
@@ -27,7 +27,7 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
27 spin_unlock_irq(&hwif->lock); 27 spin_unlock_irq(&hwif->lock);
28 28
29 if (start_queue) 29 if (start_queue)
30 blk_run_queue(q); 30 blk_mq_run_hw_queues(q, true);
31 return; 31 return;
32 } 32 }
33 spin_unlock_irq(&hwif->lock); 33 spin_unlock_irq(&hwif->lock);
@@ -36,7 +36,7 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
36 scsi_req(rq)->cmd[0] = REQ_PARK_HEADS; 36 scsi_req(rq)->cmd[0] = REQ_PARK_HEADS;
37 scsi_req(rq)->cmd_len = 1; 37 scsi_req(rq)->cmd_len = 1;
38 ide_req(rq)->type = ATA_PRIV_MISC; 38 ide_req(rq)->type = ATA_PRIV_MISC;
39 rq->special = &timeout; 39 ide_req(rq)->special = &timeout;
40 blk_execute_rq(q, NULL, rq, 1); 40 blk_execute_rq(q, NULL, rq, 1);
41 rc = scsi_req(rq)->result ? -EIO : 0; 41 rc = scsi_req(rq)->result ? -EIO : 0;
42 blk_put_request(rq); 42 blk_put_request(rq);
@@ -54,7 +54,7 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
54 scsi_req(rq)->cmd[0] = REQ_UNPARK_HEADS; 54 scsi_req(rq)->cmd[0] = REQ_UNPARK_HEADS;
55 scsi_req(rq)->cmd_len = 1; 55 scsi_req(rq)->cmd_len = 1;
56 ide_req(rq)->type = ATA_PRIV_MISC; 56 ide_req(rq)->type = ATA_PRIV_MISC;
57 elv_add_request(q, rq, ELEVATOR_INSERT_FRONT); 57 ide_insert_request_head(drive, rq);
58 58
59out: 59out:
60 return; 60 return;
@@ -67,7 +67,7 @@ ide_startstop_t ide_do_park_unpark(ide_drive_t *drive, struct request *rq)
67 67
68 memset(&cmd, 0, sizeof(cmd)); 68 memset(&cmd, 0, sizeof(cmd));
69 if (scsi_req(rq)->cmd[0] == REQ_PARK_HEADS) { 69 if (scsi_req(rq)->cmd[0] == REQ_PARK_HEADS) {
70 drive->sleep = *(unsigned long *)rq->special; 70 drive->sleep = *(unsigned long *)ide_req(rq)->special;
71 drive->dev_flags |= IDE_DFLAG_SLEEPING; 71 drive->dev_flags |= IDE_DFLAG_SLEEPING;
72 tf->command = ATA_CMD_IDLEIMMEDIATE; 72 tf->command = ATA_CMD_IDLEIMMEDIATE;
73 tf->feature = 0x44; 73 tf->feature = 0x44;
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
index 59217aa1d1fb..192e6c65d34e 100644
--- a/drivers/ide/ide-pm.c
+++ b/drivers/ide/ide-pm.c
@@ -21,7 +21,7 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
21 memset(&rqpm, 0, sizeof(rqpm)); 21 memset(&rqpm, 0, sizeof(rqpm));
22 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0); 22 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0);
23 ide_req(rq)->type = ATA_PRIV_PM_SUSPEND; 23 ide_req(rq)->type = ATA_PRIV_PM_SUSPEND;
24 rq->special = &rqpm; 24 ide_req(rq)->special = &rqpm;
25 rqpm.pm_step = IDE_PM_START_SUSPEND; 25 rqpm.pm_step = IDE_PM_START_SUSPEND;
26 if (mesg.event == PM_EVENT_PRETHAW) 26 if (mesg.event == PM_EVENT_PRETHAW)
27 mesg.event = PM_EVENT_FREEZE; 27 mesg.event = PM_EVENT_FREEZE;
@@ -40,32 +40,17 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
40 return ret; 40 return ret;
41} 41}
42 42
43static void ide_end_sync_rq(struct request *rq, blk_status_t error)
44{
45 complete(rq->end_io_data);
46}
47
48static int ide_pm_execute_rq(struct request *rq) 43static int ide_pm_execute_rq(struct request *rq)
49{ 44{
50 struct request_queue *q = rq->q; 45 struct request_queue *q = rq->q;
51 DECLARE_COMPLETION_ONSTACK(wait);
52 46
53 rq->end_io_data = &wait;
54 rq->end_io = ide_end_sync_rq;
55
56 spin_lock_irq(q->queue_lock);
57 if (unlikely(blk_queue_dying(q))) { 47 if (unlikely(blk_queue_dying(q))) {
58 rq->rq_flags |= RQF_QUIET; 48 rq->rq_flags |= RQF_QUIET;
59 scsi_req(rq)->result = -ENXIO; 49 scsi_req(rq)->result = -ENXIO;
60 __blk_end_request_all(rq, BLK_STS_OK); 50 blk_mq_end_request(rq, BLK_STS_OK);
61 spin_unlock_irq(q->queue_lock);
62 return -ENXIO; 51 return -ENXIO;
63 } 52 }
64 __elv_add_request(q, rq, ELEVATOR_INSERT_FRONT); 53 blk_execute_rq(q, NULL, rq, true);
65 __blk_run_queue_uncond(q);
66 spin_unlock_irq(q->queue_lock);
67
68 wait_for_completion_io(&wait);
69 54
70 return scsi_req(rq)->result ? -EIO : 0; 55 return scsi_req(rq)->result ? -EIO : 0;
71} 56}
@@ -79,6 +64,8 @@ int generic_ide_resume(struct device *dev)
79 struct ide_pm_state rqpm; 64 struct ide_pm_state rqpm;
80 int err; 65 int err;
81 66
67 blk_mq_start_stopped_hw_queues(drive->queue, true);
68
82 if (ide_port_acpi(hwif)) { 69 if (ide_port_acpi(hwif)) {
83 /* call ACPI _PS0 / _STM only once */ 70 /* call ACPI _PS0 / _STM only once */
84 if ((drive->dn & 1) == 0 || pair == NULL) { 71 if ((drive->dn & 1) == 0 || pair == NULL) {
@@ -92,7 +79,7 @@ int generic_ide_resume(struct device *dev)
92 memset(&rqpm, 0, sizeof(rqpm)); 79 memset(&rqpm, 0, sizeof(rqpm));
93 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, BLK_MQ_REQ_PREEMPT); 80 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, BLK_MQ_REQ_PREEMPT);
94 ide_req(rq)->type = ATA_PRIV_PM_RESUME; 81 ide_req(rq)->type = ATA_PRIV_PM_RESUME;
95 rq->special = &rqpm; 82 ide_req(rq)->special = &rqpm;
96 rqpm.pm_step = IDE_PM_START_RESUME; 83 rqpm.pm_step = IDE_PM_START_RESUME;
97 rqpm.pm_state = PM_EVENT_ON; 84 rqpm.pm_state = PM_EVENT_ON;
98 85
@@ -111,7 +98,7 @@ int generic_ide_resume(struct device *dev)
111 98
112void ide_complete_power_step(ide_drive_t *drive, struct request *rq) 99void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
113{ 100{
114 struct ide_pm_state *pm = rq->special; 101 struct ide_pm_state *pm = ide_req(rq)->special;
115 102
116#ifdef DEBUG_PM 103#ifdef DEBUG_PM
117 printk(KERN_INFO "%s: complete_power_step(step: %d)\n", 104 printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
@@ -141,7 +128,7 @@ void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
141 128
142ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) 129ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
143{ 130{
144 struct ide_pm_state *pm = rq->special; 131 struct ide_pm_state *pm = ide_req(rq)->special;
145 struct ide_cmd cmd = { }; 132 struct ide_cmd cmd = { };
146 133
147 switch (pm->pm_step) { 134 switch (pm->pm_step) {
@@ -213,8 +200,7 @@ out_do_tf:
213void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq) 200void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
214{ 201{
215 struct request_queue *q = drive->queue; 202 struct request_queue *q = drive->queue;
216 struct ide_pm_state *pm = rq->special; 203 struct ide_pm_state *pm = ide_req(rq)->special;
217 unsigned long flags;
218 204
219 ide_complete_power_step(drive, rq); 205 ide_complete_power_step(drive, rq);
220 if (pm->pm_step != IDE_PM_COMPLETED) 206 if (pm->pm_step != IDE_PM_COMPLETED)
@@ -224,22 +210,19 @@ void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
224 printk("%s: completing PM request, %s\n", drive->name, 210 printk("%s: completing PM request, %s\n", drive->name,
225 (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND) ? "suspend" : "resume"); 211 (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND) ? "suspend" : "resume");
226#endif 212#endif
227 spin_lock_irqsave(q->queue_lock, flags);
228 if (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND) 213 if (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND)
229 blk_stop_queue(q); 214 blk_mq_stop_hw_queues(q);
230 else 215 else
231 drive->dev_flags &= ~IDE_DFLAG_BLOCKED; 216 drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
232 spin_unlock_irqrestore(q->queue_lock, flags);
233 217
234 drive->hwif->rq = NULL; 218 drive->hwif->rq = NULL;
235 219
236 if (blk_end_request(rq, BLK_STS_OK, 0)) 220 blk_mq_end_request(rq, BLK_STS_OK);
237 BUG();
238} 221}
239 222
240void ide_check_pm_state(ide_drive_t *drive, struct request *rq) 223void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
241{ 224{
242 struct ide_pm_state *pm = rq->special; 225 struct ide_pm_state *pm = ide_req(rq)->special;
243 226
244 if (blk_rq_is_private(rq) && 227 if (blk_rq_is_private(rq) &&
245 ide_req(rq)->type == ATA_PRIV_PM_SUSPEND && 228 ide_req(rq)->type == ATA_PRIV_PM_SUSPEND &&
@@ -260,7 +243,6 @@ void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
260 ide_hwif_t *hwif = drive->hwif; 243 ide_hwif_t *hwif = drive->hwif;
261 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 244 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
262 struct request_queue *q = drive->queue; 245 struct request_queue *q = drive->queue;
263 unsigned long flags;
264 int rc; 246 int rc;
265#ifdef DEBUG_PM 247#ifdef DEBUG_PM
266 printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name); 248 printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
@@ -274,8 +256,6 @@ void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
274 if (rc) 256 if (rc)
275 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name); 257 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
276 258
277 spin_lock_irqsave(q->queue_lock, flags); 259 blk_mq_start_hw_queues(q);
278 blk_start_queue(q);
279 spin_unlock_irqrestore(q->queue_lock, flags);
280 } 260 }
281} 261}
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 3b75a7b7a284..63627be0811a 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -746,10 +746,16 @@ static void ide_initialize_rq(struct request *rq)
746{ 746{
747 struct ide_request *req = blk_mq_rq_to_pdu(rq); 747 struct ide_request *req = blk_mq_rq_to_pdu(rq);
748 748
749 req->special = NULL;
749 scsi_req_init(&req->sreq); 750 scsi_req_init(&req->sreq);
750 req->sreq.sense = req->sense; 751 req->sreq.sense = req->sense;
751} 752}
752 753
754static const struct blk_mq_ops ide_mq_ops = {
755 .queue_rq = ide_queue_rq,
756 .initialize_rq_fn = ide_initialize_rq,
757};
758
753/* 759/*
754 * init request queue 760 * init request queue
755 */ 761 */
@@ -759,6 +765,7 @@ static int ide_init_queue(ide_drive_t *drive)
759 ide_hwif_t *hwif = drive->hwif; 765 ide_hwif_t *hwif = drive->hwif;
760 int max_sectors = 256; 766 int max_sectors = 256;
761 int max_sg_entries = PRD_ENTRIES; 767 int max_sg_entries = PRD_ENTRIES;
768 struct blk_mq_tag_set *set;
762 769
763 /* 770 /*
764 * Our default set up assumes the normal IDE case, 771 * Our default set up assumes the normal IDE case,
@@ -767,19 +774,26 @@ static int ide_init_queue(ide_drive_t *drive)
767 * limits and LBA48 we could raise it but as yet 774 * limits and LBA48 we could raise it but as yet
768 * do not. 775 * do not.
769 */ 776 */
770 q = blk_alloc_queue_node(GFP_KERNEL, hwif_to_node(hwif), NULL); 777
771 if (!q) 778 set = &drive->tag_set;
779 set->ops = &ide_mq_ops;
780 set->nr_hw_queues = 1;
781 set->queue_depth = 32;
782 set->reserved_tags = 1;
783 set->cmd_size = sizeof(struct ide_request);
784 set->numa_node = hwif_to_node(hwif);
785 set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
786 if (blk_mq_alloc_tag_set(set))
772 return 1; 787 return 1;
773 788
774 q->request_fn = do_ide_request; 789 q = blk_mq_init_queue(set);
775 q->initialize_rq_fn = ide_initialize_rq; 790 if (IS_ERR(q)) {
776 q->cmd_size = sizeof(struct ide_request); 791 blk_mq_free_tag_set(set);
777 blk_queue_flag_set(QUEUE_FLAG_SCSI_PASSTHROUGH, q);
778 if (blk_init_allocated_queue(q) < 0) {
779 blk_cleanup_queue(q);
780 return 1; 792 return 1;
781 } 793 }
782 794
795 blk_queue_flag_set(QUEUE_FLAG_SCSI_PASSTHROUGH, q);
796
783 q->queuedata = drive; 797 q->queuedata = drive;
784 blk_queue_segment_boundary(q, 0xffff); 798 blk_queue_segment_boundary(q, 0xffff);
785 799
@@ -965,8 +979,12 @@ static void drive_release_dev (struct device *dev)
965 979
966 ide_proc_unregister_device(drive); 980 ide_proc_unregister_device(drive);
967 981
982 if (drive->sense_rq)
983 blk_mq_free_request(drive->sense_rq);
984
968 blk_cleanup_queue(drive->queue); 985 blk_cleanup_queue(drive->queue);
969 drive->queue = NULL; 986 drive->queue = NULL;
987 blk_mq_free_tag_set(&drive->tag_set);
970 988
971 drive->dev_flags &= ~IDE_DFLAG_PRESENT; 989 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
972 990
@@ -1133,6 +1151,28 @@ static void ide_port_cable_detect(ide_hwif_t *hwif)
1133 } 1151 }
1134} 1152}
1135 1153
1154/*
1155 * Deferred request list insertion handler
1156 */
1157static void drive_rq_insert_work(struct work_struct *work)
1158{
1159 ide_drive_t *drive = container_of(work, ide_drive_t, rq_work);
1160 ide_hwif_t *hwif = drive->hwif;
1161 struct request *rq;
1162 LIST_HEAD(list);
1163
1164 spin_lock_irq(&hwif->lock);
1165 if (!list_empty(&drive->rq_list))
1166 list_splice_init(&drive->rq_list, &list);
1167 spin_unlock_irq(&hwif->lock);
1168
1169 while (!list_empty(&list)) {
1170 rq = list_first_entry(&list, struct request, queuelist);
1171 list_del_init(&rq->queuelist);
1172 blk_execute_rq_nowait(drive->queue, rq->rq_disk, rq, true, NULL);
1173 }
1174}
1175
1136static const u8 ide_hwif_to_major[] = 1176static const u8 ide_hwif_to_major[] =
1137 { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR, IDE4_MAJOR, 1177 { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR, IDE4_MAJOR,
1138 IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR, IDE8_MAJOR, IDE9_MAJOR }; 1178 IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR, IDE8_MAJOR, IDE9_MAJOR };
@@ -1145,12 +1185,10 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
1145 ide_port_for_each_dev(i, drive, hwif) { 1185 ide_port_for_each_dev(i, drive, hwif) {
1146 u8 j = (hwif->index * MAX_DRIVES) + i; 1186 u8 j = (hwif->index * MAX_DRIVES) + i;
1147 u16 *saved_id = drive->id; 1187 u16 *saved_id = drive->id;
1148 struct request *saved_sense_rq = drive->sense_rq;
1149 1188
1150 memset(drive, 0, sizeof(*drive)); 1189 memset(drive, 0, sizeof(*drive));
1151 memset(saved_id, 0, SECTOR_SIZE); 1190 memset(saved_id, 0, SECTOR_SIZE);
1152 drive->id = saved_id; 1191 drive->id = saved_id;
1153 drive->sense_rq = saved_sense_rq;
1154 1192
1155 drive->media = ide_disk; 1193 drive->media = ide_disk;
1156 drive->select = (i << 4) | ATA_DEVICE_OBS; 1194 drive->select = (i << 4) | ATA_DEVICE_OBS;
@@ -1166,6 +1204,9 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
1166 1204
1167 INIT_LIST_HEAD(&drive->list); 1205 INIT_LIST_HEAD(&drive->list);
1168 init_completion(&drive->gendev_rel_comp); 1206 init_completion(&drive->gendev_rel_comp);
1207
1208 INIT_WORK(&drive->rq_work, drive_rq_insert_work);
1209 INIT_LIST_HEAD(&drive->rq_list);
1169 } 1210 }
1170} 1211}
1171 1212
@@ -1255,7 +1296,6 @@ static void ide_port_free_devices(ide_hwif_t *hwif)
1255 int i; 1296 int i;
1256 1297
1257 ide_port_for_each_dev(i, drive, hwif) { 1298 ide_port_for_each_dev(i, drive, hwif) {
1258 kfree(drive->sense_rq);
1259 kfree(drive->id); 1299 kfree(drive->id);
1260 kfree(drive); 1300 kfree(drive);
1261 } 1301 }
@@ -1283,17 +1323,10 @@ static int ide_port_alloc_devices(ide_hwif_t *hwif, int node)
1283 if (drive->id == NULL) 1323 if (drive->id == NULL)
1284 goto out_free_drive; 1324 goto out_free_drive;
1285 1325
1286 drive->sense_rq = kmalloc(sizeof(struct request) +
1287 sizeof(struct ide_request), GFP_KERNEL);
1288 if (!drive->sense_rq)
1289 goto out_free_id;
1290
1291 hwif->devices[i] = drive; 1326 hwif->devices[i] = drive;
1292 } 1327 }
1293 return 0; 1328 return 0;
1294 1329
1295out_free_id:
1296 kfree(drive->id);
1297out_free_drive: 1330out_free_drive:
1298 kfree(drive); 1331 kfree(drive);
1299out_nomem: 1332out_nomem:
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 34c1165226a4..db1a65f4b490 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -639,7 +639,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
639 goto out; 639 goto out;
640 } 640 }
641 if (req->cmd[13] & REQ_IDETAPE_PC1) { 641 if (req->cmd[13] & REQ_IDETAPE_PC1) {
642 pc = (struct ide_atapi_pc *)rq->special; 642 pc = (struct ide_atapi_pc *)ide_req(rq)->special;
643 req->cmd[13] &= ~(REQ_IDETAPE_PC1); 643 req->cmd[13] &= ~(REQ_IDETAPE_PC1);
644 req->cmd[13] |= REQ_IDETAPE_PC2; 644 req->cmd[13] |= REQ_IDETAPE_PC2;
645 goto out; 645 goto out;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index c21d5c50ae3a..17b2e379e872 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -440,7 +440,7 @@ int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
440 goto put_req; 440 goto put_req;
441 } 441 }
442 442
443 rq->special = cmd; 443 ide_req(rq)->special = cmd;
444 cmd->rq = rq; 444 cmd->rq = rq;
445 445
446 blk_execute_rq(drive->queue, NULL, rq, 0); 446 blk_execute_rq(drive->queue, NULL, rq, 0);