bwn: Porting from FreeBSD
authorImre Vadasz <imre@vdsz.com>
Thu, 27 Mar 2014 20:24:28 +0000 (21:24 +0100)
committerSascha Wildner <saw@online.de>
Sat, 5 Apr 2014 17:38:36 +0000 (19:38 +0200)
* Adding bwn and siba_bwn to sys/conf/files and to the X86_64_GENERIC kernel
  configuration.

* Replacing BWN_LOCK, BWN_UNLOCK, BWN_ASSERT_SERIALIZED with
  wlan_global_serializer.

* Increasing some alignments from 4K to 8K and some from 1 byte to 4 bytes.

* Changing slot counts for RX and TX from 64 to 256, which is the same size
  as used by b43 in Linux.

* Allow overriding the BWN_TXRING_SLOTS and BWN_RXRING_SLOTS values in the
  kernel configuration.

* Some style fixes. Removing unneeded NULL checks.

* Replace a DELAY(50000) with tsleep.

* Can't use kmalloc to allocate memory for dma like in FreeBSD and Linux.

* A few typo and grammar fixes in the bwn.4 manpage.

19 files changed:
share/man/man4/Makefile
share/man/man4/bwn.4
share/man/man4/wlan.4
share/man/man4/wlan_amrr.4
sys/conf/files
sys/conf/options
sys/config/GENERIC
sys/config/LINT
sys/config/LINT64
sys/config/X86_64_GENERIC
sys/dev/netif/Makefile
sys/dev/netif/bwn/Makefile [new file with mode: 0644]
sys/dev/netif/bwn/bwn/Makefile [new file with mode: 0644]
sys/dev/netif/bwn/bwn/if_bwn.c
sys/dev/netif/bwn/bwn/if_bwnreg.h
sys/dev/netif/bwn/bwn/if_bwnvar.h
sys/dev/netif/bwn/siba/Makefile [new file with mode: 0644]
sys/dev/netif/bwn/siba/siba_bwn.c
sys/dev/netif/bwn/siba/siba_core.c

index 4eda2cb..0dfd526 100644 (file)
@@ -55,6 +55,7 @@ MAN=  aac.4 \
        bpf.4 \
        bridge.4 \
        bt.4 \
+       bwn.4 \
        cardbus.4 \
        carp.4 \
        ccd.4 \
@@ -405,6 +406,7 @@ MLINKS+=bktr.4 brooktree.4
 MLINKS+=bnx.4 if_bnx.4
 MLINKS+=bridge.4 if_bridge.4
 #MLINKS+=bwi.4 if_bwi.4
+MLINKS+=bwn.4 if_bwn.4
 MLINKS+=crypto.4 cryptodev.4
 MLINKS+=cue.4 if_cue.4
 MLINKS+=dc.4 if_dc.4
index 4aa75fd..19b7e33 100644 (file)
@@ -22,9 +22,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/share/man/man4/bwn.4 233992 2012-04-07 09:05:30Z joel $
 .\"
-.Dd February 15, 2011
+.Dd April 5, 2014
 .Dt BWN 4
 .Os
 .Sh NAME
@@ -65,12 +65,12 @@ For more information on configuring this device, see
 .Pp
 This driver requires firmware to be loaded before it will work.
 The
-.Pa ports/net/bwn-firmware-kmod
+.Pa dports/net/bwn-firmware-kmod
 port needs to be installed before
 .Xr ifconfig 8
 will work.
-Most cases you need to use bwn_v4_ucode module but if you are a
-LP (low power) PHY user please uses bwn_v4_lp_ucode module.
+In most cases you need to use the bwn_v4_ucode module but if you are a
+LP (low power) PHY user please use the bwn_v4_lp_ucode module.
 .Sh HARDWARE
 The
 .Nm
@@ -118,9 +118,9 @@ Tunables can be set at the
 prompt before booting the kernel or stored in
 .Xr loader.conf 5 .
 .Bl -tag -width indent
-.It Va hw.bwn.msi_disable
-This tunable disables MSI support on the hardware.
-The default value is 0.
+.It Va hw.bwn.msi.enable
+By default, the driver will use MSI if it is supported.
+This behavior can be turned off by setting this tunable to 0.
 .It Va hw.bwn.usedma
 This tunable enables DMA operations on the hardware.
 If the value is 0, PIO mode would be used.
@@ -128,8 +128,9 @@ The default value is 1.
 .El
 .Sh SEE ALSO
 .Xr arp 4 ,
-.Xr bwi 4 ,
+.\".Xr bwi 4 ,
 .Xr cardbus 4 ,
+.Xr ifmedia 4 ,
 .Xr intro 4 ,
 .Xr pci 4 ,
 .Xr wlan 4 ,
@@ -152,5 +153,5 @@ driver was written by
 .\"Some card based on the BCM4306 and BCM4309 chips do not work properly
 .\"on channel 1, 2 and 3.
 .Sh CAVEATS
-Some LP PHY devices have DMA operation problems that in that case try to
-use PIO mode.
+Some LP PHY devices have DMA operation problems.
+In that case try to use the PIO mode.
index ac95364..2276b24 100644 (file)
@@ -232,6 +232,7 @@ may not interoperate.
 .Xr an 4 ,
 .Xr ath 4 ,
 .\".Xr bwi 4 ,
+.Xr bwn 4 ,
 .\".Xr ipw 4 ,
 .Xr iwi 4 ,
 .\".Xr iwl 4 ,
index 86fc981..723e59c 100644 (file)
@@ -40,6 +40,7 @@ module implements the Adaptive Multi-Rate Retry tx rate control
 algorithm for use by 802.11 device drivers.
 .Sh SEE ALSO
 .\".Xr bwi 4 ,
+.Xr bwn 4 ,
 .Xr iwn 4 ,
 .Xr ral 4 ,
 .Xr rum 4 ,
index 660c858..c75b1fa 100644 (file)
@@ -343,6 +343,7 @@ dev/netif/bce/if_bce.c                      optional bce
 dev/netif/bfe/if_bfe.c                 optional bfe
 dev/netif/bge/if_bge.c                 optional bge
 dev/netif/bnx/if_bnx.c                 optional bnx
+dev/netif/bwn/bwn/if_bwn.c             optional bwn siba_bwn
 dev/disk/buslogic/bt.c                 optional bt
 dev/disk/buslogic/bt_pci.c             optional bt pci
 dev/disk/ccd/ccd.c                     optional ccd
@@ -807,6 +808,8 @@ dev/serial/si/si.c          optional si
 dev/serial/si/si2_z280.c       optional si
 dev/serial/si/si3_t225.c       optional si
 dev/serial/si/si_pci.c         optional si pci
+dev/netif/bwn/siba/siba_bwn.c  optional siba_bwn pci
+dev/netif/bwn/siba/siba_core.c optional siba_bwn pci
 dev/netif/sln/if_sln.c         optional sln pci
 dev/netif/sn/if_sn.c           optional sn
 dev/netif/sn/if_sn_pccard.c    optional sn pccard
index dda8c28..413efb2 100644 (file)
@@ -644,6 +644,14 @@ BNX_RSS_DEBUG              opt_bnx.h
 BNX_TSO_DEBUG          opt_bnx.h
 BNX_TSS_DEBUG          opt_bnx.h
 
+# bwn driver
+BWN_DEBUG              opt_bwn.h
+BWN_RXRING_SLOTS       opt_bwn.h
+BWN_TXRING_SLOTS       opt_bwn.h
+
+# siba_bwn driver
+SIBA_DEBUG             opt_siba.h
+
 # ed driver
 ED_NO_MIIBUS           opt_ed.h
 
index e912f3a..f1db3af 100644 (file)
@@ -303,6 +303,8 @@ device              ath             # Atheros NICs
 device         ath_hal         # Atheros Hardware Access Layer
 options        AH_SUPPORT_AR5416       # enable AR5416 tx/rx descriptors
 device         ath_rate_sample # Atheros Sample TX rate control algorithm
+device         siba_bwn        # Sonic Inc. Silicon Backplane needed for bwn
+device         bwn             # Broadcom BCM43xx NICs using v4 firmware
 device         ral             # Ralink Technology 802.11 wireless NIC
 device         iwn             # Intel
 #device                rtw             # RealTek 802.11 wireless NIC
index 56e715a..2b64a9c 100644 (file)
@@ -1353,6 +1353,12 @@ options          ATH_ENABLE_DFS
 options                ATH_KTR_INTR_DEBUG
 options                ATH_RXBUF=80    # number of RX buffers to allocate
 options                ATH_TXBUF=400   # number of TX buffers to allocate
+device         siba_bwn        # Sonic Inc. Silicon Backplane needed for bwn
+options                SIBA_DEBUG      # turn on debugging output
+device         bwn             # Broadcom BCM43xx NICs using v4 firmware
+options                BWN_DEBUG       # turn on debugging output
+options                BWN_RXRING_SLOTS=128    # number of RX slots to allocate
+options                BWN_TXRING_SLOTS=128    # number of TX slots to allocate
 #device                iwl             # Intel PRO/Wireless 2100
 device         iwi             # Intel PRO/Wireless 2200BG/2915ABG
 device         iwn             # Intel WiFi Link 4965/1000/5000/5150/5300/6000/6050
index d56f131..b4e0371 100644 (file)
@@ -1225,6 +1225,12 @@ options          ATH_ENABLE_DFS
 options                ATH_KTR_INTR_DEBUG
 options                ATH_RXBUF=80    # number of RX buffers to allocate
 options                ATH_TXBUF=400   # number of TX buffers to allocate
+device         siba_bwn        # Sonic Inc. Silicon Backplane needed for bwn
+options                SIBA_DEBUG      # turn on debugging output
+device         bwn             # Broadcom BCM43xx NICs using v4 firmware
+options                BWN_DEBUG       # turn on debugging output
+options                BWN_RXRING_SLOTS=128    # number of RX slots to allocate
+options                BWN_TXRING_SLOTS=128    # number of TX slots to allocate
 #device                iwl             # Intel PRO/Wireless 2100
 device         iwi             # Intel PRO/Wireless 2200BG/2915ABG
 device         iwn             # Intel WiFi Link 4965/1000/5000/5150/5300/6000/6050
index b91ebf6..5c0c7fc 100644 (file)
@@ -280,6 +280,8 @@ device              ath             # Atheros NICs
 device         ath_hal         # Atheros Hardware Access Layer
 options        AH_SUPPORT_AR5416       # enable AR5416 tx/rx descriptors
 device         ath_rate_sample # Atheros Sample TX rate control algorithm
+device         siba_bwn        # Sonic Inc. Silicon Backplane needed for bwn
+device         bwn             # Broadcom BCM43xx NICs using v4 firmware
 device         ral             # Ralink Technology 802.11 wireless NIC
 device         iwn             # Intel
 #device                rtw             # RealTek 802.11 wireless NIC
index 14755f2..12861df 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIR= an age alc ale ath bce bfe bge \
+SUBDIR= an age alc ale ath bce bfe bge bwn \
        dc ed em ep et \
        fwe fxp ic iwi iwn jme lge lnc \
        mii_layer my msk mxge ndis nfe nge oce pcn \
diff --git a/sys/dev/netif/bwn/Makefile b/sys/dev/netif/bwn/Makefile
new file mode 100644 (file)
index 0000000..a4af068
--- /dev/null
@@ -0,0 +1,3 @@
+SUBDIR=        bwn siba
+
+.include <bsd.subdir.mk>
diff --git a/sys/dev/netif/bwn/bwn/Makefile b/sys/dev/netif/bwn/bwn/Makefile
new file mode 100644 (file)
index 0000000..b26f141
--- /dev/null
@@ -0,0 +1,6 @@
+KMOD   = if_bwn
+
+SRCS   = if_bwn.c
+SRCS   += device_if.h bus_if.h pci_if.h opt_bwn.h opt_wlan.h
+
+.include <bsd.kmod.mk>
index f5e795c..d6213e3 100644 (file)
@@ -34,6 +34,9 @@ __FBSDID("$FreeBSD: head/sys/dev/bwn/if_bwn.c 260444 2014-01-08 08:06:56Z kevlo
  * The Broadcom Wireless LAN controller driver.
  */
 
+#include <opt_wlan.h>
+#include <opt_bwn.h>
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/module.h>
@@ -41,10 +44,7 @@ __FBSDID("$FreeBSD: head/sys/dev/bwn/if_bwn.c 260444 2014-01-08 08:06:56Z kevlo
 #include <sys/endian.h>
 #include <sys/errno.h>
 #include <sys/firmware.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
+#include <sys/bus_resource.h>
 #include <sys/bus.h>
 #include <sys/rman.h>
 #include <sys/socket.h>
@@ -58,21 +58,22 @@ __FBSDID("$FreeBSD: head/sys/dev/bwn/if_bwn.c 260444 2014-01-08 08:06:56Z kevlo
 #include <net/if_llc.h>
 #include <net/if_media.h>
 #include <net/if_types.h>
+#include <net/ifq_var.h>
 
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcireg.h>
-#include <dev/siba/siba_ids.h>
-#include <dev/siba/sibareg.h>
-#include <dev/siba/sibavar.h>
+#include <bus/pci/pcivar.h>
+#include <bus/pci/pcireg.h>
+#include <dev/netif/bwn/siba/siba_ids.h>
+#include <dev/netif/bwn/siba/sibareg.h>
+#include <dev/netif/bwn/siba/sibavar.h>
 
-#include <net80211/ieee80211_var.h>
-#include <net80211/ieee80211_radiotap.h>
-#include <net80211/ieee80211_regdomain.h>
-#include <net80211/ieee80211_phy.h>
-#include <net80211/ieee80211_ratectl.h>
+#include <netproto/802_11/ieee80211_var.h>
+#include <netproto/802_11/ieee80211_radiotap.h>
+#include <netproto/802_11/ieee80211_regdomain.h>
+#include <netproto/802_11/ieee80211_phy.h>
+#include <netproto/802_11/ieee80211_ratectl.h>
 
-#include <dev/bwn/if_bwnreg.h>
-#include <dev/bwn/if_bwnvar.h>
+#include <dev/netif/bwn/bwn/if_bwnreg.h>
+#include <dev/netif/bwn/bwn/if_bwnvar.h>
 
 static SYSCTL_NODE(_hw, OID_AUTO, bwn, CTLFLAG_RD, 0,
     "Broadcom driver parameters");
@@ -109,7 +110,7 @@ enum {
 };
 #define        DPRINTF(sc, m, fmt, ...) do {                   \
        if (sc->sc_debug & (m))                         \
-               printf(fmt, __VA_ARGS__);               \
+               kprintf(fmt, __VA_ARGS__);              \
 } while (0)
 #else
 #define        DPRINTF(sc, m, fmt, ...) do { (void) sc; } while (0)
@@ -124,8 +125,8 @@ SYSCTL_INT(_hw_bwn, OID_AUTO, bluetooth, CTLFLAG_RW, &bwn_bluetooth, 0,
 static int     bwn_hwpctl = 0;
 SYSCTL_INT(_hw_bwn, OID_AUTO, hwpctl, CTLFLAG_RW, &bwn_hwpctl, 0,
     "uses H/W power control");
-static int     bwn_msi_disable = 0;            /* MSI disabled  */
-TUNABLE_INT("hw.bwn.msi_disable", &bwn_msi_disable);
+static int      bwn_msi_enable = 1;
+TUNABLE_INT("hw.bwn.msi.enable", &bwn_msi_enable);
 static int     bwn_usedma = 1;
 SYSCTL_INT(_hw_bwn, OID_AUTO, usedma, CTLFLAG_RD, &bwn_usedma, 0,
     "uses DMA");
@@ -139,8 +140,8 @@ static int  bwn_attach_post(struct bwn_softc *);
 static void    bwn_sprom_bugfixes(device_t);
 static void    bwn_init(void *);
 static int     bwn_init_locked(struct bwn_softc *);
-static int     bwn_ioctl(struct ifnet *, u_long, caddr_t);
-static void    bwn_start(struct ifnet *);
+static int     bwn_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
+static void    bwn_start(struct ifnet *, struct ifaltq_subque *);
 static int     bwn_attach_core(struct bwn_mac *);
 static void    bwn_reset_core(struct bwn_mac *, uint32_t);
 static int     bwn_phy_getinfo(struct bwn_mac *, int);
@@ -390,7 +391,7 @@ static int  bwn_switch_band(struct bwn_softc *,
 static void    bwn_phy_reset(struct bwn_mac *);
 static int     bwn_newstate(struct ieee80211vap *, enum ieee80211_state, int);
 static void    bwn_set_pretbtt(struct bwn_mac *);
-static int     bwn_intr(void *);
+static void    bwn_intr(void *);
 static void    bwn_intrtask(void *, int);
 static void    bwn_restart(struct bwn_mac *, const char *);
 static void    bwn_intr_ucode_debug(struct bwn_mac *);
@@ -534,16 +535,6 @@ static void        bwn_phy_lp_gaintbl_write_r01(struct bwn_mac *, int,
                    struct bwn_txgain_entry);
 static void    bwn_sysctl_node(struct bwn_softc *);
 
-static struct resource_spec bwn_res_spec_legacy[] = {
-       { SYS_RES_IRQ,          0,              RF_ACTIVE | RF_SHAREABLE },
-       { -1,                   0,              0 }
-};
-
-static struct resource_spec bwn_res_spec_msi[] = {
-       { SYS_RES_IRQ,          1,              RF_ACTIVE },
-       { -1,                   0,              0 }
-};
-
 static const struct bwn_channelinfo bwn_chantable_bg = {
        .channels = {
                { 2412,  1, 30 }, { 2417,  2, 30 }, { 2422,  3, 30 },
@@ -908,13 +899,17 @@ bwn_probe(device_t dev)
 {
        int i;
 
+       wlan_serialize_enter();
+
        for (i = 0; i < sizeof(bwn_devs) / sizeof(bwn_devs[0]); i++) {
                if (siba_get_vendor(dev) == bwn_devs[i].sd_vendor &&
                    siba_get_device(dev) == bwn_devs[i].sd_device &&
-                   siba_get_revid(dev) == bwn_devs[i].sd_rev)
+                   siba_get_revid(dev) == bwn_devs[i].sd_rev) {
+                       wlan_serialize_exit();
                        return (BUS_PROBE_DEFAULT);
+               }
        }
-
+       wlan_serialize_exit();
        return (ENXIO);
 }
 
@@ -923,7 +918,10 @@ bwn_attach(device_t dev)
 {
        struct bwn_mac *mac;
        struct bwn_softc *sc = device_get_softc(dev);
-       int error, i, msic, reg;
+       int error;
+       u_int irq_flags;
+
+       wlan_serialize_enter();
 
        sc->sc_dev = dev;
 #ifdef BWN_DEBUG
@@ -932,8 +930,10 @@ bwn_attach(device_t dev)
 
        if ((sc->sc_flags & BWN_FLAG_ATTACHED) == 0) {
                error = bwn_attach_pre(sc);
-               if (error != 0)
+               if (error != 0) {
+                       wlan_serialize_exit();
                        return (error);
+               }
                bwn_sprom_bugfixes(dev);
                sc->sc_flags |= BWN_FLAG_ATTACHED;
        }
@@ -944,14 +944,13 @@ bwn_attach(device_t dev)
                    siba_get_pci_device(dev) != 0x4321) {
                        device_printf(sc->sc_dev,
                            "skip 802.11 cores\n");
+                       wlan_serialize_exit();
                        return (ENODEV);
                }
        }
 
-       mac = (struct bwn_mac *)malloc(sizeof(*mac), M_DEVBUF,
-           M_NOWAIT | M_ZERO);
-       if (mac == NULL)
-               return (ENOMEM);
+       mac = (struct bwn_mac *)kmalloc(sizeof(*mac), M_DEVBUF,
+           M_INTWAIT | M_ZERO);
        mac->mac_sc = sc;
        mac->mac_status = BWN_MAC_STATUS_UNINIT;
        if (bwn_bfp != 0)
@@ -978,49 +977,19 @@ bwn_attach(device_t dev)
        else
                device_printf(sc->sc_dev, "PIO\n");
 
-       /*
-        * setup PCI resources and interrupt.
-        */
-       if (pci_find_cap(dev, PCIY_EXPRESS, &reg) == 0) {
-               msic = pci_msi_count(dev);
-               if (bootverbose)
-                       device_printf(sc->sc_dev, "MSI count : %d\n", msic);
-       } else
-               msic = 0;
-
-       mac->mac_intr_spec = bwn_res_spec_legacy;
-       if (msic == BWN_MSI_MESSAGES && bwn_msi_disable == 0) {
-               if (pci_alloc_msi(dev, &msic) == 0) {
-                       device_printf(sc->sc_dev,
-                           "Using %d MSI messages\n", msic);
-                       mac->mac_intr_spec = bwn_res_spec_msi;
-                       mac->mac_msi = 1;
-               }
-       }
-
-       error = bus_alloc_resources(dev, mac->mac_intr_spec,
-           mac->mac_res_irq);
-       if (error) {
-               device_printf(sc->sc_dev,
-                   "couldn't allocate IRQ resources (%d)\n", error);
+       /* Allocate IRQ resource. */
+       sc->bwn_irq_rid = 0;
+       sc->bwn_irq_type = pci_alloc_1intr(sc->sc_dev, bwn_msi_enable,
+           &sc->bwn_irq_rid, &irq_flags);
+       if ((sc->bwn_irq = bus_alloc_resource_any(sc->sc_dev, SYS_RES_IRQ,
+           &sc->bwn_irq_rid, irq_flags)) == NULL) {
+               device_printf(sc->sc_dev, "Cannot allocate interrupt\n");
                goto fail1;
        }
-
-       if (mac->mac_msi == 0)
-               error = bus_setup_intr(dev, mac->mac_res_irq[0],
-                   INTR_TYPE_NET | INTR_MPSAFE, bwn_intr, NULL, mac,
-                   &mac->mac_intrhand[0]);
-       else {
-               for (i = 0; i < BWN_MSI_MESSAGES; i++) {
-                       error = bus_setup_intr(dev, mac->mac_res_irq[i],
-                           INTR_TYPE_NET | INTR_MPSAFE, bwn_intr, NULL, mac,
-                           &mac->mac_intrhand[i]);
-                       if (error != 0) {
-                               device_printf(sc->sc_dev,
-                                   "couldn't setup interrupt (%d)\n", error);
-                               break;
-                       }
-               }
+       if (bus_setup_intr(sc->sc_dev, sc->bwn_irq, INTR_MPSAFE,
+               bwn_intr, mac, &sc->bwn_intr, &wlan_global_serializer)) {
+               device_printf(sc->sc_dev, "Cannot set up interrupt\n");
+               return (EINVAL);
        }
 
        TAILQ_INSERT_TAIL(&sc->sc_maclist, mac, mac_list);
@@ -1031,12 +1000,14 @@ bwn_attach(device_t dev)
        if ((sc->sc_flags & BWN_FLAG_ATTACHED) != 0)
                bwn_attach_post(sc);
 
+       wlan_serialize_exit();
        return (0);
 fail1:
-       if (msic == BWN_MSI_MESSAGES && bwn_msi_disable == 0)
+       if (sc->bwn_irq_type == PCI_INTR_TYPE_MSI)
                pci_release_msi(dev);
 fail0:
-       free(mac, M_DEVBUF);
+       kfree(mac, M_DEVBUF);
+       wlan_serialize_exit();
        return (error);
 }
 
@@ -1125,7 +1096,8 @@ bwn_detach(device_t dev)
        struct bwn_mac *mac = sc->sc_curmac;
        struct ifnet *ifp = sc->sc_ifp;
        struct ieee80211com *ic = ifp->if_l2com;
-       int i;
+
+       wlan_serialize_enter();
 
        sc->sc_flags |= BWN_FLAG_INVALID;
 
@@ -1138,27 +1110,34 @@ bwn_detach(device_t dev)
                callout_drain(&sc->sc_watchdog_ch);
                bwn_phy_detach(mac);
                if (ifp != NULL) {
+                       wlan_serialize_exit();
                        ieee80211_draintask(ic, &mac->mac_hwreset);
                        ieee80211_draintask(ic, &mac->mac_txpower);
+                       wlan_serialize_enter();
                        ieee80211_ifdetach(ic);
                        if_free(ifp);
                }
        }
+       wlan_serialize_exit();
        taskqueue_drain(sc->sc_tq, &mac->mac_intrtask);
        taskqueue_free(sc->sc_tq);
+       wlan_serialize_enter();
 
-       for (i = 0; i < BWN_MSI_MESSAGES; i++) {
-               if (mac->mac_intrhand[i] != NULL) {
-                       bus_teardown_intr(dev, mac->mac_res_irq[i],
-                           mac->mac_intrhand[i]);
-                       mac->mac_intrhand[i] = NULL;
-               }
-       }
-       bus_release_resources(dev, mac->mac_intr_spec, mac->mac_res_irq);
-       if (mac->mac_msi != 0)
+       if (sc->bwn_intr)
+               bus_teardown_intr(dev, sc->bwn_irq, sc->bwn_intr);
+       if (sc->bwn_irq != NULL)
+               bus_release_resource(dev, SYS_RES_IRQ, sc->bwn_irq_rid,
+                   sc->bwn_irq);
+
+       if (sc->bwn_irq_type == PCI_INTR_TYPE_MSI)
                pci_release_msi(dev);
 
-       BWN_LOCK_DESTROY(sc);
+       if (sc->sc_sysctl_tree) {
+               sysctl_ctx_free(&sc->sc_sysctl_ctx);
+               sc->sc_sysctl_tree = NULL;
+       }
+
+       wlan_serialize_exit();
        return (0);
 }
 
@@ -1168,15 +1147,14 @@ bwn_attach_pre(struct bwn_softc *sc)
        struct ifnet *ifp;
        int error = 0;
 
-       BWN_LOCK_INIT(sc);
        TAILQ_INIT(&sc->sc_maclist);
-       callout_init_mtx(&sc->sc_rfswitch_ch, &sc->sc_mtx, 0);
-       callout_init_mtx(&sc->sc_task_ch, &sc->sc_mtx, 0);
-       callout_init_mtx(&sc->sc_watchdog_ch, &sc->sc_mtx, 0);
+       callout_init(&sc->sc_rfswitch_ch);
+       callout_init(&sc->sc_task_ch);
+       callout_init(&sc->sc_watchdog_ch);
 
-       sc->sc_tq = taskqueue_create_fast("bwn_taskq", M_NOWAIT,
+       sc->sc_tq = taskqueue_create("bwn_taskq", M_WAITOK,
                taskqueue_thread_enqueue, &sc->sc_tq);
-       taskqueue_start_threads(&sc->sc_tq, 1, PI_NET,
+       taskqueue_start_threads(&sc->sc_tq, 1, TDPRI_KERN_DAEMON, -1,
                "%s taskq", device_get_nameunit(sc->sc_dev));
 
        ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211);
@@ -1190,18 +1168,24 @@ bwn_attach_pre(struct bwn_softc *sc)
        if_initname(ifp, device_get_name(sc->sc_dev),
            device_get_unit(sc->sc_dev));
 
+       /* prepare sysctl tree for use in sub modules */
+       sysctl_ctx_init(&sc->sc_sysctl_ctx);
+       sc->sc_sysctl_tree = SYSCTL_ADD_NODE(&sc->sc_sysctl_ctx,
+               SYSCTL_STATIC_CHILDREN(_hw),
+               OID_AUTO,
+               device_get_nameunit(sc->sc_dev),
+               CTLFLAG_RD, 0, "");
+
        ifp->if_softc = sc;
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
        ifp->if_init = bwn_init;
        ifp->if_ioctl = bwn_ioctl;
        ifp->if_start = bwn_start;
-       IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
-       ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
-       IFQ_SET_READY(&ifp->if_snd);
+       ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
 
        return (0);
 
-fail:  BWN_LOCK_DESTROY(sc);
+fail:
        return (error);
 }
 
@@ -1238,10 +1222,11 @@ bwn_sprom_bugfixes(device_t dev)
 }
 
 static int
-bwn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+bwn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data,
+         struct ucred *cr __unused)
 {
-#define        IS_RUNNING(ifp) \
-       ((ifp->if_flags & IFF_UP) && (ifp->if_drv_flags & IFF_DRV_RUNNING))
+#define IS_RUNNING(ifp) \
+        ((ifp->if_flags & IFF_UP) && (ifp->if_flags & IFF_RUNNING))
        struct bwn_softc *sc = ifp->if_softc;
        struct ieee80211com *ic = ifp->if_l2com;
        struct ifreq *ifr = (struct ifreq *)data;
@@ -1276,13 +1261,10 @@ bwn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 }
 
 static void
-bwn_start(struct ifnet *ifp)
+bwn_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
 {
-       struct bwn_softc *sc = ifp->if_softc;
-
-       BWN_LOCK(sc);
+       wlan_assert_serialized();
        bwn_start_locked(ifp);
-       BWN_UNLOCK(sc);
 }
 
 static void
@@ -1295,14 +1277,14 @@ bwn_start_locked(struct ifnet *ifp)
        struct ieee80211_key *k;
        struct mbuf *m;
 
-       BWN_ASSERT_LOCKED(sc);
+       wlan_assert_serialized();
 
-       if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || mac == NULL ||
+       if ((ifp->if_flags & IFF_RUNNING) == 0 || mac == NULL ||
            mac->mac_status < BWN_MAC_STATUS_STARTED)
                return;
 
        for (;;) {
-               IFQ_DRV_DEQUEUE(&ifp->if_snd, m);       /* XXX: LOCK */
+               m = ifq_dequeue(&ifp->if_snd);  /* XXX: LOCK */
                if (m == NULL)
                        break;
 
@@ -1317,7 +1299,7 @@ bwn_start_locked(struct ifnet *ifp)
                }
                KASSERT(ni != NULL, ("%s:%d: fail", __func__, __LINE__));
                wh = mtod(m, struct ieee80211_frame *);
-               if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
+               if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
                        k = ieee80211_crypto_encap(ni, m);
                        if (k == NULL) {
                                ieee80211_free_node(ni);
@@ -1348,8 +1330,6 @@ bwn_tx_isfull(struct bwn_softc *sc, struct mbuf *m)
        struct ifnet *ifp = sc->sc_ifp;
        int pktlen = roundup(m->m_pkthdr.len + BWN_HDRSIZE(mac), 4);
 
-       BWN_ASSERT_LOCKED(sc);
-
        if (mac->mac_flags & BWN_MAC_FLAG_DMA) {
                dr = bwn_dma_select(mac, M_WME_GETAC(m));
                if (dr->dr_stop == 1 ||
@@ -1367,8 +1347,8 @@ bwn_tx_isfull(struct bwn_softc *sc, struct mbuf *m)
        }
        return (0);
 full:
-       IFQ_DRV_PREPEND(&ifp->if_snd, m);
-       ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+       ifq_prepend(&ifp->if_snd, m);
+       ifq_set_oactive(&ifp->if_snd);
        return (1);
 }
 
@@ -1378,8 +1358,6 @@ bwn_tx_start(struct bwn_softc *sc, struct ieee80211_node *ni, struct mbuf *m)
        struct bwn_mac *mac = sc->sc_curmac;
        int error;
 
-       BWN_ASSERT_LOCKED(sc);
-
        if (m->m_pkthdr.len < IEEE80211_MIN_LEN || mac == NULL) {
                m_freem(m);
                return (ENXIO);
@@ -1406,8 +1384,6 @@ bwn_pio_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni, struct mbuf *m)
        int error;
        uint16_t ctl16;
 
-       BWN_ASSERT_LOCKED(sc);
-
        /* XXX TODO send packets after DTIM */
 
        KASSERT(!TAILQ_EMPTY(&tq->tq_pktlist), ("%s: fail", __func__));
@@ -1429,7 +1405,7 @@ bwn_pio_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni, struct mbuf *m)
                /*
                 * XXX please removes m_defrag(9)
                 */
-               m_new = m_defrag(m, M_NOWAIT);
+               m_new = m_defrag(m, M_INTWAIT);
                if (m_new == NULL) {
                        device_printf(sc->sc_dev,
                            "%s: can't defrag TX buffer\n",
@@ -1489,7 +1465,7 @@ static int
 bwn_dma_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni, struct mbuf *m)
 {
 #define        BWN_GET_TXHDRCACHE(slot)                                        \
-       &(txhdr_cache[(slot / BWN_TX_SLOTS_PER_FRAME) * BWN_HDRSIZE(mac)])
+       &(txhdr_cache[(slot / BWN_TX_SLOTS_PER_FRAME) * BWN_MAX_HDRSIZE(mac)])
        struct bwn_dma *dma = &mac->mac_method.dma;
        struct bwn_dma_ring *dr = bwn_dma_select(mac, M_WME_GETAC(m));
        struct bwn_dmadesc_generic *desc;
@@ -1499,7 +1475,6 @@ bwn_dma_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni, struct mbuf *m)
        uint8_t *txhdr_cache = (uint8_t *)dr->dr_txhdr_cache;
        int error, slot, backup[2] = { dr->dr_curslot, dr->dr_usedslot };
 
-       BWN_ASSERT_LOCKED(sc);
        KASSERT(!dr->dr_stop, ("%s:%d: fail", __func__, __LINE__));
 
        /* XXX send after DTIM */
@@ -1514,14 +1489,6 @@ bwn_dma_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni, struct mbuf *m)
            BWN_DMA_COOKIE(dr, slot));
        if (error)
                goto fail;
-       error = bus_dmamap_load(dr->dr_txring_dtag, mt->mt_dmap,
-           BWN_GET_TXHDRCACHE(slot), BWN_HDRSIZE(mac), bwn_dma_ring_addr,
-           &mt->mt_paddr, BUS_DMA_NOWAIT);
-       if (error) {
-               if_printf(ifp, "%s: can't load TX buffer (1) %d\n",
-                   __func__, error);
-               goto fail;
-       }
        bus_dmamap_sync(dr->dr_txring_dtag, mt->mt_dmap,
            BUS_DMASYNC_PREWRITE);
        dr->setdesc(dr, desc, mt->mt_paddr, BWN_HDRSIZE(mac), 1, 0, 0);
@@ -1545,7 +1512,7 @@ bwn_dma_tx_start(struct bwn_mac *mac, struct ieee80211_node *ni, struct mbuf *m)
        if (error) {    /* error == EFBIG */
                struct mbuf *m_new;
 
-               m_new = m_defrag(m, M_NOWAIT);
+               m_new = m_defrag(m, M_INTWAIT);
                if (m_new == NULL) {
                        if_printf(ifp, "%s: can't defrag TX buffer\n",
                            __func__);
@@ -1586,11 +1553,14 @@ bwn_watchdog(void *arg)
        struct bwn_softc *sc = arg;
        struct ifnet *ifp = sc->sc_ifp;
 
+       wlan_serialize_enter();
+
        if (sc->sc_watchdog_timer != 0 && --sc->sc_watchdog_timer == 0) {
                if_printf(ifp, "device timeout\n");
                ifp->if_oerrors++;
        }
-       callout_schedule(&sc->sc_watchdog_ch, hz);
+       callout_reset(&sc->sc_watchdog_ch, hz, bwn_watchdog, sc);
+       wlan_serialize_exit();
 }
 
 static int
@@ -1701,7 +1671,10 @@ bwn_attach_core(struct bwn_mac *mac)
        if (sc->sc_curmac == NULL)
                sc->sc_curmac = mac;
 
+       wlan_assert_serialized();
+       wlan_serialize_exit();
        error = bwn_dma_attach(mac);
+       wlan_serialize_enter();
        if (error != 0) {
                device_printf(sc->sc_dev, "failed to initialize DMA\n");
                goto fail;
@@ -1816,8 +1789,6 @@ bwn_chiptest(struct bwn_mac *mac)
        struct bwn_softc *sc = mac->mac_sc;
        uint32_t v, backup;
 
-       BWN_LOCK(sc);
-
        backup = bwn_shm_read_4(mac, BWN_SHARED, 0);
 
        bwn_shm_write_4(mac, BWN_SHARED, 0, TESTVAL0);
@@ -1844,10 +1815,8 @@ bwn_chiptest(struct bwn_mac *mac)
        if (v != (BWN_MACCTL_GMODE | BWN_MACCTL_IHR_ON))
                goto error;
 
-       BWN_UNLOCK(sc);
        return (0);
 error:
-       BWN_UNLOCK(sc);
        device_printf(sc->sc_dev, "failed to validate the chipaccess\n");
        return (ENODEV);
 }
@@ -1891,8 +1860,6 @@ bwn_shm_read_4(struct bwn_mac *mac, uint16_t way, uint16_t offset)
 {
        uint32_t ret;
 
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        if (way == BWN_SHARED) {
                KASSERT((offset & 0x0001) == 0,
                    ("%s:%d warn", __func__, __LINE__));
@@ -1917,8 +1884,6 @@ bwn_shm_read_2(struct bwn_mac *mac, uint16_t way, uint16_t offset)
 {
        uint16_t ret;
 
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        if (way == BWN_SHARED) {
                KASSERT((offset & 0x0001) == 0,
                    ("%s:%d warn", __func__, __LINE__));
@@ -1952,8 +1917,6 @@ static void
 bwn_shm_write_4(struct bwn_mac *mac, uint16_t way, uint16_t offset,
     uint32_t value)
 {
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        if (way == BWN_SHARED) {
                KASSERT((offset & 0x0001) == 0,
                    ("%s:%d warn", __func__, __LINE__));
@@ -1975,8 +1938,6 @@ static void
 bwn_shm_write_2(struct bwn_mac *mac, uint16_t way, uint16_t offset,
     uint16_t value)
 {
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        if (way == BWN_SHARED) {
                KASSERT((offset & 0x0001) == 0,
                    ("%s:%d warn", __func__, __LINE__));
@@ -2080,11 +2041,7 @@ bwn_phy_g_attach(struct bwn_mac *mac)
        }
 
        pg->pg_idletssi = (bg == 0 || bg == -1) ? 62 : bg;
-       pg->pg_tssi2dbm = (uint8_t *)malloc(64, M_DEVBUF, M_NOWAIT | M_ZERO);
-       if (pg->pg_tssi2dbm == NULL) {
-               device_printf(sc->sc_dev, "failed to allocate buffer\n");
-               return (ENOMEM);
-       }
+       pg->pg_tssi2dbm = (uint8_t *)kmalloc(64, M_DEVBUF, M_INTWAIT | M_ZERO);
        for (i = 0; i < 64; i++) {
                int32_t m1, m2, f, q, delta;
                int8_t j = 0;
@@ -2097,7 +2054,7 @@ bwn_phy_g_attach(struct bwn_mac *mac)
                        if (j > 15) {
                                device_printf(sc->sc_dev,
                                    "failed to generate tssi2dBm\n");
-                               free(pg->pg_tssi2dbm, M_DEVBUF);
+                               kfree(pg->pg_tssi2dbm, M_DEVBUF);
                                return (ENOMEM);
                        }
                        q = BWN_TSSI2DBM(f * 4096 - BWN_TSSI2DBM(m2 * f, 16) *
@@ -2121,7 +2078,7 @@ bwn_phy_g_detach(struct bwn_mac *mac)
        struct bwn_phy_g *pg = &mac->mac_phy.phy_g;
 
        if (pg->pg_flags & BWN_PHY_G_FLAG_TSSITABLE_ALLOC) {
-               free(pg->pg_tssi2dbm, M_DEVBUF);
+               kfree(pg->pg_tssi2dbm, M_DEVBUF);
                pg->pg_tssi2dbm = NULL;
        }
        pg->pg_flags = 0;
@@ -2362,9 +2319,9 @@ bwn_phy_g_exit(struct bwn_mac *mac)
 
        if (lo == NULL)
                return;
-       TAILQ_FOREACH_SAFE(cal, &lo->calib_list, list, tmp) {
+       TAILQ_FOREACH_MUTABLE(cal, &lo->calib_list, list, tmp) {
                TAILQ_REMOVE(&lo->calib_list, cal, list);
-               free(cal, M_DEVBUF);
+               kfree(cal, M_DEVBUF);
        }
 }
 
@@ -2596,8 +2553,6 @@ bwn_phy_g_set_txpwr(struct bwn_mac *mac)
 
        bwn_mac_suspend(mac);
 
-       BWN_ASSERT_LOCKED(sc);
-
        bbatt = pg->pg_bbatt.att;
        bbatt += pg->pg_bbatt_delta;
        rfatt = pg->pg_rfatt.att;
@@ -2671,7 +2626,7 @@ bwn_phy_g_task_15s(struct bwn_mac *mac)
        }
 
        expire = now - BWN_LO_CALIB_EXPIRE;
-       TAILQ_FOREACH_SAFE(cal, &lo->calib_list, list, tmp) {
+       TAILQ_FOREACH_MUTABLE(cal, &lo->calib_list, list, tmp) {
                if (!time_before(cal->calib_time, expire))
                        continue;
                if (BWN_BBATTCMP(&cal->bbatt, &pg->pg_bbatt) &&
@@ -2685,12 +2640,12 @@ bwn_phy_g_task_15s(struct bwn_mac *mac)
                    cal->ctl.i, cal->ctl.q);
 
                TAILQ_REMOVE(&lo->calib_list, cal, list);
-               free(cal, M_DEVBUF);
+               kfree(cal, M_DEVBUF);
        }
        if (expired || TAILQ_EMPTY(&lo->calib_list)) {
                cal = bwn_lo_calibset(mac, &pg->pg_bbatt,
                    &pg->pg_rfatt);
-               if (cal == NULL) {
+               if (cal == NULL) {      /* XXX ivadasz: can't happen */
                        device_printf(sc->sc_dev,
                            "failed to recalibrate LO\n");
                        goto fail;
@@ -2738,19 +2693,17 @@ bwn_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
        struct bwn_softc *sc = ifp->if_softc;
        struct bwn_mac *mac = sc->sc_curmac;
 
-       if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
+       if ((ifp->if_flags & IFF_RUNNING) == 0 ||
            mac->mac_status < BWN_MAC_STATUS_STARTED) {
                ieee80211_free_node(ni);
                m_freem(m);
                return (ENETDOWN);
        }
 
-       BWN_LOCK(sc);
        if (bwn_tx_isfull(sc, m)) {
                ieee80211_free_node(ni);
                m_freem(m);
                ifp->if_oerrors++;
-               BWN_UNLOCK(sc);
                return (ENOBUFS);
        }
 
@@ -2760,7 +2713,6 @@ bwn_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
                ifp->if_oerrors++;
        }
        sc->sc_watchdog_timer = 5;
-       BWN_UNLOCK(sc);
        return (0);
 }
 
@@ -2777,13 +2729,11 @@ bwn_updateslot(struct ifnet *ifp)
        struct ieee80211com *ic = ifp->if_l2com;
        struct bwn_mac *mac;
 
-       BWN_LOCK(sc);
-       if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+       if (ifp->if_flags & IFF_RUNNING) {
                mac = (struct bwn_mac *)sc->sc_curmac;
                bwn_set_slot_time(mac,
                    (ic->ic_flags & IEEE80211_F_SHSLOT) ? 9 : 20);
        }
-       BWN_UNLOCK(sc);
 }
 
 /*
@@ -2799,7 +2749,6 @@ bwn_update_promisc(struct ifnet *ifp)
        struct bwn_softc *sc = ifp->if_softc;
        struct bwn_mac *mac = sc->sc_curmac;
 
-       BWN_LOCK(sc);
        mac = sc->sc_curmac;
        if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
                if (ifp->if_flags & IFF_PROMISC)
@@ -2808,7 +2757,6 @@ bwn_update_promisc(struct ifnet *ifp)
                        sc->sc_filters &= ~BWN_MACCTL_PROMISC;
                bwn_set_opmode(mac);
        }
-       BWN_UNLOCK(sc);
 }
 
 /*
@@ -2822,7 +2770,6 @@ bwn_wme_update(struct ieee80211com *ic)
        struct wmeParams *wmep;
        int i;
 
-       BWN_LOCK(sc);
        mac = sc->sc_curmac;
        if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
                bwn_mac_suspend(mac);
@@ -2832,7 +2779,6 @@ bwn_wme_update(struct ieee80211com *ic)
                }
                bwn_mac_enable(mac);
        }
-       BWN_UNLOCK(sc);
        return (0);
 }
 
@@ -2843,7 +2789,6 @@ bwn_scan_start(struct ieee80211com *ic)
        struct bwn_softc *sc = ifp->if_softc;
        struct bwn_mac *mac;
 
-       BWN_LOCK(sc);
        mac = sc->sc_curmac;
        if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
                sc->sc_filters |= BWN_MACCTL_BEACON_PROMISC;
@@ -2851,7 +2796,6 @@ bwn_scan_start(struct ieee80211com *ic)
                /* disable CFP update during scan */
                bwn_hf_write(mac, bwn_hf_read(mac) | BWN_HF_SKIP_CFP_UPDATE);
        }
-       BWN_UNLOCK(sc);
 }
 
 static void
@@ -2861,14 +2805,12 @@ bwn_scan_end(struct ieee80211com *ic)
        struct bwn_softc *sc = ifp->if_softc;
        struct bwn_mac *mac;
 
-       BWN_LOCK(sc);
        mac = sc->sc_curmac;
        if (mac != NULL && mac->mac_status >= BWN_MAC_STATUS_INITED) {
                sc->sc_filters &= ~BWN_MACCTL_BEACON_PROMISC;
                bwn_set_opmode(mac);
                bwn_hf_write(mac, bwn_hf_read(mac) & ~BWN_HF_SKIP_CFP_UPDATE);
        }
-       BWN_UNLOCK(sc);
 }
 
 static void
@@ -2880,8 +2822,6 @@ bwn_set_channel(struct ieee80211com *ic)
        struct bwn_phy *phy = &mac->mac_phy;
        int chan, error;
 
-       BWN_LOCK(sc);
-
        error = bwn_switch_band(sc, ic->ic_curchan);
        if (error)
                goto fail;
@@ -2923,8 +2863,6 @@ fail:
                htole16(ic->ic_curchan->ic_freq);
        sc->sc_tx_th.wt_chan_flags = sc->sc_rx_th.wr_chan_flags =
                htole16(ic->ic_curchan->ic_flags & 0xffff);
-
-       BWN_UNLOCK(sc);
 }
 
 static struct ieee80211vap *
@@ -2939,6 +2877,9 @@ bwn_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
        struct bwn_vap *bvp;
        uint8_t mac[IEEE80211_ADDR_LEN];
 
+       if (!TAILQ_EMPTY(&ic->ic_vaps))         /* only one at a time */
+               return NULL;
+
        IEEE80211_ADDR_COPY(mac, mac0);
        switch (opmode) {
        case IEEE80211_M_HOSTAP:
@@ -2955,12 +2896,8 @@ bwn_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
 
        IEEE80211_ADDR_COPY(sc->sc_macaddr, mac0);
 
-       bvp = (struct bwn_vap *) malloc(sizeof(struct bwn_vap),
-           M_80211_VAP, M_NOWAIT | M_ZERO);
-       if (bvp == NULL) {
-               device_printf(sc->sc_dev, "failed to allocate a buffer\n");
-               return (NULL);
-       }
+       bvp = (struct bwn_vap *) kmalloc(sizeof(struct bwn_vap),
+           M_80211_VAP, M_INTWAIT | M_ZERO);
        vap = &bvp->bv_vap;
        ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac);
        IEEE80211_ADDR_COPY(vap->iv_myaddr, mac);
@@ -2976,6 +2913,7 @@ bwn_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
        /* complete setup */
        ieee80211_vap_attach(vap, ieee80211_media_change,
            ieee80211_media_status);
+       ic->ic_opmode = opmode;
        return (vap);
 }
 
@@ -2986,7 +2924,7 @@ bwn_vap_delete(struct ieee80211vap *vap)
 
        ieee80211_ratectl_deinit(vap);
        ieee80211_vap_detach(vap);
-       free(bvp, M_80211_VAP);
+       kfree(bvp, M_80211_VAP);
 }
 
 static void
@@ -3000,9 +2938,8 @@ bwn_init(void *arg)
        DPRINTF(sc, BWN_DEBUG_ANY, "%s: if_flags 0x%x\n",
                __func__, ifp->if_flags);
 
-       BWN_LOCK(sc);
+       wlan_assert_serialized();
        error = bwn_init_locked(sc);
-       BWN_UNLOCK(sc);
 
        if (error == 0)
                ieee80211_start_all(ic);        /* start all vap's */
@@ -3015,8 +2952,6 @@ bwn_init_locked(struct bwn_softc *sc)
        struct ifnet *ifp = sc->sc_ifp;
        int error;
 
-       BWN_ASSERT_LOCKED(sc);
-
        bzero(sc->sc_bssid, IEEE80211_ADDR_LEN);
        sc->sc_flags |= BWN_FLAG_NEED_BEACON_TP;
        sc->sc_filters = 0;
@@ -3038,7 +2973,7 @@ bwn_init_locked(struct bwn_softc *sc)
        bwn_spu_setdelay(mac, 0);
        bwn_set_macaddr(mac);
 
-       ifp->if_drv_flags |= IFF_DRV_RUNNING;
+       ifp->if_flags |= IFF_RUNNING;
        callout_reset(&sc->sc_rfswitch_ch, hz, bwn_rfswitch, sc);
        callout_reset(&sc->sc_watchdog_ch, hz, bwn_watchdog, sc);
 
@@ -3049,9 +2984,8 @@ static void
 bwn_stop(struct bwn_softc *sc, int statechg)
 {
 
-       BWN_LOCK(sc);
+       wlan_assert_serialized();
        bwn_stop_locked(sc, statechg);
-       BWN_UNLOCK(sc);
 }
 
 static void
@@ -3060,8 +2994,6 @@ bwn_stop_locked(struct bwn_softc *sc, int statechg)
        struct bwn_mac *mac = sc->sc_curmac;
        struct ifnet *ifp = sc->sc_ifp;
 
-       BWN_ASSERT_LOCKED(sc);
-
        if (mac->mac_status >= BWN_MAC_STATUS_INITED) {
                /* XXX FIXME opmode not based on VAP */
                bwn_set_opmode(mac);
@@ -3077,7 +3009,8 @@ bwn_stop_locked(struct bwn_softc *sc, int statechg)
        bwn_core_exit(mac);
        sc->sc_rf_enabled = 0;
 
-       ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
+       ifp->if_flags &= ~IFF_RUNNING;
+       ifq_clr_oactive(&ifp->if_snd);
 }
 
 static void
@@ -3269,7 +3202,7 @@ bwn_core_exit(struct bwn_mac *mac)
        struct bwn_softc *sc = mac->mac_sc;
        uint32_t macctl;
 
-       BWN_ASSERT_LOCKED(mac->mac_sc);
+       wlan_assert_serialized();
 
        KASSERT(mac->mac_status <= BWN_MAC_STATUS_INITED,
            ("%s:%d: fail", __func__, __LINE__));
@@ -3752,17 +3685,13 @@ bwn_dma_ringsetup(struct bwn_mac *mac, int controller_index,
        struct bwn_softc *sc = mac->mac_sc;
        int error, i;
 
-       dr = malloc(sizeof(*dr), M_DEVBUF, M_NOWAIT | M_ZERO);
-       if (dr == NULL)
-               goto out;
+       dr = kmalloc(sizeof(*dr), M_DEVBUF, M_INTWAIT | M_ZERO);
        dr->dr_numslots = BWN_RXRING_SLOTS;
        if (for_tx)
                dr->dr_numslots = BWN_TXRING_SLOTS;
 
-       dr->dr_meta = malloc(dr->dr_numslots * sizeof(struct bwn_dmadesc_meta),
-           M_DEVBUF, M_NOWAIT | M_ZERO);
-       if (dr->dr_meta == NULL)
-               goto fail0;
+       dr->dr_meta = kmalloc(dr->dr_numslots * sizeof(struct bwn_dmadesc_meta),
+           M_DEVBUF, M_INTWAIT | M_ZERO);
 
        dr->dr_type = type;
        dr->dr_mac = mac;
@@ -3798,7 +3727,7 @@ bwn_dma_ringsetup(struct bwn_mac *mac, int controller_index,
 
        error = bwn_dma_allocringmemory(dr);
        if (error)
-               goto fail2;
+               goto fail1;
 
        if (for_tx) {
                /*
@@ -3808,29 +3737,18 @@ bwn_dma_ringsetup(struct bwn_mac *mac, int controller_index,
                KASSERT(BWN_TXRING_SLOTS % BWN_TX_SLOTS_PER_FRAME == 0,
                    ("%s:%d: fail", __func__, __LINE__));
 
-               dr->dr_txhdr_cache =
-                   malloc((dr->dr_numslots / BWN_TX_SLOTS_PER_FRAME) *
-                       BWN_HDRSIZE(mac), M_DEVBUF, M_NOWAIT | M_ZERO);
-               KASSERT(dr->dr_txhdr_cache != NULL,
-                   ("%s:%d: fail", __func__, __LINE__));
-
                /*
                 * Create TX ring DMA stuffs
                 */
-               error = bus_dma_tag_create(dma->parent_dtag,
-                                   BWN_ALIGN, 0,
-                                   BUS_SPACE_MAXADDR,
-                                   BUS_SPACE_MAXADDR,
-                                   NULL, NULL,
-                                   BWN_HDRSIZE(mac),
-                                   1,
-                                   BUS_SPACE_MAXSIZE_32BIT,
-                                   0,
-                                   NULL, NULL,
-                                   &dr->dr_txring_dtag);
-               if (error) {
+               dr->dr_txhdr_cache = bus_dmamem_coherent_any(dma->parent_dtag,
+                   4, (dr->dr_numslots / BWN_TX_SLOTS_PER_FRAME) *
+                   BWN_MAX_HDRSIZE(mac),
+                   BUS_DMA_WAITOK | BUS_DMA_ZERO,
+                   &dr->dr_txring_dtag, &dr->dr_txring_dmap,
+                   &dr->dr_txring_paddr);
+               if (dr->dr_txhdr_cache == NULL) {
                        device_printf(sc->sc_dev,
-                           "can't create TX ring DMA tag: TODO frees\n");
+                           "can't create TX ring DMA memory\n");
                        goto fail1;
                }
 
@@ -3841,13 +3759,10 @@ bwn_dma_ringsetup(struct bwn_mac *mac, int controller_index,
                        mt->mt_m = NULL;
                        mt->mt_ni = NULL;
                        mt->mt_islast = 0;
-                       error = bus_dmamap_create(dr->dr_txring_dtag, 0,
-                           &mt->mt_dmap);
-                       if (error) {
-                               device_printf(sc->sc_dev,
-                                    "can't create RX buf DMA map\n");
-                               goto fail1;
-                       }
+                       mt->mt_dmap = dr->dr_txring_dmap;
+                       mt->mt_paddr = dr->dr_txring_paddr +
+                           (i / BWN_TX_SLOTS_PER_FRAME) *
+                           BWN_MAX_HDRSIZE(mac);
 
                        dr->getdesc(dr, i + 1, &desc, &mt);
 
@@ -3860,7 +3775,7 @@ bwn_dma_ringsetup(struct bwn_mac *mac, int controller_index,
                        if (error) {
                                device_printf(sc->sc_dev,
                                     "can't create RX buf DMA map\n");
-                               goto fail1;
+                               goto fail2;
                        }
                }
        } else {
@@ -3900,11 +3815,10 @@ bwn_dma_ringsetup(struct bwn_mac *mac, int controller_index,
        return (dr);
 
 fail2:
-       free(dr->dr_txhdr_cache, M_DEVBUF);
+       /* XXX free up dma allocations */
 fail1:
-       free(dr->dr_meta, M_DEVBUF);
-fail0:
-       free(dr, M_DEVBUF);
+       kfree(dr->dr_meta, M_DEVBUF);
+       kfree(dr, M_DEVBUF);
        return (NULL);
 }
 
@@ -3918,9 +3832,9 @@ bwn_dma_ringfree(struct bwn_dma_ring **dr)
        bwn_dma_free_descbufs(*dr);
        bwn_dma_free_ringmemory(*dr);
 
-       free((*dr)->dr_txhdr_cache, M_DEVBUF);
-       free((*dr)->dr_meta, M_DEVBUF);
-       free(*dr, M_DEVBUF);
+       if ((*dr)->dr_meta != NULL)
+               kfree((*dr)->dr_meta, M_DEVBUF);
+       kfree(*dr, M_DEVBUF);
 
        *dr = NULL;
 }
@@ -4126,7 +4040,6 @@ bwn_dma_allocringmemory(struct bwn_dma_ring *dr)
                            1,
                            BUS_SPACE_MAXSIZE_32BIT,
                            0,
-                           NULL, NULL,
                            &dr->dr_ring_dtag);
        if (error) {
                device_printf(sc->sc_dev,
@@ -4144,7 +4057,7 @@ bwn_dma_allocringmemory(struct bwn_dma_ring *dr)
        }
        error = bus_dmamap_load(dr->dr_ring_dtag, dr->dr_ring_dmap,
            dr->dr_ring_descbase, BWN_DMA_RINGMEMSIZE,
-           bwn_dma_ring_addr, &dr->dr_ring_dmabase, BUS_DMA_NOWAIT);
+           bwn_dma_ring_addr, &dr->dr_ring_dmabase, 0);
        if (error) {
                device_printf(sc->sc_dev,
                    "can't load DMA mem: TODO free\n");
@@ -4229,9 +4142,17 @@ static void
 bwn_dma_free_ringmemory(struct bwn_dma_ring *dr)
 {
 
+       if (dr->dr_tx) {
+               bus_dmamap_unload(dr->dr_txring_dtag, dr->dr_txring_dmap);
+               if (dr->dr_txhdr_cache != NULL)
+                       bus_dmamem_free(dr->dr_txring_dtag, dr->dr_txhdr_cache,
+                           dr->dr_txring_dmap);
+               bus_dma_tag_destroy(dr->dr_txring_dtag);
+       }
        bus_dmamap_unload(dr->dr_ring_dtag, dr->dr_ring_dmap);
        bus_dmamem_free(dr->dr_ring_dtag, dr->dr_ring_descbase,
            dr->dr_ring_dmap);
+       bus_dma_tag_destroy(dr->dr_ring_dtag);
 }
 
 static void
@@ -4277,12 +4198,12 @@ bwn_dma_free_descbufs(struct bwn_dma_ring *dr)
                        continue;
                }
                if (dr->dr_tx) {
-                       if (meta->mt_txtype == BWN_DMADESC_METATYPE_HEADER)
-                               bus_dmamap_unload(dr->dr_txring_dtag,
-                                   meta->mt_dmap);
-                       else if (meta->mt_txtype == BWN_DMADESC_METATYPE_BODY)
+                       if (meta->mt_txtype == BWN_DMADESC_METATYPE_HEADER) {
+                               /* Nothing */
+                       } else if (meta->mt_txtype == BWN_DMADESC_METATYPE_BODY) {
                                bus_dmamap_unload(dma->txbuf_dtag,
                                    meta->mt_dmap);
+                       }
                } else
                        bus_dmamap_unload(dma->rxbuf_dtag, meta->mt_dmap);
                bwn_dma_free_descbuf(dr, meta);
@@ -5807,8 +5728,6 @@ bwn_dummy_transmission(struct bwn_mac *mac, int ofdm, int paon)
                buffer[0] = 0x000b846e;
        }
 
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        for (i = 0; i < 5; i++)
                bwn_ram_write(mac, i * 4, buffer[i]);
 
@@ -5863,7 +5782,7 @@ bwn_ram_write(struct bwn_mac *mac, uint16_t offset, uint32_t val)
 
        macctl = BWN_READ_4(mac, BWN_MACCTL);
        if (macctl & BWN_MACCTL_BIGENDIAN)
-               printf("TODO: need swap\n");
+               kprintf("TODO: need swap\n");
 
        BWN_WRITE_4(mac, BWN_RAM_CONTROL, offset);
        BWN_BARRIER(mac, BUS_SPACE_BARRIER_WRITE);
@@ -6496,11 +6415,7 @@ bwn_lo_calibset(struct bwn_mac *mac,
        bwn_lo_restore(mac, &sval);
        bwn_mac_enable(mac);
 
-       cal = malloc(sizeof(*cal), M_DEVBUF, M_NOWAIT | M_ZERO);
-       if (!cal) {
-               device_printf(mac->mac_sc->sc_dev, "out of memory\n");
-               return (NULL);
-       }
+       cal = kmalloc(sizeof(*cal), M_DEVBUF, M_INTWAIT | M_ZERO);
        memcpy(&cal->bbatt, bbatt, sizeof(*bbatt));
        memcpy(&cal->rfatt, rfatt, sizeof(*rfatt));
        memcpy(&cal->ctl, &loctl, sizeof(loctl));
@@ -6526,7 +6441,7 @@ bwn_lo_get_calib(struct bwn_mac *mac, const struct bwn_bbatt *bbatt,
        }
 
        c = bwn_lo_calibset(mac, bbatt, rfatt);
-       if (!c)
+       if (c == NULL)  /* XXX ivadasz: can't happen */
                return (NULL);
        TAILQ_INSERT_TAIL(&lo->calib_list, c, list);
 
@@ -6570,14 +6485,14 @@ bwn_phy_g_dc_lookup_init(struct bwn_mac *mac, uint8_t update)
                rfatt = &(lo->rfatt.array[rf_offset]);
 
                cal = bwn_lo_calibset(mac, bbatt, rfatt);
-               if (!cal) {
+               if (cal == NULL) {      /* XXX ivadasz: can't happen */
                        device_printf(sc->sc_dev, "LO: Could not "
                            "calibrate DC table entry\n");
                        continue;
                }
                val = (uint8_t)(cal->ctl.q);
                val |= ((uint8_t)(cal->ctl.i)) << 4;
-               free(cal, M_DEVBUF);
+               kfree(cal, M_DEVBUF);
 
                idx = i / 2;
                if (i % 2)
@@ -6616,7 +6531,7 @@ bwn_lo_g_adjust(struct bwn_mac *mac)
        bwn_lo_fixup_rfatt(&rf);
 
        cal = bwn_lo_get_calib(mac, &pg->pg_bbatt, &rf);
-       if (!cal)
+       if (cal == NULL)        /* XXX ivadasz: can't happen */
                return;
        bwn_lo_write(mac, &cal->ctl);
 }
@@ -7704,11 +7619,13 @@ bwn_fw_get(struct bwn_mac *mac, enum bwn_fwtype type,
                bwn_do_release_fw(bfw);
        }
 
-       snprintf(namebuf, sizeof(namebuf), "bwn%s_v4_%s%s",
+       ksnprintf(namebuf, sizeof(namebuf), "bwn%s_v4_%s%s",
            (type == BWN_FWTYPE_OPENSOURCE) ? "-open" : "",
            (mac->mac_phy.type == BWN_PHYTYPE_LP) ? "lp_" : "", name);
-       /* XXX Sleeping on "fwload" with the non-sleepable locks held */
+       wlan_assert_serialized();
+       wlan_serialize_exit();
        fw = firmware_get(namebuf);
+       wlan_serialize_enter();
        if (fw == NULL) {
                device_printf(sc->sc_dev, "the fw file(%s) not found\n",
                    namebuf);
@@ -7819,7 +7736,7 @@ bwn_fw_loaducode(struct bwn_mac *mac)
                        error = ENXIO;
                        goto error;
                }
-               DELAY(50000);
+               tsleep(sc, 0, "bwndelay", (50 * hz) / 1000);
        }
        BWN_READ_4(mac, BWN_INTR_REASON);
 
@@ -8075,7 +7992,7 @@ bwn_mac_setfilter(struct bwn_mac *mac, uint16_t offset,
        static const uint8_t zero[IEEE80211_ADDR_LEN] = { 0 };
        uint16_t data;
 
-       if (!mac)
+       if (mac == NULL)
                macaddr = zero;
 
        offset |= 0x0020;
@@ -8205,7 +8122,7 @@ bwn_core_stop(struct bwn_mac *mac)
 {
        struct bwn_softc *sc = mac->mac_sc;
 
-       BWN_ASSERT_LOCKED(sc);
+       wlan_assert_serialized();
 
        if (mac->mac_status < BWN_MAC_STATUS_STARTED)
                return;
@@ -8230,8 +8147,6 @@ bwn_switch_band(struct bwn_softc *sc, struct ieee80211_channel *chan)
        int err, status;
        uint8_t gmode;
 
-       BWN_ASSERT_LOCKED(sc);
-
        TAILQ_FOREACH(mac, &sc->sc_maclist, mac_list) {
                if (IEEE80211_IS_CHAN_2GHZ(chan) &&
                    mac->mac_phy.supports_2ghz) {
@@ -8343,8 +8258,6 @@ bwn_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
        if (error != 0)
                return (error);
 
-       BWN_LOCK(sc);
-
        bwn_led_newstate(mac, nstate);
 
        /*
@@ -8377,8 +8290,6 @@ bwn_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
                bwn_set_macaddr(mac);
        }
 
-       BWN_UNLOCK(sc);
-
        return (error);
 }
 
@@ -8397,7 +8308,7 @@ bwn_set_pretbtt(struct bwn_mac *mac)
        BWN_WRITE_2(mac, BWN_TSF_CFP_PRETBTT, pretbtt);
 }
 
-static int
+static void
 bwn_intr(void *arg)
 {
        struct bwn_mac *mac = arg;
@@ -8406,14 +8317,14 @@ bwn_intr(void *arg)
 
        if (mac->mac_status < BWN_MAC_STATUS_STARTED ||
            (sc->sc_flags & BWN_FLAG_INVALID))
-               return (FILTER_STRAY);
+               return;
 
        reason = BWN_READ_4(mac, BWN_INTR_REASON);
        if (reason == 0xffffffff)       /* shared IRQ */
-               return (FILTER_STRAY);
+               return;
        reason &= mac->mac_intr_mask;
        if (reason == 0)
-               return (FILTER_HANDLED);
+               return;
 
        mac->mac_reason[0] = BWN_READ_4(mac, BWN_DMA0_REASON) & 0x0001dc00;
        mac->mac_reason[1] = BWN_READ_4(mac, BWN_DMA1_REASON) & 0x0000dc00;
@@ -8435,8 +8346,8 @@ bwn_intr(void *arg)
        BWN_BARRIER(mac, BUS_SPACE_BARRIER_READ);
        BWN_BARRIER(mac, BUS_SPACE_BARRIER_WRITE);
 
-       taskqueue_enqueue_fast(sc->sc_tq, &mac->mac_intrtask);
-       return (FILTER_HANDLED);
+       taskqueue_enqueue(sc->sc_tq, &mac->mac_intrtask);
+       return;
 }
 
 static void
@@ -8448,10 +8359,10 @@ bwn_intrtask(void *arg, int npending)
        uint32_t merged = 0;
        int i, tx = 0, rx = 0;
 
-       BWN_LOCK(sc);
+       wlan_serialize_enter();
        if (mac->mac_status < BWN_MAC_STATUS_STARTED ||
            (sc->sc_flags & BWN_FLAG_INVALID)) {
-               BWN_UNLOCK(sc);
+               wlan_serialize_exit();
                return;
        }
 
@@ -8478,7 +8389,7 @@ bwn_intrtask(void *arg, int npending)
                            mac->mac_reason[2], mac->mac_reason[3],
                            mac->mac_reason[4], mac->mac_reason[5]);
                        bwn_restart(mac, "DMA error");
-                       BWN_UNLOCK(sc);
+                       wlan_serialize_exit();
                        return;
                }
                if (merged & BWN_DMAINTR_NONFATALMASK) {
@@ -8544,15 +8455,15 @@ bwn_intrtask(void *arg, int npending)
                        bwn_led_event(mac, evt);
        }
 
-       if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
-               if (!IFQ_IS_EMPTY(&ifp->if_snd))
+       if (!ifq_is_oactive(&ifp->if_snd)) {
+               if (!ifq_is_empty(&ifp->if_snd))
                        bwn_start_locked(ifp);
        }
 
        BWN_BARRIER(mac, BUS_SPACE_BARRIER_READ);
        BWN_BARRIER(mac, BUS_SPACE_BARRIER_WRITE);
 
-       BWN_UNLOCK(sc);
+       wlan_serialize_exit();
 }
 
 static void
@@ -8741,8 +8652,6 @@ bwn_pio_rx(struct bwn_pio_rxqueue *prq)
        struct bwn_softc *sc = mac->mac_sc;
        unsigned int i;
 
-       BWN_ASSERT_LOCKED(sc);
-
        if (mac->mac_status < BWN_MAC_STATUS_STARTED)
                return (0);
 
@@ -8783,8 +8692,6 @@ bwn_intr_txeof(struct bwn_mac *mac)
        uint32_t stat0, stat1;
        uint16_t tmp;
 
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        while (1) {
                stat0 = BWN_READ_4(mac, BWN_XMITSTAT_0);
                if (!(stat0 & 0x00000001))
@@ -8815,7 +8722,7 @@ bwn_hwreset(void *arg, int npending)
        int error = 0;
        int prev_status;
 
-       BWN_LOCK(sc);
+       wlan_serialize_enter();
 
        prev_status = mac->mac_status;
        if (prev_status >= BWN_MAC_STATUS_STARTED)
@@ -8835,7 +8742,7 @@ out:
                device_printf(sc->sc_dev, "%s: failed (%d)\n", __func__, error);
                sc->sc_curmac = NULL;
        }
-       BWN_UNLOCK(sc);
+       wlan_serialize_exit();
 }
 
 static void
@@ -8891,16 +8798,12 @@ bwn_noise_gensample(struct bwn_mac *mac)
 static int
 bwn_dma_freeslot(struct bwn_dma_ring *dr)
 {
-       BWN_ASSERT_LOCKED(dr->dr_mac->mac_sc);
-
        return (dr->dr_numslots - dr->dr_usedslot);
 }
 
 static int
 bwn_dma_nextslot(struct bwn_dma_ring *dr, int slot)
 {
-       BWN_ASSERT_LOCKED(dr->dr_mac->mac_sc);
-
        KASSERT(slot >= -1 && slot <= dr->dr_numslots - 1,
            ("%s:%d: fail", __func__, __LINE__));
        if (slot == dr->dr_numslots - 1)
@@ -8994,8 +8897,6 @@ bwn_handle_txeof(struct bwn_mac *mac, const struct bwn_txstatus *status)
        struct ieee80211vap *vap;
        int retrycnt = 0, slot;
 
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        if (status->im)
                device_printf(sc->sc_dev, "TODO: STATUS IM\n");
        if (status->ampdu)
@@ -9125,7 +9026,7 @@ ready:
        padding = (macstat & BWN_RX_MAC_PADDING) ? 2 : 0;
        totlen = len + padding;
        KASSERT(totlen <= MCLBYTES, ("too big..\n"));
-       m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
+       m = m_getcl(M_INTWAIT, MT_DATA, M_PKTHDR);
        if (m == NULL) {
                device_printf(sc->sc_dev, "%s: out of memory", __func__);
                goto error;
@@ -9184,7 +9085,7 @@ bwn_dma_newbuf(struct bwn_dma_ring *dr, struct bwn_dmadesc_generic *desc,
        struct mbuf *m;
        int error;
 
-       m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
+       m = m_getcl(M_INTWAIT, MT_DATA, M_PKTHDR);
        if (m == NULL) {
                error = ENOBUFS;
 
@@ -9289,7 +9190,7 @@ bwn_hwrate2ieeerate(int rate)
        case BWN_OFDM_RATE_54MB:
                return (108);
        default:
-               printf("Ooops\n");
+               kprintf("Ooops\n");
                return (0);
        }
 }
@@ -9310,8 +9211,6 @@ bwn_rxeof(struct bwn_mac *mac, struct mbuf *m, const void *_rxhdr)
        unsigned char *mp = mtod(m, unsigned char *);
        static int rx_mac_dec_rpt = 0;
 
-       BWN_ASSERT_LOCKED(sc);
-
        phystat0 = le16toh(rxhdr->phy_status0);
        phystat3 = le16toh(rxhdr->phy_status3);
        macstat = le32toh(rxhdr->mac_status);
@@ -9369,8 +9268,6 @@ bwn_rxeof(struct bwn_mac *mac, struct mbuf *m, const void *_rxhdr)
 
        ifp->if_ipackets++;
 
-       BWN_UNLOCK(sc);
-
        ni = ieee80211_find_rxnode(ic, wh);
        if (ni != NULL) {
                type = ieee80211_input(ni, m, rssi, noise);
@@ -9378,7 +9275,6 @@ bwn_rxeof(struct bwn_mac *mac, struct mbuf *m, const void *_rxhdr)
        } else
                type = ieee80211_input_all(ic, m, rssi, noise);
 
-       BWN_LOCK(sc);
        return;
 drop:
        device_printf(sc->sc_dev, "%s: dropped\n", __func__);
@@ -9398,8 +9294,6 @@ bwn_dma_handle_txeof(struct bwn_mac *mac,
        struct mbuf *m;
        int slot;
 
-       BWN_ASSERT_LOCKED(sc);
-
        dr = bwn_dma_parse_cookie(mac, status, status->cookie, &slot);
        if (dr == NULL) {
                device_printf(sc->sc_dev, "failed to parse cookie\n");
@@ -9412,10 +9306,12 @@ bwn_dma_handle_txeof(struct bwn_mac *mac,
                    ("%s:%d: fail", __func__, __LINE__));
                dr->getdesc(dr, slot, &desc, &meta);
 
-               if (meta->mt_txtype == BWN_DMADESC_METATYPE_HEADER)
-                       bus_dmamap_unload(dr->dr_txring_dtag, meta->mt_dmap);
-               else if (meta->mt_txtype == BWN_DMADESC_METATYPE_BODY)
+               if (meta->mt_txtype == BWN_DMADESC_METATYPE_HEADER) {
+                       bus_dmamap_sync(dr->dr_txring_dtag, meta->mt_dmap,
+                           BUS_DMASYNC_POSTWRITE);
+               } else if (meta->mt_txtype == BWN_DMADESC_METATYPE_BODY) {
                        bus_dmamap_unload(dma->txbuf_dtag, meta->mt_dmap);
+               }
 
                if (meta->mt_islast) {
                        KASSERT(meta->mt_m != NULL,
@@ -9451,7 +9347,7 @@ bwn_dma_handle_txeof(struct bwn_mac *mac,
        if (dr->dr_stop) {
                KASSERT(bwn_dma_freeslot(dr) >= BWN_TX_SLOTS_PER_FRAME,
                    ("%s:%d: fail", __func__, __LINE__));
-               ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+               ifq_clr_oactive(&ifp->if_snd);
                dr->dr_stop = 0;
        }
 }
@@ -9465,8 +9361,6 @@ bwn_pio_handle_txeof(struct bwn_mac *mac,
        struct bwn_softc *sc = mac->mac_sc;
        struct ifnet *ifp = sc->sc_ifp;
 
-       BWN_ASSERT_LOCKED(sc);
-
        tq = bwn_pio_parse_cookie(mac, status->cookie, &tp);
        if (tq == NULL)
                return;
@@ -9492,7 +9386,7 @@ bwn_pio_handle_txeof(struct bwn_mac *mac,
 
        sc->sc_watchdog_timer = 0;
        if (tq->tq_stop) {
-               ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+               ifq_clr_oactive(&ifp->if_snd);
                tq->tq_stop = 0;
        }
 }
@@ -9781,7 +9675,7 @@ bwn_set_txhdr(struct bwn_mac *mac, struct ieee80211_node *ni,
         */
        if (ieee80211_radiotap_active_vap(vap)) {
                sc->sc_tx_th.wt_flags = 0;
-               if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED)
+               if (wh->i_fc[1] & IEEE80211_FC1_WEP)
                        sc->sc_tx_th.wt_flags |= IEEE80211_RADIOTAP_F_WEP;
                if (isshort &&
                    (rate == BWN_CCK_RATE_2MB || rate == BWN_CCK_RATE_5MB ||
@@ -10009,8 +9903,6 @@ bwn_dma_getslot(struct bwn_dma_ring *dr)
 {
        int slot;
 
-       BWN_ASSERT_LOCKED(dr->dr_mac->mac_sc);
-
        KASSERT(dr->dr_tx, ("%s:%d: fail", __func__, __LINE__));
        KASSERT(!(dr->dr_stop), ("%s:%d: fail", __func__, __LINE__));
        KASSERT(bwn_dma_freeslot(dr) != 0, ("%s:%d: fail", __func__, __LINE__));
@@ -10188,13 +10080,12 @@ static void
 bwn_txpwr(void *arg, int npending)
 {
        struct bwn_mac *mac = arg;
-       struct bwn_softc *sc = mac->mac_sc;
 
-       BWN_LOCK(sc);
+       wlan_serialize_enter();
        if (mac && mac->mac_status >= BWN_MAC_STATUS_STARTED &&
            mac->mac_phy.set_txpwr != NULL)
                mac->mac_phy.set_txpwr(mac);
-       BWN_UNLOCK(sc);
+       wlan_serialize_exit();
 }
 
 static void
@@ -10243,9 +10134,12 @@ bwn_tasks(void *arg)
        struct bwn_mac *mac = arg;
        struct bwn_softc *sc = mac->mac_sc;
 
-       BWN_ASSERT_LOCKED(sc);
-       if (mac->mac_status != BWN_MAC_STATUS_STARTED)
+       wlan_serialize_enter();
+
+       if (mac->mac_status != BWN_MAC_STATUS_STARTED) {
+               wlan_serialize_exit();
                return;
+       }
 
        if (mac->mac_task_state % 4 == 0)
                bwn_task_60s(mac);
@@ -10255,6 +10149,7 @@ bwn_tasks(void *arg)
 
        mac->mac_task_state++;
        callout_reset(&sc->sc_task_ch, hz * 15, bwn_tasks, mac);
+       wlan_serialize_exit();
 }
 
 static int
@@ -10320,7 +10215,7 @@ bwn_rx_radiotap(struct bwn_mac *mac, struct mbuf *m,
                sc->sc_rx_th.wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
 
        wh = mtod(m, const struct ieee80211_frame_min *);
-       if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED)
+       if (wh->i_fc[1] & IEEE80211_FC1_WEP)
                sc->sc_rx_th.wr_flags |= IEEE80211_RADIOTAP_F_WEP;
 
        bwn_tsf_read(mac, &tsf);
@@ -10386,7 +10281,6 @@ bwn_dma_attach(struct bwn_mac *mac)
                               BUS_SPACE_UNRESTRICTED,  /* nsegments */
                               BUS_SPACE_MAXSIZE,       /* maxsegsize */
                               0,                       /* flags */
-                              NULL, NULL,              /* lockfunc, lockarg */
                               &dma->parent_dtag);
        if (error) {
                device_printf(sc->sc_dev, "can't create parent DMA tag\n");
@@ -10397,7 +10291,7 @@ bwn_dma_attach(struct bwn_mac *mac)
         * Create TX/RX mbuf DMA tag
         */
        error = bus_dma_tag_create(dma->parent_dtag,
-                               1,
+                               4,
                                0,
                                BUS_SPACE_MAXADDR,
                                BUS_SPACE_MAXADDR,
@@ -10406,14 +10300,13 @@ bwn_dma_attach(struct bwn_mac *mac)
                                1,
                                BUS_SPACE_MAXSIZE_32BIT,
                                0,
-                               NULL, NULL,
                                &dma->rxbuf_dtag);
        if (error) {
                device_printf(sc->sc_dev, "can't create mbuf DMA tag\n");
                goto fail0;
        }
        error = bus_dma_tag_create(dma->parent_dtag,
-                               1,
+                               4,
                                0,
                                BUS_SPACE_MAXADDR,
                                BUS_SPACE_MAXADDR,
@@ -10422,7 +10315,6 @@ bwn_dma_attach(struct bwn_mac *mac)
                                1,
                                BUS_SPACE_MAXSIZE_32BIT,
                                0,
-                               NULL, NULL,
                                &dma->txbuf_dtag);
        if (error) {
                device_printf(sc->sc_dev, "can't create mbuf DMA tag\n");
@@ -10430,26 +10322,26 @@ bwn_dma_attach(struct bwn_mac *mac)
        }
 
        dma->wme[WME_AC_BK] = bwn_dma_ringsetup(mac, 0, 1, dma->dmatype);
-       if (!dma->wme[WME_AC_BK])
+       if (dma->wme[WME_AC_BK] == NULL)
                goto fail2;
 
        dma->wme[WME_AC_BE] = bwn_dma_ringsetup(mac, 1, 1, dma->dmatype);
-       if (!dma->wme[WME_AC_BE])
+       if (dma->wme[WME_AC_BE] == NULL)
                goto fail3;
 
        dma->wme[WME_AC_VI] = bwn_dma_ringsetup(mac, 2, 1, dma->dmatype);
-       if (!dma->wme[WME_AC_VI])
+       if (dma->wme[WME_AC_VI] == NULL)
                goto fail4;
 
        dma->wme[WME_AC_VO] = bwn_dma_ringsetup(mac, 3, 1, dma->dmatype);
-       if (!dma->wme[WME_AC_VO])
+       if (dma->wme[WME_AC_VO] == NULL)
                goto fail5;
 
        dma->mcast = bwn_dma_ringsetup(mac, 4, 1, dma->dmatype);
-       if (!dma->mcast)
+       if (dma->mcast == NULL)
                goto fail6;
        dma->rx = bwn_dma_ringsetup(mac, 0, 0, dma->dmatype);
-       if (!dma->rx)
+       if (dma->rx == NULL)
                goto fail7;
 
        return (error);
@@ -10473,8 +10365,6 @@ bwn_dma_parse_cookie(struct bwn_mac *mac, const struct bwn_txstatus *status,
        struct bwn_dma_ring *dr;
        struct bwn_softc *sc = mac->mac_sc;
 
-       BWN_ASSERT_LOCKED(mac->mac_sc);
-
        switch (cookie & 0xf000) {
        case 0x1000:
                dr = dma->wme[WME_AC_BK];
@@ -10615,7 +10505,7 @@ bwn_led_attach(struct bwn_mac *mac)
                    "%dth led, act %d, lowact %d\n", i,
                    led->led_act, led->led_flags & BWN_LED_F_ACTLOW);
        }
-       callout_init_mtx(&sc->sc_led_blink_ch, &sc->sc_mtx, 0);
+       callout_init(&sc->sc_led_blink_ch);
 }
 
 static __inline uint16_t
@@ -10645,7 +10535,7 @@ bwn_led_newstate(struct bwn_mac *mac, enum ieee80211_state nstate)
                sc->sc_led_blinking = 0;
        }
 
-       if ((ic->ic_ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
+       if ((ic->ic_ifp->if_flags & IFF_RUNNING) == 0)
                return;
 
        val = BWN_READ_2(mac, BWN_GPIO_CONTROL);
@@ -10758,12 +10648,15 @@ bwn_led_blink_next(void *arg)
        struct bwn_softc *sc = mac->mac_sc;
        uint16_t val;
 
+       wlan_serialize_enter();
+
        val = BWN_READ_2(mac, BWN_GPIO_CONTROL);
        val = bwn_led_onoff(sc->sc_blink_led, val, 0);
        BWN_WRITE_2(mac, BWN_GPIO_CONTROL, val);
 
        callout_reset(&sc->sc_led_blink_ch, sc->sc_led_blink_offdur,
            bwn_led_blink_end, mac);
+       wlan_serialize_exit();
 }
 
 static void
@@ -10780,7 +10673,10 @@ bwn_suspend(device_t dev)
 {
        struct bwn_softc *sc = device_get_softc(dev);
 
+       wlan_serialize_enter();
        bwn_stop(sc, 1);
+       wlan_serialize_exit();
+
        return (0);
 }
 
@@ -10790,8 +10686,10 @@ bwn_resume(device_t dev)
        struct bwn_softc *sc = device_get_softc(dev);
        struct ifnet *ifp = sc->sc_ifp;
 
+       wlan_serialize_enter();
        if (ifp->if_flags & IFF_UP)
                bwn_init(sc);
+       wlan_serialize_exit();
        return (0);
 }
 
@@ -10802,6 +10700,8 @@ bwn_rfswitch(void *arg)
        struct bwn_mac *mac = sc->sc_curmac;
        int cur = 0, prev = 0;
 
+       wlan_serialize_enter();
+
        KASSERT(mac->mac_status >= BWN_MAC_STATUS_STARTED,
            ("%s: invalid MAC status %d", __func__, mac->mac_status));
 
@@ -10835,7 +10735,8 @@ bwn_rfswitch(void *arg)
                }
        }
 
-       callout_schedule(&sc->sc_rfswitch_ch, hz);
+       callout_reset(&sc->sc_rfswitch_ch, hz, bwn_rfswitch, sc);
+       wlan_serialize_exit();
 }
 
 static void
@@ -11590,7 +11491,6 @@ static void
 bwn_phy_lp_bugfix(struct bwn_mac *mac)
 {
        struct bwn_phy_lp *plp = &mac->mac_phy.phy_lp;
-       struct bwn_softc *sc = mac->mac_sc;
        const unsigned int size = 256;
        struct bwn_txgain tg;
        uint32_t rxcomp, txgain, coeff, rfpwr, *tabs;
@@ -11598,12 +11498,8 @@ bwn_phy_lp_bugfix(struct bwn_mac *mac)
        uint8_t mode;
        int8_t txpwridx;
 
-       tabs = (uint32_t *)malloc(sizeof(uint32_t) * size, M_DEVBUF,
-           M_NOWAIT | M_ZERO);
-       if (tabs == NULL) {
-               device_printf(sc->sc_dev, "failed to allocate buffer.\n");
-               return;
-       }
+       tabs = (uint32_t *)kmalloc(sizeof(uint32_t) * size, M_DEVBUF,
+           M_INTWAIT | M_ZERO);
 
        bwn_phy_lp_get_txpctlmode(mac);
        mode = plp->plp_txpctlmode;
@@ -11678,7 +11574,7 @@ bwn_phy_lp_bugfix(struct bwn_mac *mac)
                bwn_phy_lp_set_rccap(mac);
        bwn_phy_lp_set_antenna(mac, plp->plp_antenna);
        bwn_phy_lp_set_txpctlmode(mac, mode);
-       free(tabs, M_DEVBUF);
+       kfree(tabs, M_DEVBUF);
 }
 
 static void
@@ -14193,9 +14089,10 @@ bwn_phy_lp_gaintbl_write_r01(struct bwn_mac *mac, int offset,
 static void
 bwn_sysctl_node(struct bwn_softc *sc)
 {
-       device_t dev = sc->sc_dev;
        struct bwn_mac *mac;
        struct bwn_stats *stats;
+       struct sysctl_ctx_list *ctx;
+       struct sysctl_oid *tree;
 
        /* XXX assume that count of MAC is only 1. */
 
@@ -14203,19 +14100,17 @@ bwn_sysctl_node(struct bwn_softc *sc)
                return;
        stats = &mac->mac_stats;
 
-       SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
-           SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
+       ctx = &sc->sc_sysctl_ctx;
+       tree = sc->sc_sysctl_tree;
+       SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
            "linknoise", CTLFLAG_RW, &stats->rts, 0, "Noise level");
-       SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
-           SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
+       SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
            "rts", CTLFLAG_RW, &stats->rts, 0, "RTS");
-       SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
-           SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
+       SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
            "rtsfail", CTLFLAG_RW, &stats->rtsfail, 0, "RTS failed to send");
 
 #ifdef BWN_DEBUG
-       SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
-           SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
+       SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
            "debug", CTLFLAG_RW, &sc->sc_debug, 0, "Debug flags");
 #endif
 }
index d2cd8fd..dbcb098 100644 (file)
@@ -29,9 +29,6 @@
  * $FreeBSD: head/sys/dev/bwn/if_bwnreg.h 203945 2010-02-16 01:44:14Z weongyo $
  */
 
-#ifndef _IF_BWNREG_H
-#define        _IF_BWNREG_H
-
 #define        PCI_VENDOR_COMPAQ               0x0e11
 #define        PCI_VENDOR_DELL                 0x1028
 #define        PCI_VENDOR_HP                   0x103c
 #define        BWN_DMA64_RXSTATDPTR            0x00001fff
 #define        BWN_DMA64_RXSTAT                0xf0000000
 #define        BWN_DMA64_RXSTAT_DISABLED       0x00000000
-#define        BWN_DMA_RINGMEMSIZE             PAGE_SIZE
+#define        BWN_DMA_RINGMEMSIZE             0x2000
 #define        BWN_DMA0_RX_FRAMEOFFSET         30
 
-#define        BWN_TXRING_SLOTS                64
-#define        BWN_RXRING_SLOTS                64
+#ifndef        BWN_TXRING_SLOTS
+#define        BWN_TXRING_SLOTS                256
+#endif
+#ifndef        BWN_RXRING_SLOTS
+#define        BWN_RXRING_SLOTS                256
+#endif
 #define        BWN_DMA0_RX_BUFFERSIZE          IEEE80211_MAX_LEN
 
 #define        BWN_PHYROUTE_BASE               0x0000
 #define        BWN_B2063_PA_CTL1               BWN_LP_RADIO(0x10B)
 #define        BWN_B2063_PA_CTL11              BWN_LP_RADIO(0x115)
 #define        BWN_B2063_VREG_CTL1             BWN_LP_RADIO(0x11D)
-
-#endif /* !_IF_BWNREG_H */
index 1115d3c..79dc840 100644 (file)
 #ifndef _IF_BWNVAR_H
 #define        _IF_BWNVAR_H
 
+#include <netproto/802_11/ieee80211_amrr.h>
+
 struct siba_dev_softc;
 struct bwn_softc;
 struct bwn_mac;
 
 #define        N(a)                    (sizeof(a) / sizeof(a[0]))
-#define        BWN_ALIGN                       0x1000
+#define        BWN_ALIGN                       0x2000
 #define        BWN_BUS_SPACE_MAXADDR_30BIT     0x3fffffff
 #define        BWN_RETRY_SHORT                 7
 #define        BWN_RETRY_LONG                  4
@@ -58,6 +60,7 @@ struct bwn_mac;
 #define        BWN_ISOLDFMT(mac)               ((mac)->mac_fw.rev <= 351)
 #define        BWN_TSSI2DBM(num, den)                                          \
        ((int32_t)((num < 0) ? num / den : (num + den / 2) / den))
+#define        BWN_MAX_HDRSIZE(mac)    (104 + sizeof(struct bwn_plcp6))
 #define        BWN_HDRSIZE(mac)                                                \
        ((BWN_ISOLDFMT(mac)) ? (100 + sizeof(struct bwn_plcp6)) :       \
            (104 + sizeof(struct bwn_plcp6)))
@@ -591,6 +594,7 @@ struct bwn_dma_ring {
        void                            *dr_txhdr_cache;
        bus_dma_tag_t                   dr_ring_dtag;
        bus_dma_tag_t                   dr_txring_dtag;
+       bus_dmamap_t                    dr_txring_dmap;
        bus_dmamap_t                    dr_spare_dmap; /* only for RX */
        bus_dmamap_t                    dr_ring_dmap;
        bus_addr_t                      dr_txring_paddr;
@@ -850,12 +854,6 @@ struct bwn_mac {
 #define        BWN_MAC_FLAG_WME                (1 << 4)
 #define        BWN_MAC_FLAG_HWCRYPTO           (1 << 5)
 
-       struct resource_spec            *mac_intr_spec;
-#define        BWN_MSI_MESSAGES                1
-       struct resource                 *mac_res_irq[BWN_MSI_MESSAGES];
-       void                            *mac_intrhand[BWN_MSI_MESSAGES];
-       int                             mac_msi;
-
        struct bwn_noise                mac_noise;
        struct bwn_phy                  mac_phy;
        struct bwn_stats                mac_stats;
@@ -896,12 +894,13 @@ struct bwn_vap {
 
 struct bwn_softc {
        device_t                        sc_dev;
-       struct mtx                      sc_mtx;
        struct ifnet                    *sc_ifp;
        unsigned                        sc_flags;
 #define        BWN_FLAG_ATTACHED               (1 << 0)
 #define        BWN_FLAG_INVALID                (1 << 1)
 #define        BWN_FLAG_NEED_BEACON_TP         (1 << 2)
+       struct sysctl_ctx_list  sc_sysctl_ctx;
+       struct sysctl_oid       *sc_sysctl_tree;
        unsigned                        sc_debug;
 
        struct bwn_mac          *sc_curmac;
@@ -937,16 +936,13 @@ struct bwn_softc {
        int                             sc_led_idle;
        int                             sc_led_blink;
 
+       struct resource                 *bwn_irq;
+       void                            *bwn_intr;
+       int                             bwn_irq_rid;
+       int                             bwn_irq_type;
+
        struct bwn_tx_radiotap_header   sc_tx_th;
        struct bwn_rx_radiotap_header   sc_rx_th;
 };
 
-#define        BWN_LOCK_INIT(sc) \
-       mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->sc_dev), \
-           MTX_NETWORK_LOCK, MTX_DEF)
-#define        BWN_LOCK_DESTROY(sc)    mtx_destroy(&(sc)->sc_mtx)
-#define        BWN_LOCK(sc)            mtx_lock(&(sc)->sc_mtx)
-#define        BWN_UNLOCK(sc)          mtx_unlock(&(sc)->sc_mtx)
-#define        BWN_ASSERT_LOCKED(sc)   mtx_assert(&(sc)->sc_mtx, MA_OWNED)
-
 #endif /* !_IF_BWNVAR_H */
diff --git a/sys/dev/netif/bwn/siba/Makefile b/sys/dev/netif/bwn/siba/Makefile
new file mode 100644 (file)
index 0000000..22bb571
--- /dev/null
@@ -0,0 +1,6 @@
+KMOD   = siba_bwn
+
+SRCS   = siba_bwn.c siba_core.c
+SRCS   += device_if.h bus_if.h pci_if.h pcidevs.h opt_siba.h
+
+.include <bsd.kmod.mk>
index 232010c..e477f49 100644 (file)
@@ -34,30 +34,26 @@ __FBSDID("$FreeBSD: head/sys/dev/siba/siba_bwn.c 257241 2013-10-28 07:29:16Z gle
  * Sonics Silicon Backplane front-end for bwn(4).
  */
 
+#include <opt_siba.h>
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/errno.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
+#include <sys/bus.h>
+#include <sys/bus_resource.h>
 #include <sys/bus.h>
 #include <sys/rman.h>
 #include <sys/socket.h>
 
-#include <net/if.h>
-#include <net/if_media.h>
-#include <net/if_arp.h>
+#include <bus/pci/pcivar.h>
+#include <bus/pci/pcireg.h>
 
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcireg.h>
-
-#include <dev/siba/siba_ids.h>
-#include <dev/siba/sibareg.h>
-#include <dev/siba/sibavar.h>
+#include <dev/netif/bwn/siba/siba_ids.h>
+#include <dev/netif/bwn/siba/sibareg.h>
+#include <dev/netif/bwn/siba/sibavar.h>
 
 /*
  * PCI glue.
@@ -135,7 +131,7 @@ siba_bwn_attach(device_t dev)
         */
        pci_enable_busmaster(dev);
 
-       /* 
+       /*
         * Setup memory-mapping of PCI registers.
         */
        siba->siba_mem_rid = SIBA_PCIR_BAR;
@@ -188,7 +184,7 @@ siba_bwn_shutdown(device_t dev)
 
        for (i = 0 ; i < devcnt ; i++)
                device_shutdown(devlistp[i]);
-       free(devlistp, M_TEMP);
+       kfree(devlistp, M_TEMP);
        return (0);
 }
 
@@ -209,11 +205,11 @@ siba_bwn_suspend(device_t dev)
                if (error) {
                        for (j = 0; j < i; j++)
                                DEVICE_RESUME(devlistp[j]);
-                       free(devlistp, M_TEMP);
+                       kfree(devlistp, M_TEMP);
                        return (error);
                }
        }
-       free(devlistp, M_TEMP);
+       kfree(devlistp, M_TEMP);
        return (siba_core_suspend(siba));
 }
 
@@ -235,18 +231,18 @@ siba_bwn_resume(device_t dev)
 
        for (i = 0 ; i < devcnt ; i++)
                DEVICE_RESUME(devlistp[i]);
-       free(devlistp, M_TEMP);
+       kfree(devlistp, M_TEMP);
        return (0);
 }
 
 /* proxying to the parent */
 static struct resource *
 siba_bwn_alloc_resource(device_t dev, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    u_long start, u_long end, u_long count, u_int flags, int cpuid)
 {
 
        return (BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
-           type, rid, start, end, count, flags));
+           type, rid, start, end, count, flags, cpuid));
 }
 
 /* proxying to the parent */
@@ -262,12 +258,12 @@ siba_bwn_release_resource(device_t dev, device_t child, int type,
 /* proxying to the parent */
 static int
 siba_bwn_setup_intr(device_t dev, device_t child, struct resource *irq,
-    int flags, driver_filter_t *filter, driver_intr_t *intr, void *arg,
-    void **cookiep)
+    int flags, driver_intr_t *intr, void *arg, void **cookiep,
+    lwkt_serialize_t serializer)
 {
 
        return (BUS_SETUP_INTR(device_get_parent(dev), dev, irq, flags,
-           filter, intr, arg, cookiep));
+           intr, arg, cookiep, serializer, NULL));
 }
 
 /* proxying to the parent */
@@ -279,14 +275,6 @@ siba_bwn_teardown_intr(device_t dev, device_t child, struct resource *irq,
        return (BUS_TEARDOWN_INTR(device_get_parent(dev), dev, irq, cookie));
 }
 
-static int
-siba_bwn_find_cap(device_t dev, device_t child, int capability,
-    int *capreg)
-{
-
-       return (pci_find_cap(dev, capability, capreg));
-}
-
 static int
 siba_bwn_find_extcap(device_t dev, device_t child, int capability,
     int *capreg)
@@ -296,15 +284,8 @@ siba_bwn_find_extcap(device_t dev, device_t child, int capability,
 }
 
 static int
-siba_bwn_find_htcap(device_t dev, device_t child, int capability,
-    int *capreg)
-{
-
-       return (pci_find_htcap(dev, capability, capreg));
-}
-
-static int
-siba_bwn_alloc_msi(device_t dev, device_t child, int *count)
+siba_bwn_alloc_msi(device_t dev, device_t child, int *rid, int count,
+    int cpuid)
 {
        struct siba_bwn_softc *ssc;
        int error;
@@ -312,7 +293,7 @@ siba_bwn_alloc_msi(device_t dev, device_t child, int *count)
        ssc = device_get_softc(dev);
        if (ssc->ssc_msi_child != NULL)
                return (EBUSY);
-       error = pci_alloc_msi(dev, count);
+       error = pci_alloc_msi(dev, rid, count, cpuid);
        if (error == 0)
                ssc->ssc_msi_child = child;
        return (error);
@@ -422,9 +403,7 @@ static device_method_t siba_bwn_methods[] = {
        DEVMETHOD(bus_teardown_intr,    siba_bwn_teardown_intr),
 
        /* PCI interface */
-       DEVMETHOD(pci_find_cap,         siba_bwn_find_cap),
        DEVMETHOD(pci_find_extcap,      siba_bwn_find_extcap),
-       DEVMETHOD(pci_find_htcap,       siba_bwn_find_htcap),
        DEVMETHOD(pci_alloc_msi,        siba_bwn_alloc_msi),
        DEVMETHOD(pci_release_msi,      siba_bwn_release_msi),
        DEVMETHOD(pci_msi_count,        siba_bwn_msi_count),
index cb54d6f..ba0190c 100644 (file)
@@ -34,6 +34,8 @@ __FBSDID("$FreeBSD: head/sys/dev/siba/siba_core.c 257241 2013-10-28 07:29:16Z gl
  * the Sonics Silicon Backplane driver.
  */
 
+#include "opt_siba.h"
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
@@ -41,24 +43,18 @@ __FBSDID("$FreeBSD: head/sys/dev/siba/siba_core.c 257241 2013-10-28 07:29:16Z gl
 #include <sys/kernel.h>
 #include <sys/endian.h>
 #include <sys/errno.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
+#include <sys/bus.h>
+#include <sys/bus_resource.h>
 #include <sys/bus.h>
 #include <sys/rman.h>
 #include <sys/socket.h>
 
-#include <net/if.h>
-#include <net/if_media.h>
-#include <net/if_arp.h>
-
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcireg.h>
+#include <bus/pci/pcivar.h>
+#include <bus/pci/pcireg.h>
 
-#include <dev/siba/siba_ids.h>
-#include <dev/siba/sibareg.h>
-#include <dev/siba/sibavar.h>
+#include <dev/netif/bwn/siba/siba_ids.h>
+#include <dev/netif/bwn/siba/sibareg.h>
+#include <dev/netif/bwn/siba/sibavar.h>
 
 #ifdef SIBA_DEBUG
 enum {
@@ -71,11 +67,11 @@ enum {
        SIBA_DEBUG_ANY          = 0xffffffff
 };
 #define DPRINTF(siba, m, fmt, ...) do {                        \
-       if (siba->siba_debug & (m))                     \
-               printf(fmt, __VA_ARGS__);               \
+       if (m)                                          \
+               kprintf(fmt, __VA_ARGS__);              \
 } while (0)
 #else
-#define DPRINTF(siba, m, fmt, ...) do { (void) siba; } while (0)
+#define DPRINTF(siba, m, fmt, ...)
 #endif
 #define        N(a)                    (sizeof(a) / sizeof(a[0]))
 
@@ -332,7 +328,7 @@ siba_scan(struct siba_softc *siba)
                DPRINTF(siba, SIBA_DEBUG_SCAN,
                    "core %d (%s) found (cc %#xrev %#x vendor %#x)\n",
                    i, siba_core_name(sd->sd_id.sd_device),
-                   sd->sd_id.sd_device, sd->sd_id.sd_rev, sd->sd_id.vendor);
+                   sd->sd_id.sd_device, sd->sd_id.sd_rev, sd->sd_id.sd_vendor);
 
                switch (sd->sd_id.sd_device) {
                case SIBA_DEVID_CHIPCOMMON:
@@ -355,7 +351,7 @@ siba_scan(struct siba_softc *siba)
                case SIBA_DEVID_PCI:
                case SIBA_DEVID_PCIE:
                        n_pci++;
-                       error = pci_find_cap(siba->siba_dev, PCIY_EXPRESS,
+                       error = pci_find_extcap(siba->siba_dev, PCIY_EXPRESS,
                            &base);
                        is_pcie = (error == 0) ? 1 : 0;
 
@@ -1197,7 +1193,7 @@ siba_cc_pmu0_pll0_init(struct siba_cc *scc, uint32_t xtalfreq)
                xtalfreq = 25000;
        if (xtalfreq)
                e = siba_cc_pmu0_plltab_findentry(xtalfreq);
-       if (!e)
+       if (e == NULL)
                e = siba_cc_pmu0_plltab_findentry(
                    SIBA_CC_PMU0_DEFAULT_XTALFREQ);
        KASSERT(e != NULL, ("%s:%d: fail", __func__, __LINE__));
@@ -1356,18 +1352,14 @@ siba_pci_sprom(struct siba_softc *siba, struct siba_sprom *sprom)
        int error = ENOMEM;
        uint16_t *buf;
 
-       buf = malloc(SIBA_SPROMSIZE_R123 * sizeof(uint16_t),
-           M_DEVBUF, M_NOWAIT | M_ZERO);
-       if (buf == NULL)
-               return (ENOMEM);
+       buf = kmalloc(SIBA_SPROMSIZE_R123 * sizeof(uint16_t),
+           M_DEVBUF, M_INTWAIT | M_ZERO);
        siba_sprom_read(siba, buf, SIBA_SPROMSIZE_R123);
        error = sprom_check_crc(buf, siba->siba_spromsize);
        if (error) {
-               free(buf, M_DEVBUF);
-               buf = malloc(SIBA_SPROMSIZE_R4 * sizeof(uint16_t),
-                   M_DEVBUF, M_NOWAIT | M_ZERO);
-               if (buf == NULL)
-                       return (ENOMEM);
+               kfree(buf, M_DEVBUF);
+               buf = kmalloc(SIBA_SPROMSIZE_R4 * sizeof(uint16_t),
+                   M_DEVBUF, M_INTWAIT | M_ZERO);
                siba_sprom_read(siba, buf, SIBA_SPROMSIZE_R4);
                error = sprom_check_crc(buf, siba->siba_spromsize);
                if (error)
@@ -1413,7 +1405,7 @@ siba_pci_sprom(struct siba_softc *siba, struct siba_sprom *sprom)
        if (sprom->bf_hi == 0xffff)
                sprom->bf_hi = 0;
 
-       free(buf, M_DEVBUF);
+       kfree(buf, M_DEVBUF);
        return (error);
 }
 
@@ -1729,7 +1721,7 @@ siba_powerdown_sub(struct siba_softc *siba)
                return (0);
 
        scc = &siba->siba_cc;
-       if (!scc->scc_dev || scc->scc_dev->sd_id.sd_rev < 5)
+       if (scc->scc_dev == NULL || scc->scc_dev->sd_id.sd_rev < 5)
                return (0);
        siba_cc_clock(scc, SIBA_CLOCK_SLOW);
        siba_pci_gpio(siba, SIBA_GPIO_CRYSTAL | SIBA_GPIO_PLL, 0);
@@ -2532,7 +2524,7 @@ siba_gpio_get(device_t dev)
 
        pcidev = siba->siba_pci.spc_dev;
        gpiodev = siba->siba_cc.scc_dev ? siba->siba_cc.scc_dev : pcidev;
-       if (!gpiodev)
+       if (gpiodev == NULL)
                return (-1);
        return (siba_read_4_sub(gpiodev, SIBA_GPIOCTL));
 }
@@ -2546,7 +2538,7 @@ siba_gpio_set(device_t dev, uint32_t value)
 
        pcidev = siba->siba_pci.spc_dev;
        gpiodev = siba->siba_cc.scc_dev ? siba->siba_cc.scc_dev : pcidev;
-       if (!gpiodev)
+       if (gpiodev == NULL)
                return;
        siba_write_4_sub(gpiodev, SIBA_GPIOCTL, value);
 }