diff options
author | jhb <jhb@FreeBSD.org> | 2014-11-20 20:50:05 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2014-11-20 20:50:05 +0000 |
commit | d23541b62beeb8a67a793ffbbbb84a3e1f0a5494 (patch) | |
tree | bbaa810399dc71aebe8cb8d0f01072240f5f0681 /sys/dev/ncv | |
parent | 86ac03a3f79123d99c1bbb40a40c6fffeaf777af (diff) | |
download | FreeBSD-src-d23541b62beeb8a67a793ffbbbb84a3e1f0a5494.zip FreeBSD-src-d23541b62beeb8a67a793ffbbbb84a3e1f0a5494.tar.gz |
Lock the scsi_low code and the drivers which use it along with other
related cleanups:
- Require each driver to initalize a mutex in the scsi_low_softc that
is shared with the scsi_low code. This mutex is used for CAM SIMs,
timers, and interrupt handlers.
- Replace the osdep function switch with direct calls to the relevant
CAM functions and direct manipulation of timers via callout(9).
- Collapse the CAM-specific scsi_low_osdep_interface substructure
directly into scsi_low_softc.
- Use bus_*() instead of bus_space_*().
- Return BUS_PROBE_DEFAULT from probe routines instead of 0.
- No need to zero softcs.
- Pass 0ul and ~0ul instead of 0 and ~0 to bus_alloc_resource().
- Spell "dettach" as "detach".
- Remove unused 'dvname' variables.
- De-spl().
Tested by: no one
Diffstat (limited to 'sys/dev/ncv')
-rw-r--r-- | sys/dev/ncv/ncr53c500.c | 363 | ||||
-rw-r--r-- | sys/dev/ncv/ncr53c500_pccard.c | 37 | ||||
-rw-r--r-- | sys/dev/ncv/ncr53c500var.h | 6 |
3 files changed, 170 insertions, 236 deletions
diff --git a/sys/dev/ncv/ncr53c500.c b/sys/dev/ncv/ncr53c500.c index 3bbded4..8362682 100644 --- a/sys/dev/ncv/ncr53c500.c +++ b/sys/dev/ncv/ncr53c500.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include <sys/queue.h> #include <sys/malloc.h> #include <sys/errno.h> +#include <sys/rman.h> #include <machine/cpu.h> #include <machine/bus.h> @@ -107,18 +108,18 @@ static int ncv_msg(struct ncv_softc *, struct targ_info *, u_int); static int ncv_reselected(struct ncv_softc *); static int ncv_disconnected(struct ncv_softc *, struct targ_info *); -static __inline void ncvhw_set_count(bus_space_tag_t, bus_space_handle_t, int); -static __inline u_int ncvhw_get_count(bus_space_tag_t, bus_space_handle_t); -static __inline void ncvhw_select_register_0(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static __inline void ncvhw_select_register_1(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static __inline void ncvhw_fpush(bus_space_tag_t, bus_space_handle_t, u_int8_t *, int); +static __inline void ncvhw_set_count(struct resource *, int); +static __inline u_int ncvhw_get_count(struct resource *); +static __inline void ncvhw_select_register_0(struct resource *, struct ncv_hw *); +static __inline void ncvhw_select_register_1(struct resource *, struct ncv_hw *); +static __inline void ncvhw_fpush(struct resource *, u_int8_t *, int); static void ncv_pdma_end(struct ncv_softc *sc, struct targ_info *); static int ncv_world_start(struct ncv_softc *, int); static void ncvhw_bus_reset(struct ncv_softc *); -static void ncvhw_reset(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static int ncvhw_check(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static void ncvhw_init(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); +static void ncvhw_reset(struct resource *, struct ncv_hw *); +static int ncvhw_check(struct resource *, struct ncv_hw *); +static void ncvhw_init(struct resource *, struct ncv_hw *); static int ncvhw_start_selection(struct ncv_softc *sc, struct slccb *); static void ncvhw_attention(struct ncv_softc *); static int ncv_ccb_nexus_establish(struct ncv_softc *); @@ -154,74 +155,56 @@ struct scsi_low_funcs ncv_funcs = { * hwfuncs **************************************************************/ static __inline void -ncvhw_select_register_0(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_select_register_0(struct resource *res, struct ncv_hw *hw) { - bus_space_write_1(iot, ioh, cr0_cfg4, hw->hw_cfg4); + bus_write_1(res, cr0_cfg4, hw->hw_cfg4); } static __inline void -ncvhw_select_register_1(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_select_register_1(struct resource *res, struct ncv_hw *hw) { - bus_space_write_1(iot, ioh, cr1_cfg5, hw->hw_cfg5); + bus_write_1(res, cr1_cfg5, hw->hw_cfg5); } static __inline void -ncvhw_fpush(iot, ioh, buf, len) - bus_space_tag_t iot; - bus_space_handle_t ioh; - u_int8_t *buf; - int len; +ncvhw_fpush(struct resource *res, u_int8_t *buf, int len) { int ptr; for (ptr = 0; ptr < len; ptr ++) - bus_space_write_1(iot, ioh, cr0_sfifo, buf[ptr]); + bus_write_1(res, cr0_sfifo, buf[ptr]); } static __inline void -ncvhw_set_count(iot, ioh, count) - bus_space_tag_t iot; - bus_space_handle_t ioh; - int count; +ncvhw_set_count(struct resource *res, int count) { - bus_space_write_1(iot, ioh, cr0_tclsb, (u_int8_t) count); - bus_space_write_1(iot, ioh, cr0_tcmsb, (u_int8_t) (count >> NBBY)); - bus_space_write_1(iot, ioh, cr0_tchsb, (u_int8_t) (count >> (NBBY * 2))); + bus_write_1(res, cr0_tclsb, (u_int8_t) count); + bus_write_1(res, cr0_tcmsb, (u_int8_t) (count >> NBBY)); + bus_write_1(res, cr0_tchsb, (u_int8_t) (count >> (NBBY * 2))); } static __inline u_int -ncvhw_get_count(iot, ioh) - bus_space_tag_t iot; - bus_space_handle_t ioh; +ncvhw_get_count(struct resource *res) { u_int count; - count = (u_int) bus_space_read_1(iot, ioh, cr0_tclsb); - count |= ((u_int) bus_space_read_1(iot, ioh, cr0_tcmsb)) << NBBY; - count |= ((u_int) bus_space_read_1(iot, ioh, cr0_tchsb)) << (NBBY * 2); + count = (u_int) bus_read_1(res, cr0_tclsb); + count |= ((u_int) bus_read_1(res, cr0_tcmsb)) << NBBY; + count |= ((u_int) bus_read_1(res, cr0_tchsb)) << (NBBY * 2); return count; } static int -ncvhw_check(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_check(struct resource *res, struct ncv_hw *hw) { u_int8_t stat; - ncvhw_select_register_0(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA); - if (bus_space_read_1(iot, ioh, cr0_cmd) != (CMD_NOP | CMD_DMA)) + ncvhw_select_register_0(res, hw); + bus_write_1(res, cr0_cmd, CMD_NOP | CMD_DMA); + if (bus_read_1(res, cr0_cmd) != (CMD_NOP | CMD_DMA)) { #ifdef NCV_DEBUG printf("ncv: cr0_cmd CMD_NOP|CMD_DMA failed\n"); @@ -229,8 +212,8 @@ ncvhw_check(iot, ioh, hw) return ENODEV; } - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); - if (bus_space_read_1(iot, ioh, cr0_cmd) != CMD_NOP) + bus_write_1(res, cr0_cmd, CMD_NOP); + if (bus_read_1(res, cr0_cmd) != CMD_NOP) { #ifdef NCV_DEBUG printf("ncv: cr0_cmd CMD_NOP failed\n"); @@ -239,23 +222,23 @@ ncvhw_check(iot, ioh, hw) } /* hardware reset */ - ncvhw_reset(iot, ioh, hw); - ncvhw_init(iot, ioh, hw); + ncvhw_reset(res, hw); + ncvhw_init(res, hw); /* bus reset */ - ncvhw_select_register_0(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTSCSI); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA); + ncvhw_select_register_0(res, hw); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_RSTSCSI); + bus_write_1(res, cr0_cmd, CMD_NOP | CMD_DMA); DELAY(100 * 1000); /* check response */ - bus_space_read_1(iot, ioh, cr0_stat); - stat = bus_space_read_1(iot, ioh, cr0_istat); + bus_read_1(res, cr0_stat); + stat = bus_read_1(res, cr0_istat); DELAY(1000); if (((stat & INTR_SBR) == 0) || - (bus_space_read_1(iot, ioh, cr0_istat) & INTR_SBR)) + (bus_read_1(res, cr0_istat) & INTR_SBR)) { #ifdef NCV_DEBUG printf("ncv: cr0_istat SCSI BUS RESET failed\n"); @@ -267,50 +250,44 @@ ncvhw_check(iot, ioh, hw) } static void -ncvhw_reset(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_reset(struct resource *res, struct ncv_hw *hw) { - ncvhw_select_register_0(iot, ioh, hw); + ncvhw_select_register_0(res, hw); /* dummy cmd twice */ - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); /* chip reset */ - bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTCHIP); + bus_write_1(res, cr0_cmd, CMD_RSTCHIP); /* again dummy cmd twice */ - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); } static void -ncvhw_init(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_init(struct resource *res, struct ncv_hw *hw) { - ncvhw_select_register_0(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr0_clk, hw->hw_clk); - bus_space_write_1(iot, ioh, cr0_srtout, SEL_TOUT); - bus_space_write_1(iot, ioh, cr0_period, 0); - bus_space_write_1(iot, ioh, cr0_offs, 0); + ncvhw_select_register_0(res, hw); + bus_write_1(res, cr0_clk, hw->hw_clk); + bus_write_1(res, cr0_srtout, SEL_TOUT); + bus_write_1(res, cr0_period, 0); + bus_write_1(res, cr0_offs, 0); - bus_space_write_1(iot, ioh, cr0_cfg1, hw->hw_cfg1); - bus_space_write_1(iot, ioh, cr0_cfg2, hw->hw_cfg2); - bus_space_write_1(iot, ioh, cr0_cfg3, hw->hw_cfg3); - bus_space_write_1(iot, ioh, cr0_tchsb, 0); + bus_write_1(res, cr0_cfg1, hw->hw_cfg1); + bus_write_1(res, cr0_cfg2, hw->hw_cfg2); + bus_write_1(res, cr0_cfg3, hw->hw_cfg3); + bus_write_1(res, cr0_tchsb, 0); - ncvhw_select_register_1(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr1_fstat, 0x0); - bus_space_write_1(iot, ioh, cr1_pflag, 0x0); - bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_ENGAGE); + ncvhw_select_register_1(res, hw); + bus_write_1(res, cr1_fstat, 0x0); + bus_write_1(res, cr1_pflag, 0x0); + bus_write_1(res, cr1_atacmd, ATACMD_ENGAGE); - ncvhw_select_register_0(iot, ioh, hw); + ncvhw_select_register_0(res, hw); } #ifdef NCV_POWER_CONTROL @@ -320,14 +297,13 @@ ncvhw_power(sc, flags) u_int flags; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; if (flags == SCSI_LOW_POWDOWN) { device_printf(slp->sl_dev, "power down\n"); - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_POWDOWN); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_atacmd, ATACMD_POWDOWN); } else { @@ -335,14 +311,14 @@ ncvhw_power(sc, flags) { case 0: device_printf(slp->sl_dev, "resume step O\n"); - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_ENGAGE); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_atacmd, ATACMD_ENGAGE); break; case 1: device_printf(slp->sl_dev, "resume step I\n"); - ncvhw_reset(iot, ioh, &sc->sc_hw); - ncvhw_init(iot, ioh, &sc->sc_hw); + ncvhw_reset(res, &sc->sc_hw); + ncvhw_init(res, &sc->sc_hw); break; } } @@ -359,7 +335,7 @@ ncvhw_attention(sc) struct ncv_softc *sc; { - bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd, CMD_SETATN); + bus_write_1(sc->port_res, cr0_cmd, CMD_SETATN); DELAY(10); } @@ -367,13 +343,11 @@ static void ncvhw_bus_reset(sc) struct ncv_softc *sc; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTSCSI); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA); + ncvhw_select_register_0(sc->port_res, &sc->sc_hw); + bus_write_1(sc->port_res, cr0_cmd, CMD_FLUSH); + bus_write_1(sc->port_res, cr0_cmd, CMD_RSTSCSI); + bus_write_1(sc->port_res, cr0_cmd, CMD_NOP | CMD_DMA); } static int @@ -382,10 +356,9 @@ ncvhw_start_selection(sc, cb) struct slccb *cb; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct targ_info *ti = cb->ti; - int s, len; + int len; u_int flags; u_int8_t cmd; @@ -411,8 +384,8 @@ ncvhw_start_selection(sc, cb) flags = SCSI_LOW_MSGOUT_INIT; } - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - if ((bus_space_read_1(iot, ioh, cr0_stat) & STAT_INT) != 0) + ncvhw_select_register_0(res, &sc->sc_hw); + if ((bus_read_1(res, cr0_stat) & STAT_INT) != 0) return SCSI_LOW_START_FAIL; ncv_target_nexus_establish(sc); @@ -421,23 +394,18 @@ ncvhw_start_selection(sc, cb) if (sc->sc_selstop == 0) scsi_low_cmd(slp, ti); - s = splhigh(); - if ((bus_space_read_1(iot, ioh, cr0_stat) & STAT_INT) != 0) - { - splx(s); + if ((bus_read_1(res, cr0_stat) & STAT_INT) != 0) return SCSI_LOW_START_FAIL; - } - bus_space_write_1(iot, ioh, cr0_dstid, ti->ti_id); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - ncvhw_fpush(iot, ioh, ti->ti_msgoutstr, len); + bus_write_1(res, cr0_dstid, ti->ti_id); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + ncvhw_fpush(res, ti->ti_msgoutstr, len); if (sc->sc_selstop == 0) { - ncvhw_fpush(iot, ioh, + ncvhw_fpush(res, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen); } - bus_space_write_1(iot, ioh, cr0_cmd, cmd); - splx(s); + bus_write_1(res, cr0_cmd, cmd); SCSI_LOW_SETUP_PHASE(ti, PH_SELSTART); return SCSI_LOW_START_OK; @@ -449,8 +417,7 @@ ncv_world_start(sc, fdone) int fdone; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; u_int8_t stat; if ((slp->sl_cfgflags & CFG_NOPARITY) == 0) @@ -458,18 +425,18 @@ ncv_world_start(sc, fdone) else sc->sc_hw.hw_cfg1 &= ~C1_PARENB; - ncvhw_reset(iot, ioh, &sc->sc_hw); - ncvhw_init(iot, ioh, &sc->sc_hw); + ncvhw_reset(res, &sc->sc_hw); + ncvhw_init(res, &sc->sc_hw); 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); + ncvhw_select_register_0(res, &sc->sc_hw); + bus_read_1(res, cr0_stat); + stat = bus_read_1(res, cr0_istat); DELAY(1000); if (((stat & INTR_SBR) == 0) || - (bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_istat) & INTR_SBR)) + (bus_read_1(res, cr0_istat) & INTR_SBR)) return ENODEV; return 0; @@ -481,8 +448,7 @@ ncv_msg(sc, ti, msg) struct targ_info *ti; u_int msg; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct ncv_targ_info *nti = (void *) ti; u_int hwcycle, period; @@ -512,9 +478,9 @@ ncv_msg(sc, ti, msg) nti->nti_reg_period = period & 0x1f; nti->nti_reg_offset = ti->ti_maxsynch.offset; - 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); + bus_write_1(res, cr0_period, nti->nti_reg_period); + bus_write_1(res, cr0_offs, nti->nti_reg_offset); + bus_write_1(res, cr0_cfg3, nti->nti_reg_cfg3); return 0; } @@ -588,18 +554,14 @@ ncv_setup_img(hw, dvcfg, hostid) } int -ncvprobesubr(iot, ioh, dvcfg, hsid) - bus_space_tag_t iot; - bus_space_handle_t ioh; - u_int dvcfg; - int hsid; +ncvprobesubr(struct resource *res, u_int dvcfg, int hsid) { struct ncv_hw hwtab; hwtab = ncv_template; if (ncv_setup_img(&hwtab, dvcfg, hsid)) return 0; - if (ncvhw_check(iot, ioh, &hwtab) != 0) + if (ncvhw_check(res, &hwtab) != 0) return 0; return 1; @@ -630,15 +592,14 @@ ncv_setup_and_start_pio(sc, reqlen) struct ncv_softc *sc; u_int reqlen; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - ncvhw_set_count(iot, ioh, reqlen); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS | CMD_DMA); + ncvhw_select_register_0(res, &sc->sc_hw); + ncvhw_set_count(res, reqlen); + bus_write_1(res, cr0_cmd, CMD_TRANS | CMD_DMA); - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_fstat, FIFO_EN); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_fstat, FIFO_EN); } static void @@ -647,8 +608,7 @@ ncv_pdma_end(sc, ti) struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; int len; slp->sl_flags &= ~HW_PDMASTART; @@ -660,9 +620,9 @@ ncv_pdma_end(sc, ti) if (ti->ti_phase == PH_DATA) { - len = ncvhw_get_count(sc->sc_iot, sc->sc_ioh); + len = ncvhw_get_count(res); if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE) - len += (bus_space_read_1(sc->sc_iot, sc->sc_ioh, + len += (bus_read_1(res, cr0_sffl) & CR0_SFFLR_BMASK); if ((u_int) len <= (u_int) sc->sc_sdatalen) @@ -698,9 +658,9 @@ bad: } out: - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_fstat, 0); - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_fstat, 0); + ncvhw_select_register_0(res, &sc->sc_hw); } static void @@ -710,8 +670,7 @@ ncv_pio_read(sc, buf, reqlen) u_int 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; + struct resource *res = sc->port_res; int tout; register u_int8_t fstat; @@ -722,17 +681,17 @@ ncv_pio_read(sc, buf, reqlen) while (reqlen >= FIFO_F_SZ && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if (fstat == (u_int8_t) -1) goto out; if (fstat & FIFO_F) { #define NCV_FAST32_ACCESS #ifdef NCV_FAST32_ACCESS - bus_space_read_multi_4(iot, ioh, cr1_fdata, + bus_read_multi_4(res, cr1_fdata, (u_int32_t *) buf, FIFO_F_SZ / 4); #else /* !NCV_FAST32_ACCESS */ - bus_space_read_multi_2(iot, ioh, cr1_fdata, + bus_read_multi_2(res, cr1_fdata, (u_int16_t *) buf, FIFO_F_SZ / 2); #endif /* !NCV_FAST32_ACCESS */ buf += FIFO_F_SZ; @@ -749,10 +708,10 @@ ncv_pio_read(sc, buf, reqlen) while (reqlen > 0 && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if ((fstat & FIFO_E) == 0) { - *buf++ = bus_space_read_1(iot, ioh, cr1_fdata); + *buf++ = bus_read_1(res, cr1_fdata); reqlen --; } else @@ -765,7 +724,7 @@ ncv_pio_read(sc, buf, reqlen) } out: - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); + ncvhw_select_register_0(res, &sc->sc_hw); sc->sc_tdatalen = reqlen; } @@ -776,8 +735,7 @@ ncv_pio_write(sc, buf, reqlen) u_int 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; + struct resource *res = sc->port_res; int tout; register u_int8_t fstat; @@ -788,17 +746,17 @@ ncv_pio_write(sc, buf, reqlen) while (reqlen >= FIFO_F_SZ && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if (fstat & FIFO_BRK) goto done; if ((fstat & FIFO_E) != 0) { #ifdef NCV_FAST32_ACCESS - bus_space_write_multi_4(iot, ioh, cr1_fdata, + bus_write_multi_4(res, cr1_fdata, (u_int32_t *) buf, FIFO_F_SZ / 4); #else /* !NCV_FAST32_ACCESS */ - bus_space_write_multi_2(iot, ioh, cr1_fdata, + bus_write_multi_2(res, cr1_fdata, (u_int16_t *) buf, FIFO_F_SZ / 2); #endif /* !NCV_FAST32_ACCESS */ buf += FIFO_F_SZ; @@ -812,13 +770,13 @@ ncv_pio_write(sc, buf, reqlen) while (reqlen > 0 && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if (fstat & FIFO_BRK) break; if ((fstat & FIFO_F) == 0) /* fifo not full */ { - bus_space_write_1(iot, ioh, cr1_fdata, *buf++); + bus_write_1(res, cr1_fdata, *buf++); reqlen --; } else @@ -828,7 +786,7 @@ ncv_pio_write(sc, buf, reqlen) } done: - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); + ncvhw_select_register_0(res, &sc->sc_hw); } /************************************************************** @@ -839,19 +797,18 @@ ncv_reselected(sc) struct ncv_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct targ_info *ti; u_int sid; - if ((bus_space_read_1(iot, ioh, cr0_sffl) & CR0_SFFLR_BMASK) != 2) + if ((bus_read_1(res, cr0_sffl) & CR0_SFFLR_BMASK) != 2) { device_printf(slp->sl_dev, "illegal fifo bytes\n"); scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "chip confused"); return EJUSTRETURN; } - sid = (u_int) bus_space_read_1(iot, ioh, cr0_sfifo); + sid = (u_int) bus_read_1(res, cr0_sfifo); sid &= ~(1 << slp->sl_hostid); sid = ffs(sid) - 1; ti = scsi_low_reselected((struct scsi_low_softc *) sc, sid); @@ -861,7 +818,7 @@ ncv_reselected(sc) #ifdef NCV_STATICS ncv_statics.reselect ++; #endif /* NCV_STATICS */ - bus_space_write_1(iot, ioh, cr0_dstid, sid); + bus_write_1(res, cr0_dstid, sid); return 0; } @@ -871,11 +828,10 @@ ncv_disconnected(sc, ti) struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_ENSEL); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_ENSEL); #ifdef NCV_STATICS ncv_statics.disconnect ++; @@ -895,12 +851,11 @@ ncv_target_nexus_establish(sc) struct scsi_low_softc *slp = &sc->sc_sclow; struct targ_info *ti = slp->sl_Tnexus; struct ncv_targ_info *nti = (void *) ti; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; - 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); + bus_write_1(res, cr0_period, nti->nti_reg_period); + bus_write_1(res, cr0_offs, nti->nti_reg_offset); + bus_write_1(res, cr0_cfg3, nti->nti_reg_cfg3); return 0; } @@ -927,14 +882,13 @@ static int ncv_catch_intr(sc) struct ncv_softc *sc; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; int wc; register u_int8_t status; for (wc = 0; wc < NCV_DELAY_MAX / NCV_DELAY_INTERVAL; wc ++) { - status = bus_space_read_1(iot, ioh, cr0_stat); + status = bus_read_1(res, cr0_stat); if ((status & STAT_INT) != 0) return 0; @@ -949,8 +903,7 @@ ncvintr(arg) { struct ncv_softc *sc = arg; struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct targ_info *ti; struct buf *bp; u_int derror, flags; @@ -964,19 +917,19 @@ again: /******************************************** * Status ********************************************/ - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - status = bus_space_read_1(iot, ioh, cr0_stat); + ncvhw_select_register_0(res, &sc->sc_hw); + status = bus_read_1(res, cr0_stat); if ((status & STAT_INT) == 0 || status == (u_int8_t) -1) return 0; - ireason = bus_space_read_1(iot, ioh, cr0_istat); + ireason = bus_read_1(res, cr0_istat); if ((ireason & INTR_SBR) != 0) { u_int8_t val; /* avoid power off hangup */ - val = bus_space_read_1(iot, ioh, cr0_cfg1); - bus_space_write_1(iot, ioh, cr0_cfg1, val | C1_SRR); + val = bus_read_1(res, cr0_cfg1); + bus_write_1(res, cr0_cfg1, val | C1_SRR); /* status init */ scsi_low_restart(slp, SCSI_LOW_RESTART_SOFT, @@ -1183,16 +1136,16 @@ again: scsi_low_attention(slp); } - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - ncvhw_fpush(iot, ioh, + bus_write_1(res, cr0_cmd, CMD_FLUSH); + ncvhw_fpush(res, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS); + bus_write_1(res, cr0_cmd, CMD_TRANS); break; case STATUS_PHASE: /* status in */ SCSI_LOW_SETUP_PHASE(ti, PH_STAT); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_ICCS); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_ICCS); sc->sc_compseq = 1; break; @@ -1201,7 +1154,7 @@ again: case MESSAGE_OUT_PHASE: /* msg out */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_FLUSH); flags = SCSI_LOW_MSGOUT_UNIFY; if (ti->ti_ophase != ti->ti_phase) @@ -1213,21 +1166,21 @@ again: scsi_low_attention(slp); } - ncvhw_fpush(iot, ioh, ti->ti_msgoutstr, len); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS); + ncvhw_fpush(res, ti->ti_msgoutstr, len); + bus_write_1(res, cr0_cmd, CMD_TRANS); SCSI_LOW_DEASSERT_ATN(slp); break; case MESSAGE_IN_PHASE: /* msg in */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); - len = bus_space_read_1(iot, ioh, cr0_sffl) & CR0_SFFLR_BMASK; + len = bus_read_1(res, cr0_sffl) & CR0_SFFLR_BMASK; if (sc->sc_compseq != 0) { sc->sc_compseq = 0; if ((ireason & INTR_FC) && len == 2) { - regv = bus_space_read_1(iot, ioh, cr0_sfifo); + regv = bus_read_1(res, cr0_sfifo); scsi_low_statusin(slp, ti, regv | derror); len --; } @@ -1236,15 +1189,14 @@ again: slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1); - bus_space_write_1(sc->sc_iot, sc->sc_ioh, - cr0_cmd, CMD_MSGOK); + bus_write_1(res, cr0_cmd, CMD_MSGOK); break; } } else if (ireason & INTR_BS) { - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_TRANS); if ((ncv_io_control & NCV_FAST_INTERRUPTS) != 0) { if (ncv_catch_intr(sc) == 0) @@ -1255,8 +1207,7 @@ again: if ((ireason & INTR_FC) && len == 1) { - regv = bus_space_read_1(sc->sc_iot, sc->sc_ioh, - cr0_sfifo); + regv = bus_read_1(res, cr0_sfifo); if (scsi_low_msgin(slp, ti, regv | derror) == 0) { if (scsi_low_is_msgout_continue(ti, 0) != 0) @@ -1264,8 +1215,7 @@ again: scsi_low_attention(slp); } } - bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd, - CMD_MSGOK); + bus_write_1(res, cr0_cmd, CMD_MSGOK); if ((ncv_io_control & NCV_FAST_INTERRUPTS) != 0) { /* XXX: @@ -1279,8 +1229,7 @@ again: { slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1); - bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd, - CMD_MSGOK); + bus_write_1(res, cr0_cmd, CMD_MSGOK); } break; } diff --git a/sys/dev/ncv/ncr53c500_pccard.c b/sys/dev/ncv/ncr53c500_pccard.c index 72df586..23c207a 100644 --- a/sys/dev/ncv/ncr53c500_pccard.c +++ b/sys/dev/ncv/ncr53c500_pccard.c @@ -98,7 +98,12 @@ static const struct ncv_product { static void ncv_pccard_intr(void * arg) { + struct ncv_softc *sc; + + sc = arg; + SCSI_LOW_LOCK(&sc->sc_sclow); ncvintr(arg); + SCSI_LOW_UNLOCK(&sc->sc_sclow); } static void @@ -129,6 +134,7 @@ ncv_release_resource(device_t dev) bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); } + mtx_destroy(&sc->sc_sclow.sl_lock); } static int @@ -148,6 +154,7 @@ ncv_alloc_resource(device_t dev) return(ENOMEM); } + mtx_init(&sc->sc_sclow.sl_lock, "ncv", NULL, MTX_DEF); sc->port_rid = 0; sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, ioaddr+offset, ioaddr+iosize-offset, @@ -223,7 +230,7 @@ ncv_pccard_probe(device_t dev) strncmp(prodstr, "SOUND/SCSI2 CARD", 16) == 0) { device_set_desc(dev, "RATOC REX-5572"); device_set_flags(dev, FLAGS_REX5572); - return (0); + return (BUS_PROBE_DEFAULT); } return(EIO); } @@ -234,8 +241,6 @@ ncv_pccard_attach(device_t dev) struct ncv_softc *sc = device_get_softc(dev); int error; - bzero(sc, sizeof(struct ncv_softc)); - error = ncv_alloc_resource(dev); if (error) { return(error); @@ -245,8 +250,8 @@ ncv_pccard_attach(device_t dev) ncv_release_resource(dev); return(ENXIO); } - error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, - NULL, ncv_pccard_intr, (void *)sc, &sc->ncv_intrhand); + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY | + INTR_MPSAFE, NULL, ncv_pccard_intr, sc, &sc->ncv_intrhand); if (error) { ncv_release_resource(dev); return(error); @@ -293,12 +298,9 @@ static void ncv_card_unload(device_t devi) { struct ncv_softc *sc = device_get_softc(devi); - intrmask_t s; - s = splcam(); - scsi_low_deactivate((struct scsi_low_softc *)sc); - scsi_low_dettach(&sc->sc_sclow); - splx(s); + scsi_low_deactivate(&sc->sc_sclow); + scsi_low_detach(&sc->sc_sclow); } static int @@ -308,8 +310,7 @@ ncvprobe(device_t devi) struct ncv_softc *sc = device_get_softc(devi); u_int32_t flags = device_get_flags(devi); - rv = ncvprobesubr(rman_get_bustag(sc->port_res), - rman_get_bushandle(sc->port_res), + rv = ncvprobesubr(sc->port_res, flags, NCV_HOSTID); return rv; @@ -321,27 +322,15 @@ ncvattach(device_t devi) struct ncv_softc *sc; struct scsi_low_softc *slp; u_int32_t flags = device_get_flags(devi); - intrmask_t s; - char dvname[16]; /* SCSI_LOW_DVNAME_LEN */ - - strcpy(dvname, "ncv"); sc = device_get_softc(devi); - if (sc == NULL) { - return(0); - } slp = &sc->sc_sclow; slp->sl_dev = devi; - sc->sc_iot = rman_get_bustag(sc->port_res); - sc->sc_ioh = rman_get_bushandle(sc->port_res); - slp->sl_hostid = NCV_HOSTID; slp->sl_cfgflags = flags; - s = splcam(); ncvattachsubr(sc); - splx(s); return(NCVIOSZ); } diff --git a/sys/dev/ncv/ncr53c500var.h b/sys/dev/ncv/ncr53c500var.h index 85e3330..d92702f 100644 --- a/sys/dev/ncv/ncr53c500var.h +++ b/sys/dev/ncv/ncr53c500var.h @@ -42,10 +42,6 @@ struct ncv_softc { struct scsi_low_softc sc_sclow; /* generic data */ - bus_space_tag_t sc_iot; - bus_space_tag_t sc_memt; - bus_space_handle_t sc_ioh; - int port_rid; int port_rid_dmy; int irq_rid; @@ -80,7 +76,7 @@ struct ncv_targ_info { /***************************************************************** * Proto *****************************************************************/ -int ncvprobesubr(bus_space_tag_t, bus_space_handle_t ioh, u_int, int); +int ncvprobesubr(struct resource *, u_int, int); void ncvattachsubr(struct ncv_softc *); int ncvintr(void *); |