Commit a1317f714af7aed60ddc182d0122477cbe36ee9b

Authored by Bartlomiej Zolnierkiewicz
Committed by David S. Miller
1 parent ba9413bd28

ide: improve handling of Power Management requests

Make hwif->rq point to PM request during PM sequence and do not allow
any other types of requests to slip in (the old comment was never correct
as there should be no such requests generated during PM sequence).

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 22 additions and 32 deletions Side-by-side Diff

drivers/ide/ide-io.c
... ... @@ -476,10 +476,14 @@
476 476  
477 477 if (!ide_lock_port(hwif)) {
478 478 ide_hwif_t *prev_port;
479   -
480   - WARN_ON_ONCE(hwif->rq);
481 479 repeat:
482 480 prev_port = hwif->host->cur_port;
  481 +
  482 + if (drive->dev_flags & IDE_DFLAG_BLOCKED)
  483 + rq = hwif->rq;
  484 + else
  485 + WARN_ON_ONCE(hwif->rq);
  486 +
483 487 if (drive->dev_flags & IDE_DFLAG_SLEEPING &&
484 488 time_after(drive->sleep, jiffies)) {
485 489 ide_unlock_port(hwif);
486 490  
487 491  
488 492  
489 493  
... ... @@ -506,43 +510,29 @@
506 510 hwif->cur_dev = drive;
507 511 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
508 512  
509   - spin_unlock_irq(&hwif->lock);
510   - spin_lock_irq(q->queue_lock);
511   - /*
512   - * we know that the queue isn't empty, but this can happen
513   - * if the q->prep_rq_fn() decides to kill a request
514   - */
515   - if (!rq)
  513 + if (rq == NULL) {
  514 + spin_unlock_irq(&hwif->lock);
  515 + spin_lock_irq(q->queue_lock);
  516 + /*
  517 + * we know that the queue isn't empty, but this can
  518 + * happen if ->prep_rq_fn() decides to kill a request
  519 + */
516 520 rq = blk_fetch_request(drive->queue);
  521 + spin_unlock_irq(q->queue_lock);
  522 + spin_lock_irq(&hwif->lock);
517 523  
518   - spin_unlock_irq(q->queue_lock);
519   - spin_lock_irq(&hwif->lock);
520   -
521   - if (!rq) {
522   - ide_unlock_port(hwif);
523   - goto out;
  524 + if (rq == NULL) {
  525 + ide_unlock_port(hwif);
  526 + goto out;
  527 + }
524 528 }
525 529  
526 530 /*
527 531 * Sanity: don't accept a request that isn't a PM request
528   - * if we are currently power managed. This is very important as
529   - * blk_stop_queue() doesn't prevent the blk_fetch_request()
530   - * above to return us whatever is in the queue. Since we call
531   - * ide_do_request() ourselves, we end up taking requests while
532   - * the queue is blocked...
533   - *
534   - * We let requests forced at head of queue with ide-preempt
535   - * though. I hope that doesn't happen too much, hopefully not
536   - * unless the subdriver triggers such a thing in its own PM
537   - * state machine.
  532 + * if we are currently power managed.
538 533 */
539   - if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
540   - blk_pm_request(rq) == 0 &&
541   - (rq->cmd_flags & REQ_PREEMPT) == 0) {
542   - /* there should be no pending command at this point */
543   - ide_unlock_port(hwif);
544   - goto plug_device;
545   - }
  534 + BUG_ON((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
  535 + blk_pm_request(rq) == 0);
546 536  
547 537 hwif->rq = rq;
548 538