diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2014-01-23 01:51:54 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2014-01-23 01:51:54 +0000 |
commit | d59d4b1a165167c9b93709484d3a8bc00d11f6e4 (patch) | |
tree | 7bda175c9db10fbd9aa5b86cea50c2fc745d3e59 /sys/dev/pci | |
parent | f9438c0d64089f2ba777bd20df336dc92f42e624 (diff) |
factor the mutex/bus_space handling of the sts block out.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/if_myx.c | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/sys/dev/pci/if_myx.c b/sys/dev/pci/if_myx.c index ae9105eec20..606fa95d880 100644 --- a/sys/dev/pci/if_myx.c +++ b/sys/dev/pci/if_myx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_myx.c,v 1.50 2014/01/21 23:26:50 dlg Exp $ */ +/* $OpenBSD: if_myx.c,v 1.51 2014/01/23 01:51:53 dlg Exp $ */ /* * Copyright (c) 2007 Reyk Floeter <reyk@openbsd.org> @@ -220,6 +220,26 @@ void myx_ring_lock_init(struct myx_ring_lock *); int myx_ring_enter(struct myx_ring_lock *); int myx_ring_leave(struct myx_ring_lock *); +static inline void +myx_sts_enter(struct myx_softc *sc) +{ + bus_dmamap_t map = sc->sc_sts_dma.mxm_map; + + mtx_enter(&sc->sc_sts_mtx); + bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, + BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); +} + +static inline void +myx_sts_leave(struct myx_softc *sc) +{ + bus_dmamap_t map = sc->sc_sts_dma.mxm_map; + + bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, + BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); + mtx_leave(&sc->sc_sts_mtx); +} + struct cfdriver myx_cd = { NULL, "myx", DV_IFNET }; @@ -839,7 +859,6 @@ void myx_media_status(struct ifnet *ifp, struct ifmediareq *imr) { struct myx_softc *sc = (struct myx_softc *)ifp->if_softc; - bus_dmamap_t map = sc->sc_sts_dma.mxm_map; u_int32_t sts; imr->ifm_active = IFM_ETHER | IFM_AUTO; @@ -848,13 +867,9 @@ myx_media_status(struct ifnet *ifp, struct ifmediareq *imr) return; } - mtx_enter(&sc->sc_sts_mtx); - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_POSTREAD); + myx_sts_enter(sc); sts = sc->sc_sts->ms_linkstate; - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_PREREAD); - mtx_leave(&sc->sc_sts_mtx); + myx_sts_leave(sc); myx_link_state(sc, sts); @@ -1319,28 +1334,23 @@ myx_down(struct myx_softc *sc) struct myx_cmd mc; int s; - mtx_enter(&sc->sc_sts_mtx); - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_POSTREAD); + myx_sts_enter(sc); sc->sc_linkdown = sc->sc_sts->ms_linkdown; - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_PREREAD); - mtx_leave(&sc->sc_sts_mtx); + myx_sts_leave(sc); memset(&mc, 0, sizeof(mc)); (void)myx_cmd(sc, MYXCMD_SET_IFDOWN, &mc, NULL); - mtx_enter(&sc->sc_sts_mtx); - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_POSTREAD); + myx_sts_enter(sc); + /* we play with the guts of sc_sts by hand here */ while (sc->sc_linkdown == sc->sc_sts->ms_linkdown) { bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_PREREAD); + BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); msleep(sc->sc_sts, &sc->sc_sts_mtx, 0, "myxdown", 0); bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_POSTREAD); + BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); } mtx_leave(&sc->sc_sts_mtx); @@ -1604,7 +1614,6 @@ myx_intr(void *arg) struct myx_softc *sc = (struct myx_softc *)arg; struct ifnet *ifp = &sc->sc_ac.ac_if; volatile struct myx_status *sts = sc->sc_sts; - bus_dmamap_t map = sc->sc_sts_dma.mxm_map; u_int32_t data, link; int refill = 0; u_int8_t valid = 0; @@ -1618,15 +1627,10 @@ myx_intr(void *arg) if (!ISSET(if_flags, IFF_RUNNING)) return (0); - mtx_enter(&sc->sc_sts_mtx); - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_POSTREAD); - + myx_sts_enter(sc); valid = sts->ms_isvalid; if (valid == 0x0) { - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_PREREAD); - mtx_leave(&sc->sc_sts_mtx); + myx_sts_leave(sc); return (0); } sts->ms_isvalid = 0; @@ -1647,23 +1651,16 @@ myx_intr(void *arg) do { data = betoh32(sts->ms_txdonecnt); - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_PREREAD); - mtx_leave(&sc->sc_sts_mtx); + myx_sts_leave(sc); if (data != sc->sc_tx_count) myx_txeof(sc, data); refill |= myx_rxeof(sc); - mtx_enter(&sc->sc_sts_mtx); - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_POSTREAD); + myx_sts_enter(sc); } while (sts->ms_isvalid); - - bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize, - BUS_DMASYNC_PREREAD); - mtx_leave(&sc->sc_sts_mtx); + myx_sts_leave(sc); if (link != 0xffffffff) { KERNEL_LOCK(); |