ath - Basic re-port, base code compile
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 2 Jan 2014 01:31:41 +0000 (17:31 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 2 Jan 2014 07:15:38 +0000 (23:15 -0800)
* First re-port pass, make base code modifications to work with DragonFly.

* Remove ath locks (mostly using #define's).

* Protect entry points with our global wlan_serializer.  This includes:
- callout functions
- PCI entry/exit
- ifnet access (typically already protected from the DFly kernel).
- taskqueue functions
- sysctl functions

* Rework the sysctl hierarchy a little.

* Fixup malloc->kmalloc, free->kfree, snprintf->ksnprintf.
* Fixup ether_sprintf() use cases.

* Fixup bad M_NOWAIT semantics from FreeBSD.  Convert all such to
  M_INTWAIT.

* IFF_RUNNING and IFF_OACTIVE adjustments.

* Temporarily #if 0 out code that our wlan infrastructure does not
  yet support.

* Add appropriate DRIVER and MODULE declarations for module handling.

* #include path adjustments

* API differences in bus_dma_tag_create(), bus_dmamap_load_mbuf_sg(),
  and related interactions.

* Several TAILQ_FOREACH_SAFE() interactions were broken (pushed to Adrian).

* Revert field name for now (tap->txa_tid -> tap_txa_ac).  We need to fixup
  our wlan infrastructure to rename txa_ac to txa_tid.

* va_list/va_start/va_end -> __va_list/__va_start/__va_end.

36 files changed:
sys/dev/netif/ath/Makefile
sys/dev/netif/ath/ath/if_ath.c
sys/dev/netif/ath/ath/if_ath_ahb.c
sys/dev/netif/ath/ath/if_ath_alq.c
sys/dev/netif/ath/ath/if_ath_beacon.c
sys/dev/netif/ath/ath/if_ath_btcoex.c
sys/dev/netif/ath/ath/if_ath_debug.c
sys/dev/netif/ath/ath/if_ath_keycache.c
sys/dev/netif/ath/ath/if_ath_led.c
sys/dev/netif/ath/ath/if_ath_lna_div.c
sys/dev/netif/ath/ath/if_ath_pci.c
sys/dev/netif/ath/ath/if_ath_rx.c
sys/dev/netif/ath/ath/if_ath_rx_edma.c
sys/dev/netif/ath/ath/if_ath_spectral.c
sys/dev/netif/ath/ath/if_ath_sysctl.c
sys/dev/netif/ath/ath/if_ath_tx.c
sys/dev/netif/ath/ath/if_ath_tx_edma.c
sys/dev/netif/ath/ath/if_athvar.h
sys/dev/netif/ath/ath_dfs/null/Makefile
sys/dev/netif/ath/ath_dfs/null/dfs_null.c
sys/dev/netif/ath/ath_hal/Makefile
sys/dev/netif/ath/ath_hal/ah_osdep.c
sys/dev/netif/ath/ath_hal/ah_osdep.h
sys/dev/netif/ath/ath_hal/ar5312/ar5312_attach.c
sys/dev/netif/ath/ath_hal/ar71xx/ar71xx_cpudef.h [new file with mode: 0644]
sys/dev/netif/ath/ath_hal/ar71xx/ar71xxreg.h [new file with mode: 0644]
sys/dev/netif/ath/ath_hal/ar9002/ar9280_attach.c
sys/dev/netif/ath/ath_hal/ar9002/ar9280_olc.c
sys/dev/netif/ath/ath_hal/ar91xx/ar91xxreg.h [new file with mode: 0644]
sys/dev/netif/ath/ath_rate/amrr/Makefile
sys/dev/netif/ath/ath_rate/amrr/amrr.c
sys/dev/netif/ath/ath_rate/onoe/Makefile
sys/dev/netif/ath/ath_rate/onoe/onoe.c
sys/dev/netif/ath/ath_rate/sample/Makefile
sys/dev/netif/ath/ath_rate/sample/sample.c
sys/dev/netif/ath/ath_rate/sample/sample.h

index 25fed53..63b8110 100644 (file)
@@ -1,6 +1,6 @@
 #
 #
 
 #
 #
 
-SUBDIR= ath ath_dfs ath_hal ath_rate
+SUBDIR= ath ath_dfs ath_rate ath_hal
 
 .include <bsd.subdir.mk>
 
 .include <bsd.subdir.mk>
index 5580266..94bf072 100644 (file)
@@ -76,6 +76,7 @@
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
+#include <net/ifq_var.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
  */
 #define        ATH_SW_PSQ
 
  */
 #define        ATH_SW_PSQ
 
+#ifdef __DragonFly__
+#define CURVNET_SET(name)
+#define CURVNET_RESTORE()
+#endif
+
 /*
  * ATH_BCBUF determines the number of vap's that can transmit
  * beacons and also (currently) the number of vap's that can
 /*
  * ATH_BCBUF determines the number of vap's that can transmit
  * beacons and also (currently) the number of vap's that can
@@ -151,11 +157,13 @@ static void       ath_init(void *);
 static void    ath_stop_locked(struct ifnet *);
 static void    ath_stop(struct ifnet *);
 static int     ath_reset_vap(struct ieee80211vap *, u_long);
 static void    ath_stop_locked(struct ifnet *);
 static void    ath_stop(struct ifnet *);
 static int     ath_reset_vap(struct ieee80211vap *, u_long);
+#if 0
 static int     ath_transmit(struct ifnet *ifp, struct mbuf *m);
 static void    ath_qflush(struct ifnet *ifp);
 static int     ath_transmit(struct ifnet *ifp, struct mbuf *m);
 static void    ath_qflush(struct ifnet *ifp);
+#endif
 static int     ath_media_change(struct ifnet *);
 static void    ath_watchdog(void *);
 static int     ath_media_change(struct ifnet *);
 static void    ath_watchdog(void *);
-static int     ath_ioctl(struct ifnet *, u_long, caddr_t);
+static int     ath_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
 static void    ath_fatal_proc(void *, int);
 static void    ath_bmiss_vap(struct ieee80211vap *);
 static void    ath_bmiss_proc(void *, int);
 static void    ath_fatal_proc(void *, int);
 static void    ath_bmiss_vap(struct ieee80211vap *);
 static void    ath_bmiss_proc(void *, int);
@@ -210,9 +218,11 @@ static void        ath_setcurmode(struct ath_softc *, enum ieee80211_phymode);
 static void    ath_announce(struct ath_softc *);
 
 static void    ath_dfs_tasklet(void *, int);
 static void    ath_announce(struct ath_softc *);
 
 static void    ath_dfs_tasklet(void *, int);
+#if 0
 static void    ath_node_powersave(struct ieee80211_node *, int);
 static void    ath_node_powersave(struct ieee80211_node *, int);
-static int     ath_node_set_tim(struct ieee80211_node *, int);
 static void    ath_node_recv_pspoll(struct ieee80211_node *, struct mbuf *);
 static void    ath_node_recv_pspoll(struct ieee80211_node *, struct mbuf *);
+#endif
+static int     ath_node_set_tim(struct ieee80211_node *, int);
 
 #ifdef IEEE80211_SUPPORT_TDMA
 #include <dev/netif/ath/ath/if_ath_tdma.h>
 
 #ifdef IEEE80211_SUPPORT_TDMA
 #include <dev/netif/ath/ath/if_ath_tdma.h>
@@ -308,6 +318,15 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
                device_get_unit(sc->sc_dev));
        CURVNET_RESTORE();
 
                device_get_unit(sc->sc_dev));
        CURVNET_RESTORE();
 
+       /* prepare sysctl tree for use in sub modules */
+       sysctl_ctx_init(&sc->sc_sysctl_ctx);
+       sc->sc_sysctl_tree = SYSCTL_ADD_NODE(&sc->sc_sysctl_ctx,
+               SYSCTL_STATIC_CHILDREN(_hw),
+               OID_AUTO,
+               device_get_nameunit(sc->sc_dev),
+               CTLFLAG_RD, 0, "");
+
+
        ah = ath_hal_attach(devid, sc, sc->sc_st, sc->sc_sh,
            sc->sc_eepromdata, &status);
        if (ah == NULL) {
        ah = ath_hal_attach(devid, sc, sc->sc_st, sc->sc_sh,
            sc->sc_eepromdata, &status);
        if (ah == NULL) {
@@ -397,7 +416,10 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
        /*
         * Allocate TX descriptors and populate the lists.
         */
        /*
         * Allocate TX descriptors and populate the lists.
         */
+       wlan_assert_serialized();
+       wlan_serialize_exit();
        error = ath_desc_alloc(sc);
        error = ath_desc_alloc(sc);
+       wlan_serialize_enter();
        if (error != 0) {
                if_printf(ifp, "failed to allocate TX descriptors: %d\n",
                    error);
        if (error != 0) {
                if_printf(ifp, "failed to allocate TX descriptors: %d\n",
                    error);
@@ -420,14 +442,14 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
                goto bad;
        }
 
                goto bad;
        }
 
-       callout_init_mtx(&sc->sc_cal_ch, &sc->sc_mtx, 0);
-       callout_init_mtx(&sc->sc_wd_ch, &sc->sc_mtx, 0);
+       callout_init_mp(&sc->sc_cal_ch);
+       callout_init_mp(&sc->sc_wd_ch);
 
        ATH_TXBUF_LOCK_INIT(sc);
 
        sc->sc_tq = taskqueue_create("ath_taskq", M_NOWAIT,
                taskqueue_thread_enqueue, &sc->sc_tq);
 
        ATH_TXBUF_LOCK_INIT(sc);
 
        sc->sc_tq = taskqueue_create("ath_taskq", M_NOWAIT,
                taskqueue_thread_enqueue, &sc->sc_tq);
-       taskqueue_start_threads(&sc->sc_tq, 1, PI_NET,
+       taskqueue_start_threads(&sc->sc_tq, 1, TDPRI_KERN_DAEMON, -1,
                "%s taskq", ifp->if_xname);
 
        TASK_INIT(&sc->sc_rxtask, 0, sc->sc_rx.recv_tasklet, sc);
                "%s taskq", ifp->if_xname);
 
        TASK_INIT(&sc->sc_rxtask, 0, sc->sc_rx.recv_tasklet, sc);
@@ -544,7 +566,7 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
        sc->sc_ledstate = 1;
        sc->sc_ledon = 0;                       /* low true */
        sc->sc_ledidle = (2700*hz)/1000;        /* 2.7sec */
        sc->sc_ledstate = 1;
        sc->sc_ledon = 0;                       /* low true */
        sc->sc_ledidle = (2700*hz)/1000;        /* 2.7sec */
-       callout_init(&sc->sc_ledtimer, CALLOUT_MPSAFE);
+       callout_init_mp(&sc->sc_ledtimer);
 
        /*
         * Don't setup hardware-based blinking.
 
        /*
         * Don't setup hardware-based blinking.
@@ -571,13 +593,17 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
 
        ifp->if_softc = sc;
        ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
 
        ifp->if_softc = sc;
        ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
+#if 0
        ifp->if_transmit = ath_transmit;
        ifp->if_qflush = ath_qflush;
        ifp->if_transmit = ath_transmit;
        ifp->if_qflush = ath_qflush;
+#endif
        ifp->if_ioctl = ath_ioctl;
        ifp->if_init = ath_init;
        ifp->if_ioctl = ath_ioctl;
        ifp->if_init = ath_init;
-       IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
+       ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
+#if 0
        ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
        IFQ_SET_READY(&ifp->if_snd);
        ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
        IFQ_SET_READY(&ifp->if_snd);
+#endif
 
        ic->ic_ifp = ifp;
        /* XXX not right but it's not used anywhere important */
 
        ic->ic_ifp = ifp;
        /* XXX not right but it's not used anywhere important */
@@ -867,7 +893,7 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
         * Check if the hardware requires PCI register serialisation.
         * Some of the Owl based MACs require this.
         */
         * Check if the hardware requires PCI register serialisation.
         * Some of the Owl based MACs require this.
         */
-       if (mp_ncpus > 1 &&
+       if (ncpus > 1 &&
            ath_hal_getcapability(ah, HAL_CAP_SERIALISE_WAR,
             0, NULL) == HAL_OK) {
                sc->sc_ah->ah_config.ah_serialise_reg_war = 1;
            ath_hal_getcapability(ah, HAL_CAP_SERIALISE_WAR,
             0, NULL) == HAL_OK) {
                sc->sc_ah->ah_config.ah_serialise_reg_war = 1;
@@ -1003,11 +1029,14 @@ bad:
        /*
         * To work around scoping issues with CURVNET_SET/CURVNET_RESTORE..
         */
        /*
         * To work around scoping issues with CURVNET_SET/CURVNET_RESTORE..
         */
+#if !defined(__DragonFly__)
        if (ifp != NULL && ifp->if_vnet) {
                CURVNET_SET(ifp->if_vnet);
                if_free(ifp);
                CURVNET_RESTORE();
        if (ifp != NULL && ifp->if_vnet) {
                CURVNET_SET(ifp->if_vnet);
                if_free(ifp);
                CURVNET_RESTORE();
-       } else if (ifp != NULL)
+       } else
+#endif
+       if (ifp != NULL)
                if_free(ifp);
        sc->sc_invalid = 1;
        return error;
                if_free(ifp);
        sc->sc_invalid = 1;
        return error;
@@ -1060,6 +1089,11 @@ ath_detach(struct ath_softc *sc)
        if_free(ifp);
        CURVNET_RESTORE();
 
        if_free(ifp);
        CURVNET_RESTORE();
 
+       if (sc->sc_sysctl_tree) {
+               sysctl_ctx_free(&sc->sc_sysctl_ctx);
+               sc->sc_sysctl_tree = NULL;
+       }
+
        return 0;
 }
 
        return 0;
 }
 
@@ -1142,7 +1176,7 @@ ath_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
        int needbeacon, error;
        enum ieee80211_opmode ic_opmode;
 
        int needbeacon, error;
        enum ieee80211_opmode ic_opmode;
 
-       avp = (struct ath_vap *) malloc(sizeof(struct ath_vap),
+       avp = (struct ath_vap *) kmalloc(sizeof(struct ath_vap),
            M_80211_VAP, M_WAITOK | M_ZERO);
        needbeacon = 0;
        IEEE80211_ADDR_COPY(mac, mac0);
            M_80211_VAP, M_WAITOK | M_ZERO);
        needbeacon = 0;
        IEEE80211_ADDR_COPY(mac, mac0);
@@ -1269,14 +1303,18 @@ ath_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
        avp->av_bmiss = vap->iv_bmiss;
        vap->iv_bmiss = ath_bmiss_vap;
 
        avp->av_bmiss = vap->iv_bmiss;
        vap->iv_bmiss = ath_bmiss_vap;
 
+#if 0
        avp->av_node_ps = vap->iv_node_ps;
        vap->iv_node_ps = ath_node_powersave;
        avp->av_node_ps = vap->iv_node_ps;
        vap->iv_node_ps = ath_node_powersave;
+#endif
 
        avp->av_set_tim = vap->iv_set_tim;
        vap->iv_set_tim = ath_node_set_tim;
 
 
        avp->av_set_tim = vap->iv_set_tim;
        vap->iv_set_tim = ath_node_set_tim;
 
+#if 0
        avp->av_recv_pspoll = vap->iv_recv_pspoll;
        vap->iv_recv_pspoll = ath_node_recv_pspoll;
        avp->av_recv_pspoll = vap->iv_recv_pspoll;
        vap->iv_recv_pspoll = ath_node_recv_pspoll;
+#endif
 
        /* Set default parameters */
 
 
        /* Set default parameters */
 
@@ -1384,7 +1422,7 @@ bad2:
        reclaim_address(sc, mac);
        ath_hal_setbssidmask(sc->sc_ah, sc->sc_hwbssidmask);
 bad:
        reclaim_address(sc, mac);
        ath_hal_setbssidmask(sc->sc_ah, sc->sc_hwbssidmask);
 bad:
-       free(avp, M_80211_VAP);
+       kfree(avp, M_80211_VAP);
        ATH_UNLOCK(sc);
        return NULL;
 }
        ATH_UNLOCK(sc);
        return NULL;
 }
@@ -1399,7 +1437,7 @@ ath_vap_delete(struct ieee80211vap *vap)
        struct ath_vap *avp = ATH_VAP(vap);
 
        DPRINTF(sc, ATH_DEBUG_RESET, "%s: called\n", __func__);
        struct ath_vap *avp = ATH_VAP(vap);
 
        DPRINTF(sc, ATH_DEBUG_RESET, "%s: called\n", __func__);
-       if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+       if (ifp->if_flags & IFF_RUNNING) {
                /*
                 * Quiesce the hardware while we remove the vap.  In
                 * particular we need to reclaim all references to
                /*
                 * Quiesce the hardware while we remove the vap.  In
                 * particular we need to reclaim all references to
@@ -1478,9 +1516,9 @@ ath_vap_delete(struct ieee80211vap *vap)
                sc->sc_swbmiss = 0;
        }
 #endif
                sc->sc_swbmiss = 0;
        }
 #endif
-       free(avp, M_80211_VAP);
+       kfree(avp, M_80211_VAP);
 
 
-       if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+       if (ifp->if_flags & IFF_RUNNING) {
                /*
                 * Restart rx+tx machines if still running (RUNNING will
                 * be reset if we just destroyed the last vap).
                /*
                 * Restart rx+tx machines if still running (RUNNING will
                 * be reset if we just destroyed the last vap).
@@ -1686,7 +1724,7 @@ ath_intr(void *arg)
        }
 
        if ((ifp->if_flags & IFF_UP) == 0 ||
        }
 
        if ((ifp->if_flags & IFF_UP) == 0 ||
-           (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
+           (ifp->if_flags & IFF_RUNNING) == 0) {
                HAL_INT status;
 
                DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags 0x%x\n",
                HAL_INT status;
 
                DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags 0x%x\n",
@@ -1920,6 +1958,7 @@ ath_fatal_proc(void *arg, int pending)
         * are caused by DMA errors.  Collect h/w state from
         * the hal so we can diagnose what's going on.
         */
         * are caused by DMA errors.  Collect h/w state from
         * the hal so we can diagnose what's going on.
         */
+       wlan_serialize_enter();
        if (ath_hal_getfatalstate(sc->sc_ah, &sp, &len)) {
                KASSERT(len >= 6*sizeof(u_int32_t), ("len %u bytes", len));
                state = sp;
        if (ath_hal_getfatalstate(sc->sc_ah, &sp, &len)) {
                KASSERT(len >= 6*sizeof(u_int32_t), ("len %u bytes", len));
                state = sp;
@@ -1928,6 +1967,7 @@ ath_fatal_proc(void *arg, int pending)
                    state[4], state[5]);
        }
        ath_reset(ifp, ATH_RESET_NOLOSS);
                    state[4], state[5]);
        }
        ath_reset(ifp, ATH_RESET_NOLOSS);
+       wlan_serialize_exit();
 }
 
 static void
 }
 
 static void
@@ -1992,6 +2032,7 @@ ath_bmiss_proc(void *arg, int pending)
         * It may be a non-recognised RX clear hang which needs a reset
         * to clear.
         */
         * It may be a non-recognised RX clear hang which needs a reset
         * to clear.
         */
+       wlan_serialize_enter();
        if (ath_hal_gethangstate(sc->sc_ah, 0xff, &hangs) && hangs != 0) {
                ath_reset(ifp, ATH_RESET_NOLOSS);
                if_printf(ifp, "bb hang detected (0x%x), resetting\n", hangs);
        if (ath_hal_gethangstate(sc->sc_ah, 0xff, &hangs) && hangs != 0) {
                ath_reset(ifp, ATH_RESET_NOLOSS);
                if_printf(ifp, "bb hang detected (0x%x), resetting\n", hangs);
@@ -1999,6 +2040,7 @@ ath_bmiss_proc(void *arg, int pending)
                ath_reset(ifp, ATH_RESET_NOLOSS);
                ieee80211_beacon_miss(ifp->if_l2com);
        }
                ath_reset(ifp, ATH_RESET_NOLOSS);
                ieee80211_beacon_miss(ifp->if_l2com);
        }
+       wlan_serialize_exit();
 }
 
 /*
 }
 
 /*
@@ -2142,7 +2184,7 @@ ath_init(void *arg)
        DPRINTF(sc, ATH_DEBUG_RESET, "%s: imask=0x%x\n",
                __func__, sc->sc_imask);
 
        DPRINTF(sc, ATH_DEBUG_RESET, "%s: imask=0x%x\n",
                __func__, sc->sc_imask);
 
-       ifp->if_drv_flags |= IFF_DRV_RUNNING;
+       ifp->if_flags |= IFF_RUNNING;
        callout_reset(&sc->sc_wd_ch, hz, ath_watchdog, sc);
        ath_hal_intrset(ah, sc->sc_imask);
 
        callout_reset(&sc->sc_wd_ch, hz, ath_watchdog, sc);
        ath_hal_intrset(ah, sc->sc_imask);
 
@@ -2166,7 +2208,7 @@ ath_stop_locked(struct ifnet *ifp)
                __func__, sc->sc_invalid, ifp->if_flags);
 
        ATH_LOCK_ASSERT(sc);
                __func__, sc->sc_invalid, ifp->if_flags);
 
        ATH_LOCK_ASSERT(sc);
-       if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+       if (ifp->if_flags & IFF_RUNNING) {
                /*
                 * Shutdown the hardware and driver:
                 *    reset 802.11 state machine
                /*
                 * Shutdown the hardware and driver:
                 *    reset 802.11 state machine
@@ -2188,7 +2230,7 @@ ath_stop_locked(struct ifnet *ifp)
 #endif
                callout_stop(&sc->sc_wd_ch);
                sc->sc_wd_timer = 0;
 #endif
                callout_stop(&sc->sc_wd_ch);
                sc->sc_wd_timer = 0;
-               ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+               ifp->if_flags &= ~IFF_RUNNING;
                if (!sc->sc_invalid) {
                        if (sc->sc_softled) {
                                callout_stop(&sc->sc_ledtimer);
                if (!sc->sc_invalid) {
                        if (sc->sc_softled) {
                                callout_stop(&sc->sc_ledtimer);
@@ -2227,7 +2269,7 @@ ath_txrx_stop_locked(struct ath_softc *sc)
            sc->sc_txstart_cnt || sc->sc_intr_cnt) {
                if (i <= 0)
                        break;
            sc->sc_txstart_cnt || sc->sc_intr_cnt) {
                if (i <= 0)
                        break;
-               msleep(sc, &sc->sc_pcu_mtx, 0, "ath_txrx_stop", 1);
+               wlan_serialize_sleep(sc, 0, "ath_txrx_stop", 1);
                i--;
        }
 
                i--;
        }
 
@@ -2292,7 +2334,7 @@ ath_reset_grablock(struct ath_softc *sc, int dowait)
                        break;
                }
                ATH_PCU_UNLOCK(sc);
                        break;
                }
                ATH_PCU_UNLOCK(sc);
-               pause("ath_reset_grablock", 1);
+               wlan_serialize_sleep(sc, 0, "ath_reset_grablock", 1);
                i--;
                ATH_PCU_LOCK(sc);
        } while (i > 0);
                i--;
                ATH_PCU_LOCK(sc);
        } while (i > 0);
@@ -2325,7 +2367,7 @@ ath_reset_grablock(struct ath_softc *sc, int dowait)
 static void
 ath_stop(struct ifnet *ifp)
 {
 static void
 ath_stop(struct ifnet *ifp)
 {
-       struct ath_softc *sc = ifp->if_softc;
+       struct ath_softc *sc __unused = ifp->if_softc;
 
        ATH_LOCK(sc);
        ath_stop_locked(ifp);
 
        ATH_LOCK(sc);
        ath_stop_locked(ifp);
@@ -2491,7 +2533,7 @@ ath_reset(struct ifnet *ifp, ATH_RESET_TYPE reset_type)
         * So, clear it.
         */
        IF_LOCK(&ifp->if_snd);
         * So, clear it.
         */
        IF_LOCK(&ifp->if_snd);
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+       ifq_clr_oactive(&ifp->if_snd);
        IF_UNLOCK(&ifp->if_snd);
 
        /* Handle any frames in the TX queue */
        IF_UNLOCK(&ifp->if_snd);
 
        /* Handle any frames in the TX queue */
@@ -2687,12 +2729,13 @@ ath_getbuf(struct ath_softc *sc, ath_buf_type_t btype)
                DPRINTF(sc, ATH_DEBUG_XMIT, "%s: stop queue\n", __func__);
                sc->sc_stats.ast_tx_qstop++;
                IF_LOCK(&ifp->if_snd);
                DPRINTF(sc, ATH_DEBUG_XMIT, "%s: stop queue\n", __func__);
                sc->sc_stats.ast_tx_qstop++;
                IF_LOCK(&ifp->if_snd);
-               ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+               ifq_set_oactive(&ifp->if_snd);
                IF_UNLOCK(&ifp->if_snd);
        }
        return bf;
 }
 
                IF_UNLOCK(&ifp->if_snd);
        }
        return bf;
 }
 
+#if 0
 static void
 ath_qflush(struct ifnet *ifp)
 {
 static void
 ath_qflush(struct ifnet *ifp)
 {
@@ -2727,7 +2770,7 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
                ATH_PCU_UNLOCK(sc);
                IF_LOCK(&ifp->if_snd);
                sc->sc_stats.ast_tx_qstop++;
                ATH_PCU_UNLOCK(sc);
                IF_LOCK(&ifp->if_snd);
                sc->sc_stats.ast_tx_qstop++;
-               ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+               ifq_set_oactive(&ifp->if_snd);
                IF_UNLOCK(&ifp->if_snd);
                ATH_KTR(sc, ATH_KTR_TX, 0, "ath_start_task: OACTIVE, finish");
                return (ENOBUFS);       /* XXX should be EINVAL or? */
                IF_UNLOCK(&ifp->if_snd);
                ATH_KTR(sc, ATH_KTR_TX, 0, "ath_start_task: OACTIVE, finish");
                return (ENOBUFS);       /* XXX should be EINVAL or? */
@@ -2818,7 +2861,7 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
                 */
                sc->sc_stats.ast_tx_nobuf++;
                IF_LOCK(&ifp->if_snd);
                 */
                sc->sc_stats.ast_tx_nobuf++;
                IF_LOCK(&ifp->if_snd);
-               ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+               ifq_set_oactive(&ifp->if_snd);
                IF_UNLOCK(&ifp->if_snd);
                m_freem(m);
                m = NULL;
                IF_UNLOCK(&ifp->if_snd);
                m_freem(m);
                m = NULL;
@@ -2972,6 +3015,7 @@ finish:
        
        return (retval);
 }
        
        return (retval);
 }
+#endif
 
 static int
 ath_media_change(struct ifnet *ifp)
 
 static int
 ath_media_change(struct ifnet *ifp)
@@ -3035,7 +3079,9 @@ ath_update_mcast(struct ifnet *ifp)
                 * Merge multicast addresses to form the hardware filter.
                 */
                mfilt[0] = mfilt[1] = 0;
                 * Merge multicast addresses to form the hardware filter.
                 */
                mfilt[0] = mfilt[1] = 0;
+#if 0
                if_maddr_rlock(ifp);    /* XXX need some fiddling to remove? */
                if_maddr_rlock(ifp);    /* XXX need some fiddling to remove? */
+#endif
                TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
                        caddr_t dl;
                        u_int32_t val;
                TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
                        caddr_t dl;
                        u_int32_t val;
@@ -3050,7 +3096,9 @@ ath_update_mcast(struct ifnet *ifp)
                        pos &= 0x3f;
                        mfilt[pos / 32] |= (1 << (pos % 32));
                }
                        pos &= 0x3f;
                        mfilt[pos / 32] |= (1 << (pos % 32));
                }
+#if 0
                if_maddr_runlock(ifp);
                if_maddr_runlock(ifp);
+#endif
        } else
                mfilt[0] = mfilt[1] = ~0;
        ath_hal_setmcastfilter(sc->sc_ah, mfilt[0], mfilt[1]);
        } else
                mfilt[0] = mfilt[1] = ~0;
        ath_hal_setmcastfilter(sc->sc_ah, mfilt[0], mfilt[1]);
@@ -3175,7 +3223,9 @@ ath_reset_proc(void *arg, int pending)
 #if 0
        if_printf(ifp, "%s: resetting\n", __func__);
 #endif
 #if 0
        if_printf(ifp, "%s: resetting\n", __func__);
 #endif
+       wlan_serialize_enter();
        ath_reset(ifp, ATH_RESET_NOLOSS);
        ath_reset(ifp, ATH_RESET_NOLOSS);
+       wlan_serialize_exit();
 }
 
 /*
 }
 
 /*
@@ -3188,6 +3238,7 @@ ath_bstuck_proc(void *arg, int pending)
        struct ifnet *ifp = sc->sc_ifp;
        uint32_t hangs = 0;
 
        struct ifnet *ifp = sc->sc_ifp;
        uint32_t hangs = 0;
 
+       wlan_serialize_enter();
        if (ath_hal_gethangstate(sc->sc_ah, 0xff, &hangs) && hangs != 0)
                if_printf(ifp, "bb hang detected (0x%x)\n", hangs);
 
        if (ath_hal_gethangstate(sc->sc_ah, 0xff, &hangs) && hangs != 0)
                if_printf(ifp, "bb hang detected (0x%x)\n", hangs);
 
@@ -3204,6 +3255,7 @@ ath_bstuck_proc(void *arg, int pending)
         * occuring.
         */
        ath_reset(ifp, ATH_RESET_NOLOSS);
         * occuring.
         */
        ath_reset(ifp, ATH_RESET_NOLOSS);
+       wlan_serialize_exit();
 }
 
 static void
 }
 
 static void
@@ -3266,8 +3318,6 @@ ath_descdma_alloc_desc(struct ath_softc *sc,
                       1,                       /* nsegments */
                       dd->dd_desc_len,         /* maxsegsize */
                       0,                       /* flags */
                       1,                       /* nsegments */
                       dd->dd_desc_len,         /* maxsegsize */
                       0,                       /* flags */
-                      NULL,                    /* lockfunc */
-                      NULL,                    /* lockarg */
                       &dd->dd_dmat);
        if (error != 0) {
                if_printf(ifp, "cannot allocate %s DMA tag\n", dd->dd_name);
                       &dd->dd_dmat);
        if (error != 0) {
                if_printf(ifp, "cannot allocate %s DMA tag\n", dd->dd_name);
@@ -3338,7 +3388,7 @@ ath_descdma_setup(struct ath_softc *sc,
 
        /* allocate rx buffers */
        bsize = sizeof(struct ath_buf) * nbuf;
 
        /* allocate rx buffers */
        bsize = sizeof(struct ath_buf) * nbuf;
-       bf = malloc(bsize, M_ATHDEV, M_NOWAIT | M_ZERO);
+       bf = kmalloc(bsize, M_ATHDEV, M_INTWAIT|M_ZERO);
        if (bf == NULL) {
                if_printf(ifp, "malloc of %s buffers failed, size %u\n",
                        dd->dd_name, bsize);
        if (bf == NULL) {
                if_printf(ifp, "malloc of %s buffers failed, size %u\n",
                        dd->dd_name, bsize);
@@ -3425,7 +3475,7 @@ ath_descdma_setup_rx_edma(struct ath_softc *sc,
 
        /* allocate rx buffers */
        bsize = sizeof(struct ath_buf) * nbuf;
 
        /* allocate rx buffers */
        bsize = sizeof(struct ath_buf) * nbuf;
-       bf = malloc(bsize, M_ATHDEV, M_NOWAIT | M_ZERO);
+       bf = kmalloc(bsize, M_ATHDEV, M_INTWAIT | M_ZERO);
        if (bf == NULL) {
                if_printf(ifp, "malloc of %s buffers failed, size %u\n",
                        dd->dd_name, bsize);
        if (bf == NULL) {
                if_printf(ifp, "malloc of %s buffers failed, size %u\n",
                        dd->dd_name, bsize);
@@ -3512,7 +3562,7 @@ ath_descdma_cleanup(struct ath_softc *sc,
                TAILQ_INIT(head);
 
        if (dd->dd_bufptr != NULL)
                TAILQ_INIT(head);
 
        if (dd->dd_bufptr != NULL)
-               free(dd->dd_bufptr, M_ATHDEV);
+               kfree(dd->dd_bufptr, M_ATHDEV);
        memset(dd, 0, sizeof(*dd));
 }
 
        memset(dd, 0, sizeof(*dd));
 }
 
@@ -3573,7 +3623,7 @@ ath_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN])
        const size_t space = sizeof(struct ath_node) + sc->sc_rc->arc_space;
        struct ath_node *an;
 
        const size_t space = sizeof(struct ath_node) + sc->sc_rc->arc_space;
        struct ath_node *an;
 
-       an = malloc(space, M_80211_NODE, M_NOWAIT|M_ZERO);
+       an = kmalloc(space, M_80211_NODE, M_INTWAIT|M_ZERO);
        if (an == NULL) {
                /* XXX stat+msg */
                return NULL;
        if (an == NULL) {
                /* XXX stat+msg */
                return NULL;
@@ -3581,9 +3631,11 @@ ath_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN])
        ath_rate_node_init(sc, an);
 
        /* Setup the mutex - there's no associd yet so set the name to NULL */
        ath_rate_node_init(sc, an);
 
        /* Setup the mutex - there's no associd yet so set the name to NULL */
-       snprintf(an->an_name, sizeof(an->an_name), "%s: node %p",
+       ksnprintf(an->an_name, sizeof(an->an_name), "%s: node %p",
            device_get_nameunit(sc->sc_dev), an);
            device_get_nameunit(sc->sc_dev), an);
+#if 0
        mtx_init(&an->an_mtx, an->an_name, NULL, MTX_DEF);
        mtx_init(&an->an_mtx, an->an_name, NULL, MTX_DEF);
+#endif
 
        /* XXX setup ath_tid */
        ath_tx_tid_init(sc, an);
 
        /* XXX setup ath_tid */
        ath_tx_tid_init(sc, an);
@@ -3615,7 +3667,9 @@ ath_node_free(struct ieee80211_node *ni)
 
        DPRINTF(sc, ATH_DEBUG_NODE, "%s: %6D: an %p\n", __func__,
            ni->ni_macaddr, ":", ATH_NODE(ni));
 
        DPRINTF(sc, ATH_DEBUG_NODE, "%s: %6D: an %p\n", __func__,
            ni->ni_macaddr, ":", ATH_NODE(ni));
+#if 0
        mtx_destroy(&ATH_NODE(ni)->an_mtx);
        mtx_destroy(&ATH_NODE(ni)->an_mtx);
+#endif
        sc->sc_node_free(ni);
 }
 
        sc->sc_node_free(ni);
 }
 
@@ -4248,6 +4302,7 @@ ath_tx_proc_q0(void *arg, int npending)
        struct ifnet *ifp = sc->sc_ifp;
        uint32_t txqs;
 
        struct ifnet *ifp = sc->sc_ifp;
        uint32_t txqs;
 
+       wlan_serialize_enter();
        ATH_PCU_LOCK(sc);
        sc->sc_txproc_cnt++;
        txqs = sc->sc_txq_active;
        ATH_PCU_LOCK(sc);
        sc->sc_txproc_cnt++;
        txqs = sc->sc_txq_active;
@@ -4263,7 +4318,7 @@ ath_tx_proc_q0(void *arg, int npending)
        if (TXQACTIVE(txqs, sc->sc_cabq->axq_qnum))
                ath_tx_processq(sc, sc->sc_cabq, 1);
        IF_LOCK(&ifp->if_snd);
        if (TXQACTIVE(txqs, sc->sc_cabq->axq_qnum))
                ath_tx_processq(sc, sc->sc_cabq, 1);
        IF_LOCK(&ifp->if_snd);
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+       ifq_clr_oactive(&ifp->if_snd);
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
@@ -4275,6 +4330,7 @@ ath_tx_proc_q0(void *arg, int npending)
        ATH_PCU_UNLOCK(sc);
 
        ath_tx_kick(sc);
        ATH_PCU_UNLOCK(sc);
 
        ath_tx_kick(sc);
+       wlan_serialize_exit();
 }
 
 /*
 }
 
 /*
@@ -4289,6 +4345,7 @@ ath_tx_proc_q0123(void *arg, int npending)
        int nacked;
        uint32_t txqs;
 
        int nacked;
        uint32_t txqs;
 
+       wlan_serialize_enter();
        ATH_PCU_LOCK(sc);
        sc->sc_txproc_cnt++;
        txqs = sc->sc_txq_active;
        ATH_PCU_LOCK(sc);
        sc->sc_txproc_cnt++;
        txqs = sc->sc_txq_active;
@@ -4316,7 +4373,7 @@ ath_tx_proc_q0123(void *arg, int npending)
                sc->sc_lastrx = ath_hal_gettsf64(sc->sc_ah);
 
        IF_LOCK(&ifp->if_snd);
                sc->sc_lastrx = ath_hal_gettsf64(sc->sc_ah);
 
        IF_LOCK(&ifp->if_snd);
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+       ifq_clr_oactive(&ifp->if_snd);
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
@@ -4328,6 +4385,7 @@ ath_tx_proc_q0123(void *arg, int npending)
        ATH_PCU_UNLOCK(sc);
 
        ath_tx_kick(sc);
        ATH_PCU_UNLOCK(sc);
 
        ath_tx_kick(sc);
+       wlan_serialize_exit();
 }
 
 /*
 }
 
 /*
@@ -4341,6 +4399,7 @@ ath_tx_proc(void *arg, int npending)
        int i, nacked;
        uint32_t txqs;
 
        int i, nacked;
        uint32_t txqs;
 
+       wlan_serialize_enter();
        ATH_PCU_LOCK(sc);
        sc->sc_txproc_cnt++;
        txqs = sc->sc_txq_active;
        ATH_PCU_LOCK(sc);
        sc->sc_txproc_cnt++;
        txqs = sc->sc_txq_active;
@@ -4361,7 +4420,7 @@ ath_tx_proc(void *arg, int npending)
 
        /* XXX check this inside of IF_LOCK? */
        IF_LOCK(&ifp->if_snd);
 
        /* XXX check this inside of IF_LOCK? */
        IF_LOCK(&ifp->if_snd);
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+       ifq_clr_oactive(&ifp->if_snd);
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
@@ -4373,6 +4432,7 @@ ath_tx_proc(void *arg, int npending)
        ATH_PCU_UNLOCK(sc);
 
        ath_tx_kick(sc);
        ATH_PCU_UNLOCK(sc);
 
        ath_tx_kick(sc);
+       wlan_serialize_exit();
 }
 #undef TXQACTIVE
 
 }
 #undef TXQACTIVE
 
@@ -4867,7 +4927,7 @@ ath_legacy_tx_drain(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
        }
 #endif /* ATH_DEBUG */
        IF_LOCK(&ifp->if_snd);
        }
 #endif /* ATH_DEBUG */
        IF_LOCK(&ifp->if_snd);
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+       ifq_clr_oactive(&ifp->if_snd);
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 }
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 }
@@ -5030,7 +5090,7 @@ finish:
        ATH_PCU_UNLOCK(sc);
 
        IF_LOCK(&ifp->if_snd);
        ATH_PCU_UNLOCK(sc);
 
        IF_LOCK(&ifp->if_snd);
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+       ifq_clr_oactive(&ifp->if_snd);
        IF_UNLOCK(&ifp->if_snd);
        ath_txrx_start(sc);
        /* XXX ath_start? */
        IF_UNLOCK(&ifp->if_snd);
        ath_txrx_start(sc);
        /* XXX ath_start? */
@@ -5053,6 +5113,7 @@ ath_calibrate(void *arg)
        HAL_BOOL aniCal, shortCal = AH_FALSE;
        int nextcal;
 
        HAL_BOOL aniCal, shortCal = AH_FALSE;
        int nextcal;
 
+       wlan_serialize_enter();
        if (ic->ic_flags & IEEE80211_F_SCAN)    /* defer, off channel */
                goto restart;
        longCal = (ticks - sc->sc_lastlongcal >= ath_longcalinterval*hz);
        if (ic->ic_flags & IEEE80211_F_SCAN)    /* defer, off channel */
                goto restart;
        longCal = (ticks - sc->sc_lastlongcal >= ath_longcalinterval*hz);
@@ -5082,7 +5143,7 @@ ath_calibrate(void *arg)
                        sc->sc_doresetcal = AH_TRUE;
                        taskqueue_enqueue(sc->sc_tq, &sc->sc_resettask);
                        callout_reset(&sc->sc_cal_ch, 1, ath_calibrate, sc);
                        sc->sc_doresetcal = AH_TRUE;
                        taskqueue_enqueue(sc->sc_tq, &sc->sc_resettask);
                        callout_reset(&sc->sc_cal_ch, 1, ath_calibrate, sc);
-                       return;
+                       goto done;
                }
                /*
                 * If this long cal is after an idle period, then
                }
                /*
                 * If this long cal is after an idle period, then
@@ -5153,6 +5214,8 @@ restart:
                    __func__);
                /* NB: don't rearm timer */
        }
                    __func__);
                /* NB: don't rearm timer */
        }
+done:
+       wlan_serialize_exit();
 }
 
 static void
 }
 
 static void
@@ -5177,7 +5240,7 @@ ath_scan_start(struct ieee80211com *ic)
        ATH_PCU_UNLOCK(sc);
 
        DPRINTF(sc, ATH_DEBUG_STATE, "%s: RX filter 0x%x bssid %s aid 0\n",
        ATH_PCU_UNLOCK(sc);
 
        DPRINTF(sc, ATH_DEBUG_STATE, "%s: RX filter 0x%x bssid %s aid 0\n",
-                __func__, rfilt, ether_sprintf(ifp->if_broadcastaddr));
+                __func__, rfilt, ath_hal_ether_sprintf(ifp->if_broadcastaddr));
 }
 
 static void
 }
 
 static void
@@ -5201,7 +5264,7 @@ ath_scan_end(struct ieee80211com *ic)
        ATH_PCU_UNLOCK(sc);
 
        DPRINTF(sc, ATH_DEBUG_STATE, "%s: RX filter 0x%x bssid %s aid 0x%x\n",
        ATH_PCU_UNLOCK(sc);
 
        DPRINTF(sc, ATH_DEBUG_STATE, "%s: RX filter 0x%x bssid %s aid 0x%x\n",
-                __func__, rfilt, ether_sprintf(sc->sc_curbssid),
+                __func__, rfilt, ath_hal_ether_sprintf(sc->sc_curbssid),
                 sc->sc_curaid);
 }
 
                 sc->sc_curaid);
 }
 
@@ -5336,7 +5399,8 @@ ath_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
                ath_hal_setassocid(ah, sc->sc_curbssid, sc->sc_curaid);
        }
        DPRINTF(sc, ATH_DEBUG_STATE, "%s: RX filter 0x%x bssid %s aid 0x%x\n",
                ath_hal_setassocid(ah, sc->sc_curbssid, sc->sc_curaid);
        }
        DPRINTF(sc, ATH_DEBUG_STATE, "%s: RX filter 0x%x bssid %s aid 0x%x\n",
-          __func__, rfilt, ether_sprintf(sc->sc_curbssid), sc->sc_curaid);
+          __func__, rfilt,
+          ath_hal_ether_sprintf(sc->sc_curbssid), sc->sc_curaid);
        ath_hal_setrxfilter(ah, rfilt);
 
        /* XXX is this to restore keycache on resume? */
        ath_hal_setrxfilter(ah, rfilt);
 
        /* XXX is this to restore keycache on resume? */
@@ -5368,7 +5432,8 @@ ath_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
                DPRINTF(sc, ATH_DEBUG_STATE,
                    "%s(RUN): iv_flags 0x%08x bintvl %d bssid %s "
                    "capinfo 0x%04x chan %d\n", __func__,
                DPRINTF(sc, ATH_DEBUG_STATE,
                    "%s(RUN): iv_flags 0x%08x bintvl %d bssid %s "
                    "capinfo 0x%04x chan %d\n", __func__,
-                   vap->iv_flags, ni->ni_intval, ether_sprintf(ni->ni_bssid),
+                   vap->iv_flags, ni->ni_intval,
+                   ath_hal_ether_sprintf(ni->ni_bssid),
                    ni->ni_capinfo, ieee80211_chan2ieee(ic, ic->ic_curchan));
 
                switch (vap->iv_opmode) {
                    ni->ni_capinfo, ieee80211_chan2ieee(ic, ic->ic_curchan));
 
                switch (vap->iv_opmode) {
@@ -5803,6 +5868,7 @@ ath_watchdog(void *arg)
        struct ath_softc *sc = arg;
        int do_reset = 0;
 
        struct ath_softc *sc = arg;
        int do_reset = 0;
 
+       wlan_serialize_enter();
        if (sc->sc_wd_timer != 0 && --sc->sc_wd_timer == 0) {
                struct ifnet *ifp = sc->sc_ifp;
                uint32_t hangs;
        if (sc->sc_wd_timer != 0 && --sc->sc_wd_timer == 0) {
                struct ifnet *ifp = sc->sc_ifp;
                uint32_t hangs;
@@ -5828,7 +5894,8 @@ ath_watchdog(void *arg)
                taskqueue_enqueue(sc->sc_tq, &sc->sc_resettask);
        }
 
                taskqueue_enqueue(sc->sc_tq, &sc->sc_resettask);
        }
 
-       callout_schedule(&sc->sc_wd_ch, hz);
+       callout_reset(&sc->sc_wd_ch, hz, ath_watchdog, sc);
+       wlan_serialize_exit();
 }
 
 /*
 }
 
 /*
@@ -5890,7 +5957,7 @@ ath_ioctl_diag(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
                /*
                 * Copy in data.
                 */
-               indata = malloc(insize, M_TEMP, M_NOWAIT);
+               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -5907,7 +5974,7 @@ ath_ioctl_diag(struct ath_softc *sc, struct ath_diag *ad)
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
-               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
+               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -5924,18 +5991,19 @@ ath_ioctl_diag(struct ath_softc *sc, struct ath_diag *ad)
        }
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
        }
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               free(indata, M_TEMP);
+               kfree(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               free(outdata, M_TEMP);
+               kfree(outdata, M_TEMP);
        return error;
 }
 #endif /* ATH_DIAGAPI */
 
 static int
        return error;
 }
 #endif /* ATH_DIAGAPI */
 
 static int
-ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data,
+         struct ucred *cr __unused)
 {
 #define        IS_RUNNING(ifp) \
 {
 #define        IS_RUNNING(ifp) \
-       ((ifp->if_flags & IFF_UP) && (ifp->if_drv_flags & IFF_DRV_RUNNING))
+       ((ifp->if_flags & IFF_UP) && (ifp->if_flags & IFF_RUNNING))
        struct ath_softc *sc = ifp->if_softc;
        struct ieee80211com *ic = ifp->if_l2com;
        struct ifreq *ifr = (struct ifreq *)data;
        struct ath_softc *sc = ifp->if_softc;
        struct ieee80211com *ic = ifp->if_l2com;
        struct ifreq *ifr = (struct ifreq *)data;
@@ -6078,6 +6146,7 @@ ath_dfs_tasklet(void *p, int npending)
         * signal this to the net80211 layer to begin DFS
         * processing.
         */
         * signal this to the net80211 layer to begin DFS
         * processing.
         */
+       wlan_serialize_enter();
        if (ath_dfs_process_radar_event(sc, sc->sc_curchan)) {
                /* DFS event found, initiate channel change */
                /*
        if (ath_dfs_process_radar_event(sc, sc->sc_curchan)) {
                /* DFS event found, initiate channel change */
                /*
@@ -6089,8 +6158,10 @@ ath_dfs_tasklet(void *p, int npending)
                ieee80211_dfs_notify_radar(ic, sc->sc_curchan);
                IEEE80211_UNLOCK(ic);
        }
                ieee80211_dfs_notify_radar(ic, sc->sc_curchan);
                IEEE80211_UNLOCK(ic);
        }
+       wlan_serialize_exit();
 }
 
 }
 
+#if 0
 /*
  * Enable/disable power save.  This must be called with
  * no TX driver locks currently held, so it should only
 /*
  * Enable/disable power save.  This must be called with
  * no TX driver locks currently held, so it should only
@@ -6121,15 +6192,19 @@ ath_node_powersave(struct ieee80211_node *ni, int enable)
                ath_tx_node_wakeup(sc, an);
 
        /* Update net80211 state */
                ath_tx_node_wakeup(sc, an);
 
        /* Update net80211 state */
-       avp->av_node_ps(ni, enable);
+       if (avp->av_node_ps)
+               avp->av_node_ps(ni, enable);
 #else
        struct ath_vap *avp = ATH_VAP(ni->ni_vap);
 
        /* Update net80211 state */
 #else
        struct ath_vap *avp = ATH_VAP(ni->ni_vap);
 
        /* Update net80211 state */
-       avp->av_node_ps(ni, enable);
+       if (avp->av_node_ps)
+               avp->av_node_ps(ni, enable);
 #endif/* ATH_SW_PSQ */
 }
 
 #endif/* ATH_SW_PSQ */
 }
 
+#endif
+
 /*
  * Notification from net80211 that the powersave queue state has
  * changed.
 /*
  * Notification from net80211 that the powersave queue state has
  * changed.
@@ -6360,6 +6435,7 @@ ath_tx_update_tim(struct ath_softc *sc, struct ieee80211_node *ni,
 #endif /* ATH_SW_PSQ */
 }
 
 #endif /* ATH_SW_PSQ */
 }
 
+#if 0
 /*
  * Received a ps-poll frame from net80211.
  *
 /*
  * Received a ps-poll frame from net80211.
  *
@@ -6433,7 +6509,8 @@ ath_node_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m)
                    ni->ni_macaddr,
                    ":");
                ATH_TX_UNLOCK(sc);
                    ni->ni_macaddr,
                    ":");
                ATH_TX_UNLOCK(sc);
-               avp->av_recv_pspoll(ni, m);
+               if (avp->av_recv_pspoll)
+                       avp->av_recv_pspoll(ni, m);
                return;
        }
 
                return;
        }
 
@@ -6458,7 +6535,8 @@ ath_node_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m)
                    __func__,
                    ni->ni_macaddr,
                    ":");
                    __func__,
                    ni->ni_macaddr,
                    ":");
-               avp->av_recv_pspoll(ni, m);
+               if (avp->av_recv_pspoll)
+                       avp->av_recv_pspoll(ni, m);
                return;
        }
 
                return;
        }
 
@@ -6500,12 +6578,16 @@ ath_node_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m)
            __func__,
            ni->ni_macaddr,
            ":");
            __func__,
            ni->ni_macaddr,
            ":");
-       avp->av_recv_pspoll(ni, m);
+       if (avp->av_recv_pspoll)
+               avp->av_recv_pspoll(ni, m);
 #else
 #else
-       avp->av_recv_pspoll(ni, m);
+       if (avp->av_recv_pspoll)
+               avp->av_recv_pspoll(ni, m);
 #endif /* ATH_SW_PSQ */
 }
 
 #endif /* ATH_SW_PSQ */
 }
 
+#endif
+
 MODULE_VERSION(if_ath, 1);
 MODULE_DEPEND(if_ath, wlan, 1, 1, 1);          /* 802.11 media layer */
 #if    defined(IEEE80211_ALQ) || defined(AH_DEBUG_ALQ)
 MODULE_VERSION(if_ath, 1);
 MODULE_DEPEND(if_ath, wlan, 1, 1, 1);          /* 802.11 media layer */
 #if    defined(IEEE80211_ALQ) || defined(AH_DEBUG_ALQ)
index 10c79a5..b707ca6 100644 (file)
 
 #include <dev/netif/ath/ath/if_athvar.h>
 
 
 #include <dev/netif/ath/ath/if_athvar.h>
 
-#include <mips/atheros/ar71xxreg.h>
-#include <mips/atheros/ar91xxreg.h>
-#include <mips/atheros/ar71xx_cpudef.h>
+#define MIPS_KSEG1_START                ((intptr_t)(int32_t)0xa0000000)
+#define MIPS_PHYS_TO_KSEG1(x)           ((uintptr_t)(x) | MIPS_KSEG1_START)
 
 
-#include <machine/resource.h>
+#include <dev/netif/ath/ath_hal/ar71xx/ar71xxreg.h>
+#include <dev/netif/ath/ath_hal/ar91xx/ar91xxreg.h>
+#include <dev/netif/ath/ath_hal/ar71xx/ar71xx_cpudef.h>
 
 /*
  * bus glue.
 
 /*
  * bus glue.
@@ -173,7 +174,7 @@ ath_ahb_attach(device_t dev)
        sc->sc_invalid = 1;
 
        /* Copy the EEPROM data out */
        sc->sc_invalid = 1;
 
        /* Copy the EEPROM data out */
-       sc->sc_eepromdata = malloc(eepromsize, M_TEMP, M_NOWAIT | M_ZERO);
+       sc->sc_eepromdata = kmalloc(eepromsize, M_TEMP, M_INTWAIT | M_ZERO);
        if (sc->sc_eepromdata == NULL) {
                device_printf(dev, "cannot allocate memory for eeprom data\n");
                goto bad1;
        if (sc->sc_eepromdata == NULL) {
                device_printf(dev, "cannot allocate memory for eeprom data\n");
                goto bad1;
@@ -199,8 +200,9 @@ ath_ahb_attach(device_t dev)
                goto bad1;
        }
        if (bus_setup_intr(dev, psc->sc_irq,
                goto bad1;
        }
        if (bus_setup_intr(dev, psc->sc_irq,
-                          INTR_TYPE_NET | INTR_MPSAFE,
-                          NULL, ath_intr, sc, &psc->sc_ih)) {
+                          INTR_MPSAFE, ath_intr,
+                          sc, &psc->sc_ih,
+                          &wlan_global_serializer)) {
                device_printf(dev, "could not establish interrupt\n");
                goto bad2;
        }
                device_printf(dev, "could not establish interrupt\n");
                goto bad2;
        }
@@ -209,7 +211,7 @@ ath_ahb_attach(device_t dev)
         * Setup DMA descriptor area.
         */
        if (bus_dma_tag_create(bus_get_dma_tag(dev),    /* parent */
         * Setup DMA descriptor area.
         */
        if (bus_dma_tag_create(bus_get_dma_tag(dev),    /* parent */
-                              1, 0,                    /* alignment, bounds */
+                              4, 0,                    /* alignment, bounds */
                               BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
                               BUS_SPACE_MAXADDR,       /* highaddr */
                               NULL, NULL,              /* filter, filterarg */
                               BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
                               BUS_SPACE_MAXADDR,       /* highaddr */
                               NULL, NULL,              /* filter, filterarg */
@@ -217,8 +219,6 @@ ath_ahb_attach(device_t dev)
                               ATH_MAX_SCATTER,         /* nsegments */
                               0x3ffff,                 /* maxsegsize XXX */
                               BUS_DMA_ALLOCNOW,        /* flags */
                               ATH_MAX_SCATTER,         /* nsegments */
                               0x3ffff,                 /* maxsegsize XXX */
                               BUS_DMA_ALLOCNOW,        /* flags */
-                              NULL,                    /* lockfunc */
-                              NULL,                    /* lockarg */
                               &sc->sc_dmat)) {
                device_printf(dev, "cannot allocate DMA tag\n");
                goto bad3;
                               &sc->sc_dmat)) {
                device_printf(dev, "cannot allocate DMA tag\n");
                goto bad3;
@@ -266,7 +266,7 @@ bad0:
 bad:
        /* XXX?! */
        if (sc->sc_eepromdata)
 bad:
        /* XXX?! */
        if (sc->sc_eepromdata)
-               free(sc->sc_eepromdata, M_TEMP);
+               kfree(sc->sc_eepromdata, M_TEMP);
        return (error);
 }
 
        return (error);
 }
 
@@ -290,7 +290,7 @@ ath_ahb_detach(device_t dev)
        bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
        /* XXX?! */
        if (sc->sc_eepromdata)
        bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
        /* XXX?! */
        if (sc->sc_eepromdata)
-               free(sc->sc_eepromdata, M_TEMP);
+               kfree(sc->sc_eepromdata, M_TEMP);
 
        ATH_TXSTATUS_LOCK_DESTROY(sc);
        ATH_RX_LOCK_DESTROY(sc);
 
        ATH_TXSTATUS_LOCK_DESTROY(sc);
        ATH_RX_LOCK_DESTROY(sc);
@@ -348,7 +348,10 @@ static driver_t ath_ahb_driver = {
        sizeof (struct ath_ahb_softc)
 };
 static devclass_t ath_devclass;
        sizeof (struct ath_ahb_softc)
 };
 static devclass_t ath_devclass;
-DRIVER_MODULE(ath, nexus, ath_ahb_driver, ath_devclass, 0, 0);
-MODULE_VERSION(ath, 1);
-MODULE_DEPEND(ath, wlan, 1, 1, 1);             /* 802.11 media layer */
-MODULE_DEPEND(ath, if_ath, 1, 1, 1);           /* if_ath driver */
+DRIVER_MODULE(ath_ahb, nexus, ath_ahb_driver, ath_devclass, 0, 0);
+MODULE_VERSION(ath_ahb, 1);
+MODULE_DEPEND(ath_ahb, wlan, 1, 1, 1);          /* 802.11 media layer */
+MODULE_DEPEND(ath_ahb, if_ath, 1, 1, 1);        /* if_ath driver */
+MODULE_DEPEND(ath_ahb, ath_hal, 1, 1, 1);       /* Atheros HAL */
+MODULE_DEPEND(ath_ahb, ath_rate, 1, 1, 1);      /* rate control alg */
+MODULE_DEPEND(ath_ahb, ath_dfs, 1, 1, 1);      /* wtf */
index d820ac6..2551740 100644 (file)
 #include <sys/bus.h>
 #include <sys/malloc.h>
 #include <sys/proc.h>
 #include <sys/bus.h>
 #include <sys/malloc.h>
 #include <sys/proc.h>
-#include <sys/pcpu.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
-#include <sys/alq.h>
 #include <sys/endian.h>
 #include <sys/time.h>
 
 #include <sys/endian.h>
 #include <sys/time.h>
 
@@ -70,8 +68,8 @@ if_ath_alq_init(struct if_ath_alq *alq, const char *devname)
        bzero(alq, sizeof(*alq));
 
        strncpy(alq->sc_alq_devname, devname, ATH_ALQ_DEVNAME_LEN);
        bzero(alq, sizeof(*alq));
 
        strncpy(alq->sc_alq_devname, devname, ATH_ALQ_DEVNAME_LEN);
-       printf("%s (%s): attached\n", __func__, alq->sc_alq_devname);
-       snprintf(alq->sc_alq_filename, ATH_ALQ_FILENAME_LEN,
+       kprintf("%s (%s): attached\n", __func__, alq->sc_alq_devname);
+       ksnprintf(alq->sc_alq_filename, ATH_ALQ_FILENAME_LEN,
            "/tmp/ath_%s_alq.log", alq->sc_alq_devname);
 
        /* XXX too conservative, right? */
            "/tmp/ath_%s_alq.log", alq->sc_alq_devname);
 
        /* XXX too conservative, right? */
@@ -95,7 +93,7 @@ if_ath_alq_tidyup(struct if_ath_alq *alq)
 {
 
        if_ath_alq_stop(alq);
 {
 
        if_ath_alq_stop(alq);
-       printf("%s (%s): detached\n", __func__, alq->sc_alq_devname);
+       kprintf("%s (%s): detached\n", __func__, alq->sc_alq_devname);
        bzero(alq, sizeof(*alq));
 }
 
        bzero(alq, sizeof(*alq));
 }
 
@@ -115,10 +113,10 @@ if_ath_alq_start(struct if_ath_alq *alq)
            alq->sc_alq_qsize, 0);
 
        if (error != 0) {
            alq->sc_alq_qsize, 0);
 
        if (error != 0) {
-               printf("%s (%s): failed, err=%d\n", __func__,
+               kprintf("%s (%s): failed, err=%d\n", __func__,
                    alq->sc_alq_devname, error);
        } else {
                    alq->sc_alq_devname, error);
        } else {
-               printf("%s (%s): opened\n", __func__, alq->sc_alq_devname);
+               kprintf("%s (%s): opened\n", __func__, alq->sc_alq_devname);
                alq->sc_alq_isactive = 1;
                if_ath_alq_post(alq, ATH_ALQ_INIT_STATE,
                    sizeof (struct if_ath_alq_init_state),
                alq->sc_alq_isactive = 1;
                if_ath_alq_post(alq, ATH_ALQ_INIT_STATE,
                    sizeof (struct if_ath_alq_init_state),
@@ -134,7 +132,7 @@ if_ath_alq_stop(struct if_ath_alq *alq)
        if (alq->sc_alq_isactive == 0)
                return (0);
 
        if (alq->sc_alq_isactive == 0)
                return (0);
 
-       printf("%s (%s): closed\n", __func__, alq->sc_alq_devname);
+       kprintf("%s (%s): closed\n", __func__, alq->sc_alq_devname);
 
        alq->sc_alq_isactive = 0;
        alq_close(alq->sc_alq_alq);
 
        alq->sc_alq_isactive = 0;
        alq_close(alq->sc_alq_alq);
index 063f5ce..14b6e49 100644 (file)
@@ -201,8 +201,8 @@ ath_beacon_alloc(struct ath_softc *sc, struct ieee80211_node *ni)
                sc->sc_stats.ast_be_nombuf++;
                return ENOMEM;
        }
                sc->sc_stats.ast_be_nombuf++;
                return ENOMEM;
        }
-       error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m,
-                                    bf->bf_segs, &bf->bf_nseg,
+       error = bus_dmamap_load_mbuf_segment(sc->sc_dmat, bf->bf_dmamap, m,
+                                    bf->bf_segs, 1, &bf->bf_nseg,
                                     BUS_DMA_NOWAIT);
        if (error != 0) {
                device_printf(sc->sc_dev,
                                     BUS_DMA_NOWAIT);
        if (error != 0) {
                device_printf(sc->sc_dev,
@@ -712,8 +712,9 @@ ath_beacon_generate(struct ath_softc *sc, struct ieee80211vap *vap)
        if (ieee80211_beacon_update(bf->bf_node, &avp->av_boff, m, nmcastq)) {
                /* XXX too conservative? */
                bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
        if (ieee80211_beacon_update(bf->bf_node, &avp->av_boff, m, nmcastq)) {
                /* XXX too conservative? */
                bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
-               error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m,
-                                            bf->bf_segs, &bf->bf_nseg,
+               error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
+                                            bf->bf_dmamap, m,
+                                            bf->bf_segs, 1, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        if_printf(vap->iv_ifp,
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        if_printf(vap->iv_ifp,
@@ -823,8 +824,9 @@ ath_beacon_start_adhoc(struct ath_softc *sc, struct ieee80211vap *vap)
        if (ieee80211_beacon_update(bf->bf_node, &avp->av_boff, m, 0)) {
                /* XXX too conservative? */
                bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
        if (ieee80211_beacon_update(bf->bf_node, &avp->av_boff, m, 0)) {
                /* XXX too conservative? */
                bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
-               error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m,
-                                            bf->bf_segs, &bf->bf_nseg,
+               error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
+                                            bf->bf_dmamap, m,
+                                            bf->bf_segs, 1, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        if_printf(vap->iv_ifp,
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        if_printf(vap->iv_ifp,
index 27005dc..71dede7 100644 (file)
@@ -64,8 +64,6 @@
 #include <netinet/if_ether.h>
 #endif
 
 #include <netinet/if_ether.h>
 #endif
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_ath_btcoex.h>
 
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_ath_btcoex.h>
 
@@ -217,7 +215,7 @@ ath_btcoex_attach(struct ath_softc *sc)
 {
        int ret;
        struct ath_hal *ah = sc->sc_ah;
 {
        int ret;
        struct ath_hal *ah = sc->sc_ah;
-       const char *profname;
+       char *profname;
 
        /*
         * No chipset bluetooth coexistence? Then do nothing.
 
        /*
         * No chipset bluetooth coexistence? Then do nothing.
@@ -303,7 +301,7 @@ ath_btcoex_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
                /*
                 * Copy in data.
                 */
-               indata = malloc(insize, M_TEMP, M_NOWAIT);
+               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -320,7 +318,7 @@ ath_btcoex_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
-               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
+               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -336,9 +334,9 @@ ath_btcoex_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               free(indata, M_TEMP);
+               kfree(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               free(outdata, M_TEMP);
+               kfree(outdata, M_TEMP);
        return (error);
 }
 
        return (error);
 }
 
index 80d166e..76d7d22 100644 (file)
@@ -103,7 +103,7 @@ ath_printrxbuf(struct ath_softc *sc, const struct ath_buf *bf,
        int i;
 
        for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
        int i;
 
        for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
-               printf("R[%2u] (DS.V:%p DS.P:%p) L:%08x D:%08x%s\n"
+               kprintf("R[%2u] (DS.V:%p DS.P:%p) L:%08x D:%08x%s\n"
                       "      %08x %08x %08x %08x\n",
                    ix, ds, (const struct ath_desc *)bf->bf_daddr + i,
                    ds->ds_link, ds->ds_data,
                       "      %08x %08x %08x %08x\n",
                    ix, ds, (const struct ath_desc *)bf->bf_daddr + i,
                    ds->ds_link, ds->ds_data,
@@ -111,17 +111,17 @@ ath_printrxbuf(struct ath_softc *sc, const struct ath_buf *bf,
                    ds->ds_ctl0, ds->ds_ctl1,
                    ds->ds_hw[0], ds->ds_hw[1]);
                if (ah->ah_magic == 0x20065416) {
                    ds->ds_ctl0, ds->ds_ctl1,
                    ds->ds_hw[0], ds->ds_hw[1]);
                if (ah->ah_magic == 0x20065416) {
-                       printf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
                            ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
                            ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
                            ds->ds_hw[8]);
                } else if (ah->ah_magic == 0x19741014) {
                            ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
                            ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
                            ds->ds_hw[8]);
                } else if (ah->ah_magic == 0x19741014) {
-                       printf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
                            ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
                            ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
                            ds->ds_hw[8]);
 
                            ds->ds_hw[2], ds->ds_hw[3], ds->ds_hw[4],
                            ds->ds_hw[5], ds->ds_hw[6], ds->ds_hw[7],
                            ds->ds_hw[8]);
 
-                       printf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
                            ds->ds_hw[9], ds->ds_hw[10], ds->ds_hw[11],
                            ds->ds_hw[12], ds->ds_hw[13], ds->ds_hw[14],
                            ds->ds_hw[15]);
                            ds->ds_hw[9], ds->ds_hw[10], ds->ds_hw[11],
                            ds->ds_hw[12], ds->ds_hw[13], ds->ds_hw[14],
                            ds->ds_hw[15]);
@@ -140,7 +140,7 @@ ath_printtxbuf_edma(struct ath_softc *sc, const struct ath_buf *first_bf,
        const struct ath_desc_txedma *eds;
        int i, n;
 
        const struct ath_desc_txedma *eds;
        int i, n;
 
-       printf("Q%u[%3u] (nseg=%d)", qnum, ix, bf->bf_nseg);
+       kprintf("Q%u[%3u] (nseg=%d)", qnum, ix, bf->bf_nseg);
        while (bf != NULL) {
                /*
                 * XXX For now, assume the txmap size is 4.
        while (bf != NULL) {
                /*
                 * XXX For now, assume the txmap size is 4.
@@ -156,38 +156,38 @@ ath_printtxbuf_edma(struct ath_softc *sc, const struct ath_buf *first_bf,
                    i < n;
                    i ++, ds += sc->sc_tx_desclen) {
                        eds = (const struct ath_desc_txedma *) ds;
                    i < n;
                    i ++, ds += sc->sc_tx_desclen) {
                        eds = (const struct ath_desc_txedma *) ds;
-                       printf(" (DS.V:%p DS.P:%p) I: %08x L:%08x F:%04x%s\n",
+                       kprintf(" (DS.V:%p DS.P:%p) I: %08x L:%08x F:%04x%s\n",
                            eds, (const struct ath_desc *)bf->bf_daddr + i,
                            eds->ds_info, eds->ds_link,
                            bf->bf_state.bfs_txflags,
                            !done ? "" : (ts->ts_status == 0) ? " *" : " !");
                            eds, (const struct ath_desc *)bf->bf_daddr + i,
                            eds->ds_info, eds->ds_link,
                            bf->bf_state.bfs_txflags,
                            !done ? "" : (ts->ts_status == 0) ? " *" : " !");
-                       printf(" (D[0] = %08x(%08x), D[1] = %08x(%08x)\n",
+                       kprintf(" (D[0] = %08x(%08x), D[1] = %08x(%08x)\n",
                            eds->ds_hw[0], eds->ds_hw[1],
                            eds->ds_hw[2], eds->ds_hw[3]);
                            eds->ds_hw[0], eds->ds_hw[1],
                            eds->ds_hw[2], eds->ds_hw[3]);
-                       printf(" (D[2] = %08x(%08x), D[3] = %08x(%08x)\n",
+                       kprintf(" (D[2] = %08x(%08x), D[3] = %08x(%08x)\n",
                            eds->ds_hw[4], eds->ds_hw[5],
                            eds->ds_hw[6], eds->ds_hw[7]);
                            eds->ds_hw[4], eds->ds_hw[5],
                            eds->ds_hw[6], eds->ds_hw[7]);
-                       printf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
+                       kprintf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
                            bf->bf_state.bfs_seqno,
                            bf->bf_state.bfs_retries,
                            bf->bf_state.bfs_addedbaw,
                            bf->bf_state.bfs_dobaw);
                            bf->bf_state.bfs_seqno,
                            bf->bf_state.bfs_retries,
                            bf->bf_state.bfs_addedbaw,
                            bf->bf_state.bfs_dobaw);
-                       printf("        %08x %08x %08x %08x %08x %08x\n",
+                       kprintf("        %08x %08x %08x %08x %08x %08x\n",
                            eds->ds_hw[8], eds->ds_hw[9],
                            eds->ds_hw[10], eds->ds_hw[11],
                            eds->ds_hw[12], eds->ds_hw[13]);
                            eds->ds_hw[8], eds->ds_hw[9],
                            eds->ds_hw[10], eds->ds_hw[11],
                            eds->ds_hw[12], eds->ds_hw[13]);
-                       printf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
                            eds->ds_hw[14], eds->ds_hw[15], eds->ds_hw[16],
                            eds->ds_hw[17], eds->ds_hw[18], eds->ds_hw[19],
                            eds->ds_hw[20]);
 #if 0
                            eds->ds_hw[14], eds->ds_hw[15], eds->ds_hw[16],
                            eds->ds_hw[17], eds->ds_hw[18], eds->ds_hw[19],
                            eds->ds_hw[20]);
 #if 0
-                       printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
+                       kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
                            ds->ds_hw[22],ds->ds_hw[23],ds->ds_hw[24],
                            ds->ds_hw[25],ds->ds_hw[26],ds->ds_hw[27],
                            ds->ds_hw[28], ds->ds_hw[29]);
 #endif
                }
                            ds->ds_hw[22],ds->ds_hw[23],ds->ds_hw[24],
                            ds->ds_hw[25],ds->ds_hw[26],ds->ds_hw[27],
                            ds->ds_hw[28], ds->ds_hw[29]);
 #endif
                }
-               printf("  [end]\n");
+               kprintf("  [end]\n");
                bf = bf->bf_next;
        }
 }
                bf = bf->bf_next;
        }
 }
@@ -202,35 +202,35 @@ ath_printtxbuf_legacy(struct ath_softc *sc, const struct ath_buf *first_bf,
        const struct ath_desc *ds;
        int i;
 
        const struct ath_desc *ds;
        int i;
 
-       printf("Q%u[%3u]", qnum, ix);
+       kprintf("Q%u[%3u]", qnum, ix);
        while (bf != NULL) {
        while (bf != NULL) {
-               printf("    (bf=%p, lastds=%p)\n", bf, first_bf->bf_lastds);
-               printf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
+               kprintf("    (bf=%p, lastds=%p)\n", bf, first_bf->bf_lastds);
+               kprintf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
                    bf->bf_state.bfs_seqno,
                    bf->bf_state.bfs_retries,
                    bf->bf_state.bfs_addedbaw,
                    bf->bf_state.bfs_dobaw);
                for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
                    bf->bf_state.bfs_seqno,
                    bf->bf_state.bfs_retries,
                    bf->bf_state.bfs_addedbaw,
                    bf->bf_state.bfs_dobaw);
                for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) {
-                       printf(" (DS.V:%p DS.P:%p) L:%08x D:%08x F:%04x%s\n",
+                       kprintf(" (DS.V:%p DS.P:%p) L:%08x D:%08x F:%04x%s\n",
                            ds, (const struct ath_desc *)bf->bf_daddr + i,
                            ds->ds_link, ds->ds_data, bf->bf_state.bfs_txflags,
                            !done ? "" : (ts->ts_status == 0) ? " *" : " !");
                            ds, (const struct ath_desc *)bf->bf_daddr + i,
                            ds->ds_link, ds->ds_data, bf->bf_state.bfs_txflags,
                            !done ? "" : (ts->ts_status == 0) ? " *" : " !");
-                       printf("        %08x %08x %08x %08x %08x %08x\n",
+                       kprintf("        %08x %08x %08x %08x %08x %08x\n",
                            ds->ds_ctl0, ds->ds_ctl1,
                            ds->ds_hw[0], ds->ds_hw[1],
                            ds->ds_hw[2], ds->ds_hw[3]);
                        if (ah->ah_magic == 0x20065416) {
                            ds->ds_ctl0, ds->ds_ctl1,
                            ds->ds_hw[0], ds->ds_hw[1],
                            ds->ds_hw[2], ds->ds_hw[3]);
                        if (ah->ah_magic == 0x20065416) {
-                               printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
+                               kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
                                    ds->ds_hw[4], ds->ds_hw[5], ds->ds_hw[6],
                                    ds->ds_hw[7], ds->ds_hw[8], ds->ds_hw[9],
                                    ds->ds_hw[10],ds->ds_hw[11]);
                                    ds->ds_hw[4], ds->ds_hw[5], ds->ds_hw[6],
                                    ds->ds_hw[7], ds->ds_hw[8], ds->ds_hw[9],
                                    ds->ds_hw[10],ds->ds_hw[11]);
-                               printf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
+                               kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
                                    ds->ds_hw[12],ds->ds_hw[13],ds->ds_hw[14],
                                    ds->ds_hw[15],ds->ds_hw[16],ds->ds_hw[17],
                                    ds->ds_hw[18], ds->ds_hw[19]);
                        }
                }
                                    ds->ds_hw[12],ds->ds_hw[13],ds->ds_hw[14],
                                    ds->ds_hw[15],ds->ds_hw[16],ds->ds_hw[17],
                                    ds->ds_hw[18], ds->ds_hw[19]);
                        }
                }
-               printf("  [end]\n");
+               kprintf("  [end]\n");
                bf = bf->bf_next;
        }
 }
                bf = bf->bf_next;
        }
 }
@@ -250,10 +250,10 @@ ath_printtxstatbuf(struct ath_softc *sc, const struct ath_buf *first_bf,
        const uint32_t *ds, u_int qnum, u_int ix, int done)
 {
 
        const uint32_t *ds, u_int qnum, u_int ix, int done)
 {
 
-       printf("Q%u[%3u] ", qnum, ix);
-       printf("        %08x %08x %08x %08x %08x %08x\n",
+       kprintf("Q%u[%3u] ", qnum, ix);
+       kprintf("        %08x %08x %08x %08x %08x %08x\n",
            ds[0], ds[1], ds[2], ds[3], ds[4], ds[5]);
            ds[0], ds[1], ds[2], ds[3], ds[4], ds[5]);
-       printf("        %08x %08x %08x %08x %08x\n",
+       kprintf("        %08x %08x %08x %08x %08x\n",
            ds[6], ds[7], ds[8], ds[9], ds[10]);
 }
 
            ds[6], ds[7], ds[8], ds[9], ds[10]);
 }
 
index 0abe09c..1db07ec 100644 (file)
@@ -91,21 +91,21 @@ ath_keyprint(struct ath_softc *sc, const char *tag, u_int ix,
        };
        int i, n;
 
        };
        int i, n;
 
-       printf("%s: [%02u] %-7s ", tag, ix, ciphers[hk->kv_type]);
+       kprintf("%s: [%02u] %-7s ", tag, ix, ciphers[hk->kv_type]);
        for (i = 0, n = hk->kv_len; i < n; i++)
        for (i = 0, n = hk->kv_len; i < n; i++)
-               printf("%02x", hk->kv_val[i]);
-       printf(" mac %s", ether_sprintf(mac));
+               kprintf("%02x", hk->kv_val[i]);
+       kprintf(" mac %s", ath_hal_ether_sprintf(mac));
        if (hk->kv_type == HAL_CIPHER_TKIP) {
        if (hk->kv_type == HAL_CIPHER_TKIP) {
-               printf(" %s ", sc->sc_splitmic ? "mic" : "rxmic");
+               kprintf(" %s ", sc->sc_splitmic ? "mic" : "rxmic");
                for (i = 0; i < sizeof(hk->kv_mic); i++)
                for (i = 0; i < sizeof(hk->kv_mic); i++)
-                       printf("%02x", hk->kv_mic[i]);
+                       kprintf("%02x", hk->kv_mic[i]);
                if (!sc->sc_splitmic) {
                if (!sc->sc_splitmic) {
-                       printf(" txmic ");
+                       kprintf(" txmic ");
                        for (i = 0; i < sizeof(hk->kv_txmic); i++)
                        for (i = 0; i < sizeof(hk->kv_txmic); i++)
-                               printf("%02x", hk->kv_txmic[i]);
+                               kprintf("%02x", hk->kv_txmic[i]);
                }
        }
                }
        }
-       printf("\n");
+       kprintf("\n");
 }
 #endif
 
 }
 #endif
 
index e5d4189..376e201 100644 (file)
@@ -147,7 +147,9 @@ ath_led_done(void *arg)
 {
        struct ath_softc *sc = arg;
 
 {
        struct ath_softc *sc = arg;
 
+       wlan_serialize_enter();
        sc->sc_blinking = 0;
        sc->sc_blinking = 0;
+       wlan_serialize_exit();
 }
 
 /*
 }
 
 /*
@@ -159,8 +161,10 @@ ath_led_off(void *arg)
 {
        struct ath_softc *sc = arg;
 
 {
        struct ath_softc *sc = arg;
 
+       wlan_serialize_enter();
        ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
        callout_reset(&sc->sc_ledtimer, sc->sc_ledoff, ath_led_done, sc);
        ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
        callout_reset(&sc->sc_ledtimer, sc->sc_ledoff, ath_led_done, sc);
+       wlan_serialize_exit();
 }
 
 /*
 }
 
 /*
@@ -170,10 +174,12 @@ static void
 ath_led_blink(struct ath_softc *sc, int on, int off)
 {
        DPRINTF(sc, ATH_DEBUG_LED, "%s: on %u off %u\n", __func__, on, off);
 ath_led_blink(struct ath_softc *sc, int on, int off)
 {
        DPRINTF(sc, ATH_DEBUG_LED, "%s: on %u off %u\n", __func__, on, off);
+       wlan_serialize_enter();
        ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, sc->sc_ledon);
        sc->sc_blinking = 1;
        sc->sc_ledoff = off;
        callout_reset(&sc->sc_ledtimer, on, ath_led_off, sc);
        ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, sc->sc_ledon);
        sc->sc_blinking = 1;
        sc->sc_ledoff = off;
        callout_reset(&sc->sc_ledtimer, on, ath_led_off, sc);
+       wlan_serialize_exit();
 }
 
 void
 }
 
 void
index aaebfbc..64c098c 100644 (file)
@@ -64,8 +64,6 @@
 #include <netinet/if_ether.h>
 #endif
 
 #include <netinet/if_ether.h>
 #endif
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_ath_debug.h>
 #include <dev/netif/ath/ath/if_ath_lna_div.h>
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_ath_debug.h>
 #include <dev/netif/ath/ath/if_ath_lna_div.h>
@@ -93,8 +91,8 @@ ath_lna_div_attach(struct ath_softc *sc)
        if (! ath_hal_hasdivantcomb(sc->sc_ah))
                return (0);
 
        if (! ath_hal_hasdivantcomb(sc->sc_ah))
                return (0);
 
-       ss = malloc(sizeof(struct if_ath_ant_comb_state),
-           M_TEMP, M_WAITOK | M_ZERO);
+       ss = kmalloc(sizeof(struct if_ath_ant_comb_state),
+                    M_TEMP, M_WAITOK | M_ZERO);
        if (ss == NULL) {
                device_printf(sc->sc_dev, "%s: failed to allocate\n",
                    __func__);
        if (ss == NULL) {
                device_printf(sc->sc_dev, "%s: failed to allocate\n",
                    __func__);
@@ -128,7 +126,7 @@ int
 ath_lna_div_detach(struct ath_softc *sc)
 {
        if (sc->sc_lna_div != NULL) {
 ath_lna_div_detach(struct ath_softc *sc)
 {
        if (sc->sc_lna_div != NULL) {
-               free(sc->sc_lna_div, M_TEMP);
+               kfree(sc->sc_lna_div, M_TEMP);
                sc->sc_lna_div = NULL;
        }
        sc->sc_dolnadiv = 0;
                sc->sc_lna_div = NULL;
        }
        sc->sc_dolnadiv = 0;
@@ -167,7 +165,7 @@ ath_lna_div_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
                /*
                 * Copy in data.
                 */
-               indata = malloc(insize, M_TEMP, M_NOWAIT);
+               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -184,7 +182,7 @@ ath_lna_div_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
-               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
+               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -200,9 +198,9 @@ ath_lna_div_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               free(indata, M_TEMP);
+               kfree(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               free(outdata, M_TEMP);
+               kfree(outdata, M_TEMP);
        return (error);
 }
 
        return (error);
 }
 
index e7a9f16..322a0b1 100644 (file)
 
 #include <netproto/802_11/ieee80211_var.h>
 
 
 #include <netproto/802_11/ieee80211_var.h>
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 
 #include <dev/netif/ath/ath/if_athvar.h>
 
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcireg.h>
+#include <bus/pci/pcivar.h>
+#include <bus/pci/pcireg.h>
 
 /* For EEPROM firmware */
 #ifdef ATH_EEPROM_FIRMWARE
 
 /* For EEPROM firmware */
 #ifdef ATH_EEPROM_FIRMWARE
@@ -192,8 +190,9 @@ ath_pci_attach(device_t dev)
                goto bad1;
        }
        if (bus_setup_intr(dev, psc->sc_irq,
                goto bad1;
        }
        if (bus_setup_intr(dev, psc->sc_irq,
-                          INTR_TYPE_NET | INTR_MPSAFE,
-                          NULL, ath_intr, sc, &psc->sc_ih)) {
+                          INTR_MPSAFE,
+                          ath_intr, sc, &psc->sc_ih,
+                          &wlan_global_serializer)) {
                device_printf(dev, "could not establish interrupt\n");
                goto bad2;
        }
                device_printf(dev, "could not establish interrupt\n");
                goto bad2;
        }
@@ -202,7 +201,7 @@ ath_pci_attach(device_t dev)
         * Setup DMA descriptor area.
         */
        if (bus_dma_tag_create(bus_get_dma_tag(dev),    /* parent */
         * Setup DMA descriptor area.
         */
        if (bus_dma_tag_create(bus_get_dma_tag(dev),    /* parent */
-                              1, 0,                    /* alignment, bounds */
+                              4, 0,                    /* alignment, bounds */
                               BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
                               BUS_SPACE_MAXADDR,       /* highaddr */
                               NULL, NULL,              /* filter, filterarg */
                               BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
                               BUS_SPACE_MAXADDR,       /* highaddr */
                               NULL, NULL,              /* filter, filterarg */
@@ -210,8 +209,6 @@ ath_pci_attach(device_t dev)
                               ATH_MAX_SCATTER,         /* nsegments */
                               0x3ffff,                 /* maxsegsize XXX */
                               BUS_DMA_ALLOCNOW,        /* flags */
                               ATH_MAX_SCATTER,         /* nsegments */
                               0x3ffff,                 /* maxsegsize XXX */
                               BUS_DMA_ALLOCNOW,        /* flags */
-                              NULL,                    /* lockfunc */
-                              NULL,                    /* lockarg */
                               &sc->sc_dmat)) {
                device_printf(dev, "cannot allocate DMA tag\n");
                goto bad3;
                               &sc->sc_dmat)) {
                device_printf(dev, "cannot allocate DMA tag\n");
                goto bad3;
@@ -237,7 +234,7 @@ ath_pci_attach(device_t dev)
                device_printf(dev, "%s: EEPROM firmware @ %p\n",
                    __func__, fw->data);
                sc->sc_eepromdata =
                device_printf(dev, "%s: EEPROM firmware @ %p\n",
                    __func__, fw->data);
                sc->sc_eepromdata =
-                   malloc(fw->datasize, M_TEMP, M_WAITOK | M_ZERO);
+                   kmalloc(fw->datasize, M_TEMP, M_WAITOK | M_ZERO);
                if (! sc->sc_eepromdata) {
                        device_printf(dev, "%s: can't malloc eepromdata\n",
                            __func__);
                if (! sc->sc_eepromdata) {
                        device_printf(dev, "%s: can't malloc eepromdata\n",
                            __func__);
@@ -300,7 +297,7 @@ ath_pci_detach(device_t dev)
        bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, psc->sc_sr);
 
        if (sc->sc_eepromdata)
        bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, psc->sc_sr);
 
        if (sc->sc_eepromdata)
-               free(sc->sc_eepromdata, M_TEMP);
+               kfree(sc->sc_eepromdata, M_TEMP);
 
        ATH_TXSTATUS_LOCK_DESTROY(sc);
        ATH_PCU_LOCK_DESTROY(sc);
 
        ATH_TXSTATUS_LOCK_DESTROY(sc);
        ATH_PCU_LOCK_DESTROY(sc);
@@ -367,3 +364,6 @@ DRIVER_MODULE(ath_pci, pci, ath_pci_driver, ath_devclass, 0, 0);
 MODULE_VERSION(ath_pci, 1);
 MODULE_DEPEND(ath_pci, wlan, 1, 1, 1);         /* 802.11 media layer */
 MODULE_DEPEND(ath_pci, if_ath, 1, 1, 1);       /* if_ath driver */
 MODULE_VERSION(ath_pci, 1);
 MODULE_DEPEND(ath_pci, wlan, 1, 1, 1);         /* 802.11 media layer */
 MODULE_DEPEND(ath_pci, if_ath, 1, 1, 1);       /* if_ath driver */
+MODULE_DEPEND(ath_pci, ath_hal, 1, 1, 1);      /* Atheros HAL */
+MODULE_DEPEND(ath_pci, ath_rate, 1, 1, 1);     /* rate control alg */
+MODULE_DEPEND(ath_pci, ath_dfs, 1, 1, 1);      /* wtf */
index c3ceb57..35ef856 100644 (file)
@@ -76,6 +76,7 @@
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
+#include <net/ifq_var.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
@@ -247,9 +248,9 @@ ath_legacy_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
                }
                m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
 
                }
                m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
 
-               error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
+               error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
                                             bf->bf_dmamap, m,
                                             bf->bf_dmamap, m,
-                                            bf->bf_segs, &bf->bf_nseg,
+                                            bf->bf_segs, 1, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        DPRINTF(sc, ATH_DEBUG_ANY,
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        DPRINTF(sc, ATH_DEBUG_ANY,
@@ -1052,11 +1053,11 @@ rx_proc_next:
        }
 
        /* XXX check this inside of IF_LOCK? */
        }
 
        /* XXX check this inside of IF_LOCK? */
-       if (resched && (ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
+       if (resched && !ifq_is_oactive(&ifp->if_snd)) {
 #ifdef IEEE80211_SUPPORT_SUPERG
                ieee80211_ff_age_all(ic, 100);
 #endif
 #ifdef IEEE80211_SUPPORT_SUPERG
                ieee80211_ff_age_all(ic, 100);
 #endif
-               if (!IFQ_IS_EMPTY(&ifp->if_snd))
+               if (!ifq_is_empty(&ifp->if_snd))
                        ath_tx_kick(sc);
        }
 #undef PA2DESC
                        ath_tx_kick(sc);
        }
 #undef PA2DESC
index bc6a01c..a35e5c1 100644 (file)
@@ -76,6 +76,7 @@
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
+#include <net/ifq_var.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
@@ -446,19 +447,17 @@ ath_edma_recv_proc_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
 static void
 ath_edma_flush_deferred_queue(struct ath_softc *sc)
 {
 static void
 ath_edma_flush_deferred_queue(struct ath_softc *sc)
 {
-       struct ath_buf *bf, *next;
+       struct ath_buf *bf;
 
        ATH_RX_LOCK_ASSERT(sc);
 
        /* Free in one set, inside the lock */
 
        ATH_RX_LOCK_ASSERT(sc);
 
        /* Free in one set, inside the lock */
-       TAILQ_FOREACH_SAFE(bf,
-           &sc->sc_rx_rxlist[HAL_RX_QUEUE_LP], bf_list, next) {
-               /* Free the buffer/mbuf */
+       while ((bf = TAILQ_FIRST(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP])) != NULL) {
+               TAILQ_REMOVE(&sc->sc_rx_rxlist[HAL_RX_QUEUE_LP], bf, bf_list);
                ath_edma_rxbuf_free(sc, bf);
        }
                ath_edma_rxbuf_free(sc, bf);
        }
-       TAILQ_FOREACH_SAFE(bf,
-           &sc->sc_rx_rxlist[HAL_RX_QUEUE_HP], bf_list, next) {
-               /* Free the buffer/mbuf */
+       while ((bf = TAILQ_FIRST(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP])) != NULL) {
+               TAILQ_REMOVE(&sc->sc_rx_rxlist[HAL_RX_QUEUE_HP], bf, bf_list);
                ath_edma_rxbuf_free(sc, bf);
        }
 }
                ath_edma_rxbuf_free(sc, bf);
        }
 }
@@ -469,7 +468,7 @@ ath_edma_recv_proc_deferred_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
 {
        int ngood = 0;
        uint64_t tsf;
 {
        int ngood = 0;
        uint64_t tsf;
-       struct ath_buf *bf, *next;
+       struct ath_buf *bf;
        struct ath_rx_status *rs;
        int16_t nf;
        ath_bufhead rxlist;
        struct ath_rx_status *rs;
        int16_t nf;
        ath_bufhead rxlist;
@@ -491,7 +490,7 @@ ath_edma_recv_proc_deferred_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
        ATH_RX_UNLOCK(sc);
 
        /* Handle the completed descriptors */
        ATH_RX_UNLOCK(sc);
 
        /* Handle the completed descriptors */
-       TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
+       TAILQ_FOREACH(bf, &rxlist, bf_list) {
                /*
                 * Skip the RX descriptor status - start at the data offset
                 */
                /*
                 * Skip the RX descriptor status - start at the data offset
                 */
@@ -516,8 +515,10 @@ ath_edma_recv_proc_deferred_queue(struct ath_softc *sc, HAL_RX_QUEUE qtype,
 
        /* Free in one set, inside the lock */
        ATH_RX_LOCK(sc);
 
        /* Free in one set, inside the lock */
        ATH_RX_LOCK(sc);
-       TAILQ_FOREACH_SAFE(bf, &rxlist, bf_list, next) {
+
+       while ((bf = TAILQ_FIRST(&rxlist)) != NULL) {
                /* Free the buffer/mbuf */
                /* Free the buffer/mbuf */
+               TAILQ_REMOVE(&rxlist, bf, bf_list);
                ath_edma_rxbuf_free(sc, bf);
        }
        ATH_RX_UNLOCK(sc);
                ath_edma_rxbuf_free(sc, bf);
        }
        ATH_RX_UNLOCK(sc);
@@ -555,11 +556,11 @@ ath_edma_recv_tasklet(void *arg, int npending)
        ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 1);
 
        /* XXX inside IF_LOCK ? */
        ath_edma_recv_proc_deferred_queue(sc, HAL_RX_QUEUE_LP, 1);
 
        /* XXX inside IF_LOCK ? */
-       if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
+       if (!ifq_is_oactive(&ifp->if_snd)) {
 #ifdef IEEE80211_SUPPORT_SUPERG
                ieee80211_ff_age_all(ic, 100);
 #endif
 #ifdef IEEE80211_SUPPORT_SUPERG
                ieee80211_ff_age_all(ic, 100);
 #endif
-               if (! IFQ_IS_EMPTY(&ifp->if_snd))
+               if (!ifq_is_empty(&ifp->if_snd))
                        ath_tx_kick(sc);
        }
        if (ath_dfs_tasklet_needed(sc, sc->sc_curchan))
                        ath_tx_kick(sc);
        }
        if (ath_dfs_tasklet_needed(sc, sc->sc_curchan))
@@ -624,8 +625,8 @@ ath_edma_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
        /*
         * Create DMA mapping.
         */
        /*
         * Create DMA mapping.
         */
-       error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
-           bf->bf_dmamap, m, bf->bf_segs, &bf->bf_nseg, BUS_DMA_NOWAIT);
+       error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
+           bf->bf_dmamap, m, bf->bf_segs, 1, &bf->bf_nseg, BUS_DMA_NOWAIT);
 
        if (error != 0) {
                device_printf(sc->sc_dev, "%s: failed; error=%d\n",
 
        if (error != 0) {
                device_printf(sc->sc_dev, "%s: failed; error=%d\n",
@@ -838,9 +839,9 @@ ath_edma_setup_rxfifo(struct ath_softc *sc, HAL_RX_QUEUE qtype)
            re->m_fifolen);
 
        /* Allocate ath_buf FIFO array, pre-zero'ed */
            re->m_fifolen);
 
        /* Allocate ath_buf FIFO array, pre-zero'ed */
-       re->m_fifo = malloc(sizeof(struct ath_buf *) * re->m_fifolen,
+       re->m_fifo = kmalloc(sizeof(struct ath_buf *) * re->m_fifolen,
            M_ATHDEV,
            M_ATHDEV,
-           M_NOWAIT | M_ZERO);
+           M_INTWAIT | M_ZERO);
        if (re->m_fifo == NULL) {
                device_printf(sc->sc_dev, "%s: malloc failed\n",
                    __func__);
        if (re->m_fifo == NULL) {
                device_printf(sc->sc_dev, "%s: malloc failed\n",
                    __func__);
@@ -865,7 +866,7 @@ ath_edma_rxfifo_free(struct ath_softc *sc, HAL_RX_QUEUE qtype)
            __func__,
            qtype);
        
            __func__,
            qtype);
        
-       free(re->m_fifo, M_ATHDEV);
+       kfree(re->m_fifo, M_ATHDEV);
 
        return (0);
 }
 
        return (0);
 }
index 25a1951..38d9574 100644 (file)
@@ -63,8 +63,6 @@
 #include <netinet/if_ether.h>
 #endif
 
 #include <netinet/if_ether.h>
 #endif
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_ath_spectral.h>
 
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_ath_spectral.h>
 
@@ -108,7 +106,7 @@ ath_spectral_attach(struct ath_softc *sc)
        if (! ath_hal_spectral_supported(sc->sc_ah))
                return (0);
 
        if (! ath_hal_spectral_supported(sc->sc_ah))
                return (0);
 
-       ss = malloc(sizeof(struct ath_spectral_state),
+       ss = kmalloc(sizeof(struct ath_spectral_state),
            M_TEMP, M_WAITOK | M_ZERO);
 
        if (ss == NULL) {
            M_TEMP, M_WAITOK | M_ZERO);
 
        if (ss == NULL) {
@@ -135,7 +133,7 @@ ath_spectral_detach(struct ath_softc *sc)
                return (0);
 
        if (sc->sc_spectral != NULL) {
                return (0);
 
        if (sc->sc_spectral != NULL) {
-               free(sc->sc_spectral, M_TEMP);
+               kfree(sc->sc_spectral, M_TEMP);
        }
        return (0);
 }
        }
        return (0);
 }
@@ -192,7 +190,7 @@ ath_ioctl_spectral(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
                /*
                 * Copy in data.
                 */
-               indata = malloc(insize, M_TEMP, M_NOWAIT);
+               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -209,7 +207,7 @@ ath_ioctl_spectral(struct ath_softc *sc, struct ath_diag *ad)
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
-               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
+               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -279,9 +277,9 @@ ath_ioctl_spectral(struct ath_softc *sc, struct ath_diag *ad)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               free(indata, M_TEMP);
+               kfree(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               free(outdata, M_TEMP);
+               kfree(outdata, M_TEMP);
        return (error);
 }
 
        return (error);
 }
 
index 16557b8..6443142 100644 (file)
@@ -105,51 +105,66 @@ static int
 ath_sysctl_slottime(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 ath_sysctl_slottime(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       u_int slottime = ath_hal_getslottime(sc->sc_ah);
+       u_int slottime;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       slottime = ath_hal_getslottime(sc->sc_ah);
        error = sysctl_handle_int(oidp, &slottime, 0, req);
        error = sysctl_handle_int(oidp, &slottime, 0, req);
-       if (error || !req->newptr)
-               return error;
-       return !ath_hal_setslottime(sc->sc_ah, slottime) ? EINVAL : 0;
+       if (error == 0 && req->newptr)
+               error = !ath_hal_setslottime(sc->sc_ah, slottime) ? EINVAL : 0;
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 ath_sysctl_acktimeout(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 }
 
 static int
 ath_sysctl_acktimeout(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       u_int acktimeout = ath_hal_getacktimeout(sc->sc_ah);
+       u_int acktimeout;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       acktimeout = ath_hal_getacktimeout(sc->sc_ah);
        error = sysctl_handle_int(oidp, &acktimeout, 0, req);
        error = sysctl_handle_int(oidp, &acktimeout, 0, req);
-       if (error || !req->newptr)
-               return error;
-       return !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0;
+       if (error == 0 && req->newptr) {
+               error = !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ?
+                       EINVAL : 0;
+       }
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 ath_sysctl_ctstimeout(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 }
 
 static int
 ath_sysctl_ctstimeout(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       u_int ctstimeout = ath_hal_getctstimeout(sc->sc_ah);
+       u_int ctstimeout;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       ctstimeout = ath_hal_getctstimeout(sc->sc_ah);
        error = sysctl_handle_int(oidp, &ctstimeout, 0, req);
        error = sysctl_handle_int(oidp, &ctstimeout, 0, req);
-       if (error || !req->newptr)
-               return error;
-       return !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0;
+       if (error == 0 && req->newptr) {
+               error = !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ?
+                       EINVAL : 0;
+       }
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 ath_sysctl_softled(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 }
 
 static int
 ath_sysctl_softled(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       int softled = sc->sc_softled;
+       int softled;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       softled = sc->sc_softled;
        error = sysctl_handle_int(oidp, &softled, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &softled, 0, req);
        if (error || !req->newptr)
-               return error;
+               goto done;
        softled = (softled != 0);
        if (softled != sc->sc_softled) {
                if (softled) {
        softled = (softled != 0);
        if (softled != sc->sc_softled) {
                if (softled) {
@@ -158,38 +173,48 @@ ath_sysctl_softled(SYSCTL_HANDLER_ARGS)
                }
                sc->sc_softled = softled;
        }
                }
                sc->sc_softled = softled;
        }
-       return 0;
+       error = 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 ath_sysctl_ledpin(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 }
 
 static int
 ath_sysctl_ledpin(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       int ledpin = sc->sc_ledpin;
+       int ledpin;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       ledpin = sc->sc_ledpin;
        error = sysctl_handle_int(oidp, &ledpin, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &ledpin, 0, req);
        if (error || !req->newptr)
-               return error;
+               goto done;
        if (ledpin != sc->sc_ledpin) {
                sc->sc_ledpin = ledpin;
                if (sc->sc_softled) {
                        ath_led_config(sc);
                }
        }
        if (ledpin != sc->sc_ledpin) {
                sc->sc_ledpin = ledpin;
                if (sc->sc_softled) {
                        ath_led_config(sc);
                }
        }
-       return 0;
+       error = 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 ath_sysctl_hardled(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 }
 
 static int
 ath_sysctl_hardled(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       int hardled = sc->sc_hardled;
+       int hardled;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       hardled = sc->sc_hardled;
        error = sysctl_handle_int(oidp, &hardled, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &hardled, 0, req);
        if (error || !req->newptr)
-               return error;
+               goto done;
        hardled = (hardled != 0);
        if (hardled != sc->sc_hardled) {
                if (hardled) {
        hardled = (hardled != 0);
        if (hardled != sc->sc_hardled) {
                if (hardled) {
@@ -198,21 +223,29 @@ ath_sysctl_hardled(SYSCTL_HANDLER_ARGS)
                }
                sc->sc_hardled = hardled;
        }
                }
                sc->sc_hardled = hardled;
        }
-       return 0;
+       error = 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 ath_sysctl_txantenna(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 }
 
 static int
 ath_sysctl_txantenna(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       u_int txantenna = ath_hal_getantennaswitch(sc->sc_ah);
+       u_int txantenna;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       txantenna = ath_hal_getantennaswitch(sc->sc_ah);
        error = sysctl_handle_int(oidp, &txantenna, 0, req);
        if (!error && req->newptr) {
                /* XXX assumes 2 antenna ports */
        error = sysctl_handle_int(oidp, &txantenna, 0, req);
        if (!error && req->newptr) {
                /* XXX assumes 2 antenna ports */
-               if (txantenna < HAL_ANT_VARIABLE || txantenna > HAL_ANT_FIXED_B)
-                       return EINVAL;
+               if (txantenna < HAL_ANT_VARIABLE ||
+                   txantenna > HAL_ANT_FIXED_B) {
+                       error = EINVAL;
+                       goto done;
+               }
                ath_hal_setantennaswitch(sc->sc_ah, txantenna);
                /*
                 * NB: with the switch locked this isn't meaningful,
                ath_hal_setantennaswitch(sc->sc_ah, txantenna);
                /*
                 * NB: with the switch locked this isn't meaningful,
@@ -221,6 +254,9 @@ ath_sysctl_txantenna(SYSCTL_HANDLER_ARGS)
                 */
                sc->sc_txantenna = txantenna;
        }
                 */
                sc->sc_txantenna = txantenna;
        }
+       error = 0;
+done:
+       wlan_serialize_exit();
        return error;
 }
 
        return error;
 }
 
@@ -228,12 +264,15 @@ static int
 ath_sysctl_rxantenna(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 ath_sysctl_rxantenna(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       u_int defantenna = ath_hal_getdefantenna(sc->sc_ah);
+       u_int defantenna;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       defantenna = ath_hal_getdefantenna(sc->sc_ah);
        error = sysctl_handle_int(oidp, &defantenna, 0, req);
        if (!error && req->newptr)
                ath_hal_setdefantenna(sc->sc_ah, defantenna);
        error = sysctl_handle_int(oidp, &defantenna, 0, req);
        if (!error && req->newptr)
                ath_hal_setdefantenna(sc->sc_ah, defantenna);
+       wlan_serialize_exit();
        return error;
 }
 
        return error;
 }
 
@@ -241,16 +280,23 @@ static int
 ath_sysctl_diversity(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 ath_sysctl_diversity(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       u_int diversity = ath_hal_getdiversity(sc->sc_ah);
+       u_int diversity;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       diversity = ath_hal_getdiversity(sc->sc_ah);
        error = sysctl_handle_int(oidp, &diversity, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &diversity, 0, req);
        if (error || !req->newptr)
-               return error;
-       if (!ath_hal_setdiversity(sc->sc_ah, diversity))
-               return EINVAL;
+               goto done;
+       if (!ath_hal_setdiversity(sc->sc_ah, diversity)) {
+               error = EINVAL;
+               goto done;
+       }
        sc->sc_diversity = diversity;
        sc->sc_diversity = diversity;
-       return 0;
+       error = 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 }
 
 static int
@@ -260,12 +306,18 @@ ath_sysctl_diag(SYSCTL_HANDLER_ARGS)
        u_int32_t diag;
        int error;
 
        u_int32_t diag;
        int error;
 
-       if (!ath_hal_getdiag(sc->sc_ah, &diag))
-               return EINVAL;
+       wlan_serialize_enter();
+       if (!ath_hal_getdiag(sc->sc_ah, &diag)) {
+               error = EINVAL;
+               goto done;
+       }
        error = sysctl_handle_int(oidp, &diag, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &diag, 0, req);
        if (error || !req->newptr)
-               return error;
-       return !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0;
+               goto done;
+       error = !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 }
 
 static int
@@ -276,26 +328,35 @@ ath_sysctl_tpscale(SYSCTL_HANDLER_ARGS)
        u_int32_t scale;
        int error;
 
        u_int32_t scale;
        int error;
 
+       wlan_serialize_enter();
        (void) ath_hal_gettpscale(sc->sc_ah, &scale);
        error = sysctl_handle_int(oidp, &scale, 0, req);
        if (error || !req->newptr)
        (void) ath_hal_gettpscale(sc->sc_ah, &scale);
        error = sysctl_handle_int(oidp, &scale, 0, req);
        if (error || !req->newptr)
-               return error;
-       return !ath_hal_settpscale(sc->sc_ah, scale) ? EINVAL :
-           (ifp->if_drv_flags & IFF_DRV_RUNNING) ?
+               goto done;
+       error = !ath_hal_settpscale(sc->sc_ah, scale) ? EINVAL :
+           (ifp->if_flags & IFF_RUNNING) ?
              ath_reset(ifp, ATH_RESET_NOLOSS) : 0;
              ath_reset(ifp, ATH_RESET_NOLOSS) : 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 ath_sysctl_tpc(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
 }
 
 static int
 ath_sysctl_tpc(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       u_int tpc = ath_hal_gettpc(sc->sc_ah);
+       u_int tpc;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       tpc = ath_hal_gettpc(sc->sc_ah);
        error = sysctl_handle_int(oidp, &tpc, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &tpc, 0, req);
        if (error || !req->newptr)
-               return error;
-       return !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0;
+               goto done;
+       error = !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 }
 
 static int
@@ -304,18 +365,29 @@ ath_sysctl_rfkill(SYSCTL_HANDLER_ARGS)
        struct ath_softc *sc = arg1;
        struct ifnet *ifp = sc->sc_ifp;
        struct ath_hal *ah = sc->sc_ah;
        struct ath_softc *sc = arg1;
        struct ifnet *ifp = sc->sc_ifp;
        struct ath_hal *ah = sc->sc_ah;
-       u_int rfkill = ath_hal_getrfkill(ah);
+       u_int rfkill;
        int error;
 
        int error;
 
+       wlan_serialize_enter();
+       rfkill = ath_hal_getrfkill(ah);
        error = sysctl_handle_int(oidp, &rfkill, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &rfkill, 0, req);
        if (error || !req->newptr)
-               return error;
-       if (rfkill == ath_hal_getrfkill(ah))    /* unchanged */
-               return 0;
-       if (!ath_hal_setrfkill(ah, rfkill))
-               return EINVAL;
-       return (ifp->if_drv_flags & IFF_DRV_RUNNING) ?
-           ath_reset(ifp, ATH_RESET_FULL) : 0;
+               goto done;
+       if (rfkill == ath_hal_getrfkill(ah)) {  /* unchanged */
+               error = 0;
+               goto done;
+       }
+       if (!ath_hal_setrfkill(ah, rfkill)) {
+               error = EINVAL;
+               goto done;
+       }
+       if (ifp->if_flags & IFF_RUNNING)
+               error = ath_reset(ifp, ATH_RESET_FULL);
+       else
+               error = 0;
+done:
+       wlan_serialize_exit();
+       return 0;
 }
 
 static int
 }
 
 static int
@@ -333,33 +405,34 @@ ath_sysctl_txagg(SYSCTL_HANDLER_ARGS)
        if (param != 1)
                return 0;
 
        if (param != 1)
                return 0;
 
-       printf("no tx bufs (empty list): %d\n", sc->sc_stats.ast_tx_getnobuf);
-       printf("no tx bufs (was busy): %d\n", sc->sc_stats.ast_tx_getbusybuf);
+       kprintf("no tx bufs (empty list): %d\n", sc->sc_stats.ast_tx_getnobuf);
+       kprintf("no tx bufs (was busy): %d\n", sc->sc_stats.ast_tx_getbusybuf);
 
 
-       printf("aggr single packet: %d\n",
+       kprintf("aggr single packet: %d\n",
            sc->sc_aggr_stats.aggr_single_pkt);
            sc->sc_aggr_stats.aggr_single_pkt);
-       printf("aggr single packet w/ BAW closed: %d\n",
+       kprintf("aggr single packet w/ BAW closed: %d\n",
            sc->sc_aggr_stats.aggr_baw_closed_single_pkt);
            sc->sc_aggr_stats.aggr_baw_closed_single_pkt);
-       printf("aggr non-baw packet: %d\n",
+       kprintf("aggr non-baw packet: %d\n",
            sc->sc_aggr_stats.aggr_nonbaw_pkt);
            sc->sc_aggr_stats.aggr_nonbaw_pkt);
-       printf("aggr aggregate packet: %d\n",
+       kprintf("aggr aggregate packet: %d\n",
            sc->sc_aggr_stats.aggr_aggr_pkt);
            sc->sc_aggr_stats.aggr_aggr_pkt);
-       printf("aggr single packet low hwq: %d\n",
+       kprintf("aggr single packet low hwq: %d\n",
            sc->sc_aggr_stats.aggr_low_hwq_single_pkt);
            sc->sc_aggr_stats.aggr_low_hwq_single_pkt);
-       printf("aggr single packet RTS aggr limited: %d\n",
+       kprintf("aggr single packet RTS aggr limited: %d\n",
            sc->sc_aggr_stats.aggr_rts_aggr_limited);
            sc->sc_aggr_stats.aggr_rts_aggr_limited);
-       printf("aggr sched, no work: %d\n",
+       kprintf("aggr sched, no work: %d\n",
            sc->sc_aggr_stats.aggr_sched_nopkt);
        for (i = 0; i < 64; i++) {
            sc->sc_aggr_stats.aggr_sched_nopkt);
        for (i = 0; i < 64; i++) {
-               printf("%2d: %10d ", i, sc->sc_aggr_stats.aggr_pkts[i]);
+               kprintf("%2d: %10d ", i, sc->sc_aggr_stats.aggr_pkts[i]);
                if (i % 4 == 3)
                if (i % 4 == 3)
-                       printf("\n");
+                       kprintf("\n");
        }
        }
-       printf("\n");
+       kprintf("\n");
 
 
+       wlan_serialize_enter();
        for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
                if (ATH_TXQ_SETUP(sc, i)) {
        for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
                if (ATH_TXQ_SETUP(sc, i)) {
-                       printf("HW TXQ %d: axq_depth=%d, axq_aggr_depth=%d, "
+                       kprintf("HW TXQ %d: axq_depth=%d, axq_aggr_depth=%d, "
                            "axq_fifo_depth=%d, holdingbf=%p\n",
                            i,
                            sc->sc_txq[i].axq_depth,
                            "axq_fifo_depth=%d, holdingbf=%p\n",
                            i,
                            sc->sc_txq[i].axq_depth,
@@ -373,31 +446,31 @@ ath_sysctl_txagg(SYSCTL_HANDLER_ARGS)
        ATH_TXBUF_LOCK(sc);
        TAILQ_FOREACH(bf, &sc->sc_txbuf, bf_list) {
                if (bf->bf_flags & ATH_BUF_BUSY) {
        ATH_TXBUF_LOCK(sc);
        TAILQ_FOREACH(bf, &sc->sc_txbuf, bf_list) {
                if (bf->bf_flags & ATH_BUF_BUSY) {
-                       printf("Busy: %d\n", t);
+                       kprintf("Busy: %d\n", t);
                        i++;
                }
                t++;
        }
        ATH_TXBUF_UNLOCK(sc);
                        i++;
                }
                t++;
        }
        ATH_TXBUF_UNLOCK(sc);
-       printf("Total TX buffers: %d; Total TX buffers busy: %d (%d)\n",
+       kprintf("Total TX buffers: %d; Total TX buffers busy: %d (%d)\n",
            t, i, sc->sc_txbuf_cnt);
 
        i = t = 0;
        ATH_TXBUF_LOCK(sc);
        TAILQ_FOREACH(bf, &sc->sc_txbuf_mgmt, bf_list) {
                if (bf->bf_flags & ATH_BUF_BUSY) {
            t, i, sc->sc_txbuf_cnt);
 
        i = t = 0;
        ATH_TXBUF_LOCK(sc);
        TAILQ_FOREACH(bf, &sc->sc_txbuf_mgmt, bf_list) {
                if (bf->bf_flags & ATH_BUF_BUSY) {
-                       printf("Busy: %d\n", t);
+                       kprintf("Busy: %d\n", t);
                        i++;
                }
                t++;
        }
        ATH_TXBUF_UNLOCK(sc);
                        i++;
                }
                t++;
        }
        ATH_TXBUF_UNLOCK(sc);
-       printf("Total mgmt TX buffers: %d; Total mgmt TX buffers busy: %d\n",
+       kprintf("Total mgmt TX buffers: %d; Total mgmt TX buffers busy: %d\n",
            t, i);
 
        ATH_RX_LOCK(sc);
        for (i = 0; i < 2; i++) {
            t, i);
 
        ATH_RX_LOCK(sc);
        for (i = 0; i < 2; i++) {
-               printf("%d: fifolen: %d/%d; head=%d; tail=%d\n",
+               kprintf("%d: fifolen: %d/%d; head=%d; tail=%d\n",
                    i,
                    sc->sc_rxedma[i].m_fifo_depth,
                    sc->sc_rxedma[i].m_fifolen,
                    i,
                    sc->sc_rxedma[i].m_fifo_depth,
                    sc->sc_rxedma[i].m_fifolen,
@@ -408,9 +481,10 @@ ath_sysctl_txagg(SYSCTL_HANDLER_ARGS)
        TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) {
                i++;
        }
        TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) {
                i++;
        }
-       printf("Total RX buffers in free list: %d buffers\n",
+       kprintf("Total RX buffers in free list: %d buffers\n",
            i);
        ATH_RX_UNLOCK(sc);
            i);
        ATH_RX_UNLOCK(sc);
+       wlan_serialize_exit();
 
        return 0;
 }
 
        return 0;
 }
@@ -422,15 +496,20 @@ ath_sysctl_rfsilent(SYSCTL_HANDLER_ARGS)
        u_int rfsilent;
        int error;
 
        u_int rfsilent;
        int error;
 
+       wlan_serialize_enter();
        (void) ath_hal_getrfsilent(sc->sc_ah, &rfsilent);
        error = sysctl_handle_int(oidp, &rfsilent, 0, req);
        if (error || !req->newptr)
        (void) ath_hal_getrfsilent(sc->sc_ah, &rfsilent);
        error = sysctl_handle_int(oidp, &rfsilent, 0, req);
        if (error || !req->newptr)
-               return error;
-       if (!ath_hal_setrfsilent(sc->sc_ah, rfsilent))
-               return EINVAL;
+               goto done;
+       if (!ath_hal_setrfsilent(sc->sc_ah, rfsilent)) {
+               error = EINVAL;
+               goto done;
+       }
        sc->sc_rfsilentpin = rfsilent & 0x1c;
        sc->sc_rfsilentpol = (rfsilent & 0x2) != 0;
        sc->sc_rfsilentpin = rfsilent & 0x1c;
        sc->sc_rfsilentpol = (rfsilent & 0x2) != 0;
-       return 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 }
 
 static int
@@ -440,11 +519,15 @@ ath_sysctl_tpack(SYSCTL_HANDLER_ARGS)
        u_int32_t tpack;
        int error;
 
        u_int32_t tpack;
        int error;
 
+       wlan_serialize_enter();
        (void) ath_hal_gettpack(sc->sc_ah, &tpack);
        error = sysctl_handle_int(oidp, &tpack, 0, req);
        if (error || !req->newptr)
        (void) ath_hal_gettpack(sc->sc_ah, &tpack);
        error = sysctl_handle_int(oidp, &tpack, 0, req);
        if (error || !req->newptr)
-               return error;
-       return !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0;
+               goto done;
+       error = !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 }
 
 static int
@@ -454,11 +537,15 @@ ath_sysctl_tpcts(SYSCTL_HANDLER_ARGS)
        u_int32_t tpcts;
        int error;
 
        u_int32_t tpcts;
        int error;
 
+       wlan_serialize_enter();
        (void) ath_hal_gettpcts(sc->sc_ah, &tpcts);
        error = sysctl_handle_int(oidp, &tpcts, 0, req);
        if (error || !req->newptr)
        (void) ath_hal_gettpcts(sc->sc_ah, &tpcts);
        error = sysctl_handle_int(oidp, &tpcts, 0, req);
        if (error || !req->newptr)
-               return error;
-       return !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0;
+               goto done;
+       error = !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 }
 
 static int
@@ -467,25 +554,30 @@ ath_sysctl_intmit(SYSCTL_HANDLER_ARGS)
        struct ath_softc *sc = arg1;
        int intmit, error;
 
        struct ath_softc *sc = arg1;
        int intmit, error;
 
+       wlan_serialize_enter();
        intmit = ath_hal_getintmit(sc->sc_ah);
        error = sysctl_handle_int(oidp, &intmit, 0, req);
        if (error || !req->newptr)
        intmit = ath_hal_getintmit(sc->sc_ah);
        error = sysctl_handle_int(oidp, &intmit, 0, req);
        if (error || !req->newptr)
-               return error;
+               goto done;
 
        /* reusing error; 1 here means "good"; 0 means "fail" */
        error = ath_hal_setintmit(sc->sc_ah, intmit);
 
        /* reusing error; 1 here means "good"; 0 means "fail" */
        error = ath_hal_setintmit(sc->sc_ah, intmit);
-       if (! error)
-               return EINVAL;
+       if (!error) {
+               error = EINVAL;
+               goto done;
+       }
 
        /*
         * Reset the hardware here - disabling ANI in the HAL
         * doesn't reset ANI related registers, so it'll leave
         * things in an inconsistent state.
         */
 
        /*
         * Reset the hardware here - disabling ANI in the HAL
         * doesn't reset ANI related registers, so it'll leave
         * things in an inconsistent state.
         */
-       if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
+       if (sc->sc_ifp->if_flags & IFF_RUNNING)
                ath_reset(sc->sc_ifp, ATH_RESET_NOLOSS);
                ath_reset(sc->sc_ifp, ATH_RESET_NOLOSS);
-
-       return 0;
+       error = 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 #ifdef IEEE80211_SUPPORT_TDMA
 }
 
 #ifdef IEEE80211_SUPPORT_TDMA
@@ -495,12 +587,15 @@ ath_sysctl_setcca(SYSCTL_HANDLER_ARGS)
        struct ath_softc *sc = arg1;
        int setcca, error;
 
        struct ath_softc *sc = arg1;
        int setcca, error;
 
+       wlan_serialize_enter();
        setcca = sc->sc_setcca;
        error = sysctl_handle_int(oidp, &setcca, 0, req);
        if (error || !req->newptr)
        setcca = sc->sc_setcca;
        error = sysctl_handle_int(oidp, &setcca, 0, req);
        if (error || !req->newptr)
-               return error;
+               goto done;
        sc->sc_setcca = (setcca != 0);
        sc->sc_setcca = (setcca != 0);
-       return 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 #endif /* IEEE80211_SUPPORT_TDMA */
 
 }
 #endif /* IEEE80211_SUPPORT_TDMA */
 
@@ -511,15 +606,18 @@ ath_sysctl_forcebstuck(SYSCTL_HANDLER_ARGS)
        int val = 0;
        int error;
 
        int val = 0;
        int error;
 
+       wlan_serialize_enter();
        error = sysctl_handle_int(oidp, &val, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &val, 0, req);
        if (error || !req->newptr)
-               return error;
+               goto done;
        if (val == 0)
        if (val == 0)
-               return 0;
+               goto done;
 
        taskqueue_enqueue_fast(sc->sc_tq, &sc->sc_bstucktask);
        val = 0;
 
        taskqueue_enqueue_fast(sc->sc_tq, &sc->sc_bstucktask);
        val = 0;
-       return 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 static int
 }
 
 static int
@@ -540,14 +638,19 @@ ath_sysctl_hangcheck(SYSCTL_HANDLER_ARGS)
                return 0;
 
        /* Do a hang check */
                return 0;
 
        /* Do a hang check */
+       wlan_serialize_enter();
        if (!ath_hal_getdiagstate(ah, HAL_DIAG_CHECK_HANGS,
            &mask, sizeof(mask),
        if (!ath_hal_getdiagstate(ah, HAL_DIAG_CHECK_HANGS,
            &mask, sizeof(mask),
-           (void *) &sp, &rsize))
-               return (0);
+           (void *) &sp, &rsize)) {
+               goto done;
+       }
        device_printf(sc->sc_dev, "%s: sp=0x%08x\n", __func__, *sp);
 
        val = 0;
        device_printf(sc->sc_dev, "%s: sp=0x%08x\n", __func__, *sp);
 
        val = 0;
-       return 0;
+       error = 0;
+done:
+       wlan_serialize_exit();
+       return error;
 }
 
 #ifdef ATH_DEBUG_ALQ
 }
 
 #ifdef ATH_DEBUG_ALQ
@@ -557,15 +660,17 @@ ath_sysctl_alq_log(SYSCTL_HANDLER_ARGS)
        struct ath_softc *sc = arg1;
        int error, enable;
 
        struct ath_softc *sc = arg1;
        int error, enable;
 
+       wlan_serialize_enter();
        enable = (sc->sc_alq.sc_alq_isactive);
        enable = (sc->sc_alq.sc_alq_isactive);
-
        error = sysctl_handle_int(oidp, &enable, 0, req);
        if (error || !req->newptr)
        error = sysctl_handle_int(oidp, &enable, 0, req);
        if (error || !req->newptr)
-               return (error);
-       else if (enable)
+               goto done;
+       if (enable)
                error = if_ath_alq_start(&sc->sc_alq);
        else
                error = if_ath_alq_stop(&sc->sc_alq);
                error = if_ath_alq_start(&sc->sc_alq);
        else
                error = if_ath_alq_stop(&sc->sc_alq);
+done:
+       wlan_serialize_exit();
        return (error);
 }
 
        return (error);
 }
 
@@ -575,8 +680,8 @@ ath_sysctl_alq_log(SYSCTL_HANDLER_ARGS)
 static void
 ath_sysctl_alq_attach(struct ath_softc *sc)
 {
 static void
 ath_sysctl_alq_attach(struct ath_softc *sc)
 {
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
 
        tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "alq", CTLFLAG_RD,
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
 
        tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "alq", CTLFLAG_RD,
@@ -603,8 +708,8 @@ ath_sysctl_alq_attach(struct ath_softc *sc)
 void
 ath_sysctlattach(struct ath_softc *sc)
 {
 void
 ath_sysctlattach(struct ath_softc *sc)
 {
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
        struct ath_hal *ah = sc->sc_ah;
 
        SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
        struct ath_hal *ah = sc->sc_ah;
 
        SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
@@ -804,9 +909,11 @@ ath_sysctl_clearstats(SYSCTL_HANDLER_ARGS)
                return error;
        if (val == 0)
                return 0;       /* Not clearing the stats is still valid */
                return error;
        if (val == 0)
                return 0;       /* Not clearing the stats is still valid */
+       wlan_serialize_enter();
        memset(&sc->sc_stats, 0, sizeof(sc->sc_stats));
        memset(&sc->sc_aggr_stats, 0, sizeof(sc->sc_aggr_stats));
        memset(&sc->sc_intr_stats, 0, sizeof(sc->sc_intr_stats));
        memset(&sc->sc_stats, 0, sizeof(sc->sc_stats));
        memset(&sc->sc_aggr_stats, 0, sizeof(sc->sc_aggr_stats));
        memset(&sc->sc_intr_stats, 0, sizeof(sc->sc_intr_stats));
+       wlan_serialize_exit();
 
        val = 0;
        return 0;
 
        val = 0;
        return 0;
@@ -815,8 +922,8 @@ ath_sysctl_clearstats(SYSCTL_HANDLER_ARGS)
 static void
 ath_sysctl_stats_attach_rxphyerr(struct ath_softc *sc, struct sysctl_oid_list *parent)
 {
 static void
 ath_sysctl_stats_attach_rxphyerr(struct ath_softc *sc, struct sysctl_oid_list *parent)
 {
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
        int i;
        char sn[8];
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
        int i;
        char sn[8];
@@ -824,7 +931,7 @@ ath_sysctl_stats_attach_rxphyerr(struct ath_softc *sc, struct sysctl_oid_list *p
        tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx_phy_err", CTLFLAG_RD, NULL, "Per-code RX PHY Errors");
        child = SYSCTL_CHILDREN(tree);
        for (i = 0; i < 64; i++) {
        tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx_phy_err", CTLFLAG_RD, NULL, "Per-code RX PHY Errors");
        child = SYSCTL_CHILDREN(tree);
        for (i = 0; i < 64; i++) {
-               snprintf(sn, sizeof(sn), "%d", i);
+               ksnprintf(sn, sizeof(sn), "%d", i);
                SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD, &sc->sc_stats.ast_rx_phy[i], 0, "");
        }
 }
                SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD, &sc->sc_stats.ast_rx_phy[i], 0, "");
        }
 }
@@ -833,8 +940,8 @@ static void
 ath_sysctl_stats_attach_intr(struct ath_softc *sc,
     struct sysctl_oid_list *parent)
 {
 ath_sysctl_stats_attach_intr(struct ath_softc *sc,
     struct sysctl_oid_list *parent)
 {
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
        int i;
        char sn[8];
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
        int i;
        char sn[8];
@@ -843,7 +950,7 @@ ath_sysctl_stats_attach_intr(struct ath_softc *sc,
            CTLFLAG_RD, NULL, "Sync interrupt statistics");
        child = SYSCTL_CHILDREN(tree);
        for (i = 0; i < 32; i++) {
            CTLFLAG_RD, NULL, "Sync interrupt statistics");
        child = SYSCTL_CHILDREN(tree);
        for (i = 0; i < 32; i++) {
-               snprintf(sn, sizeof(sn), "%d", i);
+               ksnprintf(sn, sizeof(sn), "%d", i);
                SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD,
                    &sc->sc_intr_stats.sync_intr[i], 0, "");
        }
                SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD,
                    &sc->sc_intr_stats.sync_intr[i], 0, "");
        }
@@ -852,8 +959,8 @@ ath_sysctl_stats_attach_intr(struct ath_softc *sc,
 void
 ath_sysctl_stats_attach(struct ath_softc *sc)
 {
 void
 ath_sysctl_stats_attach(struct ath_softc *sc)
 {
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
  
        /* Create "clear" node */
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
  
        /* Create "clear" node */
@@ -1095,8 +1202,8 @@ ath_sysctl_stats_attach(struct ath_softc *sc)
 void
 ath_sysctl_hal_attach(struct ath_softc *sc)
 {
 void
 ath_sysctl_hal_attach(struct ath_softc *sc)
 {
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
 
        tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hal", CTLFLAG_RD,
        struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
 
        tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hal", CTLFLAG_RD,
index 846ca25..777a002 100644 (file)
@@ -238,11 +238,11 @@ void
 ath_txfrag_cleanup(struct ath_softc *sc,
        ath_bufhead *frags, struct ieee80211_node *ni)
 {
 ath_txfrag_cleanup(struct ath_softc *sc,
        ath_bufhead *frags, struct ieee80211_node *ni)
 {
-       struct ath_buf *bf, *next;
+       struct ath_buf *bf;
 
        ATH_TXBUF_LOCK_ASSERT(sc);
 
 
        ATH_TXBUF_LOCK_ASSERT(sc);
 
-       TAILQ_FOREACH_SAFE(bf, frags, bf_list, next) {
+       while ((bf = TAILQ_FIRST(frags)) != NULL) {
                /* NB: bf assumed clean */
                TAILQ_REMOVE(frags, bf, bf_list);
                ath_returnbuf_head(sc, bf);
                /* NB: bf assumed clean */
                TAILQ_REMOVE(frags, bf, bf_list);
                ath_returnbuf_head(sc, bf);
@@ -306,8 +306,8 @@ ath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0)
         * Load the DMA map so any coalescing is done.  This
         * also calculates the number of descriptors we need.
         */
         * Load the DMA map so any coalescing is done.  This
         * also calculates the number of descriptors we need.
         */
-       error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0,
-                                    bf->bf_segs, &bf->bf_nseg,
+       error = bus_dmamap_load_mbuf_segment(sc->sc_dmat, bf->bf_dmamap, m0,
+                                    bf->bf_segs, 1, &bf->bf_nseg,
                                     BUS_DMA_NOWAIT);
        if (error == EFBIG) {
                /* XXX packet requires too many descriptors */
                                     BUS_DMA_NOWAIT);
        if (error == EFBIG) {
                /* XXX packet requires too many descriptors */
@@ -324,15 +324,23 @@ ath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0)
         */
        if (bf->bf_nseg > ATH_MAX_SCATTER) {            /* too many desc's, linearize */
                sc->sc_stats.ast_tx_linear++;
         */
        if (bf->bf_nseg > ATH_MAX_SCATTER) {            /* too many desc's, linearize */
                sc->sc_stats.ast_tx_linear++;
+
+               /* scrap for now */
+#if 0
                m = m_collapse(m0, M_NOWAIT, ATH_MAX_SCATTER);
                m = m_collapse(m0, M_NOWAIT, ATH_MAX_SCATTER);
+#else
+               m = NULL;
+#endif
+
                if (m == NULL) {
                        ath_freetx(m0);
                        sc->sc_stats.ast_tx_nombuf++;
                        return ENOMEM;
                }
                m0 = m;
                if (m == NULL) {
                        ath_freetx(m0);
                        sc->sc_stats.ast_tx_nombuf++;
                        return ENOMEM;
                }
                m0 = m;
-               error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0,
-                                            bf->bf_segs, &bf->bf_nseg,
+               error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
+                                            bf->bf_dmamap, m0,
+                                            bf->bf_segs, 1, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        sc->sc_stats.ast_tx_busdma++;
                                             BUS_DMA_NOWAIT);
                if (error != 0) {
                        sc->sc_stats.ast_tx_busdma++;
@@ -1213,7 +1221,7 @@ ath_tx_calc_ctsduration(struct ath_hal *ah, int rix, int cix,
 
        /* This mustn't be called for HT modes */
        if (rt->info[cix].phy == IEEE80211_T_HT) {
 
        /* This mustn't be called for HT modes */
        if (rt->info[cix].phy == IEEE80211_T_HT) {
-               printf("%s: HT rate where it shouldn't be (0x%x)\n",
+               kprintf("%s: HT rate where it shouldn't be (0x%x)\n",
                    __func__, rt->info[cix].rateCode);
                return (-1);
        }
                    __func__, rt->info[cix].rateCode);
                return (-1);
        }
@@ -2358,9 +2366,9 @@ ath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
 
        ATH_TX_LOCK(sc);
 
 
        ATH_TX_LOCK(sc);
 
-       if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || sc->sc_invalid) {
+       if ((ifp->if_flags & IFF_RUNNING) == 0 || sc->sc_invalid) {
                DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__,
                DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__,
-                   (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ?
+                   (ifp->if_flags & IFF_RUNNING) == 0 ?
                        "!running" : "invalid");
                m_freem(m);
                error = ENETDOWN;
                        "!running" : "invalid");
                m_freem(m);
                error = ENETDOWN;
@@ -4681,7 +4689,7 @@ ath_tx_aggr_comp_aggr(struct ath_softc *sc, struct ath_buf *bf_first,
                ath_tx_tid_filt_comp_aggr(sc, atid, bf_first, &bf_cq);
 
                /* Remove from BAW */
                ath_tx_tid_filt_comp_aggr(sc, atid, bf_first, &bf_cq);
 
                /* Remove from BAW */
-               TAILQ_FOREACH_SAFE(bf, &bf_cq, bf_list, bf_next) {
+               TAILQ_FOREACH(bf, &bf_cq, bf_list) {
                        if (bf->bf_state.bfs_addedbaw)
                                drops++;
                        if (bf->bf_state.bfs_dobaw) {
                        if (bf->bf_state.bfs_addedbaw)
                                drops++;
                        if (bf->bf_state.bfs_dobaw) {
@@ -5456,7 +5464,7 @@ ath_tx_tid_hw_queue_norm(struct ath_softc *sc, struct ath_node *an,
 void
 ath_txq_sched(struct ath_softc *sc, struct ath_txq *txq)
 {
 void
 ath_txq_sched(struct ath_softc *sc, struct ath_txq *txq)
 {
-       struct ath_tid *tid, *next, *last;
+       struct ath_tid *tid, *last;
 
        ATH_TX_LOCK_ASSERT(sc);
 
 
        ATH_TX_LOCK_ASSERT(sc);
 
@@ -5480,7 +5488,7 @@ ath_txq_sched(struct ath_softc *sc, struct ath_txq *txq)
 
        last = TAILQ_LAST(&txq->axq_tidq, axq_t_s);
 
 
        last = TAILQ_LAST(&txq->axq_tidq, axq_t_s);
 
-       TAILQ_FOREACH_SAFE(tid, &txq->axq_tidq, axq_qelem, next) {
+       while ((tid = TAILQ_FIRST(&txq->axq_tidq)) != NULL) {
                /*
                 * Suspend paused queues here; they'll be resumed
                 * once the addba completes or times out.
                /*
                 * Suspend paused queues here; they'll be resumed
                 * once the addba completes or times out.
@@ -5606,7 +5614,7 @@ ath_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
     int dialogtoken, int baparamset, int batimeout)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
     int dialogtoken, int baparamset, int batimeout)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
-       int tid = tap->txa_tid;
+       int tid = tap->txa_ac;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
 
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
 
@@ -5684,7 +5692,7 @@ ath_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
     int status, int code, int batimeout)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
     int status, int code, int batimeout)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
-       int tid = tap->txa_tid;
+       int tid = tap->txa_ac;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
        int r;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
        int r;
@@ -5731,7 +5739,7 @@ void
 ath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
 ath_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
-       int tid = tap->txa_tid;
+       int tid = tap->txa_ac;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
        ath_bufhead bf_cq;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
        ath_bufhead bf_cq;
@@ -5846,7 +5854,7 @@ ath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
     int status)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
     int status)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
-       int tid = tap->txa_tid;
+       int tid = tap->txa_ac;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
        int attempts = tap->txa_attempts;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
        int attempts = tap->txa_attempts;
@@ -5856,7 +5864,7 @@ ath_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
            __func__,
            ni->ni_macaddr,
            ":",
            __func__,
            ni->ni_macaddr,
            ":",
-           tap->txa_tid,
+           tap->txa_ac,
            atid->tid,
            status,
            attempts);
            atid->tid,
            status,
            attempts);
@@ -5895,7 +5903,7 @@ ath_addba_response_timeout(struct ieee80211_node *ni,
     struct ieee80211_tx_ampdu *tap)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
     struct ieee80211_tx_ampdu *tap)
 {
        struct ath_softc *sc = ni->ni_ic->ic_ifp->if_softc;
-       int tid = tap->txa_tid;
+       int tid = tap->txa_ac;
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
 
        struct ath_node *an = ATH_NODE(ni);
        struct ath_tid *atid = &an->an_tid[tid];
 
index 2749950..afa0e1c 100644 (file)
@@ -76,6 +76,7 @@
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 #include <net/if_llc.h>
+#include <net/ifq_var.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
 
 #include <netproto/802_11/ieee80211_var.h>
 #include <netproto/802_11/ieee80211_regdomain.h>
@@ -463,9 +464,9 @@ ath_edma_setup_txfifo(struct ath_softc *sc, int qnum)
 {
        struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
 
 {
        struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
 
-       te->m_fifo = malloc(sizeof(struct ath_buf *) * HAL_TXFIFO_DEPTH,
+       te->m_fifo = kmalloc(sizeof(struct ath_buf *) * HAL_TXFIFO_DEPTH,
            M_ATHDEV,
            M_ATHDEV,
-           M_NOWAIT | M_ZERO);
+           M_INTWAIT | M_ZERO);
        if (te->m_fifo == NULL) {
                device_printf(sc->sc_dev, "%s: malloc failed\n",
                    __func__);
        if (te->m_fifo == NULL) {
                device_printf(sc->sc_dev, "%s: malloc failed\n",
                    __func__);
@@ -486,7 +487,7 @@ ath_edma_free_txfifo(struct ath_softc *sc, int qnum)
        struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
 
        /* XXX TODO: actually deref the ath_buf entries? */
        struct ath_tx_edma_fifo *te = &sc->sc_txedma[qnum];
 
        /* XXX TODO: actually deref the ath_buf entries? */
-       free(te->m_fifo, M_ATHDEV);
+       kfree(te->m_fifo, M_ATHDEV);
        return (0);
 }
 
        return (0);
 }
 
@@ -576,7 +577,7 @@ ath_edma_tx_drain(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
        /* XXX dump out the frames */
 
        IF_LOCK(&ifp->if_snd);
        /* XXX dump out the frames */
 
        IF_LOCK(&ifp->if_snd);
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+       ifq_clr_oactive(&ifp->if_snd);
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 }
        IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 }
@@ -832,7 +833,7 @@ ath_edma_tx_processq(struct ath_softc *sc, int dosched)
 
        if (idx > 0) {
                IF_LOCK(&sc->sc_ifp->if_snd);
 
        if (idx > 0) {
                IF_LOCK(&sc->sc_ifp->if_snd);
-               sc->sc_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+               ifq_clr_oactive(&sc->sc_ifp->if_snd);
                IF_UNLOCK(&sc->sc_ifp->if_snd);
        }
 
                IF_UNLOCK(&sc->sc_ifp->if_snd);
        }
 
index d089a14..e13ff1e 100644 (file)
@@ -178,7 +178,9 @@ struct ath_node {
        struct ath_buf  *an_ff_buf[WME_NUM_AC]; /* ff staging area */
        struct ath_tid  an_tid[IEEE80211_TID_SIZE];     /* per-TID state */
        char            an_name[32];    /* eg "wlan0_a1" */
        struct ath_buf  *an_ff_buf[WME_NUM_AC]; /* ff staging area */
        struct ath_tid  an_tid[IEEE80211_TID_SIZE];     /* per-TID state */
        char            an_name[32];    /* eg "wlan0_a1" */
+#if 0
        struct mtx      an_mtx;         /* protecting the rate control state */
        struct mtx      an_mtx;         /* protecting the rate control state */
+#endif
        uint32_t        an_swq_depth;   /* how many SWQ packets for this
                                           node */
        int                     clrdmask;       /* has clrdmask been set */
        uint32_t        an_swq_depth;   /* how many SWQ packets for this
                                           node */
        int                     clrdmask;       /* has clrdmask been set */
@@ -335,7 +337,7 @@ struct ath_txq {
        u_int                   axq_intrcnt;    /* interrupt count */
        u_int32_t               *axq_link;      /* link ptr in last TX desc */
        TAILQ_HEAD(axq_q_s, ath_buf)    axq_q;          /* transmit queue */
        u_int                   axq_intrcnt;    /* interrupt count */
        u_int32_t               *axq_link;      /* link ptr in last TX desc */
        TAILQ_HEAD(axq_q_s, ath_buf)    axq_q;          /* transmit queue */
-       struct mtx              axq_lock;       /* lock on q and link */
+       struct lock             axq_lock;       /* lock on q and link */
 
        /*
         * This is the FIFO staging buffer when doing EDMA.
 
        /*
         * This is the FIFO staging buffer when doing EDMA.
@@ -375,24 +377,26 @@ struct ath_txq {
        TAILQ_HEAD(axq_t_s,ath_tid)     axq_tidq;
 };
 
        TAILQ_HEAD(axq_t_s,ath_tid)     axq_tidq;
 };
 
-#define        ATH_TXQ_LOCK_INIT(_sc, _tq) do { \
-           snprintf((_tq)->axq_name, sizeof((_tq)->axq_name), "%s_txq%u", \
-             device_get_nameunit((_sc)->sc_dev), (_tq)->axq_qnum); \
-           mtx_init(&(_tq)->axq_lock, (_tq)->axq_name, NULL, MTX_DEF); \
-       } while (0)
-#define        ATH_TXQ_LOCK_DESTROY(_tq)       mtx_destroy(&(_tq)->axq_lock)
-#define        ATH_TXQ_LOCK(_tq)               mtx_lock(&(_tq)->axq_lock)
-#define        ATH_TXQ_UNLOCK(_tq)             mtx_unlock(&(_tq)->axq_lock)
-#define        ATH_TXQ_LOCK_ASSERT(_tq)        mtx_assert(&(_tq)->axq_lock, MA_OWNED)
-#define        ATH_TXQ_UNLOCK_ASSERT(_tq)      mtx_assert(&(_tq)->axq_lock,    \
-                                           MA_NOTOWNED)
-
-
-#define        ATH_NODE_LOCK(_an)              mtx_lock(&(_an)->an_mtx)
-#define        ATH_NODE_UNLOCK(_an)            mtx_unlock(&(_an)->an_mtx)
-#define        ATH_NODE_LOCK_ASSERT(_an)       mtx_assert(&(_an)->an_mtx, MA_OWNED)
-#define        ATH_NODE_UNLOCK_ASSERT(_an)     mtx_assert(&(_an)->an_mtx,      \
-                                           MA_NOTOWNED)
+#ifdef __DragonFly__
+/* already serialized by wlan_serializer */
+#define IF_LOCK(ifp)
+#define IF_UNLOCK(ifp)
+#define IEEE80211_LOCK_ASSERT(ic)
+#define IEEE80211_LOCK(ic)
+#define IEEE80211_UNLOCK(ic)
+#endif
+
+#define        ATH_TXQ_LOCK_INIT(_sc, _tq)
+#define        ATH_TXQ_LOCK_DESTROY(_tq)
+#define        ATH_TXQ_LOCK(_tq)
+#define        ATH_TXQ_UNLOCK(_tq)
+#define        ATH_TXQ_LOCK_ASSERT(_tq)
+#define        ATH_TXQ_UNLOCK_ASSERT(_tq)
+
+#define        ATH_NODE_LOCK(_an)
+#define        ATH_NODE_UNLOCK(_an)
+#define        ATH_NODE_LOCK_ASSERT(_an)
+#define        ATH_NODE_UNLOCK_ASSERT(_an)
 
 /*
  * These are for the hardware queue.
 
 /*
  * These are for the hardware queue.
@@ -538,6 +542,8 @@ struct ath_softc {
        struct ath_stats        sc_stats;       /* interface statistics */
        struct ath_tx_aggr_stats        sc_aggr_stats;
        struct ath_intr_stats   sc_intr_stats;
        struct ath_stats        sc_stats;       /* interface statistics */
        struct ath_tx_aggr_stats        sc_aggr_stats;
        struct ath_intr_stats   sc_intr_stats;
+       struct sysctl_ctx_list  sc_sysctl_ctx;
+       struct sysctl_oid       *sc_sysctl_tree;
        uint64_t                sc_debug;
        uint64_t                sc_ktrdebug;
        int                     sc_nvaps;       /* # vaps */
        uint64_t                sc_debug;
        uint64_t                sc_ktrdebug;
        int                     sc_nvaps;       /* # vaps */
@@ -572,6 +578,7 @@ struct ath_softc {
        HAL_BUS_TAG             sc_st;          /* bus space tag */
        HAL_BUS_HANDLE          sc_sh;          /* bus space handle */
        bus_dma_tag_t           sc_dmat;        /* bus DMA tag */
        HAL_BUS_TAG             sc_st;          /* bus space tag */
        HAL_BUS_HANDLE          sc_sh;          /* bus space handle */
        bus_dma_tag_t           sc_dmat;        /* bus DMA tag */
+#if 0
        struct mtx              sc_mtx;         /* master lock (recursive) */
        struct mtx              sc_pcu_mtx;     /* PCU access mutex */
        char                    sc_pcu_mtx_name[32];
        struct mtx              sc_mtx;         /* master lock (recursive) */
        struct mtx              sc_pcu_mtx;     /* PCU access mutex */
        char                    sc_pcu_mtx_name[32];
@@ -581,6 +588,7 @@ struct ath_softc {
        char                    sc_tx_mtx_name[32];
        struct mtx              sc_tx_ic_mtx;   /* TX queue mutex */
        char                    sc_tx_ic_mtx_name[32];
        char                    sc_tx_mtx_name[32];
        struct mtx              sc_tx_ic_mtx;   /* TX queue mutex */
        char                    sc_tx_ic_mtx_name[32];
+#endif
        struct taskqueue        *sc_tq;         /* private task queue */
        struct ath_hal          *sc_ah;         /* Atheros HAL */
        struct ath_ratectrl     *sc_rc;         /* tx rate control support */
        struct taskqueue        *sc_tq;         /* private task queue */
        struct ath_hal          *sc_ah;         /* Atheros HAL */
        struct ath_ratectrl     *sc_rc;         /* tx rate control support */
@@ -727,8 +735,10 @@ struct ath_softc {
        struct ath_descdma      sc_txdma_mgmt;  /* mgmt TX descriptors */
        ath_bufhead             sc_txbuf_mgmt;  /* mgmt transmit buffer */
        struct ath_descdma      sc_txsdma;      /* EDMA TX status desc's */
        struct ath_descdma      sc_txdma_mgmt;  /* mgmt TX descriptors */
        ath_bufhead             sc_txbuf_mgmt;  /* mgmt transmit buffer */
        struct ath_descdma      sc_txsdma;      /* EDMA TX status desc's */
+#if 0
        struct mtx              sc_txbuflock;   /* txbuf lock */
        char                    sc_txname[12];  /* e.g. "ath0_buf" */
        struct mtx              sc_txbuflock;   /* txbuf lock */
        char                    sc_txname[12];  /* e.g. "ath0_buf" */
+#endif
        u_int                   sc_txqsetup;    /* h/w queues setup */
        u_int                   sc_txintrperiod;/* tx interrupt batching */
        struct ath_txq          sc_txq[HAL_NUM_TX_QUEUES];
        u_int                   sc_txqsetup;    /* h/w queues setup */
        u_int                   sc_txintrperiod;/* tx interrupt batching */
        struct ath_txq          sc_txq[HAL_NUM_TX_QUEUES];
@@ -737,8 +747,10 @@ struct ath_softc {
        struct task             sc_txqtask;     /* tx proc processing */
 
        struct ath_descdma      sc_txcompdma;   /* TX EDMA completion */
        struct task             sc_txqtask;     /* tx proc processing */
 
        struct ath_descdma      sc_txcompdma;   /* TX EDMA completion */
+#if 0
        struct mtx              sc_txcomplock;  /* TX EDMA completion lock */
        char                    sc_txcompname[12];      /* eg ath0_txcomp */
        struct mtx              sc_txcomplock;  /* TX EDMA completion lock */
        char                    sc_txcompname[12];      /* eg ath0_txcomp */
+#endif
 
        int                     sc_wd_timer;    /* count down for wd timer */
        struct callout          sc_wd_ch;       /* tx watchdog timer */
 
        int                     sc_wd_timer;    /* count down for wd timer */
        struct callout          sc_wd_ch;       /* tx watchdog timer */
@@ -866,56 +878,35 @@ struct ath_softc {
                                    int status);
 };
 
                                    int status);
 };
 
-#define        ATH_LOCK_INIT(_sc) \
-       mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
-                NULL, MTX_DEF | MTX_RECURSE)
-#define        ATH_LOCK_DESTROY(_sc)   mtx_destroy(&(_sc)->sc_mtx)
-#define        ATH_LOCK(_sc)           mtx_lock(&(_sc)->sc_mtx)
-#define        ATH_UNLOCK(_sc)         mtx_unlock(&(_sc)->sc_mtx)
-#define        ATH_LOCK_ASSERT(_sc)    mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
-#define        ATH_UNLOCK_ASSERT(_sc)  mtx_assert(&(_sc)->sc_mtx, MA_NOTOWNED)
+#define        ATH_LOCK_INIT(_sc)
+#define        ATH_LOCK_DESTROY(_sc)
+#define        ATH_LOCK(_sc)
+#define        ATH_UNLOCK(_sc)
+#define        ATH_LOCK_ASSERT(_sc)
+#define        ATH_UNLOCK_ASSERT(_sc)
 
 /*
  * The TX lock is non-reentrant and serialises the TX frame send
  * and completion operations.
  */
 
 /*
  * The TX lock is non-reentrant and serialises the TX frame send
  * and completion operations.
  */
-#define        ATH_TX_LOCK_INIT(_sc) do {\
-       snprintf((_sc)->sc_tx_mtx_name,                         \
-           sizeof((_sc)->sc_tx_mtx_name),                              \
-           "%s TX lock",                                               \
-           device_get_nameunit((_sc)->sc_dev));                        \
-       mtx_init(&(_sc)->sc_tx_mtx, (_sc)->sc_tx_mtx_name,              \
-                NULL, MTX_DEF);                                        \
-       } while (0)
-#define        ATH_TX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->sc_tx_mtx)
-#define        ATH_TX_LOCK(_sc)                mtx_lock(&(_sc)->sc_tx_mtx)
-#define        ATH_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->sc_tx_mtx)
-#define        ATH_TX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_tx_mtx,   \
-               MA_OWNED)
-#define        ATH_TX_UNLOCK_ASSERT(_sc)       mtx_assert(&(_sc)->sc_tx_mtx,   \
-               MA_NOTOWNED)
-#define        ATH_TX_TRYLOCK(_sc)     (mtx_owned(&(_sc)->sc_tx_mtx) != 0 &&   \
-                                       mtx_trylock(&(_sc)->sc_tx_mtx))
+#define        ATH_TX_LOCK_INIT(_sc)
+#define        ATH_TX_LOCK_DESTROY(_sc)
+#define        ATH_TX_LOCK(_sc)
+#define        ATH_TX_UNLOCK(_sc)
+#define        ATH_TX_LOCK_ASSERT(_sc)
+#define        ATH_TX_UNLOCK_ASSERT(_sc)
+/* #define ATH_TX_TRYLOCK(_sc) removed */
 
 /*
  * The IC TX lock is non-reentrant and serialises packet queuing from
  * the upper layers.
  */
 
 /*
  * The IC TX lock is non-reentrant and serialises packet queuing from
  * the upper layers.
  */
-#define        ATH_TX_IC_LOCK_INIT(_sc) do {\
-       snprintf((_sc)->sc_tx_ic_mtx_name,                              \
-           sizeof((_sc)->sc_tx_ic_mtx_name),                           \
-           "%s IC TX lock",                                            \
-           device_get_nameunit((_sc)->sc_dev));                        \
-       mtx_init(&(_sc)->sc_tx_ic_mtx, (_sc)->sc_tx_ic_mtx_name,        \
-                NULL, MTX_DEF);                                        \
-       } while (0)
-#define        ATH_TX_IC_LOCK_DESTROY(_sc)     mtx_destroy(&(_sc)->sc_tx_ic_mtx)
-#define        ATH_TX_IC_LOCK(_sc)             mtx_lock(&(_sc)->sc_tx_ic_mtx)
-#define        ATH_TX_IC_UNLOCK(_sc)           mtx_unlock(&(_sc)->sc_tx_ic_mtx)
-#define        ATH_TX_IC_LOCK_ASSERT(_sc)      mtx_assert(&(_sc)->sc_tx_ic_mtx,        \
-               MA_OWNED)
-#define        ATH_TX_IC_UNLOCK_ASSERT(_sc)    mtx_assert(&(_sc)->sc_tx_ic_mtx,        \
-               MA_NOTOWNED)
+#define        ATH_TX_IC_LOCK_INIT(_sc)
+#define        ATH_TX_IC_LOCK_DESTROY(_sc)
+#define        ATH_TX_IC_LOCK(_sc)
+#define        ATH_TX_IC_UNLOCK(_sc)
+#define        ATH_TX_IC_LOCK_ASSERT(_sc)
+#define        ATH_TX_IC_UNLOCK_ASSERT(_sc)
 
 /*
  * The PCU lock is non-recursive and should be treated as a spinlock.
 
 /*
  * The PCU lock is non-recursive and should be treated as a spinlock.
@@ -934,21 +925,12 @@ struct ath_softc {
  * (which only acquires ATH_LOCK when recycling buffers to the free list),
  * ath_set_channel, the channel scanning API and perhaps quite a bit more.
  */
  * (which only acquires ATH_LOCK when recycling buffers to the free list),
  * ath_set_channel, the channel scanning API and perhaps quite a bit more.
  */
-#define        ATH_PCU_LOCK_INIT(_sc) do {\
-       snprintf((_sc)->sc_pcu_mtx_name,                                \
-           sizeof((_sc)->sc_pcu_mtx_name),                             \
-           "%s PCU lock",                                              \
-           device_get_nameunit((_sc)->sc_dev));                        \
-       mtx_init(&(_sc)->sc_pcu_mtx, (_sc)->sc_pcu_mtx_name,            \
-                NULL, MTX_DEF);                                        \
-       } while (0)
-#define        ATH_PCU_LOCK_DESTROY(_sc)       mtx_destroy(&(_sc)->sc_pcu_mtx)
-#define        ATH_PCU_LOCK(_sc)               mtx_lock(&(_sc)->sc_pcu_mtx)
-#define        ATH_PCU_UNLOCK(_sc)             mtx_unlock(&(_sc)->sc_pcu_mtx)
-#define        ATH_PCU_LOCK_ASSERT(_sc)        mtx_assert(&(_sc)->sc_pcu_mtx,  \
-               MA_OWNED)
-#define        ATH_PCU_UNLOCK_ASSERT(_sc)      mtx_assert(&(_sc)->sc_pcu_mtx,  \
-               MA_NOTOWNED)
+#define        ATH_PCU_LOCK_INIT(_sc)
+#define        ATH_PCU_LOCK_DESTROY(_sc)
+#define        ATH_PCU_LOCK(_sc)
+#define        ATH_PCU_UNLOCK(_sc)
+#define        ATH_PCU_LOCK_ASSERT(_sc)
+#define        ATH_PCU_UNLOCK_ASSERT(_sc)
 
 /*
  * The RX lock is primarily a(nother) workaround to ensure that the
 
 /*
  * The RX lock is primarily a(nother) workaround to ensure that the
@@ -956,49 +938,27 @@ struct ath_softc {
  * Even though RX occurs in a single context (the ath taskqueue), the
  * RX path can be executed via various reset/channel change paths.
  */
  * Even though RX occurs in a single context (the ath taskqueue), the
  * RX path can be executed via various reset/channel change paths.
  */
-#define        ATH_RX_LOCK_INIT(_sc) do {\
-       snprintf((_sc)->sc_rx_mtx_name,                                 \
-           sizeof((_sc)->sc_rx_mtx_name),                              \
-           "%s RX lock",                                               \
-           device_get_nameunit((_sc)->sc_dev));                        \
-       mtx_init(&(_sc)->sc_rx_mtx, (_sc)->sc_rx_mtx_name,              \
-                NULL, MTX_DEF);                                        \
-       } while (0)
-#define        ATH_RX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->sc_rx_mtx)
-#define        ATH_RX_LOCK(_sc)                mtx_lock(&(_sc)->sc_rx_mtx)
-#define        ATH_RX_UNLOCK(_sc)              mtx_unlock(&(_sc)->sc_rx_mtx)
-#define        ATH_RX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_rx_mtx,   \
-               MA_OWNED)
-#define        ATH_RX_UNLOCK_ASSERT(_sc)       mtx_assert(&(_sc)->sc_rx_mtx,   \
-               MA_NOTOWNED)
+#define        ATH_RX_LOCK_INIT(_sc)
+#define        ATH_RX_LOCK_DESTROY(_sc)
+#define        ATH_RX_LOCK(_sc)
+#define        ATH_RX_UNLOCK(_sc)
+#define        ATH_RX_LOCK_ASSERT(_sc)
+#define        ATH_RX_UNLOCK_ASSERT(_sc)
 
 #define        ATH_TXQ_SETUP(sc, i)    ((sc)->sc_txqsetup & (1<<i))
 
 
 #define        ATH_TXQ_SETUP(sc, i)    ((sc)->sc_txqsetup & (1<<i))
 
-#define        ATH_TXBUF_LOCK_INIT(_sc) do { \
-       snprintf((_sc)->sc_txname, sizeof((_sc)->sc_txname), "%s_buf", \
-               device_get_nameunit((_sc)->sc_dev)); \
-       mtx_init(&(_sc)->sc_txbuflock, (_sc)->sc_txname, NULL, MTX_DEF); \
-} while (0)
-#define        ATH_TXBUF_LOCK_DESTROY(_sc)     mtx_destroy(&(_sc)->sc_txbuflock)
-#define        ATH_TXBUF_LOCK(_sc)             mtx_lock(&(_sc)->sc_txbuflock)
-#define        ATH_TXBUF_UNLOCK(_sc)           mtx_unlock(&(_sc)->sc_txbuflock)
-#define        ATH_TXBUF_LOCK_ASSERT(_sc) \
-       mtx_assert(&(_sc)->sc_txbuflock, MA_OWNED)
-#define        ATH_TXBUF_UNLOCK_ASSERT(_sc) \
-       mtx_assert(&(_sc)->sc_txbuflock, MA_NOTOWNED)
-
-#define        ATH_TXSTATUS_LOCK_INIT(_sc) do { \
-       snprintf((_sc)->sc_txcompname, sizeof((_sc)->sc_txcompname), \
-               "%s_buf", \
-               device_get_nameunit((_sc)->sc_dev)); \
-       mtx_init(&(_sc)->sc_txcomplock, (_sc)->sc_txcompname, NULL, \
-               MTX_DEF); \
-} while (0)
-#define        ATH_TXSTATUS_LOCK_DESTROY(_sc)  mtx_destroy(&(_sc)->sc_txcomplock)
-#define        ATH_TXSTATUS_LOCK(_sc)          mtx_lock(&(_sc)->sc_txcomplock)
-#define        ATH_TXSTATUS_UNLOCK(_sc)        mtx_unlock(&(_sc)->sc_txcomplock)
-#define        ATH_TXSTATUS_LOCK_ASSERT(_sc) \
-       mtx_assert(&(_sc)->sc_txcomplock, MA_OWNED)
+#define        ATH_TXBUF_LOCK_INIT(_sc)
+#define        ATH_TXBUF_LOCK_DESTROY(_sc)
+#define        ATH_TXBUF_LOCK(_sc)
+#define        ATH_TXBUF_UNLOCK(_sc)
+#define        ATH_TXBUF_LOCK_ASSERT(_sc)
+#define        ATH_TXBUF_UNLOCK_ASSERT(_sc)
+
+#define        ATH_TXSTATUS_LOCK_INIT(_sc)
+#define        ATH_TXSTATUS_LOCK_DESTROY(_sc)
+#define        ATH_TXSTATUS_LOCK(_sc)
+#define        ATH_TXSTATUS_UNLOCK(_sc)
+#define        ATH_TXSTATUS_LOCK_ASSERT(_sc)
 
 int    ath_attach(u_int16_t, struct ath_softc *);
 int    ath_detach(struct ath_softc *);
 
 int    ath_attach(u_int16_t, struct ath_softc *);
 int    ath_detach(struct ath_softc *);
index ff658ba..4068800 100644 (file)
@@ -2,7 +2,7 @@
 #
 
 KMOD=  ath_dfs
 #
 
 KMOD=  ath_dfs
-SRCS=  null.c
-SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h
+SRCS=  dfs_null.c
+SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h opt_ath.h
 
 .include <bsd.kmod.mk>
 
 .include <bsd.kmod.mk>
index b4dc7f2..64964a7 100644 (file)
@@ -63,8 +63,6 @@
 #include <netinet/if_ether.h>
 #endif
 
 #include <netinet/if_ether.h>
 #endif
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_athdfs.h>
 
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath/if_athdfs.h>
 
@@ -227,7 +225,7 @@ ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
                /*
                 * Copy in data.
                 */
-               indata = malloc(insize, M_TEMP, M_NOWAIT);
+               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -244,7 +242,7 @@ ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
                 * pointer for us to use below in reclaiming the buffer;
                 * may want to be more defensive.
                 */
-               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
+               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -275,9 +273,9 @@ ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               free(indata, M_TEMP);
+               kfree(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               free(outdata, M_TEMP);
+               kfree(outdata, M_TEMP);
        return (error);
 }
 
        return (error);
 }
 
index 7eaff88..86d640b 100644 (file)
@@ -5,11 +5,13 @@ ATH_RATE?=    sample          # tx rate control algorithm
 
 KMOD=  ath_hal
 
 
 KMOD=  ath_hal
 
-.PATH: ar5211 ar5416 ar5312 ar5212 ar9003 ar9002 ar9001 ar5210
+.PATH: ${.CURDIR}/ar5211 ${.CURDIR}/ar5416 ${.CURDIR}/ar5312
+.PATH: ${.CURDIR}/ar5212 ${.CURDIR}/ar9003 ${.CURDIR}/ar9002
+.PATH: ${.CURDIR}/ar9001 ${.CURDIR}/ar5210
 
 
-SRCS=  ah_eeprom_9287.c ah_eeprom_v4k.c ah_regdomain.c \
+SRCS=  ah_eeprom_9287.c ah_eeprom_v4k.c ah_regdomain.c
 SRCS+= ah_eeprom_v1.c ah_eeprom_v3.c ah_osdep.c ah.c ah_eeprom_v14.c
 SRCS+= ah_eeprom_v1.c ah_eeprom_v3.c ah_osdep.c ah.c ah_eeprom_v14.c
-SRCS+= device_if.h bus_if.h pci_if.h opt_inet.h opt_ath.h opt_ah.h
+SRCS+= device_if.h bus_if.h pci_if.h opt_wlan.h opt_inet.h opt_ath.h opt_ah.h
 
 # AR5211
 #
 
 # AR5211
 #
@@ -33,12 +35,17 @@ SRCS+=      ar5312_gpio.c ar5315_gpio.c ar5312_power.c ar5312_attach.c
 
 # AR5212
 #
 
 # AR5212
 #
-SRCS+= ar5212_rfgain.c ar5212_interrupts.c ar5212_ani.c ar2316.c
-SRCS+= ar2317.c ar2413.c ar5413.c ar5212_power.c ar2425.c ar5212_recv.c
+SRCS+= ar5212_rfgain.c ar5212_interrupts.c ar5212_ani.c
+SRCS+= ar2413.c ar5413.c ar5212_power.c ar2425.c ar5212_recv.c
 SRCS+= ar5212_gpio.c ar5212_beacon.c ar5212_misc.c ar5212_xmit.c
 SRCS+= ar5212_eeprom.c ar5212_keycache.c ar5212_phy.c ar5212_attach.c
 SRCS+= ar5212_reset.c ar5111.c ar5112.c
 
 SRCS+= ar5212_gpio.c ar5212_beacon.c ar5212_misc.c ar5212_xmit.c
 SRCS+= ar5212_eeprom.c ar5212_keycache.c ar5212_phy.c ar5212_attach.c
 SRCS+= ar5212_reset.c ar5111.c ar5112.c
 
+# AR2316, AR2317
+#
+#SRCS+=        ar2316.c
+#SRCS+=        ar2317.c
+
 # AR9002
 #
 
 # AR9002
 #
 
index c71cf75..775c783 100644 (file)
@@ -28,6 +28,9 @@
  *
  * $FreeBSD$
  */
  *
  * $FreeBSD$
  */
+#include "opt_ath.h"
+#include "opt_inet.h"
+#include "opt_wlan.h"
 #include "opt_ah.h"
 
 #include <sys/param.h>
 #include "opt_ah.h"
 
 #include <sys/param.h>
 #include <sys/bus.h>
 #include <sys/malloc.h>
 #include <sys/proc.h>
 #include <sys/bus.h>
 #include <sys/malloc.h>
 #include <sys/proc.h>
-#include <sys/pcpu.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
 
 #include <machine/stdarg.h>
 
 #include <sys/lock.h>
 #include <sys/mutex.h>
 
 #include <machine/stdarg.h>
 
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_media.h>
+#include <net/if_arp.h>
 #include <net/ethernet.h>              /* XXX for ether_sprintf */
 
 #include <net/ethernet.h>              /* XXX for ether_sprintf */
 
+#include <netproto/802_11/ieee80211_var.h>
+
 #include <dev/netif/ath/ath_hal/ah.h>
 #include <dev/netif/ath/ath_hal/ah_debug.h>
 
 #include <dev/netif/ath/ath_hal/ah.h>
 #include <dev/netif/ath/ath_hal/ah_debug.h>
 
@@ -70,9 +78,7 @@
  * XXX This is a global lock for now; it should be pushed to
  * a per-device lock in some platform-independent fashion.
  */
  * XXX This is a global lock for now; it should be pushed to
  * a per-device lock in some platform-independent fashion.
  */
-struct mtx ah_regser_mtx;
-MTX_SYSINIT(ah_regser, &ah_regser_mtx, "Atheros register access mutex",
-    MTX_SPIN);
+struct spinlock ah_regser_spin = SPINLOCK_INITIALIZER(ah_regser_spin);
 
 extern void ath_hal_printf(struct ath_hal *, const char*, ...)
                __printflike(2,3);
 
 extern void ath_hal_printf(struct ath_hal *, const char*, ...)
                __printflike(2,3);
@@ -106,34 +112,38 @@ static MALLOC_DEFINE(M_ATH_HAL, "ath_hal", "ath hal data");
 void*
 ath_hal_malloc(size_t size)
 {
 void*
 ath_hal_malloc(size_t size)
 {
-       return malloc(size, M_ATH_HAL, M_NOWAIT | M_ZERO);
+       return kmalloc(size, M_ATH_HAL, M_INTWAIT | M_ZERO);
 }
 
 void
 ath_hal_free(void* p)
 {
 }
 
 void
 ath_hal_free(void* p)
 {
-       free(p, M_ATH_HAL);
+       kfree(p, M_ATH_HAL);
 }
 
 void
 }
 
 void
-ath_hal_vprintf(struct ath_hal *ah, const char* fmt, va_list ap)
+ath_hal_vprintf(struct ath_hal *ah, const char* fmt, __va_list ap)
 {
 {
-       vprintf(fmt, ap);
+       kvprintf(fmt, ap);
 }
 
 void
 ath_hal_printf(struct ath_hal *ah, const char* fmt, ...)
 {
 }
 
 void
 ath_hal_printf(struct ath_hal *ah, const char* fmt, ...)
 {
-       va_list ap;
-       va_start(ap, fmt);
+       __va_list ap;
+       __va_start(ap, fmt);
        ath_hal_vprintf(ah, fmt, ap);
        ath_hal_vprintf(ah, fmt, ap);
-       va_end(ap);
+       __va_end(ap);
 }
 
 const char*
 ath_hal_ether_sprintf(const u_int8_t *mac)
 {
 }
 
 const char*
 ath_hal_ether_sprintf(const u_int8_t *mac)
 {
-       return ether_sprintf(mac);
+       static char etherbuf[18];
+
+       kether_ntoa(mac, etherbuf);
+
+       return etherbuf;
 }
 
 #ifdef AH_DEBUG
 }
 
 #ifdef AH_DEBUG
@@ -145,9 +155,9 @@ DO_HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
            (ah != NULL && ah->ah_config.ah_debug & mask) ||
            (ath_hal_debug & mask)) {
                __va_list ap;
            (ah != NULL && ah->ah_config.ah_debug & mask) ||
            (ath_hal_debug & mask)) {
                __va_list ap;
-               va_start(ap, fmt);
+               __va_start(ap, fmt);
                ath_hal_vprintf(ah, fmt, ap);
                ath_hal_vprintf(ah, fmt, ap);
-               va_end(ap);
+               __va_end(ap);
        }
 }
 #undef HAL_DEBUG_UNMASKABLE
        }
 }
 #undef HAL_DEBUG_UNMASKABLE
@@ -168,7 +178,6 @@ DO_HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
  *     is emitted and the different devices are not identified.
  */
 #include <sys/alq.h>
  *     is emitted and the different devices are not identified.
  */
 #include <sys/alq.h>
-#include <sys/pcpu.h>
 #include <dev/netif/ath/ath_hal/ah_decode.h>
 
 static struct alq *ath_hal_alq;
 #include <dev/netif/ath/ath_hal/ah_decode.h>
 
 static struct alq *ath_hal_alq;
@@ -192,13 +201,13 @@ ath_hal_setlogging(int enable)
                        sizeof (struct athregrec), ath_hal_alq_qsize);
                ath_hal_alq_lost = 0;
                ath_hal_alq_emitdev = 1;
                        sizeof (struct athregrec), ath_hal_alq_qsize);
                ath_hal_alq_lost = 0;
                ath_hal_alq_emitdev = 1;
-               printf("ath_hal: logging to %s enabled\n",
+               kprintf("ath_hal: logging to %s enabled\n",
                        ath_hal_logfile);
        } else {
                if (ath_hal_alq)
                        alq_close(ath_hal_alq);
                ath_hal_alq = NULL;
                        ath_hal_logfile);
        } else {
                if (ath_hal_alq)
                        alq_close(ath_hal_alq);
                ath_hal_alq = NULL;
-               printf("ath_hal: logging disabled\n");
+               kprintf("ath_hal: logging disabled\n");
                error = 0;
        }
        return (error);
                error = 0;
        }
        return (error);
@@ -265,10 +274,10 @@ ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
                }
        }
        if (ah->ah_config.ah_serialise_reg_war)
                }
        }
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_lock_spin(&ah_regser_mtx);
+               spin_lock(&ah_regser_spin);
        bus_space_write_4(tag, h, reg, val);
        if (ah->ah_config.ah_serialise_reg_war)
        bus_space_write_4(tag, h, reg, val);
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_unlock_spin(&ah_regser_mtx);
+               spin_unlock(&ah_regser_spin);
 }
 
 u_int32_t
 }
 
 u_int32_t
@@ -279,10 +288,10 @@ ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
        u_int32_t val;
 
        if (ah->ah_config.ah_serialise_reg_war)
        u_int32_t val;
 
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_lock_spin(&ah_regser_mtx);
+               spin_lock(&ah_regser_spin);
        val = bus_space_read_4(tag, h, reg);
        if (ah->ah_config.ah_serialise_reg_war)
        val = bus_space_read_4(tag, h, reg);
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_unlock_spin(&ah_regser_mtx);
+               spin_unlock(&ah_regser_spin);
        if (ath_hal_alq) {
                struct ale *ale = ath_hal_alq_get(ah);
                if (ale) {
        if (ath_hal_alq) {
                struct ale *ale = ath_hal_alq_get(ah);
                if (ale) {
@@ -331,10 +340,10 @@ ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
        bus_space_handle_t h = ah->ah_sh;
 
        if (ah->ah_config.ah_serialise_reg_war)
        bus_space_handle_t h = ah->ah_sh;
 
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_lock_spin(&ah_regser_mtx);
+               spin_lock(&ah_regser_spin);
        bus_space_write_4(tag, h, reg, val);
        if (ah->ah_config.ah_serialise_reg_war)
        bus_space_write_4(tag, h, reg, val);
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_unlock_spin(&ah_regser_mtx);
+               spin_unlock(&ah_regser_spin);
 }
 
 u_int32_t
 }
 
 u_int32_t
@@ -345,10 +354,10 @@ ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
        u_int32_t val;
 
        if (ah->ah_config.ah_serialise_reg_war)
        u_int32_t val;
 
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_lock_spin(&ah_regser_mtx);
+               spin_lock(&ah_regser_spin);
        val = bus_space_read_4(tag, h, reg);
        if (ah->ah_config.ah_serialise_reg_war)
        val = bus_space_read_4(tag, h, reg);
        if (ah->ah_config.ah_serialise_reg_war)
-               mtx_unlock_spin(&ah_regser_mtx);
+               spin_unlock(&ah_regser_spin);
        return val;
 }
 #endif /* AH_DEBUG || AH_REGOPS_FUNC */
        return val;
 }
 #endif /* AH_DEBUG || AH_REGOPS_FUNC */
@@ -357,8 +366,43 @@ ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
 void
 ath_hal_assert_failed(const char* filename, int lineno, const char *msg)
 {
 void
 ath_hal_assert_failed(const char* filename, int lineno, const char *msg)
 {
-       printf("Atheros HAL assertion failure: %s: line %u: %s\n",
+       kprintf("Atheros HAL assertion failure: %s: line %u: %s\n",
                filename, lineno, msg);
        panic("ath_hal_assert");
 }
 #endif /* AH_ASSERT */
                filename, lineno, msg);
        panic("ath_hal_assert");
 }
 #endif /* AH_ASSERT */
+
+/*
+ * Module glue.
+ */
+static int
+ath_hal_modevent(module_t mod, int type, void *unused)
+{
+       int error;
+
+       wlan_serialize_enter();
+
+       switch (type) {
+       case MOD_LOAD:
+               error = 0;
+               break;
+       case MOD_UNLOAD:
+               error = 0;
+               break;
+       default:
+               error = EINVAL;
+               break;
+       }
+       wlan_serialize_exit();
+
+       return error;
+}
+
+static moduledata_t ath_hal_mod = {
+       "ath_hal",
+       ath_hal_modevent,
+       0
+};
+
+DECLARE_MODULE(ath_hal, ath_hal_mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
+MODULE_VERSION(ath_hal, 1);
index f28fb17..3663862 100644 (file)
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/endian.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/endian.h>
+#include <sys/bus.h>
+#include <sys/spinlock.h>
 #include <sys/linker_set.h>
 
 #include <sys/linker_set.h>
 
+#include <sys/spinlock2.h>
+
 /*
  * Bus i/o type definitions.
  */
 /*
  * Bus i/o type definitions.
  */
index 4ca1a4d..24b05e0 100644 (file)
@@ -108,18 +108,18 @@ ar5312Attach(uint16_t devid, HAL_SOFTC sc,
        } else
 #endif
        {
        } else
 #endif
        {
-               ahp->ah_priv.ah_gpioCfgOutput   = ar5312GpioCfgOutput;
-               ahp->ah_priv.ah_gpioCfgInput    = ar5312GpioCfgInput;
-               ahp->ah_priv.ah_gpioGet         = ar5312GpioGet;
-               ahp->ah_priv.ah_gpioSet         = ar5312GpioSet;
-               ahp->ah_priv.ah_gpioSetIntr     = ar5312GpioSetIntr;
+               ahp->ah_priv.h.ah_gpioCfgOutput = ar5312GpioCfgOutput;
+               ahp->ah_priv.h.ah_gpioCfgInput  = ar5312GpioCfgInput;
+               ahp->ah_priv.h.ah_gpioGet       = ar5312GpioGet;
+               ahp->ah_priv.h.ah_gpioSet       = ar5312GpioSet;
+               ahp->ah_priv.h.ah_gpioSetIntr   = ar5312GpioSetIntr;
        }
 
        }
 
-       ah->ah_gpioCfgInput             = ahp->ah_priv.ah_gpioCfgInput;
-       ah->ah_gpioCfgOutput            = ahp->ah_priv.ah_gpioCfgOutput;
-       ah->ah_gpioGet                  = ahp->ah_priv.ah_gpioGet;
-       ah->ah_gpioSet                  = ahp->ah_priv.ah_gpioSet;
-       ah->ah_gpioSetIntr              = ahp->ah_priv.ah_gpioSetIntr;
+       ah->ah_gpioCfgInput             = ahp->ah_priv.h.ah_gpioCfgInput;
+       ah->ah_gpioCfgOutput            = ahp->ah_priv.h.ah_gpioCfgOutput;
+       ah->ah_gpioGet                  = ahp->ah_priv.h.ah_gpioGet;
+       ah->ah_gpioSet                  = ahp->ah_priv.h.ah_gpioSet;
+       ah->ah_gpioSetIntr              = ahp->ah_priv.h.ah_gpioSetIntr;
 
        /* setup common ini data; rf backends handle remainder */
        HAL_INI_INIT(&ahp->ah_ini_modes, ar5212Modes, 6);
 
        /* setup common ini data; rf backends handle remainder */
        HAL_INI_INIT(&ahp->ah_ini_modes, ar5212Modes, 6);
diff --git a/sys/dev/netif/ath/ath_hal/ar71xx/ar71xx_cpudef.h b/sys/dev/netif/ath/ath_hal/ar71xx/ar71xx_cpudef.h
new file mode 100644 (file)
index 0000000..9a1133b
--- /dev/null
@@ -0,0 +1,160 @@
+/*-
+ * Copyright (c) 2010 Adrian Chadd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $FreeBSD$ */
+
+#ifndef        __AR71XX_CPUDEF_H__
+#define        __AR71XX_CPUDEF_H__
+
+struct ar71xx_cpu_def {
+       void (* detect_mem_size) (void);
+       void (* detect_sys_frequency) (void);
+       void (* ar71xx_chip_device_stop) (uint32_t);
+       void (* ar71xx_chip_device_start) (uint32_t);
+       int (* ar71xx_chip_device_stopped) (uint32_t);
+       void (* ar71xx_chip_set_pll_ge) (int, int, uint32_t);
+       void (* ar71xx_chip_set_mii_speed) (uint32_t, uint32_t);
+       void (* ar71xx_chip_set_mii_if) (uint32_t, ar71xx_mii_mode);
+       void (* ar71xx_chip_ddr_flush_ge) (int);
+       uint32_t (* ar71xx_chip_get_eth_pll) (unsigned int, int);
+
+       /*
+        * From Linux - Handling this IRQ is a bit special.
+        * AR71xx - AR71XX_DDR_REG_FLUSH_PCI
+        * AR724x - AR724X_DDR_REG_FLUSH_PCIE
+        * AR91xx - AR91XX_DDR_REG_FLUSH_WMAC
+        *
+        * These are set when STATUSF_IP2 is set in regiser c0.
+        * This flush is done before the IRQ is handled to make
+        * sure the driver correctly sees any memory updates.
+        */
+       void (* ar71xx_chip_ddr_flush_ip2) (void);
+       /*
+        * The USB peripheral init code is subtly different for
+        * each chip.
+        */
+       void (* ar71xx_chip_init_usb_peripheral) (void);
+
+       void (* ar71xx_chip_reset_ethernet_switch) (void);
+
+       void (* ar71xx_chip_reset_wmac) (void);
+
+       void (* ar71xx_chip_init_gmac) (void);
+};
+
+extern struct ar71xx_cpu_def * ar71xx_cpu_ops;
+
+static inline void ar71xx_detect_sys_frequency(void)
+{
+       ar71xx_cpu_ops->detect_sys_frequency();
+}
+
+static inline void ar71xx_device_stop(uint32_t mask)
+{
+       ar71xx_cpu_ops->ar71xx_chip_device_stop(mask);
+}
+
+static inline void ar71xx_device_start(uint32_t mask)
+{
+       ar71xx_cpu_ops->ar71xx_chip_device_start(mask);
+}
+
+static inline int ar71xx_device_stopped(uint32_t mask)
+{
+       return ar71xx_cpu_ops->ar71xx_chip_device_stopped(mask);
+}
+
+static inline void ar71xx_device_set_pll_ge(int unit, int speed, uint32_t pll)
+{
+       ar71xx_cpu_ops->ar71xx_chip_set_pll_ge(unit, speed, pll);
+}
+
+static inline void ar71xx_device_set_mii_speed(int unit, int speed)
+{
+       ar71xx_cpu_ops->ar71xx_chip_set_mii_speed(unit, speed);
+}
+
+static inline void ar71xx_device_set_mii_if(int unit, ar71xx_mii_mode mii_cfg)
+{
+       ar71xx_cpu_ops->ar71xx_chip_set_mii_if(unit, mii_cfg);
+}
+
+static inline void ar71xx_device_flush_ddr_ge(int unit)
+{
+       ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ge(unit);
+}
+
+static inline uint32_t ar71xx_device_get_eth_pll(unsigned int unit, int speed)
+{
+       return (ar71xx_cpu_ops->ar71xx_chip_get_eth_pll(unit, speed));
+}
+
+static inline void ar71xx_init_usb_peripheral(void)
+{
+       ar71xx_cpu_ops->ar71xx_chip_init_usb_peripheral();
+}
+
+static inline void ar71xx_reset_ethernet_switch(void)
+{
+       if (ar71xx_cpu_ops->ar71xx_chip_reset_ethernet_switch)
+               ar71xx_cpu_ops->ar71xx_chip_reset_ethernet_switch();
+}
+
+static inline void ar71xx_reset_wmac(void)
+{
+       if (ar71xx_cpu_ops->ar71xx_chip_reset_wmac)
+               ar71xx_cpu_ops->ar71xx_chip_reset_wmac();
+}
+
+static inline void ar71xx_init_gmac(void)
+{
+       if (ar71xx_cpu_ops->ar71xx_chip_init_gmac)
+               ar71xx_cpu_ops->ar71xx_chip_init_gmac();
+}
+
+static inline void ar71xx_device_ddr_flush_ip2(void)
+{
+       ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ip2();
+}
+
+/* XXX shouldn't be here! */
+extern uint32_t u_ar71xx_refclk;
+extern uint32_t u_ar71xx_cpu_freq;
+extern uint32_t u_ar71xx_ahb_freq;
+extern uint32_t u_ar71xx_ddr_freq;
+extern uint32_t u_ar71xx_uart_freq;
+extern uint32_t u_ar71xx_wdt_freq;
+extern uint32_t u_ar71xx_mdio_freq;
+
+static inline uint64_t ar71xx_refclk(void) { return u_ar71xx_refclk; }
+static inline uint64_t ar71xx_cpu_freq(void) { return u_ar71xx_cpu_freq; }
+static inline uint64_t ar71xx_ahb_freq(void) { return u_ar71xx_ahb_freq; }
+static inline uint64_t ar71xx_ddr_freq(void) { return u_ar71xx_ddr_freq; }
+static inline uint64_t ar71xx_uart_freq(void) { return u_ar71xx_uart_freq; }
+static inline uint64_t ar71xx_wdt_freq(void) { return u_ar71xx_wdt_freq; }
+static inline uint64_t ar71xx_mdio_freq(void) { return u_ar71xx_mdio_freq; }
+
+#endif
diff --git a/sys/dev/netif/ath/ath_hal/ar71xx/ar71xxreg.h b/sys/dev/netif/ath/ath_hal/ar71xx/ar71xxreg.h
new file mode 100644 (file)
index 0000000..e8ece03
--- /dev/null
@@ -0,0 +1,565 @@
+/*-
+ * Copyright (c) 2009 Oleksandr Tymoshenko
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $FreeBSD$ */
+
+#ifndef _AR71XX_REG_H_
+#define _AR71XX_REG_H_
+
+/* PCI region */
+#define AR71XX_PCI_MEM_BASE            0x10000000
+/*
+ * PCI mem windows is 0x08000000 bytes long but we exclude control
+ * region from the resource manager
+ */
+#define AR71XX_PCI_MEM_SIZE            0x07000000
+#define AR71XX_PCI_IRQ_START           0
+#define AR71XX_PCI_IRQ_END             2
+#define AR71XX_PCI_NIRQS               3
+/*
+ * PCI devices slots are starting from this number
+ */
+#define        AR71XX_PCI_BASE_SLOT            17
+
+/* PCI config registers */
+#define        AR71XX_PCI_LCONF_CMD            0x17010000
+#define                        PCI_LCONF_CMD_READ      0x00000000
+#define                        PCI_LCONF_CMD_WRITE     0x00010000
+#define        AR71XX_PCI_LCONF_WRITE_DATA     0x17010004
+#define        AR71XX_PCI_LCONF_READ_DATA      0x17010008
+#define        AR71XX_PCI_CONF_ADDR            0x1701000C
+#define        AR71XX_PCI_CONF_CMD             0x17010010
+#define                        PCI_CONF_CMD_READ       0x0000000A
+#define                        PCI_CONF_CMD_WRITE      0x0000000B
+#define        AR71XX_PCI_CONF_WRITE_DATA      0x17010014
+#define        AR71XX_PCI_CONF_READ_DATA       0x17010018
+#define        AR71XX_PCI_ERROR                0x1701001C
+#define        AR71XX_PCI_ERROR_ADDR           0x17010020
+#define        AR71XX_PCI_AHB_ERROR            0x17010024
+#define        AR71XX_PCI_AHB_ERROR_ADDR       0x17010028
+
+/* APB region */
+/*
+ * Size is not really true actual APB window size is
+ * 0x01000000 but it should handle OHCI memory as well
+ * because this controller's interrupt is routed through
+ * APB.
+ */
+#define AR71XX_APB_BASE         0x18000000
+#define AR71XX_APB_SIZE         0x06000000
+
+/* DDR registers */
+#define AR71XX_DDR_CONFIG              0x18000000
+#define AR71XX_DDR_CONFIG2             0x18000004
+#define AR71XX_DDR_MODE_REGISTER       0x18000008
+#define AR71XX_DDR_EXT_MODE_REGISTER   0x1800000C
+#define AR71XX_DDR_CONTROL             0x18000010
+#define AR71XX_DDR_REFRESH             0x18000014
+#define AR71XX_DDR_RD_DATA_THIS_CYCLE  0x18000018
+#define AR71XX_TAP_CONTROL0            0x1800001C
+#define AR71XX_TAP_CONTROL1            0x18000020
+#define AR71XX_TAP_CONTROL2            0x18000024
+#define AR71XX_TAP_CONTROL3            0x18000028
+#define AR71XX_PCI_WINDOW0             0x1800007C
+#define AR71XX_PCI_WINDOW1             0x18000080
+#define AR71XX_PCI_WINDOW2             0x18000084
+#define AR71XX_PCI_WINDOW3             0x18000088
+#define AR71XX_PCI_WINDOW4             0x1800008C
+#define AR71XX_PCI_WINDOW5             0x18000090
+#define AR71XX_PCI_WINDOW6             0x18000094
+#define AR71XX_PCI_WINDOW7             0x18000098
+#define AR71XX_WB_FLUSH_GE0            0x1800009C
+#define AR71XX_WB_FLUSH_GE1            0x180000A0
+#define AR71XX_WB_FLUSH_USB            0x180000A4
+#define AR71XX_WB_FLUSH_PCI            0x180000A8
+
+/*
+ * Values for PCI_WINDOW_X registers
+ */
+#define PCI_WINDOW0_ADDR               0x10000000
+#define PCI_WINDOW1_ADDR               0x11000000
+#define PCI_WINDOW2_ADDR               0x12000000
+#define PCI_WINDOW3_ADDR               0x13000000
+#define PCI_WINDOW4_ADDR               0x14000000
+#define PCI_WINDOW5_ADDR               0x15000000
+#define PCI_WINDOW6_ADDR               0x16000000
+#define PCI_WINDOW7_ADDR               0x17000000
+/* This value enables acces to PCI config registers */
+#define PCI_WINDOW7_CONF_ADDR          0x07000000
+
+#define        AR71XX_UART_ADDR                0x18020000
+
+#define        AR71XX_USB_CTRL_FLADJ           0x18030000
+#define                USB_CTRL_FLADJ_HOST_SHIFT       12
+#define                USB_CTRL_FLADJ_A5_SHIFT         10
+#define                USB_CTRL_FLADJ_A4_SHIFT         8
+#define                USB_CTRL_FLADJ_A3_SHIFT         6
+#define                USB_CTRL_FLADJ_A2_SHIFT         4
+#define                USB_CTRL_FLADJ_A1_SHIFT         2
+#define                USB_CTRL_FLADJ_A0_SHIFT         0
+#define        AR71XX_USB_CTRL_CONFIG          0x18030004
+#define                USB_CTRL_CONFIG_OHCI_DES_SWAP   (1 << 19)
+#define                USB_CTRL_CONFIG_OHCI_BUF_SWAP   (1 << 18)
+#define                USB_CTRL_CONFIG_EHCI_DES_SWAP   (1 << 17)
+#define                USB_CTRL_CONFIG_EHCI_BUF_SWAP   (1 << 16)
+#define                USB_CTRL_CONFIG_DISABLE_XTL     (1 << 13)
+#define                USB_CTRL_CONFIG_OVERRIDE_XTL    (1 << 12)
+#define                USB_CTRL_CONFIG_CLK_SEL_SHIFT   4
+#define                USB_CTRL_CONFIG_CLK_SEL_MASK    3
+#define                USB_CTRL_CONFIG_CLK_SEL_12      0
+#define                USB_CTRL_CONFIG_CLK_SEL_24      1
+#define                USB_CTRL_CONFIG_CLK_SEL_48      2
+#define                USB_CTRL_CONFIG_OVER_CURRENT_AS_GPIO    (1 << 8)
+#define                USB_CTRL_CONFIG_SS_SIMULATION_MODE      (1 << 2)
+#define                USB_CTRL_CONFIG_RESUME_UTMI_PLS_DIS     (1 << 1)
+#define                USB_CTRL_CONFIG_UTMI_BACKWARD_ENB       (1 << 0)
+
+#define        AR71XX_GPIO_BASE                0x18040000
+#define                AR71XX_GPIO_OE                  0x00
+#define                AR71XX_GPIO_IN                  0x04
+#define                AR71XX_GPIO_OUT                 0x08
+#define                AR71XX_GPIO_SET                 0x0c
+#define                AR71XX_GPIO_CLEAR               0x10
+#define                AR71XX_GPIO_INT                 0x14
+#define                AR71XX_GPIO_INT_TYPE            0x18
+#define                AR71XX_GPIO_INT_POLARITY        0x1c
+#define                AR71XX_GPIO_INT_PENDING         0x20
+#define                AR71XX_GPIO_INT_MASK            0x24
+#define                AR71XX_GPIO_FUNCTION            0x28
+#define                        GPIO_FUNC_STEREO_EN     (1 << 17)
+#define                        GPIO_FUNC_SLIC_EN       (1 << 16)
+#define                        GPIO_FUNC_SPI_CS2_EN    (1 << 13)
+                               /* CS2 is shared with GPIO_1 */
+#define                        GPIO_FUNC_SPI_CS1_EN    (1 << 12)
+                               /* CS1 is shared with GPIO_0 */
+#define                        GPIO_FUNC_UART_EN       (1 << 8)
+#define                        GPIO_FUNC_USB_OC_EN     (1 << 4)
+#define                        GPIO_FUNC_USB_CLK_EN    (0)
+
+#define        AR71XX_BASE_FREQ                40000000
+#define        AR71XX_PLL_CPU_BASE             0x18050000
+#define        AR71XX_PLL_CPU_CONFIG           0x18050000
+#define                PLL_SW_UPDATE                   (1U << 31)
+#define                PLL_LOCKED                      (1 << 30)
+#define                PLL_AHB_DIV_SHIFT               20
+#define                PLL_AHB_DIV_MASK                7
+#define                PLL_DDR_DIV_SEL_SHIFT           18
+#define                PLL_DDR_DIV_SEL_MASK            3
+#define                PLL_CPU_DIV_SEL_SHIFT           16
+#define                PLL_CPU_DIV_SEL_MASK            3
+#define                PLL_LOOP_BW_SHIFT               12
+#define                PLL_LOOP_BW_MASK                0xf
+#define                PLL_DIV_IN_SHIFT                10
+#define                PLL_DIV_IN_MASK                 3
+#define                PLL_DIV_OUT_SHIFT               8
+#define                PLL_DIV_OUT_MASK                3
+#define                PLL_FB_SHIFT                    3
+#define                PLL_FB_MASK                     0x1f
+#define                PLL_BYPASS                      (1 << 1)
+#define                PLL_POWER_DOWN                  (1 << 0)
+#define        AR71XX_PLL_SEC_CONFIG           0x18050004
+#define                AR71XX_PLL_ETH0_SHIFT           17
+#define                AR71XX_PLL_ETH1_SHIFT           19
+#define        AR71XX_PLL_CPU_CLK_CTRL         0x18050008
+#define        AR71XX_PLL_ETH_INT0_CLK         0x18050010
+#define        AR71XX_PLL_ETH_INT1_CLK         0x18050014
+#define                XPLL_ETH_INT_CLK_10             0x00991099
+#define                XPLL_ETH_INT_CLK_100            0x00441011
+#define                XPLL_ETH_INT_CLK_1000           0x13110000
+#define                XPLL_ETH_INT_CLK_1000_GMII      0x14110000
+#define                PLL_ETH_INT_CLK_10              0x00991099
+#define                PLL_ETH_INT_CLK_100             0x00001099
+#define                PLL_ETH_INT_CLK_1000            0x00110000
+#define        AR71XX_PLL_ETH_EXT_CLK          0x18050018
+#define        AR71XX_PLL_PCI_CLK              0x1805001C
+
+/* Reset block */
+#define        AR71XX_RST_BLOCK_BASE   0x18060000
+
+#define AR71XX_RST_WDOG_CONTROL        0x18060008
+#define                RST_WDOG_LAST                   (1U << 31)
+#define                RST_WDOG_ACTION_MASK            3
+#define                RST_WDOG_ACTION_RESET           3
+#define                RST_WDOG_ACTION_NMI             2
+#define                RST_WDOG_ACTION_GP_INTR         1
+#define                RST_WDOG_ACTION_NOACTION        0
+
+#define AR71XX_RST_WDOG_TIMER  0x1806000C
+/*
+ * APB interrupt status and mask register and interrupt bit numbers for
+ */
+#define AR71XX_MISC_INTR_STATUS        0x18060010
+#define AR71XX_MISC_INTR_MASK  0x18060014
+#define                MISC_INTR_TIMER         0
+#define                MISC_INTR_ERROR         1
+#define                MISC_INTR_GPIO          2
+#define                MISC_INTR_UART          3
+#define                MISC_INTR_WATCHDOG      4
+#define                MISC_INTR_PERF          5
+#define                MISC_INTR_OHCI          6
+#define                MISC_INTR_DMA           7
+
+#define AR71XX_PCI_INTR_STATUS 0x18060018
+#define AR71XX_PCI_INTR_MASK   0x1806001C
+#define                PCI_INTR_CORE           (1 << 4)
+
+#define AR71XX_RST_RESET       0x18060024
+#define                RST_RESET_FULL_CHIP     (1 << 24) /* Same as pulling
+                                                            the reset pin */
+#define                RST_RESET_CPU_COLD      (1 << 20) /* Cold reset */
+#define                RST_RESET_GE1_MAC       (1 << 13)
+#define                RST_RESET_GE1_PHY       (1 << 12)
+#define                RST_RESET_GE0_MAC       (1 <<  9)
+#define                RST_RESET_GE0_PHY       (1 <<  8)
+#define                RST_RESET_USB_OHCI_DLL  (1 <<  6)
+#define                RST_RESET_USB_HOST      (1 <<  5)
+#define                RST_RESET_USB_PHY       (1 <<  4)
+#define                RST_RESET_PCI_BUS       (1 <<  1)
+#define                RST_RESET_PCI_CORE      (1 <<  0)
+
+/* Chipset revision details */
+#define        AR71XX_RST_RESET_REG_REV_ID     0x18060090
+#define                REV_ID_MAJOR_MASK       0xfff0
+#define                REV_ID_MAJOR_AR71XX     0x00a0
+#define                REV_ID_MAJOR_AR913X     0x00b0
+#define                REV_ID_MAJOR_AR7240     0x00c0
+#define                REV_ID_MAJOR_AR7241     0x0100
+#define                REV_ID_MAJOR_AR7242     0x1100
+
+/* AR71XX chipset revision details */
+#define                AR71XX_REV_ID_MINOR_MASK        0x3
+#define                AR71XX_REV_ID_MINOR_AR7130      0x0
+#define                AR71XX_REV_ID_MINOR_AR7141      0x1
+#define                AR71XX_REV_ID_MINOR_AR7161      0x2
+#define                AR71XX_REV_ID_REVISION_MASK     0x3
+#define                AR71XX_REV_ID_REVISION_SHIFT    2
+
+/* AR724X chipset revision details */
+#define                AR724X_REV_ID_REVISION_MASK     0x3
+
+/* AR91XX chipset revision details */
+#define                AR91XX_REV_ID_MINOR_MASK        0x3
+#define                AR91XX_REV_ID_MINOR_AR9130      0x0
+#define                AR91XX_REV_ID_MINOR_AR9132      0x1
+#define                AR91XX_REV_ID_REVISION_MASK     0x3
+#define                AR91XX_REV_ID_REVISION_SHIFT    2
+
+typedef enum {
+       AR71XX_MII_MODE_NONE = 0,
+       AR71XX_MII_MODE_GMII,
+       AR71XX_MII_MODE_MII,
+       AR71XX_MII_MODE_RGMII,
+       AR71XX_MII_MODE_RMII,
+} ar71xx_mii_mode;
+
+/*
+ * AR71xx MII control region
+ */
+#define        AR71XX_MII0_CTRL        0x18070000
+#define                        MII_CTRL_SPEED_SHIFT    4
+#define                        MII_CTRL_SPEED_MASK     3
+#define                                MII_CTRL_SPEED_10       0
+#define                                MII_CTRL_SPEED_100      1
+#define                                MII_CTRL_SPEED_1000     2
+#define                        MII_CTRL_IF_MASK        3
+#define                        MII_CTRL_IF_SHIFT       0
+#define                                MII0_CTRL_IF_GMII       0
+#define                                MII0_CTRL_IF_MII        1
+#define                                MII0_CTRL_IF_RGMII      2
+#define                                MII0_CTRL_IF_RMII       3
+
+#define        AR71XX_MII1_CTRL        0x18070004
+
+#define                                MII1_CTRL_IF_RGMII      0
+#define                                MII1_CTRL_IF_RMII       1
+
+/*
+ * GigE adapters region
+ */
+#define AR71XX_MAC0_BASE       0x19000000
+#define AR71XX_MAC1_BASE       0x1A000000
+
+#define                AR71XX_MAC_CFG1                 0x00
+#define                        MAC_CFG1_SOFT_RESET             (1U << 31)
+#define                        MAC_CFG1_SIMUL_RESET            (1 << 30)
+#define                        MAC_CFG1_MAC_RX_BLOCK_RESET     (1 << 19)
+#define                        MAC_CFG1_MAC_TX_BLOCK_RESET     (1 << 18)
+#define                        MAC_CFG1_RX_FUNC_RESET          (1 << 17)
+#define                        MAC_CFG1_TX_FUNC_RESET          (1 << 16)
+#define                        MAC_CFG1_LOOPBACK               (1 <<  8)
+#define                        MAC_CFG1_RXFLOW_CTRL            (1 <<  5)
+#define                        MAC_CFG1_TXFLOW_CTRL            (1 <<  4)
+#define                        MAC_CFG1_SYNC_RX                (1 <<  3)
+#define                        MAC_CFG1_RX_ENABLE              (1 <<  2)
+#define                        MAC_CFG1_SYNC_TX                (1 <<  1)
+#define                        MAC_CFG1_TX_ENABLE              (1 <<  0)
+#define                AR71XX_MAC_CFG2                 0x04
+#define                        MAC_CFG2_PREAMBLE_LEN_MASK      0xf
+#define                        MAC_CFG2_PREAMBLE_LEN_SHIFT     12
+#define                        MAC_CFG2_IFACE_MODE_1000        (2 << 8)
+#define                        MAC_CFG2_IFACE_MODE_10_100      (1 << 8)
+#define                        MAC_CFG2_IFACE_MODE_SHIFT       8
+#define                        MAC_CFG2_IFACE_MODE_MASK        3
+#define                        MAC_CFG2_HUGE_FRAME             (1 << 5)
+#define                        MAC_CFG2_LENGTH_FIELD           (1 << 4)
+#define                        MAC_CFG2_ENABLE_PADCRC          (1 << 2)
+#define                        MAC_CFG2_ENABLE_CRC             (1 << 1)
+#define                        MAC_CFG2_FULL_DUPLEX            (1 << 0)
+#define                AR71XX_MAC_IFG                  0x08
+#define                AR71XX_MAC_HDUPLEX              0x0C
+#define                AR71XX_MAC_MAX_FRAME_LEN        0x10
+#define                AR71XX_MAC_MII_CFG              0x20
+#define                        MAC_MII_CFG_RESET               (1U << 31)
+#define                        MAC_MII_CFG_SCAN_AUTO_INC       (1 <<  5)
+#define                        MAC_MII_CFG_PREAMBLE_SUP        (1 <<  4)
+#define                        MAC_MII_CFG_CLOCK_SELECT_MASK   0x7
+#define                        MAC_MII_CFG_CLOCK_SELECT_MASK_AR933X    0xf
+#define                        MAC_MII_CFG_CLOCK_DIV_4         0
+#define                        MAC_MII_CFG_CLOCK_DIV_6         2
+#define                        MAC_MII_CFG_CLOCK_DIV_8         3
+#define                        MAC_MII_CFG_CLOCK_DIV_10        4
+#define                        MAC_MII_CFG_CLOCK_DIV_14        5
+#define                        MAC_MII_CFG_CLOCK_DIV_20        6
+#define                        MAC_MII_CFG_CLOCK_DIV_28        7
+
+/* .. and the AR933x/AR934x extensions */
+#define                        MAC_MII_CFG_CLOCK_DIV_34        8
+#define                        MAC_MII_CFG_CLOCK_DIV_42        9
+#define                        MAC_MII_CFG_CLOCK_DIV_50        10
+#define                        MAC_MII_CFG_CLOCK_DIV_58        11
+#define                        MAC_MII_CFG_CLOCK_DIV_66        12
+#define                        MAC_MII_CFG_CLOCK_DIV_74        13
+#define                        MAC_MII_CFG_CLOCK_DIV_82        14
+#define                        MAC_MII_CFG_CLOCK_DIV_98        15
+
+#define                AR71XX_MAC_MII_CMD              0x24
+#define                        MAC_MII_CMD_SCAN_CYCLE          (1 << 1)
+#define                        MAC_MII_CMD_READ                1
+#define                        MAC_MII_CMD_WRITE               0
+#define                AR71XX_MAC_MII_ADDR             0x28
+#define                        MAC_MII_PHY_ADDR_SHIFT          8
+#define                        MAC_MII_PHY_ADDR_MASK           0xff
+#define                        MAC_MII_REG_MASK                0x1f
+#define                AR71XX_MAC_MII_CONTROL          0x2C
+#define                        MAC_MII_CONTROL_MASK            0xffff
+#define                AR71XX_MAC_MII_STATUS           0x30
+#define                        MAC_MII_STATUS_MASK             0xffff
+#define                AR71XX_MAC_MII_INDICATOR        0x34
+#define                        MAC_MII_INDICATOR_NOT_VALID     (1 << 2)
+#define                        MAC_MII_INDICATOR_SCANNING      (1 << 1)
+#define                        MAC_MII_INDICATOR_BUSY          (1 << 0)
+#define                AR71XX_MAC_IFCONTROL            0x38
+#define                        MAC_IFCONTROL_SPEED     (1 << 16)
+#define                AR71XX_MAC_STA_ADDR1            0x40
+#define                AR71XX_MAC_STA_ADDR2            0x44
+#define                AR71XX_MAC_FIFO_CFG0            0x48
+#define                        FIFO_CFG0_TX_FABRIC             (1 << 4)
+#define                        FIFO_CFG0_TX_SYSTEM             (1 << 3)
+#define                        FIFO_CFG0_RX_FABRIC             (1 << 2)
+#define                        FIFO_CFG0_RX_SYSTEM             (1 << 1)
+#define                        FIFO_CFG0_WATERMARK             (1 << 0)
+#define                        FIFO_CFG0_ALL                   ((1 << 5) - 1)
+#define                        FIFO_CFG0_ENABLE_SHIFT          8
+#define                AR71XX_MAC_FIFO_CFG1            0x4C
+#define                AR71XX_MAC_FIFO_CFG2            0x50
+#define                AR71XX_MAC_FIFO_TX_THRESHOLD    0x54
+#define                AR71XX_MAC_FIFO_RX_FILTMATCH    0x58
+/*
+ * These flags applicable both to AR71XX_MAC_FIFO_RX_FILTMASK and
+ * to AR71XX_MAC_FIFO_RX_FILTMATCH
+ */
+#define                        FIFO_RX_MATCH_UNICAST           (1 << 17)
+#define                        FIFO_RX_MATCH_TRUNC_FRAME       (1 << 16)
+#define                        FIFO_RX_MATCH_VLAN_TAG          (1 << 15)
+#define                        FIFO_RX_MATCH_UNSUP_OPCODE      (1 << 14)
+#define                        FIFO_RX_MATCH_PAUSE_FRAME       (1 << 13)
+#define                        FIFO_RX_MATCH_CTRL_FRAME        (1 << 12)
+#define                        FIFO_RX_MATCH_LONG_EVENT        (1 << 11)
+#define                        FIFO_RX_MATCH_DRIBBLE_NIBBLE    (1 << 10)
+#define                        FIFO_RX_MATCH_BCAST             (1 <<  9)
+#define                        FIFO_RX_MATCH_MCAST             (1 <<  8)
+#define                        FIFO_RX_MATCH_OK                (1 <<  7)
+#define                        FIFO_RX_MATCH_OORANGE           (1 <<  6)
+#define                        FIFO_RX_MATCH_LEN_MSMTCH        (1 <<  5)
+#define                        FIFO_RX_MATCH_CRC_ERROR         (1 <<  4)
+#define                        FIFO_RX_MATCH_CODE_ERROR        (1 <<  3)
+#define                        FIFO_RX_MATCH_FALSE_CARRIER     (1 <<  2)
+#define                        FIFO_RX_MATCH_RX_DV_EVENT       (1 <<  1)
+#define                        FIFO_RX_MATCH_DROP_EVENT        (1 <<  0)
+/*
+ * Exclude unicast and truncated frames from matching
+ */
+#define                        FIFO_RX_FILTMATCH_DEFAULT               \
+                               (FIFO_RX_MATCH_VLAN_TAG         | \
+                               FIFO_RX_MATCH_UNSUP_OPCODE      | \
+                               FIFO_RX_MATCH_PAUSE_FRAME       | \
+                               FIFO_RX_MATCH_CTRL_FRAME        | \
+                               FIFO_RX_MATCH_LONG_EVENT        | \
+                               FIFO_RX_MATCH_DRIBBLE_NIBBLE    | \
+                               FIFO_RX_MATCH_BCAST             | \
+                               FIFO_RX_MATCH_MCAST             | \
+                               FIFO_RX_MATCH_OK                | \
+                               FIFO_RX_MATCH_OORANGE           | \
+                               FIFO_RX_MATCH_LEN_MSMTCH        | \
+                               FIFO_RX_MATCH_CRC_ERROR         | \
+                               FIFO_RX_MATCH_CODE_ERROR        | \
+                               FIFO_RX_MATCH_FALSE_CARRIER     | \
+                               FIFO_RX_MATCH_RX_DV_EVENT       | \
+                               FIFO_RX_MATCH_DROP_EVENT)
+#define                AR71XX_MAC_FIFO_RX_FILTMASK     0x5C
+#define                        FIFO_RX_MASK_BYTE_MODE          (1 << 19)
+#define                        FIFO_RX_MASK_NO_SHORT_FRAME     (1 << 18)
+#define                        FIFO_RX_MASK_BIT17              (1 << 17)
+#define                        FIFO_RX_MASK_BIT16              (1 << 16)
+#define                        FIFO_RX_MASK_TRUNC_FRAME        (1 << 15)
+#define                        FIFO_RX_MASK_LONG_EVENT         (1 << 14)
+#define                        FIFO_RX_MASK_VLAN_TAG           (1 << 13)
+#define                        FIFO_RX_MASK_UNSUP_OPCODE       (1 << 12)
+#define                        FIFO_RX_MASK_PAUSE_FRAME        (1 << 11)
+#define                        FIFO_RX_MASK_CTRL_FRAME         (1 << 10)
+#define                        FIFO_RX_MASK_DRIBBLE_NIBBLE     (1 <<  9)
+#define                        FIFO_RX_MASK_BCAST              (1 <<  8)
+#define                        FIFO_RX_MASK_MCAST              (1 <<  7)
+#define                        FIFO_RX_MASK_OK                 (1 <<  6)
+#define                        FIFO_RX_MASK_OORANGE            (1 <<  5)
+#define                        FIFO_RX_MASK_LEN_MSMTCH         (1 <<  4)
+#define                        FIFO_RX_MASK_CODE_ERROR         (1 <<  3)
+#define                        FIFO_RX_MASK_FALSE_CARRIER      (1 <<  2)
+#define                        FIFO_RX_MASK_RX_DV_EVENT        (1 <<  1)
+#define                        FIFO_RX_MASK_DROP_EVENT         (1 <<  0)
+
+/*
+ *  Len. mismatch, unsup. opcode and short frmae bits excluded
+ */
+#define                        FIFO_RX_FILTMASK_DEFAULT \
+                               (FIFO_RX_MASK_NO_SHORT_FRAME    | \
+                               FIFO_RX_MASK_BIT17              | \
+                               FIFO_RX_MASK_BIT16              | \
+                               FIFO_RX_MASK_TRUNC_FRAME        | \
+                               FIFO_RX_MASK_LONG_EVENT         | \
+                               FIFO_RX_MASK_VLAN_TAG           | \
+                               FIFO_RX_MASK_PAUSE_FRAME        | \
+                               FIFO_RX_MASK_CTRL_FRAME         | \
+                               FIFO_RX_MASK_DRIBBLE_NIBBLE     | \
+                               FIFO_RX_MASK_BCAST              | \
+                               FIFO_RX_MASK_MCAST              | \
+                               FIFO_RX_MASK_OK                 | \
+                               FIFO_RX_MASK_OORANGE            | \
+                               FIFO_RX_MASK_CODE_ERROR         | \
+                               FIFO_RX_MASK_FALSE_CARRIER      | \
+                               FIFO_RX_MASK_RX_DV_EVENT        | \
+                               FIFO_RX_MASK_DROP_EVENT)
+
+#define                AR71XX_MAC_FIFO_RAM0            0x60
+#define                AR71XX_MAC_FIFO_RAM1            0x64
+#define                AR71XX_MAC_FIFO_RAM2            0x68
+#define                AR71XX_MAC_FIFO_RAM3            0x6C
+#define                AR71XX_MAC_FIFO_RAM4            0x70
+#define                AR71XX_MAC_FIFO_RAM5            0x74
+#define                AR71XX_MAC_FIFO_RAM6            0x78
+#define                AR71XX_DMA_TX_CONTROL           0x180
+#define                        DMA_TX_CONTROL_EN               (1 << 0)
+#define                AR71XX_DMA_TX_DESC              0x184
+#define                AR71XX_DMA_TX_STATUS            0x188
+#define                        DMA_TX_STATUS_PCOUNT_MASK       0xff
+#define                        DMA_TX_STATUS_PCOUNT_SHIFT      16
+#define                        DMA_TX_STATUS_BUS_ERROR         (1 << 3)
+#define                        DMA_TX_STATUS_UNDERRUN          (1 << 1)
+#define                        DMA_TX_STATUS_PKT_SENT          (1 << 0)
+#define                AR71XX_DMA_RX_CONTROL           0x18C
+#define                        DMA_RX_CONTROL_EN               (1 << 0)
+#define                AR71XX_DMA_RX_DESC              0x190
+#define                AR71XX_DMA_RX_STATUS            0x194
+#define                        DMA_RX_STATUS_PCOUNT_MASK       0xff
+#define                        DMA_RX_STATUS_PCOUNT_SHIFT      16
+#define                        DMA_RX_STATUS_BUS_ERROR         (1 << 3)
+#define                        DMA_RX_STATUS_OVERFLOW          (1 << 2)
+#define                        DMA_RX_STATUS_PKT_RECVD         (1 << 0)
+#define                AR71XX_DMA_INTR                         0x198
+#define                AR71XX_DMA_INTR_STATUS                  0x19C
+#define                        DMA_INTR_ALL                    ((1 << 8) - 1)
+#define                        DMA_INTR_RX_BUS_ERROR           (1 << 7)
+#define                        DMA_INTR_RX_OVERFLOW            (1 << 6)
+#define                        DMA_INTR_RX_PKT_RCVD            (1 << 4)
+#define                        DMA_INTR_TX_BUS_ERROR           (1 << 3)
+#define                        DMA_INTR_TX_UNDERRUN            (1 << 1)
+#define                        DMA_INTR_TX_PKT_SENT            (1 << 0)
+
+#define        AR71XX_SPI_BASE 0x1f000000
+#define                AR71XX_SPI_FS           0x00
+#define                AR71XX_SPI_CTRL         0x04
+#define                        SPI_CTRL_REMAP_DISABLE          (1 << 6)
+#define                        SPI_CTRL_CLOCK_DIVIDER_MASK     ((1 << 6) - 1)
+#define                AR71XX_SPI_IO_CTRL      0x08
+#define                        SPI_IO_CTRL_CS2                 (1 << 18)
+#define                        SPI_IO_CTRL_CS1                 (1 << 17)
+#define                        SPI_IO_CTRL_CS0                 (1 << 16)
+#define                        SPI_IO_CTRL_CSMASK              (7 << 16)
+#define                        SPI_IO_CTRL_CLK                 (1 << 8)
+#define                        SPI_IO_CTRL_DO                  1
+#define                AR71XX_SPI_RDS          0x0C
+
+#define ATH_READ_REG(reg) \
+    *((volatile uint32_t *)MIPS_PHYS_TO_KSEG1((reg)))
+
+#define ATH_WRITE_REG(reg, val) \
+    *((volatile uint32_t *)MIPS_PHYS_TO_KSEG1((reg))) = (val)
+
+static inline void
+ar71xx_ddr_flush(uint32_t reg)
+{
+       ATH_WRITE_REG(reg, 1);
+       while ((ATH_READ_REG(reg) & 0x1))
+               ;
+       ATH_WRITE_REG(reg, 1);
+       while ((ATH_READ_REG(reg) & 0x1))
+               ;
+}
+
+static inline void
+ar71xx_write_pll(uint32_t cfg_reg, uint32_t pll_reg, uint32_t pll, uint32_t pll_reg_shift)
+{
+       uint32_t sec_cfg;
+
+       /* set PLL registers */
+       sec_cfg = ATH_READ_REG(cfg_reg);
+       sec_cfg &= ~(3 << pll_reg_shift);
+       sec_cfg |= (2 << pll_reg_shift);
+
+       ATH_WRITE_REG(cfg_reg, sec_cfg);
+       DELAY(100);
+
+       ATH_WRITE_REG(pll_reg, pll);
+       sec_cfg |= (3 << pll_reg_shift);
+       ATH_WRITE_REG(cfg_reg, sec_cfg);
+       DELAY(100);
+
+       sec_cfg &= ~(3 << pll_reg_shift);
+       ATH_WRITE_REG(cfg_reg, sec_cfg);
+       DELAY(100);
+}
+
+#endif /* _AR71XX_REG_H_ */
index 2a67fe5..949b970 100644 (file)
@@ -315,7 +315,7 @@ ar9280Attach(uint16_t devid, HAL_SOFTC sc,
         */
        ecode = ath_hal_eepromGet(ah, AR_EEP_PWDCLKIND, &pwr);
        if (AR_SREV_MERLIN_20_OR_LATER(ah) && ecode == HAL_OK && pwr == 0) {
         */
        ecode = ath_hal_eepromGet(ah, AR_EEP_PWDCLKIND, &pwr);
        if (AR_SREV_MERLIN_20_OR_LATER(ah) && ecode == HAL_OK && pwr == 0) {
-               printf("[ath] enabling AN_TOP2_FIXUP\n");
+               kprintf("[ath] enabling AN_TOP2_FIXUP\n");
                AH5416(ah)->ah_need_an_top2_fixup = 1;
        }
 
                AH5416(ah)->ah_need_an_top2_fixup = 1;
        }
 
index 361930b..5076d7d 100644 (file)
@@ -342,7 +342,7 @@ ar9280SetPowerCalTable(struct ath_hal *ah, struct ar5416eeprom *pEepData,
        for (i = 0; i < AR5416_MAX_CHAINS; i++) {
                regChainOffset = ar5416GetRegChainOffset(ah, i);
                if (pEepData->baseEepHeader.txMask & (1 << i)) {
        for (i = 0; i < AR5416_MAX_CHAINS; i++) {
                regChainOffset = ar5416GetRegChainOffset(ah, i);
                if (pEepData->baseEepHeader.txMask & (1 << i)) {
-                       uint16_t diff;
+                       uint16_t diff = 0;
 
                        if (IEEE80211_IS_CHAN_2GHZ(chan)) {
                                pRawDataset = pEepData->calPierData2G[i];
 
                        if (IEEE80211_IS_CHAN_2GHZ(chan)) {
                                pRawDataset = pEepData->calPierData2G[i];
diff --git a/sys/dev/netif/ath/ath_hal/ar91xx/ar91xxreg.h b/sys/dev/netif/ath/ath_hal/ar91xx/ar91xxreg.h
new file mode 100644 (file)
index 0000000..2dfaeb5
--- /dev/null
@@ -0,0 +1,84 @@
+/*-
+ * Copyright (c) 2010 Adrian Chadd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $FreeBSD$ */
+
+#ifndef        __AR91XX_REG_H__
+#define        __AR91XX_REG_H__
+
+#define        AR91XX_BASE_FREQ                5000000
+
+/* reset block */
+#define        AR91XX_RESET_REG_RESET_MODULE   AR71XX_RST_BLOCK_BASE + 0x1c
+
+#define        AR91XX_RST_RESET_MODULE_USBSUS_OVERRIDE (1 << 10)
+#define        AR91XX_RST_RESET_MODULE_AMBA2WMAC       (1 << 22)
+
+/* PLL block */
+#define        AR91XX_PLL_REG_CPU_CONFIG       AR71XX_PLL_CPU_BASE + 0x00
+#define        AR91XX_PLL_REG_ETH_CONFIG       AR71XX_PLL_CPU_BASE + 0x04
+#define        AR91XX_PLL_REG_ETH0_INT_CLOCK   AR71XX_PLL_CPU_BASE + 0x14
+#define        AR91XX_PLL_REG_ETH1_INT_CLOCK   AR71XX_PLL_CPU_BASE + 0x18
+
+#define        AR91XX_PLL_DIV_SHIFT            0
+#define        AR91XX_PLL_DIV_MASK             0x3ff
+#define        AR91XX_DDR_DIV_SHIFT            22
+#define        AR91XX_DDR_DIV_MASK             0x3
+#define        AR91XX_AHB_DIV_SHIFT            19
+#define        AR91XX_AHB_DIV_MASK             0x1
+
+#define        AR91XX_ETH0_PLL_SHIFT           20
+#define        AR91XX_ETH1_PLL_SHIFT           22
+
+#define        AR91XX_PLL_VAL_1000             0x1a000000
+#define        AR91XX_PLL_VAL_100              0x13000a44
+#define        AR91XX_PLL_VAL_10               0x00441099
+
+/* DDR block */
+#define        AR91XX_DDR_CTRLBASE             (AR71XX_APB_BASE + 0)
+#define        AR91XX_DDR_CTRL_SIZE            0x10000
+#define        AR91XX_DDR_REG_FLUSH_GE0        AR91XX_DDR_CTRLBASE + 0x7c
+#define        AR91XX_DDR_REG_FLUSH_GE1        AR91XX_DDR_CTRLBASE + 0x80
+#define        AR91XX_DDR_REG_FLUSH_USB        AR91XX_DDR_CTRLBASE + 0x84
+#define        AR91XX_DDR_REG_FLUSH_WMAC       AR91XX_DDR_CTRLBASE + 0x88
+
+/* WMAC stuff */
+#define        AR91XX_WMAC_BASE                (AR71XX_APB_BASE + 0x000C0000)
+#define        AR91XX_WMAC_SIZE                0x30000
+
+/* GPIO stuff */
+#define        AR91XX_GPIO_FUNC_WMAC_LED_EN    (1 << 22)
+#define        AR91XX_GPIO_FUNC_EXP_PORT_CS_EN (1 << 21)
+#define        AR91XX_GPIO_FUNC_I2S_REFCLKEN   (1 << 20)
+#define        AR91XX_GPIO_FUNC_I2S_MCKEN      (1 << 19)
+#define        AR91XX_GPIO_FUNC_I2S1_EN        (1 << 18)
+#define        AR91XX_GPIO_FUNC_I2S0_EN        (1 << 17)
+#define        AR91XX_GPIO_FUNC_SLIC_EN        (1 << 16)
+#define        AR91XX_GPIO_FUNC_UART_RTSCTS_EN (1 << 9)
+#define        AR91XX_GPIO_FUNC_UART_EN        (1 << 8)
+#define        AR91XX_GPIO_FUNC_USB_CLK_EN     (1 << 4)
+
+#endif
index 53d7ed1..56bd558 100644 (file)
@@ -3,6 +3,6 @@
 
 KMOD=  ath_rate
 SRCS=  amrr.c
 
 KMOD=  ath_rate
 SRCS=  amrr.c
-SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h
+SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h opt_ath.h
 
 .include <bsd.kmod.mk>
 
 .include <bsd.kmod.mk>
index 1c3f342..38b2e08 100644 (file)
@@ -71,8 +71,6 @@
 #include <netinet/if_ether.h>
 #endif
 
 #include <netinet/if_ether.h>
 #endif
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath_rate/amrr/amrr.h>
 #include <dev/netif/ath/ath_hal/ah_desc.h>
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath_rate/amrr/amrr.h>
 #include <dev/netif/ath/ath_hal/ah_desc.h>
@@ -429,8 +427,8 @@ ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an,
 static void
 ath_rate_sysctlattach(struct ath_softc *sc)
 {
 static void
 ath_rate_sysctlattach(struct ath_softc *sc)
 {
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
 
        SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
                "rate_interval", CTLFLAG_RW, &ath_rateinterval, 0,
 
        SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
                "rate_interval", CTLFLAG_RW, &ath_rateinterval, 0,
@@ -449,7 +447,7 @@ ath_rate_attach(struct ath_softc *sc)
 {
        struct amrr_softc *asc;
 
 {
        struct amrr_softc *asc;
 
-       asc = malloc(sizeof(struct amrr_softc), M_DEVBUF, M_NOWAIT|M_ZERO);
+       asc = kmalloc(sizeof(struct amrr_softc), M_DEVBUF, M_INTWAIT|M_ZERO);
        if (asc == NULL)
                return NULL;
        asc->arc.arc_space = sizeof(struct amrr_node);
        if (asc == NULL)
                return NULL;
        asc->arc.arc_space = sizeof(struct amrr_node);
@@ -463,5 +461,46 @@ ath_rate_detach(struct ath_ratectrl *arc)
 {
        struct amrr_softc *asc = (struct amrr_softc *) arc;
 
 {
        struct amrr_softc *asc = (struct amrr_softc *) arc;
 
-       free(asc, M_DEVBUF);
+       kfree(asc, M_DEVBUF);
+}
+
+/*
+ * Module glue.
+ */
+static int
+amrr_modevent(module_t mod, int type, void *unused)
+{
+       int error;
+
+       wlan_serialize_enter();
+
+       switch (type) {
+       case MOD_LOAD:
+               if (bootverbose) {
+                       kprintf("ath_rate: <AMRR rate control "
+                               "algorithm> version 0.1\n");
+               }
+               error = 0;
+               break;
+       case MOD_UNLOAD:
+               error = 0;
+               break;
+       default:
+               error = EINVAL;
+               break;
+       }
+       wlan_serialize_exit();
+
+       return error;
 }
 }
+
+static moduledata_t amrr_mod = {
+        "ath_rate",
+       amrr_modevent,
+       0
+};
+
+DECLARE_MODULE(ath_rate, amrr_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
+MODULE_VERSION(ath_rate, 1);
+MODULE_DEPEND(ath_rate, ath_hal, 1, 1, 1);
+MODULE_DEPEND(ath_rate, wlan, 1, 1, 1);
index 44385d3..63fd96c 100644 (file)
@@ -3,6 +3,6 @@
 
 KMOD=  ath_rate
 SRCS=  onoe.c
 
 KMOD=  ath_rate
 SRCS=  onoe.c
-SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h
+SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h opt_ath.h
 
 .include <bsd.kmod.mk>
 
 .include <bsd.kmod.mk>
index 2dd0556..5e4d434 100644 (file)
@@ -60,8 +60,6 @@
 #include <netinet/if_ether.h>
 #endif
 
 #include <netinet/if_ether.h>
 #endif
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath_rate/onoe/onoe.h>
 #include <dev/netif/ath/ath_hal/ah_desc.h>
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath_rate/onoe/onoe.h>
 #include <dev/netif/ath/ath_hal/ah_desc.h>
@@ -389,8 +387,8 @@ ath_rate_ctl(void *arg, struct ieee80211_node *ni)
 static void
 ath_rate_sysctlattach(struct ath_softc *sc)
 {
 static void
 ath_rate_sysctlattach(struct ath_softc *sc)
 {
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
 
        SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
                "rate_interval", CTLFLAG_RW, &ath_rateinterval, 0,
 
        SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
                "rate_interval", CTLFLAG_RW, &ath_rateinterval, 0,
@@ -417,7 +415,7 @@ ath_rate_attach(struct ath_softc *sc)
 {
        struct onoe_softc *osc;
 
 {
        struct onoe_softc *osc;
 
-       osc = malloc(sizeof(struct onoe_softc), M_DEVBUF, M_NOWAIT|M_ZERO);
+       osc = kmalloc(sizeof(struct onoe_softc), M_DEVBUF, M_INTWAIT|M_ZERO);
        if (osc == NULL)
                return NULL;
        osc->arc.arc_space = sizeof(struct onoe_node);
        if (osc == NULL)
                return NULL;
        osc->arc.arc_space = sizeof(struct onoe_node);
@@ -431,5 +429,46 @@ ath_rate_detach(struct ath_ratectrl *arc)
 {
        struct onoe_softc *osc = (struct onoe_softc *) arc;
 
 {
        struct onoe_softc *osc = (struct onoe_softc *) arc;
 
-       free(osc, M_DEVBUF);
+       kfree(osc, M_DEVBUF);
 }
 }
+
+/*
+ * Module glue.
+ */
+static int
+onoe_modevent(module_t mod, int type, void *unused)
+{
+       int error;
+
+       wlan_serialize_enter();
+
+       switch (type) {
+       case MOD_LOAD:
+               if (bootverbose) {
+                       kprintf("ath_rate: <Atsushi Onoe's rate "
+                               "control algorithm>\n");
+               }
+               error = 0;
+               break;
+       case MOD_UNLOAD:
+               error = 0;
+               break;
+       default:
+               error = EINVAL;
+               break;
+       }
+       wlan_serialize_exit();
+
+       return error;
+}
+
+static moduledata_t onoe_mod = {
+       "ath_rate",
+       onoe_modevent,
+       0
+};
+
+DECLARE_MODULE(ath_rate, onoe_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
+MODULE_VERSION(ath_rate, 1);
+MODULE_DEPEND(ath_rate, ath_hal, 1, 1, 1);
+MODULE_DEPEND(ath_rate, wlan, 1, 1, 1);
index 834e5e9..bccda26 100644 (file)
@@ -3,6 +3,6 @@
 
 KMOD=  ath_rate
 SRCS=  sample.c
 
 KMOD=  ath_rate
 SRCS=  sample.c
-SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h
+SRCS+= device_if.h bus_if.h pci_if.h opt_ah.h opt_wlan.h opt_inet.h opt_ath.h
 
 .include <bsd.kmod.mk>
 
 .include <bsd.kmod.mk>
index 159593b..f9ef40b 100644 (file)
 #include <netinet/if_ether.h>
 #endif
 
 #include <netinet/if_ether.h>
 #endif
 
-#include <machine/resource.h>
-
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath_rate/sample/sample.h>
 #include <dev/netif/ath/ath_hal/ah_desc.h>
 #include <dev/netif/ath/ath_rate/sample/tx_schedules.h>
 
 #include <dev/netif/ath/ath/if_athvar.h>
 #include <dev/netif/ath/ath_rate/sample/sample.h>
 #include <dev/netif/ath/ath_hal/ah_desc.h>
 #include <dev/netif/ath/ath_rate/sample/tx_schedules.h>
 
+extern  const char* ath_hal_ether_sprintf(const uint8_t *mac);
+
 /*
  * This file is an implementation of the SampleRate algorithm
  * in "Bit-rate Selection in Wireless Networks"
 /*
  * This file is an implementation of the SampleRate algorithm
  * in "Bit-rate Selection in Wireless Networks"
@@ -584,7 +584,7 @@ ath_rate_findrate(struct ath_softc *sc, struct ath_node *an,
                         * This is likely not optimal!
                         */
 #if 0
                         * This is likely not optimal!
                         */
 #if 0
-                       printf("cur rix/att %x/%d, best rix/att %x/%d\n",
+                       kprintf("cur rix/att %x/%d, best rix/att %x/%d\n",
                            MCS(cur_rix), cur_att, MCS(best_rix), average_tx_time);
 #endif
                        if ((MCS(best_rix) > MCS(cur_rix)) &&
                            MCS(cur_rix), cur_att, MCS(best_rix), average_tx_time);
 #endif
                        if ((MCS(best_rix) > MCS(cur_rix)) &&
@@ -638,7 +638,7 @@ done:
         * out how to better reproduce it.
         */
        if (rix < 0 || rix >= rt->rateCount) {
         * out how to better reproduce it.
         */
        if (rix < 0 || rix >= rt->rateCount) {
-               printf("%s: ERROR: rix %d out of bounds (rateCount=%d)\n",
+               kprintf("%s: ERROR: rix %d out of bounds (rateCount=%d)\n",
                    __func__,
                    rix,
                    rt->rateCount);
                    __func__,
                    rix,
                    rt->rateCount);
@@ -1094,11 +1094,11 @@ ath_rate_ctl_reset(struct ath_softc *sc, struct ieee80211_node *ni)
                for (mask = sn->ratemask, rix = 0; mask != 0; mask >>= 1, rix++) {
                        if ((mask & 1) == 0)
                                continue;
                for (mask = sn->ratemask, rix = 0; mask != 0; mask >>= 1, rix++) {
                        if ((mask & 1) == 0)
                                continue;
-                       printf(" %d %s/%d", dot11rate(rt, rix), dot11rate_label(rt, rix),
+                       kprintf(" %d %s/%d", dot11rate(rt, rix), dot11rate_label(rt, rix),
                            calc_usecs_unicast_packet(sc, 1600, rix, 0,0,
                                (ni->ni_chw == 40)));
                }
                            calc_usecs_unicast_packet(sc, 1600, rix, 0,0,
                                (ni->ni_chw == 40)));
                }
-               printf("\n");
+               kprintf("\n");
        }
 #endif
        for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
        }
 #endif
        for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
@@ -1193,8 +1193,8 @@ ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an,
         * Take a temporary copy of the sample node state so we can
         * modify it before we copy it.
         */
         * Take a temporary copy of the sample node state so we can
         * modify it before we copy it.
         */
-       tv = malloc(sizeof(struct ath_rateioctl_rt), M_TEMP,
-           M_NOWAIT | M_ZERO);
+       tv = kmalloc(sizeof(struct ath_rateioctl_rt), M_TEMP,
+                    M_INTWAIT | M_ZERO);
        if (tv == NULL) {
                return (ENOMEM);
        }
        if (tv == NULL) {
                return (ENOMEM);
        }
@@ -1234,7 +1234,7 @@ ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an,
        copyout(sn, rs->buf + o, sizeof(struct sample_node));
        o += sizeof(struct sample_node);
 
        copyout(sn, rs->buf + o, sizeof(struct sample_node));
        o += sizeof(struct sample_node);
 
-       free(tv, M_TEMP);
+       kfree(tv, M_TEMP);
 
        return (0);
 }
 
        return (0);
 }
@@ -1248,25 +1248,26 @@ sample_stats(void *arg, struct ieee80211_node *ni)
        uint64_t mask;
        int rix, y;
 
        uint64_t mask;
        int rix, y;
 
-       printf("\n[%s] refcnt %d static_rix (%d %s) ratemask 0x%jx\n",
-           ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni),
+       kprintf("\n[%s] refcnt %d static_rix (%d %s) ratemask 0x%jx\n",
+           ath_hal_ether_sprintf(ni->ni_macaddr),
+           ieee80211_node_refcnt(ni),
            dot11rate(rt, sn->static_rix),
            dot11rate_label(rt, sn->static_rix),
            (uintmax_t)sn->ratemask);
        for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
            dot11rate(rt, sn->static_rix),
            dot11rate_label(rt, sn->static_rix),
            (uintmax_t)sn->ratemask);
        for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
-               printf("[%4u] cur rix %d (%d %s) since switch: packets %d ticks %u\n",
+               kprintf("[%4u] cur rix %d (%d %s) since switch: packets %d ticks %u\n",
                    bin_to_size(y), sn->current_rix[y],
                    dot11rate(rt, sn->current_rix[y]),
                    dot11rate_label(rt, sn->current_rix[y]),
                    sn->packets_since_switch[y], sn->ticks_since_switch[y]);
                    bin_to_size(y), sn->current_rix[y],
                    dot11rate(rt, sn->current_rix[y]),
                    dot11rate_label(rt, sn->current_rix[y]),
                    sn->packets_since_switch[y], sn->ticks_since_switch[y]);
-               printf("[%4u] last sample (%d %s) cur sample (%d %s) packets sent %d\n",
+               kprintf("[%4u] last sample (%d %s) cur sample (%d %s) packets sent %d\n",
                    bin_to_size(y),
                    dot11rate(rt, sn->last_sample_rix[y]),
                    dot11rate_label(rt, sn->last_sample_rix[y]),
                    dot11rate(rt, sn->current_sample_rix[y]),
                    dot11rate_label(rt, sn->current_sample_rix[y]),
                    sn->packets_sent[y]);
                    bin_to_size(y),
                    dot11rate(rt, sn->last_sample_rix[y]),
                    dot11rate_label(rt, sn->last_sample_rix[y]),
                    dot11rate(rt, sn->current_sample_rix[y]),
                    dot11rate_label(rt, sn->current_sample_rix[y]),
                    sn->packets_sent[y]);
-               printf("[%4u] packets since sample %d sample tt %u\n",
+               kprintf("[%4u] packets since sample %d sample tt %u\n",
                    bin_to_size(y), sn->packets_since_sample[y],
                    sn->sample_tt[y]);
        }
                    bin_to_size(y), sn->packets_since_sample[y],
                    sn->sample_tt[y]);
        }
@@ -1276,7 +1277,7 @@ sample_stats(void *arg, struct ieee80211_node *ni)
                for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
                        if (sn->stats[y][rix].total_packets == 0)
                                continue;
                for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
                        if (sn->stats[y][rix].total_packets == 0)
                                continue;
-                       printf("[%2u %s:%4u] %8ju:%-8ju (%3d%%) (EWMA %3d.%1d%%) T %8ju F %4d avg %5u last %u\n",
+                       kprintf("[%2u %s:%4u] %8ju:%-8ju (%3d%%) (EWMA %3d.%1d%%) T %8ju F %4d avg %5u last %u\n",
                            dot11rate(rt, rix), dot11rate_label(rt, rix),
                            bin_to_size(y),
                            (uintmax_t) sn->stats[y][rix].total_packets,
                            dot11rate(rt, rix), dot11rate_label(rt, rix),
                            bin_to_size(y),
                            (uintmax_t) sn->stats[y][rix].total_packets,
@@ -1345,8 +1346,8 @@ ath_rate_sysctl_sample_rate(SYSCTL_HANDLER_ARGS)
 static void
 ath_rate_sysctlattach(struct ath_softc *sc, struct sample_softc *ssc)
 {
 static void
 ath_rate_sysctlattach(struct ath_softc *sc, struct sample_softc *ssc)
 {
-       struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
-       struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
+       struct sysctl_ctx_list *ctx = &sc->sc_sysctl_ctx;
+       struct sysctl_oid *tree = sc->sc_sysctl_tree;
 
        SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
            "smoothing_rate", CTLTYPE_INT | CTLFLAG_RW, ssc, 0,
 
        SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
            "smoothing_rate", CTLTYPE_INT | CTLFLAG_RW, ssc, 0,
@@ -1367,7 +1368,7 @@ ath_rate_attach(struct ath_softc *sc)
 {
        struct sample_softc *ssc;
        
 {
        struct sample_softc *ssc;
        
-       ssc = malloc(sizeof(struct sample_softc), M_DEVBUF, M_NOWAIT|M_ZERO);
+       ssc = kmalloc(sizeof(struct sample_softc), M_DEVBUF, M_INTWAIT|M_ZERO);
        if (ssc == NULL)
                return NULL;
        ssc->arc.arc_space = sizeof(struct sample_node);
        if (ssc == NULL)
                return NULL;
        ssc->arc.arc_space = sizeof(struct sample_node);
@@ -1386,5 +1387,46 @@ ath_rate_detach(struct ath_ratectrl *arc)
 {
        struct sample_softc *ssc = (struct sample_softc *) arc;
        
 {
        struct sample_softc *ssc = (struct sample_softc *) arc;
        
-       free(ssc, M_DEVBUF);
+       kfree(ssc, M_DEVBUF);
 }
 }
+
+/*
+ * Module glue.
+ */
+static int
+sample_modevent(module_t mod, int type, void *unused)
+{
+        int error;
+
+        wlan_serialize_enter();
+
+        switch (type) {
+        case MOD_LOAD:
+                if (bootverbose) {
+                        kprintf("ath_rate: <SampleRate bit-rate "
+                                "selection algorithm>\n");
+                }
+                error = 0;
+                break;
+        case MOD_UNLOAD:
+                error = 0;
+                break;
+        default:
+                error = EINVAL;
+                break;
+        }
+        wlan_serialize_exit();
+
+        return error;
+}
+
+static moduledata_t sample_mod = {
+       "ath_rate",
+       sample_modevent,
+       0
+};
+
+DECLARE_MODULE(ath_rate, sample_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
+MODULE_VERSION(ath_rate, 1);
+MODULE_DEPEND(ath_rate, ath_hal, 1, 1, 1);
+MODULE_DEPEND(ath_rate, wlan, 1, 1, 1);
index 7438a3d..235fae5 100644 (file)
@@ -149,7 +149,7 @@ static unsigned calc_usecs_unicast_packet(struct ath_softc *sc,
        KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
 
        if (rix >= rt->rateCount) {
        KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
 
        if (rix >= rt->rateCount) {
-               printf("bogus rix %d, max %u, mode %u\n",
+               kprintf("bogus rix %d, max %u, mode %u\n",
                       rix, rt->rateCount, sc->sc_curmode);
                return 0;
        }
                       rix, rt->rateCount, sc->sc_curmode);
                return 0;
        }