diff --git a/sys/dev/ep/if_ep.c b/sys/dev/ep/if_ep.c index e1132b2d4fd1..ba59f692eb8d 100644 --- a/sys/dev/ep/if_ep.c +++ b/sys/dev/ep/if_ep.c @@ -95,8 +95,8 @@ static int epioctl(struct ifnet *, u_long, caddr_t); static void epstart(struct ifnet *); static void epwatchdog(struct ifnet *); -static void epstart_body(struct ifnet *); -static void epinit_body(struct ep_softc *); +static void epstart_locked(struct ifnet *); +static void epinit_locked(struct ep_softc *); /* if_media functions */ static int ep_ifmedia_upd(struct ifnet *); @@ -270,12 +270,11 @@ ep_attach(struct ep_softc *sc) int error; sc->gone = 0; - mtx_init(&sc->sc_mtx, device_get_nameunit(sc->dev), MTX_NETWORK_LOCK, - MTX_DEF); + EP_LOCK_INIT(sc); error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); if (error) { device_printf(sc->dev, "Unable to get Ethernet address!\n"); - mtx_destroy(&sc->sc_mtx); + EP_LOCK_DESTORY(sc); return (ENXIO); } /* @@ -349,6 +348,7 @@ ep_detach(device_t dev) struct ifnet *ifp; sc = device_get_softc(dev); + EP_ASSERT_UNLOCKED(sc); ifp = &sc->arpcom.ac_if; if (sc->gone) { @@ -363,7 +363,7 @@ ep_detach(device_t dev) sc->gone = 1; ep_free(dev); - mtx_destroy(&sc->sc_mtx); + EP_LOCK_DESTORY(sc); return (0); } @@ -373,7 +373,7 @@ epinit(void *xsc) { struct ep_softc *sc = xsc; EP_LOCK(sc); - epinit_body(sc); + epinit_locked(sc); EP_UNLOCK(sc); } @@ -382,7 +382,7 @@ epinit(void *xsc) * interrupts. ?! */ static void -epinit_body(struct ep_softc *sc) +epinit_locked(struct ep_softc *sc) { struct ifnet *ifp = &sc->arpcom.ac_if; int i; @@ -390,7 +390,8 @@ epinit_body(struct ep_softc *sc) if (sc->gone) return; - EP_BUSY_WAIT; + EP_ASSERT_LOCKED(sc); + EP_BUSY_WAIT(sc); GO_WINDOW(0); CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER); @@ -412,7 +413,7 @@ epinit_body(struct ep_softc *sc) CSR_WRITE_2(sc, EP_COMMAND, RX_RESET); CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); - EP_BUSY_WAIT; + EP_BUSY_WAIT(sc); /* Window 1 is operating window */ GO_WINDOW(1); @@ -461,7 +462,7 @@ epinit_body(struct ep_softc *sc) */ GO_WINDOW(1); - epstart_body(ifp); + epstart_locked(ifp); } static void @@ -470,12 +471,12 @@ epstart(struct ifnet *ifp) struct ep_softc *sc; sc = ifp->if_softc; EP_LOCK(sc); - epstart_body(ifp); + epstart_locked(ifp); EP_UNLOCK(sc); } static void -epstart_body(struct ifnet *ifp) +epstart_locked(struct ifnet *ifp) { struct ep_softc *sc; u_int len; @@ -485,8 +486,8 @@ epstart_body(struct ifnet *ifp) sc = ifp->if_softc; if (sc->gone) return; - - EP_BUSY_WAIT; + EP_ASSERT_LOCKED(sc); + EP_BUSY_WAIT(sc); if (ifp->if_flags & IFF_OACTIVE) return; startagain: @@ -617,7 +618,7 @@ ep_intr(void *arg) ifp->if_flags &= ~IFF_OACTIVE; GO_WINDOW(1); CSR_READ_2(sc, EP_W1_FREE_TX); - epstart_body(ifp); + epstart_locked(ifp); } if (status & S_CARD_FAILURE) { ifp->if_timer = 0; @@ -642,7 +643,7 @@ ep_intr(void *arg) #endif #endif - epinit_body(sc); + epinit_locked(sc); EP_UNLOCK(sc); return; } @@ -690,7 +691,7 @@ ep_intr(void *arg) ifp->if_flags &= ~IFF_OACTIVE; GO_WINDOW(1); CSR_READ_2(sc, EP_W1_FREE_TX); - epstart_body(ifp); + epstart_locked(ifp); } /* end TX_COMPLETE */ } @@ -835,7 +836,7 @@ epread(struct ep_softc *sc) (*ifp->if_input) (ifp, top); EP_LOCK(sc); sc->top = 0; - EP_BUSY_WAIT; + EP_BUSY_WAIT(sc); CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH); return; @@ -849,7 +850,7 @@ epread(struct ep_softc *sc) #endif } EP_FSET(sc, F_RX_FIRST); - EP_BUSY_WAIT; + EP_BUSY_WAIT(sc); CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH); } @@ -921,7 +922,7 @@ epioctl(struct ifnet *ifp, u_long cmd, caddr_t data) epstop(sc); } else /* reinitialize card on any parameter change */ - epinit_body(sc); + epinit_locked(sc); EP_UNLOCK(sc); break; #ifdef notdef @@ -974,16 +975,16 @@ epstop(struct ep_softc *sc) return; CSR_WRITE_2(sc, EP_COMMAND, RX_DISABLE); CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK); - EP_BUSY_WAIT; + EP_BUSY_WAIT(sc); CSR_WRITE_2(sc, EP_COMMAND, TX_DISABLE); CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER); DELAY(800); CSR_WRITE_2(sc, EP_COMMAND, RX_RESET); - EP_BUSY_WAIT; + EP_BUSY_WAIT(sc); CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); - EP_BUSY_WAIT; + EP_BUSY_WAIT(sc); CSR_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH); CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK); diff --git a/sys/dev/ep/if_ep_pccard.c b/sys/dev/ep/if_ep_pccard.c index 67efa1b2c6ed..4b9cefb50cce 100644 --- a/sys/dev/ep/if_ep_pccard.c +++ b/sys/dev/ep/if_ep_pccard.c @@ -224,7 +224,7 @@ ep_pccard_attach(device_t dev) CSR_WRITE_2(sc, EP_W3_OPTIONS, 0xc040); CSR_WRITE_2(sc, EP_COMMAND, RX_RESET); CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); - EP_BUSY_WAIT; + EP_BUSY_WAIT(sc); DELAY(1000); CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); } else diff --git a/sys/dev/ep/if_epreg.h b/sys/dev/ep/if_epreg.h index 3a5fb8bfdc7e..1944f78cb36e 100644 --- a/sys/dev/ep/if_epreg.h +++ b/sys/dev/ep/if_epreg.h @@ -308,7 +308,7 @@ S_TX_AVAIL|S_RX_COMPLETE|S_RX_EARLY) #define S_COMMAND_IN_PROGRESS (u_short) (0x1000) -#define EP_BUSY_WAIT while (CSR_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS) +#define EP_BUSY_WAIT(sc) while (CSR_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS) /* Address Config. Register. * Window 0/Port 06 diff --git a/sys/dev/ep/if_epvar.h b/sys/dev/ep/if_epvar.h index ec4161671e15..242ccd46569d 100644 --- a/sys/dev/ep/if_epvar.h +++ b/sys/dev/ep/if_epvar.h @@ -103,3 +103,9 @@ int ep_get_macaddr(struct ep_softc *, u_char *); #define EP_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) #define EP_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) +#define EP_LOCK_INIT(_sc) \ + mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->dev), \ + MTX_NETWORK_LOCK, MTX_DEF) +#define EP_LOCK_DESTORY(_sc) mtx_destroy(&_sc->sc_mtx); +#define EP_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED); +#define EP_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);