From d8235d53ee96a253ee790b20c34f899a5fc717fb Mon Sep 17 00:00:00 2001 From: Joe Talbott Date: Wed, 8 Sep 2010 23:30:00 -0400 Subject: [PATCH] wlan - Bring ral back into the fold. *** NB *** This has not been tested other than that it compiles (due to lack of hardware) but will be tested within the week. --- sys/dev/netif/ral/if_ral_pci.c | 23 +++++++++++++-- sys/dev/netif/ral/rt2560.c | 51 ++++---------------------------- sys/dev/netif/ral/rt2560var.h | 6 ---- sys/dev/netif/ral/rt2661.c | 54 ++++------------------------------ sys/dev/netif/ral/rt2661var.h | 6 ---- 5 files changed, 33 insertions(+), 107 deletions(-) diff --git a/sys/dev/netif/ral/if_ral_pci.c b/sys/dev/netif/ral/if_ral_pci.c index c94fad7c14..50b594456a 100644 --- a/sys/dev/netif/ral/if_ral_pci.c +++ b/sys/dev/netif/ral/if_ral_pci.c @@ -146,13 +146,17 @@ ral_pci_probe(device_t dev) { const struct ral_pci_ident *ident; + wlan_serialize_enter(); + for (ident = ral_pci_ids; ident->name != NULL; ident++) { if (pci_get_vendor(dev) == ident->vendor && pci_get_device(dev) == ident->device) { device_set_desc(dev, ident->name); + wlan_serialize_exit(); return 0; } } + wlan_serialize_exit(); return ENXIO; } @@ -167,6 +171,7 @@ ral_pci_attach(device_t dev) struct ifnet *ifp; int error; + wlan_serialize_enter(); if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { device_printf(dev, "chip is in D%d power mode " "-- setting to D0\n", pci_get_powerstate(dev)); @@ -184,6 +189,7 @@ ral_pci_attach(device_t dev) RF_ACTIVE); if (psc->mem == NULL) { device_printf(dev, "could not allocate memory resource\n"); + wlan_serialize_exit(); return ENXIO; } @@ -196,25 +202,30 @@ ral_pci_attach(device_t dev) RF_ACTIVE | RF_SHAREABLE); if (psc->irq == NULL) { device_printf(dev, "could not allocate interrupt resource\n"); + wlan_serialize_exit(); return ENXIO; } error = (*psc->sc_opns->attach)(dev, pci_get_device(dev)); - if (error != 0) + if (error != 0) { + wlan_serialize_exit(); return error; + } ifp = sc->sc_ifp; /* * Hook our interrupt after all initialization is complete. */ error = bus_setup_intr(dev, psc->irq, INTR_MPSAFE, - psc->sc_opns->intr, psc, &psc->sc_ih, ifp->if_serializer); + psc->sc_opns->intr, psc, &psc->sc_ih, &wlan_global_serializer); if (error != 0) { device_printf(dev, "could not set up interrupt\n"); + wlan_serialize_exit(); return error; } sc->sc_invalid = 0; + wlan_serialize_exit(); return 0; } @@ -224,6 +235,7 @@ ral_pci_detach(device_t dev) struct ral_pci_softc *psc = device_get_softc(dev); struct rt2560_softc *sc = &psc->u.sc_rt2560; + wlan_serialize_enter(); /* check if device was removed */ sc->sc_invalid = !bus_child_present(dev); @@ -235,6 +247,7 @@ ral_pci_detach(device_t dev) bus_release_resource(dev, SYS_RES_MEMORY, psc->mem_rid, psc->mem); + wlan_serialize_exit(); return 0; } @@ -243,7 +256,9 @@ ral_pci_shutdown(device_t dev) { struct ral_pci_softc *psc = device_get_softc(dev); + wlan_serialize_enter(); (*psc->sc_opns->shutdown)(psc); + wlan_serialize_exit(); return 0; } @@ -253,7 +268,9 @@ ral_pci_suspend(device_t dev) { struct ral_pci_softc *psc = device_get_softc(dev); + wlan_serialize_enter(); (*psc->sc_opns->suspend)(psc); + wlan_serialize_exit(); return 0; } @@ -263,7 +280,9 @@ ral_pci_resume(device_t dev) { struct ral_pci_softc *psc = device_get_softc(dev); + wlan_serialize_enter(); (*psc->sc_opns->resume)(psc); + wlan_serialize_exit(); return 0; } diff --git a/sys/dev/netif/ral/rt2560.c b/sys/dev/netif/ral/rt2560.c index cd299c1ddf..08d66246b4 100644 --- a/sys/dev/netif/ral/rt2560.c +++ b/sys/dev/netif/ral/rt2560.c @@ -127,7 +127,7 @@ static int rt2560_tx_data(struct rt2560_softc *, struct mbuf *, struct ieee80211_node *); static void rt2560_start_locked(struct ifnet *); static void rt2560_start(struct ifnet *); -static void rt2560_watchdog(void *); +static void rt2560_watchdog_callout(void *); static int rt2560_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); static void rt2560_bbp_write(struct rt2560_softc *, uint8_t, @@ -205,9 +205,6 @@ rt2560_attach(device_t dev, int id) sc->sc_dev = dev; - lockinit(&sc->sc_lock, __DECONST(char *, device_get_nameunit(dev)), - 0, LK_CANRECURSE); - callout_init(&sc->watchdog_ch); /* retrieve RT2560 rev. no */ @@ -351,7 +348,7 @@ fail5: rt2560_free_tx_ring(sc, &sc->bcnq); fail4: rt2560_free_tx_ring(sc, &sc->prioq); fail3: rt2560_free_tx_ring(sc, &sc->atimq); fail2: rt2560_free_tx_ring(sc, &sc->txq); -fail1: lockuninit(&sc->sc_lock); +fail1: return ENXIO; } @@ -375,8 +372,6 @@ rt2560_detach(void *xsc) if_free(ifp); - lockuninit(&sc->sc_lock); - return 0; } @@ -1232,7 +1227,6 @@ rt2560_decryption_intr(struct rt2560_softc *sc) } sc->sc_flags |= RT2560_F_INPUT_RUNNING; - RAL_UNLOCK(); wh = mtod(m, struct ieee80211_frame *); ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh); @@ -1242,7 +1236,6 @@ rt2560_decryption_intr(struct rt2560_softc *sc) } else (void) ieee80211_input_all(ic, m, rssi, nf); - RAL_LOCK(); sc->sc_flags &= ~RT2560_F_INPUT_RUNNING; skip: desc->flags = htole32(RT2560_RX_BUSY); @@ -1371,14 +1364,11 @@ rt2560_intr(void *arg) struct ifnet *ifp = sc->sc_ifp; uint32_t r; - RAL_LOCK(); - /* disable interrupts */ RAL_WRITE(sc, RT2560_CSR8, 0xffffffff); /* don't re-enable interrupts if we're shutting down */ if (!(ifp->if_flags & IFF_RUNNING)) { - RAL_UNLOCK(); return; } @@ -1410,8 +1400,6 @@ rt2560_intr(void *arg) /* re-enable interrupts */ RAL_WRITE(sc, RT2560_CSR8, RT2560_INTR_MASK); - - RAL_UNLOCK(); } #define RAL_SIFS 10 /* us */ @@ -1928,8 +1916,6 @@ rt2560_start_locked(struct ifnet *ifp) struct mbuf *m; struct ieee80211_node *ni; - RAL_LOCK_ASSERT(); - for (;;) { IF_DEQUEUE(&ifp->if_snd, m); if (m == NULL) @@ -1954,19 +1940,15 @@ rt2560_start_locked(struct ifnet *ifp) static void rt2560_start(struct ifnet *ifp) { - RAL_LOCK(); rt2560_start_locked(ifp); - RAL_UNLOCK(); } static void -rt2560_watchdog(void *arg) +rt2560_watchdog_callout(void *arg) { struct rt2560_softc *sc = arg; struct ifnet *ifp = sc->sc_ifp; - RAL_LOCK(); - KASSERT(ifp->if_flags & IFF_RUNNING, ("not running")); if (sc->sc_invalid) /* card ejected */ @@ -1982,8 +1964,7 @@ rt2560_watchdog(void *arg) /* NB: callout is reset in rt2560_init() */ return; } - callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); - RAL_UNLOCK(); + callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog_callout, sc); } static int @@ -1996,7 +1977,6 @@ rt2560_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *ucred) switch (cmd) { case SIOCSIFFLAGS: - RAL_LOCK(); if (ifp->if_flags & IFF_UP) { if ((ifp->if_flags & IFF_RUNNING) == 0) { rt2560_init_locked(sc); @@ -2007,7 +1987,6 @@ rt2560_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *ucred) if (ifp->if_flags & IFF_RUNNING) rt2560_stop_locked(sc); } - RAL_UNLOCK(); if (startall) ieee80211_start_all(ic); break; @@ -2208,9 +2187,7 @@ rt2560_set_channel(struct ieee80211com *ic) struct ifnet *ifp = ic->ic_ifp; struct rt2560_softc *sc = ifp->if_softc; - RAL_LOCK(); rt2560_set_chan(sc, ic->ic_curchan); - RAL_UNLOCK(); } @@ -2625,8 +2602,6 @@ rt2560_init_locked(struct rt2560_softc *sc) uint32_t tmp; int i; - RAL_LOCK_ASSERT(); - rt2560_stop_locked(sc); /* setup tx rings */ @@ -2666,7 +2641,6 @@ rt2560_init_locked(struct rt2560_softc *sc) if (rt2560_bbp_init(sc) != 0) { rt2560_stop(sc); - RAL_UNLOCK(); return; } @@ -2701,7 +2675,7 @@ rt2560_init_locked(struct rt2560_softc *sc) ifp->if_flags &= ~IFF_OACTIVE; ifp->if_flags |= IFF_RUNNING; - callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); + callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog_callout, sc); #undef N } @@ -2712,9 +2686,7 @@ rt2560_init(void *priv) struct ifnet *ifp = sc->sc_ifp; struct ieee80211com *ic = ifp->if_l2com; - RAL_LOCK(); rt2560_init_locked(sc); - RAL_UNLOCK(); if (ifp->if_flags & IFF_RUNNING) ieee80211_start_all(ic); /* start all vap's */ @@ -2726,10 +2698,8 @@ rt2560_stop_locked(struct rt2560_softc *sc) struct ifnet *ifp = sc->sc_ifp; volatile int *flags = &sc->sc_flags; - RAL_LOCK_ASSERT(); - while (*flags & RT2560_F_INPUT_RUNNING) - lksleep(sc, &sc->sc_lock, 0, "ralrunning", hz/10); + zsleep(sc, &wlan_global_serializer, 0, "ralrunning", hz/10); callout_stop(&sc->watchdog_ch); sc->sc_tx_timer = 0; @@ -2765,9 +2735,7 @@ rt2560_stop(void *arg) { struct rt2560_softc *sc = arg; - RAL_LOCK(); rt2560_stop_locked(sc); - RAL_UNLOCK(); } static int @@ -2778,11 +2746,8 @@ rt2560_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, struct ifnet *ifp = ic->ic_ifp; struct rt2560_softc *sc = ifp->if_softc; - RAL_LOCK(); - /* prevent management frames from being sent if we're not ready */ if (!(ifp->if_flags & IFF_RUNNING)) { - RAL_UNLOCK(); m_freem(m); ieee80211_free_node(ni); return ENETDOWN; @@ -2790,7 +2755,6 @@ rt2560_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, if (sc->prioq.queued >= RT2560_PRIO_RING_COUNT) { ifp->if_flags |= IFF_OACTIVE; sc->sc_flags |= RT2560_F_PRIO_OACTIVE; - RAL_UNLOCK(); m_freem(m); ieee80211_free_node(ni); return ENOBUFS; /* XXX */ @@ -2815,12 +2779,9 @@ rt2560_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, } sc->sc_tx_timer = 5; - RAL_UNLOCK(); - return 0; bad: ifp->if_oerrors++; ieee80211_free_node(ni); - RAL_UNLOCK(); return EIO; /* XXX */ } diff --git a/sys/dev/netif/ral/rt2560var.h b/sys/dev/netif/ral/rt2560var.h index 063660303d..48fcf640d6 100644 --- a/sys/dev/netif/ral/rt2560var.h +++ b/sys/dev/netif/ral/rt2560var.h @@ -111,8 +111,6 @@ struct rt2560_softc { bus_space_tag_t sc_st; bus_space_handle_t sc_sh; - struct lock sc_lock; - struct callout watchdog_ch; int sc_tx_timer; @@ -165,7 +163,3 @@ int rt2560_detach(void *); void rt2560_stop(void *); void rt2560_resume(void *); void rt2560_intr(void *); - -#define RAL_LOCK() lwkt_gettoken(&wlan_token) -#define RAL_LOCK_ASSERT() ASSERT_LWKT_TOKEN_HELD(&wlan_token) -#define RAL_UNLOCK() lwkt_reltoken(&wlan_token) diff --git a/sys/dev/netif/ral/rt2661.c b/sys/dev/netif/ral/rt2661.c index 3288566681..797a303faa 100644 --- a/sys/dev/netif/ral/rt2661.c +++ b/sys/dev/netif/ral/rt2661.c @@ -123,7 +123,7 @@ static void rt2661_start_locked(struct ifnet *); static void rt2661_start(struct ifnet *); static int rt2661_raw_xmit(struct ieee80211_node *, struct mbuf *, const struct ieee80211_bpf_params *); -static void rt2661_watchdog(void *); +static void rt2661_watchdog_callout(void *); static int rt2661_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); static void rt2661_bbp_write(struct rt2661_softc *, uint8_t, @@ -215,9 +215,6 @@ rt2661_attach(device_t dev, int id) } ic = ifp->if_l2com; - lockinit(&sc->sc_lock, __DECONST(char *, device_get_nameunit(dev)), - 0, LK_CANRECURSE); - callout_init(&sc->watchdog_ch); /* wait for NIC to initialize */ @@ -346,7 +343,7 @@ rt2661_attach(device_t dev, int id) fail3: rt2661_free_tx_ring(sc, &sc->mgtq); fail2: while (--ac >= 0) rt2661_free_tx_ring(sc, &sc->txq[ac]); -fail1: lockuninit(&sc->sc_lock); +fail1: if_free(ifp); return error; } @@ -358,9 +355,7 @@ rt2661_detach(void *xsc) struct ifnet *ifp = sc->sc_ifp; struct ieee80211com *ic = ifp->if_l2com; - RAL_LOCK(); rt2661_stop_locked(sc); - RAL_UNLOCK(); ieee80211_ifdetach(ic); @@ -373,8 +368,6 @@ rt2661_detach(void *xsc) if_free(ifp); - lockuninit(&sc->sc_lock); - return 0; } @@ -1115,7 +1108,6 @@ rt2661_rx_intr(struct rt2661_softc *sc) tap->wr_antnoise = nf; } sc->sc_flags |= RAL_INPUT_RUNNING; - RAL_UNLOCK(); wh = mtod(m, struct ieee80211_frame *); /* send the frame to the 802.11 layer */ @@ -1127,7 +1119,6 @@ rt2661_rx_intr(struct rt2661_softc *sc) } else (void) ieee80211_input_all(ic, m, rssi, nf); - RAL_LOCK(); sc->sc_flags &= ~RAL_INPUT_RUNNING; skip: desc->flags |= htole32(RT2661_RX_BUSY); @@ -1175,15 +1166,12 @@ rt2661_intr(void *arg) struct ifnet *ifp = sc->sc_ifp; uint32_t r1, r2; - RAL_LOCK(); - /* disable MAC and MCU interrupts */ RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0xffffff7f); RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff); /* don't re-enable interrupts if we're shutting down */ if (!(ifp->if_flags & IFF_RUNNING)) { - RAL_UNLOCK(); return; } @@ -1227,7 +1215,6 @@ rt2661_intr(void *arg) RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0x0000ff10); RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0); - RAL_UNLOCK(); } static uint8_t @@ -1628,8 +1615,6 @@ rt2661_start_locked(struct ifnet *ifp) struct ieee80211_node *ni; int ac; - RAL_LOCK_ASSERT(); - /* prevent management frames from being sent if we're not ready */ if (!(ifp->if_flags & IFF_RUNNING) || sc->sc_invalid) return; @@ -1660,9 +1645,7 @@ rt2661_start_locked(struct ifnet *ifp) static void rt2661_start(struct ifnet *ifp) { - RAL_LOCK(); rt2661_start_locked(ifp); - RAL_UNLOCK(); } static int @@ -1673,18 +1656,14 @@ rt2661_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, struct ifnet *ifp = ic->ic_ifp; struct rt2661_softc *sc = ifp->if_softc; - RAL_LOCK(); - /* prevent management frames from being sent if we're not ready */ if (!(ifp->if_flags & IFF_RUNNING)) { - RAL_UNLOCK(); m_freem(m); ieee80211_free_node(ni); return ENETDOWN; } if (sc->mgtq.queued >= RT2661_MGT_RING_COUNT) { ifp->if_flags |= IFF_OACTIVE; - RAL_UNLOCK(); m_freem(m); ieee80211_free_node(ni); return ENOBUFS; /* XXX */ @@ -1701,24 +1680,19 @@ rt2661_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, goto bad; sc->sc_tx_timer = 5; - RAL_UNLOCK(); - return 0; bad: ifp->if_oerrors++; ieee80211_free_node(ni); - RAL_UNLOCK(); return EIO; /* XXX */ } static void -rt2661_watchdog(void *arg) +rt2661_watchdog_callout(void *arg) { struct rt2661_softc *sc = (struct rt2661_softc *)arg; struct ifnet *ifp = sc->sc_ifp; - RAL_LOCK(); - KASSERT(ifp->if_flags & IFF_RUNNING, ("not running")); if (sc->sc_invalid) /* card ejected */ @@ -1731,9 +1705,8 @@ rt2661_watchdog(void *arg) /* NB: callout is reset in rt2661_init() */ return; } - callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); + callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog_callout, sc); - RAL_UNLOCK(); } static int @@ -1746,7 +1719,6 @@ rt2661_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *ucred) switch (cmd) { case SIOCSIFFLAGS: - RAL_LOCK(); if (ifp->if_flags & IFF_UP) { if ((ifp->if_flags & IFF_RUNNING) == 0) { rt2661_init_locked(sc); @@ -1757,7 +1729,6 @@ rt2661_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *ucred) if (ifp->if_flags & IFF_RUNNING) rt2661_stop_locked(sc); } - RAL_UNLOCK(); if (startall) ieee80211_start_all(ic); break; @@ -2329,8 +2300,6 @@ rt2661_init_locked(struct rt2661_softc *sc) uint32_t tmp, sta[3]; int i, error, ntries; - RAL_LOCK_ASSERT(); - if ((sc->sc_flags & RAL_FW_LOADED) == 0) { error = rt2661_load_microcode(sc); if (error != 0) { @@ -2451,7 +2420,7 @@ rt2661_init_locked(struct rt2661_softc *sc) ifp->if_flags &= ~IFF_OACTIVE; ifp->if_flags |= IFF_RUNNING; - callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); + callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog_callout, sc); #undef N } @@ -2462,9 +2431,7 @@ rt2661_init(void *priv) struct ifnet *ifp = sc->sc_ifp; struct ieee80211com *ic = ifp->if_l2com; - RAL_LOCK(); rt2661_init_locked(sc); - RAL_UNLOCK(); if (ifp->if_flags & IFF_RUNNING) ieee80211_start_all(ic); /* start all vap's */ @@ -2478,7 +2445,7 @@ rt2661_stop_locked(struct rt2661_softc *sc) volatile int *flags = &sc->sc_flags; while (*flags & RAL_INPUT_RUNNING) - lksleep(sc, &sc->sc_lock, 0, "ralrunning", hz/10); + zsleep(sc, &wlan_global_serializer, 0, "ralrunning", hz/10); callout_stop(&sc->watchdog_ch); sc->sc_tx_timer = 0; @@ -2520,9 +2487,7 @@ rt2661_stop(void *priv) { struct rt2661_softc *sc = priv; - RAL_LOCK(); rt2661_stop_locked(sc); - RAL_UNLOCK(); } static int @@ -2533,8 +2498,6 @@ rt2661_load_microcode(struct rt2661_softc *sc) const char *imagename; int ntries, error; - RAL_LOCK_ASSERT(); - switch (sc->sc_id) { case 0x0301: imagename = "rt2561sfw"; break; case 0x0302: imagename = "rt2561fw"; break; @@ -2545,9 +2508,7 @@ rt2661_load_microcode(struct rt2661_softc *sc) __func__, sc->sc_id); return EINVAL; } - RAL_UNLOCK(); fp = firmware_get(imagename); - RAL_LOCK(); if (fp == NULL) { if_printf(ifp, "%s: unable to retrieve firmware image %s\n", __func__, imagename); @@ -2862,8 +2823,5 @@ rt2661_set_channel(struct ieee80211com *ic) struct ifnet *ifp = ic->ic_ifp; struct rt2661_softc *sc = ifp->if_softc; - RAL_LOCK(); rt2661_set_chan(sc, ic->ic_curchan); - RAL_UNLOCK(); - } diff --git a/sys/dev/netif/ral/rt2661var.h b/sys/dev/netif/ral/rt2661var.h index 49532ea9b0..3006ee0792 100644 --- a/sys/dev/netif/ral/rt2661var.h +++ b/sys/dev/netif/ral/rt2661var.h @@ -103,8 +103,6 @@ struct rt2661_softc { bus_space_tag_t sc_st; bus_space_handle_t sc_sh; - struct lock sc_lock; - struct callout watchdog_ch; int sc_tx_timer; @@ -170,7 +168,3 @@ void rt2661_shutdown(void *); void rt2661_suspend(void *); void rt2661_resume(void *); void rt2661_intr(void *); - -#define RAL_LOCK() lwkt_gettoken(&wlan_token) -#define RAL_LOCK_ASSERT() ASSERT_LWKT_TOKEN_HELD(&wlan_token) -#define RAL_UNLOCK() lwkt_reltoken(&wlan_token) -- 2.41.0