1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

Minor style nits suggested by sam and mdodd:

o give an argument to EP_BUSY_WAIT
o use foo_locked rather than foo_body
o Add locking assertions for extra safety.
This commit is contained in:
Warner Losh 2003-10-25 21:28:40 +00:00
parent 470de03fd0
commit 1e56655e43
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=121515
4 changed files with 33 additions and 26 deletions

View File

@ -95,8 +95,8 @@ static int epioctl(struct ifnet *, u_long, caddr_t);
static void epstart(struct ifnet *); static void epstart(struct ifnet *);
static void epwatchdog(struct ifnet *); static void epwatchdog(struct ifnet *);
static void epstart_body(struct ifnet *); static void epstart_locked(struct ifnet *);
static void epinit_body(struct ep_softc *); static void epinit_locked(struct ep_softc *);
/* if_media functions */ /* if_media functions */
static int ep_ifmedia_upd(struct ifnet *); static int ep_ifmedia_upd(struct ifnet *);
@ -270,12 +270,11 @@ ep_attach(struct ep_softc *sc)
int error; int error;
sc->gone = 0; sc->gone = 0;
mtx_init(&sc->sc_mtx, device_get_nameunit(sc->dev), MTX_NETWORK_LOCK, EP_LOCK_INIT(sc);
MTX_DEF);
error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
if (error) { if (error) {
device_printf(sc->dev, "Unable to get Ethernet address!\n"); device_printf(sc->dev, "Unable to get Ethernet address!\n");
mtx_destroy(&sc->sc_mtx); EP_LOCK_DESTORY(sc);
return (ENXIO); return (ENXIO);
} }
/* /*
@ -349,6 +348,7 @@ ep_detach(device_t dev)
struct ifnet *ifp; struct ifnet *ifp;
sc = device_get_softc(dev); sc = device_get_softc(dev);
EP_ASSERT_UNLOCKED(sc);
ifp = &sc->arpcom.ac_if; ifp = &sc->arpcom.ac_if;
if (sc->gone) { if (sc->gone) {
@ -363,7 +363,7 @@ ep_detach(device_t dev)
sc->gone = 1; sc->gone = 1;
ep_free(dev); ep_free(dev);
mtx_destroy(&sc->sc_mtx); EP_LOCK_DESTORY(sc);
return (0); return (0);
} }
@ -373,7 +373,7 @@ epinit(void *xsc)
{ {
struct ep_softc *sc = xsc; struct ep_softc *sc = xsc;
EP_LOCK(sc); EP_LOCK(sc);
epinit_body(sc); epinit_locked(sc);
EP_UNLOCK(sc); EP_UNLOCK(sc);
} }
@ -382,7 +382,7 @@ epinit(void *xsc)
* interrupts. ?! * interrupts. ?!
*/ */
static void static void
epinit_body(struct ep_softc *sc) epinit_locked(struct ep_softc *sc)
{ {
struct ifnet *ifp = &sc->arpcom.ac_if; struct ifnet *ifp = &sc->arpcom.ac_if;
int i; int i;
@ -390,7 +390,8 @@ epinit_body(struct ep_softc *sc)
if (sc->gone) if (sc->gone)
return; return;
EP_BUSY_WAIT; EP_ASSERT_LOCKED(sc);
EP_BUSY_WAIT(sc);
GO_WINDOW(0); GO_WINDOW(0);
CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER); 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, RX_RESET);
CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
EP_BUSY_WAIT; EP_BUSY_WAIT(sc);
/* Window 1 is operating window */ /* Window 1 is operating window */
GO_WINDOW(1); GO_WINDOW(1);
@ -461,7 +462,7 @@ epinit_body(struct ep_softc *sc)
*/ */
GO_WINDOW(1); GO_WINDOW(1);
epstart_body(ifp); epstart_locked(ifp);
} }
static void static void
@ -470,12 +471,12 @@ epstart(struct ifnet *ifp)
struct ep_softc *sc; struct ep_softc *sc;
sc = ifp->if_softc; sc = ifp->if_softc;
EP_LOCK(sc); EP_LOCK(sc);
epstart_body(ifp); epstart_locked(ifp);
EP_UNLOCK(sc); EP_UNLOCK(sc);
} }
static void static void
epstart_body(struct ifnet *ifp) epstart_locked(struct ifnet *ifp)
{ {
struct ep_softc *sc; struct ep_softc *sc;
u_int len; u_int len;
@ -485,8 +486,8 @@ epstart_body(struct ifnet *ifp)
sc = ifp->if_softc; sc = ifp->if_softc;
if (sc->gone) if (sc->gone)
return; return;
EP_ASSERT_LOCKED(sc);
EP_BUSY_WAIT; EP_BUSY_WAIT(sc);
if (ifp->if_flags & IFF_OACTIVE) if (ifp->if_flags & IFF_OACTIVE)
return; return;
startagain: startagain:
@ -617,7 +618,7 @@ ep_intr(void *arg)
ifp->if_flags &= ~IFF_OACTIVE; ifp->if_flags &= ~IFF_OACTIVE;
GO_WINDOW(1); GO_WINDOW(1);
CSR_READ_2(sc, EP_W1_FREE_TX); CSR_READ_2(sc, EP_W1_FREE_TX);
epstart_body(ifp); epstart_locked(ifp);
} }
if (status & S_CARD_FAILURE) { if (status & S_CARD_FAILURE) {
ifp->if_timer = 0; ifp->if_timer = 0;
@ -642,7 +643,7 @@ ep_intr(void *arg)
#endif #endif
#endif #endif
epinit_body(sc); epinit_locked(sc);
EP_UNLOCK(sc); EP_UNLOCK(sc);
return; return;
} }
@ -690,7 +691,7 @@ ep_intr(void *arg)
ifp->if_flags &= ~IFF_OACTIVE; ifp->if_flags &= ~IFF_OACTIVE;
GO_WINDOW(1); GO_WINDOW(1);
CSR_READ_2(sc, EP_W1_FREE_TX); CSR_READ_2(sc, EP_W1_FREE_TX);
epstart_body(ifp); epstart_locked(ifp);
} /* end TX_COMPLETE */ } /* end TX_COMPLETE */
} }
@ -835,7 +836,7 @@ epread(struct ep_softc *sc)
(*ifp->if_input) (ifp, top); (*ifp->if_input) (ifp, top);
EP_LOCK(sc); EP_LOCK(sc);
sc->top = 0; sc->top = 0;
EP_BUSY_WAIT; EP_BUSY_WAIT(sc);
CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH); CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
return; return;
@ -849,7 +850,7 @@ epread(struct ep_softc *sc)
#endif #endif
} }
EP_FSET(sc, F_RX_FIRST); 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); 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); epstop(sc);
} else } else
/* reinitialize card on any parameter change */ /* reinitialize card on any parameter change */
epinit_body(sc); epinit_locked(sc);
EP_UNLOCK(sc); EP_UNLOCK(sc);
break; break;
#ifdef notdef #ifdef notdef
@ -974,16 +975,16 @@ epstop(struct ep_softc *sc)
return; return;
CSR_WRITE_2(sc, EP_COMMAND, RX_DISABLE); CSR_WRITE_2(sc, EP_COMMAND, RX_DISABLE);
CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK); 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, TX_DISABLE);
CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER); CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
DELAY(800); DELAY(800);
CSR_WRITE_2(sc, EP_COMMAND, RX_RESET); CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
EP_BUSY_WAIT; EP_BUSY_WAIT(sc);
CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); 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, C_INTR_LATCH);
CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK); CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK);

View File

@ -224,7 +224,7 @@ ep_pccard_attach(device_t dev)
CSR_WRITE_2(sc, EP_W3_OPTIONS, 0xc040); CSR_WRITE_2(sc, EP_W3_OPTIONS, 0xc040);
CSR_WRITE_2(sc, EP_COMMAND, RX_RESET); CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
EP_BUSY_WAIT; EP_BUSY_WAIT(sc);
DELAY(1000); DELAY(1000);
CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040);
} else } else

View File

@ -308,7 +308,7 @@
S_TX_AVAIL|S_RX_COMPLETE|S_RX_EARLY) S_TX_AVAIL|S_RX_COMPLETE|S_RX_EARLY)
#define S_COMMAND_IN_PROGRESS (u_short) (0x1000) #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. /* Address Config. Register.
* Window 0/Port 06 * Window 0/Port 06

View File

@ -103,3 +103,9 @@ int ep_get_macaddr(struct ep_softc *, u_char *);
#define EP_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) #define EP_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
#define EP_UNLOCK(_sc) mtx_unlock(&(_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);