diff options
| author | bouyer <bouyer@NetBSD.org> | 2011-08-27 17:05:57 +0000 |
|---|---|---|
| committer | bouyer <bouyer@NetBSD.org> | 2011-08-27 17:05:57 +0000 |
| commit | 4440fe5f520a93d7ebd60bd2490d86b4a6e4ddfc (patch) | |
| tree | 0cf1fd051e4a8e26a4faebdc2c0e8885e68c3a2d /sys/dev | |
| parent | 6665a850d036343dd05387e8be73d06fa15ffea4 (diff) | |
The loongon2f+cs5526+jmicron PATA->SATA bridge cause an interresting issue:
1) because the CS5536 is not associated with a x86 CPU, interrupts are not
ack'ed as it expects so interrupts cannot configured as edge-triggered
(as is expected for a PCIIDE in compat mode)
2) the PATA->SATA bridge ignores the WDC_IDS (interrupt disable bit) so
the PATA IRQ line gets asserted when resetting or running some polled
commands. It also wrongly asserts IRQ when the (nonexistent) slave
device is selected
2) wouldn't be an issue with edge-triggered interrupt because we would
get a spurious interrupt and continue operation, a new interrupt only shows
up when the PATA IRQ line goes low and high again. But because of 1),
we get an unclearable interrupt instead, and the system loops on the
interrupt handler.
To workaround this, introduce a WDC_NO_IDS compile option which runs
all polled commands (including reset) at splbio() and without sleeps,
so that the controller's interrupt is effectively disabled and
won't be reenabled before the interrupt can be cleared.
The conditions triggering this problem are speficic enough to handle
this via a compile-time option; no need for a run-time (e.g. a
config(9), device property or callback to disable interrupts) solution.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/ata/ata_wdc.c | 10 | ||||
| -rw-r--r-- | sys/dev/ic/wdc.c | 70 |
2 files changed, 60 insertions, 20 deletions
diff --git a/sys/dev/ata/ata_wdc.c b/sys/dev/ata/ata_wdc.c index 46b40fcd983..6f77c18b083 100644 --- a/sys/dev/ata/ata_wdc.c +++ b/sys/dev/ata/ata_wdc.c @@ -1,4 +1,4 @@ -/* $NetBSD: ata_wdc.c,v 1.93 2010/03/28 20:46:18 snj Exp $ */ +/* $NetBSD: ata_wdc.c,v 1.94 2011/08/27 17:05:57 bouyer Exp $ */ /* * Copyright (c) 1998, 2001, 2003 Manuel Bouyer. @@ -54,9 +54,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ata_wdc.c,v 1.93 2010/03/28 20:46:18 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ata_wdc.c,v 1.94 2011/08/27 17:05:57 bouyer Exp $"); #include "opt_ata.h" +#include "opt_wdc.h" #include <sys/param.h> #include <sys/systm.h> @@ -180,6 +181,11 @@ wdc_ata_bio_start(struct ata_channel *chp, struct ata_xfer *xfer) struct ata_drive_datas *drvp = &chp->ch_drive[xfer->c_drive]; int wait_flags = (xfer->c_flags & C_POLL) ? AT_POLL : 0; const char *errstring; +#ifdef WDC_NO_IDS + wait_flags = AT_POLL; +#else +#error "NEED WDC_NO_IDS" +#endif ATADEBUG_PRINT(("wdc_ata_bio_start %s:%d:%d\n", device_xname(atac->atac_dev), chp->ch_channel, xfer->c_drive), diff --git a/sys/dev/ic/wdc.c b/sys/dev/ic/wdc.c index 9c2632c6f36..6a33877dec4 100644 --- a/sys/dev/ic/wdc.c +++ b/sys/dev/ic/wdc.c @@ -1,4 +1,4 @@ -/* $NetBSD: wdc.c,v 1.262 2011/08/13 16:02:48 jakllsch Exp $ */ +/* $NetBSD: wdc.c,v 1.263 2011/08/27 17:05:58 bouyer Exp $ */ /* * Copyright (c) 1998, 2001, 2003 Manuel Bouyer. All rights reserved. @@ -58,9 +58,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.262 2011/08/13 16:02:48 jakllsch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.263 2011/08/27 17:05:58 bouyer Exp $"); #include "opt_ata.h" +#include "opt_wdc.h" #include <sys/param.h> #include <sys/systm.h> @@ -298,28 +299,33 @@ wdc_drvprobe(struct ata_channel *chp) return; } + s = splbio(); /* for ATA/OLD drives, wait for DRDY, 3s timeout */ for (i = 0; i < mstohz(3000); i++) { - if (chp->ch_drive[0].drive_flags & (DRIVE_ATA|DRIVE_OLD)) { + /* + * select drive 1 first, so that master is selected on + * exit from the loop + */ + if (chp->ch_drive[1].drive_flags & (DRIVE_ATA|DRIVE_OLD)) { if (wdc->select) - wdc->select(chp,0); + wdc->select(chp,1); bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], - 0, WDSD_IBM); + 0, WDSD_IBM | 0x10); delay(10); /* 400ns delay */ - st0 = bus_space_read_1(wdr->cmd_iot, + st1 = bus_space_read_1(wdr->cmd_iot, wdr->cmd_iohs[wd_status], 0); } - - if (chp->ch_drive[1].drive_flags & (DRIVE_ATA|DRIVE_OLD)) { + if (chp->ch_drive[0].drive_flags & (DRIVE_ATA|DRIVE_OLD)) { if (wdc->select) - wdc->select(chp,1); + wdc->select(chp,0); bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], - 0, WDSD_IBM | 0x10); + 0, WDSD_IBM); delay(10); /* 400ns delay */ - st1 = bus_space_read_1(wdr->cmd_iot, + st0 = bus_space_read_1(wdr->cmd_iot, wdr->cmd_iohs[wd_status], 0); } + if (((chp->ch_drive[0].drive_flags & (DRIVE_ATA|DRIVE_OLD)) == 0 || (st0 & WDCS_DRDY)) && @@ -327,9 +333,16 @@ wdc_drvprobe(struct ata_channel *chp) == 0 || (st1 & WDCS_DRDY))) break; +#ifdef WDC_NO_IDS + /* cannot tsleep here (can't enable IPL_BIO interrups), + * delay instead + */ + delay(1000000 / hz); +#else +#error "NEED WDC_NO_IDS" tsleep(¶ms, PRIBIO, "atadrdy", 1); +#endif } - s = splbio(); if ((st0 & WDCS_DRDY) == 0) chp->ch_drive[0].drive_flags &= ~(DRIVE_ATA|DRIVE_OLD); if ((st1 & WDCS_DRDY) == 0) @@ -689,16 +702,22 @@ wdcprobe1(struct ata_channel *chp, int poll) DELAY(2000); (void) bus_space_read_1(wdr->cmd_iot, wdr->cmd_iohs[wd_error], 0); bus_space_write_1(wdr->ctl_iot, wdr->ctl_ioh, wd_aux_ctlr, WDCTL_4BIT); +#ifdef WDC_NO_IDS + ret_value = __wdcwait_reset(chp, ret_value, RESET_POLL); +#else splx(s); - ret_value = __wdcwait_reset(chp, ret_value, poll); + s = splbio(); +#endif ATADEBUG_PRINT(("%s:%d: after reset, ret_value=0x%d\n", device_xname(chp->ch_atac->atac_dev), chp->ch_channel, ret_value), DEBUG_PROBE); /* if reset failed, there's nothing here */ - if (ret_value == 0) + if (ret_value == 0) { + splx(s); return 0; + } /* * Test presence of drives. First test register signatures looking @@ -732,7 +751,6 @@ wdcprobe1(struct ata_channel *chp, int poll) * sc & sn are supposted to be 0x1 for ATAPI but in some cases * we get wrong values here, so ignore it. */ - s = splbio(); if (cl == 0x14 && ch == 0xeb) { chp->ch_drive[drive].drive_flags |= DRIVE_ATAPI; } else { @@ -740,8 +758,18 @@ wdcprobe1(struct ata_channel *chp, int poll) if ((wdc->cap & WDC_CAPABILITY_PREATA) != 0) chp->ch_drive[drive].drive_flags |= DRIVE_OLD; } - splx(s); } + /* + * Select an existing drive before lowering spl, some WDC_NO_IDS + * devices incorrectly assert IRQ on nonexistent slave + */ + if (ret_value & 0x01) { + bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], 0, + WDSD_IBM); + (void)bus_space_read_1(wdr->cmd_iot, + wdr->cmd_iohs[wd_status], 0); + } + splx(s); return (ret_value); } @@ -908,7 +936,6 @@ wdc_reset_channel(struct ata_channel *chp, int flags) #if NATA_DMA || NATA_PIOBM struct wdc_softc *wdc = CHAN_TO_WDC(chp); #endif - TAILQ_INIT(&reset_xfer); chp->ch_flags &= ~ATACH_IRQ_WAIT; @@ -1006,6 +1033,9 @@ wdcreset(struct ata_channel *chp, int poll) struct wdc_regs *wdr = &wdc->regs[chp->ch_channel]; int drv_mask1, drv_mask2; +#ifdef WDC_NO_IDS + poll = RESET_POLL; +#endif wdc->reset(chp, poll); drv_mask1 = (chp->ch_drive[0].drive_flags & DRIVE) ? 0x01:0x00; @@ -1066,7 +1096,7 @@ __wdcwait_reset(struct ata_channel *chp, int drv_mask, int poll) u_int8_t sc0 = 0, sn0 = 0, cl0 = 0, ch0 = 0; u_int8_t sc1 = 0, sn1 = 0, cl1 = 0, ch1 = 0; #endif - + KASSERT(poll == 1); if (poll) nloop = WDCNDELAY_RST; else @@ -1475,12 +1505,16 @@ __wdccommand_intr(struct ata_channel *chp, struct ata_xfer *xfer, int irq) drive_flags = chp->ch_drive[xfer->c_drive].drive_flags; } +#ifdef WDC_NO_IDS + wflags = AT_POLL; +#else if ((ata_c->flags & (AT_WAIT | AT_POLL)) == (AT_WAIT | AT_POLL)) { /* both wait and poll, we can tsleep here */ wflags = AT_WAIT | AT_POLL; } else { wflags = AT_POLL; } +#endif again: ATADEBUG_PRINT(("__wdccommand_intr %s:%d:%d\n", |
