staging: brcm80211: removed last typedefs from fullmac
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmfmac / dhd_sdio.c
index a71c6f8..3cbfacb 100644 (file)
 
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/kthread.h>
 #include <linux/printk.h>
 #include <linux/pci_ids.h>
 #include <linux/netdevice.h>
-#include <bcmdefs.h>
-#include <bcmsdh.h>
+#include <linux/sched.h>
+#include <linux/mmc/sdio.h>
+#include <linux/mmc/sdio_func.h>
+#include <linux/semaphore.h>
+#include <linux/firmware.h>
+#include <asm/unaligned.h>
+#include <defs.h>
+#include <brcmu_wifi.h>
+#include <brcmu_utils.h>
+#include <brcm_hw_ids.h>
+#include <soc.h>
+#include "sdio_host.h"
+#include "bcmsdbus.h"
+
+/* register access macros */
+#ifndef __BIG_ENDIAN
+#ifndef __mips__
+#define R_REG(r) \
+       brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r)))
+#else                          /* __mips__ */
+#define R_REG(r) \
+       ({ \
+               __typeof(*(r)) __osl_v; \
+               __asm__ __volatile__("sync"); \
+               __osl_v = brcmf_sdcard_reg_read(NULL, (unsigned long)(r),\
+                                         sizeof(*(r))); \
+               __asm__ __volatile__("sync"); \
+               __osl_v; \
+       })
+#endif                         /* __mips__ */
+
+#define W_REG(r, v) do { \
+               brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \
+                                      (v)); \
+       } while (0)
+#else                          /* __BIG_ENDIAN */
+#define R_REG(r) \
+       brcmf_sdcard_reg_read(NULL, (unsigned long)(r), sizeof(*(r)))
+#define W_REG(r, v) do { \
+               brcmf_sdcard_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), \
+                                      (v)); \
+       } while (0)
+#endif                         /* __BIG_ENDIAN */
+
+#define AND_REG(r, v)  W_REG((r), R_REG(r) & (v))
+#define OR_REG(r, v)   W_REG((r), R_REG(r) | (v))
+
+#define SET_REG(r, mask, val) \
+               W_REG((r), ((R_REG(r) & ~(mask)) | (val)))
+
+#ifdef BCMDBG
+
+/* ARM trap handling */
+
+/* Trap types defined by ARM (see arminc.h) */
+
+/* Trap locations in lo memory */
+#define        TRAP_STRIDE     4
+#define FIRST_TRAP     TR_RST
+#define LAST_TRAP      (TR_FIQ * TRAP_STRIDE)
+
+#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;
+};
 
-#ifdef BCMEMBEDIMAGE
-#include BCMEMBEDIMAGE
-#endif                         /* BCMEMBEDIMAGE */
+#define CBUF_LEN       (128)
 
-#include <bcmdefs.h>
-#include <bcmutils.h>
-#include <bcmdevs.h>
+#define LOG_BUF_LEN    1024
 
-#include <hndsoc.h>
-#ifdef DHD_DEBUG
-#include <hndrte_armtrap.h>
-#include <hndrte_cons.h>
-#endif                         /* DHD_DEBUG */
-#include <sbchipc.h>
-#include <sbhnddma.h>
-
-#include <sdio.h>
-#include <sbsdio.h>
-#include <sbsdpcmdev.h>
-#include <bcmsdpcm.h>
-
-#include <proto/802.11.h>
-
-#include <dngl_stats.h>
-#include <dhd.h>
-#include <dhd_bus.h>
-#include <dhd_proto.h>
-#include <dhd_dbg.h>
-#include <dhdioctl.h>
-#include <sdiovar.h>
+struct rte_log {
+       u32 buf;                /* Can't be pointer on (64-bit) hosts */
+       uint buf_size;
+       uint idx;
+       char *_buf_compat;      /* Redundant pointer for backward compat. */
+};
+
+struct rte_console {
+       /* Virtual UART
+        * When there is no UART (e.g. Quickturn),
+        * the host should write a complete
+        * input line directly into cbuf and then write
+        * the length into vcons_in.
+        * This may also be used when there is a real UART
+        * (at risk of conflicting with
+        * the real UART).  vcons_out is currently unused.
+        */
+       volatile uint vcons_in;
+       volatile uint vcons_out;
+
+       /* Output (logging) buffer
+        * Console output is written to a ring buffer log_buf at index log_idx.
+        * The host may read the output when it sees log_idx advance.
+        * Output will be lost if the output wraps around faster than the host
+        * polls.
+        */
+       struct rte_log log;
+
+       /* Console input line buffer
+        * Characters are read one at a time into cbuf
+        * until <CR> is received, then
+        * the buffer is processed as a command line.
+        * Also used for virtual UART.
+        */
+       uint cbuf_idx;
+       char cbuf[CBUF_LEN];
+};
+
+#endif                         /* BCMDBG */
+#include <chipcommon.h>
+
+#include "sbsdio.h"
+
+#include "dngl_stats.h"
+#include "dhd.h"
+#include "dhd_bus.h"
+#include "dhd_proto.h"
+#include "dhd_dbg.h"
 #include <bcmchip.h>
 
 #ifndef DHDSDIO_MEM_DUMP_FNAME
 #define MAX_DATA_BUF   (32 * 1024)     /* Must be large enough to hold
                                 biggest possible glom */
 
-/* Packet alignment for most efficient SDIO (can change based on platform) */
-#ifndef DHD_SDALIGN
-#define DHD_SDALIGN    32
+#ifndef BRCMF_FIRSTREAD
+#define BRCMF_FIRSTREAD        32
 #endif
-#if !ISPOWEROF2(DHD_SDALIGN)
-#error DHD_SDALIGN is not a power of 2!
-#endif
-
-#ifndef DHD_FIRSTREAD
-#define DHD_FIRSTREAD  32
-#endif
-#if !ISPOWEROF2(DHD_FIRSTREAD)
-#error DHD_FIRSTREAD is not a power of 2!
+#if !ISPOWEROF2(BRCMF_FIRSTREAD)
+#error BRCMF_FIRSTREAD is not a power of 2!
 #endif
 
 /* Total length of frame header for dongle protocol */
 #define SDPCM_HDRLEN   (SDPCM_FRAMETAG_LEN + SDPCM_SWHEADER_LEN)
 #ifdef SDTEST
-#define SDPCM_RESERVE  (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN)
+#define SDPCM_RESERVE  (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN)
 #else
-#define SDPCM_RESERVE  (SDPCM_HDRLEN + DHD_SDALIGN)
+#define SDPCM_RESERVE  (SDPCM_HDRLEN + BRCMF_SDALIGN)
 #endif
 
+/*
+ * Software allocation of To SB Mailbox resources
+ */
+
+/* tosbmailbox bits corresponding to intstatus bits */
+#define SMB_NAK                (1 << 0)        /* Frame NAK */
+#define SMB_INT_ACK    (1 << 1)        /* Host Interrupt ACK */
+#define SMB_USE_OOB    (1 << 2)        /* Use OOB Wakeup */
+#define SMB_DEV_INT    (1 << 3)        /* Miscellaneous Interrupt */
+
+/* tosbmailboxdata */
+#define SMB_DATA_VERSION_SHIFT 16      /* host protocol version */
+
+/*
+ * Software allocation of To Host Mailbox resources
+ */
+
+/* intstatus bits */
+#define I_HMB_FC_STATE I_HMB_SW0       /* Flow Control State */
+#define I_HMB_FC_CHANGE        I_HMB_SW1       /* Flow Control State Changed */
+#define I_HMB_FRAME_IND        I_HMB_SW2       /* Frame Indication */
+#define I_HMB_HOST_INT I_HMB_SW3       /* Miscellaneous Interrupt */
+
+/* tohostmailboxdata */
+#define HMB_DATA_NAKHANDLED    1       /* retransmit NAK'd frame */
+#define HMB_DATA_DEVREADY      2       /* talk to host after enable */
+#define HMB_DATA_FC            4       /* per prio flowcontrol update flag */
+#define HMB_DATA_FWREADY       8       /* fw ready for protocol activity */
+
+#define HMB_DATA_FCDATA_MASK   0xff000000
+#define HMB_DATA_FCDATA_SHIFT  24
+
+#define HMB_DATA_VERSION_MASK  0x00ff0000
+#define HMB_DATA_VERSION_SHIFT 16
+
+/*
+ * Software-defined protocol header
+ */
+
+/* Current protocol version */
+#define SDPCM_PROT_VERSION     4
+
+/* SW frame header */
+#define SDPCM_PACKET_SEQUENCE(p)       (((u8 *)p)[0] & 0xff)
+
+#define SDPCM_CHANNEL_MASK             0x00000f00
+#define SDPCM_CHANNEL_SHIFT            8
+#define SDPCM_PACKET_CHANNEL(p)                (((u8 *)p)[1] & 0x0f)
+
+#define SDPCM_NEXTLEN_OFFSET           2
+
+/* Data Offset from SOF (HW Tag, SW Tag, Pad) */
+#define SDPCM_DOFFSET_OFFSET           3       /* Data Offset */
+#define SDPCM_DOFFSET_VALUE(p)         (((u8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff)
+#define SDPCM_DOFFSET_MASK             0xff000000
+#define SDPCM_DOFFSET_SHIFT            24
+#define SDPCM_FCMASK_OFFSET            4       /* Flow control */
+#define SDPCM_FCMASK_VALUE(p)          (((u8 *)p)[SDPCM_FCMASK_OFFSET] & 0xff)
+#define SDPCM_WINDOW_OFFSET            5       /* Credit based fc */
+#define SDPCM_WINDOW_VALUE(p)          (((u8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff)
+
+#define SDPCM_SWHEADER_LEN     8       /* SW header is 64 bits */
+
+/* logical channel numbers */
+#define SDPCM_CONTROL_CHANNEL  0       /* Control channel Id */
+#define SDPCM_EVENT_CHANNEL    1       /* Asyc Event Indication Channel Id */
+#define SDPCM_DATA_CHANNEL     2       /* Data Xmit/Recv Channel Id */
+#define SDPCM_GLOM_CHANNEL     3       /* For coalesced packets */
+#define SDPCM_TEST_CHANNEL     15      /* Reserved for test/debug packets */
+
+#define SDPCM_SEQUENCE_WRAP    256     /* wrap-around val for 8bit frame seq */
+
+#define SDPCM_GLOMDESC(p)      (((u8 *)p)[1] & 0x80)
+
+/* For TEST_CHANNEL packets, define another 4-byte header */
+#define SDPCM_TEST_HDRLEN      4       /*
+                                        * Generally: Cmd(1), Ext(1), Len(2);
+                                        * Semantics of Ext byte depend on
+                                        * command. Len is current or requested
+                                        * frame length, not including test
+                                        * header; sent little-endian.
+                                        */
+#define SDPCM_TEST_DISCARD     0x01    /* Receiver discards. Ext:pattern id. */
+#define SDPCM_TEST_ECHOREQ     0x02    /* Echo request. Ext:pattern id. */
+#define SDPCM_TEST_ECHORSP     0x03    /* Echo response. Ext:pattern id. */
+#define SDPCM_TEST_BURST       0x04    /*
+                                        * Receiver to send a burst.
+                                        * Ext is a frame count
+                                        */
+#define SDPCM_TEST_SEND                0x05    /*
+                                        * Receiver sets send mode.
+                                        * Ext is boolean on/off
+                                        */
+
+/* Handy macro for filling in datagen packets with a pattern */
+#define SDPCM_TEST_FILL(byteno, id)    ((u8)(id + byteno))
+
+/*
+ * Shared structure between dongle and the host.
+ * The structure contains pointers to trap or assert information.
+ */
+#define SDPCM_SHARED_VERSION       0x0002
+#define SDPCM_SHARED_VERSION_MASK  0x00FF
+#define SDPCM_SHARED_ASSERT_BUILT  0x0100
+#define SDPCM_SHARED_ASSERT        0x0200
+#define SDPCM_SHARED_TRAP          0x0400
+
+
 /* Space for header read, limit for data packets */
 #ifndef MAX_HDR_READ
 #define MAX_HDR_READ   32
 /* Flags for SDH calls */
 #define F2SYNC (SDIO_REQ_4BYTE | SDIO_REQ_FIXED)
 
+/* sbimstate */
+#define        SBIM_IBE                0x20000 /* inbanderror */
+#define        SBIM_TO                 0x40000 /* timeout */
+#define        SBIM_BY                 0x01800000      /* busy (sonics >= 2.3) */
+#define        SBIM_RJ                 0x02000000      /* reject (sonics >= 2.3) */
+
+/* sbtmstatelow */
+#define        SBTML_RESET             0x0001  /* reset */
+#define        SBTML_REJ_MASK          0x0006  /* reject field */
+#define        SBTML_REJ               0x0002  /* reject */
+#define        SBTML_TMPREJ            0x0004  /* temporary reject, for error recovery */
+
+#define        SBTML_SICF_SHIFT        16      /* Shift to locate the SI control flags in sbtml */
+
+/* sbtmstatehigh */
+#define        SBTMH_SERR              0x0001  /* serror */
+#define        SBTMH_INT               0x0002  /* interrupt */
+#define        SBTMH_BUSY              0x0004  /* busy */
+#define        SBTMH_TO                0x0020  /* timeout (sonics >= 2.3) */
+
+#define        SBTMH_SISF_SHIFT        16      /* Shift to locate the SI status flags in sbtmh */
+
+/* sbidlow */
+#define        SBIDL_INIT              0x80    /* initiator */
+
+/* sbidhigh */
+#define        SBIDH_RC_MASK           0x000f  /* revision code */
+#define        SBIDH_RCE_MASK          0x7000  /* revision code extension field */
+#define        SBIDH_RCE_SHIFT         8
+#define        SBCOREREV(sbidh) \
+       ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK))
+#define        SBIDH_CC_MASK           0x8ff0  /* core code */
+#define        SBIDH_CC_SHIFT          4
+#define        SBIDH_VC_MASK           0xffff0000      /* vendor code */
+#define        SBIDH_VC_SHIFT          16
+
 /*
  * Conversion of 802.1D priority to precedence level
  */
        (((prio) == PRIO_8021D_NONE || (prio) == PRIO_8021D_BE) ? \
        ((prio^2)) : (prio))
 
-DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep);
-extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
-                           uint len);
+BRCMF_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep);
+
+/* Core reg address translation */
+#define CORE_CC_REG(base, field)       (base + offsetof(chipcregs_t, field))
+#define CORE_BUS_REG(base, field) \
+               (base + offsetof(struct sdpcmd_regs, field))
+#define CORE_SB(base, field) \
+               (base + SBCONFIGOFF + offsetof(struct sbconfig, field))
+
+/* core registers */
+struct sdpcmd_regs {
+       u32 corecontrol;                /* 0x00, rev8 */
+       u32 corestatus;                 /* rev8 */
+       u32 PAD[1];
+       u32 biststatus;                 /* rev8 */
+
+       /* PCMCIA access */
+       u16 pcmciamesportaladdr;        /* 0x010, rev8 */
+       u16 PAD[1];
+       u16 pcmciamesportalmask;        /* rev8 */
+       u16 PAD[1];
+       u16 pcmciawrframebc;            /* rev8 */
+       u16 PAD[1];
+       u16 pcmciaunderflowtimer;       /* rev8 */
+       u16 PAD[1];
+
+       /* interrupt */
+       u32 intstatus;                  /* 0x020, rev8 */
+       u32 hostintmask;                /* rev8 */
+       u32 intmask;                    /* rev8 */
+       u32 sbintstatus;                /* rev8 */
+       u32 sbintmask;                  /* rev8 */
+       u32 funcintmask;                /* rev4 */
+       u32 PAD[2];
+       u32 tosbmailbox;                /* 0x040, rev8 */
+       u32 tohostmailbox;              /* rev8 */
+       u32 tosbmailboxdata;            /* rev8 */
+       u32 tohostmailboxdata;          /* rev8 */
+
+       /* synchronized access to registers in SDIO clock domain */
+       u32 sdioaccess;                 /* 0x050, rev8 */
+       u32 PAD[3];
+
+       /* PCMCIA frame control */
+       u8 pcmciaframectrl;             /* 0x060, rev8 */
+       u8 PAD[3];
+       u8 pcmciawatermark;             /* rev8 */
+       u8 PAD[155];
+
+       /* interrupt batching control */
+       u32 intrcvlazy;                 /* 0x100, rev8 */
+       u32 PAD[3];
+
+       /* counters */
+       u32 cmd52rd;                    /* 0x110, rev8 */
+       u32 cmd52wr;                    /* rev8 */
+       u32 cmd53rd;                    /* rev8 */
+       u32 cmd53wr;                    /* rev8 */
+       u32 abort;                      /* rev8 */
+       u32 datacrcerror;               /* rev8 */
+       u32 rdoutofsync;                /* rev8 */
+       u32 wroutofsync;                /* rev8 */
+       u32 writebusy;                  /* rev8 */
+       u32 readwait;                   /* rev8 */
+       u32 readterm;                   /* rev8 */
+       u32 writeterm;                  /* rev8 */
+       u32 PAD[40];
+       u32 clockctlstatus;             /* rev8 */
+       u32 PAD[7];
+
+       u32 PAD[128];                   /* DMA engines */
+
+       /* SDIO/PCMCIA CIS region */
+       char cis[512];                  /* 0x400-0x5ff, rev6 */
+
+       /* PCMCIA function control registers */
+       char pcmciafcr[256];            /* 0x600-6ff, rev6 */
+       u16 PAD[55];
+
+       /* PCMCIA backplane access */
+       u16 backplanecsr;               /* 0x76E, rev6 */
+       u16 backplaneaddr0;             /* rev6 */
+       u16 backplaneaddr1;             /* rev6 */
+       u16 backplaneaddr2;             /* rev6 */
+       u16 backplaneaddr3;             /* rev6 */
+       u16 backplanedata0;             /* rev6 */
+       u16 backplanedata1;             /* rev6 */
+       u16 backplanedata2;             /* rev6 */
+       u16 backplanedata3;             /* rev6 */
+       u16 PAD[31];
+
+       /* sprom "size" & "blank" info */
+       u16 spromstatus;                /* 0x7BE, rev2 */
+       u32 PAD[464];
+
+       u16 PAD[0x80];
+};
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
 /* Device console log buffer state */
-typedef struct dhd_console {
+struct dhd_console {
        uint count;             /* Poll interval msec counter */
        uint log_addr;          /* Log struct address (fixed) */
-       hndrte_log_t log;       /* Log struct (host copy) */
+       struct rte_log log;     /* Log struct (host copy) */
        uint bufsize;           /* Size of log buffer */
        u8 *buf;                /* Log buffer (host copy) */
        uint last;              /* Last buffer read index */
-} dhd_console_t;
-#endif                         /* DHD_DEBUG */
+};
+#endif                         /* BCMDBG */
+
+struct sdpcm_shared {
+       u32 flags;
+       u32 trap_addr;
+       u32 assert_exp_addr;
+       u32 assert_file_addr;
+       u32 assert_line;
+       u32 console_addr;       /* Address of struct rte_console */
+       u32 msgtrace_addr;
+       u8 tag[32];
+};
+
 
 /* misc chip info needed by some of the routines */
 struct chip_info {
@@ -177,16 +542,16 @@ struct chip_info {
 };
 
 /* Private data for SDIO bus interaction */
-typedef struct dhd_bus {
-       dhd_pub_t *dhd;
+struct brcmf_bus {
+       struct brcmf_pub *drvr;
 
-       bcmsdh_info_t *sdh;     /* Handle for BCMSDH calls */
+       struct brcmf_sdio_card *card;   /* Handle for sdio card calls */
        struct chip_info *ci;   /* Chip info struct */
        char *vars;             /* Variables (from CIS and/or other) */
        uint varsz;             /* Size of variables buffer */
        u32 sbaddr;             /* Current SB window pointer (-1, invalid) */
 
-       sdpcmd_regs_t *regs;    /* Registers for SDIO core */
+       struct sdpcmd_regs *regs;       /* SDIO core */
        uint sdpcmrev;          /* SDIO core revision */
        uint armrev;            /* CPU core revision */
        uint ramrev;            /* SOCRAM core revision */
@@ -199,10 +564,7 @@ typedef struct dhd_bus {
        bool dpc_sched;         /* Indicates DPC schedule (intrpt rcvd) */
        bool fcstate;           /* State of dongle flow-control */
 
-       u16 cl_devid;   /* cached devid for dhdsdio_probe_attach() */
-       char *fw_path;          /* module_param: path to firmware image */
-       char *nv_path;          /* module_param: path to nvram vars file */
-       const char *nvram_params;       /* user specified nvram params. */
+       u16 cl_devid;   /* cached devid for brcmf_sdio_probe_attach() */
 
        uint blocksize;         /* Block size of SDIO transfers */
        uint roundup;           /* Max roundup limit */
@@ -212,7 +574,7 @@ typedef struct dhd_bus {
        u8 tx_seq;              /* Transmit sequence number (next) */
        u8 tx_max;              /* Maximum transmit sequence allowed */
 
-       u8 hdrbuf[MAX_HDR_READ + DHD_SDALIGN];
+       u8 hdrbuf[MAX_HDR_READ + BRCMF_SDALIGN];
        u8 *rxhdr;              /* Header of current rx frame (in hdrbuf) */
        u16 nextlen;            /* Next Read Len from last header */
        u8 rx_seq;              /* Receive sequence number (expected) */
@@ -242,10 +604,10 @@ typedef struct dhd_bus {
        uint polltick;          /* Tick counter */
        uint pollcnt;           /* Count of active polls */
 
-#ifdef DHD_DEBUG
-       dhd_console_t console;  /* Console output polling support */
+#ifdef BCMDBG
+       struct dhd_console console;     /* Console output polling support */
        uint console_addr;      /* Console address from shared struct */
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
        uint regfails;          /* Count of R_REG/W_REG failures */
 
@@ -254,9 +616,7 @@ typedef struct dhd_bus {
        s32 idletime;           /* Control for activity timeout */
        s32 idlecount;  /* Activity timeout counter */
        s32 idleclock;  /* How to set bus driver when idle */
-       s32 sd_divisor; /* Speed control to bus driver */
-       s32 sd_mode;            /* Mode control to bus driver */
-       s32 sd_rxchain; /* If bcmsdh api accepts PKT chains */
+       s32 sd_rxchain;
        bool use_rxchain;       /* If dhd should use PKT chains */
        bool sleeping;          /* Is SDIO bus sleeping? */
        bool rxflow_mode;       /* Rx flow control mode */
@@ -314,7 +674,68 @@ typedef struct dhd_bus {
        u8 *ctrl_frame_buf;
        u32 ctrl_frame_len;
        bool ctrl_frame_stat;
-} dhd_bus_t;
+
+       spinlock_t txqlock;
+       wait_queue_head_t ctrl_wait;
+
+       struct timer_list timer;
+       struct completion watchdog_wait;
+       struct task_struct *watchdog_tsk;
+       bool wd_timer_valid;
+
+       struct tasklet_struct tasklet;
+       struct task_struct *dpc_tsk;
+       struct completion dpc_wait;
+
+       bool threads_only;
+       struct semaphore sdsem;
+       spinlock_t sdlock;
+
+       const char *fw_name;
+       const struct firmware *firmware;
+       const char *nv_name;
+       u32 fw_ptr;
+};
+
+struct sbconfig {
+       u32 PAD[2];
+       u32 sbipsflag;  /* initiator port ocp slave flag */
+       u32 PAD[3];
+       u32 sbtpsflag;  /* target port ocp slave flag */
+       u32 PAD[11];
+       u32 sbtmerrloga;        /* (sonics >= 2.3) */
+       u32 PAD;
+       u32 sbtmerrlog; /* (sonics >= 2.3) */
+       u32 PAD[3];
+       u32 sbadmatch3; /* address match3 */
+       u32 PAD;
+       u32 sbadmatch2; /* address match2 */
+       u32 PAD;
+       u32 sbadmatch1; /* address match1 */
+       u32 PAD[7];
+       u32 sbimstate;  /* initiator agent state */
+       u32 sbintvec;   /* interrupt mask */
+       u32 sbtmstatelow;       /* target state */
+       u32 sbtmstatehigh;      /* target state */
+       u32 sbbwa0;             /* bandwidth allocation table0 */
+       u32 PAD;
+       u32 sbimconfiglow;      /* initiator configuration */
+       u32 sbimconfighigh;     /* initiator configuration */
+       u32 sbadmatch0; /* address match0 */
+       u32 PAD;
+       u32 sbtmconfiglow;      /* target configuration */
+       u32 sbtmconfighigh;     /* target configuration */
+       u32 sbbconfig;  /* broadcast configuration */
+       u32 PAD;
+       u32 sbbstate;   /* broadcast state */
+       u32 PAD[3];
+       u32 sbactcnfg;  /* activate configuration */
+       u32 PAD[3];
+       u32 sbflagst;   /* current sbflags */
+       u32 PAD[3];
+       u32 sbidlow;            /* identification */
+       u32 sbidhigh;   /* identification */
+};
 
 /* clkstate */
 #define CLK_NONE       0
@@ -324,27 +745,43 @@ typedef struct dhd_bus {
 
 #define DHD_NOPMU(dhd) (false)
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
 static int qcount[NUMPRIO];
 static int tx_packets[NUMPRIO];
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
 /* Deferred transmit */
-const uint dhd_deferred_tx = 1;
+uint brcmf_deferred_tx = 1;
+module_param(brcmf_deferred_tx, uint, 0);
+
+/* Watchdog thread priority, -1 to use kernel timer */
+int brcmf_watchdog_prio = 97;
+module_param(brcmf_watchdog_prio, int, 0);
+
+/* Watchdog interval */
+uint brcmf_watchdog_ms = 10;
+module_param(brcmf_watchdog_ms, uint, 0);
+
+/* DPC thread priority, -1 to use tasklet */
+int brcmf_dpc_prio = 98;
+module_param(brcmf_dpc_prio, int, 0);
 
-extern uint dhd_watchdog_ms;
-extern void dhd_os_wd_timer(void *bus, uint wdtick);
+#ifdef BCMDBG
+/* Console poll interval */
+uint brcmf_console_ms;
+module_param(brcmf_console_ms, uint, 0);
+#endif         /* DHD_DEBUG */
 
 /* Tx/Rx bounds */
-uint dhd_txbound;
-uint dhd_rxbound;
+uint brcmf_txbound;
+uint brcmf_rxbound;
 uint dhd_txminmax;
 
 /* override the RAM size if possible */
 #define DONGLE_MIN_MEMSIZE (128 * 1024)
-int dhd_dongle_memsize;
+int brcmf_dongle_memsize;
 
-static bool dhd_alignctl;
+static bool brcmf_alignctl;
 
 static bool sd1idle;
 
@@ -352,7 +789,7 @@ static bool retrydata;
 #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata)
 
 static const uint watermark = 8;
-static const uint firstread = DHD_FIRSTREAD;
+static const uint firstread = BRCMF_FIRSTREAD;
 
 #define HDATLEN (firstread - (SDPCM_HDRLEN))
 
@@ -364,13 +801,6 @@ static bool forcealign;
 
 #define ALIGNMENT  4
 
-#if defined(OOB_INTR_ONLY) && defined(HW_OOB)
-extern void bcmsdh_enable_hw_oob_intr(void *sdh, bool enable);
-#endif
-
-#if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD)
-#error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD
-#endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */
 #define PKTALIGN(_p, _len, _align)                             \
        do {                                                            \
                uint datalign;                                          \
@@ -387,7 +817,7 @@ extern void bcmsdh_enable_hw_oob_intr(void *sdh, bool enable);
 static const uint max_roundup = 512;
 
 /* Try doing readahead */
-static bool dhd_readahead;
+static bool brcmf_readahead;
 
 /* To check if there's window offered */
 #define DATAOK(bus) \
@@ -401,7 +831,8 @@ do { \
        retryvar = 0; \
        do { \
                regvar = R_REG(regaddr); \
-       } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
+       } while (brcmf_sdcard_regfail(bus->card) && \
+                (++retryvar <= retry_limit)); \
        if (retryvar) { \
                bus->regfails += (retryvar-1); \
                if (retryvar > retry_limit) { \
@@ -417,7 +848,8 @@ do { \
        retryvar = 0; \
        do { \
                W_REG(regaddr, regval); \
-       } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
+       } while (brcmf_sdcard_regfail(bus->card) && \
+                (++retryvar <= retry_limit)); \
        if (retryvar) { \
                bus->regfails += (retryvar-1); \
                if (retryvar > retry_limit) \
@@ -433,100 +865,114 @@ do { \
 #define HOSTINTMASK            (I_HMB_SW_MASK | I_CHIPACTIVE)
 
 #ifdef SDTEST
-static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq);
-static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start);
+static void brcmf_sdbrcm_checkdied(struct brcmf_bus *bus, void *pkt, uint seq);
+static void brcmf_sdbrcm_sdtest_set(struct brcmf_bus *bus, bool start);
 #endif
 
-#ifdef DHD_DEBUG
-static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size);
-static int dhdsdio_mem_dump(dhd_bus_t *bus);
-#endif                         /* DHD_DEBUG  */
-static int dhdsdio_download_state(dhd_bus_t *bus, bool enter);
-
-static void dhdsdio_release(dhd_bus_t *bus);
-static void dhdsdio_release_malloc(dhd_bus_t *bus);
-static void dhdsdio_disconnect(void *ptr);
-static bool dhdsdio_chipmatch(u16 chipid);
-static bool dhdsdio_probe_attach(dhd_bus_t *bus, void *sdh,
+#ifdef BCMDBG
+static int brcmf_sdbrcm_bus_console_in(struct brcmf_pub *drvr,
+                                      unsigned char *msg, uint msglen);
+static int brcmf_sdbrcm_checkdied(struct brcmf_bus *bus, u8 *data, uint size);
+static int brcmf_sdbrcm_mem_dump(struct brcmf_bus *bus);
+#endif                         /* BCMDBG  */
+static int brcmf_sdbrcm_download_state(struct brcmf_bus *bus, bool enter);
+
+static void brcmf_sdbrcm_release(struct brcmf_bus *bus);
+static void brcmf_sdbrcm_release_malloc(struct brcmf_bus *bus);
+static void brcmf_sdbrcm_disconnect(void *ptr);
+static bool brcmf_sdbrcm_chipmatch(u16 chipid);
+static bool brcmf_sdbrcm_probe_attach(struct brcmf_bus *bus, void *card,
                                 void *regsva, u16 devid);
-static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh);
-static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh);
-static void dhdsdio_release_dongle(dhd_bus_t *bus);
+static bool brcmf_sdbrcm_probe_malloc(struct brcmf_bus *bus, void *card);
+static bool brcmf_sdbrcm_probe_init(struct brcmf_bus *bus, void *card);
+static void brcmf_sdbrcm_release_dongle(struct brcmf_bus *bus);
 
-static uint process_nvram_vars(char *varbuf, uint len);
+static uint brcmf_process_nvram_vars(char *varbuf, uint len);
 
-static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size);
-static int dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn,
+static void brcmf_sdbrcm_setmemsize(struct brcmf_bus *bus, int mem_size);
+static int brcmf_sdbrcm_send_buf(struct brcmf_bus *bus, u32 addr, uint fn,
                               uint flags, u8 *buf, uint nbytes,
-                              struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete,
+                              struct sk_buff *pkt,
+                              void (*complete)(void *handle, int status,
+                                                     bool sync_waiting),
                               void *handle);
 
-static bool dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh);
-static int _dhdsdio_download_firmware(struct dhd_bus *bus);
+static bool brcmf_sdbrcm_download_firmware(struct brcmf_bus *bus, void *card);
+static int  _brcmf_sdbrcm_download_firmware(struct brcmf_bus *bus);
 
-static int dhdsdio_download_code_file(struct dhd_bus *bus, char *image_path);
-static int dhdsdio_download_nvram(struct dhd_bus *bus);
-#ifdef BCMEMBEDIMAGE
-static int dhdsdio_download_code_array(struct dhd_bus *bus);
-#endif
-static void dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase);
-static int dhdsdio_chip_attach(struct dhd_bus *bus, void *regs);
-static void dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase);
-static void dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus,
+static int brcmf_sdbrcm_download_code_file(struct brcmf_bus *bus);
+static int brcmf_sdbrcm_download_nvram(struct brcmf_bus *bus);
+
+static void
+brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio_card *card, u32 corebase);
+
+static int brcmf_sdbrcm_chip_attach(struct brcmf_bus *bus, void *regs);
+
+static void
+brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio_card *card, u32 corebase);
+
+static void brcmf_sdbrcm_sdiod_drive_strength_init(struct brcmf_bus *bus,
                                        u32 drivestrength);
-static void dhdsdio_chip_detach(struct dhd_bus *bus);
+static void brcmf_sdbrcm_chip_detach(struct brcmf_bus *bus);
+static void brcmf_sdbrcm_wait_for_event(struct brcmf_bus *bus, bool *lockvar);
+static void brcmf_sdbrcm_wait_event_wakeup(struct brcmf_bus *bus);
+static void brcmf_sdbrcm_watchdog(unsigned long data);
+static int brcmf_sdbrcm_watchdog_thread(void *data);
+static int brcmf_sdbrcm_dpc_thread(void *data);
+static void brcmf_sdbrcm_dpc_tasklet(unsigned long data);
+static void brcmf_sdbrcm_sched_dpc(struct brcmf_bus *bus);
+static void brcmf_sdbrcm_sdlock(struct brcmf_bus *bus);
+static void brcmf_sdbrcm_sdunlock(struct brcmf_bus *bus);
+static int brcmf_sdbrcm_get_image(char *buf, int len, struct brcmf_bus *bus);
 
 /* Packet free applicable unconditionally for sdio and sdspi.
  * Conditional if bufpool was present for gspi bus.
  */
-static void dhdsdio_pktfree2(dhd_bus_t *bus, struct sk_buff *pkt)
+static void brcmf_sdbrcm_pktfree2(struct brcmf_bus *bus, struct sk_buff *pkt)
 {
-       dhd_os_sdlock_rxq(bus->dhd);
        if ((bus->bus != SPI_BUS) || bus->usebufpool)
-               bcm_pkt_buf_free_skb(pkt);
-       dhd_os_sdunlock_rxq(bus->dhd);
+               brcmu_pkt_buf_free_skb(pkt);
 }
 
-static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size)
+static void brcmf_sdbrcm_setmemsize(struct brcmf_bus *bus, int mem_size)
 {
        s32 min_size = DONGLE_MIN_MEMSIZE;
        /* Restrict the memsize to user specified limit */
        DHD_ERROR(("user: Restrict the dongle ram size to %d, min %d\n",
-               dhd_dongle_memsize, min_size));
-       if ((dhd_dongle_memsize > min_size) &&
-           (dhd_dongle_memsize < (s32) bus->orig_ramsize))
-               bus->ramsize = dhd_dongle_memsize;
+               brcmf_dongle_memsize, min_size));
+       if ((brcmf_dongle_memsize > min_size) &&
+           (brcmf_dongle_memsize < (s32) bus->orig_ramsize))
+               bus->ramsize = brcmf_dongle_memsize;
 }
 
-static int dhdsdio_set_siaddr_window(dhd_bus_t *bus, u32 address)
+static int brcmf_sdbrcm_set_siaddr_window(struct brcmf_bus *bus, u32 address)
 {
        int err = 0;
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW,
                         (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err);
        if (!err)
-               bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID,
+               brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1,
+                                SBSDIO_FUNC1_SBADDRMID,
                                 (address >> 16) & SBSDIO_SBADDRMID_MASK, &err);
        if (!err)
-               bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH,
-                                (address >> 24) & SBSDIO_SBADDRHIGH_MASK,
-                                &err);
+               brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1,
+                                      SBSDIO_FUNC1_SBADDRHIGH,
+                                      (address >> 24) & SBSDIO_SBADDRHIGH_MASK,
+                                      &err);
        return err;
 }
 
 /* Turn backplane clock on or off */
-static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
+static int brcmf_sdbrcm_htclk(struct brcmf_bus *bus, bool on, bool pendok)
 {
        int err;
        u8 clkctl, clkreq, devctl;
-       bcmsdh_info_t *sdh;
+       struct brcmf_sdio_card *card;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
-#if defined(OOB_INTR_ONLY)
-       pendok = false;
-#endif
        clkctl = 0;
-       sdh = bus->sdh;
+       card = bus->card;
 
        if (on) {
                /* Request HT Avail */
@@ -537,8 +983,8 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
                    && (bus->ci->chiprev == 0))
                        clkreq |= SBSDIO_FORCE_ALP;
 
-               bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                clkreq, &err);
+               brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                                      SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
                if (err) {
                        DHD_ERROR(("%s: HT Avail request error: %d\n",
                                   __func__, err));
@@ -552,9 +998,8 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
                }
 
                /* Check current status */
-               clkctl =
-                   bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                   &err);
+               clkctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                              SBSDIO_FUNC1_CHIPCLKCSR, &err);
                if (err) {
                        DHD_ERROR(("%s: HT Avail read error: %d\n",
                                   __func__, err));
@@ -564,9 +1009,8 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
                /* Go to pending and await interrupt if appropriate */
                if (!SBSDIO_CLKAV(clkctl, bus->alp_only) && pendok) {
                        /* Allow only clock-available interrupt */
-                       devctl =
-                           bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                           &err);
+                       devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                       SBSDIO_DEVICE_CTL, &err);
                        if (err) {
                                DHD_ERROR(("%s: Devctl error setting CA: %d\n",
                                        __func__, err));
@@ -574,8 +1018,8 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
                        }
 
                        devctl |= SBSDIO_DEVCTL_CA_INT_ONLY;
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                        devctl, &err);
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                                              SBSDIO_DEVICE_CTL, devctl, &err);
                        DHD_INFO(("CLKCTL: set PENDING\n"));
                        bus->clkstate = CLK_PENDING;
 
@@ -583,22 +1027,22 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
                } else if (bus->clkstate == CLK_PENDING) {
                        /* Cancel CA-only interrupt filter */
                        devctl =
-                           bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                           &err);
+                           brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                                 SBSDIO_DEVICE_CTL, &err);
                        devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                        devctl, &err);
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                               SBSDIO_DEVICE_CTL, devctl, &err);
                }
 
                /* Otherwise, wait here (polling) for HT Avail */
                if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) {
-                       SPINWAIT_SLEEP(sdioh_spinwait_sleep,
-                                      ((clkctl =
-                                        bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
-                                                SBSDIO_FUNC1_CHIPCLKCSR,
-                                                        &err)),
-                                       !SBSDIO_CLKAV(clkctl, bus->alp_only)),
-                                      PMU_MAX_TRANSITION_DLY);
+                       BRCMF_SPINWAIT_SLEEP(sdioh_spinwait_sleep,
+                              ((clkctl =
+                                brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                        SBSDIO_FUNC1_CHIPCLKCSR,
+                                                &err)),
+                               !SBSDIO_CLKAV(clkctl, bus->alp_only)),
+                              PMU_MAX_TRANSITION_DLY);
                }
                if (err) {
                        DHD_ERROR(("%s: HT Avail request error: %d\n",
@@ -615,21 +1059,14 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
                bus->clkstate = CLK_AVAIL;
                DHD_INFO(("CLKCTL: turned ON\n"));
 
-#if defined(DHD_DEBUG)
-               if (bus->alp_only == true) {
-#if !defined(BCMLXSDMMC)
-                       if (!SBSDIO_ALPONLY(clkctl)) {
-                               DHD_ERROR(("%s: HT Clock, when ALP Only\n",
-                                          __func__));
-                       }
-#endif                         /* !defined(BCMLXSDMMC) */
-               } else {
+#if defined(BCMDBG)
+               if (bus->alp_only != true) {
                        if (SBSDIO_ALPONLY(clkctl)) {
                                DHD_ERROR(("%s: HT Clock should be on.\n",
                                           __func__));
                        }
                }
-#endif                         /* defined (DHD_DEBUG) */
+#endif                         /* defined (BCMDBG) */
 
                bus->activity = true;
        } else {
@@ -637,17 +1074,16 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
 
                if (bus->clkstate == CLK_PENDING) {
                        /* Cancel CA-only interrupt filter */
-                       devctl =
-                           bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                           &err);
+                       devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                       SBSDIO_DEVICE_CTL, &err);
                        devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                        devctl, &err);
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                               SBSDIO_DEVICE_CTL, devctl, &err);
                }
 
                bus->clkstate = CLK_SDONLY;
-               bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                clkreq, &err);
+               brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                       SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
                DHD_INFO(("CLKCTL: turned OFF\n"));
                if (err) {
                        DHD_ERROR(("%s: Failed access turning clock off: %d\n",
@@ -659,105 +1095,31 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok)
 }
 
 /* Change idle/active SD state */
-static int dhdsdio_sdclk(dhd_bus_t *bus, bool on)
+static int brcmf_sdbrcm_sdclk(struct brcmf_bus *bus, bool on)
 {
-       int err;
-       s32 iovalue;
-
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       if (on) {
-               if (bus->idleclock == DHD_IDLE_STOP) {
-                       /* Turn on clock and restore mode */
-                       iovalue = 1;
-                       err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0,
-                                             &iovalue, sizeof(iovalue), true);
-                       if (err) {
-                               DHD_ERROR(("%s: error enabling sd_clock: %d\n",
-                                          __func__, err));
-                               return -EBADE;
-                       }
-
-                       iovalue = bus->sd_mode;
-                       err = bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0,
-                                             &iovalue, sizeof(iovalue), true);
-                       if (err) {
-                               DHD_ERROR(("%s: error changing sd_mode: %d\n",
-                                          __func__, err));
-                               return -EBADE;
-                       }
-               } else if (bus->idleclock != DHD_IDLE_ACTIVE) {
-                       /* Restore clock speed */
-                       iovalue = bus->sd_divisor;
-                       err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0,
-                                             &iovalue, sizeof(iovalue), true);
-                       if (err) {
-                               DHD_ERROR(("%s: error restoring sd_divisor: %d\n",
-                                       __func__, err));
-                               return -EBADE;
-                       }
-               }
+       if (on)
                bus->clkstate = CLK_SDONLY;
-       } else {
-               /* Stop or slow the SD clock itself */
-               if ((bus->sd_divisor == -1) || (bus->sd_mode == -1)) {
-                       DHD_TRACE(("%s: can't idle clock, divisor %d mode %d\n",
-                                  __func__, bus->sd_divisor, bus->sd_mode));
-                       return -EBADE;
-               }
-               if (bus->idleclock == DHD_IDLE_STOP) {
-                       if (sd1idle) {
-                               /* Change to SD1 mode and turn off clock */
-                               iovalue = 1;
-                               err =
-                                   bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL,
-                                                   0, &iovalue,
-                                                   sizeof(iovalue), true);
-                               if (err) {
-                                       DHD_ERROR(("%s: error changing sd_clock: %d\n",
-                                               __func__, err));
-                                       return -EBADE;
-                               }
-                       }
-
-                       iovalue = 0;
-                       err = bcmsdh_iovar_op(bus->sdh, "sd_clock", NULL, 0,
-                                             &iovalue, sizeof(iovalue), true);
-                       if (err) {
-                               DHD_ERROR(("%s: error disabling sd_clock: %d\n",
-                                          __func__, err));
-                               return -EBADE;
-                       }
-               } else if (bus->idleclock != DHD_IDLE_ACTIVE) {
-                       /* Set divisor to idle value */
-                       iovalue = bus->idleclock;
-                       err = bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0,
-                                             &iovalue, sizeof(iovalue), true);
-                       if (err) {
-                               DHD_ERROR(("%s: error changing sd_divisor: %d\n",
-                                       __func__, err));
-                               return -EBADE;
-                       }
-               }
+       else
                bus->clkstate = CLK_NONE;
-       }
 
        return 0;
 }
 
 /* Transition SD and backplane clock readiness */
-static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok)
+static int brcmf_sdbrcm_clkctl(struct brcmf_bus *bus, uint target, bool pendok)
 {
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        uint oldstate = bus->clkstate;
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
        /* Early exit if we're already there */
        if (bus->clkstate == target) {
                if (target == CLK_AVAIL) {
-                       dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
+                       brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms);
                        bus->activity = true;
                }
                return 0;
@@ -767,48 +1129,48 @@ static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok)
        case CLK_AVAIL:
                /* Make sure SD clock is available */
                if (bus->clkstate == CLK_NONE)
-                       dhdsdio_sdclk(bus, true);
+                       brcmf_sdbrcm_sdclk(bus, true);
                /* Now request HT Avail on the backplane */
-               dhdsdio_htclk(bus, true, pendok);
-               dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
+               brcmf_sdbrcm_htclk(bus, true, pendok);
+               brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms);
                bus->activity = true;
                break;
 
        case CLK_SDONLY:
                /* Remove HT request, or bring up SD clock */
                if (bus->clkstate == CLK_NONE)
-                       dhdsdio_sdclk(bus, true);
+                       brcmf_sdbrcm_sdclk(bus, true);
                else if (bus->clkstate == CLK_AVAIL)
-                       dhdsdio_htclk(bus, false, false);
+                       brcmf_sdbrcm_htclk(bus, false, false);
                else
-                       DHD_ERROR(("dhdsdio_clkctl: request for %d -> %d\n",
-                                  bus->clkstate, target));
-               dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
+                       DHD_ERROR(("brcmf_sdbrcm_clkctl: request for %d -> %d"
+                                  "\n", bus->clkstate, target));
+               brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms);
                break;
 
        case CLK_NONE:
                /* Make sure to remove HT request */
                if (bus->clkstate == CLK_AVAIL)
-                       dhdsdio_htclk(bus, false, false);
+                       brcmf_sdbrcm_htclk(bus, false, false);
                /* Now remove the SD clock */
-               dhdsdio_sdclk(bus, false);
-               dhd_os_wd_timer(bus->dhd, 0);
+               brcmf_sdbrcm_sdclk(bus, false);
+               brcmf_sdbrcm_wd_timer(bus, 0);
                break;
        }
-#ifdef DHD_DEBUG
-       DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate, bus->clkstate));
-#endif                         /* DHD_DEBUG */
+#ifdef BCMDBG
+       DHD_INFO(("brcmf_sdbrcm_clkctl: %d -> %d\n", oldstate, bus->clkstate));
+#endif                         /* BCMDBG */
 
        return 0;
 }
 
-int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep)
+int brcmf_sdbrcm_bussleep(struct brcmf_bus *bus, bool sleep)
 {
-       bcmsdh_info_t *sdh = bus->sdh;
-       sdpcmd_regs_t *regs = bus->regs;
+       struct brcmf_sdio_card *card = bus->card;
+       struct sdpcmd_regs *regs = bus->regs;
        uint retries = 0;
 
-       DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n",
+       DHD_INFO(("brcmf_sdbrcm_bussleep: request %s (currently %s)\n",
                  (sleep ? "SLEEP" : "WAKE"),
                  (bus->sleeping ? "SLEEP" : "WAKE")));
 
@@ -823,10 +1185,10 @@ int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep)
                        return -EBUSY;
 
                /* Disable SDIO interrupts (no longer interested) */
-               bcmsdh_intr_disable(bus->sdh);
+               brcmf_sdcard_intr_disable(bus->card);
 
                /* Make sure the controller has the bus up */
-               dhdsdio_clkctl(bus, CLK_AVAIL, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
 
                /* Tell device to start using OOB wakeup */
                W_SDREG(SMB_USE_OOB, &regs->tosbmailbox, retries);
@@ -834,16 +1196,18 @@ int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep)
                        DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
 
                /* Turn off our contribution to the HT clock request */
-               dhdsdio_clkctl(bus, CLK_SDONLY, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false);
 
-               bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                SBSDIO_FORCE_HW_CLKREQ_OFF, NULL);
+               brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                       SBSDIO_FUNC1_CHIPCLKCSR,
+                       SBSDIO_FORCE_HW_CLKREQ_OFF, NULL);
 
                /* Isolate the bus */
                if (bus->ci->chip != BCM4329_CHIP_ID
                    && bus->ci->chip != BCM4319_CHIP_ID) {
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                        SBSDIO_DEVCTL_PADS_ISO, NULL);
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                               SBSDIO_DEVICE_CTL,
+                               SBSDIO_DEVCTL_PADS_ISO, NULL);
                }
 
                /* Change state */
@@ -852,18 +1216,18 @@ int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep)
        } else {
                /* Waking up: bus power up is ok, set local state */
 
-               bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                0, NULL);
+               brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                       SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);
 
                /* Force pad isolation off if possible
                         (in case power never toggled) */
                if ((bus->ci->buscoretype == PCMCIA_CORE_ID)
                    && (bus->ci->buscorerev >= 10))
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, 0,
-                                        NULL);
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                               SBSDIO_DEVICE_CTL, 0, NULL);
 
                /* Make sure the controller has the bus up */
-               dhdsdio_clkctl(bus, CLK_AVAIL, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
 
                /* Send misc interrupt to indicate OOB not needed */
                W_SDREG(0, &regs->tosbmailboxdata, retries);
@@ -874,60 +1238,30 @@ int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep)
                        DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n"));
 
                /* Make sure we have SD bus access */
-               dhdsdio_clkctl(bus, CLK_SDONLY, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false);
 
                /* Change state */
                bus->sleeping = false;
 
                /* Enable interrupts again */
-               if (bus->intr && (bus->dhd->busstate == DHD_BUS_DATA)) {
+               if (bus->intr && (bus->drvr->busstate == DHD_BUS_DATA)) {
                        bus->intdis = false;
-                       bcmsdh_intr_enable(bus->sdh);
+                       brcmf_sdcard_intr_enable(bus->card);
                }
        }
 
        return 0;
 }
 
-#if defined(OOB_INTR_ONLY)
-void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable)
-{
-#if defined(HW_OOB)
-       bcmsdh_enable_hw_oob_intr(bus->sdh, enable);
-#else
-       sdpcmd_regs_t *regs = bus->regs;
-       uint retries = 0;
-
-       dhdsdio_clkctl(bus, CLK_AVAIL, false);
-       if (enable == true) {
-
-               /* Tell device to start using OOB wakeup */
-               W_SDREG(SMB_USE_OOB, &regs->tosbmailbox, retries);
-               if (retries > retry_limit)
-                       DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
-
-       } else {
-               /* Send misc interrupt to indicate OOB not needed */
-               W_SDREG(0, &regs->tosbmailboxdata, retries);
-               if (retries <= retry_limit)
-                       W_SDREG(SMB_DEV_INT, &regs->tosbmailbox, retries);
-       }
-
-       /* Turn off our contribution to the HT clock request */
-       dhdsdio_clkctl(bus, CLK_SDONLY, false);
-#endif                         /* !defined(HW_OOB) */
-}
-#endif                         /* defined(OOB_INTR_ONLY) */
-
 #define BUS_WAKE(bus) \
        do { \
                if ((bus)->sleeping) \
-                       dhdsdio_bussleep((bus), false); \
+                       brcmf_sdbrcm_bussleep((bus), false); \
        } while (0);
 
 /* Writes a HW/SW header into the packet and sends it. */
 /* Assumes: (a) header space already there, (b) caller holds lock */
-static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
+static int brcmf_sdbrcm_txpkt(struct brcmf_bus *bus, struct sk_buff *pkt, uint chan,
                         bool free_pkt)
 {
        int ret;
@@ -935,15 +1269,15 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
        u16 len, pad = 0;
        u32 swheader;
        uint retries = 0;
-       bcmsdh_info_t *sdh;
+       struct brcmf_sdio_card *card;
        struct sk_buff *new;
        int i;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       sdh = bus->sdh;
+       card = bus->card;
 
-       if (bus->dhd->dongle_reset) {
+       if (bus->drvr->dongle_reset) {
                ret = -EPERM;
                goto done;
        }
@@ -951,30 +1285,30 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
        frame = (u8 *) (pkt->data);
 
        /* Add alignment padding, allocate new packet if needed */
-       pad = ((unsigned long)frame % DHD_SDALIGN);
+       pad = ((unsigned long)frame % BRCMF_SDALIGN);
        if (pad) {
                if (skb_headroom(pkt) < pad) {
                        DHD_INFO(("%s: insufficient headroom %d for %d pad\n",
                                  __func__, skb_headroom(pkt), pad));
-                       bus->dhd->tx_realloc++;
-                       new = bcm_pkt_buf_get_skb(pkt->len + DHD_SDALIGN);
+                       bus->drvr->tx_realloc++;
+                       new = brcmu_pkt_buf_get_skb(pkt->len + BRCMF_SDALIGN);
                        if (!new) {
                                DHD_ERROR(("%s: couldn't allocate new %d-byte "
                                        "packet\n",
-                                       __func__, pkt->len + DHD_SDALIGN));
+                                       __func__, pkt->len + BRCMF_SDALIGN));
                                ret = -ENOMEM;
                                goto done;
                        }
 
-                       PKTALIGN(new, pkt->len, DHD_SDALIGN);
+                       PKTALIGN(new, pkt->len, BRCMF_SDALIGN);
                        memcpy(new->data, pkt->data, pkt->len);
                        if (free_pkt)
-                               bcm_pkt_buf_free_skb(pkt);
+                               brcmu_pkt_buf_free_skb(pkt);
                        /* free the pkt if canned one is not used */
                        free_pkt = true;
                        pkt = new;
                        frame = (u8 *) (pkt->data);
-                       ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0);
+                       ASSERT(((unsigned long)frame % BRCMF_SDALIGN) == 0);
                        pad = 0;
                } else {
                        skb_push(pkt, pad);
@@ -984,7 +1318,7 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
                        memset(frame, 0, pad + SDPCM_HDRLEN);
                }
        }
-       ASSERT(pad < DHD_SDALIGN);
+       ASSERT(pad < BRCMF_SDALIGN);
 
        /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
        len = (u16) (pkt->len);
@@ -1000,7 +1334,7 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
        put_unaligned_le32(swheader, frame + SDPCM_FRAMETAG_LEN);
        put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader));
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        tx_packets[pkt->priority]++;
        if (DHD_BYTES_ON() &&
            (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) ||
@@ -1018,31 +1352,19 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
        if (bus->roundup && bus->blocksize && (len > bus->blocksize)) {
                u16 pad = bus->blocksize - (len % bus->blocksize);
                if ((pad <= bus->roundup) && (pad < bus->blocksize))
-#ifdef NOTUSED
-                       if (pad <= skb_tailroom(pkt))
-#endif                         /* NOTUSED */
                                len += pad;
-       } else if (len % DHD_SDALIGN) {
-               len += DHD_SDALIGN - (len % DHD_SDALIGN);
+       } else if (len % BRCMF_SDALIGN) {
+               len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN);
        }
 
        /* Some controllers have trouble with odd bytes -- round to even */
        if (forcealign && (len & (ALIGNMENT - 1))) {
-#ifdef NOTUSED
-               if (skb_tailroom(pkt))
-#endif
                        len = roundup(len, ALIGNMENT);
-#ifdef NOTUSED
-               else
-                       DHD_ERROR(("%s: sending unrounded %d-byte packet\n",
-                                  __func__, len));
-#endif
        }
 
        do {
-               ret =
-                   dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
-                                       F2SYNC, frame, len, pkt, NULL, NULL);
+               ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(card),
+                       SDIO_FUNC_2, F2SYNC, frame, len, pkt, NULL, NULL);
                bus->f2txdata++;
                ASSERT(ret != -BCME_PENDING);
 
@@ -1053,18 +1375,18 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
                                "terminate frame.\n", __func__, ret));
                        bus->tx_sderrs++;
 
-                       bcmsdh_abort(sdh, SDIO_FUNC_2);
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1,
+                       brcmf_sdcard_abort(card, SDIO_FUNC_2);
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
                                         SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM,
                                         NULL);
                        bus->f1regdata++;
 
                        for (i = 0; i < 3; i++) {
                                u8 hi, lo;
-                               hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
+                               hi = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
                                                     SBSDIO_FUNC1_WFRAMEBCHI,
                                                     NULL);
-                               lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
+                               lo = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
                                                     SBSDIO_FUNC1_WFRAMEBCLO,
                                                     NULL);
                                bus->f1regdata += 2;
@@ -1081,17 +1403,17 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
 done:
        /* restore pkt buffer pointer before calling tx complete routine */
        skb_pull(pkt, SDPCM_HDRLEN + pad);
-       dhd_os_sdunlock(bus->dhd);
-       dhd_txcomplete(bus->dhd, pkt, ret != 0);
-       dhd_os_sdlock(bus->dhd);
+       brcmf_sdbrcm_sdunlock(bus);
+       brcmf_txcomplete(bus->drvr, pkt, ret != 0);
+       brcmf_sdbrcm_sdlock(bus);
 
        if (free_pkt)
-               bcm_pkt_buf_free_skb(pkt);
+               brcmu_pkt_buf_free_skb(pkt);
 
        return ret;
 }
 
-int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt)
+int brcmf_sdbrcm_bus_txdata(struct brcmf_bus *bus, struct sk_buff *pkt)
 {
        int ret = -EBADE;
        uint datalen, prec;
@@ -1122,7 +1444,7 @@ int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt)
 
        /* Check for existing queue, current flow-control,
                         pending event, or pending clock */
-       if (dhd_deferred_tx || bus->fcstate || pktq_len(&bus->txq)
+       if (brcmf_deferred_tx || bus->fcstate || pktq_len(&bus->txq)
            || bus->dpc_sched || (!DATAOK(bus))
            || (bus->flowcontrol & NBITVAL(prec))
            || (bus->clkstate != CLK_AVAIL)) {
@@ -1131,64 +1453,65 @@ int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt)
                bus->fcqueued++;
 
                /* Priority based enq */
-               dhd_os_sdlock_txq(bus->dhd);
-               if (dhd_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) {
+               spin_lock_bh(&bus->txqlock);
+               if (brcmf_c_prec_enq(bus->drvr, &bus->txq, pkt, prec) == false) {
                        skb_pull(pkt, SDPCM_HDRLEN);
-                       dhd_txcomplete(bus->dhd, pkt, false);
-                       bcm_pkt_buf_free_skb(pkt);
+                       brcmf_txcomplete(bus->drvr, pkt, false);
+                       brcmu_pkt_buf_free_skb(pkt);
                        DHD_ERROR(("%s: out of bus->txq !!!\n", __func__));
                        ret = -ENOSR;
                } else {
                        ret = 0;
                }
-               dhd_os_sdunlock_txq(bus->dhd);
+               spin_unlock_bh(&bus->txqlock);
 
                if (pktq_len(&bus->txq) >= TXHI)
-                       dhd_txflowcontrol(bus->dhd, 0, ON);
+                       brcmf_txflowcontrol(bus->drvr, 0, ON);
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                if (pktq_plen(&bus->txq, prec) > qcount[prec])
                        qcount[prec] = pktq_plen(&bus->txq, prec);
 #endif
                /* Schedule DPC if needed to send queued packet(s) */
-               if (dhd_deferred_tx && !bus->dpc_sched) {
+               if (brcmf_deferred_tx && !bus->dpc_sched) {
                        bus->dpc_sched = true;
-                       dhd_sched_dpc(bus->dhd);
+                       brcmf_sdbrcm_sched_dpc(bus);
                }
        } else {
                /* Lock: we're about to use shared data/code (and SDIO) */
-               dhd_os_sdlock(bus->dhd);
+               brcmf_sdbrcm_sdlock(bus);
 
                /* Otherwise, send it now */
                BUS_WAKE(bus);
                /* Make sure back plane ht clk is on, no pending allowed */
-               dhdsdio_clkctl(bus, CLK_AVAIL, true);
+               brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true);
 
 #ifndef SDTEST
                DHD_TRACE(("%s: calling txpkt\n", __func__));
-               ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true);
+               ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true);
 #else
-               ret = dhdsdio_txpkt(bus, pkt,
+               ret = brcmf_sdbrcm_txpkt(bus, pkt,
                                    (bus->ext_loop ? SDPCM_TEST_CHANNEL :
                                     SDPCM_DATA_CHANNEL), true);
 #endif
                if (ret)
-                       bus->dhd->tx_errors++;
+                       bus->drvr->tx_errors++;
                else
-                       bus->dhd->dstats.tx_bytes += datalen;
+                       bus->drvr->dstats.tx_bytes += datalen;
 
-               if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
+               if (bus->idletime == BRCMF_IDLE_IMMEDIATE &&
+                   !bus->dpc_sched) {
                        bus->activity = false;
-                       dhdsdio_clkctl(bus, CLK_NONE, true);
+                       brcmf_sdbrcm_clkctl(bus, CLK_NONE, true);
                }
 
-               dhd_os_sdunlock(bus->dhd);
+               brcmf_sdbrcm_sdunlock(bus);
        }
 
        return ret;
 }
 
-static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes)
+static uint brcmf_sdbrcm_sendfromq(struct brcmf_bus *bus, uint maxframes)
 {
        struct sk_buff *pkt;
        u32 intstatus = 0;
@@ -1198,8 +1521,8 @@ static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes)
        uint datalen;
        u8 tx_prec_map;
 
-       dhd_pub_t *dhd = bus->dhd;
-       sdpcmd_regs_t *regs = bus->regs;
+       struct brcmf_pub *drvr = bus->drvr;
+       struct sdpcmd_regs *regs = bus->regs;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
@@ -1207,33 +1530,33 @@ static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes)
 
        /* Send frames until the limit or some other event */
        for (cnt = 0; (cnt < maxframes) && DATAOK(bus); cnt++) {
-               dhd_os_sdlock_txq(bus->dhd);
-               pkt = bcm_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out);
+               spin_lock_bh(&bus->txqlock);
+               pkt = brcmu_pktq_mdeq(&bus->txq, tx_prec_map, &prec_out);
                if (pkt == NULL) {
-                       dhd_os_sdunlock_txq(bus->dhd);
+                       spin_unlock_bh(&bus->txqlock);
                        break;
                }
-               dhd_os_sdunlock_txq(bus->dhd);
+               spin_unlock_bh(&bus->txqlock);
                datalen = pkt->len - SDPCM_HDRLEN;
 
 #ifndef SDTEST
-               ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true);
+               ret = brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true);
 #else
-               ret = dhdsdio_txpkt(bus, pkt,
+               ret = brcmf_sdbrcm_txpkt(bus, pkt,
                                    (bus->ext_loop ? SDPCM_TEST_CHANNEL :
                                     SDPCM_DATA_CHANNEL), true);
 #endif
                if (ret)
-                       bus->dhd->tx_errors++;
+                       bus->drvr->tx_errors++;
                else
-                       bus->dhd->dstats.tx_bytes += datalen;
+                       bus->drvr->dstats.tx_bytes += datalen;
 
                /* In poll mode, need to check for other events */
                if (!bus->intr && cnt) {
                        /* Check device status, signal pending interrupt */
                        R_SDREG(intstatus, &regs->intstatus, retries);
                        bus->f2txdata++;
-                       if (bcmsdh_regfail(bus->sdh))
+                       if (brcmf_sdcard_regfail(bus->card))
                                break;
                        if (intstatus & bus->hostintmask)
                                bus->ipend = true;
@@ -1241,27 +1564,28 @@ static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes)
        }
 
        /* Deflow-control stack if needed */
-       if (dhd->up && (dhd->busstate == DHD_BUS_DATA) &&
-           dhd->txoff && (pktq_len(&bus->txq) < TXLOW))
-               dhd_txflowcontrol(dhd, 0, OFF);
+       if (drvr->up && (drvr->busstate == DHD_BUS_DATA) &&
+           drvr->txoff && (pktq_len(&bus->txq) < TXLOW))
+               brcmf_txflowcontrol(drvr, 0, OFF);
 
        return cnt;
 }
 
-int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
+int
+brcmf_sdbrcm_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint msglen)
 {
        u8 *frame;
        u16 len;
        u32 swheader;
        uint retries = 0;
-       bcmsdh_info_t *sdh = bus->sdh;
+       struct brcmf_sdio_card *card = bus->card;
        u8 doff = 0;
        int ret = -1;
        int i;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       if (bus->dhd->dongle_reset)
+       if (bus->drvr->dongle_reset)
                return -EIO;
 
        /* Back the pointer to make a room for bus header */
@@ -1269,15 +1593,15 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
        len = (msglen += SDPCM_HDRLEN);
 
        /* Add alignment padding (optional for ctl frames) */
-       if (dhd_alignctl) {
-               doff = ((unsigned long)frame % DHD_SDALIGN);
+       if (brcmf_alignctl) {
+               doff = ((unsigned long)frame % BRCMF_SDALIGN);
                if (doff) {
                        frame -= doff;
                        len += doff;
                        msglen += doff;
                        memset(frame, 0, doff + SDPCM_HDRLEN);
                }
-               ASSERT(doff < DHD_SDALIGN);
+               ASSERT(doff < BRCMF_SDALIGN);
        }
        doff += SDPCM_HDRLEN;
 
@@ -1286,8 +1610,8 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
                u16 pad = bus->blocksize - (len % bus->blocksize);
                if ((pad <= bus->roundup) && (pad < bus->blocksize))
                        len += pad;
-       } else if (len % DHD_SDALIGN) {
-               len += DHD_SDALIGN - (len % DHD_SDALIGN);
+       } else if (len % BRCMF_SDALIGN) {
+               len += BRCMF_SDALIGN - (len % BRCMF_SDALIGN);
        }
 
        /* Satisfy length-alignment requirements */
@@ -1297,12 +1621,12 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
        ASSERT(IS_ALIGNED((unsigned long)frame, 2));
 
        /* Need to lock here to protect txseq and SDIO tx calls */
-       dhd_os_sdlock(bus->dhd);
+       brcmf_sdbrcm_sdlock(bus);
 
        BUS_WAKE(bus);
 
        /* Make sure backplane clock is on */
-       dhdsdio_clkctl(bus, CLK_AVAIL, false);
+       brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
 
        /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
        *(u16 *) frame = cpu_to_le16((u16) msglen);
@@ -1325,7 +1649,7 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
                bus->ctrl_frame_buf = frame;
                bus->ctrl_frame_len = len;
 
-               dhd_wait_for_event(bus->dhd, &bus->ctrl_frame_stat);
+               brcmf_sdbrcm_wait_for_event(bus, &bus->ctrl_frame_stat);
 
                if (bus->ctrl_frame_stat == false) {
                        DHD_INFO(("%s: ctrl_frame_stat == false\n", __func__));
@@ -1337,7 +1661,7 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
        }
 
        if (ret == -1) {
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                if (DHD_BYTES_ON() && DHD_CTL_ON()) {
                        printk(KERN_DEBUG "Tx Frame:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
@@ -1351,10 +1675,9 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
 
                do {
                        bus->ctrl_frame_stat = false;
-                       ret =
-                           dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh),
-                                               SDIO_FUNC_2, F2SYNC, frame, len,
-                                               NULL, NULL, NULL);
+                       ret = brcmf_sdbrcm_send_buf(bus,
+                               brcmf_sdcard_cur_sbwad(card), SDIO_FUNC_2,
+                               F2SYNC, frame, len, NULL, NULL, NULL);
 
                        ASSERT(ret != -BCME_PENDING);
 
@@ -1365,21 +1688,23 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
                                        __func__, ret));
                                bus->tx_sderrs++;
 
-                               bcmsdh_abort(sdh, SDIO_FUNC_2);
+                               brcmf_sdcard_abort(card, SDIO_FUNC_2);
 
-                               bcmsdh_cfg_write(sdh, SDIO_FUNC_1,
+                               brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
                                                 SBSDIO_FUNC1_FRAMECTRL,
                                                 SFC_WF_TERM, NULL);
                                bus->f1regdata++;
 
                                for (i = 0; i < 3; i++) {
                                        u8 hi, lo;
-                                       hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
+                                       hi = brcmf_sdcard_cfg_read(card,
+                                            SDIO_FUNC_1,
                                             SBSDIO_FUNC1_WFRAMEBCHI,
                                             NULL);
-                                       lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
+                                       lo = brcmf_sdcard_cfg_read(card,
+                                            SDIO_FUNC_1,
                                             SBSDIO_FUNC1_WFRAMEBCLO,
-                                                            NULL);
+                                            NULL);
                                        bus->f1regdata += 2;
                                        if ((hi == 0) && (lo == 0))
                                                break;
@@ -1393,22 +1718,22 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
                } while ((ret < 0) && retries++ < TXRETRIES);
        }
 
-       if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
+       if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) {
                bus->activity = false;
-               dhdsdio_clkctl(bus, CLK_NONE, true);
+               brcmf_sdbrcm_clkctl(bus, CLK_NONE, true);
        }
 
-       dhd_os_sdunlock(bus->dhd);
+       brcmf_sdbrcm_sdunlock(bus);
 
        if (ret)
-               bus->dhd->tx_ctlerrs++;
+               bus->drvr->tx_ctlerrs++;
        else
-               bus->dhd->tx_ctlpkts++;
+               bus->drvr->tx_ctlpkts++;
 
        return ret ? -EIO : 0;
 }
 
-int dhd_bus_rxctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
+int brcmf_sdbrcm_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint msglen)
 {
        int timeleft;
        uint rxlen = 0;
@@ -1416,44 +1741,44 @@ int dhd_bus_rxctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       if (bus->dhd->dongle_reset)
+       if (bus->drvr->dongle_reset)
                return -EIO;
 
        /* Wait until control frame is available */
-       timeleft = dhd_os_ioctl_resp_wait(bus->dhd, &bus->rxlen, &pending);
+       timeleft = brcmf_os_ioctl_resp_wait(bus->drvr, &bus->rxlen, &pending);
 
-       dhd_os_sdlock(bus->dhd);
+       brcmf_sdbrcm_sdlock(bus);
        rxlen = bus->rxlen;
        memcpy(msg, bus->rxctl, min(msglen, rxlen));
        bus->rxlen = 0;
-       dhd_os_sdunlock(bus->dhd);
+       brcmf_sdbrcm_sdunlock(bus);
 
        if (rxlen) {
                DHD_CTL(("%s: resumed on rxctl frame, got %d expected %d\n",
                         __func__, rxlen, msglen));
        } else if (timeleft == 0) {
                DHD_ERROR(("%s: resumed on timeout\n", __func__));
-#ifdef DHD_DEBUG
-               dhd_os_sdlock(bus->dhd);
-               dhdsdio_checkdied(bus, NULL, 0);
-               dhd_os_sdunlock(bus->dhd);
+#ifdef BCMDBG
+               brcmf_sdbrcm_sdlock(bus);
+               brcmf_sdbrcm_checkdied(bus, NULL, 0);
+               brcmf_sdbrcm_sdunlock(bus);
 #endif                         /* DHD_DEBUG */
        } else if (pending == true) {
                DHD_CTL(("%s: cancelled\n", __func__));
                return -ERESTARTSYS;
        } else {
                DHD_CTL(("%s: resumed for unknown reason?\n", __func__));
-#ifdef DHD_DEBUG
-               dhd_os_sdlock(bus->dhd);
-               dhdsdio_checkdied(bus, NULL, 0);
-               dhd_os_sdunlock(bus->dhd);
+#ifdef BCMDBG
+               brcmf_sdbrcm_sdlock(bus);
+               brcmf_sdbrcm_checkdied(bus, NULL, 0);
+               brcmf_sdbrcm_sdunlock(bus);
 #endif                         /* DHD_DEBUG */
        }
 
        if (rxlen)
-               bus->dhd->rx_ctlpkts++;
+               bus->drvr->rx_ctlpkts++;
        else
-               bus->dhd->rx_ctlerrs++;
+               bus->drvr->rx_ctlerrs++;
 
        return rxlen ? (int)rxlen : -ETIMEDOUT;
 }
@@ -1467,8 +1792,10 @@ enum {
        IOV_SDCIS,
        IOV_MEMBYTES,
        IOV_MEMSIZE,
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        IOV_CHECKDIED,
+       IOV_CONS,
+       IOV_DCONSOLE_POLL,
 #endif
        IOV_DOWNLOAD,
        IOV_FORCEEVEN,
@@ -1491,10 +1818,11 @@ enum {
        IOV_IDLECLOCK,
        IOV_SD1IDLE,
        IOV_SLEEP,
+       IOV_WDTICK,
        IOV_VARS
 };
 
-const bcm_iovar_t dhdsdio_iovars[] = {
+const struct brcmu_iovar dhdsdio_iovars[] = {
        {"intr", IOV_INTR, 0, IOVT_BOOL, 0},
        {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0},
        {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0},
@@ -1511,12 +1839,17 @@ const bcm_iovar_t dhdsdio_iovars[] = {
        {"alignctl", IOV_ALIGNCTL, 0, IOVT_BOOL, 0},
        {"sdalign", IOV_SDALIGN, 0, IOVT_BOOL, 0},
        {"devreset", IOV_DEVRESET, 0, IOVT_BOOL, 0},
-#ifdef DHD_DEBUG
-       {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(sdreg_t)}
+       {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0},
+#ifdef BCMDBG
+       {"cons", IOV_CONS, 0, IOVT_BUFFER, 0}
+       ,
+       {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0}
        ,
-       {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(sdreg_t)}
+       {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
        ,
-       {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN}
+       {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
+       ,
+       {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, BRCMF_IOCTL_MAXLEN}
        ,
        {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0}
        ,
@@ -1528,15 +1861,13 @@ const bcm_iovar_t dhdsdio_iovars[] = {
        ,
        {"cpu", IOV_CPU, 0, IOVT_BOOL, 0}
        ,
-#ifdef DHD_DEBUG
        {"checkdied", IOV_CHECKDIED, 0, IOVT_BUFFER, 0}
        ,
-#endif                         /* DHD_DEBUG  */
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 #ifdef SDTEST
        {"extloop", IOV_EXTLOOP, 0, IOVT_BOOL, 0}
        ,
-       {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(dhd_pktgen_t)}
+       {"pktgen", IOV_PKTGEN, 0, IOVT_BUFFER, sizeof(struct brcmf_pktgen)}
        ,
 #endif                         /* SDTEST */
 
@@ -1544,122 +1875,122 @@ const bcm_iovar_t dhdsdio_iovars[] = {
 };
 
 static void
-dhd_dump_pct(struct bcmstrbuf *strbuf, char *desc, uint num, uint div)
+dhd_dump_pct(struct brcmu_strbuf *strbuf, char *desc, uint num, uint div)
 {
        uint q1, q2;
 
        if (!div) {
-               bcm_bprintf(strbuf, "%s N/A", desc);
+               brcmu_bprintf(strbuf, "%s N/A", desc);
        } else {
                q1 = num / div;
                q2 = (100 * (num - (q1 * div))) / div;
-               bcm_bprintf(strbuf, "%s %d.%02d", desc, q1, q2);
+               brcmu_bprintf(strbuf, "%s %d.%02d", desc, q1, q2);
        }
 }
 
-void dhd_bus_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf)
+void brcmf_sdbrcm_bus_dump(struct brcmf_pub *drvr, struct brcmu_strbuf *strbuf)
 {
-       dhd_bus_t *bus = dhdp->bus;
+       struct brcmf_bus *bus = drvr->bus;
 
-       bcm_bprintf(strbuf, "Bus SDIO structure:\n");
-       bcm_bprintf(strbuf,
+       brcmu_bprintf(strbuf, "Bus SDIO structure:\n");
+       brcmu_bprintf(strbuf,
                    "hostintmask 0x%08x intstatus 0x%08x sdpcm_ver %d\n",
                    bus->hostintmask, bus->intstatus, bus->sdpcm_ver);
-       bcm_bprintf(strbuf,
+       brcmu_bprintf(strbuf,
                    "fcstate %d qlen %d tx_seq %d, max %d, rxskip %d rxlen %d rx_seq %d\n",
                    bus->fcstate, pktq_len(&bus->txq), bus->tx_seq, bus->tx_max,
                    bus->rxskip, bus->rxlen, bus->rx_seq);
-       bcm_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n",
+       brcmu_bprintf(strbuf, "intr %d intrcount %d lastintrs %d spurious %d\n",
                    bus->intr, bus->intrcount, bus->lastintrs, bus->spurious);
-       bcm_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n",
+       brcmu_bprintf(strbuf, "pollrate %d pollcnt %d regfails %d\n",
                    bus->pollrate, bus->pollcnt, bus->regfails);
 
-       bcm_bprintf(strbuf, "\nAdditional counters:\n");
-       bcm_bprintf(strbuf,
+       brcmu_bprintf(strbuf, "\nAdditional counters:\n");
+       brcmu_bprintf(strbuf,
                    "tx_sderrs %d fcqueued %d rxrtx %d rx_toolong %d rxc_errors %d\n",
                    bus->tx_sderrs, bus->fcqueued, bus->rxrtx, bus->rx_toolong,
                    bus->rxc_errors);
-       bcm_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n",
+       brcmu_bprintf(strbuf, "rx_hdrfail %d badhdr %d badseq %d\n",
                    bus->rx_hdrfail, bus->rx_badhdr, bus->rx_badseq);
-       bcm_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n", bus->fc_rcvd,
-                   bus->fc_xoff, bus->fc_xon);
-       bcm_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n",
+       brcmu_bprintf(strbuf, "fc_rcvd %d, fc_xoff %d, fc_xon %d\n",
+                     bus->fc_rcvd, bus->fc_xoff, bus->fc_xon);
+       brcmu_bprintf(strbuf, "rxglomfail %d, rxglomframes %d, rxglompkts %d\n",
                    bus->rxglomfail, bus->rxglomframes, bus->rxglompkts);
-       bcm_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs %d\n",
-                   (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs,
-                   bus->f2rxdata, bus->f2txdata, bus->f1regdata);
+       brcmu_bprintf(strbuf, "f2rx (hdrs/data) %d (%d/%d), f2tx %d f1regs"
+                     " %d\n",
+                     (bus->f2rxhdrs + bus->f2rxdata), bus->f2rxhdrs,
+                     bus->f2rxdata, bus->f2txdata, bus->f1regdata);
        {
-               dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->dhd->rx_packets,
+               dhd_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->drvr->rx_packets,
                             (bus->f2rxhdrs + bus->f2rxdata));
-               dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets,
+               dhd_dump_pct(strbuf, ", pkts/f1sd", bus->drvr->rx_packets,
                             bus->f1regdata);
-               dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets,
+               dhd_dump_pct(strbuf, ", pkts/sd", bus->drvr->rx_packets,
                             (bus->f2rxhdrs + bus->f2rxdata + bus->f1regdata));
-               dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->rx_packets,
+               dhd_dump_pct(strbuf, ", pkts/int", bus->drvr->rx_packets,
                             bus->intrcount);
-               bcm_bprintf(strbuf, "\n");
+               brcmu_bprintf(strbuf, "\n");
 
                dhd_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts),
-                            bus->dhd->rx_packets);
+                            bus->drvr->rx_packets);
                dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts,
                             bus->rxglomframes);
-               bcm_bprintf(strbuf, "\n");
+               brcmu_bprintf(strbuf, "\n");
 
-               dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->dhd->tx_packets,
+               dhd_dump_pct(strbuf, "Tx: pkts/f2wr", bus->drvr->tx_packets,
                             bus->f2txdata);
-               dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets,
+               dhd_dump_pct(strbuf, ", pkts/f1sd", bus->drvr->tx_packets,
                             bus->f1regdata);
-               dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets,
+               dhd_dump_pct(strbuf, ", pkts/sd", bus->drvr->tx_packets,
                             (bus->f2txdata + bus->f1regdata));
-               dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets,
+               dhd_dump_pct(strbuf, ", pkts/int", bus->drvr->tx_packets,
                             bus->intrcount);
-               bcm_bprintf(strbuf, "\n");
+               brcmu_bprintf(strbuf, "\n");
 
                dhd_dump_pct(strbuf, "Total: pkts/f2rw",
-                            (bus->dhd->tx_packets + bus->dhd->rx_packets),
+                            (bus->drvr->tx_packets + bus->drvr->rx_packets),
                             (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata));
                dhd_dump_pct(strbuf, ", pkts/f1sd",
-                            (bus->dhd->tx_packets + bus->dhd->rx_packets),
+                            (bus->drvr->tx_packets + bus->drvr->rx_packets),
                             bus->f1regdata);
                dhd_dump_pct(strbuf, ", pkts/sd",
-                            (bus->dhd->tx_packets + bus->dhd->rx_packets),
+                            (bus->drvr->tx_packets + bus->drvr->rx_packets),
                             (bus->f2txdata + bus->f2rxhdrs + bus->f2rxdata +
                              bus->f1regdata));
                dhd_dump_pct(strbuf, ", pkts/int",
-                            (bus->dhd->tx_packets + bus->dhd->rx_packets),
+                            (bus->drvr->tx_packets + bus->drvr->rx_packets),
                             bus->intrcount);
-               bcm_bprintf(strbuf, "\n\n");
+               brcmu_bprintf(strbuf, "\n\n");
        }
 
 #ifdef SDTEST
        if (bus->pktgen_count) {
-               bcm_bprintf(strbuf, "pktgen config and count:\n");
-               bcm_bprintf(strbuf,
+               brcmu_bprintf(strbuf, "pktgen config and count:\n");
+               brcmu_bprintf(strbuf,
                            "freq %d count %d print %d total %d min %d len %d\n",
                            bus->pktgen_freq, bus->pktgen_count,
                            bus->pktgen_print, bus->pktgen_total,
                            bus->pktgen_minlen, bus->pktgen_maxlen);
-               bcm_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n",
+               brcmu_bprintf(strbuf, "send attempts %d rcvd %d fail %d\n",
                            bus->pktgen_sent, bus->pktgen_rcvd,
                            bus->pktgen_fail);
        }
 #endif                         /* SDTEST */
-#ifdef DHD_DEBUG
-       bcm_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n",
-                   bus->dpc_sched,
-                   (bcmsdh_intr_pending(bus->sdh) ? " " : " not "));
-       bcm_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize,
+#ifdef BCMDBG
+       brcmu_bprintf(strbuf, "dpc_sched %d host interrupt%spending\n",
+                     bus->dpc_sched, " not ");
+       brcmu_bprintf(strbuf, "blocksize %d roundup %d\n", bus->blocksize,
                    bus->roundup);
-#endif                         /* DHD_DEBUG */
-       bcm_bprintf(strbuf,
+#endif                         /* BCMDBG */
+       brcmu_bprintf(strbuf,
                    "clkstate %d activity %d idletime %d idlecount %d sleeping %d\n",
                    bus->clkstate, bus->activity, bus->idletime, bus->idlecount,
                    bus->sleeping);
 }
 
-void dhd_bus_clearcounts(dhd_pub_t *dhdp)
+void brcmf_bus_clearcounts(struct brcmf_pub *drvr)
 {
-       dhd_bus_t *bus = (dhd_bus_t *) dhdp->bus;
+       struct brcmf_bus *bus = (struct brcmf_bus *) drvr->bus;
 
        bus->intrcount = bus->lastintrs = bus->spurious = bus->regfails = 0;
        bus->rxrtx = bus->rx_toolong = bus->rxc_errors = 0;
@@ -1670,11 +2001,11 @@ void dhd_bus_clearcounts(dhd_pub_t *dhdp)
 }
 
 #ifdef SDTEST
-static int dhdsdio_pktgen_get(dhd_bus_t *bus, u8 *arg)
+static int brcmf_sdbrcm_pktgen_get(struct brcmf_bus *bus, u8 *arg)
 {
-       dhd_pktgen_t pktgen;
+       struct brcmf_pktgen pktgen;
 
-       pktgen.version = DHD_PKTGEN_VERSION;
+       pktgen.version = BRCMF_PKTGEN_VERSION;
        pktgen.freq = bus->pktgen_freq;
        pktgen.count = bus->pktgen_count;
        pktgen.print = bus->pktgen_print;
@@ -1692,13 +2023,13 @@ static int dhdsdio_pktgen_get(dhd_bus_t *bus, u8 *arg)
        return 0;
 }
 
-static int dhdsdio_pktgen_set(dhd_bus_t *bus, u8 *arg)
+static int brcmf_sdbrcm_pktgen_set(struct brcmf_bus *bus, u8 *arg)
 {
-       dhd_pktgen_t pktgen;
+       struct brcmf_pktgen pktgen;
        uint oldcnt, oldmode;
 
        memcpy(&pktgen, arg, sizeof(pktgen));
-       if (pktgen.version != DHD_PKTGEN_VERSION)
+       if (pktgen.version != BRCMF_PKTGEN_VERSION)
                return -EINVAL;
 
        oldcnt = bus->pktgen_count;
@@ -1726,7 +2057,7 @@ static int dhdsdio_pktgen_set(dhd_bus_t *bus, u8 *arg)
 #endif                         /* SDTEST */
 
 static int
-dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data,
+brcmf_sdbrcm_membytes(struct brcmf_bus *bus, bool write, u32 address, u8 *data,
                 uint size)
 {
        int bcmerror = 0;
@@ -1741,7 +2072,7 @@ dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data,
                dsize = size;
 
        /* Set the backplane window to include the start address */
-       bcmerror = dhdsdio_set_siaddr_window(bus, address);
+       bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address);
        if (bcmerror) {
                DHD_ERROR(("%s: window change failed\n", __func__));
                goto xfer_done;
@@ -1753,7 +2084,7 @@ dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data,
                          __func__, (write ? "write" : "read"), dsize,
                          sdaddr, (address & SBSDIO_SBWINDOW_MASK)));
                bcmerror =
-                    bcmsdh_rwdata(bus->sdh, write, sdaddr, data, dsize);
+                    brcmf_sdcard_rwdata(bus->card, write, sdaddr, data, dsize);
                if (bcmerror) {
                        DHD_ERROR(("%s: membytes transfer failed\n", __func__));
                        break;
@@ -1764,7 +2095,7 @@ dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data,
                if (size) {
                        data += dsize;
                        address += dsize;
-                       bcmerror = dhdsdio_set_siaddr_window(bus, address);
+                       bcmerror = brcmf_sdbrcm_set_siaddr_window(bus, address);
                        if (bcmerror) {
                                DHD_ERROR(("%s: window change failed\n",
                                           __func__));
@@ -1777,23 +2108,25 @@ dhdsdio_membytes(dhd_bus_t *bus, bool write, u32 address, u8 *data,
 
 xfer_done:
        /* Return the window to backplane enumeration space for core access */
-       if (dhdsdio_set_siaddr_window(bus, bcmsdh_cur_sbwad(bus->sdh))) {
+       if (brcmf_sdbrcm_set_siaddr_window(bus,
+                                          brcmf_sdcard_cur_sbwad(bus->card))) {
                DHD_ERROR(("%s: FAILED to set window back to 0x%x\n",
-                          __func__, bcmsdh_cur_sbwad(bus->sdh)));
+                          __func__, brcmf_sdcard_cur_sbwad(bus->card)));
        }
 
        return bcmerror;
 }
 
-#ifdef DHD_DEBUG
-static int dhdsdio_readshared(dhd_bus_t *bus, sdpcm_shared_t *sh)
+#ifdef BCMDBG
+static int brcmf_sdbrcm_readshared(struct brcmf_bus *bus, struct sdpcm_shared *sh)
 {
        u32 addr;
        int rv;
 
        /* Read last word in memory to determine address of
                         sdpcm_shared structure */
-       rv = dhdsdio_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr, 4);
+       rv = brcmf_sdbrcm_membytes(bus, false, bus->ramsize - 4, (u8 *)&addr,
+                                  4);
        if (rv < 0)
                return rv;
 
@@ -1811,9 +2144,9 @@ static int dhdsdio_readshared(dhd_bus_t *bus, sdpcm_shared_t *sh)
                return -EBADE;
        }
 
-       /* Read hndrte_shared structure */
-       rv = dhdsdio_membytes(bus, false, addr, (u8 *) sh,
-                             sizeof(sdpcm_shared_t));
+       /* Read rte_shared structure */
+       rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *) sh,
+                             sizeof(struct sdpcm_shared));
        if (rv < 0)
                return rv;
 
@@ -1837,16 +2170,16 @@ static int dhdsdio_readshared(dhd_bus_t *bus, sdpcm_shared_t *sh)
        return 0;
 }
 
-static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size)
+static int brcmf_sdbrcm_checkdied(struct brcmf_bus *bus, u8 *data, uint size)
 {
        int bcmerror = 0;
        uint msize = 512;
        char *mbuffer = NULL;
        uint maxstrlen = 256;
        char *str = NULL;
-       trap_t tr;
-       sdpcm_shared_t sdpcm_shared;
-       struct bcmstrbuf strbuf;
+       struct brcmf_trap tr;
+       struct sdpcm_shared sdpcm_shared;
+       struct brcmu_strbuf strbuf;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
@@ -1872,13 +2205,13 @@ static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size)
                goto done;
        }
 
-       bcmerror = dhdsdio_readshared(bus, &sdpcm_shared);
+       bcmerror = brcmf_sdbrcm_readshared(bus, &sdpcm_shared);
        if (bcmerror < 0)
                goto done;
 
-       bcm_binit(&strbuf, data, size);
+       brcmu_binit(&strbuf, data, size);
 
-       bcm_bprintf(&strbuf,
+       brcmu_bprintf(&strbuf,
                    "msgtrace address : 0x%08X\nconsole address  : 0x%08X\n",
                    sdpcm_shared.msgtrace_addr, sdpcm_shared.console_addr);
 
@@ -1887,7 +2220,7 @@ static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size)
                 * (Avoids conflict with real asserts for programmatic
                 * parsing of output.)
                 */
-               bcm_bprintf(&strbuf, "Assrt not built in dongle\n");
+               brcmu_bprintf(&strbuf, "Assrt not built in dongle\n");
        }
 
        if ((sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP)) ==
@@ -1896,49 +2229,49 @@ static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size)
                 * (Avoids conflict with real asserts for programmatic
                 * parsing of output.)
                 */
-               bcm_bprintf(&strbuf, "No trap%s in dongle",
+               brcmu_bprintf(&strbuf, "No trap%s in dongle",
                            (sdpcm_shared.flags & SDPCM_SHARED_ASSERT_BUILT)
                            ? "/assrt" : "");
        } else {
                if (sdpcm_shared.flags & SDPCM_SHARED_ASSERT) {
                        /* Download assert */
-                       bcm_bprintf(&strbuf, "Dongle assert");
+                       brcmu_bprintf(&strbuf, "Dongle assert");
                        if (sdpcm_shared.assert_exp_addr != 0) {
                                str[0] = '\0';
-                               bcmerror = dhdsdio_membytes(bus, false,
+                               bcmerror = brcmf_sdbrcm_membytes(bus, false,
                                                sdpcm_shared.assert_exp_addr,
                                                (u8 *) str, maxstrlen);
                                if (bcmerror < 0)
                                        goto done;
 
                                str[maxstrlen - 1] = '\0';
-                               bcm_bprintf(&strbuf, " expr \"%s\"", str);
+                               brcmu_bprintf(&strbuf, " expr \"%s\"", str);
                        }
 
                        if (sdpcm_shared.assert_file_addr != 0) {
                                str[0] = '\0';
-                               bcmerror = dhdsdio_membytes(bus, false,
+                               bcmerror = brcmf_sdbrcm_membytes(bus, false,
                                                sdpcm_shared.assert_file_addr,
                                                (u8 *) str, maxstrlen);
                                if (bcmerror < 0)
                                        goto done;
 
                                str[maxstrlen - 1] = '\0';
-                               bcm_bprintf(&strbuf, " file \"%s\"", str);
+                               brcmu_bprintf(&strbuf, " file \"%s\"", str);
                        }
 
-                       bcm_bprintf(&strbuf, " line %d ",
+                       brcmu_bprintf(&strbuf, " line %d ",
                                    sdpcm_shared.assert_line);
                }
 
                if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) {
-                       bcmerror = dhdsdio_membytes(bus, false,
+                       bcmerror = brcmf_sdbrcm_membytes(bus, false,
                                        sdpcm_shared.trap_addr, (u8 *)&tr,
-                                       sizeof(trap_t));
+                                       sizeof(struct brcmf_trap));
                        if (bcmerror < 0)
                                goto done;
 
-                       bcm_bprintf(&strbuf,
+                       brcmu_bprintf(&strbuf,
                                    "Dongle trap type 0x%x @ epc 0x%x, cpsr 0x%x, spsr 0x%x, sp 0x%x,"
                                    "lp 0x%x, rpc 0x%x Trap offset 0x%x, "
                                    "r0 0x%x, r1 0x%x, r2 0x%x, r3 0x%x, r4 0x%x, r5 0x%x, r6 0x%x, r7 0x%x\n",
@@ -1952,12 +2285,12 @@ static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size)
        if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP))
                DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf));
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        if (sdpcm_shared.flags & SDPCM_SHARED_TRAP) {
                /* Mem dump to a file on device */
-               dhdsdio_mem_dump(bus);
+               brcmf_sdbrcm_mem_dump(bus);
        }
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
 done:
        kfree(mbuffer);
@@ -1966,7 +2299,7 @@ done:
        return bcmerror;
 }
 
-static int dhdsdio_mem_dump(dhd_bus_t *bus)
+static int brcmf_sdbrcm_mem_dump(struct brcmf_bus *bus)
 {
        int ret = 0;
        int size;               /* Full mem size */
@@ -1987,7 +2320,8 @@ static int dhdsdio_mem_dump(dhd_bus_t *bus)
        databuf = buf;
        while (size) {
                read_size = min(MEMBLOCK, size);
-               ret = dhdsdio_membytes(bus, false, start, databuf, read_size);
+               ret = brcmf_sdbrcm_membytes(bus, false, start, databuf,
+                                         read_size);
                if (ret) {
                        DHD_ERROR(("%s: Error membytes %d\n", __func__, ret));
                        kfree(buf);
@@ -2003,20 +2337,20 @@ static int dhdsdio_mem_dump(dhd_bus_t *bus)
        printk(KERN_DEBUG "Done\n");
 
        /* free buf before return !!! */
-       if (write_to_file(bus->dhd, buf, bus->ramsize)) {
+       if (brcmf_write_to_file(bus->drvr, buf, bus->ramsize)) {
                DHD_ERROR(("%s: Error writing to files\n", __func__));
                return -1;
        }
 
-       /* buf free handled in write_to_file, not here */
+       /* buf free handled in brcmf_write_to_file, not here */
        return 0;
 }
 
 #define CONSOLE_LINE_MAX       192
 
-static int dhdsdio_readconsole(dhd_bus_t *bus)
+static int brcmf_sdbrcm_readconsole(struct brcmf_bus *bus)
 {
-       dhd_console_t *c = &bus->console;
+       struct dhd_console *c = &bus->console;
        u8 line[CONSOLE_LINE_MAX], ch;
        u32 n, idx, addr;
        int rv;
@@ -2026,8 +2360,8 @@ static int dhdsdio_readconsole(dhd_bus_t *bus)
                return 0;
 
        /* Read console log struct */
-       addr = bus->console_addr + offsetof(hndrte_cons_t, log);
-       rv = dhdsdio_membytes(bus, false, addr, (u8 *)&c->log,
+       addr = bus->console_addr + offsetof(struct rte_console, log);
+       rv = brcmf_sdbrcm_membytes(bus, false, addr, (u8 *)&c->log,
                                sizeof(c->log));
        if (rv < 0)
                return rv;
@@ -2053,7 +2387,7 @@ static int dhdsdio_readconsole(dhd_bus_t *bus)
 
        /* Read the console buffer */
        addr = le32_to_cpu(c->log.buf);
-       rv = dhdsdio_membytes(bus, false, addr, c->buf, c->bufsize);
+       rv = brcmf_sdbrcm_membytes(bus, false, addr, c->buf, c->bufsize);
        if (rv < 0)
                return rv;
 
@@ -2089,16 +2423,16 @@ break2:
 
        return 0;
 }
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
-int dhdsdio_downloadvars(dhd_bus_t *bus, void *arg, int len)
+int brcmf_sdbrcm_downloadvars(struct brcmf_bus *bus, void *arg, int len)
 {
        int bcmerror = 0;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
        /* Basic sanity checks */
-       if (bus->dhd->up) {
+       if (bus->drvr->up) {
                bcmerror = -EISCONN;
                goto err;
        }
@@ -2125,7 +2459,7 @@ err:
 }
 
 static int
-dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
+brcmf_sdbrcm_doiovar(struct brcmf_bus *bus, const struct brcmu_iovar *vi, u32 actionid,
                const char *name, void *params, int plen, void *arg, int len,
                int val_size)
 {
@@ -2137,7 +2471,7 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                "len %d val_size %d\n",
                __func__, actionid, name, params, plen, arg, len, val_size));
 
-       bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid));
+       bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid));
        if (bcmerror != 0)
                goto exit;
 
@@ -2147,10 +2481,10 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
        bool_val = (int_val != 0) ? true : false;
 
        /* Some ioctls use the bus */
-       dhd_os_sdlock(bus->dhd);
+       brcmf_sdbrcm_sdlock(bus);
 
        /* Check if dongle is in reset. If so, only allow DEVRESET iovars */
-       if (bus->dhd->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) ||
+       if (bus->drvr->dongle_reset && !(actionid == IOV_SVAL(IOV_DEVRESET) ||
                                        actionid == IOV_GVAL(IOV_DEVRESET))) {
                bcmerror = -EPERM;
                goto exit;
@@ -2159,7 +2493,7 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
        /* Handle sleep stuff before any clock mucking */
        if (vi->varid == IOV_SLEEP) {
                if (IOV_ISSET(actionid)) {
-                       bcmerror = dhdsdio_bussleep(bus, bool_val);
+                       bcmerror = brcmf_sdbrcm_bussleep(bus, bool_val);
                } else {
                        int_val = (s32) bus->sleeping;
                        memcpy(arg, &int_val, val_size);
@@ -2168,9 +2502,9 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
        }
 
        /* Request clock to allow SDIO accesses */
-       if (!bus->dhd->dongle_reset) {
+       if (!bus->drvr->dongle_reset) {
                BUS_WAKE(bus);
-               dhdsdio_clkctl(bus, CLK_AVAIL, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
        }
 
        switch (actionid) {
@@ -2182,15 +2516,15 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
        case IOV_SVAL(IOV_INTR):
                bus->intr = bool_val;
                bus->intdis = false;
-               if (bus->dhd->up) {
+               if (bus->drvr->up) {
                        if (bus->intr) {
                                DHD_INTR(("%s: enable SDIO device interrupts\n",
                                          __func__));
-                               bcmsdh_intr_enable(bus->sdh);
+                               brcmf_sdcard_intr_enable(bus->card);
                        } else {
                                DHD_INTR(("%s: disable SDIO interrupts\n",
                                          __func__));
-                               bcmsdh_intr_disable(bus->sdh);
+                               brcmf_sdcard_intr_disable(bus->card);
                        }
                }
                break;
@@ -2211,7 +2545,7 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                break;
 
        case IOV_SVAL(IOV_IDLETIME):
-               if ((int_val < 0) && (int_val != DHD_IDLE_IMMEDIATE))
+               if ((int_val < 0) && (int_val != BRCMF_IDLE_IMMEDIATE))
                        bcmerror = -EINVAL;
                else
                        bus->idletime = int_val;
@@ -2283,8 +2617,8 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                            2 * sizeof(int) : (u8 *) arg;
 
                        /* Call to do the transfer */
-                       bcmerror =
-                           dhdsdio_membytes(bus, set, address, data, size);
+                       bcmerror = brcmf_sdbrcm_membytes(bus, set, address,
+                                                        data, size);
 
                        break;
                }
@@ -2295,33 +2629,33 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                break;
 
        case IOV_GVAL(IOV_SDIOD_DRIVE):
-               int_val = (s32) dhd_sdiod_drive_strength;
+               int_val = (s32) brcmf_sdiod_drive_strength;
                memcpy(arg, &int_val, val_size);
                break;
 
        case IOV_SVAL(IOV_SDIOD_DRIVE):
-               dhd_sdiod_drive_strength = int_val;
-               dhdsdio_sdiod_drive_strength_init(bus,
-                                            dhd_sdiod_drive_strength);
+               brcmf_sdiod_drive_strength = int_val;
+               brcmf_sdbrcm_sdiod_drive_strength_init(bus,
+                                            brcmf_sdiod_drive_strength);
                break;
 
        case IOV_SVAL(IOV_DOWNLOAD):
-               bcmerror = dhdsdio_download_state(bus, bool_val);
+               bcmerror = brcmf_sdbrcm_download_state(bus, bool_val);
                break;
 
        case IOV_SVAL(IOV_VARS):
-               bcmerror = dhdsdio_downloadvars(bus, arg, len);
+               bcmerror = brcmf_sdbrcm_downloadvars(bus, arg, len);
                break;
 
        case IOV_GVAL(IOV_READAHEAD):
-               int_val = (s32) dhd_readahead;
+               int_val = (s32) brcmf_readahead;
                memcpy(arg, &int_val, val_size);
                break;
 
        case IOV_SVAL(IOV_READAHEAD):
-               if (bool_val && !dhd_readahead)
+               if (bool_val && !brcmf_readahead)
                        bus->nextlen = 0;
-               dhd_readahead = bool_val;
+               brcmf_readahead = bool_val;
                break;
 
        case IOV_GVAL(IOV_SDRXCHAIN):
@@ -2336,40 +2670,56 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                        bus->use_rxchain = bool_val;
                break;
        case IOV_GVAL(IOV_ALIGNCTL):
-               int_val = (s32) dhd_alignctl;
+               int_val = (s32) brcmf_alignctl;
                memcpy(arg, &int_val, val_size);
                break;
 
        case IOV_SVAL(IOV_ALIGNCTL):
-               dhd_alignctl = bool_val;
+               brcmf_alignctl = bool_val;
                break;
 
        case IOV_GVAL(IOV_SDALIGN):
-               int_val = DHD_SDALIGN;
+               int_val = BRCMF_SDALIGN;
                memcpy(arg, &int_val, val_size);
                break;
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        case IOV_GVAL(IOV_VARS):
                if (bus->varsz < (uint) len)
                        memcpy(arg, bus->vars, bus->varsz);
                else
                        bcmerror = -EOVERFLOW;
                break;
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
+
+#ifdef BCMDBG
+       case IOV_GVAL(IOV_DCONSOLE_POLL):
+               int_val = (s32) brcmf_console_ms;
+               memcpy(arg, &int_val, val_size);
+               break;
+
+       case IOV_SVAL(IOV_DCONSOLE_POLL):
+               brcmf_console_ms = (uint) int_val;
+               break;
+
+       case IOV_SVAL(IOV_CONS):
+               if (len > 0)
+                       bcmerror = brcmf_sdbrcm_bus_console_in(bus->drvr,
+                                                              arg, len - 1);
+               break;
 
-#ifdef DHD_DEBUG
        case IOV_GVAL(IOV_SDREG):
                {
-                       sdreg_t *sd_ptr;
+                       struct brcmf_sdreg *sd_ptr;
                        u32 addr, size;
 
-                       sd_ptr = (sdreg_t *) params;
+                       sd_ptr = (struct brcmf_sdreg *) params;
 
                        addr = (unsigned long)bus->regs + sd_ptr->offset;
                        size = sd_ptr->func;
-                       int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size);
-                       if (bcmsdh_regfail(bus->sdh))
+                       int_val = (s32) brcmf_sdcard_reg_read(bus->card, addr,
+                                                             size);
+                       if (brcmf_sdcard_regfail(bus->card))
                                bcmerror = -EIO;
                        memcpy(arg, &int_val, sizeof(s32));
                        break;
@@ -2377,15 +2727,16 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
 
        case IOV_SVAL(IOV_SDREG):
                {
-                       sdreg_t *sd_ptr;
+                       struct brcmf_sdreg *sd_ptr;
                        u32 addr, size;
 
-                       sd_ptr = (sdreg_t *) params;
+                       sd_ptr = (struct brcmf_sdreg *) params;
 
                        addr = (unsigned long)bus->regs + sd_ptr->offset;
                        size = sd_ptr->func;
-                       bcmsdh_reg_write(bus->sdh, addr, size, sd_ptr->value);
-                       if (bcmsdh_regfail(bus->sdh))
+                       brcmf_sdcard_reg_write(bus->card, addr, size,
+                                              sd_ptr->value);
+                       if (brcmf_sdcard_regfail(bus->card))
                                bcmerror = -EIO;
                        break;
                }
@@ -2394,15 +2745,16 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                 (not SDIO core) */
        case IOV_GVAL(IOV_SBREG):
                {
-                       sdreg_t sdreg;
+                       struct brcmf_sdreg sdreg;
                        u32 addr, size;
 
                        memcpy(&sdreg, params, sizeof(sdreg));
 
                        addr = SI_ENUM_BASE + sdreg.offset;
                        size = sdreg.func;
-                       int_val = (s32) bcmsdh_reg_read(bus->sdh, addr, size);
-                       if (bcmsdh_regfail(bus->sdh))
+                       int_val = (s32) brcmf_sdcard_reg_read(bus->card, addr,
+                                                             size);
+                       if (brcmf_sdcard_regfail(bus->card))
                                bcmerror = -EIO;
                        memcpy(arg, &int_val, sizeof(s32));
                        break;
@@ -2410,15 +2762,16 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
 
        case IOV_SVAL(IOV_SBREG):
                {
-                       sdreg_t sdreg;
+                       struct brcmf_sdreg sdreg;
                        u32 addr, size;
 
                        memcpy(&sdreg, params, sizeof(sdreg));
 
                        addr = SI_ENUM_BASE + sdreg.offset;
                        size = sdreg.func;
-                       bcmsdh_reg_write(bus->sdh, addr, size, sdreg.value);
-                       if (bcmsdh_regfail(bus->sdh))
+                       brcmf_sdcard_reg_write(bus->card, addr, size,
+                                              sdreg.value);
+                       if (brcmf_sdcard_regfail(bus->card))
                                bcmerror = -EIO;
                        break;
                }
@@ -2428,15 +2781,15 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                        *(char *)arg = 0;
 
                        strcat(arg, "\nFunc 0\n");
-                       bcmsdh_cis_read(bus->sdh, 0x10,
+                       brcmf_sdcard_cis_read(bus->card, 0x10,
                                        (u8 *) arg + strlen(arg),
                                        SBSDIO_CIS_SIZE_LIMIT);
                        strcat(arg, "\nFunc 1\n");
-                       bcmsdh_cis_read(bus->sdh, 0x11,
+                       brcmf_sdcard_cis_read(bus->card, 0x11,
                                        (u8 *) arg + strlen(arg),
                                        SBSDIO_CIS_SIZE_LIMIT);
                        strcat(arg, "\nFunc 2\n");
-                       bcmsdh_cis_read(bus->sdh, 0x12,
+                       brcmf_sdcard_cis_read(bus->card, 0x12,
                                        (u8 *) arg + strlen(arg),
                                        SBSDIO_CIS_SIZE_LIMIT);
                        break;
@@ -2452,21 +2805,21 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                break;
 
        case IOV_GVAL(IOV_TXBOUND):
-               int_val = (s32) dhd_txbound;
+               int_val = (s32) brcmf_txbound;
                memcpy(arg, &int_val, val_size);
                break;
 
        case IOV_SVAL(IOV_TXBOUND):
-               dhd_txbound = (uint) int_val;
+               brcmf_txbound = (uint) int_val;
                break;
 
        case IOV_GVAL(IOV_RXBOUND):
-               int_val = (s32) dhd_rxbound;
+               int_val = (s32) brcmf_rxbound;
                memcpy(arg, &int_val, val_size);
                break;
 
        case IOV_SVAL(IOV_RXBOUND):
-               dhd_rxbound = (uint) int_val;
+               brcmf_rxbound = (uint) int_val;
                break;
 
        case IOV_GVAL(IOV_TXMINMAX):
@@ -2477,7 +2830,7 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
        case IOV_SVAL(IOV_TXMINMAX):
                dhd_txminmax = (uint) int_val;
                break;
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
 #ifdef SDTEST
        case IOV_GVAL(IOV_EXTLOOP):
@@ -2490,21 +2843,21 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                break;
 
        case IOV_GVAL(IOV_PKTGEN):
-               bcmerror = dhdsdio_pktgen_get(bus, arg);
+               bcmerror = brcmf_sdbrcm_pktgen_get(bus, arg);
                break;
 
        case IOV_SVAL(IOV_PKTGEN):
-               bcmerror = dhdsdio_pktgen_set(bus, arg);
+               bcmerror = brcmf_sdbrcm_pktgen_set(bus, arg);
                break;
 #endif                         /* SDTEST */
 
        case IOV_SVAL(IOV_DEVRESET):
                DHD_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d "
                        "busstate=%d\n",
-                       __func__, bool_val, bus->dhd->dongle_reset,
-                       bus->dhd->busstate));
+                       __func__, bool_val, bus->drvr->dongle_reset,
+                       bus->drvr->busstate));
 
-               dhd_bus_devreset(bus->dhd, (u8) bool_val);
+               brcmf_bus_devreset(bus->drvr, (u8) bool_val);
 
                break;
 
@@ -2512,40 +2865,53 @@ dhdsdio_doiovar(dhd_bus_t *bus, const bcm_iovar_t *vi, u32 actionid,
                DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__));
 
                /* Get its status */
-               int_val = (bool) bus->dhd->dongle_reset;
+               int_val = (bool) bus->drvr->dongle_reset;
                memcpy(arg, &int_val, val_size);
 
                break;
 
+       case IOV_GVAL(IOV_WDTICK):
+               int_val = (s32) brcmf_watchdog_ms;
+               memcpy(arg, &int_val, val_size);
+               break;
+
+       case IOV_SVAL(IOV_WDTICK):
+               if (!bus->drvr->up) {
+                       bcmerror = -ENOLINK;
+                       break;
+               }
+               brcmf_sdbrcm_wd_timer(bus, (uint) int_val);
+               break;
+
        default:
                bcmerror = -ENOTSUPP;
                break;
        }
 
 exit:
-       if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
+       if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) {
                bus->activity = false;
-               dhdsdio_clkctl(bus, CLK_NONE, true);
+               brcmf_sdbrcm_clkctl(bus, CLK_NONE, true);
        }
 
-       dhd_os_sdunlock(bus->dhd);
+       brcmf_sdbrcm_sdunlock(bus);
 
        if (actionid == IOV_SVAL(IOV_DEVRESET) && bool_val == false)
-               dhd_preinit_ioctls((dhd_pub_t *) bus->dhd);
+               brcmf_c_preinit_ioctls(bus->drvr);
 
        return bcmerror;
 }
 
-static int dhdsdio_write_vars(dhd_bus_t *bus)
+static int brcmf_sdbrcm_write_vars(struct brcmf_bus *bus)
 {
        int bcmerror = 0;
        u32 varsize;
        u32 varaddr;
        u8 *vbuffer;
        u32 varsizew;
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        char *nvram_ularray;
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
        /* Even if there are no vars are to be written, we still
                 need to set the ramsize. */
@@ -2561,8 +2927,8 @@ static int dhdsdio_write_vars(dhd_bus_t *bus)
 
                /* Write the vars list */
                bcmerror =
-                   dhdsdio_membytes(bus, true, varaddr, vbuffer, varsize);
-#ifdef DHD_DEBUG
+                   brcmf_sdbrcm_membytes(bus, true, varaddr, vbuffer, varsize);
+#ifdef BCMDBG
                /* Verify NVRAM bytes */
                DHD_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize));
                nvram_ularray = kmalloc(varsize, GFP_ATOMIC);
@@ -2574,7 +2940,7 @@ static int dhdsdio_write_vars(dhd_bus_t *bus)
 
                /* Read the vars list to temp buffer for comparison */
                bcmerror =
-                   dhdsdio_membytes(bus, false, varaddr, nvram_ularray,
+                   brcmf_sdbrcm_membytes(bus, false, varaddr, nvram_ularray,
                                     varsize);
                if (bcmerror) {
                        DHD_ERROR(("%s: error %d on reading %d nvram bytes at "
@@ -2589,7 +2955,7 @@ static int dhdsdio_write_vars(dhd_bus_t *bus)
                                __func__));
 
                kfree(nvram_ularray);
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
                kfree(vbuffer);
        }
@@ -2617,13 +2983,13 @@ static int dhdsdio_write_vars(dhd_bus_t *bus)
                  varsizew));
 
        /* Write the length token to the last word */
-       bcmerror = dhdsdio_membytes(bus, true, (bus->orig_ramsize - 4),
+       bcmerror = brcmf_sdbrcm_membytes(bus, true, (bus->orig_ramsize - 4),
                                    (u8 *)&varsizew, 4);
 
        return bcmerror;
 }
 
-static int dhdsdio_download_state(dhd_bus_t *bus, bool enter)
+static int brcmf_sdbrcm_download_state(struct brcmf_bus *bus, bool enter)
 {
        uint retries;
        u32 regdata;
@@ -2635,18 +3001,18 @@ static int dhdsdio_download_state(dhd_bus_t *bus, bool enter)
        if (enter) {
                bus->alp_only = true;
 
-               dhdsdio_chip_disablecore(bus->sdh, bus->ci->armcorebase);
+               brcmf_sdbrcm_chip_disablecore(bus->card, bus->ci->armcorebase);
 
-               dhdsdio_chip_resetcore(bus->sdh, bus->ci->ramcorebase);
+               brcmf_sdbrcm_chip_resetcore(bus->card, bus->ci->ramcorebase);
 
                /* Clear the top bit of memory */
                if (bus->ramsize) {
                        u32 zeros = 0;
-                       dhdsdio_membytes(bus, true, bus->ramsize - 4,
+                       brcmf_sdbrcm_membytes(bus, true, bus->ramsize - 4,
                                         (u8 *)&zeros, 4);
                }
        } else {
-               regdata = bcmsdh_reg_read(bus->sdh,
+               regdata = brcmf_sdcard_reg_read(bus->card,
                        CORE_SB(bus->ci->ramcorebase, sbtmstatelow), 4);
                regdata &= (SBTML_RESET | SBTML_REJ_MASK |
                        (SICF_CLOCK_EN << SBTML_SICF_SHIFT));
@@ -2657,7 +3023,7 @@ static int dhdsdio_download_state(dhd_bus_t *bus, bool enter)
                        goto fail;
                }
 
-               bcmerror = dhdsdio_write_vars(bus);
+               bcmerror = brcmf_sdbrcm_write_vars(bus);
                if (bcmerror) {
                        DHD_ERROR(("%s: no vars written to RAM\n", __func__));
                        bcmerror = 0;
@@ -2665,23 +3031,23 @@ static int dhdsdio_download_state(dhd_bus_t *bus, bool enter)
 
                W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries);
 
-               dhdsdio_chip_resetcore(bus->sdh, bus->ci->armcorebase);
+               brcmf_sdbrcm_chip_resetcore(bus->card, bus->ci->armcorebase);
 
                /* Allow HT Clock now that the ARM is running. */
                bus->alp_only = false;
 
-               bus->dhd->busstate = DHD_BUS_LOAD;
+               bus->drvr->busstate = DHD_BUS_LOAD;
        }
 fail:
        return bcmerror;
 }
 
 int
-dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name,
-                void *params, int plen, void *arg, int len, bool set)
+brcmf_sdbrcm_bus_iovar_op(struct brcmf_pub *drvr, const char *name,
+                         void *params, int plen, void *arg, int len, bool set)
 {
-       dhd_bus_t *bus = dhdp->bus;
-       const bcm_iovar_t *vi = NULL;
+       struct brcmf_bus *bus = drvr->bus;
+       const struct brcmu_iovar *vi = NULL;
        int bcmerror = 0;
        int val_size;
        u32 actionid;
@@ -2698,52 +3064,23 @@ dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name,
        ASSERT(!set || (!params && !plen));
 
        /* Look up var locally; if not found pass to host driver */
-       vi = bcm_iovar_lookup(dhdsdio_iovars, name);
+       vi = brcmu_iovar_lookup(dhdsdio_iovars, name);
        if (vi == NULL) {
-               dhd_os_sdlock(bus->dhd);
+               brcmf_sdbrcm_sdlock(bus);
 
                BUS_WAKE(bus);
 
                /* Turn on clock in case SD command needs backplane */
-               dhdsdio_clkctl(bus, CLK_AVAIL, false);
-
-               bcmerror =
-                   bcmsdh_iovar_op(bus->sdh, name, params, plen, arg, len,
-                                   set);
+               brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
 
-               /* Check for bus configuration changes of interest */
+               bcmerror = brcmf_sdcard_iovar_op(bus->card, name, params, plen,
+                                                arg, len, set);
 
-               /* If it was divisor change, read the new one */
-               if (set && strcmp(name, "sd_divisor") == 0) {
-                       if (bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0,
-                                           &bus->sd_divisor, sizeof(s32),
-                                           false) != 0) {
-                               bus->sd_divisor = -1;
-                               DHD_ERROR(("%s: fail on %s get\n", __func__,
-                                          name));
-                       } else {
-                               DHD_INFO(("%s: noted %s update, value now %d\n",
-                                         __func__, name, bus->sd_divisor));
-                       }
-               }
-               /* If it was a mode change, read the new one */
-               if (set && strcmp(name, "sd_mode") == 0) {
-                       if (bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0,
-                                           &bus->sd_mode, sizeof(s32),
-                                           false) != 0) {
-                               bus->sd_mode = -1;
-                               DHD_ERROR(("%s: fail on %s get\n", __func__,
-                                          name));
-                       } else {
-                               DHD_INFO(("%s: noted %s update, value now %d\n",
-                                         __func__, name, bus->sd_mode));
-                       }
-               }
                /* Similar check for blocksize change */
                if (set && strcmp(name, "sd_blocksize") == 0) {
                        s32 fnum = 2;
-                       if (bcmsdh_iovar_op
-                           (bus->sdh, "sd_blocksize", &fnum, sizeof(s32),
+                       if (brcmf_sdcard_iovar_op
+                           (bus->card, "sd_blocksize", &fnum, sizeof(s32),
                             &bus->blocksize, sizeof(s32),
                             false) != 0) {
                                bus->blocksize = 0;
@@ -2757,12 +3094,13 @@ dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name,
                }
                bus->roundup = min(max_roundup, bus->blocksize);
 
-               if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
+               if (bus->idletime == BRCMF_IDLE_IMMEDIATE &&
+                   !bus->dpc_sched) {
                        bus->activity = false;
-                       dhdsdio_clkctl(bus, CLK_NONE, true);
+                       brcmf_sdbrcm_clkctl(bus, CLK_NONE, true);
                }
 
-               dhd_os_sdunlock(bus->dhd);
+               brcmf_sdbrcm_sdunlock(bus);
                goto exit;
        }
 
@@ -2786,15 +3124,14 @@ dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name,
                val_size = sizeof(int);
 
        actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
-       bcmerror =
-           dhdsdio_doiovar(bus, vi, actionid, name, params, plen, arg, len,
-                           val_size);
+       bcmerror = brcmf_sdbrcm_doiovar(bus, vi, actionid, name, params, plen,
+                                       arg, len, val_size);
 
 exit:
        return bcmerror;
 }
 
-void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex)
+void brcmf_sdbrcm_bus_stop(struct brcmf_bus *bus, bool enforce_mutex)
 {
        u32 local_hostintmask;
        u8 saveclk;
@@ -2804,12 +3141,25 @@ void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex)
        DHD_TRACE(("%s: Enter\n", __func__));
 
        if (enforce_mutex)
-               dhd_os_sdlock(bus->dhd);
+               brcmf_sdbrcm_sdlock(bus);
 
        BUS_WAKE(bus);
 
        /* Enable clock for device interrupts */
-       dhdsdio_clkctl(bus, CLK_AVAIL, false);
+       brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
+
+       if (bus->watchdog_tsk) {
+               send_sig(SIGTERM, bus->watchdog_tsk, 1);
+               kthread_stop(bus->watchdog_tsk);
+               bus->watchdog_tsk = NULL;
+       }
+
+       if (bus->dpc_tsk) {
+               send_sig(SIGTERM, bus->dpc_tsk, 1);
+               kthread_stop(bus->dpc_tsk);
+               bus->dpc_tsk = NULL;
+       } else
+               tasklet_kill(&bus->tasklet);
 
        /* Disable and clear interrupts at the chip level also */
        W_SDREG(0, &bus->regs->hostintmask, retries);
@@ -2817,15 +3167,15 @@ void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex)
        bus->hostintmask = 0;
 
        /* Change our idea of bus state */
-       bus->dhd->busstate = DHD_BUS_DOWN;
+       bus->drvr->busstate = DHD_BUS_DOWN;
 
        /* Force clocks on backplane to be sure F2 interrupt propagates */
-       saveclk =
-           bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                           &err);
+       saveclk = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1,
+                                       SBSDIO_FUNC1_CHIPCLKCSR, &err);
        if (!err) {
-               bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                (saveclk | SBSDIO_FORCE_HT), &err);
+               brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1,
+                                      SBSDIO_FUNC1_CHIPCLKCSR,
+                                      (saveclk | SBSDIO_FORCE_HT), &err);
        }
        if (err) {
                DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
@@ -2834,44 +3184,44 @@ void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex)
 
        /* Turn off the bus (F2), free any pending packets */
        DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
-       bcmsdh_intr_disable(bus->sdh);
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN,
+       brcmf_sdcard_intr_disable(bus->card);
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx,
                         SDIO_FUNC_ENABLE_1, NULL);
 
        /* Clear any pending interrupts now that F2 is disabled */
        W_SDREG(local_hostintmask, &bus->regs->intstatus, retries);
 
        /* Turn off the backplane clock (only) */
-       dhdsdio_clkctl(bus, CLK_SDONLY, false);
+       brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false);
 
        /* Clear the data packet queues */
-       bcm_pktq_flush(&bus->txq, true, NULL, NULL);
+       brcmu_pktq_flush(&bus->txq, true, NULL, NULL);
 
        /* Clear any held glomming stuff */
        if (bus->glomd)
-               bcm_pkt_buf_free_skb(bus->glomd);
+               brcmu_pkt_buf_free_skb(bus->glomd);
 
        if (bus->glom)
-               bcm_pkt_buf_free_skb(bus->glom);
+               brcmu_pkt_buf_free_skb(bus->glom);
 
        bus->glom = bus->glomd = NULL;
 
        /* Clear rx control and wake any waiters */
        bus->rxlen = 0;
-       dhd_os_ioctl_resp_wake(bus->dhd);
+       brcmf_os_ioctl_resp_wake(bus->drvr);
 
        /* Reset some F2 state stuff */
        bus->rxskip = false;
        bus->tx_seq = bus->rx_seq = 0;
 
        if (enforce_mutex)
-               dhd_os_sdunlock(bus->dhd);
+               brcmf_sdbrcm_sdunlock(bus);
 }
 
-int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex)
+int brcmf_sdbrcm_bus_init(struct brcmf_pub *drvr, bool enforce_mutex)
 {
-       dhd_bus_t *bus = dhdp->bus;
-       dhd_timeout_t tmo;
+       struct brcmf_bus *bus = drvr->bus;
+       struct brcmf_timeout tmo;
        uint retries = 0;
        u8 ready, enable;
        int err, ret = 0;
@@ -2879,25 +3229,36 @@ int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex)
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       ASSERT(bus->dhd);
-       if (!bus->dhd)
+       /* try to download image and nvram to the dongle */
+       if (drvr->busstate == DHD_BUS_DOWN) {
+               if (!(brcmf_sdbrcm_download_firmware(bus, bus->card)))
+                       return -1;
+       }
+
+       ASSERT(bus->drvr);
+       if (!bus->drvr)
                return 0;
 
+       /* Start the watchdog timer */
+       bus->drvr->tickcnt = 0;
+       brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms);
+
        if (enforce_mutex)
-               dhd_os_sdlock(bus->dhd);
+               brcmf_sdbrcm_sdlock(bus);
 
        /* Make sure backplane clock is on, needed to generate F2 interrupt */
-       dhdsdio_clkctl(bus, CLK_AVAIL, false);
+       brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
        if (bus->clkstate != CLK_AVAIL)
                goto exit;
 
        /* Force clocks on backplane to be sure F2 interrupt propagates */
        saveclk =
-           bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                           &err);
+           brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1,
+                                 SBSDIO_FUNC1_CHIPCLKCSR, &err);
        if (!err) {
-               bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                (saveclk | SBSDIO_FORCE_HT), &err);
+               brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1,
+                                      SBSDIO_FUNC1_CHIPCLKCSR,
+                                      (saveclk | SBSDIO_FORCE_HT), &err);
        }
        if (err) {
                DHD_ERROR(("%s: Failed to force clock for F2: err %d\n",
@@ -2910,16 +3271,16 @@ int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex)
                &bus->regs->tosbmailboxdata, retries);
        enable = (SDIO_FUNC_ENABLE_1 | SDIO_FUNC_ENABLE_2);
 
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable, NULL);
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx, enable,
+                              NULL);
 
        /* Give the dongle some time to do its thing and set IOR2 */
-       dhd_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000);
+       brcmf_timeout_start(&tmo, DHD_WAIT_F2RDY * 1000);
 
        ready = 0;
-       while (ready != enable && !dhd_timeout_expired(&tmo))
-               ready =
-                   bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IORDY,
-                                   NULL);
+       while (ready != enable && !brcmf_timeout_expired(&tmo))
+               ready = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_0,
+                                             SDIO_CCCR_IORx, NULL);
 
        DHD_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n",
                  __func__, enable, ready, tmo.elapsed));
@@ -2932,22 +3293,20 @@ int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex)
                        (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase,
                        hostintmask), retries);
 
-               bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_WATERMARK,
+               brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_WATERMARK,
                                 (u8) watermark, &err);
 
                /* Set bus state according to enable result */
-               dhdp->busstate = DHD_BUS_DATA;
-
-               /* bcmsdh_intr_unmask(bus->sdh); */
+               drvr->busstate = DHD_BUS_DATA;
 
                bus->intdis = false;
                if (bus->intr) {
                        DHD_INTR(("%s: enable SDIO device interrupts\n",
                                  __func__));
-                       bcmsdh_intr_enable(bus->sdh);
+                       brcmf_sdcard_intr_enable(bus->card);
                } else {
                        DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
-                       bcmsdh_intr_disable(bus->sdh);
+                       brcmf_sdcard_intr_disable(bus->card);
                }
 
        }
@@ -2955,29 +3314,42 @@ int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex)
        else {
                /* Disable F2 again */
                enable = SDIO_FUNC_ENABLE_1;
-               bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, enable,
-                                NULL);
+               brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx,
+                                      enable, NULL);
        }
 
        /* Restore previous clock setting */
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
                         saveclk, &err);
 
+#if defined(OOB_INTR_ONLY)
+       /* Host registration for OOB interrupt */
+       if (brcmf_sdio_register_oob_intr(bus->dhd)) {
+               brcmf_sdbrcm_wd_timer(bus, 0);
+               DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
+               ret = -ENODEV;
+               goto exit;
+       }
+
+       /* Enable oob at firmware */
+       brcmf_sdbrcm_enable_oob_intr(bus, true);
+#endif         /* defined(OOB_INTR_ONLY) */
+
        /* If we didn't come up, turn off backplane clock */
-       if (dhdp->busstate != DHD_BUS_DATA)
-               dhdsdio_clkctl(bus, CLK_NONE, false);
+       if (drvr->busstate != DHD_BUS_DATA)
+               brcmf_sdbrcm_clkctl(bus, CLK_NONE, false);
 
 exit:
        if (enforce_mutex)
-               dhd_os_sdunlock(bus->dhd);
+               brcmf_sdbrcm_sdunlock(bus);
 
        return ret;
 }
 
-static void dhdsdio_rxfail(dhd_bus_t *bus, bool abort, bool rtx)
+static void brcmf_sdbrcm_rxfail(struct brcmf_bus *bus, bool abort, bool rtx)
 {
-       bcmsdh_info_t *sdh = bus->sdh;
-       sdpcmd_regs_t *regs = bus->regs;
+       struct brcmf_sdio_card *card = bus->card;
+       struct sdpcmd_regs *regs = bus->regs;
        uint retries = 0;
        u16 lastrbc;
        u8 hi, lo;
@@ -2988,18 +3360,18 @@ static void dhdsdio_rxfail(dhd_bus_t *bus, bool abort, bool rtx)
                   (rtx ? ", send NAK" : "")));
 
        if (abort)
-               bcmsdh_abort(sdh, SDIO_FUNC_2);
+               brcmf_sdcard_abort(card, SDIO_FUNC_2);
 
-       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM,
-                        &err);
+       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_FRAMECTRL,
+                              SFC_RF_TERM, &err);
        bus->f1regdata++;
 
        /* Wait until the packet has been flushed (device/FIFO stable) */
        for (lastrbc = retries = 0xffff; retries > 0; retries--) {
-               hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCHI,
-                                    NULL);
-               lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_RFRAMEBCLO,
-                                    NULL);
+               hi = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                          SBSDIO_FUNC1_RFRAMEBCHI, NULL);
+               lo = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                          SBSDIO_FUNC1_RFRAMEBCLO, NULL);
                bus->f1regdata += 2;
 
                if ((hi == 0) && (lo == 0))
@@ -3033,14 +3405,14 @@ static void dhdsdio_rxfail(dhd_bus_t *bus, bool abort, bool rtx)
        bus->nextlen = 0;
 
        /* If we can't reach the device, signal failure */
-       if (err || bcmsdh_regfail(sdh))
-               bus->dhd->busstate = DHD_BUS_DOWN;
+       if (err || brcmf_sdcard_regfail(card))
+               bus->drvr->busstate = DHD_BUS_DOWN;
 }
 
 static void
-dhdsdio_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff)
+brcmf_sdbrcm_read_control(struct brcmf_bus *bus, u8 *hdr, uint len, uint doff)
 {
-       bcmsdh_info_t *sdh = bus->sdh;
+       struct brcmf_sdio_card *card = bus->card;
        uint rdlen, pad;
 
        int sdret;
@@ -3054,11 +3426,11 @@ dhdsdio_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff)
        ASSERT(bus->rxbuf);
        /* Set rxctl for frame (w/optional alignment) */
        bus->rxctl = bus->rxbuf;
-       if (dhd_alignctl) {
+       if (brcmf_alignctl) {
                bus->rxctl += firstread;
-               pad = ((unsigned long)bus->rxctl % DHD_SDALIGN);
+               pad = ((unsigned long)bus->rxctl % BRCMF_SDALIGN);
                if (pad)
-                       bus->rxctl += (DHD_SDALIGN - pad);
+                       bus->rxctl += (BRCMF_SDALIGN - pad);
                bus->rxctl -= firstread;
        }
        ASSERT(bus->rxctl >= bus->rxbuf);
@@ -3079,10 +3451,10 @@ dhdsdio_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff)
        if (bus->roundup && bus->blocksize && (rdlen > bus->blocksize)) {
                pad = bus->blocksize - (rdlen % bus->blocksize);
                if ((pad <= bus->roundup) && (pad < bus->blocksize) &&
-                   ((len + pad) < bus->dhd->maxctl))
+                   ((len + pad) < bus->drvr->maxctl))
                        rdlen += pad;
-       } else if (rdlen % DHD_SDALIGN) {
-               rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN);
+       } else if (rdlen % BRCMF_SDALIGN) {
+               rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN);
        }
 
        /* Satisfy length-alignment requirements */
@@ -3090,26 +3462,27 @@ dhdsdio_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff)
                rdlen = roundup(rdlen, ALIGNMENT);
 
        /* Drop if the read is too big or it exceeds our maximum */
-       if ((rdlen + firstread) > bus->dhd->maxctl) {
+       if ((rdlen + firstread) > bus->drvr->maxctl) {
                DHD_ERROR(("%s: %d-byte control read exceeds %d-byte buffer\n",
-                          __func__, rdlen, bus->dhd->maxctl));
-               bus->dhd->rx_errors++;
-               dhdsdio_rxfail(bus, false, false);
+                          __func__, rdlen, bus->drvr->maxctl));
+               bus->drvr->rx_errors++;
+               brcmf_sdbrcm_rxfail(bus, false, false);
                goto done;
        }
 
-       if ((len - doff) > bus->dhd->maxctl) {
+       if ((len - doff) > bus->drvr->maxctl) {
                DHD_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds "
                        "%d-byte limit\n",
-                       __func__, len, (len - doff), bus->dhd->maxctl));
-               bus->dhd->rx_errors++;
+                       __func__, len, (len - doff), bus->drvr->maxctl));
+               bus->drvr->rx_errors++;
                bus->rx_toolong++;
-               dhdsdio_rxfail(bus, false, false);
+               brcmf_sdbrcm_rxfail(bus, false, false);
                goto done;
        }
 
        /* Read remainder of frame body into the rxctl buffer */
-       sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
+       sdret = brcmf_sdcard_recv_buf(card, brcmf_sdcard_cur_sbwad(card),
+                               SDIO_FUNC_2,
                                F2SYNC, (bus->rxctl + firstread), rdlen,
                                NULL, NULL, NULL);
        bus->f2rxdata++;
@@ -3120,13 +3493,13 @@ dhdsdio_read_control(dhd_bus_t *bus, u8 *hdr, uint len, uint doff)
                DHD_ERROR(("%s: read %d control bytes failed: %d\n",
                           __func__, rdlen, sdret));
                bus->rxc_errors++;      /* dhd.rx_ctlerrs is higher level */
-               dhdsdio_rxfail(bus, true, true);
+               brcmf_sdbrcm_rxfail(bus, true, true);
                goto done;
        }
 
 gotpkt:
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        if (DHD_BYTES_ON() && DHD_CTL_ON()) {
                printk(KERN_DEBUG "RxCtrl:\n");
                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, bus->rxctl, len);
@@ -3139,10 +3512,10 @@ gotpkt:
 
 done:
        /* Awake any waiters */
-       dhd_os_ioctl_resp_wake(bus->dhd);
+       brcmf_os_ioctl_resp_wake(bus->drvr);
 }
 
-static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
+static u8 brcmf_sdbrcm_rxglom(struct brcmf_bus *bus, u8 rxseq)
 {
        u16 dlen, totlen;
        u8 *dptr, num = 0;
@@ -3160,13 +3533,11 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
        /* If packets, issue read(s) and send up packet chain */
        /* Return sequence numbers consumed? */
 
-       DHD_TRACE(("dhdsdio_rxglom: start: glomd %p glom %p\n", bus->glomd,
+       DHD_TRACE(("brcmf_sdbrcm_rxglom: start: glomd %p glom %p\n", bus->glomd,
                   bus->glom));
 
        /* If there's a descriptor, generate the packet chain */
        if (bus->glomd) {
-               dhd_os_sdlock_rxq(bus->dhd);
-
                pfirst = plast = pnext = NULL;
                dlen = (u16) (bus->glomd->len);
                dptr = bus->glomd->data;
@@ -3188,9 +3559,9 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                                pnext = NULL;
                                break;
                        }
-                       if (sublen % DHD_SDALIGN) {
+                       if (sublen % BRCMF_SDALIGN) {
                                DHD_ERROR(("%s: sublen %d not multiple of %d\n",
-                               __func__, sublen, DHD_SDALIGN));
+                               __func__, sublen, BRCMF_SDALIGN));
                                usechain = false;
                        }
                        totlen += sublen;
@@ -3204,7 +3575,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                        }
 
                        /* Allocate/chain packet for next subframe */
-                       pnext = bcm_pkt_buf_get_skb(sublen + DHD_SDALIGN);
+                       pnext = brcmu_pkt_buf_get_skb(sublen + BRCMF_SDALIGN);
                        if (pnext == NULL) {
                                DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed, "
                                        "num %d len %d\n", __func__,
@@ -3222,7 +3593,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                        }
 
                        /* Adhere to start alignment requirements */
-                       PKTALIGN(pnext, sublen, DHD_SDALIGN);
+                       PKTALIGN(pnext, sublen, BRCMF_SDALIGN);
                }
 
                /* If all allocations succeeded, save packet chain
@@ -3241,17 +3612,15 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                        pfirst = pnext = NULL;
                } else {
                        if (pfirst)
-                               bcm_pkt_buf_free_skb(pfirst);
+                               brcmu_pkt_buf_free_skb(pfirst);
                        bus->glom = NULL;
                        num = 0;
                }
 
                /* Done with descriptor packet */
-               bcm_pkt_buf_free_skb(bus->glomd);
+               brcmu_pkt_buf_free_skb(bus->glomd);
                bus->glomd = NULL;
                bus->nextlen = 0;
-
-               dhd_os_sdunlock_rxq(bus->dhd);
        }
 
        /* Ok -- either we just generated a packet chain,
@@ -3268,23 +3637,25 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                }
 
                pfirst = bus->glom;
-               dlen = (u16) bcm_pkttotlen(pfirst);
+               dlen = (u16) brcmu_pkttotlen(pfirst);
 
                /* Do an SDIO read for the superframe.  Configurable iovar to
                 * read directly into the chained packet, or allocate a large
                 * packet and and copy into the chain.
                 */
                if (usechain) {
-                       errcode = bcmsdh_recv_buf(bus,
-                                       bcmsdh_cur_sbwad(bus->sdh), SDIO_FUNC_2,
+                       errcode = brcmf_sdcard_recv_buf(bus->card,
+                                       brcmf_sdcard_cur_sbwad(bus->card),
+                                       SDIO_FUNC_2,
                                        F2SYNC, (u8 *) pfirst->data, dlen,
                                        pfirst, NULL, NULL);
                } else if (bus->dataptr) {
-                       errcode = bcmsdh_recv_buf(bus,
-                                       bcmsdh_cur_sbwad(bus->sdh), SDIO_FUNC_2,
+                       errcode = brcmf_sdcard_recv_buf(bus->card,
+                                       brcmf_sdcard_cur_sbwad(bus->card),
+                                       SDIO_FUNC_2,
                                        F2SYNC, bus->dataptr, dlen,
                                        NULL, NULL, NULL);
-                       sublen = (u16) bcm_pktfrombuf(pfirst, 0, dlen,
+                       sublen = (u16) brcmu_pktfrombuf(pfirst, 0, dlen,
                                                bus->dataptr);
                        if (sublen != dlen) {
                                DHD_ERROR(("%s: FAILED TO COPY, dlen %d sublen %d\n",
@@ -3304,22 +3675,20 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                if (errcode < 0) {
                        DHD_ERROR(("%s: glom read of %d bytes failed: %d\n",
                                   __func__, dlen, errcode));
-                       bus->dhd->rx_errors++;
+                       bus->drvr->rx_errors++;
 
                        if (bus->glomerr++ < 3) {
-                               dhdsdio_rxfail(bus, true, true);
+                               brcmf_sdbrcm_rxfail(bus, true, true);
                        } else {
                                bus->glomerr = 0;
-                               dhdsdio_rxfail(bus, true, false);
-                               dhd_os_sdlock_rxq(bus->dhd);
-                               bcm_pkt_buf_free_skb(bus->glom);
-                               dhd_os_sdunlock_rxq(bus->dhd);
+                               brcmf_sdbrcm_rxfail(bus, true, false);
+                               brcmu_pkt_buf_free_skb(bus->glom);
                                bus->rxglomfail++;
                                bus->glom = NULL;
                        }
                        return 0;
                }
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                if (DHD_GLOM_ON()) {
                        printk(KERN_DEBUG "SUPERFRAME:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
@@ -3403,7 +3772,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                        check = get_unaligned_le16(dptr + sizeof(u16));
                        chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]);
                        doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]);
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                        if (DHD_GLOM_ON()) {
                                printk(KERN_DEBUG "subframe:\n");
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
@@ -3440,13 +3809,11 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                        if (bus->glomerr++ < 3) {
                                /* Restore superframe header space */
                                skb_push(pfirst, sfdoff);
-                               dhdsdio_rxfail(bus, true, true);
+                               brcmf_sdbrcm_rxfail(bus, true, true);
                        } else {
                                bus->glomerr = 0;
-                               dhdsdio_rxfail(bus, true, false);
-                               dhd_os_sdlock_rxq(bus->dhd);
-                               bcm_pkt_buf_free_skb(bus->glom);
-                               dhd_os_sdunlock_rxq(bus->dhd);
+                               brcmf_sdbrcm_rxfail(bus, true, false);
+                               brcmu_pkt_buf_free_skb(bus->glom);
                                bus->rxglomfail++;
                                bus->glom = NULL;
                        }
@@ -3459,7 +3826,6 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                bus->glom = NULL;
                plast = NULL;
 
-               dhd_os_sdlock_rxq(bus->dhd);
                for (num = 0; pfirst; rxseq++, pfirst = pnext) {
                        pnext = pfirst->next;
                        pfirst->next = NULL;
@@ -3484,7 +3850,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                                bus->rx_badseq++;
                                rxseq = seq;
                        }
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                        if (DHD_BYTES_ON() && DHD_DATA_ON()) {
                                printk(KERN_DEBUG "Rx Subframe Data:\n");
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
@@ -3496,7 +3862,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                        skb_pull(pfirst, doff);
 
                        if (pfirst->len == 0) {
-                               bcm_pkt_buf_free_skb(pfirst);
+                               brcmu_pkt_buf_free_skb(pfirst);
                                if (plast) {
                                        plast->next = pnext;
                                } else {
@@ -3504,12 +3870,12 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                                        save_pfirst = pnext;
                                }
                                continue;
-                       } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pfirst) !=
-                                  0) {
+                       } else if (brcmf_proto_hdrpull(bus->drvr, &ifidx, pfirst)
+                                       != 0) {
                                DHD_ERROR(("%s: rx protocol error\n",
                                           __func__));
-                               bus->dhd->rx_errors++;
-                               bcm_pkt_buf_free_skb(pfirst);
+                               bus->drvr->rx_errors++;
+                               brcmu_pkt_buf_free_skb(pfirst);
                                if (plast) {
                                        plast->next = pnext;
                                } else {
@@ -3525,7 +3891,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                        plast = pfirst;
                        num++;
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                        if (DHD_GLOM_ON()) {
                                DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) "
                                "nxt/lnk %p/%p\n",
@@ -3536,13 +3902,12 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
                                                pfirst->data,
                                                min_t(int, pfirst->len, 32));
                        }
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
                }
-               dhd_os_sdunlock_rxq(bus->dhd);
                if (num) {
-                       dhd_os_sdunlock(bus->dhd);
-                       dhd_rx_frame(bus->dhd, ifidx, save_pfirst, num);
-                       dhd_os_sdlock(bus->dhd);
+                       brcmf_sdbrcm_sdunlock(bus);
+                       brcmf_rx_frame(bus->drvr, ifidx, save_pfirst, num);
+                       brcmf_sdbrcm_sdlock(bus);
                }
 
                bus->rxglomframes++;
@@ -3552,9 +3917,10 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
 }
 
 /* Return true if there may be more frames to read */
-static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
+static uint
+brcmf_sdbrcm_readframes(struct brcmf_bus *bus, uint maxframes, bool *finished)
 {
-       bcmsdh_info_t *sdh = bus->sdh;
+       struct brcmf_sdio_card *card = bus->card;
 
        u16 len, check; /* Extracted hardware header fields */
        u8 chan, seq, doff;     /* Extracted software header fields */
@@ -3565,7 +3931,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
        u16 rdlen;              /* Total number of bytes to read */
        u8 rxseq;               /* Next sequence number to expect */
        uint rxleft = 0;        /* Remaining number of frames allowed */
-       int sdret;              /* Return code from bcmsdh calls */
+       int sdret;              /* Return code from calls */
        u8 txmax;               /* Maximum tx sequence offered */
        bool len_consistent;    /* Result of comparing readahead len and
                                         len from hw-hdr */
@@ -3573,7 +3939,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
        int ifidx = 0;
        uint rxcount = 0;       /* Total frames read */
 
-#if defined(DHD_DEBUG) || defined(SDTEST)
+#if defined(BCMDBG) || defined(SDTEST)
        bool sdtest = false;    /* To limit message spew from test mode */
 #endif
 
@@ -3583,7 +3949,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
 
 #ifdef SDTEST
        /* Allow pktgen to override maxframes */
-       if (bus->pktgen_count && (bus->pktgen_mode == DHD_PKTGEN_RECV)) {
+       if (bus->pktgen_count && (bus->pktgen_mode == BRCMF_PKTGEN_RECV)) {
                maxframes = bus->pktgen_count;
                sdtest = true;
        }
@@ -3593,7 +3959,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
        *finished = false;
 
        for (rxseq = bus->rx_seq, rxleft = maxframes;
-            !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN;
+            !bus->rxskip && rxleft && bus->drvr->busstate != DHD_BUS_DOWN;
             rxseq++, rxleft--) {
 
                /* Handle glomming separately */
@@ -3601,7 +3967,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        u8 cnt;
                        DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n",
                                  __func__, bus->glomd, bus->glom));
-                       cnt = dhdsdio_rxglom(bus, rxseq);
+                       cnt = brcmf_sdbrcm_rxglom(bus, rxseq);
                        DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt));
                        rxseq += cnt - 1;
                        rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1;
@@ -3609,7 +3975,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                }
 
                /* Try doing single read if we can */
-               if (dhd_readahead && bus->nextlen) {
+               if (brcmf_readahead && bus->nextlen) {
                        u16 nextlen = bus->nextlen;
                        bus->nextlen = 0;
 
@@ -3629,9 +3995,9 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                            && ((rdlen + pad + firstread) <
                                                MAX_RX_DATASZ))
                                                rdlen += pad;
-                               } else if (rdlen % DHD_SDALIGN) {
+                               } else if (rdlen % BRCMF_SDALIGN) {
                                        rdlen +=
-                                           DHD_SDALIGN - (rdlen % DHD_SDALIGN);
+                                           BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN);
                                }
                        }
 
@@ -3646,29 +4012,28 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                         * or non-data frame.
                         */
                        /* Allocate a packet buffer */
-                       dhd_os_sdlock_rxq(bus->dhd);
-                       pkt = bcm_pkt_buf_get_skb(rdlen + DHD_SDALIGN);
+                       pkt = brcmu_pkt_buf_get_skb(rdlen + BRCMF_SDALIGN);
                        if (!pkt) {
                                if (bus->bus == SPI_BUS) {
                                        bus->usebufpool = false;
                                        bus->rxctl = bus->rxbuf;
-                                       if (dhd_alignctl) {
+                                       if (brcmf_alignctl) {
                                                bus->rxctl += firstread;
                                                pad = ((unsigned long)bus->rxctl %
-                                                     DHD_SDALIGN);
+                                                     BRCMF_SDALIGN);
                                                if (pad)
                                                        bus->rxctl +=
-                                                           (DHD_SDALIGN - pad);
+                                                           (BRCMF_SDALIGN - pad);
                                                bus->rxctl -= firstread;
                                        }
                                        ASSERT(bus->rxctl >= bus->rxbuf);
                                        rxbuf = bus->rxctl;
                                        /* Read the entire frame */
-                                       sdret = bcmsdh_recv_buf(bus,
-                                                   bcmsdh_cur_sbwad(sdh),
-                                                   SDIO_FUNC_2, F2SYNC,
-                                                   rxbuf, rdlen,
-                                                   NULL, NULL, NULL);
+                                       sdret = brcmf_sdcard_recv_buf(card,
+                                                  brcmf_sdcard_cur_sbwad(card),
+                                                  SDIO_FUNC_2, F2SYNC,
+                                                  rxbuf, rdlen,
+                                                  NULL, NULL, NULL);
                                        bus->f2rxdata++;
                                        ASSERT(sdret != -BCME_PENDING);
 
@@ -3680,8 +4045,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                                        rdlen, sdret));
                                                /* dhd.rx_ctlerrs is higher */
                                                bus->rxc_errors++;
-                                               dhd_os_sdunlock_rxq(bus->dhd);
-                                               dhdsdio_rxfail(bus, true,
+                                               brcmf_sdbrcm_rxfail(bus, true,
                                                       (bus->bus ==
                                                        SPI_BUS) ? false
                                                       : true);
@@ -3691,13 +4055,11 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                        /* Give up on data,
                                        request rtx of events */
                                        DHD_ERROR(("%s (nextlen): "
-                                                  "bcm_pkt_buf_get_skb failed:"
+                                                  "brcmu_pkt_buf_get_skb "
+                                                  "failed:"
                                                   " len %d rdlen %d expected"
                                                   " rxseq %d\n", __func__,
                                                   len, rdlen, rxseq));
-                                       /* Just go try again w/normal
-                                       header read */
-                                       dhd_os_sdunlock_rxq(bus->dhd);
                                        continue;
                                }
                        } else {
@@ -3705,11 +4067,11 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                        bus->usebufpool = true;
 
                                ASSERT(!(pkt->prev));
-                               PKTALIGN(pkt, rdlen, DHD_SDALIGN);
+                               PKTALIGN(pkt, rdlen, BRCMF_SDALIGN);
                                rxbuf = (u8 *) (pkt->data);
                                /* Read the entire frame */
-                               sdret = bcmsdh_recv_buf(bus,
-                                               bcmsdh_cur_sbwad(sdh),
+                               sdret = brcmf_sdcard_recv_buf(card,
+                                               brcmf_sdcard_cur_sbwad(card),
                                                SDIO_FUNC_2, F2SYNC,
                                                rxbuf, rdlen,
                                                pkt, NULL, NULL);
@@ -3719,21 +4081,19 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                if (sdret < 0) {
                                        DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n",
                                                __func__, rdlen, sdret));
-                                       bcm_pkt_buf_free_skb(pkt);
-                                       bus->dhd->rx_errors++;
-                                       dhd_os_sdunlock_rxq(bus->dhd);
+                                       brcmu_pkt_buf_free_skb(pkt);
+                                       bus->drvr->rx_errors++;
                                        /* Force retry w/normal header read.
                                         * Don't attempt NAK for
                                         * gSPI
                                         */
-                                       dhdsdio_rxfail(bus, true,
+                                       brcmf_sdbrcm_rxfail(bus, true,
                                                       (bus->bus ==
                                                        SPI_BUS) ? false :
                                                       true);
                                        continue;
                                }
                        }
-                       dhd_os_sdunlock_rxq(bus->dhd);
 
                        /* Now check the header */
                        memcpy(bus->rxhdr, rxbuf, SDPCM_HDRLEN);
@@ -3746,7 +4106,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        if (!(len | check)) {
                                DHD_INFO(("%s (nextlen): read zeros in HW "
                                        "header???\n", __func__));
-                               dhdsdio_pktfree2(bus, pkt);
+                               brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
 
@@ -3757,8 +4117,8 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                        " 0x%04x/0x%04x/0x%04x\n",
                                        __func__, nextlen, len, check));
                                bus->rx_badhdr++;
-                               dhdsdio_rxfail(bus, false, false);
-                               dhdsdio_pktfree2(bus, pkt);
+                               brcmf_sdbrcm_rxfail(bus, false, false);
+                               brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
 
@@ -3766,7 +4126,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        if (len < SDPCM_HDRLEN) {
                                DHD_ERROR(("%s (nextlen): HW hdr length "
                                        "invalid: %d\n", __func__, len));
-                               dhdsdio_pktfree2(bus, pkt);
+                               brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
 
@@ -3780,8 +4140,9 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                        "expected rxseq %d\n",
                                        __func__, nextlen,
                                        len, roundup(len, 16), rxseq));
-                               dhdsdio_rxfail(bus, true, (bus->bus != SPI_BUS));
-                               dhdsdio_pktfree2(bus, pkt);
+                               brcmf_sdbrcm_rxfail(bus, true,
+                                                 bus->bus != SPI_BUS);
+                               brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
 
@@ -3804,7 +4165,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                bus->nextlen = 0;
                        }
 
-                       bus->dhd->rx_readahead_cnt++;
+                       bus->drvr->rx_readahead_cnt++;
 
                        /* Handle Flow Control */
                        fcbits = SDPCM_FCMASK_VALUE(
@@ -3838,7 +4199,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        }
                        bus->tx_max = txmax;
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                        if (DHD_BYTES_ON() && DHD_DATA_ON()) {
                                printk(KERN_DEBUG "Rx Data:\n");
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
@@ -3852,16 +4213,16 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
 
                        if (chan == SDPCM_CONTROL_CHANNEL) {
                                if (bus->bus == SPI_BUS) {
-                                       dhdsdio_read_control(bus, rxbuf, len,
-                                                            doff);
+                                       brcmf_sdbrcm_read_control(bus, rxbuf,
+                                                                 len, doff);
                                } else {
                                        DHD_ERROR(("%s (nextlen): readahead on control" " packet %d?\n",
                                                __func__, seq));
                                        /* Force retry w/normal header read */
                                        bus->nextlen = 0;
-                                       dhdsdio_rxfail(bus, false, true);
+                                       brcmf_sdbrcm_rxfail(bus, false, true);
                                }
-                               dhdsdio_pktfree2(bus, pkt);
+                               brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
 
@@ -3875,8 +4236,8 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        if ((doff < SDPCM_HDRLEN) || (doff > len)) {
                                DHD_ERROR(("%s (nextlen): bad data offset %d: HW len %d min %d\n",
                                        __func__, doff, len, SDPCM_HDRLEN));
-                               dhdsdio_rxfail(bus, false, false);
-                               dhdsdio_pktfree2(bus, pkt);
+                               brcmf_sdbrcm_rxfail(bus, false, false);
+                               brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
 
@@ -3888,7 +4249,8 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        break;
 
                /* Read frame header (hardware and software) */
-               sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh),
+               sdret = brcmf_sdcard_recv_buf(card,
+                               brcmf_sdcard_cur_sbwad(card),
                                SDIO_FUNC_2, F2SYNC, bus->rxhdr, firstread,
                                NULL, NULL, NULL);
                bus->f2rxhdrs++;
@@ -3898,10 +4260,10 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__,
                                   sdret));
                        bus->rx_hdrfail++;
-                       dhdsdio_rxfail(bus, true, true);
+                       brcmf_sdbrcm_rxfail(bus, true, true);
                        continue;
                }
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                if (DHD_BYTES_ON() || DHD_HDRS_ON()) {
                        printk(KERN_DEBUG "RxHdr:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
@@ -3924,7 +4286,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n",
                                __func__, len, check));
                        bus->rx_badhdr++;
-                       dhdsdio_rxfail(bus, false, false);
+                       brcmf_sdbrcm_rxfail(bus, false, false);
                        continue;
                }
 
@@ -3948,7 +4310,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                __func__, doff, len, SDPCM_HDRLEN, seq));
                        bus->rx_badhdr++;
                        ASSERT(0);
-                       dhdsdio_rxfail(bus, false, false);
+                       brcmf_sdbrcm_rxfail(bus, false, false);
                        continue;
                }
 
@@ -3994,7 +4356,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
 
                /* Call a separate function for control frames */
                if (chan == SDPCM_CONTROL_CHANNEL) {
-                       dhdsdio_read_control(bus, bus->rxhdr, len, doff);
+                       brcmf_sdbrcm_read_control(bus, bus->rxhdr, len, doff);
                        continue;
                }
 
@@ -4013,8 +4375,8 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        if ((pad <= bus->roundup) && (pad < bus->blocksize) &&
                            ((rdlen + pad + firstread) < MAX_RX_DATASZ))
                                rdlen += pad;
-               } else if (rdlen % DHD_SDALIGN) {
-                       rdlen += DHD_SDALIGN - (rdlen % DHD_SDALIGN);
+               } else if (rdlen % BRCMF_SDALIGN) {
+                       rdlen += BRCMF_SDALIGN - (rdlen % BRCMF_SDALIGN);
                }
 
                /* Satisfy length-alignment requirements */
@@ -4025,36 +4387,34 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                        /* Too long -- skip this frame */
                        DHD_ERROR(("%s: too long: len %d rdlen %d\n",
                                   __func__, len, rdlen));
-                       bus->dhd->rx_errors++;
+                       bus->drvr->rx_errors++;
                        bus->rx_toolong++;
-                       dhdsdio_rxfail(bus, false, false);
+                       brcmf_sdbrcm_rxfail(bus, false, false);
                        continue;
                }
 
-               dhd_os_sdlock_rxq(bus->dhd);
-               pkt = bcm_pkt_buf_get_skb(rdlen + firstread + DHD_SDALIGN);
+               pkt = brcmu_pkt_buf_get_skb(rdlen + firstread + BRCMF_SDALIGN);
                if (!pkt) {
                        /* Give up on data, request rtx of events */
-                       DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed: rdlen %d "
-                               "chan %d\n", __func__, rdlen, chan));
-                       bus->dhd->rx_dropped++;
-                       dhd_os_sdunlock_rxq(bus->dhd);
-                       dhdsdio_rxfail(bus, false, RETRYCHAN(chan));
+                       DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed: rdlen %d"
+                                  " chan %d\n", __func__, rdlen, chan));
+                       bus->drvr->rx_dropped++;
+                       brcmf_sdbrcm_rxfail(bus, false, RETRYCHAN(chan));
                        continue;
                }
-               dhd_os_sdunlock_rxq(bus->dhd);
 
                ASSERT(!(pkt->prev));
 
                /* Leave room for what we already read, and align remainder */
                ASSERT(firstread < pkt->len);
                skb_pull(pkt, firstread);
-               PKTALIGN(pkt, rdlen, DHD_SDALIGN);
+               PKTALIGN(pkt, rdlen, BRCMF_SDALIGN);
 
                /* Read the remaining frame data */
-               sdret = bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
-                                       F2SYNC, ((u8 *) (pkt->data)), rdlen,
-                                       pkt, NULL, NULL);
+               sdret = brcmf_sdcard_recv_buf(card,
+                               brcmf_sdcard_cur_sbwad(card),
+                               SDIO_FUNC_2, F2SYNC, ((u8 *) (pkt->data)),
+                               rdlen, pkt, NULL, NULL);
                bus->f2rxdata++;
                ASSERT(sdret != -BCME_PENDING);
 
@@ -4066,11 +4426,9 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                                        SDPCM_DATA_CHANNEL)
                                       ? "data" : "test")),
                                   sdret));
-                       dhd_os_sdlock_rxq(bus->dhd);
-                       bcm_pkt_buf_free_skb(pkt);
-                       dhd_os_sdunlock_rxq(bus->dhd);
-                       bus->dhd->rx_errors++;
-                       dhdsdio_rxfail(bus, true, RETRYCHAN(chan));
+                       brcmu_pkt_buf_free_skb(pkt);
+                       bus->drvr->rx_errors++;
+                       brcmf_sdbrcm_rxfail(bus, true, RETRYCHAN(chan));
                        continue;
                }
 
@@ -4078,7 +4436,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
                skb_push(pkt, firstread);
                memcpy(pkt->data, bus->rxhdr, firstread);
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                if (DHD_BYTES_ON() && DHD_DATA_ON()) {
                        printk(KERN_DEBUG "Rx Data:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
@@ -4092,7 +4450,7 @@ deliver:
                        if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) {
                                DHD_GLOM(("%s: glom descriptor, %d bytes:\n",
                                        __func__, len));
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                                if (DHD_GLOM_ON()) {
                                        printk(KERN_DEBUG "Glom Data:\n");
                                        print_hex_dump_bytes("",
@@ -4107,7 +4465,7 @@ deliver:
                        } else {
                                DHD_ERROR(("%s: glom superframe w/o "
                                        "descriptor!\n", __func__));
-                               dhdsdio_rxfail(bus, false, false);
+                               brcmf_sdbrcm_rxfail(bus, false, false);
                        }
                        continue;
                }
@@ -4119,38 +4477,34 @@ deliver:
 #ifdef SDTEST
                /* Test channel packets are processed separately */
                if (chan == SDPCM_TEST_CHANNEL) {
-                       dhdsdio_testrcv(bus, pkt, seq);
+                       brcmf_sdbrcm_checkdied(bus, pkt, seq);
                        continue;
                }
 #endif                         /* SDTEST */
 
                if (pkt->len == 0) {
-                       dhd_os_sdlock_rxq(bus->dhd);
-                       bcm_pkt_buf_free_skb(pkt);
-                       dhd_os_sdunlock_rxq(bus->dhd);
+                       brcmu_pkt_buf_free_skb(pkt);
                        continue;
-               } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) {
+               } else if (brcmf_proto_hdrpull(bus->drvr, &ifidx, pkt) != 0) {
                        DHD_ERROR(("%s: rx protocol error\n", __func__));
-                       dhd_os_sdlock_rxq(bus->dhd);
-                       bcm_pkt_buf_free_skb(pkt);
-                       dhd_os_sdunlock_rxq(bus->dhd);
-                       bus->dhd->rx_errors++;
+                       brcmu_pkt_buf_free_skb(pkt);
+                       bus->drvr->rx_errors++;
                        continue;
                }
 
                /* Unlock during rx call */
-               dhd_os_sdunlock(bus->dhd);
-               dhd_rx_frame(bus->dhd, ifidx, pkt, 1);
-               dhd_os_sdlock(bus->dhd);
+               brcmf_sdbrcm_sdunlock(bus);
+               brcmf_rx_frame(bus->drvr, ifidx, pkt, 1);
+               brcmf_sdbrcm_sdlock(bus);
        }
        rxcount = maxframes - rxleft;
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        /* Message if we hit the limit */
        if (!rxleft && !sdtest)
                DHD_DATA(("%s: hit rx limit of %d frames\n", __func__,
                          maxframes));
        else
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
                DHD_DATA(("%s: processed %d frames\n", __func__, rxcount));
        /* Back off rxseq if awaiting rtx, update rx_seq */
        if (bus->rxskip)
@@ -4160,9 +4514,9 @@ deliver:
        return rxcount;
 }
 
-static u32 dhdsdio_hostmail(dhd_bus_t *bus)
+static u32 brcmf_sdbrcm_hostmail(struct brcmf_bus *bus)
 {
-       sdpcmd_regs_t *regs = bus->regs;
+       struct sdpcmd_regs *regs = bus->regs;
        u32 intstatus = 0;
        u32 hmb_data;
        u8 fcbits;
@@ -4234,14 +4588,14 @@ static u32 dhdsdio_hostmail(dhd_bus_t *bus)
        return intstatus;
 }
 
-bool dhdsdio_dpc(dhd_bus_t *bus)
+static bool brcmf_sdbrcm_dpc(struct brcmf_bus *bus)
 {
-       bcmsdh_info_t *sdh = bus->sdh;
-       sdpcmd_regs_t *regs = bus->regs;
+       struct brcmf_sdio_card *card = bus->card;
+       struct sdpcmd_regs *regs = bus->regs;
        u32 intstatus, newstatus = 0;
        uint retries = 0;
-       uint rxlimit = dhd_rxbound;     /* Rx frames to read before resched */
-       uint txlimit = dhd_txbound;     /* Tx frames to send before resched */
+       uint rxlimit = brcmf_rxbound;   /* Rx frames to read before resched */
+       uint txlimit = brcmf_txbound;   /* Tx frames to send before resched */
        uint framecnt = 0;      /* Temporary counter of tx/rx frames */
        bool rxdone = true;     /* Flag for no more read data */
        bool resched = false;   /* Flag indicating resched wanted */
@@ -4251,55 +4605,53 @@ bool dhdsdio_dpc(dhd_bus_t *bus)
        /* Start with leftover status bits */
        intstatus = bus->intstatus;
 
-       dhd_os_sdlock(bus->dhd);
+       brcmf_sdbrcm_sdlock(bus);
 
        /* If waiting for HTAVAIL, check status */
        if (bus->clkstate == CLK_PENDING) {
                int err;
                u8 clkctl, devctl = 0;
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                /* Check for inconsistent device control */
-               devctl =
-                   bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL, &err);
+               devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                              SBSDIO_DEVICE_CTL, &err);
                if (err) {
                        DHD_ERROR(("%s: error reading DEVCTL: %d\n",
                                   __func__, err));
-                       bus->dhd->busstate = DHD_BUS_DOWN;
+                       bus->drvr->busstate = DHD_BUS_DOWN;
                } else {
                        ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY);
                }
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
                /* Read CSR, if clock on switch to AVAIL, else ignore */
-               clkctl =
-                   bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                   &err);
+               clkctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                              SBSDIO_FUNC1_CHIPCLKCSR, &err);
                if (err) {
                        DHD_ERROR(("%s: error reading CSR: %d\n", __func__,
                                   err));
-                       bus->dhd->busstate = DHD_BUS_DOWN;
+                       bus->drvr->busstate = DHD_BUS_DOWN;
                }
 
                DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl,
                          clkctl));
 
                if (SBSDIO_HTAV(clkctl)) {
-                       devctl =
-                           bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                           &err);
+                       devctl = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                                      SBSDIO_DEVICE_CTL, &err);
                        if (err) {
                                DHD_ERROR(("%s: error reading DEVCTL: %d\n",
                                           __func__, err));
-                               bus->dhd->busstate = DHD_BUS_DOWN;
+                               bus->drvr->busstate = DHD_BUS_DOWN;
                        }
                        devctl &= ~SBSDIO_DEVCTL_CA_INT_ONLY;
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
-                                        devctl, &err);
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
+                               SBSDIO_DEVICE_CTL, devctl, &err);
                        if (err) {
                                DHD_ERROR(("%s: error writing DEVCTL: %d\n",
                                           __func__, err));
-                               bus->dhd->busstate = DHD_BUS_DOWN;
+                               bus->drvr->busstate = DHD_BUS_DOWN;
                        }
                        bus->clkstate = CLK_AVAIL;
                } else {
@@ -4310,7 +4662,7 @@ bool dhdsdio_dpc(dhd_bus_t *bus)
        BUS_WAKE(bus);
 
        /* Make sure backplane clock is on */
-       dhdsdio_clkctl(bus, CLK_AVAIL, true);
+       brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, true);
        if (bus->clkstate == CLK_PENDING)
                goto clkwait;
 
@@ -4319,7 +4671,7 @@ bool dhdsdio_dpc(dhd_bus_t *bus)
                bus->ipend = false;
                R_SDREG(newstatus, &regs->intstatus, retries);
                bus->f1regdata++;
-               if (bcmsdh_regfail(bus->sdh))
+               if (brcmf_sdcard_regfail(bus->card))
                        newstatus = 0;
                newstatus &= bus->hostintmask;
                bus->fcstate = !!(newstatus & I_HMB_FC_STATE);
@@ -4350,7 +4702,7 @@ bool dhdsdio_dpc(dhd_bus_t *bus)
        /* Handle host mailbox indication */
        if (intstatus & I_HMB_HOST_INT) {
                intstatus &= ~I_HMB_HOST_INT;
-               intstatus |= dhdsdio_hostmail(bus);
+               intstatus |= brcmf_sdbrcm_hostmail(bus);
        }
 
        /* Generally don't ask for these, can get CRC errors... */
@@ -4381,7 +4733,7 @@ bool dhdsdio_dpc(dhd_bus_t *bus)
 
        /* On frame indication, read available frames */
        if (PKT_AVAILABLE()) {
-               framecnt = dhdsdio_readframes(bus, rxlimit, &rxdone);
+               framecnt = brcmf_sdbrcm_readframes(bus, rxlimit, &rxdone);
                if (rxdone || bus->rxskip)
                        intstatus &= ~I_HMB_FRAME_IND;
                rxlimit -= min(framecnt, rxlimit);
@@ -4391,29 +4743,24 @@ bool dhdsdio_dpc(dhd_bus_t *bus)
        bus->intstatus = intstatus;
 
 clkwait:
-#if defined(OOB_INTR_ONLY)
-       bcmsdh_oob_intr_set(1);
-#endif                         /* (OOB_INTR_ONLY) */
        /* Re-enable interrupts to detect new device events (mailbox, rx frame)
         * or clock availability.  (Allows tx loop to check ipend if desired.)
         * (Unless register access seems hosed, as we may not be able to ACK...)
         */
-       if (bus->intr && bus->intdis && !bcmsdh_regfail(sdh)) {
+       if (bus->intr && bus->intdis && !brcmf_sdcard_regfail(card)) {
                DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n",
                          __func__, rxdone, framecnt));
                bus->intdis = false;
-               bcmsdh_intr_enable(sdh);
+               brcmf_sdcard_intr_enable(card);
        }
 
        if (DATAOK(bus) && bus->ctrl_frame_stat &&
                (bus->clkstate == CLK_AVAIL)) {
                int ret, i;
 
-               ret =
-                   dhd_bcmsdh_send_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
-                                       F2SYNC, (u8 *) bus->ctrl_frame_buf,
-                                       (u32) bus->ctrl_frame_len, NULL,
-                                       NULL, NULL);
+               ret = brcmf_sdbrcm_send_buf(bus, brcmf_sdcard_cur_sbwad(card),
+                       SDIO_FUNC_2, F2SYNC, (u8 *) bus->ctrl_frame_buf,
+                       (u32) bus->ctrl_frame_len, NULL, NULL, NULL);
                ASSERT(ret != -BCME_PENDING);
 
                if (ret < 0) {
@@ -4423,19 +4770,19 @@ clkwait:
                                "terminate frame.\n", __func__, ret));
                        bus->tx_sderrs++;
 
-                       bcmsdh_abort(sdh, SDIO_FUNC_2);
+                       brcmf_sdcard_abort(card, SDIO_FUNC_2);
 
-                       bcmsdh_cfg_write(sdh, SDIO_FUNC_1,
+                       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
                                         SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM,
                                         NULL);
                        bus->f1regdata++;
 
                        for (i = 0; i < 3; i++) {
                                u8 hi, lo;
-                               hi = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
+                               hi = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
                                                     SBSDIO_FUNC1_WFRAMEBCHI,
                                                     NULL);
-                               lo = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
+                               lo = brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
                                                     SBSDIO_FUNC1_WFRAMEBCLO,
                                                     NULL);
                                bus->f1regdata += 2;
@@ -4449,14 +4796,14 @@ clkwait:
 
                DHD_INFO(("Return_dpc value is : %d\n", ret));
                bus->ctrl_frame_stat = false;
-               dhd_wait_event_wakeup(bus->dhd);
+               brcmf_sdbrcm_wait_event_wakeup(bus);
        }
        /* Send queued frames (limit 1 if rx may still be pending) */
        else if ((bus->clkstate == CLK_AVAIL) && !bus->fcstate &&
-                bcm_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit
+                brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) && txlimit
                 && DATAOK(bus)) {
                framecnt = rxdone ? txlimit : min(txlimit, dhd_txminmax);
-               framecnt = dhdsdio_sendfromq(bus, framecnt);
+               framecnt = brcmf_sdbrcm_sendfromq(bus, framecnt);
                txlimit -= framecnt;
        }
 
@@ -4464,18 +4811,20 @@ clkwait:
                 else await next interrupt */
        /* On failed register access, all bets are off:
                 no resched or interrupts */
-       if ((bus->dhd->busstate == DHD_BUS_DOWN) || bcmsdh_regfail(sdh)) {
+       if ((bus->drvr->busstate == DHD_BUS_DOWN) ||
+           brcmf_sdcard_regfail(card)) {
                DHD_ERROR(("%s: failed backplane access over SDIO, halting "
-                       "operation %d\n", __func__, bcmsdh_regfail(sdh)));
-               bus->dhd->busstate = DHD_BUS_DOWN;
+                          "operation %d\n", __func__,
+                         brcmf_sdcard_regfail(card)));
+               bus->drvr->busstate = DHD_BUS_DOWN;
                bus->intstatus = 0;
        } else if (bus->clkstate == CLK_PENDING) {
                DHD_INFO(("%s: rescheduled due to CLK_PENDING awaiting "
                        "I_CHIPACTIVE interrupt\n", __func__));
                resched = true;
        } else if (bus->intstatus || bus->ipend ||
-               (!bus->fcstate && bcm_pktq_mlen(&bus->txq, ~bus->flowcontrol) &&
-                       DATAOK(bus)) || PKT_AVAILABLE()) {
+               (!bus->fcstate && brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol)
+                && DATAOK(bus)) || PKT_AVAILABLE()) {
                resched = true;
        }
 
@@ -4483,31 +4832,20 @@ clkwait:
 
        /* If we're done for now, turn off clock request. */
        if ((bus->clkstate != CLK_PENDING)
-           && bus->idletime == DHD_IDLE_IMMEDIATE) {
+           && bus->idletime == BRCMF_IDLE_IMMEDIATE) {
                bus->activity = false;
-               dhdsdio_clkctl(bus, CLK_NONE, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_NONE, false);
        }
 
-       dhd_os_sdunlock(bus->dhd);
-
-       return resched;
-}
-
-bool dhd_bus_dpc(struct dhd_bus *bus)
-{
-       bool resched;
-
-       /* Call the DPC directly. */
-       DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__));
-       resched = dhdsdio_dpc(bus);
+       brcmf_sdbrcm_sdunlock(bus);
 
        return resched;
 }
 
-void dhdsdio_isr(void *arg)
+void brcmf_sdbrcm_isr(void *arg)
 {
-       dhd_bus_t *bus = (dhd_bus_t *) arg;
-       bcmsdh_info_t *sdh;
+       struct brcmf_bus *bus = (struct brcmf_bus *) arg;
+       struct brcmf_sdio_card *card;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
@@ -4515,9 +4853,9 @@ void dhdsdio_isr(void *arg)
                DHD_ERROR(("%s : bus is null pointer , exit\n", __func__));
                return;
        }
-       sdh = bus->sdh;
+       card = bus->card;
 
-       if (bus->dhd->busstate == DHD_BUS_DOWN) {
+       if (bus->drvr->busstate == DHD_BUS_DOWN) {
                DHD_ERROR(("%s : bus is down. we have nothing to do\n",
                           __func__));
                return;
@@ -4536,46 +4874,47 @@ void dhdsdio_isr(void *arg)
        if (bus->intr)
                DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
        else
-               DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n"));
+               DHD_ERROR(("brcmf_sdbrcm_isr() w/o interrupt configured!\n"));
 
-       bcmsdh_intr_disable(sdh);
+       brcmf_sdcard_intr_disable(card);
        bus->intdis = true;
 
 #if defined(SDIO_ISR_THREAD)
-       DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__));
-       while (dhdsdio_dpc(bus))
+       DHD_TRACE(("Calling brcmf_sdbrcm_dpc() from %s\n", __func__));
+       while (brcmf_sdbrcm_dpc(bus))
                ;
 #else
        bus->dpc_sched = true;
-       dhd_sched_dpc(bus->dhd);
+       brcmf_sdbrcm_sched_dpc(bus);
 #endif
 
 }
 
 #ifdef SDTEST
-static void dhdsdio_pktgen_init(dhd_bus_t *bus)
+static void brcmf_sdbrcm_pktgen_init(struct brcmf_bus *bus)
 {
        /* Default to specified length, or full range */
-       if (dhd_pktgen_len) {
-               bus->pktgen_maxlen = min(dhd_pktgen_len, MAX_PKTGEN_LEN);
+       if (brcmf_pktgen_len) {
+               bus->pktgen_maxlen = min(brcmf_pktgen_len,
+                                        BRCMF_MAX_PKTGEN_LEN);
                bus->pktgen_minlen = bus->pktgen_maxlen;
        } else {
-               bus->pktgen_maxlen = MAX_PKTGEN_LEN;
+               bus->pktgen_maxlen = BRCMF_MAX_PKTGEN_LEN;
                bus->pktgen_minlen = 0;
        }
        bus->pktgen_len = (u16) bus->pktgen_minlen;
 
        /* Default to per-watchdog burst with 10s print time */
        bus->pktgen_freq = 1;
-       bus->pktgen_print = 10000 / dhd_watchdog_ms;
-       bus->pktgen_count = (dhd_pktgen * dhd_watchdog_ms + 999) / 1000;
+       bus->pktgen_print = 10000 / brcmf_watchdog_ms;
+       bus->pktgen_count = (brcmf_pktgen * brcmf_watchdog_ms + 999) / 1000;
 
        /* Default to echo mode */
-       bus->pktgen_mode = DHD_PKTGEN_ECHO;
+       bus->pktgen_mode = BRCMF_PKTGEN_ECHO;
        bus->pktgen_stop = 1;
 }
 
-static void dhdsdio_pktgen(dhd_bus_t *bus)
+static void brcmf_sdbrcm_pktgen(struct brcmf_bus *bus)
 {
        struct sk_buff *pkt;
        u8 *data;
@@ -4591,9 +4930,9 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
        }
 
        /* For recv mode, just make sure dongle has started sending */
-       if (bus->pktgen_mode == DHD_PKTGEN_RECV) {
+       if (bus->pktgen_mode == BRCMF_PKTGEN_RECV) {
                if (!bus->pktgen_rcvd)
-                       dhdsdio_sdtest_set(bus, true);
+                       brcmf_sdbrcm_sdtest_set(bus, true);
                return;
        }
 
@@ -4608,31 +4947,31 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
 
                /* Allocate an appropriate-sized packet */
                len = bus->pktgen_len;
-               pkt = bcm_pkt_buf_get_skb(
-                       (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN),
+               pkt = brcmu_pkt_buf_get_skb(
+                       len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + BRCMF_SDALIGN,
                        true);
                if (!pkt) {
-                       DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed!\n",
-                               __func__));
+                       DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n",
+                                  __func__));
                        break;
                }
                PKTALIGN(pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN),
-                        DHD_SDALIGN);
+                        BRCMF_SDALIGN);
                data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
 
                /* Write test header cmd and extra based on mode */
                switch (bus->pktgen_mode) {
-               case DHD_PKTGEN_ECHO:
+               case BRCMF_PKTGEN_ECHO:
                        *data++ = SDPCM_TEST_ECHOREQ;
                        *data++ = (u8) bus->pktgen_sent;
                        break;
 
-               case DHD_PKTGEN_SEND:
+               case BRCMF_PKTGEN_SEND:
                        *data++ = SDPCM_TEST_DISCARD;
                        *data++ = (u8) bus->pktgen_sent;
                        break;
 
-               case DHD_PKTGEN_RXBURST:
+               case BRCMF_PKTGEN_RXBURST:
                        *data++ = SDPCM_TEST_BURST;
                        *data++ = (u8) bus->pktgen_count;
                        break;
@@ -4640,7 +4979,7 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
                default:
                        DHD_ERROR(("Unrecognized pktgen mode %d\n",
                                   bus->pktgen_mode));
-                       bcm_pkt_buf_free_skb(pkt, true);
+                       brcmu_pkt_buf_free_skb(pkt, true);
                        bus->pktgen_count = 0;
                        return;
                }
@@ -4655,17 +4994,17 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
                        *data++ =
                            SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent);
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
                if (DHD_BYTES_ON() && DHD_DATA_ON()) {
                        data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
-                       printk(KERN_DEBUG "dhdsdio_pktgen: Tx Data:\n");
+                       printk(KERN_DEBUG "brcmf_sdbrcm_pktgen: Tx Data:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, data,
                                             pkt->len - SDPCM_HDRLEN);
                }
 #endif
 
                /* Send it */
-               if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) {
+               if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true)) {
                        bus->pktgen_fail++;
                        if (bus->pktgen_stop
                            && bus->pktgen_stop == bus->pktgen_fail)
@@ -4678,24 +5017,24 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
                        bus->pktgen_len = (u16) bus->pktgen_minlen;
 
                /* Special case for burst mode: just send one request! */
-               if (bus->pktgen_mode == DHD_PKTGEN_RXBURST)
+               if (bus->pktgen_mode == BRCMF_PKTGEN_RXBURST)
                        break;
        }
 }
 
-static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start)
+static void brcmf_sdbrcm_sdtest_set(struct brcmf_bus *bus, bool start)
 {
        struct sk_buff *pkt;
        u8 *data;
 
        /* Allocate the packet */
-       pkt = bcm_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN +
-               DHD_SDALIGN, true);
+       pkt = brcmu_pkt_buf_get_skb(SDPCM_HDRLEN + SDPCM_TEST_HDRLEN +
+               BRCMF_SDALIGN, true);
        if (!pkt) {
-               DHD_ERROR(("%s: bcm_pkt_buf_get_skb failed!\n", __func__));
+               DHD_ERROR(("%s: brcmu_pkt_buf_get_skb failed!\n", __func__));
                return;
        }
-       PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN);
+       PKTALIGN(pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), BRCMF_SDALIGN);
        data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
 
        /* Fill in the test header */
@@ -4705,11 +5044,12 @@ static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start)
        *data++ = (bus->pktgen_maxlen >> 8);
 
        /* Send it */
-       if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true))
+       if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true))
                bus->pktgen_fail++;
 }
 
-static void dhdsdio_testrcv(dhd_bus_t *bus, struct sk_buff *pkt, uint seq)
+static void
+brcmf_sdbrcm_checkdied(struct brcmf_bus *bus, struct sk_buff *pkt, uint seq)
 {
        u8 *data;
        uint pktlen;
@@ -4722,9 +5062,9 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, struct sk_buff *pkt, uint seq)
        /* Check for min length */
        pktlen = pkt->len;
        if (pktlen < SDPCM_TEST_HDRLEN) {
-               DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n",
-                          pktlen));
-               bcm_pkt_buf_free_skb(pkt, false);
+               DHD_ERROR(("brcmf_sdbrcm_checkdied: toss runt frame, pktlen "
+                          "%d\n", pktlen));
+               brcmu_pkt_buf_free_skb(pkt, false);
                return;
        }
 
@@ -4739,10 +5079,11 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, struct sk_buff *pkt, uint seq)
        if (cmd == SDPCM_TEST_DISCARD || cmd == SDPCM_TEST_ECHOREQ
            || cmd == SDPCM_TEST_ECHORSP) {
                if (pktlen != len + SDPCM_TEST_HDRLEN) {
-                       DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, "
-                               "pktlen %d seq %d" " cmd %d extra %d len %d\n",
+                       DHD_ERROR(("brcmf_sdbrcm_checkdied: frame length "
+                               "mismatch, pktlen %d seq %d" " cmd %d extra %d "
+                               "len %d\n",
                                pktlen, seq, cmd, extra, len));
-                       bcm_pkt_buf_free_skb(pkt, false);
+                       brcmu_pkt_buf_free_skb(pkt, false);
                        return;
                }
        }
@@ -4753,76 +5094,79 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, struct sk_buff *pkt, uint seq)
                /* Rx->Tx turnaround ok (even on NDIS w/current
                         implementation) */
                *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP;
-               if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) {
+               if (brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0)
                        bus->pktgen_sent++;
-               else {
+               else {
                        bus->pktgen_fail++;
-                       bcm_pkt_buf_free_skb(pkt, false);
+                       brcmu_pkt_buf_free_skb(pkt, false);
                }
                bus->pktgen_rcvd++;
                break;
 
        case SDPCM_TEST_ECHORSP:
                if (bus->ext_loop) {
-                       bcm_pkt_buf_free_skb(pkt, false);
+                       brcmu_pkt_buf_free_skb(pkt, false);
                        bus->pktgen_rcvd++;
                        break;
                }
 
                for (offset = 0; offset < len; offset++, data++) {
                        if (*data != SDPCM_TEST_FILL(offset, extra)) {
-                               DHD_ERROR(("dhdsdio_testrcv: echo data mismatch: " "offset %d (len %d) expect 0x%02x rcvd 0x%02x\n",
-                                       offset, len,
-                                       SDPCM_TEST_FILL(offset, extra), *data));
+                               DHD_ERROR(("brcmf_sdbrcm_checkdied: echo data "
+                                          "mismatch: " "offset %d (len %d) "
+                                          "expect 0x%02x rcvd 0x%02x\n",
+                                          offset, len,
+                                          SDPCM_TEST_FILL(offset, extra),
+                                          *data));
                                break;
                        }
                }
-               bcm_pkt_buf_free_skb(pkt, false);
+               brcmu_pkt_buf_free_skb(pkt, false);
                bus->pktgen_rcvd++;
                break;
 
        case SDPCM_TEST_DISCARD:
-               bcm_pkt_buf_free_skb(pkt, false);
+               brcmu_pkt_buf_free_skb(pkt, false);
                bus->pktgen_rcvd++;
                break;
 
        case SDPCM_TEST_BURST:
        case SDPCM_TEST_SEND:
        default:
-               DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, "
-                       "pktlen %d seq %d" " cmd %d extra %d len %d\n",
+               DHD_INFO(("brcmf_sdbrcm_checkdied: unsupported or unknown "
+                       "command, pktlen %d seq %d" " cmd %d extra %d len %d\n",
                        pktlen, seq, cmd, extra, len));
-               bcm_pkt_buf_free_skb(pkt, false);
+               brcmu_pkt_buf_free_skb(pkt, false);
                break;
        }
 
        /* For recv mode, stop at limie (and tell dongle to stop sending) */
-       if (bus->pktgen_mode == DHD_PKTGEN_RECV) {
+       if (bus->pktgen_mode == BRCMF_PKTGEN_RECV) {
                if (bus->pktgen_total
                    && (bus->pktgen_rcvd >= bus->pktgen_total)) {
                        bus->pktgen_count = 0;
-                       dhdsdio_sdtest_set(bus, false);
+                       brcmf_sdbrcm_sdtest_set(bus, false);
                }
        }
 }
 #endif                         /* SDTEST */
 
-extern bool dhd_bus_watchdog(dhd_pub_t *dhdp)
+extern bool brcmf_sdbrcm_bus_watchdog(struct brcmf_pub *drvr)
 {
-       dhd_bus_t *bus;
+       struct brcmf_bus *bus;
 
        DHD_TIMER(("%s: Enter\n", __func__));
 
-       bus = dhdp->bus;
+       bus = drvr->bus;
 
-       if (bus->dhd->dongle_reset)
+       if (bus->drvr->dongle_reset)
                return false;
 
        /* Ignore the timer if simulating bus down */
        if (bus->sleeping)
                return false;
 
-       dhd_os_sdlock(bus->dhd);
+       brcmf_sdbrcm_sdlock(bus);
 
        /* Poll period: check device if appropriate. */
        if (bus->poll && (++bus->polltick >= bus->pollrate)) {
@@ -4836,9 +5180,9 @@ extern bool dhd_bus_watchdog(dhd_pub_t *dhdp)
 
                        if (!bus->dpc_sched) {
                                u8 devpend;
-                               devpend = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_0,
-                                                         SDIOD_CCCR_INTPEND,
-                                                         NULL);
+                               devpend = brcmf_sdcard_cfg_read(bus->card,
+                                               SDIO_FUNC_0, SDIO_CCCR_INTx,
+                                               NULL);
                                intstatus =
                                    devpend & (INTR_STATUS_FUNC1 |
                                               INTR_STATUS_FUNC2);
@@ -4850,10 +5194,10 @@ extern bool dhd_bus_watchdog(dhd_pub_t *dhdp)
                                bus->pollcnt++;
                                bus->ipend = true;
                                if (bus->intr)
-                                       bcmsdh_intr_disable(bus->sdh);
+                                       brcmf_sdcard_intr_disable(bus->card);
 
                                bus->dpc_sched = true;
-                               dhd_sched_dpc(bus->dhd);
+                               brcmf_sdbrcm_sched_dpc(bus);
 
                        }
                }
@@ -4861,28 +5205,28 @@ extern bool dhd_bus_watchdog(dhd_pub_t *dhdp)
                /* Update interrupt tracking */
                bus->lastintrs = bus->intrcount;
        }
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        /* Poll for console output periodically */
-       if (dhdp->busstate == DHD_BUS_DATA && dhd_console_ms != 0) {
-               bus->console.count += dhd_watchdog_ms;
-               if (bus->console.count >= dhd_console_ms) {
-                       bus->console.count -= dhd_console_ms;
+       if (drvr->busstate == DHD_BUS_DATA && brcmf_console_ms != 0) {
+               bus->console.count += brcmf_watchdog_ms;
+               if (bus->console.count >= brcmf_console_ms) {
+                       bus->console.count -= brcmf_console_ms;
                        /* Make sure backplane clock is on */
-                       dhdsdio_clkctl(bus, CLK_AVAIL, false);
-                       if (dhdsdio_readconsole(bus) < 0)
-                               dhd_console_ms = 0;     /* On error,
+                       brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
+                       if (brcmf_sdbrcm_readconsole(bus) < 0)
+                               brcmf_console_ms = 0;   /* On error,
                                                         stop trying */
                }
        }
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
 #ifdef SDTEST
        /* Generate packets if configured */
        if (bus->pktgen_count && (++bus->pktgen_tick >= bus->pktgen_freq)) {
                /* Make sure backplane clock is on */
-               dhdsdio_clkctl(bus, CLK_AVAIL, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
                bus->pktgen_tick = 0;
-               dhdsdio_pktgen(bus);
+               brcmf_sdbrcm_pktgen(bus);
        }
 #endif
 
@@ -4892,22 +5236,23 @@ extern bool dhd_bus_watchdog(dhd_pub_t *dhdp)
                        bus->idlecount = 0;
                        if (bus->activity) {
                                bus->activity = false;
-                               dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms);
+                               brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms);
                        } else {
-                               dhdsdio_clkctl(bus, CLK_NONE, false);
+                               brcmf_sdbrcm_clkctl(bus, CLK_NONE, false);
                        }
                }
        }
 
-       dhd_os_sdunlock(bus->dhd);
+       brcmf_sdbrcm_sdunlock(bus);
 
        return bus->ipend;
 }
 
-#ifdef DHD_DEBUG
-extern int dhd_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, uint msglen)
+#ifdef BCMDBG
+static int brcmf_sdbrcm_bus_console_in(struct brcmf_pub *drvr,
+                                      unsigned char *msg, uint msglen)
 {
-       dhd_bus_t *bus = dhdp->bus;
+       struct brcmf_bus *bus = drvr->bus;
        u32 addr, val;
        int rv;
        struct sk_buff *pkt;
@@ -4917,88 +5262,59 @@ extern int dhd_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, uint msglen)
                return -ENOTSUPP;
 
        /* Exclusive bus access */
-       dhd_os_sdlock(bus->dhd);
+       brcmf_sdbrcm_sdlock(bus);
 
        /* Don't allow input if dongle is in reset */
-       if (bus->dhd->dongle_reset) {
-               dhd_os_sdunlock(bus->dhd);
+       if (bus->drvr->dongle_reset) {
+               brcmf_sdbrcm_sdunlock(bus);
                return -EPERM;
        }
 
        /* Request clock to allow SDIO accesses */
        BUS_WAKE(bus);
        /* No pend allowed since txpkt is called later, ht clk has to be on */
-       dhdsdio_clkctl(bus, CLK_AVAIL, false);
+       brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
 
        /* Zero cbuf_index */
-       addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf_idx);
+       addr = bus->console_addr + offsetof(struct rte_console, cbuf_idx);
        val = cpu_to_le32(0);
-       rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val));
+       rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val));
        if (rv < 0)
                goto done;
 
        /* Write message into cbuf */
-       addr = bus->console_addr + offsetof(hndrte_cons_t, cbuf);
-       rv = dhdsdio_membytes(bus, true, addr, (u8 *)msg, msglen);
+       addr = bus->console_addr + offsetof(struct rte_console, cbuf);
+       rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)msg, msglen);
        if (rv < 0)
                goto done;
 
        /* Write length into vcons_in */
-       addr = bus->console_addr + offsetof(hndrte_cons_t, vcons_in);
+       addr = bus->console_addr + offsetof(struct rte_console, vcons_in);
        val = cpu_to_le32(msglen);
-       rv = dhdsdio_membytes(bus, true, addr, (u8 *)&val, sizeof(val));
+       rv = brcmf_sdbrcm_membytes(bus, true, addr, (u8 *)&val, sizeof(val));
        if (rv < 0)
                goto done;
 
        /* Bump dongle by sending an empty event pkt.
         * sdpcm_sendup (RX) checks for virtual console input.
         */
-       pkt = bcm_pkt_buf_get_skb(4 + SDPCM_RESERVE);
+       pkt = brcmu_pkt_buf_get_skb(4 + SDPCM_RESERVE);
        if ((pkt != NULL) && bus->clkstate == CLK_AVAIL)
-               dhdsdio_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true);
+               brcmf_sdbrcm_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true);
 
 done:
-       if ((bus->idletime == DHD_IDLE_IMMEDIATE) && !bus->dpc_sched) {
+       if ((bus->idletime == BRCMF_IDLE_IMMEDIATE) && !bus->dpc_sched) {
                bus->activity = false;
-               dhdsdio_clkctl(bus, CLK_NONE, true);
+               brcmf_sdbrcm_clkctl(bus, CLK_NONE, true);
        }
 
-       dhd_os_sdunlock(bus->dhd);
+       brcmf_sdbrcm_sdunlock(bus);
 
        return rv;
 }
-#endif                         /* DHD_DEBUG */
-
-#ifdef DHD_DEBUG
-static void dhd_dump_cis(uint fn, u8 *cis)
-{
-       uint byte, tag, tdata;
-       DHD_INFO(("Function %d CIS:\n", fn));
-
-       for (tdata = byte = 0; byte < SBSDIO_CIS_SIZE_LIMIT; byte++) {
-               if ((byte % 16) == 0)
-                       DHD_INFO(("    "));
-               DHD_INFO(("%02x ", cis[byte]));
-               if ((byte % 16) == 15)
-                       DHD_INFO(("\n"));
-               if (!tdata--) {
-                       tag = cis[byte];
-                       if (tag == 0xff)
-                               break;
-                       else if (!tag)
-                               tdata = 0;
-                       else if ((byte + 1) < SBSDIO_CIS_SIZE_LIMIT)
-                               tdata = cis[byte + 1] + 1;
-                       else
-                               DHD_INFO(("]"));
-               }
-       }
-       if ((byte % 16) != 15)
-               DHD_INFO(("\n"));
-}
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
-static bool dhdsdio_chipmatch(u16 chipid)
+static bool brcmf_sdbrcm_chipmatch(u16 chipid)
 {
        if (chipid == BCM4325_CHIP_ID)
                return true;
@@ -5009,12 +5325,12 @@ static bool dhdsdio_chipmatch(u16 chipid)
        return false;
 }
 
-static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
+static void *brcmf_sdbrcm_probe(u16 venid, u16 devid, u16 bus_no,
                           u16 slot, u16 func, uint bustype, void *regsva,
-                          void *sdh)
+                          void *card)
 {
        int ret;
-       dhd_bus_t *bus;
+       struct brcmf_bus *bus;
 
        /* Init global variables at run-time, not as part of the declaration.
         * This is required to support init/de-init of the driver.
@@ -5024,18 +5340,18 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
         * first time that the driver is initialized vs subsequent
         * initializations.
         */
-       dhd_txbound = DHD_TXBOUND;
-       dhd_rxbound = DHD_RXBOUND;
-       dhd_alignctl = true;
+       brcmf_txbound = DHD_TXBOUND;
+       brcmf_rxbound = DHD_RXBOUND;
+       brcmf_alignctl = true;
        sd1idle = true;
-       dhd_readahead = true;
+       brcmf_readahead = true;
        retrydata = false;
-       dhd_dongle_memsize = 0;
+       brcmf_dongle_memsize = 0;
        dhd_txminmax = DHD_TXMINMAX;
 
        forcealign = true;
 
-       dhd_common_init();
+       brcmf_c_init();
 
        DHD_TRACE(("%s: Enter\n", __func__));
        DHD_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid));
@@ -5043,7 +5359,7 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
        /* We make assumptions about address window mappings */
        ASSERT((unsigned long)regsva == SI_ENUM_BASE);
 
-       /* BCMSDH passes venid and devid based on CIS parsing -- but
+       /* SDIO car passes venid and devid based on CIS parsing -- but
         * low-power start
         * means early parse could fail, so here we should get either an ID
         * we recognize OR (-1) indicating we must request power first.
@@ -5088,12 +5404,12 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
        }
 
        /* Allocate private bus interface state */
-       bus = kzalloc(sizeof(dhd_bus_t), GFP_ATOMIC);
+       bus = kzalloc(sizeof(struct brcmf_bus), GFP_ATOMIC);
        if (!bus) {
-               DHD_ERROR(("%s: kmalloc of dhd_bus_t failed\n", __func__));
+               DHD_ERROR(("%s: kmalloc of struct dhd_bus failed\n", __func__));
                goto fail;
        }
-       bus->sdh = sdh;
+       bus->card = card;
        bus->cl_devid = (u16) devid;
        bus->bus = DHD_BUS;
        bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1;
@@ -5101,36 +5417,83 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
                                         else use locally malloced rxbuf */
 
        /* attempt to attach to the dongle */
-       if (!(dhdsdio_probe_attach(bus, sdh, regsva, devid))) {
-               DHD_ERROR(("%s: dhdsdio_probe_attach failed\n", __func__));
+       if (!(brcmf_sdbrcm_probe_attach(bus, card, regsva, devid))) {
+               DHD_ERROR(("%s: brcmf_sdbrcm_probe_attach failed\n", __func__));
                goto fail;
        }
 
+       spin_lock_init(&bus->txqlock);
+       init_waitqueue_head(&bus->ctrl_wait);
+
+       /* Set up the watchdog timer */
+       init_timer(&bus->timer);
+       bus->timer.data = (unsigned long)bus;
+       bus->timer.function = brcmf_sdbrcm_watchdog;
+
+       /* Initialize thread based operation and lock */
+       if ((brcmf_watchdog_prio >= 0) && (brcmf_dpc_prio >= 0)) {
+               bus->threads_only = true;
+               sema_init(&bus->sdsem, 1);
+       } else {
+               bus->threads_only = false;
+               spin_lock_init(&bus->sdlock);
+       }
+
+       if (brcmf_dpc_prio >= 0) {
+               /* Initialize watchdog thread */
+               init_completion(&bus->watchdog_wait);
+               bus->watchdog_tsk = kthread_run(brcmf_sdbrcm_watchdog_thread,
+                                               bus, "brcmf_watchdog");
+               if (IS_ERR(bus->watchdog_tsk)) {
+                       printk(KERN_WARNING
+                              "brcmf_watchdog thread failed to start\n");
+                       bus->watchdog_tsk = NULL;
+               }
+       } else
+               bus->watchdog_tsk = NULL;
+
+       /* Set up the bottom half handler */
+       if (brcmf_dpc_prio >= 0) {
+               /* Initialize DPC thread */
+               init_completion(&bus->dpc_wait);
+               bus->dpc_tsk = kthread_run(brcmf_sdbrcm_dpc_thread,
+                                          bus, "dhd_dpc");
+               if (IS_ERR(bus->dpc_tsk)) {
+                       printk(KERN_WARNING
+                              "dhd_dpc thread failed to start\n");
+                       bus->dpc_tsk = NULL;
+               }
+       } else {
+               tasklet_init(&bus->tasklet, brcmf_sdbrcm_dpc_tasklet,
+                            (unsigned long)bus);
+               bus->dpc_tsk = NULL;
+       }
+
        /* Attach to the dhd/OS/network interface */
-       bus->dhd = dhd_attach(bus, SDPCM_RESERVE);
-       if (!bus->dhd) {
+       bus->drvr = brcmf_attach(bus, SDPCM_RESERVE);
+       if (!bus->drvr) {
                DHD_ERROR(("%s: dhd_attach failed\n", __func__));
                goto fail;
        }
 
        /* Allocate buffers */
-       if (!(dhdsdio_probe_malloc(bus, sdh))) {
-               DHD_ERROR(("%s: dhdsdio_probe_malloc failed\n", __func__));
+       if (!(brcmf_sdbrcm_probe_malloc(bus, card))) {
+               DHD_ERROR(("%s: brcmf_sdbrcm_probe_malloc failed\n", __func__));
                goto fail;
        }
 
-       if (!(dhdsdio_probe_init(bus, sdh))) {
-               DHD_ERROR(("%s: dhdsdio_probe_init failed\n", __func__));
+       if (!(brcmf_sdbrcm_probe_init(bus, card))) {
+               DHD_ERROR(("%s: brcmf_sdbrcm_probe_init failed\n", __func__));
                goto fail;
        }
 
        /* Register interrupt callback, but mask it (not operational yet). */
        DHD_INTR(("%s: disable SDIO interrupts (not interested yet)\n",
                  __func__));
-       bcmsdh_intr_disable(sdh);
-       ret = bcmsdh_intr_reg(sdh, dhdsdio_isr, bus);
+       brcmf_sdcard_intr_disable(card);
+       ret = brcmf_sdcard_intr_reg(card, brcmf_sdbrcm_isr, bus);
        if (ret != 0) {
-               DHD_ERROR(("%s: FAILED: bcmsdh_intr_reg returned %d\n",
+               DHD_ERROR(("%s: FAILED: sdcard_intr_reg returned %d\n",
                           __func__, ret));
                goto fail;
        }
@@ -5139,7 +5502,7 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
        DHD_INFO(("%s: completed!!\n", __func__));
 
        /* if firmware path present try to download and bring up bus */
-       ret = dhd_bus_start(bus->dhd);
+       ret = brcmf_bus_start(bus->drvr);
        if (ret != 0) {
                if (ret == -ENOLINK) {
                        DHD_ERROR(("%s: dongle is not responding\n", __func__));
@@ -5147,7 +5510,7 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
                }
        }
        /* Ok, have the per-port tell the stack we're open for business */
-       if (dhd_net_attach(bus->dhd, 0) != 0) {
+       if (brcmf_net_attach(bus->drvr, 0) != 0) {
                DHD_ERROR(("%s: Net attach failed!!\n", __func__));
                goto fail;
        }
@@ -5155,12 +5518,13 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
        return bus;
 
 fail:
-       dhdsdio_release(bus);
+       brcmf_sdbrcm_release(bus);
        return NULL;
 }
 
 static bool
-dhdsdio_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, u16 devid)
+brcmf_sdbrcm_probe_attach(struct brcmf_bus *bus, void *card, void *regsva,
+                         u16 devid)
 {
        u8 clkctl = 0;
        int err = 0;
@@ -5168,102 +5532,52 @@ dhdsdio_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, u16 devid)
        bus->alp_only = true;
 
        /* Return the window to backplane enumeration space for core access */
-       if (dhdsdio_set_siaddr_window(bus, SI_ENUM_BASE))
+       if (brcmf_sdbrcm_set_siaddr_window(bus, SI_ENUM_BASE))
                DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__));
 
-#ifdef DHD_DEBUG
+#ifdef BCMDBG
        printk(KERN_DEBUG "F1 signature read @0x18000000=0x%4x\n",
-              bcmsdh_reg_read(bus->sdh, SI_ENUM_BASE, 4));
+              brcmf_sdcard_reg_read(bus->card, SI_ENUM_BASE, 4));
 
-#endif                         /* DHD_DEBUG */
+#endif                         /* BCMDBG */
 
        /*
-        * Force PLL off until dhdsdio_chip_attach()
+        * Force PLL off until brcmf_sdbrcm_chip_attach()
         * programs PLL control regs
         */
 
-       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
+       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
                         DHD_INIT_CLKCTL1, &err);
        if (!err)
                clkctl =
-                   bcmsdh_cfg_read(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                   &err);
+                   brcmf_sdcard_cfg_read(card, SDIO_FUNC_1,
+                                         SBSDIO_FUNC1_CHIPCLKCSR, &err);
 
        if (err || ((clkctl & ~SBSDIO_AVBITS) != DHD_INIT_CLKCTL1)) {
-               DHD_ERROR(("dhdsdio_probe: ChipClkCSR access: err %d wrote "
-                       "0x%02x read 0x%02x\n",
+               DHD_ERROR(("brcmf_sdbrcm_probe: ChipClkCSR access: err %d wrote"
+                       " 0x%02x read 0x%02x\n",
                        err, DHD_INIT_CLKCTL1, clkctl));
                goto fail;
        }
-#ifdef DHD_DEBUG
-       if (DHD_INFO_ON()) {
-               uint fn, numfn;
-               u8 *cis[SDIOD_MAX_IOFUNCS];
-               int err = 0;
-
-               numfn = bcmsdh_query_iofnum(sdh);
-               ASSERT(numfn <= SDIOD_MAX_IOFUNCS);
 
-               /* Make sure ALP is available before trying to read CIS */
-               SPINWAIT(((clkctl = bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
-                                                   SBSDIO_FUNC1_CHIPCLKCSR,
-                                                   NULL)),
-                         !SBSDIO_ALPAV(clkctl)), PMU_MAX_TRANSITION_DLY);
-
-               /* Now request ALP be put on the bus */
-               bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
-                                DHD_INIT_CLKCTL2, &err);
-               udelay(65);
-
-               for (fn = 0; fn <= numfn; fn++) {
-                       cis[fn] = kzalloc(SBSDIO_CIS_SIZE_LIMIT, GFP_ATOMIC);
-                       if (!cis[fn]) {
-                               DHD_INFO(("dhdsdio_probe: fn %d cis malloc "
-                                       "failed\n", fn));
-                               break;
-                       }
-
-                       err = bcmsdh_cis_read(sdh, fn, cis[fn],
-                                               SBSDIO_CIS_SIZE_LIMIT);
-                       if (err) {
-                               DHD_INFO(("dhdsdio_probe: fn %d cis read "
-                                       "err %d\n", fn, err));
-                               kfree(cis[fn]);
-                               break;
-                       }
-                       dhd_dump_cis(fn, cis[fn]);
-               }
-
-               while (fn-- > 0) {
-                       ASSERT(cis[fn]);
-                       kfree(cis[fn]);
-               }
-
-               if (err) {
-                       DHD_ERROR(("dhdsdio_probe: error read/parsing CIS\n"));
-                       goto fail;
-               }
-       }
-#endif                         /* DHD_DEBUG */
-
-       if (dhdsdio_chip_attach(bus, regsva)) {
-               DHD_ERROR(("%s: dhdsdio_chip_attach failed!\n", __func__));
+       if (brcmf_sdbrcm_chip_attach(bus, regsva)) {
+               DHD_ERROR(("%s: brcmf_sdbrcm_chip_attach failed!\n", __func__));
                goto fail;
        }
 
-       bcmsdh_chipinfo(sdh, bus->ci->chip, bus->ci->chiprev);
+       brcmf_sdcard_chipinfo(card, bus->ci->chip, bus->ci->chiprev);
 
-       if (!dhdsdio_chipmatch((u16) bus->ci->chip)) {
+       if (!brcmf_sdbrcm_chipmatch((u16) bus->ci->chip)) {
                DHD_ERROR(("%s: unsupported chip: 0x%04x\n",
                           __func__, bus->ci->chip));
                goto fail;
        }
 
-       dhdsdio_sdiod_drive_strength_init(bus, dhd_sdiod_drive_strength);
+       brcmf_sdbrcm_sdiod_drive_strength_init(bus, brcmf_sdiod_drive_strength);
 
        /* Get info on the ARM and SOCRAM cores... */
        if (!DHD_NOPMU(bus)) {
-               bus->armrev = SBCOREREV(bcmsdh_reg_read(bus->sdh,
+               bus->armrev = SBCOREREV(brcmf_sdcard_reg_read(bus->card,
                        CORE_SB(bus->ci->armcorebase, sbidhigh), 4));
                bus->orig_ramsize = bus->ci->ramsize;
                if (!(bus->orig_ramsize)) {
@@ -5272,8 +5586,8 @@ dhdsdio_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, u16 devid)
                        goto fail;
                }
                bus->ramsize = bus->orig_ramsize;
-               if (dhd_dongle_memsize)
-                       dhd_dongle_setmemsize(bus, dhd_dongle_memsize);
+               if (brcmf_dongle_memsize)
+                       brcmf_sdbrcm_setmemsize(bus, brcmf_dongle_memsize);
 
                DHD_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n",
                           bus->ramsize, bus->orig_ramsize));
@@ -5284,14 +5598,15 @@ dhdsdio_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, u16 devid)
        /* Set core control so an SDIO reset does a backplane reset */
        OR_REG(&bus->regs->corecontrol, CC_BPRESEN);
 
-       bcm_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN);
+       brcmu_pktq_init(&bus->txq, (PRIOMASK + 1), TXQLEN);
 
        /* Locate an appropriately-aligned portion of hdrbuf */
-       bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0], DHD_SDALIGN);
+       bus->rxhdr = (u8 *) roundup((unsigned long)&bus->hdrbuf[0],
+                                   BRCMF_SDALIGN);
 
        /* Set the poll and/or interrupt flags */
-       bus->intr = (bool) dhd_intr;
-       bus->poll = (bool) dhd_poll;
+       bus->intr = (bool) brcmf_intr;
+       bus->poll = (bool) brcmf_poll;
        if (bus->poll)
                bus->pollrate = 1;
 
@@ -5301,14 +5616,14 @@ fail:
        return false;
 }
 
-static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh)
+static bool brcmf_sdbrcm_probe_malloc(struct brcmf_bus *bus, void *card)
 {
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       if (bus->dhd->maxctl) {
+       if (bus->drvr->maxctl) {
                bus->rxblen =
-                   roundup((bus->dhd->maxctl + SDPCM_HDRLEN),
-                           ALIGNMENT) + DHD_SDALIGN;
+                   roundup((bus->drvr->maxctl + SDPCM_HDRLEN),
+                           ALIGNMENT) + BRCMF_SDALIGN;
                bus->rxbuf = kmalloc(bus->rxblen, GFP_ATOMIC);
                if (!(bus->rxbuf)) {
                        DHD_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n",
@@ -5329,10 +5644,9 @@ static bool dhdsdio_probe_malloc(dhd_bus_t *bus, void *sdh)
        }
 
        /* Align the buffer */
-       if ((unsigned long)bus->databuf % DHD_SDALIGN)
-               bus->dataptr =
-                   bus->databuf + (DHD_SDALIGN -
-                                   ((unsigned long)bus->databuf % DHD_SDALIGN));
+       if ((unsigned long)bus->databuf % BRCMF_SDALIGN)
+               bus->dataptr = bus->databuf + (BRCMF_SDALIGN -
+                              ((unsigned long)bus->databuf % BRCMF_SDALIGN));
        else
                bus->dataptr = bus->databuf;
 
@@ -5342,57 +5656,37 @@ fail:
        return false;
 }
 
-static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh)
+static bool brcmf_sdbrcm_probe_init(struct brcmf_bus *bus, void *card)
 {
        s32 fnum;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
 #ifdef SDTEST
-       dhdsdio_pktgen_init(bus);
+       brcmf_sdbrcm_pktgen_init(bus);
 #endif                         /* SDTEST */
 
        /* Disable F2 to clear any intermediate frame state on the dongle */
-       bcmsdh_cfg_write(sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, SDIO_FUNC_ENABLE_1,
-                        NULL);
+       brcmf_sdcard_cfg_write(card, SDIO_FUNC_0, SDIO_CCCR_IOEx,
+                              SDIO_FUNC_ENABLE_1, NULL);
 
-       bus->dhd->busstate = DHD_BUS_DOWN;
+       bus->drvr->busstate = DHD_BUS_DOWN;
        bus->sleeping = false;
        bus->rxflow = false;
        bus->prev_rxlim_hit = 0;
 
        /* Done with backplane-dependent accesses, can drop clock... */
-       bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, NULL);
+       brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0,
+                              NULL);
 
        /* ...and initialize clock/power states */
        bus->clkstate = CLK_SDONLY;
-       bus->idletime = (s32) dhd_idletime;
-       bus->idleclock = DHD_IDLE_ACTIVE;
-
-       /* Query the SD clock speed */
-       if (bcmsdh_iovar_op(sdh, "sd_divisor", NULL, 0,
-                           &bus->sd_divisor, sizeof(s32),
-                           false) != 0) {
-               DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_divisor"));
-               bus->sd_divisor = -1;
-       } else {
-               DHD_INFO(("%s: Initial value for %s is %d\n",
-                         __func__, "sd_divisor", bus->sd_divisor));
-       }
-
-       /* Query the SD bus mode */
-       if (bcmsdh_iovar_op(sdh, "sd_mode", NULL, 0,
-                           &bus->sd_mode, sizeof(s32), false) != 0) {
-               DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_mode"));
-               bus->sd_mode = -1;
-       } else {
-               DHD_INFO(("%s: Initial value for %s is %d\n",
-                         __func__, "sd_mode", bus->sd_mode));
-       }
+       bus->idletime = (s32) brcmf_idletime;
+       bus->idleclock = BRCMF_IDLE_ACTIVE;
 
        /* Query the F2 block size, set roundup accordingly */
        fnum = 2;
-       if (bcmsdh_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32),
+       if (brcmf_sdcard_iovar_op(card, "sd_blocksize", &fnum, sizeof(s32),
                            &bus->blocksize, sizeof(s32), false) != 0) {
                bus->blocksize = 0;
                DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize"));
@@ -5404,12 +5698,12 @@ static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh)
 
        /* Query if bus module supports packet chaining,
                 default to use if supported */
-       if (bcmsdh_iovar_op(sdh, "sd_rxchain", NULL, 0,
+       if (brcmf_sdcard_iovar_op(card, "sd_rxchain", NULL, 0,
                            &bus->sd_rxchain, sizeof(s32),
                            false) != 0) {
                bus->sd_rxchain = false;
        } else {
-               DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n",
+               DHD_INFO(("%s: bus module (through sdiocard API) %s chaining\n",
                          __func__,
                          (bus->sd_rxchain ? "supports" : "does not support")));
        }
@@ -5418,50 +5712,38 @@ static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh)
        return true;
 }
 
-bool
-dhd_bus_download_firmware(struct dhd_bus *bus, char *fw_path, char *nv_path)
-{
-       bool ret;
-       bus->fw_path = fw_path;
-       bus->nv_path = nv_path;
-
-       ret = dhdsdio_download_firmware(bus, bus->sdh);
-
-       return ret;
-}
-
 static bool
-dhdsdio_download_firmware(struct dhd_bus *bus, void *sdh)
+brcmf_sdbrcm_download_firmware(struct brcmf_bus *bus, void *card)
 {
        bool ret;
 
        /* Download the firmware */
-       dhdsdio_clkctl(bus, CLK_AVAIL, false);
+       brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
 
-       ret = _dhdsdio_download_firmware(bus) == 0;
+       ret = _brcmf_sdbrcm_download_firmware(bus) == 0;
 
-       dhdsdio_clkctl(bus, CLK_SDONLY, false);
+       brcmf_sdbrcm_clkctl(bus, CLK_SDONLY, false);
 
        return ret;
 }
 
 /* Detach and free everything */
-static void dhdsdio_release(dhd_bus_t *bus)
+static void brcmf_sdbrcm_release(struct brcmf_bus *bus)
 {
        DHD_TRACE(("%s: Enter\n", __func__));
 
        if (bus) {
                /* De-register interrupt handler */
-               bcmsdh_intr_disable(bus->sdh);
-               bcmsdh_intr_dereg(bus->sdh);
+               brcmf_sdcard_intr_disable(bus->card);
+               brcmf_sdcard_intr_dereg(bus->card);
 
-               if (bus->dhd) {
-                       dhd_detach(bus->dhd);
-                       dhdsdio_release_dongle(bus);
-                       bus->dhd = NULL;
+               if (bus->drvr) {
+                       brcmf_detach(bus->drvr);
+                       brcmf_sdbrcm_release_dongle(bus);
+                       bus->drvr = NULL;
                }
 
-               dhdsdio_release_malloc(bus);
+               brcmf_sdbrcm_release_malloc(bus);
 
                kfree(bus);
        }
@@ -5469,34 +5751,32 @@ static void dhdsdio_release(dhd_bus_t *bus)
        DHD_TRACE(("%s: Disconnected\n", __func__));
 }
 
-static void dhdsdio_release_malloc(dhd_bus_t *bus)
+static void brcmf_sdbrcm_release_malloc(struct brcmf_bus *bus)
 {
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       if (bus->dhd && bus->dhd->dongle_reset)
+       if (bus->drvr && bus->drvr->dongle_reset)
                return;
 
-       if (bus->rxbuf) {
-               kfree(bus->rxbuf);
-               bus->rxctl = bus->rxbuf = NULL;
-               bus->rxlen = 0;
-       }
+       kfree(bus->rxbuf);
+       bus->rxctl = bus->rxbuf = NULL;
+       bus->rxlen = 0;
 
        kfree(bus->databuf);
        bus->databuf = NULL;
 }
 
-static void dhdsdio_release_dongle(dhd_bus_t *bus)
+static void brcmf_sdbrcm_release_dongle(struct brcmf_bus *bus)
 {
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       if (bus->dhd && bus->dhd->dongle_reset)
+       if (bus->drvr && bus->drvr->dongle_reset)
                return;
 
        if (bus->ci) {
-               dhdsdio_clkctl(bus, CLK_AVAIL, false);
-               dhdsdio_clkctl(bus, CLK_NONE, false);
-               dhdsdio_chip_detach(bus);
+               brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
+               brcmf_sdbrcm_clkctl(bus, CLK_NONE, false);
+               brcmf_sdbrcm_chip_detach(bus);
                if (bus->vars && bus->varsz)
                        kfree(bus->vars);
                bus->vars = NULL;
@@ -5505,15 +5785,15 @@ static void dhdsdio_release_dongle(dhd_bus_t *bus)
        DHD_TRACE(("%s: Disconnected\n", __func__));
 }
 
-static void dhdsdio_disconnect(void *ptr)
+static void brcmf_sdbrcm_disconnect(void *ptr)
 {
-       dhd_bus_t *bus = (dhd_bus_t *)ptr;
+       struct brcmf_bus *bus = (struct brcmf_bus *)ptr;
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
        if (bus) {
-               ASSERT(bus->dhd);
-               dhdsdio_release(bus);
+               ASSERT(bus->drvr);
+               brcmf_sdbrcm_release(bus);
        }
 
        DHD_TRACE(("%s: Disconnected\n", __func__));
@@ -5524,147 +5804,76 @@ static void dhdsdio_disconnect(void *ptr)
  * order to look for or await the device.
  */
 
-static bcmsdh_driver_t dhd_sdio = {
-       dhdsdio_probe,
-       dhdsdio_disconnect
+static struct brcmf_sdioh_driver dhd_sdio = {
+       brcmf_sdbrcm_probe,
+       brcmf_sdbrcm_disconnect
 };
 
-int dhd_bus_register(void)
+int brcmf_bus_register(void)
 {
        DHD_TRACE(("%s: Enter\n", __func__));
 
-       return bcmsdh_register(&dhd_sdio);
-}
+       /* Sanity check on the module parameters */
+       do {
+               /* Both watchdog and DPC as tasklets are ok */
+               if ((brcmf_watchdog_prio < 0) && (brcmf_dpc_prio < 0))
+                       break;
 
-void dhd_bus_unregister(void)
-{
-       DHD_TRACE(("%s: Enter\n", __func__));
+               /* If both watchdog and DPC are threads, TX must be deferred */
+               if ((brcmf_watchdog_prio >= 0) && (brcmf_dpc_prio >= 0)
+                   && brcmf_deferred_tx)
+                       break;
+
+               DHD_ERROR(("Invalid module parameters.\n"));
+               return -EINVAL;
+       } while (0);
 
-       bcmsdh_unregister();
+       return brcmf_sdio_register(&dhd_sdio);
 }
 
-#ifdef BCMEMBEDIMAGE
-static int dhdsdio_download_code_array(struct dhd_bus *bus)
+void brcmf_bus_unregister(void)
 {
-       int bcmerror = -1;
-       int offset = 0;
-
-       DHD_INFO(("%s: download embedded firmware...\n", __func__));
-
-       /* Download image */
-       while ((offset + MEMBLOCK) < sizeof(dlarray)) {
-               bcmerror =
-                   dhdsdio_membytes(bus, true, offset, dlarray + offset,
-                                    MEMBLOCK);
-               if (bcmerror) {
-                       DHD_ERROR(("%s: error %d on writing %d membytes at "
-                               "0x%08x\n",
-                               __func__, bcmerror, MEMBLOCK, offset));
-                       goto err;
-               }
-
-               offset += MEMBLOCK;
-       }
-
-       if (offset < sizeof(dlarray)) {
-               bcmerror = dhdsdio_membytes(bus, true, offset,
-                                           dlarray + offset,
-                                           sizeof(dlarray) - offset);
-               if (bcmerror) {
-                       DHD_ERROR(("%s: error %d on writing %d membytes at "
-                               "0x%08x\n", __func__, bcmerror,
-                               sizeof(dlarray) - offset, offset));
-                       goto err;
-               }
-       }
-#ifdef DHD_DEBUG
-       /* Upload and compare the downloaded code */
-       {
-               unsigned char *ularray;
-
-               ularray = kmalloc(bus->ramsize, GFP_ATOMIC);
-               if (!ularray) {
-                       bcmerror = -ENOMEM;
-                       goto err;
-               }
-               /* Upload image to verify downloaded contents. */
-               offset = 0;
-               memset(ularray, 0xaa, bus->ramsize);
-               while ((offset + MEMBLOCK) < sizeof(dlarray)) {
-                       bcmerror =
-                           dhdsdio_membytes(bus, false, offset,
-                                            ularray + offset, MEMBLOCK);
-                       if (bcmerror) {
-                               DHD_ERROR(("%s: error %d on reading %d membytes"
-                                       " at 0x%08x\n",
-                                       __func__, bcmerror, MEMBLOCK, offset));
-                               goto free;
-                       }
-
-                       offset += MEMBLOCK;
-               }
-
-               if (offset < sizeof(dlarray)) {
-                       bcmerror = dhdsdio_membytes(bus, false, offset,
-                                                   ularray + offset,
-                                                   sizeof(dlarray) - offset);
-                       if (bcmerror) {
-                               DHD_ERROR(("%s: error %d on reading %d membytes at 0x%08x\n",
-                               __func__, bcmerror,
-                               sizeof(dlarray) - offset, offset));
-                               goto free;
-                       }
-               }
-
-               if (memcmp(dlarray, ularray, sizeof(dlarray))) {
-                       DHD_ERROR(("%s: Downloaded image is corrupted.\n",
-                                  __func__));
-                       ASSERT(0);
-                       goto free;
-               } else
-                       DHD_ERROR(("%s: Download/Upload/Compare succeeded.\n",
-                               __func__));
-free:
-               kfree(ularray);
-       }
-#endif                         /* DHD_DEBUG */
+       DHD_TRACE(("%s: Enter\n", __func__));
 
-err:
-       return bcmerror;
+       brcmf_sdio_unregister();
 }
-#endif                         /* BCMEMBEDIMAGE */
 
-static int dhdsdio_download_code_file(struct dhd_bus *bus, char *fw_path)
+static int brcmf_sdbrcm_download_code_file(struct brcmf_bus *bus)
 {
-       int bcmerror = -1;
        int offset = 0;
        uint len;
-       void *image = NULL;
        u8 *memblock = NULL, *memptr;
+       int ret;
 
-       DHD_INFO(("%s: download firmware %s\n", __func__, fw_path));
+       DHD_INFO(("%s: Enter\n", __func__));
 
-       image = dhd_os_open_image(fw_path);
-       if (image == NULL)
-               goto err;
+       bus->fw_name = BCM4329_FW_NAME;
+       ret = request_firmware(&bus->firmware, bus->fw_name,
+                              &gInstance->func[2]->dev);
+       if (ret) {
+               DHD_ERROR(("%s: Fail to request firmware %d\n", __func__, ret));
+               return ret;
+       }
+       bus->fw_ptr = 0;
 
-       memptr = memblock = kmalloc(MEMBLOCK + DHD_SDALIGN, GFP_ATOMIC);
+       memptr = memblock = kmalloc(MEMBLOCK + BRCMF_SDALIGN, GFP_ATOMIC);
        if (memblock == NULL) {
                DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
                           __func__, MEMBLOCK));
+               ret = -ENOMEM;
                goto err;
        }
-       if ((u32)(unsigned long)memblock % DHD_SDALIGN)
-               memptr +=
-                   (DHD_SDALIGN - ((u32)(unsigned long)memblock % DHD_SDALIGN));
+       if ((u32)(unsigned long)memblock % BRCMF_SDALIGN)
+               memptr += (BRCMF_SDALIGN -
+                          ((u32)(unsigned long)memblock % BRCMF_SDALIGN));
 
        /* Download image */
        while ((len =
-               dhd_os_get_image_block((char *)memptr, MEMBLOCK, image))) {
-               bcmerror = dhdsdio_membytes(bus, true, offset, memptr, len);
-               if (bcmerror) {
+               brcmf_sdbrcm_get_image((char *)memptr, MEMBLOCK, bus))) {
+               ret = brcmf_sdbrcm_membytes(bus, true, offset, memptr, len);
+               if (ret) {
                        DHD_ERROR(("%s: error %d on writing %d membytes at "
-                       "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset));
+                       "0x%08x\n", __func__, ret, MEMBLOCK, offset));
                        goto err;
                }
 
@@ -5674,10 +5883,10 @@ static int dhdsdio_download_code_file(struct dhd_bus *bus, char *fw_path)
 err:
        kfree(memblock);
 
-       if (image)
-               dhd_os_close_image(image);
+       release_firmware(bus->firmware);
+       bus->fw_ptr = 0;
 
-       return bcmerror;
+       return ret;
 }
 
 /*
@@ -5689,7 +5898,7 @@ err:
  * by two NULs.
 */
 
-static uint process_nvram_vars(char *varbuf, uint len)
+static uint brcmf_process_nvram_vars(char *varbuf, uint len)
 {
        char *dp;
        bool findNewline;
@@ -5731,144 +5940,72 @@ static uint process_nvram_vars(char *varbuf, uint len)
        return buf_len;
 }
 
-/*
-       EXAMPLE: nvram_array
-       nvram_arry format:
-       name=value
-       Use carriage return at the end of each assignment,
-        and an empty string with
-       carriage return at the end of array.
-
-       For example:
-       unsigned char  nvram_array[] = {"name1=value1\n",
-       "name2=value2\n", "\n"};
-       Hex values start with 0x, and mac addr format: xx:xx:xx:xx:xx:xx.
-
-       Search "EXAMPLE: nvram_array" to see how the array is activated.
-*/
-
-void dhd_bus_set_nvram_params(struct dhd_bus *bus, const char *nvram_params)
-{
-       bus->nvram_params = nvram_params;
-}
-
-static int dhdsdio_download_nvram(struct dhd_bus *bus)
+static int brcmf_sdbrcm_download_nvram(struct brcmf_bus *bus)
 {
-       int bcmerror = -1;
        uint len;
-       void *image = NULL;
        char *memblock = NULL;
        char *bufp;
-       char *nv_path;
-       bool nvram_file_exists;
-
-       nv_path = bus->nv_path;
-
-       nvram_file_exists = ((nv_path != NULL) && (nv_path[0] != '\0'));
-       if (!nvram_file_exists && (bus->nvram_params == NULL))
-               return 0;
+       int ret;
 
-       if (nvram_file_exists) {
-               image = dhd_os_open_image(nv_path);
-               if (image == NULL)
-                       goto err;
+       bus->nv_name = BCM4329_NV_NAME;
+       ret = request_firmware(&bus->firmware, bus->nv_name,
+                              &gInstance->func[2]->dev);
+       if (ret) {
+               DHD_ERROR(("%s: Fail to request nvram %d\n", __func__, ret));
+               return ret;
        }
+       bus->fw_ptr = 0;
 
        memblock = kmalloc(MEMBLOCK, GFP_ATOMIC);
        if (memblock == NULL) {
                DHD_ERROR(("%s: Failed to allocate memory %d bytes\n",
                           __func__, MEMBLOCK));
+               ret = -ENOMEM;
                goto err;
        }
 
-       /* Download variables */
-       if (nvram_file_exists) {
-               len = dhd_os_get_image_block(memblock, MEMBLOCK, image);
-       } else {
-               len = strlen(bus->nvram_params);
-               ASSERT(len <= MEMBLOCK);
-               if (len > MEMBLOCK)
-                       len = MEMBLOCK;
-               memcpy(memblock, bus->nvram_params, len);
-       }
+       len = brcmf_sdbrcm_get_image(memblock, MEMBLOCK, bus);
 
        if (len > 0 && len < MEMBLOCK) {
                bufp = (char *)memblock;
                bufp[len] = 0;
-               len = process_nvram_vars(bufp, len);
+               len = brcmf_process_nvram_vars(bufp, len);
                bufp += len;
                *bufp++ = 0;
                if (len)
-                       bcmerror = dhdsdio_downloadvars(bus, memblock, len + 1);
-               if (bcmerror) {
+                       ret = brcmf_sdbrcm_downloadvars(bus, memblock, len + 1);
+               if (ret)
                        DHD_ERROR(("%s: error downloading vars: %d\n",
-                                  __func__, bcmerror));
-               }
+                                  __func__, ret));
        } else {
                DHD_ERROR(("%s: error reading nvram file: %d\n",
                           __func__, len));
-               bcmerror = -EIO;
+               ret = -EIO;
        }
 
 err:
        kfree(memblock);
 
-       if (image)
-               dhd_os_close_image(image);
+       release_firmware(bus->firmware);
+       bus->fw_ptr = 0;
 
-       return bcmerror;
+       return ret;
 }
 
-static int _dhdsdio_download_firmware(struct dhd_bus *bus)
+static int _brcmf_sdbrcm_download_firmware(struct brcmf_bus *bus)
 {
        int bcmerror = -1;
 
-       bool embed = false;     /* download embedded firmware */
-       bool dlok = false;      /* download firmware succeeded */
-
-       /* Out immediately if no image to download */
-       if ((bus->fw_path == NULL) || (bus->fw_path[0] == '\0')) {
-#ifdef BCMEMBEDIMAGE
-               embed = true;
-#else
-               return bcmerror;
-#endif
-       }
-
        /* Keep arm in reset */
-       if (dhdsdio_download_state(bus, true)) {
+       if (brcmf_sdbrcm_download_state(bus, true)) {
                DHD_ERROR(("%s: error placing ARM core in reset\n", __func__));
                goto err;
        }
 
        /* External image takes precedence if specified */
-       if ((bus->fw_path != NULL) && (bus->fw_path[0] != '\0')) {
-               if (dhdsdio_download_code_file(bus, bus->fw_path)) {
-                       DHD_ERROR(("%s: dongle image file download failed\n",
-                                  __func__));
-#ifdef BCMEMBEDIMAGE
-                       embed = true;
-#else
-                       goto err;
-#endif
-               } else {
-                       embed = false;
-                       dlok = true;
-               }
-       }
-#ifdef BCMEMBEDIMAGE
-       if (embed) {
-               if (dhdsdio_download_code_array(bus)) {
-                       DHD_ERROR(("%s: dongle image array download failed\n",
-                                  __func__));
-                       goto err;
-               } else {
-                       dlok = true;
-               }
-       }
-#endif
-       if (!dlok) {
-               DHD_ERROR(("%s: dongle image download failed\n", __func__));
+       if (brcmf_sdbrcm_download_code_file(bus)) {
+               DHD_ERROR(("%s: dongle image file download failed\n",
+                         __func__));
                goto err;
        }
 
@@ -5878,13 +6015,13 @@ static int _dhdsdio_download_firmware(struct dhd_bus *bus)
        /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */
 
        /* External nvram takes precedence if specified */
-       if (dhdsdio_download_nvram(bus)) {
+       if (brcmf_sdbrcm_download_nvram(bus)) {
                DHD_ERROR(("%s: dongle nvram file download failed\n",
                           __func__));
        }
 
        /* Take arm out of reset */
-       if (dhdsdio_download_state(bus, false)) {
+       if (brcmf_sdbrcm_download_state(bus, false)) {
                DHD_ERROR(("%s: error getting out of ARM core reset\n",
                           __func__));
                goto err;
@@ -5898,56 +6035,59 @@ err:
 
 
 static int
-dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags,
+brcmf_sdbrcm_send_buf(struct brcmf_bus *bus, u32 addr, uint fn, uint flags,
                    u8 *buf, uint nbytes, struct sk_buff *pkt,
-                   bcmsdh_cmplt_fn_t complete, void *handle)
+                   void (*complete)(void *handle, int status,
+                                    bool sync_waiting),
+                   void *handle)
 {
-       return bcmsdh_send_buf
-               (bus->sdh, addr, fn, flags, buf, nbytes, pkt, complete,
+       return brcmf_sdcard_send_buf
+               (bus->card, addr, fn, flags, buf, nbytes, pkt, complete,
                 handle);
 }
 
-uint dhd_bus_chip(struct dhd_bus *bus)
+uint brcmf_bus_chip(struct brcmf_bus *bus)
 {
        ASSERT(bus->ci != NULL);
        return bus->ci->chip;
 }
 
-void *dhd_bus_pub(struct dhd_bus *bus)
+void *brcmf_bus_drvr(struct brcmf_bus *bus)
 {
-       return bus->dhd;
+       return bus->drvr;
 }
 
-void *dhd_bus_txq(struct dhd_bus *bus)
+void *brcmf_bus_txq(struct brcmf_bus *bus)
 {
        return &bus->txq;
 }
 
-uint dhd_bus_hdrlen(struct dhd_bus *bus)
+uint brcmf_bus_hdrlen(struct brcmf_bus *bus)
 {
        return SDPCM_HDRLEN;
 }
 
-int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag)
+int brcmf_bus_devreset(struct brcmf_pub *drvr, u8 flag)
 {
        int bcmerror = 0;
-       dhd_bus_t *bus;
+       struct brcmf_bus *bus;
 
-       bus = dhdp->bus;
+       bus = drvr->bus;
 
        if (flag == true) {
-               if (!bus->dhd->dongle_reset) {
+               brcmf_sdbrcm_wd_timer(bus, 0);
+               if (!bus->drvr->dongle_reset) {
                        /* Expect app to have torn down any
                         connection before calling */
                        /* Stop the bus, disable F2 */
-                       dhd_bus_stop(bus, false);
+                       brcmf_sdbrcm_bus_stop(bus, false);
 
                        /* Clean tx/rx buffer pointers,
                         detach from the dongle */
-                       dhdsdio_release_dongle(bus);
+                       brcmf_sdbrcm_release_dongle(bus);
 
-                       bus->dhd->dongle_reset = true;
-                       bus->dhd->up = false;
+                       bus->drvr->dongle_reset = true;
+                       bus->drvr->up = false;
 
                        DHD_TRACE(("%s:  WLAN OFF DONE\n", __func__));
                        /* App can now remove power from device */
@@ -5958,31 +6098,20 @@ int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag)
 
                DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__));
 
-               if (bus->dhd->dongle_reset) {
+               if (bus->drvr->dongle_reset) {
                        /* Turn on WLAN */
-                       /* Reset SD client */
-                       bcmsdh_reset(bus->sdh);
 
                        /* Attempt to re-attach & download */
-                       if (dhdsdio_probe_attach(bus, bus->sdh,
+                       if (brcmf_sdbrcm_probe_attach(bus, bus->card,
                                                 (u32 *) SI_ENUM_BASE,
                                                 bus->cl_devid)) {
                                /* Attempt to download binary to the dongle */
-                               if (dhdsdio_probe_init
-                                   (bus, bus->sdh)
-                                   && dhdsdio_download_firmware(bus,
-                                                                bus->sdh)) {
-
+                               if (brcmf_sdbrcm_probe_init(bus, bus->card)) {
                                        /* Re-init bus, enable F2 transfer */
-                                       dhd_bus_init((dhd_pub_t *) bus->dhd,
-                                                    false);
-
-#if defined(OOB_INTR_ONLY)
-                                       dhd_enable_oob_intr(bus, true);
-#endif                         /* defined(OOB_INTR_ONLY) */
+                                       brcmf_sdbrcm_bus_init(bus->drvr, false);
 
-                                       bus->dhd->dongle_reset = false;
-                                       bus->dhd->up = true;
+                                       bus->drvr->dongle_reset = false;
+                                       bus->drvr->up = true;
 
                                        DHD_TRACE(("%s: WLAN ON DONE\n",
                                                   __func__));
@@ -5996,12 +6125,14 @@ int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag)
                                "is on\n", __func__));
                        bcmerror = -EIO;
                }
+               brcmf_sdbrcm_wd_timer(bus, brcmf_watchdog_ms);
        }
        return bcmerror;
 }
 
 static int
-dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs)
+brcmf_sdbrcm_chip_recognition(struct brcmf_sdio_card *card,
+                             struct chip_info *ci, void *regs)
 {
        u32 regdata;
 
@@ -6012,7 +6143,8 @@ dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs)
         * other ways of recognition should be added here.
         */
        ci->cccorebase = (u32)regs;
-       regdata = bcmsdh_reg_read(sdh, CORE_CC_REG(ci->cccorebase, chipid), 4);
+       regdata = brcmf_sdcard_reg_read(card,
+                               CORE_CC_REG(ci->cccorebase, chipid), 4);
        ci->chip = regdata & CID_ID_MASK;
        ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
 
@@ -6033,15 +6165,16 @@ dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs)
                return -ENODEV;
        }
 
-       regdata = bcmsdh_reg_read(sdh,
+       regdata = brcmf_sdcard_reg_read(card,
                CORE_SB(ci->cccorebase, sbidhigh), 4);
        ci->ccrev = SBCOREREV(regdata);
 
-       regdata = bcmsdh_reg_read(sdh,
+       regdata = brcmf_sdcard_reg_read(card,
                CORE_CC_REG(ci->cccorebase, pmucapabilities), 4);
        ci->pmurev = regdata & PCAP_REV_MASK;
 
-       regdata = bcmsdh_reg_read(sdh, CORE_SB(ci->buscorebase, sbidhigh), 4);
+       regdata = brcmf_sdcard_reg_read(card,
+                                       CORE_SB(ci->buscorebase, sbidhigh), 4);
        ci->buscorerev = SBCOREREV(regdata);
        ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT;
 
@@ -6050,93 +6183,93 @@ dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs)
                ci->buscorerev, ci->buscoretype));
 
        /* get chipcommon capabilites */
-       ci->cccaps = bcmsdh_reg_read(sdh,
+       ci->cccaps = brcmf_sdcard_reg_read(card,
                CORE_CC_REG(ci->cccorebase, capabilities), 4);
 
        return 0;
 }
 
 static void
-dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase)
+brcmf_sdbrcm_chip_disablecore(struct brcmf_sdio_card *card, u32 corebase)
 {
        u32 regdata;
 
-       regdata = bcmsdh_reg_read(sdh,
+       regdata = brcmf_sdcard_reg_read(card,
                CORE_SB(corebase, sbtmstatelow), 4);
        if (regdata & SBTML_RESET)
                return;
 
-       regdata = bcmsdh_reg_read(sdh,
+       regdata = brcmf_sdcard_reg_read(card,
                CORE_SB(corebase, sbtmstatelow), 4);
        if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) {
                /*
                 * set target reject and spin until busy is clear
                 * (preserve core-specific bits)
                 */
-               regdata = bcmsdh_reg_read(sdh,
+               regdata = brcmf_sdcard_reg_read(card,
                        CORE_SB(corebase, sbtmstatelow), 4);
-               bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
+               brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4,
                        regdata | SBTML_REJ);
 
-               regdata = bcmsdh_reg_read(sdh,
+               regdata = brcmf_sdcard_reg_read(card,
                        CORE_SB(corebase, sbtmstatelow), 4);
                udelay(1);
-               SPINWAIT((bcmsdh_reg_read(sdh,
+               SPINWAIT((brcmf_sdcard_reg_read(card,
                        CORE_SB(corebase, sbtmstatehigh), 4) &
                        SBTMH_BUSY), 100000);
 
-               regdata = bcmsdh_reg_read(sdh,
+               regdata = brcmf_sdcard_reg_read(card,
                        CORE_SB(corebase, sbtmstatehigh), 4);
                if (regdata & SBTMH_BUSY)
                        DHD_ERROR(("%s: ARM core still busy\n", __func__));
 
-               regdata = bcmsdh_reg_read(sdh,
+               regdata = brcmf_sdcard_reg_read(card,
                        CORE_SB(corebase, sbidlow), 4);
                if (regdata & SBIDL_INIT) {
-                       regdata = bcmsdh_reg_read(sdh,
+                       regdata = brcmf_sdcard_reg_read(card,
                                CORE_SB(corebase, sbimstate), 4) |
                                SBIM_RJ;
-                       bcmsdh_reg_write(sdh,
+                       brcmf_sdcard_reg_write(card,
                                CORE_SB(corebase, sbimstate), 4,
                                regdata);
-                       regdata = bcmsdh_reg_read(sdh,
+                       regdata = brcmf_sdcard_reg_read(card,
                                CORE_SB(corebase, sbimstate), 4);
                        udelay(1);
-                       SPINWAIT((bcmsdh_reg_read(sdh,
+                       SPINWAIT((brcmf_sdcard_reg_read(card,
                                CORE_SB(corebase, sbimstate), 4) &
                                SBIM_BY), 100000);
                }
 
                /* set reset and reject while enabling the clocks */
-               bcmsdh_reg_write(sdh,
+               brcmf_sdcard_reg_write(card,
                        CORE_SB(corebase, sbtmstatelow), 4,
                        (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) |
                        SBTML_REJ | SBTML_RESET));
-               regdata = bcmsdh_reg_read(sdh,
+               regdata = brcmf_sdcard_reg_read(card,
                        CORE_SB(corebase, sbtmstatelow), 4);
                udelay(10);
 
                /* clear the initiator reject bit */
-               regdata = bcmsdh_reg_read(sdh,
+               regdata = brcmf_sdcard_reg_read(card,
                        CORE_SB(corebase, sbidlow), 4);
                if (regdata & SBIDL_INIT) {
-                       regdata = bcmsdh_reg_read(sdh,
+                       regdata = brcmf_sdcard_reg_read(card,
                                CORE_SB(corebase, sbimstate), 4) &
                                ~SBIM_RJ;
-                       bcmsdh_reg_write(sdh,
+                       brcmf_sdcard_reg_write(card,
                                CORE_SB(corebase, sbimstate), 4,
                                regdata);
                }
        }
 
        /* leave reset and reject asserted */
-       bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
+       brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4,
                (SBTML_REJ | SBTML_RESET));
        udelay(1);
 }
 
 static int
-dhdsdio_chip_attach(struct dhd_bus *bus, void *regs)
+brcmf_sdbrcm_chip_attach(struct brcmf_bus *bus, void *regs)
 {
        struct chip_info *ci;
        int err;
@@ -6156,7 +6289,7 @@ dhdsdio_chip_attach(struct dhd_bus *bus, void *regs)
        /* bus/core/clk setup for register access */
        /* Try forcing SDIO core to do ALPAvail request only */
        clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ;
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
                        clkset, &err);
        if (err) {
                DHD_ERROR(("%s: error writing for HT off\n", __func__));
@@ -6165,11 +6298,11 @@ dhdsdio_chip_attach(struct dhd_bus *bus, void *regs)
 
        /* If register supported, wait for ALPAvail and then force ALP */
        /* This may take up to 15 milliseconds */
-       clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1,
+       clkval = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1,
                        SBSDIO_FUNC1_CHIPCLKCSR, NULL);
        if ((clkval & ~SBSDIO_AVBITS) == clkset) {
                SPINWAIT(((clkval =
-                               bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1,
+                               brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1,
                                                SBSDIO_FUNC1_CHIPCLKCSR,
                                                NULL)),
                                !SBSDIO_ALPAV(clkval)),
@@ -6182,7 +6315,7 @@ dhdsdio_chip_attach(struct dhd_bus *bus, void *regs)
                }
                clkset = SBSDIO_FORCE_HW_CLKREQ_OFF |
                                SBSDIO_FORCE_ALP;
-               bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1,
+               brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1,
                                SBSDIO_FUNC1_CHIPCLKCSR,
                                clkset, &err);
                udelay(65);
@@ -6194,10 +6327,10 @@ dhdsdio_chip_attach(struct dhd_bus *bus, void *regs)
        }
 
        /* Also, disable the extra SDIO pull-ups */
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, 0,
-                        NULL);
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP,
+                              0, NULL);
 
-       err = dhdsdio_chip_recognition(bus->sdh, ci, regs);
+       err = brcmf_sdbrcm_chip_recognition(bus->card, ci, regs);
        if (err)
                goto fail;
 
@@ -6205,24 +6338,24 @@ dhdsdio_chip_attach(struct dhd_bus *bus, void *regs)
         * Make sure any on-chip ARM is off (in case strapping is wrong),
         * or downloaded code was already running.
         */
-       dhdsdio_chip_disablecore(bus->sdh, ci->armcorebase);
+       brcmf_sdbrcm_chip_disablecore(bus->card, ci->armcorebase);
 
-       bcmsdh_reg_write(bus->sdh,
+       brcmf_sdcard_reg_write(bus->card,
                CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0);
-       bcmsdh_reg_write(bus->sdh,
+       brcmf_sdcard_reg_write(bus->card,
                CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0);
 
        /* Disable F2 to clear any intermediate frame state on the dongle */
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN,
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_0, SDIO_CCCR_IOEx,
                SDIO_FUNC_ENABLE_1, NULL);
 
        /* WAR: cmd52 backplane read so core HW will drop ALPReq */
-       clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1,
+       clkval = brcmf_sdcard_cfg_read(bus->card, SDIO_FUNC_1,
                        0, NULL);
 
        /* Done with backplane-dependent accesses, can drop clock... */
-       bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0,
-                        NULL);
+       brcmf_sdcard_cfg_write(bus->card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
+                              0, NULL);
 
        bus->ci = ci;
        return 0;
@@ -6233,7 +6366,7 @@ fail:
 }
 
 static void
-dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase)
+brcmf_sdbrcm_chip_resetcore(struct brcmf_sdio_card *card, u32 corebase)
 {
        u32 regdata;
 
@@ -6241,35 +6374,37 @@ dhdsdio_chip_resetcore(bcmsdh_info_t *sdh, u32 corebase)
         * Must do the disable sequence first to work for
         * arbitrary current core state.
         */
-       dhdsdio_chip_disablecore(sdh, corebase);
+       brcmf_sdbrcm_chip_disablecore(card, corebase);
 
        /*
         * Now do the initialization sequence.
         * set reset while enabling the clock and
         * forcing them on throughout the core
         */
-       bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
+       brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4,
                ((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) |
                SBTML_RESET);
        udelay(1);
 
-       regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbtmstatehigh), 4);
+       regdata = brcmf_sdcard_reg_read(card, CORE_SB(corebase, sbtmstatehigh),
+                                       4);
        if (regdata & SBTMH_SERR)
-               bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatehigh), 4, 0);
+               brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatehigh),
+                                      4, 0);
 
-       regdata = bcmsdh_reg_read(sdh, CORE_SB(corebase, sbimstate), 4);
+       regdata = brcmf_sdcard_reg_read(card, CORE_SB(corebase, sbimstate), 4);
        if (regdata & (SBIM_IBE | SBIM_TO))
-               bcmsdh_reg_write(sdh, CORE_SB(corebase, sbimstate), 4,
+               brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbimstate), 4,
                        regdata & ~(SBIM_IBE | SBIM_TO));
 
        /* clear reset and allow it to propagate throughout the core */
-       bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
+       brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4,
                (SICF_FGC << SBTML_SICF_SHIFT) |
                (SICF_CLOCK_EN << SBTML_SICF_SHIFT));
        udelay(1);
 
        /* leave clock enabled */
-       bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4,
+       brcmf_sdcard_reg_write(card, CORE_SB(corebase, sbtmstatelow), 4,
                (SICF_CLOCK_EN << SBTML_SICF_SHIFT));
        udelay(1);
 }
@@ -6317,7 +6452,7 @@ static const struct sdiod_drive_str sdiod_drive_strength_tab3[] = {
 #define SDIOD_DRVSTR_KEY(chip, pmu)     (((chip) << 16) | (pmu))
 
 static void
-dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) {
+brcmf_sdbrcm_sdiod_drive_strength_init(struct brcmf_bus *bus, u32 drivestrength) {
        struct sdiod_drive_str *str_tab = NULL;
        u32 str_mask = 0;
        u32 str_shift = 0;
@@ -6346,7 +6481,7 @@ dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) {
        default:
                DHD_ERROR(("No SDIO Drive strength init"
                        "done for chip %s rev %d pmurev %d\n",
-                       bcm_chipname(bus->ci->chip, chn, 8),
+                       brcmu_chipname(bus->ci->chip, chn, 8),
                        bus->ci->chiprev, bus->ci->pmurev));
                break;
        }
@@ -6363,15 +6498,15 @@ dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) {
                        }
                }
 
-               bcmsdh_reg_write(bus->sdh,
+               brcmf_sdcard_reg_write(bus->card,
                        CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr),
                        4, 1);
-               cc_data_temp = bcmsdh_reg_read(bus->sdh,
+               cc_data_temp = brcmf_sdcard_reg_read(bus->card,
                        CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr), 4);
                cc_data_temp &= ~str_mask;
                drivestrength_sel <<= str_shift;
                cc_data_temp |= drivestrength_sel;
-               bcmsdh_reg_write(bus->sdh,
+               brcmf_sdcard_reg_write(bus->card,
                        CORE_CC_REG(bus->ci->cccorebase, chipcontrol_addr),
                        4, cc_data_temp);
 
@@ -6381,10 +6516,209 @@ dhdsdio_sdiod_drive_strength_init(struct dhd_bus *bus, u32 drivestrength) {
 }
 
 static void
-dhdsdio_chip_detach(struct dhd_bus *bus)
+brcmf_sdbrcm_chip_detach(struct brcmf_bus *bus)
 {
        DHD_TRACE(("%s: Enter\n", __func__));
 
        kfree(bus->ci);
        bus->ci = NULL;
 }
+
+static void
+brcmf_sdbrcm_wait_for_event(struct brcmf_bus *bus, bool *lockvar)
+{
+       brcmf_sdbrcm_sdunlock(bus);
+       wait_event_interruptible_timeout(bus->ctrl_wait,
+                                        (*lockvar == false), HZ * 2);
+       brcmf_sdbrcm_sdlock(bus);
+       return;
+}
+
+static void
+brcmf_sdbrcm_wait_event_wakeup(struct brcmf_bus *bus)
+{
+       if (waitqueue_active(&bus->ctrl_wait))
+               wake_up_interruptible(&bus->ctrl_wait);
+       return;
+}
+
+static int
+brcmf_sdbrcm_watchdog_thread(void *data)
+{
+       struct brcmf_bus *bus = (struct brcmf_bus *)data;
+
+       /* This thread doesn't need any user-level access,
+       * so get rid of all our resources
+       */
+       if (brcmf_watchdog_prio > 0) {
+               struct sched_param param;
+               param.sched_priority = (brcmf_watchdog_prio < MAX_RT_PRIO) ?
+                                      brcmf_watchdog_prio : (MAX_RT_PRIO - 1);
+               sched_setscheduler(current, SCHED_FIFO, &param);
+       }
+
+       allow_signal(SIGTERM);
+       /* Run until signal received */
+       while (1) {
+               if (kthread_should_stop())
+                       break;
+               if (!wait_for_completion_interruptible(&bus->watchdog_wait)) {
+                       if (bus->drvr->dongle_reset == false)
+                               brcmf_sdbrcm_bus_watchdog(bus->drvr);
+                       /* Count the tick for reference */
+                       bus->drvr->tickcnt++;
+               } else
+                       break;
+       }
+       return 0;
+}
+
+static void
+brcmf_sdbrcm_watchdog(unsigned long data)
+{
+       struct brcmf_bus *bus = (struct brcmf_bus *)data;
+
+       if (brcmf_watchdog_prio >= 0) {
+               if (bus->watchdog_tsk)
+                       complete(&bus->watchdog_wait);
+               else
+                       return;
+       } else {
+               brcmf_sdbrcm_bus_watchdog(bus->drvr);
+
+               /* Count the tick for reference */
+               bus->drvr->tickcnt++;
+       }
+
+       /* Reschedule the watchdog */
+       if (bus->wd_timer_valid)
+               mod_timer(&bus->timer, jiffies + brcmf_watchdog_ms * HZ / 1000);
+}
+
+void
+brcmf_sdbrcm_wd_timer(struct brcmf_bus *bus, uint wdtick)
+{
+       static uint save_ms;
+
+       /* don't start the wd until fw is loaded */
+       if (bus->drvr->busstate == DHD_BUS_DOWN)
+               return;
+
+       /* Totally stop the timer */
+       if (!wdtick && bus->wd_timer_valid == true) {
+               del_timer_sync(&bus->timer);
+               bus->wd_timer_valid = false;
+               save_ms = wdtick;
+               return;
+       }
+
+       if (wdtick) {
+               brcmf_watchdog_ms = (uint) wdtick;
+
+               if (save_ms != brcmf_watchdog_ms) {
+                       if (bus->wd_timer_valid == true)
+                               /* Stop timer and restart at new value */
+                               del_timer_sync(&bus->timer);
+
+                       /* Create timer again when watchdog period is
+                          dynamically changed or in the first instance
+                        */
+                       bus->timer.expires =
+                               jiffies + brcmf_watchdog_ms * HZ / 1000;
+                       add_timer(&bus->timer);
+
+               } else {
+                       /* Re arm the timer, at last watchdog period */
+                       mod_timer(&bus->timer,
+                               jiffies + brcmf_watchdog_ms * HZ / 1000);
+               }
+
+               bus->wd_timer_valid = true;
+               save_ms = wdtick;
+       }
+}
+
+static int brcmf_sdbrcm_dpc_thread(void *data)
+{
+       struct brcmf_bus *bus = (struct brcmf_bus *) data;
+
+       /* This thread doesn't need any user-level access,
+        * so get rid of all our resources
+        */
+       if (brcmf_dpc_prio > 0) {
+               struct sched_param param;
+               param.sched_priority = (brcmf_dpc_prio < MAX_RT_PRIO) ?
+                                      brcmf_dpc_prio : (MAX_RT_PRIO - 1);
+               sched_setscheduler(current, SCHED_FIFO, &param);
+       }
+
+       allow_signal(SIGTERM);
+       /* Run until signal received */
+       while (1) {
+               if (kthread_should_stop())
+                       break;
+               if (!wait_for_completion_interruptible(&bus->dpc_wait)) {
+                       /* Call bus dpc unless it indicated down
+                       (then clean stop) */
+                       if (bus->drvr->busstate != DHD_BUS_DOWN) {
+                               if (brcmf_sdbrcm_dpc(bus))
+                                       complete(&bus->dpc_wait);
+                       } else {
+                               brcmf_sdbrcm_bus_stop(bus, true);
+                       }
+               } else
+                       break;
+       }
+       return 0;
+}
+
+static void brcmf_sdbrcm_dpc_tasklet(unsigned long data)
+{
+       struct brcmf_bus *bus = (struct brcmf_bus *) data;
+
+       /* Call bus dpc unless it indicated down (then clean stop) */
+       if (bus->drvr->busstate != DHD_BUS_DOWN) {
+               if (brcmf_sdbrcm_dpc(bus))
+                       tasklet_schedule(&bus->tasklet);
+       } else
+               brcmf_sdbrcm_bus_stop(bus, true);
+}
+
+static void brcmf_sdbrcm_sched_dpc(struct brcmf_bus *bus)
+{
+       if (bus->dpc_tsk) {
+               complete(&bus->dpc_wait);
+               return;
+       }
+
+       tasklet_schedule(&bus->tasklet);
+}
+
+static void brcmf_sdbrcm_sdlock(struct brcmf_bus *bus)
+{
+       if (bus->threads_only)
+               down(&bus->sdsem);
+       else
+               spin_lock_bh(&bus->sdlock);
+}
+
+static void brcmf_sdbrcm_sdunlock(struct brcmf_bus *bus)
+{
+       if (bus->threads_only)
+               up(&bus->sdsem);
+       else
+               spin_unlock_bh(&bus->sdlock);
+}
+
+static int brcmf_sdbrcm_get_image(char *buf, int len, struct brcmf_bus *bus)
+{
+       if (bus->firmware->size < bus->fw_ptr + len)
+               len = bus->firmware->size - bus->fw_ptr;
+
+       memcpy(buf, &bus->firmware->data[bus->fw_ptr], len);
+       bus->fw_ptr += len;
+       return len;
+}
+
+MODULE_FIRMWARE(BCM4329_FW_NAME);
+MODULE_FIRMWARE(BCM4329_NV_NAME);