diff options
author | Finn Thain <fthain@telegraphics.com.au> | 2014-11-12 00:12:08 -0500 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2014-11-20 03:11:13 -0500 |
commit | 16b29e75a78ae03250233468b68f7ae467d3dc7a (patch) | |
tree | a5ba9e016d5557d2a6f5fb60dc83ae906ae771af /drivers/scsi/atari_scsi.c | |
parent | cbad48deb38d8e442db9760ca1f950cd24429707 (diff) |
atari_scsi: Fix atari_scsi deadlocks on Falcon
Don't disable irqs when waiting for the ST DMA "lock"; its release may
require an interrupt.
Introduce stdma_try_lock() for use in soft irq context. atari_scsi now tells
the SCSI mid-layer to defer queueing a command if the ST DMA lock is not
available, as per Michael's patch:
http://marc.info/?l=linux-m68k&m=139095335824863&w=2
The falcon_got_lock variable is race prone: we can't disable IRQs while
waiting to acquire the lock, so after acquiring it there must be some
interval during which falcon_got_lock remains false. Introduce
stdma_is_locked_by() to replace falcon_got_lock.
The falcon_got_lock tests in the EH handlers are incorrect these days. It
can happen that an EH handler is called after a command completes normally.
Remove these checks along with falcon_got_lock.
Also remove the complicated and racy fairness wait queues. If fairness is an
issue (when SCSI competes with IDE for the ST DMA interrupt), the solution
is likely to be a lower value for host->can_queue.
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Tested-by: Michael Schmitz <schmitzmic@gmail.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/scsi/atari_scsi.c')
-rw-r--r-- | drivers/scsi/atari_scsi.c | 75 |
1 files changed, 14 insertions, 61 deletions
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c index 48fabebdbbb0..b2e86d0630ce 100644 --- a/drivers/scsi/atari_scsi.c +++ b/drivers/scsi/atari_scsi.c | |||
@@ -184,7 +184,7 @@ static void atari_scsi_fetch_restbytes(void); | |||
184 | static irqreturn_t scsi_tt_intr(int irq, void *dummy); | 184 | static irqreturn_t scsi_tt_intr(int irq, void *dummy); |
185 | static irqreturn_t scsi_falcon_intr(int irq, void *dummy); | 185 | static irqreturn_t scsi_falcon_intr(int irq, void *dummy); |
186 | static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata); | 186 | static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata); |
187 | static void falcon_get_lock(void); | 187 | static int falcon_get_lock(void); |
188 | #ifdef CONFIG_ATARI_SCSI_RESET_BOOT | 188 | #ifdef CONFIG_ATARI_SCSI_RESET_BOOT |
189 | static void atari_scsi_reset_boot(void); | 189 | static void atari_scsi_reset_boot(void); |
190 | #endif | 190 | #endif |
@@ -473,17 +473,10 @@ static void atari_scsi_fetch_restbytes(void) | |||
473 | #endif /* REAL_DMA */ | 473 | #endif /* REAL_DMA */ |
474 | 474 | ||
475 | 475 | ||
476 | static int falcon_got_lock = 0; | ||
477 | static DECLARE_WAIT_QUEUE_HEAD(falcon_fairness_wait); | ||
478 | static int falcon_trying_lock = 0; | ||
479 | static DECLARE_WAIT_QUEUE_HEAD(falcon_try_wait); | ||
480 | static int falcon_dont_release = 0; | 476 | static int falcon_dont_release = 0; |
481 | 477 | ||
482 | /* This function releases the lock on the DMA chip if there is no | 478 | /* This function releases the lock on the DMA chip if there is no |
483 | * connected command and the disconnected queue is empty. On | 479 | * connected command and the disconnected queue is empty. |
484 | * releasing, instances of falcon_get_lock are awoken, that put | ||
485 | * themselves to sleep for fairness. They can now try to get the lock | ||
486 | * again (but others waiting longer more probably will win). | ||
487 | */ | 480 | */ |
488 | 481 | ||
489 | static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata) | 482 | static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata) |
@@ -495,20 +488,12 @@ static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata) | |||
495 | 488 | ||
496 | local_irq_save(flags); | 489 | local_irq_save(flags); |
497 | 490 | ||
498 | if (falcon_got_lock && !hostdata->disconnected_queue && | 491 | if (!hostdata->disconnected_queue && |
499 | !hostdata->issue_queue && !hostdata->connected) { | 492 | !hostdata->issue_queue && |
500 | 493 | !hostdata->connected && | |
501 | if (falcon_dont_release) { | 494 | !falcon_dont_release && |
502 | #if 0 | 495 | stdma_is_locked_by(scsi_falcon_intr)) |
503 | printk("WARNING: Lock release not allowed. Ignored\n"); | ||
504 | #endif | ||
505 | local_irq_restore(flags); | ||
506 | return; | ||
507 | } | ||
508 | falcon_got_lock = 0; | ||
509 | stdma_release(); | 496 | stdma_release(); |
510 | wake_up(&falcon_fairness_wait); | ||
511 | } | ||
512 | 497 | ||
513 | local_irq_restore(flags); | 498 | local_irq_restore(flags); |
514 | } | 499 | } |
@@ -517,51 +502,19 @@ static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata) | |||
517 | * If the DMA isn't locked already for SCSI, it tries to lock it by | 502 | * If the DMA isn't locked already for SCSI, it tries to lock it by |
518 | * calling stdma_lock(). But if the DMA is locked by the SCSI code and | 503 | * calling stdma_lock(). But if the DMA is locked by the SCSI code and |
519 | * there are other drivers waiting for the chip, we do not issue the | 504 | * there are other drivers waiting for the chip, we do not issue the |
520 | * command immediately but wait on 'falcon_fairness_queue'. We will be | 505 | * command immediately but tell the SCSI mid-layer to defer. |
521 | * waked up when the DMA is unlocked by some SCSI interrupt. After that | ||
522 | * we try to get the lock again. | ||
523 | * But we must be prepared that more than one instance of | ||
524 | * falcon_get_lock() is waiting on the fairness queue. They should not | ||
525 | * try all at once to call stdma_lock(), one is enough! For that, the | ||
526 | * first one sets 'falcon_trying_lock', others that see that variable | ||
527 | * set wait on the queue 'falcon_try_wait'. | ||
528 | * Complicated, complicated.... Sigh... | ||
529 | */ | 506 | */ |
530 | 507 | ||
531 | static void falcon_get_lock(void) | 508 | static int falcon_get_lock(void) |
532 | { | 509 | { |
533 | unsigned long flags; | ||
534 | |||
535 | if (IS_A_TT()) | 510 | if (IS_A_TT()) |
536 | return; | 511 | return 1; |
537 | 512 | ||
538 | local_irq_save(flags); | 513 | if (in_interrupt()) |
514 | return stdma_try_lock(scsi_falcon_intr, NULL); | ||
539 | 515 | ||
540 | wait_event_cmd(falcon_fairness_wait, | 516 | stdma_lock(scsi_falcon_intr, NULL); |
541 | in_interrupt() || !falcon_got_lock || !stdma_others_waiting(), | 517 | return 1; |
542 | local_irq_restore(flags), | ||
543 | local_irq_save(flags)); | ||
544 | |||
545 | while (!falcon_got_lock) { | ||
546 | if (in_irq()) | ||
547 | panic("Falcon SCSI hasn't ST-DMA lock in interrupt"); | ||
548 | if (!falcon_trying_lock) { | ||
549 | falcon_trying_lock = 1; | ||
550 | stdma_lock(scsi_falcon_intr, NULL); | ||
551 | falcon_got_lock = 1; | ||
552 | falcon_trying_lock = 0; | ||
553 | wake_up(&falcon_try_wait); | ||
554 | } else { | ||
555 | wait_event_cmd(falcon_try_wait, | ||
556 | falcon_got_lock && !falcon_trying_lock, | ||
557 | local_irq_restore(flags), | ||
558 | local_irq_save(flags)); | ||
559 | } | ||
560 | } | ||
561 | |||
562 | local_irq_restore(flags); | ||
563 | if (!falcon_got_lock) | ||
564 | panic("Falcon SCSI: someone stole the lock :-(\n"); | ||
565 | } | 518 | } |
566 | 519 | ||
567 | 520 | ||