wlan - Sync dev/netif/ath from FreeBSD part 4/N
authorMatthew Dillon <dillon@backplane.com>
Thu, 12 May 2016 05:49:30 +0000 (22:49 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 24 May 2016 04:27:09 +0000 (21:27 -0700)
* Sync dev/netif/ath from FreeBSD, fbsd git dd885b9a0a0e, May 11 2016.
  (freebase + our Makefiles, does not include dfly adjustments).

74 files changed:
sys/dev/netif/ath/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_debug.h
sys/dev/netif/ath/ath/if_ath_descdma.c [new file with mode: 0644]
sys/dev/netif/ath/ath/if_ath_descdma.h [copied from sys/dev/netif/ath/ath/if_ath_keycache.h with 68% similarity]
sys/dev/netif/ath/ath/if_ath_ioctl.c [new file with mode: 0644]
sys/dev/netif/ath/ath/if_ath_ioctl.h [copied from sys/dev/netif/ath/ath/if_ath_keycache.h with 72% similarity]
sys/dev/netif/ath/ath/if_ath_keycache.c
sys/dev/netif/ath/ath/if_ath_keycache.h
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_misc.h
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_tdma.c
sys/dev/netif/ath/ath/if_ath_tx.c
sys/dev/netif/ath/ath/if_ath_tx.h
sys/dev/netif/ath/ath/if_ath_tx_edma.c
sys/dev/netif/ath/ath/if_ath_tx_ht.c
sys/dev/netif/ath/ath/if_athioctl.h
sys/dev/netif/ath/ath/if_athvar.h
sys/dev/netif/ath/ath_dfs/null/dfs_null.c
sys/dev/netif/ath/ath_hal/ah.c
sys/dev/netif/ath/ath_hal/ah.h
sys/dev/netif/ath/ath_hal/ah_devid.h
sys/dev/netif/ath/ath_hal/ah_eeprom_9287.c
sys/dev/netif/ath/ath_hal/ah_eeprom_v4k.c
sys/dev/netif/ath/ath_hal/ah_internal.h
sys/dev/netif/ath/ath_hal/ah_osdep.c
sys/dev/netif/ath/ath_hal/ah_osdep.h
sys/dev/netif/ath/ath_hal/ah_regdomain.c
sys/dev/netif/ath/ath_hal/ar5210/ar5210.h
sys/dev/netif/ath/ath_hal/ar5210/ar5210_reset.c
sys/dev/netif/ath/ath_hal/ar5211/ar5211.h
sys/dev/netif/ath/ath_hal/ar5211/ar5211_reset.c
sys/dev/netif/ath/ath_hal/ar5212/ar2316.c
sys/dev/netif/ath/ath_hal/ar5212/ar2317.c
sys/dev/netif/ath/ath_hal/ar5212/ar2413.c
sys/dev/netif/ath/ath_hal/ar5212/ar2425.c
sys/dev/netif/ath/ath_hal/ar5212/ar5212.h
sys/dev/netif/ath/ath_hal/ar5212/ar5212_ani.c
sys/dev/netif/ath/ath_hal/ar5212/ar5212_attach.c
sys/dev/netif/ath/ath_hal/ar5212/ar5212_misc.c
sys/dev/netif/ath/ath_hal/ar5212/ar5212_power.c
sys/dev/netif/ath/ath_hal/ar5212/ar5212_reset.c
sys/dev/netif/ath/ath_hal/ar5212/ar5413.c
sys/dev/netif/ath/ath_hal/ar5312/ar5312.h
sys/dev/netif/ath/ath_hal/ar5312/ar5312_reset.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416.h
sys/dev/netif/ath/ath_hal/ar5416/ar5416_ani.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416_attach.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416_btcoex.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416_cal.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416_radar.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416_reset.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416_spectral.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416_xmit.c
sys/dev/netif/ath/ath_hal/ar5416/ar5416reg.h
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/ar9002/ar9285_btcoex.c
sys/dev/netif/ath/ath_hal/ar9003/ar9300_devid.h
sys/dev/netif/ath/ath_rate/amrr/amrr.c
sys/dev/netif/ath/ath_rate/onoe/onoe.c
sys/dev/netif/ath/ath_rate/sample/sample.c
sys/dev/netif/ath/ath_rate/sample/sample.h

index ff16889..f185f01 100644 (file)
@@ -9,6 +9,7 @@ SRCS+=  if_ath_alq.c if_ath_lna_div.c if_ath_tdma.c
 SRCS+= if_ath_beacon.c if_ath_pci.c if_ath_tx.c
 SRCS+= if_ath_btcoex.c if_ath_rx.c if_ath_tx_edma.c
 SRCS+= if_ath_debug.c if_ath_rx_edma.c if_ath_tx_ht.c
+SRCS+= if_ath_descdma.c if_ath_ioctl.c
 
 SRCS+= device_if.h bus_if.h pci_if.h
 SRCS+= opt_ath.h opt_ah.h opt_wlan.h opt_inet.h opt_ktr.h
index 64712a6..87daaf3 100644 (file)
@@ -30,8 +30,6 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#define CTLFLAG_RWTUN  CTLFLAG_RW
-
 /*
  * Driver for the Atheros Wireless LAN controller.
  *
@@ -70,6 +68,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/module.h>
 #include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
+
+#include <machine/bus.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -79,15 +80,14 @@ __FBSDID("$FreeBSD$");
 #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 <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
 
 #include <net/bpf.h>
@@ -97,32 +97,34 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
-
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
-#include <dev/netif/ath/ath/if_ath_tsf.h>
-#include <dev/netif/ath/ath/if_ath_tx.h>
-#include <dev/netif/ath/ath/if_ath_sysctl.h>
-#include <dev/netif/ath/ath/if_ath_led.h>
-#include <dev/netif/ath/ath/if_ath_keycache.h>
-#include <dev/netif/ath/ath/if_ath_rx.h>
-#include <dev/netif/ath/ath/if_ath_rx_edma.h>
-#include <dev/netif/ath/ath/if_ath_tx_edma.h>
-#include <dev/netif/ath/ath/if_ath_beacon.h>
-#include <dev/netif/ath/ath/if_ath_btcoex.h>
-#include <dev/netif/ath/ath/if_ath_spectral.h>
-#include <dev/netif/ath/ath/if_ath_lna_div.h>
-#include <dev/netif/ath/ath/if_athdfs.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
+
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_tsf.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_sysctl.h>
+#include <dev/ath/if_ath_led.h>
+#include <dev/ath/if_ath_keycache.h>
+#include <dev/ath/if_ath_rx.h>
+#include <dev/ath/if_ath_rx_edma.h>
+#include <dev/ath/if_ath_tx_edma.h>
+#include <dev/ath/if_ath_beacon.h>
+#include <dev/ath/if_ath_btcoex.h>
+#include <dev/ath/if_ath_spectral.h>
+#include <dev/ath/if_ath_lna_div.h>
+#include <dev/ath/if_athdfs.h>
+#include <dev/ath/if_ath_ioctl.h>
+#include <dev/ath/if_ath_descdma.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
 #ifdef ATH_DEBUG_ALQ
-#include <dev/netif/ath/ath/if_ath_alq.h>
+#include <dev/ath/if_ath_alq.h>
 #endif
 
 /*
@@ -151,21 +153,13 @@ static struct ieee80211vap *ath_vap_create(struct ieee80211com *,
                    const uint8_t [IEEE80211_ADDR_LEN],
                    const uint8_t [IEEE80211_ADDR_LEN]);
 static void    ath_vap_delete(struct ieee80211vap *);
-static void    ath_init(void *);
-static void    ath_stop_locked(struct ifnet *);
-static void    ath_stop(struct ifnet *);
+static int     ath_init(struct ath_softc *);
+static void    ath_stop(struct ath_softc *);
 static int     ath_reset_vap(struct ieee80211vap *, u_long);
-static int     ath_transmit(struct ifnet *ifp, struct mbuf *m);
-#if !defined(__DragonFly__)
-static void    ath_qflush(struct ifnet *ifp);
-#endif
+static int     ath_transmit(struct ieee80211com *, struct mbuf *);
 static int     ath_media_change(struct ifnet *);
 static void    ath_watchdog(void *);
-#if defined(__DragonFly__)
-static int     ath_ioctl(struct ifnet *, u_long, caddr_t, struct ucred * __unused);
-#else
-static int     ath_ioctl(struct ifnet *, u_long, caddr_t);
-#endif
+static void    ath_parent(struct ieee80211com *);
 static void    ath_fatal_proc(void *, int);
 static void    ath_bmiss_vap(struct ieee80211vap *);
 static void    ath_bmiss_proc(void *, int);
@@ -225,16 +219,10 @@ 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 *);
 
-#if defined(__DragonFly__)
-static void    ath_start(struct ifnet *ifp, struct ifaltq_subque *ifsq);
-#endif
-
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <dev/netif/ath/ath/if_ath_tdma.h>
+#include <dev/ath/if_ath_tdma.h>
 #endif
 
-extern const char* ath_hal_ether_sprintf(const u_int8_t *mac);
-
 SYSCTL_DECL(_hw_ath);
 
 /* XXX validate sysctl values */
@@ -254,17 +242,12 @@ SYSCTL_INT(_hw_ath, OID_AUTO, anical, CTLFLAG_RW, &ath_anicalinterval,
 int ath_rxbuf = ATH_RXBUF;             /* # rx buffers to allocate */
 SYSCTL_INT(_hw_ath, OID_AUTO, rxbuf, CTLFLAG_RWTUN, &ath_rxbuf,
            0, "rx buffers allocated");
-TUNABLE_INT("hw.ath.rxbuf", &ath_rxbuf);
-
 int ath_txbuf = ATH_TXBUF;             /* # tx buffers to allocate */
 SYSCTL_INT(_hw_ath, OID_AUTO, txbuf, CTLFLAG_RWTUN, &ath_txbuf,
            0, "tx buffers allocated");
-TUNABLE_INT("hw.ath.txbuf", &ath_txbuf);
-
 int ath_txbuf_mgmt = ATH_MGMT_TXBUF;   /* # mgmt tx buffers to allocate */
 SYSCTL_INT(_hw_ath, OID_AUTO, txbuf_mgmt, CTLFLAG_RWTUN, &ath_txbuf_mgmt,
            0, "tx (mgmt) buffers allocated");
-TUNABLE_INT("hw.ath.txbuf_mgmt", &ath_txbuf_mgmt);
 
 int ath_bstuck_threshold = 4;          /* max missed beacons */
 SYSCTL_INT(_hw_ath, OID_AUTO, bstuck, CTLFLAG_RW, &ath_bstuck_threshold,
@@ -527,6 +510,60 @@ ath_setup_hal_config(struct ath_softc *sc, HAL_OPS_CONFIG *ah_config)
 
 }
 
+/*
+ * Attempt to fetch the MAC address from the kernel environment.
+ *
+ * Returns 0, macaddr in macaddr if successful; -1 otherwise.
+ */
+static int
+ath_fetch_mac_kenv(struct ath_softc *sc, uint8_t *macaddr)
+{
+       char devid_str[32];
+       int local_mac = 0;
+       char *local_macstr;
+
+       /*
+        * Fetch from the kenv rather than using hints.
+        *
+        * Hints would be nice but the transition to dynamic
+        * hints/kenv doesn't happen early enough for this
+        * to work reliably (eg on anything embedded.)
+        */
+       snprintf(devid_str, 32, "hint.%s.%d.macaddr",
+           device_get_name(sc->sc_dev),
+           device_get_unit(sc->sc_dev));
+
+       if ((local_macstr = kern_getenv(devid_str)) != NULL) {
+               uint32_t tmpmac[ETHER_ADDR_LEN];
+               int count;
+               int i;
+
+               /* Have a MAC address; should use it */
+               device_printf(sc->sc_dev,
+                   "Overriding MAC address from environment: '%s'\n",
+                   local_macstr);
+
+               /* Extract out the MAC address */
+               count = sscanf(local_macstr, "%x%*c%x%*c%x%*c%x%*c%x%*c%x",
+                   &tmpmac[0], &tmpmac[1],
+                   &tmpmac[2], &tmpmac[3],
+                   &tmpmac[4], &tmpmac[5]);
+               if (count == 6) {
+                       /* Valid! */
+                       local_mac = 1;
+                       for (i = 0; i < ETHER_ADDR_LEN; i++)
+                               macaddr[i] = tmpmac[i];
+               }
+               /* Done! */
+               freeenv(local_macstr);
+               local_macstr = NULL;
+       }
+
+       if (local_mac)
+               return (0);
+       return (-1);
+}
+
 #define        HAL_MODE_HT20 (HAL_MODE_11NG_HT20 | HAL_MODE_11NA_HT20)
 #define        HAL_MODE_HT40 \
        (HAL_MODE_11NG_HT40PLUS | HAL_MODE_11NG_HT40MINUS | \
@@ -534,36 +571,19 @@ ath_setup_hal_config(struct ath_softc *sc, HAL_OPS_CONFIG *ah_config)
 int
 ath_attach(u_int16_t devid, struct ath_softc *sc)
 {
-       struct ifnet *ifp;
-       struct ieee80211com *ic;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = NULL;
        HAL_STATUS status;
        int error = 0, i;
        u_int wmodes;
-       uint8_t macaddr[IEEE80211_ADDR_LEN];
        int rx_chainmask, tx_chainmask;
        HAL_OPS_CONFIG ah_config;
 
        DPRINTF(sc, ATH_DEBUG_ANY, "%s: devid 0x%x\n", __func__, devid);
 
-       wlan_serialize_enter();
-       CURVNET_SET(vnet0);
-       ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
-       if (ifp == NULL) {
-               device_printf(sc->sc_dev, "can not if_alloc()\n");
-               error = ENOSPC;
-               CURVNET_RESTORE();
-               goto bad;
-       }
-       ic = ifp->if_l2com;
        ic->ic_softc = sc;
        ic->ic_name = device_get_nameunit(sc->sc_dev);
 
-       /* set these up early for if_printf use */
-       if_initname(ifp, device_get_name(sc->sc_dev),
-               device_get_unit(sc->sc_dev));
-       CURVNET_RESTORE();
-
        /*
         * Configure the initial configuration data.
         *
@@ -576,8 +596,8 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
        ah = ath_hal_attach(devid, sc, sc->sc_st, sc->sc_sh,
            sc->sc_eepromdata, &ah_config, &status);
        if (ah == NULL) {
-               if_printf(ifp, "unable to attach hardware; HAL status %u\n",
-                       status);
+               device_printf(sc->sc_dev,
+                   "unable to attach hardware; HAL status %u\n", status);
                error = ENXIO;
                goto bad;
        }
@@ -628,8 +648,9 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
         */
        sc->sc_keymax = ath_hal_keycachesize(ah);
        if (sc->sc_keymax > ATH_KEYMAX) {
-               if_printf(ifp, "Warning, using only %u of %u key cache slots\n",
-                       ATH_KEYMAX, sc->sc_keymax);
+               device_printf(sc->sc_dev,
+                   "Warning, using only %u of %u key cache slots\n",
+                   ATH_KEYMAX, sc->sc_keymax);
                sc->sc_keymax = ATH_KEYMAX;
        }
        /*
@@ -668,14 +689,14 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
         */
        error = ath_desc_alloc(sc);
        if (error != 0) {
-               if_printf(ifp, "failed to allocate TX descriptors: %d\n",
-                   error);
+               device_printf(sc->sc_dev,
+                   "failed to allocate TX descriptors: %d\n", error);
                goto bad;
        }
        error = ath_txdma_setup(sc);
        if (error != 0) {
-               if_printf(ifp, "failed to allocate TX descriptors: %d\n",
-                   error);
+               device_printf(sc->sc_dev,
+                   "failed to allocate TX descriptors: %d\n", error);
                goto bad;
        }
 
@@ -684,20 +705,20 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
         */
        error = ath_rxdma_setup(sc);
        if (error != 0) {
-               if_printf(ifp, "failed to allocate RX descriptors: %d\n",
-                   error);
+               device_printf(sc->sc_dev,
+                    "failed to allocate RX descriptors: %d\n", error);
                goto bad;
        }
 
-       callout_init_lk(&sc->sc_cal_ch, &sc->sc_mtx);
-       callout_init_lk(&sc->sc_wd_ch, &sc->sc_mtx);
+       callout_init_mtx(&sc->sc_cal_ch, &sc->sc_mtx, 0);
+       callout_init_mtx(&sc->sc_wd_ch, &sc->sc_mtx, 0);
 
        ATH_TXBUF_LOCK_INIT(sc);
 
-       sc->sc_tq = taskqueue_create("ath_taskq", M_INTWAIT,
+       sc->sc_tq = taskqueue_create("ath_taskq", M_NOWAIT,
                taskqueue_thread_enqueue, &sc->sc_tq);
-       taskqueue_start_threads(&sc->sc_tq, 1, TDPRI_KERN_DAEMON, -1,
-               "%s taskq", ifp->if_xname);
+       taskqueue_start_threads(&sc->sc_tq, 1, PI_NET, "%s taskq",
+           device_get_nameunit(sc->sc_dev));
 
        TASK_INIT(&sc->sc_rxtask, 0, sc->sc_rx.recv_tasklet, sc);
        TASK_INIT(&sc->sc_bmisstask, 0, ath_bmiss_proc, sc);
@@ -716,20 +737,22 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
         */
        sc->sc_bhalq = ath_beaconq_setup(sc);
        if (sc->sc_bhalq == (u_int) -1) {
-               if_printf(ifp, "unable to setup a beacon xmit queue!\n");
+               device_printf(sc->sc_dev,
+                   "unable to setup a beacon xmit queue!\n");
                error = EIO;
                goto bad2;
        }
        sc->sc_cabq = ath_txq_setup(sc, HAL_TX_QUEUE_CAB, 0);
        if (sc->sc_cabq == NULL) {
-               if_printf(ifp, "unable to setup CAB xmit queue!\n");
+               device_printf(sc->sc_dev, "unable to setup CAB xmit queue!\n");
                error = EIO;
                goto bad2;
        }
        /* NB: insure BK queue is the lowest priority h/w queue */
        if (!ath_tx_setup(sc, WME_AC_BK, HAL_WME_AC_BK)) {
-               if_printf(ifp, "unable to setup xmit queue for %s traffic!\n",
-                       ieee80211_wme_acnames[WME_AC_BK]);
+               device_printf(sc->sc_dev,
+                   "unable to setup xmit queue for %s traffic!\n",
+                   ieee80211_wme_acnames[WME_AC_BK]);
                error = EIO;
                goto bad2;
        }
@@ -813,7 +836,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 */
-       callout_init_mp(&sc->sc_ledtimer);
+       callout_init(&sc->sc_ledtimer, 1);
 
        /*
         * Don't setup hardware-based blinking.
@@ -838,29 +861,6 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
        ath_led_config(sc);
        ath_hal_setledstate(ah, HAL_LED_INIT);
 
-       ifp->if_softc = sc;
-       ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
-#if defined(__DragonFly__)
-       ifp->if_start = ath_start;
-#else
-       ifp->if_transmit = ath_transmit;
-       ifp->if_qflush = ath_qflush;
-#endif
-       ifp->if_ioctl = ath_ioctl;
-       ifp->if_init = ath_init;
-#if defined(__DragonFly__)
-       if (sc->sc_isedma)
-               ifp->if_nmbjclusters = ath_rxbuf;
-       else
-               ifp->if_nmbclusters = ath_rxbuf;
-       ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
-#else
-       IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
-       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_phytype = IEEE80211_T_OFDM;
        ic->ic_opmode = IEEE80211_M_STA;
@@ -1062,6 +1062,7 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
        if (ath_hal_getcapability(ah, HAL_CAP_HT, 0, NULL) == HAL_OK &&
            (wmodes & (HAL_MODE_HT20 | HAL_MODE_HT40))) {
                uint32_t rxs, txs;
+               uint32_t ldpc;
 
                device_printf(sc->sc_dev, "[HT] enabling HT modes\n");
 
@@ -1073,7 +1074,6 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
                            | IEEE80211_HTCAP_MAXAMSDU_3839
                                                        /* max A-MSDU length */
                            | IEEE80211_HTCAP_SMPS_OFF; /* SM power save off */
-                       ;
 
                /*
                 * Enable short-GI for HT20 only if the hardware
@@ -1131,6 +1131,18 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
                            "[HT] RTS aggregates limited to %d KiB\n",
                            sc->sc_rts_aggr_limit / 1024);
 
+               /*
+                * LDPC
+                */
+               if ((ath_hal_getcapability(ah, HAL_CAP_LDPC, 0, &ldpc))
+                   == HAL_OK && (ldpc == 1)) {
+                       sc->sc_has_ldpc = 1;
+                       device_printf(sc->sc_dev,
+                           "[HT] LDPC transmit/receive enabled\n");
+                       ic->ic_htcaps |= IEEE80211_HTCAP_LDPC;
+               }
+
+
                device_printf(sc->sc_dev,
                    "[HT] %d RX streams; %d TX streams\n", rxs, txs);
        }
@@ -1150,7 +1162,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.
         */
-       if (ncpus > 1 &&
+       if (mp_ncpus > 1 &&
            ath_hal_getcapability(ah, HAL_CAP_SERIALISE_WAR,
             0, NULL) == HAL_OK) {
                sc->sc_ah->ah_config.ah_serialise_reg_war = 1;
@@ -1181,20 +1193,29 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
         */
        sc->sc_hasveol = ath_hal_hasveol(ah);
 
-       /* get mac address from hardware */
-       ath_hal_getmac(ah, macaddr);
+       /* get mac address from kenv first, then hardware */
+       if (ath_fetch_mac_kenv(sc, ic->ic_macaddr) == 0) {
+               /* Tell the HAL now about the new MAC */
+               ath_hal_setmac(ah, ic->ic_macaddr);
+       } else {
+               ath_hal_getmac(ah, ic->ic_macaddr);
+       }
+
        if (sc->sc_hasbmask)
                ath_hal_getbssidmask(ah, sc->sc_hwbssidmask);
 
        /* NB: used to size node table key mapping array */
        ic->ic_max_keyix = sc->sc_keymax;
-       /* Call MI attach routine. */
-       ieee80211_ifattach(ic, macaddr);
+       /* call MI attach routine. */
+       ieee80211_ifattach(ic);
        ic->ic_setregdomain = ath_setregdomain;
        ic->ic_getradiocaps = ath_getradiocaps;
        sc->sc_opmode = HAL_M_STA;
 
        /* override default methods */
+       ic->ic_ioctl = ath_ioctl;
+       ic->ic_parent = ath_parent;
+       ic->ic_transmit = ath_transmit;
        ic->ic_newassoc = ath_newassoc;
        ic->ic_updateslot = ath_updateslot;
        ic->ic_wme.wme_update = ath_wme_update;
@@ -1281,8 +1302,6 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
        ath_power_setpower(sc, HAL_PM_FULL_SLEEP);
        ATH_UNLOCK(sc);
 
-       wlan_serialize_exit();
-
        return 0;
 bad2:
        ath_tx_cleanup(sc);
@@ -1292,32 +1311,13 @@ bad2:
 bad:
        if (ah)
                ath_hal_detach(ah);
-
-       /*
-        * 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();
-       } else 
-#endif
-       if (ifp != NULL)
-               if_free(ifp);
        sc->sc_invalid = 1;
-       wlan_serialize_exit();
-
        return error;
 }
 
 int
 ath_detach(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-
-       DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
-               __func__, ifp->if_flags);
 
        /*
         * NB: the order of these is important:
@@ -1342,16 +1342,14 @@ ath_detach(struct ath_softc *sc)
        ATH_LOCK(sc);
        ath_power_set_power_state(sc, HAL_PM_AWAKE);
        ath_power_setpower(sc, HAL_PM_AWAKE);
-       ATH_UNLOCK(sc);
 
        /*
         * Stop things cleanly.
         */
-       ath_stop(ifp);
+       ath_stop(sc);
+       ATH_UNLOCK(sc);
 
-       wlan_serialize_enter();
-       ieee80211_ifdetach(ifp->if_l2com);
-       wlan_serialize_exit();
+       ieee80211_ifdetach(&sc->sc_ic);
        taskqueue_free(sc->sc_tq);
 #ifdef ATH_TX99_DIAG
        if (sc->sc_tx99 != NULL)
@@ -1371,10 +1369,6 @@ ath_detach(struct ath_softc *sc)
        ath_tx_cleanup(sc);
        ath_hal_detach(sc->sc_ah);      /* NB: sets chip in full sleep */
 
-       CURVNET_SET(ifp->if_vnet);
-       if_free(ifp);
-       CURVNET_RESTORE();
-
        return 0;
 }
 
@@ -1457,7 +1451,7 @@ ath_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
        int needbeacon, error;
        enum ieee80211_opmode ic_opmode;
 
-       avp = kmalloc(sizeof(struct ath_vap), M_80211_VAP, M_WAITOK | M_ZERO);
+       avp = malloc(sizeof(struct ath_vap), M_80211_VAP, M_WAITOK | M_ZERO);
        needbeacon = 0;
        IEEE80211_ADDR_COPY(mac, mac0);
 
@@ -1557,8 +1551,7 @@ ath_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
        vap = &avp->av_vap;
        /* XXX can't hold mutex across if_alloc */
        ATH_UNLOCK(sc);
-       error = ieee80211_vap_setup(ic, vap, name, unit, opmode, flags,
-           bssid, mac);
+       error = ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
        ATH_LOCK(sc);
        if (error != 0) {
                device_printf(sc->sc_dev, "%s: error %d creating vap\n",
@@ -1692,13 +1685,14 @@ ath_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
        ATH_UNLOCK(sc);
 
        /* complete setup */
-       ieee80211_vap_attach(vap, ath_media_change, ieee80211_media_status);
+       ieee80211_vap_attach(vap, ath_media_change, ieee80211_media_status,
+           mac);
        return vap;
 bad2:
        reclaim_address(sc, mac);
        ath_hal_setbssidmask(sc->sc_ah, sc->sc_hwbssidmask);
 bad:
-       kfree(avp, M_80211_VAP);
+       free(avp, M_80211_VAP);
        ATH_UNLOCK(sc);
        return NULL;
 }
@@ -1707,7 +1701,6 @@ static void
 ath_vap_delete(struct ieee80211vap *vap)
 {
        struct ieee80211com *ic = vap->iv_ic;
-       struct ifnet *ifp = ic->ic_ifp;
        struct ath_softc *sc = ic->ic_softc;
        struct ath_hal *ah = sc->sc_ah;
        struct ath_vap *avp = ATH_VAP(vap);
@@ -1717,7 +1710,7 @@ ath_vap_delete(struct ieee80211vap *vap)
        ATH_UNLOCK(sc);
 
        DPRINTF(sc, ATH_DEBUG_RESET, "%s: called\n", __func__);
-       if (ifp->if_flags & IFF_RUNNING) {
+       if (sc->sc_running) {
                /*
                 * Quiesce the hardware while we remove the vap.  In
                 * particular we need to reclaim all references to
@@ -1746,7 +1739,7 @@ ath_vap_delete(struct ieee80211vap *vap)
         * may be being scheduled between sw->hw txq. Tsk.
         *
         * TODO: figure out why a new node gets allocated somewhere around
-        * here (after the ath_tx_swq() call; and after an ath_stop_locked()
+        * here (after the ath_tx_swq() call; and after an ath_stop()
         * call!)
         */
 
@@ -1798,16 +1791,16 @@ ath_vap_delete(struct ieee80211vap *vap)
                sc->sc_swbmiss = 0;
        }
 #endif
-       kfree(avp, M_80211_VAP);
+       free(avp, M_80211_VAP);
 
-       if (ifp->if_flags & IFF_RUNNING) {
+       if (sc->sc_running) {
                /*
                 * Restart rx+tx machines if still running (RUNNING will
                 * be reset if we just destroyed the last vap).
                 */
                if (ath_startrecv(sc) != 0)
-                       if_printf(ifp, "%s: unable to restart recv logic\n",
-                           __func__);
+                       device_printf(sc->sc_dev,
+                           "%s: unable to restart recv logic\n", __func__);
                if (sc->sc_beacons) {           /* restart beacons */
 #ifdef IEEE80211_SUPPORT_TDMA
                        if (sc->sc_tdma)
@@ -1827,13 +1820,9 @@ ath_vap_delete(struct ieee80211vap *vap)
 void
 ath_suspend(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
-
-       DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
-               __func__, ifp->if_flags);
+       struct ieee80211com *ic = &sc->sc_ic;
 
-       sc->sc_resume_up = (ifp->if_flags & IFF_UP) != 0;
+       sc->sc_resume_up = ic->ic_nrunning != 0;
 
        ieee80211_suspend_all(ic);
        /*
@@ -1854,7 +1843,7 @@ ath_suspend(struct ath_softc *sc)
        taskqueue_block(sc->sc_tq);
 
        ATH_LOCK(sc);
-       callout_stop_sync(&sc->sc_cal_ch);
+       callout_stop(&sc->sc_cal_ch);
        ATH_UNLOCK(sc);
 
        /*
@@ -1874,8 +1863,7 @@ ath_suspend(struct ath_softc *sc)
 static void
 ath_reset_keycache(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        int i;
 
@@ -1917,15 +1905,10 @@ ath_update_chainmasks(struct ath_softc *sc, struct ieee80211_channel *chan)
 void
 ath_resume(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        HAL_STATUS status;
 
-       DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
-               __func__, ifp->if_flags);
-
-       /* Re-enable PCIe, re-enable the PCIe bus */
        ath_hal_enablepcie(ah, 0, 0);
 
        /*
@@ -1946,7 +1929,7 @@ ath_resume(struct ath_softc *sc)
 
        ath_hal_reset(ah, sc->sc_opmode,
            sc->sc_curchan != NULL ? sc->sc_curchan : ic->ic_curchan,
-           AH_FALSE, &status);
+           AH_FALSE, HAL_RESET_NORMAL, &status);
        ath_reset_keycache(sc);
 
        ATH_RX_LOCK(sc);
@@ -1991,12 +1974,10 @@ ath_resume(struct ath_softc *sc)
 void
 ath_shutdown(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
 
-       DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags %x\n",
-               __func__, ifp->if_flags);
-
-       ath_stop(ifp);
+       ATH_LOCK(sc);
+       ath_stop(sc);
+       ATH_UNLOCK(sc);
        /* NB: no point powering down chip as we're about to reboot */
 }
 
@@ -2007,7 +1988,6 @@ void
 ath_intr(void *arg)
 {
        struct ath_softc *sc = arg;
-       struct ifnet *ifp = sc->sc_ifp;
        struct ath_hal *ah = sc->sc_ah;
        HAL_INT status = 0;
        uint32_t txqs;
@@ -2046,12 +2026,11 @@ ath_intr(void *arg)
        ath_power_set_power_state(sc, HAL_PM_AWAKE);
        ATH_UNLOCK(sc);
 
-       if ((ifp->if_flags & IFF_UP) == 0 ||
-           (ifp->if_flags & IFF_RUNNING) == 0) {
+       if (sc->sc_ic.ic_nrunning == 0 && sc->sc_running == 0) {
                HAL_INT status;
 
-               DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags 0x%x\n",
-                       __func__, ifp->if_flags);
+               DPRINTF(sc, ATH_DEBUG_ANY, "%s: ic_nrunning %d sc_running %d\n",
+                   __func__, sc->sc_ic.ic_nrunning, sc->sc_running);
                ath_hal_getisr(ah, &status);    /* clear ISR */
                ath_hal_intrset(ah, 0);         /* disable further intr's */
                ATH_PCU_UNLOCK(sc);
@@ -2133,7 +2112,7 @@ ath_intr(void *arg)
 #ifdef IEEE80211_SUPPORT_TDMA
                        if (sc->sc_tdma) {
                                if (sc->sc_tdmaswba == 0) {
-                                       struct ieee80211com *ic = ifp->if_l2com;
+                                       struct ieee80211com *ic = &sc->sc_ic;
                                        struct ieee80211vap *vap =
                                            TAILQ_FIRST(&ic->ic_vaps);
                                        ath_tdma_beacon_send(sc, vap);
@@ -2289,27 +2268,27 @@ static void
 ath_fatal_proc(void *arg, int pending)
 {
        struct ath_softc *sc = arg;
-       struct ifnet *ifp = sc->sc_ifp;
        u_int32_t *state;
        u_int32_t len;
        void *sp;
 
-       if_printf(ifp, "hardware error; resetting\n");
+       if (sc->sc_invalid)
+               return;
+
+       device_printf(sc->sc_dev, "hardware error; resetting\n");
        /*
         * Fatal errors are unrecoverable.  Typically these
         * 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_printf(ifp, "0x%08x 0x%08x 0x%08x, 0x%08x 0x%08x 0x%08x\n",
-                   state[0], state[1] , state[2], state[3],
-                   state[4], state[5]);
+               device_printf(sc->sc_dev,
+                   "0x%08x 0x%08x 0x%08x, 0x%08x 0x%08x 0x%08x\n", state[0],
+                   state[1] , state[2], state[3], state[4], state[5]);
        }
-       ath_reset(ifp, ATH_RESET_NOLOSS);
-       wlan_serialize_exit();
+       ath_reset(sc, ATH_RESET_NOLOSS);
 }
 
 static void
@@ -2393,7 +2372,6 @@ static void
 ath_bmiss_proc(void *arg, int pending)
 {
        struct ath_softc *sc = arg;
-       struct ifnet *ifp = sc->sc_ifp;
        uint32_t hangs;
 
        DPRINTF(sc, ATH_DEBUG_ANY, "%s: pending %u\n", __func__, pending);
@@ -2411,11 +2389,12 @@ ath_bmiss_proc(void *arg, int pending)
         * to clear.
         */
        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);
+               ath_reset(sc, ATH_RESET_NOLOSS);
+               device_printf(sc->sc_dev,
+                   "bb hang detected (0x%x), resetting\n", hangs);
        } else {
-               ath_reset(ifp, ATH_RESET_NOLOSS);
-               ieee80211_beacon_miss(ifp->if_l2com);
+               ath_reset(sc, ATH_RESET_NOLOSS);
+               ieee80211_beacon_miss(&sc->sc_ic);
        }
 
        /* Force a beacon resync, in case they've drifted */
@@ -2435,8 +2414,7 @@ ath_bmiss_proc(void *arg, int pending)
 static void
 ath_settkipmic(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
 
        if ((ic->ic_cryptocaps & IEEE80211_CRYPTO_TKIP) && !sc->sc_wmetkipmic) {
                if (ic->ic_flags & IEEE80211_F_WME) {
@@ -2449,19 +2427,15 @@ ath_settkipmic(struct ath_softc *sc)
        }
 }
 
-static void
-ath_init(void *arg)
+static int
+ath_init(struct ath_softc *sc)
 {
-       struct ath_softc *sc = (struct ath_softc *) arg;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        HAL_STATUS status;
 
-       DPRINTF(sc, ATH_DEBUG_ANY, "%s: if_flags 0x%x\n",
-               __func__, ifp->if_flags);
+       ATH_LOCK_ASSERT(sc);
 
-       ATH_LOCK(sc);
        /*
         * Force the sleep state awake.
         */
@@ -2473,7 +2447,7 @@ ath_init(void *arg)
         * Stop anything previously setup.  This is safe
         * whether this is the first time through or not.
         */
-       ath_stop_locked(ifp);
+       ath_stop(sc);
 
        /*
         * The basic interface to setting the hardware in a good
@@ -2487,11 +2461,11 @@ ath_init(void *arg)
        ath_hal_setchainmasks(sc->sc_ah, sc->sc_cur_txchainmask,
            sc->sc_cur_rxchainmask);
 
-       if (!ath_hal_reset(ah, sc->sc_opmode, ic->ic_curchan, AH_FALSE, &status)) {
-               if_printf(ifp, "unable to reset hardware; hal status %u\n",
-                       status);
-               ATH_UNLOCK(sc);
-               return;
+       if (!ath_hal_reset(ah, sc->sc_opmode, ic->ic_curchan, AH_FALSE,
+           HAL_RESET_NORMAL, &status)) {
+               device_printf(sc->sc_dev,
+                   "unable to reset hardware; hal status %u\n", status);
+               return (ENODEV);
        }
 
        ATH_RX_LOCK(sc);
@@ -2526,11 +2500,11 @@ ath_init(void *arg)
         * state cached in the driver.
         */
        sc->sc_diversity = ath_hal_getdiversity(ah);
-       sc->sc_lastlongcal = 0;
+       sc->sc_lastlongcal = ticks;
        sc->sc_resetcal = 1;
        sc->sc_lastcalreset = 0;
-       sc->sc_lastani = 0;
-       sc->sc_lastshortcal = 0;
+       sc->sc_lastani = ticks;
+       sc->sc_lastshortcal = ticks;
        sc->sc_doresetcal = AH_FALSE;
        /*
         * Beacon timers were cleared here; give ath_newstate()
@@ -2547,10 +2521,9 @@ ath_init(void *arg)
         * here except setup the interrupt mask.
         */
        if (ath_startrecv(sc) != 0) {
-               if_printf(ifp, "unable to start recv logic\n");
+               device_printf(sc->sc_dev, "unable to start recv logic\n");
                ath_power_restore_power_state(sc);
-               ATH_UNLOCK(sc);
-               return;
+               return (ENODEV);
        }
 
        /*
@@ -2598,30 +2571,20 @@ ath_init(void *arg)
        DPRINTF(sc, ATH_DEBUG_RESET, "%s: imask=0x%x\n",
                __func__, sc->sc_imask);
 
-       ifp->if_flags |= IFF_RUNNING;
+       sc->sc_running = 1;
        callout_reset(&sc->sc_wd_ch, hz, ath_watchdog, sc);
        ath_hal_intrset(ah, sc->sc_imask);
 
        ath_power_restore_power_state(sc);
-       ATH_UNLOCK(sc);
 
-#ifdef ATH_TX99_DIAG
-       if (sc->sc_tx99 != NULL)
-               sc->sc_tx99->start(sc->sc_tx99);
-       else
-#endif
-       ieee80211_start_all(ic);                /* start all vap's */
+       return (0);
 }
 
 static void
-ath_stop_locked(struct ifnet *ifp)
+ath_stop(struct ath_softc *sc)
 {
-       struct ath_softc *sc = ifp->if_softc;
        struct ath_hal *ah = sc->sc_ah;
 
-       DPRINTF(sc, ATH_DEBUG_ANY, "%s: invalid %u if_flags 0x%x\n",
-               __func__, sc->sc_invalid, ifp->if_flags);
-
        ATH_LOCK_ASSERT(sc);
 
        /*
@@ -2629,7 +2592,7 @@ ath_stop_locked(struct ifnet *ifp)
         */
        ath_power_set_power_state(sc, HAL_PM_AWAKE);
 
-       if (ifp->if_flags & IFF_RUNNING) {
+       if (sc->sc_running) {
                /*
                 * Shutdown the hardware and driver:
                 *    reset 802.11 state machine
@@ -2649,12 +2612,12 @@ ath_stop_locked(struct ifnet *ifp)
                if (sc->sc_tx99 != NULL)
                        sc->sc_tx99->stop(sc->sc_tx99);
 #endif
-               callout_stop_sync(&sc->sc_wd_ch);
+               callout_stop(&sc->sc_wd_ch);
                sc->sc_wd_timer = 0;
-               ifp->if_flags &= ~IFF_RUNNING;
+               sc->sc_running = 0;
                if (!sc->sc_invalid) {
                        if (sc->sc_softled) {
-                               callout_stop_sync(&sc->sc_ledtimer);
+                               callout_stop(&sc->sc_ledtimer);
                                ath_hal_gpioset(ah, sc->sc_ledpin,
                                        !sc->sc_ledon);
                                sc->sc_blinking = 0;
@@ -2702,15 +2665,8 @@ ath_txrx_stop_locked(struct ath_softc *sc)
            sc->sc_txstart_cnt || sc->sc_intr_cnt) {
                if (i <= 0)
                        break;
-               if (wlan_is_serialized()) {
-                       wlan_serialize_exit();
-                       lksleep(sc, &sc->sc_pcu_mtx, 0, "ath_txrx_stop",
-                               msecs_to_ticks(10));
-                       wlan_serialize_enter();
-               } else {
-                       lksleep(sc, &sc->sc_pcu_mtx, 0, "ath_txrx_stop",
-                               msecs_to_ticks(10));
-               }
+               msleep(sc, &sc->sc_pcu_mtx, 0, "ath_txrx_stop",
+                   msecs_to_ticks(10));
                i--;
        }
 
@@ -2742,7 +2698,7 @@ ath_txrx_start(struct ath_softc *sc)
 }
 
 /*
- * Grab the reset lock, and wait around until noone else
+ * Grab the reset lock, and wait around until no one else
  * is trying to do anything with it.
  *
  * This is totally horrible but we can't hold this lock for
@@ -2775,17 +2731,11 @@ ath_reset_grablock(struct ath_softc *sc, int dowait)
                        break;
                }
                ATH_PCU_UNLOCK(sc);
-
                /*
                 * 1 tick is likely not enough time for long calibrations
                 * to complete.  So we should wait quite a while.
                 */
-#if defined(__DragonFly__)
-               tsleep(&sc->sc_inreset_cnt, 0,
-                      "ath_reset_grablock", (hz + 99) / 100);
-#else
                pause("ath_reset_grablock", msecs_to_ticks(100));
-#endif
                i--;
                ATH_PCU_LOCK(sc);
        } while (i > 0);
@@ -2811,20 +2761,6 @@ ath_reset_grablock(struct ath_softc *sc, int dowait)
 }
 #undef MAX_RESET_ITERATIONS
 
-/*
- * XXX TODO: write ath_reset_releaselock
- */
-
-static void
-ath_stop(struct ifnet *ifp)
-{
-       struct ath_softc *sc = ifp->if_softc;
-
-       ATH_LOCK(sc);
-       ath_stop_locked(ifp);
-       ATH_UNLOCK(sc);
-}
-
 /*
  * Reset the hardware w/o losing operational state.  This is
  * basically a more efficient way of doing ath_stop, ath_init,
@@ -2833,10 +2769,9 @@ ath_stop(struct ifnet *ifp)
  * to reset or reload hardware state.
  */
 int
-ath_reset(struct ifnet *ifp, ATH_RESET_TYPE reset_type)
+ath_reset(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
 {
-       struct ieee80211com *ic = ifp->if_l2com;
-       struct ath_softc *sc = ic->ic_softc;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        HAL_STATUS status;
        int i;
@@ -2847,7 +2782,7 @@ ath_reset(struct ifnet *ifp, ATH_RESET_TYPE reset_type)
        ATH_PCU_UNLOCK_ASSERT(sc);
        ATH_UNLOCK_ASSERT(sc);
 
-       /* Try to (stop any further TX/RX from occuring */
+       /* Try to (stop any further TX/RX from occurring */
        taskqueue_block(sc->sc_tq);
 
        /*
@@ -2891,7 +2826,7 @@ ath_reset(struct ifnet *ifp, ATH_RESET_TYPE reset_type)
 
        /*
         * Should now wait for pending TX/RX to complete
-        * and block future ones from occuring. This needs to be
+        * and block future ones from occurring. This needs to be
         * done before the TX queue is drained.
         */
        ath_draintxq(sc, reset_type);   /* stop xmit side */
@@ -2901,9 +2836,11 @@ ath_reset(struct ifnet *ifp, ATH_RESET_TYPE reset_type)
        ath_update_chainmasks(sc, ic->ic_curchan);
        ath_hal_setchainmasks(sc->sc_ah, sc->sc_cur_txchainmask,
            sc->sc_cur_rxchainmask);
-       if (!ath_hal_reset(ah, sc->sc_opmode, ic->ic_curchan, AH_TRUE, &status))
-               if_printf(ifp, "%s: unable to reset hardware; hal status %u\n",
-                       __func__, status);
+       if (!ath_hal_reset(ah, sc->sc_opmode, ic->ic_curchan, AH_TRUE,
+           HAL_RESET_NORMAL, &status))
+               device_printf(sc->sc_dev,
+                   "%s: unable to reset hardware; hal status %u\n",
+                   __func__, status);
        sc->sc_diversity = ath_hal_getdiversity(ah);
 
        ATH_RX_LOCK(sc);
@@ -2932,7 +2869,8 @@ ath_reset(struct ifnet *ifp, ATH_RESET_TYPE reset_type)
                ath_hal_setenforcetxop(sc->sc_ah, 0);
 
        if (ath_startrecv(sc) != 0)     /* restart recv */
-               if_printf(ifp, "%s: unable to start recv logic\n", __func__);
+               device_printf(sc->sc_dev,
+                   "%s: unable to start recv logic\n", __func__);
        /*
         * We may be doing a reset in response to an ioctl
         * that changes the channel so update any state that
@@ -2996,19 +2934,6 @@ ath_reset(struct ifnet *ifp, ATH_RESET_TYPE reset_type)
                }
        }
 
-       /*
-        * This may have been set during an ath_start() call which
-        * set this once it detected a concurrent TX was going on.
-        * So, clear it.
-        */
-       IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-       ifq_clr_oactive(&ifp->if_snd);
-#else
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-#endif
-       IF_UNLOCK(&ifp->if_snd);
-
        ATH_LOCK(sc);
        ath_power_restore_power_state(sc);
        ATH_UNLOCK(sc);
@@ -3030,7 +2955,6 @@ static int
 ath_reset_vap(struct ieee80211vap *vap, u_long cmd)
 {
        struct ieee80211com *ic = vap->iv_ic;
-       struct ifnet *ifp = ic->ic_ifp;
        struct ath_softc *sc = ic->ic_softc;
        struct ath_hal *ah = sc->sc_ah;
 
@@ -3046,7 +2970,7 @@ ath_reset_vap(struct ieee80211vap *vap, u_long cmd)
                return 0;
        }
        /* XXX? Full or NOLOSS? */
-       return ath_reset(ifp, ATH_RESET_FULL);
+       return ath_reset(sc, ATH_RESET_FULL);
 }
 
 struct ath_buf *
@@ -3206,32 +3130,12 @@ ath_getbuf(struct ath_softc *sc, ath_buf_type_t btype)
                bf = _ath_getbuf_locked(sc, ATH_BUFTYPE_NORMAL);
        ATH_TXBUF_UNLOCK(sc);
        if (bf == NULL) {
-               struct ifnet *ifp = sc->sc_ifp;
-
                DPRINTF(sc, ATH_DEBUG_XMIT, "%s: stop queue\n", __func__);
                sc->sc_stats.ast_tx_qstop++;
-               IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-               ifq_set_oactive(&ifp->if_snd);
-#else
-               ifp->if_drv_flags |= IFF_DRV_OACTIVE;
-#endif
-               IF_UNLOCK(&ifp->if_snd);
        }
        return bf;
 }
 
-#if !defined(__DragonFly__)
-
-static void
-ath_qflush(struct ifnet *ifp)
-{
-
-       /* XXX TODO */
-}
-
-#endif
-
 /*
  * Transmit a single frame.
  *
@@ -3239,9 +3143,8 @@ ath_qflush(struct ifnet *ifp)
  * fails, so don't free the node reference here.
  */
 static int
-ath_transmit(struct ifnet *ifp, struct mbuf *m)
+ath_transmit(struct ieee80211com *ic, struct mbuf *m)
 {
-       struct ieee80211com *ic = ifp->if_l2com;
        struct ath_softc *sc = ic->ic_softc;
        struct ieee80211_node *ni;
        struct mbuf *next;
@@ -3257,20 +3160,8 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
                DPRINTF(sc, ATH_DEBUG_XMIT,
                    "%s: sc_inreset_cnt > 0; bailing\n", __func__);
                ATH_PCU_UNLOCK(sc);
-               IF_LOCK(&ifp->if_snd);
                sc->sc_stats.ast_tx_qstop++;
-#if defined(__DragonFly__)
-               /* removed, DragonFly uses OACTIVE to control if_start calls */
-               /*ifq_set_oactive(&ifp->if_snd);*/
-#else
-               ifp->if_drv_flags |= IFF_DRV_OACTIVE;
-#endif
-               IF_UNLOCK(&ifp->if_snd);
                ATH_KTR(sc, ATH_KTR_TX, 0, "ath_start_task: OACTIVE, finish");
-#if defined(__DragonFly__)
-               m_freem(m);
-               m = NULL;
-#endif
                return (ENOBUFS);       /* XXX should be EINVAL or? */
        }
        sc->sc_txstart_cnt++;
@@ -3309,8 +3200,6 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
        if ((!(m->m_flags & M_EAPOL)) &&
            (ATH_NODE(ni)->an_swq_depth > sc->sc_txq_node_maxdepth)) {
                sc->sc_stats.ast_tx_nodeq_overflow++;
-               m_freem(m);
-               m = NULL;
                retval = ENOBUFS;
                goto finish;
        }
@@ -3334,8 +3223,6 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
        if ((!(m->m_flags & M_EAPOL)) &&
            (sc->sc_txbuf_cnt <= sc->sc_txq_data_minfree)) {
                sc->sc_stats.ast_tx_nobuf++;
-               m_freem(m);
-               m = NULL;
                retval = ENOBUFS;
                goto finish;
        }
@@ -3363,16 +3250,6 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
                 * above.
                 */
                sc->sc_stats.ast_tx_nobuf++;
-               IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-               /* removed, DragonFly uses OACTIVE to control if_start calls */
-               /*ifq_set_oactive(&ifp->if_snd);*/
-#else
-               ifp->if_drv_flags |= IFF_DRV_OACTIVE;
-#endif
-               IF_UNLOCK(&ifp->if_snd);
-               m_freem(m);
-               m = NULL;
                retval = ENOBUFS;
                goto finish;
        }
@@ -3394,12 +3271,13 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
                DPRINTF(sc, ATH_DEBUG_XMIT,
                    "%s: out of txfrag buffers\n", __func__);
                sc->sc_stats.ast_tx_nofrag++;
-#if defined(__DragonFly__)
-               ++ifp->if_oerrors;
-#else
-               if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
-#endif
-               ath_freetx(m);
+               if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1);
+               /*
+                * XXXGL: is mbuf valid after ath_txfrag_setup? If yes,
+                * we shouldn't free it but return back.
+                */
+               ieee80211_free_mbuf(m);
+               m = NULL;
                goto bad;
        }
 
@@ -3441,16 +3319,6 @@ ath_transmit(struct ifnet *ifp, struct mbuf *m)
                }
        }
 
-       /*
-        * Bump the ifp output counter.
-        *
-        * XXX should use atomics?
-        */
-#if defined(__DragonFly__)
-       ++ifp->if_opackets;
-#else
-       if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
-#endif
 nextfrag:
        /*
         * Pass the frame to the h/w for transmission.
@@ -3466,15 +3334,14 @@ nextfrag:
         *
         * Note: if this fails, then the mbufs are freed but
         * not the node reference.
+        *
+        * So, we now have to free the node reference ourselves here
+        * and return OK up to the stack.
         */
        next = m->m_nextpkt;
        if (ath_tx_start(sc, ni, bf, m)) {
 bad:
-#if defined(__DragonFly__)
-               ++ifp->if_oerrors;
-#else
-               if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
-#endif
+               if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1);
 reclaim:
                bf->bf_m = NULL;
                bf->bf_node = NULL;
@@ -3486,7 +3353,14 @@ reclaim:
                 */
                ath_txfrag_cleanup(sc, &frags, ni);
                ATH_TXBUF_UNLOCK(sc);
-               retval = ENOBUFS;
+
+               /*
+                * XXX: And free the node/return OK; ath_tx_start() may have
+                *      modified the buffer.  We currently have no way to
+                *      signify that the mbuf was freed but there was an error.
+                */
+               ieee80211_free_node(ni);
+               retval = 0;
                goto finish;
        }
 
@@ -3506,7 +3380,7 @@ reclaim:
                            __func__,
                            ieee80211_state_name[ni->ni_vap->iv_state]);
                        /* XXX dmamap */
-                       ath_freetx(next);
+                       ieee80211_free_mbuf(next);
                        goto reclaim;
                }
                m = next;
@@ -3598,40 +3472,41 @@ ath_update_promisc(struct ieee80211com *ic)
 static void
 ath_update_mcast_hw(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
+       struct ieee80211com *ic = &sc->sc_ic;
        u_int32_t mfilt[2];
 
        /* calculate and install multicast filter */
-       if ((ifp->if_flags & IFF_ALLMULTI) == 0) {
+       if (ic->ic_allmulti == 0) {
+               struct ieee80211vap *vap;
+               struct ifnet *ifp;
                struct ifmultiaddr *ifma;
+
                /*
                 * Merge multicast addresses to form the hardware filter.
                 */
                mfilt[0] = mfilt[1] = 0;
-#if defined(__DragonFly__)
-               /* nothing */
-#else
-               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;
-                       u_int8_t pos;
-
-                       /* calculate XOR of eight 6bit values */
-                       dl = LLADDR((struct sockaddr_dl *) ifma->ifma_addr);
-                       val = LE_READ_4(dl + 0);
-                       pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
-                       val = LE_READ_4(dl + 3);
-                       pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
-                       pos &= 0x3f;
-                       mfilt[pos / 32] |= (1 << (pos % 32));
+               TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
+                       ifp = vap->iv_ifp;
+                       if_maddr_rlock(ifp);
+                       TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
+                               caddr_t dl;
+                               uint32_t val;
+                               uint8_t pos;
+
+                               /* calculate XOR of eight 6bit values */
+                               dl = LLADDR((struct sockaddr_dl *)
+                                   ifma->ifma_addr);
+                               val = le32dec(dl + 0);
+                               pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^
+                                   val;
+                               val = le32dec(dl + 3);
+                               pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^
+                                   val;
+                               pos &= 0x3f;
+                               mfilt[pos / 32] |= (1 << (pos % 32));
+                       }
+                       if_maddr_runlock(ifp);
                }
-#if defined(__DragonFly__)
-               /* nothing */
-#else
-               if_maddr_runlock(ifp);
-#endif
        } else
                mfilt[0] = mfilt[1] = ~0;
 
@@ -3664,7 +3539,7 @@ ath_update_mcast(struct ieee80211com *ic)
 void
 ath_mode_init(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        u_int32_t rfilt;
 
@@ -3675,17 +3550,8 @@ ath_mode_init(struct ath_softc *sc)
        /* configure operational mode */
        ath_hal_setopmode(ah);
 
-#if !defined(__DragonFly__)
-       DPRINTF(sc, ATH_DEBUG_STATE | ATH_DEBUG_MODE,
-           "%s: ah=%p, ifp=%p, if_addr=%p\n",
-           __func__,
-           ah,
-           ifp,
-           (ifp == NULL) ? NULL : ifp->if_addr);
-#endif
-
        /* handle any link-level address change */
-       ath_hal_setmac(ah, IF_LLADDR(ifp));
+       ath_hal_setmac(ah, ic->ic_macaddr);
 
        /* calculate and install multicast filter */
        ath_update_mcast_hw(sc);
@@ -3697,7 +3563,7 @@ ath_mode_init(struct ath_softc *sc)
 void
 ath_setslottime(struct ath_softc *sc)
 {
-       struct ieee80211com *ic = sc->sc_ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        u_int usec;
 
@@ -3781,14 +3647,11 @@ static void
 ath_reset_proc(void *arg, int pending)
 {
        struct ath_softc *sc = arg;
-       struct ifnet *ifp = sc->sc_ifp;
 
 #if 0
-       if_printf(ifp, "%s: resetting\n", __func__);
+       device_printf(sc->sc_dev, "%s: resetting\n", __func__);
 #endif
-       wlan_serialize_enter();
-       ath_reset(ifp, ATH_RESET_NOLOSS);
-       wlan_serialize_exit();
+       ath_reset(sc, ATH_RESET_NOLOSS);
 }
 
 /*
@@ -3798,339 +3661,24 @@ static void
 ath_bstuck_proc(void *arg, int pending)
 {
        struct ath_softc *sc = arg;
-       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);
+               device_printf(sc->sc_dev, "bb hang detected (0x%x)\n", hangs);
 
 #ifdef ATH_DEBUG_ALQ
        if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_STUCK_BEACON))
                if_ath_alq_post(&sc->sc_alq, ATH_ALQ_STUCK_BEACON, 0, NULL);
 #endif
 
-       if_printf(ifp, "stuck beacon; resetting (bmiss count %u)\n",
-               sc->sc_bmisscount);
+       device_printf(sc->sc_dev, "stuck beacon; resetting (bmiss count %u)\n",
+           sc->sc_bmisscount);
        sc->sc_stats.ast_bstuck++;
        /*
         * This assumes that there's no simultaneous channel mode change
-        * occuring.
-        */
-       ath_reset(ifp, ATH_RESET_NOLOSS);
-       wlan_serialize_exit();
-}
-
-static void
-ath_load_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
-{
-       bus_addr_t *paddr = (bus_addr_t*) arg;
-       KASSERT(error == 0, ("error %u on bus_dma callback", error));
-       *paddr = segs->ds_addr;
-}
-
-/*
- * Allocate the descriptors and appropriate DMA tag/setup.
- *
- * For some situations (eg EDMA TX completion), there isn't a requirement
- * for the ath_buf entries to be allocated.
- */
-int
-ath_descdma_alloc_desc(struct ath_softc *sc,
-       struct ath_descdma *dd, ath_bufhead *head,
-       const char *name, int ds_size, int ndesc)
-{
-#define        DS2PHYS(_dd, _ds) \
-       ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
-#define        ATH_DESC_4KB_BOUND_CHECK(_daddr, _len) \
-       ((((u_int32_t)(_daddr) & 0xFFF) > (0x1000 - (_len))) ? 1 : 0)
-       struct ifnet *ifp = sc->sc_ifp;
-       int error;
-
-       dd->dd_descsize = ds_size;
-
-       DPRINTF(sc, ATH_DEBUG_RESET,
-           "%s: %s DMA: %u desc, %d bytes per descriptor\n",
-           __func__, name, ndesc, dd->dd_descsize);
-
-       dd->dd_name = name;
-       dd->dd_desc_len = dd->dd_descsize * ndesc;
-
-       /*
-        * Merlin work-around:
-        * Descriptors that cross the 4KB boundary can't be used.
-        * Assume one skipped descriptor per 4KB page.
-        */
-       if (! ath_hal_split4ktrans(sc->sc_ah)) {
-               int numpages = dd->dd_desc_len / 4096;
-               dd->dd_desc_len += ds_size * numpages;
-       }
-
-       /*
-        * Setup DMA descriptor area.
-        *
-        * BUS_DMA_ALLOCNOW is not used; we never use bounce
-        * buffers for the descriptors themselves.
-        */
-       error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), /* parent */
-                      PAGE_SIZE, 0,            /* alignment, bounds */
-                      BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
-                      BUS_SPACE_MAXADDR,       /* highaddr */
-                      NULL, NULL,              /* filter, filterarg */
-                      dd->dd_desc_len,         /* maxsize */
-                      1,                       /* nsegments */
-                      dd->dd_desc_len,         /* maxsegsize */
-                      0,                       /* flags */
-#if !defined(__DragonFly__)
-                      NULL,                    /* lockfunc */
-                      NULL,                    /* lockarg */
-#endif
-                      &dd->dd_dmat);
-       if (error != 0) {
-               if_printf(ifp, "cannot allocate %s DMA tag\n", dd->dd_name);
-               return error;
-       }
-
-       /* allocate descriptors */
-       error = bus_dmamem_alloc(dd->dd_dmat, (void**) &dd->dd_desc,
-                                BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
-                                &dd->dd_dmamap);
-       if (error != 0) {
-               if_printf(ifp, "unable to alloc memory for %u %s descriptors, "
-                       "error %u\n", ndesc, dd->dd_name, error);
-               goto fail1;
-       }
-
-       error = bus_dmamap_load(dd->dd_dmat, dd->dd_dmamap,
-                               dd->dd_desc, dd->dd_desc_len,
-                               ath_load_cb, &dd->dd_desc_paddr,
-                               BUS_DMA_NOWAIT);
-       if (error != 0) {
-               if_printf(ifp, "unable to map %s descriptors, error %u\n",
-                       dd->dd_name, error);
-               goto fail2;
-       }
-
-       DPRINTF(sc, ATH_DEBUG_RESET, "%s: %s DMA map: %p (%lu) -> %p (%lu)\n",
-           __func__, dd->dd_name, (uint8_t *) dd->dd_desc,
-           (u_long) dd->dd_desc_len, (caddr_t) dd->dd_desc_paddr,
-           /*XXX*/ (u_long) dd->dd_desc_len);
-
-       return (0);
-
-fail2:
-       bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
-fail1:
-       bus_dma_tag_destroy(dd->dd_dmat);
-       memset(dd, 0, sizeof(*dd));
-       return error;
-#undef DS2PHYS
-#undef ATH_DESC_4KB_BOUND_CHECK
-}
-
-int
-ath_descdma_setup(struct ath_softc *sc,
-       struct ath_descdma *dd, ath_bufhead *head,
-       const char *name, int ds_size, int nbuf, int ndesc)
-{
-#define        DS2PHYS(_dd, _ds) \
-       ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
-#define        ATH_DESC_4KB_BOUND_CHECK(_daddr, _len) \
-       ((((u_int32_t)(_daddr) & 0xFFF) > (0x1000 - (_len))) ? 1 : 0)
-       struct ifnet *ifp = sc->sc_ifp;
-       uint8_t *ds;
-       struct ath_buf *bf;
-       int i, bsize, error;
-
-       /* Allocate descriptors */
-       error = ath_descdma_alloc_desc(sc, dd, head, name, ds_size,
-           nbuf * ndesc);
-
-       /* Assume any errors during allocation were dealt with */
-       if (error != 0) {
-               return (error);
-       }
-
-       ds = (uint8_t *) dd->dd_desc;
-
-       /* allocate rx buffers */
-       bsize = sizeof(struct ath_buf) * nbuf;
-       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);
-               goto fail3;
-       }
-       dd->dd_bufptr = bf;
-
-       TAILQ_INIT(head);
-       for (i = 0; i < nbuf; i++, bf++, ds += (ndesc * dd->dd_descsize)) {
-               bf->bf_desc = (struct ath_desc *) ds;
-               bf->bf_daddr = DS2PHYS(dd, ds);
-               if (! ath_hal_split4ktrans(sc->sc_ah)) {
-                       /*
-                        * Merlin WAR: Skip descriptor addresses which
-                        * cause 4KB boundary crossing along any point
-                        * in the descriptor.
-                        */
-                        if (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr,
-                            dd->dd_descsize)) {
-                               /* Start at the next page */
-                               ds += 0x1000 - (bf->bf_daddr & 0xFFF);
-                               bf->bf_desc = (struct ath_desc *) ds;
-                               bf->bf_daddr = DS2PHYS(dd, ds);
-                       }
-               }
-               error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT,
-                               &bf->bf_dmamap);
-               if (error != 0) {
-                       if_printf(ifp, "unable to create dmamap for %s "
-                               "buffer %u, error %u\n", dd->dd_name, i, error);
-                       ath_descdma_cleanup(sc, dd, head);
-                       return error;
-               }
-               bf->bf_lastds = bf->bf_desc;    /* Just an initial value */
-               TAILQ_INSERT_TAIL(head, bf, bf_list);
-       }
-
-       /*
-        * XXX TODO: ensure that ds doesn't overflow the descriptor
-        * allocation otherwise weird stuff will occur and crash your
-        * machine.
-        */
-       return 0;
-       /* XXX this should likely just call ath_descdma_cleanup() */
-fail3:
-       bus_dmamap_unload(dd->dd_dmat, dd->dd_dmamap);
-       bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
-       bus_dma_tag_destroy(dd->dd_dmat);
-       memset(dd, 0, sizeof(*dd));
-       return error;
-#undef DS2PHYS
-#undef ATH_DESC_4KB_BOUND_CHECK
-}
-
-/*
- * Allocate ath_buf entries but no descriptor contents.
- *
- * This is for RX EDMA where the descriptors are the header part of
- * the RX buffer.
- */
-int
-ath_descdma_setup_rx_edma(struct ath_softc *sc,
-       struct ath_descdma *dd, ath_bufhead *head,
-       const char *name, int nbuf, int rx_status_len)
-{
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ath_buf *bf;
-       int i, bsize, error;
-
-       DPRINTF(sc, ATH_DEBUG_RESET, "%s: %s DMA: %u buffers\n",
-           __func__, name, nbuf);
-
-       dd->dd_name = name;
-       /*
-        * This is (mostly) purely for show.  We're not allocating any actual
-        * descriptors here as EDMA RX has the descriptor be part
-        * of the RX buffer.
-        *
-        * However, dd_desc_len is used by ath_descdma_free() to determine
-        * whether we have already freed this DMA mapping.
+        * occurring.
         */
-       dd->dd_desc_len = rx_status_len * nbuf;
-       dd->dd_descsize = rx_status_len;
-
-       /* allocate rx buffers */
-       bsize = sizeof(struct ath_buf) * nbuf;
-       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);
-               error = ENOMEM;
-               goto fail3;
-       }
-       dd->dd_bufptr = bf;
-
-       TAILQ_INIT(head);
-       for (i = 0; i < nbuf; i++, bf++) {
-               bf->bf_desc = NULL;
-               bf->bf_daddr = 0;
-               bf->bf_lastds = NULL;   /* Just an initial value */
-
-               error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT,
-                               &bf->bf_dmamap);
-               if (error != 0) {
-                       if_printf(ifp, "unable to create dmamap for %s "
-                               "buffer %u, error %u\n", dd->dd_name, i, error);
-                       ath_descdma_cleanup(sc, dd, head);
-                       return error;
-               }
-               TAILQ_INSERT_TAIL(head, bf, bf_list);
-       }
-       return 0;
-fail3:
-       memset(dd, 0, sizeof(*dd));
-       return error;
-}
-
-void
-ath_descdma_cleanup(struct ath_softc *sc,
-       struct ath_descdma *dd, ath_bufhead *head)
-{
-       struct ath_buf *bf;
-       struct ieee80211_node *ni;
-       int do_warning = 0;
-
-       if (dd->dd_dmamap != 0) {
-               bus_dmamap_unload(dd->dd_dmat, dd->dd_dmamap);
-               bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
-               bus_dma_tag_destroy(dd->dd_dmat);
-       }
-
-       if (head != NULL) {
-               TAILQ_FOREACH(bf, head, bf_list) {
-                       if (bf->bf_m) {
-                               /*
-                                * XXX warn if there's buffers here.
-                                * XXX it should have been freed by the
-                                * owner!
-                                */
-                               
-                               if (do_warning == 0) {
-                                       do_warning = 1;
-                                       device_printf(sc->sc_dev,
-                                           "%s: %s: mbuf should've been"
-                                           " unmapped/freed!\n",
-                                           __func__,
-                                           dd->dd_name);
-                               }
-                               bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
-                                   BUS_DMASYNC_POSTREAD);
-                               bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
-                               m_freem(bf->bf_m);
-                               bf->bf_m = NULL;
-                       }
-                       if (bf->bf_dmamap != NULL) {
-                               bus_dmamap_destroy(sc->sc_dmat, bf->bf_dmamap);
-                               bf->bf_dmamap = NULL;
-                       }
-                       ni = bf->bf_node;
-                       bf->bf_node = NULL;
-                       if (ni != NULL) {
-                               /*
-                                * Reclaim node reference.
-                                */
-                               ieee80211_free_node(ni);
-                       }
-               }
-       }
-
-       if (head != NULL)
-               TAILQ_INIT(head);
-
-       if (dd->dd_bufptr != NULL)
-               kfree(dd->dd_bufptr, M_ATHDEV);
-       memset(dd, 0, sizeof(*dd));
+       ath_reset(sc, ATH_RESET_NOLOSS);
 }
 
 static int
@@ -4190,7 +3738,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;
 
-       an = kmalloc(space, M_80211_NODE, M_INTWAIT | M_ZERO);
+       an = malloc(space, M_80211_NODE, M_NOWAIT|M_ZERO);
        if (an == NULL) {
                /* XXX stat+msg */
                return NULL;
@@ -4198,15 +3746,14 @@ 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 */
-       ksnprintf(an->an_name, sizeof(an->an_name), "%s: node %p",
+       snprintf(an->an_name, sizeof(an->an_name), "%s: node %p",
            device_get_nameunit(sc->sc_dev), an);
-       lockinit(&an->an_mtx, an->an_name, 0, 0);
+       mtx_init(&an->an_mtx, an->an_name, NULL, MTX_DEF);
 
        /* XXX setup ath_tid */
        ath_tx_tid_init(sc, an);
 
-       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %s: an %p\n", __func__,
-           ath_hal_ether_sprintf(mac), an);
+       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %6D: an %p\n", __func__, mac, ":", an);
        return &an->an_node;
 }
 
@@ -4216,8 +3763,8 @@ ath_node_cleanup(struct ieee80211_node *ni)
        struct ieee80211com *ic = ni->ni_ic;
        struct ath_softc *sc = ic->ic_softc;
 
-       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %s: an %p\n", __func__,
-           ath_hal_ether_sprintf(ni->ni_macaddr), ATH_NODE(ni));
+       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %6D: an %p\n", __func__,
+           ni->ni_macaddr, ":", ATH_NODE(ni));
 
        /* Cleanup ath_tid, free unused bufs, unlink bufs in TXQ */
        ath_tx_node_flush(sc, ATH_NODE(ni));
@@ -4231,9 +3778,9 @@ ath_node_free(struct ieee80211_node *ni)
        struct ieee80211com *ic = ni->ni_ic;
        struct ath_softc *sc = ic->ic_softc;
 
-       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %s: an %p\n", __func__,
-           ath_hal_ether_sprintf(ni->ni_macaddr), ATH_NODE(ni));
-       lockuninit(&ATH_NODE(ni)->an_mtx);
+       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %6D: an %p\n", __func__,
+           ni->ni_macaddr, ":", ATH_NODE(ni));
+       mtx_destroy(&ATH_NODE(ni)->an_mtx);
        sc->sc_node_free(ni);
 }
 
@@ -4289,7 +3836,6 @@ ath_txq_init(struct ath_softc *sc, struct ath_txq *txq, int qnum)
 static struct ath_txq *
 ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
 {
-#define        N(a)    (sizeof(a)/sizeof(a[0]))
        struct ath_hal *ah = sc->sc_ah;
        HAL_TXQ_INFO qi;
        int qnum;
@@ -4326,10 +3872,10 @@ ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
                 */
                return NULL;
        }
-       if (qnum >= N(sc->sc_txq)) {
+       if (qnum >= nitems(sc->sc_txq)) {
                device_printf(sc->sc_dev,
                        "hal qnum %u out of range, max %zu!\n",
-                       qnum, N(sc->sc_txq));
+                       qnum, nitems(sc->sc_txq));
                ath_hal_releasetxqueue(ah, qnum);
                return NULL;
        }
@@ -4338,7 +3884,6 @@ ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
                sc->sc_txqsetup |= 1<<qnum;
        }
        return &sc->sc_txq[qnum];
-#undef N
 }
 
 /*
@@ -4353,12 +3898,11 @@ ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
 static int
 ath_tx_setup(struct ath_softc *sc, int ac, int haltype)
 {
-#define        N(a)    (sizeof(a)/sizeof(a[0]))
        struct ath_txq *txq;
 
-       if (ac >= N(sc->sc_ac2q)) {
+       if (ac >= nitems(sc->sc_ac2q)) {
                device_printf(sc->sc_dev, "AC %u out of range, max %zu!\n",
-                       ac, N(sc->sc_ac2q));
+                       ac, nitems(sc->sc_ac2q));
                return 0;
        }
        txq = ath_txq_setup(sc, HAL_TX_QUEUE_DATA, haltype);
@@ -4368,7 +3912,6 @@ ath_tx_setup(struct ath_softc *sc, int ac, int haltype)
                return 1;
        } else
                return 0;
-#undef N
 }
 
 /*
@@ -4378,9 +3921,7 @@ static int
 ath_txq_update(struct ath_softc *sc, int ac)
 {
 #define        ATH_EXPONENT_TO_VALUE(v)        ((1<<v)-1)
-#define        ATH_TXOP_TO_US(v)               (v<<5)
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_txq *txq = sc->sc_ac2q[ac];
        struct wmeParams *wmep = &ic->ic_wme.wme_chanParams.cap_wmeParams[ac];
        struct ath_hal *ah = sc->sc_ah;
@@ -4425,7 +3966,7 @@ ath_txq_update(struct ath_softc *sc, int ac)
                qi.tqi_cwmin = ATH_EXPONENT_TO_VALUE(wmep->wmep_logcwmin);
                qi.tqi_cwmax = ATH_EXPONENT_TO_VALUE(wmep->wmep_logcwmax);
                qi.tqi_readyTime = 0;
-               qi.tqi_burstTime = ATH_TXOP_TO_US(wmep->wmep_txopLimit);
+               qi.tqi_burstTime = IEEE80211_TXOP_TO_US(wmep->wmep_txopLimit);
 #ifdef IEEE80211_SUPPORT_TDMA
        }
 #endif
@@ -4436,15 +3977,13 @@ ath_txq_update(struct ath_softc *sc, int ac)
            qi.tqi_aifs, qi.tqi_cwmin, qi.tqi_cwmax, qi.tqi_burstTime);
 
        if (!ath_hal_settxqueueprops(ah, txq->axq_qnum, &qi)) {
-               if_printf(ifp, "unable to update hardware queue "
-                       "parameters for %s traffic!\n",
-                       ieee80211_wme_acnames[ac]);
+               device_printf(sc->sc_dev, "unable to update hardware queue "
+                   "parameters for %s traffic!\n", ieee80211_wme_acnames[ac]);
                return 0;
        } else {
                ath_hal_resettxqueue(ah, txq->axq_qnum); /* push to h/w */
                return 1;
        }
-#undef ATH_TXOP_TO_US
 #undef ATH_EXPONENT_TO_VALUE
 }
 
@@ -4505,8 +4044,7 @@ ath_tx_update_stats(struct ath_softc *sc, struct ath_tx_status *ts,
     struct ath_buf *bf)
 {
        struct ieee80211_node *ni = bf->bf_node;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        int sr, lr, pri;
 
        if (ts->ts_status == 0) {
@@ -4707,7 +4245,7 @@ ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq, int dosched)
        struct ath_tx_status *ts;
        struct ieee80211_node *ni;
 #ifdef IEEE80211_SUPPORT_SUPERG
-       struct ieee80211com *ic = sc->sc_ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
 #endif /* IEEE80211_SUPPORT_SUPERG */
        int nacked;
        HAL_STATUS status;
@@ -4861,7 +4399,6 @@ static void
 ath_tx_proc_q0(void *arg, int npending)
 {
        struct ath_softc *sc = arg;
-       struct ifnet *ifp = sc->sc_ifp;
        uint32_t txqs;
 
        ATH_PCU_LOCK(sc);
@@ -4882,13 +4419,6 @@ ath_tx_proc_q0(void *arg, int npending)
                sc->sc_lastrx = ath_hal_gettsf64(sc->sc_ah);
        if (TXQACTIVE(txqs, sc->sc_cabq->axq_qnum))
                ath_tx_processq(sc, sc->sc_cabq, 1);
-       IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-       ifq_clr_oactive(&ifp->if_snd);
-#else
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-#endif
-       IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
        if (sc->sc_softled)
@@ -4913,7 +4443,6 @@ static void
 ath_tx_proc_q0123(void *arg, int npending)
 {
        struct ath_softc *sc = arg;
-       struct ifnet *ifp = sc->sc_ifp;
        int nacked;
        uint32_t txqs;
 
@@ -4947,13 +4476,6 @@ ath_tx_proc_q0123(void *arg, int npending)
        if (nacked)
                sc->sc_lastrx = ath_hal_gettsf64(sc->sc_ah);
 
-       IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-       ifq_clr_oactive(&ifp->if_snd);
-#else
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-#endif
-       IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
        if (sc->sc_softled)
@@ -4977,7 +4499,6 @@ static void
 ath_tx_proc(void *arg, int npending)
 {
        struct ath_softc *sc = arg;
-       struct ifnet *ifp = sc->sc_ifp;
        int i, nacked;
        uint32_t txqs;
 
@@ -5003,14 +4524,6 @@ ath_tx_proc(void *arg, int npending)
        if (nacked)
                sc->sc_lastrx = ath_hal_gettsf64(sc->sc_ah);
 
-       /* XXX check this inside of IF_LOCK? */
-       IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-       ifq_clr_oactive(&ifp->if_snd);
-#else
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-#endif
-       IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 
        if (sc->sc_softled)
@@ -5224,7 +4737,7 @@ ath_tx_freebuf(struct ath_softc *sc, struct ath_buf *bf, int status)
        /*
         * Make sure that we only sync/unload if there's an mbuf.
         * If not (eg we cloned a buffer), the unload will have already
-        * occured.
+        * occurred.
         */
        if (bf->bf_m != NULL) {
                bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
@@ -5321,7 +4834,7 @@ ath_tx_draintxq(struct ath_softc *sc, struct ath_txq *txq)
                        txq->axq_aggr_depth--;
 #ifdef ATH_DEBUG
                if (sc->sc_debug & ATH_DEBUG_RESET) {
-                       struct ieee80211com *ic = sc->sc_ifp->if_l2com;
+                       struct ieee80211com *ic = &sc->sc_ic;
                        int status = 0;
 
                        /*
@@ -5466,9 +4979,8 @@ void
 ath_legacy_tx_drain(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
 {
        struct ath_hal *ah = sc->sc_ah;
-       struct ifnet *ifp = sc->sc_ifp;
-       int i;
        struct ath_buf *bf_last;
+       int i;
 
        (void) ath_stoptxdma(sc);
 
@@ -5520,19 +5032,12 @@ ath_legacy_tx_drain(struct ath_softc *sc, ATH_RESET_TYPE reset_type)
                        ath_printtxbuf(sc, bf, sc->sc_bhalq, 0,
                                ath_hal_txprocdesc(ah, bf->bf_lastds,
                                    &bf->bf_status.ds_txstat) == HAL_OK);
-                       ieee80211_dump_pkt(ifp->if_l2com,
+                       ieee80211_dump_pkt(&sc->sc_ic,
                            mtod(bf->bf_m, const uint8_t *), bf->bf_m->m_len,
                            0, -1);
                }
        }
 #endif /* ATH_DEBUG */
-       IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-       ifq_clr_oactive(&ifp->if_snd);
-#else
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-#endif
-       IF_UNLOCK(&ifp->if_snd);
        sc->sc_wd_timer = 0;
 }
 
@@ -5563,8 +5068,7 @@ ath_chan_change(struct ath_softc *sc, struct ieee80211_channel *chan)
 static int
 ath_chan_set(struct ath_softc *sc, struct ieee80211_channel *chan)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        int ret = 0;
 
@@ -5572,7 +5076,7 @@ ath_chan_set(struct ath_softc *sc, struct ieee80211_channel *chan)
        ATH_PCU_UNLOCK_ASSERT(sc);
        ATH_UNLOCK_ASSERT(sc);
 
-       /* (Try to) stop TX/RX from occuring */
+       /* (Try to) stop TX/RX from occurring */
        taskqueue_block(sc->sc_tq);
 
        ATH_PCU_LOCK(sc);
@@ -5619,8 +5123,9 @@ ath_chan_set(struct ath_softc *sc, struct ieee80211_channel *chan)
                ath_update_chainmasks(sc, chan);
                ath_hal_setchainmasks(sc->sc_ah, sc->sc_cur_txchainmask,
                    sc->sc_cur_rxchainmask);
-               if (!ath_hal_reset(ah, sc->sc_opmode, chan, AH_TRUE, &status)) {
-                       if_printf(ifp, "%s: unable to reset "
+               if (!ath_hal_reset(ah, sc->sc_opmode, chan, AH_TRUE,
+                   HAL_RESET_NORMAL, &status)) {
+                       device_printf(sc->sc_dev, "%s: unable to reset "
                            "channel %u (%u MHz, flags 0x%x), hal status %u\n",
                            __func__, ieee80211_chan2ieee(ic, chan),
                            chan->ic_freq, chan->ic_flags, status);
@@ -5659,8 +5164,8 @@ ath_chan_set(struct ath_softc *sc, struct ieee80211_channel *chan)
                 * Re-enable rx framework.
                 */
                if (ath_startrecv(sc) != 0) {
-                       if_printf(ifp, "%s: unable to restart recv logic\n",
-                           __func__);
+                       device_printf(sc->sc_dev,
+                           "%s: unable to restart recv logic\n", __func__);
                        ret = EIO;
                        goto finish;
                }
@@ -5699,13 +5204,6 @@ finish:
        ath_hal_intrset(ah, sc->sc_imask);
        ATH_PCU_UNLOCK(sc);
 
-       IF_LOCK(&ifp->if_snd);
-#if defined(__DragonFly__)
-       ifq_clr_oactive(&ifp->if_snd);
-#else
-       ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-#endif
-       IF_UNLOCK(&ifp->if_snd);
        ath_txrx_start(sc);
        /* XXX ath_start? */
 
@@ -5721,8 +5219,7 @@ ath_calibrate(void *arg)
 {
        struct ath_softc *sc = arg;
        struct ath_hal *ah = sc->sc_ah;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        HAL_BOOL longCal, isCalDone = AH_TRUE;
        HAL_BOOL aniCal, shortCal = AH_FALSE;
        int nextcal;
@@ -5848,12 +5345,12 @@ restart:
 static void
 ath_scan_start(struct ieee80211com *ic)
 {
-       struct ifnet *ifp = ic->ic_ifp;
        struct ath_softc *sc = ic->ic_softc;
        struct ath_hal *ah = sc->sc_ah;
        u_int32_t rfilt;
 
        /* XXX calibration timer? */
+       /* XXXGL: is constant ieee80211broadcastaddr a correct choice? */
 
        ATH_LOCK(sc);
        sc->sc_scanning = 1;
@@ -5863,11 +5360,11 @@ ath_scan_start(struct ieee80211com *ic)
 
        ATH_PCU_LOCK(sc);
        ath_hal_setrxfilter(ah, rfilt);
-       ath_hal_setassocid(ah, ifp->if_broadcastaddr, 0);
+       ath_hal_setassocid(ah, ieee80211broadcastaddr, 0);
        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, ether_sprintf(ieee80211broadcastaddr));
 }
 
 static void
@@ -6020,7 +5517,7 @@ ath_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
         * And stop the calibration callout whilst we have
         * ATH_LOCK held.
         */
-       callout_stop_sync(&sc->sc_cal_ch);
+       callout_stop(&sc->sc_cal_ch);
        ATH_UNLOCK(sc);
 
        if (ostate == IEEE80211_S_CSA && nstate == IEEE80211_S_RUN)
@@ -6340,9 +5837,10 @@ ath_newassoc(struct ieee80211_node *ni, int isnew)
        an->an_mcastrix = ath_tx_findrix(sc, tp->mcastrate);
        an->an_mgmtrix = ath_tx_findrix(sc, tp->mgmtrate);
 
-       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %s: reassoc; isnew=%d, is_powersave=%d\n",
+       DPRINTF(sc, ATH_DEBUG_NODE, "%s: %6D: reassoc; isnew=%d, is_powersave=%d\n",
            __func__,
-           ath_hal_ether_sprintf(ni->ni_macaddr),
+           ni->ni_macaddr,
+           ":",
            isnew,
            an->an_is_powersave);
 
@@ -6359,16 +5857,17 @@ ath_newassoc(struct ieee80211_node *ni, int isnew)
         * If we're reassociating, make sure that any paused queues
         * get unpaused.
         *
-        * Now, we may hvae frames in the hardware queue for this node.
+        * Now, we may have frames in the hardware queue for this node.
         * So if we are reassociating and there are frames in the queue,
         * we need to go through the cleanup path to ensure that they're
         * marked as non-aggregate.
         */
        if (! isnew) {
                DPRINTF(sc, ATH_DEBUG_NODE,
-                   "%s: %s: reassoc; is_powersave=%d\n",
+                   "%s: %6D: reassoc; is_powersave=%d\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr),
+                   ni->ni_macaddr,
+                   ":",
                    an->an_is_powersave);
 
                /* XXX for now, we can't hold the lock across assoc */
@@ -6423,8 +5922,7 @@ ath_getradiocaps(struct ieee80211com *ic,
 static int
 ath_getchannels(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        HAL_STATUS status;
 
@@ -6434,8 +5932,9 @@ ath_getchannels(struct ath_softc *sc)
        status = ath_hal_init_channels(ah, ic->ic_channels, IEEE80211_CHAN_MAX,
            &ic->ic_nchans, HAL_MODE_ALL, CTRY_DEFAULT, SKU_NONE, AH_TRUE);
        if (status != HAL_OK) {
-               if_printf(ifp, "%s: unable to collect channel list from hal, "
-                   "status %d\n", __func__, status);
+               device_printf(sc->sc_dev,
+                   "%s: unable to collect channel list from hal, status %d\n",
+                   __func__, status);
                return EINVAL;
        }
        (void) ath_hal_getregdomain(ah, &sc->sc_eerd);
@@ -6507,7 +6006,6 @@ ath_rate_setup(struct ath_softc *sc, u_int mode)
 static void
 ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode)
 {
-#define        N(a)    (sizeof(a)/sizeof(a[0]))
        /* NB: on/off times from the Atheros NDIS driver, w/ permission */
        static const struct {
                u_int           rate;           /* tx/rx 802.11 rate */
@@ -6544,7 +6042,7 @@ ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode)
                        sc->sc_rixmap[ieeerate | IEEE80211_RATE_MCS] = i;
        }
        memset(sc->sc_hwmap, 0, sizeof(sc->sc_hwmap));
-       for (i = 0; i < N(sc->sc_hwmap); i++) {
+       for (i = 0; i < nitems(sc->sc_hwmap); i++) {
                if (i >= rt->rateCount) {
                        sc->sc_hwmap[i].ledon = (500 * hz) / 1000;
                        sc->sc_hwmap[i].ledoff = (130 * hz) / 1000;
@@ -6559,7 +6057,7 @@ ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode)
                    rt->info[i].phy == IEEE80211_T_OFDM)
                        sc->sc_hwmap[i].txflags |= IEEE80211_RADIOTAP_F_SHORTPRE;
                sc->sc_hwmap[i].rxflags = sc->sc_hwmap[i].txflags;
-               for (j = 0; j < N(blinkrates)-1; j++)
+               for (j = 0; j < nitems(blinkrates)-1; j++)
                        if (blinkrates[j].rate == sc->sc_hwmap[i].ieeerate)
                                break;
                /* NB: this uses the last entry if the rate isn't found */
@@ -6570,7 +6068,7 @@ ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode)
        sc->sc_currates = rt;
        sc->sc_curmode = mode;
        /*
-        * All protection frames are transmited at 2Mb/s for
+        * All protection frames are transmitted at 2Mb/s for
         * 11g, otherwise at 1Mb/s.
         */
        if (mode == IEEE80211_MODE_11G)
@@ -6578,35 +6076,30 @@ ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode)
        else
                sc->sc_protrix = ath_tx_findrix(sc, 2*1);
        /* NB: caller is responsible for resetting rate control state */
-#undef N
 }
 
 static void
 ath_watchdog(void *arg)
 {
        struct ath_softc *sc = arg;
+       struct ieee80211com *ic = &sc->sc_ic;
        int do_reset = 0;
 
        ATH_LOCK_ASSERT(sc);
 
        if (sc->sc_wd_timer != 0 && --sc->sc_wd_timer == 0) {
-               struct ifnet *ifp = sc->sc_ifp;
                uint32_t hangs;
 
                ath_power_set_power_state(sc, HAL_PM_AWAKE);
 
                if (ath_hal_gethangstate(sc->sc_ah, 0xffff, &hangs) &&
                    hangs != 0) {
-                       if_printf(ifp, "%s hang detected (0x%x)\n",
+                       device_printf(sc->sc_dev, "%s hang detected (0x%x)\n",
                            hangs & 0xff ? "bb" : "mac", hangs);
                } else
-                       if_printf(ifp, "device timeout\n");
+                       device_printf(sc->sc_dev, "device timeout\n");
                do_reset = 1;
-#if defined(__DragonFly__)
-               ++ifp->if_oerrors;
-#else
-               if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
-#endif
+               counter_u64_add(ic->ic_oerrors, 1);
                sc->sc_stats.ast_watchdog++;
 
                ath_power_restore_power_state(sc);
@@ -6622,194 +6115,27 @@ ath_watchdog(void *arg)
                taskqueue_enqueue(sc->sc_tq, &sc->sc_resettask);
        }
 
-#if defined(__DragonFly__)
-       callout_reset(&sc->sc_wd_ch, hz, ath_watchdog, sc);
-#else
        callout_schedule(&sc->sc_wd_ch, hz);
-#endif
 }
 
-#if defined(__DragonFly__)
-
-/*
- * (DragonFly network start)
- */
 static void
-ath_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
-{
-       struct ath_softc *sc = ifp->if_softc;
-       struct mbuf *m;
-       int wst;
-
-       ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
-       wst = wlan_serialize_push();
-
-       if ((ifp->if_flags & IFF_RUNNING) == 0 || sc->sc_invalid) {
-               ifq_purge(&ifp->if_snd);
-               wlan_serialize_pop(wst);
-               return;
-       }
-       ifq_set_oactive(&ifp->if_snd);
-       for (;;) {
-               m = ifq_dequeue(&ifp->if_snd);
-               if (m == NULL)
-                       break;
-               ath_transmit(ifp, m);
-       }
-       ifq_clr_oactive(&ifp->if_snd);
-       wlan_serialize_pop(wst);
-}
-
-#endif
-
-/*
- * Fetch the rate control statistics for the given node.
- */
-static int
-ath_ioctl_ratestats(struct ath_softc *sc, struct ath_rateioctl *rs)
+ath_parent(struct ieee80211com *ic)
 {
-       struct ath_node *an;
-       struct ieee80211com *ic = sc->sc_ifp->if_l2com;
-       struct ieee80211_node *ni;
-       int error = 0;
-
-       /* Perform a lookup on the given node */
-       ni = ieee80211_find_node(&ic->ic_sta, rs->is_u.macaddr);
-       if (ni == NULL) {
-               error = EINVAL;
-               goto bad;
-       }
-
-       /* Lock the ath_node */
-       an = ATH_NODE(ni);
-       ATH_NODE_LOCK(an);
-
-       /* Fetch the rate control stats for this node */
-       error = ath_rate_fetch_node_stats(sc, an, rs);
-
-       /* No matter what happens here, just drop through */
-
-       /* Unlock the ath_node */
-       ATH_NODE_UNLOCK(an);
-
-       /* Unref the node */
-       ieee80211_node_decref(ni);
-
-bad:
-       return (error);
-}
+       struct ath_softc *sc = ic->ic_softc;
+       int error = EDOOFUS;
 
-#ifdef ATH_DIAGAPI
-/*
- * Diagnostic interface to the HAL.  This is used by various
- * tools to do things like retrieve register contents for
- * debugging.  The mechanism is intentionally opaque so that
- * it can change frequently w/o concern for compatiblity.
- */
-static int
-ath_ioctl_diag(struct ath_softc *sc, struct ath_diag *ad)
-{
-       struct ath_hal *ah = sc->sc_ah;
-       u_int id = ad->ad_id & ATH_DIAG_ID;
-       void *indata = NULL;
-       void *outdata = NULL;
-       u_int32_t insize = ad->ad_in_size;
-       u_int32_t outsize = ad->ad_out_size;
-       int error = 0;
-
-       if (ad->ad_id & ATH_DIAG_IN) {
-               /*
-                * Copy in data.
-                */
-               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
-               if (indata == NULL) {
-                       error = ENOMEM;
-                       goto bad;
-               }
-               error = copyin(ad->ad_in_data, indata, insize);
-               if (error)
-                       goto bad;
-       }
-       if (ad->ad_id & ATH_DIAG_DYN) {
+       ATH_LOCK(sc);
+       if (ic->ic_nrunning > 0) {
                /*
-                * Allocate a buffer for the results (otherwise the HAL
-                * returns a pointer to a buffer where we can read the
-                * results).  Note that we depend on the HAL leaving this
-                * pointer for us to use below in reclaiming the buffer;
-                * may want to be more defensive.
+                * To avoid rescanning another access point,
+                * do not call ath_init() here.  Instead,
+                * only reflect promisc mode settings.
                 */
-               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
-               if (outdata == NULL) {
-                       error = ENOMEM;
-                       goto bad;
-               }
-       }
-
-
-       ATH_LOCK(sc);
-       if (id != HAL_DIAG_REGS)
-               ath_power_set_power_state(sc, HAL_PM_AWAKE);
-       ATH_UNLOCK(sc);
-
-       if (ath_hal_getdiagstate(ah, id, indata, insize, &outdata, &outsize)) {
-               if (outsize < ad->ad_out_size)
-                       ad->ad_out_size = outsize;
-               if (outdata != NULL)
-                       error = copyout(outdata, ad->ad_out_data,
-                                       ad->ad_out_size);
-       } else {
-               error = EINVAL;
-       }
-
-       ATH_LOCK(sc);
-       if (id != HAL_DIAG_REGS)
-               ath_power_restore_power_state(sc);
-       ATH_UNLOCK(sc);
-
-bad:
-       if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               kfree(indata, M_TEMP);
-       if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               kfree(outdata, M_TEMP);
-       return error;
-}
-#endif /* ATH_DIAGAPI */
-
-#if defined(__DragonFly__)
-
-static int
-ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data,
-         struct ucred *cred __unused)
-
-#else
-
-static int
-ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
-
-#endif
-{
-#define        IS_RUNNING(ifp) \
-       ((ifp->if_flags & IFF_UP) && (ifp->if_flags & IFF_RUNNING))
-       struct ieee80211com *ic = ifp->if_l2com;
-       struct ath_softc *sc = ic->ic_softc;
-       struct ifreq *ifr = (struct ifreq *)data;
-       const HAL_RATE_TABLE *rt;
-       int error = 0;
-
-       switch (cmd) {
-       case SIOCSIFFLAGS:
-               if (IS_RUNNING(ifp)) {
-                       /*
-                        * To avoid rescanning another access point,
-                        * do not call ath_init() here.  Instead,
-                        * only reflect promisc mode settings.
-                        */
-                       ATH_LOCK(sc);
+               if (sc->sc_running) {
                        ath_power_set_power_state(sc, HAL_PM_AWAKE);
                        ath_mode_init(sc);
                        ath_power_restore_power_state(sc);
-                       ATH_UNLOCK(sc);
-               } else if (ifp->if_flags & IFF_UP) {
+               } else if (!sc->sc_invalid) {
                        /*
                         * Beware of being called during attach/detach
                         * to reset promiscuous mode.  In that case we
@@ -6819,82 +6145,23 @@ ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
                         * torn down much of our state.  There's
                         * probably a better way to deal with this.
                         */
-                       if (!sc->sc_invalid)
-                               ath_init(sc);   /* XXX lose error */
-               } else {
-                       ATH_LOCK(sc);
-                       ath_stop_locked(ifp);
-                       if (!sc->sc_invalid)
-                               ath_power_setpower(sc, HAL_PM_FULL_SLEEP);
-                       ATH_UNLOCK(sc);
+                       error = ath_init(sc);
                }
-               break;
-       case SIOCGIFMEDIA:
-       case SIOCSIFMEDIA:
-               error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
-               break;
-       case SIOCGATHSTATS:
-               /* NB: embed these numbers to get a consistent view */
-#if defined(__DragonFly__)
-               sc->sc_stats.ast_tx_packets = ifp->if_opackets;
-               sc->sc_stats.ast_rx_packets = ifp->if_ipackets;
-#else
-               sc->sc_stats.ast_tx_packets = ifp->if_get_counter(ifp,
-                   IFCOUNTER_OPACKETS);
-               sc->sc_stats.ast_rx_packets = ifp->if_get_counter(ifp,
-                   IFCOUNTER_IPACKETS);
-#endif
-               sc->sc_stats.ast_tx_rssi = ATH_RSSI(sc->sc_halstats.ns_avgtxrssi);
-               sc->sc_stats.ast_rx_rssi = ATH_RSSI(sc->sc_halstats.ns_avgrssi);
-#ifdef IEEE80211_SUPPORT_TDMA
-               sc->sc_stats.ast_tdma_tsfadjp = TDMA_AVG(sc->sc_avgtsfdeltap);
-               sc->sc_stats.ast_tdma_tsfadjm = TDMA_AVG(sc->sc_avgtsfdeltam);
-#endif
-               rt = sc->sc_currates;
-               sc->sc_stats.ast_tx_rate =
-                   rt->info[sc->sc_txrix].dot11Rate &~ IEEE80211_RATE_BASIC;
-               if (rt->info[sc->sc_txrix].phy & IEEE80211_T_HT)
-                       sc->sc_stats.ast_tx_rate |= IEEE80211_RATE_MCS;
-               error = copyout(&sc->sc_stats,
-                   ifr->ifr_data, sizeof (sc->sc_stats));
-               break;
-       case SIOCGATHAGSTATS:
-               error = copyout(&sc->sc_aggr_stats,
-                   ifr->ifr_data, sizeof (sc->sc_aggr_stats));
-               break;
-       case SIOCZATHSTATS:
-               error = priv_check(curthread, PRIV_DRIVER);
-               if (error == 0) {
-                       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));
-               }
-               break;
-#ifdef ATH_DIAGAPI
-       case SIOCGATHDIAG:
-               error = ath_ioctl_diag(sc, (struct ath_diag *) ifr);
-               break;
-       case SIOCGATHPHYERR:
-               error = ath_ioctl_phyerr(sc,(struct ath_diag*) ifr);
-               break;
+       } else {
+               ath_stop(sc);
+               if (!sc->sc_invalid)
+                       ath_power_setpower(sc, HAL_PM_FULL_SLEEP);
+       }
+       ATH_UNLOCK(sc);
+
+       if (error == 0) {                        
+#ifdef ATH_TX99_DIAG
+               if (sc->sc_tx99 != NULL)
+                       sc->sc_tx99->start(sc->sc_tx99);
+               else
 #endif
-       case SIOCGATHSPECTRAL:
-               error = ath_ioctl_spectral(sc,(struct ath_diag*) ifr);
-               break;
-       case SIOCGATHNODERATESTATS:
-               error = ath_ioctl_ratestats(sc, (struct ath_rateioctl *) ifr);
-               break;
-       case SIOCGIFADDR:
-               error = ether_ioctl(ifp, cmd, data);
-               break;
-       default:
-               error = EINVAL;
-               break;
+               ieee80211_start_all(ic);
        }
-       return error;
-#undef IS_RUNNING
 }
 
 /*
@@ -6903,39 +6170,39 @@ ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 static void
 ath_announce(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
        struct ath_hal *ah = sc->sc_ah;
 
-       if_printf(ifp, "AR%s mac %d.%d RF%s phy %d.%d\n",
+       device_printf(sc->sc_dev, "%s mac %d.%d RF%s phy %d.%d\n",
                ath_hal_mac_name(ah), ah->ah_macVersion, ah->ah_macRev,
                ath_hal_rf_name(ah), ah->ah_phyRev >> 4, ah->ah_phyRev & 0xf);
-       if_printf(ifp, "2GHz radio: 0x%.4x; 5GHz radio: 0x%.4x\n",
+       device_printf(sc->sc_dev, "2GHz radio: 0x%.4x; 5GHz radio: 0x%.4x\n",
                ah->ah_analog2GhzRev, ah->ah_analog5GhzRev);
        if (bootverbose) {
                int i;
                for (i = 0; i <= WME_AC_VO; i++) {
                        struct ath_txq *txq = sc->sc_ac2q[i];
-                       if_printf(ifp, "Use hw queue %u for %s traffic\n",
-                               txq->axq_qnum, ieee80211_wme_acnames[i]);
+                       device_printf(sc->sc_dev,
+                           "Use hw queue %u for %s traffic\n",
+                           txq->axq_qnum, ieee80211_wme_acnames[i]);
                }
-               if_printf(ifp, "Use hw queue %u for CAB traffic\n",
-                       sc->sc_cabq->axq_qnum);
-               if_printf(ifp, "Use hw queue %u for beacons\n", sc->sc_bhalq);
+               device_printf(sc->sc_dev, "Use hw queue %u for CAB traffic\n",
+                   sc->sc_cabq->axq_qnum);
+               device_printf(sc->sc_dev, "Use hw queue %u for beacons\n",
+                   sc->sc_bhalq);
        }
        if (ath_rxbuf != ATH_RXBUF)
-               if_printf(ifp, "using %u rx buffers\n", ath_rxbuf);
+               device_printf(sc->sc_dev, "using %u rx buffers\n", ath_rxbuf);
        if (ath_txbuf != ATH_TXBUF)
-               if_printf(ifp, "using %u tx buffers\n", ath_txbuf);
+               device_printf(sc->sc_dev, "using %u tx buffers\n", ath_txbuf);
        if (sc->sc_mcastkey && bootverbose)
-               if_printf(ifp, "using multicast key search\n");
+               device_printf(sc->sc_dev, "using multicast key search\n");
 }
 
 static void
 ath_dfs_tasklet(void *p, int npending)
 {
        struct ath_softc *sc = (struct ath_softc *) p;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
 
        /*
         * If previous processing has found a radar event,
@@ -6972,9 +6239,10 @@ ath_node_powersave(struct ieee80211_node *ni, int enable)
 
        /* XXX and no TXQ locks should be held here */
 
-       DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, "%s: %6s: enable=%d\n",
+       DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE, "%s: %6D: enable=%d\n",
            __func__,
-           ath_hal_ether_sprintf(ni->ni_macaddr),
+           ni->ni_macaddr,
+           ":",
            !! enable);
 
        /* Suspend or resume software queue handling */
@@ -7069,16 +6337,18 @@ ath_node_set_tim(struct ieee80211_node *ni, int enable)
         */
        if (enable && an->an_tim_set == 1) {
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: enable=%d, tim_set=1, ignoring\n",
+                   "%s: %6D: enable=%d, tim_set=1, ignoring\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr),
+                   ni->ni_macaddr,
+                   ":",
                    enable);
                ATH_TX_UNLOCK(sc);
        } else if (enable) {
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: enable=%d, enabling TIM\n",
+                   "%s: %6D: enable=%d, enabling TIM\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr),
+                   ni->ni_macaddr,
+                   ":",
                    enable);
                an->an_tim_set = 1;
                ATH_TX_UNLOCK(sc);
@@ -7086,9 +6356,10 @@ ath_node_set_tim(struct ieee80211_node *ni, int enable)
        } else if (an->an_swq_depth == 0) {
                /* disable */
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: enable=%d, an_swq_depth == 0, disabling\n",
+                   "%s: %6D: enable=%d, an_swq_depth == 0, disabling\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr),
+                   ni->ni_macaddr,
+                   ":",
                    enable);
                an->an_tim_set = 0;
                ATH_TX_UNLOCK(sc);
@@ -7098,9 +6369,10 @@ ath_node_set_tim(struct ieee80211_node *ni, int enable)
                 * disable regardless; the node isn't in powersave now
                 */
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: enable=%d, an_pwrsave=0, disabling\n",
+                   "%s: %6D: enable=%d, an_pwrsave=0, disabling\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr),
+                   ni->ni_macaddr,
+                   ":",
                    enable);
                an->an_tim_set = 0;
                ATH_TX_UNLOCK(sc);
@@ -7113,9 +6385,10 @@ ath_node_set_tim(struct ieee80211_node *ni, int enable)
                 */
                ATH_TX_UNLOCK(sc);
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: enable=%d, an_swq_depth > 0, ignoring\n",
+                   "%s: %6D: enable=%d, an_swq_depth > 0, ignoring\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr),
+                   ni->ni_macaddr,
+                   ":",
                    enable);
                changed = 0;
        }
@@ -7185,9 +6458,10 @@ ath_tx_update_tim(struct ath_softc *sc, struct ieee80211_node *ni,
                    an->an_tim_set == 0 &&
                    an->an_swq_depth != 0) {
                        DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                           "%s: %s: swq_depth>0, tim_set=0, set!\n",
+                           "%s: %6D: swq_depth>0, tim_set=0, set!\n",
                            __func__,
-                           ath_hal_ether_sprintf(ni->ni_macaddr));
+                           ni->ni_macaddr,
+                           ":");
                        an->an_tim_set = 1;
                        (void) avp->av_set_tim(ni, 1);
                }
@@ -7203,10 +6477,11 @@ ath_tx_update_tim(struct ath_softc *sc, struct ieee80211_node *ni,
                    an->an_tim_set == 1 &&
                    an->an_swq_depth == 0) {
                        DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                           "%s: %s: swq_depth=0, tim_set=1, psq_set=0,"
+                           "%s: %6D: swq_depth=0, tim_set=1, psq_set=0,"
                            " clear!\n",
                            __func__,
-                           ath_hal_ether_sprintf(ni->ni_macaddr));
+                           ni->ni_macaddr,
+                           ":");
                        an->an_tim_set = 0;
                        (void) avp->av_set_tim(ni, 0);
                }
@@ -7284,9 +6559,10 @@ ath_node_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m)
         */
        if (! an->an_is_powersave) {
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: not in powersave?\n",
+                   "%s: %6D: not in powersave?\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr));
+                   ni->ni_macaddr,
+                   ":");
                ATH_TX_UNLOCK(sc);
                avp->av_recv_pspoll(ni, m);
                return;
@@ -7309,9 +6585,10 @@ ath_node_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m)
        if (an->an_swq_depth == 0) {
                ATH_TX_UNLOCK(sc);
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: SWQ empty; punting to net80211\n",
+                   "%s: %6D: SWQ empty; punting to net80211\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr));
+                   ni->ni_macaddr,
+                   ":");
                avp->av_recv_pspoll(ni, m);
                return;
        }
@@ -7336,9 +6613,10 @@ ath_node_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m)
                ATH_TX_UNLOCK(sc);
                taskqueue_enqueue(sc->sc_tq, &sc->sc_txqtask);
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: leaking frame to TID %d\n",
+                   "%s: %6D: leaking frame to TID %d\n",
                    __func__,
-                   ath_hal_ether_sprintf(ni->ni_macaddr),
+                   ni->ni_macaddr,
+                   ":",
                    tid);
                return;
        }
@@ -7349,9 +6627,10 @@ ath_node_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m)
         * XXX nothing in the TIDs at this point? Eek.
         */
        DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-           "%s: %s: TIDs empty, but ath_node showed traffic?!\n",
+           "%s: %6D: TIDs empty, but ath_node showed traffic?!\n",
            __func__,
-           ath_hal_ether_sprintf(ni->ni_macaddr));
+           ni->ni_macaddr,
+           ":");
        avp->av_recv_pspoll(ni, m);
 #else
        avp->av_recv_pspoll(ni, m);
index ab7540f..0b546a0 100644 (file)
@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/errno.h>
 
+#include <machine/bus.h>
+#include <machine/resource.h>
 #include <sys/bus.h>
 #include <sys/rman.h>
 
@@ -56,15 +58,13 @@ __FBSDID("$FreeBSD$");
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 
-#include <netproto/802_11/ieee80211_var.h>
+#include <net80211/ieee80211_var.h>
 
-#include <dev/netif/ath/ath/if_athvar.h>
+#include <dev/ath/if_athvar.h>
 
-#if 0
 #include <mips/atheros/ar71xxreg.h>
 #include <mips/atheros/ar91xxreg.h>
 #include <mips/atheros/ar71xx_cpudef.h>
-#endif
 
 /*
  * bus glue.
@@ -117,6 +117,14 @@ ath_ahb_probe(device_t dev)
        return ENXIO;
 }
 
+static void
+ath_ahb_intr(void *arg)
+{
+       /* XXX TODO: check if its ours! */
+       ar71xx_device_flush_ddr(AR71XX_CPU_DDR_FLUSH_WMAC);
+       ath_intr(arg);
+}
+
 static int
 ath_ahb_attach(device_t dev)
 {
@@ -153,12 +161,24 @@ ath_ahb_attach(device_t dev)
                eepromsize = ATH_EEPROM_DATA_SIZE * 2;
        }
 
-
        rid = 0;
        device_printf(sc->sc_dev, "eeprom @ %p (%d bytes)\n",
            (void *) eepromaddr, eepromsize);
-       psc->sc_eeprom = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, (uintptr_t) eepromaddr,
-         (uintptr_t) eepromaddr + (uintptr_t) (eepromsize - 1), 0, RF_ACTIVE);
+       /*
+        * XXX this assumes that the parent device is the nexus
+        * and will just pass through requests for all of memory.
+        *
+        * Later on, when this has to attach off of the actual
+        * AHB, this won't work.
+        *
+        * Ideally this would be done in machdep code in mips/atheros/
+        * and it'd expose the EEPROM via the firmware interface,
+        * so the ath/ath_ahb drivers can be loaded as modules
+        * after boot-time.
+        */
+       psc->sc_eeprom = bus_alloc_resource(dev, SYS_RES_MEMORY,
+           &rid, (uintptr_t) eepromaddr,
+           (uintptr_t) eepromaddr + (uintptr_t) (eepromsize - 1), 0, RF_ACTIVE);
        if (psc->sc_eeprom == NULL) {
                device_printf(dev, "cannot map eeprom space\n");
                goto bad0;
@@ -173,7 +193,7 @@ ath_ahb_attach(device_t dev)
        sc->sc_invalid = 1;
 
        /* Copy the EEPROM data out */
-       sc->sc_eepromdata = kmalloc(eepromsize, M_TEMP, M_INTWAIT | M_ZERO);
+       sc->sc_eepromdata = malloc(eepromsize, M_TEMP, M_NOWAIT | M_ZERO);
        if (sc->sc_eepromdata == NULL) {
                device_printf(dev, "cannot allocate memory for eeprom data\n");
                goto bad1;
@@ -198,33 +218,18 @@ ath_ahb_attach(device_t dev)
                device_printf(dev, "could not map interrupt\n");
                goto bad1;
        }
-
-#if defined(__DragonFly__)
-       if (bus_setup_intr(dev, psc->sc_irq,
-                          INTR_MPSAFE,
-                          ath_intr, sc, &psc->sc_ih,
-                          &wlan_global_serializer)) {
-               device_printf(dev, "could not establish interrupt\n");
-               goto bad2;
-       }
-#else
        if (bus_setup_intr(dev, psc->sc_irq,
                           INTR_TYPE_NET | INTR_MPSAFE,
-                          NULL, ath_intr, sc, &psc->sc_ih)) {
+                          NULL, ath_ahb_intr, sc, &psc->sc_ih)) {
                device_printf(dev, "could not establish interrupt\n");
                goto bad2;
        }
-#endif
 
        /*
         * Setup DMA descriptor area.
         */
        if (bus_dma_tag_create(bus_get_dma_tag(dev),    /* parent */
-#if defined(__DragonFly__)
-                              4, 0,                    /* alignment, bounds */
-#else
                               1, 0,                    /* alignment, bounds */
-#endif
                               BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
                               BUS_SPACE_MAXADDR,       /* highaddr */
                               NULL, NULL,              /* filter, filterarg */
@@ -232,10 +237,8 @@ ath_ahb_attach(device_t dev)
                               ATH_MAX_SCATTER,         /* nsegments */
                               0x3ffff,                 /* maxsegsize XXX */
                               BUS_DMA_ALLOCNOW,        /* flags */
-#if !defined(__DragonFly__)
                               NULL,                    /* lockfunc */
                               NULL,                    /* lockarg */
-#endif
                               &sc->sc_dmat)) {
                device_printf(dev, "cannot allocate DMA tag\n");
                goto bad3;
@@ -258,7 +261,6 @@ ath_ahb_attach(device_t dev)
        ATH_PCU_LOCK_INIT(sc);
        ATH_RX_LOCK_INIT(sc);
        ATH_TX_LOCK_INIT(sc);
-       ATH_TX_IC_LOCK_INIT(sc);
        ATH_TXSTATUS_LOCK_INIT(sc);
 
        error = ath_attach(device_id, sc);
@@ -268,7 +270,6 @@ ath_ahb_attach(device_t dev)
        ATH_TXSTATUS_LOCK_DESTROY(sc);
        ATH_RX_LOCK_DESTROY(sc);
        ATH_TX_LOCK_DESTROY(sc);
-       ATH_TX_IC_LOCK_DESTROY(sc);
        ATH_PCU_LOCK_DESTROY(sc);
        ATH_LOCK_DESTROY(sc);
        bus_dma_tag_destroy(sc->sc_dmat);
@@ -283,7 +284,7 @@ bad0:
 bad:
        /* XXX?! */
        if (sc->sc_eepromdata)
-               kfree(sc->sc_eepromdata, M_TEMP);
+               free(sc->sc_eepromdata, M_TEMP);
        return (error);
 }
 
@@ -307,12 +308,11 @@ ath_ahb_detach(device_t dev)
        bus_release_resource(dev, SYS_RES_MEMORY, 0, psc->sc_eeprom);
        /* XXX?! */
        if (sc->sc_eepromdata)
-               kfree(sc->sc_eepromdata, M_TEMP);
+               free(sc->sc_eepromdata, M_TEMP);
 
        ATH_TXSTATUS_LOCK_DESTROY(sc);
        ATH_RX_LOCK_DESTROY(sc);
        ATH_TX_LOCK_DESTROY(sc);
-       ATH_TX_IC_LOCK_DESTROY(sc);
        ATH_PCU_LOCK_DESTROY(sc);
        ATH_LOCK_DESTROY(sc);
 
@@ -365,7 +365,8 @@ static driver_t ath_ahb_driver = {
        sizeof (struct ath_ahb_softc)
 };
 static devclass_t ath_devclass;
-DRIVER_MODULE(ath, nexus, ath_ahb_driver, ath_devclass, NULL, NULL);
+DRIVER_MODULE(ath, nexus, ath_ahb_driver, ath_devclass, 0, 0);
+DRIVER_MODULE(ath, apb, 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 */
index 2551740..8ca53ae 100644 (file)
 #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/alq.h>
 #include <sys/endian.h>
 #include <sys/time.h>
 
-#include <dev/netif/ath/ath/if_ath_alq.h>
+#include <dev/ath/if_ath_alq.h>
 
 #ifdef ATH_DEBUG_ALQ
 static struct ale *
@@ -68,8 +70,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);
-       kprintf("%s (%s): attached\n", __func__, alq->sc_alq_devname);
-       ksnprintf(alq->sc_alq_filename, ATH_ALQ_FILENAME_LEN,
+       printf("%s (%s): attached\n", __func__, alq->sc_alq_devname);
+       snprintf(alq->sc_alq_filename, ATH_ALQ_FILENAME_LEN,
            "/tmp/ath_%s_alq.log", alq->sc_alq_devname);
 
        /* XXX too conservative, right? */
@@ -93,7 +95,7 @@ if_ath_alq_tidyup(struct if_ath_alq *alq)
 {
 
        if_ath_alq_stop(alq);
-       kprintf("%s (%s): detached\n", __func__, alq->sc_alq_devname);
+       printf("%s (%s): detached\n", __func__, alq->sc_alq_devname);
        bzero(alq, sizeof(*alq));
 }
 
@@ -113,10 +115,10 @@ if_ath_alq_start(struct if_ath_alq *alq)
            alq->sc_alq_qsize, 0);
 
        if (error != 0) {
-               kprintf("%s (%s): failed, err=%d\n", __func__,
+               printf("%s (%s): failed, err=%d\n", __func__,
                    alq->sc_alq_devname, error);
        } else {
-               kprintf("%s (%s): opened\n", __func__, alq->sc_alq_devname);
+               printf("%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),
@@ -132,7 +134,7 @@ if_ath_alq_stop(struct if_ath_alq *alq)
        if (alq->sc_alq_isactive == 0)
                return (0);
 
-       kprintf("%s (%s): closed\n", __func__, alq->sc_alq_devname);
+       printf("%s (%s): closed\n", __func__, alq->sc_alq_devname);
 
        alq->sc_alq_isactive = 0;
        alq_close(alq->sc_alq_alq);
index cf0fc96..c700230 100644 (file)
@@ -68,7 +68,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/module.h>
 #include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
 
+#include <machine/bus.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -79,10 +81,10 @@ __FBSDID("$FreeBSD$");
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 
-#include <netproto/802_11/ieee80211_var.h>
-#include <netproto/802_11/ieee80211_regdomain.h>
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 
 #include <net/bpf.h>
@@ -92,15 +94,15 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
+#include <dev/ath/if_athvar.h>
 
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
-#include <dev/netif/ath/ath/if_ath_tx.h>
-#include <dev/netif/ath/ath/if_ath_beacon.h>
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_beacon.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
 /*
@@ -132,7 +134,7 @@ int
 ath_beaconq_config(struct ath_softc *sc)
 {
 #define        ATH_EXPONENT_TO_VALUE(v)        ((1<<(v))-1)
-       struct ieee80211com *ic = sc->sc_ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        HAL_TXQ_INFO qi;
 
@@ -197,21 +199,15 @@ ath_beacon_alloc(struct ath_softc *sc, struct ieee80211_node *ni)
         * we assume the mbuf routines will return us something
         * with this alignment (perhaps should assert).
         */
-       m = ieee80211_beacon_alloc(ni, &avp->av_boff);
+       m = ieee80211_beacon_alloc(ni);
        if (m == NULL) {
                device_printf(sc->sc_dev, "%s: cannot get mbuf\n", __func__);
                sc->sc_stats.ast_be_nombuf++;
                return ENOMEM;
        }
-#if defined(__DragonFly__)
-       error = bus_dmamap_load_mbuf_segment(sc->sc_dmat, bf->bf_dmamap, m,
-                                    bf->bf_segs, 1, &bf->bf_nseg,
-                                    BUS_DMA_NOWAIT);
-#else
        error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m,
                                     bf->bf_segs, &bf->bf_nseg,
                                     BUS_DMA_NOWAIT);
-#endif
        if (error != 0) {
                device_printf(sc->sc_dev,
                    "%s: cannot map mbuf, bus_dmamap_load_mbuf_sg returns %d\n",
@@ -378,7 +374,7 @@ ath_beacon_setup(struct ath_softc *sc, struct ath_buf *bf)
 void
 ath_beacon_update(struct ieee80211vap *vap, int item)
 {
-       struct ieee80211_beacon_offsets *bo = &ATH_VAP(vap)->av_boff;
+       struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off;
 
        setbit(bo->bo_flags, item);
 }
@@ -468,7 +464,7 @@ ath_beacon_proc(void *arg, int pending)
        }
 
        if (sc->sc_stagbeacons) {                       /* staggered beacons */
-               struct ieee80211com *ic = sc->sc_ifp->if_l2com;
+               struct ieee80211com *ic = &sc->sc_ic;
                uint32_t tsftu;
 
                tsftu = ath_hal_gettsf32(ah) >> 10;
@@ -717,19 +713,12 @@ ath_beacon_generate(struct ath_softc *sc, struct ieee80211vap *vap)
        /* XXX lock mcastq? */
        nmcastq = avp->av_mcastq.axq_depth;
 
-       if (ieee80211_beacon_update(bf->bf_node, &avp->av_boff, m, nmcastq)) {
+       if (ieee80211_beacon_update(bf->bf_node, m, nmcastq)) {
                /* XXX too conservative? */
                bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
-#if defined(__DragonFly__)
-               error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
-                                            bf->bf_dmamap, m,
-                                            bf->bf_segs, 1, &bf->bf_nseg,
-                                            BUS_DMA_NOWAIT);
-#else
                error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m,
                                             bf->bf_segs, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
-#endif
                if (error != 0) {
                        if_printf(vap->iv_ifp,
                            "%s: bus_dmamap_load_mbuf_sg failed, error %u\n",
@@ -737,7 +726,7 @@ ath_beacon_generate(struct ath_softc *sc, struct ieee80211vap *vap)
                        return NULL;
                }
        }
-       if ((avp->av_boff.bo_tim[4] & 1) && cabq->axq_depth) {
+       if ((vap->iv_bcn_off.bo_tim[4] & 1) && cabq->axq_depth) {
                DPRINTF(sc, ATH_DEBUG_BEACON,
                    "%s: cabq did not drain, mcastq %u cabq %u\n",
                    __func__, nmcastq, cabq->axq_depth);
@@ -775,7 +764,7 @@ ath_beacon_generate(struct ath_softc *sc, struct ieee80211vap *vap)
         * Enable the CAB queue before the beacon queue to
         * insure cab frames are triggered by this beacon.
         */
-       if (avp->av_boff.bo_tim[4] & 1) {
+       if (vap->iv_bcn_off.bo_tim[4] & 1) {
 
                /* NB: only at DTIM */
                ATH_TXQ_LOCK(&avp->av_mcastq);
@@ -840,19 +829,12 @@ ath_beacon_start_adhoc(struct ath_softc *sc, struct ieee80211vap *vap)
         */
        bf = avp->av_bcbuf;
        m = bf->bf_m;
-       if (ieee80211_beacon_update(bf->bf_node, &avp->av_boff, m, 0)) {
+       if (ieee80211_beacon_update(bf->bf_node, m, 0)) {
                /* XXX too conservative? */
                bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
-#if defined(__DragonFly__)
-               error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
-                                            bf->bf_dmamap, m,
-                                            bf->bf_segs, 1, &bf->bf_nseg,
-                                            BUS_DMA_NOWAIT);
-#else
                error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m,
                                             bf->bf_segs, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
-#endif
                if (error != 0) {
                        if_printf(vap->iv_ifp,
                            "%s: bus_dmamap_load_mbuf_sg failed, error %u\n",
@@ -935,7 +917,7 @@ ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap)
        ((((u_int32_t)(_h)) << 22) | (((u_int32_t)(_l)) >> 10))
 #define        FUDGE   2
        struct ath_hal *ah = sc->sc_ah;
-       struct ieee80211com *ic = sc->sc_ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ieee80211_node *ni;
        u_int32_t nexttbtt, intval, tsftu;
        u_int32_t nexttbtt_u8, intval_u8;
@@ -960,11 +942,11 @@ ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap)
        ATH_UNLOCK(sc);
 
        /* extract tstamp from last beacon and convert to TU */
-       nexttbtt = TSF_TO_TU(LE_READ_4(ni->ni_tstamp.data + 4),
-                            LE_READ_4(ni->ni_tstamp.data));
+       nexttbtt = TSF_TO_TU(le32dec(ni->ni_tstamp.data + 4),
+                            le32dec(ni->ni_tstamp.data));
 
-       tsf_beacon = ((uint64_t) LE_READ_4(ni->ni_tstamp.data + 4)) << 32;
-       tsf_beacon |= LE_READ_4(ni->ni_tstamp.data);
+       tsf_beacon = ((uint64_t) le32dec(ni->ni_tstamp.data + 4)) << 32;
+       tsf_beacon |= le32dec(ni->ni_tstamp.data);
 
        if (ic->ic_opmode == IEEE80211_M_HOSTAP ||
            ic->ic_opmode == IEEE80211_M_MBSS) {
index b789993..b78f866 100644 (file)
@@ -48,6 +48,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/errno.h>
 
+#include <machine/bus.h>
+#include <machine/resource.h>
 #include <sys/bus.h>
 
 #include <sys/socket.h>
@@ -58,7 +60,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_arp.h>
 #include <net/ethernet.h>              /* XXX for ether_sprintf */
 
-#include <netproto/802_11/ieee80211_var.h>
+#include <net80211/ieee80211_var.h>
 
 #include <net/bpf.h>
 
@@ -67,8 +69,8 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath/if_ath_btcoex.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/if_ath_btcoex.h>
 
 /*
  * Initial AR9285 / (WB195) bluetooth coexistence settings,
@@ -372,7 +374,7 @@ ath_btcoex_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
-               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
+               indata = malloc(insize, M_TEMP, M_NOWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -389,7 +391,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.
                 */
-               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
+               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -405,9 +407,9 @@ ath_btcoex_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               kfree(indata, M_TEMP);
+               free(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               kfree(outdata, M_TEMP);
+               free(outdata, M_TEMP);
        return (error);
 }
 
index 4f04851..d21ad6f 100644 (file)
@@ -30,8 +30,6 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#define CTLFLAG_RWTUN  CTLFLAG_RW
-
 #include "opt_inet.h"
 #include "opt_ath.h"
 #include "opt_wlan.h"
@@ -54,6 +52,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/taskqueue.h>
 #include <sys/priv.h>
 
+#include <machine/bus.h>
+
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <net/if_media.h>
@@ -62,13 +62,13 @@ __FBSDID("$FreeBSD$");
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 
-#include <netproto/802_11/ieee80211_var.h>
-#include <netproto/802_11/ieee80211_regdomain.h>
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
 
 #include <net/bpf.h>
@@ -78,16 +78,16 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
 #ifdef ATH_DEBUG
-#include <dev/netif/ath/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_debug.h>
 
 uint64_t ath_debug = 0;
 
@@ -105,7 +105,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++) {
-               kprintf("R[%2u] (DS.V:%p DS.P:%p) L:%08x D:%08x%s\n"
+               printf("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,
@@ -113,17 +113,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) {
-                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       printf("        %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) {
-                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       printf("        %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]);
 
-                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       printf("        %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]);
@@ -142,7 +142,7 @@ ath_printtxbuf_edma(struct ath_softc *sc, const struct ath_buf *first_bf,
        const struct ath_desc_txedma *eds;
        int i, n;
 
-       kprintf("Q%u[%3u] (nseg=%d)", qnum, ix, bf->bf_nseg);
+       printf("Q%u[%3u] (nseg=%d)", qnum, ix, bf->bf_nseg);
        while (bf != NULL) {
                /*
                 * XXX For now, assume the txmap size is 4.
@@ -158,38 +158,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;
-                       kprintf(" (DS.V:%p DS.P:%p) I: %08x L:%08x F:%04x%s\n",
+                       printf(" (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) ? " *" : " !");
-                       kprintf(" (D[0] = %08x(%08x), D[1] = %08x(%08x)\n",
+                       printf(" (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]);
-                       kprintf(" (D[2] = %08x(%08x), D[3] = %08x(%08x)\n",
+                       printf(" (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]);
-                       kprintf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
+                       printf("        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);
-                       kprintf("        %08x %08x %08x %08x %08x %08x\n",
+                       printf("        %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]);
-                       kprintf("        %08x %08x %08x %08x %08x %08x %08x\n",
+                       printf("        %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
-                       kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
+                       printf("        %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
                }
-               kprintf("  [end]\n");
+               printf("  [end]\n");
                bf = bf->bf_next;
        }
 }
@@ -204,35 +204,35 @@ ath_printtxbuf_legacy(struct ath_softc *sc, const struct ath_buf *first_bf,
        const struct ath_desc *ds;
        int i;
 
-       kprintf("Q%u[%3u]", qnum, ix);
+       printf("Q%u[%3u]", qnum, ix);
        while (bf != NULL) {
-               kprintf("    (bf=%p, lastds=%p)\n", bf, first_bf->bf_lastds);
-               kprintf("        Seq: %d swtry: %d ADDBAW?: %d DOBAW?: %d\n",
+               printf("    (bf=%p, lastds=%p)\n", bf, first_bf->bf_lastds);
+               printf("        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++) {
-                       kprintf(" (DS.V:%p DS.P:%p) L:%08x D:%08x F:%04x%s\n",
+                       printf(" (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) ? " *" : " !");
-                       kprintf("        %08x %08x %08x %08x %08x %08x\n",
+                       printf("        %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) {
-                               kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
+                               printf("        %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]);
-                               kprintf("        %08x %08x %08x %08x %08x %08x %08x %08x\n",
+                               printf("        %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]);
                        }
                }
-               kprintf("  [end]\n");
+               printf("  [end]\n");
                bf = bf->bf_next;
        }
 }
@@ -252,10 +252,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)
 {
 
-       kprintf("Q%u[%3u] ", qnum, ix);
-       kprintf("        %08x %08x %08x %08x %08x %08x\n",
+       printf("Q%u[%3u] ", qnum, ix);
+       printf("        %08x %08x %08x %08x %08x %08x\n",
            ds[0], ds[1], ds[2], ds[3], ds[4], ds[5]);
-       kprintf("        %08x %08x %08x %08x %08x\n",
+       printf("        %08x %08x %08x %08x %08x\n",
            ds[6], ds[7], ds[8], ds[9], ds[10]);
 }
 
index 337ecf7..5d47139 100644 (file)
@@ -84,26 +84,17 @@ enum {
        ATH_KTR_TX              = 0x00000080,
 };
 
-#if defined(__DragonFly__)
-
-#define        ATH_KTR(_sc, _km, _kf, ...)
-
-#else
-
 #define        ATH_KTR(_sc, _km, _kf, ...)     do {    \
        if (sc->sc_ktrdebug & (_km))            \
                CTR##_kf(KTR_DEV, __VA_ARGS__); \
        } while (0)
-#endif
 
 extern uint64_t ath_debug;
 
-#define        IFF_DUMPPKTS(sc, m) \
-       ((sc->sc_debug & (m)) || \
-           (sc->sc_ifp->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2))
+#define        IFF_DUMPPKTS(sc, m)     (sc->sc_debug & (m))
 #define        DPRINTF(sc, m, fmt, ...) do {                           \
        if (sc->sc_debug & (m))                                 \
-               device_printf(sc->sc_dev, fmt, __VA_ARGS__);    \
+               device_printf(sc->sc_dev, fmt, __VA_ARGS__);            \
 } while (0)
 #define        KEYPRINTF(sc, ix, hk, mac) do {                         \
        if (sc->sc_debug & ATH_DEBUG_KEYCACHE)                  \
@@ -119,8 +110,7 @@ extern      void ath_printtxstatbuf(struct ath_softc *sc, const struct ath_buf *bf,
 #else  /* ATH_DEBUG */
 #define        ATH_KTR(_sc, _km, _kf, ...)     do { } while (0)
 
-#define        IFF_DUMPPKTS(sc, m) \
-       ((sc->sc_ifp->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2))
+#define        IFF_DUMPPKTS(sc, m)     (0)
 #define        DPRINTF(sc, m, fmt, ...) do {                           \
        (void) sc;                                              \
 } while (0)
diff --git a/sys/dev/netif/ath/ath/if_ath_descdma.c b/sys/dev/netif/ath/ath/if_ath_descdma.c
new file mode 100644 (file)
index 0000000..66ff351
--- /dev/null
@@ -0,0 +1,442 @@
+/*-
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
+ * 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,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ *    redistribution must be conditioned upon including a substantially
+ *    similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Driver for the Atheros Wireless LAN controller.
+ *
+ * This software is derived from work of Atsushi Onoe; his contribution
+ * is greatly appreciated.
+ */
+
+#include "opt_inet.h"
+#include "opt_ath.h"
+/*
+ * This is needed for register operations which are performed
+ * by the driver - eg, calls to ath_hal_gettsf32().
+ *
+ * It's also required for any AH_DEBUG checks in here, eg the
+ * module dependencies.
+ */
+#include "opt_ah.h"
+#include "opt_wlan.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/sysctl.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/errno.h>
+#include <sys/callout.h>
+#include <sys/bus.h>
+#include <sys/endian.h>
+#include <sys/kthread.h>
+#include <sys/taskqueue.h>
+#include <sys/priv.h>
+#include <sys/module.h>
+#include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
+
+#include <machine/bus.h>
+
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <net/if_llc.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
+#ifdef IEEE80211_SUPPORT_SUPERG
+#include <net80211/ieee80211_superg.h>
+#endif
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <net80211/ieee80211_tdma.h>
+#endif
+
+#include <net/bpf.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#endif
+
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
+
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
+#if 0
+#include <dev/ath/if_ath_tsf.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_sysctl.h>
+#include <dev/ath/if_ath_led.h>
+#include <dev/ath/if_ath_keycache.h>
+#include <dev/ath/if_ath_rx.h>
+#include <dev/ath/if_ath_rx_edma.h>
+#include <dev/ath/if_ath_tx_edma.h>
+#include <dev/ath/if_ath_beacon.h>
+#include <dev/ath/if_ath_btcoex.h>
+#include <dev/ath/if_ath_spectral.h>
+#include <dev/ath/if_ath_lna_div.h>
+#include <dev/ath/if_athdfs.h>
+#endif
+#include <dev/ath/if_ath_descdma.h>
+
+MALLOC_DECLARE(M_ATHDEV);
+
+/*
+ * This is the descriptor setup / busdma memory intialisation and
+ * teardown routines.
+ */
+
+static void
+ath_load_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
+{
+       bus_addr_t *paddr = (bus_addr_t*) arg;
+       KASSERT(error == 0, ("error %u on bus_dma callback", error));
+       *paddr = segs->ds_addr;
+}
+
+/*
+ * Allocate the descriptors and appropriate DMA tag/setup.
+ *
+ * For some situations (eg EDMA TX completion), there isn't a requirement
+ * for the ath_buf entries to be allocated.
+ */
+int
+ath_descdma_alloc_desc(struct ath_softc *sc,
+       struct ath_descdma *dd, ath_bufhead *head,
+       const char *name, int ds_size, int ndesc)
+{
+#define        DS2PHYS(_dd, _ds) \
+       ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
+#define        ATH_DESC_4KB_BOUND_CHECK(_daddr, _len) \
+       ((((u_int32_t)(_daddr) & 0xFFF) > (0x1000 - (_len))) ? 1 : 0)
+       int error;
+
+       dd->dd_descsize = ds_size;
+
+       DPRINTF(sc, ATH_DEBUG_RESET,
+           "%s: %s DMA: %u desc, %d bytes per descriptor\n",
+           __func__, name, ndesc, dd->dd_descsize);
+
+       dd->dd_name = name;
+       dd->dd_desc_len = dd->dd_descsize * ndesc;
+
+       /*
+        * Merlin work-around:
+        * Descriptors that cross the 4KB boundary can't be used.
+        * Assume one skipped descriptor per 4KB page.
+        */
+       if (! ath_hal_split4ktrans(sc->sc_ah)) {
+               int numpages = dd->dd_desc_len / 4096;
+               dd->dd_desc_len += ds_size * numpages;
+       }
+
+       /*
+        * Setup DMA descriptor area.
+        *
+        * BUS_DMA_ALLOCNOW is not used; we never use bounce
+        * buffers for the descriptors themselves.
+        */
+       error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), /* parent */
+                      PAGE_SIZE, 0,            /* alignment, bounds */
+                      BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
+                      BUS_SPACE_MAXADDR,       /* highaddr */
+                      NULL, NULL,              /* filter, filterarg */
+                      dd->dd_desc_len,         /* maxsize */
+                      1,                       /* nsegments */
+                      dd->dd_desc_len,         /* maxsegsize */
+                      0,                       /* flags */
+                      NULL,                    /* lockfunc */
+                      NULL,                    /* lockarg */
+                      &dd->dd_dmat);
+       if (error != 0) {
+               device_printf(sc->sc_dev,
+                   "cannot allocate %s DMA tag\n", dd->dd_name);
+               return error;
+       }
+
+       /* allocate descriptors */
+       error = bus_dmamem_alloc(dd->dd_dmat, (void**) &dd->dd_desc,
+                                BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
+                                &dd->dd_dmamap);
+       if (error != 0) {
+               device_printf(sc->sc_dev,
+                   "unable to alloc memory for %u %s descriptors, error %u\n",
+                   ndesc, dd->dd_name, error);
+               goto fail1;
+       }
+
+       error = bus_dmamap_load(dd->dd_dmat, dd->dd_dmamap,
+                               dd->dd_desc, dd->dd_desc_len,
+                               ath_load_cb, &dd->dd_desc_paddr,
+                               BUS_DMA_NOWAIT);
+       if (error != 0) {
+               device_printf(sc->sc_dev,
+                   "unable to map %s descriptors, error %u\n",
+                   dd->dd_name, error);
+               goto fail2;
+       }
+
+       DPRINTF(sc, ATH_DEBUG_RESET, "%s: %s DMA map: %p (%lu) -> %p (%lu)\n",
+           __func__, dd->dd_name, (uint8_t *) dd->dd_desc,
+           (u_long) dd->dd_desc_len, (caddr_t) dd->dd_desc_paddr,
+           /*XXX*/ (u_long) dd->dd_desc_len);
+
+       return (0);
+
+fail2:
+       bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
+fail1:
+       bus_dma_tag_destroy(dd->dd_dmat);
+       memset(dd, 0, sizeof(*dd));
+       return error;
+#undef DS2PHYS
+#undef ATH_DESC_4KB_BOUND_CHECK
+}
+
+int
+ath_descdma_setup(struct ath_softc *sc,
+       struct ath_descdma *dd, ath_bufhead *head,
+       const char *name, int ds_size, int nbuf, int ndesc)
+{
+#define        DS2PHYS(_dd, _ds) \
+       ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
+#define        ATH_DESC_4KB_BOUND_CHECK(_daddr, _len) \
+       ((((u_int32_t)(_daddr) & 0xFFF) > (0x1000 - (_len))) ? 1 : 0)
+       uint8_t *ds;
+       struct ath_buf *bf;
+       int i, bsize, error;
+
+       /* Allocate descriptors */
+       error = ath_descdma_alloc_desc(sc, dd, head, name, ds_size,
+           nbuf * ndesc);
+
+       /* Assume any errors during allocation were dealt with */
+       if (error != 0) {
+               return (error);
+       }
+
+       ds = (uint8_t *) dd->dd_desc;
+
+       /* allocate rx buffers */
+       bsize = sizeof(struct ath_buf) * nbuf;
+       bf = malloc(bsize, M_ATHDEV, M_NOWAIT | M_ZERO);
+       if (bf == NULL) {
+               device_printf(sc->sc_dev,
+                   "malloc of %s buffers failed, size %u\n",
+                   dd->dd_name, bsize);
+               goto fail3;
+       }
+       dd->dd_bufptr = bf;
+
+       TAILQ_INIT(head);
+       for (i = 0; i < nbuf; i++, bf++, ds += (ndesc * dd->dd_descsize)) {
+               bf->bf_desc = (struct ath_desc *) ds;
+               bf->bf_daddr = DS2PHYS(dd, ds);
+               if (! ath_hal_split4ktrans(sc->sc_ah)) {
+                       /*
+                        * Merlin WAR: Skip descriptor addresses which
+                        * cause 4KB boundary crossing along any point
+                        * in the descriptor.
+                        */
+                        if (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr,
+                            dd->dd_descsize)) {
+                               /* Start at the next page */
+                               ds += 0x1000 - (bf->bf_daddr & 0xFFF);
+                               bf->bf_desc = (struct ath_desc *) ds;
+                               bf->bf_daddr = DS2PHYS(dd, ds);
+                       }
+               }
+               error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT,
+                               &bf->bf_dmamap);
+               if (error != 0) {
+                       device_printf(sc->sc_dev, "unable to create dmamap "
+                           "for %s buffer %u, error %u\n",
+                           dd->dd_name, i, error);
+                       ath_descdma_cleanup(sc, dd, head);
+                       return error;
+               }
+               bf->bf_lastds = bf->bf_desc;    /* Just an initial value */
+               TAILQ_INSERT_TAIL(head, bf, bf_list);
+       }
+
+       /*
+        * XXX TODO: ensure that ds doesn't overflow the descriptor
+        * allocation otherwise weird stuff will occur and crash your
+        * machine.
+        */
+       return 0;
+       /* XXX this should likely just call ath_descdma_cleanup() */
+fail3:
+       bus_dmamap_unload(dd->dd_dmat, dd->dd_dmamap);
+       bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
+       bus_dma_tag_destroy(dd->dd_dmat);
+       memset(dd, 0, sizeof(*dd));
+       return error;
+#undef DS2PHYS
+#undef ATH_DESC_4KB_BOUND_CHECK
+}
+
+/*
+ * Allocate ath_buf entries but no descriptor contents.
+ *
+ * This is for RX EDMA where the descriptors are the header part of
+ * the RX buffer.
+ */
+int
+ath_descdma_setup_rx_edma(struct ath_softc *sc,
+       struct ath_descdma *dd, ath_bufhead *head,
+       const char *name, int nbuf, int rx_status_len)
+{
+       struct ath_buf *bf;
+       int i, bsize, error;
+
+       DPRINTF(sc, ATH_DEBUG_RESET, "%s: %s DMA: %u buffers\n",
+           __func__, name, nbuf);
+
+       dd->dd_name = name;
+       /*
+        * This is (mostly) purely for show.  We're not allocating any actual
+        * descriptors here as EDMA RX has the descriptor be part
+        * of the RX buffer.
+        *
+        * However, dd_desc_len is used by ath_descdma_free() to determine
+        * whether we have already freed this DMA mapping.
+        */
+       dd->dd_desc_len = rx_status_len * nbuf;
+       dd->dd_descsize = rx_status_len;
+
+       /* allocate rx buffers */
+       bsize = sizeof(struct ath_buf) * nbuf;
+       bf = malloc(bsize, M_ATHDEV, M_NOWAIT | M_ZERO);
+       if (bf == NULL) {
+               device_printf(sc->sc_dev,
+                   "malloc of %s buffers failed, size %u\n",
+                   dd->dd_name, bsize);
+               error = ENOMEM;
+               goto fail3;
+       }
+       dd->dd_bufptr = bf;
+
+       TAILQ_INIT(head);
+       for (i = 0; i < nbuf; i++, bf++) {
+               bf->bf_desc = NULL;
+               bf->bf_daddr = 0;
+               bf->bf_lastds = NULL;   /* Just an initial value */
+
+               error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT,
+                               &bf->bf_dmamap);
+               if (error != 0) {
+                       device_printf(sc->sc_dev, "unable to create dmamap "
+                           "for %s buffer %u, error %u\n",
+                           dd->dd_name, i, error);
+                       ath_descdma_cleanup(sc, dd, head);
+                       return error;
+               }
+               TAILQ_INSERT_TAIL(head, bf, bf_list);
+       }
+       return 0;
+fail3:
+       memset(dd, 0, sizeof(*dd));
+       return error;
+}
+
+void
+ath_descdma_cleanup(struct ath_softc *sc,
+       struct ath_descdma *dd, ath_bufhead *head)
+{
+       struct ath_buf *bf;
+       struct ieee80211_node *ni;
+       int do_warning = 0;
+
+       if (dd->dd_dmamap != 0) {
+               bus_dmamap_unload(dd->dd_dmat, dd->dd_dmamap);
+               bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
+               bus_dma_tag_destroy(dd->dd_dmat);
+       }
+
+       if (head != NULL) {
+               TAILQ_FOREACH(bf, head, bf_list) {
+                       if (bf->bf_m) {
+                               /*
+                                * XXX warn if there's buffers here.
+                                * XXX it should have been freed by the
+                                * owner!
+                                */
+                               
+                               if (do_warning == 0) {
+                                       do_warning = 1;
+                                       device_printf(sc->sc_dev,
+                                           "%s: %s: mbuf should've been"
+                                           " unmapped/freed!\n",
+                                           __func__,
+                                           dd->dd_name);
+                               }
+                               bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap,
+                                   BUS_DMASYNC_POSTREAD);
+                               bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap);
+                               m_freem(bf->bf_m);
+                               bf->bf_m = NULL;
+                       }
+                       if (bf->bf_dmamap != NULL) {
+                               bus_dmamap_destroy(sc->sc_dmat, bf->bf_dmamap);
+                               bf->bf_dmamap = NULL;
+                       }
+                       ni = bf->bf_node;
+                       bf->bf_node = NULL;
+                       if (ni != NULL) {
+                               /*
+                                * Reclaim node reference.
+                                */
+                               ieee80211_free_node(ni);
+                       }
+               }
+       }
+
+       if (head != NULL)
+               TAILQ_INIT(head);
+
+       if (dd->dd_bufptr != NULL)
+               free(dd->dd_bufptr, M_ATHDEV);
+       memset(dd, 0, sizeof(*dd));
+}
similarity index 68%
copy from sys/dev/netif/ath/ath/if_ath_keycache.h
copy to sys/dev/netif/ath/ath/if_ath_descdma.h
index 0b79e6f..d9c0a89 100644 (file)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2011 Sam Leffler, Errno Consulting
+ * Copyright (c) 2015 Adrian Chadd <adrian@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  *
  * $FreeBSD$
  */
+#ifndef        __IF_ATH_DESCDMA_H__
+#define        __IF_ATH_DESCDMA_H__
 
-#ifndef        __IF_ATH_CRYPTO_H__
-#define        __IF_ATH_CRYPTO_H__
-
-extern int ath_key_alloc(struct ieee80211vap *, struct ieee80211_key *,
-    ieee80211_keyix *, ieee80211_keyix *);
-extern int ath_key_delete(struct ieee80211vap *, const struct ieee80211_key *);
-extern int ath_key_set(struct ieee80211vap *, const struct ieee80211_key *,
-    const u_int8_t mac[IEEE80211_ADDR_LEN]);
-extern int ath_keyset(struct ath_softc *sc, struct ieee80211vap *vap,
-    const struct ieee80211_key *k, struct ieee80211_node *bss);
+extern  int ath_descdma_alloc_desc(struct ath_softc *sc,
+           struct ath_descdma *dd, ath_bufhead *head, const char *name,
+           int ds_size, int ndesc);
+extern  int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
+           ath_bufhead *head, const char *name, int ds_size, int nbuf,
+           int ndesc);
+extern  int ath_descdma_setup_rx_edma(struct ath_softc *sc,
+           struct ath_descdma *dd, ath_bufhead *head, const char *name,
+           int nbuf, int desclen);
+extern  void ath_descdma_cleanup(struct ath_softc *sc,
+           struct ath_descdma *dd, ath_bufhead *head);
 
 #endif
diff --git a/sys/dev/netif/ath/ath/if_ath_ioctl.c b/sys/dev/netif/ath/ath/if_ath_ioctl.c
new file mode 100644 (file)
index 0000000..1128c18
--- /dev/null
@@ -0,0 +1,307 @@
+/*-
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
+ * 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,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ *    redistribution must be conditioned upon including a substantially
+ *    similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Driver for the Atheros Wireless LAN controller.
+ *
+ * This software is derived from work of Atsushi Onoe; his contribution
+ * is greatly appreciated.
+ */
+
+#include "opt_inet.h"
+#include "opt_ath.h"
+/*
+ * This is needed for register operations which are performed
+ * by the driver - eg, calls to ath_hal_gettsf32().
+ *
+ * It's also required for any AH_DEBUG checks in here, eg the
+ * module dependencies.
+ */
+#include "opt_ah.h"
+#include "opt_wlan.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/sysctl.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/errno.h>
+#include <sys/callout.h>
+#include <sys/bus.h>
+#include <sys/endian.h>
+#include <sys/kthread.h>
+#include <sys/taskqueue.h>
+#include <sys/priv.h>
+#include <sys/module.h>
+#include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
+
+#include <machine/bus.h>
+
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+#include <net/if_arp.h>
+#include <net/ethernet.h>
+#include <net/if_llc.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
+#ifdef IEEE80211_SUPPORT_SUPERG
+#include <net80211/ieee80211_superg.h>
+#endif
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <net80211/ieee80211_tdma.h>
+#endif
+
+#include <net/bpf.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#endif
+
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
+
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_btcoex.h>
+#include <dev/ath/if_ath_spectral.h>
+#include <dev/ath/if_ath_lna_div.h>
+#include <dev/ath/if_athdfs.h>
+
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <dev/ath/if_ath_tdma.h>
+#endif
+
+#include <dev/ath/if_ath_ioctl.h>
+
+/*
+ * ioctl() related pieces.
+ *
+ * Some subsystems (eg spectral, dfs) have their own ioctl method which
+ * we call.
+ */
+
+/*
+ * Fetch the rate control statistics for the given node.
+ */
+static int
+ath_ioctl_ratestats(struct ath_softc *sc, struct ath_rateioctl *rs)
+{
+       struct ath_node *an;
+       struct ieee80211com *ic = &sc->sc_ic;
+       struct ieee80211_node *ni;
+       int error = 0;
+
+       /* Perform a lookup on the given node */
+       ni = ieee80211_find_node(&ic->ic_sta, rs->is_u.macaddr);
+       if (ni == NULL) {
+               error = EINVAL;
+               goto bad;
+       }
+
+       /* Lock the ath_node */
+       an = ATH_NODE(ni);
+       ATH_NODE_LOCK(an);
+
+       /* Fetch the rate control stats for this node */
+       error = ath_rate_fetch_node_stats(sc, an, rs);
+
+       /* No matter what happens here, just drop through */
+
+       /* Unlock the ath_node */
+       ATH_NODE_UNLOCK(an);
+
+       /* Unref the node */
+       ieee80211_node_decref(ni);
+
+bad:
+       return (error);
+}
+
+#ifdef ATH_DIAGAPI
+/*
+ * Diagnostic interface to the HAL.  This is used by various
+ * tools to do things like retrieve register contents for
+ * debugging.  The mechanism is intentionally opaque so that
+ * it can change frequently w/o concern for compatibility.
+ */
+static int
+ath_ioctl_diag(struct ath_softc *sc, struct ath_diag *ad)
+{
+       struct ath_hal *ah = sc->sc_ah;
+       u_int id = ad->ad_id & ATH_DIAG_ID;
+       void *indata = NULL;
+       void *outdata = NULL;
+       u_int32_t insize = ad->ad_in_size;
+       u_int32_t outsize = ad->ad_out_size;
+       int error = 0;
+
+       if (ad->ad_id & ATH_DIAG_IN) {
+               /*
+                * Copy in data.
+                */
+               indata = malloc(insize, M_TEMP, M_NOWAIT);
+               if (indata == NULL) {
+                       error = ENOMEM;
+                       goto bad;
+               }
+               error = copyin(ad->ad_in_data, indata, insize);
+               if (error)
+                       goto bad;
+       }
+       if (ad->ad_id & ATH_DIAG_DYN) {
+               /*
+                * Allocate a buffer for the results (otherwise the HAL
+                * returns a pointer to a buffer where we can read the
+                * results).  Note that we depend on the HAL leaving this
+                * pointer for us to use below in reclaiming the buffer;
+                * may want to be more defensive.
+                */
+               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
+               if (outdata == NULL) {
+                       error = ENOMEM;
+                       goto bad;
+               }
+       }
+
+
+       ATH_LOCK(sc);
+       if (id != HAL_DIAG_REGS)
+               ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
+       if (ath_hal_getdiagstate(ah, id, indata, insize, &outdata, &outsize)) {
+               if (outsize < ad->ad_out_size)
+                       ad->ad_out_size = outsize;
+               if (outdata != NULL)
+                       error = copyout(outdata, ad->ad_out_data,
+                                       ad->ad_out_size);
+       } else {
+               error = EINVAL;
+       }
+
+       ATH_LOCK(sc);
+       if (id != HAL_DIAG_REGS)
+               ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+bad:
+       if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
+               free(indata, M_TEMP);
+       if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
+               free(outdata, M_TEMP);
+       return error;
+}
+#endif /* ATH_DIAGAPI */
+
+int
+ath_ioctl(struct ieee80211com *ic, u_long cmd, void *data)
+{
+       struct ifreq *ifr = data;
+       struct ath_softc *sc = ic->ic_softc;
+
+       switch (cmd) {
+       case SIOCGATHSTATS: {
+               struct ieee80211vap *vap;
+               struct ifnet *ifp;
+               const HAL_RATE_TABLE *rt;
+
+               /* NB: embed these numbers to get a consistent view */
+               sc->sc_stats.ast_tx_packets = 0;
+               sc->sc_stats.ast_rx_packets = 0;
+               TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
+                       ifp = vap->iv_ifp;
+                       sc->sc_stats.ast_tx_packets += ifp->if_get_counter(ifp,
+                           IFCOUNTER_OPACKETS);
+                       sc->sc_stats.ast_rx_packets += ifp->if_get_counter(ifp,
+                           IFCOUNTER_IPACKETS);
+               }
+               sc->sc_stats.ast_tx_rssi = ATH_RSSI(sc->sc_halstats.ns_avgtxrssi);
+               sc->sc_stats.ast_rx_rssi = ATH_RSSI(sc->sc_halstats.ns_avgrssi);
+#ifdef IEEE80211_SUPPORT_TDMA
+               sc->sc_stats.ast_tdma_tsfadjp = TDMA_AVG(sc->sc_avgtsfdeltap);
+               sc->sc_stats.ast_tdma_tsfadjm = TDMA_AVG(sc->sc_avgtsfdeltam);
+#endif
+               rt = sc->sc_currates;
+               sc->sc_stats.ast_tx_rate =
+                   rt->info[sc->sc_txrix].dot11Rate &~ IEEE80211_RATE_BASIC;
+               if (rt->info[sc->sc_txrix].phy & IEEE80211_T_HT)
+                       sc->sc_stats.ast_tx_rate |= IEEE80211_RATE_MCS;
+               return copyout(&sc->sc_stats,
+                   ifr->ifr_data, sizeof (sc->sc_stats));
+       }
+       case SIOCGATHAGSTATS:
+               return copyout(&sc->sc_aggr_stats,
+                   ifr->ifr_data, sizeof (sc->sc_aggr_stats));
+       case SIOCZATHSTATS: {
+               int error;
+
+               error = priv_check(curthread, PRIV_DRIVER);
+               if (error == 0) {
+                       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));
+               }
+               return (error);
+       }
+#ifdef ATH_DIAGAPI
+       case SIOCGATHDIAG:
+               return (ath_ioctl_diag(sc, data));
+       case SIOCGATHPHYERR:
+               return (ath_ioctl_phyerr(sc, data));
+#endif
+       case SIOCGATHSPECTRAL:
+               return (ath_ioctl_spectral(sc, data));
+       case SIOCGATHNODERATESTATS:
+               return (ath_ioctl_ratestats(sc, data));
+       default:
+               /*
+                * This signals the net80211 layer that we didn't handle this
+                * ioctl.
+                */
+               return (ENOTTY);
+       }
+}
+
similarity index 72%
copy from sys/dev/netif/ath/ath/if_ath_keycache.h
copy to sys/dev/netif/ath/ath/if_ath_ioctl.h
index 0b79e6f..efbe2a3 100644 (file)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2011 Sam Leffler, Errno Consulting
+ * Copyright (c) 2015 Adrian Chadd <adrian@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  *
  * $FreeBSD$
  */
+#ifndef        __IF_ATH_IOCTL_H__
+#define        __IF_ATH_IOCTL_H__
 
-#ifndef        __IF_ATH_CRYPTO_H__
-#define        __IF_ATH_CRYPTO_H__
-
-extern int ath_key_alloc(struct ieee80211vap *, struct ieee80211_key *,
-    ieee80211_keyix *, ieee80211_keyix *);
-extern int ath_key_delete(struct ieee80211vap *, const struct ieee80211_key *);
-extern int ath_key_set(struct ieee80211vap *, const struct ieee80211_key *,
-    const u_int8_t mac[IEEE80211_ADDR_LEN]);
-extern int ath_keyset(struct ath_softc *sc, struct ieee80211vap *vap,
-    const struct ieee80211_key *k, struct ieee80211_node *bss);
+extern int ath_ioctl(struct ieee80211com *ic, u_long cmd, void *data);
 
 #endif
index 35a4c55..ff1df84 100644 (file)
@@ -59,6 +59,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/taskqueue.h>
 #include <sys/priv.h>
 
+#include <machine/bus.h>
+
 #include <net/if.h>
 #include <net/if_var.h>
 #include <net/if_dl.h>
@@ -68,15 +70,15 @@ __FBSDID("$FreeBSD$");
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 
-#include <netproto/802_11/ieee80211_var.h>
+#include <net80211/ieee80211_var.h>
 
 #include <net/bpf.h>
 
-#include <dev/netif/ath/ath/if_athvar.h>
+#include <dev/ath/if_athvar.h>
 
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_keycache.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_keycache.h>
+#include <dev/ath/if_ath_misc.h>
 
 #ifdef ATH_DEBUG
 static void
@@ -93,21 +95,21 @@ ath_keyprint(struct ath_softc *sc, const char *tag, u_int ix,
        };
        int i, n;
 
-       kprintf("%s: [%02u] %-7s ", tag, ix, ciphers[hk->kv_type]);
+       printf("%s: [%02u] %-7s ", tag, ix, ciphers[hk->kv_type]);
        for (i = 0, n = hk->kv_len; i < n; i++)
-               kprintf("%02x", hk->kv_val[i]);
-       kprintf(" mac %s", ether_sprintf(mac));
+               printf("%02x", hk->kv_val[i]);
+       printf(" mac %s", ether_sprintf(mac));
        if (hk->kv_type == HAL_CIPHER_TKIP) {
-               kprintf(" %s ", sc->sc_splitmic ? "mic" : "rxmic");
+               printf(" %s ", sc->sc_splitmic ? "mic" : "rxmic");
                for (i = 0; i < sizeof(hk->kv_mic); i++)
-                       kprintf("%02x", hk->kv_mic[i]);
+                       printf("%02x", hk->kv_mic[i]);
                if (!sc->sc_splitmic) {
-                       kprintf(" txmic ");
+                       printf(" txmic ");
                        for (i = 0; i < sizeof(hk->kv_txmic); i++)
-                               kprintf("%02x", hk->kv_txmic[i]);
+                               printf("%02x", hk->kv_txmic[i]);
                }
        }
-       kprintf("\n");
+       printf("\n");
 }
 #endif
 
@@ -182,7 +184,6 @@ ath_keyset(struct ath_softc *sc, struct ieee80211vap *vap,
        const struct ieee80211_key *k,
        struct ieee80211_node *bss)
 {
-#define        N(a)    (sizeof(a)/sizeof(a[0]))
        static const u_int8_t ciphermap[] = {
                HAL_CIPHER_WEP,         /* IEEE80211_CIPHER_WEP */
                HAL_CIPHER_TKIP,        /* IEEE80211_CIPHER_TKIP */
@@ -206,7 +207,7 @@ ath_keyset(struct ath_softc *sc, struct ieee80211vap *vap,
         * so that rx frames have an entry to match.
         */
        if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) == 0) {
-               KASSERT(cip->ic_cipher < N(ciphermap),
+               KASSERT(cip->ic_cipher < nitems(ciphermap),
                        ("invalid cipher type %u", cip->ic_cipher));
                hk.kv_type = ciphermap[cip->ic_cipher];
                hk.kv_len = k->wk_keylen;
@@ -264,7 +265,6 @@ ath_keyset(struct ath_softc *sc, struct ieee80211vap *vap,
        ATH_UNLOCK(sc);
 
        return (ret);
-#undef N
 }
 
 /*
@@ -275,12 +275,11 @@ static u_int16_t
 key_alloc_2pair(struct ath_softc *sc,
        ieee80211_keyix *txkeyix, ieee80211_keyix *rxkeyix)
 {
-#define        N(a)    (sizeof(a)/sizeof(a[0]))
        u_int i, keyix;
 
        KASSERT(sc->sc_splitmic, ("key cache !split"));
        /* XXX could optimize */
-       for (i = 0; i < N(sc->sc_keymap)/4; i++) {
+       for (i = 0; i < nitems(sc->sc_keymap)/4; i++) {
                u_int8_t b = sc->sc_keymap[i];
                if (b != 0xff) {
                        /*
@@ -319,7 +318,6 @@ key_alloc_2pair(struct ath_softc *sc,
        }
        DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of pair space\n", __func__);
        return 0;
-#undef N
 }
 
 /*
@@ -330,12 +328,11 @@ static u_int16_t
 key_alloc_pair(struct ath_softc *sc,
        ieee80211_keyix *txkeyix, ieee80211_keyix *rxkeyix)
 {
-#define        N(a)    (sizeof(a)/sizeof(a[0]))
        u_int i, keyix;
 
        KASSERT(!sc->sc_splitmic, ("key cache split"));
        /* XXX could optimize */
-       for (i = 0; i < N(sc->sc_keymap)/4; i++) {
+       for (i = 0; i < nitems(sc->sc_keymap)/4; i++) {
                u_int8_t b = sc->sc_keymap[i];
                if (b != 0xff) {
                        /*
@@ -367,7 +364,6 @@ key_alloc_pair(struct ath_softc *sc,
        }
        DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of pair space\n", __func__);
        return 0;
-#undef N
 }
 
 /*
@@ -377,7 +373,6 @@ static int
 key_alloc_single(struct ath_softc *sc,
        ieee80211_keyix *txkeyix, ieee80211_keyix *rxkeyix)
 {
-#define        N(a)    (sizeof(a)/sizeof(a[0]))
        u_int i, keyix;
 
        if (sc->sc_hasclrkey == 0) {
@@ -389,7 +384,7 @@ key_alloc_single(struct ath_softc *sc,
        }
 
        /* XXX try i,i+32,i+64,i+32+64 to minimize key pair conflicts */
-       for (i = 0; i < N(sc->sc_keymap); i++) {
+       for (i = 0; i < nitems(sc->sc_keymap); i++) {
                u_int8_t b = sc->sc_keymap[i];
                if (b != 0xff) {
                        /*
@@ -407,7 +402,6 @@ key_alloc_single(struct ath_softc *sc,
        }
        DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s: out of space\n", __func__);
        return 0;
-#undef N
 }
 
 /*
@@ -533,8 +527,7 @@ ath_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
  * slot(s) must already have been allocated by ath_key_alloc.
  */
 int
-ath_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k,
-       const u_int8_t mac[IEEE80211_ADDR_LEN])
+ath_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k)
 {
        struct ath_softc *sc = vap->iv_ic->ic_softc;
 
index 0b79e6f..c67e555 100644 (file)
@@ -35,8 +35,7 @@
 extern int ath_key_alloc(struct ieee80211vap *, struct ieee80211_key *,
     ieee80211_keyix *, ieee80211_keyix *);
 extern int ath_key_delete(struct ieee80211vap *, const struct ieee80211_key *);
-extern int ath_key_set(struct ieee80211vap *, const struct ieee80211_key *,
-    const u_int8_t mac[IEEE80211_ADDR_LEN]);
+extern int ath_key_set(struct ieee80211vap *, const struct ieee80211_key *);
 extern int ath_keyset(struct ath_softc *sc, struct ieee80211vap *vap,
     const struct ieee80211_key *k, struct ieee80211_node *bss);
 
index e616d4a..a55e036 100644 (file)
@@ -65,6 +65,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/module.h>
 #include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
+
+#include <machine/bus.h>
 
 #include <net/if.h>
 #include <net/if_dl.h>
@@ -74,13 +77,13 @@ __FBSDID("$FreeBSD$");
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 
-#include <netproto/802_11/ieee80211_var.h>
-#include <netproto/802_11/ieee80211_regdomain.h>
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
 
 #include <net/bpf.h>
@@ -90,14 +93,14 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
 
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
 
-#include <dev/netif/ath/ath/if_ath_led.h>
+#include <dev/ath/if_ath_led.h>
 
 /*
  * Software LED driver routines.
index 8cbb4e9..5c102fb 100644 (file)
@@ -48,6 +48,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/errno.h>
 
+#include <machine/bus.h>
+#include <machine/resource.h>
 #include <sys/bus.h>
 
 #include <sys/socket.h>
@@ -58,7 +60,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_arp.h>
 #include <net/ethernet.h>              /* XXX for ether_sprintf */
 
-#include <netproto/802_11/ieee80211_var.h>
+#include <net80211/ieee80211_var.h>
 
 #include <net/bpf.h>
 
@@ -67,11 +69,11 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#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/ath/if_athvar.h>
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_lna_div.h>
 
-/* Linux compability macros */
+/* Linux compatibility macros */
 /*
  * XXX these don't handle rounding, underflow, overflow, wrapping!
  */
@@ -94,8 +96,8 @@ ath_lna_div_attach(struct ath_softc *sc)
        if (! ath_hal_hasdivantcomb(sc->sc_ah))
                return (0);
 
-       ss = kmalloc(sizeof(struct if_ath_ant_comb_state),
-                    M_TEMP, M_WAITOK | M_ZERO);
+       ss = malloc(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__);
@@ -129,7 +131,7 @@ int
 ath_lna_div_detach(struct ath_softc *sc)
 {
        if (sc->sc_lna_div != NULL) {
-               kfree(sc->sc_lna_div, M_TEMP);
+               free(sc->sc_lna_div, M_TEMP);
                sc->sc_lna_div = NULL;
        }
        sc->sc_dolnadiv = 0;
@@ -168,7 +170,7 @@ ath_lna_div_ioctl(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
-               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
+               indata = malloc(insize, M_TEMP, M_NOWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -185,7 +187,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.
                 */
-               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
+               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -201,9 +203,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)
-               kfree(indata, M_TEMP);
+               free(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               kfree(outdata, M_TEMP);
+               free(outdata, M_TEMP);
        return (error);
 }
 
@@ -764,7 +766,7 @@ ath_lna_rx_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs,
 
        /* Short scan check */
        if (antcomb->scan && antcomb->alt_good) {
-               if (time_after(ticks, antcomb->scan_start_time +
+               if (ieee80211_time_after(ticks, antcomb->scan_start_time +
                    msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
                        short_scan = AH_TRUE;
                else
index 4632976..fbc4d67 100644 (file)
  * and into something else.
  */
 
-/* unaligned little endian access */
-#define LE_READ_2(p)                                                   \
-       ((u_int16_t)                                                    \
-        ((((u_int8_t *)(p))[0]      ) | (((u_int8_t *)(p))[1] <<  8)))
-#define LE_READ_4(p)                                                   \
-       ((u_int32_t)                                                    \
-        ((((u_int8_t *)(p))[0]      ) | (((u_int8_t *)(p))[1] <<  8) | \
-         (((u_int8_t *)(p))[2] << 16) | (((u_int8_t *)(p))[3] << 24)))
-
 extern int ath_rxbuf;
 extern int ath_txbuf;
 extern int ath_txbuf_mgmt;
@@ -65,7 +56,7 @@ extern void ath_freebuf(struct ath_softc *sc, struct ath_buf *bf);
 extern void ath_returnbuf_head(struct ath_softc *sc, struct ath_buf *bf);
 extern void ath_returnbuf_tail(struct ath_softc *sc, struct ath_buf *bf);
 
-extern int ath_reset(struct ifnet *, ATH_RESET_TYPE);
+extern int ath_reset(struct ath_softc *, ATH_RESET_TYPE);
 extern void ath_tx_default_comp(struct ath_softc *sc, struct ath_buf *bf,
            int fail);
 extern void ath_tx_update_ratectrl(struct ath_softc *sc,
@@ -88,18 +79,6 @@ extern void ath_setdefantenna(struct ath_softc *sc, u_int antenna);
 
 extern void ath_setslottime(struct ath_softc *sc);
 
-extern int ath_descdma_alloc_desc(struct ath_softc *sc,
-           struct ath_descdma *dd, ath_bufhead *head, const char *name,
-           int ds_size, int ndesc);
-extern int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
-           ath_bufhead *head, const char *name, int ds_size, int nbuf,
-           int ndesc);
-extern int ath_descdma_setup_rx_edma(struct ath_softc *sc,
-           struct ath_descdma *dd, ath_bufhead *head, const char *name,
-           int nbuf, int desclen);
-extern void ath_descdma_cleanup(struct ath_softc *sc,
-           struct ath_descdma *dd, ath_bufhead *head);
-
 extern void ath_legacy_attach_comp_func(struct ath_softc *sc);
 
 extern void ath_tx_draintxq(struct ath_softc *sc, struct ath_txq *txq);
@@ -122,6 +101,7 @@ extern      void ath_tx_update_tim(struct ath_softc *sc,
  * if_ath.c and do the ath_start() call there.  Once that's done,
  * we can kill this.
  */
+extern void ath_start(struct ifnet *ifp);
 extern void ath_start_task(void *arg, int npending);
 
 extern void ath_tx_dump(struct ath_softc *sc, struct ath_txq *txq);
index 860b9c7..88cbaff 100644 (file)
@@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/errno.h>
 
+#include <machine/bus.h>
+#include <machine/resource.h>
 #include <sys/bus.h>
 #include <sys/rman.h>
 
@@ -54,22 +56,13 @@ __FBSDID("$FreeBSD$");
 #include <net/if_arp.h>
 #include <net/ethernet.h>
 
-#include <netproto/802_11/ieee80211_var.h>
+#include <net80211/ieee80211_var.h>
 
-#include <dev/netif/ath/ath/if_athvar.h>
-
-#if defined(__DragonFly__)
-
-#include <bus/pci/pcivar.h>
-#include <bus/pci/pcireg.h>
-
-#else
+#include <dev/ath/if_athvar.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 
-#endif
-
 /* For EEPROM firmware */
 #ifdef ATH_EEPROM_FIRMWARE
 #include <sys/linker.h>
@@ -89,7 +82,7 @@ struct ath_pci_softc {
 
 /*
  * XXX eventually this should be some system level definition
- * so modules will hvae probe/attach information like USB.
+ * so modules will have probe/attach information like USB.
  * But for now..
  */
 struct pci_device_id {
@@ -286,6 +279,12 @@ ath_pci_attach(device_t dev)
         */
        sc->sc_invalid = 1;
 
+       ATH_LOCK_INIT(sc);
+       ATH_PCU_LOCK_INIT(sc);
+       ATH_RX_LOCK_INIT(sc);
+       ATH_TX_LOCK_INIT(sc);
+       ATH_TXSTATUS_LOCK_INIT(sc);
+
        /*
         * Arrange interrupt line.
         */
@@ -296,32 +295,18 @@ ath_pci_attach(device_t dev)
                device_printf(dev, "could not map interrupt\n");
                goto bad1;
        }
-#if defined(__DragonFly__)
-       if (bus_setup_intr(dev, psc->sc_irq,
-                          INTR_MPSAFE,
-                          ath_intr, sc, &psc->sc_ih,
-                          &wlan_global_serializer)) {
-               device_printf(dev, "could not establish interrupt\n");
-               goto bad2;
-       }
-#else
        if (bus_setup_intr(dev, psc->sc_irq,
                           INTR_TYPE_NET | INTR_MPSAFE,
                           NULL, ath_intr, sc, &psc->sc_ih)) {
                device_printf(dev, "could not establish interrupt\n");
                goto bad2;
        }
-#endif
 
        /*
         * Setup DMA descriptor area.
         */
        if (bus_dma_tag_create(bus_get_dma_tag(dev),    /* parent */
-#if defined(__DragonFly__)
-                              4, 0,                    /* alignment, bounds */
-#else
                               1, 0,                    /* alignment, bounds */
-#endif
                               BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
                               BUS_SPACE_MAXADDR,       /* highaddr */
                               NULL, NULL,              /* filter, filterarg */
@@ -329,10 +314,8 @@ ath_pci_attach(device_t dev)
                               ATH_MAX_SCATTER,         /* nsegments */
                               0x3ffff,                 /* maxsegsize XXX */
                               BUS_DMA_ALLOCNOW,        /* flags */
-#if !defined(__DragonFly__)
                               NULL,                    /* lockfunc */
                               NULL,                    /* lockarg */
-#endif
                               &sc->sc_dmat)) {
                device_printf(dev, "cannot allocate DMA tag\n");
                goto bad3;
@@ -352,40 +335,30 @@ ath_pci_attach(device_t dev)
                if (fw == NULL) {
                        device_printf(dev, "%s: couldn't find firmware\n",
                            __func__);
-                       goto bad3;
+                       goto bad4;
                }
 
                device_printf(dev, "%s: EEPROM firmware @ %p\n",
                    __func__, fw->data);
                sc->sc_eepromdata =
-                   kmalloc(fw->datasize, M_TEMP, M_WAITOK | M_ZERO);
+                   malloc(fw->datasize, M_TEMP, M_WAITOK | M_ZERO);
                if (! sc->sc_eepromdata) {
                        device_printf(dev, "%s: can't malloc eepromdata\n",
                            __func__);
-                       goto bad3;
+                       goto bad4;
                }
                memcpy(sc->sc_eepromdata, fw->data, fw->datasize);
                firmware_put(fw, 0);
        }
 #endif /* ATH_EEPROM_FIRMWARE */
 
-       ATH_LOCK_INIT(sc);
-       ATH_PCU_LOCK_INIT(sc);
-       ATH_RX_LOCK_INIT(sc);
-       ATH_TX_LOCK_INIT(sc);
-       ATH_TX_IC_LOCK_INIT(sc);
-       ATH_TXSTATUS_LOCK_INIT(sc);
-
        error = ath_attach(pci_get_device(dev), sc);
        if (error == 0)                                 /* success */
                return 0;
 
-       ATH_TXSTATUS_LOCK_DESTROY(sc);
-       ATH_PCU_LOCK_DESTROY(sc);
-       ATH_RX_LOCK_DESTROY(sc);
-       ATH_TX_IC_LOCK_DESTROY(sc);
-       ATH_TX_LOCK_DESTROY(sc);
-       ATH_LOCK_DESTROY(sc);
+#ifdef ATH_EEPROM_FIRMWARE
+bad4:
+#endif
        bus_dma_tag_destroy(sc->sc_dmat);
 bad3:
        bus_teardown_intr(dev, psc->sc_irq, psc->sc_ih);
@@ -393,6 +366,13 @@ bad2:
        bus_release_resource(dev, SYS_RES_IRQ, 0, psc->sc_irq);
 bad1:
        bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, psc->sc_sr);
+
+       ATH_TXSTATUS_LOCK_DESTROY(sc);
+       ATH_PCU_LOCK_DESTROY(sc);
+       ATH_RX_LOCK_DESTROY(sc);
+       ATH_TX_LOCK_DESTROY(sc);
+       ATH_LOCK_DESTROY(sc);
+
 bad:
        return (error);
 }
@@ -421,12 +401,11 @@ ath_pci_detach(device_t dev)
        bus_release_resource(dev, SYS_RES_MEMORY, BS_BAR, psc->sc_sr);
 
        if (sc->sc_eepromdata)
-               kfree(sc->sc_eepromdata, M_TEMP);
+               free(sc->sc_eepromdata, M_TEMP);
 
        ATH_TXSTATUS_LOCK_DESTROY(sc);
        ATH_PCU_LOCK_DESTROY(sc);
        ATH_RX_LOCK_DESTROY(sc);
-       ATH_TX_IC_LOCK_DESTROY(sc);
        ATH_TX_LOCK_DESTROY(sc);
        ATH_LOCK_DESTROY(sc);
 
@@ -484,7 +463,7 @@ static driver_t ath_pci_driver = {
        sizeof (struct ath_pci_softc)
 };
 static devclass_t ath_devclass;
-DRIVER_MODULE(ath_pci, pci, ath_pci_driver, ath_devclass, NULL, NULL);
+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 */
index 13b19ee..cacd8f8 100644 (file)
@@ -68,6 +68,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/module.h>
 #include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
+
+#include <machine/bus.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -77,15 +80,14 @@ __FBSDID("$FreeBSD$");
 #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 <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
 
 #include <net/bpf.h>
@@ -95,30 +97,31 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
-
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
-#include <dev/netif/ath/ath/if_ath_tsf.h>
-#include <dev/netif/ath/ath/if_ath_tx.h>
-#include <dev/netif/ath/ath/if_ath_sysctl.h>
-#include <dev/netif/ath/ath/if_ath_led.h>
-#include <dev/netif/ath/ath/if_ath_keycache.h>
-#include <dev/netif/ath/ath/if_ath_rx.h>
-#include <dev/netif/ath/ath/if_ath_beacon.h>
-#include <dev/netif/ath/ath/if_athdfs.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
+
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_tsf.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_sysctl.h>
+#include <dev/ath/if_ath_led.h>
+#include <dev/ath/if_ath_keycache.h>
+#include <dev/ath/if_ath_rx.h>
+#include <dev/ath/if_ath_beacon.h>
+#include <dev/ath/if_athdfs.h>
+#include <dev/ath/if_ath_descdma.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
 #ifdef ATH_DEBUG_ALQ
-#include <dev/netif/ath/ath/if_ath_alq.h>
+#include <dev/ath/if_ath_alq.h>
 #endif
 
-#include <dev/netif/ath/ath/if_ath_lna_div.h>
+#include <dev/ath/if_ath_lna_div.h>
 
 /*
  * Calculate the receive filter according to the
@@ -152,8 +155,7 @@ __FBSDID("$FreeBSD$");
 u_int32_t
 ath_calcrxfilter(struct ath_softc *sc)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        u_int32_t rfilt;
 
        rfilt = HAL_RX_FILTER_UCAST | HAL_RX_FILTER_BCAST | HAL_RX_FILTER_MCAST;
@@ -162,7 +164,7 @@ ath_calcrxfilter(struct ath_softc *sc)
        if (ic->ic_opmode != IEEE80211_M_STA)
                rfilt |= HAL_RX_FILTER_PROBEREQ;
        /* XXX ic->ic_monvaps != 0? */
-       if (ic->ic_opmode == IEEE80211_M_MONITOR || (ifp->if_flags & IFF_PROMISC))
+       if (ic->ic_opmode == IEEE80211_M_MONITOR || ic->ic_promisc > 0)
                rfilt |= HAL_RX_FILTER_PROM;
 
        /*
@@ -170,9 +172,14 @@ ath_calcrxfilter(struct ath_softc *sc)
         *
         * Otherwise we only really need to hear beacons from
         * our own BSSID.
+        *
+        * IBSS? software beacon miss? Just receive all beacons.
+        * We need to hear beacons/probe requests from everyone so
+        * we can merge ibss.
         */
-       if (ic->ic_opmode == IEEE80211_M_STA ||
-           ic->ic_opmode == IEEE80211_M_IBSS || sc->sc_swbmiss) {
+       if (ic->ic_opmode == IEEE80211_M_IBSS || sc->sc_swbmiss) {
+               rfilt |= HAL_RX_FILTER_BEACON;
+       } else if (ic->ic_opmode == IEEE80211_M_STA) {
                if (sc->sc_do_mybeacon && ! sc->sc_scanning) {
                        rfilt |= HAL_RX_FILTER_MYBEACON;
                } else { /* scanning, non-mybeacon chips */
@@ -230,8 +237,8 @@ ath_calcrxfilter(struct ath_softc *sc)
        if (sc->sc_dospectral)
                rfilt |= HAL_RX_FILTER_PHYRADAR;
 
-       DPRINTF(sc, ATH_DEBUG_MODE, "%s: RX filter 0x%x, %s if_flags 0x%x\n",
-           __func__, rfilt, ieee80211_opmode_name[ic->ic_opmode], ifp->if_flags);
+       DPRINTF(sc, ATH_DEBUG_MODE, "%s: RX filter 0x%x, %s\n",
+           __func__, rfilt, ieee80211_opmode_name[ic->ic_opmode]);
        return rfilt;
 }
 
@@ -263,17 +270,10 @@ ath_legacy_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
                }
                m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
 
-#if defined(__DragonFly__)
-               error = bus_dmamap_load_mbuf_segment(sc->sc_dmat,
-                                            bf->bf_dmamap, m,
-                                            bf->bf_segs, 1, &bf->bf_nseg,
-                                            BUS_DMA_NOWAIT);
-#else
                error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
                                             bf->bf_dmamap, m,
                                             bf->bf_segs, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
-#endif
                if (error != 0) {
                        DPRINTF(sc, ATH_DEBUG_ANY,
                            "%s: bus_dmamap_load_mbuf_sg failed; error %d\n",
@@ -344,8 +344,8 @@ ath_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m,
        uint64_t tsf_beacon_target;
        int tsf_intval;
 
-       tsf_beacon_old = ((uint64_t) LE_READ_4(ni->ni_tstamp.data + 4)) << 32;
-       tsf_beacon_old |= LE_READ_4(ni->ni_tstamp.data);
+       tsf_beacon_old = ((uint64_t) le32dec(ni->ni_tstamp.data + 4)) << 32;
+       tsf_beacon_old |= le32dec(ni->ni_tstamp.data);
 
 #define        TU_TO_TSF(_tu)  (((u_int64_t)(_tu)) << 10)
        tsf_intval = 1;
@@ -361,86 +361,102 @@ ath_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m,
        ATH_VAP(vap)->av_recv_mgmt(ni, m, subtype, rxs, rssi, nf);
        switch (subtype) {
        case IEEE80211_FC0_SUBTYPE_BEACON:
-               /* update rssi statistics for use by the hal */
-               /* XXX unlocked check against vap->iv_bss? */
-               ATH_RSSI_LPF(sc->sc_halstats.ns_avgbrssi, rssi);
-
-               tsf_beacon = ((uint64_t) LE_READ_4(ni->ni_tstamp.data + 4)) << 32;
-               tsf_beacon |= LE_READ_4(ni->ni_tstamp.data);
-
-               nexttbtt = ath_hal_getnexttbtt(sc->sc_ah);
 
                /*
-                * Let's calculate the delta and remainder, so we can see
-                * if the beacon timer from the AP is varying by more than
-                * a few TU.  (Which would be a huge, huge problem.)
+                * Only do the following processing if it's for
+                * the current BSS.
+                *
+                * In scan and IBSS mode we receive all beacons,
+                * which means we need to filter out stuff
+                * that isn't for us or we'll end up constantly
+                * trying to sync / merge to BSSes that aren't
+                * actually us.
                 */
-               tsf_delta = (long long) tsf_beacon - (long long) tsf_beacon_old;
+               if (IEEE80211_ADDR_EQ(ni->ni_bssid, vap->iv_bss->ni_bssid)) {
+                       /* update rssi statistics for use by the hal */
+                       /* XXX unlocked check against vap->iv_bss? */
+                       ATH_RSSI_LPF(sc->sc_halstats.ns_avgbrssi, rssi);
 
-               tsf_delta_bmiss = tsf_delta / tsf_intval;
 
-               /*
-                * If our delta is greater than half the beacon interval,
-                * let's round the bmiss value up to the next beacon
-                * interval.  Ie, we're running really, really early
-                * on the next beacon.
-                */
-               if (tsf_delta % tsf_intval > (tsf_intval / 2))
-                       tsf_delta_bmiss ++;
+                       tsf_beacon = ((uint64_t) le32dec(ni->ni_tstamp.data + 4)) << 32;
+                       tsf_beacon |= le32dec(ni->ni_tstamp.data);
 
-               tsf_beacon_target = tsf_beacon_old +
-                   (((unsigned long long) tsf_delta_bmiss) * (long long) tsf_intval);
+                       nexttbtt = ath_hal_getnexttbtt(sc->sc_ah);
 
-               /*
-                * The remainder using '%' is between 0 .. intval-1.
-                * If we're actually running too fast, then the remainder
-                * will be some large number just under intval-1.
-                * So we need to look at whether we're running
-                * before or after the target beacon interval
-                * and if we are, modify how we do the remainder
-                * calculation.
-                */
-               if (tsf_beacon < tsf_beacon_target) {
-                       tsf_remainder =
-                           -(tsf_intval - ((tsf_beacon - tsf_beacon_old) % tsf_intval));
-               } else {
-                       tsf_remainder = (tsf_beacon - tsf_beacon_old) % tsf_intval;
-               }
+                       /*
+                        * Let's calculate the delta and remainder, so we can see
+                        * if the beacon timer from the AP is varying by more than
+                        * a few TU.  (Which would be a huge, huge problem.)
+                        */
+                       tsf_delta = (long long) tsf_beacon - (long long) tsf_beacon_old;
+
+                       tsf_delta_bmiss = tsf_delta / tsf_intval;
 
-               DPRINTF(sc, ATH_DEBUG_BEACON, "%s: old_tsf=%llu, new_tsf=%llu, target_tsf=%llu, delta=%lld, bmiss=%d, remainder=%d\n",
-                   __func__,
-                   (unsigned long long) tsf_beacon_old,
-                   (unsigned long long) tsf_beacon,
-                   (unsigned long long) tsf_beacon_target,
-                   (long long) tsf_delta,
-                   tsf_delta_bmiss,
-                   tsf_remainder);
-
-               DPRINTF(sc, ATH_DEBUG_BEACON, "%s: tsf=%llu, nexttbtt=%llu, delta=%d\n",
-                   __func__,
-                   (unsigned long long) tsf_beacon,
-                   (unsigned long long) nexttbtt,
-                   (int32_t) tsf_beacon - (int32_t) nexttbtt + tsf_intval);
-
-               if (sc->sc_syncbeacon &&
-                   ni == vap->iv_bss &&
-                   (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)) {
-                       DPRINTF(sc, ATH_DEBUG_BEACON,
-                           "%s: syncbeacon=1; syncing\n",
-                           __func__);
                        /*
-                        * Resync beacon timers using the tsf of the beacon
-                        * frame we just received.
+                        * If our delta is greater than half the beacon interval,
+                        * let's round the bmiss value up to the next beacon
+                        * interval.  Ie, we're running really, really early
+                        * on the next beacon.
                         */
-                       ath_beacon_config(sc, vap);
-                       sc->sc_syncbeacon = 0;
-               }
+                       if (tsf_delta % tsf_intval > (tsf_intval / 2))
+                               tsf_delta_bmiss ++;
+
+                       tsf_beacon_target = tsf_beacon_old +
+                           (((unsigned long long) tsf_delta_bmiss) * (long long) tsf_intval);
+
+                       /*
+                        * The remainder using '%' is between 0 .. intval-1.
+                        * If we're actually running too fast, then the remainder
+                        * will be some large number just under intval-1.
+                        * So we need to look at whether we're running
+                        * before or after the target beacon interval
+                        * and if we are, modify how we do the remainder
+                        * calculation.
+                        */
+                       if (tsf_beacon < tsf_beacon_target) {
+                               tsf_remainder =
+                                   -(tsf_intval - ((tsf_beacon - tsf_beacon_old) % tsf_intval));
+                       } else {
+                               tsf_remainder = (tsf_beacon - tsf_beacon_old) % tsf_intval;
+                       }
 
+                       DPRINTF(sc, ATH_DEBUG_BEACON, "%s: old_tsf=%llu, new_tsf=%llu, target_tsf=%llu, delta=%lld, bmiss=%d, remainder=%d\n",
+                           __func__,
+                           (unsigned long long) tsf_beacon_old,
+                           (unsigned long long) tsf_beacon,
+                           (unsigned long long) tsf_beacon_target,
+                           (long long) tsf_delta,
+                           tsf_delta_bmiss,
+                           tsf_remainder);
+
+                       DPRINTF(sc, ATH_DEBUG_BEACON, "%s: tsf=%llu, nexttbtt=%llu, delta=%d\n",
+                           __func__,
+                           (unsigned long long) tsf_beacon,
+                           (unsigned long long) nexttbtt,
+                           (int32_t) tsf_beacon - (int32_t) nexttbtt + tsf_intval);
+
+                       /* We only do syncbeacon on STA VAPs; not on IBSS */
+                       if (vap->iv_opmode == IEEE80211_M_STA &&
+                           sc->sc_syncbeacon &&
+                           ni == vap->iv_bss &&
+                           (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)) {
+                               DPRINTF(sc, ATH_DEBUG_BEACON,
+                                   "%s: syncbeacon=1; syncing\n",
+                                   __func__);
+                               /*
+                                * Resync beacon timers using the tsf of the beacon
+                                * frame we just received.
+                                */
+                               ath_beacon_config(sc, vap);
+                               sc->sc_syncbeacon = 0;
+                       }
+               }
 
                /* fall thru... */
        case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
                if (vap->iv_opmode == IEEE80211_M_IBSS &&
-                   vap->iv_state == IEEE80211_S_RUN) {
+                   vap->iv_state == IEEE80211_S_RUN &&
+                   ieee80211_ibss_merge_check(ni)) {
                        uint32_t rstamp = sc->sc_lastrs->rs_tstamp;
                        uint64_t tsf = ath_extend_tsf(sc, rstamp,
                                ath_hal_gettsf64(sc->sc_ah));
@@ -468,10 +484,9 @@ ath_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m,
 
 #ifdef ATH_ENABLE_RADIOTAP_VENDOR_EXT
 static void
-ath_rx_tap_vendor(struct ifnet *ifp, struct mbuf *m,
+ath_rx_tap_vendor(struct ath_softc *sc, struct mbuf *m,
     const struct ath_rx_status *rs, u_int64_t tsf, int16_t nf)
 {
-       struct ath_softc *sc = ifp->if_softc;
 
        /* Fill in the extension bitmap */
        sc->sc_rx_th.wr_ext_bitmap = htole32(1 << ATH_RADIOTAP_VENDOR_HEADER);
@@ -534,14 +549,13 @@ ath_rx_tap_vendor(struct ifnet *ifp, struct mbuf *m,
 #endif /* ATH_ENABLE_RADIOTAP_VENDOR_EXT */
 
 static void
-ath_rx_tap(struct ifnet *ifp, struct mbuf *m,
+ath_rx_tap(struct ath_softc *sc, struct mbuf *m,
        const struct ath_rx_status *rs, u_int64_t tsf, int16_t nf)
 {
 #define        CHAN_HT20       htole32(IEEE80211_CHAN_HT20)
 #define        CHAN_HT40U      htole32(IEEE80211_CHAN_HT40U)
 #define        CHAN_HT40D      htole32(IEEE80211_CHAN_HT40D)
 #define        CHAN_HT         (CHAN_HT20|CHAN_HT40U|CHAN_HT40D)
-       struct ath_softc *sc = ifp->if_softc;
        const HAL_RATE_TABLE *rt;
        uint8_t rix;
 
@@ -565,7 +579,7 @@ ath_rx_tap(struct ifnet *ifp, struct mbuf *m,
                else if (IEEE80211_IS_CHAN_HT20(sc->sc_curchan))
                        sc->sc_rx_th.wr_chan_flags |= CHAN_HT20;
        } else if (sc->sc_rx_th.wr_rate & IEEE80211_RATE_MCS) { /* HT rate */
-               struct ieee80211com *ic = ifp->if_l2com;
+               struct ieee80211com *ic = &sc->sc_ic;
 
                if ((rs->rs_flags & HAL_RX_2040) == 0)
                        sc->sc_rx_th.wr_chan_flags |= CHAN_HT20;
@@ -622,8 +636,7 @@ ath_rx_pkt(struct ath_softc *sc, struct ath_rx_status *rs, HAL_STATUS status,
 {
        uint64_t rstamp;
        int len, type;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ieee80211_node *ni;
        int is_good = 0;
        struct ath_rx_edma *re = &sc->sc_rxedma[qtype];
@@ -709,11 +722,7 @@ ath_rx_pkt(struct ath_softc *sc, struct ath_rx_status *rs, HAL_STATUS status,
                                        rs->rs_keyix-32 : rs->rs_keyix);
                        }
                }
-#if defined(__DragonFly__)
-               ++ifp->if_ierrors;
-#else
-               if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
-#endif
+               counter_u64_add(ic->ic_ierrors, 1);
 rx_error:
                /*
                 * Cleanup any pending partial frame.
@@ -733,9 +742,9 @@ rx_error:
                        /* NB: bpf needs the mbuf length setup */
                        len = rs->rs_datalen;
                        m->m_pkthdr.len = m->m_len = len;
-                       ath_rx_tap(ifp, m, rs, rstamp, nf);
+                       ath_rx_tap(sc, m, rs, rstamp, nf);
 #ifdef ATH_ENABLE_RADIOTAP_VENDOR_EXT
-                       ath_rx_tap_vendor(ifp, m, rs, rstamp, nf);
+                       ath_rx_tap_vendor(sc, m, rs, rstamp, nf);
 #endif /* ATH_ENABLE_RADIOTAP_VENDOR_EXT */
                        ieee80211_radiotap_rx_all(ic, m);
                }
@@ -758,7 +767,6 @@ rx_accept:
                        sc->sc_stats.ast_rx_toobig++;
                        m_freem(re->m_rxpending);
                }
-               m->m_pkthdr.rcvif = ifp;
                m->m_pkthdr.len = len;
                re->m_rxpending = m;
                m = NULL;
@@ -775,10 +783,8 @@ rx_accept:
                re->m_rxpending = NULL;
        } else {
                /*
-                * Normal single-descriptor receive; setup
-                * the rcvif and packet length.
+                * Normal single-descriptor receive; setup packet length.
                 */
-               m->m_pkthdr.rcvif = ifp;
                m->m_pkthdr.len = len;
        }
 
@@ -796,7 +802,7 @@ rx_accept:
         * This code should be removed once the actual
         * root cause of the issue has been identified.
         * For example, it may be that the rs_antenna
-        * field is only valid for the lsat frame of
+        * field is only valid for the last frame of
         * an aggregate and it just happens that it is
         * "mostly" right. (This is a general statement -
         * the majority of the statistics are only valid
@@ -839,11 +845,6 @@ rx_accept:
                        rs->rs_antenna |= 0x4;
        }
 
-#if defined(__DragonFly__)
-       ++ifp->if_ipackets;
-#else
-       if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
-#endif
        sc->sc_stats.ast_ant_rx[rs->rs_antenna]++;
 
        /*
@@ -854,9 +855,9 @@ rx_accept:
         * noise setting is filled in above.
         */
        if (ieee80211_radiotap_active(ic)) {
-               ath_rx_tap(ifp, m, rs, rstamp, nf);
+               ath_rx_tap(sc, m, rs, rstamp, nf);
 #ifdef ATH_ENABLE_RADIOTAP_VENDOR_EXT
-               ath_rx_tap_vendor(ifp, m, rs, rstamp, nf);
+               ath_rx_tap_vendor(sc, m, rs, rstamp, nf);
 #endif /* ATH_ENABLE_RADIOTAP_VENDOR_EXT */
        }
 
@@ -1004,10 +1005,9 @@ ath_rx_proc(struct ath_softc *sc, int resched)
        ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
                ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
        struct ath_buf *bf;
-       struct ifnet *ifp = sc->sc_ifp;
        struct ath_hal *ah = sc->sc_ah;
 #ifdef IEEE80211_SUPPORT_SUPERG
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
 #endif
        struct ath_desc *ds;
        struct ath_rx_status *rs;
@@ -1050,7 +1050,7 @@ ath_rx_proc(struct ath_softc *sc, int resched)
 
                bf = TAILQ_FIRST(&sc->sc_rxbuf);
                if (sc->sc_rxslink && bf == NULL) {     /* NB: shouldn't happen */
-                       if_printf(ifp, "%s: no buffer!\n", __func__);
+                       device_printf(sc->sc_dev, "%s: no buffer!\n", __func__);
                        break;
                } else if (bf == NULL) {
                        /*
@@ -1067,7 +1067,7 @@ ath_rx_proc(struct ath_softc *sc, int resched)
                         * will be no mbuf; try again to re-populate it.
                         */
                        /* XXX make debug msg */
-                       if_printf(ifp, "%s: no mbuf!\n", __func__);
+                       device_printf(sc->sc_dev, "%s: no mbuf!\n", __func__);
                        TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list);
                        goto rx_proc_next;
                }
@@ -1202,24 +1202,10 @@ rx_proc_next:
                ATH_PCU_UNLOCK(sc);
        }
 
-       /* XXX check this inside of IF_LOCK? */
-#if defined(__DragonFly__)
-       if (resched && !ifq_is_oactive(&ifp->if_snd)) {
-#else
-       if (resched && (ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
-#endif
 #ifdef IEEE80211_SUPPORT_SUPERG
+       if (resched)
                ieee80211_ff_age_all(ic, 100);
 #endif
-#if defined(__DragonFly__)
-               if (!ifq_is_empty(&ifp->if_snd))
-                       ath_tx_kick(sc);
-#else
-               if (!IFQ_IS_EMPTY(&ifp->if_snd))
-                       ath_tx_kick(sc);
-#endif
-       }
-#undef PA2DESC
 
        /*
         * Put the hardware to sleep again if we're done with it.
@@ -1241,7 +1227,7 @@ rx_proc_next:
        sc->sc_rxproc_cnt--;
        ATH_PCU_UNLOCK(sc);
 }
-
+#undef PA2DESC
 #undef ATH_RX_MAX
 
 /*
index cc7d06e..13e141c 100644 (file)
@@ -68,6 +68,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/module.h>
 #include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
+
+#include <machine/bus.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -77,15 +80,14 @@ __FBSDID("$FreeBSD$");
 #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 <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
 
 #include <net/bpf.h>
@@ -95,29 +97,30 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
-
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
-#include <dev/netif/ath/ath/if_ath_tsf.h>
-#include <dev/netif/ath/ath/if_ath_tx.h>
-#include <dev/netif/ath/ath/if_ath_sysctl.h>
-#include <dev/netif/ath/ath/if_ath_led.h>
-#include <dev/netif/ath/ath/if_ath_keycache.h>
-#include <dev/netif/ath/ath/if_ath_rx.h>
-#include <dev/netif/ath/ath/if_ath_beacon.h>
-#include <dev/netif/ath/ath/if_athdfs.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
+
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_tsf.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_sysctl.h>
+#include <dev/ath/if_ath_led.h>
+#include <dev/ath/if_ath_keycache.h>
+#include <dev/ath/if_ath_rx.h>
+#include <dev/ath/if_ath_beacon.h>
+#include <dev/ath/if_athdfs.h>
+#include <dev/ath/if_ath_descdma.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
-#include <dev/netif/ath/ath/if_ath_rx_edma.h>
+#include <dev/ath/if_ath_rx_edma.h>
 
 #ifdef ATH_DEBUG_ALQ
-#include <dev/netif/ath/ath/if_ath_alq.h>
+#include <dev/ath/if_ath_alq.h>
 #endif
 
 /*
@@ -577,9 +580,8 @@ static void
 ath_edma_recv_tasklet(void *arg, int npending)
 {
        struct ath_softc *sc = (struct ath_softc *) arg;
-       struct ifnet *ifp = sc->sc_ifp;
 #ifdef IEEE80211_SUPPORT_SUPERG
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
 #endif
 
        DPRINTF(sc, ATH_DEBUG_EDMA_RX, "%s: called; npending=%d\n",
@@ -615,23 +617,9 @@ ath_edma_recv_tasklet(void *arg, int npending)
        ath_power_restore_power_state(sc);
        ATH_UNLOCK(sc);
 
-       /* XXX inside IF_LOCK ? */
-#if defined(__DragonFly__)
-       if (!ifq_is_oactive(&ifp->if_snd)) {
-#else
-       if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
-#endif
 #ifdef IEEE80211_SUPPORT_SUPERG
-               ieee80211_ff_age_all(ic, 100);
-#endif
-#if defined(__DragonFly__)
-               if (! ifq_is_empty(&ifp->if_snd))
-                       ath_tx_kick(sc);
-#else
-               if (! IFQ_IS_EMPTY(&ifp->if_snd))
-                       ath_tx_kick(sc);
+       ieee80211_ff_age_all(ic, 100);
 #endif
-       }
        if (ath_dfs_tasklet_needed(sc, sc->sc_curchan))
                taskqueue_enqueue(sc->sc_tq, &sc->sc_dfstask);
 
@@ -658,11 +646,7 @@ ath_edma_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
 
        ATH_RX_LOCK_ASSERT(sc);
 
-#if defined(__DragonFly__)
-       m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, sc->sc_edma_bufsize);
-#else
        m = m_getm(NULL, sc->sc_edma_bufsize, M_NOWAIT, MT_DATA);
-#endif
        if (! m)
                return (ENOBUFS);               /* XXX ?*/
 
@@ -698,14 +682,8 @@ ath_edma_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf)
        /*
         * Create DMA mapping.
         */
-#if defined(__DragonFly__)
-       error = bus_dmamap_load_mbuf_segment(
-                               sc->sc_dmat, bf->bf_dmamap, m,
-                               bf->bf_segs, 1, &bf->bf_nseg, BUS_DMA_NOWAIT);
-#else
        error = bus_dmamap_load_mbuf_sg(sc->sc_dmat,
            bf->bf_dmamap, m, bf->bf_segs, &bf->bf_nseg, BUS_DMA_NOWAIT);
-#endif
 
        if (error != 0) {
                device_printf(sc->sc_dev, "%s: failed; error=%d\n",
@@ -921,8 +899,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_fifo = kmalloc(sizeof(struct ath_buf *) * re->m_fifolen,
-                            M_ATHDEV, M_INTWAIT | M_ZERO);
+       re->m_fifo = malloc(sizeof(struct ath_buf *) * re->m_fifolen,
+           M_ATHDEV,
+           M_NOWAIT | M_ZERO);
        if (re->m_fifo == NULL) {
                device_printf(sc->sc_dev, "%s: malloc failed\n",
                    __func__);
@@ -947,7 +926,7 @@ ath_edma_rxfifo_free(struct ath_softc *sc, HAL_RX_QUEUE qtype)
            __func__,
            qtype);
        
-       kfree(re->m_fifo, M_ATHDEV);
+       free(re->m_fifo, M_ATHDEV);
 
        return (0);
 }
index d3b24fc..e4afdae 100644 (file)
@@ -47,6 +47,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/errno.h>
 
+#include <machine/bus.h>
+#include <machine/resource.h>
 #include <sys/bus.h>
 
 #include <sys/socket.h>
@@ -57,7 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_arp.h>
 #include <net/ethernet.h>              /* XXX for ether_sprintf */
 
-#include <netproto/802_11/ieee80211_var.h>
+#include <net80211/ieee80211_var.h>
 
 #include <net/bpf.h>
 
@@ -66,10 +68,10 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath/if_ath_spectral.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/if_ath_spectral.h>
 
-#include <dev/netif/ath/ath_hal/ah_desc.h>
+#include <dev/ath/ath_hal/ah_desc.h>
 
 struct ath_spectral_state {
        HAL_SPECTRAL_PARAM      spectral_state;
@@ -109,7 +111,7 @@ ath_spectral_attach(struct ath_softc *sc)
        if (! ath_hal_spectral_supported(sc->sc_ah))
                return (0);
 
-       ss = kmalloc(sizeof(struct ath_spectral_state),
+       ss = malloc(sizeof(struct ath_spectral_state),
            M_TEMP, M_WAITOK | M_ZERO);
 
        if (ss == NULL) {
@@ -136,7 +138,7 @@ ath_spectral_detach(struct ath_softc *sc)
                return (0);
 
        if (sc->sc_spectral != NULL) {
-               kfree(sc->sc_spectral, M_TEMP);
+               free(sc->sc_spectral, M_TEMP);
        }
        return (0);
 }
@@ -193,7 +195,7 @@ ath_ioctl_spectral(struct ath_softc *sc, struct ath_diag *ad)
                /*
                 * Copy in data.
                 */
-               indata = kmalloc(insize, M_TEMP, M_INTWAIT);
+               indata = malloc(insize, M_TEMP, M_NOWAIT);
                if (indata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -210,7 +212,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.
                 */
-               outdata = kmalloc(outsize, M_TEMP, M_INTWAIT);
+               outdata = malloc(outsize, M_TEMP, M_NOWAIT);
                if (outdata == NULL) {
                        error = ENOMEM;
                        goto bad;
@@ -280,9 +282,9 @@ ath_ioctl_spectral(struct ath_softc *sc, struct ath_diag *ad)
                error = EFAULT;
 bad:
        if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
-               kfree(indata, M_TEMP);
+               free(indata, M_TEMP);
        if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
-               kfree(outdata, M_TEMP);
+               free(outdata, M_TEMP);
        return (error);
 }
 
index e9d143b..ab829df 100644 (file)
@@ -59,6 +59,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/taskqueue.h>
 #include <sys/priv.h>
 
+#include <machine/bus.h>
+
 #include <net/if.h>
 #include <net/if_var.h>
 #include <net/if_dl.h>
@@ -68,13 +70,13 @@ __FBSDID("$FreeBSD$");
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 
-#include <netproto/802_11/ieee80211_var.h>
-#include <netproto/802_11/ieee80211_regdomain.h>
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
 
 #include <net/bpf.h>
@@ -84,22 +86,22 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
 
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_led.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
-#include <dev/netif/ath/ath/if_ath_tx.h>
-#include <dev/netif/ath/ath/if_ath_sysctl.h>
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_led.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_sysctl.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
 #ifdef ATH_DEBUG_ALQ
-#include <dev/netif/ath/ath/if_ath_alq.h>
+#include <dev/ath/if_ath_alq.h>
 #endif
 
 static int
@@ -132,26 +134,52 @@ 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;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       acktimeout = ath_hal_getacktimeout(sc->sc_ah);
+       ATH_UNLOCK(sc);
+
        error = sysctl_handle_int(oidp, &acktimeout, 0, req);
        if (error || !req->newptr)
-               return error;
-       return !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0;
+               goto finish;
+
+       error = !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 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;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ctstimeout = ath_hal_getctstimeout(sc->sc_ah);
+       ATH_UNLOCK(sc);
+
        error = sysctl_handle_int(oidp, &ctstimeout, 0, req);
        if (error || !req->newptr)
-               return error;
-       return !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0;
+               goto finish;
+
+       error = !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
@@ -219,14 +247,22 @@ 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;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
+       txantenna = ath_hal_getantennaswitch(sc->sc_ah);
+
        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 finish;
+               }
                ath_hal_setantennaswitch(sc->sc_ah, txantenna);
                /*
                 * NB: with the switch locked this isn't meaningful,
@@ -235,36 +271,67 @@ ath_sysctl_txantenna(SYSCTL_HANDLER_ARGS)
                 */
                sc->sc_txantenna = txantenna;
        }
-       return error;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
 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;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       defantenna = ath_hal_getdefantenna(sc->sc_ah);
+       ATH_UNLOCK(sc);
+
        error = sysctl_handle_int(oidp, &defantenna, 0, req);
        if (!error && req->newptr)
                ath_hal_setdefantenna(sc->sc_ah, defantenna);
-       return error;
+
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
 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;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
+       diversity = ath_hal_getdiversity(sc->sc_ah);
+
        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 finish;
+       if (!ath_hal_setdiversity(sc->sc_ah, diversity)) {
+               error = EINVAL;
+               goto finish;
+       }
        sc->sc_diversity = diversity;
-       return 0;
+       error = 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
@@ -274,62 +341,114 @@ ath_sysctl_diag(SYSCTL_HANDLER_ARGS)
        u_int32_t diag;
        int error;
 
-       if (!ath_hal_getdiag(sc->sc_ah, &diag))
-               return EINVAL;
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
+       if (!ath_hal_getdiag(sc->sc_ah, &diag)) {
+               error = EINVAL;
+               goto finish;
+       }
+
        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 finish;
+       error = !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
 ath_sysctl_tpscale(SYSCTL_HANDLER_ARGS)
 {
        struct ath_softc *sc = arg1;
-       struct ifnet *ifp = sc->sc_ifp;
        u_int32_t scale;
        int error;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
        (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_flags & IFF_RUNNING) ?
-             ath_reset(ifp, ATH_RESET_NOLOSS) : 0;
+               goto finish;
+
+       error = !ath_hal_settpscale(sc->sc_ah, scale) ? EINVAL :
+           (sc->sc_running) ? ath_reset(sc, ATH_RESET_NOLOSS) : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 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;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
+       tpc = ath_hal_gettpc(sc->sc_ah);
+
        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 finish;
+       error = !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
 ath_sysctl_rfkill(SYSCTL_HANDLER_ARGS)
 {
        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;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
+       rfkill = ath_hal_getrfkill(ah);
+
        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_flags & IFF_RUNNING) ?
-           ath_reset(ifp, ATH_RESET_FULL) : 0;
+               goto finish;
+       if (rfkill == ath_hal_getrfkill(ah)) {  /* unchanged */
+               error = 0;
+               goto finish;
+       }
+       if (!ath_hal_setrfkill(ah, rfkill)) {
+               error = EINVAL;
+               goto finish;
+       }
+       error = sc->sc_running ? ath_reset(sc, ATH_RESET_FULL) : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
@@ -347,33 +466,33 @@ ath_sysctl_txagg(SYSCTL_HANDLER_ARGS)
        if (param != 1)
                return 0;
 
-       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("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("aggr single packet: %d\n",
+       printf("aggr single packet: %d\n",
            sc->sc_aggr_stats.aggr_single_pkt);
-       kprintf("aggr single packet w/ BAW closed: %d\n",
+       printf("aggr single packet w/ BAW closed: %d\n",
            sc->sc_aggr_stats.aggr_baw_closed_single_pkt);
-       kprintf("aggr non-baw packet: %d\n",
+       printf("aggr non-baw packet: %d\n",
            sc->sc_aggr_stats.aggr_nonbaw_pkt);
-       kprintf("aggr aggregate packet: %d\n",
+       printf("aggr aggregate packet: %d\n",
            sc->sc_aggr_stats.aggr_aggr_pkt);
-       kprintf("aggr single packet low hwq: %d\n",
+       printf("aggr single packet low hwq: %d\n",
            sc->sc_aggr_stats.aggr_low_hwq_single_pkt);
-       kprintf("aggr single packet RTS aggr limited: %d\n",
+       printf("aggr single packet RTS aggr limited: %d\n",
            sc->sc_aggr_stats.aggr_rts_aggr_limited);
-       kprintf("aggr sched, no work: %d\n",
+       printf("aggr sched, no work: %d\n",
            sc->sc_aggr_stats.aggr_sched_nopkt);
        for (i = 0; i < 64; i++) {
-               kprintf("%2d: %10d ", i, sc->sc_aggr_stats.aggr_pkts[i]);
+               printf("%2d: %10d ", i, sc->sc_aggr_stats.aggr_pkts[i]);
                if (i % 4 == 3)
-                       kprintf("\n");
+                       printf("\n");
        }
-       kprintf("\n");
+       printf("\n");
 
        for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
                if (ATH_TXQ_SETUP(sc, i)) {
-                       kprintf("HW TXQ %d: axq_depth=%d, axq_aggr_depth=%d, "
+                       printf("HW TXQ %d: axq_depth=%d, axq_aggr_depth=%d, "
                            "axq_fifo_depth=%d, holdingbf=%p\n",
                            i,
                            sc->sc_txq[i].axq_depth,
@@ -387,31 +506,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) {
-                       kprintf("Busy: %d\n", t);
+                       printf("Busy: %d\n", t);
                        i++;
                }
                t++;
        }
        ATH_TXBUF_UNLOCK(sc);
-       kprintf("Total TX buffers: %d; Total TX buffers busy: %d (%d)\n",
+       printf("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) {
-                       kprintf("Busy: %d\n", t);
+                       printf("Busy: %d\n", t);
                        i++;
                }
                t++;
        }
        ATH_TXBUF_UNLOCK(sc);
-       kprintf("Total mgmt TX buffers: %d; Total mgmt TX buffers busy: %d\n",
+       printf("Total mgmt TX buffers: %d; Total mgmt TX buffers busy: %d\n",
            t, i);
 
        ATH_RX_LOCK(sc);
        for (i = 0; i < 2; i++) {
-               kprintf("%d: fifolen: %d/%d; head=%d; tail=%d; m_pending=%p, m_holdbf=%p\n",
+               printf("%d: fifolen: %d/%d; head=%d; tail=%d; m_pending=%p, m_holdbf=%p\n",
                    i,
                    sc->sc_rxedma[i].m_fifo_depth,
                    sc->sc_rxedma[i].m_fifolen,
@@ -424,7 +543,7 @@ ath_sysctl_txagg(SYSCTL_HANDLER_ARGS)
        TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) {
                i++;
        }
-       kprintf("Total RX buffers in free list: %d buffers\n",
+       printf("Total RX buffers in free list: %d buffers\n",
            i);
        ATH_RX_UNLOCK(sc);
 
@@ -438,12 +557,18 @@ ath_sysctl_rfsilent(SYSCTL_HANDLER_ARGS)
        u_int rfsilent;
        int error;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
        (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 finish;
+       if (!ath_hal_setrfsilent(sc->sc_ah, rfsilent)) {
+               error = EINVAL;
+               goto finish;
+       }
        /*
         * Earlier chips (< AR5212) have up to 8 GPIO
         * pins exposed.
@@ -454,7 +579,14 @@ ath_sysctl_rfsilent(SYSCTL_HANDLER_ARGS)
         */
        sc->sc_rfsilentpin = rfsilent & 0x3c;
        sc->sc_rfsilentpol = (rfsilent & 0x2) != 0;
-       return 0;
+       error = 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
@@ -464,11 +596,22 @@ ath_sysctl_tpack(SYSCTL_HANDLER_ARGS)
        u_int32_t tpack;
        int error;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
        (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 finish;
+       error = !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
@@ -478,11 +621,23 @@ ath_sysctl_tpcts(SYSCTL_HANDLER_ARGS)
        u_int32_t tpcts;
        int error;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
        (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 finish;
+
+       error = !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 static int
@@ -491,25 +646,38 @@ ath_sysctl_intmit(SYSCTL_HANDLER_ARGS)
        struct ath_softc *sc = arg1;
        int intmit, error;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
        intmit = ath_hal_getintmit(sc->sc_ah);
        error = sysctl_handle_int(oidp, &intmit, 0, req);
        if (error || !req->newptr)
-               return error;
+               goto finish;
 
        /* 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 finish;
+       }
 
        /*
         * 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)
-               ath_reset(sc->sc_ifp, ATH_RESET_NOLOSS);
+       if (sc->sc_running)
+               ath_reset(sc, ATH_RESET_NOLOSS);
 
-       return 0;
+       error = 0;
+
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 #ifdef IEEE80211_SUPPORT_TDMA
@@ -541,11 +709,7 @@ ath_sysctl_forcebstuck(SYSCTL_HANDLER_ARGS)
        if (val == 0)
                return 0;
 
-#if defined(__DragonFly__)
        taskqueue_enqueue(sc->sc_tq, &sc->sc_bstucktask);
-#else
-       taskqueue_enqueue_fast(sc->sc_tq, &sc->sc_bstucktask);
-#endif
        val = 0;
        return 0;
 }
@@ -567,15 +731,28 @@ ath_sysctl_hangcheck(SYSCTL_HANDLER_ARGS)
        if (val == 0)
                return 0;
 
+       ATH_LOCK(sc);
+       ath_power_set_power_state(sc, HAL_PM_AWAKE);
+       ATH_UNLOCK(sc);
+
        /* Do a hang check */
        if (!ath_hal_getdiagstate(ah, HAL_DIAG_CHECK_HANGS,
            &mask, sizeof(mask),
-           (void *) &sp, &rsize))
-               return (0);
+           (void *) &sp, &rsize)) {
+               error = 0;
+               goto finish;
+       }
+
        device_printf(sc->sc_dev, "%s: sp=0x%08x\n", __func__, *sp);
 
        val = 0;
-       return 0;
+       error = 0;
+finish:
+       ATH_LOCK(sc);
+       ath_power_restore_power_state(sc);
+       ATH_UNLOCK(sc);
+
+       return (error);
 }
 
 #ifdef ATH_DEBUG_ALQ
@@ -642,26 +819,14 @@ ath_sysctlattach(struct ath_softc *sc)
                "regdomain", CTLFLAG_RD, &sc->sc_eerd, 0,
                "EEPROM regdomain code");
 #ifdef ATH_DEBUG
-#if defined(__DragonFly__)
-       SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
-               "debug", CTLFLAG_RW, &sc->sc_debug, 0,
-               "control debugging printfs");
-#else
        SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
                "debug", CTLFLAG_RW, &sc->sc_debug,
                "control debugging printfs");
 #endif
-#endif
 #ifdef ATH_DEBUG_ALQ
-#if defined(__DragonFly__)
-       SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
-               "ktrdebug", CTLFLAG_RW, &sc->sc_ktrdebug, 0,
-               "control debugging KTR");
-#else
        SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
                "ktrdebug", CTLFLAG_RW, &sc->sc_ktrdebug,
                "control debugging KTR");
-#endif
 #endif /* ATH_DEBUG_ALQ */
        SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
                "slottime", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
@@ -864,7 +1029,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++) {
-               ksnprintf(sn, sizeof(sn), "%d", i);
+               snprintf(sn, sizeof(sn), "%d", i);
                SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD, &sc->sc_stats.ast_rx_phy[i], 0, "");
        }
 }
@@ -883,7 +1048,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++) {
-               ksnprintf(sn, sizeof(sn), "%d", i);
+               snprintf(sn, sizeof(sn), "%d", i);
                SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD,
                    &sc->sc_intr_stats.sync_intr[i], 0, "");
        }
@@ -1120,6 +1285,12 @@ ath_sysctl_stats_attach(struct ath_softc *sc)
        SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_stbc",
            CTLFLAG_RD, &sc->sc_stats.ast_rx_stbc, 0,
            "Number of STBC frames received");
+       SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_stbc",
+           CTLFLAG_RD, &sc->sc_stats.ast_tx_stbc, 0,
+           "Number of STBC frames transmitted");
+       SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_ldpc",
+           CTLFLAG_RD, &sc->sc_stats.ast_tx_ldpc, 0,
+           "Number of LDPC frames transmitted");
        
        /* Attach the RX phy error array */
        ath_sysctl_stats_attach_rxphyerr(sc, child);
index b587dc0..e3460c6 100644 (file)
@@ -68,6 +68,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/module.h>
 #include <sys/ktr.h>
+#include <sys/smp.h>   /* for mp_ncpus */
+
+#include <machine/bus.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -78,13 +81,13 @@ __FBSDID("$FreeBSD$");
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 
-#include <netproto/802_11/ieee80211_var.h>
-#include <netproto/802_11/ieee80211_regdomain.h>
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
 
 #include <net/bpf.h>
@@ -94,31 +97,31 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
-
-#include <dev/netif/ath/ath/if_ath_debug.h>
-#include <dev/netif/ath/ath/if_ath_misc.h>
-#include <dev/netif/ath/ath/if_ath_tsf.h>
-#include <dev/netif/ath/ath/if_ath_tx.h>
-#include <dev/netif/ath/ath/if_ath_sysctl.h>
-#include <dev/netif/ath/ath/if_ath_led.h>
-#include <dev/netif/ath/ath/if_ath_keycache.h>
-#include <dev/netif/ath/ath/if_ath_rx.h>
-#include <dev/netif/ath/ath/if_ath_beacon.h>
-#include <dev/netif/ath/ath/if_athdfs.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
+
+#include <dev/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_tsf.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_sysctl.h>
+#include <dev/ath/if_ath_led.h>
+#include <dev/ath/if_ath_keycache.h>
+#include <dev/ath/if_ath_rx.h>
+#include <dev/ath/if_ath_beacon.h>
+#include <dev/ath/if_athdfs.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
 #ifdef ATH_DEBUG_ALQ
-#include <dev/netif/ath/ath/if_ath_alq.h>
+#include <dev/ath/if_ath_alq.h>
 #endif
 
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <dev/netif/ath/ath/if_ath_tdma.h>
+#include <dev/ath/if_ath_tdma.h>
 
 static void    ath_tdma_settimers(struct ath_softc *sc, u_int32_t nexttbtt,
                    u_int32_t bintval);
@@ -247,8 +250,7 @@ void
 ath_tdma_config(struct ath_softc *sc, struct ieee80211vap *vap)
 {
        struct ath_hal *ah = sc->sc_ah;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        const struct ieee80211_txparam *tp;
        const struct ieee80211_tdma_state *tdma = NULL;
        int rix;
@@ -256,7 +258,7 @@ ath_tdma_config(struct ath_softc *sc, struct ieee80211vap *vap)
        if (vap == NULL) {
                vap = TAILQ_FIRST(&ic->ic_vaps);   /* XXX */
                if (vap == NULL) {
-                       if_printf(ifp, "%s: no vaps?\n", __func__);
+                       device_printf(sc->sc_dev, "%s: no vaps?\n", __func__);
                        return;
                }
        }
@@ -286,7 +288,7 @@ ath_tdma_config(struct ath_softc *sc, struct ieee80211vap *vap)
                /* XXX short preamble assumed */
                /* XXX non-11n rate assumed */
                sc->sc_tdmaguard = ath_hal_computetxtime(ah, sc->sc_currates,
-                       ifp->if_mtu + IEEE80211_MAXOVERHEAD, rix, AH_TRUE);
+                   vap->iv_ifp->if_mtu + IEEE80211_MAXOVERHEAD, rix, AH_TRUE);
        }
 
        ath_hal_intrset(ah, 0);
@@ -546,7 +548,7 @@ ath_tdma_update(struct ieee80211_node *ni,
         *     slot position changes) because ieee80211_add_tdma
         *     skips over the data.
         */
-       memcpy(ATH_VAP(vap)->av_boff.bo_tdma +
+       memcpy(vap->iv_bcn_off.bo_tdma +
                __offsetof(struct ieee80211_tdma_param, tdma_tstamp),
                &ni->ni_tstamp.data, 8);
 #if 0
index cc80a8f..d08df69 100644 (file)
@@ -61,6 +61,8 @@ __FBSDID("$FreeBSD$");
 #include <sys/priv.h>
 #include <sys/ktr.h>
 
+#include <machine/bus.h>
+
 #include <net/if.h>
 #include <net/if_var.h>
 #include <net/if_dl.h>
@@ -70,15 +72,15 @@ __FBSDID("$FreeBSD$");
 #include <net/ethernet.h>
 #include <net/if_llc.h>
 
-#include <netproto/802_11/ieee80211_var.h>
-#include <netproto/802_11/ieee80211_regdomain.h>
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_regdomain.h>
 #ifdef IEEE80211_SUPPORT_SUPERG
-#include <netproto/802_11/ieee80211_superg.h>
+#include <net80211/ieee80211_superg.h>
 #endif
 #ifdef IEEE80211_SUPPORT_TDMA
-#include <netproto/802_11/ieee80211_tdma.h>
+#include <net80211/ieee80211_tdma.h>
 #endif
-#include <netproto/802_11/ieee80211_ht.h>
+#include <net80211/ieee80211_ht.h>
 
 #include <net/bpf.h>
 
@@ -87,26 +89,24 @@ __FBSDID("$FreeBSD$");
 #include <netinet/if_ether.h>
 #endif
 
-#include <dev/netif/ath/ath/if_athvar.h>
-#include <dev/netif/ath/ath_hal/ah_devid.h>            /* XXX for softled */
-#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
+#include <dev/ath/if_athvar.h>
+#include <dev/ath/ath_hal/ah_devid.h>          /* XXX for softled */
+#include <dev/ath/ath_hal/ah_diagcodes.h>
 
-#include <dev/netif/ath/ath/if_ath_debug.h>
+#include <dev/ath/if_ath_debug.h>
 
 #ifdef ATH_TX99_DIAG
-#include <dev/netif/ath/ath_tx99/ath_tx99.h>
+#include <dev/ath/ath_tx99/ath_tx99.h>
 #endif
 
-#include <dev/netif/ath/ath/if_ath_misc.h>
-#include <dev/netif/ath/ath/if_ath_tx.h>
-#include <dev/netif/ath/ath/if_ath_tx_ht.h>
+#include <dev/ath/if_ath_misc.h>
+#include <dev/ath/if_ath_tx.h>
+#include <dev/ath/if_ath_tx_ht.h>
 
 #ifdef ATH_DEBUG_ALQ
-#include <dev/netif/ath/ath/if_ath_alq.h>
+#include <dev/ath/if_ath_alq.h>
 #endif
 
-extern  const char* ath_hal_ether_sprintf(const uint8_t *mac);
-
 /*
  * How many retries to perform in software
  */
@@ -283,50 +283,25 @@ ath_txfrag_setup(struct ath_softc *sc, ath_bufhead *frags,
        return !TAILQ_EMPTY(frags);
 }
 
-/*
- * Reclaim mbuf resources.  For fragmented frames we
- * need to claim each frag chained with m_nextpkt.
- */
-void
-ath_freetx(struct mbuf *m)
-{
-       struct mbuf *next;
-
-       do {
-               next = m->m_nextpkt;
-               m->m_nextpkt = NULL;
-               m_freem(m);
-       } while ((m = next) != NULL);
-}
-
 static int
 ath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0)
 {
-#if defined(__DragonFly__)
-#else
        struct mbuf *m;
-#endif
        int error;
 
        /*
         * Load the DMA map so any coalescing is done.  This
         * also calculates the number of descriptors we need.
         */
-#if defined(__DragonFly__)
-       error = bus_dmamap_load_mbuf_segment(sc->sc_dmat, bf->bf_dmamap, m0,
-                                    bf->bf_segs, 1, &bf->bf_nseg,
-                                    BUS_DMA_NOWAIT);
-#else
        error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0,
                                     bf->bf_segs, &bf->bf_nseg,
                                     BUS_DMA_NOWAIT);
-#endif
        if (error == EFBIG) {
                /* XXX packet requires too many descriptors */
                bf->bf_nseg = ATH_MAX_SCATTER + 1;
        } else if (error != 0) {
                sc->sc_stats.ast_tx_busdma++;
-               ath_freetx(m0);
+               ieee80211_free_mbuf(m0);
                return error;
        }
        /*
@@ -336,15 +311,9 @@ 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 defined(__DragonFly__)
-               error = bus_dmamap_load_mbuf_defrag(sc->sc_dmat,
-                                            bf->bf_dmamap, &m0,
-                                            bf->bf_segs, ATH_TXDESC,
-                                            &bf->bf_nseg, BUS_DMA_NOWAIT);
-#else
                m = m_collapse(m0, M_NOWAIT, ATH_MAX_SCATTER);
                if (m == NULL) {
-                       ath_freetx(m0);
+                       ieee80211_free_mbuf(m0);
                        sc->sc_stats.ast_tx_nombuf++;
                        return ENOMEM;
                }
@@ -352,17 +321,16 @@ ath_tx_dmasetup(struct ath_softc *sc, struct ath_buf *bf, struct mbuf *m0)
                error = bus_dmamap_load_mbuf_sg(sc->sc_dmat, bf->bf_dmamap, m0,
                                             bf->bf_segs, &bf->bf_nseg,
                                             BUS_DMA_NOWAIT);
-#endif
                if (error != 0) {
                        sc->sc_stats.ast_tx_busdma++;
-                       ath_freetx(m0);
+                       ieee80211_free_mbuf(m0);
                        return error;
                }
                KASSERT(bf->bf_nseg <= ATH_MAX_SCATTER,
                    ("too many segments after defrag; nseg %u", bf->bf_nseg));
        } else if (bf->bf_nseg == 0) {          /* null packet, discard */
                sc->sc_stats.ast_tx_nodata++;
-               ath_freetx(m0);
+               ieee80211_free_mbuf(m0);
                return EIO;
        }
        DPRINTF(sc, ATH_DEBUG_XMIT, "%s: m %p len %u\n",
@@ -1067,8 +1035,7 @@ ath_tx_calc_protection(struct ath_softc *sc, struct ath_buf *bf)
        uint16_t flags;
        int shortPreamble;
        const HAL_RATE_TABLE *rt = sc->sc_currates;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
 
        flags = bf->bf_state.bfs_txflags;
        rix = bf->bf_state.bfs_rc[0].rix;
@@ -1216,7 +1183,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) {
-               kprintf("%s: HT rate where it shouldn't be (0x%x)\n",
+               printf("%s: HT rate where it shouldn't be (0x%x)\n",
                    __func__, rt->info[cix].rateCode);
                return (-1);
        }
@@ -1480,10 +1447,9 @@ ath_tx_should_swq_frame(struct ath_softc *sc, struct ath_node *an,
                 * for now!
                 */
                DPRINTF(sc, ATH_DEBUG_XMIT, 
-                   "%s: %s: Node is asleep; sending mgmt "
+                   "%s: %6D: Node is asleep; sending mgmt "
                    "(type=%d, subtype=%d)\n",
-                   __func__, ath_hal_ether_sprintf(ni->ni_macaddr),
-                   type, subtype);
+                   __func__, ni->ni_macaddr, ":", type, subtype);
                return (0);
        } else {
                return (1);
@@ -1562,8 +1528,7 @@ ath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni,
 {
        struct ieee80211vap *vap = ni->ni_vap;
        struct ath_hal *ah = sc->sc_ah;
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams;
        int error, iswep, ismcast, isfrag, ismrr;
        int keyix, hdrlen, pktlen, try0 = 0;
@@ -1600,7 +1565,7 @@ ath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni,
        /* Handle encryption twiddling if needed */
        if (! ath_tx_tag_crypto(sc, ni, m0, iswep, isfrag, &hdrlen,
            &pktlen, &keyix)) {
-               ath_freetx(m0);
+               ieee80211_free_mbuf(m0);
                return EIO;
        }
 
@@ -1708,11 +1673,11 @@ ath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni,
                        flags |= HAL_TXDESC_NOACK;
                break;
        default:
-               if_printf(ifp, "bogus frame type 0x%x (%s)\n",
-                       wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__);
+               device_printf(sc->sc_dev, "bogus frame type 0x%x (%s)\n",
+                   wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK, __func__);
                /* XXX statistic */
                /* XXX free tx dmamap */
-               ath_freetx(m0);
+               ieee80211_free_mbuf(m0);
                return EIO;
        }
 
@@ -1768,7 +1733,7 @@ ath_tx_normal_setup(struct ath_softc *sc, struct ieee80211_node *ni,
                    "%s: discard frame, ACK required w/ TDMA\n", __func__);
                sc->sc_stats.ast_tdma_ack++;
                /* XXX free tx dmamap */
-               ath_freetx(m0);
+               ieee80211_free_mbuf(m0);
                return EIO;
        }
 #endif
@@ -2091,8 +2056,7 @@ ath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni,
        struct ath_buf *bf, struct mbuf *m0,
        const struct ieee80211_bpf_params *params)
 {
-       struct ifnet *ifp = sc->sc_ifp;
-       struct ieee80211com *ic = ifp->if_l2com;
+       struct ieee80211com *ic = &sc->sc_ic;
        struct ath_hal *ah = sc->sc_ah;
        struct ieee80211vap *vap = ni->ni_vap;
        int error, ismcast, ismrr;
@@ -2153,7 +2117,7 @@ ath_tx_raw_start(struct ath_softc *sc, struct ieee80211_node *ni,
        if (! ath_tx_tag_crypto(sc, ni,
            m0, params->ibp_flags & IEEE80211_BPF_CRYPTO, 0,
            &hdrlen, &pktlen, &keyix)) {
-               ath_freetx(m0);
+               ieee80211_free_mbuf(m0);
                return EIO;
        }
        /* packet header may have moved, reset our local pointer */
@@ -2357,7 +2321,6 @@ ath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
        const struct ieee80211_bpf_params *params)
 {
        struct ieee80211com *ic = ni->ni_ic;
-       struct ifnet *ifp = ic->ic_ifp;
        struct ath_softc *sc = ic->ic_softc;
        struct ath_buf *bf;
        struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
@@ -2381,10 +2344,9 @@ ath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
 
        ATH_TX_LOCK(sc);
 
-       if ((ifp->if_flags & IFF_RUNNING) == 0 || sc->sc_invalid) {
-               DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, %s", __func__,
-                   (ifp->if_flags & IFF_RUNNING) == 0 ?
-                       "!running" : "invalid");
+       if (!sc->sc_running || sc->sc_invalid) {
+               DPRINTF(sc, ATH_DEBUG_XMIT, "%s: discard frame, r/i: %d/%d",
+                   __func__, sc->sc_running, sc->sc_invalid);
                m_freem(m);
                error = ENETDOWN;
                goto bad;
@@ -2441,11 +2403,6 @@ ath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
                }
        }
        sc->sc_wd_timer = 5;
-#if defined(__DragonFly__)
-       ++ifp->if_opackets;
-#else
-       if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
-#endif
        sc->sc_stats.ast_tx_raw++;
 
        /*
@@ -2494,13 +2451,7 @@ bad:
 badbad:
        ATH_KTR(sc, ATH_KTR_TX, 2, "ath_raw_xmit: bad0: m=%p, params=%p",
            m, params);
-#if defined(__DragonFly__)
-       ++ifp->if_oerrors;
-#else
-       if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
-#endif
        sc->sc_stats.ast_tx_raw_fail++;
-       ieee80211_free_node(ni);
 
        return error;
 }
@@ -2816,9 +2767,10 @@ ath_tx_leak_count_update(struct ath_softc *sc, struct ath_tid *tid,
                        wh->i_fc[1] &= ~IEEE80211_FC1_MORE_DATA;
 
                DPRINTF(sc, ATH_DEBUG_NODE_PWRSAVE,
-                   "%s: %s: leak count = %d, psq=%d, swq=%d, MORE=%d\n",
+                   "%s: %6D: leak count = %d, psq=%d, swq=%d, MORE=%d\n",
                    __func__,
-                   ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+                   tid->an->an_node.ni_macaddr,
+                   ":",
                    tid->an->an_leak_count,
                    tid->an->an_stack_psq,
                    tid->an->an_swq_depth,
@@ -3173,7 +3125,7 @@ ath_tx_swq(struct ath_softc *sc, struct ieee80211_node *ni,
         * If we're not doing A-MPDU, be prepared to direct dispatch
         * up to both limits if possible.  This particular corner
         * case may end up with packet starvation between aggregate
-        * traffic and non-aggregate traffic: we wnat to ensure
+        * traffic and non-aggregate traffic: we want to ensure
         * that non-aggregate stations get a few frames queued to the
         * hardware before the aggregate station(s) get their chance.
         *
@@ -3284,9 +3236,9 @@ ath_tx_tid_pause(struct ath_softc *sc, struct ath_tid *tid)
 
        ATH_TX_LOCK_ASSERT(sc);
        tid->paused++;
-       DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: [%s]: tid=%d, paused = %d\n",
+       DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL, "%s: [%6D]: tid=%d, paused = %d\n",
            __func__,
-           ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+           tid->an->an_node.ni_macaddr, ":",
            tid->tid,
            tid->paused);
 }
@@ -3306,18 +3258,18 @@ ath_tx_tid_resume(struct ath_softc *sc, struct ath_tid *tid)
         */
        if (tid->paused == 0) {
                device_printf(sc->sc_dev,
-                   "%s: [%s]: tid=%d, paused=0?\n",
+                   "%s: [%6D]: tid=%d, paused=0?\n",
                    __func__,
-                   ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+                   tid->an->an_node.ni_macaddr, ":",
                    tid->tid);
        } else {
                tid->paused--;
        }
 
        DPRINTF(sc, ATH_DEBUG_SW_TX_CTRL,
-           "%s: [%s]: tid=%d, unpaused = %d\n",
+           "%s: [%6D]: tid=%d, unpaused = %d\n",
            __func__,
-           ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+           tid->an->an_node.ni_macaddr, ":",
            tid->tid,
            tid->paused);
 
@@ -3596,16 +3548,16 @@ ath_tx_tid_bar_unsuspend(struct ath_softc *sc, struct ath_tid *tid)
        ATH_TX_LOCK_ASSERT(sc);
 
        DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-           "%s: %s: TID=%d, called\n",
+           "%s: %6D: TID=%d, called\n",
            __func__,
-           ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+           tid->an->an_node.ni_macaddr,
+           ":",
            tid->tid);
 
        if (tid->bar_tx == 0 || tid->bar_wait == 0) {
                DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-                   "%s: %s: TID=%d, bar_tx=%d, bar_wait=%d: ?\n",
-                   __func__,
-                   ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+                   "%s: %6D: TID=%d, bar_tx=%d, bar_wait=%d: ?\n",
+                   __func__, tid->an->an_node.ni_macaddr, ":",
                    tid->tid, tid->bar_tx, tid->bar_wait);
        }
 
@@ -3628,9 +3580,10 @@ ath_tx_tid_bar_tx_ready(struct ath_softc *sc, struct ath_tid *tid)
                return (0);
 
        DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-           "%s: %s: TID=%d, bar ready\n",
+           "%s: %6D: TID=%d, bar ready\n",
            __func__,
-           ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+           tid->an->an_node.ni_macaddr,
+           ":",
            tid->tid);
 
        return (1);
@@ -3656,9 +3609,10 @@ ath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid)
        ATH_TX_LOCK_ASSERT(sc);
 
        DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-           "%s: %s: TID=%d, called\n",
+           "%s: %6D: TID=%d, called\n",
            __func__,
-           ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+           tid->an->an_node.ni_macaddr,
+           ":",
            tid->tid);
 
        tap = ath_tx_get_tx_tid(tid->an, tid->tid);
@@ -3668,9 +3622,8 @@ ath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid)
         */
        if (tid->bar_wait == 0 || tid->bar_tx == 1) {
                DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-                   "%s: %s: TID=%d, bar_tx=%d, bar_wait=%d: ?\n",
-                   __func__,
-                   ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+                   "%s: %6D: TID=%d, bar_tx=%d, bar_wait=%d: ?\n",
+                   __func__, tid->an->an_node.ni_macaddr, ":",
                    tid->tid, tid->bar_tx, tid->bar_wait);
                return;
        }
@@ -3678,9 +3631,10 @@ ath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid)
        /* Don't do anything if we still have pending frames */
        if (tid->hwq_depth > 0) {
                DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-                   "%s: %s: TID=%d, hwq_depth=%d, waiting\n",
+                   "%s: %6D: TID=%d, hwq_depth=%d, waiting\n",
                    __func__,
-                   ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+                   tid->an->an_node.ni_macaddr,
+                   ":",
                    tid->tid,
                    tid->hwq_depth);
                return;
@@ -3702,9 +3656,10 @@ ath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid)
         * XXX verify this is _actually_ the valid value to begin at!
         */
        DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-           "%s: %s: TID=%d, new BAW left edge=%d\n",
+           "%s: %6D: TID=%d, new BAW left edge=%d\n",
            __func__,
-           ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+           tid->an->an_node.ni_macaddr,
+           ":",
            tid->tid,
            tap->txa_start);
 
@@ -3721,9 +3676,8 @@ ath_tx_tid_bar_tx(struct ath_softc *sc, struct ath_tid *tid)
        /* Failure? For now, warn loudly and continue */
        ATH_TX_LOCK(sc);
        DPRINTF(sc, ATH_DEBUG_SW_TX_BAR,
-           "%s: %s: TID=%d, failed to TX BAR, continue!\n",
-           __func__,
-           ath_hal_ether_sprintf(tid->an->an_node.ni_macaddr),
+           "%s: %6D: TID=%d, failed to TX BAR, continue!\n",
+           __func__, tid->an->an_node.ni_macaddr, ":",
            tid->tid);
        ath_tx_tid_bar_unsuspend(sc, tid);
 }
@@ -3780,44 +3734,48 @@ ath_tx_tid_drain_print(struct ath_softc *sc, struct ath_node *an,
        tap = ath_tx_get_tx_tid(an, tid->tid);
 
        DPRINTF(sc, ATH_DEBUG_SW_TX | ATH_DEBUG_RESET,
-           "%s: %s: %s: bf=%p: addbaw=%d, dobaw=%d, "
+           "%s: %s: %6D: bf=%p: addbaw=%d, dobaw=%d, "
            "seqno=%d, retry=%d\n",
            __func__,
            pfx,
-           ath_hal_ether_sprintf(ni->ni_macaddr),
+           ni->ni_macaddr,
+           ":",
            bf,
            bf->bf_state.bfs_addedbaw,
            bf->bf_state.bfs_dobaw,
            SEQNO(bf->bf_state.bfs_seqno),
            bf->bf_state.bfs_retries);
        DPRINTF(sc, ATH_DEBUG_SW_TX | ATH_DEBUG_RESET,
-           "%s: %s: %s: bf=%p: txq[%d] axq_depth=%d, axq_aggr_depth=%d\n",
+           "%s: %s: %6D: bf=%p: txq[%d] axq_depth=%d, axq_aggr_depth=%d\n",
            __func__,
            pfx,
-           ath_hal_ether_sprintf(ni->ni_macaddr),
+           ni->ni_macaddr,
+           ":",