drivers: brcmfmac: update to stable version
Rhyland Klein [Tue, 15 May 2012 16:22:56 +0000 (12:22 -0400)]
Update the driver to the stable version.

Based on 33252fe66aa42cc1c217b9fd632b5df6c77932c6 from

branch: dev/amartin/chromeos-3.0-t30

Change-Id: I53db887749b8781d90667a07de71abbea390ac5c
Signed-off-by: Rhyland Klein <rklein@nvidia.com>
Reviewed-on: http://git-master/r/111334
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Narayan Reddy <narayanr@nvidia.com>
Reviewed-by: Wei Ni <wni@nvidia.com>
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>

73 files changed:
drivers/staging/brcm80211/Kconfig
drivers/staging/brcm80211/Makefile
drivers/staging/brcm80211/README
drivers/staging/brcm80211/TODO [deleted file]
drivers/staging/brcm80211/brcmfmac/Makefile
drivers/staging/brcm80211/brcmfmac/bcmsdh.c
drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c
drivers/staging/brcm80211/brcmfmac/dhd.h
drivers/staging/brcm80211/brcmfmac/dhd_bus.h
drivers/staging/brcm80211/brcmfmac/dhd_cdc.c
drivers/staging/brcm80211/brcmfmac/dhd_common.c
drivers/staging/brcm80211/brcmfmac/dhd_dbg.h
drivers/staging/brcm80211/brcmfmac/dhd_linux.c
drivers/staging/brcm80211/brcmfmac/dhd_proto.h
drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
drivers/staging/brcm80211/brcmfmac/sdio_host.h
drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
drivers/staging/brcm80211/brcmsmac/Makefile
drivers/staging/brcm80211/brcmsmac/aiutils.c
drivers/staging/brcm80211/brcmsmac/aiutils.h
drivers/staging/brcm80211/brcmsmac/alloc.c [deleted file]
drivers/staging/brcm80211/brcmsmac/ampdu.c
drivers/staging/brcm80211/brcmsmac/antsel.c
drivers/staging/brcm80211/brcmsmac/bmac.c [deleted file]
drivers/staging/brcm80211/brcmsmac/bmac.h [deleted file]
drivers/staging/brcm80211/brcmsmac/brcms_trace_events.c [moved from drivers/staging/brcm80211/brcmsmac/alloc.h with 76% similarity]
drivers/staging/brcm80211/brcmsmac/brcms_trace_events.h [new file with mode: 0644]
drivers/staging/brcm80211/brcmsmac/channel.c
drivers/staging/brcm80211/brcmsmac/channel.h
drivers/staging/brcm80211/brcmsmac/d11.h
drivers/staging/brcm80211/brcmsmac/dma.c
drivers/staging/brcm80211/brcmsmac/dma.h
drivers/staging/brcm80211/brcmsmac/mac80211_if.c
drivers/staging/brcm80211/brcmsmac/mac80211_if.h
drivers/staging/brcm80211/brcmsmac/main.c
drivers/staging/brcm80211/brcmsmac/main.h
drivers/staging/brcm80211/brcmsmac/nicpci.c
drivers/staging/brcm80211/brcmsmac/nicpci.h
drivers/staging/brcm80211/brcmsmac/otp.c
drivers/staging/brcm80211/brcmsmac/otp.h
drivers/staging/brcm80211/brcmsmac/phy/phy_cmn.c
drivers/staging/brcm80211/brcmsmac/phy/phy_hal.h
drivers/staging/brcm80211/brcmsmac/phy/phy_int.h
drivers/staging/brcm80211/brcmsmac/phy/phy_lcn.c
drivers/staging/brcm80211/brcmsmac/phy/phy_n.c
drivers/staging/brcm80211/brcmsmac/phy/phy_qmath.c
drivers/staging/brcm80211/brcmsmac/phy/phytbl_lcn.c
drivers/staging/brcm80211/brcmsmac/phy/phytbl_n.c
drivers/staging/brcm80211/brcmsmac/phy/phytbl_n.h
drivers/staging/brcm80211/brcmsmac/phy_shim.c
drivers/staging/brcm80211/brcmsmac/phy_shim.h
drivers/staging/brcm80211/brcmsmac/pmu.c
drivers/staging/brcm80211/brcmsmac/pmu.h
drivers/staging/brcm80211/brcmsmac/pub.h
drivers/staging/brcm80211/brcmsmac/rate.c
drivers/staging/brcm80211/brcmsmac/rate.h
drivers/staging/brcm80211/brcmsmac/scb.h
drivers/staging/brcm80211/brcmsmac/srom.c
drivers/staging/brcm80211/brcmsmac/srom.h
drivers/staging/brcm80211/brcmsmac/stf.c
drivers/staging/brcm80211/brcmsmac/stf.h
drivers/staging/brcm80211/brcmsmac/types.h
drivers/staging/brcm80211/brcmsmac/ucode_loader.c
drivers/staging/brcm80211/brcmsmac/ucode_loader.h
drivers/staging/brcm80211/brcmutil/Makefile
drivers/staging/brcm80211/brcmutil/utils.c
drivers/staging/brcm80211/brcmutil/wifi.c [deleted file]
drivers/staging/brcm80211/include/brcmu_utils.h
drivers/staging/brcm80211/include/brcmu_wifi.h
drivers/staging/brcm80211/include/chipcommon.h
drivers/staging/brcm80211/include/defs.h
drivers/staging/brcm80211/include/soc.h

index 379cf16..586de7f 100644 (file)
@@ -21,7 +21,6 @@ config BRCMFMAC
        default n
        depends on MMC
        depends on WLAN && CFG80211
-       depends on X86 || MIPS
        select BRCMUTIL
        select FW_LOADER
        select WIRELESS_EXT
index 8b01f5e..b595cab 100644 (file)
@@ -16,8 +16,8 @@
 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 # common flags
-subdir-ccflags-y                                       := -DBCMDMA32
-subdir-ccflags-$(CONFIG_BRCMDBG)       += -DBCMDBG
+subdir-ccflags-y                       := -DBCMDMA32
+subdir-ccflags-$(CONFIG_BRCMDBG)       += -DBCMDBG -DBCMDBG_ASSERT
 
 obj-$(CONFIG_BRCMUTIL) += brcmutil/
 obj-$(CONFIG_BRCMFMAC) += brcmfmac/
index bb86b1b..8ad5586 100644 (file)
@@ -1 +1,64 @@
-refer to: http://linuxwireless.org/en/users/Drivers/brcm80211
+Broadcom brcmsmac (mac80211-based softmac PCIe) and brcmfmac (SDIO) drivers.
+
+Completely open source host drivers, no binary object files.
+
+Support for the following chips:
+===============================
+
+    brcmsmac (PCIe)
+    Name        Device ID
+    BCM4313     0x4727
+    BCM43224    0x4353
+    BCM43225    0x4357
+
+    brcmfmac (SDIO)
+    Name
+    BCM4329
+
+Both brcmsmac and brcmfmac drivers require firmware files that need to be
+separately downloaded.
+
+Firmware
+======================
+Firmware is available from the Linux firmware repository at:
+
+    git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git
+    http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git
+    https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git
+
+
+===============================================================
+Broadcom brcmsmac driver
+===============================================================
+- Support for both 32 and 64 bit Linux kernels
+
+
+Firmware installation
+======================
+Copy brcm/bcm43xx-0.fw and brcm/bcm43xx_hdr-0.fw to
+/lib/firmware/brcm (or wherever firmware is normally installed
+on your system).
+
+
+===============================================================
+Broadcom brcmfmac driver
+===============================================================
+- Support for 32 bit Linux kernel, 64 bit untested
+
+
+Firmware installation
+======================
+Copy brcm/bcm4329-fullmac-4.bin and brcm/bcm4329-fullmac-4.txt
+to /lib/firmware/brcm (or wherever firmware is normally installed on your
+system).
+
+
+Contact Info:
+=============
+Brett Rudley           brudley@broadcom.com
+Henry Ptasinski                henryp@broadcom.com
+Dowan Kim              dowan@broadcom.com
+Roland Vossen          rvossen@broadcom.com
+Arend van Spriel       arend@broadcom.com
+
+For more info, refer to: http://linuxwireless.org/en/users/Drivers/brcm80211
diff --git a/drivers/staging/brcm80211/TODO b/drivers/staging/brcm80211/TODO
deleted file mode 100644 (file)
index e2e2ef9..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-To Do List for Broadcom Mac80211 driver before getting in mainline
-
-Bugs
-====
-- none known at this moment
-
-brcmfmac
-=====================
-- ASSERTS deprecated in mainline, replace by warning + error handling
-
-brcm80211 info page
-=====================
-http://linuxwireless.org/en/users/Drivers/brcm80211
index da3c805..71c7fe9 100644 (file)
 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-ccflags-y :=                   \
-       -DBRCMF_FIRSTREAD=64    \
-       -DBRCMF_SDALIGN=64      \
-       -DMAX_HDR_READ=64
-
-ccflags-$(CONFIG_BRCMDBG)      += -DSHOW_EVENTS
-
 ccflags-y += \
        -Idrivers/staging/brcm80211/brcmfmac    \
        -Idrivers/staging/brcm80211/include
 
+ccflags-y += -DISR_THREAD
+
 DHDOFILES = \
        wl_cfg80211.o \
        dhd_cdc.o \
@@ -37,3 +32,4 @@ DHDOFILES = \
 
 obj-$(CONFIG_BRCMFMAC) += brcmfmac.o
 brcmfmac-objs += $(DHDOFILES)
+ccflags-y += -D__CHECK_ENDIAN__
index f4e72ed..bff9dcd 100644 (file)
@@ -21,6 +21,9 @@
 #include <linux/pci_ids.h>
 #include <linux/sched.h>
 #include <linux/completion.h>
+#include <linux/mmc/sdio.h>
+#include <linux/mmc/sdio_func.h>
+#include <linux/mmc/card.h>
 
 #include <defs.h>
 #include <brcm_hw_ids.h>
 #include <soc.h>
 #include "dhd.h"
 #include "dhd_bus.h"
+#include "dhd_dbg.h"
 #include "sdio_host.h"
 
 #define SDIOH_API_ACCESS_RETRY_LIMIT   2
 
-#define BRCMF_SD_ERROR_VAL     0x0001  /* Error */
-#define BRCMF_SD_INFO_VAL              0x0002  /* Info */
-
-
-#ifdef BCMDBG
-#define BRCMF_SD_ERROR(x) \
-       do { \
-               if ((brcmf_sdio_msglevel & BRCMF_SD_ERROR_VAL) && \
-                   net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#define BRCMF_SD_INFO(x)       \
-       do { \
-               if ((brcmf_sdio_msglevel & BRCMF_SD_INFO_VAL) && \
-                   net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#else                          /* BCMDBG */
-#define BRCMF_SD_ERROR(x)
-#define BRCMF_SD_INFO(x)
-#endif                         /* BCMDBG */
-
-/* debugging macros */
-#define SDLX_MSG(x)
-
-#define SDIOH_CMD_TYPE_NORMAL   0      /* Normal command */
-#define SDIOH_CMD_TYPE_APPEND   1      /* Append command */
-#define SDIOH_CMD_TYPE_CUTTHRU  2      /* Cut-through command */
-
-#define SDIOH_DATA_PIO          0      /* PIO mode */
-#define SDIOH_DATA_DMA          1      /* DMA mode */
-
-struct brcmf_sdio_card {
-       bool init_success;      /* underlying driver successfully attached */
-       void *sdioh;            /* handler for sdioh */
-       u32 vendevid;   /* Target Vendor and Device ID on SD bus */
-       bool regfail;           /* Save status of last
-                                reg_read/reg_write call */
-       u32 sbwad;              /* Save backplane window address */
-};
-
-/**
- * SDIO Host Controller info
- */
-struct sdio_hc {
-       struct sdio_hc *next;
-       struct device *dev;     /* platform device handle */
-       void *regs;             /* SDIO Host Controller address */
-       struct brcmf_sdio_card *card;
-       void *ch;
-       unsigned int oob_irq;
-       unsigned long oob_flags;        /* OOB Host specifiction
-                                       as edge and etc */
-       bool oob_irq_registered;
-};
-
-/* local copy of bcm sd handler */
-static struct brcmf_sdio_card *l_card;
-
-const uint brcmf_sdio_msglevel = BRCMF_SD_ERROR_VAL;
-
-static struct sdio_hc *sdhcinfo;
-
-/* driver info, initialized when brcmf_sdio_register is called */
-static struct brcmf_sdioh_driver drvinfo = { NULL, NULL };
-
-/* Module parameters specific to each host-controller driver */
-
-module_param(sd_msglevel, uint, 0);
-
-extern uint sd_f2_blocksize;
-module_param(sd_f2_blocksize, int, 0);
-
-/* forward declarations */
-int brcmf_sdio_probe(struct device *dev);
-EXPORT_SYMBOL(brcmf_sdio_probe);
-
-int brcmf_sdio_remove(struct device *dev);
-EXPORT_SYMBOL(brcmf_sdio_remove);
-
-struct brcmf_sdio_card*
-brcmf_sdcard_attach(void *cfghdl, u32 *regsva, uint irq)
+static void brcmf_sdioh_irqhandler(struct sdio_func *func)
 {
-       struct brcmf_sdio_card *card;
+       struct brcmf_sdio_dev *sdiodev = dev_get_drvdata(&func->card->dev);
 
-       card = kzalloc(sizeof(struct brcmf_sdio_card), GFP_ATOMIC);
-       if (card == NULL) {
-               BRCMF_SD_ERROR(("sdcard_attach: out of memory"));
-               return NULL;
-       }
-
-       /* save the handler locally */
-       l_card = card;
-
-       card->sdioh = brcmf_sdioh_attach(cfghdl, irq);
-       if (!card->sdioh) {
-               brcmf_sdcard_detach(card);
-               return NULL;
-       }
+       brcmf_dbg(TRACE, "***IRQHandler\n");
 
-       card->init_success = true;
+       sdio_release_host(func);
 
-       *regsva = SI_ENUM_BASE;
+       brcmf_sdbrcm_isr(sdiodev->bus);
 
-       /* Report the BAR, to fix if needed */
-       card->sbwad = SI_ENUM_BASE;
-       return card;
+       sdio_claim_host(func);
 }
 
-int brcmf_sdcard_detach(struct brcmf_sdio_card *card)
+int brcmf_sdcard_intr_reg(struct brcmf_sdio_dev *sdiodev)
 {
-       if (card != NULL) {
-               if (card->sdioh) {
-                       brcmf_sdioh_detach(card->sdioh);
-                       card->sdioh = NULL;
-               }
-               kfree(card);
-       }
-
-       l_card = NULL;
-       return 0;
-}
+       brcmf_dbg(TRACE, "Entering\n");
 
-int
-brcmf_sdcard_iovar_op(struct brcmf_sdio_card *card, const char *name,
-               void *params, int plen, void *arg, int len, bool set)
-{
-       return brcmf_sdioh_iovar_op(card->sdioh, name, params, plen, arg,
-                                   len, set);
-}
+       sdio_claim_host(sdiodev->func[1]);
+       sdio_claim_irq(sdiodev->func[1], brcmf_sdioh_irqhandler);
+       sdio_release_host(sdiodev->func[1]);
 
-int brcmf_sdcard_intr_enable(struct brcmf_sdio_card *card)
-{
-       return brcmf_sdioh_interrupt_set(card->sdioh, true);
+       return 0;
 }
 
-int brcmf_sdcard_intr_disable(struct brcmf_sdio_card *card)
+int brcmf_sdcard_intr_dereg(struct brcmf_sdio_dev *sdiodev)
 {
-       return brcmf_sdioh_interrupt_set(card->sdioh, false);
-}
+       brcmf_dbg(TRACE, "Entering\n");
 
-int brcmf_sdcard_intr_reg(struct brcmf_sdio_card *card,
-                         void (*fn)(void *), void *argh)
-{
-       return brcmf_sdioh_interrupt_register(card->sdioh, fn, argh);
-}
+       sdio_claim_host(sdiodev->func[1]);
+       sdio_release_irq(sdiodev->func[1]);
+       sdio_release_host(sdiodev->func[1]);
 
-int brcmf_sdcard_intr_dereg(struct brcmf_sdio_card *card)
-{
-       return brcmf_sdioh_interrupt_deregister(card->sdioh);
+       return 0;
 }
 
-u8 brcmf_sdcard_cfg_read(struct brcmf_sdio_card *card, uint fnc_num, u32 addr,
+u8 brcmf_sdcard_cfg_read(struct brcmf_sdio_dev *sdiodev, uint fnc_num, u32 addr,
                         int *err)
 {
        int status;
        s32 retry = 0;
        u8 data = 0;
 
-       if (!card)
-               card = l_card;
-
        do {
                if (retry)      /* wait for 1 ms till bus get settled down */
                        udelay(1000);
-               status =
-                   brcmf_sdioh_cfg_read(card->sdioh, fnc_num, addr,
-                                  (u8 *) &data);
+               status = brcmf_sdioh_request_byte(sdiodev, SDIOH_READ, fnc_num,
+                                                 addr, (u8 *) &data);
        } while (status != 0
                 && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
        if (err)
                *err = status;
 
-       BRCMF_SD_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n",
-                    __func__, fnc_num, addr, data));
+       brcmf_dbg(INFO, "fun = %d, addr = 0x%x, u8data = 0x%x\n",
+                 fnc_num, addr, data);
 
        return data;
 }
 
 void
-brcmf_sdcard_cfg_write(struct brcmf_sdio_card *card, uint fnc_num, u32 addr,
+brcmf_sdcard_cfg_write(struct brcmf_sdio_dev *sdiodev, uint fnc_num, u32 addr,
                       u8 data, int *err)
 {
        int status;
        s32 retry = 0;
 
-       if (!card)
-               card = l_card;
-
        do {
                if (retry)      /* wait for 1 ms till bus get settled down */
                        udelay(1000);
-               status =
-                   brcmf_sdioh_cfg_write(card->sdioh, fnc_num, addr,
-                                   (u8 *) &data);
+               status = brcmf_sdioh_request_byte(sdiodev, SDIOH_WRITE, fnc_num,
+                                                 addr, (u8 *) &data);
        } while (status != 0
                 && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT));
        if (err)
                *err = status;
 
-       BRCMF_SD_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n",
-                    __func__, fnc_num, addr, data));
+       brcmf_dbg(INFO, "fun = %d, addr = 0x%x, u8data = 0x%x\n",
+                 fnc_num, addr, data);
 }
 
-u32 brcmf_sdcard_cfg_read_word(struct brcmf_sdio_card *card, uint fnc_num,
-                              u32 addr, int *err)
-{
-       int status;
-       u32 data = 0;
-
-       if (!card)
-               card = l_card;
-
-       status = brcmf_sdioh_request_word(card->sdioh, SDIOH_CMD_TYPE_NORMAL,
-               SDIOH_READ, fnc_num, addr, &data, 4);
-
-       if (err)
-               *err = status;
-
-       BRCMF_SD_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n",
-                    __func__, fnc_num, addr, data));
-
-       return data;
-}
-
-void
-brcmf_sdcard_cfg_write_word(struct brcmf_sdio_card *card, uint fnc_num,
-                           u32 addr, u32 data, int *err)
-{
-       int status;
-
-       if (!card)
-               card = l_card;
-
-       status =
-           brcmf_sdioh_request_word(card->sdioh, SDIOH_CMD_TYPE_NORMAL,
-                              SDIOH_WRITE, fnc_num, addr, &data, 4);
-
-       if (err)
-               *err = status;
-
-       BRCMF_SD_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n",
-                    __func__, fnc_num, addr, data));
-}
-
-int brcmf_sdcard_cis_read(struct brcmf_sdio_card *card, uint func, u8 * cis,
-                         uint length)
-{
-       int status;
-
-       u8 *tmp_buf, *tmp_ptr;
-       u8 *ptr;
-       bool ascii = func & ~0xf;
-       func &= 0x7;
-
-       if (!card)
-               card = l_card;
-
-       status = brcmf_sdioh_cis_read(card->sdioh, func, cis, length);
-
-       if (ascii) {
-               /* Move binary bits to tmp and format them
-                        into the provided buffer. */
-               tmp_buf = kmalloc(length, GFP_ATOMIC);
-               if (tmp_buf == NULL) {
-                       BRCMF_SD_ERROR(("%s: out of memory\n", __func__));
-                       return -ENOMEM;
-               }
-               memcpy(tmp_buf, cis, length);
-               for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4);
-                    tmp_ptr++) {
-                       ptr += sprintf((char *)ptr, "%.2x ", *tmp_ptr & 0xff);
-                       if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0)
-                               ptr += sprintf((char *)ptr, "\n");
-               }
-               kfree(tmp_buf);
-       }
-
-       return status;
-}
-
-static int
-brcmf_sdcard_set_sbaddr_window(struct brcmf_sdio_card *card, u32 address)
+int
+brcmf_sdcard_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address)
 {
        int err = 0;
-       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
+       brcmf_sdcard_cfg_write(sdiodev, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
                         (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
        if (!err)
-               brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+               brcmf_sdcard_cfg_write(sdiodev, SDIO_FUNC_1,
                                       SBSDIO_FUNC1_SBADDRMID,
                                       (address >> 16) & SBSDIO_SBADDRMID_MASK,
                                       &err);
        if (!err)
-               brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+               brcmf_sdcard_cfg_write(sdiodev, SDIO_FUNC_1,
                                       SBSDIO_FUNC1_SBADDRHIGH,
                                       (address >> 24) & SBSDIO_SBADDRHIGH_MASK,
                                       &err);
@@ -334,34 +136,31 @@ brcmf_sdcard_set_sbaddr_window(struct brcmf_sdio_card *card, u32 address)
        return err;
 }
 
-u32 brcmf_sdcard_reg_read(struct brcmf_sdio_card *card, u32 addr, uint size)
+u32 brcmf_sdcard_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr, uint size)
 {
        int status;
        u32 word = 0;
        uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
 
-       BRCMF_SD_INFO(("%s:fun = 1, addr = 0x%x, ", __func__, addr));
-
-       if (!card)
-               card = l_card;
+       brcmf_dbg(INFO, "fun = 1, addr = 0x%x\n", addr);
 
-       if (bar0 != card->sbwad) {
-               if (brcmf_sdcard_set_sbaddr_window(card, bar0))
+       if (bar0 != sdiodev->sbwad) {
+               if (brcmf_sdcard_set_sbaddr_window(sdiodev, bar0))
                        return 0xFFFFFFFF;
 
-               card->sbwad = bar0;
+               sdiodev->sbwad = bar0;
        }
 
        addr &= SBSDIO_SB_OFT_ADDR_MASK;
        if (size == 4)
                addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
 
-       status = brcmf_sdioh_request_word(card->sdioh, SDIOH_CMD_TYPE_NORMAL,
-                                   SDIOH_READ, SDIO_FUNC_1, addr, &word, size);
+       status = brcmf_sdioh_request_word(sdiodev, SDIOH_READ, SDIO_FUNC_1,
+                                         addr, &word, size);
 
-       card->regfail = (status != 0);
+       sdiodev->regfail = (status != 0);
 
-       BRCMF_SD_INFO(("u32data = 0x%x\n", word));
+       brcmf_dbg(INFO, "u32data = 0x%x\n", word);
 
        /* if ok, return appropriately masked word */
        if (status == 0) {
@@ -373,66 +172,59 @@ u32 brcmf_sdcard_reg_read(struct brcmf_sdio_card *card, u32 addr, uint size)
                case sizeof(u32):
                        return word;
                default:
-                       card->regfail = true;
+                       sdiodev->regfail = true;
 
                }
        }
 
        /* otherwise, bad sdio access or invalid size */
-       BRCMF_SD_ERROR(("%s: error reading addr 0x%04x size %d\n", __func__,
-                     addr, size));
+       brcmf_dbg(ERROR, "error reading addr 0x%04x size %d\n", addr, size);
        return 0xFFFFFFFF;
 }
 
-u32 brcmf_sdcard_reg_write(struct brcmf_sdio_card *card, u32 addr, uint size,
+u32 brcmf_sdcard_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr, uint size,
                           u32 data)
 {
        int status;
        uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
        int err = 0;
 
-       BRCMF_SD_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n",
-                    __func__, addr, size * 8, data));
-
-       if (!card)
-               card = l_card;
+       brcmf_dbg(INFO, "fun = 1, addr = 0x%x, uint%ddata = 0x%x\n",
+                 addr, size * 8, data);
 
-       if (bar0 != card->sbwad) {
-               err = brcmf_sdcard_set_sbaddr_window(card, bar0);
+       if (bar0 != sdiodev->sbwad) {
+               err = brcmf_sdcard_set_sbaddr_window(sdiodev, bar0);
                if (err)
                        return err;
 
-               card->sbwad = bar0;
+               sdiodev->sbwad = bar0;
        }
 
        addr &= SBSDIO_SB_OFT_ADDR_MASK;
        if (size == 4)
                addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
        status =
-           brcmf_sdioh_request_word(card->sdioh, SDIOH_CMD_TYPE_NORMAL,
-                              SDIOH_WRITE, SDIO_FUNC_1, addr, &data, size);
-       card->regfail = (status != 0);
+           brcmf_sdioh_request_word(sdiodev, SDIOH_WRITE, SDIO_FUNC_1,
+                                    addr, &data, size);
+       sdiodev->regfail = (status != 0);
 
        if (status == 0)
                return 0;
 
-       BRCMF_SD_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n",
-                     __func__, data, addr, size));
+       brcmf_dbg(ERROR, "error writing 0x%08x to addr 0x%04x size %d\n",
+                 data, addr, size);
        return 0xFFFFFFFF;
 }
 
-bool brcmf_sdcard_regfail(struct brcmf_sdio_card *card)
+bool brcmf_sdcard_regfail(struct brcmf_sdio_dev *sdiodev)
 {
-       return card->regfail;
+       return sdiodev->regfail;
 }
 
 int
-brcmf_sdcard_recv_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
+brcmf_sdcard_recv_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
                      uint flags,
-                     u8 *buf, uint nbytes, struct sk_buff *pkt,
-                     void (*complete)(void *handle, int status,
-                                      bool sync_waiting),
-                     void *handle)
+                     u8 *buf, uint nbytes, struct sk_buff *pkt)
 {
        int status;
        uint incr_fix;
@@ -440,19 +232,18 @@ brcmf_sdcard_recv_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
        uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
        int err = 0;
 
-       BRCMF_SD_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
-                    __func__, fn, addr, nbytes));
+       brcmf_dbg(INFO, "fun = %d, addr = 0x%x, size = %d\n", fn, addr, nbytes);
 
        /* Async not implemented yet */
        if (flags & SDIO_REQ_ASYNC)
                return -ENOTSUPP;
 
-       if (bar0 != card->sbwad) {
-               err = brcmf_sdcard_set_sbaddr_window(card, bar0);
+       if (bar0 != sdiodev->sbwad) {
+               err = brcmf_sdcard_set_sbaddr_window(sdiodev, bar0);
                if (err)
                        return err;
 
-               card->sbwad = bar0;
+               sdiodev->sbwad = bar0;
        }
 
        addr &= SBSDIO_SB_OFT_ADDR_MASK;
@@ -462,37 +253,33 @@ brcmf_sdcard_recv_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
        if (width == 4)
                addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
 
-       status = brcmf_sdioh_request_buffer(card->sdioh, SDIOH_DATA_PIO,
-               incr_fix, SDIOH_READ, fn, addr, width, nbytes, buf, pkt);
+       status = brcmf_sdioh_request_buffer(sdiodev, incr_fix, SDIOH_READ,
+                                           fn, addr, width, nbytes, buf, pkt);
 
        return status;
 }
 
 int
-brcmf_sdcard_send_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
-                     uint flags, u8 *buf, uint nbytes, void *pkt,
-                     void (*complete)(void *handle, int status,
-                                      bool sync_waiting),
-                     void *handle)
+brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
+                     uint flags, u8 *buf, uint nbytes, struct sk_buff *pkt)
 {
        uint incr_fix;
        uint width;
        uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK;
        int err = 0;
 
-       BRCMF_SD_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n",
-                    __func__, fn, addr, nbytes));
+       brcmf_dbg(INFO, "fun = %d, addr = 0x%x, size = %d\n", fn, addr, nbytes);
 
        /* Async not implemented yet */
        if (flags & SDIO_REQ_ASYNC)
                return -ENOTSUPP;
 
-       if (bar0 != card->sbwad) {
-               err = brcmf_sdcard_set_sbaddr_window(card, bar0);
+       if (bar0 != sdiodev->sbwad) {
+               err = brcmf_sdcard_set_sbaddr_window(sdiodev, bar0);
                if (err)
                        return err;
 
-               card->sbwad = bar0;
+               sdiodev->sbwad = bar0;
        }
 
        addr &= SBSDIO_SB_OFT_ADDR_MASK;
@@ -502,141 +289,83 @@ brcmf_sdcard_send_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
        if (width == 4)
                addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
 
-       return brcmf_sdioh_request_buffer(card->sdioh, SDIOH_DATA_PIO,
-               incr_fix, SDIOH_WRITE, fn, addr, width, nbytes, buf, pkt);
+       return brcmf_sdioh_request_buffer(sdiodev, incr_fix, SDIOH_WRITE, fn,
+                                         addr, width, nbytes, buf, pkt);
 }
 
-int brcmf_sdcard_rwdata(struct brcmf_sdio_card *card, uint rw, u32 addr,
+int brcmf_sdcard_rwdata(struct brcmf_sdio_dev *sdiodev, uint rw, u32 addr,
                        u8 *buf, uint nbytes)
 {
        addr &= SBSDIO_SB_OFT_ADDR_MASK;
        addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
 
-       return brcmf_sdioh_request_buffer(card->sdioh, SDIOH_DATA_PIO,
-               SDIOH_DATA_INC, (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1,
+       return brcmf_sdioh_request_buffer(sdiodev, SDIOH_DATA_INC,
+               (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1,
                addr, 4, nbytes, buf, NULL);
 }
 
-int brcmf_sdcard_abort(struct brcmf_sdio_card *card, uint fn)
+int brcmf_sdcard_abort(struct brcmf_sdio_dev *sdiodev, uint fn)
 {
-       return brcmf_sdioh_abort(card->sdioh, fn);
-}
-
-int brcmf_sdcard_query_device(struct brcmf_sdio_card *card)
-{
-       card->vendevid = (PCI_VENDOR_ID_BROADCOM << 16) | 0;
-       return card->vendevid;
-}
+       char t_func = (char)fn;
+       brcmf_dbg(TRACE, "Enter\n");
 
-u32 brcmf_sdcard_cur_sbwad(struct brcmf_sdio_card *card)
-{
-       if (!card)
-               card = l_card;
+       /* issue abort cmd52 command through F0 */
+       brcmf_sdioh_request_byte(sdiodev, SDIOH_WRITE, SDIO_FUNC_0,
+                                SDIO_CCCR_ABORT, &t_func);
 
-       return card->sbwad;
+       brcmf_dbg(TRACE, "Exit\n");
+       return 0;
 }
 
-int brcmf_sdio_probe(struct device *dev)
+int brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
 {
-       struct sdio_hc *sdhc = NULL;
        u32 regs = 0;
-       struct brcmf_sdio_card *card = NULL;
-       int irq = 0;
-       u32 vendevid;
-       unsigned long irq_flags = 0;
-
-       /* allocate SDIO Host Controller state info */
-       sdhc = kzalloc(sizeof(struct sdio_hc), GFP_ATOMIC);
-       if (!sdhc) {
-               SDLX_MSG(("%s: out of memory\n", __func__));
-               goto err;
-       }
-       sdhc->dev = (void *)dev;
+       int ret = 0;
 
-       card = brcmf_sdcard_attach((void *)0, &regs, irq);
-       if (!card) {
-               SDLX_MSG(("%s: attach failed\n", __func__));
-               goto err;
-       }
+       ret = brcmf_sdioh_attach(sdiodev);
+       if (ret)
+               goto out;
 
-       sdhc->card = card;
-       sdhc->oob_irq = irq;
-       sdhc->oob_flags = irq_flags;
-       sdhc->oob_irq_registered = false;       /* to make sure.. */
+       regs = SI_ENUM_BASE;
 
-       /* chain SDIO Host Controller info together */
-       sdhc->next = sdhcinfo;
-       sdhcinfo = sdhc;
-       /* Read the vendor/device ID from the CIS */
-       vendevid = brcmf_sdcard_query_device(card);
+       /* Report the BAR, to fix if needed */
+       sdiodev->sbwad = SI_ENUM_BASE;
 
        /* try to attach to the target device */
-       sdhc->ch = drvinfo.attach((vendevid >> 16), (vendevid & 0xFFFF),
-                                 0, 0, 0, 0, regs, card);
-       if (!sdhc->ch) {
-               SDLX_MSG(("%s: device attach failed\n", __func__));
-               goto err;
+       sdiodev->bus = brcmf_sdbrcm_probe(0, 0, 0, 0, regs, sdiodev);
+       if (!sdiodev->bus) {
+               brcmf_dbg(ERROR, "device attach failed\n");
+               ret = -ENODEV;
+               goto out;
        }
 
-       return 0;
-
-       /* error handling */
-err:
-       if (sdhc) {
-               if (sdhc->card)
-                       brcmf_sdcard_detach(sdhc->card);
-               kfree(sdhc);
-       }
+out:
+       if (ret)
+               brcmf_sdio_remove(sdiodev);
 
-       return -ENODEV;
+       return ret;
 }
+EXPORT_SYMBOL(brcmf_sdio_probe);
 
-int brcmf_sdio_remove(struct device *dev)
+int brcmf_sdio_remove(struct brcmf_sdio_dev *sdiodev)
 {
-       struct sdio_hc *sdhc, *prev;
-
-       sdhc = sdhcinfo;
-       drvinfo.detach(sdhc->ch);
-       brcmf_sdcard_detach(sdhc->card);
-       /* find the SDIO Host Controller state for this pdev
-                and take it out from the list */
-       for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
-               if (sdhc->dev == (void *)dev) {
-                       if (prev)
-                               prev->next = sdhc->next;
-                       else
-                               sdhcinfo = NULL;
-                       break;
-               }
-               prev = sdhc;
-       }
-       if (!sdhc) {
-               SDLX_MSG(("%s: failed\n", __func__));
-               return 0;
+       if (sdiodev->bus) {
+               brcmf_sdbrcm_disconnect(sdiodev->bus);
+               sdiodev->bus = NULL;
        }
 
-       /* release SDIO Host Controller info */
-       kfree(sdhc);
-       return 0;
-}
-
-int brcmf_sdio_register(struct brcmf_sdioh_driver *driver)
-{
-       drvinfo = *driver;
+       brcmf_sdioh_detach(sdiodev);
 
-       SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
-       return brcmf_sdio_function_init();
-}
+       sdiodev->sbwad = 0;
 
-void brcmf_sdio_unregister(void)
-{
-       brcmf_sdio_function_cleanup();
+       return 0;
 }
+EXPORT_SYMBOL(brcmf_sdio_remove);
 
-void brcmf_sdio_wdtmr_enable(bool enable)
+void brcmf_sdio_wdtmr_enable(struct brcmf_sdio_dev *sdiodev, bool enable)
 {
        if (enable)
-               brcmf_sdbrcm_wd_timer(sdhcinfo->ch, brcmf_watchdog_ms);
+               brcmf_sdbrcm_wd_timer(sdiodev->bus, BRCMF_WD_POLL_MS);
        else
-               brcmf_sdbrcm_wd_timer(sdhcinfo->ch, 0);
+               brcmf_sdbrcm_wd_timer(sdiodev->bus, 0);
 }
index 38bd9ba..bbaeb2d 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/suspend.h>
 #include <linux/errno.h>
 #include <linux/sched.h>       /* request_irq() */
+#include <linux/module.h>
 #include <net/cfg80211.h>
 
 #include <defs.h>
 #include "dhd_dbg.h"
 #include "wl_cfg80211.h"
 
-#define BLOCK_SIZE_64 64
-#define BLOCK_SIZE_512 512
-#define BLOCK_SIZE_4318 64
-#define BLOCK_SIZE_4328 512
-
-/* private bus modes */
-#define SDIOH_MODE_SD4         2
-
-#define CLIENT_INTR            0x100   /* Get rid of this! */
-
-#if !defined(SDIO_VENDOR_ID_BROADCOM)
 #define SDIO_VENDOR_ID_BROADCOM                0x02d0
-#endif                         /* !defined(SDIO_VENDOR_ID_BROADCOM) */
-
-#define SDIO_DEVICE_ID_BROADCOM_DEFAULT        0x0000
 
 #define DMA_ALIGN_MASK 0x03
 
-#if !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB)
-#define SDIO_DEVICE_ID_BROADCOM_4325_SDGWB     0x0492  /* BCM94325SDGWB */
-#endif         /* !defined(SDIO_DEVICE_ID_BROADCOM_4325_SDGWB) */
-#if !defined(SDIO_DEVICE_ID_BROADCOM_4325)
-#define SDIO_DEVICE_ID_BROADCOM_4325   0x0493
-#endif         /* !defined(SDIO_DEVICE_ID_BROADCOM_4325) */
-#if !defined(SDIO_DEVICE_ID_BROADCOM_4329)
 #define SDIO_DEVICE_ID_BROADCOM_4329   0x4329
-#endif         /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
-#if !defined(SDIO_DEVICE_ID_BROADCOM_4319)
-#define SDIO_DEVICE_ID_BROADCOM_4319   0x4319
-#endif         /* !defined(SDIO_DEVICE_ID_BROADCOM_4329) */
-
-/* Common msglevel constants */
-#define SDH_ERROR_VAL          0x0001  /* Error */
-#define SDH_TRACE_VAL          0x0002  /* Trace */
-#define SDH_INFO_VAL           0x0004  /* Info */
-#define SDH_DEBUG_VAL          0x0008  /* Debug */
-#define SDH_DATA_VAL           0x0010  /* Data */
-#define SDH_CTRL_VAL           0x0020  /* Control Regs */
-#define SDH_LOG_VAL            0x0040  /* Enable bcmlog */
-#define SDH_DMA_VAL            0x0080  /* DMA */
-
-#ifdef BCMDBG
-#define sd_err(x)      \
-       do { \
-               if ((sd_msglevel & SDH_ERROR_VAL) && net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#define sd_trace(x)    \
-       do { \
-               if ((sd_msglevel & SDH_TRACE_VAL) && net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#define sd_info(x)     \
-       do { \
-               if ((sd_msglevel & SDH_INFO_VAL) && net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#define sd_debug(x)    \
-       do { \
-               if ((sd_msglevel & SDH_DEBUG_VAL) && net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#define sd_data(x)     \
-       do { \
-               if ((sd_msglevel & SDH_DATA_VAL) && net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#define sd_ctrl(x)     \
-       do { \
-               if ((sd_msglevel & SDH_CTRL_VAL) && net_ratelimit()) \
-                       printk x; \
-       } while (0)
-#else
-#define sd_err(x)
-#define sd_trace(x)
-#define sd_info(x)
-#define sd_debug(x)
-#define sd_data(x)
-#define sd_ctrl(x)
-#endif
-
-struct sdos_info {
-       struct sdioh_info *sd;
-       spinlock_t lock;
-};
-
-static void brcmf_sdioh_irqhandler(struct sdio_func *func);
-static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func);
-static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr);
-static int brcmf_ops_sdio_probe(struct sdio_func *func,
-                               const struct sdio_device_id *id);
-static void brcmf_ops_sdio_remove(struct sdio_func *func);
-
-#ifdef CONFIG_PM
-static int brcmf_sdio_suspend(struct device *dev);
-static int brcmf_sdio_resume(struct device *dev);
-#endif /* CONFIG_PM */
 
-uint sd_f2_blocksize = 512;    /* Default blocksize */
-
-uint sd_msglevel = 0x01;
-
-/* module param defaults */
-static int clockoverride;
-
-module_param(clockoverride, int, 0644);
-MODULE_PARM_DESC(clockoverride, "SDIO card clock override");
-
-struct brcmf_sdmmc_instance *gInstance;
-
-struct device sdmmc_dev;
+#define SDIO_FUNC1_BLOCKSIZE           64
+#define SDIO_FUNC2_BLOCKSIZE           512
 
 /* devices we support, null terminated */
 static const struct sdio_device_id brcmf_sdmmc_ids[] = {
-       {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_DEFAULT)},
-       {SDIO_DEVICE
-        (SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325_SDGWB)},
-       {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4325)},
        {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4329)},
-       {SDIO_DEVICE(SDIO_VENDOR_ID_BROADCOM, SDIO_DEVICE_ID_BROADCOM_4319)},
        { /* end: all zeroes */ },
 };
-
-#ifdef CONFIG_PM
-static const struct dev_pm_ops brcmf_sdio_pm_ops = {
-       .suspend        = brcmf_sdio_suspend,
-       .resume         = brcmf_sdio_resume,
-};
-#endif /* CONFIG_PM */
-
-static struct sdio_driver brcmf_sdmmc_driver = {
-       .probe = brcmf_ops_sdio_probe,
-       .remove = brcmf_ops_sdio_remove,
-       .name = "brcmfmac",
-       .id_table = brcmf_sdmmc_ids,
-#ifdef CONFIG_PM
-       .drv = {
-               .pm = &brcmf_sdio_pm_ops,
-       },
-#endif /* CONFIG_PM */
-};
-
 MODULE_DEVICE_TABLE(sdio, brcmf_sdmmc_ids);
 
-BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait);
-BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_word_wait);
-BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait);
-BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait);
-
-static int
-brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
-                        int regsize, u32 *data);
-
-static int brcmf_sdioh_enablefuncs(struct sdioh_info *sd)
+static bool
+brcmf_pm_resume_error(struct brcmf_sdio_dev *sdiodev)
 {
-       int err_ret;
-       u32 fbraddr;
-       u8 func;
-
-       sd_trace(("%s\n", __func__));
-
-       /* Get the Card's common CIS address */
-       sd->com_cis_ptr = brcmf_sdioh_get_cisaddr(sd, SDIO_CCCR_CIS);
-       sd->func_cis_ptr[0] = sd->com_cis_ptr;
-       sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
-                sd->com_cis_ptr));
-
-       /* Get the Card's function CIS (for each function) */
-       for (fbraddr = SDIO_FBR_BASE(1), func = 1;
-            func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
-               sd->func_cis_ptr[func] =
-                   brcmf_sdioh_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr);
-               sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func,
-                        sd->func_cis_ptr[func]));
-       }
-
-       sd->func_cis_ptr[0] = sd->com_cis_ptr;
-       sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
-                sd->com_cis_ptr));
-
-       /* Enable Function 1 */
-       sdio_claim_host(gInstance->func[1]);
-       err_ret = sdio_enable_func(gInstance->func[1]);
-       sdio_release_host(gInstance->func[1]);
-       if (err_ret) {
-               sd_err(("brcmf_sdioh_enablefuncs: Failed to enable F1 "
-                       "Err: 0x%08x\n", err_ret));
-       }
-
-       return false;
-}
-
-/*
- *     Public entry points & extern's
- */
-struct sdioh_info *brcmf_sdioh_attach(void *bar0, uint irq)
-{
-       struct sdioh_info *sd;
-       int err_ret;
-
-       sd_trace(("%s\n", __func__));
-
-       if (gInstance == NULL) {
-               sd_err(("%s: SDIO Device not present\n", __func__));
-               return NULL;
-       }
-
-       sd = kzalloc(sizeof(struct sdioh_info), GFP_ATOMIC);
-       if (sd == NULL) {
-               sd_err(("sdioh_attach: out of memory\n"));
-               return NULL;
-       }
-       if (brcmf_sdioh_osinit(sd) != 0) {
-               sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__));
-               kfree(sd);
-               return NULL;
-       }
-
-       sd->num_funcs = 2;
-       sd->use_client_ints = true;
-       sd->client_block_size[0] = 64;
-
-       gInstance->sd = sd;
-
-       /* Claim host controller */
-       sdio_claim_host(gInstance->func[1]);
-
-       sd->client_block_size[1] = 64;
-       err_ret = sdio_set_block_size(gInstance->func[1], 64);
-       if (err_ret)
-               sd_err(("brcmf_sdioh_attach: Failed to set F1 blocksize\n"));
-
-       /* Release host controller F1 */
-       sdio_release_host(gInstance->func[1]);
-
-       if (gInstance->func[2]) {
-               /* Claim host controller F2 */
-               sdio_claim_host(gInstance->func[2]);
-
-               sd->client_block_size[2] = sd_f2_blocksize;
-               err_ret =
-                   sdio_set_block_size(gInstance->func[2], sd_f2_blocksize);
-               if (err_ret)
-                       sd_err(("brcmf_sdioh_attach: Failed to set F2 blocksize"
-                               " to %d\n", sd_f2_blocksize));
-
-               /* Release host controller F2 */
-               sdio_release_host(gInstance->func[2]);
-       }
-
-       brcmf_sdioh_enablefuncs(sd);
-
-       sd_trace(("%s: Done\n", __func__));
-       return sd;
-}
-
-extern int brcmf_sdioh_detach(struct sdioh_info *sd)
-{
-       sd_trace(("%s\n", __func__));
-
-       if (sd) {
-
-               /* Disable Function 2 */
-               sdio_claim_host(gInstance->func[2]);
-               sdio_disable_func(gInstance->func[2]);
-               sdio_release_host(gInstance->func[2]);
-
-               /* Disable Function 1 */
-               sdio_claim_host(gInstance->func[1]);
-               sdio_disable_func(gInstance->func[1]);
-               sdio_release_host(gInstance->func[1]);
-
-               /* deregister irq */
-               brcmf_sdioh_osfree(sd);
-
-               kfree(sd);
-       }
-       return 0;
-}
-
-/* Configure callback to client when we receive client interrupt */
-extern int
-brcmf_sdioh_interrupt_register(struct sdioh_info *sd, void (*fn)(void *),
-                              void *argh)
-{
-       sd_trace(("%s: Entering\n", __func__));
-       if (fn == NULL) {
-               sd_err(("%s: interrupt handler is NULL, not registering\n",
-                       __func__));
-               return -EINVAL;
-       }
-
-       sd->intr_handler = fn;
-       sd->intr_handler_arg = argh;
-       sd->intr_handler_valid = true;
-
-       /* register and unmask irq */
-       if (gInstance->func[2]) {
-               sdio_claim_host(gInstance->func[2]);
-               sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2);
-               sdio_release_host(gInstance->func[2]);
-       }
-
-       if (gInstance->func[1]) {
-               sdio_claim_host(gInstance->func[1]);
-               sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler);
-               sdio_release_host(gInstance->func[1]);
-       }
-
-       return 0;
+       bool is_err = false;
+#ifdef CONFIG_PM_SLEEP
+       is_err = atomic_read(&sdiodev->suspend);
+#endif
+       return is_err;
 }
 
-extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *sd)
+static void
+brcmf_pm_resume_wait(struct brcmf_sdio_dev *sdiodev, wait_queue_head_t *wq)
 {
-       sd_trace(("%s: Entering\n", __func__));
-
-       if (gInstance->func[1]) {
-               /* register and unmask irq */
-               sdio_claim_host(gInstance->func[1]);
-               sdio_release_irq(gInstance->func[1]);
-               sdio_release_host(gInstance->func[1]);
-       }
-
-       if (gInstance->func[2]) {
-               /* Claim host controller F2 */
-               sdio_claim_host(gInstance->func[2]);
-               sdio_release_irq(gInstance->func[2]);
-               /* Release host controller F2 */
-               sdio_release_host(gInstance->func[2]);
-       }
-
-       sd->intr_handler_valid = false;
-       sd->intr_handler = NULL;
-       sd->intr_handler_arg = NULL;
-
-       return 0;
+#ifdef CONFIG_PM_SLEEP
+       int retry = 0;
+       while (atomic_read(&sdiodev->suspend) && retry++ != 30)
+               wait_event_timeout(*wq, false, HZ/100);
+#endif
 }
 
-/* IOVar table */
-enum {
-       IOV_MSGLEVEL = 1,
-       IOV_BLOCKSIZE,
-       IOV_USEINTS,
-       IOV_NUMINTS,
-       IOV_DEVREG,
-       IOV_HCIREGS,
-       IOV_RXCHAIN
-};
-
-const struct brcmu_iovar sdioh_iovars[] = {
-       {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0},
-       {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) |
-                                                                size) */
-       {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0},
-       {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0},
-       {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
-       ,
-       {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0}
-       ,
-       {NULL, 0, 0, 0, 0}
-};
-
-int
-brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
-                    void *params, int plen, void *arg, int len, bool set)
+static inline int brcmf_sdioh_f0_write_byte(struct brcmf_sdio_dev *sdiodev,
+                                           uint regaddr, u8 *byte)
 {
-       const struct brcmu_iovar *vi = NULL;
-       int bcmerror = 0;
-       int val_size;
-       s32 int_val = 0;
-       bool bool_val;
-       u32 actionid;
-
-       if (name == NULL || len <= 0)
-               return -EINVAL;
-
-       /* Set does not take qualifiers */
-       if (set && (params || plen))
-               return -EINVAL;
-
-       /* Get must have return space;*/
-       if (!set && !(arg && len))
-               return -EINVAL;
-
-       sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"),
-                 name));
-
-       vi = brcmu_iovar_lookup(sdioh_iovars, name);
-       if (vi == NULL) {
-               bcmerror = -ENOTSUPP;
-               goto exit;
-       }
-
-       bcmerror = brcmu_iovar_lencheck(vi, arg, len, set);
-       if (bcmerror != 0)
-               goto exit;
-
-       /* Set up params so get and set can share the convenience variables */
-       if (params == NULL) {
-               params = arg;
-               plen = len;
-       }
-
-       if (vi->type == IOVT_VOID)
-               val_size = 0;
-       else if (vi->type == IOVT_BUFFER)
-               val_size = len;
-       else
-               val_size = sizeof(int);
-
-       if (plen >= (int)sizeof(int_val))
-               memcpy(&int_val, params, sizeof(int_val));
-
-       bool_val = (int_val != 0) ? true : false;
-
-       actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
-       switch (actionid) {
-       case IOV_GVAL(IOV_MSGLEVEL):
-               int_val = (s32) sd_msglevel;
-               memcpy(arg, &int_val, val_size);
-               break;
-
-       case IOV_SVAL(IOV_MSGLEVEL):
-               sd_msglevel = int_val;
-               break;
-
-       case IOV_GVAL(IOV_BLOCKSIZE):
-               if ((u32) int_val > si->num_funcs) {
-                       bcmerror = -EINVAL;
-                       break;
-               }
-               int_val = (s32) si->client_block_size[int_val];
-               memcpy(arg, &int_val, val_size);
-               break;
-
-       case IOV_SVAL(IOV_BLOCKSIZE):
-               {
-                       uint func = ((u32) int_val >> 16);
-                       uint blksize = (u16) int_val;
-                       uint maxsize;
-
-                       if (func > si->num_funcs) {
-                               bcmerror = -EINVAL;
-                               break;
-                       }
-
-                       switch (func) {
-                       case 0:
-                               maxsize = 32;
-                               break;
-                       case 1:
-                               maxsize = BLOCK_SIZE_4318;
-                               break;
-                       case 2:
-                               maxsize = BLOCK_SIZE_4328;
-                               break;
-                       default:
-                               maxsize = 0;
-                       }
-                       if (blksize > maxsize) {
-                               bcmerror = -EINVAL;
-                               break;
-                       }
-                       if (!blksize)
-                               blksize = maxsize;
-
-                       /* Now set it */
-                       si->client_block_size[func] = blksize;
-
-                       break;
-               }
-
-       case IOV_GVAL(IOV_RXCHAIN):
-               int_val = false;
-               memcpy(arg, &int_val, val_size);
-               break;
-
-       case IOV_GVAL(IOV_USEINTS):
-               int_val = (s32) si->use_client_ints;
-               memcpy(arg, &int_val, val_size);
-               break;
-
-       case IOV_SVAL(IOV_USEINTS):
-               si->use_client_ints = (bool) int_val;
-               if (si->use_client_ints)
-                       si->intmask |= CLIENT_INTR;
-               else
-                       si->intmask &= ~CLIENT_INTR;
-
-               break;
-
-       case IOV_GVAL(IOV_NUMINTS):
-               int_val = (s32) si->intrcount;
-               memcpy(arg, &int_val, val_size);
-               break;
-
-       case IOV_GVAL(IOV_DEVREG):
-               {
-                       struct brcmf_sdreg *sd_ptr =
-                                       (struct brcmf_sdreg *) params;
-                       u8 data = 0;
-
-                       if (brcmf_sdioh_cfg_read
-                           (si, sd_ptr->func, sd_ptr->offset, &data)) {
-                               bcmerror = -EIO;
-                               break;
-                       }
-
-                       int_val = (int)data;
-                       memcpy(arg, &int_val, sizeof(int_val));
-                       break;
-               }
-
-       case IOV_SVAL(IOV_DEVREG):
-               {
-                       struct brcmf_sdreg *sd_ptr =
-                                       (struct brcmf_sdreg *) params;
-                       u8 data = (u8) sd_ptr->value;
+       struct sdio_func *sdfunc = sdiodev->func[0];
+       int err_ret;
 
-                       if (brcmf_sdioh_cfg_write
-                           (si, sd_ptr->func, sd_ptr->offset, &data)) {
-                               bcmerror = -EIO;
-                               break;
+       /*
+        * Can only directly write to some F0 registers.
+        * Handle F2 enable/disable and Abort command
+        * as a special case.
+        */
+       if (regaddr == SDIO_CCCR_IOEx) {
+               sdfunc = sdiodev->func[2];
+               if (sdfunc) {
+                       sdio_claim_host(sdfunc);
+                       if (*byte & SDIO_FUNC_ENABLE_2) {
+                               /* Enable Function 2 */
+                               err_ret = sdio_enable_func(sdfunc);
+                               if (err_ret)
+                                       brcmf_dbg(ERROR,
+                                                 "enable F2 failed:%d\n",
+                                                 err_ret);
+                       } else {
+                               /* Disable Function 2 */
+                               err_ret = sdio_disable_func(sdfunc);
+                               if (err_ret)
+                                       brcmf_dbg(ERROR,
+                                                 "Disable F2 failed:%d\n",
+                                                 err_ret);
                        }
-                       break;
-               }
-
-       default:
-               bcmerror = -ENOTSUPP;
-               break;
-       }
-exit:
-
-       return bcmerror;
-}
-
-extern int
-brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
-{
-       int status;
-       /* No lock needed since brcmf_sdioh_request_byte does locking */
-       status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
-       return status;
-}
-
-extern int
-brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
-{
-       /* No lock needed since brcmf_sdioh_request_byte does locking */
-       int status;
-       status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
-       return status;
-}
-
-static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr)
-{
-       /* read 24 bits and return valid 17 bit addr */
-       int i;
-       u32 scratch, regdata;
-       u8 *ptr = (u8 *)&scratch;
-       for (i = 0; i < 3; i++) {
-               if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, &regdata)) !=
-                   SUCCESS)
-                       sd_err(("%s: Can't read!\n", __func__));
-
-               *ptr++ = (u8) regdata;
-               regaddr++;
-       }
-
-       /* Only the lower 17-bits are valid */
-       scratch = le32_to_cpu(scratch);
-       scratch &= 0x0001FFFF;
-       return scratch;
-}
-
-extern int
-brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length)
-{
-       u32 count;
-       int offset;
-       u32 foo;
-       u8 *cis = cisd;
-
-       sd_trace(("%s: Func = %d\n", __func__, func));
-
-       if (!sd->func_cis_ptr[func]) {
-               memset(cis, 0, length);
-               sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
-               return -ENOTSUPP;
-       }
-
-       sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
-               sd->func_cis_ptr[func]));
-
-       for (count = 0; count < length; count++) {
-               offset = sd->func_cis_ptr[func] + count;
-               if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
-                       sd_err(("%s: regread failed: Can't read CIS\n",
-                               __func__));
-                       return -EIO;
+                       sdio_release_host(sdfunc);
                }
-
-               *cis = (u8) (foo & 0xff);
-               cis++;
+       } else if (regaddr == SDIO_CCCR_ABORT) {
+               sdio_claim_host(sdfunc);
+               sdio_writeb(sdfunc, *byte, regaddr, &err_ret);
+               sdio_release_host(sdfunc);
+       } else if (regaddr < 0xF0) {
+               brcmf_dbg(ERROR, "F0 Wr:0x%02x: write disallowed\n", regaddr);
+               err_ret = -EPERM;
+       } else {
+               sdio_claim_host(sdfunc);
+               sdio_f0_writeb(sdfunc, *byte, regaddr, &err_ret);
+               sdio_release_host(sdfunc);
        }
 
-       return 0;
+       return err_ret;
 }
 
-extern int
-brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func,
-                        uint regaddr, u8 *byte)
+int brcmf_sdioh_request_byte(struct brcmf_sdio_dev *sdiodev, uint rw, uint func,
+                            uint regaddr, u8 *byte)
 {
        int err_ret;
 
-       sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
-                regaddr));
+       brcmf_dbg(INFO, "rw=%d, func=%d, addr=0x%05x\n", rw, func, regaddr);
 
-       BRCMF_PM_RESUME_WAIT(sdioh_request_byte_wait);
-       BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
-       if (rw) {               /* CMD52 Write */
-               if (func == 0) {
-                       /* Can only directly write to some F0 registers.
-                        * Handle F2 enable
-                        * as a special case.
-                        */
-                       if (regaddr == SDIO_CCCR_IOEx) {
-                               if (gInstance->func[2]) {
-                                       sdio_claim_host(gInstance->func[2]);
-                                       if (*byte & SDIO_FUNC_ENABLE_2) {
-                                               /* Enable Function 2 */
-                                               err_ret =
-                                                   sdio_enable_func
-                                                   (gInstance->func[2]);
-                                               if (err_ret)
-                                                       sd_err(("request_byte: "
-                                                               "enable F2 "
-                                                               "failed:%d\n",
-                                                                err_ret));
-                                       } else {
-                                               /* Disable Function 2 */
-                                               err_ret =
-                                                   sdio_disable_func
-                                                   (gInstance->func[2]);
-                                               if (err_ret)
-                                                       sd_err(("request_byte: "
-                                                               "Disab F2 "
-                                                               "failed:%d\n",
-                                                                err_ret));
-                                       }
-                                       sdio_release_host(gInstance->func[2]);
-                               }
-                       }
-                       /* to allow abort command through F1 */
-                       else if (regaddr == SDIO_CCCR_ABORT) {
-                               sdio_claim_host(gInstance->func[func]);
-                               /*
-                                * this sdio_f0_writeb() can be replaced
-                                * with another api
-                                * depending upon MMC driver change.
-                                * As of this time, this is temporaray one
-                                */
-                               sdio_writeb(gInstance->func[func], *byte,
-                                           regaddr, &err_ret);
-                               sdio_release_host(gInstance->func[func]);
-                       } else if (regaddr < 0xF0) {
-                               sd_err(("brcmf: F0 Wr:0x%02x: write "
-                                       "disallowed\n", regaddr));
-                       } else {
-                               /* Claim host controller, perform F0 write,
-                                and release */
-                               sdio_claim_host(gInstance->func[func]);
-                               sdio_f0_writeb(gInstance->func[func], *byte,
-                                              regaddr, &err_ret);
-                               sdio_release_host(gInstance->func[func]);
-                       }
-               } else {
-                       /* Claim host controller, perform Fn write,
-                        and release */
-                       sdio_claim_host(gInstance->func[func]);
-                       sdio_writeb(gInstance->func[func], *byte, regaddr,
-                                   &err_ret);
-                       sdio_release_host(gInstance->func[func]);
-               }
-       } else {                /* CMD52 Read */
-               /* Claim host controller, perform Fn read, and release */
-               sdio_claim_host(gInstance->func[func]);
+       brcmf_pm_resume_wait(sdiodev, &sdiodev->request_byte_wait);
+       if (brcmf_pm_resume_error(sdiodev))
+               return -EIO;
 
-               if (func == 0) {
-                       *byte =
-                           sdio_f0_readb(gInstance->func[func], regaddr,
-                                         &err_ret);
+       if (rw && func == 0) {
+               /* handle F0 separately */
+               err_ret = brcmf_sdioh_f0_write_byte(sdiodev, regaddr, byte);
+       } else {
+               sdio_claim_host(sdiodev->func[func]);
+               if (rw) /* CMD52 Write */
+                       sdio_writeb(sdiodev->func[func], *byte, regaddr,
+                                   &err_ret);
+               else if (func == 0) {
+                       *byte = sdio_f0_readb(sdiodev->func[func], regaddr,
+                                             &err_ret);
                } else {
-                       *byte =
-                           sdio_readb(gInstance->func[func], regaddr,
-                                      &err_ret);
+                       *byte = sdio_readb(sdiodev->func[func], regaddr,
+                                          &err_ret);
                }
-
-               sdio_release_host(gInstance->func[func]);
+               sdio_release_host(sdiodev->func[func]);
        }
 
        if (err_ret)
-               sd_err(("brcmf: Failed to %s byte F%d:@0x%05x=%02x, "
-                       "Err: %d\n", rw ? "Write" : "Read", func, regaddr,
-                       *byte, err_ret));
+               brcmf_dbg(ERROR, "Failed to %s byte F%d:@0x%05x=%02x, Err: %d\n",
+                         rw ? "write" : "read", func, regaddr, *byte, err_ret);
 
        return err_ret;
 }
 
-extern int
-brcmf_sdioh_request_word(struct sdioh_info *sd, uint cmd_type, uint rw,
-                        uint func, uint addr, u32 *word, uint nbytes)
+int brcmf_sdioh_request_word(struct brcmf_sdio_dev *sdiodev,
+                            uint rw, uint func, uint addr, u32 *word,
+                            uint nbytes)
 {
        int err_ret = -EIO;
 
        if (func == 0) {
-               sd_err(("%s: Only CMD52 allowed to F0.\n", __func__));
+               brcmf_dbg(ERROR, "Only CMD52 allowed to F0\n");
                return -EINVAL;
        }
 
-       sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
-                __func__, cmd_type, rw, func, addr, nbytes));
+       brcmf_dbg(INFO, "rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
+                 rw, func, addr, nbytes);
 
-       BRCMF_PM_RESUME_WAIT(sdioh_request_word_wait);
-       BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
+       brcmf_pm_resume_wait(sdiodev, &sdiodev->request_word_wait);
+       if (brcmf_pm_resume_error(sdiodev))
+               return -EIO;
        /* Claim host controller */
-       sdio_claim_host(gInstance->func[func]);
+       sdio_claim_host(sdiodev->func[func]);
 
        if (rw) {               /* CMD52 Write */
-               if (nbytes == 4) {
-                       sdio_writel(gInstance->func[func], *word, addr,
+               if (nbytes == 4)
+                       sdio_writel(sdiodev->func[func], *word, addr,
                                    &err_ret);
-               } else if (nbytes == 2) {
-                       sdio_writew(gInstance->func[func], (*word & 0xFFFF),
+               else if (nbytes == 2)
+                       sdio_writew(sdiodev->func[func], (*word & 0xFFFF),
                                    addr, &err_ret);
-               } else {
-                       sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
-               }
+               else
+                       brcmf_dbg(ERROR, "Invalid nbytes: %d\n", nbytes);
        } else {                /* CMD52 Read */
-               if (nbytes == 4) {
-                       *word =
-                           sdio_readl(gInstance->func[func], addr, &err_ret);
-               } else if (nbytes == 2) {
-                       *word =
-                           sdio_readw(gInstance->func[func], addr,
-                                      &err_ret) & 0xFFFF;
-               } else {
-                       sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
-               }
+               if (nbytes == 4)
+                       *word = sdio_readl(sdiodev->func[func], addr, &err_ret);
+               else if (nbytes == 2)
+                       *word = sdio_readw(sdiodev->func[func], addr,
+                                          &err_ret) & 0xFFFF;
+               else
+                       brcmf_dbg(ERROR, "Invalid nbytes: %d\n", nbytes);
        }
 
        /* Release host controller */
-       sdio_release_host(gInstance->func[func]);
+       sdio_release_host(sdiodev->func[func]);
 
-       if (err_ret) {
-               sd_err(("brcmf: Failed to %s word, Err: 0x%08x\n",
-                       rw ? "Write" : "Read", err_ret));
-       }
+       if (err_ret)
+               brcmf_dbg(ERROR, "Failed to %s word, Err: 0x%08x\n",
+                         rw ? "write" : "read", err_ret);
 
        return err_ret;
 }
 
 static int
-brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
-                          uint func, uint addr, struct sk_buff *pkt)
+brcmf_sdioh_request_packet(struct brcmf_sdio_dev *sdiodev, uint fix_inc,
+                          uint write, uint func, uint addr,
+                          struct sk_buff *pkt)
 {
        bool fifo = (fix_inc == SDIOH_DATA_FIX);
        u32 SGCount = 0;
@@ -806,46 +215,45 @@ brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
 
        struct sk_buff *pnext;
 
-       sd_trace(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
-       BRCMF_PM_RESUME_WAIT(sdioh_request_packet_wait);
-       BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
+       brcmf_pm_resume_wait(sdiodev, &sdiodev->request_packet_wait);
+       if (brcmf_pm_resume_error(sdiodev))
+               return -EIO;
 
        /* Claim host controller */
-       sdio_claim_host(gInstance->func[func]);
+       sdio_claim_host(sdiodev->func[func]);
        for (pnext = pkt; pnext; pnext = pnext->next) {
                uint pkt_len = pnext->len;
                pkt_len += 3;
                pkt_len &= 0xFFFFFFFC;
 
                if ((write) && (!fifo)) {
-                       err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
+                       err_ret = sdio_memcpy_toio(sdiodev->func[func], addr,
                                                   ((u8 *) (pnext->data)),
                                                   pkt_len);
                } else if (write) {
-                       err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
+                       err_ret = sdio_memcpy_toio(sdiodev->func[func], addr,
                                                   ((u8 *) (pnext->data)),
                                                   pkt_len);
                } else if (fifo) {
-                       err_ret = sdio_readsb(gInstance->func[func],
+                       err_ret = sdio_readsb(sdiodev->func[func],
                                              ((u8 *) (pnext->data)),
                                              addr, pkt_len);
                } else {
-                       err_ret = sdio_memcpy_fromio(gInstance->func[func],
+                       err_ret = sdio_memcpy_fromio(sdiodev->func[func],
                                                     ((u8 *) (pnext->data)),
                                                     addr, pkt_len);
                }
 
                if (err_ret) {
-                       sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
-                                "ERR=0x%08x\n", __func__,
-                                (write) ? "TX" : "RX",
-                                pnext, SGCount, addr, pkt_len, err_ret));
+                       brcmf_dbg(ERROR, "%s FAILED %p[%d], addr=0x%05x, pkt_len=%d, ERR=0x%08x\n",
+                                 write ? "TX" : "RX", pnext, SGCount, addr,
+                                 pkt_len, err_ret);
                } else {
-                       sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
-                                 __func__,
-                                 (write) ? "TX" : "RX",
-                                 pnext, SGCount, addr, pkt_len));
+                       brcmf_dbg(TRACE, "%s xfr'd %p[%d], addr=0x%05x, len=%d\n",
+                                 write ? "TX" : "RX", pnext, SGCount, addr,
+                                 pkt_len);
                }
 
                if (!fifo)
@@ -855,9 +263,9 @@ brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
        }
 
        /* Release host controller */
-       sdio_release_host(gInstance->func[func]);
+       sdio_release_host(sdiodev->func[func]);
 
-       sd_trace(("%s: Exit\n", __func__));
+       brcmf_dbg(TRACE, "Exit\n");
        return err_ret;
 }
 
@@ -876,26 +284,27 @@ brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
  * aligned packet.
  *
  */
-extern int
-brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
-                          uint write, uint func, uint addr, uint reg_width,
-                          uint buflen_u, u8 *buffer, struct sk_buff *pkt)
+int brcmf_sdioh_request_buffer(struct brcmf_sdio_dev *sdiodev,
+                              uint fix_inc, uint write, uint func, uint addr,
+                              uint reg_width, uint buflen_u, u8 *buffer,
+                              struct sk_buff *pkt)
 {
        int Status;
        struct sk_buff *mypkt = NULL;
 
-       sd_trace(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
-       BRCMF_PM_RESUME_WAIT(sdioh_request_buffer_wait);
-       BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
+       brcmf_pm_resume_wait(sdiodev, &sdiodev->request_buffer_wait);
+       if (brcmf_pm_resume_error(sdiodev))
+               return -EIO;
        /* Case 1: we don't have a packet. */
        if (pkt == NULL) {
-               sd_data(("%s: Creating new %s Packet, len=%d\n",
-                        __func__, write ? "TX" : "RX", buflen_u));
+               brcmf_dbg(DATA, "Creating new %s Packet, len=%d\n",
+                         write ? "TX" : "RX", buflen_u);
                mypkt = brcmu_pkt_buf_get_skb(buflen_u);
                if (!mypkt) {
-                       sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
-                               __func__, buflen_u));
+                       brcmf_dbg(ERROR, "brcmu_pkt_buf_get_skb failed: len %d\n",
+                                 buflen_u);
                        return -EIO;
                }
 
@@ -903,8 +312,8 @@ brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
                if (write)
                        memcpy(mypkt->data, buffer, buflen_u);
 
-               Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
-                                                   addr, mypkt);
+               Status = brcmf_sdioh_request_packet(sdiodev, fix_inc, write,
+                                                   func, addr, mypkt);
 
                /* For a read, copy the packet data back to the buffer. */
                if (!write)
@@ -916,12 +325,12 @@ brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
                 * Case 2: We have a packet, but it is unaligned.
                 * In this case, we cannot have a chain (pkt->next == NULL)
                 */
-               sd_data(("%s: Creating aligned %s Packet, len=%d\n",
-                        __func__, write ? "TX" : "RX", pkt->len));
+               brcmf_dbg(DATA, "Creating aligned %s Packet, len=%d\n",
+                         write ? "TX" : "RX", pkt->len);
                mypkt = brcmu_pkt_buf_get_skb(pkt->len);
                if (!mypkt) {
-                       sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
-                               __func__, pkt->len));
+                       brcmf_dbg(ERROR, "brcmu_pkt_buf_get_skb failed: len %d\n",
+                                 pkt->len);
                        return -EIO;
                }
 
@@ -929,8 +338,8 @@ brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
                if (write)
                        memcpy(mypkt->data, pkt->data, pkt->len);
 
-               Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
-                                                   addr, mypkt);
+               Status = brcmf_sdioh_request_packet(sdiodev, fix_inc, write,
+                                                   func, addr, mypkt);
 
                /* For a read, copy the packet data back to the buffer. */
                if (!write)
@@ -939,128 +348,185 @@ brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
                brcmu_pkt_buf_free_skb(mypkt);
        } else {                /* case 3: We have a packet and
                                 it is aligned. */
-               sd_data(("%s: Aligned %s Packet, direct DMA\n",
-                        __func__, write ? "Tx" : "Rx"));
-               Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
-                                                   addr, pkt);
+               brcmf_dbg(DATA, "Aligned %s Packet, direct DMA\n",
+                         write ? "Tx" : "Rx");
+               Status = brcmf_sdioh_request_packet(sdiodev, fix_inc, write,
+                                                   func, addr, pkt);
        }
 
        return Status;
 }
 
-/* this function performs "abort" for both of host & device */
-extern int brcmf_sdioh_abort(struct sdioh_info *sd, uint func)
-{
-       char t_func = (char)func;
-       sd_trace(("%s: Enter\n", __func__));
-
-       /* issue abort cmd52 command through F0 */
-       brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
-                          &t_func);
-
-       sd_trace(("%s: Exit\n", __func__));
-       return 0;
-}
-
-/* Disable device interrupt */
-void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd)
-{
-       sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
-       sd->intmask &= ~CLIENT_INTR;
-}
-
-/* Enable device interrupt */
-void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd)
-{
-       sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
-       sd->intmask |= CLIENT_INTR;
-}
-
 /* Read client card reg */
-int
-brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
+static int
+brcmf_sdioh_card_regread(struct brcmf_sdio_dev *sdiodev, int func, u32 regaddr,
                         int regsize, u32 *data)
 {
 
        if ((func == 0) || (regsize == 1)) {
                u8 temp = 0;
 
-               brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
+               brcmf_sdioh_request_byte(sdiodev, SDIOH_READ, func, regaddr,
+                                        &temp);
                *data = temp;
                *data &= 0xff;
-               sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
+               brcmf_dbg(DATA, "byte read data=0x%02x\n", *data);
        } else {
-               brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
-                                  regsize);
+               brcmf_sdioh_request_word(sdiodev, SDIOH_READ, func, regaddr,
+                                        data, regsize);
                if (regsize == 2)
                        *data &= 0xffff;
 
-               sd_data(("%s: word read data=0x%08x\n", __func__, *data));
+               brcmf_dbg(DATA, "word read data=0x%08x\n", *data);
        }
 
        return SUCCESS;
 }
 
-static void brcmf_sdioh_irqhandler(struct sdio_func *func)
+static int brcmf_sdioh_get_cisaddr(struct brcmf_sdio_dev *sdiodev, u32 regaddr)
 {
-       struct sdioh_info *sd;
+       /* read 24 bits and return valid 17 bit addr */
+       int i;
+       u32 scratch, regdata;
+       __le32 scratch_le;
+       u8 *ptr = (u8 *)&scratch_le;
 
-       sd_trace(("brcmf: ***IRQHandler\n"));
-       sd = gInstance->sd;
+       for (i = 0; i < 3; i++) {
+               if ((brcmf_sdioh_card_regread(sdiodev, 0, regaddr, 1,
+                               &regdata)) != SUCCESS)
+                       brcmf_dbg(ERROR, "Can't read!\n");
 
-       sdio_release_host(gInstance->func[0]);
+               *ptr++ = (u8) regdata;
+               regaddr++;
+       }
 
-       if (sd->use_client_ints) {
-               sd->intrcount++;
-               (sd->intr_handler) (sd->intr_handler_arg);
-       } else {
-               sd_err(("brcmf: ***IRQHandler\n"));
+       /* Only the lower 17-bits are valid */
+       scratch = le32_to_cpu(scratch_le);
+       scratch &= 0x0001FFFF;
+       return scratch;
+}
 
-               sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
-                       __func__, sd->client_intr_enabled, sd->intr_handler));
+static int brcmf_sdioh_enablefuncs(struct brcmf_sdio_dev *sdiodev)
+{
+       int err_ret;
+       u32 fbraddr;
+       u8 func;
+
+       brcmf_dbg(TRACE, "\n");
+
+       /* Get the Card's common CIS address */
+       sdiodev->func_cis_ptr[0] = brcmf_sdioh_get_cisaddr(sdiodev,
+                                                          SDIO_CCCR_CIS);
+       brcmf_dbg(INFO, "Card's Common CIS Ptr = 0x%x\n",
+                 sdiodev->func_cis_ptr[0]);
+
+       /* Get the Card's function CIS (for each function) */
+       for (fbraddr = SDIO_FBR_BASE(1), func = 1;
+            func <= sdiodev->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
+               sdiodev->func_cis_ptr[func] =
+                   brcmf_sdioh_get_cisaddr(sdiodev, SDIO_FBR_CIS + fbraddr);
+               brcmf_dbg(INFO, "Function %d CIS Ptr = 0x%x\n",
+                         func, sdiodev->func_cis_ptr[func]);
+       }
+
+       /* Enable Function 1 */
+       sdio_claim_host(sdiodev->func[1]);
+       err_ret = sdio_enable_func(sdiodev->func[1]);
+       sdio_release_host(sdiodev->func[1]);
+       if (err_ret)
+               brcmf_dbg(ERROR, "Failed to enable F1 Err: 0x%08x\n", err_ret);
+
+       return false;
+}
+
+/*
+ *     Public entry points & extern's
+ */
+int brcmf_sdioh_attach(struct brcmf_sdio_dev *sdiodev)
+{
+       int err_ret = 0;
+
+       brcmf_dbg(TRACE, "\n");
+
+       sdiodev->num_funcs = 2;
+
+       sdio_claim_host(sdiodev->func[1]);
+       err_ret = sdio_set_block_size(sdiodev->func[1], SDIO_FUNC1_BLOCKSIZE);
+       sdio_release_host(sdiodev->func[1]);
+       if (err_ret) {
+               brcmf_dbg(ERROR, "Failed to set F1 blocksize\n");
+               goto out;
+       }
+
+       sdio_claim_host(sdiodev->func[2]);
+       err_ret = sdio_set_block_size(sdiodev->func[2], SDIO_FUNC2_BLOCKSIZE);
+       sdio_release_host(sdiodev->func[2]);
+       if (err_ret) {
+               brcmf_dbg(ERROR, "Failed to set F2 blocksize\n");
+               goto out;
        }
 
-       sdio_claim_host(gInstance->func[0]);
+       brcmf_sdioh_enablefuncs(sdiodev);
+
+out:
+       brcmf_dbg(TRACE, "Done\n");
+       return err_ret;
 }
 
-/* interrupt handler for F2 (dummy handler) */
-static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
+void brcmf_sdioh_detach(struct brcmf_sdio_dev *sdiodev)
 {
-       struct sdioh_info *sd;
+       brcmf_dbg(TRACE, "\n");
+
+       /* Disable Function 2 */
+       sdio_claim_host(sdiodev->func[2]);
+       sdio_disable_func(sdiodev->func[2]);
+       sdio_release_host(sdiodev->func[2]);
 
-       sd_trace(("brcmf: ***IRQHandlerF2\n"));
+       /* Disable Function 1 */
+       sdio_claim_host(sdiodev->func[1]);
+       sdio_disable_func(sdiodev->func[1]);
+       sdio_release_host(sdiodev->func[1]);
 
-       sd = gInstance->sd;
 }
 
 static int brcmf_ops_sdio_probe(struct sdio_func *func,
                              const struct sdio_device_id *id)
 {
        int ret = 0;
-       static struct sdio_func sdio_func_0;
-       sd_trace(("sdio_probe: %s Enter\n", __func__));
-       sd_trace(("sdio_probe: func->class=%x\n", func->class));
-       sd_trace(("sdio_vendor: 0x%04x\n", func->vendor));
-       sd_trace(("sdio_device: 0x%04x\n", func->device));
-       sd_trace(("Function#: 0x%04x\n", func->num));
+       struct brcmf_sdio_dev *sdiodev;
+       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(TRACE, "func->class=%x\n", func->class);
+       brcmf_dbg(TRACE, "sdio_vendor: 0x%04x\n", func->vendor);
+       brcmf_dbg(TRACE, "sdio_device: 0x%04x\n", func->device);
+       brcmf_dbg(TRACE, "Function#: 0x%04x\n", func->num);
 
        if (func->num == 1) {
-               sdio_func_0.num = 0;
-               sdio_func_0.card = func->card;
-               gInstance->func[0] = &sdio_func_0;
-               if (func->device == 0x4) {      /* 4318 */
-                       gInstance->func[2] = NULL;
-                       sd_trace(("NIC found, calling brcmf_sdio_probe...\n"));
-                       ret = brcmf_sdio_probe(&sdmmc_dev);
+               if (dev_get_drvdata(&func->card->dev)) {
+                       brcmf_dbg(ERROR, "card private drvdata occupied\n");
+                       return -ENXIO;
                }
-       }
+               sdiodev = kzalloc(sizeof(struct brcmf_sdio_dev), GFP_KERNEL);
+               if (!sdiodev)
+                       return -ENOMEM;
+               sdiodev->func[0] = func->card->sdio_func[0];
+               sdiodev->func[1] = func;
+               dev_set_drvdata(&func->card->dev, sdiodev);
 
-       gInstance->func[func->num] = func;
+               atomic_set(&sdiodev->suspend, false);
+               init_waitqueue_head(&sdiodev->request_byte_wait);
+               init_waitqueue_head(&sdiodev->request_word_wait);
+               init_waitqueue_head(&sdiodev->request_packet_wait);
+               init_waitqueue_head(&sdiodev->request_buffer_wait);
+       }
 
        if (func->num == 2) {
-               brcmf_cfg80211_sdio_func(func);
-               sd_trace(("F2 found, calling brcmf_sdio_probe...\n"));
-               ret = brcmf_sdio_probe(&sdmmc_dev);
+               sdiodev = dev_get_drvdata(&func->card->dev);
+               if ((!sdiodev) || (sdiodev->func[1]->card != func->card))
+                       return -ENODEV;
+               sdiodev->func[2] = func;
+
+               brcmf_dbg(TRACE, "F2 found, calling brcmf_sdio_probe...\n");
+               ret = brcmf_sdio_probe(sdiodev);
        }
 
        return ret;
@@ -1068,129 +534,93 @@ static int brcmf_ops_sdio_probe(struct sdio_func *func,
 
 static void brcmf_ops_sdio_remove(struct sdio_func *func)
 {
-       sd_trace(("%s Enter\n", __func__));
-       sd_info(("func->class=%x\n", func->class));
-       sd_info(("sdio_vendor: 0x%04x\n", func->vendor));
-       sd_info(("sdio_device: 0x%04x\n", func->device));
-       sd_info(("Function#: 0x%04x\n", func->num));
+       struct brcmf_sdio_dev *sdiodev;
+       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(INFO, "func->class=%x\n", func->class);
+       brcmf_dbg(INFO, "sdio_vendor: 0x%04x\n", func->vendor);
+       brcmf_dbg(INFO, "sdio_device: 0x%04x\n", func->device);
+       brcmf_dbg(INFO, "Function#: 0x%04x\n", func->num);
 
        if (func->num == 2) {
-               sd_trace(("F2 found, calling brcmf_sdio_remove...\n"));
-               brcmf_sdio_remove(&sdmmc_dev);
+               sdiodev = dev_get_drvdata(&func->card->dev);
+               brcmf_dbg(TRACE, "F2 found, calling brcmf_sdio_remove...\n");
+               brcmf_sdio_remove(sdiodev);
+               dev_set_drvdata(&func->card->dev, NULL);
+               kfree(sdiodev);
        }
 }
 
-
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 static int brcmf_sdio_suspend(struct device *dev)
 {
        mmc_pm_flag_t sdio_flags;
+       struct brcmf_sdio_dev *sdiodev;
+       struct sdio_func *func = dev_to_sdio_func(dev);
        int ret = 0;
 
-       sd_trace(("%s\n", __func__));
+       brcmf_dbg(TRACE, "\n");
+
+       sdiodev = dev_get_drvdata(&func->card->dev);
+
+       atomic_set(&sdiodev->suspend, true);
 
-       sdio_flags = sdio_get_host_pm_caps(gInstance->func[1]);
+       sdio_flags = sdio_get_host_pm_caps(sdiodev->func[1]);
        if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
-               sd_err(("Host can't keep power while suspended\n"));
+               brcmf_dbg(ERROR, "Host can't keep power while suspended\n");
                return -EINVAL;
        }
 
-       ret = sdio_set_host_pm_flags(gInstance->func[1], MMC_PM_KEEP_POWER);
+       ret = sdio_set_host_pm_flags(sdiodev->func[1], MMC_PM_KEEP_POWER);
        if (ret) {
-               sd_err(("Failed to set pm_flags\n"));
+               brcmf_dbg(ERROR, "Failed to set pm_flags\n");
                return ret;
        }
 
-       brcmf_sdio_wdtmr_enable(false);
+       brcmf_sdio_wdtmr_enable(sdiodev, false);
 
        return ret;
 }
 
 static int brcmf_sdio_resume(struct device *dev)
 {
-       brcmf_sdio_wdtmr_enable(true);
-       return 0;
-}
-#endif         /* CONFIG_PM */
-
-int brcmf_sdioh_osinit(struct sdioh_info *sd)
-{
-       struct sdos_info *sdos;
-
-       sdos = kmalloc(sizeof(struct sdos_info), GFP_ATOMIC);
-       sd->sdos_info = (void *)sdos;
-       if (sdos == NULL)
-               return -ENOMEM;
+       struct brcmf_sdio_dev *sdiodev;
+       struct sdio_func *func = dev_to_sdio_func(dev);
 
-       sdos->sd = sd;
-       spin_lock_init(&sdos->lock);
+       sdiodev = dev_get_drvdata(&func->card->dev);
+       brcmf_sdio_wdtmr_enable(sdiodev, true);
+       atomic_set(&sdiodev->suspend, false);
        return 0;
 }
 
-void brcmf_sdioh_osfree(struct sdioh_info *sd)
-{
-       struct sdos_info *sdos;
-
-       sdos = (struct sdos_info *)sd->sdos_info;
-       kfree(sdos);
-}
-
-/* Interrupt enable/disable */
-int brcmf_sdioh_interrupt_set(struct sdioh_info *sd, bool enable)
-{
-       unsigned long flags;
-       struct sdos_info *sdos;
-
-       sd_trace(("%s: %s\n", __func__, enable ? "Enabling" : "Disabling"));
-
-       sdos = (struct sdos_info *)sd->sdos_info;
-
-       if (enable && !(sd->intr_handler && sd->intr_handler_arg)) {
-               sd_err(("%s: no handler registered, will not enable\n",
-                       __func__));
-               return -EINVAL;
-       }
-
-       /* Ensure atomicity for enable/disable calls */
-       spin_lock_irqsave(&sdos->lock, flags);
-
-       sd->client_intr_enabled = enable;
-       if (enable)
-               brcmf_sdioh_dev_intr_on(sd);
-       else
-               brcmf_sdioh_dev_intr_off(sd);
-
-       spin_unlock_irqrestore(&sdos->lock, flags);
+static const struct dev_pm_ops brcmf_sdio_pm_ops = {
+       .suspend        = brcmf_sdio_suspend,
+       .resume         = brcmf_sdio_resume,
+};
+#endif /* CONFIG_PM_SLEEP */
 
-       return 0;
-}
+static struct sdio_driver brcmf_sdmmc_driver = {
+       .probe = brcmf_ops_sdio_probe,
+       .remove = brcmf_ops_sdio_remove,
+       .name = "brcmfmac",
+       .id_table = brcmf_sdmmc_ids,
+#ifdef CONFIG_PM_SLEEP
+       .drv = {
+               .pm = &brcmf_sdio_pm_ops,
+       },
+#endif /* CONFIG_PM_SLEEP */
+};
 
-/*
- * module init
-*/
-int brcmf_sdio_function_init(void)
+/* bus register interface */
+int brcmf_bus_register(void)
 {
-       int error = 0;
-       sd_trace(("brcmf_sdio_function_init: %s Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
-       gInstance = kzalloc(sizeof(struct brcmf_sdmmc_instance), GFP_KERNEL);
-       if (!gInstance)
-               return -ENOMEM;
-
-       memset(&sdmmc_dev, 0, sizeof(sdmmc_dev));
-       error = sdio_register_driver(&brcmf_sdmmc_driver);
-
-       return error;
+       return sdio_register_driver(&brcmf_sdmmc_driver);
 }
 
-/*
- * module cleanup
-*/
-void brcmf_sdio_function_cleanup(void)
+void brcmf_bus_unregister(void)
 {
-       sd_trace(("%s Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        sdio_unregister_driver(&brcmf_sdmmc_driver);
-
-       kfree(gInstance);
 }
index 82bf04d..4645766 100644 (file)
 
 #define BRCMF_VERSION_STR              "4.218.248.5"
 
-#define        BRCMF_C_IOCTL_SMLEN     256     /* "small" ioctl buffer required */
-#define BRCMF_C_IOCTL_MEDLEN   1536    /* "med" ioctl buffer required */
-#define        BRCMF_C_IOCTL_MAXLEN    8192
-
+/*******************************************************************************
+ * IO codes that are interpreted by dongle firmware
+ ******************************************************************************/
 #define BRCMF_C_UP                             2
 #define BRCMF_C_SET_PROMISC                    10
 #define BRCMF_C_GET_RATE                       12
 #define        WLC_PHY_TYPE_LCN        8
 #define        WLC_PHY_TYPE_NULL       0xf
 
-#define BRCMF_PKT_FILTER_FIXED_LEN     offsetof(struct brcmf_pkt_filter, u)
-#define BRCMF_PKT_FILTER_PATTERN_FIXED_LEN     \
-       offsetof(struct brcmf_pkt_filter_pattern, mask_and_pattern)
-
 #define BRCMF_EVENTING_MASK_LEN        16
 
 #define TOE_TX_CSUM_OL         0x00000001
 #define TOE_RX_CSUM_OL         0x00000002
 
-/* maximum channels returned by the get valid channels iovar */
-#define WL_NUMCHANNELS         64
-
 #define        BRCMF_BSS_INFO_VERSION  108 /* current ver of brcmf_bss_info struct */
 
 /* size of brcmf_scan_params not including variable length array */
 #define BRCMF_SCAN_RESULTS_ABORTED     3
 #define BRCMF_SCAN_RESULTS_NO_MEM      4
 
-#define WL_SOFT_KEY    (1 << 0)        /* Indicates this key is using soft encrypt */
-#define BRCMF_PRIMARY_KEY      (1 << 1)        /* primary (ie tx) key */
-#define WL_KF_RES_4    (1 << 4)        /* Reserved for backward compat */
-#define WL_KF_RES_5    (1 << 5)        /* Reserved for backward compat */
-#define WL_IBSS_PEER_GROUP_KEY (1 << 6)        /* Indicates a group key for a IBSS PEER */
+/* Indicates this key is using soft encrypt */
+#define WL_SOFT_KEY    (1 << 0)
+/* primary (ie tx) key */
+#define BRCMF_PRIMARY_KEY      (1 << 1)
+/* Reserved for backward compat */
+#define WL_KF_RES_4    (1 << 4)
+/* Reserved for backward compat */
+#define WL_KF_RES_5    (1 << 5)
+/* Indicates a group key for a IBSS PEER */
+#define WL_IBSS_PEER_GROUP_KEY (1 << 6)
 
 /* For supporting multiple interfaces */
 #define BRCMF_MAX_IFS  16
 #define BRCMF_EVENT_MSG_GROUP          0x04
 
 struct brcmf_event_msg {
-       u16 version;
-       u16 flags;
-       u32 event_type;
-       u32 status;
-       u32 reason;
-       u32 auth_type;
-       u32 datalen;
+       __be16 version;
+       __be16 flags;
+       __be32 event_type;
+       __be32 status;
+       __be32 reason;
+       __be32 auth_type;
+       __be32 datalen;
        u8 addr[ETH_ALEN];
        char ifname[IFNAMSIZ];
 } __packed;
@@ -173,6 +170,7 @@ struct dngl_stats {
        unsigned long multicast;        /* multicast packets received */
 };
 
+/* event codes sent by the dongle to this driver */
 #define BRCMF_E_SET_SSID                       0
 #define BRCMF_E_JOIN                           1
 #define BRCMF_E_START                          2
@@ -332,30 +330,35 @@ enum brcmf_bus_state {
  * start matching, the pattern to match, the size of the pattern, and a bitmask
  * that indicates which bits within the pattern should be matched.
  */
-struct brcmf_pkt_filter_pattern {
-       u32 offset;             /* Offset within received packet to start pattern matching.
-                                * Offset '0' is the first byte of the ethernet header.
-                                */
-       u32 size_bytes; /* Size of the pattern.  Bitmask must be the same size. */
-       u8 mask_and_pattern[1]; /* Variable length mask and pattern data.  mask starts
-                                        * at offset 0.  Pattern immediately follows mask.
-                                        */
+struct brcmf_pkt_filter_pattern_le {
+       /*
+        * Offset within received packet to start pattern matching.
+        * Offset '0' is the first byte of the ethernet header.
+        */
+       __le32 offset;
+       /* Size of the pattern.  Bitmask must be the same size.*/
+       __le32 size_bytes;
+       /*
+        * Variable length mask and pattern data. mask starts at offset 0.
+        * Pattern immediately follows mask.
+        */
+       u8 mask_and_pattern[1];
 };
 
 /* IOVAR "pkt_filter_add" parameter. Used to install packet filters. */
-struct brcmf_pkt_filter {
-       u32 id;         /* Unique filter id, specified by app. */
-       u32 type;               /* Filter type (WL_PKT_FILTER_TYPE_xxx). */
-       u32 negate_match;       /* Negate the result of filter matches */
+struct brcmf_pkt_filter_le {
+       __le32 id;              /* Unique filter id, specified by app. */
+       __le32 type;            /* Filter type (WL_PKT_FILTER_TYPE_xxx). */
+       __le32 negate_match;    /* Negate the result of filter matches */
        union {                 /* Filter definitions */
-               struct brcmf_pkt_filter_pattern pattern; /* Filter pattern */
+               struct brcmf_pkt_filter_pattern_le pattern; /* Filter pattern */
        } u;
 };
 
 /* IOVAR "pkt_filter_enable" parameter. */
-struct brcmf_pkt_filter_enable {
-       u32 id;         /* Unique filter id */
-       u32 enable;             /* Enable/disable bool */
+struct brcmf_pkt_filter_enable_le {
+       __le32 id;              /* Unique filter id */
+       __le32 enable;          /* Enable/disable bool */
 };
 
 /* BSS info structure
@@ -363,63 +366,76 @@ struct brcmf_pkt_filter_enable {
  * next bss_info structure in a vector (in struct brcmf_scan_results)
  */
 struct brcmf_bss_info {
-       u32 version;            /* version field */
-       u32 length;             /* byte length of data in this record,
+       __le32 version;         /* version field */
+       __le32 length;          /* byte length of data in this record,
                                 * starting at version and including IEs
                                 */
        u8 BSSID[ETH_ALEN];
-       u16 beacon_period;      /* units are Kusec */
-       u16 capability; /* Capability information */
+       __le16 beacon_period;   /* units are Kusec */
+       __le16 capability;      /* Capability information */
        u8 SSID_len;
        u8 SSID[32];
        struct {
-               uint count;     /* # rates in this set */
-               u8 rates[16];   /* rates in 500kbps units w/hi bit set if basic */
+               __le32 count;   /* # rates in this set */
+               u8 rates[16]; /* rates in 500kbps units w/hi bit set if basic */
        } rateset;              /* supported rates */
-       chanspec_t chanspec;    /* chanspec for bss */
-       u16 atim_window;        /* units are Kusec */
+       __le16 chanspec;        /* chanspec for bss */
+       __le16 atim_window;     /* units are Kusec */
        u8 dtim_period; /* DTIM period */
-       s16 RSSI;               /* receive signal strength (in dBm) */
+       __le16 RSSI;            /* receive signal strength (in dBm) */
        s8 phy_noise;           /* noise (in dBm) */
 
        u8 n_cap;               /* BSS is 802.11N Capable */
-       u32 nbss_cap;   /* 802.11N BSS Capabilities (based on HT_CAP_*) */
+       /* 802.11N BSS Capabilities (based on HT_CAP_*): */
+       __le32 nbss_cap;
        u8 ctl_ch;              /* 802.11N BSS control channel number */
-       u32 reserved32[1];      /* Reserved for expansion of BSS properties */
+       __le32 reserved32[1];   /* Reserved for expansion of BSS properties */
        u8 flags;               /* flags */
        u8 reserved[3]; /* Reserved for expansion of BSS properties */
        u8 basic_mcs[MCSSET_LEN];       /* 802.11N BSS required MCS set */
 
-       u16 ie_offset;  /* offset at which IEs start, from beginning */
-       u32 ie_length;  /* byte length of Information Elements */
-       s16 SNR;                /* average SNR of during frame reception */
+       __le16 ie_offset;       /* offset at which IEs start, from beginning */
+       __le32 ie_length;       /* byte length of Information Elements */
+       __le16 SNR;             /* average SNR of during frame reception */
        /* Add new fields here */
        /* variable length Information Elements */
 };
 
+struct brcm_rateset_le {
+       /* # rates in this set */
+       __le32 count;
+       /* rates in 500kbps units w/hi bit set if basic */
+       u8 rates[WL_NUMRATES];
+};
+
 struct brcmf_ssid {
        u32 SSID_len;
        unsigned char SSID[32];
 };
 
-struct brcmf_scan_params {
-       struct brcmf_ssid ssid; /* default: {0, ""} */
+struct brcmf_ssid_le {
+       __le32 SSID_len;
+       unsigned char SSID[32];
+};
+
+struct brcmf_scan_params_le {
+       struct brcmf_ssid_le ssid_le;   /* default: {0, ""} */
        u8 bssid[ETH_ALEN];     /* default: bcast */
        s8 bss_type;            /* default: any,
                                 * DOT11_BSSTYPE_ANY/INFRASTRUCTURE/INDEPENDENT
                                 */
        u8 scan_type;   /* flags, 0 use default */
-       s32 nprobes;            /* -1 use default, number of probes per channel */
-       s32 active_time;        /* -1 use default, dwell time per channel for
+       __le32 nprobes;   /* -1 use default, number of probes per channel */
+       __le32 active_time;     /* -1 use default, dwell time per channel for
                                 * active scanning
                                 */
-       s32 passive_time;       /* -1 use default, dwell time per channel
+       __le32 passive_time;    /* -1 use default, dwell time per channel
                                 * for passive scanning
                                 */
-       s32 home_time;  /* -1 use default, dwell time for the home channel
-                                * between channel scans
+       __le32 home_time;       /* -1 use default, dwell time for the
+                                * home channel between channel scans
                                 */
-       s32 channel_num;        /* count of channels and ssids that follow
+       __le32 channel_num;     /* count of channels and ssids that follow
                                 *
                                 * low half is count of channels in
                                 * channel_list, 0 means default (use all
@@ -435,22 +451,17 @@ struct brcmf_scan_params {
                                 * fixed parameter portion is assumed, otherwise
                                 * ssid in the fixed portion is ignored
                                 */
-       u16 channel_list[1];    /* list of chanspecs */
+       __le16 channel_list[1]; /* list of chanspecs */
 };
 
 /* incremental scan struct */
-struct brcmf_iscan_params {
-       u32 version;
-       u16 action;
-       u16 scan_duration;
-       struct brcmf_scan_params params;
+struct brcmf_iscan_params_le {
+       __le32 version;
+       __le16 action;
+       __le16 scan_duration;
+       struct brcmf_scan_params_le params_le;
 };
 
-/* 3 fields + size of brcmf_scan_params, not including variable length array */
-#define BRCMF_ISCAN_PARAMS_FIXED_SIZE \
-       (offsetof(struct brcmf_iscan_params, params) + \
-        sizeof(struct brcmf_ssid))
-
 struct brcmf_scan_results {
        u32 buflen;
        u32 version;
@@ -458,21 +469,28 @@ struct brcmf_scan_results {
        struct brcmf_bss_info bss_info[1];
 };
 
+struct brcmf_scan_results_le {
+       __le32 buflen;
+       __le32 version;
+       __le32 count;
+       struct brcmf_bss_info bss_info[1];
+};
+
 /* used for association with a specific BSSID and chanspec list */
-struct brcmf_assoc_params {
-       u8 bssid[ETH_ALEN];     /* 00:00:00:00:00:00: broadcast scan */
-       s32 chanspec_num;       /* 0: all available channels,
-                                * otherwise count of chanspecs in chanspec_list
-                                */
-       chanspec_t chanspec_list[1];    /* list of chanspecs */
+struct brcmf_assoc_params_le {
+       /* 00:00:00:00:00:00: broadcast scan */
+       u8 bssid[ETH_ALEN];
+       /* 0: all available channels, otherwise count of chanspecs in
+        * chanspec_list */
+       __le32 chanspec_num;
+       /* list of chanspecs */
+       __le16 chanspec_list[1];
 };
-#define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
-       (sizeof(struct brcmf_assoc_params) - sizeof(chanspec_t))
 
 /* used for join with or without a specific bssid and channel list */
 struct brcmf_join_params {
-       struct brcmf_ssid ssid;
-       struct brcmf_assoc_params params;
+       struct brcmf_ssid_le ssid_le;
+       struct brcmf_assoc_params_le params_le;
 };
 
 /* size of brcmf_scan_results not including variable length array */
@@ -481,8 +499,14 @@ struct brcmf_join_params {
 
 /* incremental scan results struct */
 struct brcmf_iscan_results {
-       u32 status;
-       struct brcmf_scan_results results;
+       union {
+               u32 status;
+               __le32 status_le;
+       };
+       union {
+               struct brcmf_scan_results results;
+               struct brcmf_scan_results_le results_le;
+       };
 };
 
 /* size of brcmf_iscan_results not including variable length array */
@@ -495,40 +519,61 @@ struct brcmf_wsec_key {
        u32 len;                /* key length */
        u8 data[WLAN_MAX_KEY_LEN];      /* key data */
        u32 pad_1[18];
-       u32 algo;               /* CRYPTO_ALGO_AES_CCM, CRYPTO_ALGO_WEP128, etc */
-       u32 flags;              /* misc flags */
-       u32 pad_2[2];
-       int pad_3;
-       int iv_initialized;     /* has IV been initialized already? */
-       int pad_4;
+       u32 algo;       /* CRYPTO_ALGO_AES_CCM, CRYPTO_ALGO_WEP128, etc */
+       u32 flags;      /* misc flags */
+       u32 pad_2[3];
+       u32 iv_initialized;     /* has IV been initialized already? */
+       u32 pad_3;
        /* Rx IV */
        struct {
                u32 hi; /* upper 32 bits of IV */
                u16 lo; /* lower 16 bits of IV */
        } rxiv;
-       u32 pad_5[2];
+       u32 pad_4[2];
+       u8 ea[ETH_ALEN];        /* per station */
+};
+
+/*
+ * dongle requires same struct as above but with fields in little endian order
+ */
+struct brcmf_wsec_key_le {
+       __le32 index;           /* key index */
+       __le32 len;             /* key length */
+       u8 data[WLAN_MAX_KEY_LEN];      /* key data */
+       __le32 pad_1[18];
+       __le32 algo;    /* CRYPTO_ALGO_AES_CCM, CRYPTO_ALGO_WEP128, etc */
+       __le32 flags;   /* misc flags */
+       __le32 pad_2[3];
+       __le32 iv_initialized;  /* has IV been initialized already? */
+       __le32 pad_3;
+       /* Rx IV */
+       struct {
+               __le32 hi;      /* upper 32 bits of IV */
+               __le16 lo;      /* lower 16 bits of IV */
+       } rxiv;
+       __le32 pad_4[2];
        u8 ea[ETH_ALEN];        /* per station */
 };
 
 /* Used to get specific STA parameters */
-struct brcmf_scb_val {
-       u32 val;
+struct brcmf_scb_val_le {
+       __le32 val;
        u8 ea[ETH_ALEN];
 };
 
 /* channel encoding */
-struct brcmf_channel_info {
-       int hw_channel;
-       int target_channel;
-       int scan_channel;
+struct brcmf_channel_info_le {
+       __le32 hw_channel;
+       __le32 target_channel;
+       __le32 scan_channel;
 };
 
-/* Linux network driver ioctl encoding */
-struct brcmf_ioctl {
-       uint cmd;               /* common ioctl definition */
+/* Bus independent dongle command */
+struct brcmf_dcmd {
+       uint cmd;               /* common dongle cmd definition */
        void *buf;              /* pointer to user buffer */
        uint len;               /* length of user buffer */
-       u8 set;         /* get or set request (optional) */
+       u8 set;                 /* get or set request (optional) */
        uint used;              /* bytes read or written (optional) */
        uint needed;            /* bytes needed (optional) */
 };
@@ -537,6 +582,7 @@ struct brcmf_ioctl {
 struct brcmf_bus;              /* device bus info */
 struct brcmf_proto;    /* device communication protocol info */
 struct brcmf_info;     /* device driver info */
+struct brcmf_cfg80211_dev; /* cfg80211 device info */
 
 /* Common structure for module and instance linkage */
 struct brcmf_pub {
@@ -544,11 +590,11 @@ struct brcmf_pub {
        struct brcmf_bus *bus;
        struct brcmf_proto *prot;
        struct brcmf_info *info;
+       struct brcmf_cfg80211_dev *config;
 
        /* Internal brcmf items */
        bool up;                /* Driver up/down (to OS) */
        bool txoff;             /* Transmit flow-controlled */
-       bool dongle_reset;      /* true = DEVRESET put dongle into reset */
        enum brcmf_bus_state busstate;
        uint hdrlen;            /* Total BRCMF header length (proto + bus) */
        uint maxctl;            /* Max size rxctl request from proto to bus */
@@ -558,32 +604,45 @@ struct brcmf_pub {
        /* Dongle media info */
        bool iswl;              /* Dongle-resident driver is wl */
        unsigned long drv_version;      /* Version of dongle-resident driver */
-       u8 mac[ETH_ALEN];                       /* MAC address obtained from dongle */
+       u8 mac[ETH_ALEN];               /* MAC address obtained from dongle */
        struct dngl_stats dstats;       /* Stats for dongle-based data */
 
        /* Additional stats for the bus level */
-       unsigned long tx_packets;       /* Data packets sent to dongle */
-       unsigned long tx_multicast;     /* Multicast data packets sent to dongle */
-       unsigned long tx_errors;        /* Errors in sending data to dongle */
-       unsigned long tx_ctlpkts;       /* Control packets sent to dongle */
-       unsigned long tx_ctlerrs;       /* Errors sending control frames to dongle */
-       unsigned long rx_packets;       /* Packets sent up the network interface */
-       unsigned long rx_multicast;     /* Multicast packets sent up the network
-                                        interface */
-       unsigned long rx_errors;        /* Errors processing rx data packets */
-       unsigned long rx_ctlpkts;       /* Control frames processed from dongle */
-       unsigned long rx_ctlerrs;       /* Errors in processing rx control frames */
-       unsigned long rx_dropped;       /* Packets dropped locally (no memory) */
-       unsigned long rx_flushed;       /* Packets flushed due to
-                               unscheduled sendup thread */
-       unsigned long wd_dpc_sched;     /* Number of times dpc scheduled by
-                                        watchdog timer */
-
-       unsigned long rx_readahead_cnt; /* Number of packets where header read-ahead
-                                        was used. */
-       unsigned long tx_realloc;       /* Number of tx packets we had to realloc for
-                                        headroom */
-       unsigned long fc_packets;       /* Number of flow control pkts recvd */
+
+       /* Data packets sent to dongle */
+       unsigned long tx_packets;
+       /* Multicast data packets sent to dongle */
+       unsigned long tx_multicast;
+       /* Errors in sending data to dongle */
+       unsigned long tx_errors;
+       /* Control packets sent to dongle */
+       unsigned long tx_ctlpkts;
+       /* Errors sending control frames to dongle */
+       unsigned long tx_ctlerrs;
+       /* Packets sent up the network interface */
+       unsigned long rx_packets;
+       /* Multicast packets sent up the network interface */
+       unsigned long rx_multicast;
+       /* Errors processing rx data packets */
+       unsigned long rx_errors;
+       /* Control frames processed from dongle */
+       unsigned long rx_ctlpkts;
+
+       /* Errors in processing rx control frames */
+       unsigned long rx_ctlerrs;
+       /* Packets dropped locally (no memory) */
+       unsigned long rx_dropped;
+       /* Packets flushed due to unscheduled sendup thread */
+       unsigned long rx_flushed;
+       /* Number of times dpc scheduled by watchdog timer */
+       unsigned long wd_dpc_sched;
+
+       /* Number of packets where header read-ahead was used. */
+       unsigned long rx_readahead_cnt;
+       /* Number of tx packets we had to realloc for headroom */
+       unsigned long tx_realloc;
+       /* Number of flow control pkts recvd */
+       unsigned long fc_packets;
 
        /* Last error return */
        int bcmerror;
@@ -614,146 +673,15 @@ struct brcmf_if_event {
        u8 bssidx;
 };
 
-struct brcmf_timeout {
-       u32 limit;              /* Expiration time (usec) */
-       u32 increment;  /* Current expiration increment (usec) */
-       u32 elapsed;            /* Current elapsed time (usec) */
-       u32 tick;               /* O/S tick time (usec) */
-};
-
 struct bcmevent_name {
        uint event;
        const char *name;
 };
 
-#if defined(CONFIG_PM_SLEEP)
-extern atomic_t brcmf_mmc_suspend;
-#define BRCMF_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
-#define _BRCMF_PM_RESUME_WAIT(a, b) do { \
-               int retry = 0; \
-               while (atomic_read(&brcmf_mmc_suspend) && retry++ != b) { \
-                       wait_event_timeout(a, false, HZ/100); \
-               } \
-       }       while (0)
-#define BRCMF_PM_RESUME_WAIT(a)        _BRCMF_PM_RESUME_WAIT(a, 30)
-#define BRCMF_PM_RESUME_RETURN_ERROR(a)        \
-       do { if (atomic_read(&brcmf_mmc_suspend)) return a; } while (0)
-
-#define BRCMF_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
-#define BRCMF_SPINWAIT_SLEEP(a, exp, us) do { \
-               uint countdown = (us) + 9999; \
-               while ((exp) && (countdown >= 10000)) { \
-                       wait_event_timeout(a, false, HZ/100); \
-                       countdown -= 10000; \
-               } \
-       } while (0)
-
-#else
-
-#define BRCMF_PM_RESUME_WAIT_INIT(a)
-#define BRCMF_PM_RESUME_WAIT(a)
-#define BRCMF_PM_RESUME_RETURN_ERROR(a)
-
-#define BRCMF_SPINWAIT_SLEEP_INIT(a)
-#define BRCMF_SPINWAIT_SLEEP(a, exp, us)  do { \
-               uint countdown = (us) + 9; \
-               while ((exp) && (countdown >= 10)) { \
-                       udelay(10);  \
-                       countdown -= 10;  \
-               } \
-       } while (0)
-
-#endif /* defined(CONFIG_PM_SLEEP) */
-
-/*
- * Insmod parameters for debug/test
- */
-
-/* Use interrupts */
-extern uint brcmf_intr;
-
-/* Use polling */
-extern uint brcmf_poll;
-
-/* ARP offload agent mode */
-extern uint brcmf_arp_mode;
-
-/* ARP offload enable */
-extern uint brcmf_arp_enable;
-
-/* Pkt filte enable control */
-extern uint brcmf_pkt_filter_enable;
-
-/*  Pkt filter init setup */
-extern uint brcmf_pkt_filter_init;
-
-/* Pkt filter mode control */
-extern uint brcmf_master_mode;
-
-/* Roaming mode control */
-extern uint brcmf_roam;
-
-/* Roaming mode control */
-extern uint brcmf_radio_up;
-
-/* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
-extern int brcmf_idletime;
-#define BRCMF_IDLETIME_TICKS 1
-
-/* SDIO Drive Strength */
-extern uint brcmf_sdiod_drive_strength;
-
-/* Override to force tx queueing all the time */
-extern uint brcmf_force_tx_queueing;
-
-#ifdef SDTEST
-/* Echo packet generator (SDIO), pkts/s */
-extern uint brcmf_pktgen;
-
-/* Echo packet len (0 => sawtooth, max 1800) */
-extern uint brcmf_pktgen_len;
-#define BRCMF_MAX_PKTGEN_LEN 1800
-#endif
-
 extern const struct bcmevent_name bcmevent_names[];
-extern const int bcmevent_names_size;
-
-
-static inline void MUTEX_LOCK_INIT(struct brcmf_pub *drvr)
-{
-}
-
-static inline void MUTEX_LOCK(struct brcmf_pub *drvr)
-{
-}
-
-static inline void MUTEX_UNLOCK(struct brcmf_pub *drvr)
-{
-}
-
-static inline void MUTEX_LOCK_SOFTAP_SET_INIT(struct brcmf_pub *drvr)
-{
-}
-
-static inline void MUTEX_LOCK_SOFTAP_SET(struct brcmf_pub *drvr)
-{
-}
-
-static inline void MUTEX_UNLOCK_SOFTAP_SET(struct brcmf_pub *drvr)
-{
-}
 
-static inline void MUTEX_LOCK_WL_SCAN_SET_INIT(void)
-{
-}
-
-static inline void MUTEX_LOCK_WL_SCAN_SET(void)
-{
-}
-
-static inline void MUTEX_UNLOCK_WL_SCAN_SET(void)
-{
-}
+extern uint brcmf_c_mkiovar(char *name, char *data, uint datalen,
+                         char *buf, uint len);
 
 /* Indication from bus module regarding presence/insertion of dongle.
  * Return struct brcmf_pub pointer, used as handle to OS module in later calls.
@@ -763,7 +691,9 @@ static inline void MUTEX_UNLOCK_WL_SCAN_SET(void)
 extern struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus,
                                      uint bus_hdrlen);
 extern int brcmf_net_attach(struct brcmf_pub *drvr, int idx);
-extern int brcmf_netdev_wait_pend8021x(struct net_device *dev);
+extern int brcmf_netdev_wait_pend8021x(struct net_device *ndev);
+
+extern s32 brcmf_exec_dcmd(struct net_device *dev, u32 cmd, void *arg, u32 len);
 
 /* Indication from bus module regarding removal/absence of dongle */
 extern void brcmf_detach(struct brcmf_pub *drvr);
@@ -785,25 +715,17 @@ extern char *brcmf_ifname(struct brcmf_pub *drvr, int idx);
 extern void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp,
                             bool success);
 
-/* Query ioctl */
-extern int brcmf_proto_cdc_query_ioctl(struct brcmf_pub *drvr, int ifidx,
+/* Query dongle */
+extern int brcmf_proto_cdc_query_dcmd(struct brcmf_pub *drvr, int ifidx,
                                       uint cmd, void *buf, uint len);
 
 /* OS independent layer functions */
 extern int brcmf_os_proto_block(struct brcmf_pub *drvr);
 extern int brcmf_os_proto_unblock(struct brcmf_pub *drvr);
-extern int brcmf_os_ioctl_resp_wait(struct brcmf_pub *drvr, uint *condition,
-                                 bool *pending);
-extern int brcmf_os_ioctl_resp_wake(struct brcmf_pub *drvr);
-extern unsigned int brcmf_os_get_ioctl_resp_timeout(void);
-extern void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
 #ifdef BCMDBG
-extern int brcmf_write_to_file(struct brcmf_pub *drvr, u8 *buf, int size);
+extern int brcmf_write_to_file(struct brcmf_pub *drvr, const u8 *buf, int size);
 #endif                         /* BCMDBG */
 
-extern void brcmf_timeout_start(struct brcmf_timeout *tmo, uint usec);
-extern int brcmf_timeout_expired(struct brcmf_timeout *tmo);
-
 extern int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name);
 extern int brcmf_c_host_event(struct brcmf_info *drvr_priv, int *idx,
                              void *pktdata, struct brcmf_event_msg *,
@@ -811,44 +733,24 @@ extern int brcmf_c_host_event(struct brcmf_info *drvr_priv, int *idx,
 
 extern void brcmf_c_init(void);
 
-extern int brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, void *handle,
-                     char *name, u8 *mac_addr, u32 flags, u8 bssidx);
+extern int brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx,
+                       struct net_device *ndev, char *name, u8 *mac_addr,
+                       u32 flags, u8 bssidx);
 extern void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx);
 
 /* Send packet to dongle via data channel */
 extern int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx,\
                         struct sk_buff *pkt);
 
-extern int brcmf_bus_devreset(struct brcmf_pub *drvr, u8 flag);
 extern int brcmf_bus_start(struct brcmf_pub *drvr);
 
 extern void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg);
 extern void brcmf_c_pktfilter_offload_enable(struct brcmf_pub *drvr, char *arg,
                                             int enable, int master_mode);
 
-/* Linux network driver ioctl encoding */
-struct brcmf_c_ioctl {
-       uint cmd;               /* common ioctl definition */
-       void *buf;              /* pointer to user buffer */
-       uint len;               /* length of user buffer */
-       bool set;               /* get or set request (optional) */
-       uint used;              /* bytes read or written (optional) */
-       uint needed;            /* bytes needed (optional) */
-       uint driver;            /* to identify target driver */
-};
-
-/* per-driver magic numbers */
-#define BRCMF_IOCTL_MAGIC              0x00444944
-
-/* bump this number if you change the ioctl interface */
-#define BRCMF_IOCTL_VERSION    1
-#define        BRCMF_IOCTL_MAXLEN      8192    /* max length ioctl buffer required */
-
-/* common ioctl definitions */
-#define BRCMF_GET_MAGIC                                0
-#define BRCMF_GET_VERSION                              1
-#define BRCMF_GET_VAR                          2
-#define BRCMF_SET_VAR                          3
+#define        BRCMF_DCMD_SMLEN        256     /* "small" cmd buffer required */
+#define BRCMF_DCMD_MEDLEN      1536    /* "med" cmd buffer required */
+#define        BRCMF_DCMD_MAXLEN       8192    /* max length cmd buffer required */
 
 /* message levels */
 #define BRCMF_ERROR_VAL        0x0001
@@ -865,40 +767,10 @@ struct brcmf_c_ioctl {
 #define BRCMF_BTA_VAL  0x1000
 #define BRCMF_ISCAN_VAL 0x2000
 
-#ifdef SDTEST
-/* For pktgen iovar */
-struct brcmf_pktgen {
-       uint version;           /* To allow structure change tracking */
-       uint freq;              /* Max ticks between tx/rx attempts */
-       uint count;             /* Test packets to send/rcv each attempt */
-       uint print;             /* Print counts every <print> attempts */
-       uint total;             /* Total packets (or bursts) */
-       uint minlen;            /* Minimum length of packets to send */
-       uint maxlen;            /* Maximum length of packets to send */
-       uint numsent;           /* Count of test packets sent */
-       uint numrcvd;           /* Count of test packets received */
-       uint numfail;           /* Count of test send failures */
-       uint mode;              /* Test mode (type of test packets) */
-       uint stop;              /* Stop after this many tx failures */
-};
-
-/* Version in case structure changes */
-#define BRCMF_PKTGEN_VERSION   2
-
-/* Type of test packets to use */
-#define BRCMF_PKTGEN_ECHO      1       /* Send echo requests */
-#define BRCMF_PKTGEN_SEND      2       /* Send discard packets */
-#define BRCMF_PKTGEN_RXBURST   3       /* Request dongle send N packets */
-#define BRCMF_PKTGEN_RECV              4       /* Continuous rx from continuous
-                                        tx dongle */
-#endif                         /* SDTEST */
-
 /* Enter idle immediately (no timeout) */
 #define BRCMF_IDLE_IMMEDIATE   (-1)
-
-/* Values for idleclock iovar: other values are the sd_divisor to use
-        when idle */
 #define BRCMF_IDLE_ACTIVE      0       /* Do not request any SD clock change
                                 when idle */
+#define BRCMF_IDLE_INTERVAL    1
 
 #endif                         /* _BRCMF_H_ */
index 653cf0d..a249407 100644 (file)
 #define _BRCMF_BUS_H_
 
 /* Packet alignment for most efficient SDIO (can change based on platform) */
-#ifndef BRCMF_SDALIGN
-#define BRCMF_SDALIGN  32
-#endif
-#if !ISPOWEROF2(BRCMF_SDALIGN)
-#error BRCMF_SDALIGN is not a power of 2!
-#endif
+#define BRCMF_SDALIGN  (1 << 6)
+
+/* watchdog polling interval in ms */
+#define BRCMF_WD_POLL_MS       10
 
 /*
  * Exported from brcmf bus module (brcmf_usb, brcmf_sdio)
  */
 
-/* dongle ram module parameter */
-extern int brcmf_dongle_memsize;
-
-/* Tx/Rx bounds module parameters */
-extern uint brcmf_txbound;
-extern uint brcmf_rxbound;
-
-/* Watchdog timer interval */
-extern uint brcmf_watchdog_ms;
-
 /* Indicate (dis)interest in finding dongles. */
 extern int brcmf_bus_register(void);
 extern void brcmf_bus_unregister(void);
 
+/* obtain linux device object providing bus function */
+extern struct device *brcmf_bus_get_device(struct brcmf_bus *bus);
+
 /* Stop bus module: clear pending frames, disable data flow */
-extern void brcmf_sdbrcm_bus_stop(struct brcmf_bus *bus, bool enforce_mutex);
+extern void brcmf_sdbrcm_bus_stop(struct brcmf_bus *bus);
 
 /* Initialize bus module: prepare for communication w/dongle */
-extern int brcmf_sdbrcm_bus_init(struct brcmf_pub *drvr, bool enforce_mutex);
+extern int brcmf_sdbrcm_bus_init(struct brcmf_pub *drvr);
 
 /* Send a data frame to the dongle.  Callee disposes of txp. */
 extern int brcmf_sdbrcm_bus_txdata(struct brcmf_bus *bus, struct sk_buff *txp);
@@ -61,18 +52,6 @@ brcmf_sdbrcm_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint msglen);
 extern int
 brcmf_sdbrcm_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint msglen);
 
-/* Check for and handle local prot-specific iovar commands */
-extern int brcmf_sdbrcm_bus_iovar_op(struct brcmf_pub *drvr, const char *name,
-                           void *params, int plen, void *arg, int len,
-                           bool set);
-
-/* Add bus dump output to a buffer */
-extern void brcmf_sdbrcm_bus_dump(struct brcmf_pub *drvr,
-                                 struct brcmu_strbuf *strbuf);
-
-/* Clear any bus counters */
-extern void brcmf_bus_clearcounts(struct brcmf_pub *drvr);
-
 extern void brcmf_sdbrcm_wd_timer(struct brcmf_bus *bus, uint wdtick);
 
 #endif                         /* _BRCMF_BUS_H_ */
index 345acab..e34c5c3 100644 (file)
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+/*******************************************************************************
+ * Communicates with the dongle by using dcmd codes.
+ * For certain dcmd codes, the dongle interprets string data from the host.
+ ******************************************************************************/
+
 #include <linux/types.h>
 #include <linux/netdevice.h>
 #include <linux/sched.h>
 #include "dhd_bus.h"
 #include "dhd_dbg.h"
 
-struct brcmf_proto_cdc_ioctl {
-       u32 cmd;        /* ioctl command value */
-       u32 len;        /* lower 16: output buflen;
+struct brcmf_proto_cdc_dcmd {
+       __le32 cmd;     /* dongle command value */
+       __le32 len;     /* lower 16: output buflen;
                         * upper 16: input buflen (excludes header) */
-       u32 flags;      /* flag defns given below */
-       u32 status;     /* status code returned from the device */
+       __le32 flags;   /* flag defns given below */
+       __le32 status;  /* status code returned from the device */
 };
 
 /* Max valid buffer size that can be sent to the dongle */
 #define CDC_MAX_MSG_SIZE       (ETH_FRAME_LEN+ETH_FCS_LEN)
 
 /* CDC flag definitions */
-#define CDCF_IOC_ERROR         0x01            /* 1=ioctl cmd failed */
-#define CDCF_IOC_SET           0x02            /* 0=get, 1=set cmd */
-#define CDCF_IOC_IF_MASK       0xF000          /* I/F index */
-#define CDCF_IOC_IF_SHIFT      12
-#define CDCF_IOC_ID_MASK       0xFFFF0000      /* id an ioctl pairing */
-#define CDCF_IOC_ID_SHIFT      16              /* ID Mask shift bits */
-#define CDC_IOC_ID(flags)      \
-       (((flags) & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT)
-#define CDC_SET_IF_IDX(hdr, idx) \
-       ((hdr)->flags = (((hdr)->flags & ~CDCF_IOC_IF_MASK) | \
-       ((idx) << CDCF_IOC_IF_SHIFT)))
+#define CDC_DCMD_ERROR         0x01    /* 1=cmd failed */
+#define CDC_DCMD_SET           0x02    /* 0=get, 1=set cmd */
+#define CDC_DCMD_IF_MASK       0xF000          /* I/F index */
+#define CDC_DCMD_IF_SHIFT      12
+#define CDC_DCMD_ID_MASK       0xFFFF0000      /* id an cmd pairing */
+#define CDC_DCMD_ID_SHIFT      16              /* ID Mask shift bits */
+#define CDC_DCMD_ID(flags)     \
+       (((flags) & CDC_DCMD_ID_MASK) >> CDC_DCMD_ID_SHIFT)
 
 /*
  * BDC header - Broadcom specific extension of CDC.
@@ -79,7 +81,7 @@ struct brcmf_proto_bdc_header {
 };
 
 
-#define RETRIES 2      /* # of retries to retrieve matching ioctl response */
+#define RETRIES 2 /* # of retries to retrieve matching dcmd response */
 #define BUS_HEADER_LEN (16+BRCMF_SDALIGN) /* Must be atleast SDPCM_RESERVE
                                         * (amount of header tha might be added)
                                         * plus any space that might be needed
@@ -94,17 +96,17 @@ struct brcmf_proto {
        u8 pending;
        u32 lastcmd;
        u8 bus_header[BUS_HEADER_LEN];
-       struct brcmf_proto_cdc_ioctl msg;
-       unsigned char buf[BRCMF_C_IOCTL_MAXLEN + ROUND_UP_MARGIN];
+       struct brcmf_proto_cdc_dcmd msg;
+       unsigned char buf[BRCMF_DCMD_MAXLEN + ROUND_UP_MARGIN];
 };
 
 static int brcmf_proto_cdc_msg(struct brcmf_pub *drvr)
 {
        struct brcmf_proto *prot = drvr->prot;
        int len = le32_to_cpu(prot->msg.len) +
-                       sizeof(struct brcmf_proto_cdc_ioctl);
+                       sizeof(struct brcmf_proto_cdc_dcmd);
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        /* NOTE : cdc->msg.len holds the desired length of the buffer to be
         *        returned. Only up to CDC_MAX_MSG_SIZE of this buffer area
@@ -123,31 +125,31 @@ static int brcmf_proto_cdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len)
        int ret;
        struct brcmf_proto *prot = drvr->prot;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        do {
                ret = brcmf_sdbrcm_bus_rxctl(drvr->bus,
                                (unsigned char *)&prot->msg,
-                               len + sizeof(struct brcmf_proto_cdc_ioctl));
+                               len + sizeof(struct brcmf_proto_cdc_dcmd));
                if (ret < 0)
                        break;
-       } while (CDC_IOC_ID(le32_to_cpu(prot->msg.flags)) != id);
+       } while (CDC_DCMD_ID(le32_to_cpu(prot->msg.flags)) != id);
 
        return ret;
 }
 
 int
-brcmf_proto_cdc_query_ioctl(struct brcmf_pub *drvr, int ifidx, uint cmd,
-                           void *buf, uint len)
+brcmf_proto_cdc_query_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
+                              void *buf, uint len)
 {
        struct brcmf_proto *prot = drvr->prot;
-       struct brcmf_proto_cdc_ioctl *msg = &prot->msg;
+       struct brcmf_proto_cdc_dcmd *msg = &prot->msg;
        void *info;
        int ret = 0, retries = 0;
-       u32 id, flags = 0;
+       u32 id, flags;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
-       BRCMF_CTL(("%s: cmd %d len %d\n", __func__, cmd, len));
+       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(CTL, "cmd %d len %d\n", cmd, len);
 
        /* Respond "bcmerror" and "bcmerrorstr" with local cache */
        if (cmd == BRCMF_C_GET_VAR && buf) {
@@ -161,21 +163,22 @@ brcmf_proto_cdc_query_ioctl(struct brcmf_pub *drvr, int ifidx, uint cmd,
                }
        }
 
-       memset(msg, 0, sizeof(struct brcmf_proto_cdc_ioctl));
+       memset(msg, 0, sizeof(struct brcmf_proto_cdc_dcmd));
 
        msg->cmd = cpu_to_le32(cmd);
        msg->len = cpu_to_le32(len);
-       msg->flags = (++prot->reqid << CDCF_IOC_ID_SHIFT);
-       CDC_SET_IF_IDX(msg, ifidx);
-       msg->flags = cpu_to_le32(msg->flags);
+       flags = (++prot->reqid << CDC_DCMD_ID_SHIFT);
+       flags = (flags & ~CDC_DCMD_IF_MASK) |
+               (ifidx << CDC_DCMD_IF_SHIFT);
+       msg->flags = cpu_to_le32(flags);
 
        if (buf)
                memcpy(prot->buf, buf, len);
 
        ret = brcmf_proto_cdc_msg(drvr);
        if (ret < 0) {
-               BRCMF_ERROR(("brcmf_proto_cdc_query_ioctl: brcmf_proto_cdc_msg "
-                            "failed w/status %d\n", ret));
+               brcmf_dbg(ERROR, "brcmf_proto_cdc_msg failed w/status %d\n",
+                         ret);
                goto done;
        }
 
@@ -186,14 +189,13 @@ retry:
                goto done;
 
        flags = le32_to_cpu(msg->flags);
-       id = (flags & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT;
+       id = (flags & CDC_DCMD_ID_MASK) >> CDC_DCMD_ID_SHIFT;
 
        if ((id < prot->reqid) && (++retries < RETRIES))
                goto retry;
        if (id != prot->reqid) {
-               BRCMF_ERROR(("%s: %s: unexpected request id %d (expected %d)\n",
-                            brcmf_ifname(drvr, ifidx), __func__, id,
-                            prot->reqid));
+               brcmf_dbg(ERROR, "%s: unexpected request id %d (expected %d)\n",
+                         brcmf_ifname(drvr, ifidx), id, prot->reqid);
                ret = -EINVAL;
                goto done;
        }
@@ -209,7 +211,7 @@ retry:
        }
 
        /* Check the ERROR flag */
-       if (flags & CDCF_IOC_ERROR) {
+       if (flags & CDC_DCMD_ERROR) {
                ret = le32_to_cpu(msg->status);
                /* Cache error from dongle */
                drvr->dongle_error = ret;
@@ -219,24 +221,25 @@ done:
        return ret;
 }
 
-int brcmf_proto_cdc_set_ioctl(struct brcmf_pub *drvr, int ifidx, uint cmd,
-                             void *buf, uint len)
+int brcmf_proto_cdc_set_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd,
+                                void *buf, uint len)
 {
        struct brcmf_proto *prot = drvr->prot;
-       struct brcmf_proto_cdc_ioctl *msg = &prot->msg;
+       struct brcmf_proto_cdc_dcmd *msg = &prot->msg;
        int ret = 0;
        u32 flags, id;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
-       BRCMF_CTL(("%s: cmd %d len %d\n", __func__, cmd, len));
+       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_dbg(CTL, "cmd %d len %d\n", cmd, len);
 
-       memset(msg, 0, sizeof(struct brcmf_proto_cdc_ioctl));
+       memset(msg, 0, sizeof(struct brcmf_proto_cdc_dcmd));
 
        msg->cmd = cpu_to_le32(cmd);
        msg->len = cpu_to_le32(len);
-       msg->flags = (++prot->reqid << CDCF_IOC_ID_SHIFT) | CDCF_IOC_SET;
-       CDC_SET_IF_IDX(msg, ifidx);
-       msg->flags = cpu_to_le32(msg->flags);
+       flags = (++prot->reqid << CDC_DCMD_ID_SHIFT) | CDC_DCMD_SET;
+       flags = (flags & ~CDC_DCMD_IF_MASK) |
+               (ifidx << CDC_DCMD_IF_SHIFT);
+       msg->flags = cpu_to_le32(flags);
 
        if (buf)
                memcpy(prot->buf, buf, len);
@@ -250,18 +253,17 @@ int brcmf_proto_cdc_set_ioctl(struct brcmf_pub *drvr, int ifidx, uint cmd,
                goto done;
 
        flags = le32_to_cpu(msg->flags);
-       id = (flags & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT;
+       id = (flags & CDC_DCMD_ID_MASK) >> CDC_DCMD_ID_SHIFT;
 
        if (id != prot->reqid) {
-               BRCMF_ERROR(("%s: %s: unexpected request id %d (expected %d)\n",
-                            brcmf_ifname(drvr, ifidx), __func__, id,
-                            prot->reqid));
+               brcmf_dbg(ERROR, "%s: unexpected request id %d (expected %d)\n",
+                         brcmf_ifname(drvr, ifidx), id, prot->reqid);
                ret = -EINVAL;
                goto done;
        }
 
        /* Check the ERROR flag */
-       if (flags & CDCF_IOC_ERROR) {
+       if (flags & CDC_DCMD_ERROR) {
                ret = le32_to_cpu(msg->status);
                /* Cache error from dongle */
                drvr->dongle_error = ret;
@@ -272,65 +274,64 @@ done:
 }
 
 int
-brcmf_proto_ioctl(struct brcmf_pub *drvr, int ifidx, struct brcmf_ioctl *ioc,
-                 void *buf, int len)
+brcmf_proto_dcmd(struct brcmf_pub *drvr, int ifidx, struct brcmf_dcmd *dcmd,
+                 int len)
 {
        struct brcmf_proto *prot = drvr->prot;
        int ret = -1;
 
        if (drvr->busstate == BRCMF_BUS_DOWN) {
-               BRCMF_ERROR(("%s : bus is down. we have nothing to do\n",
-                            __func__));
+               brcmf_dbg(ERROR, "bus is down. we have nothing to do.\n");
                return ret;
        }
        brcmf_os_proto_block(drvr);
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
-       if (len > BRCMF_C_IOCTL_MAXLEN)
+       if (len > BRCMF_DCMD_MAXLEN)
                goto done;
 
        if (prot->pending == true) {
-               BRCMF_TRACE(("CDC packet is pending!!!! cmd=0x%x (%lu) "
-                            "lastcmd=0x%x (%lu)\n",
-                            ioc->cmd, (unsigned long)ioc->cmd, prot->lastcmd,
-                            (unsigned long)prot->lastcmd));
-               if ((ioc->cmd == BRCMF_C_SET_VAR) ||
-                   (ioc->cmd == BRCMF_C_GET_VAR))
-                       BRCMF_TRACE(("iovar cmd=%s\n", (char *)buf));
+               brcmf_dbg(TRACE, "CDC packet is pending!!!! cmd=0x%x (%lu) lastcmd=0x%x (%lu)\n",
+                         dcmd->cmd, (unsigned long)dcmd->cmd, prot->lastcmd,
+                         (unsigned long)prot->lastcmd);
+               if (dcmd->cmd == BRCMF_C_SET_VAR ||
+                   dcmd->cmd == BRCMF_C_GET_VAR)
+                       brcmf_dbg(TRACE, "iovar cmd=%s\n", (char *)dcmd->buf);
 
                goto done;
        }
 
        prot->pending = true;
-       prot->lastcmd = ioc->cmd;
-       if (ioc->set)
-               ret = brcmf_proto_cdc_set_ioctl(drvr, ifidx, ioc->cmd,
-                                               buf, len);
+       prot->lastcmd = dcmd->cmd;
+       if (dcmd->set)
+               ret = brcmf_proto_cdc_set_dcmd(drvr, ifidx, dcmd->cmd,
+                                                  dcmd->buf, len);
        else {
-               ret = brcmf_proto_cdc_query_ioctl(drvr, ifidx, ioc->cmd,
-                                                 buf, len);
+               ret = brcmf_proto_cdc_query_dcmd(drvr, ifidx, dcmd->cmd,
+                                                    dcmd->buf, len);
                if (ret > 0)
-                       ioc->used = ret - sizeof(struct brcmf_proto_cdc_ioctl);
+                       dcmd->used = ret -
+                                       sizeof(struct brcmf_proto_cdc_dcmd);
        }
 
-       /* Too many programs assume ioctl() returns 0 on success */
        if (ret >= 0)
                ret = 0;
        else {
-               struct brcmf_proto_cdc_ioctl *msg = &prot->msg;
+               struct brcmf_proto_cdc_dcmd *msg = &prot->msg;
                /* len == needed when set/query fails from dongle */
-               ioc->needed = le32_to_cpu(msg->len);
+               dcmd->needed = le32_to_cpu(msg->len);
        }
 
-       /* Intercept the wme_dp ioctl here */
-       if (!ret && ioc->cmd == BRCMF_C_SET_VAR &&
-           !strcmp(buf, "wme_dp")) {
-               int slen, val = 0;
+       /* Intercept the wme_dp dongle cmd here */
+       if (!ret && dcmd->cmd == BRCMF_C_SET_VAR &&
+           !strcmp(dcmd->buf, "wme_dp")) {
+               int slen;
+               __le32 val = 0;
 
                slen = strlen("wme_dp") + 1;
                if (len >= (int)(slen + sizeof(int)))
-                       memcpy(&val, (char *)buf + slen, sizeof(int));
+                       memcpy(&val, (char *)dcmd->buf + slen, sizeof(int));
                drvr->wme_dp = (u8) le32_to_cpu(val);
        }
 
@@ -342,15 +343,14 @@ done:
        return ret;
 }
 
-#define PKTSUMNEEDED(skb) \
-               (((struct sk_buff *)(skb))->ip_summed == CHECKSUM_PARTIAL)
-#define PKTSETSUMGOOD(skb, x) \
-               (((struct sk_buff *)(skb))->ip_summed = \
-               ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
+static bool pkt_sum_needed(struct sk_buff *skb)
+{
+       return skb->ip_summed == CHECKSUM_PARTIAL;
+}
 
-void brcmf_proto_dump(struct brcmf_pub *drvr, struct brcmu_strbuf *strbuf)
+static void pkt_set_sum_good(struct sk_buff *skb, bool x)
 {
-       brcmu_bprintf(strbuf, "Protocol CDC: reqid %d\n", drvr->prot->reqid);
+       skb->ip_summed = (x ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE);
 }
 
 void brcmf_proto_hdrpush(struct brcmf_pub *drvr, int ifidx,
@@ -358,7 +358,7 @@ void brcmf_proto_hdrpush(struct brcmf_pub *drvr, int ifidx,
 {
        struct brcmf_proto_bdc_header *h;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        /* Push BDC header used to convey priority for buses that don't */
 
@@ -367,7 +367,7 @@ void brcmf_proto_hdrpush(struct brcmf_pub *drvr, int ifidx,
        h = (struct brcmf_proto_bdc_header *)(pktbuf->data);
 
        h->flags = (BDC_PROTO_VER << BDC_FLAG_VER_SHIFT);
-       if (PKTSUMNEEDED(pktbuf))
+       if (pkt_sum_needed(pktbuf))
                h->flags |= BDC_FLAG_SUM_NEEDED;
 
        h->priority = (pktbuf->priority & BDC_PRIORITY_MASK);
@@ -381,13 +381,13 @@ int brcmf_proto_hdrpull(struct brcmf_pub *drvr, int *ifidx,
 {
        struct brcmf_proto_bdc_header *h;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        /* Pop BDC header used to convey priority for buses that don't */
 
        if (pktbuf->len < BDC_HEADER_LEN) {
-               BRCMF_ERROR(("%s: rx data too short (%d < %d)\n", __func__,
-                            pktbuf->len, BDC_HEADER_LEN));
+               brcmf_dbg(ERROR, "rx data too short (%d < %d)\n",
+                         pktbuf->len, BDC_HEADER_LEN);
                return -EBADE;
        }
 
@@ -395,23 +395,21 @@ int brcmf_proto_hdrpull(struct brcmf_pub *drvr, int *ifidx,
 
        *ifidx = BDC_GET_IF_IDX(h);
        if (*ifidx >= BRCMF_MAX_IFS) {
-               BRCMF_ERROR(("%s: rx data ifnum out of range (%d)\n",
-                            __func__, *ifidx));
+               brcmf_dbg(ERROR, "rx data ifnum out of range (%d)\n", *ifidx);
                return -EBADE;
        }
 
        if (((h->flags & BDC_FLAG_VER_MASK) >> BDC_FLAG_VER_SHIFT) !=
            BDC_PROTO_VER) {
-               BRCMF_ERROR(("%s: non-BDC packet received, flags 0x%x\n",
-                            brcmf_ifname(drvr, *ifidx), h->flags));
+               brcmf_dbg(ERROR, "%s: non-BDC packet received, flags 0x%x\n",
+                         brcmf_ifname(drvr, *ifidx), h->flags);
                return -EBADE;
        }
 
        if (h->flags & BDC_FLAG_SUM_GOOD) {
-               BRCMF_INFO(("%s: BDC packet received with good rx-csum, "
-                           "flags 0x%x\n",
-                           brcmf_ifname(drvr, *ifidx), h->flags));
-               PKTSETSUMGOOD(pktbuf, true);
+               brcmf_dbg(INFO, "%s: BDC packet received with good rx-csum, flags 0x%x\n",
+                         brcmf_ifname(drvr, *ifidx), h->flags);
+               pkt_set_sum_good(pktbuf, true);
        }
 
        pktbuf->priority = h->priority & BDC_PRIORITY_MASK;
@@ -426,21 +424,19 @@ int brcmf_proto_attach(struct brcmf_pub *drvr)
        struct brcmf_proto *cdc;
 
        cdc = kzalloc(sizeof(struct brcmf_proto), GFP_ATOMIC);
-       if (!cdc) {
-               BRCMF_ERROR(("%s: kmalloc failed\n", __func__));
+       if (!cdc)
                goto fail;
-       }
 
        /* ensure that the msg buf directly follows the cdc msg struct */
        if ((unsigned long)(&cdc->msg + 1) != (unsigned long)cdc->buf) {
-               BRCMF_ERROR(("struct brcmf_proto is not correctly defined\n"));
+               brcmf_dbg(ERROR, "struct brcmf_proto is not correctly defined\n");
                goto fail;
        }
 
        drvr->prot = cdc;
        drvr->hdrlen += BDC_HEADER_LEN;
-       drvr->maxctl = BRCMF_C_IOCTL_MAXLEN +
-                       sizeof(struct brcmf_proto_cdc_ioctl) + ROUND_UP_MARGIN;
+       drvr->maxctl = BRCMF_DCMD_MAXLEN +
+                       sizeof(struct brcmf_proto_cdc_dcmd) + ROUND_UP_MARGIN;
        return 0;
 
 fail:
@@ -472,13 +468,13 @@ int brcmf_proto_init(struct brcmf_pub *drvr)
        int ret = 0;
        char buf[128];
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        brcmf_os_proto_block(drvr);
 
        /* Get the device MAC address */
        strcpy(buf, "cur_etheraddr");
-       ret = brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR,
+       ret = brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR,
                                          buf, sizeof(buf));
        if (ret < 0) {
                brcmf_os_proto_unblock(drvr);
@@ -488,7 +484,7 @@ int brcmf_proto_init(struct brcmf_pub *drvr)
 
        brcmf_os_proto_unblock(drvr);
 
-       ret = brcmf_c_preinit_ioctls(drvr);
+       ret = brcmf_c_preinit_dcmds(drvr);
 
        /* Always assumes wl for now */
        drvr->iswl = true;
index fdec468..8918261 100644 (file)
 #define DOT11_OUI_LEN                  3
 #define BCMILCP_BCM_SUBTYPE_EVENT      1
 #define PKTFILTER_BUF_SIZE             2048
+#define BRCMF_ARPOL_MODE               0xb     /* agent|snoop|peer_autoreply */
 
 int brcmf_msg_level;
 
 #define MSGTRACE_VERSION       1
 
+#define BRCMF_PKT_FILTER_FIXED_LEN     offsetof(struct brcmf_pkt_filter_le, u)
+#define BRCMF_PKT_FILTER_PATTERN_FIXED_LEN     \
+       offsetof(struct brcmf_pkt_filter_pattern_le, mask_and_pattern)
+
 #ifdef BCMDBG
-const char brcmf_version[] =
-"Dongle Host Driver, version " BRCMF_VERSION_STR "\nCompiled on " __DATE__
-" at " __TIME__;
+static const char brcmf_version[] =
+       "Dongle Host Driver, version " BRCMF_VERSION_STR "\nCompiled on "
+       __DATE__ " at " __TIME__;
 #else
-const char brcmf_version[] = "Dongle Host Driver, version " BRCMF_VERSION_STR;
+static const char brcmf_version[] =
+       "Dongle Host Driver, version " BRCMF_VERSION_STR;
 #endif
 
-/* IOVar table */
-enum {
-       IOV_VERSION = 1,
-       IOV_MSGLEVEL,
-       IOV_BCMERRORSTR,
-       IOV_BCMERROR,
-       IOV_DUMP,
-       IOV_CLEARCOUNTS,
-       IOV_LOGDUMP,
-       IOV_LOGCAL,
-       IOV_LOGSTAMP,
-       IOV_GPIOOB,
-       IOV_IOCTLTIMEOUT,
-       IOV_LAST
-};
-
-const struct brcmu_iovar brcmf_iovars[] = {
-       {"version", IOV_VERSION, 0, IOVT_BUFFER, sizeof(brcmf_version)}
-       ,
-#ifdef BCMDBG
-       {"msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0}
-       ,
-#endif                         /* BCMDBG */
-       {"bcmerrorstr", IOV_BCMERRORSTR, 0, IOVT_BUFFER, BCME_STRLEN}
-       ,
-       {"bcmerror", IOV_BCMERROR, 0, IOVT_INT8, 0}
-       ,
-       {"dump", IOV_DUMP, 0, IOVT_BUFFER, BRCMF_IOCTL_MAXLEN}
-       ,
-       {"clearcounts", IOV_CLEARCOUNTS, 0, IOVT_VOID, 0}
-       ,
-       {"gpioob", IOV_GPIOOB, 0, IOVT_UINT32, 0}
-       ,
-       {"ioctl_timeout", IOV_IOCTLTIMEOUT, 0, IOVT_UINT32, 0}
-       ,
-       {NULL, 0, 0, 0, 0}
-};
-
 /* Message trace header */
 struct msgtrace_hdr {
        u8 version;
        u8 spare;
-       u16 len;                /* Len of the trace */
-       u32 seqnum;             /* Sequence number of message. Useful
+       __be16 len;             /* Len of the trace */
+       __be32 seqnum;          /* Sequence number of message. Useful
                                 * if the messsage has been lost
                                 * because of DMA error or a bus reset
                                 * (ex: SDIO Func2)
                                 */
-       u32 discarded_bytes;    /* Number of discarded bytes because of
+       __be32 discarded_bytes; /* Number of discarded bytes because of
                                 trace overflow  */
-       u32 discarded_printf;   /* Number of discarded printf
+       __be32 discarded_printf;        /* Number of discarded printf
                                 because of trace overflow */
 } __packed;
 
+
+uint
+brcmf_c_mkiovar(char *name, char *data, uint datalen, char *buf, uint buflen)
+{
+       uint len;
+
+       len = strlen(name) + 1;
+
+       if ((len + datalen) > buflen)
+               return 0;
+
+       strncpy(buf, name, buflen);
+
+       /* append data onto the end of the name string */
+       memcpy(&buf[len], data, datalen);
+       len += datalen;
+
+       return len;
+}
+
 void brcmf_c_init(void)
 {
        /* Init global variables at run-time, not as part of the declaration.
@@ -110,147 +98,6 @@ void brcmf_c_init(void)
        brcmf_msg_level = BRCMF_ERROR_VAL;
 }
 
-static int brcmf_c_dump(struct brcmf_pub *drvr, char *buf, int buflen)
-{
-       struct brcmu_strbuf b;
-       struct brcmu_strbuf *strbuf = &b;
-
-       brcmu_binit(strbuf, buf, buflen);
-
-       /* Base info */
-       brcmu_bprintf(strbuf, "%s\n", brcmf_version);
-       brcmu_bprintf(strbuf, "\n");
-       brcmu_bprintf(strbuf, "pub.up %d pub.txoff %d pub.busstate %d\n",
-                   drvr->up, drvr->txoff, drvr->busstate);
-       brcmu_bprintf(strbuf, "pub.hdrlen %d pub.maxctl %d pub.rxsz %d\n",
-                   drvr->hdrlen, drvr->maxctl, drvr->rxsz);
-       brcmu_bprintf(strbuf, "pub.iswl %d pub.drv_version %ld pub.mac %pM\n",
-                   drvr->iswl, drvr->drv_version, &drvr->mac);
-       brcmu_bprintf(strbuf, "pub.bcmerror %d tickcnt %d\n", drvr->bcmerror,
-                   drvr->tickcnt);
-
-       brcmu_bprintf(strbuf, "dongle stats:\n");
-       brcmu_bprintf(strbuf,
-                   "tx_packets %ld tx_bytes %ld tx_errors %ld tx_dropped %ld\n",
-                   drvr->dstats.tx_packets, drvr->dstats.tx_bytes,
-                   drvr->dstats.tx_errors, drvr->dstats.tx_dropped);
-       brcmu_bprintf(strbuf,
-                   "rx_packets %ld rx_bytes %ld rx_errors %ld rx_dropped %ld\n",
-                   drvr->dstats.rx_packets, drvr->dstats.rx_bytes,
-                   drvr->dstats.rx_errors, drvr->dstats.rx_dropped);
-       brcmu_bprintf(strbuf, "multicast %ld\n", drvr->dstats.multicast);
-
-       brcmu_bprintf(strbuf, "bus stats:\n");
-       brcmu_bprintf(strbuf, "tx_packets %ld tx_multicast %ld tx_errors %ld\n",
-                   drvr->tx_packets, drvr->tx_multicast, drvr->tx_errors);
-       brcmu_bprintf(strbuf, "tx_ctlpkts %ld tx_ctlerrs %ld\n",
-                   drvr->tx_ctlpkts, drvr->tx_ctlerrs);
-       brcmu_bprintf(strbuf, "rx_packets %ld rx_multicast %ld rx_errors %ld\n",
-                   drvr->rx_packets, drvr->rx_multicast, drvr->rx_errors);
-       brcmu_bprintf(strbuf,
-                   "rx_ctlpkts %ld rx_ctlerrs %ld rx_dropped %ld rx_flushed %ld\n",
-                   drvr->rx_ctlpkts, drvr->rx_ctlerrs, drvr->rx_dropped,
-                   drvr->rx_flushed);
-       brcmu_bprintf(strbuf,
-                   "rx_readahead_cnt %ld tx_realloc %ld fc_packets %ld\n",
-                   drvr->rx_readahead_cnt, drvr->tx_realloc, drvr->fc_packets);
-       brcmu_bprintf(strbuf, "wd_dpc_sched %ld\n", drvr->wd_dpc_sched);
-       brcmu_bprintf(strbuf, "\n");
-
-       /* Add any prot info */
-       brcmf_proto_dump(drvr, strbuf);
-       brcmu_bprintf(strbuf, "\n");
-
-       /* Add any bus info */
-       brcmf_sdbrcm_bus_dump(drvr, strbuf);
-
-       return !strbuf->size ? -EOVERFLOW : 0;
-}
-
-static int
-brcmf_c_doiovar(struct brcmf_pub *drvr, const struct brcmu_iovar *vi,
-               u32 actionid, const char *name, void *params, int plen,
-               void *arg, int len, int val_size)
-{
-       int bcmerror = 0;
-       s32 int_val = 0;
-
-       BRCMF_TRACE(("%s: Enter\n", __func__));
-
-       bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid));
-       if (bcmerror != 0)
-               goto exit;
-
-       if (plen >= (int)sizeof(int_val))
-               memcpy(&int_val, params, sizeof(int_val));
-
-       switch (actionid) {
-       case IOV_GVAL(IOV_VERSION):
-               /* Need to have checked buffer length */
-               strncpy((char *)arg, brcmf_version, len);
-               break;
-
-       case IOV_GVAL(IOV_MSGLEVEL):
-               int_val = (s32) brcmf_msg_level;
-               memcpy(arg, &int_val, val_size);
-               break;
-
-       case IOV_SVAL(IOV_MSGLEVEL):
-               brcmf_msg_level = int_val;
-               break;
-
-       case IOV_GVAL(IOV_BCMERRORSTR):
-               strncpy((char *)arg, "bcm_error",
-                       BCME_STRLEN);
-               ((char *)arg)[BCME_STRLEN - 1] = 0x00;
-               break;
-
-       case IOV_GVAL(IOV_BCMERROR):
-               int_val = (s32) drvr->bcmerror;
-               memcpy(arg, &int_val, val_size);
-               break;
-
-       case IOV_GVAL(IOV_DUMP):
-               bcmerror = brcmf_c_dump(drvr, arg, len);
-               break;
-
-       case IOV_SVAL(IOV_CLEARCOUNTS):
-               drvr->tx_packets = drvr->rx_packets = 0;
-               drvr->tx_errors = drvr->rx_errors = 0;
-               drvr->tx_ctlpkts = drvr->rx_ctlpkts = 0;
-               drvr->tx_ctlerrs = drvr->rx_ctlerrs = 0;
-               drvr->rx_dropped = 0;
-               drvr->rx_readahead_cnt = 0;
-               drvr->tx_realloc = 0;
-               drvr->wd_dpc_sched = 0;
-               memset(&drvr->dstats, 0, sizeof(drvr->dstats));
-               brcmf_bus_clearcounts(drvr);
-               break;
-
-       case IOV_GVAL(IOV_IOCTLTIMEOUT):{
-                       int_val = (s32) brcmf_os_get_ioctl_resp_timeout();
-                       memcpy(arg, &int_val, sizeof(int_val));
-                       break;
-               }
-
-       case IOV_SVAL(IOV_IOCTLTIMEOUT):{
-                       if (int_val <= 0)
-                               bcmerror = -EINVAL;
-                       else
-                               brcmf_os_set_ioctl_resp_timeout((unsigned int)
-                                                             int_val);
-                       break;
-               }
-
-       default:
-               bcmerror = -ENOTSUPP;
-               break;
-       }
-
-exit:
-       return bcmerror;
-}
-
 bool brcmf_c_prec_enq(struct brcmf_pub *drvr, struct pktq *q,
                      struct sk_buff *pkt, int prec)
 {
@@ -278,159 +125,28 @@ bool brcmf_c_prec_enq(struct brcmf_pub *drvr, struct pktq *q,
        /* Evict if needed */
        if (eprec >= 0) {
                /* Detect queueing to unconfigured precedence */
-               discard_oldest = AC_BITMAP_TST(drvr->wme_dp, eprec);
+               discard_oldest = ac_bitmap_tst(drvr->wme_dp, eprec);
                if (eprec == prec && !discard_oldest)
                        return false;   /* refuse newer (incoming) packet */
                /* Evict packet according to discard policy */
                p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) :
                        brcmu_pktq_pdeq_tail(q, eprec);
-               if (p == NULL) {
-                       BRCMF_ERROR(("%s: brcmu_pktq_penq() failed, oldest %d.",
-                                    __func__, discard_oldest));
-               }
+               if (p == NULL)
+                       brcmf_dbg(ERROR, "brcmu_pktq_penq() failed, oldest %d\n",
+                                 discard_oldest);
+
                brcmu_pkt_buf_free_skb(p);
        }
 
        /* Enqueue */
        p = brcmu_pktq_penq(q, prec, pkt);
-       if (p == NULL) {
-               BRCMF_ERROR(("%s: brcmu_pktq_penq() failed.", __func__));
-       }
+       if (p == NULL)
+               brcmf_dbg(ERROR, "brcmu_pktq_penq() failed\n");
 
        return p != NULL;
 }
 
-static int
-brcmf_c_iovar_op(struct brcmf_pub *drvr, const char *name,
-            void *params, int plen, void *arg, int len, bool set)
-{
-       int bcmerror = 0;
-       int val_size;
-       const struct brcmu_iovar *vi = NULL;
-       u32 actionid;
-
-       BRCMF_TRACE(("%s: Enter\n", __func__));
-
-       if (name == NULL || len <= 0)
-               return -EINVAL;
-
-       /* Set does not take qualifiers */
-       if (set && (params || plen))
-               return -EINVAL;
-
-       /* Get must have return space;*/
-       if (!set && !(arg && len))
-               return -EINVAL;
-
-       vi = brcmu_iovar_lookup(brcmf_iovars, name);
-       if (vi == NULL) {
-               bcmerror = -ENOTSUPP;
-               goto exit;
-       }
-
-       BRCMF_CTL(("%s: %s %s, len %d plen %d\n", __func__,
-                  name, (set ? "set" : "get"), len, plen));
-
-       /* set up 'params' pointer in case this is a set command so that
-        * the convenience int and bool code can be common to set and get
-        */
-       if (params == NULL) {
-               params = arg;
-               plen = len;
-       }
-
-       if (vi->type == IOVT_VOID)
-               val_size = 0;
-       else if (vi->type == IOVT_BUFFER)
-               val_size = len;
-       else
-               /* all other types are integer sized */
-               val_size = sizeof(int);
-
-       actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
-       bcmerror =
-           brcmf_c_doiovar(drvr, vi, actionid, name, params, plen, arg, len,
-                       val_size);
-
-exit:
-       return bcmerror;
-}
-
-int brcmf_c_ioctl(struct brcmf_pub *drvr, struct brcmf_c_ioctl *ioc, void *buf,
-                 uint buflen)
-{
-       int bcmerror = 0;
-
-       BRCMF_TRACE(("%s: Enter\n", __func__));
-
-       if (!buf)
-               return -EINVAL;
-
-       switch (ioc->cmd) {
-       case BRCMF_GET_MAGIC:
-               if (buflen < sizeof(int))
-                       bcmerror = -EOVERFLOW;
-               else
-                       *(int *)buf = BRCMF_IOCTL_MAGIC;
-               break;
-
-       case BRCMF_GET_VERSION:
-               if (buflen < sizeof(int))
-                       bcmerror = -EOVERFLOW;
-               else
-                       *(int *)buf = BRCMF_IOCTL_VERSION;
-               break;
-
-       case BRCMF_GET_VAR:
-       case BRCMF_SET_VAR:{
-                       char *arg;
-                       uint arglen;
-
-                       /* scan past the name to any arguments */
-                       for (arg = buf, arglen = buflen; *arg && arglen;
-                            arg++, arglen--)
-                               ;
-
-                       if (*arg) {
-                               bcmerror = -EOVERFLOW;
-                               break;
-                       }
-
-                       /* account for the NUL terminator */
-                       arg++, arglen--;
-
-                       /* call with the appropriate arguments */
-                       if (ioc->cmd == BRCMF_GET_VAR)
-                               bcmerror = brcmf_c_iovar_op(drvr, buf, arg,
-                                               arglen, buf, buflen, IOV_GET);
-                       else
-                               bcmerror =
-                                   brcmf_c_iovar_op(drvr, buf, NULL, 0, arg,
-                                                    arglen, IOV_SET);
-                       if (bcmerror != -ENOTSUPP)
-                               break;
-
-                       /* if still not found, try bus module */
-                       if (ioc->cmd == BRCMF_GET_VAR)
-                               bcmerror = brcmf_sdbrcm_bus_iovar_op(drvr,
-                                               buf, arg, arglen, buf, buflen,
-                                               IOV_GET);
-                       else
-                               bcmerror = brcmf_sdbrcm_bus_iovar_op(drvr,
-                                               buf, NULL, 0, arg, arglen,
-                                               IOV_SET);
-
-                       break;
-               }
-
-       default:
-               bcmerror = -ENOTSUPP;
-       }
-
-       return bcmerror;
-}
-
-#ifdef SHOW_EVENTS
+#ifdef BCMDBG
 static void
 brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data)
 {
@@ -502,6 +218,11 @@ brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data)
                BRCMF_E_PFN_SCAN_COMPLETE, "SCAN_COMPLETE"}
        };
        uint event_type, flags, auth_type, datalen;
+       static u32 seqnum_prev;
+       struct msgtrace_hdr hdr;
+       u32 nblost;
+       char *s, *p;
+
        event_type = be32_to_cpu(event->event_type);
        flags = be16_to_cpu(event->flags);
        status = be32_to_cpu(event->status);
@@ -517,9 +238,9 @@ brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data)
                        event_name = event_names[i].event_name;
        }
 
-       BRCMF_EVENT(("EVENT: %s, event ID = %d\n", event_name, event_type));
-       BRCMF_EVENT(("flags 0x%04x, status %d, reason %d, auth_type %d"
-                    " MAC %s\n", flags, status, reason, auth_type, eabuf));
+       brcmf_dbg(EVENT, "EVENT: %s, event ID = %d\n", event_name, event_type);
+       brcmf_dbg(EVENT, "flags 0x%04x, status %d, reason %d, auth_type %d MAC %s\n",
+                 flags, status, reason, auth_type, eabuf);
 
        if (flags & BRCMF_EVENT_MSG_LINK)
                link = true;
@@ -532,36 +253,34 @@ brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data)
        case BRCMF_E_START:
        case BRCMF_E_DEAUTH:
        case BRCMF_E_DISASSOC:
-               BRCMF_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
+               brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf);
                break;
 
        case BRCMF_E_ASSOC_IND:
        case BRCMF_E_REASSOC_IND:
-               BRCMF_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
+               brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf);
                break;
 
        case BRCMF_E_ASSOC:
        case BRCMF_E_REASSOC:
-               if (status == BRCMF_E_STATUS_SUCCESS) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, SUCCESS\n",
-                                    event_name, eabuf));
-               } else if (status == BRCMF_E_STATUS_TIMEOUT) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, TIMEOUT\n",
-                                    event_name, eabuf));
-               } else if (status == BRCMF_E_STATUS_FAIL) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, FAILURE,"
-                                    " reason %d\n", event_name, eabuf,
-                                    (int)reason));
-               } else {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, unexpected status "
-                                    "%d\n", event_name, eabuf, (int)status));
-               }
+               if (status == BRCMF_E_STATUS_SUCCESS)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, SUCCESS\n",
+                                 event_name, eabuf);
+               else if (status == BRCMF_E_STATUS_TIMEOUT)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, TIMEOUT\n",
+                                 event_name, eabuf);
+               else if (status == BRCMF_E_STATUS_FAIL)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, FAILURE, reason %d\n",
+                                 event_name, eabuf, (int)reason);
+               else
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, unexpected status %d\n",
+                                 event_name, eabuf, (int)status);
                break;
 
        case BRCMF_E_DEAUTH_IND:
        case BRCMF_E_DISASSOC_IND:
-               BRCMF_EVENT(("MACEVENT: %s, MAC %s, reason %d\n", event_name,
-                            eabuf, (int)reason));
+               brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, reason %d\n",
+                         event_name, eabuf, (int)reason);
                break;
 
        case BRCMF_E_AUTH:
@@ -574,19 +293,18 @@ brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data)
                        sprintf(err_msg, "AUTH unknown: %d", (int)auth_type);
                        auth_str = err_msg;
                }
-               if (event_type == BRCMF_E_AUTH_IND) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, %s\n", event_name,
-                                    eabuf, auth_str));
-               } else if (status == BRCMF_E_STATUS_SUCCESS) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, %s, SUCCESS\n",
-                                    event_name, eabuf, auth_str));
-               } else if (status == BRCMF_E_STATUS_TIMEOUT) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, %s, TIMEOUT\n",
-                                    event_name, eabuf, auth_str));
-               } else if (status == BRCMF_E_STATUS_FAIL) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s, %s, FAILURE, "
-                                    "reason %d\n",
-                                    event_name, eabuf, auth_str, (int)reason));
+               if (event_type == BRCMF_E_AUTH_IND)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s\n",
+                                 event_name, eabuf, auth_str);
+               else if (status == BRCMF_E_STATUS_SUCCESS)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, SUCCESS\n",
+                                 event_name, eabuf, auth_str);
+               else if (status == BRCMF_E_STATUS_TIMEOUT)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, TIMEOUT\n",
+                                 event_name, eabuf, auth_str);
+               else if (status == BRCMF_E_STATUS_FAIL) {
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, FAILURE, reason %d\n",
+                                 event_name, eabuf, auth_str, (int)reason);
                }
 
                break;
@@ -594,149 +312,138 @@ brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data)
        case BRCMF_E_JOIN:
        case BRCMF_E_ROAM:
        case BRCMF_E_SET_SSID:
-               if (status == BRCMF_E_STATUS_SUCCESS) {
-                       BRCMF_EVENT(("MACEVENT: %s, MAC %s\n", event_name,
-                                    eabuf));
-               } else if (status == BRCMF_E_STATUS_FAIL) {
-                       BRCMF_EVENT(("MACEVENT: %s, failed\n", event_name));
-               } else if (status == BRCMF_E_STATUS_NO_NETWORKS) {
-                       BRCMF_EVENT(("MACEVENT: %s, no networks found\n",
-                                    event_name));
-               } else {
-                       BRCMF_EVENT(("MACEVENT: %s, unexpected status %d\n",
-                                    event_name, (int)status));
-               }
+               if (status == BRCMF_E_STATUS_SUCCESS)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n",
+                                 event_name, eabuf);
+               else if (status == BRCMF_E_STATUS_FAIL)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, failed\n", event_name);
+               else if (status == BRCMF_E_STATUS_NO_NETWORKS)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, no networks found\n",
+                                 event_name);
+               else
+                       brcmf_dbg(EVENT, "MACEVENT: %s, unexpected status %d\n",
+                                 event_name, (int)status);
                break;
 
        case BRCMF_E_BEACON_RX:
-               if (status == BRCMF_E_STATUS_SUCCESS) {
-                       BRCMF_EVENT(("MACEVENT: %s, SUCCESS\n", event_name));
-               } else if (status == BRCMF_E_STATUS_FAIL) {
-                       BRCMF_EVENT(("MACEVENT: %s, FAIL\n", event_name));
-               } else {
-                       BRCMF_EVENT(("MACEVENT: %s, status %d\n", event_name,
-                                    status));
-               }
+               if (status == BRCMF_E_STATUS_SUCCESS)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, SUCCESS\n", event_name);
+               else if (status == BRCMF_E_STATUS_FAIL)
+                       brcmf_dbg(EVENT, "MACEVENT: %s, FAIL\n", event_name);
+               else
+                       brcmf_dbg(EVENT, "MACEVENT: %s, status %d\n",
+                                 event_name, status);
                break;
 
        case BRCMF_E_LINK:
-               BRCMF_EVENT(("MACEVENT: %s %s\n", event_name,
-                            link ? "UP" : "DOWN"));
+               brcmf_dbg(EVENT, "MACEVENT: %s %s\n",
+                         event_name, link ? "UP" : "DOWN");
                break;
 
        case BRCMF_E_MIC_ERROR:
-               BRCMF_EVENT(("MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
-                            event_name, eabuf, group, flush_txq));
+               brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
+                         event_name, eabuf, group, flush_txq);
                break;
 
        case BRCMF_E_ICV_ERROR:
        case BRCMF_E_UNICAST_DECODE_ERROR:
        case BRCMF_E_MULTICAST_DECODE_ERROR:
-               BRCMF_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
+               brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf);
                break;
 
        case BRCMF_E_TXFAIL:
-               BRCMF_EVENT(("MACEVENT: %s, RA %s\n", event_name, eabuf));
+               brcmf_dbg(EVENT, "MACEVENT: %s, RA %s\n", event_name, eabuf);
                break;
 
        case BRCMF_E_SCAN_COMPLETE:
        case BRCMF_E_PMKID_CACHE:
-               BRCMF_EVENT(("MACEVENT: %s\n", event_name));
+               brcmf_dbg(EVENT, "MACEVENT: %s\n", event_name);
                break;
 
        case BRCMF_E_PFN_NET_FOUND:
        case BRCMF_E_PFN_NET_LOST:
        case BRCMF_E_PFN_SCAN_COMPLETE:
-               BRCMF_EVENT(("PNOEVENT: %s\n", event_name));
+               brcmf_dbg(EVENT, "PNOEVENT: %s\n", event_name);
                break;
 
        case BRCMF_E_PSK_SUP:
        case BRCMF_E_PRUNE:
-               BRCMF_EVENT(("MACEVENT: %s, status %d, reason %d\n",
-                          event_name, (int)status, (int)reason));
+               brcmf_dbg(EVENT, "MACEVENT: %s, status %d, reason %d\n",
+                         event_name, (int)status, (int)reason);
                break;
 
        case BRCMF_E_TRACE:
-               {
-                       static u32 seqnum_prev;
-                       struct msgtrace_hdr hdr;
-                       u32 nblost;
-                       char *s, *p;
-
-                       buf = (unsigned char *) event_data;
-                       memcpy(&hdr, buf, sizeof(struct msgtrace_hdr));
-
-                       if (hdr.version != MSGTRACE_VERSION) {
-                               BRCMF_ERROR(
-                                   ("\nMACEVENT: %s [unsupported version --> "
-                                    "brcmf version:%d dongle version:%d]\n",
-                                    event_name, MSGTRACE_VERSION, hdr.version)
-                               );
-                               /* Reset datalen to avoid display below */
-                               datalen = 0;
-                               break;
-                       }
-
-                       /* There are 2 bytes available at the end of data */
-                       *(buf + sizeof(struct msgtrace_hdr)
-                                + be16_to_cpu(hdr.len)) = '\0';
-
-                       if (be32_to_cpu(hdr.discarded_bytes)
-                           || be32_to_cpu(hdr.discarded_printf)) {
-                               BRCMF_ERROR(
-                                   ("\nWLC_E_TRACE: [Discarded traces in dongle -->"
-                                    "discarded_bytes %d discarded_printf %d]\n",
-                                    be32_to_cpu(hdr.discarded_bytes),
-                                    be32_to_cpu(hdr.discarded_printf)));
-                       }
-
-                       nblost = be32_to_cpu(hdr.seqnum) - seqnum_prev - 1;
-                       if (nblost > 0) {
-                               BRCMF_ERROR(
-                                   ("\nWLC_E_TRACE: [Event lost --> seqnum %d nblost %d\n",
-                                    be32_to_cpu(hdr.seqnum), nblost));
-                       }
-                       seqnum_prev = be32_to_cpu(hdr.seqnum);
-
-                       /* Display the trace buffer. Advance from \n to \n to
-                        * avoid display big
-                        * printf (issue with Linux printk )
-                        */
-                       p = (char *)&buf[sizeof(struct msgtrace_hdr)];
-                       while ((s = strstr(p, "\n")) != NULL) {
-                               *s = '\0';
-                               printk(KERN_DEBUG"%s\n", p);
-                               p = s + 1;
-                       }
-                       printk(KERN_DEBUG "%s\n", p);
+               buf = (unsigned char *) event_data;
+               memcpy(&hdr, buf, sizeof(struct msgtrace_hdr));
 
+               if (hdr.version != MSGTRACE_VERSION) {
+                       brcmf_dbg(ERROR,
+                                 "MACEVENT: %s [unsupported version --> brcmf"
+                                 " version:%d dongle version:%d]\n",
+                                 event_name, MSGTRACE_VERSION, hdr.version);
                        /* Reset datalen to avoid display below */
                        datalen = 0;
+                       break;
+               }
+
+               /* There are 2 bytes available at the end of data */
+               *(buf + sizeof(struct msgtrace_hdr)
+                        + be16_to_cpu(hdr.len)) = '\0';
+
+               if (be32_to_cpu(hdr.discarded_bytes)
+                   || be32_to_cpu(hdr.discarded_printf))
+                       brcmf_dbg(ERROR,
+                                 "WLC_E_TRACE: [Discarded traces in dongle -->"
+                                 " discarded_bytes %d discarded_printf %d]\n",
+                                 be32_to_cpu(hdr.discarded_bytes),
+                                 be32_to_cpu(hdr.discarded_printf));
+
+               nblost = be32_to_cpu(hdr.seqnum) - seqnum_prev - 1;
+               if (nblost > 0)
+                       brcmf_dbg(ERROR, "WLC_E_TRACE: [Event lost --> seqnum "
+                                 " %d nblost %d\n", be32_to_cpu(hdr.seqnum),
+                                 nblost);
+               seqnum_prev = be32_to_cpu(hdr.seqnum);
+
+               /* Display the trace buffer. Advance from \n to \n to
+                * avoid display big
+                * printf (issue with Linux printk )
+                */
+               p = (char *)&buf[sizeof(struct msgtrace_hdr)];
+               while ((s = strstr(p, "\n")) != NULL) {
+                       *s = '\0';
+                       printk(KERN_DEBUG"%s\n", p);
+                       p = s + 1;
                }
+               printk(KERN_DEBUG "%s\n", p);
+
+               /* Reset datalen to avoid display below */
+               datalen = 0;
                break;
 
        case BRCMF_E_RSSI:
-               BRCMF_EVENT(("MACEVENT: %s %d\n", event_name,
-                            be32_to_cpu(*((int *)event_data))));
+               brcmf_dbg(EVENT, "MACEVENT: %s %d\n",
+                         event_name, be32_to_cpu(*((__be32 *)event_data)));
                break;
 
        default:
-               BRCMF_EVENT(("MACEVENT: %s %d, MAC %s, status %d, reason %d, "
-                            "auth %d\n", event_name, event_type, eabuf,
-                            (int)status, (int)reason, (int)auth_type));
+               brcmf_dbg(EVENT,
+                         "MACEVENT: %s %d, MAC %s, status %d, reason %d, "
+                         "auth %d\n", event_name, event_type, eabuf,
+                         (int)status, (int)reason, (int)auth_type);
                break;
        }
 
        /* show any appended data */
        if (datalen) {
                buf = (unsigned char *) event_data;
-               BRCMF_EVENT((" data (%d) : ", datalen));
+               brcmf_dbg(EVENT, " data (%d) : ", datalen);
                for (i = 0; i < datalen; i++)
-                       BRCMF_EVENT((" 0x%02x ", *buf++));
-               BRCMF_EVENT(("\n"));
+                       brcmf_dbg(EVENT, " 0x%02x ", *buf++);
+               brcmf_dbg(EVENT, "\n");
        }
 }
-#endif                         /* SHOW_EVENTS */
+#endif                         /* BCMDBG */
 
 int
 brcmf_c_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
@@ -744,20 +451,21 @@ brcmf_c_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
 {
        /* check whether packet is a BRCM event pkt */
        struct brcmf_event *pvt_data = (struct brcmf_event *) pktdata;
+       struct brcmf_if_event *ifevent;
        char *event_data;
        u32 type, status;
        u16 flags;
        int evlen;
 
        if (memcmp(BRCM_OUI, &pvt_data->hdr.oui[0], DOT11_OUI_LEN)) {
-               BRCMF_ERROR(("%s: mismatched OUI, bailing\n", __func__));
+               brcmf_dbg(ERROR, "mismatched OUI, bailing\n");
                return -EBADE;
        }
 
        /* BRCM event pkt may be unaligned - use xxx_ua to load user_subtype. */
        if (get_unaligned_be16(&pvt_data->hdr.usr_subtype) !=
            BCMILCP_BCM_SUBTYPE_EVENT) {
-               BRCMF_ERROR(("%s: mismatched subtype, bailing\n", __func__));
+               brcmf_dbg(ERROR, "mismatched subtype, bailing\n");
                return -EBADE;
        }
 
@@ -775,27 +483,22 @@ brcmf_c_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
 
        switch (type) {
        case BRCMF_E_IF:
-               {
-                       struct brcmf_if_event *ifevent =
-                                       (struct brcmf_if_event *) event_data;
-                       BRCMF_TRACE(("%s: if event\n", __func__));
-
-                       if (ifevent->ifidx > 0 &&
-                                ifevent->ifidx < BRCMF_MAX_IFS) {
-                               if (ifevent->action == BRCMF_E_IF_ADD)
-                                       brcmf_add_if(drvr_priv, ifevent->ifidx,
-                                                  NULL, event->ifname,
-                                                  pvt_data->eth.h_dest,
-                                                  ifevent->flags,
-                                                  ifevent->bssidx);
-                               else
-                                       brcmf_del_if(drvr_priv, ifevent->ifidx);
-                       } else {
-                               BRCMF_ERROR(("%s: Invalid ifidx %d for %s\n",
-                                            __func__, ifevent->ifidx,
-                                            event->ifname));
-                       }
+               ifevent = (struct brcmf_if_event *) event_data;
+               brcmf_dbg(TRACE, "if event\n");
+
+               if (ifevent->ifidx > 0 && ifevent->ifidx < BRCMF_MAX_IFS) {
+                       if (ifevent->action == BRCMF_E_IF_ADD)
+                               brcmf_add_if(drvr_priv, ifevent->ifidx, NULL,
+                                            event->ifname,
+                                            pvt_data->eth.h_dest,
+                                            ifevent->flags, ifevent->bssidx);
+                       else
+                               brcmf_del_if(drvr_priv, ifevent->ifidx);
+               } else {
+                       brcmf_dbg(ERROR, "Invalid ifidx %d for %s\n",
+                                 ifevent->ifidx, event->ifname);
                }
+
                /* send up the if event: btamp user needs it */
                *ifidx = brcmf_ifname2idx(drvr_priv, event->ifname);
                break;
@@ -810,27 +513,28 @@ brcmf_c_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
                /* Fall through: this should get _everything_  */
 
                *ifidx = brcmf_ifname2idx(drvr_priv, event->ifname);
-               BRCMF_TRACE(("%s: MAC event %d, flags %x, status %x\n",
-                            __func__, type, flags, status));
+               brcmf_dbg(TRACE, "MAC event %d, flags %x, status %x\n",
+                         type, flags, status);
 
                /* put it back to BRCMF_E_NDIS_LINK */
                if (type == BRCMF_E_NDIS_LINK) {
-                       u32 temp;
+                       u32 temp1;
+                       __be32 temp2;
 
-                       temp = get_unaligned_be32(&event->event_type);
-                       BRCMF_TRACE(("Converted to WLC_E_LINK type %d\n",
-                                    temp));
+                       temp1 = get_unaligned_be32(&event->event_type);
+                       brcmf_dbg(TRACE, "Converted to WLC_E_LINK type %d\n",
+                                 temp1);
 
-                       temp = be32_to_cpu(BRCMF_E_NDIS_LINK);
-                       memcpy((void *)(&pvt_data->msg.event_type), &temp,
+                       temp2 = cpu_to_be32(BRCMF_E_NDIS_LINK);
+                       memcpy((void *)(&pvt_data->msg.event_type), &temp2,
                               sizeof(pvt_data->msg.event_type));
                }
                break;
        }
 
-#ifdef SHOW_EVENTS
+#ifdef BCMDBG
        brcmf_c_show_host_event(event, event_data);
-#endif                         /* SHOW_EVENTS */
+#endif                         /* BCMDBG */
 
        return 0;
 }
@@ -840,19 +544,22 @@ static int brcmf_c_pattern_atoh(char *src, char *dst)
 {
        int i;
        if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
-               BRCMF_ERROR(("Mask invalid format. Needs to start with 0x\n"));
-               return -1;
+               brcmf_dbg(ERROR, "Mask invalid format. Needs to start with 0x\n");
+               return -EINVAL;
        }
        src = src + 2;          /* Skip past 0x */
        if (strlen(src) % 2 != 0) {
-               BRCMF_ERROR(("Mask invalid format. Length must be even.\n"));
-               return -1;
+               brcmf_dbg(ERROR, "Mask invalid format. Length must be even.\n");
+               return -EINVAL;
        }
        for (i = 0; *src != '\0'; i++) {
+               unsigned long res;
                char num[3];
                strncpy(num, src, 2);
                num[2] = '\0';
-               dst[i] = (u8) simple_strtoul(num, NULL, 16);
+               if (kstrtoul(num, 16, &res))
+                       return -EINVAL;
+               dst[i] = (u8)res;
                src += 2;
        }
        return i;
@@ -862,22 +569,23 @@ void
 brcmf_c_pktfilter_offload_enable(struct brcmf_pub *drvr, char *arg, int enable,
                             int master_mode)
 {
+       unsigned long res;
        char *argv[8];
        int i = 0;
        const char *str;
        int buf_len;
        int str_len;
-       char *arg_save = 0, *arg_org = 0;
+       char *arg_save = NULL, *arg_org = NULL;
        int rc;
        char buf[128];
-       struct brcmf_pkt_filter_enable enable_parm;
-       struct brcmf_pkt_filter_enable *pkt_filterp;
+       struct brcmf_pkt_filter_enable_le enable_parm;
+       struct brcmf_pkt_filter_enable_le *pkt_filterp;
+       __le32 mmode_le;
 
        arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
-       if (!arg_save) {
-               BRCMF_ERROR(("%s: kmalloc failed\n", __func__));
+       if (!arg_save)
                goto fail;
-       }
+
        arg_org = arg_save;
        memcpy(arg_save, arg, strlen(arg) + 1);
 
@@ -885,7 +593,7 @@ brcmf_c_pktfilter_offload_enable(struct brcmf_pub *drvr, char *arg, int enable,
 
        i = 0;
        if (NULL == argv[i]) {
-               BRCMF_ERROR(("No args provided\n"));
+               brcmf_dbg(ERROR, "No args provided\n");
                goto fail;
        }
 
@@ -895,36 +603,38 @@ brcmf_c_pktfilter_offload_enable(struct brcmf_pub *drvr, char *arg, int enable,
        buf[str_len] = '\0';
        buf_len = str_len + 1;
 
-       pkt_filterp = (struct brcmf_pkt_filter_enable *) (buf + str_len + 1);
+       pkt_filterp = (struct brcmf_pkt_filter_enable_le *) (buf + str_len + 1);
 
        /* Parse packet filter id. */
-       enable_parm.id = simple_strtoul(argv[i], NULL, 0);
+       enable_parm.id = 0;
+       if (!kstrtoul(argv[i], 0, &res))
+               enable_parm.id = cpu_to_le32((u32)res);
 
        /* Parse enable/disable value. */
-       enable_parm.enable = enable;
+       enable_parm.enable = cpu_to_le32(enable);
 
        buf_len += sizeof(enable_parm);
        memcpy((char *)pkt_filterp, &enable_parm, sizeof(enable_parm));
 
        /* Enable/disable the specified filter. */
-       rc = brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len);
+       rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len);
        rc = rc >= 0 ? 0 : rc;
        if (rc)
-               BRCMF_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
-                            __func__, arg, rc));
+               brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n",
+                         arg, rc);
        else
-               BRCMF_TRACE(("%s: successfully added pktfilter %s\n",
-                            __func__, arg));
+               brcmf_dbg(TRACE, "successfully added pktfilter %s\n", arg);
 
        /* Contorl the master mode */
-       brcmu_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf,
+       mmode_le = cpu_to_le32(master_mode);
+       brcmf_c_mkiovar("pkt_filter_mode", (char *)&mmode_le, 4, buf,
                    sizeof(buf));
-       rc = brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, buf,
+       rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf,
                                       sizeof(buf));
        rc = rc >= 0 ? 0 : rc;
        if (rc)
-               BRCMF_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
-                            __func__, arg, rc));
+               brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n",
+                         arg, rc);
 
 fail:
        kfree(arg_org);
@@ -933,32 +643,27 @@ fail:
 void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg)
 {
        const char *str;
-       struct brcmf_pkt_filter pkt_filter;
-       struct brcmf_pkt_filter *pkt_filterp;
+       struct brcmf_pkt_filter_le pkt_filter;
+       struct brcmf_pkt_filter_le *pkt_filterp;
+       unsigned long res;
        int buf_len;
        int str_len;
        int rc;
        u32 mask_size;
        u32 pattern_size;
-       char *argv[8], *buf = 0;
+       char *argv[8], *buf = NULL;
        int i = 0;
-       char *arg_save = 0, *arg_org = 0;
+       char *arg_save = NULL, *arg_org = NULL;
 
-       arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
-       if (!arg_save) {
-               BRCMF_ERROR(("%s: kmalloc failed\n", __func__));
+       arg_save = kstrdup(arg, GFP_ATOMIC);
+       if (!arg_save)
                goto fail;
-       }
 
        arg_org = arg_save;
 
        buf = kmalloc(PKTFILTER_BUF_SIZE, GFP_ATOMIC);
-       if (!buf) {
-               BRCMF_ERROR(("%s: kmalloc failed\n", __func__));
+       if (!buf)
                goto fail;
-       }
-
-       strcpy(arg_save, arg);
 
        argv[i] = strsep(&arg_save, " ");
        while (argv[i++])
@@ -966,7 +671,7 @@ void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg)
 
        i = 0;
        if (NULL == argv[i]) {
-               BRCMF_ERROR(("No args provided\n"));
+               brcmf_dbg(ERROR, "No args provided\n");
                goto fail;
        }
 
@@ -975,37 +680,45 @@ void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg)
        str_len = strlen(str);
        buf_len = str_len + 1;
 
-       pkt_filterp = (struct brcmf_pkt_filter *) (buf + str_len + 1);
+       pkt_filterp = (struct brcmf_pkt_filter_le *) (buf + str_len + 1);
 
        /* Parse packet filter id. */
-       pkt_filter.id = simple_strtoul(argv[i], NULL, 0);
+       pkt_filter.id = 0;
+       if (!kstrtoul(argv[i], 0, &res))
+               pkt_filter.id = cpu_to_le32((u32)res);
 
        if (NULL == argv[++i]) {
-               BRCMF_ERROR(("Polarity not provided\n"));
+               brcmf_dbg(ERROR, "Polarity not provided\n");
                goto fail;
        }
 
        /* Parse filter polarity. */
-       pkt_filter.negate_match = simple_strtoul(argv[i], NULL, 0);
+       pkt_filter.negate_match = 0;
+       if (!kstrtoul(argv[i], 0, &res))
+               pkt_filter.negate_match = cpu_to_le32((u32)res);
 
        if (NULL == argv[++i]) {
-               BRCMF_ERROR(("Filter type not provided\n"));
+               brcmf_dbg(ERROR, "Filter type not provided\n");
                goto fail;
        }
 
        /* Parse filter type. */
-       pkt_filter.type = simple_strtoul(argv[i], NULL, 0);
+       pkt_filter.type = 0;
+       if (!kstrtoul(argv[i], 0, &res))
+               pkt_filter.type = cpu_to_le32((u32)res);
 
        if (NULL == argv[++i]) {
-               BRCMF_ERROR(("Offset not provided\n"));
+               brcmf_dbg(ERROR, "Offset not provided\n");
                goto fail;
        }
 
        /* Parse pattern filter offset. */
-       pkt_filter.u.pattern.offset = simple_strtoul(argv[i], NULL, 0);
+       pkt_filter.u.pattern.offset = 0;
+       if (!kstrtoul(argv[i], 0, &res))
+               pkt_filter.u.pattern.offset = cpu_to_le32((u32)res);
 
        if (NULL == argv[++i]) {
-               BRCMF_ERROR(("Bitmask not provided\n"));
+               brcmf_dbg(ERROR, "Bitmask not provided\n");
                goto fail;
        }
 
@@ -1015,7 +728,7 @@ void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg)
                   (argv[i], (char *)pkt_filterp->u.pattern.mask_and_pattern);
 
        if (NULL == argv[++i]) {
-               BRCMF_ERROR(("Pattern not provided\n"));
+               brcmf_dbg(ERROR, "Pattern not provided\n");
                goto fail;
        }
 
@@ -1026,11 +739,11 @@ void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg)
                                   mask_and_pattern[mask_size]);
 
        if (mask_size != pattern_size) {
-               BRCMF_ERROR(("Mask and pattern not the same size\n"));
+               brcmf_dbg(ERROR, "Mask and pattern not the same size\n");
                goto fail;
        }
 
-       pkt_filter.u.pattern.size_bytes = mask_size;
+       pkt_filter.u.pattern.size_bytes = cpu_to_le32(mask_size);
        buf_len += BRCMF_PKT_FILTER_FIXED_LEN;
        buf_len += (BRCMF_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
 
@@ -1043,15 +756,14 @@ void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg)
               &pkt_filter,
               BRCMF_PKT_FILTER_FIXED_LEN + BRCMF_PKT_FILTER_PATTERN_FIXED_LEN);
 
-       rc = brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len);
+       rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len);
        rc = rc >= 0 ? 0 : rc;
 
        if (rc)
-               BRCMF_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
-                            __func__, arg, rc));
+               brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n",
+                         arg, rc);
        else
-               BRCMF_TRACE(("%s: successfully added pktfilter %s\n",
-                            __func__, arg));
+               brcmf_dbg(TRACE, "successfully added pktfilter %s\n", arg);
 
 fail:
        kfree(arg_org);
@@ -1059,49 +771,50 @@ fail:
        kfree(buf);
 }
 
-void brcmf_c_arp_offload_set(struct brcmf_pub *drvr, int arp_mode)
+static void brcmf_c_arp_offload_set(struct brcmf_pub *drvr, int arp_mode)
 {
        char iovbuf[32];
        int retcode;
 
-       brcmu_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
-       retcode = brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR,
+       brcmf_c_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
+       retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR,
                                   iovbuf, sizeof(iovbuf));
        retcode = retcode >= 0 ? 0 : retcode;
        if (retcode)
-               BRCMF_TRACE(("%s: failed to set ARP offload mode to 0x%x, "
-                            "retcode = %d\n", __func__, arp_mode, retcode));
+               brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, retcode = %d\n",
+                         arp_mode, retcode);
        else
-               BRCMF_TRACE(("%s: successfully set ARP offload mode to 0x%x\n",
-                            __func__, arp_mode));
+               brcmf_dbg(TRACE, "successfully set ARP offload mode to 0x%x\n",
+                         arp_mode);
 }
 
-void brcmf_c_arp_offload_enable(struct brcmf_pub *drvr, int arp_enable)
+static void brcmf_c_arp_offload_enable(struct brcmf_pub *drvr, int arp_enable)
 {
        char iovbuf[32];
        int retcode;
 
-       brcmu_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf));
-       retcode = brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR,
+       brcmf_c_mkiovar("arpoe", (char *)&arp_enable, 4,
+                       iovbuf, sizeof(iovbuf));
+       retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR,
                                   iovbuf, sizeof(iovbuf));
        retcode = retcode >= 0 ? 0 : retcode;
        if (retcode)
-               BRCMF_TRACE(("%s: failed to enabe ARP offload to %d, "
-                            "retcode = %d\n", __func__, arp_enable, retcode));
+               brcmf_dbg(TRACE, "failed to enable ARP offload to %d, retcode = %d\n",
+                         arp_enable, retcode);
        else
-               BRCMF_TRACE(("%s: successfully enabed ARP offload to %d\n",
-                            __func__, arp_enable));
+               brcmf_dbg(TRACE, "successfully enabled ARP offload to %d\n",
+                         arp_enable);
 }
 
-int brcmf_c_preinit_ioctls(struct brcmf_pub *drvr)
+int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr)
 {
        char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];      /*  Room for
                                 "event_msgs" + '\0' + bitvec  */
        uint up = 0;
        char buf[128], *ptr;
-       uint power_mode = PM_FAST;
        u32 dongle_align = BRCMF_SDALIGN;
        u32 glom = 0;
+       u32 roaming = 1;
        uint bcn_timeout = 3;
        int scan_assoc_time = 40;
        int scan_unassoc_time = 40;
@@ -1111,83 +824,69 @@ int brcmf_c_preinit_ioctls(struct brcmf_pub *drvr)
 
        /* Set Country code */
        if (drvr->country_code[0] != 0) {
-               if (brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_COUNTRY,
-                                    drvr->country_code,
-                                    sizeof(drvr->country_code)) < 0) {
-                       BRCMF_ERROR(("%s: country code setting failed\n",
-                                    __func__));
-               }
+               if (brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_COUNTRY,
+                                             drvr->country_code,
+                                             sizeof(drvr->country_code)) < 0)
+                       brcmf_dbg(ERROR, "country code setting failed\n");
        }
 
        /* query for 'ver' to get version info from firmware */
        memset(buf, 0, sizeof(buf));
        ptr = buf;
-       brcmu_mkiovar("ver", 0, 0, buf, sizeof(buf));
-       brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR, buf, sizeof(buf));
+       brcmf_c_mkiovar("ver", NULL, 0, buf, sizeof(buf));
+       brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, buf, sizeof(buf));
        strsep(&ptr, "\n");
        /* Print fw version info */
-       BRCMF_ERROR(("Firmware version = %s\n", buf));
-
-       /* Set PowerSave mode */
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_PM, (char *)&power_mode,
-                        sizeof(power_mode));
+       brcmf_dbg(ERROR, "Firmware version = %s\n", buf);
 
        /* Match Host and Dongle rx alignment */
-       brcmu_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
+       brcmf_c_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
                    sizeof(iovbuf));
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
                                  sizeof(iovbuf));
 
        /* disable glom option per default */
-       brcmu_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
+       brcmf_c_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
                                  sizeof(iovbuf));
 
        /* Setup timeout if Beacons are lost and roam is off to report
                 link down */
-       brcmu_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf,
+       brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf,
                    sizeof(iovbuf));
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
                                  sizeof(iovbuf));
 
        /* Enable/Disable build-in roaming to allowed ext supplicant to take
                 of romaing */
-       brcmu_mkiovar("roam_off", (char *)&brcmf_roam, 4,
+       brcmf_c_mkiovar("roam_off", (char *)&roaming, 4,
                      iovbuf, sizeof(iovbuf));
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
                                  sizeof(iovbuf));
 
        /* Force STA UP */
-       if (brcmf_radio_up)
-               brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_UP, (char *)&up,
-                                         sizeof(up));
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_UP, (char *)&up, sizeof(up));
 
        /* Setup event_msgs */
-       brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
+       brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
                      iovbuf, sizeof(iovbuf));
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
                                  sizeof(iovbuf));
 
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_SCAN_CHANNEL_TIME,
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_CHANNEL_TIME,
                         (char *)&scan_assoc_time, sizeof(scan_assoc_time));
-       brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_SCAN_UNASSOC_TIME,
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_UNASSOC_TIME,
                         (char *)&scan_unassoc_time, sizeof(scan_unassoc_time));
 
        /* Set and enable ARP offload feature */
-       if (brcmf_arp_enable)
-               brcmf_c_arp_offload_set(drvr, brcmf_arp_mode);
-       brcmf_c_arp_offload_enable(drvr, brcmf_arp_enable);
+       brcmf_c_arp_offload_set(drvr, BRCMF_ARPOL_MODE);
+       brcmf_c_arp_offload_enable(drvr, true);
 
        /* Set up pkt filter */
-       if (brcmf_pkt_filter_enable) {
-               for (i = 0; i < drvr->pktfilter_count; i++) {
-                       brcmf_c_pktfilter_offload_set(drvr,
-                                                 drvr->pktfilter[i]);
-                       brcmf_c_pktfilter_offload_enable(drvr,
-                            drvr->pktfilter[i],
-                            brcmf_pkt_filter_init,
-                            brcmf_master_mode);
-               }
+       for (i = 0; i < drvr->pktfilter_count; i++) {
+               brcmf_c_pktfilter_offload_set(drvr, drvr->pktfilter[i]);
+               brcmf_c_pktfilter_offload_enable(drvr, drvr->pktfilter[i],
+                                                0, true);
        }
 
        brcmf_os_proto_unblock(drvr);
index 5be4d7a..7467922 100644 (file)
 
 #if defined(BCMDBG)
 
-#define BRCMF_ERROR(args) \
-       do {if ((brcmf_msg_level & BRCMF_ERROR_VAL) && (net_ratelimit())) \
-               printk args; } while (0)
-#define BRCMF_TRACE(args)      do {if (brcmf_msg_level & BRCMF_TRACE_VAL) \
-                                       printk args; } while (0)
-#define BRCMF_INFO(args)       do {if (brcmf_msg_level & BRCMF_INFO_VAL) \
-                                       printk args; } while (0)
-#define BRCMF_DATA(args)       do {if (brcmf_msg_level & BRCMF_DATA_VAL) \
-                                       printk args; } while (0)
-#define BRCMF_CTL(args)                do {if (brcmf_msg_level & BRCMF_CTL_VAL) \
-                                       printk args; } while (0)
-#define BRCMF_TIMER(args)      do {if (brcmf_msg_level & BRCMF_TIMER_VAL) \
-                                       printk args; } while (0)
-#define BRCMF_INTR(args)       do {if (brcmf_msg_level & BRCMF_INTR_VAL) \
-                                       printk args; } while (0)
-#define BRCMF_GLOM(args)       do {if (brcmf_msg_level & BRCMF_GLOM_VAL) \
-                                       printk args; } while (0)
-#define BRCMF_EVENT(args)      do {if (brcmf_msg_level & BRCMF_EVENT_VAL) \
-                                       printk args; } while (0)
+#define brcmf_dbg(level, fmt, ...)                                     \
+do {                                                                   \
+       if (BRCMF_ERROR_VAL == BRCMF_##level##_VAL) {                   \
+               if (brcmf_msg_level & BRCMF_##level##_VAL) {            \
+                       if (net_ratelimit())                            \
+                               printk(KERN_DEBUG "%s: " fmt,           \
+                                      __func__, ##__VA_ARGS__);        \
+               }                                                       \
+       } else {                                                        \
+               if (brcmf_msg_level & BRCMF_##level##_VAL) {            \
+                       printk(KERN_DEBUG "%s: " fmt,                   \
+                              __func__, ##__VA_ARGS__);                \
+               }                                                       \
+       }                                                               \
+} while (0)
 
 #define BRCMF_DATA_ON()                (brcmf_msg_level & BRCMF_DATA_VAL)
 #define BRCMF_CTL_ON()         (brcmf_msg_level & BRCMF_CTL_VAL)
 
 #else  /* (defined BCMDBG) || (defined BCMDBG) */
 
-#define BRCMF_ERROR(args)  do {if (net_ratelimit()) printk args; } while (0)
-#define BRCMF_TRACE(args)
-#define BRCMF_INFO(args)
-#define BRCMF_DATA(args)
-#define BRCMF_CTL(args)
-#define BRCMF_TIMER(args)
-#define BRCMF_INTR(args)
-#define BRCMF_GLOM(args)
-#define BRCMF_EVENT(args)
+#define brcmf_dbg(level, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
 
 #define BRCMF_DATA_ON()                0
 #define BRCMF_CTL_ON()         0
 #define BRCMF_HDRS_ON()                0
-#define BRCMF_BYTES_ON()               0
+#define BRCMF_BYTES_ON()       0
 #define BRCMF_GLOM_ON()                0
 
 #endif                         /* defined(BCMDBG) */
index 05dada9..4acbac5 100644 (file)
 #include <linux/fcntl.h>
 #include <linux/fs.h>
 #include <linux/uaccess.h>
-#include <linux/interrupt.h>
 #include <linux/hardirq.h>
+#include <linux/mutex.h>
+#include <linux/wait.h>
+#include <linux/module.h>
 #include <net/cfg80211.h>
+#include <net/rtnetlink.h>
 #include <defs.h>
 #include <brcmu_utils.h>
 #include <brcmu_wifi.h>
 #include "wl_cfg80211.h"
 #include "bcmchip.h"
 
-#if defined(CONFIG_PM_SLEEP)
-#include <linux/suspend.h>
-atomic_t brcmf_mmc_suspend;
-#endif /*  defined(CONFIG_PM_SLEEP) */
-
 MODULE_AUTHOR("Broadcom Corporation");
 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
@@ -57,15 +55,11 @@ MODULE_LICENSE("Dual BSD/GPL");
 struct brcmf_if {
        struct brcmf_info *info;        /* back pointer to brcmf_info */
        /* OS/stack specifics */
-       struct net_device *net;
+       struct net_device *ndev;
        struct net_device_stats stats;
        int idx;                /* iface idx in dongle */
        int state;              /* interface state */
-       uint subunit;           /* subunit */
        u8 mac_addr[ETH_ALEN];  /* assigned MAC address */
-       bool attached;          /* Delayed attachment when unset */
-       bool txflowcontrol;     /* Per interface flow control indicator */
-       char name[IFNAMSIZ];    /* linux interface name */
 };
 
 /* Local private structure (extension of pub) */
@@ -75,14 +69,10 @@ struct brcmf_info {
        /* OS/stack specifics */
        struct brcmf_if *iflist[BRCMF_MAX_IFS];
 
-       struct semaphore proto_sem;
-       wait_queue_head_t ioctl_resp_wait;
+       struct mutex proto_block;
 
-       /* Thread to issue ioctl for multicast */
-       struct task_struct *sysioc_tsk;
-       struct semaphore sysioc_sem;
-       bool set_multicast;
-       bool set_macaddress;
+       struct work_struct setmacaddr_work;
+       struct work_struct multicast_work;
        u8 macvalue[ETH_ALEN];
        atomic_t pend_8021x_cnt;
 };
@@ -90,148 +80,13 @@ struct brcmf_info {
 /* Error bits */
 module_param(brcmf_msg_level, int, 0);
 
-/* Spawn a thread for system ioctls (set mac, set mcast) */
-uint brcmf_sysioc = true;
-module_param(brcmf_sysioc, uint, 0);
-
-/* ARP offload agent mode : Enable ARP Host Auto-Reply
-and ARP Peer Auto-Reply */
-uint brcmf_arp_mode = 0xb;
-module_param(brcmf_arp_mode, uint, 0);
-
-/* ARP offload enable */
-uint brcmf_arp_enable = true;
-module_param(brcmf_arp_enable, uint, 0);
-
-/* Global Pkt filter enable control */
-uint brcmf_pkt_filter_enable = true;
-module_param(brcmf_pkt_filter_enable, uint, 0);
-
-/*  Pkt filter init setup */
-uint brcmf_pkt_filter_init;
-module_param(brcmf_pkt_filter_init, uint, 0);
-
-/* Pkt filter mode control */
-uint brcmf_master_mode = true;
-module_param(brcmf_master_mode, uint, 0);
-
-module_param(brcmf_dongle_memsize, int, 0);
-
-/* Contorl fw roaming */
-uint brcmf_roam = 1;
-
-/* Control radio state */
-uint brcmf_radio_up = 1;
-
-/* Network inteface name */
-char iface_name[IFNAMSIZ] = "wlan";
-module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
-
-/* The following are specific to the SDIO dongle */
-
-/* IOCTL response timeout */
-int brcmf_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
-
-/* Idle timeout for backplane clock */
-int brcmf_idletime = BRCMF_IDLETIME_TICKS;
-module_param(brcmf_idletime, int, 0);
-
-/* Use polling */
-uint brcmf_poll;
-module_param(brcmf_poll, uint, 0);
 
-/* Use interrupts */
-uint brcmf_intr = true;
-module_param(brcmf_intr, uint, 0);
-
-/* SDIO Drive Strength (in milliamps) */
-uint brcmf_sdiod_drive_strength = 6;
-module_param(brcmf_sdiod_drive_strength, uint, 0);
-
-/* Tx/Rx bounds */
-module_param(brcmf_txbound, uint, 0);
-module_param(brcmf_rxbound, uint, 0);
-
-#ifdef SDTEST
-/* Echo packet generator (pkts/s) */
-uint brcmf_pktgen;
-module_param(brcmf_pktgen, uint, 0);
-
-/* Echo packet len (0 => sawtooth, max 2040) */
-uint brcmf_pktgen_len;
-module_param(brcmf_pktgen_len, uint, 0);
-#endif
-
-static int brcmf_toe_get(struct brcmf_info *drvr_priv, int idx, u32 *toe_ol);
-static int brcmf_toe_set(struct brcmf_info *drvr_priv, int idx, u32 toe_ol);
-static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
-                           struct brcmf_event_msg *event_ptr,
-                           void **data_ptr);
-
-/*
- * Generalized timeout mechanism.  Uses spin sleep with exponential
- * back-off until
- * the sleep time reaches one jiffy, then switches over to task delay.  Usage:
- *
- *      brcmf_timeout_start(&tmo, usec);
- *      while (!brcmf_timeout_expired(&tmo))
- *              if (poll_something())
- *                      break;
- *      if (brcmf_timeout_expired(&tmo))
- *              fatal();
- */
-
-void brcmf_timeout_start(struct brcmf_timeout *tmo, uint usec)
-{
-       tmo->limit = usec;
-       tmo->increment = 0;
-       tmo->elapsed = 0;
-       tmo->tick = 1000000 / HZ;
-}
-
-int brcmf_timeout_expired(struct brcmf_timeout *tmo)
-{
-       /* Does nothing the first call */
-       if (tmo->increment == 0) {
-               tmo->increment = 1;
-               return 0;
-       }
-
-       if (tmo->elapsed >= tmo->limit)
-               return 1;
-
-       /* Add the delay that's about to take place */
-       tmo->elapsed += tmo->increment;
-
-       if (tmo->increment < tmo->tick) {
-               udelay(tmo->increment);
-               tmo->increment *= 2;
-               if (tmo->increment > tmo->tick)
-                       tmo->increment = tmo->tick;
-       } else {
-               wait_queue_head_t delay_wait;
-               DECLARE_WAITQUEUE(wait, current);
-               int pending;
-               init_waitqueue_head(&delay_wait);
-               add_wait_queue(&delay_wait, &wait);
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(1);
-               pending = signal_pending(current);
-               remove_wait_queue(&delay_wait, &wait);
-               set_current_state(TASK_RUNNING);
-               if (pending)
-                       return 1;       /* Interrupted */
-       }
-
-       return 0;
-}
-
-static int brcmf_net2idx(struct brcmf_info *drvr_priv, struct net_device *net)
+static int brcmf_net2idx(struct brcmf_info *drvr_priv, struct net_device *ndev)
 {
        int i = 0;
 
        while (i < BRCMF_MAX_IFS) {
-               if (drvr_priv->iflist[i] && (drvr_priv->iflist[i]->net == net))
+               if (drvr_priv->iflist[i] && drvr_priv->iflist[i]->ndev == ndev)
                        return i;
                i++;
        }
@@ -242,16 +97,18 @@ static int brcmf_net2idx(struct brcmf_info *drvr_priv, struct net_device *net)
 int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name)
 {
        int i = BRCMF_MAX_IFS;
+       struct brcmf_if *ifp;
 
        if (name == NULL || *name == '\0')
                return 0;
 
-       while (--i > 0)
-               if (drvr_priv->iflist[i]
-                   && !strncmp(drvr_priv->iflist[i]->name, name, IFNAMSIZ))
+       while (--i > 0) {
+               ifp = drvr_priv->iflist[i];
+               if (ifp && !strncmp(ifp->ndev->name, name, IFNAMSIZ))
                        break;
+       }
 
-       BRCMF_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
+       brcmf_dbg(TRACE, "return idx %d for \"%s\"\n", i, name);
 
        return i;               /* default - the primary interface */
 }
@@ -261,56 +118,58 @@ char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
        struct brcmf_info *drvr_priv = drvr->info;
 
        if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
-               BRCMF_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
+               brcmf_dbg(ERROR, "ifidx %d out of range\n", ifidx);
                return "<if_bad>";
        }
 
        if (drvr_priv->iflist[ifidx] == NULL) {
-               BRCMF_ERROR(("%s: null i/f %d\n", __func__, ifidx));
+               brcmf_dbg(ERROR, "null i/f %d\n", ifidx);
                return "<if_null>";
        }
 
-       if (drvr_priv->iflist[ifidx]->net)
-               return drvr_priv->iflist[ifidx]->net->name;
+       if (drvr_priv->iflist[ifidx]->ndev)
+               return drvr_priv->iflist[ifidx]->ndev->name;
 
        return "<if_none>";
 }
 
-static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx)
+static void _brcmf_set_multicast_list(struct work_struct *work)
 {
-       struct net_device *dev;
+       struct net_device *ndev;
        struct netdev_hw_addr *ha;
-       u32 allmulti, cnt;
+       u32 dcmd_value, cnt;
+       __le32 cnt_le;
+       __le32 dcmd_le_value;
 
-       struct brcmf_ioctl ioc;
+       struct brcmf_dcmd dcmd;
        char *buf, *bufp;
        uint buflen;
        int ret;
 
-       dev = drvr_priv->iflist[ifidx]->net;
-       cnt = netdev_mc_count(dev);
+       struct brcmf_info *drvr_priv = container_of(work, struct brcmf_info,
+                                                   multicast_work);
+
+       ndev = drvr_priv->iflist[0]->ndev;
+       cnt = netdev_mc_count(ndev);
 
        /* Determine initial value of allmulti flag */
-       allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
+       dcmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false;
 
        /* Send down the multicast list first. */
 
        buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
        bufp = buf = kmalloc(buflen, GFP_ATOMIC);
-       if (!bufp) {
-               BRCMF_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
+       if (!bufp)
                return;
-       }
 
        strcpy(bufp, "mcast_list");
        bufp += strlen("mcast_list") + 1;
 
-       cnt = cpu_to_le32(cnt);
-       memcpy(bufp, &cnt, sizeof(cnt));
-       bufp += sizeof(cnt);
+       cnt_le = cpu_to_le32(cnt);
+       memcpy(bufp, &cnt_le, sizeof(cnt));
+       bufp += sizeof(cnt_le);
 
-       netdev_for_each_mc_addr(ha, dev) {
+       netdev_for_each_mc_addr(ha, ndev) {
                if (!cnt)
                        break;
                memcpy(bufp, ha->addr, ETH_ALEN);
@@ -318,17 +177,17 @@ static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx)
                cnt--;
        }
 
-       memset(&ioc, 0, sizeof(ioc));
-       ioc.cmd = BRCMF_C_SET_VAR;
-       ioc.buf = buf;
-       ioc.len = buflen;
-       ioc.set = true;
+       memset(&dcmd, 0, sizeof(dcmd));
+       dcmd.cmd = BRCMF_C_SET_VAR;
+       dcmd.buf = buf;
+       dcmd.len = buflen;
+       dcmd.set = true;
 
-       ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
+       ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
        if (ret < 0) {
-               BRCMF_ERROR(("%s: set mcast_list failed, cnt %d\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
-               allmulti = cnt ? true : allmulti;
+               brcmf_dbg(ERROR, "%s: set mcast_list failed, cnt %d\n",
+                         brcmf_ifname(&drvr_priv->pub, 0), cnt);
+               dcmd_value = cnt ? true : dcmd_value;
        }
 
        kfree(buf);
@@ -338,36 +197,34 @@ static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx)
         * were trying to set some addresses and dongle rejected it...
         */
 
-       buflen = sizeof("allmulti") + sizeof(allmulti);
+       buflen = sizeof("allmulti") + sizeof(dcmd_value);
        buf = kmalloc(buflen, GFP_ATOMIC);
-       if (!buf) {
-               BRCMF_ERROR(("%s: out of memory for allmulti\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx)));
+       if (!buf)
                return;
-       }
-       allmulti = cpu_to_le32(allmulti);
-
-       if (!brcmu_mkiovar
-           ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
-               BRCMF_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
-                            "buflen %u\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx),
-                            (int)sizeof(allmulti), buflen));
+
+       dcmd_le_value = cpu_to_le32(dcmd_value);
+
+       if (!brcmf_c_mkiovar
+           ("allmulti", (void *)&dcmd_le_value,
+           sizeof(dcmd_le_value), buf, buflen)) {
+               brcmf_dbg(ERROR, "%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
+                         brcmf_ifname(&drvr_priv->pub, 0),
+                         (int)sizeof(dcmd_value), buflen);
                kfree(buf);
                return;
        }
 
-       memset(&ioc, 0, sizeof(ioc));
-       ioc.cmd = BRCMF_C_SET_VAR;
-       ioc.buf = buf;
-       ioc.len = buflen;
-       ioc.set = true;
+       memset(&dcmd, 0, sizeof(dcmd));
+       dcmd.cmd = BRCMF_C_SET_VAR;
+       dcmd.buf = buf;
+       dcmd.len = buflen;
+       dcmd.set = true;
 
-       ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
+       ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
        if (ret < 0) {
-               BRCMF_ERROR(("%s: set allmulti %d failed\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx),
-                            le32_to_cpu(allmulti)));
+               brcmf_dbg(ERROR, "%s: set allmulti %d failed\n",
+                         brcmf_ifname(&drvr_priv->pub, 0),
+                         le32_to_cpu(dcmd_le_value));
        }
 
        kfree(buf);
@@ -375,237 +232,84 @@ static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx)
        /* Finally, pick up the PROMISC flag as well, like the NIC
                 driver does */
 
-       allmulti = (dev->flags & IFF_PROMISC) ? true : false;
-       allmulti = cpu_to_le32(allmulti);
+       dcmd_value = (ndev->flags & IFF_PROMISC) ? true : false;
+       dcmd_le_value = cpu_to_le32(dcmd_value);
 
-       memset(&ioc, 0, sizeof(ioc));
-       ioc.cmd = BRCMF_C_SET_PROMISC;
-       ioc.buf = &allmulti;
-       ioc.len = sizeof(allmulti);
-       ioc.set = true;
+       memset(&dcmd, 0, sizeof(dcmd));
+       dcmd.cmd = BRCMF_C_SET_PROMISC;
+       dcmd.buf = &dcmd_le_value;
+       dcmd.len = sizeof(dcmd_le_value);
+       dcmd.set = true;
 
-       ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
+       ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
        if (ret < 0) {
-               BRCMF_ERROR(("%s: set promisc %d failed\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx),
-                            le32_to_cpu(allmulti)));
+               brcmf_dbg(ERROR, "%s: set promisc %d failed\n",
+                         brcmf_ifname(&drvr_priv->pub, 0),
+                         le32_to_cpu(dcmd_le_value));
        }
 }
 
-static int _brcmf_set_mac_address(struct brcmf_info *drvr_priv, int ifidx, u8 *addr)
+static void
+_brcmf_set_mac_address(struct work_struct *work)
 {
        char buf[32];
-       struct brcmf_ioctl ioc;
+       struct brcmf_dcmd dcmd;
        int ret;
 
-       BRCMF_TRACE(("%s enter\n", __func__));
-       if (!brcmu_mkiovar
-           ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
-               BRCMF_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx)));
-               return -1;
-       }
-       memset(&ioc, 0, sizeof(ioc));
-       ioc.cmd = BRCMF_C_SET_VAR;
-       ioc.buf = buf;
-       ioc.len = 32;
-       ioc.set = true;
-
-       ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
-       if (ret < 0) {
-               BRCMF_ERROR(("%s: set cur_etheraddr failed\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx)));
-       } else {
-               memcpy(drvr_priv->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
-       }
-
-       return ret;
-}
-
-#ifdef SOFTAP
-extern struct net_device *ap_net_dev;
-#endif
-
-/* Virtual interfaces only ((ifp && ifp->info && ifp->idx == true) */
-static void brcmf_op_if(struct brcmf_if *ifp)
-{
-       struct brcmf_info *drvr_priv;
-       int ret = 0, err = 0;
-
-       drvr_priv = ifp->info;
-
-       BRCMF_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
-
-       switch (ifp->state) {
-       case BRCMF_E_IF_ADD:
-               /*
-                * Delete the existing interface before overwriting it
-                * in case we missed the BRCMF_E_IF_DEL event.
-                */
-               if (ifp->net != NULL) {
-                       BRCMF_ERROR(("%s: ERROR: netdev:%s already exists, "
-                                    "try free & unregister\n",
-                                    __func__, ifp->net->name));
-                       netif_stop_queue(ifp->net);
-                       unregister_netdev(ifp->net);
-                       free_netdev(ifp->net);
-               }
-               /* Allocate etherdev, including space for private structure */
-               ifp->net = alloc_etherdev(sizeof(drvr_priv));
-               if (!ifp->net) {
-                       BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
-                       ret = -ENOMEM;
-               }
-               if (ret == 0) {
-                       strcpy(ifp->net->name, ifp->name);
-                       memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv));
-                       err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
-                       if (err != 0) {
-                               BRCMF_ERROR(("%s: brcmf_net_attach failed, "
-                                            "err %d\n",
-                                            __func__, err));
-                               ret = -EOPNOTSUPP;
-                       } else {
-#ifdef SOFTAP
-                               /* semaphore that the soft AP CODE
-                                        waits on */
-                               extern struct semaphore ap_eth_sema;
-
-                               /* save ptr to wl0.1 netdev for use
-                                        in wl_iw.c  */
-                               ap_net_dev = ifp->net;
-                               /* signal to the SOFTAP 'sleeper' thread,
-                                        wl0.1 is ready */
-                               up(&ap_eth_sema);
-#endif
-                               BRCMF_TRACE(("\n ==== pid:%x, net_device for "
-                                            "if:%s created ===\n\n",
-                                            current->pid, ifp->net->name));
-                               ifp->state = 0;
-                       }
-               }
-               break;
-       case BRCMF_E_IF_DEL:
-               if (ifp->net != NULL) {
-                       BRCMF_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
-                                    __func__));
-                       netif_stop_queue(ifp->net);
-                       unregister_netdev(ifp->net);
-                       ret = BRCMF_DEL_IF;     /* Make sure the free_netdev()
-                                                        is called */
-               }
-               break;
-       default:
-               BRCMF_ERROR(("%s: bad op %d\n", __func__, ifp->state));
-               break;
-       }
+       struct brcmf_info *drvr_priv = container_of(work, struct brcmf_info,
+                                                   setmacaddr_work);
 
-       if (ret < 0) {
-               if (ifp->net)
-                       free_netdev(ifp->net);
-
-               drvr_priv->iflist[ifp->idx] = NULL;
-               kfree(ifp);
-#ifdef SOFTAP
-               if (ifp->net == ap_net_dev)
-                       ap_net_dev = NULL;      /*  NULL  SOFTAP global
-                                                        wl0.1 as well */
-#endif                         /*  SOFTAP */
+       brcmf_dbg(TRACE, "enter\n");
+       if (!brcmf_c_mkiovar("cur_etheraddr", (char *)drvr_priv->macvalue,
+                          ETH_ALEN, buf, 32)) {
+               brcmf_dbg(ERROR, "%s: mkiovar failed for cur_etheraddr\n",
+                         brcmf_ifname(&drvr_priv->pub, 0));
+               return;
        }
-}
-
-static int _brcmf_sysioc_thread(void *data)
-{
-       struct brcmf_info *drvr_priv = (struct brcmf_info *) data;
-       int i;
-#ifdef SOFTAP
-       bool in_ap = false;
-#endif
+       memset(&dcmd, 0, sizeof(dcmd));
+       dcmd.cmd = BRCMF_C_SET_VAR;
+       dcmd.buf = buf;
+       dcmd.len = 32;
+       dcmd.set = true;
 
-       allow_signal(SIGTERM);
+       ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
+       if (ret < 0)
+               brcmf_dbg(ERROR, "%s: set cur_etheraddr failed\n",
+                         brcmf_ifname(&drvr_priv->pub, 0));
+       else
+               memcpy(drvr_priv->iflist[0]->ndev->dev_addr,
+                      drvr_priv->macvalue, ETH_ALEN);
 
-       while (down_interruptible(&drvr_priv->sysioc_sem) == 0) {
-               if (kthread_should_stop())
-                       break;
-               for (i = 0; i < BRCMF_MAX_IFS; i++) {
-                       struct brcmf_if *ifentry = drvr_priv->iflist[i];
-                       if (ifentry) {
-#ifdef SOFTAP
-                               in_ap = (ap_net_dev != NULL);
-#endif                         /* SOFTAP */
-                               if (ifentry->state)
-                                       brcmf_op_if(ifentry);
-#ifdef SOFTAP
-                               if (drvr_priv->iflist[i] == NULL) {
-                                       BRCMF_TRACE(("\n\n %s: interface %d "
-                                                    "removed!\n", __func__,
-                                                    i));
-                                       continue;
-                               }
-
-                               if (in_ap && drvr_priv->set_macaddress) {
-                                       BRCMF_TRACE(("attempt to set MAC for"
-                                                    " %s in AP Mode,"
-                                                    " blocked.\n",
-                                                    ifentry->net->name));
-                                       drvr_priv->set_macaddress = false;
-                                       continue;
-                               }
-
-                               if (in_ap && drvr_priv->set_multicast) {
-                                       BRCMF_TRACE(("attempt to set MULTICAST "
-                                                    "list for %s in AP Mode, "
-                                                    "blocked.\n",
-                                                    ifentry->net->name));
-                                       drvr_priv->set_multicast = false;
-                                       continue;
-                               }
-#endif                         /* SOFTAP */
-                               if (drvr_priv->set_multicast) {
-                                       drvr_priv->set_multicast = false;
-                                       _brcmf_set_multicast_list(drvr_priv, i);
-                               }
-                               if (drvr_priv->set_macaddress) {
-                                       drvr_priv->set_macaddress = false;
-                                       _brcmf_set_mac_address(drvr_priv, i,
-                                               drvr_priv->macvalue);
-                               }
-                       }
-               }
-       }
-       return 0;
+       return;
 }
 
-static int brcmf_netdev_set_mac_address(struct net_device *dev, void *addr)
+static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr)
 {
-       int ret = 0;
-
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
        struct sockaddr *sa = (struct sockaddr *)addr;
        int ifidx;
 
-       ifidx = brcmf_net2idx(drvr_priv, dev);
+       ifidx = brcmf_net2idx(drvr_priv, ndev);
        if (ifidx == BRCMF_BAD_IF)
                return -1;
 
        memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN);
-       drvr_priv->set_macaddress = true;
-       up(&drvr_priv->sysioc_sem);
-
-       return ret;
+       schedule_work(&drvr_priv->setmacaddr_work);
+       return 0;
 }
 
-static void brcmf_netdev_set_multicast_list(struct net_device *dev)
+static void brcmf_netdev_set_multicast_list(struct net_device *ndev)
 {
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
        int ifidx;
 
-       ifidx = brcmf_net2idx(drvr_priv, dev);
+       ifidx = brcmf_net2idx(drvr_priv, ndev);
        if (ifidx == BRCMF_BAD_IF)
                return;
 
-       drvr_priv->set_multicast = true;
-       up(&drvr_priv->sysioc_sem);
+       schedule_work(&drvr_priv->multicast_work);
 }
 
 int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf)
@@ -634,27 +338,27 @@ int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf)
        return brcmf_sdbrcm_bus_txdata(drvr->bus, pktbuf);
 }
 
-static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *net)
+static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 {
        int ret;
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
        int ifidx;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        /* Reject if down */
        if (!drvr_priv->pub.up || (drvr_priv->pub.busstate == BRCMF_BUS_DOWN)) {
-               BRCMF_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
-                            __func__, drvr_priv->pub.up,
-                            drvr_priv->pub.busstate));
-               netif_stop_queue(net);
+               brcmf_dbg(ERROR, "xmit rejected pub.up=%d busstate=%d\n",
+                         drvr_priv->pub.up, drvr_priv->pub.busstate);
+               netif_stop_queue(ndev);
                return -ENODEV;
        }
 
-       ifidx = brcmf_net2idx(drvr_priv, net);
+       ifidx = brcmf_net2idx(drvr_priv, ndev);
        if (ifidx == BRCMF_BAD_IF) {
-               BRCMF_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
-               netif_stop_queue(net);
+               brcmf_dbg(ERROR, "bad ifidx %d\n", ifidx);
+               netif_stop_queue(ndev);
                return -ENODEV;
        }
 
@@ -662,15 +366,15 @@ static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *net)
        if (skb_headroom(skb) < drvr_priv->pub.hdrlen) {
                struct sk_buff *skb2;
 
-               BRCMF_INFO(("%s: insufficient headroom\n",
-                           brcmf_ifname(&drvr_priv->pub, ifidx)));
+               brcmf_dbg(INFO, "%s: insufficient headroom\n",
+                         brcmf_ifname(&drvr_priv->pub, ifidx));
                drvr_priv->pub.tx_realloc++;
                skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen);
                dev_kfree_skb(skb);
                skb = skb2;
                if (skb == NULL) {
-                       BRCMF_ERROR(("%s: skb_realloc_headroom failed\n",
-                                    brcmf_ifname(&drvr_priv->pub, ifidx)));
+                       brcmf_dbg(ERROR, "%s: skb_realloc_headroom failed\n",
+                                 brcmf_ifname(&drvr_priv->pub, ifidx));
                        ret = -ENOMEM;
                        goto done;
                }
@@ -690,17 +394,34 @@ done:
 
 void brcmf_txflowcontrol(struct brcmf_pub *drvr, int ifidx, bool state)
 {
-       struct net_device *net;
+       struct net_device *ndev;
        struct brcmf_info *drvr_priv = drvr->info;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        drvr->txoff = state;
-       net = drvr_priv->iflist[ifidx]->net;
+       ndev = drvr_priv->iflist[ifidx]->ndev;
        if (state == ON)
-               netif_stop_queue(net);
+               netif_stop_queue(ndev);
        else
-               netif_wake_queue(net);
+               netif_wake_queue(ndev);
+}
+
+static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx,
+                           void *pktdata, struct brcmf_event_msg *event,
+                           void **data)
+{
+       int bcmerror = 0;
+
+       bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
+       if (bcmerror != 0)
+               return bcmerror;
+
+       if (drvr_priv->iflist[*ifidx]->ndev)
+               brcmf_cfg80211_event(drvr_priv->iflist[*ifidx]->ndev,
+                                    event, *data);
+
+       return bcmerror;
 }
 
 void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
@@ -715,7 +436,7 @@ void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
        struct brcmf_if *ifp;
        struct brcmf_event_msg event;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        save_pktbuf = skb;
 
@@ -743,7 +464,7 @@ void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
                if (ifp == NULL)
                        ifp = drvr_priv->iflist[0];
 
-               skb->dev = ifp->net;
+               skb->dev = ifp->ndev;
                skb->protocol = eth_type_trans(skb, skb->dev);
 
                if (skb->pkt_type == PACKET_MULTICAST)
@@ -765,15 +486,15 @@ void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
                    !drvr_priv->iflist[ifidx]->state)
                        ifp = drvr_priv->iflist[ifidx];
 
-               if (ifp->net)
-                       ifp->net->last_rx = jiffies;
+               if (ifp->ndev)
+                       ifp->ndev->last_rx = jiffies;
 
                drvr->dstats.rx_bytes += skb->len;
                drvr->rx_packets++;     /* Local count */
 
-               if (in_interrupt()) {
+               if (in_interrupt())
                        netif_rx(skb);
-               } else {
+               else
                        /* If the receive is not processed inside an ISR,
                         * the softirqd must be woken explicitly to service
                         * the NET_RX_SOFTIRQ.  In 2.6 kernels, this is handled
@@ -781,7 +502,6 @@ void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
                         * to do it manually.
                         */
                        netif_rx_ni(skb);
-               }
        }
 }
 
@@ -802,24 +522,24 @@ void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp, bool success)
 
 }
 
-static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *net)
+static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
 {
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
        struct brcmf_if *ifp;
        int ifidx;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
-       ifidx = brcmf_net2idx(drvr_priv, net);
+       ifidx = brcmf_net2idx(drvr_priv, ndev);
        if (ifidx == BRCMF_BAD_IF)
                return NULL;
 
        ifp = drvr_priv->iflist[ifidx];
 
-       if (drvr_priv->pub.up) {
+       if (drvr_priv->pub.up)
                /* Use the protocol to get dongle stats */
                brcmf_proto_dstats(&drvr_priv->pub);
-       }
 
        /* Copy dongle stats to net device stats */
        ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets;
@@ -839,33 +559,35 @@ static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *net)
         as a bitmap in toe_ol iovar */
 static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol)
 {
-       struct brcmf_ioctl ioc;
+       struct brcmf_dcmd dcmd;
+       __le32 toe_le;
        char buf[32];
        int ret;
 
-       memset(&ioc, 0, sizeof(ioc));
+       memset(&dcmd, 0, sizeof(dcmd));
 
-       ioc.cmd = BRCMF_C_GET_VAR;
-       ioc.buf = buf;
-       ioc.len = (uint) sizeof(buf);
-       ioc.set = false;
+       dcmd.cmd = BRCMF_C_GET_VAR;
+       dcmd.buf = buf;
+       dcmd.len = (uint) sizeof(buf);
+       dcmd.set = false;
 
        strcpy(buf, "toe_ol");
-       ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
+       ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
        if (ret < 0) {
                /* Check for older dongle image that doesn't support toe_ol */
                if (ret == -EIO) {
-                       BRCMF_ERROR(("%s: toe not supported by device\n",
-                                    brcmf_ifname(&drvr_priv->pub, ifidx)));
+                       brcmf_dbg(ERROR, "%s: toe not supported by device\n",
+                                 brcmf_ifname(&drvr_priv->pub, ifidx));
                        return -EOPNOTSUPP;
                }
 
-               BRCMF_INFO(("%s: could not get toe_ol: ret=%d\n",
-                           brcmf_ifname(&drvr_priv->pub, ifidx), ret));
+               brcmf_dbg(INFO, "%s: could not get toe_ol: ret=%d\n",
+                         brcmf_ifname(&drvr_priv->pub, ifidx), ret);
                return ret;
        }
 
-       memcpy(toe_ol, buf, sizeof(u32));
+       memcpy(&toe_le, buf, sizeof(u32));
+       *toe_ol = le32_to_cpu(toe_le);
        return 0;
 }
 
@@ -873,63 +595,63 @@ static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol)
         and set toe global enable iovar */
 static int brcmf_toe_set(struct brcmf_info *drvr_priv, int ifidx, u32 toe_ol)
 {
-       struct brcmf_ioctl ioc;
+       struct brcmf_dcmd dcmd;
        char buf[32];
-       int toe, ret;
+       int ret;
+       __le32 toe_le = cpu_to_le32(toe_ol);
 
-       memset(&ioc, 0, sizeof(ioc));
+       memset(&dcmd, 0, sizeof(dcmd));
 
-       ioc.cmd = BRCMF_C_SET_VAR;
-       ioc.buf = buf;
-       ioc.len = (uint) sizeof(buf);
-       ioc.set = true;
+       dcmd.cmd = BRCMF_C_SET_VAR;
+       dcmd.buf = buf;
+       dcmd.len = (uint) sizeof(buf);
+       dcmd.set = true;
 
        /* Set toe_ol as requested */
-
        strcpy(buf, "toe_ol");
-       memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
+       memcpy(&buf[sizeof("toe_ol")], &toe_le, sizeof(u32));
 
-       ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
+       ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
        if (ret < 0) {
-               BRCMF_ERROR(("%s: could not set toe_ol: ret=%d\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx), ret));
+               brcmf_dbg(ERROR, "%s: could not set toe_ol: ret=%d\n",
+                         brcmf_ifname(&drvr_priv->pub, ifidx), ret);
                return ret;
        }
 
        /* Enable toe globally only if any components are enabled. */
-
-       toe = (toe_ol != 0);
+       toe_le = cpu_to_le32(toe_ol != 0);
 
        strcpy(buf, "toe");
-       memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
+       memcpy(&buf[sizeof("toe")], &toe_le, sizeof(u32));
 
-       ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
+       ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
        if (ret < 0) {
-               BRCMF_ERROR(("%s: could not set toe: ret=%d\n",
-                            brcmf_ifname(&drvr_priv->pub, ifidx), ret));
+               brcmf_dbg(ERROR, "%s: could not set toe: ret=%d\n",
+                         brcmf_ifname(&drvr_priv->pub, ifidx), ret);
                return ret;
        }
 
        return 0;
 }
 
-static void brcmf_ethtool_get_drvinfo(struct net_device *net,
+static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
                                    struct ethtool_drvinfo *info)
 {
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
 
        sprintf(info->driver, KBUILD_MODNAME);
        sprintf(info->version, "%lu", drvr_priv->pub.drv_version);
        sprintf(info->fw_version, "%s", BCM4329_FW_NAME);
        sprintf(info->bus_info, "%s",
-               dev_name(&brcmf_cfg80211_get_sdio_func()->dev));
+               dev_name(brcmf_bus_get_device(drvr_priv->pub.bus)));
 }
 
-struct ethtool_ops brcmf_ethtool_ops = {
+static struct ethtool_ops brcmf_ethtool_ops = {
        .get_drvinfo = brcmf_ethtool_get_drvinfo
 };
 
-static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
+static int brcmf_ethtool(struct brcmf_info *drvr_priv, void __user *uaddr)
 {
        struct ethtool_drvinfo info;
        char drvname[sizeof(info.driver)];
@@ -938,7 +660,7 @@ static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
        u32 toe_cmpnt, csum_dir;
        int ret;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        /* all ethtool calls start with a cmd word */
        if (copy_from_user(&cmd, uaddr, sizeof(u32)))
@@ -964,7 +686,7 @@ static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
 
                /* otherwise, require dongle to be up */
                else if (!drvr_priv->pub.up) {
-                       BRCMF_ERROR(("%s: dongle is not up\n", __func__));
+                       brcmf_dbg(ERROR, "dongle is not up\n");
                        return -ENODEV;
                }
 
@@ -977,8 +699,8 @@ static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
                sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
                if (copy_to_user(uaddr, &info, sizeof(info)))
                        return -EFAULT;
-               BRCMF_CTL(("%s: given %*s, returning %s\n", __func__,
-                          (int)sizeof(drvname), drvname, info.driver));
+               brcmf_dbg(CTL, "given %*s, returning %s\n",
+                         (int)sizeof(drvname), drvname, info.driver);
                break;
 
                /* Get toe offload components from dongle */
@@ -1024,10 +746,10 @@ static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
                /* If setting TX checksum mode, tell Linux the new mode */
                if (cmd == ETHTOOL_STXCSUM) {
                        if (edata.data)
-                               drvr_priv->iflist[0]->net->features |=
+                               drvr_priv->iflist[0]->ndev->features |=
                                    NETIF_F_IP_CSUM;
                        else
-                               drvr_priv->iflist[0]->net->features &=
+                               drvr_priv->iflist[0]->ndev->features &=
                                    ~NETIF_F_IP_CSUM;
                }
 
@@ -1040,180 +762,131 @@ static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
        return 0;
 }
 
-static int brcmf_netdev_ioctl_entry(struct net_device *net, struct ifreq *ifr,
+static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
                                    int cmd)
 {
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
-       struct brcmf_c_ioctl ioc;
-       int bcmerror = 0;
-       int buflen = 0;
-       void *buf = NULL;
-       uint driver = 0;
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
        int ifidx;
-       bool is_set_key_cmd;
 
-       ifidx = brcmf_net2idx(drvr_priv, net);
-       BRCMF_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
+       ifidx = brcmf_net2idx(drvr_priv, ndev);
+       brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifidx, cmd);
 
        if (ifidx == BRCMF_BAD_IF)
                return -1;
 
        if (cmd == SIOCETHTOOL)
-               return brcmf_ethtool(drvr_priv, (void *)ifr->ifr_data);
-
-       if (cmd != SIOCDEVPRIVATE)
-               return -EOPNOTSUPP;
-
-       memset(&ioc, 0, sizeof(ioc));
+               return brcmf_ethtool(drvr_priv, ifr->ifr_data);
 
-       /* Copy the ioc control structure part of ioctl request */
-       if (copy_from_user(&ioc, ifr->ifr_data, sizeof(struct brcmf_ioctl))) {
-               bcmerror = -EINVAL;
-               goto done;
-       }
+       return -EOPNOTSUPP;
+}
 
-       /* Copy out any buffer passed */
-       if (ioc.buf) {
-               buflen = min_t(int, ioc.len, BRCMF_IOCTL_MAXLEN);
-               /* optimization for direct ioctl calls from kernel */
-               /*
-                  if (segment_eq(get_fs(), KERNEL_DS)) {
-                  buf = ioc.buf;
-                  } else {
-                */
-               {
-                       buf = kmalloc(buflen, GFP_ATOMIC);
-                       if (!buf) {
-                               bcmerror = -ENOMEM;
-                               goto done;
-                       }
-                       if (copy_from_user(buf, ioc.buf, buflen)) {
-                               bcmerror = -EINVAL;
-                               goto done;
-                       }
-               }
-       }
+/* called only from within this driver. Sends a command to the dongle. */
+s32 brcmf_exec_dcmd(struct net_device *ndev, u32 cmd, void *arg, u32 len)
+{
+       struct brcmf_dcmd dcmd;
+       s32 err = 0;
+       int buflen = 0;
+       bool is_set_key_cmd;
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
+       int ifidx;
 
-       /* To differentiate read 4 more byes */
-       if ((copy_from_user(&driver, (char *)ifr->ifr_data +
-                           sizeof(struct brcmf_ioctl), sizeof(uint)) != 0)) {
-               bcmerror = -EINVAL;
-               goto done;
-       }
+       memset(&dcmd, 0, sizeof(dcmd));
+       dcmd.cmd = cmd;
+       dcmd.buf = arg;
+       dcmd.len = len;
 
-       if (!capable(CAP_NET_ADMIN)) {
-               bcmerror = -EPERM;
-               goto done;
-       }
+       ifidx = brcmf_net2idx(drvr_priv, ndev);
 
-       /* check for local brcmf ioctl and handle it */
-       if (driver == BRCMF_IOCTL_MAGIC) {
-               bcmerror = brcmf_c_ioctl((void *)&drvr_priv->pub, &ioc, buf, buflen);
-               if (bcmerror)
-                       drvr_priv->pub.bcmerror = bcmerror;
-               goto done;
-       }
+       if (dcmd.buf != NULL)
+               buflen = min_t(uint, dcmd.len, BRCMF_DCMD_MAXLEN);
 
        /* send to dongle (must be up, and wl) */
        if ((drvr_priv->pub.busstate != BRCMF_BUS_DATA)) {
-               BRCMF_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
-               bcmerror = -EIO;
+               brcmf_dbg(ERROR, "DONGLE_DOWN\n");
+               err = -EIO;
                goto done;
        }
 
        if (!drvr_priv->pub.iswl) {
-               bcmerror = -EIO;
+               err = -EIO;
                goto done;
        }
 
        /*
-        * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
-        * set key IOCTL to prevent M4 encryption.
+        * Intercept BRCMF_C_SET_KEY CMD - serialize M4 send and
+        * set key CMD to prevent M4 encryption.
         */
-       is_set_key_cmd = ((ioc.cmd == BRCMF_C_SET_KEY) ||
-                         ((ioc.cmd == BRCMF_C_SET_VAR) &&
-                          !(strncmp("wsec_key", ioc.buf, 9))) ||
-                         ((ioc.cmd == BRCMF_C_SET_VAR) &&
-                          !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
+       is_set_key_cmd = ((dcmd.cmd == BRCMF_C_SET_KEY) ||
+                         ((dcmd.cmd == BRCMF_C_SET_VAR) &&
+                          !(strncmp("wsec_key", dcmd.buf, 9))) ||
+                         ((dcmd.cmd == BRCMF_C_SET_VAR) &&
+                          !(strncmp("bsscfg:wsec_key", dcmd.buf, 15))));
        if (is_set_key_cmd)
-               brcmf_netdev_wait_pend8021x(net);
+               brcmf_netdev_wait_pend8021x(ndev);
 
-       bcmerror =
-           brcmf_proto_ioctl(&drvr_priv->pub, ifidx, (struct brcmf_ioctl *)&ioc,
-                             buf, buflen);
+       err = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, buflen);
 
 done:
-       if (!bcmerror && buf && ioc.buf) {
-               if (copy_to_user(ioc.buf, buf, buflen))
-                       bcmerror = -EFAULT;
-       }
-
-       kfree(buf);
-
-       if (bcmerror > 0)
-               bcmerror = 0;
+       if (err > 0)
+               err = 0;
 
-       return bcmerror;
+       return err;
 }
 
-static int brcmf_netdev_stop(struct net_device *net)
+static int brcmf_netdev_stop(struct net_device *ndev)
 {
-#if !defined(IGNORE_ETH0_DOWN)
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
+       struct brcmf_pub *drvr = *(struct brcmf_pub **) netdev_priv(ndev);
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
-       brcmf_cfg80211_down();
-       if (drvr_priv->pub.up == 0)
+       brcmf_dbg(TRACE, "Enter\n");
+       brcmf_cfg80211_down(drvr->config);
+       if (drvr->up == 0)
                return 0;
 
        /* Set state and stop OS transmissions */
-       drvr_priv->pub.up = 0;
-       netif_stop_queue(net);
-#else
-       BRCMF_ERROR(("BYPASS %s:due to BRCM compilation: under investigation\n",
-                    __func__));
-#endif                         /* !defined(IGNORE_ETH0_DOWN) */
+       drvr->up = 0;
+       netif_stop_queue(ndev);
 
        return 0;
 }
 
-static int brcmf_netdev_open(struct net_device *net)
+static int brcmf_netdev_open(struct net_device *ndev)
 {
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)
+                                       netdev_priv(ndev);
        u32 toe_ol;
-       int ifidx = brcmf_net2idx(drvr_priv, net);
+       int ifidx = brcmf_net2idx(drvr_priv, ndev);
        s32 ret = 0;
 
-       BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
+       brcmf_dbg(TRACE, "ifidx %d\n", ifidx);
 
        if (ifidx == 0) {       /* do it only for primary eth0 */
 
                /* try to bring up bus */
                ret = brcmf_bus_start(&drvr_priv->pub);
                if (ret != 0) {
-                       BRCMF_ERROR(("%s: failed with code %d\n",
-                                    __func__, ret));
+                       brcmf_dbg(ERROR, "failed with code %d\n", ret);
                        return -1;
                }
                atomic_set(&drvr_priv->pend_8021x_cnt, 0);
 
-               memcpy(net->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
+               memcpy(ndev->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
 
                /* Get current TOE mode from dongle */
                if (brcmf_toe_get(drvr_priv, ifidx, &toe_ol) >= 0
                    && (toe_ol & TOE_TX_CSUM_OL) != 0)
-                       drvr_priv->iflist[ifidx]->net->features |=
+                       drvr_priv->iflist[ifidx]->ndev->features |=
                                NETIF_F_IP_CSUM;
                else
-                       drvr_priv->iflist[ifidx]->net->features &=
+                       drvr_priv->iflist[ifidx]->ndev->features &=
                                ~NETIF_F_IP_CSUM;
        }
        /* Allow transmit calls */
-       netif_start_queue(net);
+       netif_start_queue(ndev);
        drvr_priv->pub.up = 1;
-       if (unlikely(brcmf_cfg80211_up())) {
-               BRCMF_ERROR(("%s: failed to bring up cfg80211\n",
-                            __func__));
+       if (brcmf_cfg80211_up(drvr_priv->pub.config)) {
+               brcmf_dbg(ERROR, "failed to bring up cfg80211\n");
                return -1;
        }
 
@@ -1221,35 +894,74 @@ static int brcmf_netdev_open(struct net_device *net)
 }
 
 int
-brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, void *handle, char *name,
-          u8 *mac_addr, u32 flags, u8 bssidx)
+brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, struct net_device *ndev,
+            char *name, u8 *mac_addr, u32 flags, u8 bssidx)
 {
        struct brcmf_if *ifp;
+       int ret = 0, err = 0;
 
-       BRCMF_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
+       brcmf_dbg(TRACE, "idx %d, handle->%p\n", ifidx, ndev);
 
        ifp = drvr_priv->iflist[ifidx];
        if (!ifp) {
                ifp = kmalloc(sizeof(struct brcmf_if), GFP_ATOMIC);
-               if (!ifp) {
-                       BRCMF_ERROR(("%s: OOM - struct brcmf_if\n", __func__));
+               if (!ifp)
                        return -ENOMEM;
-               }
        }
 
        memset(ifp, 0, sizeof(struct brcmf_if));
        ifp->info = drvr_priv;
        drvr_priv->iflist[ifidx] = ifp;
-       strlcpy(ifp->name, name, IFNAMSIZ);
        if (mac_addr != NULL)
                memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
 
-       if (handle == NULL) {
+       if (ndev == NULL) {
                ifp->state = BRCMF_E_IF_ADD;
                ifp->idx = ifidx;
-               up(&drvr_priv->sysioc_sem);
+               /*
+                * Delete the existing interface before overwriting it
+                * in case we missed the BRCMF_E_IF_DEL event.
+                */
+               if (ifp->ndev != NULL) {
+                       brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n",
+                                 ifp->ndev->name);
+                       netif_stop_queue(ifp->ndev);
+                       unregister_netdev(ifp->ndev);
+                       free_netdev(ifp->ndev);
+               }
+
+               /* Allocate netdev, including space for private structure */
+               ifp->ndev = alloc_netdev(sizeof(drvr_priv), "wlan%d",
+                                        ether_setup);
+               if (!ifp->ndev) {
+                       brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
+                       ret = -ENOMEM;
+               }
+
+               if (ret == 0) {
+                       memcpy(netdev_priv(ifp->ndev), &drvr_priv,
+                              sizeof(drvr_priv));
+                       err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
+                       if (err != 0) {
+                               brcmf_dbg(ERROR, "brcmf_net_attach failed, err %d\n",
+                                         err);
+                               ret = -EOPNOTSUPP;
+                       } else {
+                               brcmf_dbg(TRACE, " ==== pid:%x, net_device for if:%s created ===\n",
+                                         current->pid, ifp->ndev->name);
+                               ifp->state = 0;
+                       }
+               }
+
+               if (ret < 0) {
+                       if (ifp->ndev)
+                               free_netdev(ifp->ndev);
+
+                       drvr_priv->iflist[ifp->idx] = NULL;
+                       kfree(ifp);
+               }
        } else
-               ifp->net = (struct net_device *)handle;
+               ifp->ndev = ndev;
 
        return 0;
 }
@@ -1258,65 +970,55 @@ void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx)
 {
        struct brcmf_if *ifp;
 
-       BRCMF_TRACE(("%s: idx %d\n", __func__, ifidx));
+       brcmf_dbg(TRACE, "idx %d\n", ifidx);
 
        ifp = drvr_priv->iflist[ifidx];
        if (!ifp) {
-               BRCMF_ERROR(("%s: Null interface\n", __func__));
+               brcmf_dbg(ERROR, "Null interface\n");
                return;
        }
 
        ifp->state = BRCMF_E_IF_DEL;
        ifp->idx = ifidx;
-       up(&drvr_priv->sysioc_sem);
+       if (ifp->ndev != NULL) {
+               netif_stop_queue(ifp->ndev);
+               unregister_netdev(ifp->ndev);
+               free_netdev(ifp->ndev);
+               drvr_priv->iflist[ifidx] = NULL;
+               kfree(ifp);
+       }
 }
 
 struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
 {
        struct brcmf_info *drvr_priv = NULL;
-       struct net_device *net;
+       struct net_device *ndev;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
-       /* Allocate etherdev, including space for private structure */
-       net = alloc_etherdev(sizeof(drvr_priv));
-       if (!net) {
-               BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
+       /* Allocate netdev, including space for private structure */
+       ndev = alloc_netdev(sizeof(drvr_priv), "wlan%d", ether_setup);
+       if (!ndev) {
+               brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
                goto fail;
        }
 
        /* Allocate primary brcmf_info */
        drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC);
-       if (!drvr_priv) {
-               BRCMF_ERROR(("%s: OOM - alloc brcmf_info\n", __func__));
+       if (!drvr_priv)
                goto fail;
-       }
 
        /*
         * Save the brcmf_info into the priv
         */
-       memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
-
-       /* Set network interface name if it was provided as module parameter */
-       if (iface_name[0]) {
-               int len;
-               char ch;
-               strncpy(net->name, iface_name, IFNAMSIZ);
-               net->name[IFNAMSIZ - 1] = 0;
-               len = strlen(net->name);
-               ch = net->name[len - 1];
-               if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
-                       strcat(net->name, "%d");
-       }
+       memcpy(netdev_priv(ndev), &drvr_priv, sizeof(drvr_priv));
 
-       if (brcmf_add_if(drvr_priv, 0, (void *)net, net->name, NULL, 0, 0) ==
+       if (brcmf_add_if(drvr_priv, 0, ndev, ndev->name, NULL, 0, 0) ==
            BRCMF_BAD_IF)
                goto fail;
 
-       net->netdev_ops = NULL;
-       sema_init(&drvr_priv->proto_sem, 1);
-       /* Initialize other structure content */
-       init_waitqueue_head(&drvr_priv->ioctl_resp_wait);
+       ndev->netdev_ops = NULL;
+       mutex_init(&drvr_priv->proto_block);
 
        /* Link to info module */
        drvr_priv->pub.info = drvr_priv;
@@ -1327,41 +1029,33 @@ struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
 
        /* Attach and link in the protocol */
        if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
-               BRCMF_ERROR(("brcmf_prot_attach failed\n"));
+               brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
                goto fail;
        }
 
        /* Attach and link in the cfg80211 */
-       if (unlikely(brcmf_cfg80211_attach(net, &drvr_priv->pub))) {
-               BRCMF_ERROR(("wl_cfg80211_attach failed\n"));
+       drvr_priv->pub.config =
+                       brcmf_cfg80211_attach(ndev,
+                                             brcmf_bus_get_device(bus),
+                                             &drvr_priv->pub);
+       if (drvr_priv->pub.config == NULL) {
+               brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n");
                goto fail;
        }
 
-       if (brcmf_sysioc) {
-               sema_init(&drvr_priv->sysioc_sem, 0);
-               drvr_priv->sysioc_tsk = kthread_run(_brcmf_sysioc_thread, drvr_priv,
-                                               "_brcmf_sysioc");
-               if (IS_ERR(drvr_priv->sysioc_tsk)) {
-                       printk(KERN_WARNING
-                               "_brcmf_sysioc thread failed to start\n");
-                       drvr_priv->sysioc_tsk = NULL;
-               }
-       } else
-               drvr_priv->sysioc_tsk = NULL;
+       INIT_WORK(&drvr_priv->setmacaddr_work, _brcmf_set_mac_address);
+       INIT_WORK(&drvr_priv->multicast_work, _brcmf_set_multicast_list);
 
        /*
         * Save the brcmf_info into the priv
         */
-       memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
+       memcpy(netdev_priv(ndev), &drvr_priv, sizeof(drvr_priv));
 
-#if defined(CONFIG_PM_SLEEP)
-       atomic_set(&brcmf_mmc_suspend, false);
-#endif /* defined(CONFIG_PM_SLEEP) */
        return &drvr_priv->pub;
 
 fail:
-       if (net)
-               free_netdev(net);
+       if (ndev)
+               free_netdev(ndev);
        if (drvr_priv)
                brcmf_detach(&drvr_priv->pub);
 
@@ -1375,25 +1069,24 @@ int brcmf_bus_start(struct brcmf_pub *drvr)
        /* Room for "event_msgs" + '\0' + bitvec */
        char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
 
-       BRCMF_TRACE(("%s:\n", __func__));
+       brcmf_dbg(TRACE, "\n");
 
        /* Bring up the bus */
-       ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub, true);
+       ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub);
        if (ret != 0) {
-               BRCMF_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__,
-                            ret));
+               brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
                return ret;
        }
 
        /* If bus is not ready, can't come up */
        if (drvr_priv->pub.busstate != BRCMF_BUS_DATA) {
-               BRCMF_ERROR(("%s failed bus is not ready\n", __func__));
+               brcmf_dbg(ERROR, "failed bus is not ready\n");
                return -ENODEV;
        }
 
-       brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
+       brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
                      iovbuf, sizeof(iovbuf));
-       brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
+       brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
                                    sizeof(iovbuf));
        memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
 
@@ -1437,20 +1130,20 @@ static struct net_device_ops brcmf_netdev_ops_pri = {
        .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
        .ndo_start_xmit = brcmf_netdev_start_xmit,
        .ndo_set_mac_address = brcmf_netdev_set_mac_address,
-       .ndo_set_multicast_list = brcmf_netdev_set_multicast_list
+       .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
 };
 
 int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
 {
        struct brcmf_info *drvr_priv = drvr->info;
-       struct net_device *net;
+       struct net_device *ndev;
        u8 temp_addr[ETH_ALEN] = {
                0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
 
-       BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
+       brcmf_dbg(TRACE, "ifidx %d\n", ifidx);
 
-       net = drvr_priv->iflist[ifidx]->net;
-       net->netdev_ops = &brcmf_netdev_ops_pri;
+       ndev = drvr_priv->iflist[ifidx]->ndev;
+       ndev->netdev_ops = &brcmf_netdev_ops_pri;
 
        /*
         * We have to use the primary MAC for virtual interfaces
@@ -1462,32 +1155,31 @@ int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
        }
 
        if (ifidx == 1) {
-               BRCMF_TRACE(("%s ACCESS POINT MAC:\n", __func__));
+               brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
                /*  ACCESSPOINT INTERFACE CASE */
                temp_addr[0] |= 0X02;   /* set bit 2 ,
                         - Locally Administered address  */
 
        }
-       net->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
-       net->ethtool_ops = &brcmf_ethtool_ops;
+       ndev->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
+       ndev->ethtool_ops = &brcmf_ethtool_ops;
 
-       drvr_priv->pub.rxsz = net->mtu + net->hard_header_len +
-                               drvr_priv->pub.hdrlen;
+       drvr_priv->pub.rxsz = ndev->mtu + ndev->hard_header_len +
+                             drvr_priv->pub.hdrlen;
 
-       memcpy(net->dev_addr, temp_addr, ETH_ALEN);
+       memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
 
-       if (register_netdev(net) != 0) {
-               BRCMF_ERROR(("%s: couldn't register the net device\n",
-                            __func__));
+       if (register_netdev(ndev) != 0) {
+               brcmf_dbg(ERROR, "couldn't register the net device\n");
                goto fail;
        }
 
-       BRCMF_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
+       brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
 
        return 0;
 
 fail:
-       net->netdev_ops = NULL;
+       ndev->netdev_ops = NULL;
        return -EBADE;
 }
 
@@ -1495,7 +1187,7 @@ static void brcmf_bus_detach(struct brcmf_pub *drvr)
 {
        struct brcmf_info *drvr_priv;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        if (drvr) {
                drvr_priv = drvr->info;
@@ -1504,7 +1196,7 @@ static void brcmf_bus_detach(struct brcmf_pub *drvr)
                        brcmf_proto_stop(&drvr_priv->pub);
 
                        /* Stop the bus module */
-                       brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus, true);
+                       brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus);
                }
        }
 }
@@ -1513,7 +1205,7 @@ void brcmf_detach(struct brcmf_pub *drvr)
 {
        struct brcmf_info *drvr_priv;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        if (drvr) {
                drvr_priv = drvr->info;
@@ -1526,25 +1218,24 @@ void brcmf_detach(struct brcmf_pub *drvr)
                                        brcmf_del_if(drvr_priv, i);
 
                        ifp = drvr_priv->iflist[0];
-                       if (ifp->net->netdev_ops == &brcmf_netdev_ops_pri) {
-                               brcmf_netdev_stop(ifp->net);
-                               unregister_netdev(ifp->net);
+                       if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
+                               rtnl_lock();
+                               brcmf_netdev_stop(ifp->ndev);
+                               rtnl_unlock();
+                               unregister_netdev(ifp->ndev);
                        }
 
-                       if (drvr_priv->sysioc_tsk) {
-                               send_sig(SIGTERM, drvr_priv->sysioc_tsk, 1);
-                               kthread_stop(drvr_priv->sysioc_tsk);
-                               drvr_priv->sysioc_tsk = NULL;
-                       }
+                       cancel_work_sync(&drvr_priv->setmacaddr_work);
+                       cancel_work_sync(&drvr_priv->multicast_work);
 
                        brcmf_bus_detach(drvr);
 
                        if (drvr->prot)
                                brcmf_proto_detach(drvr);
 
-                       brcmf_cfg80211_detach();
+                       brcmf_cfg80211_detach(drvr->config);
 
-                       free_netdev(ifp->net);
+                       free_netdev(ifp->ndev);
                        kfree(ifp);
                        kfree(drvr_priv);
                }
@@ -1553,7 +1244,7 @@ void brcmf_detach(struct brcmf_pub *drvr)
 
 static void __exit brcmf_module_cleanup(void)
 {
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        brcmf_bus_unregister();
 }
@@ -1562,12 +1253,12 @@ static int __init brcmf_module_init(void)
 {
        int error;
 
-       BRCMF_TRACE(("%s: Enter\n", __func__));
+       brcmf_dbg(TRACE, "Enter\n");
 
        error = brcmf_bus_register();
 
        if (error) {
-               BRCMF_ERROR(("%s: brcmf_bus_register failed\n", __func__));
+               brcmf_dbg(ERROR, "brcmf_bus_register failed\n");
                goto failed;
        }
        return 0;
@@ -1584,7 +1275,7 @@ int brcmf_os_proto_block(struct brcmf_pub *drvr)
        struct brcmf_info *drvr_priv = drvr->info;
 
        if (drvr_priv) {
-               down(&drvr_priv->proto_sem);
+               mutex_lock(&drvr_priv->proto_block);
                return 1;
        }
        return 0;
@@ -1595,84 +1286,13 @@ int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
        struct brcmf_info *drvr_priv = drvr->info;
 
        if (drvr_priv) {
-               up(&drvr_priv->proto_sem);
+               mutex_unlock(&drvr_priv->proto_block);
                return 1;
        }
 
        return 0;
 }
 
-unsigned int brcmf_os_get_ioctl_resp_timeout(void)
-{
-       return (unsigned int)brcmf_ioctl_timeout_msec;
-}
-
-void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
-{
-       brcmf_ioctl_timeout_msec = (int)timeout_msec;
-}
-
-int brcmf_os_ioctl_resp_wait(struct brcmf_pub *drvr, uint *condition,
-                            bool *pending)
-{
-       struct brcmf_info *drvr_priv = drvr->info;
-       DECLARE_WAITQUEUE(wait, current);
-       int timeout = brcmf_ioctl_timeout_msec;
-
-       /* Convert timeout in millsecond to jiffies */
-       timeout = timeout * HZ / 1000;
-
-       /* Wait until control frame is available */
-       add_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
-       set_current_state(TASK_INTERRUPTIBLE);
-
-       while (!(*condition) && (!signal_pending(current) && timeout))
-               timeout = schedule_timeout(timeout);
-
-       if (signal_pending(current))
-               *pending = true;
-
-       set_current_state(TASK_RUNNING);
-       remove_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
-
-       return timeout;
-}
-
-int brcmf_os_ioctl_resp_wake(struct brcmf_pub *drvr)
-{
-       struct brcmf_info *drvr_priv = drvr->info;
-
-       if (waitqueue_active(&drvr_priv->ioctl_resp_wait))
-               wake_up_interruptible(&drvr_priv->ioctl_resp_wait);
-
-       return 0;
-}
-
-static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
-                           struct brcmf_event_msg *event, void **data)
-{
-       int bcmerror = 0;
-
-       bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
-       if (bcmerror != 0)
-               return bcmerror;
-
-       if (drvr_priv->iflist[*ifidx]->net)
-               brcmf_cfg80211_event(drvr_priv->iflist[*ifidx]->net,
-                                    event, *data);
-
-       return bcmerror;
-}
-
-int brcmf_netdev_reset(struct net_device *dev, u8 flag)
-{
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
-
-       brcmf_bus_devreset(&drvr_priv->pub, flag);
-
-       return 1;
-}
-
 static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
 {
        return atomic_read(&drvr_priv->pend_8021x_cnt);
@@ -1680,9 +1300,9 @@ static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
 
 #define MAX_WAIT_FOR_8021X_TX  10
 
-int brcmf_netdev_wait_pend8021x(struct net_device *dev)
+int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
 {
-       struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
+       struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(ndev);
        int timeout = 10 * HZ / 1000;
        int ntimes = MAX_WAIT_FOR_8021X_TX;
        int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
@@ -1700,7 +1320,7 @@ int brcmf_netdev_wait_pend8021x(struct net_device *dev)
 }
 
 #ifdef BCMDBG
-int brcmf_write_to_file(struct brcmf_pub *drvr, u8 *buf, int size)
+int brcmf_write_to_file(struct brcmf_pub *drvr, const u8 *buf, int size)
 {
        int ret = 0;
        struct file *fp;
@@ -1714,13 +1334,13 @@ int brcmf_write_to_file(struct brcmf_pub *drvr, u8 *buf, int size)
        /* open file to write */
        fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
        if (!fp) {
-               BRCMF_ERROR(("%s: open file error\n", __func__));
+               brcmf_dbg(ERROR, "open file error\n");
                ret = -1;
                goto exit;
        }
 
        /* Write buf to file */
-       fp->f_op->write(fp, buf, size, &pos);
+       fp->f_op->write(fp, (char __user *)buf, size, &pos);
 
 exit:
        /* free buf before return */
index ff788b3..4ee1ea8 100644 (file)
 #ifndef _BRCMF_PROTO_H_
 #define _BRCMF_PROTO_H_
 
-#ifndef IOCTL_RESP_TIMEOUT
-#define IOCTL_RESP_TIMEOUT  2000       /* In milli second */
-#endif
-
-#ifndef IOCTL_CHIP_ACTIVE_TIMEOUT
-#define IOCTL_CHIP_ACTIVE_TIMEOUT  10  /* In milli second */
-#endif
-
 /*
  * Exported from the brcmf protocol module (brcmf_cdc)
  */
@@ -53,23 +45,16 @@ extern void brcmf_proto_hdrpush(struct brcmf_pub *, int ifidx,
 extern int brcmf_proto_hdrpull(struct brcmf_pub *, int *ifidx,
                               struct sk_buff *rxp);
 
-/* Use protocol to issue ioctl to dongle */
-extern int brcmf_proto_ioctl(struct brcmf_pub *drvr, int ifidx,
-                            struct brcmf_ioctl *ioc, void *buf, int len);
-
-/* Add prot dump output to a buffer */
-extern void brcmf_proto_dump(struct brcmf_pub *drvr,
-                            struct brcmu_strbuf *strbuf);
+/* Use protocol to issue command to dongle */
+extern int brcmf_proto_dcmd(struct brcmf_pub *drvr, int ifidx,
+                               struct brcmf_dcmd *dcmd, int len);
 
 /* Update local copy of dongle statistics */
 extern void brcmf_proto_dstats(struct brcmf_pub *drvr);
 
-extern int brcmf_c_ioctl(struct brcmf_pub *drvr, struct brcmf_c_ioctl *ioc,
-                        void *buf, uint buflen);
-
-extern int brcmf_c_preinit_ioctls(struct brcmf_pub *drvr);
+extern int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr);
 
-extern int brcmf_proto_cdc_set_ioctl(struct brcmf_pub *drvr, int ifidx,
+extern int brcmf_proto_cdc_set_dcmd(struct brcmf_pub *drvr, int ifidx,
                                     uint cmd, void *buf, uint len);
 
 #endif                         /* _BRCMF_PROTO_H_ */
index 7fa95b6..b716e31 100644 (file)
 #include <linux/sched.h>
 #include <linux/mmc/sdio.h>
 #include <linux/mmc/sdio_func.h>
+#include <linux/mmc/card.h>
 #include <linux/semaphore.h>
 #include <linux/firmware.h>
+#include <linux/module.h>
 #include <asm/unaligned.h>
 #include <defs.h>
 #include <brcmu_wifi.h>
 #include <soc.h>
 #include "sdio_host.h"
 
-/* register access macros */
-#ifndef __BIG_ENDIAN
-#ifndef __mips__
-#define R_REG(r, typ) \
-       brcmf_sdcard_reg_read(NULL, (r), sizeof(typ))
-#else                          /* __mips__ */
-#define R_REG(r, typ) \
-       ({ \
-               __typeof(*(r)) __osl_v; \
-               __asm__ __volatile__("sync"); \
-               __osl_v = brcmf_sdcard_reg_read(NULL, (r),\
-                                         sizeof(typ)); \
-               __asm__ __volatile__("sync"); \
-               __osl_v; \
-       })
-#endif                         /* __mips__ */
-
-#else                          /* __BIG_ENDIAN */
-#define R_REG(r, typ) \
-       brcmf_sdcard_reg_read(NULL, (r), sizeof(typ))
-#endif                         /* __BIG_ENDIAN */
-
-#define OR_REG(r, v, typ) \
-       brcmf_sdcard_reg_write(NULL, (r), sizeof(typ), R_REG(r, typ) | (v))
+#define DCMD_RESP_TIMEOUT  2000        /* In milli second */
 
 #ifdef BCMDBG
 
-/* ARM trap handling */
-
-/* Trap types defined by ARM (see arminc.h) */
-
-#if defined(__ARM_ARCH_4T__)
-#define        MAX_TRAP_TYPE   (TR_FIQ + 1)
-#elif defined(__ARM_ARCH_7M__)
-#define        MAX_TRAP_TYPE   (TR_ISR + ARMCM3_NUMINTS)
-#endif                         /* __ARM_ARCH_7M__ */
-
-/* The trap structure is defined here as offsets for assembly */
-#define        TR_TYPE         0x00
-#define        TR_EPC          0x04
-#define        TR_CPSR         0x08
-#define        TR_SPSR         0x0c
-#define        TR_REGS         0x10
-#define        TR_REG(n)       (TR_REGS + (n) * 4)
-#define        TR_SP           TR_REG(13)
-#define        TR_LR           TR_REG(14)
-#define        TR_PC           TR_REG(15)
-
-#define        TRAP_T_SIZE     80
-
-struct brcmf_trap {
-       u32 type;
-       u32 epc;
-       u32 cpsr;
-       u32 spsr;
-       u32 r0;
-       u32 r1;
-       u32 r2;
-       u32 r3;
-       u32 r4;
-       u32 r5;
-       u32 r6;
-       u32 r7;
-       u32 r8;
-       u32 r9;
-       u32 r10;
-       u32 r11;
-       u32 r12;
-       u32 r13;
-       u32 r14;
-       u32 pc;
-};
+#define BRCMF_TRAP_INFO_SIZE   80
 
 #define CBUF_LEN       (128)
 
-struct rte_log {
-       u32 buf;                /* Can't be pointer on (64-bit) hosts */
-       uint buf_size;
-       uint idx;
+struct rte_log_le {
+       __le32 buf;             /* Can't be pointer on (64-bit) hosts */
+       __le32 buf_size;
+       __le32 idx;
        char *_buf_compat;      /* Redundant pointer for backward compat. */
 };
 
@@ -126,8 +61,8 @@ struct rte_console {
         * (at risk of conflicting with
         * the real UART).  vcons_out is currently unused.
         */
-       volatile uint vcons_in;
-       volatile uint vcons_out;
+       uint vcons_in;
+       uint vcons_out;
 
        /* Output (logging) buffer
         * Console output is written to a ring buffer log_buf at index log_idx.
@@ -135,7 +70,7 @@ struct rte_console {
         * Output will be lost if the output wraps around faster than the host
         * polls.
         */
-       struct rte_log log;
+       struct rte_log_le log_le;
 
        /* Console input line buffer
         * Characters are read one at a time into cbuf
@@ -176,57 +111,67 @@ struct rte_console {
 #define MAX_DATA_BUF   (32 * 1024)     /* Must be large enough to hold
                                 biggest possible glom */
 
-#ifndef BRCMF_FIRSTREAD
-#define BRCMF_FIRSTREAD        32
-#endif
+#define BRCMF_FIRSTREAD        (1 << 6)
 
-#if !ISPOWEROF2(BRCMF_FIRSTREAD)
-#error BRCMF_FIRSTREAD is not a power of 2!
-#endif
 
 /* SBSDIO_DEVICE_CTL */
-#define SBSDIO_DEVCTL_SETBUSY          0x01    /* 1: device will assert busy signal when
-                                                * receiving CMD53
-                                                */
-#define SBSDIO_DEVCTL_SPI_INTR_SYNC    0x02    /* 1: assertion of sdio interrupt is
-                                                * synchronous to the sdio clock
-                                                */
-#define SBSDIO_DEVCTL_CA_INT_ONLY      0x04    /* 1: mask all interrupts to host
-                                                * except the chipActive (rev 8)
-                                                */
-#define SBSDIO_DEVCTL_PADS_ISO         0x08    /* 1: isolate internal sdio signals, put
-                                                * external pads in tri-state; requires
-                                                * sdio bus power cycle to clear (rev 9)
-                                                */
-#define SBSDIO_DEVCTL_SB_RST_CTL       0x30    /* Force SD->SB reset mapping (rev 11) */
-#define SBSDIO_DEVCTL_RST_CORECTL      0x00    /*   Determined by CoreControl bit */
-#define SBSDIO_DEVCTL_RST_BPRESET      0x10    /*   Force backplane reset */
-#define SBSDIO_DEVCTL_RST_NOBPRESET    0x20    /*   Force no backplane reset */
+
+/* 1: device will assert busy signal when receiving CMD53 */
+#define SBSDIO_DEVCTL_SETBUSY          0x01
+/* 1: assertion of sdio interrupt is synchronous to the sdio clock */
+#define SBSDIO_DEVCTL_SPI_INTR_SYNC    0x02
+/* 1: mask all interrupts to host except the chipActive (rev 8) */
+#define SBSDIO_DEVCTL_CA_INT_ONLY      0x04
+/* 1: isolate internal sdio signals, put external pads in tri-state; requires
+ * sdio bus power cycle to clear (rev 9) */
+#define SBSDIO_DEVCTL_PADS_ISO         0x08
+/* Force SD->SB reset mapping (rev 11) */
+#define SBSDIO_DEVCTL_SB_RST_CTL       0x30
+/*   Determined by CoreControl bit */
+#define SBSDIO_DEVCTL_RST_CORECTL      0x00
+/*   Force backplane reset */
+#define SBSDIO_DEVCTL_RST_BPRESET      0x10
+/*   Force no backplane reset */
+#define SBSDIO_DEVCTL_RST_NOBPRESET    0x20
 
 /* SBSDIO_FUNC1_CHIPCLKCSR */
-#define SBSDIO_FORCE_ALP               0x01    /* Force ALP request to backplane */
-#define SBSDIO_FORCE_HT                        0x02    /* Force HT request to backplane */
-#define SBSDIO_FORCE_ILP               0x04    /* Force ILP request to backplane */
-#define SBSDIO_ALP_AVAIL_REQ           0x08    /* Make ALP ready (power up xtal) */
-#define SBSDIO_HT_AVAIL_REQ            0x10    /* Make HT ready (power up PLL) */
-#define SBSDIO_FORCE_HW_CLKREQ_OFF     0x20    /* Squelch clock requests from HW */
-#define SBSDIO_ALP_AVAIL               0x40    /* Status: ALP is ready */
-#define SBSDIO_HT_AVAIL                        0x80    /* Status: HT is ready */
-
-#define SBSDIO_AVBITS                  (SBSDIO_HT_AVAIL | SBSDIO_ALP_AVAIL)
-#define SBSDIO_ALPAV(regval)           ((regval) & SBSDIO_AVBITS)
-#define SBSDIO_HTAV(regval)    &nb