diff options
author | non <non@FreeBSD.org> | 2001-02-25 12:40:30 +0000 |
---|---|---|
committer | non <non@FreeBSD.org> | 2001-02-25 12:40:30 +0000 |
commit | 292085c2c12f53507fafb6423983ac0153495991 (patch) | |
tree | cf8aa02bf1dfdf3f0c69596059bacd58a5560793 /sys/dev | |
parent | 4f21d5f03f0b6bd39903d4ef8d34cab68c6a0db3 (diff) | |
download | FreeBSD-src-292085c2c12f53507fafb6423983ac0153495991.zip FreeBSD-src-292085c2c12f53507fafb6423983ac0153495991.tar.gz |
o Support AUTO SENSE correctly.
o Offset and period in synch messages and width negotiation should be
done for per target not per lun. Move these from *lun_info to
*targ_info.
o Change in handling XPT_RESET_DEV and XPT_GET_TRAN_SETTINGS .
o Change CAM_* xpt_done return values.
o Busy loop did not timeout. Change this to timeout as original NetBSD/pc98.
Reviewed by: bsd-nomads ML
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ncv/ncr53c500.c | 127 | ||||
-rw-r--r-- | sys/dev/ncv/ncr53c500var.h | 13 | ||||
-rw-r--r-- | sys/dev/nsp/nsp.c | 191 | ||||
-rw-r--r-- | sys/dev/nsp/nspvar.h | 11 | ||||
-rw-r--r-- | sys/dev/stg/tmc18c30.c | 176 | ||||
-rw-r--r-- | sys/dev/stg/tmc18c30var.h | 10 |
6 files changed, 165 insertions, 363 deletions
diff --git a/sys/dev/ncv/ncr53c500.c b/sys/dev/ncv/ncr53c500.c index bb9e1d8..73bc3df 100644 --- a/sys/dev/ncv/ncr53c500.c +++ b/sys/dev/ncv/ncr53c500.c @@ -128,6 +128,10 @@ extern struct cfdriver ncv_cd; /************************************************************** * DECLARE **************************************************************/ +#ifdef __NetBSD__ +extern int delaycount; +#endif + /* static */ static void ncv_pio_read __P((struct ncv_softc *, u_int8_t *, u_int)); static void ncv_pio_write __P((struct ncv_softc *, u_int8_t *, u_int)); @@ -153,13 +157,12 @@ static int ncv_nexus __P((struct ncv_softc *, struct targ_info *)); #ifdef NCV_POWER_CONTROL static int ncvhw_power __P((struct ncv_softc *, u_int)); #endif -static int ncv_lun_init __P((struct ncv_softc *, struct targ_info *, struct lun_info *)); -static void settimeout __P((void *)); +static int ncv_targ_init __P((struct ncv_softc *, struct targ_info *)); struct scsi_low_funcs ncv_funcs = { SC_LOW_INIT_T ncv_world_start, SC_LOW_BUSRST_T ncvhw_bus_reset, - SC_LOW_LUN_INIT_T ncv_lun_init, + SC_LOW_TARG_INIT_T ncv_targ_init, SC_LOW_SELECT_T ncvhw_start_selection, SC_LOW_NEXUS_T ncv_nexus, @@ -434,18 +437,24 @@ ncv_world_start(sc, fdone) bus_space_tag_t iot = sc->sc_iot; bus_space_handle_t ioh = sc->sc_ioh; u_int8_t stat; +#ifdef __FreeBSD__ intrmask_t s; +#endif ncvhw_reset(iot, ioh, &sc->sc_hw); ncvhw_init(iot, ioh, &sc->sc_hw); +#ifdef __FreeBSD__ s = splcam(); +#endif scsi_low_bus_reset(slp); ncvhw_select_register_0(iot, ioh, &sc->sc_hw); bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_stat); stat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_istat); +#ifdef __FreeBSD__ splx(s); +#endif delay(1000); if (((stat & INTR_SBR) == 0) || @@ -462,41 +471,39 @@ ncv_msg(sc, ti, msg) struct targ_info *ti; u_int msg; { - struct lun_info *li = ti->ti_li; - struct ncv_lun_info *nli = (void *) li; + struct ncv_targ_info *nti = (void *) ti; u_int hwcycle, period; if ((msg & SCSI_LOW_MSG_SYNCH) == 0) return 0; - period = li->li_maxsynch.period; + period = ti->ti_maxsynch.period; hwcycle = 1000 / ((sc->sc_hw.clk == 0) ? 40 : (5 * sc->sc_hw.clk)); if (period < 200 / 4 && period >= 100 / 4) - nli->nli_reg_cfg3 |= C3_FSCSI; + nti->nti_reg_cfg3 |= C3_FSCSI; else - nli->nli_reg_cfg3 &= ~C3_FSCSI; + nti->nti_reg_cfg3 &= ~C3_FSCSI; period = ((period * 40 / hwcycle) + 5) / 10; - nli->nli_reg_period = period & 0x1f; - nli->nli_reg_offset = li->li_maxsynch.offset; + nti->nti_reg_period = period & 0x1f; + nti->nti_reg_offset = ti->ti_maxsynch.offset; return 0; } static int -ncv_lun_init(sc, ti, li) +ncv_targ_init(sc, ti) struct ncv_softc *sc; struct targ_info *ti; - struct lun_info *li; { - struct ncv_lun_info *nli = (void *) li; + struct ncv_targ_info *nti = (void *) ti; - li->li_maxsynch.period = sc->sc_hw.mperiod; - li->li_maxsynch.offset = sc->sc_hw.moffset; + ti->ti_maxsynch.period = sc->sc_hw.mperiod; + ti->ti_maxsynch.offset = sc->sc_hw.moffset; - nli->nli_reg_cfg3 = sc->sc_hw.cfg3; - nli->nli_reg_period = 0; - nli->nli_reg_offset = 0; + nti->nti_reg_cfg3 = sc->sc_hw.cfg3; + nti->nti_reg_period = 0; + nti->nti_reg_offset = 0; return 0; } @@ -590,9 +597,14 @@ ncvattachsubr(sc) printf("\n"); sc->sc_hw = ncv_template; ncv_setup_img(&sc->sc_hw, slp->sl_cfgflags, slp->sl_hostid); +#ifdef __FreeBSD__ + sc->sc_wc = 0x2000 * 2000; /* XXX need calibration */ +#else /* NetBSD */ + sc->sc_wc = delaycount * 2000; /* 2 sec */ +#endif slp->sl_funcs = &ncv_funcs; (void) scsi_low_attach(slp, 2, NCV_NTARGETS, NCV_NLUNS, - sizeof(struct ncv_lun_info)); + sizeof(struct ncv_targ_info)); } /************************************************************** @@ -678,12 +690,8 @@ ncv_pio_read(sc, buf, reqlen) struct scsi_low_softc *slp = &sc->sc_sclow; bus_space_tag_t iot = sc->sc_iot; bus_space_handle_t ioh = sc->sc_ioh; - int s; - int tout = 0; + int tout = sc->sc_wc; register u_int8_t fstat; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif ncvhw_select_register_1(iot, ioh, &sc->sc_hw); bus_space_write_1(iot, ioh, cr1_pflag, 0); @@ -696,12 +704,7 @@ ncv_pio_read(sc, buf, reqlen) bus_space_write_1(iot, ioh, cr1_fstat, FIFO_EN); slp->sl_flags |= HW_PDMASTART; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif - while (reqlen >= FIFO_F_SZ && tout == 0) + while (reqlen >= FIFO_F_SZ && tout > 0) { fstat = bus_space_read_1(iot, ioh, cr1_fstat); if (fstat & FIFO_F) @@ -721,6 +724,7 @@ ncv_pio_read(sc, buf, reqlen) else if (fstat & FIFO_BRK) break; + tout --; } if (reqlen >= FIFO_2_SZ) @@ -740,7 +744,7 @@ ncv_pio_read(sc, buf, reqlen) } } - while (reqlen > 0 && tout == 0) + while (reqlen > 0 && tout > 0) { fstat = bus_space_read_1(iot, ioh, cr1_fstat); if ((fstat & FIFO_E) == 0) @@ -752,23 +756,14 @@ ncv_pio_read(sc, buf, reqlen) else if (fstat & FIFO_BRK) break; + tout --; } ncvhw_select_register_0(iot, ioh, &sc->sc_hw); sc->sc_tdatalen = reqlen; - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (tout <= 0) printf("%s pio read timeout\n", slp->sl_xname); - } } static void @@ -780,12 +775,8 @@ ncv_pio_write(sc, buf, reqlen) struct scsi_low_softc *slp = &sc->sc_sclow; bus_space_tag_t iot = sc->sc_iot; bus_space_handle_t ioh = sc->sc_ioh; - int s; - int tout = 0; + int tout = sc->sc_wc; register u_int8_t fstat; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif ncvhw_select_register_1(iot, ioh, &sc->sc_hw); bus_space_write_1(iot, ioh, cr1_pflag, 0); @@ -798,12 +789,7 @@ ncv_pio_write(sc, buf, reqlen) bus_space_write_1(iot, ioh, cr1_fstat, FIFO_EN); slp->sl_flags |= HW_PDMASTART; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif - while (reqlen >= FIFO_F_SZ && tout == 0) + while (reqlen >= FIFO_F_SZ && tout > 0) { fstat = bus_space_read_1(iot, ioh, cr1_fstat); if (fstat & FIFO_BRK) @@ -821,9 +807,11 @@ ncv_pio_write(sc, buf, reqlen) buf += FIFO_F_SZ; reqlen -= FIFO_F_SZ; } + else + tout --; } - while (reqlen > 0 && tout == 0) + while (reqlen > 0 && tout > 0) { fstat = bus_space_read_1(iot, ioh, cr1_fstat); if (fstat & FIFO_BRK) @@ -834,32 +822,15 @@ ncv_pio_write(sc, buf, reqlen) bus_space_write_1(iot, ioh, cr1_fdata, *buf++); reqlen --; } + else + tout --; } done: ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (tout <= 0) printf("%s pio write timeout\n", slp->sl_xname); - } -} - -static void -settimeout(arg) - void *arg; -{ - int *tout = arg; - - *tout = 1; } /************************************************************** @@ -928,15 +899,15 @@ ncv_nexus(sc, ti) bus_space_tag_t iot = sc->sc_iot; bus_space_handle_t ioh = sc->sc_ioh; struct lun_info *li = ti->ti_li; - struct ncv_lun_info *nli = (void *) li; + struct ncv_targ_info *nti = (void *) ti; if (li->li_flags & SCSI_LOW_NOPARITY) bus_space_write_1(iot, ioh, cr0_cfg1, sc->sc_hw.cfg1); else bus_space_write_1(iot, ioh, cr0_cfg1, sc->sc_hw.cfg1 | C1_PARENB); - bus_space_write_1(iot, ioh, cr0_period, nli->nli_reg_period); - bus_space_write_1(iot, ioh, cr0_offs, nli->nli_reg_offset); - bus_space_write_1(iot, ioh, cr0_cfg3, nli->nli_reg_cfg3); + bus_space_write_1(iot, ioh, cr0_period, nti->nti_reg_period); + bus_space_write_1(iot, ioh, cr0_offs, nti->nti_reg_offset); + bus_space_write_1(iot, ioh, cr0_cfg3, nti->nti_reg_cfg3); return 0; } diff --git a/sys/dev/ncv/ncr53c500var.h b/sys/dev/ncv/ncr53c500var.h index 07e85f8..c01bc85 100644 --- a/sys/dev/ncv/ncr53c500var.h +++ b/sys/dev/ncv/ncr53c500var.h @@ -47,6 +47,7 @@ struct ncv_softc { bus_space_handle_t sc_ioh; void *sc_ih; + int sc_wc; /* weight counter */ int sc_selstop; /* sel atn stop asserted */ int sc_compseq; /* completion seq cmd asserted */ int sc_tdatalen; /* temp xfer data len */ @@ -64,14 +65,14 @@ struct ncv_softc { }; /***************************************************************** - * Lun information + * Target information *****************************************************************/ -struct ncv_lun_info { - struct lun_info nli_li; +struct ncv_targ_info { + struct targ_info nti_ti; - u_int8_t nli_reg_cfg3; /* cfg3 images per lun */ - u_int8_t nli_reg_offset; /* synch offset register per lun */ - u_int8_t nli_reg_period; /* synch period register per lun */ + u_int8_t nti_reg_cfg3; /* cfg3 images per target */ + u_int8_t nti_reg_offset; /* synch offset register per target */ + u_int8_t nti_reg_period; /* synch period register per target */ }; /***************************************************************** diff --git a/sys/dev/nsp/nsp.c b/sys/dev/nsp/nsp.c index b564c67..b10bdb3 100644 --- a/sys/dev/nsp/nsp.c +++ b/sys/dev/nsp/nsp.c @@ -138,6 +138,10 @@ extern struct cfdriver nsp_cd; /************************************************************** * DECLARE **************************************************************/ +#ifdef __NetBSD__ +extern int delaycount; +#endif + /* static */ static void nsp_pio_read __P((struct nsp_softc *, struct targ_info *)); static void nsp_pio_write __P((struct nsp_softc *, struct targ_info *)); @@ -158,13 +162,12 @@ static int nsp_expect_signal __P((struct nsp_softc *, u_int8_t, u_int8_t)); static __inline void nsp_start_timer __P((struct nsp_softc *, int)); static int nsp_dataphase_bypass __P((struct nsp_softc *, struct targ_info *)); static void nsp_setup_fifo __P((struct nsp_softc *, int)); -static int nsp_lun_init __P((struct nsp_softc *, struct targ_info *, struct lun_info *)); -static void settimeout __P((void *)); +static int nsp_targ_init __P((struct nsp_softc *, struct targ_info *)); struct scsi_low_funcs nspfuncs = { SC_LOW_INIT_T nsp_world_start, SC_LOW_BUSRST_T nsphw_bus_reset, - SC_LOW_LUN_INIT_T nsp_lun_init, + SC_LOW_TARG_INIT_T nsp_targ_init, SC_LOW_SELECT_T nsphw_start_selection, SC_LOW_NEXUS_T nsp_nexus, @@ -214,19 +217,10 @@ nsp_expect_signal(sc, curphase, mask) struct scsi_low_softc *slp = &sc->sc_sclow; bus_space_tag_t bst = sc->sc_iot; bus_space_handle_t bsh = sc->sc_ioh; - int rv = -1; - int s; - int tout = 0; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif + int wc = (sc->sc_wc >> 2); u_int8_t ph, isrc; + int rv = -1; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, hz/2); -#else - timeout(settimeout, &tout, hz/2); -#endif do { ph = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); @@ -244,18 +238,9 @@ nsp_expect_signal(sc, curphase, mask) break; } } - while (tout == 0); + while (wc -- > 0); - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (wc <= 0) { printf("%s: nsp_expect_signal timeout\n", slp->sl_xname); rv = -1; } @@ -363,11 +348,7 @@ nsphw_start_selection(sc, cb) bus_space_handle_t bsh = sc->sc_ioh; struct targ_info *ti = cb->ti; register u_int8_t arbs, ph; - int s; - int tout = 0; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif + int s, wc = sc->sc_wc; /* check bus free */ if (slp->sl_disc > 0) @@ -385,28 +366,13 @@ nsphw_start_selection(sc, cb) /* start arbitration */ SCSI_LOW_SETUP_PHASE(ti, PH_ARBSTART); nsp_cr_write_1(bst, bsh, NSPR_ARBITS, ARBITS_EXEC); -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif do { /* XXX: what a stupid chip! */ arbs = nsp_cr_read_1(bst, bsh, NSPR_ARBITS); delay(1); } - while ((arbs & (ARBITS_WIN | ARBITS_FAIL)) == 0 && tout == 0); - - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - } - splx(s); + while ((arbs & (ARBITS_WIN | ARBITS_FAIL)) == 0 && wc -- > 0); if ((arbs & ARBITS_WIN) == 0) { @@ -443,9 +409,11 @@ nsp_world_start(sc, fdone) int fdone; { struct scsi_low_softc *slp = &sc->sc_sclow; +#ifdef __FreeBSD__ intrmask_t s; s = splcam(); +#endif sc->sc_cnt = 0; sc->sc_seltout = 0; if ((slp->sl_cfgflags & CFG_NOATTEN) == 0) @@ -456,7 +424,9 @@ nsp_world_start(sc, fdone) nsphw_init(sc); scsi_low_bus_reset(slp); +#ifdef __FreeBSD__ splx(s); +#endif SOFT_INTR_REQUIRED(slp); return 0; @@ -491,16 +461,15 @@ nsp_msg(sc, ti, msg) u_int msg; { struct ncp_synch_data *sdp; - struct lun_info *li = ti->ti_li; - struct nsp_lun_info *nli = (void *) li; + struct nsp_targ_info *nti = (void *) ti; u_int period, offset; int i; if ((msg & SCSI_LOW_MSG_SYNCH) == 0) return 0; - period = li->li_maxsynch.period; - offset = li->li_maxsynch.offset; + period = ti->ti_maxsynch.period; + offset = ti->ti_maxsynch.offset; if (sc->sc_iclkdiv == CLKDIVR_20M) sdp = &ncp_sync_data_20M[0]; else @@ -518,31 +487,30 @@ nsp_msg(sc, ti, msg) * NO proper period/offset found, * Retry neg with the target. */ - li->li_maxsynch.period = 0; - li->li_maxsynch.offset = 0; - nli->nli_reg_syncr = 0; - nli->nli_reg_ackwidth = 0; + ti->ti_maxsynch.period = 0; + ti->ti_maxsynch.offset = 0; + nti->nti_reg_syncr = 0; + nti->nti_reg_ackwidth = 0; return EINVAL; } - nli->nli_reg_syncr = (sdp->chip_period << SYNCR_PERS) | + nti->nti_reg_syncr = (sdp->chip_period << SYNCR_PERS) | (offset & SYNCR_OFFM); - nli->nli_reg_ackwidth = sdp->ack_width; + nti->nti_reg_ackwidth = sdp->ack_width; return 0; } static int -nsp_lun_init(sc, ti, li) +nsp_targ_init(sc, ti) struct nsp_softc *sc; struct targ_info *ti; - struct lun_info *li; { - struct nsp_lun_info *nli = (void *) li; + struct nsp_targ_info *nti = (void *) ti; - li->li_maxsynch.period = 200 / 4; - li->li_maxsynch.offset = 15; - nli->nli_reg_syncr = 0; - nli->nli_reg_ackwidth = 0; + ti->ti_maxsynch.period = 200 / 4; + ti->ti_maxsynch.offset = 15; + nti->nti_reg_syncr = 0; + nti->nti_reg_ackwidth = 0; return 0; } @@ -582,6 +550,11 @@ nspattachsubr(sc) printf("\n"); +#ifdef __FreeBSD__ + sc->sc_wc = 0x2000 * 2000; /* XXX need calibration */ +#else + sc->sc_wc = delaycount * 2000; /* 2 sec */ +#endif sc->sc_idbit = (1 << slp->sl_hostid); slp->sl_funcs = &nspfuncs; if (sc->sc_memh != NULL) @@ -590,7 +563,7 @@ nspattachsubr(sc) sc->sc_xmode = NSP_PIO; (void) scsi_low_attach(slp, 2, NSP_NTARGETS, NSP_NLUNS, - sizeof(struct nsp_lun_info)); + sizeof(struct nsp_targ_info)); } /************************************************************** @@ -706,23 +679,14 @@ nsp_pio_read(sc, ti) struct scsi_low_softc *slp = &sc->sc_sclow; bus_space_tag_t bst = sc->sc_iot; bus_space_handle_t bsh = sc->sc_ioh; - int s; - int tout = 0; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif + int tout = sc->sc_wc; u_int res, ocount, mask = sc->sc_mask; u_int8_t stat, fstat; slp->sl_flags |= HW_PDMASTART; ocount = sc->sc_cnt; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif - while (slp->sl_scp.scp_datalen > 0 && tout == 0) + while (slp->sl_scp.scp_datalen > 0 && tout -- > 0) { stat = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); stat &= SCBUSMON_PHMASK; @@ -772,18 +736,8 @@ nsp_pio_read(sc, ti) } sc->sc_cnt = ocount; - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (tout <= 0) printf("%s pio read timeout\n", slp->sl_xname); - } } static void @@ -795,21 +749,12 @@ nsp_pio_write(sc, ti) bus_space_tag_t bst = sc->sc_iot; bus_space_handle_t bsh = sc->sc_ioh; u_int res, ocount, mask = sc->sc_mask; - int s; - int tout = 0; + int tout = sc->sc_wc; register u_int8_t stat; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif ocount = sc->sc_cnt; slp->sl_flags |= HW_PDMASTART; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif - while (slp->sl_scp.scp_datalen > 0 && tout == 0) + while (slp->sl_scp.scp_datalen > 0 && tout -- > 0) { stat = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); stat &= SCBUSMON_PHMASK; @@ -847,27 +792,8 @@ nsp_pio_write(sc, ti) } sc->sc_cnt = ocount; - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (tout <= 0) printf("%s pio write timeout\n", slp->sl_xname); - } -} - -static void -settimeout(arg) - void *arg; -{ - int *tout = arg; - - *tout = 1; } static int @@ -879,38 +805,19 @@ nsp_negate_signal(sc, mask, s) struct scsi_low_softc *slp = &sc->sc_sclow; bus_space_tag_t bst = sc->sc_iot; bus_space_handle_t bsh = sc->sc_ioh; - int tout = 0; - int ss; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif + int wc = (sc->sc_wc >> 2); u_int8_t regv; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, hz/2); -#else - timeout(settimeout, &tout, hz/2); -#endif do { regv = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); if (regv == 0xff) break; } - while ((regv & mask) != 0 && tout == 0); + while ((regv & mask) != 0 && (-- wc) > 0); - ss = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(ss); - } else { - splx(ss); + if (wc <= 0) printf("%s: %s singla off timeout \n", slp->sl_xname, s); - } return 0; } @@ -1063,11 +970,11 @@ nsp_nexus(sc, ti) { bus_space_tag_t bst = sc->sc_iot; bus_space_handle_t bsh = sc->sc_ioh; - struct nsp_lun_info *nli = (void *) ti->ti_li; + struct nsp_targ_info *nti = (void *) ti; /* setup synch transfer registers */ - nsp_cr_write_1(bst, bsh, NSPR_SYNCR, nli->nli_reg_syncr); - nsp_cr_write_1(bst, bsh, NSPR_ACKWIDTH, nli->nli_reg_ackwidth); + nsp_cr_write_1(bst, bsh, NSPR_SYNCR, nti->nti_reg_syncr); + nsp_cr_write_1(bst, bsh, NSPR_ACKWIDTH, nti->nti_reg_ackwidth); /* setup pdma fifo */ nsp_setup_fifo(sc, 1); diff --git a/sys/dev/nsp/nspvar.h b/sys/dev/nsp/nspvar.h index 078f1b9..41912d3 100644 --- a/sys/dev/nsp/nspvar.h +++ b/sys/dev/nsp/nspvar.h @@ -46,6 +46,7 @@ struct nsp_softc { bus_space_handle_t sc_memh; void *sc_ih; + int sc_wc; int sc_seltout; /* selection timeout counter */ int sc_timer; /* timer start */ @@ -77,13 +78,13 @@ struct nsp_softc { }; /***************************************************************** - * Lun information + * Target information *****************************************************************/ -struct nsp_lun_info { - struct lun_info nli_li; /* generic lun info */ +struct nsp_targ_info { + struct targ_info nti_ti; /* generic target info */ - u_int8_t nli_reg_syncr; /* sync registers per devices */ - u_int8_t nli_reg_ackwidth; /* ackwidth per devices */ + u_int8_t nti_reg_syncr; /* sync registers per devices */ + u_int8_t nti_reg_ackwidth; /* ackwidth per devices */ }; /***************************************************************** diff --git a/sys/dev/stg/tmc18c30.c b/sys/dev/stg/tmc18c30.c index 6d5ea0b..b331dd3 100644 --- a/sys/dev/stg/tmc18c30.c +++ b/sys/dev/stg/tmc18c30.c @@ -150,6 +150,10 @@ extern struct cfdriver stg_cd; /************************************************************** * DECLARE **************************************************************/ +#ifdef __NetBSD__ +extern int delaycount; +#endif + /* static */ static void stg_pio_read __P((struct stg_softc *, struct targ_info *)); static void stg_pio_write __P((struct stg_softc *, struct targ_info *)); @@ -168,14 +172,13 @@ static int stghw_start_selection __P((struct stg_softc *sc, struct slccb *)); static void stghw_bus_reset __P((struct stg_softc *)); static void stghw_attention __P((struct stg_softc *)); static int stg_nexus __P((struct stg_softc *, struct targ_info *)); -static int stg_lun_init __P((struct stg_softc *, struct targ_info *, struct lun_info *)); +static int stg_targ_init __P((struct stg_softc *, struct targ_info *)); static __inline void stghw_bcr_write_1 __P((struct stg_softc *, u_int8_t)); -static void settimeout __P((void *)); struct scsi_low_funcs stgfuncs = { SC_LOW_INIT_T stg_world_start, SC_LOW_BUSRST_T stghw_bus_reset, - SC_LOW_LUN_INIT_T stg_lun_init, + SC_LOW_TARG_INIT_T stg_targ_init, SC_LOW_SELECT_T stghw_start_selection, SC_LOW_NEXUS_T stg_nexus, @@ -271,16 +274,22 @@ stg_world_start(sc, fdone) { struct scsi_low_softc *slp = &sc->sc_sclow; int error; +#ifdef __FreeBSD__ intrmask_t s; +#endif if ((error = stghw_check(sc)) != 0) return error; +#ifdef __FreeBSD__ s = splcam(); +#endif stghw_init(sc); scsi_low_bus_reset(slp); stghw_init(sc); +#ifdef __FreeBSD__ splx(s); +#endif SOFT_INTR_REQUIRED(slp); return 0; @@ -292,29 +301,28 @@ stg_msg(sc, ti, msg) struct targ_info *ti; u_int msg; { - struct lun_info *li = ti->ti_li; - struct stg_lun_info *sli = (void *) li; + struct stg_targ_info *sti = (void *) ti; u_int period, offset; if (msg != SCSI_LOW_MSG_SYNCH) return EINVAL; - period = li->li_maxsynch.period; - offset = li->li_maxsynch.offset; + period = ti->ti_maxsynch.period; + offset = ti->ti_maxsynch.offset; period = period << 2; if (period >= 200) { - sli->sli_reg_synch = (period - 200) / 50; + sti->sti_reg_synch = (period - 200) / 50; if (period % 50) - sli->sli_reg_synch ++; - sli->sli_reg_synch |= SSCTL_SYNCHEN; + sti->sti_reg_synch ++; + sti->sti_reg_synch |= SSCTL_SYNCHEN; } else if (period >= 100) { - sli->sli_reg_synch = (period - 100) / 50; + sti->sti_reg_synch = (period - 100) / 50; if (period % 50) - sli->sli_reg_synch ++; - sli->sli_reg_synch |= SSCTL_SYNCHEN | SSCTL_FSYNCHEN; + sti->sti_reg_synch ++; + sti->sti_reg_synch |= SSCTL_SYNCHEN | SSCTL_FSYNCHEN; } return 0; } @@ -391,16 +399,15 @@ stghw_init(sc) } static int -stg_lun_init(sc, ti, li) +stg_targ_init(sc, ti) struct stg_softc *sc; struct targ_info *ti; - struct lun_info *li; { - struct stg_lun_info *sli = (void *) li; + struct stg_targ_info *sti = (void *) ti; - li->li_maxsynch.period = 0; - li->li_maxsynch.offset = 8; - sli->sli_reg_synch = 0; + ti->ti_maxsynch.period = 0; + ti->ti_maxsynch.offset = 8; + sti->sti_reg_synch = 0; return 0; } @@ -449,6 +456,11 @@ stgattachsubr(sc) printf("\n"); +#ifdef __FreeBSD__ + sc->sc_wc = 0x2000 * 2000; /* XXX need calibration */ +#else + sc->sc_wc = delaycount * 2000; /* 2 sec */ +#endif sc->sc_idbit = (1 << slp->sl_hostid); slp->sl_funcs = &stgfuncs; @@ -461,7 +473,7 @@ stgattachsubr(sc) } (void) scsi_low_attach(slp, 2, STG_NTARGETS, STG_NLUNS, - sizeof(struct stg_lun_info)); + sizeof(struct stg_targ_info)); } /************************************************************** @@ -531,23 +543,14 @@ stg_pio_read(sc, ti) bus_space_tag_t iot = sc->sc_iot; bus_space_handle_t ioh = sc->sc_ioh; struct sc_p *sp = &slp->sl_scp; - int s; - int tout = 0; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif + int tout = sc->sc_wc; u_int res; u_int8_t stat; bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit | FCTL_FIFOEN); slp->sl_flags |= HW_PDMASTART; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif - while (sp->scp_datalen > 0 && tout == 0) + while (sp->scp_datalen > 0 && tout -- > 0) { res = bus_space_read_2(iot, ioh, tmc_fdcnt); if (res == 0) @@ -578,18 +581,8 @@ stg_pio_read(sc, ti) sp->scp_data += res; } - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (tout <= 0) printf("%s pio read timeout\n", slp->sl_xname); - } } #define WFIFO_CRIT 0x100 @@ -604,24 +597,15 @@ stg_pio_write(sc, ti) bus_space_handle_t ioh = sc->sc_ioh; struct sc_p *sp = &slp->sl_scp; u_int res; - int s; - int tout = 0; + int tout = sc->sc_wc; register u_int8_t stat; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif stat = sc->sc_fcWinit | FCTL_FIFOEN | FCTL_FIFOW; bus_space_write_1(iot, ioh, tmc_fctl, stat | FCTL_CLRFIFO); bus_space_write_1(iot, ioh, tmc_fctl, stat); slp->sl_flags |= HW_PDMASTART; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif - while (sp->scp_datalen > 0 && tout == 0) + while (sp->scp_datalen > 0 && tout -- > 0) { stat = bus_space_read_1(iot, ioh, tmc_bstat); if ((stat & BSTAT_PHMASK) != 0) @@ -645,18 +629,8 @@ stg_pio_write(sc, ti) sp->scp_data += res; } - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (tout <= 0) printf("%s pio write timeout\n", slp->sl_xname); - } } static int @@ -668,61 +642,25 @@ stg_negate_signal(sc, mask, s) struct scsi_low_softc *slp = &sc->sc_sclow; bus_space_tag_t bst = sc->sc_iot; bus_space_handle_t bsh = sc->sc_ioh; - int ss; - int tout = 0; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif + int wc = (sc->sc_wc >> 2); u_int8_t regv; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, 2 * hz); -#else - timeout(settimeout, &tout, 2 * hz); -#endif do { regv = bus_space_read_1(bst, bsh, tmc_bstat); - if (regv == 0xff) { - ss = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - } - splx(ss); + if (regv == 0xff) return EIO; - } } - while ((regv & mask) != 0 && tout == 0); + while ((regv & mask) != 0 && (-- wc) > 0); - ss = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(ss); - } else { - splx(ss); + if (wc <= 0) + { printf("%s: %s singal off timeout \n", slp->sl_xname, s); return EIO; } return 0; } -static void -settimeout(arg) - void *arg; -{ - int *tout = arg; - - *tout = 1; -} - static int stg_expect_signal(sc, phase, mask) struct stg_softc *sc; @@ -731,20 +669,11 @@ stg_expect_signal(sc, phase, mask) struct scsi_low_softc *slp = &sc->sc_sclow; bus_space_tag_t bst = sc->sc_iot; bus_space_handle_t bsh = sc->sc_ioh; + int wc = (sc->sc_wc >> 2); int rv = -1; - int s; - int tout = 0; -#ifdef __FreeBSD__ - struct callout_handle ch; -#endif u_int8_t ph; phase &= BSTAT_PHMASK; -#ifdef __FreeBSD__ - ch = timeout(settimeout, &tout, hz/2); -#else - timeout(settimeout, &tout, hz/2); -#endif do { ph = bus_space_read_1(bst, bsh, tmc_bstat); @@ -761,18 +690,9 @@ stg_expect_signal(sc, phase, mask) break; } } - while (tout == 0); + while (wc -- > 0); - s = splhigh(); - if (tout == 0) { -#ifdef __FreeBSD__ - untimeout(settimeout, &tout, ch); -#else - untimeout(settimeout, &tout); -#endif - splx(s); - } else { - splx(s); + if (wc <= 0) { printf("%s: stg_expect_signal timeout\n", slp->sl_xname); rv = -1; } @@ -907,14 +827,14 @@ stg_nexus(sc, ti) bus_space_tag_t iot = sc->sc_iot; bus_space_handle_t ioh = sc->sc_ioh; struct lun_info *li = ti->ti_li; - struct stg_lun_info *sli = (void *) ti->ti_li; + struct stg_targ_info *sti = (void *) ti; if (li->li_flags & SCSI_LOW_NOPARITY) sc->sc_fcRinit &= ~FCTL_PARENB; else sc->sc_fcRinit |= FCTL_PARENB; - bus_space_write_1(iot, ioh, tmc_ssctl, sli->sli_reg_synch); + bus_space_write_1(iot, ioh, tmc_ssctl, sti->sti_reg_synch); return 0; } diff --git a/sys/dev/stg/tmc18c30var.h b/sys/dev/stg/tmc18c30var.h index 46cc986..0940fc7 100644 --- a/sys/dev/stg/tmc18c30var.h +++ b/sys/dev/stg/tmc18c30var.h @@ -50,6 +50,8 @@ struct stg_softc { void *sc_ih; + int sc_wc; /* weight counter */ + u_int sc_chip; /* chip type */ u_int sc_fsz; /* fifo size */ u_int sc_idbit; /* host id bit */ @@ -75,12 +77,12 @@ struct stg_softc { }; /***************************************************************** - * Lun information + * Target information *****************************************************************/ -struct stg_lun_info { - struct lun_info sli_li; /* generic data */ +struct stg_targ_info { + struct targ_info sti_ti; /* generic data */ - u_int8_t sli_reg_synch; /* synch register per lun */ + u_int8_t sti_reg_synch; /* synch register per target */ }; /***************************************************************** |