| .. | .. |
|---|
| 67 | 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 | + drive->sense_rq_active = false; |
|---|
| 74 | + } |
|---|
| 75 | + |
|---|
| 76 | + __blk_mq_end_request(rq, error); |
|---|
| 77 | + return 0; |
|---|
| 78 | + } |
|---|
| 79 | + |
|---|
| 80 | + return 1; |
|---|
| 71 | 81 | } |
|---|
| 72 | 82 | EXPORT_SYMBOL_GPL(ide_end_rq); |
|---|
| 73 | 83 | |
|---|
| .. | .. |
|---|
| 103 | 113 | } |
|---|
| 104 | 114 | |
|---|
| 105 | 115 | if (rq && ata_taskfile_request(rq)) { |
|---|
| 106 | | - struct ide_cmd *orig_cmd = rq->special; |
|---|
| 116 | + struct ide_cmd *orig_cmd = ide_req(rq)->special; |
|---|
| 107 | 117 | |
|---|
| 108 | 118 | if (cmd->tf_flags & IDE_TFLAG_DYN) |
|---|
| 109 | 119 | kfree(orig_cmd); |
|---|
| .. | .. |
|---|
| 223 | 233 | void ide_map_sg(ide_drive_t *drive, struct ide_cmd *cmd) |
|---|
| 224 | 234 | { |
|---|
| 225 | 235 | ide_hwif_t *hwif = drive->hwif; |
|---|
| 226 | | - struct scatterlist *sg = hwif->sg_table; |
|---|
| 236 | + struct scatterlist *sg = hwif->sg_table, *last_sg = NULL; |
|---|
| 227 | 237 | struct request *rq = cmd->rq; |
|---|
| 228 | 238 | |
|---|
| 229 | | - cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg); |
|---|
| 239 | + cmd->sg_nents = __blk_rq_map_sg(drive->queue, rq, sg, &last_sg); |
|---|
| 240 | + if (blk_rq_bytes(rq) && (blk_rq_bytes(rq) & rq->q->dma_pad_mask)) |
|---|
| 241 | + last_sg->length += |
|---|
| 242 | + (rq->q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1; |
|---|
| 230 | 243 | } |
|---|
| 231 | 244 | EXPORT_SYMBOL_GPL(ide_map_sg); |
|---|
| 232 | 245 | |
|---|
| .. | .. |
|---|
| 253 | 266 | static ide_startstop_t execute_drive_cmd (ide_drive_t *drive, |
|---|
| 254 | 267 | struct request *rq) |
|---|
| 255 | 268 | { |
|---|
| 256 | | - struct ide_cmd *cmd = rq->special; |
|---|
| 269 | + struct ide_cmd *cmd = ide_req(rq)->special; |
|---|
| 257 | 270 | |
|---|
| 258 | 271 | if (cmd) { |
|---|
| 259 | 272 | if (cmd->protocol == ATA_PROT_PIO) { |
|---|
| .. | .. |
|---|
| 307 | 320 | { |
|---|
| 308 | 321 | ide_startstop_t startstop; |
|---|
| 309 | 322 | |
|---|
| 310 | | - BUG_ON(!(rq->rq_flags & RQF_STARTED)); |
|---|
| 311 | | - |
|---|
| 312 | 323 | #ifdef DEBUG |
|---|
| 313 | 324 | printk("%s: start_request: current=0x%08lx\n", |
|---|
| 314 | 325 | drive->hwif->name, (unsigned long) rq); |
|---|
| .. | .. |
|---|
| 319 | 330 | rq->rq_flags |= RQF_FAILED; |
|---|
| 320 | 331 | goto kill_rq; |
|---|
| 321 | 332 | } |
|---|
| 333 | + |
|---|
| 334 | + if (drive->prep_rq && !drive->prep_rq(drive, rq)) |
|---|
| 335 | + return ide_stopped; |
|---|
| 322 | 336 | |
|---|
| 323 | 337 | if (ata_pm_request(rq)) |
|---|
| 324 | 338 | ide_check_pm_state(drive, rq); |
|---|
| .. | .. |
|---|
| 343 | 357 | if (ata_taskfile_request(rq)) |
|---|
| 344 | 358 | return execute_drive_cmd(drive, rq); |
|---|
| 345 | 359 | else if (ata_pm_request(rq)) { |
|---|
| 346 | | - struct ide_pm_state *pm = rq->special; |
|---|
| 360 | + struct ide_pm_state *pm = ide_req(rq)->special; |
|---|
| 347 | 361 | #ifdef DEBUG_PM |
|---|
| 348 | 362 | printk("%s: start_power_step(step: %d)\n", |
|---|
| 349 | 363 | drive->name, pm->pm_step); |
|---|
| .. | .. |
|---|
| 430 | 444 | } |
|---|
| 431 | 445 | } |
|---|
| 432 | 446 | |
|---|
| 433 | | -static 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 | | - |
|---|
| 443 | 447 | void ide_requeue_and_plug(ide_drive_t *drive, struct request *rq) |
|---|
| 444 | 448 | { |
|---|
| 445 | 449 | struct request_queue *q = drive->queue; |
|---|
| 446 | | - unsigned long flags; |
|---|
| 447 | 450 | |
|---|
| 448 | | - spin_lock_irqsave(q->queue_lock, flags); |
|---|
| 449 | | - __ide_requeue_and_plug(q, rq); |
|---|
| 450 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
|---|
| 451 | + /* Use 3ms as that was the old plug delay */ |
|---|
| 452 | + if (rq) { |
|---|
| 453 | + blk_mq_requeue_request(rq, false); |
|---|
| 454 | + blk_mq_delay_kick_requeue_list(q, 3); |
|---|
| 455 | + } else |
|---|
| 456 | + blk_mq_delay_run_hw_queue(q->queue_hw_ctx[0], 3); |
|---|
| 451 | 457 | } |
|---|
| 452 | 458 | |
|---|
| 453 | | -/* |
|---|
| 454 | | - * Issue a new request to a device. |
|---|
| 455 | | - */ |
|---|
| 456 | | -void do_ide_request(struct request_queue *q) |
|---|
| 459 | +blk_status_t ide_issue_rq(ide_drive_t *drive, struct request *rq, |
|---|
| 460 | + bool local_requeue) |
|---|
| 457 | 461 | { |
|---|
| 458 | | - ide_drive_t *drive = q->queuedata; |
|---|
| 459 | | - ide_hwif_t *hwif = drive->hwif; |
|---|
| 462 | + ide_hwif_t *hwif = drive->hwif; |
|---|
| 460 | 463 | struct ide_host *host = hwif->host; |
|---|
| 461 | | - struct request *rq = NULL; |
|---|
| 462 | 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 | 471 | /* HLD do_request() callback might sleep, make sure it's okay */ |
|---|
| 467 | 472 | might_sleep(); |
|---|
| 468 | 473 | |
|---|
| 469 | 474 | if (ide_lock_host(host, hwif)) |
|---|
| 470 | | - goto plug_device_2; |
|---|
| 475 | + return BLK_STS_DEV_RESOURCE; |
|---|
| 471 | 476 | |
|---|
| 472 | 477 | spin_lock_irq(&hwif->lock); |
|---|
| 473 | 478 | |
|---|
| .. | .. |
|---|
| 503 | 508 | hwif->cur_dev = drive; |
|---|
| 504 | 509 | drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED); |
|---|
| 505 | 510 | |
|---|
| 506 | | - spin_unlock_irq(&hwif->lock); |
|---|
| 507 | | - spin_lock_irq(q->queue_lock); |
|---|
| 508 | | - /* |
|---|
| 509 | | - * we know that the queue isn't empty, but this can happen |
|---|
| 510 | | - * if the q->prep_rq_fn() decides to kill a request |
|---|
| 511 | | - */ |
|---|
| 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) { |
|---|
| 519 | | - ide_unlock_port(hwif); |
|---|
| 520 | | - goto out; |
|---|
| 521 | | - } |
|---|
| 522 | | - |
|---|
| 523 | 511 | /* |
|---|
| 524 | 512 | * Sanity: don't accept a request that isn't a PM request |
|---|
| 525 | 513 | * if we are currently power managed. This is very important as |
|---|
| .. | .. |
|---|
| 530 | 518 | */ |
|---|
| 531 | 519 | if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && |
|---|
| 532 | 520 | ata_pm_request(rq) == 0 && |
|---|
| 533 | | - (rq->rq_flags & RQF_PREEMPT) == 0) { |
|---|
| 521 | + (rq->rq_flags & RQF_PM) == 0) { |
|---|
| 534 | 522 | /* there should be no pending command at this point */ |
|---|
| 535 | 523 | ide_unlock_port(hwif); |
|---|
| 536 | 524 | goto plug_device; |
|---|
| .. | .. |
|---|
| 546 | 534 | if (startstop == ide_stopped) { |
|---|
| 547 | 535 | rq = hwif->rq; |
|---|
| 548 | 536 | hwif->rq = NULL; |
|---|
| 549 | | - goto repeat; |
|---|
| 537 | + if (rq) |
|---|
| 538 | + goto repeat; |
|---|
| 539 | + ide_unlock_port(hwif); |
|---|
| 540 | + goto out; |
|---|
| 550 | 541 | } |
|---|
| 551 | | - } else |
|---|
| 552 | | - goto plug_device; |
|---|
| 542 | + } else { |
|---|
| 543 | +plug_device: |
|---|
| 544 | + if (local_requeue) |
|---|
| 545 | + list_add(&rq->queuelist, &drive->rq_list); |
|---|
| 546 | + spin_unlock_irq(&hwif->lock); |
|---|
| 547 | + ide_unlock_host(host); |
|---|
| 548 | + if (!local_requeue) |
|---|
| 549 | + ide_requeue_and_plug(drive, rq); |
|---|
| 550 | + return BLK_STS_OK; |
|---|
| 551 | + } |
|---|
| 552 | + |
|---|
| 553 | 553 | out: |
|---|
| 554 | 554 | spin_unlock_irq(&hwif->lock); |
|---|
| 555 | 555 | if (rq == NULL) |
|---|
| 556 | 556 | ide_unlock_host(host); |
|---|
| 557 | | - spin_lock_irq(q->queue_lock); |
|---|
| 558 | | - return; |
|---|
| 557 | + return BLK_STS_OK; |
|---|
| 558 | +} |
|---|
| 559 | 559 | |
|---|
| 560 | | -plug_device: |
|---|
| 560 | +/* |
|---|
| 561 | + * Issue a new request to a device. |
|---|
| 562 | + */ |
|---|
| 563 | +blk_status_t ide_queue_rq(struct blk_mq_hw_ctx *hctx, |
|---|
| 564 | + const struct blk_mq_queue_data *bd) |
|---|
| 565 | +{ |
|---|
| 566 | + ide_drive_t *drive = hctx->queue->queuedata; |
|---|
| 567 | + ide_hwif_t *hwif = drive->hwif; |
|---|
| 568 | + |
|---|
| 569 | + spin_lock_irq(&hwif->lock); |
|---|
| 570 | + if (drive->sense_rq_active) { |
|---|
| 571 | + spin_unlock_irq(&hwif->lock); |
|---|
| 572 | + return BLK_STS_DEV_RESOURCE; |
|---|
| 573 | + } |
|---|
| 561 | 574 | spin_unlock_irq(&hwif->lock); |
|---|
| 562 | | - ide_unlock_host(host); |
|---|
| 563 | | -plug_device_2: |
|---|
| 564 | | - spin_lock_irq(q->queue_lock); |
|---|
| 565 | | - __ide_requeue_and_plug(q, rq); |
|---|
| 575 | + |
|---|
| 576 | + blk_mq_start_request(bd->rq); |
|---|
| 577 | + return ide_issue_rq(drive, bd->rq, false); |
|---|
| 566 | 578 | } |
|---|
| 567 | 579 | |
|---|
| 568 | 580 | static int drive_is_ready(ide_drive_t *drive) |
|---|
| .. | .. |
|---|
| 605 | 617 | void ide_timer_expiry (struct timer_list *t) |
|---|
| 606 | 618 | { |
|---|
| 607 | 619 | ide_hwif_t *hwif = from_timer(hwif, t, timer); |
|---|
| 608 | | - ide_drive_t *uninitialized_var(drive); |
|---|
| 620 | + ide_drive_t *drive; |
|---|
| 609 | 621 | ide_handler_t *handler; |
|---|
| 610 | 622 | unsigned long flags; |
|---|
| 611 | 623 | int wait = -1; |
|---|
| 612 | 624 | int plug_device = 0; |
|---|
| 613 | | - struct request *uninitialized_var(rq_in_flight); |
|---|
| 625 | + struct request *rq_in_flight; |
|---|
| 614 | 626 | |
|---|
| 615 | 627 | spin_lock_irqsave(&hwif->lock, flags); |
|---|
| 616 | 628 | |
|---|
| .. | .. |
|---|
| 763 | 775 | { |
|---|
| 764 | 776 | ide_hwif_t *hwif = (ide_hwif_t *)dev_id; |
|---|
| 765 | 777 | struct ide_host *host = hwif->host; |
|---|
| 766 | | - ide_drive_t *uninitialized_var(drive); |
|---|
| 778 | + ide_drive_t *drive; |
|---|
| 767 | 779 | ide_handler_t *handler; |
|---|
| 768 | 780 | unsigned long flags; |
|---|
| 769 | 781 | ide_startstop_t startstop; |
|---|
| 770 | 782 | irqreturn_t irq_ret = IRQ_NONE; |
|---|
| 771 | 783 | int plug_device = 0; |
|---|
| 772 | | - struct request *uninitialized_var(rq_in_flight); |
|---|
| 784 | + struct request *rq_in_flight; |
|---|
| 773 | 785 | |
|---|
| 774 | 786 | if (host->host_flags & IDE_HFLAG_SERIALIZE) { |
|---|
| 775 | 787 | if (hwif != host->cur_port) |
|---|
| .. | .. |
|---|
| 882 | 894 | } |
|---|
| 883 | 895 | } |
|---|
| 884 | 896 | EXPORT_SYMBOL_GPL(ide_pad_transfer); |
|---|
| 897 | + |
|---|
| 898 | +void ide_insert_request_head(ide_drive_t *drive, struct request *rq) |
|---|
| 899 | +{ |
|---|
| 900 | + drive->sense_rq_active = true; |
|---|
| 901 | + list_add_tail(&rq->queuelist, &drive->rq_list); |
|---|
| 902 | + kblockd_schedule_work(&drive->rq_work); |
|---|
| 903 | +} |
|---|
| 904 | +EXPORT_SYMBOL_GPL(ide_insert_request_head); |
|---|