hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/ide/ide-io.c
....@@ -67,7 +67,17 @@
6767 ide_dma_on(drive);
6868 }
6969
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;
7181 }
7282 EXPORT_SYMBOL_GPL(ide_end_rq);
7383
....@@ -103,7 +113,7 @@
103113 }
104114
105115 if (rq && ata_taskfile_request(rq)) {
106
- struct ide_cmd *orig_cmd = rq->special;
116
+ struct ide_cmd *orig_cmd = ide_req(rq)->special;
107117
108118 if (cmd->tf_flags & IDE_TFLAG_DYN)
109119 kfree(orig_cmd);
....@@ -223,10 +233,13 @@
223233 void ide_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
224234 {
225235 ide_hwif_t *hwif = drive->hwif;
226
- struct scatterlist *sg = hwif->sg_table;
236
+ struct scatterlist *sg = hwif->sg_table, *last_sg = NULL;
227237 struct request *rq = cmd->rq;
228238
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;
230243 }
231244 EXPORT_SYMBOL_GPL(ide_map_sg);
232245
....@@ -253,7 +266,7 @@
253266 static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
254267 struct request *rq)
255268 {
256
- struct ide_cmd *cmd = rq->special;
269
+ struct ide_cmd *cmd = ide_req(rq)->special;
257270
258271 if (cmd) {
259272 if (cmd->protocol == ATA_PROT_PIO) {
....@@ -307,8 +320,6 @@
307320 {
308321 ide_startstop_t startstop;
309322
310
- BUG_ON(!(rq->rq_flags & RQF_STARTED));
311
-
312323 #ifdef DEBUG
313324 printk("%s: start_request: current=0x%08lx\n",
314325 drive->hwif->name, (unsigned long) rq);
....@@ -319,6 +330,9 @@
319330 rq->rq_flags |= RQF_FAILED;
320331 goto kill_rq;
321332 }
333
+
334
+ if (drive->prep_rq && !drive->prep_rq(drive, rq))
335
+ return ide_stopped;
322336
323337 if (ata_pm_request(rq))
324338 ide_check_pm_state(drive, rq);
....@@ -343,7 +357,7 @@
343357 if (ata_taskfile_request(rq))
344358 return execute_drive_cmd(drive, rq);
345359 else if (ata_pm_request(rq)) {
346
- struct ide_pm_state *pm = rq->special;
360
+ struct ide_pm_state *pm = ide_req(rq)->special;
347361 #ifdef DEBUG_PM
348362 printk("%s: start_power_step(step: %d)\n",
349363 drive->name, pm->pm_step);
....@@ -430,44 +444,35 @@
430444 }
431445 }
432446
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
-
443447 void ide_requeue_and_plug(ide_drive_t *drive, struct request *rq)
444448 {
445449 struct request_queue *q = drive->queue;
446
- unsigned long flags;
447450
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);
451457 }
452458
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)
457461 {
458
- ide_drive_t *drive = q->queuedata;
459
- ide_hwif_t *hwif = drive->hwif;
462
+ ide_hwif_t *hwif = drive->hwif;
460463 struct ide_host *host = hwif->host;
461
- struct request *rq = NULL;
462464 ide_startstop_t startstop;
463465
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
+ }
465470
466471 /* HLD do_request() callback might sleep, make sure it's okay */
467472 might_sleep();
468473
469474 if (ide_lock_host(host, hwif))
470
- goto plug_device_2;
475
+ return BLK_STS_DEV_RESOURCE;
471476
472477 spin_lock_irq(&hwif->lock);
473478
....@@ -503,23 +508,6 @@
503508 hwif->cur_dev = drive;
504509 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
505510
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
-
523511 /*
524512 * Sanity: don't accept a request that isn't a PM request
525513 * if we are currently power managed. This is very important as
....@@ -530,7 +518,7 @@
530518 */
531519 if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
532520 ata_pm_request(rq) == 0 &&
533
- (rq->rq_flags & RQF_PREEMPT) == 0) {
521
+ (rq->rq_flags & RQF_PM) == 0) {
534522 /* there should be no pending command at this point */
535523 ide_unlock_port(hwif);
536524 goto plug_device;
....@@ -546,23 +534,47 @@
546534 if (startstop == ide_stopped) {
547535 rq = hwif->rq;
548536 hwif->rq = NULL;
549
- goto repeat;
537
+ if (rq)
538
+ goto repeat;
539
+ ide_unlock_port(hwif);
540
+ goto out;
550541 }
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
+
553553 out:
554554 spin_unlock_irq(&hwif->lock);
555555 if (rq == NULL)
556556 ide_unlock_host(host);
557
- spin_lock_irq(q->queue_lock);
558
- return;
557
+ return BLK_STS_OK;
558
+}
559559
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
+ }
561574 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);
566578 }
567579
568580 static int drive_is_ready(ide_drive_t *drive)
....@@ -605,12 +617,12 @@
605617 void ide_timer_expiry (struct timer_list *t)
606618 {
607619 ide_hwif_t *hwif = from_timer(hwif, t, timer);
608
- ide_drive_t *uninitialized_var(drive);
620
+ ide_drive_t *drive;
609621 ide_handler_t *handler;
610622 unsigned long flags;
611623 int wait = -1;
612624 int plug_device = 0;
613
- struct request *uninitialized_var(rq_in_flight);
625
+ struct request *rq_in_flight;
614626
615627 spin_lock_irqsave(&hwif->lock, flags);
616628
....@@ -763,13 +775,13 @@
763775 {
764776 ide_hwif_t *hwif = (ide_hwif_t *)dev_id;
765777 struct ide_host *host = hwif->host;
766
- ide_drive_t *uninitialized_var(drive);
778
+ ide_drive_t *drive;
767779 ide_handler_t *handler;
768780 unsigned long flags;
769781 ide_startstop_t startstop;
770782 irqreturn_t irq_ret = IRQ_NONE;
771783 int plug_device = 0;
772
- struct request *uninitialized_var(rq_in_flight);
784
+ struct request *rq_in_flight;
773785
774786 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
775787 if (hwif != host->cur_port)
....@@ -882,3 +894,11 @@
882894 }
883895 }
884896 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);