Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
authorLarry Finger <Larry.Finger@lwfinger.net>
Tue, 26 Jul 2011 20:52:24 +0000 (15:52 -0500)
committerLarry Finger <Larry.Finger@lwfinger.net>
Tue, 26 Jul 2011 20:52:24 +0000 (15:52 -0500)
Conflicts:
Documentation/feature-removal-schedule.txt
drivers/staging/bcm/headers.h
drivers/staging/brcm80211/brcmfmac/dhd_linux.c
drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
drivers/staging/brcm80211/brcmfmac/wl_iw.c
drivers/staging/et131x/et131x_netdev.c
drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
drivers/staging/rtl8192e/r8192E.h
drivers/staging/usbip/userspace/src/utils.h

23 files changed:
1  2 
MAINTAINERS
drivers/staging/ath6kl/os/linux/include/ar6000_drv.h
drivers/staging/brcm80211/brcmfmac/dhd_linux.c
drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
drivers/staging/brcm80211/brcmsmac/mac80211_if.c
drivers/staging/brcm80211/brcmsmac/mac80211_if.h
drivers/staging/et131x/et131x_netdev.c
drivers/staging/gma500/psb_intel_display.c
drivers/staging/hv/hv_mouse.c
drivers/staging/lirc/lirc_zilog.c
drivers/staging/rtl8187se/ieee80211/ieee80211.h
drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
drivers/staging/rtl8192e/ieee80211/ieee80211.h
drivers/staging/rtl8192e/ieee80211/ieee80211_module.c
drivers/staging/rtl8192e/r8192E_core.c
drivers/staging/rtl8192u/ieee80211/ieee80211.h
drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
drivers/staging/rtl8192u/r8192U_core.c
drivers/staging/rtl8712/osdep_service.h
drivers/staging/sep/sep_driver.c
drivers/staging/usbip/userspace/src/utils.h
drivers/staging/wlags49_h2/wl_internal.h

diff --combined MAINTAINERS
@@@ -1,4 -1,5 +1,5 @@@
  
        List of maintainers and how to submit kernel changes
  
  Please try to follow the guidelines below.  This will make things
@@@ -533,6 -534,8 +534,8 @@@ L: device-drivers-devel@blackfin.uclinu
  L:    alsa-devel@alsa-project.org (moderated for non-subscribers)
  W:    http://wiki.analog.com/
  S:    Supported
+ F:    sound/soc/codecs/adau*
+ F:    sound/soc/codecs/adav*
  F:    sound/soc/codecs/ad1*
  F:    sound/soc/codecs/ssm*
  
@@@ -594,6 -597,16 +597,16 @@@ S:       Maintaine
  F:    arch/arm/lib/floppydma.S
  F:    arch/arm/include/asm/floppy.h
  
+ ARM PMU PROFILING AND DEBUGGING
+ M:    Will Deacon <will.deacon@arm.com>
+ S:    Maintained
+ F:    arch/arm/kernel/perf_event*
+ F:    arch/arm/oprofile/common.c
+ F:    arch/arm/kernel/pmu.c
+ F:    arch/arm/include/asm/pmu.h
+ F:    arch/arm/kernel/hw_breakpoint.c
+ F:    arch/arm/include/asm/hw_breakpoint.h
  ARM PORT
  M:    Russell King <linux@arm.linux.org.uk>
  L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@@ -683,7 -696,7 +696,7 @@@ T: git git://git.infradead.org/users/cb
  
  ARM/CIRRUS LOGIC EP93XX ARM ARCHITECTURE
  M:    Hartley Sweeten <hsweeten@visionengravers.com>
- M:    Ryan Mallon <ryan@bluewatersys.com>
+ M:    Ryan Mallon <rmallon@gmail.com>
  L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
  S:    Maintained
  F:    arch/arm/mach-ep93xx/
@@@ -1533,14 -1546,19 +1546,20 @@@ F:   drivers/net/tg3.
  BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER
  M:    Brett Rudley <brudley@broadcom.com>
  M:    Henry Ptasinski <henryp@broadcom.com>
 -M:    Dowan Kim <dowan@broadcom.com>
  M:    Roland Vossen <rvossen@broadcom.com>
  M:    Arend van Spriel <arend@broadcom.com>
 +M:    Franky (Zhenhui) Lin <frankyl@broadcom.com>
 +M:    Kan Yan <kanyan@broadcom.com>
  L:    linux-wireless@vger.kernel.org
  S:    Supported
  F:    drivers/staging/brcm80211/
  
+ BROADCOM BNX2FC 10 GIGABIT FCOE DRIVER
+ M:    Bhanu Prakash Gollapudi <bprakash@broadcom.com>
+ L:    linux-scsi@vger.kernel.org
+ S:    Supported
+ F:    drivers/scsi/bnx2fc/
  BROCADE BFA FC SCSI DRIVER
  M:    Jing Huang <huangj@brocade.com>
  L:    linux-scsi@vger.kernel.org
@@@ -1570,7 -1588,7 +1589,7 @@@ F:      Documentation/sound/alsa/Bt87x.tx
  F:    sound/pci/bt87x.c
  
  BT8XXGPIO DRIVER
- M:    Michael Buesch <mb@bu3sch.de>
+ M:    Michael Buesch <m@bues.ch>
  W:    http://bu3sch.de/btgpio.php
  S:    Maintained
  F:    drivers/gpio/bt8xxgpio.c
@@@ -1763,7 -1781,8 +1782,8 @@@ F:      include/linux/clk.
  
  CISCO FCOE HBA DRIVER
  M:    Abhijeet Joglekar <abjoglek@cisco.com>
- M:    Joe Eykholt <jeykholt@cisco.com>
+ M:    Venkata Siva Vijayendra Bhamidipati <vbhamidi@cisco.com>
+ M:    Brian Uchino <buchino@cisco.com>
  L:    linux-scsi@vger.kernel.org
  S:    Supported
  F:    drivers/scsi/fnic/
@@@ -2198,7 -2217,7 +2218,7 @@@ F:      drivers/acpi/dock.
  DOCUMENTATION
  M:    Randy Dunlap <rdunlap@xenotime.net>
  L:    linux-doc@vger.kernel.org
- T:    quilt oss.oracle.com/~rdunlap/kernel-doc-patches/current/
+ T:    quilt http://userweb.kernel.org/~rdunlap/kernel-doc-patches/current/
  S:    Maintained
  F:    Documentation/
  
@@@ -2993,7 -3012,7 +3013,7 @@@ F:      kernel/hrtimer.
  F:    kernel/time/clockevents.c
  F:    kernel/time/tick*.*
  F:    kernel/time/timer_*.c
- F:    include/linux/clockevents.h
+ F:    include/linux/clockchips.h
  F:    include/linux/hrtimer.h
  
  HIGH-SPEED SCC DRIVER FOR AX.25
@@@ -3416,10 -3435,9 +3436,9 @@@ S:     Maintaine
  F:    drivers/net/ipg.*
  
  IPATH DRIVER
- M:    Ralph Campbell <infinipath@qlogic.com>
+ M:    Mike Marciniszyn <infinipath@qlogic.com>
  L:    linux-rdma@vger.kernel.org
- T:    git git://git.qlogic.com/ipath-linux-2.6
- S:    Supported
+ S:    Maintained
  F:    drivers/infiniband/hw/ipath/
  
  IPMI SUBSYSTEM
@@@ -3942,6 -3960,13 +3961,13 @@@ L:    lm-sensors@lm-sensors.or
  S:    Maintained
  F:    drivers/hwmon/lm73.c
  
+ LM78 HARDWARE MONITOR DRIVER
+ M:    Jean Delvare <khali@linux-fr.org>
+ L:    lm-sensors@lm-sensors.org
+ S:    Maintained
+ F:    Documentation/hwmon/lm78
+ F:    drivers/hwmon/lm78.c
  LM83 HARDWARE MONITOR DRIVER
  M:    Jean Delvare <khali@linux-fr.org>
  L:    lm-sensors@lm-sensors.org
@@@ -4088,6 -4113,12 +4114,12 @@@ S:    Maintaine
  F:    drivers/net/mv643xx_eth.*
  F:    include/linux/mv643xx.h
  
+ MARVELL MWIFIEX WIRELESS DRIVER
+ M:    Bing Zhao <bzhao@marvell.com>
+ L:    linux-wireless@vger.kernel.org
+ S:    Maintained
+ F:    drivers/net/wireless/mwifiex/
  MARVELL MWL8K WIRELESS DRIVER
  M:    Lennert Buytenhek <buytenh@wantstofly.org>
  L:    linux-wireless@vger.kernel.org
@@@ -4280,8 -4311,8 +4312,8 @@@ S:      Maintaine
  F:    drivers/usb/musb/
  
  MYRICOM MYRI-10G 10GbE DRIVER (MYRI10GE)
+ M:    Jon Mason <mason@myri.com>
  M:    Andrew Gallatin <gallatin@myri.com>
- M:    Brice Goglin <brice@myri.com>
  L:    netdev@vger.kernel.org
  W:    http://www.myri.com/scs/download-Myri10GE.html
  S:    Supported
@@@ -4575,9 -4606,8 +4607,8 @@@ S:      Maintaine
  F:    drivers/mmc/host/omap.c
  
  OMAP HS MMC SUPPORT
- M:    Madhusudhan Chikkature <madhu.cr@ti.com>
  L:    linux-omap@vger.kernel.org
- S:    Maintained
+ S:    Orphan
  F:    drivers/mmc/host/omap_hsmmc.c
  
  OMAP RANDOM NUMBER GENERATOR SUPPORT
@@@ -4671,6 -4701,14 +4702,14 @@@ F:    drivers/o
  F:    include/linux/of*.h
  K:    of_get_property
  
+ OPENRISC ARCHITECTURE
+ M:    Jonas Bonn <jonas@southpole.se>
+ W:    http://openrisc.net
+ L:    linux@lists.openrisc.net
+ S:    Maintained
+ T:    git git://openrisc.net/~jonas/linux
+ F:    arch/openrisc
  OPL4 DRIVER
  M:    Clemens Ladisch <clemens@ladisch.de>
  L:    alsa-devel@alsa-project.org (moderated for non-subscribers)
@@@ -4983,7 -5021,7 +5022,7 @@@ F:      drivers/power/power_supply
  
  PNP SUPPORT
  M:    Adam Belay <abelay@mit.edu>
- M:    Bjorn Helgaas <bjorn.helgaas@hp.com>
+ M:    Bjorn Helgaas <bhelgaas@google.com>
  S:    Maintained
  F:    drivers/pnp/
  
@@@ -5143,6 -5181,12 +5182,12 @@@ M:    Robert Jarzmik <robert.jarzmik@free.
  L:    rtc-linux@googlegroups.com
  S:    Maintained
  
+ QIB DRIVER
+ M:    Mike Marciniszyn <infinipath@qlogic.com>
+ L:    linux-rdma@vger.kernel.org
+ S:    Supported
+ F:    drivers/infiniband/hw/qib/
  QLOGIC QLA1280 SCSI DRIVER
  M:    Michael Reed <mdr@sgi.com>
  L:    linux-scsi@vger.kernel.org
@@@ -5304,6 -5348,13 +5349,13 @@@ L:    reiserfs-devel@vger.kernel.or
  S:    Supported
  F:    fs/reiserfs/
  
+ REGISTER MAP ABSTRACTION
+ M:    Mark Brown <broonie@opensource.wolfsonmicro.com>
+ T:    git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git
+ S:    Supported
+ F:    drivers/base/regmap/
+ F:    include/linux/regmap.h
  RFKILL
  M:    Johannes Berg <johannes@sipsolutions.net>
  L:    linux-wireless@vger.kernel.org
@@@ -5866,7 -5917,7 +5918,7 @@@ S:      Maintaine
  F:    drivers/net/sonic.*
  
  SONICS SILICON BACKPLANE DRIVER (SSB)
- M:    Michael Buesch <mb@bu3sch.de>
+ M:    Michael Buesch <m@bues.ch>
  L:    netdev@vger.kernel.org
  S:    Maintained
  F:    drivers/ssb/
@@@ -6040,145 -6091,6 +6092,145 @@@ L:  devel@driverdev.osuosl.or
  S:    Maintained
  F:    drivers/staging/
  
 +STAGING - AGERE HERMES II and II.5 WIRELESS DRIVERS
 +M:    Henk de Groot <pe1dnn@amsat.org>
 +S:    Odd Fixes
 +F:    drivers/staging/wlags49_h2/
 +F:    drivers/staging/wlags49_h25/
 +
 +STAGING - ASUS OLED
 +M:    Jakub Schmidtke <sjakub@gmail.com>
 +S:    Odd Fixes
 +F:    drivers/staging/asus_oled/
 +
 +STAGING - ATHEROS ATH6KL WIRELESS DRIVER
 +M:    Luis R. Rodriguez <mcgrof@gmail.com>
 +M:    Naveen Singh <nsingh@atheros.com>
 +S:    Odd Fixes
 +F:    drivers/staging/ath6kl/
 +
 +STAGING - COMEDI
 +M:    Ian Abbott <abbotti@mev.co.uk>
 +M:    Mori Hess <fmhess@users.sourceforge.net>
 +S:    Odd Fixes
 +F:    drivers/staging/comedi/
 +
 +STAGING - CRYSTAL HD VIDEO DECODER
 +M:    Naren Sankar <nsankar@broadcom.com>
 +M:    Jarod Wilson <jarod@wilsonet.com>
 +M:    Scott Davilla <davilla@4pi.com>
 +M:    Manu Abraham <abraham.manu@gmail.com>
 +S:    Odd Fixes
 +F:    drivers/staging/crystalhd/
 +
 +STAGING - CYPRESS WESTBRIDGE SUPPORT
 +M:    David Cross <david.cross@cypress.com>
 +S:    Odd Fixes
 +F:    drivers/staging/westbridge/
 +
 +STAGING - ECHO CANCELLER
 +M:    Steve Underwood <steveu@coppice.org>
 +M:    David Rowe <david@rowetel.com>
 +S:    Odd Fixes
 +F:    drivers/staging/echo/
 +
 +STAGING - FLARION FT1000 DRIVERS
 +M:    Marek Belisko <marek.belisko@gmail.com>
 +S:    Odd Fixes
 +F:    drivers/staging/ft1000/
 +
 +STAGING - FRONTIER TRANZPORT AND ALPHATRACK
 +M:    David Täht <d@teklibre.com>
 +S:    Odd Fixes
 +F:    drivers/staging/frontier/
 +
 +STAGING - HYPER-V (MICROSOFT)
 +M:    Hank Janssen <hjanssen@microsoft.com>
 +M:    Haiyang Zhang <haiyangz@microsoft.com>
 +S:    Odd Fixes
 +F:    drivers/staging/hv/
 +
 +STAGING - INDUSTRIAL IO
 +M:    Jonathan Cameron <jic23@cam.ac.uk>
 +L:    linux-iio@vger.kernel.org
 +S:    Odd Fixes
 +F:    drivers/staging/iio/
 +
 +STAGING - LIRC (LINUX INFRARED REMOTE CONTROL) DRIVERS
 +M:    Jarod Wilson <jarod@wilsonet.com>
 +W:    http://www.lirc.org/
 +S:    Odd Fixes
 +F:    drivers/staging/lirc/
 +
 +STAGING - OLPC SECONDARY DISPLAY CONTROLLER (DCON)
 +M:    Andres Salomon <dilinger@queued.net>
 +M:    Chris Ball <cjb@laptop.org>
 +M:    Jon Nettleton <jon.nettleton@gmail.com>
 +W:    http://wiki.laptop.org/go/DCON
 +S:    Odd Fixes
 +F:    drivers/staging/olpc_dcon/
 +
 +STAGING - PARALLEL LCD/KEYPAD PANEL DRIVER
 +M:    Willy Tarreau <willy@meta-x.org>
 +S:    Odd Fixes
 +F:    drivers/staging/panel/
 +
 +STAGING - REALTEK RTL8712U DRIVERS
 +M:    Larry Finger <Larry.Finger@lwfinger.net>
 +M:    Florian Schilhabel <florian.c.schilhabel@googlemail.com>.
 +S:    Odd Fixes
 +F:    drivers/staging/rtl8712/
 +
 +STAGING - SILICON MOTION SM7XX FRAME BUFFER DRIVER
 +M:    Teddy Wang <teddy.wang@siliconmotion.com.cn>
 +S:    Odd Fixes
 +F:    drivers/staging/sm7xx/
 +
 +STAGING - SOFTLOGIC 6x10 MPEG CODEC
 +M:    Ben Collins <bcollins@bluecherry.net>
 +S:    Odd Fixes
 +F:    drivers/staging/solo6x10/
 +
 +STAGING - SPEAKUP CONSOLE SPEECH DRIVER
 +M:    William Hubbs <w.d.hubbs@gmail.com>
 +M:    Chris Brannon <chris@the-brannons.com>
 +M:    Kirk Reiser <kirk@braille.uwo.ca>
 +M:    Samuel Thibault <samuel.thibault@ens-lyon.org>
 +L:    speakup@braille.uwo.ca
 +W:    http://www.linux-speakup.org/
 +S:    Odd Fixes
 +F:    drivers/staging/speakup/
 +
 +STAGING - TI DSP BRIDGE DRIVERS
 +M:    Omar Ramirez Luna <omar.ramirez@ti.com>
 +S:    Odd Fixes
 +F:    drivers/staging/tidspbridge/
 +
 +STAGING - TRIDENT TVMASTER TMxxxx USB VIDEO CAPTURE DRIVERS
 +L:    linux-media@vger.kernel.org
 +S:    Odd Fixes
 +F:    drivers/staging/tm6000/
 +
 +STAGING - USB ENE SM/MS CARD READER DRIVER
 +M:    Al Cho <acho@novell.com>
 +S:    Odd Fixes
 +F:    drivers/staging/keucr/
 +
 +STAGING - VIA VT665X DRIVERS
 +M:    Forest Bond <forest@alittletooquiet.net>
 +S:    Odd Fixes
 +F:    drivers/staging/vt665?/
 +
 +STAGING - WINBOND IS89C35 WLAN USB DRIVER
 +M:    Pavel Machek <pavel@ucw.cz>
 +S:    Odd Fixes
 +F:    drivers/staging/winbond/
 +
 +STAGING - XGI Z7,Z9,Z11 PCI DISPLAY DRIVER
 +M:    Arnaud Patard <apatard@mandriva.com>
 +S:    Odd Fixes
 +F:    drivers/staging/xgifb/
 +
  STARFIRE/DURALAN NETWORK DRIVER
  M:    Ion Badulescu <ionut@badula.org>
  S:    Odd Fixes
@@@ -6372,9 -6284,14 +6424,14 @@@ F:    drivers/char/toshiba.
  F:    include/linux/toshiba.h
  
  TMIO MMC DRIVER
+ M:    Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  M:    Ian Molton <ian@mnementh.co.uk>
+ L:    linux-mmc@vger.kernel.org
  S:    Maintained
- F:    drivers/mmc/host/tmio_mmc.*
+ F:    drivers/mmc/host/tmio_mmc*
+ F:    drivers/mmc/host/sh_mobile_sdhi.c
+ F:    include/linux/mmc/tmio.h
+ F:    include/linux/mmc/sh_mobile_sdhi.h
  
  TMPFS (SHMEM FILESYSTEM)
  M:    Hugh Dickins <hughd@google.com>
@@@ -6451,7 -6368,7 +6508,7 @@@ F:      drivers/scsi/u14-34f.
  
  UBI FILE SYSTEM (UBIFS)
  M:    Artem Bityutskiy <dedekind1@gmail.com>
- M:    Adrian Hunter <adrian.hunter@nokia.com>
+ M:    Adrian Hunter <adrian.hunter@intel.com>
  L:    linux-mtd@lists.infradead.org
  T:    git git://git.infradead.org/ubifs-2.6.git
  W:    http://www.linux-mtd.infradead.org/doc/ubifs.html
@@@ -6676,6 -6593,13 +6733,6 @@@ W:     http://pegasus2.sourceforge.net
  S:    Maintained
  F:    drivers/net/usb/rtl8150.c
  
 -USB SE401 DRIVER
 -L:    linux-usb@vger.kernel.org
 -W:    http://www.chello.nl/~j.vreeken/se401/
 -S:    Orphan
 -F:    Documentation/video4linux/se401.txt
 -F:    drivers/staging/se401/
 -
  USB SERIAL BELKIN F5U103 DRIVER
  M:    William Greathouse <wgreathouse@smva.com>
  L:    linux-usb@vger.kernel.org
@@@ -6866,6 -6790,7 +6923,7 @@@ F:      fs/fat
  VIDEOBUF2 FRAMEWORK
  M:    Pawel Osciak <pawel@osciak.com>
  M:    Marek Szyprowski <m.szyprowski@samsung.com>
+ M:    Kyungmin Park <kyungmin.park@samsung.com>
  L:    linux-media@vger.kernel.org
  S:    Maintained
  F:    drivers/media/video/videobuf2-*
@@@ -7060,9 -6985,9 +7118,9 @@@ S:      Maintaine
  F:    drivers/input/misc/wistron_btns.c
  
  WL1251 WIRELESS DRIVER
- M:    Kalle Valo <kvalo@adurom.com>
+ M:    Luciano Coelho <coelho@ti.com>
  L:    linux-wireless@vger.kernel.org
- W:    http://wireless.kernel.org
+ W:    http://wireless.kernel.org/en/users/Drivers/wl1251
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
  S:    Maintained
  F:    drivers/net/wireless/wl1251/*
@@@ -52,7 -52,6 +52,6 @@@
  #include "aggr_recv_api.h"
  #include <host_version.h>
  #include <linux/rtnetlink.h>
- #include <linux/init.h>
  #include <linux/moduleparam.h>
  #include "ar6000_api.h"
  #ifdef CONFIG_HOST_TCMD_SUPPORT
@@@ -546,9 -545,15 +545,9 @@@ struct ar6_softc 
      s8 arMaxRetries;
      u8 arPhyCapability;
  #ifdef CONFIG_HOST_TCMD_SUPPORT
 -    u8 tcmdRxReport;
 -    u32 tcmdRxTotalPkt;
 -    s32 tcmdRxRssi;
 -    u32 tcmdPm;
      u32 arTargetMode;
 -    u32 tcmdRxcrcErrPkt;
 -    u32 tcmdRxsecErrPkt;
 -    u16 tcmdRateCnt[TCMD_MAX_RATES];
 -    u16 tcmdRateCntShortGuard[TCMD_MAX_RATES];
 +    void *tcmd_rx_report;
 +    int tcmd_rx_report_len;
  #endif
      AR6000_WLAN_STATE       arWlanState;
      struct ar_node_mapping  arNodeMap[MAX_NODE_NUM];
      void                    *arApDev;
  #endif
      u8 arAutoAuthStage;
 +
 +      u8 *fw_otp;
 +      size_t fw_otp_len;
 +      u8 *fw;
 +      size_t fw_len;
 +      u8 *fw_patch;
 +      size_t fw_patch_len;
 +      u8 *fw_data;
 +      size_t fw_data_len;
  };
  
  #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
@@@ -14,6 -14,9 +14,6 @@@
   * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   */
  
 -#ifdef CONFIG_WIFI_CONTROL_FUNC
 -#include <linux/platform_device.h>
 -#endif
  #include <linux/init.h>
  #include <linux/kernel.h>
  #include <linux/kthread.h>
  #include <linux/fcntl.h>
  #include <linux/fs.h>
  #include <linux/uaccess.h>
- #include <net/cfg80211.h>
- #include <defs.h>
- #include <brcmu_utils.h>
- #include <brcmu_wifi.h>
- #include "dhd.h"
- #include "dhd_bus.h"
- #include "dhd_proto.h"
- #include "dhd_dbg.h"
- #include "wl_cfg80211.h"
- #include "bcmchip.h"
+ #include <linux/interrupt.h>
+ #include <linux/hardirq.h>
+ #include <bcmdefs.h>
+ #include <bcmutils.h>
+ #include <dngl_stats.h>
+ #include <dhd.h>
+ #include <dhd_bus.h>
+ #include <dhd_proto.h>
+ #include <dhd_dbg.h>
+ #include <wl_cfg80211.h>
+ #define EPI_VERSION_STR               "4.218.248.5"
+ #define ETH_P_BRCM                    0x886c
+ #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
+ #include <linux/wifi_tiwlan.h>
+ struct semaphore wifi_control_sem;
+ struct dhd_bus *g_bus;
+ static struct wifi_platform_data *wifi_control_data;
+ static struct resource *wifi_irqres;
+ int wifi_get_irq_number(unsigned long *irq_flags_ptr)
+ {
+       if (wifi_irqres) {
+               *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
+               return (int)wifi_irqres->start;
+       }
+ #ifdef CUSTOM_OOB_GPIO_NUM
+       return CUSTOM_OOB_GPIO_NUM;
+ #else
+       return -1;
+ #endif
+ }
+ int wifi_set_carddetect(int on)
+ {
+       printk(KERN_ERR "%s = %d\n", __func__, on);
+       if (wifi_control_data && wifi_control_data->set_carddetect)
+               wifi_control_data->set_carddetect(on);
+       return 0;
+ }
+ int wifi_set_power(int on, unsigned long msec)
+ {
+       printk(KERN_ERR "%s = %d\n", __func__, on);
+       if (wifi_control_data && wifi_control_data->set_power)
+               wifi_control_data->set_power(on);
+       if (msec)
+               mdelay(msec);
+       return 0;
+ }
+ int wifi_set_reset(int on, unsigned long msec)
+ {
+       printk(KERN_ERR "%s = %d\n", __func__, on);
+       if (wifi_control_data && wifi_control_data->set_reset)
+               wifi_control_data->set_reset(on);
+       if (msec)
+               mdelay(msec);
+       return 0;
+ }
+ static int wifi_probe(struct platform_device *pdev)
+ {
+       struct wifi_platform_data *wifi_ctrl =
+           (struct wifi_platform_data *)(pdev->dev.platform_data);
+       printk(KERN_ERR "## %s\n", __func__);
+       wifi_irqres =
+           platform_get_resource_byname(pdev, IORESOURCE_IRQ,
+                                        "bcm4329_wlan_irq");
+       wifi_control_data = wifi_ctrl;
+       wifi_set_power(1, 0);   /* Power On */
+       wifi_set_carddetect(1); /* CardDetect (0->1) */
+       up(&wifi_control_sem);
+       return 0;
+ }
+ static int wifi_remove(struct platform_device *pdev)
+ {
+       struct wifi_platform_data *wifi_ctrl =
+           (struct wifi_platform_data *)(pdev->dev.platform_data);
+       printk(KERN_ERR "## %s\n", __func__);
+       wifi_control_data = wifi_ctrl;
+       wifi_set_carddetect(0); /* CardDetect (1->0) */
+       wifi_set_power(0, 0);   /* Power Off */
+       up(&wifi_control_sem);
+       return 0;
+ }
+ static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
+ {
+       DHD_TRACE(("##> %s\n", __func__));
+       return 0;
+ }
+ static int wifi_resume(struct platform_device *pdev)
+ {
+       DHD_TRACE(("##> %s\n", __func__));
+       return 0;
+ }
+ static struct platform_driver wifi_device = {
+       .probe = wifi_probe,
+       .remove = wifi_remove,
+       .suspend = wifi_suspend,
+       .resume = wifi_resume,
+       .driver = {
+                  .name = KBUILD_MODNAME,
+                  }
+ };
+ int wifi_add_dev(void)
+ {
+       DHD_TRACE(("## Calling platform_driver_register\n"));
+       return platform_driver_register(&wifi_device);
+ }
+ void wifi_del_dev(void)
+ {
+       DHD_TRACE(("## Unregister platform_driver_register\n"));
+       platform_driver_unregister(&wifi_device);
+ }
+ #endif        /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
  
  #if defined(CONFIG_PM_SLEEP)
  #include <linux/suspend.h>
 -atomic_t dhd_mmc_suspend;
 -DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
 +atomic_t brcmf_mmc_suspend;
  #endif        /*  defined(CONFIG_PM_SLEEP) */
  
 -#if defined(OOB_INTR_ONLY)
 -extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
 -#endif        /* defined(OOB_INTR_ONLY) */
 -
  MODULE_AUTHOR("Broadcom Corporation");
  MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
  MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
  MODULE_LICENSE("Dual BSD/GPL");
  
 -#define DRV_MODULE_NAME "brcmfmac"
 -
 -/* Linux wireless extension support */
 -#if defined(CONFIG_WIRELESS_EXT)
 -#include <wl_iw.h>
 -extern wl_iw_extra_params_t g_wl_iw_params;
 -#endif                /* defined(CONFIG_WIRELESS_EXT) */
 -
 -#if defined(CONFIG_HAS_EARLYSUSPEND)
 -#include <linux/earlysuspend.h>
 -extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
 -                          uint len);
 -#endif                /* defined(CONFIG_HAS_EARLYSUSPEND) */
 -
 -#ifdef PKT_FILTER_SUPPORT
 -extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
 -extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
 -                                       int master_mode);
 -#endif
  
  /* Interface control information */
 -typedef struct dhd_if {
 -      struct dhd_info *info;  /* back pointer to dhd_info */
 +struct brcmf_if {
 +      struct brcmf_info *info;        /* back pointer to brcmf_info */
        /* OS/stack specifics */
        struct net_device *net;
        struct net_device_stats stats;
        bool attached;          /* Delayed attachment when unset */
        bool txflowcontrol;     /* Per interface flow control indicator */
        char name[IFNAMSIZ];    /* linux interface name */
 -} dhd_if_t;
 +};
  
  /* Local private structure (extension of pub) */
 -typedef struct dhd_info {
 -#if defined(CONFIG_WIRELESS_EXT)
 -      wl_iw_t iw;             /* wireless extensions state (must be first) */
 -#endif                                /* defined(CONFIG_WIRELESS_EXT) */
 -
 -      dhd_pub_t pub;
 +struct brcmf_info {
 +      struct brcmf_pub pub;
  
        /* OS/stack specifics */
 -      dhd_if_t *iflist[DHD_MAX_IFS];
 +      struct brcmf_if *iflist[BRCMF_MAX_IFS];
  
        struct semaphore proto_sem;
        wait_queue_head_t ioctl_resp_wait;
 -      struct timer_list timer;
 -      bool wd_timer_valid;
 -      struct tasklet_struct tasklet;
 -      spinlock_t sdlock;
 -      spinlock_t txqlock;
 -      /* Thread based operation */
 -      bool threads_only;
 -      struct semaphore sdsem;
 -      struct task_struct *watchdog_tsk;
 -      struct semaphore watchdog_sem;
 -      struct task_struct *dpc_tsk;
 -      struct semaphore dpc_sem;
  
        /* Thread to issue ioctl for multicast */
        struct task_struct *sysioc_tsk;
        bool set_multicast;
        bool set_macaddress;
        u8 macvalue[ETH_ALEN];
 -      wait_queue_head_t ctrl_wait;
        atomic_t pend_8021x_cnt;
 -
 -#ifdef CONFIG_HAS_EARLYSUSPEND
 -      struct early_suspend early_suspend;
 -#endif                                /* CONFIG_HAS_EARLYSUSPEND */
 -} dhd_info_t;
 -
 -/* Definitions to provide path to the firmware and nvram
 - * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
 - */
 -char firmware_path[MOD_PARAM_PATHLEN];
 -char nvram_path[MOD_PARAM_PATHLEN];
 -
 -/* load firmware and/or nvram values from the filesystem */
 -module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
 -module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
 +};
  
  /* Error bits */
 -module_param(dhd_msg_level, int, 0);
 +module_param(brcmf_msg_level, int, 0);
  
  /* Spawn a thread for system ioctls (set mac, set mcast) */
 -uint dhd_sysioc = true;
 -module_param(dhd_sysioc, uint, 0);
 -
 -/* Watchdog interval */
 -uint dhd_watchdog_ms = 10;
 -module_param(dhd_watchdog_ms, uint, 0);
 -
 -#ifdef DHD_DEBUG
 -/* Console poll interval */
 -uint dhd_console_ms;
 -module_param(dhd_console_ms, uint, 0);
 -#endif                                /* DHD_DEBUG */
 +uint brcmf_sysioc = true;
 +module_param(brcmf_sysioc, uint, 0);
  
  /* ARP offload agent mode : Enable ARP Host Auto-Reply
  and ARP Peer Auto-Reply */
 -uint dhd_arp_mode = 0xb;
 -module_param(dhd_arp_mode, uint, 0);
 +uint brcmf_arp_mode = 0xb;
 +module_param(brcmf_arp_mode, uint, 0);
  
  /* ARP offload enable */
 -uint dhd_arp_enable = true;
 -module_param(dhd_arp_enable, uint, 0);
 +uint brcmf_arp_enable = true;
 +module_param(brcmf_arp_enable, uint, 0);
  
  /* Global Pkt filter enable control */
 -uint dhd_pkt_filter_enable = true;
 -module_param(dhd_pkt_filter_enable, uint, 0);
 +uint brcmf_pkt_filter_enable = true;
 +module_param(brcmf_pkt_filter_enable, uint, 0);
  
  /*  Pkt filter init setup */
 -uint dhd_pkt_filter_init;
 -module_param(dhd_pkt_filter_init, uint, 0);
 +uint brcmf_pkt_filter_init;
 +module_param(brcmf_pkt_filter_init, uint, 0);
  
  /* Pkt filter mode control */
 -uint dhd_master_mode = true;
 -module_param(dhd_master_mode, uint, 1);
 +uint brcmf_master_mode = true;
 +module_param(brcmf_master_mode, uint, 0);
  
 -/* Watchdog thread priority, -1 to use kernel timer */
 -int dhd_watchdog_prio = 97;
 -module_param(dhd_watchdog_prio, int, 0);
 -
 -/* DPC thread priority, -1 to use tasklet */
 -int dhd_dpc_prio = 98;
 -module_param(dhd_dpc_prio, int, 0);
 -
 -/* DPC thread priority, -1 to use tasklet */
 -extern int dhd_dongle_memsize;
 -module_param(dhd_dongle_memsize, int, 0);
 +module_param(brcmf_dongle_memsize, int, 0);
  
  /* Contorl fw roaming */
 -#ifdef CUSTOMER_HW2
 -uint dhd_roam;
 -#else
 -uint dhd_roam = 1;
 -#endif
 +uint brcmf_roam = 1;
  
  /* Control radio state */
 -uint dhd_radio_up = 1;
 +uint brcmf_radio_up = 1;
  
  /* Network inteface name */
  char iface_name[IFNAMSIZ] = "wlan";
@@@ -128,58 -333,252 +251,58 @@@ module_param_string(iface_name, iface_n
  /* The following are specific to the SDIO dongle */
  
  /* IOCTL response timeout */
 -int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
 +int brcmf_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
  
  /* Idle timeout for backplane clock */
 -int dhd_idletime = DHD_IDLETIME_TICKS;
 -module_param(dhd_idletime, int, 0);
 +int brcmf_idletime = BRCMF_IDLETIME_TICKS;
 +module_param(brcmf_idletime, int, 0);
  
  /* Use polling */
 -uint dhd_poll = false;
 -module_param(dhd_poll, uint, 0);
 -
 -/* Use cfg80211 */
 -uint dhd_cfg80211 = true;
 -module_param(dhd_cfg80211, uint, 0);
 +uint brcmf_poll;
 +module_param(brcmf_poll, uint, 0);
  
  /* Use interrupts */
 -uint dhd_intr = true;
 -module_param(dhd_intr, uint, 0);
 +uint brcmf_intr = true;
 +module_param(brcmf_intr, uint, 0);
  
  /* SDIO Drive Strength (in milliamps) */
 -uint dhd_sdiod_drive_strength = 6;
 -module_param(dhd_sdiod_drive_strength, uint, 0);
 +uint brcmf_sdiod_drive_strength = 6;
 +module_param(brcmf_sdiod_drive_strength, uint, 0);
  
  /* Tx/Rx bounds */
 -extern uint dhd_txbound;
 -extern uint dhd_rxbound;
 -module_param(dhd_txbound, uint, 0);
 -module_param(dhd_rxbound, uint, 0);
 -
 -/* Deferred transmits */
 -extern uint dhd_deferred_tx;
 -module_param(dhd_deferred_tx, uint, 0);
 +module_param(brcmf_txbound, uint, 0);
 +module_param(brcmf_rxbound, uint, 0);
  
  #ifdef SDTEST
  /* Echo packet generator (pkts/s) */
 -uint dhd_pktgen;
 -module_param(dhd_pktgen, uint, 0);
 +uint brcmf_pktgen;
 +module_param(brcmf_pktgen, uint, 0);
  
  /* Echo packet len (0 => sawtooth, max 2040) */
 -uint dhd_pktgen_len;
 -module_param(dhd_pktgen_len, uint, 0);
 +uint brcmf_pktgen_len;
 +module_param(brcmf_pktgen_len, uint, 0);
  #endif
  
 -#define FAVORITE_WIFI_CP      (!!dhd_cfg80211)
 -#define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
 -#define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
 -#define NO_FW_REQ() (dhd_cfg80211 & 0x80)
 -
 -/* Version string to report */
 -#ifdef DHD_DEBUG
 -#define DHD_COMPILED "\nCompiled in " SRCBASE
 -#else
 -#define DHD_COMPILED
 -#endif
 -
 -static void dhd_dpc(unsigned long data);
 -/* forward decl */
 -extern int dhd_wait_pend8021x(struct net_device *dev);
 -
 -#ifdef TOE
 -#ifndef BDC
 -#error TOE requires BDC
 -#endif                                /* !BDC */
 -static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
 -static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
 -#endif                                /* TOE */
 -
 -static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
 -                           wl_event_msg_t *event_ptr, void **data_ptr);
 -
 -#if defined(CONFIG_PM_SLEEP)
 -static int dhd_sleep_pm_callback(struct notifier_block *nfb,
 -                               unsigned long action, void *ignored)
 -{
 -      switch (action) {
 -      case PM_HIBERNATION_PREPARE:
 -      case PM_SUSPEND_PREPARE:
 -              atomic_set(&dhd_mmc_suspend, true);
 -              return NOTIFY_OK;
 -      case PM_POST_HIBERNATION:
 -      case PM_POST_SUSPEND:
 -              atomic_set(&dhd_mmc_suspend, false);
 -              return NOTIFY_OK;
 -      }
 -      return 0;
 -}
 -
 -static struct notifier_block dhd_sleep_pm_notifier = {
 -      .notifier_call = dhd_sleep_pm_callback,
 -      .priority = 0
 -};
 -
 -extern int register_pm_notifier(struct notifier_block *nb);
 -extern int unregister_pm_notifier(struct notifier_block *nb);
 -#endif        /* defined(CONFIG_PM_SLEEP) */
 -      /* && defined(DHD_GPL) */
 -static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
 -{
 -#ifdef PKT_FILTER_SUPPORT
 -      DHD_TRACE(("%s: %d\n", __func__, value));
 -      /* 1 - Enable packet filter, only allow unicast packet to send up */
 -      /* 0 - Disable packet filter */
 -      if (dhd_pkt_filter_enable) {
 -              int i;
 -
 -              for (i = 0; i < dhd->pktfilter_count; i++) {
 -                      dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
 -                      dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
 -                                                   value, dhd_master_mode);
 -              }
 -      }
 -#endif
 -}
 -
 -#if defined(CONFIG_HAS_EARLYSUSPEND)
 -static int dhd_set_suspend(int value, dhd_pub_t *dhd)
 -{
 -      int power_mode = PM_MAX;
 -      /* wl_pkt_filter_enable_t       enable_parm; */
 -      char iovbuf[32];
 -      int bcn_li_dtim = 3;
 -#ifdef CUSTOMER_HW2
 -      uint roamvar = 1;
 -#endif                                /* CUSTOMER_HW2 */
 -
 -      DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
 -                 __func__, value, dhd->in_suspend));
 -
 -      if (dhd && dhd->up) {
 -              if (value && dhd->in_suspend) {
 -
 -                      /* Kernel suspended */
 -                      DHD_TRACE(("%s: force extra Suspend setting\n",
 -                                 __func__));
 -
 -                      dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
 -                                       (char *)&power_mode,
 -                                       sizeof(power_mode));
 -
 -                      /* Enable packet filter, only allow unicast
 -                               packet to send up */
 -                      dhd_set_packet_filter(1, dhd);
 -
 -                      /* if dtim skip setup as default force it
 -                       * to wake each third dtim
 -                       * for better power saving.
 -                       * Note that side effect is chance to miss BC/MC
 -                       * packet
 -                       */
 -                      if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
 -                              bcn_li_dtim = 3;
 -                      else
 -                              bcn_li_dtim = dhd->dtim_skip;
 -                      bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
 -                                  4, iovbuf, sizeof(iovbuf));
 -                      dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
 -                                       sizeof(iovbuf));
 -#ifdef CUSTOMER_HW2
 -                      /* Disable build-in roaming to allowed \
 -                       * supplicant to take of romaing
 -                       */
 -                      bcm_mkiovar("roam_off", (char *)&roamvar, 4,
 -                                  iovbuf, sizeof(iovbuf));
 -                      dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
 -                                       sizeof(iovbuf));
 -#endif                                /* CUSTOMER_HW2 */
 -              } else {
 -
 -                      /* Kernel resumed  */
 -                      DHD_TRACE(("%s: Remove extra suspend setting\n",
 -                                 __func__));
 -
 -                      power_mode = PM_FAST;
 -                      dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
 -                                       (char *)&power_mode,
 -                                       sizeof(power_mode));
 -
 -                      /* disable pkt filter */
 -                      dhd_set_packet_filter(0, dhd);
 -
 -                      /* restore pre-suspend setting for dtim_skip */
 -                      bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
 -                                  4, iovbuf, sizeof(iovbuf));
 -
 -                      dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
 -                                       sizeof(iovbuf));
 -#ifdef CUSTOMER_HW2
 -                      roamvar = 0;
 -                      bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
 -                                  sizeof(iovbuf));
 -                      dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
 -                                       sizeof(iovbuf));
 -#endif                                /* CUSTOMER_HW2 */
 -              }
 -      }
 -
 -      return 0;
 -}
 -
 -static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
 -{
 -      dhd_pub_t *dhdp = &dhd->pub;
 -
 -      dhd_os_proto_block(dhdp);
 -      /* Set flag when early suspend was called */
 -      dhdp->in_suspend = val;
 -      if (!dhdp->suspend_disable_flag)
 -              dhd_set_suspend(val, dhdp);
 -      dhd_os_proto_unblock(dhdp);
 -}
 -
 -static void dhd_early_suspend(struct early_suspend *h)
 -{
 -      struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
 -
 -      DHD_TRACE(("%s: enter\n", __func__));
 -
 -      if (dhd)
 -              dhd_suspend_resume_helper(dhd, 1);
 -
 -}
 -
 -static void dhd_late_resume(struct early_suspend *h)
 -{
 -      struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
 -
 -      DHD_TRACE(("%s: enter\n", __func__));
 -
 -      if (dhd)
 -              dhd_suspend_resume_helper(dhd, 0);
 -}
 -#endif                                /* defined(CONFIG_HAS_EARLYSUSPEND) */
 +static int brcmf_toe_get(struct brcmf_info *drvr_priv, int idx, u32 *toe_ol);
 +static int brcmf_toe_set(struct brcmf_info *drvr_priv, int idx, u32 toe_ol);
 +static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
 +                          struct brcmf_event_msg *event_ptr,
 +                          void **data_ptr);
  
  /*
   * Generalized timeout mechanism.  Uses spin sleep with exponential
   * back-off until
   * the sleep time reaches one jiffy, then switches over to task delay.  Usage:
   *
 - *      dhd_timeout_start(&tmo, usec);
 - *      while (!dhd_timeout_expired(&tmo))
 + *      brcmf_timeout_start(&tmo, usec);
 + *      while (!brcmf_timeout_expired(&tmo))
   *              if (poll_something())
   *                      break;
 - *      if (dhd_timeout_expired(&tmo))
 + *      if (brcmf_timeout_expired(&tmo))
   *              fatal();
   */
  
 -void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
 +void brcmf_timeout_start(struct brcmf_timeout *tmo, uint usec)
  {
        tmo->limit = usec;
        tmo->increment = 0;
        tmo->tick = 1000000 / HZ;
  }
  
 -int dhd_timeout_expired(dhd_timeout_t *tmo)
 +int brcmf_timeout_expired(struct brcmf_timeout *tmo)
  {
        /* Does nothing the first call */
        if (tmo->increment == 0) {
        return 0;
  }
  
 -static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
 +static int brcmf_net2idx(struct brcmf_info *drvr_priv, struct net_device *net)
  {
        int i = 0;
  
 -      ASSERT(dhd);
 -      while (i < DHD_MAX_IFS) {
 -              if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
 +      while (i < BRCMF_MAX_IFS) {
 +              if (drvr_priv->iflist[i] && (drvr_priv->iflist[i]->net == net))
                        return i;
                i++;
        }
  
 -      return DHD_BAD_IF;
 +      return BRCMF_BAD_IF;
  }
  
 -int dhd_ifname2idx(dhd_info_t *dhd, char *name)
 +int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name)
  {
 -      int i = DHD_MAX_IFS;
 -
 -      ASSERT(dhd);
 +      int i = BRCMF_MAX_IFS;
  
        if (name == NULL || *name == '\0')
                return 0;
  
        while (--i > 0)
 -              if (dhd->iflist[i]
 -                  && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
 +              if (drvr_priv->iflist[i]
 +                  && !strncmp(drvr_priv->iflist[i]->name, name, IFNAMSIZ))
                        break;
  
 -      DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
 +      BRCMF_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
  
        return i;               /* default - the primary interface */
  }
  
 -char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
 +char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
 +      struct brcmf_info *drvr_priv = drvr->info;
  
 -      ASSERT(dhd);
 -
 -      if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
 -              DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
 +      if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
 +              BRCMF_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
                return "<if_bad>";
        }
  
 -      if (dhd->iflist[ifidx] == NULL) {
 -              DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
 +      if (drvr_priv->iflist[ifidx] == NULL) {
 +              BRCMF_ERROR(("%s: null i/f %d\n", __func__, ifidx));
                return "<if_null>";
        }
  
 -      if (dhd->iflist[ifidx]->net)
 -              return dhd->iflist[ifidx]->net->name;
 +      if (drvr_priv->iflist[ifidx]->net)
 +              return drvr_priv->iflist[ifidx]->net->name;
  
        return "<if_none>";
  }
  
 -static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
 +static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx)
  {
        struct net_device *dev;
        struct netdev_hw_addr *ha;
        u32 allmulti, cnt;
  
 -      wl_ioctl_t ioc;
 +      struct brcmf_ioctl ioc;
        char *buf, *bufp;
        uint buflen;
        int ret;
  
 -      ASSERT(dhd && dhd->iflist[ifidx]);
 -      dev = dhd->iflist[ifidx]->net;
 +      dev = drvr_priv->iflist[ifidx]->net;
        cnt = netdev_mc_count(dev);
  
        /* Determine initial value of allmulti flag */
        buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
        bufp = buf = kmalloc(buflen, GFP_ATOMIC);
        if (!bufp) {
 -              DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
 -                         dhd_ifname(&dhd->pub, ifidx), cnt));
 +              BRCMF_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
                return;
        }
  
        }
  
        memset(&ioc, 0, sizeof(ioc));
 -      ioc.cmd = WLC_SET_VAR;
 +      ioc.cmd = BRCMF_C_SET_VAR;
        ioc.buf = buf;
        ioc.len = buflen;
        ioc.set = true;
  
 -      ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
 +      ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
 -              DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
 -                         dhd_ifname(&dhd->pub, ifidx), cnt));
 +              BRCMF_ERROR(("%s: set mcast_list failed, cnt %d\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
                allmulti = cnt ? true : allmulti;
        }
  
        buflen = sizeof("allmulti") + sizeof(allmulti);
        buf = kmalloc(buflen, GFP_ATOMIC);
        if (!buf) {
 -              DHD_ERROR(("%s: out of memory for allmulti\n",
 -                         dhd_ifname(&dhd->pub, ifidx)));
 +              BRCMF_ERROR(("%s: out of memory for allmulti\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx)));
                return;
        }
        allmulti = cpu_to_le32(allmulti);
  
 -      if (!bcm_mkiovar
 +      if (!brcmu_mkiovar
            ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
 -              DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
 -                      "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
 -                      (int)sizeof(allmulti), buflen));
 +              BRCMF_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
 +                           "buflen %u\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx),
 +                           (int)sizeof(allmulti), buflen));
                kfree(buf);
                return;
        }
  
        memset(&ioc, 0, sizeof(ioc));
 -      ioc.cmd = WLC_SET_VAR;
 +      ioc.cmd = BRCMF_C_SET_VAR;
        ioc.buf = buf;
        ioc.len = buflen;
        ioc.set = true;
  
 -      ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
 +      ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
 -              DHD_ERROR(("%s: set allmulti %d failed\n",
 -                         dhd_ifname(&dhd->pub, ifidx),
 -                         le32_to_cpu(allmulti)));
 +              BRCMF_ERROR(("%s: set allmulti %d failed\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx),
 +                           le32_to_cpu(allmulti)));
        }
  
        kfree(buf);
        allmulti = cpu_to_le32(allmulti);
  
        memset(&ioc, 0, sizeof(ioc));
 -      ioc.cmd = WLC_SET_PROMISC;
 +      ioc.cmd = BRCMF_C_SET_PROMISC;
        ioc.buf = &allmulti;
        ioc.len = sizeof(allmulti);
        ioc.set = true;
  
 -      ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
 +      ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
 -              DHD_ERROR(("%s: set promisc %d failed\n",
 -                         dhd_ifname(&dhd->pub, ifidx),
 -                         le32_to_cpu(allmulti)));
 +              BRCMF_ERROR(("%s: set promisc %d failed\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx),
 +                           le32_to_cpu(allmulti)));
        }
  }
  
 -static int
 -_dhd_set_mac_address(dhd_info_t *dhd, int ifidx, u8 *addr)
 +static int _brcmf_set_mac_address(struct brcmf_info *drvr_priv, int ifidx, u8 *addr)
  {
        char buf[32];
 -      wl_ioctl_t ioc;
 +      struct brcmf_ioctl ioc;
        int ret;
  
 -      DHD_TRACE(("%s enter\n", __func__));
 -      if (!bcm_mkiovar
 +      BRCMF_TRACE(("%s enter\n", __func__));
 +      if (!brcmu_mkiovar
            ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
 -              DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
 -                         dhd_ifname(&dhd->pub, ifidx)));
 +              BRCMF_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx)));
                return -1;
        }
        memset(&ioc, 0, sizeof(ioc));
 -      ioc.cmd = WLC_SET_VAR;
 +      ioc.cmd = BRCMF_C_SET_VAR;
        ioc.buf = buf;
        ioc.len = 32;
        ioc.set = true;
  
 -      ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
 +      ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
 -              DHD_ERROR(("%s: set cur_etheraddr failed\n",
 -                         dhd_ifname(&dhd->pub, ifidx)));
 +              BRCMF_ERROR(("%s: set cur_etheraddr failed\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx)));
        } else {
 -              memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
 +              memcpy(drvr_priv->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
        }
  
        return ret;
  extern struct net_device *ap_net_dev;
  #endif
  
 -static void dhd_op_if(dhd_if_t *ifp)
 +/* Virtual interfaces only ((ifp && ifp->info && ifp->idx == true) */
 +static void brcmf_op_if(struct brcmf_if *ifp)
  {
 -      dhd_info_t *dhd;
 +      struct brcmf_info *drvr_priv;
        int ret = 0, err = 0;
  
 -      ASSERT(ifp && ifp->info && ifp->idx);   /* Virtual interfaces only */
 -
 -      dhd = ifp->info;
 +      drvr_priv = ifp->info;
  
 -      DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
 +      BRCMF_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
  
        switch (ifp->state) {
 -      case WLC_E_IF_ADD:
 +      case BRCMF_E_IF_ADD:
                /*
                 * Delete the existing interface before overwriting it
 -               * in case we missed the WLC_E_IF_DEL event.
 +               * in case we missed the BRCMF_E_IF_DEL event.
                 */
                if (ifp->net != NULL) {
 -                      DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
 -                      "try free & unregister\n",
 -                      __func__, ifp->net->name));
 +                      BRCMF_ERROR(("%s: ERROR: netdev:%s already exists, "
 +                                   "try free & unregister\n",
 +                                   __func__, ifp->net->name));
                        netif_stop_queue(ifp->net);
                        unregister_netdev(ifp->net);
                        free_netdev(ifp->net);
                }
                /* Allocate etherdev, including space for private structure */
 -              ifp->net = alloc_etherdev(sizeof(dhd));
 +              ifp->net = alloc_etherdev(sizeof(drvr_priv));
                if (!ifp->net) {
 -                      DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
 +                      BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
                        ret = -ENOMEM;
                }
                if (ret == 0) {
                        strcpy(ifp->net->name, ifp->name);
 -                      memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
 -                      err = dhd_net_attach(&dhd->pub, ifp->idx);
 +                      memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv));
 +                      err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
                        if (err != 0) {
 -                              DHD_ERROR(("%s: dhd_net_attach failed, "
 -                                      "err %d\n",
 -                                      __func__, err));
 +                              BRCMF_ERROR(("%s: brcmf_net_attach failed, "
 +                                           "err %d\n",
 +                                           __func__, err));
                                ret = -EOPNOTSUPP;
                        } else {
  #ifdef SOFTAP
                                         wl0.1 is ready */
                                up(&ap_eth_sema);
  #endif
 -                              DHD_TRACE(("\n ==== pid:%x, net_device for "
 -                                      "if:%s created ===\n\n",
 -                                      current->pid, ifp->net->name));
 +                              BRCMF_TRACE(("\n ==== pid:%x, net_device for "
 +                                           "if:%s created ===\n\n",
 +                                           current->pid, ifp->net->name));
                                ifp->state = 0;
                        }
                }
                break;
 -      case WLC_E_IF_DEL:
 +      case BRCMF_E_IF_DEL:
                if (ifp->net != NULL) {
 -                      DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
 -                                 __func__));
 +                      BRCMF_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
 +                                   __func__));
                        netif_stop_queue(ifp->net);
                        unregister_netdev(ifp->net);
 -                      ret = DHD_DEL_IF;       /* Make sure the free_netdev()
 +                      ret = BRCMF_DEL_IF;     /* Make sure the free_netdev()
                                                         is called */
                }
                break;
        default:
 -              DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
 -              ASSERT(!ifp->state);
 +              BRCMF_ERROR(("%s: bad op %d\n", __func__, ifp->state));
                break;
        }
  
                if (ifp->net)
                        free_netdev(ifp->net);
  
 -              dhd->iflist[ifp->idx] = NULL;
 +              drvr_priv->iflist[ifp->idx] = NULL;
                kfree(ifp);
  #ifdef SOFTAP
                if (ifp->net == ap_net_dev)
        }
  }
  
 -static int _dhd_sysioc_thread(void *data)
 +static int _brcmf_sysioc_thread(void *data)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) data;
 +      struct brcmf_info *drvr_priv = (struct brcmf_info *) data;
        int i;
  #ifdef SOFTAP
        bool in_ap = false;
  
        allow_signal(SIGTERM);
  
 -      while (down_interruptible(&dhd->sysioc_sem) == 0) {
 +      while (down_interruptible(&drvr_priv->sysioc_sem) == 0) {
                if (kthread_should_stop())
                        break;
 -              for (i = 0; i < DHD_MAX_IFS; i++) {
 -                      if (dhd->iflist[i]) {
 +              for (i = 0; i < BRCMF_MAX_IFS; i++) {
 +                      struct brcmf_if *ifentry = drvr_priv->iflist[i];
 +                      if (ifentry) {
  #ifdef SOFTAP
                                in_ap = (ap_net_dev != NULL);
  #endif                                /* SOFTAP */
 -                              if (dhd->iflist[i]->state)
 -                                      dhd_op_if(dhd->iflist[i]);
 +                              if (ifentry->state)
 +                                      brcmf_op_if(ifentry);
  #ifdef SOFTAP
 -                              if (dhd->iflist[i] == NULL) {
 -                                      DHD_TRACE(("\n\n %s: interface %d "
 -                                              "removed!\n", __func__, i));
 +                              if (drvr_priv->iflist[i] == NULL) {
 +                                      BRCMF_TRACE(("\n\n %s: interface %d "
 +                                                   "removed!\n", __func__,
 +                                                   i));
                                        continue;
                                }
  
 -                              if (in_ap && dhd->set_macaddress) {
 -                                      DHD_TRACE(("attempt to set MAC for %s "
 -                                              "in AP Mode," "blocked. \n",
 -                                              dhd->iflist[i]->net->name));
 -                                      dhd->set_macaddress = false;
 +                              if (in_ap && drvr_priv->set_macaddress) {
 +                                      BRCMF_TRACE(("attempt to set MAC for"
 +                                                   " %s in AP Mode,"
 +                                                   " blocked.\n",
 +                                                   ifentry->net->name));
 +                                      drvr_priv->set_macaddress = false;
                                        continue;
                                }
  
 -                              if (in_ap && dhd->set_multicast) {
 -                                      DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
 -                                              dhd->iflist[i]->net->name));
 -                                      dhd->set_multicast = false;
 +                              if (in_ap && drvr_priv->set_multicast) {
 +                                      BRCMF_TRACE(("attempt to set MULTICAST "
 +                                                   "list for %s in AP Mode, "
 +                                                   "blocked.\n",
 +                                                   ifentry->net->name));
 +                                      drvr_priv->set_multicast = false;
                                        continue;
                                }
  #endif                                /* SOFTAP */
 -                              if (dhd->set_multicast) {
 -                                      dhd->set_multicast = false;
 -                                      _dhd_set_multicast_list(dhd, i);
 +                              if (drvr_priv->set_multicast) {
 +                                      drvr_priv->set_multicast = false;
 +                                      _brcmf_set_multicast_list(drvr_priv, i);
                                }
 -                              if (dhd->set_macaddress) {
 -                                      dhd->set_macaddress = false;
 -                                      _dhd_set_mac_address(dhd, i,
 -                                                           dhd->macvalue);
 +                              if (drvr_priv->set_macaddress) {
 +                                      drvr_priv->set_macaddress = false;
 +                                      _brcmf_set_mac_address(drvr_priv, i,
 +                                              drvr_priv->macvalue);
                                }
                        }
                }
        return 0;
  }
  
 -static int dhd_set_mac_address(struct net_device *dev, void *addr)
 +static int brcmf_netdev_set_mac_address(struct net_device *dev, void *addr)
  {
        int ret = 0;
  
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
        struct sockaddr *sa = (struct sockaddr *)addr;
        int ifidx;
  
 -      ifidx = dhd_net2idx(dhd, dev);
 -      if (ifidx == DHD_BAD_IF)
 +      ifidx = brcmf_net2idx(drvr_priv, dev);
 +      if (ifidx == BRCMF_BAD_IF)
                return -1;
  
 -      ASSERT(dhd->sysioc_tsk);
 -      memcpy(&dhd->macvalue, sa->sa_data, ETH_ALEN);
 -      dhd->set_macaddress = true;
 -      up(&dhd->sysioc_sem);
 +      memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN);
 +      drvr_priv->set_macaddress = true;
 +      up(&drvr_priv->sysioc_sem);
  
        return ret;
  }
  
 -static void dhd_set_multicast_list(struct net_device *dev)
 +static void brcmf_netdev_set_multicast_list(struct net_device *dev)
  {
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
        int ifidx;
  
 -      ifidx = dhd_net2idx(dhd, dev);
 -      if (ifidx == DHD_BAD_IF)
 +      ifidx = brcmf_net2idx(drvr_priv, dev);
 +      if (ifidx == BRCMF_BAD_IF)
                return;
  
 -      ASSERT(dhd->sysioc_tsk);
 -      dhd->set_multicast = true;
 -      up(&dhd->sysioc_sem);
 +      drvr_priv->set_multicast = true;
 +      up(&drvr_priv->sysioc_sem);
  }
  
 -int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf)
 +int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf)
  {
 -      int ret;
 -      dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
 +      struct brcmf_info *drvr_priv = drvr->info;
  
        /* Reject if down */
 -      if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
 +      if (!drvr->up || (drvr->busstate == BRCMF_BUS_DOWN))
                return -ENODEV;
  
        /* Update multicast statistic */
                struct ethhdr *eh = (struct ethhdr *)pktdata;
  
                if (is_multicast_ether_addr(eh->h_dest))
 -                      dhdp->tx_multicast++;
 +                      drvr->tx_multicast++;
                if (ntohs(eh->h_proto) == ETH_P_PAE)
 -                      atomic_inc(&dhd->pend_8021x_cnt);
 +                      atomic_inc(&drvr_priv->pend_8021x_cnt);
        }
  
        /* If the protocol uses a data header, apply it */
 -      dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
 +      brcmf_proto_hdrpush(drvr, ifidx, pktbuf);
  
        /* Use bus module to send data frame */
 -#ifdef BCMDBUS
 -      ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
 -#else
 -      ret = dhd_bus_txdata(dhdp->bus, pktbuf);
 -#endif                                /* BCMDBUS */
 -
 -      return ret;
 -}
 -
 -static inline void *
 -osl_pkt_frmnative(struct sk_buff *skb)
 -{
 -      return (void *)skb;
 +      return brcmf_sdbrcm_bus_txdata(drvr->bus, pktbuf);
  }
 -#define PKTFRMNATIVE(osh, skb)        \
 -      osl_pkt_frmnative((struct sk_buff *)(skb))
  
 -static inline struct sk_buff *
 -osl_pkt_tonative(void *pkt)
 -{
 -      return (struct sk_buff *)pkt;
 -}
 -#define PKTTONATIVE(osh, pkt) \
 -      osl_pkt_tonative((pkt))
 -
 -static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
 +static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *net)
  {
        int ret;
 -      void *pktbuf;
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
        int ifidx;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* Reject if down */
 -      if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
 -              DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
 -                         __func__, dhd->pub.up, dhd->pub.busstate));
 +      if (!drvr_priv->pub.up || (drvr_priv->pub.busstate == BRCMF_BUS_DOWN)) {
 +              BRCMF_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
 +                           __func__, drvr_priv->pub.up,
 +                           drvr_priv->pub.busstate));
                netif_stop_queue(net);
                return -ENODEV;
        }
  
 -      ifidx = dhd_net2idx(dhd, net);
 -      if (ifidx == DHD_BAD_IF) {
 -              DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
 +      ifidx = brcmf_net2idx(drvr_priv, net);
 +      if (ifidx == BRCMF_BAD_IF) {
 +              BRCMF_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
                netif_stop_queue(net);
                return -ENODEV;
        }
  
        /* Make sure there's enough room for any header */
 -      if (skb_headroom(skb) < dhd->pub.hdrlen) {
 +      if (skb_headroom(skb) < drvr_priv->pub.hdrlen) {
                struct sk_buff *skb2;
  
 -              DHD_INFO(("%s: insufficient headroom\n",
 -                        dhd_ifname(&dhd->pub, ifidx)));
 -              dhd->pub.tx_realloc++;
 -              skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
 +              BRCMF_INFO(("%s: insufficient headroom\n",
 +                          brcmf_ifname(&drvr_priv->pub, ifidx)));
 +              drvr_priv->pub.tx_realloc++;
 +              skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen);
                dev_kfree_skb(skb);
                skb = skb2;
                if (skb == NULL) {
 -                      DHD_ERROR(("%s: skb_realloc_headroom failed\n",
 -                                 dhd_ifname(&dhd->pub, ifidx)));
 +                      BRCMF_ERROR(("%s: skb_realloc_headroom failed\n",
 +                                   brcmf_ifname(&drvr_priv->pub, ifidx)));
                        ret = -ENOMEM;
                        goto done;
                }
        }
  
 -      /* Convert to packet */
 -      pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
 -      if (!pktbuf) {
 -              DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
 -                         dhd_ifname(&dhd->pub, ifidx)));
 -              dev_kfree_skb_any(skb);
 -              ret = -ENOMEM;
 -              goto done;
 -      }
 -
 -      ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
 +      ret = brcmf_sendpkt(&drvr_priv->pub, ifidx, skb);
  
  done:
        if (ret)
 -              dhd->pub.dstats.tx_dropped++;
 +              drvr_priv->pub.dstats.tx_dropped++;
        else
 -              dhd->pub.tx_packets++;
 +              drvr_priv->pub.tx_packets++;
  
        /* Return ok: we always eat the packet */
        return 0;
  }
  
 -void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
 +void brcmf_txflowcontrol(struct brcmf_pub *drvr, int ifidx, bool state)
  {
        struct net_device *net;
 -      dhd_info_t *dhd = dhdp->info;
 +      struct brcmf_info *drvr_priv = drvr->info;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -      dhdp->txoff = state;
 -      ASSERT(dhd && dhd->iflist[ifidx]);
 -      net = dhd->iflist[ifidx]->net;
 +      drvr->txoff = state;
 +      net = drvr_priv->iflist[ifidx]->net;
        if (state == ON)
                netif_stop_queue(net);
        else
                netif_wake_queue(net);
  }
  
 -void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf,
 +void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
                  int numpkt)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
 -      struct sk_buff *skb;
 +      struct brcmf_info *drvr_priv = drvr->info;
        unsigned char *eth;
        uint len;
        void *data;
        struct sk_buff *pnext, *save_pktbuf;
        int i;
 -      dhd_if_t *ifp;
 -      wl_event_msg_t event;
 +      struct brcmf_if *ifp;
 +      struct brcmf_event_msg event;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -      save_pktbuf = pktbuf;
 +      save_pktbuf = skb;
  
 -      for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
 +      for (i = 0; skb && i < numpkt; i++, skb = pnext) {
  
 -              pnext = pktbuf->next;
 -              pktbuf->next = NULL;
 -
 -              skb = PKTTONATIVE(dhdp->osh, pktbuf);
 +              pnext = skb->next;
 +              skb->next = NULL;
  
                /* Get the protocol, maintain skb around eth_type_trans()
                 * The main reason for this hack is for the limitation of
                eth = skb->data;
                len = skb->len;
  
 -              ifp = dhd->iflist[ifidx];
 +              ifp = drvr_priv->iflist[ifidx];
                if (ifp == NULL)
 -                      ifp = dhd->iflist[0];
 +                      ifp = drvr_priv->iflist[0];
  
 -              ASSERT(ifp);
                skb->dev = ifp->net;
                skb->protocol = eth_type_trans(skb, skb->dev);
  
                if (skb->pkt_type == PACKET_MULTICAST)
 -                      dhd->pub.rx_multicast++;
 +                      drvr_priv->pub.rx_multicast++;
  
                skb->data = eth;
                skb->len = len;
                skb_pull(skb, ETH_HLEN);
  
                /* Process special event packets and then discard them */
 -              if (ntohs(skb->protocol) == ETH_P_BRCM)
 -                      dhd_wl_host_event(dhd, &ifidx,
 +              if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
 +                      brcmf_host_event(drvr_priv, &ifidx,
                                          skb_mac_header(skb),
                                          &event, &data);
  
 -              ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
 -              if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
 -                      ifp = dhd->iflist[ifidx];
 +              if (drvr_priv->iflist[ifidx] &&
 +                  !drvr_priv->iflist[ifidx]->state)
 +                      ifp = drvr_priv->iflist[ifidx];
  
                if (ifp->net)
                        ifp->net->last_rx = jiffies;
  
 -              dhdp->dstats.rx_bytes += skb->len;
 -              dhdp->rx_packets++;     /* Local count */
 +              drvr->dstats.rx_bytes += skb->len;
 +              drvr->rx_packets++;     /* Local count */
  
                if (in_interrupt()) {
                        netif_rx(skb);
        }
  }
  
 -void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
 -{
 -      /* Linux version has nothing to do */
 -      return;
 -}
 -
 -void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success)
 +void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp, bool success)
  {
        uint ifidx;
 -      dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
 +      struct brcmf_info *drvr_priv = drvr->info;
        struct ethhdr *eh;
        u16 type;
  
 -      dhd_prot_hdrpull(dhdp, &ifidx, txp);
 +      brcmf_proto_hdrpull(drvr, &ifidx, txp);
  
        eh = (struct ethhdr *)(txp->data);
        type = ntohs(eh->h_proto);
  
        if (type == ETH_P_PAE)
 -              atomic_dec(&dhd->pend_8021x_cnt);
 +              atomic_dec(&drvr_priv->pend_8021x_cnt);
  
  }
  
 -static struct net_device_stats *dhd_get_stats(struct net_device *net)
 +static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *net)
  {
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 -      dhd_if_t *ifp;
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
 +      struct brcmf_if *ifp;
        int ifidx;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -      ifidx = dhd_net2idx(dhd, net);
 -      if (ifidx == DHD_BAD_IF)
 +      ifidx = brcmf_net2idx(drvr_priv, net);
 +      if (ifidx == BRCMF_BAD_IF)
                return NULL;
  
 -      ifp = dhd->iflist[ifidx];
 -      ASSERT(dhd && ifp);
 +      ifp = drvr_priv->iflist[ifidx];
  
 -      if (dhd->pub.up) {
 +      if (drvr_priv->pub.up) {
                /* Use the protocol to get dongle stats */
 -              dhd_prot_dstats(&dhd->pub);
 +              brcmf_proto_dstats(&drvr_priv->pub);
        }
  
        /* Copy dongle stats to net device stats */
 -      ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
 -      ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
 -      ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
 -      ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
 -      ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
 -      ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
 -      ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
 -      ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
 -      ifp->stats.multicast = dhd->pub.dstats.multicast;
 +      ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets;
 +      ifp->stats.tx_packets = drvr_priv->pub.dstats.tx_packets;
 +      ifp->stats.rx_bytes = drvr_priv->pub.dstats.rx_bytes;
 +      ifp->stats.tx_bytes = drvr_priv->pub.dstats.tx_bytes;
 +      ifp->stats.rx_errors = drvr_priv->pub.dstats.rx_errors;
 +      ifp->stats.tx_errors = drvr_priv->pub.dstats.tx_errors;
 +      ifp->stats.rx_dropped = drvr_priv->pub.dstats.rx_dropped;
 +      ifp->stats.tx_dropped = drvr_priv->pub.dstats.tx_dropped;
 +      ifp->stats.multicast = drvr_priv->pub.dstats.multicast;
  
        return &ifp->stats;
  }
  
 -static int dhd_watchdog_thread(void *data)
 -{
 -      dhd_info_t *dhd = (dhd_info_t *) data;
 -
 -      /* This thread doesn't need any user-level access,
 -       * so get rid of all our resources
 -       */
 -#ifdef DHD_SCHED
 -      if (dhd_watchdog_prio > 0) {
 -              struct sched_param param;
 -              param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
 -                  dhd_watchdog_prio : (MAX_RT_PRIO - 1);
 -              setScheduler(current, SCHED_FIFO, &param);
 -      }
 -#endif                                /* DHD_SCHED */
 -
 -      allow_signal(SIGTERM);
 -      /* Run until signal received */
 -      while (1) {
 -              if (kthread_should_stop())
 -                      break;
 -              if (down_interruptible(&dhd->watchdog_sem) == 0) {
 -                      if (dhd->pub.dongle_reset == false) {
 -                              /* Call the bus module watchdog */
 -                              dhd_bus_watchdog(&dhd->pub);
 -                      }
 -                      /* Count the tick for reference */
 -                      dhd->pub.tickcnt++;
 -              } else
 -                      break;
 -      }
 -      return 0;
 -}
 -
 -static void dhd_watchdog(unsigned long data)
 -{
 -      dhd_info_t *dhd = (dhd_info_t *) data;
 -
 -      if (dhd->watchdog_tsk) {
 -              up(&dhd->watchdog_sem);
 -
 -              /* Reschedule the watchdog */
 -              if (dhd->wd_timer_valid) {
 -                      mod_timer(&dhd->timer,
 -                                jiffies + dhd_watchdog_ms * HZ / 1000);
 -              }
 -              return;
 -      }
 -
 -      /* Call the bus module watchdog */
 -      dhd_bus_watchdog(&dhd->pub);
 -
 -      /* Count the tick for reference */
 -      dhd->pub.tickcnt++;
 -
 -      /* Reschedule the watchdog */
 -      if (dhd->wd_timer_valid)
 -              mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
 -}
 -
 -static int dhd_dpc_thread(void *data)
 -{
 -      dhd_info_t *dhd = (dhd_info_t *) data;
 -
 -      /* This thread doesn't need any user-level access,
 -       * so get rid of all our resources
 -       */
 -#ifdef DHD_SCHED
 -      if (dhd_dpc_prio > 0) {
 -              struct sched_param param;
 -              param.sched_priority =
 -                  (dhd_dpc_prio <
 -                   MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
 -              setScheduler(current, SCHED_FIFO, &param);
 -      }
 -#endif                                /* DHD_SCHED */
 -
 -      allow_signal(SIGTERM);
 -      /* Run until signal received */
 -      while (1) {
 -              if (kthread_should_stop())
 -                      break;
 -              if (down_interruptible(&dhd->dpc_sem) == 0) {
 -                      /* Call bus dpc unless it indicated down
 -                               (then clean stop) */
 -                      if (dhd->pub.busstate != DHD_BUS_DOWN) {
 -                              if (dhd_bus_dpc(dhd->pub.bus)) {
 -                                      up(&dhd->dpc_sem);
 -                              }
 -                      } else {
 -                              dhd_bus_stop(dhd->pub.bus, true);
 -                      }
 -              } else
 -                      break;
 -      }
 -      return 0;
 -}
 -
 -static void dhd_dpc(unsigned long data)
 -{
 -      dhd_info_t *dhd;
 -
 -      dhd = (dhd_info_t *) data;
 -
 -      /* Call bus dpc unless it indicated down (then clean stop) */
 -      if (dhd->pub.busstate != DHD_BUS_DOWN) {
 -              if (dhd_bus_dpc(dhd->pub.bus))
 -                      tasklet_schedule(&dhd->tasklet);
 -      } else {
 -              dhd_bus_stop(dhd->pub.bus, true);
 -      }
 -}
 -
 -void dhd_sched_dpc(dhd_pub_t *dhdp)
 -{
 -      dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
 -
 -      if (dhd->dpc_tsk) {
 -              up(&dhd->dpc_sem);
 -              return;
 -      }
 -
 -      tasklet_schedule(&dhd->tasklet);
 -}
 -
 -#ifdef TOE
  /* Retrieve current toe component enables, which are kept
         as a bitmap in toe_ol iovar */
 -static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
 +static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol)
  {
 -      wl_ioctl_t ioc;
 +      struct brcmf_ioctl ioc;
        char buf[32];
        int ret;
  
        memset(&ioc, 0, sizeof(ioc));
  
 -      ioc.cmd = WLC_GET_VAR;
 +      ioc.cmd = BRCMF_C_GET_VAR;
        ioc.buf = buf;
        ioc.len = (uint) sizeof(buf);
        ioc.set = false;
  
        strcpy(buf, "toe_ol");
 -      ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
 +      ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
                /* Check for older dongle image that doesn't support toe_ol */
                if (ret == -EIO) {
 -                      DHD_ERROR(("%s: toe not supported by device\n",
 -                                 dhd_ifname(&dhd->pub, ifidx)));
 +                      BRCMF_ERROR(("%s: toe not supported by device\n",
 +                                   brcmf_ifname(&drvr_priv->pub, ifidx)));
                        return -EOPNOTSUPP;
                }
  
 -              DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
 -                        dhd_ifname(&dhd->pub, ifidx), ret));
 +              BRCMF_INFO(("%s: could not get toe_ol: ret=%d\n",
 +                          brcmf_ifname(&drvr_priv->pub, ifidx), ret));
                return ret;
        }
  
  
  /* Set current toe component enables in toe_ol iovar,
         and set toe global enable iovar */
 -static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
 +static int brcmf_toe_set(struct brcmf_info *drvr_priv, int ifidx, u32 toe_ol)
  {
 -      wl_ioctl_t ioc;
 +      struct brcmf_ioctl ioc;
        char buf[32];
        int toe, ret;
  
        memset(&ioc, 0, sizeof(ioc));
  
 -      ioc.cmd = WLC_SET_VAR;
 +      ioc.cmd = BRCMF_C_SET_VAR;
        ioc.buf = buf;
        ioc.len = (uint) sizeof(buf);
        ioc.set = true;
        strcpy(buf, "toe_ol");
        memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
  
 -      ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
 +      ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
 -              DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
 -                         dhd_ifname(&dhd->pub, ifidx), ret));
 +              BRCMF_ERROR(("%s: could not set toe_ol: ret=%d\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx), ret));
                return ret;
        }
  
        strcpy(buf, "toe");
        memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
  
 -      ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
 +      ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
 -              DHD_ERROR(("%s: could not set toe: ret=%d\n",
 -                         dhd_ifname(&dhd->pub, ifidx), ret));
 +              BRCMF_ERROR(("%s: could not set toe: ret=%d\n",
 +                           brcmf_ifname(&drvr_priv->pub, ifidx), ret));
                return ret;
        }
  
        return 0;
  }
 -#endif                                /* TOE */
  
 -static void dhd_ethtool_get_drvinfo(struct net_device *net,
 +static void brcmf_ethtool_get_drvinfo(struct net_device *net,
                                    struct ethtool_drvinfo *info)
  {
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
  
 -      sprintf(info->driver, DRV_MODULE_NAME);
 -      sprintf(info->version, "%lu", dhd->pub.drv_version);
 -      sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
 -      sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
 +      sprintf(info->driver, KBUILD_MODNAME);
 +      sprintf(info->version, "%lu", drvr_priv->pub.drv_version);
 +      sprintf(info->fw_version, "%s", BCM4329_FW_NAME);
 +      sprintf(info->bus_info, "%s",
 +              dev_name(&brcmf_cfg80211_get_sdio_func()->dev));
  }
  
 -struct ethtool_ops dhd_ethtool_ops = {
 -      .get_drvinfo = dhd_ethtool_get_drvinfo
 +struct ethtool_ops brcmf_ethtool_ops = {
 +      .get_drvinfo = brcmf_ethtool_get_drvinfo
  };
  
 -static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
 +static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
  {
        struct ethtool_drvinfo info;
        char drvname[sizeof(info.driver)];
        u32 cmd;
 -#ifdef TOE
        struct ethtool_value edata;
        u32 toe_cmpnt, csum_dir;
        int ret;
 -#endif
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* all ethtool calls start with a cmd word */
        if (copy_from_user(&cmd, uaddr, sizeof(u32)))
                memset(&info, 0, sizeof(info));
                info.cmd = cmd;
  
 -              /* if dhd requested, identify ourselves */
 +              /* if requested, identify ourselves */
                if (strcmp(drvname, "?dhd") == 0) {
                        sprintf(info.driver, "dhd");
 -                      strcpy(info.version, EPI_VERSION_STR);
 +                      strcpy(info.version, BRCMF_VERSION_STR);
                }
  
                /* otherwise, require dongle to be up */
 -              else if (!dhd->pub.up) {
 -                      DHD_ERROR(("%s: dongle is not up\n", __func__));
 +              else if (!drvr_priv->pub.up) {
 +                      BRCMF_ERROR(("%s: dongle is not up\n", __func__));
                        return -ENODEV;
                }
  
                /* finally, report dongle driver type */
 -              else if (dhd->pub.iswl)
 +              else if (drvr_priv->pub.iswl)
                        sprintf(info.driver, "wl");
                else
                        sprintf(info.driver, "xx");
  
 -              sprintf(info.version, "%lu", dhd->pub.drv_version);
 +              sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
                if (copy_to_user(uaddr, &info, sizeof(info)))
                        return -EFAULT;
 -              DHD_CTL(("%s: given %*s, returning %s\n", __func__,
 -                       (int)sizeof(drvname), drvname, info.driver));
 +              BRCMF_CTL(("%s: given %*s, returning %s\n", __func__,
 +                         (int)sizeof(drvname), drvname, info.driver));
                break;
  
 -#ifdef TOE
                /* Get toe offload components from dongle */
        case ETHTOOL_GRXCSUM:
        case ETHTOOL_GTXCSUM:
 -              ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
 +              ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
                if (ret < 0)
                        return ret;
  
                        return -EFAULT;
  
                /* Read the current settings, update and write back */
 -              ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
 +              ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
                if (ret < 0)
                        return ret;
  
                else
                        toe_cmpnt &= ~csum_dir;
  
 -              ret = dhd_toe_set(dhd, 0, toe_cmpnt);
 +              ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt);
                if (ret < 0)
                        return ret;
  
                /* If setting TX checksum mode, tell Linux the new mode */
                if (cmd == ETHTOOL_STXCSUM) {
                        if (edata.data)
 -                              dhd->iflist[0]->net->features |=
 +                              drvr_priv->iflist[0]->net->features |=
                                    NETIF_F_IP_CSUM;
                        else
 -                              dhd->iflist[0]->net->features &=
 +                              drvr_priv->iflist[0]->net->features &=
                                    ~NETIF_F_IP_CSUM;
                }
  
                break;
 -#endif                                /* TOE */
  
        default:
                return -EOPNOTSUPP;
        return 0;
  }
  
 -static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
 +static int brcmf_netdev_ioctl_entry(struct net_device *net, struct ifreq *ifr,
 +                                  int cmd)
  {
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 -      dhd_ioctl_t ioc;
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
 +      struct brcmf_c_ioctl ioc;
        int bcmerror = 0;
        int buflen = 0;
        void *buf = NULL;
        int ifidx;
        bool is_set_key_cmd;
  
 -      ifidx = dhd_net2idx(dhd, net);
 -      DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
 +      ifidx = brcmf_net2idx(drvr_priv, net);
 +      BRCMF_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
  
 -      if (ifidx == DHD_BAD_IF)
 +      if (ifidx == BRCMF_BAD_IF)
                return -1;
  
 -#if defined(CONFIG_WIRELESS_EXT)
 -      /* linux wireless extensions */
 -      if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
 -              /* may recurse, do NOT lock */
 -              return wl_iw_ioctl(net, ifr, cmd);
 -      }
 -#endif                                /* defined(CONFIG_WIRELESS_EXT) */
 -
        if (cmd == SIOCETHTOOL)
 -              return dhd_ethtool(dhd, (void *)ifr->ifr_data);
 +              return brcmf_ethtool(drvr_priv, (void *)ifr->ifr_data);
  
        if (cmd != SIOCDEVPRIVATE)
                return -EOPNOTSUPP;
        memset(&ioc, 0, sizeof(ioc));
  
        /* Copy the ioc control structure part of ioctl request */
 -      if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
 +      if (copy_from_user(&ioc, ifr->ifr_data, sizeof(struct brcmf_ioctl))) {
                bcmerror = -EINVAL;
                goto done;
        }
  
        /* Copy out any buffer passed */
        if (ioc.buf) {
 -              buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
 +              buflen = min_t(int, ioc.len, BRCMF_IOCTL_MAXLEN);
                /* optimization for direct ioctl calls from kernel */
                /*
                   if (segment_eq(get_fs(), KERNEL_DS)) {
                }
        }
  
 -      /* To differentiate between wl and dhd read 4 more byes */
 -      if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
 -                          sizeof(uint)) != 0)) {
 +      /* To differentiate read 4 more byes */
 +      if ((copy_from_user(&driver, (char *)ifr->ifr_data +
 +                          sizeof(struct brcmf_ioctl), sizeof(uint)) != 0)) {
                bcmerror = -EINVAL;
                goto done;
        }
                goto done;
        }
  
 -      /* check for local dhd ioctl and handle it */
 -      if (driver == DHD_IOCTL_MAGIC) {
 -              bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
 +      /* check for local brcmf ioctl and handle it */
 +      if (driver == BRCMF_IOCTL_MAGIC) {
 +              bcmerror = brcmf_c_ioctl((void *)&drvr_priv->pub, &ioc, buf, buflen);
                if (bcmerror)
 -                      dhd->pub.bcmerror = bcmerror;
 +                      drvr_priv->pub.bcmerror = bcmerror;
                goto done;
        }
  
        /* send to dongle (must be up, and wl) */
 -      if ((dhd->pub.busstate != DHD_BUS_DATA)) {
 -              DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
 +      if ((drvr_priv->pub.busstate != BRCMF_BUS_DATA)) {
 +              BRCMF_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
                bcmerror = -EIO;
                goto done;
        }
  
 -      if (!dhd->pub.iswl) {
 +      if (!drvr_priv->pub.iswl) {
                bcmerror = -EIO;
                goto done;
        }
  
 -      /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
 -       * prevent M4 encryption.
 +      /*
 +       * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
 +       * set key IOCTL to prevent M4 encryption.
         */
 -      is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
 -                        ((ioc.cmd == WLC_SET_VAR) &&
 +      is_set_key_cmd = ((ioc.cmd == BRCMF_C_SET_KEY) ||
 +                        ((ioc.cmd == BRCMF_C_SET_VAR) &&
                           !(strncmp("wsec_key", ioc.buf, 9))) ||
 -                        ((ioc.cmd == WLC_SET_VAR) &&
 +                        ((ioc.cmd == BRCMF_C_SET_VAR) &&
                           !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
        if (is_set_key_cmd)
 -              dhd_wait_pend8021x(net);
 +              brcmf_netdev_wait_pend8021x(net);
  
        bcmerror =
 -          dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
 +          brcmf_proto_ioctl(&drvr_priv->pub, ifidx, (struct brcmf_ioctl *)&ioc,
 +                            buf, buflen);
  
  done:
        if (!bcmerror && buf && ioc.buf) {
        return bcmerror;
  }
  
 -static int dhd_stop(struct net_device *net)
 +static int brcmf_netdev_stop(struct net_device *net)
  {
  #if !defined(IGNORE_ETH0_DOWN)
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 -      if (IS_CFG80211_FAVORITE()) {
 -              wl_cfg80211_down();
 -      }
 -      if (dhd->pub.up == 0)
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
 +      brcmf_cfg80211_down();
 +      if (drvr_priv->pub.up == 0)
                return 0;
  
        /* Set state and stop OS transmissions */
 -      dhd->pub.up = 0;
 +      drvr_priv->pub.up = 0;
        netif_stop_queue(net);
  #else
 -      DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
 -              __func__));
 +      BRCMF_ERROR(("BYPASS %s:due to BRCM compilation: under investigation\n",
 +                   __func__));
  #endif                                /* !defined(IGNORE_ETH0_DOWN) */
  
        return 0;
  }
  
 -static int dhd_open(struct net_device *net)
 +static int brcmf_netdev_open(struct net_device *net)
  {
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 -#ifdef TOE
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
        u32 toe_ol;
 -#endif
 -      int ifidx = dhd_net2idx(dhd, net);
 +      int ifidx = brcmf_net2idx(drvr_priv, net);
        s32 ret = 0;
  
 -      DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
 +      BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
  
        if (ifidx == 0) {       /* do it only for primary eth0 */
  
                /* try to bring up bus */
 -              ret = dhd_bus_start(&dhd->pub);
 +              ret = brcmf_bus_start(&drvr_priv->pub);
                if (ret != 0) {
 -                      DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
 +                      BRCMF_ERROR(("%s: failed with code %d\n",
 +                                   __func__, ret));
                        return -1;
                }
 -              atomic_set(&dhd->pend_8021x_cnt, 0);
 +              atomic_set(&drvr_priv->pend_8021x_cnt, 0);
  
 -              memcpy(net->dev_addr, dhd->pub.mac, ETH_ALEN);
 +              memcpy(net->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
  
 -#ifdef TOE
                /* Get current TOE mode from dongle */
 -              if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
 +              if (brcmf_toe_get(drvr_priv, ifidx, &toe_ol) >= 0
                    && (toe_ol & TOE_TX_CSUM_OL) != 0)
 -                      dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
 +                      drvr_priv->iflist[ifidx]->net->features |=
 +                              NETIF_F_IP_CSUM;
                else
 -                      dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
 -#endif
 +                      drvr_priv->iflist[ifidx]->net->features &=
 +                              ~NETIF_F_IP_CSUM;
        }
        /* Allow transmit calls */
        netif_start_queue(net);
 -      dhd->pub.up = 1;
 -      if (IS_CFG80211_FAVORITE()) {
 -              if (unlikely(wl_cfg80211_up())) {
 -                      DHD_ERROR(("%s: failed to bring up cfg80211\n",
 -                                 __func__));
 -                      return -1;
 -              }
 +      drvr_priv->pub.up = 1;
 +      if (unlikely(brcmf_cfg80211_up())) {
 +              BRCMF_ERROR(("%s: failed to bring up cfg80211\n",
 +                           __func__));
 +              return -1;
        }
  
        return ret;
  }
  
  int
 -dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
 +brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, void *handle, char *name,
           u8 *mac_addr, u32 flags, u8 bssidx)
  {
 -      dhd_if_t *ifp;
 -
 -      DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
 +      struct brcmf_if *ifp;
  
 -      ASSERT(dhd && (ifidx < DHD_MAX_IFS));
 +      BRCMF_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
  
 -      ifp = dhd->iflist[ifidx];
 -      if (!ifp && !(ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC))) {
 -              DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
 -              return -ENOMEM;
 +      ifp = drvr_priv->iflist[ifidx];
 +      if (!ifp) {
 +              ifp = kmalloc(sizeof(struct brcmf_if), GFP_ATOMIC);
 +              if (!ifp) {
 +                      BRCMF_ERROR(("%s: OOM - struct brcmf_if\n", __func__));
 +                      return -ENOMEM;
 +              }
        }
  
 -      memset(ifp, 0, sizeof(dhd_if_t));
 -      ifp->info = dhd;
 -      dhd->iflist[ifidx] = ifp;
 +      memset(ifp, 0, sizeof(struct brcmf_if));
 +      ifp->info = drvr_priv;
 +      drvr_priv->iflist[ifidx] = ifp;
        strlcpy(ifp->name, name, IFNAMSIZ);
        if (mac_addr != NULL)
                memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
  
        if (handle == NULL) {
 -              ifp->state = WLC_E_IF_ADD;
 +              ifp->state = BRCMF_E_IF_ADD;
                ifp->idx = ifidx;
 -              ASSERT(dhd->sysioc_tsk);
 -              up(&dhd->sysioc_sem);
 +              up(&drvr_priv->sysioc_sem);
        } else
                ifp->net = (struct net_device *)handle;
  
        return 0;
  }
  
 -void dhd_del_if(dhd_info_t *dhd, int ifidx)
 +void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx)
  {
 -      dhd_if_t *ifp;
 +      struct brcmf_if *ifp;
  
 -      DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
 +      BRCMF_TRACE(("%s: idx %d\n", __func__, ifidx));
  
 -      ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
 -      ifp = dhd->iflist[ifidx];
 +      ifp = drvr_priv->iflist[ifidx];
        if (!ifp) {
 -              DHD_ERROR(("%s: Null interface\n", __func__));
 +              BRCMF_ERROR(("%s: Null interface\n", __func__));
                return;
        }
  
 -      ifp->state = WLC_E_IF_DEL;
 +      ifp->state = BRCMF_E_IF_DEL;
        ifp->idx = ifidx;
 -      ASSERT(dhd->sysioc_tsk);
 -      up(&dhd->sysioc_sem);
 +      up(&drvr_priv->sysioc_sem);
  }
  
 -dhd_pub_t *dhd_attach(struct dhd_bus *bus, uint bus_hdrlen)
 +struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
  {
 -      dhd_info_t *dhd = NULL;
 +      struct brcmf_info *drvr_priv = NULL;
        struct net_device *net;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 -      /* updates firmware nvram path if it was provided as module
 -               paramters */
 -      if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
 -              strcpy(fw_path, firmware_path);
 -      if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
 -              strcpy(nv_path, nvram_path);
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* Allocate etherdev, including space for private structure */
 -      net = alloc_etherdev(sizeof(dhd));
 +      net = alloc_etherdev(sizeof(drvr_priv));
        if (!net) {
 -              DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
 +              BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
                goto fail;
        }
  
 -      /* Allocate primary dhd_info */
 -      dhd = kzalloc(sizeof(dhd_info_t), GFP_ATOMIC);
 -      if (!dhd) {
 -              DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
 +      /* Allocate primary brcmf_info */
 +      drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC);
 +      if (!drvr_priv) {
 +              BRCMF_ERROR(("%s: OOM - alloc brcmf_info\n", __func__));
                goto fail;
        }
  
        /*
 -       * Save the dhd_info into the priv
 +       * Save the brcmf_info into the priv
         */
 -      memcpy(netdev_priv(net), &dhd, sizeof(dhd));
 +      memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
  
        /* Set network interface name if it was provided as module parameter */
        if (iface_name[0]) {
                        strcat(net->name, "%d");
        }
  
 -      if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
 -          DHD_BAD_IF)
 +      if (brcmf_add_if(drvr_priv, 0, (void *)net, net->name, NULL, 0, 0) ==
 +          BRCMF_BAD_IF)
                goto fail;
  
        net->netdev_ops = NULL;
 -      sema_init(&dhd->proto_sem, 1);
 +      sema_init(&drvr_priv->proto_sem, 1);
        /* Initialize other structure content */
 -      init_waitqueue_head(&dhd->ioctl_resp_wait);
 -      init_waitqueue_head(&dhd->ctrl_wait);
 -
 -      /* Initialize the spinlocks */
 -      spin_lock_init(&dhd->sdlock);
 -      spin_lock_init(&dhd->txqlock);
 +      init_waitqueue_head(&drvr_priv->ioctl_resp_wait);
  
        /* Link to info module */
 -      dhd->pub.info = dhd;
 +      drvr_priv->pub.info = drvr_priv;
  
        /* Link to bus module */
 -      dhd->pub.bus = bus;
 -      dhd->pub.hdrlen = bus_hdrlen;
 +      drvr_priv->pub.bus = bus;
 +      drvr_priv->pub.hdrlen = bus_hdrlen;
  
        /* Attach and link in the protocol */
 -      if (dhd_prot_attach(&dhd->pub) != 0) {
 -              DHD_ERROR(("dhd_prot_attach failed\n"));
 +      if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
 +              BRCMF_ERROR(("brcmf_prot_attach failed\n"));
                goto fail;
        }
 -#if defined(CONFIG_WIRELESS_EXT)
 -      /* Attach and link in the iw */
 -      if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
 -              DHD_ERROR(("wl_iw_attach failed\n"));
 -              goto fail;
 -      }
 -#endif        /* defined(CONFIG_WIRELESS_EXT) */
  
        /* Attach and link in the cfg80211 */
 -      if (IS_CFG80211_FAVORITE()) {
 -              if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
 -                      DHD_ERROR(("wl_cfg80211_attach failed\n"));
 -                      goto fail;
 -              }
 -              if (!NO_FW_REQ()) {
 -                      strcpy(fw_path, wl_cfg80211_get_fwname());
 -                      strcpy(nv_path, wl_cfg80211_get_nvramname());
 -              }
 -      }
 -
 -      /* Set up the watchdog timer */
 -      init_timer(&dhd->timer);
 -      dhd->timer.data = (unsigned long) dhd;
 -      dhd->timer.function = dhd_watchdog;
 -
 -      /* Initialize thread based operation and lock */
 -      sema_init(&dhd->sdsem, 1);
 -      if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
 -              dhd->threads_only = true;
 -      else
 -              dhd->threads_only = false;
 -
 -      if (dhd_dpc_prio >= 0) {
 -              /* Initialize watchdog thread */
 -              sema_init(&dhd->watchdog_sem, 0);
 -              dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
 -                                              "dhd_watchdog");
 -              if (IS_ERR(dhd->watchdog_tsk)) {
 -                      printk(KERN_WARNING
 -                              "dhd_watchdog thread failed to start\n");
 -                      dhd->watchdog_tsk = NULL;
 -              }
 -      } else {
 -              dhd->watchdog_tsk = NULL;
 -      }
 -
 -      /* Set up the bottom half handler */
 -      if (dhd_dpc_prio >= 0) {
 -              /* Initialize DPC thread */
 -              sema_init(&dhd->dpc_sem, 0);
 -              dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
 -              if (IS_ERR(dhd->dpc_tsk)) {
 -                      printk(KERN_WARNING
 -                              "dhd_dpc thread failed to start\n");
 -                      dhd->dpc_tsk = NULL;
 -              }
 -      } else {
 -              tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
 -              dhd->dpc_tsk = NULL;
 +      if (unlikely(brcmf_cfg80211_attach(net, &drvr_priv->pub))) {
 +              BRCMF_ERROR(("wl_cfg80211_attach failed\n"));
 +              goto fail;
        }
  
 -      if (dhd_sysioc) {
 -              sema_init(&dhd->sysioc_sem, 0);
 -              dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
 -                                              "_dhd_sysioc");
 -              if (IS_ERR(dhd->sysioc_tsk)) {
 +      if (brcmf_sysioc) {
 +              sema_init(&drvr_priv->sysioc_sem, 0);
 +              drvr_priv->sysioc_tsk = kthread_run(_brcmf_sysioc_thread, drvr_priv,
 +                                              "_brcmf_sysioc");
 +              if (IS_ERR(drvr_priv->sysioc_tsk)) {
                        printk(KERN_WARNING
 -                              "_dhd_sysioc thread failed to start\n");
 -                      dhd->sysioc_tsk = NULL;
 +                              "_brcmf_sysioc thread failed to start\n");
 +                      drvr_priv->sysioc_tsk = NULL;
                }
        } else
 -              dhd->sysioc_tsk = NULL;
 +              drvr_priv->sysioc_tsk = NULL;
  
        /*
 -       * Save the dhd_info into the priv
 +       * Save the brcmf_info into the priv
         */
 -      memcpy(netdev_priv(net), &dhd, sizeof(dhd));
 +      memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
  
 -#if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
 -      g_bus = bus;
 -#endif
  #if defined(CONFIG_PM_SLEEP)
 -      atomic_set(&dhd_mmc_suspend, false);
 -      if (!IS_CFG80211_FAVORITE())
 -              register_pm_notifier(&dhd_sleep_pm_notifier);
 +      atomic_set(&brcmf_mmc_suspend, false);
  #endif        /* defined(CONFIG_PM_SLEEP) */
 -      /* && defined(DHD_GPL) */
 -      /* Init lock suspend to prevent kernel going to suspend */
 -#ifdef CONFIG_HAS_EARLYSUSPEND
 -      dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
 -      dhd->early_suspend.suspend = dhd_early_suspend;
 -      dhd->early_suspend.resume = dhd_late_resume;
 -      register_early_suspend(&dhd->early_suspend);
 -#endif
 -
 -      return &dhd->pub;
 +      return &drvr_priv->pub;
  
  fail:
        if (net)
                free_netdev(net);
 -      if (dhd)
 -              dhd_detach(&dhd->pub);
 +      if (drvr_priv)
 +              brcmf_detach(&drvr_priv->pub);
  
        return NULL;
  }
  
 -int dhd_bus_start(dhd_pub_t *dhdp)
 +int brcmf_bus_start(struct brcmf_pub *drvr)
  {
        int ret = -1;
 -      dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
 -#ifdef EMBEDDED_PLATFORM
 -      char iovbuf[WL_EVENTING_MASK_LEN + 12]; /*  Room for "event_msgs" +
 -                                               '\0' + bitvec  */
 -#endif                                /* EMBEDDED_PLATFORM */
 -
 -      ASSERT(dhd);
 -
 -      DHD_TRACE(("%s:\n", __func__));
 -
 -      /* try to download image and nvram to the dongle */
 -      if (dhd->pub.busstate == DHD_BUS_DOWN) {
 -              if (!(dhd_bus_download_firmware(dhd->pub.bus,
 -                                              fw_path, nv_path))) {
 -                      DHD_ERROR(("%s: dhdsdio_probe_download failed. "
 -                              "firmware = %s nvram = %s\n",
 -                              __func__, fw_path, nv_path));
 -                      return -1;
 -              }
 -      }
 +      struct brcmf_info *drvr_priv = drvr->info;
 +      /* Room for "event_msgs" + '\0' + bitvec */
 +      char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
  
 -      /* Start the watchdog timer */
 -      dhd->pub.tickcnt = 0;
 -      dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
 +      BRCMF_TRACE(("%s:\n", __func__));
  
        /* Bring up the bus */
 -      ret = dhd_bus_init(&dhd->pub, true);
 +      ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub, true);
        if (ret != 0) {
 -              DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
 +              BRCMF_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__,
 +                           ret));
                return ret;
        }
 -#if defined(OOB_INTR_ONLY)
 -      /* Host registration for OOB interrupt */
 -      if (bcmsdh_register_oob_intr(dhdp)) {
 -              del_timer_sync(&dhd->timer);
 -              dhd->wd_timer_valid = false;
 -              DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
 -              return -ENODEV;
 -      }
 -
 -      /* Enable oob at firmware */
 -      dhd_enable_oob_intr(dhd->pub.bus, true);
 -#endif                                /* defined(OOB_INTR_ONLY) */
  
        /* If bus is not ready, can't come up */
 -      if (dhd->pub.busstate != DHD_BUS_DATA) {
 -              del_timer_sync(&dhd->timer);
 -              dhd->wd_timer_valid = false;
 -              DHD_ERROR(("%s failed bus is not ready\n", __func__));
 +      if (drvr_priv->pub.busstate != BRCMF_BUS_DATA) {
 +              BRCMF_ERROR(("%s failed bus is not ready\n", __func__));
                return -ENODEV;
        }
 -#ifdef EMBEDDED_PLATFORM
 -      bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
 -                  sizeof(iovbuf));
 -      dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
 -      memcpy(dhdp->eventmask, iovbuf, WL_EVENTING_MASK_LEN);
 -
 -      setbit(dhdp->eventmask, WLC_E_SET_SSID);
 -      setbit(dhdp->eventmask, WLC_E_PRUNE);
 -      setbit(dhdp->eventmask, WLC_E_AUTH);
 -      setbit(dhdp->eventmask, WLC_E_REASSOC);
 -      setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
 -      setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
 -      setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
 -      setbit(dhdp->eventmask, WLC_E_DISASSOC);
 -      setbit(dhdp->eventmask, WLC_E_JOIN);
 -      setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
 -      setbit(dhdp->eventmask, WLC_E_PSK_SUP);
 -      setbit(dhdp->eventmask, WLC_E_LINK);
 -      setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
 -      setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
 -      setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
 -      setbit(dhdp->eventmask, WLC_E_TXFAIL);
 -      setbit(dhdp->eventmask, WLC_E_JOIN_START);
 -      setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
 -#ifdef PNO_SUPPORT
 -      setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
 -#endif                                /* PNO_SUPPORT */
 +
 +      brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
 +                    iovbuf, sizeof(iovbuf));
 +      brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
 +                                  sizeof(iovbuf));
 +      memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
 +
 +      setbit(drvr->eventmask, BRCMF_E_SET_SSID);
 +      setbit(drvr->eventmask, BRCMF_E_PRUNE);
 +      setbit(drvr->eventmask, BRCMF_E_AUTH);
 +      setbit(drvr->eventmask, BRCMF_E_REASSOC);
 +      setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
 +      setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
 +      setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
 +      setbit(drvr->eventmask, BRCMF_E_DISASSOC);
 +      setbit(drvr->eventmask, BRCMF_E_JOIN);
 +      setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
 +      setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
 +      setbit(drvr->eventmask, BRCMF_E_LINK);
 +      setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
 +      setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
 +      setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
 +      setbit(drvr->eventmask, BRCMF_E_TXFAIL);
 +      setbit(drvr->eventmask, BRCMF_E_JOIN_START);
 +      setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
  
  /* enable dongle roaming event */
  
 -      dhdp->pktfilter_count = 1;
 +      drvr->pktfilter_count = 1;
        /* Setup filter to allow only unicast */
 -      dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
 -#endif                                /* EMBEDDED_PLATFORM */
 +      drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
  
        /* Bus is ready, do any protocol initialization */
 -      ret = dhd_prot_init(&dhd->pub);
 +      ret = brcmf_proto_init(&drvr_priv->pub);
        if (ret < 0)
                return ret;
  
        return 0;
  }
  
 -int
 -dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
 -        int set)
 -{
 -      char buf[strlen(name) + 1 + cmd_len];
 -      int len = sizeof(buf);
 -      wl_ioctl_t ioc;
 -      int ret;
 -
 -      len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
 -
 -      memset(&ioc, 0, sizeof(ioc));
 -
 -      ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
 -      ioc.buf = buf;
 -      ioc.len = len;
 -      ioc.set = set;
 -
 -      ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
 -      if (!set && ret >= 0)
 -              memcpy(cmd_buf, buf, cmd_len);
 -
 -      return ret;
 -}
 -
 -static struct net_device_ops dhd_ops_pri = {
 -      .ndo_open = dhd_open,
 -      .ndo_stop = dhd_stop,
 -      .ndo_get_stats = dhd_get_stats,
 -      .ndo_do_ioctl = dhd_ioctl_entry,
 -      .ndo_start_xmit = dhd_start_xmit,
 -      .ndo_set_mac_address = dhd_set_mac_address,
 -      .ndo_set_multicast_list = dhd_set_multicast_list
 +static struct net_device_ops brcmf_netdev_ops_pri = {
 +      .ndo_open = brcmf_netdev_open,
 +      .ndo_stop = brcmf_netdev_stop,
 +      .ndo_get_stats = brcmf_netdev_get_stats,
 +      .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
 +      .ndo_start_xmit = brcmf_netdev_start_xmit,
 +      .ndo_set_mac_address = brcmf_netdev_set_mac_address,
 +      .ndo_set_multicast_list = brcmf_netdev_set_multicast_list
  };
  
 -int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
 +int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
 +      struct brcmf_info *drvr_priv = drvr->info;
        struct net_device *net;
        u8 temp_addr[ETH_ALEN] = {
                0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
  
 -      DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
 -
 -      ASSERT(dhd && dhd->iflist[ifidx]);
 -
 -      net = dhd->iflist[ifidx]->net;
 -      ASSERT(net);
 +      BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
  
 -      ASSERT(!net->netdev_ops);
 -      net->netdev_ops = &dhd_ops_pri;
 +      net = drvr_priv->iflist[ifidx]->net;
 +      net->netdev_ops = &brcmf_netdev_ops_pri;
  
        /*
         * We have to use the primary MAC for virtual interfaces
         */
        if (ifidx != 0) {
                /* for virtual interfaces use the primary MAC  */
 -              memcpy(temp_addr, dhd->pub.mac, ETH_ALEN);
 +              memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
  
        }
  
        if (ifidx == 1) {
 -              DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
 +              BRCMF_TRACE(("%s ACCESS POINT MAC:\n", __func__));
                /*  ACCESSPOINT INTERFACE CASE */
                temp_addr[0] |= 0X02;   /* set bit 2 ,
                         - Locally Administered address  */
  
        }
 -      net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
 -      net->ethtool_ops = &dhd_ethtool_ops;
 +      net->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
 +      net->ethtool_ops = &brcmf_ethtool_ops;
  
 -      dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
 +      drvr_priv->pub.rxsz = net->mtu + net->hard_header_len +
 +                              drvr_priv->pub.hdrlen;
  
        memcpy(net->dev_addr, temp_addr, ETH_ALEN);
  
        if (register_netdev(net) != 0) {
 -              DHD_ERROR(("%s: couldn't register the net device\n",
 -                      __func__));
 +              BRCMF_ERROR(("%s: couldn't register the net device\n",
 +                           __func__));
                goto fail;
        }
  
 -      DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
 +      BRCMF_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
  
        return 0;
  
        return -EBADE;
  }
  
 -void dhd_bus_detach(dhd_pub_t *dhdp)
 +static void brcmf_bus_detach(struct brcmf_pub *drvr)
  {
 -      dhd_info_t *dhd;
 +      struct brcmf_info *drvr_priv;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -      if (dhdp) {
 -              dhd = (dhd_info_t *) dhdp->info;
 -              if (dhd) {
 +      if (drvr) {
 +              drvr_priv = drvr->info;
 +              if (drvr_priv) {
                        /* Stop the protocol module */
 -                      dhd_prot_stop(&dhd->pub);
 +                      brcmf_proto_stop(&drvr_priv->pub);
  
                        /* Stop the bus module */
 -                      dhd_bus_stop(dhd->pub.bus, true);
 -#if defined(OOB_INTR_ONLY)
 -                      bcmsdh_unregister_oob_intr();
 -#endif                                /* defined(OOB_INTR_ONLY) */
 -
 -                      /* Clear the watchdog timer */
 -                      del_timer_sync(&dhd->timer);
 -                      dhd->wd_timer_valid = false;
 +                      brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus, true);
                }
        }
  }
  
 -void dhd_detach(dhd_pub_t *dhdp)
 +void brcmf_detach(struct brcmf_pub *drvr)
  {
 -      dhd_info_t *dhd;
 +      struct brcmf_info *drvr_priv;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -      if (dhdp) {
 -              dhd = (dhd_info_t *) dhdp->info;
 -              if (dhd) {
 -                      dhd_if_t *ifp;
 +      if (drvr) {
 +              drvr_priv = drvr->info;
 +              if (drvr_priv) {
 +                      struct brcmf_if *ifp;
                        int i;
  
 -#if defined(CONFIG_HAS_EARLYSUSPEND)
 -                      if (dhd->early_suspend.suspend)
 -                              unregister_early_suspend(&dhd->early_suspend);
 -#endif                                /* defined(CONFIG_HAS_EARLYSUSPEND) */
 +                      for (i = 1; i < BRCMF_MAX_IFS; i++)
 +                              if (drvr_priv->iflist[i])
 +                                      brcmf_del_if(drvr_priv, i);
  
 -                      for (i = 1; i < DHD_MAX_IFS; i++)
 -                              if (dhd->iflist[i])
 -                                      dhd_del_if(dhd, i);
 -
 -                      ifp = dhd->iflist[0];
 -                      ASSERT(ifp);
 -                      if (ifp->net->netdev_ops == &dhd_ops_pri) {
 -                              dhd_stop(ifp->net);
 +                      ifp = drvr_priv->iflist[0];
 +                      if (ifp->net->netdev_ops == &brcmf_netdev_ops_pri) {
 +                              brcmf_netdev_stop(ifp->net);
                                unregister_netdev(ifp->net);
                        }
  
 -                      if (dhd->watchdog_tsk) {
 -                              send_sig(SIGTERM, dhd->watchdog_tsk, 1);
 -                              kthread_stop(dhd->watchdog_tsk);
 -                              dhd->watchdog_tsk = NULL;
 -                      }
 -
 -                      if (dhd->dpc_tsk) {
 -                              send_sig(SIGTERM, dhd->dpc_tsk, 1);
 -                              kthread_stop(dhd->dpc_tsk);
 -                              dhd->dpc_tsk = NULL;
 -                      } else
 -                              tasklet_kill(&dhd->tasklet);
 -
 -                      if (dhd->sysioc_tsk) {
 -                              send_sig(SIGTERM, dhd->sysioc_tsk, 1);
 -                              kthread_stop(dhd->sysioc_tsk);
 -                              dhd->sysioc_tsk = NULL;
 +                      if (drvr_priv->sysioc_tsk) {
 +                              send_sig(SIGTERM, drvr_priv->sysioc_tsk, 1);
 +                              kthread_stop(drvr_priv->sysioc_tsk);
 +                              drvr_priv->sysioc_tsk = NULL;
                        }
  
 -                      dhd_bus_detach(dhdp);
 +                      brcmf_bus_detach(drvr);
  
 -                      if (dhdp->prot)
 -                              dhd_prot_detach(dhdp);
 +                      if (drvr->prot)
 +                              brcmf_proto_detach(drvr);
  
 -#if defined(CONFIG_WIRELESS_EXT)
 -                      wl_iw_detach();
 -#endif                                /* (CONFIG_WIRELESS_EXT) */
 +                      brcmf_cfg80211_detach();
  
 -                      if (IS_CFG80211_FAVORITE())
 -                              wl_cfg80211_detach();
 -
 -#if defined(CONFIG_PM_SLEEP)
 -                      if (!IS_CFG80211_FAVORITE())
 -                              unregister_pm_notifier(&dhd_sleep_pm_notifier);
 -#endif        /* defined(CONFIG_PM_SLEEP) */
 -                      /* && defined(DHD_GPL) */
                        free_netdev(ifp->net);
                        kfree(ifp);
 -                      kfree(dhd);
 +                      kfree(drvr_priv);
                }
        }
  }
  
 -static void __exit dhd_module_cleanup(void)
 +static void __exit brcmf_module_cleanup(void)
  {
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -      dhd_bus_unregister();
 -#if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
 -      wifi_del_dev();
 -#endif
 -      /* Call customer gpio to turn off power with WL_REG_ON signal */
 -      dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
 +      brcmf_bus_unregister();
  }
  
 -static int __init dhd_module_init(void)
 +static int __init brcmf_module_init(void)
  {
        int error;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 -
 -      /* Sanity check on the module parameters */
 -      do {
 -              /* Both watchdog and DPC as tasklets are ok */
 -              if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
 -                      break;
 -
 -              /* If both watchdog and DPC are threads, TX must be deferred */
 -              if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
 -                  && dhd_deferred_tx)
 -                      break;
 -
 -              DHD_ERROR(("Invalid module parameters.\n"));
 -              return -EINVAL;
 -      } while (0);
 -      /* Call customer gpio to turn on power with WL_REG_ON signal */
 -      dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -#if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
 -      sema_init(&wifi_control_sem, 0);
 +      error = brcmf_bus_register();
  
 -      error = wifi_add_dev();
        if (error) {
 -              DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
 -              goto failed;
 -      }
 -
 -      /* Waiting callback after platform_driver_register is done or
 -               exit with error */
 -      if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
 -              printk(KERN_ERR "%s: platform_driver_register timeout\n",
 -                      __func__);
 -              /* remove device */
 -              wifi_del_dev();
 +              BRCMF_ERROR(("%s: brcmf_bus_register failed\n", __func__));
                goto failed;
        }
 -#endif        /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
 -
 -      error = dhd_bus_register();
 -
 -      if (error) {
 -              DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
 -              goto failed;
 -      }
 -      return error;
 +      return 0;
  
  failed:
 -      /* turn off power and exit */
 -      dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
        return -EINVAL;
  }
  
 -module_init(dhd_module_init);
 -module_exit(dhd_module_cleanup);
 +module_init(brcmf_module_init);
 +module_exit(brcmf_module_cleanup);
  
 -/*
 - * OS specific functions required to implement DHD driver in OS independent way
 - */
 -int dhd_os_proto_block(dhd_pub_t *pub)
 +int brcmf_os_proto_block(struct brcmf_pub *drvr)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) (pub->info);
 +      struct brcmf_info *drvr_priv = drvr->info;
  
 -      if (dhd) {
 -              down(&dhd->proto_sem);
 +      if (drvr_priv) {
 +              down(&drvr_priv->proto_sem);
                return 1;
        }
        return 0;
  }
  
 -int dhd_os_proto_unblock(dhd_pub_t *pub)
 +int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) (pub->info);
 +      struct brcmf_info *drvr_priv = drvr->info;
  
 -      if (dhd) {
 -              up(&dhd->proto_sem);
 +      if (drvr_priv) {
 +              up(&drvr_priv->proto_sem);
                return 1;
        }
  
        return 0;
  }
  
 -unsigned int dhd_os_get_ioctl_resp_timeout(void)
 +unsigned int brcmf_os_get_ioctl_resp_timeout(void)
  {
 -      return (unsigned int)dhd_ioctl_timeout_msec;
 +      return (unsigned int)brcmf_ioctl_timeout_msec;
  }
  
 -void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
 +void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
  {
 -      dhd_ioctl_timeout_msec = (int)timeout_msec;
 +      brcmf_ioctl_timeout_msec = (int)timeout_msec;
  }
  
 -int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
 +int brcmf_os_ioctl_resp_wait(struct brcmf_pub *drvr, uint *condition,
 +                           bool *pending)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) (pub->info);
 +      struct brcmf_info *drvr_priv = drvr->info;
        DECLARE_WAITQUEUE(wait, current);
 -      int timeout = dhd_ioctl_timeout_msec;
 +      int timeout = brcmf_ioctl_timeout_msec;
  
        /* Convert timeout in millsecond to jiffies */
        timeout = timeout * HZ / 1000;
  
        /* Wait until control frame is available */
 -      add_wait_queue(&dhd->ioctl_resp_wait, &wait);
 +      add_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
        set_current_state(TASK_INTERRUPTIBLE);
  
        while (!(*condition) && (!signal_pending(current) && timeout))
                *pending = true;
  
        set_current_state(TASK_RUNNING);
 -      remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
 +      remove_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
  
        return timeout;
  }
  
 -int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
 +int brcmf_os_ioctl_resp_wake(struct brcmf_pub *drvr)
  {
 -      dhd_info_t *dhd = (dhd_info_t *) (pub->info);
 +      struct brcmf_info *drvr_priv = drvr->info;
  
 -      if (waitqueue_active(&dhd->ioctl_resp_wait))
 -              wake_up_interruptible(&dhd->ioctl_resp_wait);
 +      if (waitqueue_active(&drvr_priv->ioctl_resp_wait))
 +              wake_up_interruptible(&drvr_priv->ioctl_resp_wait);
  
        return 0;
  }
  
 -void dhd_os_wd_timer(void *bus, uint wdtick)
 -{
 -      dhd_pub_t *pub = bus;
 -      static uint save_dhd_watchdog_ms;
 -      dhd_info_t *dhd = (dhd_info_t *) pub->info;
 -
 -      /* don't start the wd until fw is loaded */
 -      if (pub->busstate == DHD_BUS_DOWN)
 -              return;
 -
 -      /* Totally stop the timer */
 -      if (!wdtick && dhd->wd_timer_valid == true) {
 -              del_timer_sync(&dhd->timer);
 -              dhd->wd_timer_valid = false;
 -              save_dhd_watchdog_ms = wdtick;
 -              return;
 -      }
 -
 -      if (wdtick) {
 -              dhd_watchdog_ms = (uint) wdtick;
 -
 -              if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
 -
 -                      if (dhd->wd_timer_valid == true)
 -                              /* Stop timer and restart at new value */
 -                              del_timer_sync(&dhd->timer);
 -
 -                      /* Create timer again when watchdog period is
 -                         dynamically changed or in the first instance
 -                       */
 -                      dhd->timer.expires =
 -                          jiffies + dhd_watchdog_ms * HZ / 1000;
 -                      add_timer(&dhd->timer);
 -
 -              } else {
 -                      /* Re arm the timer, at last watchdog period */
 -                      mod_timer(&dhd->timer,
 -                                jiffies + dhd_watchdog_ms * HZ / 1000);
 -              }
 -
 -              dhd->wd_timer_valid = true;
 -              save_dhd_watchdog_ms = wdtick;
 -      }
 -}
 -
 -void *dhd_os_open_image(char *filename)
 -{
 -      struct file *fp;
 -
 -      if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
 -              return wl_cfg80211_request_fw(filename);
 -
 -      fp = filp_open(filename, O_RDONLY, 0);
 -      /*
 -       * 2.6.11 (FC4) supports filp_open() but later revs don't?
 -       * Alternative:
 -       * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
 -       * ???
 -       */
 -      if (IS_ERR(fp))
 -              fp = NULL;
 -
 -      return fp;
 -}
 -
 -int dhd_os_get_image_block(char *buf, int len, void *image)
 -{
 -      struct file *fp = (struct file *)image;
 -      int rdlen;
 -
 -      if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
 -              return wl_cfg80211_read_fw(buf, len);
 -
 -      if (!image)
 -              return 0;
 -
 -      rdlen = kernel_read(fp, fp->f_pos, buf, len);
 -      if (rdlen > 0)
 -              fp->f_pos += rdlen;
 -
 -      return rdlen;
 -}
 -
 -void dhd_os_close_image(void *image)
 -{
 -      if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
 -              return wl_cfg80211_release_fw();
 -      if (image)
 -              filp_close((struct file *)image, NULL);
 -}
 -
 -void dhd_os_sdlock(dhd_pub_t *pub)
 -{
 -      dhd_info_t *dhd;
 -
 -      dhd = (dhd_info_t *) (pub->info);
 -
 -      if (dhd->threads_only)
 -              down(&dhd->sdsem);
 -      else
 -              spin_lock_bh(&dhd->sdlock);
 -}
 -
 -void dhd_os_sdunlock(dhd_pub_t *pub)
 -{
 -      dhd_info_t *dhd;
 -
 -      dhd = (dhd_info_t *) (pub->info);
 -
 -      if (dhd->threads_only)
 -              up(&dhd->sdsem);
 -      else
 -              spin_unlock_bh(&dhd->sdlock);
 -}
 -
 -void dhd_os_sdlock_txq(dhd_pub_t *pub)
 -{
 -      dhd_info_t *dhd;
 -
 -      dhd = (dhd_info_t *) (pub->info);
 -      spin_lock_bh(&dhd->txqlock);
 -}
 -
 -void dhd_os_sdunlock_txq(dhd_pub_t *pub)
 -{
 -      dhd_info_t *dhd;
 -
 -      dhd = (dhd_info_t *) (pub->info);
 -      spin_unlock_bh(&dhd->txqlock);
 -}
 -
 -void dhd_os_sdlock_rxq(dhd_pub_t *pub)
 -{
 -}
 -
 -void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
 -{
 -}
 -
 -void dhd_os_sdtxlock(dhd_pub_t *pub)
 -{
 -      dhd_os_sdlock(pub);
 -}
 -
 -void dhd_os_sdtxunlock(dhd_pub_t *pub)
 -{
 -      dhd_os_sdunlock(pub);
 -}
 -
 -static int
 -dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
 -                wl_event_msg_t *event, void **data)
 +static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
 +                          struct brcmf_event_msg *event, void **data)
  {
        int bcmerror = 0;
  
 -      ASSERT(dhd != NULL);
 -
 -      bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
 +      bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
        if (bcmerror != 0)
                return bcmerror;
  
 -#if defined(CONFIG_WIRELESS_EXT)
 -      if (!IS_CFG80211_FAVORITE()) {
 -              if ((dhd->iflist[*ifidx] == NULL)
 -                  || (dhd->iflist[*ifidx]->net == NULL)) {
 -                      DHD_ERROR(("%s Exit null pointer\n", __func__));
 -                      return bcmerror;
 -              }
 -
 -              if (dhd->iflist[*ifidx]->net)
 -                      wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
 -      }
 -#endif                                /* defined(CONFIG_WIRELESS_EXT)  */
 -
 -      if (IS_CFG80211_FAVORITE()) {
 -              ASSERT(dhd->iflist[*ifidx] != NULL);
 -              ASSERT(dhd->iflist[*ifidx]->net != NULL);
 -              if (dhd->iflist[*ifidx]->net)
 -                      wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
 -                                        *data);
 -      }
 +      if (drvr_priv->iflist[*ifidx]->net)
 +              brcmf_cfg80211_event(drvr_priv->iflist[*ifidx]->net,
 +                                   event, *data);
  
        return bcmerror;
  }
  
 -/* send up locally generated event */
 -void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
 +int brcmf_netdev_reset(struct net_device *dev, u8 flag)
  {
 -      switch (be32_to_cpu(event->event_type)) {
 -      default:
 -              break;
 -      }
 -}
 -
 -void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
 -{
 -      struct dhd_info *dhdinfo = dhd->info;
 -      dhd_os_sdunlock(dhd);
 -      wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
 -                                       (*lockvar == false), HZ * 2);
 -      dhd_os_sdlock(dhd);
 -      return;
 -}
 -
 -void dhd_wait_event_wakeup(dhd_pub_t *dhd)
 -{
 -      struct dhd_info *dhdinfo = dhd->info;
 -      if (waitqueue_active(&dhdinfo->ctrl_wait))
 -              wake_up_interruptible(&dhdinfo->ctrl_wait);
 -      return;
 -}
 -
 -int dhd_dev_reset(struct net_device *dev, u8 flag)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
  
 -      /* Turning off watchdog */
 -      if (flag)
 -              dhd_os_wd_timer(&dhd->pub, 0);
 -
 -      dhd_bus_devreset(&dhd->pub, flag);
 -
 -      /* Turning on watchdog back */
 -      if (!flag)
 -              dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
 -      DHD_ERROR(("%s:  WLAN OFF DONE\n", __func__));
 +      brcmf_bus_devreset(&drvr_priv->pub, flag);
  
        return 1;
  }
  
 -int net_os_set_suspend_disable(struct net_device *dev, int val)
 +static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
  {
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 -      int ret = 0;
 -
 -      if (dhd) {
 -              ret = dhd->pub.suspend_disable_flag;
 -              dhd->pub.suspend_disable_flag = val;
 -      }
 -      return ret;
 -}
 -
 -int net_os_set_suspend(struct net_device *dev, int val)
 -{
 -      int ret = 0;
 -#if defined(CONFIG_HAS_EARLYSUSPEND)
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 -
 -      if (dhd) {
 -              dhd_os_proto_block(&dhd->pub);
 -              ret = dhd_set_suspend(val, &dhd->pub);
 -              dhd_os_proto_unblock(&dhd->pub);
 -      }
 -#endif                /* defined(CONFIG_HAS_EARLYSUSPEND) */
 -      return ret;
 -}
 -
 -int net_os_set_dtim_skip(struct net_device *dev, int val)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
 -
 -      if (dhd)
 -              dhd->pub.dtim_skip = val;
 -
 -      return 0;
 -}
 -
 -int net_os_set_packet_filter(struct net_device *dev, int val)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
 -      int ret = 0;
 -
 -      /* Packet filtering is set only if we still in early-suspend and
 -       * we need either to turn it ON or turn it OFF
 -       * We can always turn it OFF in case of early-suspend, but we turn it
 -       * back ON only if suspend_disable_flag was not set
 -       */
 -      if (dhd && dhd->pub.up) {
 -              dhd_os_proto_block(&dhd->pub);
 -              if (dhd->pub.in_suspend) {
 -                      if (!val || (val && !dhd->pub.suspend_disable_flag))
 -                              dhd_set_packet_filter(val, &dhd->pub);
 -              }
 -              dhd_os_proto_unblock(&dhd->pub);
 -      }
 -      return ret;
 -}
 -
 -void dhd_dev_init_ioctl(struct net_device *dev)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 -
 -      dhd_preinit_ioctls(&dhd->pub);
 -}
 -
 -#ifdef PNO_SUPPORT
 -/* Linux wrapper to call common dhd_pno_clean */
 -int dhd_dev_pno_reset(struct net_device *dev)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 -
 -      return dhd_pno_clean(&dhd->pub);
 -}
 -
 -/* Linux wrapper to call common dhd_pno_enable */
 -int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 -
 -      return dhd_pno_enable(&dhd->pub, pfn_enabled);
 -}
 -
 -/* Linux wrapper to call common dhd_pno_set */
 -int
 -dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
 -              unsigned char scan_fr)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 -
 -      return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
 -}
 -
 -/* Linux wrapper to get  pno status */
 -int dhd_dev_get_pno_status(struct net_device *dev)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 -
 -      return dhd_pno_get_status(&dhd->pub);
 -}
 -
 -#endif                                /* PNO_SUPPORT */
 -
 -static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
 -{
 -      return atomic_read(&dhd->pend_8021x_cnt);
 +      return atomic_read(&drvr_priv->pend_8021x_cnt);
  }
  
  #define MAX_WAIT_FOR_8021X_TX 10
  
 -int dhd_wait_pend8021x(struct net_device *dev)
 +int brcmf_netdev_wait_pend8021x(struct net_device *dev)
  {
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
 +      struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
        int timeout = 10 * HZ / 1000;
        int ntimes = MAX_WAIT_FOR_8021X_TX;
 -      int pend = dhd_get_pend_8021x_cnt(dhd);
 +      int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  
        while (ntimes && pend) {
                if (pend) {
                        set_current_state(TASK_RUNNING);
                        ntimes--;
                }
 -              pend = dhd_get_pend_8021x_cnt(dhd);
 +              pend = brcmf_get_pend_8021x_cnt(drvr_priv);
        }
        return pend;
  }
  
 -void wl_os_wd_timer(struct net_device *ndev, uint wdtick)
 -{
 -      dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(ndev);
 -
 -      dhd_os_wd_timer(&dhd->pub, wdtick);
 -}
 -
 -#ifdef DHD_DEBUG
 -int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
 +#ifdef BCMDBG
 +int brcmf_write_to_file(struct brcmf_pub *drvr, u8 *buf, int size)
  {
        int ret = 0;
        struct file *fp;
        /* open file to write */
        fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
        if (!fp) {
 -              DHD_ERROR(("%s: open file error\n", __func__));
 +              BRCMF_ERROR(("%s: open file error\n", __func__));
                ret = -1;
                goto exit;
        }
@@@ -1731,4 -2861,4 +1854,4 @@@ exit
  
        return ret;
  }
 -#endif                                /* DHD_DEBUG */
 +#endif                                /* BCMDBG */
  
  #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 <linux/interrupt.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 <bcmdefs.h>
+ #include <bcmsdh.h>
  
- /* register access macros */
- #ifndef __BIG_ENDIAN
- #ifndef __mips__
- #define R_REG(r, typ) \
-       brcmf_sdcard_reg_read(NULL, (r), sizeof(typ))
- #else                         /* __mips__ */
- #define R_REG(r, typ) \
-       ({ \
-               __typeof(*(r)) __osl_v; \
-               __asm__ __volatile__("sync"); \
-               __osl_v = brcmf_sdcard_reg_read(NULL, (r),\
-                                         sizeof(typ)); \
-               __asm__ __volatile__("sync"); \
-               __osl_v; \
-       })
- #endif                                /* __mips__ */
+ #ifdef BCMEMBEDIMAGE
+ #include BCMEMBEDIMAGE
+ #endif                                /* BCMEMBEDIMAGE */
  
- #else                         /* __BIG_ENDIAN */
- #define R_REG(r, typ) \
-       brcmf_sdcard_reg_read(NULL, (r), sizeof(typ))
- #endif                                /* __BIG_ENDIAN */
+ #include <bcmutils.h>
+ #include <bcmdevs.h>
  
- #define OR_REG(r, v, typ) \
-       brcmf_sdcard_reg_write(NULL, (r), sizeof(typ), R_REG(r, typ) | (v))
+ #include <hndsoc.h>
+ #ifdef DHD_DEBUG
+ #include <hndrte_armtrap.h>
+ #include <hndrte_cons.h>
+ #endif                                /* DHD_DEBUG */
+ #include <sbchipc.h>
+ #include <sbhnddma.h>
  
- #ifdef BCMDBG
+ #include <sdio.h>
+ #include <sbsdio.h>
+ #include <sbsdpcmdev.h>
+ #include <bcmsdpcm.h>
  
- /* ARM trap handling */
+ #include <proto/802.11.h>
  
- /* Trap types defined by ARM (see arminc.h) */
- #if defined(__ARM_ARCH_4T__)
- #define       MAX_TRAP_TYPE   (TR_FIQ + 1)
- #elif defined(__ARM_ARCH_7M__)
- #define       MAX_TRAP_TYPE   (TR_ISR + ARMCM3_NUMINTS)
- #endif                                /* __ARM_ARCH_7M__ */
- /* The trap structure is defined here as offsets for assembly */
- #define       TR_TYPE         0x00
- #define       TR_EPC          0x04
- #define       TR_CPSR         0x08
- #define       TR_SPSR         0x0c
- #define       TR_REGS         0x10
- #define       TR_REG(n)       (TR_REGS + (n) * 4)
- #define       TR_SP           TR_REG(13)
- #define       TR_LR           TR_REG(14)
- #define       TR_PC           TR_REG(15)
- #define       TRAP_T_SIZE     80
- struct brcmf_trap {
-       u32 type;
-       u32 epc;
-       u32 cpsr;
-       u32 spsr;
-       u32 r0;
-       u32 r1;
-       u32 r2;
-       u32 r3;
-       u32 r4;
-       u32 r5;
-       u32 r6;
-       u32 r7;
-       u32 r8;
-       u32 r9;
-       u32 r10;
-       u32 r11;
-       u32 r12;
-       u32 r13;
-       u32 r14;
-       u32 pc;
- };
+ #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>
+ #include <bcmchip.h>
  
 -#ifndef DHDSDIO_MEM_DUMP_FNAME
 -#define DHDSDIO_MEM_DUMP_FNAME         "mem_dump"
 -#endif
 +#define CBUF_LEN      (128)
 +
 +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 "dhd.h"
 +#include "dhd_bus.h"
 +#include "dhd_proto.h"
 +#include "dhd_dbg.h"
 +#include <bcmchip.h>
  
  #define TXQLEN                2048    /* bulk tx queue length */
  #define TXHI          (TXQLEN - 256)  /* turn on flow control above TXHI */
  
  #define TXRETRIES     2       /* # of retries for tx frames */
  
 -#if defined(CONFIG_MACH_SANDGATE2G)
 -#define DHD_RXBOUND   250     /* Default for max rx frames in
 +#define BRCMF_RXBOUND 50      /* Default for max rx frames in
                                 one scheduling */
 -#else
 -#define DHD_RXBOUND   50      /* Default for max rx frames in
 -                               one scheduling */
 -#endif                                /* defined(CONFIG_MACH_SANDGATE2G) */
  
 -#define DHD_TXBOUND   20      /* Default for max tx frames in
 +#define BRCMF_TXBOUND 20      /* Default for max tx frames in
                                 one scheduling */
  
 -#define DHD_TXMINMAX  1       /* Max tx frames if rx still pending */
 +#define BRCMF_TXMINMAX        1       /* Max tx frames if rx still pending */
  
  #define MEMBLOCK      2048    /* Block size used for downloading
                                 of dongle image */
  #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
 -#endif
 -#if !ISPOWEROF2(DHD_SDALIGN)
 -#error DHD_SDALIGN is not a power of 2!
 +#ifndef BRCMF_FIRSTREAD
 +#define BRCMF_FIRSTREAD       32
  #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
  
 +/* SBSDIO_DEVICE_CTL */
 +#define SBSDIO_DEVCTL_SETBUSY         0x01    /* 1: device will assert busy signal when
 +                                               * receiving CMD53
 +                                               */
 +#define SBSDIO_DEVCTL_SPI_INTR_SYNC   0x02    /* 1: assertion of sdio interrupt is
 +                                               * synchronous to the sdio clock
 +                                               */
 +#define SBSDIO_DEVCTL_CA_INT_ONLY     0x04    /* 1: mask all interrupts to host
 +                                               * except the chipActive (rev 8)
 +                                               */
 +#define SBSDIO_DEVCTL_PADS_ISO                0x08    /* 1: isolate internal sdio signals, put
 +                                               * external pads in tri-state; requires
 +                                               * sdio bus power cycle to clear (rev 9)
 +                                               */
 +#define SBSDIO_DEVCTL_SB_RST_CTL      0x30    /* Force SD->SB reset mapping (rev 11) */
 +#define SBSDIO_DEVCTL_RST_CORECTL     0x00    /*   Determined by CoreControl bit */
 +#define SBSDIO_DEVCTL_RST_BPRESET     0x10    /*   Force backplane reset */
 +#define SBSDIO_DEVCTL_RST_NOBPRESET   0x20    /*   Force no backplane reset */
 +
 +/* SBSDIO_FUNC1_CHIPCLKCSR */
 +#define SBSDIO_FORCE_ALP              0x01    /* Force ALP request to backplane */
 +#define SBSDIO_FORCE_HT                       0x02    /* Force HT request to backplane */
 +#define SBSDIO_FORCE_ILP              0x04    /* Force ILP request to backplane */
 +#define SBSDIO_ALP_AVAIL_REQ          0x08    /* Make ALP ready (power up xtal) */
 +#define SBSDIO_HT_AVAIL_REQ           0x10    /* Make HT ready (power up PLL) */
 +#define SBSDIO_FORCE_HW_CLKREQ_OFF    0x20    /* Squelch clock requests from HW */
 +#define SBSDIO_ALP_AVAIL              0x40    /* Status: ALP is ready */
 +#define SBSDIO_HT_AVAIL                       0x80    /* Status: HT is ready */
 +
 +#define SBSDIO_AVBITS                 (SBSDIO_HT_AVAIL | SBSDIO_ALP_AVAIL)
 +#define SBSDIO_ALPAV(regval)          ((regval) & SBSDIO_AVBITS)
 +#define SBSDIO_HTAV(regval)           (((regval) & SBSDIO_AVBITS) == SBSDIO_AVBITS)
 +#define SBSDIO_ALPONLY(regval)                (SBSDIO_ALPAV(regval) && !SBSDIO_HTAV(regval))
 +#define SBSDIO_CLKAV(regval, alponly) (SBSDIO_ALPAV(regval) && \
 +                                      (alponly ? 1 : SBSDIO_HTAV(regval)))
 +/* direct(mapped) cis space */
 +#define SBSDIO_CIS_BASE_COMMON                0x1000  /* MAPPED common CIS address */
 +#define SBSDIO_CIS_SIZE_LIMIT         0x200   /* maximum bytes in one CIS */
 +#define SBSDIO_CIS_OFT_ADDR_MASK      0x1FFFF /* cis offset addr is < 17 bits */
 +
 +#define SBSDIO_CIS_MANFID_TUPLE_LEN   6       /* manfid tuple length, include tuple,
 +                                               * link bytes
 +                                               */
 +
 +/* intstatus */
 +#define I_SMB_SW0     (1 << 0)        /* To SB Mail S/W interrupt 0 */
 +#define I_SMB_SW1     (1 << 1)        /* To SB Mail S/W interrupt 1 */
 +#define I_SMB_SW2     (1 << 2)        /* To SB Mail S/W interrupt 2 */
 +#define I_SMB_SW3     (1 << 3)        /* To SB Mail S/W interrupt 3 */
 +#define I_SMB_SW_MASK 0x0000000f      /* To SB Mail S/W interrupts mask */
 +#define I_SMB_SW_SHIFT        0       /* To SB Mail S/W interrupts shift */
 +#define I_HMB_SW0     (1 << 4)        /* To Host Mail S/W interrupt 0 */
 +#define I_HMB_SW1     (1 << 5)        /* To Host Mail S/W interrupt 1 */
 +#define I_HMB_SW2     (1 << 6)        /* To Host Mail S/W interrupt 2 */
 +#define I_HMB_SW3     (1 << 7)        /* To Host Mail S/W interrupt 3 */
 +#define I_HMB_SW_MASK 0x000000f0      /* To Host Mail S/W interrupts mask */
 +#define I_HMB_SW_SHIFT        4       /* To Host Mail S/W interrupts shift */
 +#define I_WR_OOSYNC   (1 << 8)        /* Write Frame Out Of Sync */
 +#define I_RD_OOSYNC   (1 << 9)        /* Read Frame Out Of Sync */
 +#define       I_PC            (1 << 10)       /* descriptor error */
 +#define       I_PD            (1 << 11)       /* data error */
 +#define       I_DE            (1 << 12)       /* Descriptor protocol Error */
 +#define       I_RU            (1 << 13)       /* Receive descriptor Underflow */
 +#define       I_RO            (1 << 14)       /* Receive fifo Overflow */
 +#define       I_XU            (1 << 15)       /* Transmit fifo Underflow */
 +#define       I_RI            (1 << 16)       /* Receive Interrupt */
 +#define I_BUSPWR      (1 << 17)       /* SDIO Bus Power Change (rev 9) */
 +#define I_XMTDATA_AVAIL (1 << 23)     /* bits in fifo */
 +#define       I_XI            (1 << 24)       /* Transmit Interrupt */
 +#define I_RF_TERM     (1 << 25)       /* Read Frame Terminate */
 +#define I_WF_TERM     (1 << 26)       /* Write Frame Terminate */
 +#define I_PCMCIA_XU   (1 << 27)       /* PCMCIA Transmit FIFO Underflow */
 +#define I_SBINT               (1 << 28)       /* sbintstatus Interrupt */
 +#define I_CHIPACTIVE  (1 << 29)       /* chip from doze to active state */
 +#define I_SRESET      (1 << 30)       /* CCCR RES interrupt */
 +#define I_IOE2                (1U << 31)      /* CCCR IOE2 Bit Changed */
 +#define       I_ERRORS        (I_PC | I_PD | I_DE | I_RU | I_RO | I_XU)
 +#define I_DMA         (I_RI | I_XI | I_ERRORS)
 +
 +/* corecontrol */
 +#define CC_CISRDY             (1 << 0)        /* CIS Ready */
 +#define CC_BPRESEN            (1 << 1)        /* CCCR RES signal */
 +#define CC_F2RDY              (1 << 2)        /* set CCCR IOR2 bit */
 +#define CC_CLRPADSISO         (1 << 3)        /* clear SDIO pads isolation */
 +#define CC_XMTDATAAVAIL_MODE  (1 << 4)
 +#define CC_XMTDATAAVAIL_CTRL  (1 << 5)
 +
 +/* SDA_FRAMECTRL */
 +#define SFC_RF_TERM   (1 << 0)        /* Read Frame Terminate */
 +#define SFC_WF_TERM   (1 << 1)        /* Write Frame Terminate */
 +#define SFC_CRC4WOOS  (1 << 2)        /* CRC error for write out of sync */
 +#define SFC_ABORTALL  (1 << 3)        /* Abort all in-progress frames */
 +
 +/* HW frame tag */
 +#define SDPCM_FRAMETAG_LEN    4       /* 2 bytes len, 2 bytes check val */
 +
  /* 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
  #define MAX_RX_DATASZ 2048
  
  /* Maximum milliseconds to wait for F2 to come up */
 -#define DHD_WAIT_F2RDY        3000
 +#define BRCMF_WAIT_F2RDY      3000
  
  /* Bump up limit on waiting for HT to account for first startup;
   * if the image is doing a CRC calculation before programming the PMU
  #endif
  
  /* Value for ChipClockCSR during initial setup */
 -#define DHD_INIT_CLKCTL1      (SBSDIO_FORCE_HW_CLKREQ_OFF |   \
 +#define BRCMF_INIT_CLKCTL1    (SBSDIO_FORCE_HW_CLKREQ_OFF |   \
                                        SBSDIO_ALP_AVAIL_REQ)
 -#define DHD_INIT_CLKCTL2      (SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP)
  
  /* 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);
  
 -#ifdef DHD_DEBUG
 +/*
 + * Core reg address translation.
 + * Both macro's returns a 32 bits byte address on the backplane bus.
 + */
 +#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 BCMDBG
  /* Device console log buffer state */
 -typedef struct dhd_console {
 +struct brcmf_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 {
        u32 cccorebase;
        u32 ccrev;
        u32 cccaps;
 -      u32 buscorebase;
 +      u32 buscorebase; /* 32 bits backplane bus address */
        u32 buscorerev;
        u32 buscoretype;
        u32 ramcorebase;
  };
  
  /* 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 */
 -      uint sdpcmrev;          /* SDIO core revision */
 -      uint armrev;            /* CPU core revision */
 -      uint ramrev;            /* SOCRAM core revision */
        u32 ramsize;            /* Size of RAM in SOCRAM (bytes) */
        u32 orig_ramsize;       /* Size of RAM in SOCRAM (bytes) */
  
        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 */
        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) */
        uint polltick;          /* Tick counter */
        uint pollcnt;           /* Count of active polls */
  
 -#ifdef DHD_DEBUG
 -      dhd_console_t console;  /* Console output polling support */
 +#ifdef BCMDBG
 +      struct brcmf_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 */
 +      uint regfails;          /* Count of R_REG failures */
  
        uint clkstate;          /* State of sd and backplane clock(s) */
        bool activity;          /* Activity flag for clock down */
        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 */
 -      bool use_rxchain;       /* If dhd should use PKT chains */
 +      s32 sd_rxchain;
 +      bool use_rxchain;       /* If brcmf should use PKT chains */
        bool sleeping;          /* Is SDIO bus sleeping? */
        bool rxflow_mode;       /* Rx flow control mode */
        bool rxflow;            /* Is rx flow control on */
 -      uint prev_rxlim_hit;    /* Is prev rx limit exceeded
 -                                       (per dpc schedule) */
        bool alp_only;          /* Don't use HT clock (ALP only) */
  /* Field to decide if rx of control frames happen in rxbuf or lb-pool */
        bool usebufpool;
        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
  #define CLK_PENDING   2       /* Not used yet */
  #define CLK_AVAIL     3
  
 -#define DHD_NOPMU(dhd)        (false)
 +#define BRCMF_NOPMU(brcmf)    (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);
  
 -extern uint dhd_watchdog_ms;
 -extern void dhd_os_wd_timer(void *bus, uint wdtick);
 +/* 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);
 +
 +#ifdef BCMDBG
 +/* Console poll interval */
 +uint brcmf_console_ms;
 +module_param(brcmf_console_ms, uint, 0);
 +#endif                /* BCMDBG */
  
  /* Tx/Rx bounds */
 -uint dhd_txbound;
 -uint dhd_rxbound;
 -uint dhd_txminmax;
 +uint brcmf_txbound;
 +uint brcmf_rxbound;
 +uint brcmf_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;
  
@@@ -851,7 -351,9 +798,7 @@@ static bool retrydata
  #define RETRYCHAN(chan) (((chan) == SDPCM_EVENT_CHANNEL) || retrydata)
  
  static const uint watermark = 8;
 -static const uint firstread = DHD_FIRSTREAD;
 -
 -#define HDATLEN (firstread - (SDPCM_HDRLEN))
 +static const uint firstread = BRCMF_FIRSTREAD;
  
  /* Retry count for register access failures */
  static const uint retry_limit = 2;
@@@ -861,11 -363,20 +808,11 @@@ 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;                                          \
                datalign = (unsigned long)((_p)->data);                 \
                datalign = roundup(datalign, (_align)) - datalign;      \
 -              ASSERT(datalign < (_align));                            \
 -              ASSERT((_p)->len >= ((_len) + datalign));               \
                if (datalign)                                           \
                        skb_pull((_p), datalign);                       \
                __skb_trim((_p), (_len));                               \
  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) \
        (((u8)(bus->tx_max - bus->tx_seq) != 0) && \
        (((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0))
  
 -/* Macros to get register read/write status */
 -/* NOTE: these assume a local dhdsdio_bus_t *bus! */
 -#define R_SDREG(regvar, regaddr, retryvar) \
 -do { \
 -      retryvar = 0; \
 -      do { \
 -              regvar = R_REG(regaddr); \
 -      } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
 -      if (retryvar) { \
 -              bus->regfails += (retryvar-1); \
 -              if (retryvar > retry_limit) { \
 -                      DHD_ERROR(("%s: FAILED" #regvar "READ, LINE %d\n", \
 -                      __func__, __LINE__)); \
 -                      regvar = 0; \
 -              } \
 -      } \
 -} while (0)
 -
 -#define W_SDREG(regval, regaddr, retryvar) \
 -do { \
 -      retryvar = 0; \
 -      do { \
 -              W_REG(regaddr, regval); \
 -      } while (bcmsdh_regfail(bus->sdh) && (++retryvar <= retry_limit)); \
 -      if (retryvar) { \
 -              bus->regfails += (retryvar-1); \
 -              if (retryvar > retry_limit) \
 -                      DHD_ERROR(("%s: FAILED REGISTER WRITE, LINE %d\n", \
 -                      __func__, __LINE__)); \
 -      } \
 -} while (0)
 -
 -#define DHD_BUS                       SDIO_BUS
 +/*
 + * Reads a register in the SDIO hardware block. This block occupies a series of
 + * adresses on the 32 bit backplane bus.
 + */
 +static void
 +r_sdreg32(struct brcmf_bus *bus, u32 *regvar, u32 reg_offset, u32 *retryvar)
 +{
 +      *retryvar = 0;
 +      do {
 +              *regvar = R_REG(bus->ci->buscorebase + reg_offset, u32);
 +      } while (brcmf_sdcard_regfail(bus->card) &&
 +               (++(*retryvar) <= retry_limit));
 +      if (*retryvar) {
 +              bus->regfails += (*retryvar-1);
 +              if (*retryvar > retry_limit) {
 +                      BRCMF_ERROR(("FAILED READ %Xh\n", reg_offset));
 +                      *regvar = 0;
 +              }
 +      }
 +}
 +
 +static void
 +w_sdreg32(struct brcmf_bus *bus, u32 regval, u32 reg_offset, u32 *retryvar)
 +{
 +      *retryvar = 0;
 +      do {
 +              brcmf_sdcard_reg_write(NULL, bus->ci->buscorebase + reg_offset,
 +                                     sizeof(u32), regval);
 +      } while (brcmf_sdcard_regfail(bus->card) &&
 +               (++(*retryvar) <= retry_limit));
 +      if (*retryvar) {
 +              bus->regfails += (*retryvar-1);
 +              if (*retryvar > retry_limit)
 +                      BRCMF_ERROR(("FAILED REGISTER WRITE"
 +                                   " %Xh\n", reg_offset));
 +      }
 +}
 +
 +#define BRCMF_BUS                     SDIO_BUS
  
  #define PKT_AVAILABLE()               (intstatus & I_HMB_FRAME_IND)
  
  #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,
 -                               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 uint 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,
 +#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,
 +                                    u32 regsva, u16 devid);
 +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 brcmf_process_nvram_vars(char *varbuf, uint len);
 +
 +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, u32 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_ERROR(("user: Restrict the dongle ram size to %d, min %d\n",
 +                   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__));
 +      BRCMF_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 */
                    && (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));
 +                      BRCMF_ERROR(("%s: HT Avail request error: %d\n",
 +                                   __func__, err));
                        return -EBADE;
                }
  
                if (pendok && ((bus->ci->buscoretype == PCMCIA_CORE_ID)
                               && (bus->ci->buscorerev == 9))) {
                        u32 dummy, retries;
 -                      R_SDREG(dummy, &bus->regs->clockctlstatus, retries);
 +                      r_sdreg32(bus, &dummy,
 +                                offsetof(struct sdpcmd_regs, clockctlstatus),
 +                                &retries);
                }
  
                /* 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));
 +                      BRCMF_ERROR(("%s: HT Avail read error: %d\n",
 +                                   __func__, err));
                        return -EBADE;
                }
  
                /* 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));
 +                              BRCMF_ERROR(("%s: Devctl error setting CA:"
 +                                           " %d\n", __func__, err));
                                return -EBADE;
                        }
  
                        devctl |= SBSDIO_DEVCTL_CA_INT_ONLY;
 -                      bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_DEVICE_CTL,
 -                                       devctl, &err);
 -                      DHD_INFO(("CLKCTL: set PENDING\n"));
 +                      brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
 +                                             SBSDIO_DEVICE_CTL, devctl, &err);
 +                      BRCMF_INFO(("CLKCTL: set PENDING\n"));
                        bus->clkstate = CLK_PENDING;
  
                        return 0;
                } 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",
 -                                 __func__, err));
 +                      BRCMF_ERROR(("%s: HT Avail request error: %d\n",
 +                                   __func__, err));
                        return -EBADE;
                }
                if (!SBSDIO_CLKAV(clkctl, bus->alp_only)) {
 -                      DHD_ERROR(("%s: HT Avail timeout (%d): clkctl 0x%02x\n",
 -                                 __func__, PMU_MAX_TRANSITION_DLY, clkctl));
 +                      BRCMF_ERROR(("%s: HT Avail timeout (%d): "
 +                                   "clkctl 0x%02x\n", __func__,
 +                                   PMU_MAX_TRANSITION_DLY, clkctl));
                        return -EBADE;
                }
  
                /* Mark clock available */
                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 {
 +              BRCMF_INFO(("CLKCTL: turned ON\n"));
 +
 +#if defined(BCMDBG)
 +              if (bus->alp_only != true) {
                        if (SBSDIO_ALPONLY(clkctl)) {
 -                              DHD_ERROR(("%s: HT Clock should be on.\n",
 -                                         __func__));
 +                              BRCMF_ERROR(("%s: HT Clock should be on.\n",
 +                                           __func__));
                        }
                }
 -#endif                                /* defined (DHD_DEBUG) */
 +#endif                                /* defined (BCMDBG) */
  
                bus->activity = true;
        } else {
  
                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);
 -              DHD_INFO(("CLKCTL: turned OFF\n"));
 +              brcmf_sdcard_cfg_write(card, SDIO_FUNC_1,
 +                      SBSDIO_FUNC1_CHIPCLKCSR, clkreq, &err);
 +              BRCMF_INFO(("CLKCTL: turned OFF\n"));
                if (err) {
 -                      DHD_ERROR(("%s: Failed access turning clock off: %d\n",
 -                                 __func__, err));
 +                      BRCMF_ERROR(("%s: Failed access turning clock off:"
 +                                   " %d\n", __func__, err));
                        return -EBADE;
                }
        }
  }
  
  /* 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;
 -                      }
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -                      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__));
 +      BRCMF_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;
        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);
 +                      BRCMF_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
 +      BRCMF_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;
        uint retries = 0;
  
 -      DHD_INFO(("dhdsdio_bussleep: request %s (currently %s)\n",
 -                (sleep ? "SLEEP" : "WAKE"),
 -                (bus->sleeping ? "SLEEP" : "WAKE")));
 +      BRCMF_INFO(("brcmf_sdbrcm_bussleep: request %s (currently %s)\n",
 +                  (sleep ? "SLEEP" : "WAKE"),
 +                  (bus->sleeping ? "SLEEP" : "WAKE")));
  
        /* Done if we're already in the requested state */
        if (sleep == bus->sleeping)
                        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);
 +              w_sdreg32(bus, SMB_USE_OOB,
 +                        offsetof(struct sdpcmd_regs, tosbmailbox), &retries);
                if (retries > retry_limit)
 -                      DHD_ERROR(("CANNOT SIGNAL CHIP, WILL NOT WAKE UP!!\n"));
 +                      BRCMF_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 */
        } 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);
 +              w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, tosbmailboxdata),
 +                        &retries);
                if (retries <= retry_limit)
 -                      W_SDREG(SMB_DEV_INT, &regs->tosbmailbox, retries);
 +                      w_sdreg32(bus, SMB_DEV_INT,
 +                                offsetof(struct sdpcmd_regs, tosbmailbox),
 +                                &retries);
  
                if (retries > retry_limit)
 -                      DHD_ERROR(("CANNOT SIGNAL CHIP TO CLEAR OOB!!\n"));
 +                      BRCMF_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 == BRCMF_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;
        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__));
 +      BRCMF_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;
        }
        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);
 +                      BRCMF_INFO(("%s: insufficient headroom %d for %d pad\n",
 +                                  __func__, skb_headroom(pkt), pad));
 +                      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));
 +                              BRCMF_ERROR(("%s: couldn't allocate new "
 +                                           "%d-byte packet\n", __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);
 +                      /* precondition: (frame % BRCMF_SDALIGN) == 0) */
                        pad = 0;
                } else {
                        skb_push(pkt, pad);
                        frame = (u8 *) (pkt->data);
 -
 -                      ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len));
 +                      /* precondition: pad + SDPCM_HDRLEN <= pkt->len */
                        memset(frame, 0, pad + SDPCM_HDRLEN);
                }
        }
 -      ASSERT(pad < DHD_SDALIGN);
 +      /* precondition: pad < BRCMF_SDALIGN */
  
        /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
        len = (u16) (pkt->len);
        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)) ||
 -            (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) {
 +      if (BRCMF_BYTES_ON() &&
 +          (((BRCMF_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) ||
 +            (BRCMF_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) {
                printk(KERN_DEBUG "Tx Frame:\n");
                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, frame, len);
 -      } else if (DHD_HDRS_ON()) {
 +      } else if (BRCMF_HDRS_ON()) {
                printk(KERN_DEBUG "TxHdr:\n");
                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                     frame, min_t(u16, len, 16));
        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);
  
                if (ret < 0) {
                        /* On failure, abort the command
                         and terminate the frame */
 -                      DHD_INFO(("%s: sdio error %d, abort command and "
 -                              "terminate frame.\n", __func__, ret));
 +                      BRCMF_INFO(("%s: sdio error %d, abort command and "
 +                                  "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;
  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;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        datalen = pkt->len;
  
  
        /* Add space for the header */
        skb_push(pkt, SDPCM_HDRLEN);
 -      ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2));
 +      /* precondition: IS_ALIGNED((unsigned long)(pkt->data), 2) */
  
        prec = PRIO2PREC((pkt->priority & PRIOMASK));
  
        /* 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)) {
 -              DHD_TRACE(("%s: deferring pktq len %d\n", __func__,
 -                         pktq_len(&bus->txq)));
 +              BRCMF_TRACE(("%s: deferring pktq len %d\n", __func__,
 +                           pktq_len(&bus->txq)));
                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);
 -                      DHD_ERROR(("%s: out of bus->txq !!!\n", __func__));
 +                      brcmf_txcomplete(bus->drvr, pkt, false);
 +                      brcmu_pkt_buf_free_skb(pkt);
 +                      BRCMF_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);
 +              BRCMF_TRACE(("%s: calling txpkt\n", __func__));
 +              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;
        uint datalen;
        u8 tx_prec_map;
  
 -      dhd_pub_t *dhd = bus->dhd;
 -      sdpcmd_regs_t *regs = bus->regs;
 +      struct brcmf_pub *drvr = bus->drvr;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        tx_prec_map = ~bus->flowcontrol;
  
        /* 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);
 +                      r_sdreg32(bus, &intstatus,
 +                                offsetof(struct sdpcmd_regs, intstatus),
 +                                &retries);
                        bus->f2txdata++;
 -                      if (bcmsdh_regfail(bus->sdh))
 +                      if (brcmf_sdcard_regfail(bus->card))
                                break;
                        if (intstatus & bus->hostintmask)
                                bus->ipend = true;
        }
  
        /* 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 == BRCMF_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__));
 +      BRCMF_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 */
        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);
 +              /* precondition: doff < BRCMF_SDALIGN */
        }
        doff += SDPCM_HDRLEN;
  
                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 */
        if (forcealign && (len & (ALIGNMENT - 1)))
                len = roundup(len, ALIGNMENT);
  
 -      ASSERT(IS_ALIGNED((unsigned long)frame, 2));
 +      /* precondition: 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);
        put_unaligned_le32(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader));
  
        if (!DATAOK(bus)) {
 -              DHD_INFO(("%s: No bus credit bus->tx_max %d, bus->tx_seq %d\n",
 -                        __func__, bus->tx_max, bus->tx_seq));
 +              BRCMF_INFO(("%s: No bus credit bus->tx_max %d,"
 +                          " bus->tx_seq %d\n", __func__,
 +                          bus->tx_max, bus->tx_seq));
                bus->ctrl_frame_stat = true;
                /* Send from dpc */
                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__));
 +                      BRCMF_INFO(("%s: ctrl_frame_stat == false\n",
 +                                  __func__));
                        ret = 0;
                } else {
 -                      DHD_INFO(("%s: ctrl_frame_stat == true\n", __func__));
 +                      BRCMF_INFO(("%s: ctrl_frame_stat == true\n", __func__));
                        ret = -1;
                }
        }
  
        if (ret == -1) {
 -#ifdef DHD_DEBUG
 -              if (DHD_BYTES_ON() && DHD_CTL_ON()) {
 +#ifdef BCMDBG
 +              if (BRCMF_BYTES_ON() && BRCMF_CTL_ON()) {
                        printk(KERN_DEBUG "Tx Frame:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                             frame, len);
 -              } else if (DHD_HDRS_ON()) {
 +              } else if (BRCMF_HDRS_ON()) {
                        printk(KERN_DEBUG "TxHdr:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                             frame, min_t(u16, len, 16));
  
                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);
 -
 -                      ASSERT(ret != -BCME_PENDING);
 +                      ret = brcmf_sdbrcm_send_buf(bus,
 +                              brcmf_sdcard_cur_sbwad(card), SDIO_FUNC_2,
 +                              F2SYNC, frame, len, NULL, NULL, NULL);
  
                        if (ret < 0) {
                                /* On failure, abort the command and
                                 terminate the frame */
 -                              DHD_INFO(("%s: sdio error %d, abort command and terminate frame.\n",
 -                                      __func__, ret));
 +                              BRCMF_INFO(("%s: sdio error %d, abort command "
 +                                          "and 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);
 +                                           NULL);
                                        bus->f1regdata += 2;
                                        if ((hi == 0) && (lo == 0))
                                                break;
                } 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;
        bool pending;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_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));
 +              BRCMF_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);
 -#endif                                /* DHD_DEBUG */
 +              BRCMF_ERROR(("%s: resumed on timeout\n", __func__));
 +#ifdef BCMDBG
 +              brcmf_sdbrcm_sdlock(bus);
 +              brcmf_sdbrcm_checkdied(bus, NULL, 0);
 +              brcmf_sdbrcm_sdunlock(bus);
 +#endif                                /* BCMDBG */
        } else if (pending == true) {
 -              DHD_CTL(("%s: cancelled\n", __func__));
 +              BRCMF_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);
 -#endif                                /* DHD_DEBUG */
 +              BRCMF_CTL(("%s: resumed for unknown reason?\n", __func__));
 +#ifdef BCMDBG
 +              brcmf_sdbrcm_sdlock(bus);
 +              brcmf_sdbrcm_checkdied(bus, NULL, 0);
 +              brcmf_sdbrcm_sdunlock(bus);
 +#endif                                /* BCMDBG */
        }
  
        if (rxlen)
 -              bus->dhd->rx_ctlpkts++;
 +              bus->drvr->rx_ctlpkts++;
        else
 -              bus->dhd->rx_ctlerrs++;
 +              bus->drvr->rx_ctlerrs++;
  
        return rxlen ? (int)rxlen : -ETIMEDOUT;
  }
@@@ -1862,10 -1466,8 +1809,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,
        IOV_IDLECLOCK,
        IOV_SD1IDLE,
        IOV_SLEEP,
 +      IOV_WDTICK,
        IOV_VARS
  };
  
 -const bcm_iovar_t dhdsdio_iovars[] = {
 +const struct brcmu_iovar brcmf_sdio_iovars[] = {
        {"intr", IOV_INTR, 0, IOVT_BOOL, 0},
        {"sleep", IOV_SLEEP, 0, IOVT_BOOL, 0},
        {"pollrate", IOV_POLLRATE, 0, IOVT_UINT32, 0},
        {"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}
 +      ,
 +      {"sdreg", IOV_SDREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
        ,
 -      {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(sdreg_t)}
 +      {"sbreg", IOV_SBREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
        ,
 -      {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN}
 +      {"sd_cis", IOV_SDCIS, 0, IOVT_BUFFER, BRCMF_IOCTL_MAXLEN}
        ,
        {"forcealign", IOV_FORCEEVEN, 0, IOVT_BOOL, 0}
        ,
        ,
        {"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 */
  
  };
  
  static void
 -dhd_dump_pct(struct bcmstrbuf *strbuf, char *desc, uint num, uint div)
 +brcmf_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,
 +              brcmf_dump_pct(strbuf, "\nRx: pkts/f2rd", bus->drvr->rx_packets,
                             (bus->f2rxhdrs + bus->f2rxdata));
 -              dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->rx_packets,
 +              brcmf_dump_pct(strbuf, ", pkts/f1sd", bus->drvr->rx_packets,
                             bus->f1regdata);
 -              dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->rx_packets,
 +              brcmf_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,
 +              brcmf_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);
 -              dhd_dump_pct(strbuf, ", pkts/glom", bus->rxglompkts,
 +              brcmf_dump_pct(strbuf, "Rx: glom pct", (100 * bus->rxglompkts),
 +                           bus->drvr->rx_packets);
 +              brcmf_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,
 +              brcmf_dump_pct(strbuf, "Tx: pkts/f2wr", bus->drvr->tx_packets,
                             bus->f2txdata);
 -              dhd_dump_pct(strbuf, ", pkts/f1sd", bus->dhd->tx_packets,
 +              brcmf_dump_pct(strbuf, ", pkts/f1sd", bus->drvr->tx_packets,
                             bus->f1regdata);
 -              dhd_dump_pct(strbuf, ", pkts/sd", bus->dhd->tx_packets,
 +              brcmf_dump_pct(strbuf, ", pkts/sd", bus->drvr->tx_packets,
                             (bus->f2txdata + bus->f1regdata));
 -              dhd_dump_pct(strbuf, ", pkts/int", bus->dhd->tx_packets,
 +              brcmf_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),
 +              brcmf_dump_pct(strbuf, "Total: pkts/f2rw",
 +                           (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),
 +              brcmf_dump_pct(strbuf, ", pkts/f1sd",
 +                           (bus->drvr->tx_packets + bus->drvr->rx_packets),
                             bus->f1regdata);
 -              dhd_dump_pct(strbuf, ", pkts/sd",
 -                           (bus->dhd->tx_packets + bus->dhd->rx_packets),
 +              brcmf_dump_pct(strbuf, ", pkts/sd",
 +                           (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),
 +              brcmf_dump_pct(strbuf, ", pkts/int",
 +                           (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;
  }
  
  #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;
        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;
  #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;
                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__));
 +              BRCMF_ERROR(("%s: window change failed\n", __func__));
                goto xfer_done;
        }
  
        /* Do the transfer(s) */
        while (size) {
 -              DHD_INFO(("%s: %s %d bytes at offset 0x%08x in window 0x%08x\n",
 -                        __func__, (write ? "write" : "read"), dsize,
 -                        sdaddr, (address & SBSDIO_SBWINDOW_MASK)));
 +              BRCMF_INFO(("%s: %s %d bytes at offset 0x%08x in window"
 +                          " 0x%08x\n", __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__));
 +                      BRCMF_ERROR(("%s: membytes transfer failed\n",
 +                                   __func__));
                        break;
                }
  
                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__));
 +                              BRCMF_ERROR(("%s: window change failed\n",
 +                                           __func__));
                                break;
                        }
                        sdaddr = 0;
  
  xfer_done:
        /* Return the window to backplane enumeration space for core access */
 -      if (dhdsdio_set_siaddr_window(bus, bcmsdh_cur_sbwad(bus->sdh))) {
 -              DHD_ERROR(("%s: FAILED to set window back to 0x%x\n",
 -                         __func__, bcmsdh_cur_sbwad(bus->sdh)));
 +      if (brcmf_sdbrcm_set_siaddr_window(bus,
 +                                         brcmf_sdcard_cur_sbwad(bus->card))) {
 +              BRCMF_ERROR(("%s: FAILED to set window back to 0x%x\n",
 +                           __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;
  
        addr = le32_to_cpu(addr);
  
 -      DHD_INFO(("sdpcm_shared address 0x%08X\n", addr));
 +      BRCMF_INFO(("sdpcm_shared address 0x%08X\n", addr));
  
        /*
         * Check if addr is valid.
         * NVRAM length at the end of memory should have been overwritten.
         */
        if (addr == 0 || ((~addr >> 16) & 0xffff) == (addr & 0xffff)) {
 -              DHD_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n",
 -                         __func__, addr));
 +              BRCMF_ERROR(("%s: address (0x%08x) of sdpcm_shared invalid\n",
 +                           __func__, addr));
                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;
  
        sh->msgtrace_addr = le32_to_cpu(sh->msgtrace_addr);
  
        if ((sh->flags & SDPCM_SHARED_VERSION_MASK) != SDPCM_SHARED_VERSION) {
 -              DHD_ERROR(("%s: sdpcm_shared version %d in dhd "
 -                         "is different than sdpcm_shared version %d in dongle\n",
 -                         __func__, SDPCM_SHARED_VERSION,
 -                         sh->flags & SDPCM_SHARED_VERSION_MASK));
 +              BRCMF_ERROR(("%s: sdpcm_shared version %d in brcmf "
 +                           "is different than sdpcm_shared version %d in dongle\n",
 +                           __func__, SDPCM_SHARED_VERSION,
 +                           sh->flags & SDPCM_SHARED_VERSION_MASK));
                return -EBADE;
        }
  
        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__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        if (data == NULL) {
                /*
                size = msize;
                mbuffer = data = kmalloc(msize, GFP_ATOMIC);
                if (mbuffer == NULL) {
 -                      DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__,
 -                                 msize));
 +                      BRCMF_ERROR(("%s: kmalloc(%d) failed\n", __func__,
 +                                   msize));
                        bcmerror = -ENOMEM;
                        goto done;
                }
  
        str = kmalloc(maxstrlen, GFP_ATOMIC);
        if (str == NULL) {
 -              DHD_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen));
 +              BRCMF_ERROR(("%s: kmalloc(%d) failed\n", __func__, maxstrlen));
                bcmerror = -ENOMEM;
                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);
  
                 * (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)) ==
                 * (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",
        }
  
        if (sdpcm_shared.flags & (SDPCM_SHARED_ASSERT | SDPCM_SHARED_TRAP))
 -              DHD_ERROR(("%s: %s\n", __func__, strbuf.origbuf));
 +              BRCMF_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);
        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 */
        size = bus->ramsize;
        buf = kmalloc(size, GFP_ATOMIC);
        if (!buf) {
 -              DHD_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size));
 +              BRCMF_ERROR(("%s: Out of memory (%d bytes)\n", __func__, size));
                return -1;
        }
  
        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));
 +                      BRCMF_ERROR(("%s: Error membytes %d\n", __func__, ret));
                        kfree(buf);
                        return -1;
                }
        printk(KERN_DEBUG "Done\n");
  
        /* free buf before return !!! */
 -      if (write_to_file(bus->dhd, buf, bus->ramsize)) {
 -              DHD_ERROR(("%s: Error writing to files\n", __func__));
 +      if (brcmf_write_to_file(bus->drvr, buf, bus->ramsize)) {
 +              BRCMF_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 brcmf_console *c = &bus->console;
        u8 line[CONSOLE_LINE_MAX], ch;
        u32 n, idx, addr;
        int rv;
                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;
  
        /* 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;
  
@@@ -2494,16 -2088,16 +2441,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__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* Basic sanity checks */
 -      if (bus->dhd->up) {
 +      if (bus->drvr->up) {
                bcmerror = -EISCONN;
                goto err;
        }
@@@ -2530,7 -2124,7 +2477,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)
  {
        s32 int_val = 0;
        bool bool_val = 0;
  
 -      DHD_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p "
 -              "len %d val_size %d\n",
 -              __func__, actionid, name, params, plen, arg, len, val_size));
 +      BRCMF_TRACE(("%s: Enter, action %d name %s params %p plen %d arg %p "
 +                   "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;
  
        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;
        /* 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);
        }
  
        /* 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) {
        case IOV_SVAL(IOV_INTR):
                bus->intr = bool_val;
                bus->intdis = false;
 -              if (bus->dhd->up) {
 +              if (bus->drvr->up) {
 +                      BRCMF_INTR(("%s: %s SDIO interrupts\n", __func__,
 +                                  bus->intr ? "enable" : "disable"));
                        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;
                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;
  
                        bool set = (actionid == IOV_SVAL(IOV_MEMBYTES));
  
 -                      ASSERT(plen >= 2 * sizeof(int));
 -
                        address = (u32) int_val;
                        memcpy(&int_val, (char *)params + sizeof(int_val),
                               sizeof(int_val));
                        /* Do some validation */
                        dsize = set ? plen - (2 * sizeof(int)) : len;
                        if (dsize < size) {
 -                              DHD_ERROR(("%s: error on %s membytes, addr "
 -                              "0x%08x size %d dsize %d\n",
 -                              __func__, (set ? "set" : "get"),
 -                              address, size, dsize));
 +                              BRCMF_ERROR(("%s: error on %s membytes, addr "
 +                                           "0x%08x size %d dsize %d\n",
 +                                           __func__, (set ? "set" : "get"),
 +                                           address, size, dsize));
                                bcmerror = -EINVAL;
                                break;
                        }
  
 -                      DHD_INFO(("%s: Request to %s %d bytes at address "
 -                      "0x%08x\n",
 -                      __func__, (set ? "write" : "read"), size, address));
 +                      BRCMF_INFO(("%s: Request to %s %d bytes at address "
 +                                  "0x%08x\n", __func__,
 +                                  (set ? "write" : "read"), size, address));
  
                        /* If we know about SOCRAM, check for a fit */
                        if ((bus->orig_ramsize) &&
                            ((address > bus->orig_ramsize)
                             || (address + size > bus->orig_ramsize))) {
 -                              DHD_ERROR(("%s: ramsize 0x%08x doesn't have %d "
 -                              "bytes at 0x%08x\n",
 -                              __func__, bus->orig_ramsize, size, address));
 +                              BRCMF_ERROR(("%s: ramsize 0x%08x doesn't have"
 +                                           " %d bytes at 0x%08x\n", __func__,
 +                                           bus->orig_ramsize, size, address));
                                bcmerror = -EINVAL;
                                break;
                        }
                            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;
                }
                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):
                        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;
 +                      addr = bus->ci->buscorebase + 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;
  
        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;
 +                      addr = bus->ci->buscorebase + 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;
                }
                 (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;
  
        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;
                }
                        *(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;
                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):
 -              int_val = (s32) dhd_txminmax;
 +              int_val = (s32) brcmf_txminmax;
                memcpy(arg, &int_val, val_size);
                break;
  
        case IOV_SVAL(IOV_TXMINMAX):
 -              dhd_txminmax = (uint) int_val;
 +              brcmf_txminmax = (uint) int_val;
                break;
 -#endif                                /* DHD_DEBUG */
 +#endif                                /* BCMDBG */
  
  #ifdef SDTEST
        case IOV_GVAL(IOV_EXTLOOP):
                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));
 +              BRCMF_TRACE(("%s: Called set IOV_DEVRESET=%d dongle_reset=%d "
 +                           "busstate=%d\n",
 +                           __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;
  
        case IOV_GVAL(IOV_DEVRESET):
 -              DHD_TRACE(("%s: Called get IOV_DEVRESET\n", __func__));
 +              BRCMF_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. */
  
                /* 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));
 +              BRCMF_INFO(("Compare NVRAM dl & ul; varsize=%d\n", varsize));
                nvram_ularray = kmalloc(varsize, GFP_ATOMIC);
                if (!nvram_ularray)
                        return -ENOMEM;
  
                /* 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 "
 -                      "0x%08x\n", __func__, bcmerror, varsize, varaddr));
 +                      BRCMF_ERROR(("%s: error %d on reading %d nvram bytes"
 +                                   " at 0x%08x\n", __func__, bcmerror,
 +                                   varsize, varaddr));
                }
                /* Compare the org NVRAM with the one read from RAM */
                if (memcmp(vbuffer, nvram_ularray, varsize)) {
 -                      DHD_ERROR(("%s: Downloaded NVRAM image is corrupted.\n",
 -                                 __func__));
 +                      BRCMF_ERROR(("%s: Downloaded NVRAM image is "
 +                                   "corrupted.\n", __func__));
                } else
 -                      DHD_ERROR(("%s: Download/Upload/Compare of NVRAM ok.\n",
 -                              __func__));
 +                      BRCMF_ERROR(("%s: Download/Upload/Compare of"
 +                                   " NVRAM ok.\n", __func__));
  
                kfree(nvram_ularray);
 -#endif                                /* DHD_DEBUG */
 +#endif                                /* BCMDBG */
  
                kfree(vbuffer);
        }
  
        /* adjust to the user specified RAM */
 -      DHD_INFO(("Physical memory size: %d, usable memory size: %d\n",
 -                bus->orig_ramsize, bus->ramsize));
 -      DHD_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize));
 +      BRCMF_INFO(("Physical memory size: %d, usable memory size: %d\n",
 +                  bus->orig_ramsize, bus->ramsize));
 +      BRCMF_INFO(("Vars are at %d, orig varsize is %d\n", varaddr, varsize));
        varsize = ((bus->orig_ramsize - 4) - varaddr);
  
        /*
                varsizew = cpu_to_le32(varsizew);
        }
  
 -      DHD_INFO(("New varsize is %d, length token=0x%08x\n", varsize,
 -                varsizew));
 +      BRCMF_INFO(("New varsize is %d, length token=0x%08x\n", varsize,
 +                  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;
        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));
                if ((SICF_CLOCK_EN << SBTML_SICF_SHIFT) != regdata) {
 -                      DHD_ERROR(("%s: SOCRAM core is down after reset?\n",
 -                                 __func__));
 +                      BRCMF_ERROR(("%s: SOCRAM core is down after reset?\n",
 +                                   __func__));
                        bcmerror = -EBADE;
                        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__));
 +                      BRCMF_ERROR(("%s: no vars written to RAM\n", __func__));
                        bcmerror = 0;
                }
  
 -              W_SDREG(0xFFFFFFFF, &bus->regs->intstatus, retries);
 +              w_sdreg32(bus, 0xFFFFFFFF,
 +                        offsetof(struct sdpcmd_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 = BRCMF_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;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -      ASSERT(name);
 -      ASSERT(len >= 0);
 +      if (name == NULL || len <= 0)
 +              return -EINVAL;
  
 -      /* Get MUST have return space */
 -      ASSERT(set || (arg && len));
 +      /* Set does not take qualifiers */
 +      if (set && (params || plen))
 +              return -EINVAL;
  
 -      /* Set does NOT take qualifiers */
 -      ASSERT(!set || (!params && !plen));
 +      /* Get must have return space;*/
 +      if (!set && !(arg && len))
 +              return -EINVAL;
  
        /* Look up var locally; if not found pass to host driver */
 -      vi = bcm_iovar_lookup(dhdsdio_iovars, name);
 +      vi = brcmu_iovar_lookup(brcmf_sdio_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);
 +              brcmf_sdbrcm_clkctl(bus, CLK_AVAIL, false);
 +
 +              bcmerror = brcmf_sdcard_iovar_op(bus->card, name, params, plen,
 +                                               arg, len, set);
  
 -              bcmerror =
 -                  bcmsdh_iovar_op(bus->sdh, name, params, plen, arg, len,
 -                                  set);
 -
 -              /* Check for bus configuration changes of interest */
 -
 -              /* 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;
 -                              DHD_ERROR(("%s: fail on %s get\n", __func__,
 -                                         "sd_blocksize"));
 +                              BRCMF_ERROR(("%s: fail on %s get\n", __func__,
 +                                           "sd_blocksize"));
                        } else {
 -                              DHD_INFO(("%s: noted %s update, value now %d\n",
 -                                        __func__, "sd_blocksize",
 -                                        bus->blocksize));
 +                              BRCMF_INFO(("%s: noted sd_blocksize update,"
 +                                          " value now %d\n", __func__,
 +                                          bus->blocksize));
                        }
                }
                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;
        }
  
 -      DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__,
 -               name, (set ? "set" : "get"), len, plen));
 +      BRCMF_CTL(("%s: %s %s, len %d plen %d\n", __func__,
 +                 name, (set ? "set" : "get"), len, plen));
  
        /* set up 'params' pointer in case this is a set command so that
         * the convenience int and bool code can be common to set and get
                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;
        uint retries;
        int err;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_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);
 +      w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, hostintmask), &retries);
        local_hostintmask = bus->hostintmask;
        bus->hostintmask = 0;
  
        /* Change our idea of bus state */
 -      bus->dhd->busstate = DHD_BUS_DOWN;
 +      bus->drvr->busstate = BRCMF_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",
 -                         __func__, err));
 +              BRCMF_ERROR(("%s: Failed to force clock for F2: err %d\n",
 +                           __func__, err));
        }
  
        /* 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_INTR(("%s: disable SDIO interrupts\n", __func__));
 +      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);
 +      w_sdreg32(bus, local_hostintmask,
 +                offsetof(struct sdpcmd_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;
        u8 saveclk;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
 +
 +      /* try to download image and nvram to the dongle */
 +      if (drvr->busstate == BRCMF_BUS_DOWN) {
 +              if (!(brcmf_sdbrcm_download_firmware(bus, bus->card)))
 +                      return -1;
 +      }
  
 -      ASSERT(bus->dhd);
 -      if (!bus->dhd)
 +      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",
 -                         __func__, err));
 +              BRCMF_ERROR(("%s: Failed to force clock for F2: err %d\n",
 +                           __func__, err));
                goto exit;
        }
  
        /* Enable function 2 (frame transfers) */
 -      W_SDREG((SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT),
 -              &bus->regs->tosbmailboxdata, retries);
 +      w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT,
 +                offsetof(struct sdpcmd_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, BRCMF_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));
 +      BRCMF_INFO(("%s: enable 0x%02x, ready 0x%02x (waited %uus)\n",
 +                  __func__, enable, ready, tmo.elapsed));
  
        /* If F2 successfully enabled, set core and enable interrupts */
        if (ready == enable) {
                /* Set up the interrupt mask and enable interrupts */
                bus->hostintmask = HOSTINTMASK;
 -              W_SDREG(bus->hostintmask,
 -                      (unsigned int *)CORE_BUS_REG(bus->ci->buscorebase,
 -                      hostintmask), retries);
 +              w_sdreg32(bus, bus->hostintmask,
 +                        offsetof(struct sdpcmd_regs, 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 = BRCMF_BUS_DATA;
  
                bus->intdis = false;
                if (bus->intr) {
 -                      DHD_INTR(("%s: enable SDIO device interrupts\n",
 -                                __func__));
 -                      bcmsdh_intr_enable(bus->sdh);
 +                      BRCMF_INTR(("%s: enable SDIO device interrupts\n",
 +                                  __func__));
 +                      brcmf_sdcard_intr_enable(bus->card);
                } else {
 -                      DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
 -                      bcmsdh_intr_disable(bus->sdh);
 +                      BRCMF_INTR(("%s: disable SDIO interrupts\n", __func__));
 +                      brcmf_sdcard_intr_disable(bus->card);
                }
  
        }
        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);
 +              BRCMF_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 != BRCMF_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;
        uint retries = 0;
        u16 lastrbc;
        u8 hi, lo;
        int err;
  
 -      DHD_ERROR(("%s: %sterminate frame%s\n", __func__,
 -                 (abort ? "abort command, " : ""),
 -                 (rtx ? ", send NAK" : "")));
 +      BRCMF_ERROR(("%s: %sterminate frame%s\n", __func__,
 +                   (abort ? "abort command, " : ""),
 +                   (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))
                        break;
  
                if ((hi > (lastrbc >> 8)) && (lo > (lastrbc & 0x00ff))) {
 -                      DHD_ERROR(("%s: count growing: last 0x%04x now "
 -                              "0x%04x\n",
 -                              __func__, lastrbc, ((hi << 8) + lo)));
 +                      BRCMF_ERROR(("%s: count growing: last 0x%04x now "
 +                                   "0x%04x\n",
 +                                   __func__, lastrbc, ((hi << 8) + lo)));
                }
                lastrbc = (hi << 8) + lo;
        }
  
        if (!retries) {
 -              DHD_ERROR(("%s: count never zeroed: last 0x%04x\n",
 -                         __func__, lastrbc));
 +              BRCMF_ERROR(("%s: count never zeroed: last 0x%04x\n",
 +                           __func__, lastrbc));
        } else {
 -              DHD_INFO(("%s: flush took %d iterations\n", __func__,
 -                        (0xffff - retries)));
 +              BRCMF_INFO(("%s: flush took %d iterations\n", __func__,
 +                          (0xffff - retries)));
        }
  
        if (rtx) {
                bus->rxrtx++;
 -              W_SDREG(SMB_NAK, &regs->tosbmailbox, retries);
 +              w_sdreg32(bus, SMB_NAK,
 +                        offsetof(struct sdpcmd_regs, tosbmailbox), &retries);
 +
                bus->f1regdata++;
                if (retries <= retry_limit)
                        bus->rxskip = true;
        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 = BRCMF_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;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* Control data already received in aligned rxctl */
        if ((bus->bus == SPI_BUS) && (!bus->usebufpool))
                goto gotpkt;
  
 -      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);
  
        /* Copy the already-read portion over */
        memcpy(bus->rxctl, hdr, firstread);
        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 */
                rdlen = roundup(rdlen, ALIGNMENT);
  
        /* Drop if the read is too big or it exceeds our maximum */
 -      if ((rdlen + firstread) > bus->dhd->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);
 +      if ((rdlen + firstread) > bus->drvr->maxctl) {
 +              BRCMF_ERROR(("%s: %d-byte control read exceeds %d-byte"
 +                           " buffer\n", __func__, rdlen, bus->drvr->maxctl));
 +              bus->drvr->rx_errors++;
 +              brcmf_sdbrcm_rxfail(bus, false, false);
                goto done;
        }
  
 -      if ((len - doff) > bus->dhd->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++;
 +      if ((len - doff) > bus->drvr->maxctl) {
 +              BRCMF_ERROR(("%s: %d-byte ctl frame (%d-byte ctl data) exceeds "
 +                           "%d-byte limit\n",
 +                           __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++;
 -      ASSERT(sdret != -BCME_PENDING);
  
        /* Control frame failures need retransmission */
        if (sdret < 0) {
 -              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_ERROR(("%s: read %d control bytes failed: %d\n",
 +                           __func__, rdlen, sdret));
 +              bus->rxc_errors++;
 +              brcmf_sdbrcm_rxfail(bus, true, true);
                goto done;
        }
  
  gotpkt:
  
 -#ifdef DHD_DEBUG
 -      if (DHD_BYTES_ON() && DHD_CTL_ON()) {
 +#ifdef BCMDBG
 +      if (BRCMF_BYTES_ON() && BRCMF_CTL_ON()) {
                printk(KERN_DEBUG "RxCtrl:\n");
                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, bus->rxctl, len);
        }
  
  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;
        /* 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,
 -                 bus->glom));
 +      BRCMF_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;
                if (!dlen || (dlen & 1)) {
 -                      DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n",
 -                      __func__, dlen));
 +                      BRCMF_ERROR(("%s: bad glomd len(%d),"
 +                                   " ignore descriptor\n",
 +                                   __func__, dlen));
                        dlen = 0;
                }
  
                        dptr += sizeof(u16);
                        if ((sublen < SDPCM_HDRLEN) ||
                            ((num == 0) && (sublen < (2 * SDPCM_HDRLEN)))) {
 -                              DHD_ERROR(("%s: descriptor len %d bad: %d\n",
 -                                         __func__, num, sublen));
 +                              BRCMF_ERROR(("%s: descriptor len %d bad: %d\n",
 +                                           __func__, num, sublen));
                                pnext = NULL;
                                break;
                        }
 -                      if (sublen % DHD_SDALIGN) {
 -                              DHD_ERROR(("%s: sublen %d not multiple of %d\n",
 -                              __func__, sublen, DHD_SDALIGN));
 +                      if (sublen % BRCMF_SDALIGN) {
 +                              BRCMF_ERROR(("%s: sublen %d not multiple of"
 +                                           " %d\n", __func__, sublen,
 +                                           BRCMF_SDALIGN));
                                usechain = false;
                        }
                        totlen += sublen;
                        }
  
                        /* 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__,
 -                                      num, sublen));
 +                              BRCMF_ERROR(("%s: bcm_pkt_buf_get_skb failed, "
 +                                           "num %d len %d\n", __func__,
 +                                           num, sublen));
                                break;
                        }
 -                      ASSERT(!(pnext->prev));
                        if (!pfirst) {
 -                              ASSERT(!plast);
                                pfirst = plast = pnext;
                        } else {
 -                              ASSERT(plast);
                                plast->next = pnext;
                                plast = pnext;
                        }
  
                        /* Adhere to start alignment requirements */
 -                      PKTALIGN(pnext, sublen, DHD_SDALIGN);
 +                      PKTALIGN(pnext, sublen, BRCMF_SDALIGN);
                }
  
                /* If all allocations succeeded, save packet chain
                         in bus structure */
                if (pnext) {
 -                      DHD_GLOM(("%s: allocated %d-byte packet chain for %d "
 -                              "subframes\n", __func__, totlen, num));
 -                      if (DHD_GLOM_ON() && bus->nextlen) {
 +                      BRCMF_GLOM(("%s: allocated %d-byte packet chain for %d "
 +                                  "subframes\n", __func__, totlen, num));
 +                      if (BRCMF_GLOM_ON() && bus->nextlen) {
                                if (totlen != bus->nextlen) {
 -                                      DHD_GLOM(("%s: glomdesc mismatch: nextlen %d glomdesc %d " "rxseq %d\n",
 -                                              __func__, bus->nextlen,
 -                                              totlen, rxseq));
 +                                      BRCMF_GLOM(("%s: glomdesc mismatch: "
 +                                                  "nextlen %d glomdesc %d "
 +                                                  "rxseq %d\n", __func__,
 +                                                  bus->nextlen,
 +                                                  totlen, rxseq));
                                }
                        }
                        bus->glom = pfirst;
                        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,
                 or had one from before */
        if (bus->glom) {
 -              if (DHD_GLOM_ON()) {
 -                      DHD_GLOM(("%s: try superframe read, packet chain:\n",
 -                              __func__));
 +              if (BRCMF_GLOM_ON()) {
 +                      BRCMF_GLOM(("%s: try superframe read, packet chain:\n",
 +                                  __func__));
                        for (pnext = bus->glom; pnext; pnext = pnext->next) {
 -                              DHD_GLOM(("    %p: %p len 0x%04x (%d)\n",
 -                                        pnext, (u8 *) (pnext->data),
 -                                        pnext->len, pnext->len));
 +                              BRCMF_GLOM(("    %p: %p len 0x%04x (%d)\n",
 +                                          pnext, (u8 *) (pnext->data),
 +                                          pnext->len, pnext->len));
                        }
                }
  
                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",
 -                                      __func__, dlen, sublen));
 +                              BRCMF_ERROR(("%s: FAILED TO COPY, dlen %d "
 +                                           "sublen %d\n",
 +                                           __func__, dlen, sublen));
                                errcode = -1;
                        }
                        pnext = NULL;
                } else {
 -                      DHD_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, FORCE FAILURE\n",
 -                              dlen));
 +                      BRCMF_ERROR(("COULDN'T ALLOC %d-BYTE GLOM, "
 +                                   "FORCE FAILURE\n", dlen));
                        errcode = -1;
                }
                bus->f2rxdata++;
 -              ASSERT(errcode != -BCME_PENDING);
  
                /* On failure, kill the superframe, allow a couple retries */
                if (errcode < 0) {
 -                      DHD_ERROR(("%s: glom read of %d bytes failed: %d\n",
 -                                 __func__, dlen, errcode));
 -                      bus->dhd->rx_errors++;
 +                      BRCMF_ERROR(("%s: glom read of %d bytes failed: %d\n",
 +                                   __func__, dlen, errcode));
 +                      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
 -              if (DHD_GLOM_ON()) {
 +#ifdef BCMDBG
 +              if (BRCMF_GLOM_ON()) {
                        printk(KERN_DEBUG "SUPERFRAME:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                pfirst->data, min_t(int, pfirst->len, 48));
                seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]);
                bus->nextlen = dptr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET];
                if ((bus->nextlen << 4) > MAX_RX_DATASZ) {
 -                      DHD_INFO(("%s: nextlen too large (%d) seq %d\n",
 -                              __func__, bus->nextlen, seq));
 +                      BRCMF_INFO(("%s: nextlen too large (%d) seq %d\n",
 +                                  __func__, bus->nextlen, seq));
                        bus->nextlen = 0;
                }
                doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]);
  
                errcode = 0;
                if ((u16)~(sublen ^ check)) {
 -                      DHD_ERROR(("%s (superframe): HW hdr error: len/check "
 -                              "0x%04x/0x%04x\n", __func__, sublen, check));
 +                      BRCMF_ERROR(("%s (superframe): HW hdr error: len/check "
 +                                   "0x%04x/0x%04x\n", __func__, sublen,
 +                                   check));
                        errcode = -1;
                } else if (roundup(sublen, bus->blocksize) != dlen) {
 -                      DHD_ERROR(("%s (superframe): len 0x%04x, rounded "
 -                              "0x%04x, expect 0x%04x\n",
 -                              __func__, sublen,
 -                              roundup(sublen, bus->blocksize), dlen));
 +                      BRCMF_ERROR(("%s (superframe): len 0x%04x, rounded "
 +                                   "0x%04x, expect 0x%04x\n",
 +                                   __func__, sublen,
 +                                   roundup(sublen, bus->blocksize), dlen));
                        errcode = -1;
                } else if (SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]) !=
                           SDPCM_GLOM_CHANNEL) {
 -                      DHD_ERROR(("%s (superframe): bad channel %d\n",
 +                      BRCMF_ERROR(("%s (superframe): bad channel %d\n",
                                   __func__,
                                   SDPCM_PACKET_CHANNEL(&dptr
                                                        [SDPCM_FRAMETAG_LEN])));
                        errcode = -1;
                } else if (SDPCM_GLOMDESC(&dptr[SDPCM_FRAMETAG_LEN])) {
 -                      DHD_ERROR(("%s (superframe): got second descriptor?\n",
 -                                 __func__));
 +                      BRCMF_ERROR(("%s (superframe): got 2nd descriptor?\n",
 +                                   __func__));
                        errcode = -1;
                } else if ((doff < SDPCM_HDRLEN) ||
                           (doff > (pfirst->len - SDPCM_HDRLEN))) {
 -                      DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d "
 -                              "pkt %d min %d\n",
 -                              __func__, doff, sublen,
 -                              pfirst->len, SDPCM_HDRLEN));
 +                      BRCMF_ERROR(("%s (superframe): Bad data offset %d: "
 +                                   "HW %d pkt %d min %d\n",
 +                                   __func__, doff, sublen,
 +                                   pfirst->len, SDPCM_HDRLEN));
                        errcode = -1;
                }
  
                /* Check sequence number of superframe SW header */
                if (rxseq != seq) {
 -                      DHD_INFO(("%s: (superframe) rx_seq %d, expected %d\n",
 -                                __func__, seq, rxseq));
 +                      BRCMF_INFO(("%s: (superframe) rx_seq %d, expected %d\n",
 +                                  __func__, seq, rxseq));
                        bus->rx_badseq++;
                        rxseq = seq;
                }
  
                /* Check window for sanity */
                if ((u8) (txmax - bus->tx_seq) > 0x40) {
 -                      DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
 -                              __func__, txmax, bus->tx_seq));
 +                      BRCMF_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
 +                                   __func__, txmax, bus->tx_seq));
                        txmax = bus->tx_seq + 2;
                }
                bus->tx_max = txmax;
                        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
 -                      if (DHD_GLOM_ON()) {
 +#ifdef BCMDBG
 +                      if (BRCMF_GLOM_ON()) {
                                printk(KERN_DEBUG "subframe:\n");
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                                     dptr, 32);
  #endif
  
                        if ((u16)~(sublen ^ check)) {
 -                              DHD_ERROR(("%s (subframe %d): HW hdr error: "
 -                                         "len/check 0x%04x/0x%04x\n",
 -                                         __func__, num, sublen, check));
 +                              BRCMF_ERROR(("%s (subframe %d): HW hdr error: "
 +                                           "len/check 0x%04x/0x%04x\n",
 +                                           __func__, num, sublen, check));
                                errcode = -1;
                        } else if ((sublen > dlen) || (sublen < SDPCM_HDRLEN)) {
 -                              DHD_ERROR(("%s (subframe %d): length mismatch: "
 -                                         "len 0x%04x, expect 0x%04x\n",
 -                                         __func__, num, sublen, dlen));
 +                              BRCMF_ERROR(("%s (subframe %d): length mismatch"
 +                                           ": len 0x%04x, expect 0x%04x\n",
 +                                           __func__, num, sublen, dlen));
                                errcode = -1;
                        } else if ((chan != SDPCM_DATA_CHANNEL) &&
                                   (chan != SDPCM_EVENT_CHANNEL)) {
 -                              DHD_ERROR(("%s (subframe %d): bad channel %d\n",
 -                                         __func__, num, chan));
 +                              BRCMF_ERROR(("%s (subframe %d): bad channel"
 +                                           " %d\n", __func__, num, chan));
                                errcode = -1;
                        } else if ((doff < SDPCM_HDRLEN) || (doff > sublen)) {
 -                              DHD_ERROR(("%s (subframe %d): Bad data offset %d: HW %d min %d\n",
 -                                      __func__, num, doff, sublen,
 -                                      SDPCM_HDRLEN));
 +                              BRCMF_ERROR(("%s (subframe %d): Bad data offset"
 +                                           " %d: HW %d min %d\n",
 +                                           __func__, num, doff, sublen,
 +                                           SDPCM_HDRLEN));
                                errcode = -1;
                        }
                }
                        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;
                        }
                bus->glom = NULL;
                plast = NULL;
  
 -              dhd_os_sdlock_rxq(bus->dhd);
                for (num = 0; pfirst; rxseq++, pfirst = pnext) {
                        pnext = pfirst->next;
                        pfirst->next = NULL;
                        seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]);
                        doff = SDPCM_DOFFSET_VALUE(&dptr[SDPCM_FRAMETAG_LEN]);
  
 -                      DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d "
 -                              "chan %d seq %d\n",
 -                              __func__, num, pfirst, pfirst->data,
 -                              pfirst->len, sublen, chan, seq));
 +                      BRCMF_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d "
 +                                  "chan %d seq %d\n",
 +                                  __func__, num, pfirst, pfirst->data,
 +                                  pfirst->len, sublen, chan, seq));
  
 -                      ASSERT((chan == SDPCM_DATA_CHANNEL)
 -                             || (chan == SDPCM_EVENT_CHANNEL));
 +                      /* precondition: chan == SDPCM_DATA_CHANNEL ||
 +                                       chan == SDPCM_EVENT_CHANNEL */
  
                        if (rxseq != seq) {
 -                              DHD_GLOM(("%s: rx_seq %d, expected %d\n",
 -                                        __func__, seq, rxseq));
 +                              BRCMF_GLOM(("%s: rx_seq %d, expected %d\n",
 +                                          __func__, seq, rxseq));
                                bus->rx_badseq++;
                                rxseq = seq;
                        }
 -#ifdef DHD_DEBUG
 -                      if (DHD_BYTES_ON() && DHD_DATA_ON()) {
 +#ifdef BCMDBG
 +                      if (BRCMF_BYTES_ON() && BRCMF_DATA_ON()) {
                                printk(KERN_DEBUG "Rx Subframe Data:\n");
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                                     dptr, dlen);
                        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 {
 -                                      ASSERT(save_pfirst == pfirst);
                                        save_pfirst = pnext;
                                }
                                continue;
 -                      } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pfirst) !=
 -                                 0) {
 -                              DHD_ERROR(("%s: rx protocol error\n",
 -                                         __func__));
 -                              bus->dhd->rx_errors++;
 -                              bcm_pkt_buf_free_skb(pfirst);
 +                      } else if (brcmf_proto_hdrpull(bus->drvr, &ifidx, pfirst)
 +                                      != 0) {
 +                              BRCMF_ERROR(("%s: rx protocol error\n",
 +                                           __func__));
 +                              bus->drvr->rx_errors++;
 +                              brcmu_pkt_buf_free_skb(pfirst);
                                if (plast) {
                                        plast->next = pnext;
                                } else {
 -                                      ASSERT(save_pfirst == pfirst);
                                        save_pfirst = pnext;
                                }
                                continue;
                        plast = pfirst;
                        num++;
  
 -#ifdef DHD_DEBUG
 -                      if (DHD_GLOM_ON()) {
 -                              DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) "
 -                              "nxt/lnk %p/%p\n",
 -                              __func__, num, pfirst, pfirst->data,
 -                              pfirst->len, pfirst->next,
 -                              pfirst->prev));
 +#ifdef BCMDBG
 +                      if (BRCMF_GLOM_ON()) {
 +                              BRCMF_GLOM(("%s subframe %d to stack, %p"
 +                                          "(%p/%d) nxt/lnk %p/%p\n",
 +                                          __func__, num, pfirst, pfirst->data,
 +                                          pfirst->len, pfirst->next,
 +                                          pfirst->prev));
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                                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++;
  }
  
  /* 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 */
        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 */
        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
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 -
 -      ASSERT(maxframes);
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
  #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;
        }
        *finished = false;
  
        for (rxseq = bus->rx_seq, rxleft = maxframes;
 -           !bus->rxskip && rxleft && bus->dhd->busstate != DHD_BUS_DOWN;
 +           !bus->rxskip && rxleft && bus->drvr->busstate != BRCMF_BUS_DOWN;
             rxseq++, rxleft--) {
  
                /* Handle glomming separately */
                if (bus->glom || bus->glomd) {
                        u8 cnt;
 -                      DHD_GLOM(("%s: calling rxglom: glomd %p, glom %p\n",
 -                                __func__, bus->glomd, bus->glom));
 -                      cnt = dhdsdio_rxglom(bus, rxseq);
 -                      DHD_GLOM(("%s: rxglom returned %d\n", __func__, cnt));
 +                      BRCMF_GLOM(("%s: calling rxglom: glomd %p, glom %p\n",
 +                                  __func__, bus->glomd, bus->glom));
 +                      cnt = brcmf_sdbrcm_rxglom(bus, rxseq);
 +                      BRCMF_GLOM(("%s: rxglom returned %d\n", __func__, cnt));
                        rxseq += cnt - 1;
                        rxleft = (rxleft > cnt) ? (rxleft - cnt) : 1;
                        continue;
                }
  
                /* Try doing single read if we can */
 -              if (dhd_readahead && bus->nextlen) {
 +              if (brcmf_readahead && bus->nextlen) {
                        u16 nextlen = bus->nextlen;
                        bus->nextlen = 0;
  
                                            && ((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);
                                }
                        }
  
                         * 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);
  
                                        /* Control frame failures need
                                         retransmission */
                                        if (sdret < 0) {
 -                                              DHD_ERROR(("%s: read %d control bytes failed: %d\n",
 -                                                      __func__,
 -                                                      rdlen, sdret));
 +                                              BRCMF_ERROR(("%s: read %d "
 +                                                           "control bytes "
 +                                                           "failed: %d\n",
 +                                                           __func__,
 +                                                           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);
                                } else {
                                        /* Give up on data,
                                        request rtx of events */
 -                                      DHD_ERROR(("%s (nextlen): "
 -                                                 "bcm_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);
 +                                      BRCMF_ERROR(("%s (nextlen): "
 +                                                   "brcmu_pkt_buf_get_skb "
 +                                                   "failed:"
 +                                                   " len %d rdlen %d expected"
 +                                                   " rxseq %d\n", __func__,
 +                                                   len, rdlen, rxseq));
                                        continue;
                                }
                        } else {
                                if (bus->bus == SPI_BUS)
                                        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);
                                bus->f2rxdata++;
 -                              ASSERT(sdret != -BCME_PENDING);
  
                                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);
 +                                      BRCMF_ERROR(("%s (nextlen): read %d"
 +                                                   " bytes failed: %d\n",
 +                                                   __func__, rdlen, sdret));
 +                                      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);
  
                        /* All zeros means readahead info was bad */
                        if (!(len | check)) {
 -                              DHD_INFO(("%s (nextlen): read zeros in HW "
 -                                      "header???\n", __func__));
 -                              dhdsdio_pktfree2(bus, pkt);
 +                              BRCMF_INFO(("%s (nextlen): read zeros in HW "
 +                                          "header???\n", __func__));
 +                              brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
  
                        /* Validate check bytes */
                        if ((u16)~(len ^ check)) {
 -                              DHD_ERROR(("%s (nextlen): HW hdr error:"
 -                                      " nextlen/len/check"
 -                                      " 0x%04x/0x%04x/0x%04x\n",
 -                                      __func__, nextlen, len, check));
 +                              BRCMF_ERROR(("%s (nextlen): HW hdr error:"
 +                                           " nextlen/len/check"
 +                                           " 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;
                        }
  
                        /* Validate frame length */
                        if (len < SDPCM_HDRLEN) {
 -                              DHD_ERROR(("%s (nextlen): HW hdr length "
 -                                      "invalid: %d\n", __func__, len));
 -                              dhdsdio_pktfree2(bus, pkt);
 +                              BRCMF_ERROR(("%s (nextlen): HW hdr length "
 +                                           "invalid: %d\n", __func__, len));
 +                              brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
  
                        if (len_consistent) {
                                /* Mismatch, force retry w/normal
                                        header (may be >4K) */
 -                              DHD_ERROR(("%s (nextlen): mismatch, "
 -                                      "nextlen %d len %d rnd %d; "
 -                                      "expected rxseq %d\n",
 -                                      __func__, nextlen,
 -                                      len, roundup(len, 16), rxseq));
 -                              dhdsdio_rxfail(bus, true, (bus->bus != SPI_BUS));
 -                              dhdsdio_pktfree2(bus, pkt);
 +                              BRCMF_ERROR(("%s (nextlen): mismatch, "
 +                                           "nextlen %d len %d rnd %d; "
 +                                           "expected rxseq %d\n",
 +                                           __func__, nextlen,
 +                                           len, roundup(len, 16), rxseq));
 +                              brcmf_sdbrcm_rxfail(bus, true,
 +                                                bus->bus != SPI_BUS);
 +                              brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
  
                            bus->rxhdr[SDPCM_FRAMETAG_LEN +
                                       SDPCM_NEXTLEN_OFFSET];
                        if ((bus->nextlen << 4) > MAX_RX_DATASZ) {
 -                              DHD_INFO(("%s (nextlen): got frame w/nextlen too large" " (%d), seq %d\n",
 -                                      __func__, bus->nextlen, seq));
 +                              BRCMF_INFO(("%s (nextlen): got frame w/nextlen"
 +                                          " too large (%d), seq %d\n",
 +                                          __func__, bus->nextlen, seq));
                                bus->nextlen = 0;
                        }
  
 -                      bus->dhd->rx_readahead_cnt++;
 +                      bus->drvr->rx_readahead_cnt++;
  
                        /* Handle Flow Control */
                        fcbits = SDPCM_FCMASK_VALUE(
  
                        /* Check and update sequence number */
                        if (rxseq != seq) {
 -                              DHD_INFO(("%s (nextlen): rx_seq %d, expected "
 -                                      "%d\n", __func__, seq, rxseq));
 +                              BRCMF_INFO(("%s (nextlen): rx_seq %d, expected "
 +                                          "%d\n", __func__, seq, rxseq));
                                bus->rx_badseq++;
                                rxseq = seq;
                        }
  
                        /* Check window for sanity */
                        if ((u8) (txmax - bus->tx_seq) > 0x40) {
 -                              DHD_ERROR(("%s: got unlikely tx max %d with "
 -                                      "tx_seq %d\n",
 -                                      __func__, txmax, bus->tx_seq));
 +                              BRCMF_ERROR(("%s: got unlikely tx max %d with "
 +                                           "tx_seq %d\n",
 +                                           __func__, txmax, bus->tx_seq));
                                txmax = bus->tx_seq + 2;
                        }
                        bus->tx_max = txmax;
  
 -#ifdef DHD_DEBUG
 -                      if (DHD_BYTES_ON() && DHD_DATA_ON()) {
 +#ifdef BCMDBG
 +                      if (BRCMF_BYTES_ON() && BRCMF_DATA_ON()) {
                                printk(KERN_DEBUG "Rx Data:\n");
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                                     rxbuf, len);
 -                      } else if (DHD_HDRS_ON()) {
 +                      } else if (BRCMF_HDRS_ON()) {
                                printk(KERN_DEBUG "RxHdr:\n");
                                print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                                     bus->rxhdr, SDPCM_HDRLEN);
  
                        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));
 +                                      BRCMF_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;
                        }
  
                        if ((bus->bus == SPI_BUS) && !bus->usebufpool) {
 -                              DHD_ERROR(("Received %d bytes on %d channel. Running out of " "rx pktbuf's or not yet malloced.\n",
 -                                      len, chan));
 +                              BRCMF_ERROR(("Received %d bytes on %d channel."
 +                                           " Running out of " "rx pktbuf's or"
 +                                           " not yet malloced.\n",
 +                                           len, chan));
                                continue;
                        }
  
                        /* Validate data offset */
                        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_ERROR(("%s (nextlen): bad data offset %d:"
 +                                           " HW len %d min %d\n", __func__,
 +                                           doff, len, SDPCM_HDRLEN));
 +                              brcmf_sdbrcm_rxfail(bus, false, false);
 +                              brcmf_sdbrcm_pktfree2(bus, pkt);
                                continue;
                        }
  
                        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++;
 -              ASSERT(sdret != -BCME_PENDING);
  
                if (sdret < 0) {
 -                      DHD_ERROR(("%s: RXHEADER FAILED: %d\n", __func__,
 -                                 sdret));
 +                      BRCMF_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
 -              if (DHD_BYTES_ON() || DHD_HDRS_ON()) {
 +#ifdef BCMDBG
 +              if (BRCMF_BYTES_ON() || BRCMF_HDRS_ON()) {
                        printk(KERN_DEBUG "RxHdr:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                             bus->rxhdr, SDPCM_HDRLEN);
  
                /* Validate check bytes */
                if ((u16) ~(len ^ check)) {
 -                      DHD_ERROR(("%s: HW hdr err: len/check 0x%04x/0x%04x\n",
 -                              __func__, len, check));
 +                      BRCMF_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;
                }
  
                /* Validate frame length */
                if (len < SDPCM_HDRLEN) {
 -                      DHD_ERROR(("%s: HW hdr length invalid: %d\n",
 -                                 __func__, len));
 +                      BRCMF_ERROR(("%s: HW hdr length invalid: %d\n",
 +                                   __func__, len));
                        continue;
                }
  
  
                /* Validate data offset */
                if ((doff < SDPCM_HDRLEN) || (doff > len)) {
 -                      DHD_ERROR(("%s: Bad data offset %d: HW len %d, min %d "
 -                              "seq %d\n",
 -                              __func__, doff, len, SDPCM_HDRLEN, seq));
 +                      BRCMF_ERROR(("%s: Bad data offset %d: HW len %d,"
 +                                   " min %d seq %d\n", __func__, doff,
 +                                   len, SDPCM_HDRLEN, seq));
                        bus->rx_badhdr++;
 -                      ASSERT(0);
 -                      dhdsdio_rxfail(bus, false, false);
 +                      brcmf_sdbrcm_rxfail(bus, false, false);
                        continue;
                }
  
                bus->nextlen =
                    bus->rxhdr[SDPCM_FRAMETAG_LEN + SDPCM_NEXTLEN_OFFSET];
                if ((bus->nextlen << 4) > MAX_RX_DATASZ) {
 -                      DHD_INFO(("%s (nextlen): got frame w/nextlen too large "
 -                              "(%d), seq %d\n",
 -                              __func__, bus->nextlen, seq));
 +                      BRCMF_INFO(("%s (nextlen): got frame w/nextlen too"
 +                                  " large (%d), seq %d\n",
 +                                  __func__, bus->nextlen, seq));
                        bus->nextlen = 0;
                }
  
  
                /* Check and update sequence number */
                if (rxseq != seq) {
 -                      DHD_INFO(("%s: rx_seq %d, expected %d\n", __func__,
 -                                seq, rxseq));
 +                      BRCMF_INFO(("%s: rx_seq %d, expected %d\n", __func__,
 +                                  seq, rxseq));
                        bus->rx_badseq++;
                        rxseq = seq;
                }
  
                /* Check window for sanity */
                if ((u8) (txmax - bus->tx_seq) > 0x40) {
 -                      DHD_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
 -                              __func__, txmax, bus->tx_seq));
 +                      BRCMF_ERROR(("%s: unlikely tx max %d with tx_seq %d\n",
 +                                   __func__, txmax, bus->tx_seq));
                        txmax = bus->tx_seq + 2;
                }
                bus->tx_max = txmax;
  
                /* 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;
                }
  
 -              ASSERT((chan == SDPCM_DATA_CHANNEL)
 -                     || (chan == SDPCM_EVENT_CHANNEL)
 -                     || (chan == SDPCM_TEST_CHANNEL)
 -                     || (chan == SDPCM_GLOM_CHANNEL));
 +              /* precondition: chan is either SDPCM_DATA_CHANNEL,
 +                 SDPCM_EVENT_CHANNEL, SDPCM_TEST_CHANNEL or
 +                 SDPCM_GLOM_CHANNEL */
  
                /* Length to read */
                rdlen = (len > firstread) ? (len - firstread) : 0;
                        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 */
  
                if ((rdlen + firstread) > MAX_RX_DATASZ) {
                        /* Too long -- skip this frame */
 -                      DHD_ERROR(("%s: too long: len %d rdlen %d\n",
 -                                 __func__, len, rdlen));
 -                      bus->dhd->rx_errors++;
 +                      BRCMF_ERROR(("%s: too long: len %d rdlen %d\n",
 +                                   __func__, len, rdlen));
 +                      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));
 +                      BRCMF_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);
  
                if (sdret < 0) {
 -                      DHD_ERROR(("%s: read %d %s bytes failed: %d\n",
 -                                 __func__, rdlen,
 -                                 ((chan ==
 -                                   SDPCM_EVENT_CHANNEL) ? "event" : ((chan ==
 -                                      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));
 +                      BRCMF_ERROR(("%s: read %d %s bytes failed: %d\n",
 +                                   __func__, rdlen,
 +                                   ((chan == SDPCM_EVENT_CHANNEL) ? "event"
 +                                   : ((chan == SDPCM_DATA_CHANNEL) ? "data"
 +                                   : "test")), sdret));
 +                      brcmu_pkt_buf_free_skb(pkt);
 +                      bus->drvr->rx_errors++;
 +                      brcmf_sdbrcm_rxfail(bus, true, RETRYCHAN(chan));
                        continue;
                }
  
                skb_push(pkt, firstread);
                memcpy(pkt->data, bus->rxhdr, firstread);
  
 -#ifdef DHD_DEBUG
 -              if (DHD_BYTES_ON() && DHD_DATA_ON()) {
 +#ifdef BCMDBG
 +              if (BRCMF_BYTES_ON() && BRCMF_DATA_ON()) {
                        printk(KERN_DEBUG "Rx Data:\n");
                        print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
                                             pkt->data, len);
@@@ -4512,10 -4089,10 +4459,10 @@@ deliver
                /* Save superframe descriptor and allocate packet frame */
                if (chan == SDPCM_GLOM_CHANNEL) {
                        if (SDPCM_GLOMDESC(&bus->rxhdr[SDPCM_FRAMETAG_LEN])) {
 -                              DHD_GLOM(("%s: glom descriptor, %d bytes:\n",
 -                                      __func__, len));
 -#ifdef DHD_DEBUG
 -                              if (DHD_GLOM_ON()) {
 +                              BRCMF_GLOM(("%s: glom descriptor, %d bytes:\n",
 +                                          __func__, len));
 +#ifdef BCMDBG
 +                              if (BRCMF_GLOM_ON()) {
                                        printk(KERN_DEBUG "Glom Data:\n");
                                        print_hex_dump_bytes("",
                                                             DUMP_PREFIX_OFFSET,
                                }
  #endif
                                __skb_trim(pkt, len);
 -                              ASSERT(doff == SDPCM_HDRLEN);
                                skb_pull(pkt, SDPCM_HDRLEN);
                                bus->glomd = pkt;
                        } else {
 -                              DHD_ERROR(("%s: glom superframe w/o "
 -                                      "descriptor!\n", __func__));
 -                              dhdsdio_rxfail(bus, false, false);
 +                              BRCMF_ERROR(("%s: glom superframe w/o "
 +                                           "descriptor!\n", __func__));
 +                              brcmf_sdbrcm_rxfail(bus, false, false);
                        }
                        continue;
                }
  #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) {
 -                      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++;
 +              } else if (brcmf_proto_hdrpull(bus->drvr, &ifidx, pkt) != 0) {
 +                      BRCMF_ERROR(("%s: rx protocol error\n", __func__));
 +                      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));
 +              BRCMF_DATA(("%s: hit rx limit of %d frames\n", __func__,
 +                          maxframes));
        else
 -#endif                                /* DHD_DEBUG */
 -              DHD_DATA(("%s: processed %d frames\n", __func__, rxcount));
 +#endif                                /* BCMDBG */
 +              BRCMF_DATA(("%s: processed %d frames\n", __func__, rxcount));
        /* Back off rxseq if awaiting rtx, update rx_seq */
        if (bus->rxskip)
                rxseq--;
        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;
        u32 intstatus = 0;
        u32 hmb_data;
        u8 fcbits;
        uint retries = 0;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* Read mailbox data and ack that we did so */
 -      R_SDREG(hmb_data, &regs->tohostmailboxdata, retries);
 +      r_sdreg32(bus, &hmb_data,
 +                offsetof(struct sdpcmd_regs, tohostmailboxdata), &retries);
 +
        if (retries <= retry_limit)
 -              W_SDREG(SMB_INT_ACK, &regs->tosbmailbox, retries);
 +              w_sdreg32(bus, SMB_INT_ACK,
 +                        offsetof(struct sdpcmd_regs, tosbmailbox), &retries);
        bus->f1regdata += 2;
  
        /* Dongle recomposed rx frames, accept them again */
        if (hmb_data & HMB_DATA_NAKHANDLED) {
 -              DHD_INFO(("Dongle reports NAK handled, expect rtx of %d\n",
 -                        bus->rx_seq));
 +              BRCMF_INFO(("Dongle reports NAK handled, expect rtx of %d\n",
 +                          bus->rx_seq));
                if (!bus->rxskip)
 -                      DHD_ERROR(("%s: unexpected NAKHANDLED!\n", __func__));
 +                      BRCMF_ERROR(("%s: unexpected NAKHANDLED!\n", __func__));
  
                bus->rxskip = false;
                intstatus |= I_HMB_FRAME_IND;
                    (hmb_data & HMB_DATA_VERSION_MASK) >>
                    HMB_DATA_VERSION_SHIFT;
                if (bus->sdpcm_ver != SDPCM_PROT_VERSION)
 -                      DHD_ERROR(("Version mismatch, dongle reports %d, "
 -                              "expecting %d\n",
 -                              bus->sdpcm_ver, SDPCM_PROT_VERSION));
 +                      BRCMF_ERROR(("Version mismatch, dongle reports %d, "
 +                                   "expecting %d\n",
 +                                   bus->sdpcm_ver, SDPCM_PROT_VERSION));
                else
 -                      DHD_INFO(("Dongle ready, protocol version %d\n",
 -                                bus->sdpcm_ver));
 +                      BRCMF_INFO(("Dongle ready, protocol version %d\n",
 +                                  bus->sdpcm_ver));
        }
  
        /*
                         HMB_DATA_FC |
                         HMB_DATA_FWREADY |
                         HMB_DATA_FCDATA_MASK | HMB_DATA_VERSION_MASK)) {
 -              DHD_ERROR(("Unknown mailbox data content: 0x%02x\n", hmb_data));
 +              BRCMF_ERROR(("Unknown mailbox data content: 0x%02x\n",
 +                           hmb_data));
        }
  
        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;
        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 */
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* 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;
 -              } else {
 -                      ASSERT(devctl & SBSDIO_DEVCTL_CA_INT_ONLY);
 +                      BRCMF_ERROR(("%s: error reading DEVCTL: %d\n",
 +                                   __func__, err));
 +                      bus->drvr->busstate = BRCMF_BUS_DOWN;
                }
 -#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;
 +                      BRCMF_ERROR(("%s: error reading CSR: %d\n", __func__,
 +                                   err));
 +                      bus->drvr->busstate = BRCMF_BUS_DOWN;
                }
  
 -              DHD_INFO(("DPC: PENDING, devctl 0x%02x clkctl 0x%02x\n", devctl,
 -                        clkctl));
 +              BRCMF_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;
 +                              BRCMF_ERROR(("%s: error reading DEVCTL: %d\n",
 +                                           __func__, err));
 +                              bus->drvr->busstate = BRCMF_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;
 +                              BRCMF_ERROR(("%s: error writing DEVCTL: %d\n",
 +                                           __func__, err));
 +                              bus->drvr->busstate = BRCMF_BUS_DOWN;
                        }
                        bus->clkstate = CLK_AVAIL;
                } else {
        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;
  
        /* Pending interrupt indicates new device status */
        if (bus->ipend) {
                bus->ipend = false;
 -              R_SDREG(newstatus, &regs->intstatus, retries);
 +              r_sdreg32(bus, &newstatus,
 +                        offsetof(struct sdpcmd_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);
                if (newstatus) {
 -                      W_SDREG(newstatus, &regs->intstatus, retries);
 +                      w_sdreg32(bus, newstatus,
 +                                offsetof(struct sdpcmd_regs, intstatus),
 +                                &retries);
                        bus->f1regdata++;
                }
        }
         */
        if (intstatus & I_HMB_FC_CHANGE) {
                intstatus &= ~I_HMB_FC_CHANGE;
 -              W_SDREG(I_HMB_FC_CHANGE, &regs->intstatus, retries);
 -              R_SDREG(newstatus, &regs->intstatus, retries);
 +              w_sdreg32(bus, I_HMB_FC_CHANGE,
 +                        offsetof(struct sdpcmd_regs, intstatus), &retries);
 +
 +              r_sdreg32(bus, &newstatus,
 +                        offsetof(struct sdpcmd_regs, intstatus), &retries);
                bus->f1regdata += 2;
                bus->fcstate =
                    !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE));
        /* 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... */
        if (intstatus & I_WR_OOSYNC) {
 -              DHD_ERROR(("Dongle reports WR_OOSYNC\n"));
 +              BRCMF_ERROR(("Dongle reports WR_OOSYNC\n"));
                intstatus &= ~I_WR_OOSYNC;
        }
  
        if (intstatus & I_RD_OOSYNC) {
 -              DHD_ERROR(("Dongle reports RD_OOSYNC\n"));
 +              BRCMF_ERROR(("Dongle reports RD_OOSYNC\n"));
                intstatus &= ~I_RD_OOSYNC;
        }
  
        if (intstatus & I_SBINT) {
 -              DHD_ERROR(("Dongle reports SBINT\n"));
 +              BRCMF_ERROR(("Dongle reports SBINT\n"));
                intstatus &= ~I_SBINT;
        }
  
        /* Would be active due to wake-wlan in gSPI */
        if (intstatus & I_CHIPACTIVE) {
 -              DHD_INFO(("Dongle reports CHIPACTIVE\n"));
 +              BRCMF_INFO(("Dongle reports CHIPACTIVE\n"));
                intstatus &= ~I_CHIPACTIVE;
        }
  
  
        /* 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);
        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)) {
 -              DHD_INTR(("%s: enable SDIO interrupts, rxdone %d framecnt %d\n",
 -                        __func__, rxdone, framecnt));
 +      if (bus->intr && bus->intdis && !brcmf_sdcard_regfail(card)) {
 +              BRCMF_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);
 -              ASSERT(ret != -BCME_PENDING);
 +              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);
  
                if (ret < 0) {
                        /* On failure, abort the command and
                                terminate the frame */
 -                      DHD_INFO(("%s: sdio error %d, abort command and "
 -                              "terminate frame.\n", __func__, ret));
 +                      BRCMF_INFO(("%s: sdio error %d, abort command and "
 +                                  "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;
                if (ret == 0)
                        bus->tx_seq = (bus->tx_seq + 1) % SDPCM_SEQUENCE_WRAP;
  
 -              DHD_INFO(("Return_dpc value is : %d\n", ret));
 +              BRCMF_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 = rxdone ? txlimit : min(txlimit, brcmf_txminmax);
 +              framecnt = brcmf_sdbrcm_sendfromq(bus, framecnt);
                txlimit -= framecnt;
        }
  
                 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)) {
 -              DHD_ERROR(("%s: failed backplane access over SDIO, halting "
 -                      "operation %d\n", __func__, bcmsdh_regfail(sdh)));
 -              bus->dhd->busstate = DHD_BUS_DOWN;
 +      if ((bus->drvr->busstate == BRCMF_BUS_DOWN) ||
 +          brcmf_sdcard_regfail(card)) {
 +              BRCMF_ERROR(("%s: failed backplane access over SDIO, halting "
 +                           "operation %d\n", __func__,
 +                           brcmf_sdcard_regfail(card)));
 +              bus->drvr->busstate = BRCMF_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__));
 +              BRCMF_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;
        }
  
  
        /* 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);
 +      brcmf_sdbrcm_sdunlock(bus);
  
        return resched;
  }
  
 -bool dhd_bus_dpc(struct dhd_bus *bus)
 +void brcmf_sdbrcm_isr(void *arg)
  {
 -      bool resched;
 +      struct brcmf_bus *bus = (struct brcmf_bus *) arg;
 +      struct brcmf_sdio_card *card;
  
 -      /* Call the DPC directly. */
 -      DHD_TRACE(("Calling dhdsdio_dpc() from %s\n", __func__));
 -      resched = dhdsdio_dpc(bus);
 -
 -      return resched;
 -}
 -
 -void dhdsdio_isr(void *arg)
 -{
 -      dhd_bus_t *bus = (dhd_bus_t *) arg;
 -      bcmsdh_info_t *sdh;
 -
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        if (!bus) {
 -              DHD_ERROR(("%s : bus is null pointer , exit\n", __func__));
 +              BRCMF_ERROR(("%s : bus is null pointer , exit\n", __func__));
                return;
        }
 -      sdh = bus->sdh;
 +      card = bus->card;
  
 -      if (bus->dhd->busstate == DHD_BUS_DOWN) {
 -              DHD_ERROR(("%s : bus is down. we have nothing to do\n",
 +      if (bus->drvr->busstate == BRCMF_BUS_DOWN) {
 +              BRCMF_ERROR(("%s : bus is down. we have nothing to do\n",
                           __func__));
                return;
        }
  
        /* Shouldn't get this interrupt if we're sleeping? */
        if (bus->sleeping) {
 -              DHD_ERROR(("INTERRUPT WHILE SLEEPING??\n"));
 +              BRCMF_ERROR(("INTERRUPT WHILE SLEEPING??\n"));
                return;
        }
  
        /* Disable additional interrupts (is this needed now)? */
        if (bus->intr)
 -              DHD_INTR(("%s: disable SDIO interrupts\n", __func__));
 +              BRCMF_INTR(("%s: disable SDIO interrupts\n", __func__));
        else
 -              DHD_ERROR(("dhdsdio_isr() w/o interrupt configured!\n"));
 +              BRCMF_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))
 +      BRCMF_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;
        }
  
        /* 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;
        }
  
  
                /* 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__));
 +                      BRCMF_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;
  
                default:
 -                      DHD_ERROR(("Unrecognized pktgen mode %d\n",
 -                                 bus->pktgen_mode));
 -                      bcm_pkt_buf_free_skb(pkt, true);
 +                      BRCMF_ERROR(("Unrecognized pktgen mode %d\n",
 +                                   bus->pktgen_mode));
 +                      brcmu_pkt_buf_free_skb(pkt, true);
                        bus->pktgen_count = 0;
                        return;
                }
                        *data++ =
                            SDPCM_TEST_FILL(fillbyte, (u8) bus->pktgen_sent);
  
 -#ifdef DHD_DEBUG
 -              if (DHD_BYTES_ON() && DHD_DATA_ON()) {
 +#ifdef BCMDBG
 +              if (BRCMF_BYTES_ON() && BRCMF_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)
                        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__));
 +              BRCMF_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 */
        *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;
        /* 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);
 +              BRCMF_ERROR(("brcmf_sdbrcm_checkdied: toss runt frame, pktlen "
 +                           "%d\n", pktlen));
 +              brcmu_pkt_buf_free_skb(pkt, false);
                return;
        }
  
        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",
 -                              pktlen, seq, cmd, extra, len));
 -                      bcm_pkt_buf_free_skb(pkt, false);
 +                      BRCMF_ERROR(("brcmf_sdbrcm_checkdied: frame length "
 +                                   "mismatch, pktlen %d seq %d"
 +                                   " cmd %d extra %d len %d\n",
 +                                   pktlen, seq, cmd, extra, len));
 +                      brcmu_pkt_buf_free_skb(pkt, false);
                        return;
                }
        }
                /* 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));
 +                              BRCMF_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",
 -                      pktlen, seq, cmd, extra, len));
 -              bcm_pkt_buf_free_skb(pkt, false);
 +              BRCMF_INFO(("brcmf_sdbrcm_checkdied: unsupported or unknown "
 +                          "command, pktlen %d seq %d" " cmd %d extra %d"
 +                          " len %d\n", pktlen, seq, cmd, extra, len));
 +              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__));
 +      BRCMF_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)) {
  
                        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);
                                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);
  
                        }
                }
                /* 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 == BRCMF_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
  
                        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;
                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;
        return false;
  }
  
 -static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
 -                         u16 slot, u16 func, uint bustype, void *regsva,
 -                         void *sdh)
 +static void *brcmf_sdbrcm_probe(u16 venid, u16 devid, u16 bus_no,
 +                         u16 slot, u16 func, uint bustype, u32 regsva,
 +                         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.
         * first time that the driver is initialized vs subsequent
         * initializations.
         */
 -      dhd_txbound = DHD_TXBOUND;
 -      dhd_rxbound = DHD_RXBOUND;
 -      dhd_alignctl = true;
 +      brcmf_txbound = BRCMF_TXBOUND;
 +      brcmf_rxbound = BRCMF_RXBOUND;
 +      brcmf_alignctl = true;
        sd1idle = true;
 -      dhd_readahead = true;
 +      brcmf_readahead = true;
        retrydata = false;
 -      dhd_dongle_memsize = 0;
 -      dhd_txminmax = DHD_TXMINMAX;
 +      brcmf_dongle_memsize = 0;
 +      brcmf_txminmax = BRCMF_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));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_INFO(("%s: venid 0x%04x devid 0x%04x\n", __func__, venid, devid));
  
 -      /* We make assumptions about address window mappings */
 -      ASSERT((unsigned long)regsva == SI_ENUM_BASE);
 +      /* We make an assumption about address window mappings:
 +       * 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.
        case PCI_VENDOR_ID_BROADCOM:
                break;
        default:
 -              DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid));
 +              BRCMF_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid));
                return NULL;
        }
  
        case BCM4325_D11DUAL_ID:        /* 4325 802.11a/g id */
        case BCM4325_D11G_ID:   /* 4325 802.11g 2.4Ghz band id */
        case BCM4325_D11A_ID:   /* 4325 802.11a 5Ghz band id */
 -              DHD_INFO(("%s: found 4325 Dongle\n", __func__));
 +              BRCMF_INFO(("%s: found 4325 Dongle\n", __func__));
                break;
        case BCM4329_D11NDUAL_ID:       /* 4329 802.11n dualband device */
        case BCM4329_D11N2G_ID: /* 4329 802.11n 2.4G device */
        case BCM4329_D11N5G_ID: /* 4329 802.11n 5G device */
        case 0x4329:
 -              DHD_INFO(("%s: found 4329 Dongle\n", __func__));
 +              BRCMF_INFO(("%s: found 4329 Dongle\n", __func__));
                break;
        case BCM4319_D11N_ID:   /* 4319 802.11n id */
        case BCM4319_D11N2G_ID: /* 4319 802.11n2g id */
        case BCM4319_D11N5G_ID: /* 4319 802.11n5g id */
 -              DHD_INFO(("%s: found 4319 Dongle\n", __func__));
 +              BRCMF_INFO(("%s: found 4319 Dongle\n", __func__));
                break;
        case 0:
 -              DHD_INFO(("%s: allow device id 0, will check chip internals\n",
 -                        __func__));
 +              BRCMF_INFO(("%s: allow device id 0, will check chip"
 +                          " internals\n", __func__));
                break;
  
        default:
 -              DHD_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n",
 -                         __func__, venid, devid));
 +              BRCMF_ERROR(("%s: skipping 0x%04x/0x%04x, not a dongle\n",
 +                           __func__, venid, devid));
                return NULL;
        }
  
        /* 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__));
 +              BRCMF_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->bus = BRCMF_BUS;
        bus->tx_seq = SDPCM_SEQUENCE_WRAP - 1;
        bus->usebufpool = false;        /* Use bufpool if allocated,
                                         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))) {
 +              BRCMF_ERROR(("%s: brcmf_sdbrcm_probe_attach failed\n",
 +                           __func__));
                goto fail;
        }
  
 -      /* Attach to the dhd/OS/network interface */
 -      bus->dhd = dhd_attach(bus, SDPCM_RESERVE);
 -      if (!bus->dhd) {
 -              DHD_ERROR(("%s: dhd_attach failed\n", __func__));
 +      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, "brcmf_dpc");
 +              if (IS_ERR(bus->dpc_tsk)) {
 +                      printk(KERN_WARNING
 +                             "brcmf_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 brcmf/OS/network interface */
 +      bus->drvr = brcmf_attach(bus, SDPCM_RESERVE);
 +      if (!bus->drvr) {
 +              BRCMF_ERROR(("%s: brcmf_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))) {
 +              BRCMF_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))) {
 +              BRCMF_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_INTR(("%s: disable SDIO interrupts (not interested yet)\n",
 +                  __func__));
 +      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",
 -                         __func__, ret));
 +              BRCMF_ERROR(("%s: FAILED: sdcard_intr_reg returned %d\n",
 +                           __func__, ret));
                goto fail;
        }
 -      DHD_INTR(("%s: registered SDIO interrupt function ok\n", __func__));
 +      BRCMF_INTR(("%s: registered SDIO interrupt function ok\n", __func__));
  
 -      DHD_INFO(("%s: completed!!\n", __func__));
 +      BRCMF_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__));
 +                      BRCMF_ERROR(("%s: dongle is not responding\n",
 +                                   __func__));
                        goto fail;
                }
        }
        /* Ok, have the per-port tell the stack we're open for business */
 -      if (dhd_net_attach(bus->dhd, 0) != 0) {
 -              DHD_ERROR(("%s: Net attach failed!!\n", __func__));
 +      if (brcmf_net_attach(bus->drvr, 0) != 0) {
 +              BRCMF_ERROR(("%s: Net attach failed!!\n", __func__));
                goto fail;
        }
  
        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, u32 regsva,
 +                        u16 devid)
  {
        u8 clkctl = 0;
        int err = 0;
        bus->alp_only = true;
  
        /* Return the window to backplane enumeration space for core access */
 -      if (dhdsdio_set_siaddr_window(bus, SI_ENUM_BASE))
 -              DHD_ERROR(("%s: FAILED to return to SI_ENUM_BASE\n", __func__));
 +      if (brcmf_sdbrcm_set_siaddr_window(bus, SI_ENUM_BASE))
 +              BRCMF_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,
 -                       DHD_INIT_CLKCTL1, &err);
 +      brcmf_sdcard_cfg_write(card, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
 +                       BRCMF_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",
 -                      err, DHD_INIT_CLKCTL1, clkctl));
 +      if (err || ((clkctl & ~SBSDIO_AVBITS) != BRCMF_INIT_CLKCTL1)) {
 +              BRCMF_ERROR(("brcmf_sdbrcm_probe: ChipClkCSR access: err %d"
 +                           " wrote 0x%02x read 0x%02x\n",
 +                           err, BRCMF_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)) {
 +              BRCMF_ERROR(("%s: brcmf_sdbrcm_chip_attach failed!\n",
 +                           __func__));
                goto fail;
        }
  
 -      bcmsdh_chipinfo(sdh, bus->ci->chip, bus->ci->chiprev);
 -
 -      if (!dhdsdio_chipmatch((u16) bus->ci->chip)) {
 -              DHD_ERROR(("%s: unsupported chip: 0x%04x\n",
 -                         __func__, bus->ci->chip));
 +      if (!brcmf_sdbrcm_chipmatch((u16) bus->ci->chip)) {
 +              BRCMF_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,
 -                      CORE_SB(bus->ci->armcorebase, sbidhigh), 4));
 +      if (!BRCMF_NOPMU(bus)) {
 +              brcmf_sdcard_reg_read(bus->card,
 +                        CORE_SB(bus->ci->armcorebase, sbidhigh), 4);
                bus->orig_ramsize = bus->ci->ramsize;
                if (!(bus->orig_ramsize)) {
 -                      DHD_ERROR(("%s: failed to find SOCRAM memory!\n",
 -                                 __func__));
 +                      BRCMF_ERROR(("%s: failed to find SOCRAM memory!\n",
 +                                   __func__));
                        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));
 +              BRCMF_ERROR(("DHD: dongle ram size is set to %d(orig %d)\n",
 +                           bus->ramsize, bus->orig_ramsize));
        }
  
 -      bus->regs = (void *)bus->ci->buscorebase;
 -
        /* Set core control so an SDIO reset does a backplane reset */
 -      OR_REG(&bus->regs->corecontrol, CC_BPRESEN);
 +      OR_REG(bus->ci->buscorebase + offsetof(struct sdpcmd_regs,
 +                                                     corecontrol),
 +             CC_BPRESEN, u32);
  
 -      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;
  
@@@ -5689,18 -5300,18 +5636,18 @@@ 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__));
 +      BRCMF_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",
 -                                 __func__, bus->rxblen));
 +                      BRCMF_ERROR(("%s: kmalloc of %d-byte rxbuf failed\n",
 +                                   __func__, bus->rxblen));
                        goto fail;
                }
        }
        /* Allocate buffer to receive glomed packet */
        bus->databuf = kmalloc(MAX_DATA_BUF, GFP_ATOMIC);
        if (!(bus->databuf)) {
 -              DHD_ERROR(("%s: kmalloc of %d-byte databuf failed\n",
 -                         __func__, MAX_DATA_BUF));
 +              BRCMF_ERROR(("%s: kmalloc of %d-byte databuf failed\n",
 +                           __func__, MAX_DATA_BUF));
                /* release rxbuf which was already located as above */
                if (!bus->rxblen)
                        kfree(bus->rxbuf);
        }
  
        /* 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;
  
        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__));
 +      BRCMF_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 = BRCMF_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"));
 +              BRCMF_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize"));
        } else {
 -              DHD_INFO(("%s: Initial value for %s is %d\n",
 -                        __func__, "sd_blocksize", bus->blocksize));
 +              BRCMF_INFO(("%s: Initial value for %s is %d\n",
 +                          __func__, "sd_blocksize", bus->blocksize));
        }
        bus->roundup = min(max_roundup, bus->blocksize);
  
        /* 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",
 -                        __func__,
 -                        (bus->sd_rxchain ? "supports" : "does not support")));
 +              BRCMF_INFO(("%s: bus module (through sdiocard API) %s"
 +                          " chaining\n", __func__, bus->sd_rxchain
 +                          ? "supports" : "does not support"));
        }
        bus->use_rxchain = (bool) bus->sd_rxchain;
  
        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__));
 +      BRCMF_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);
        }
  
 -      DHD_TRACE(("%s: Disconnected\n", __func__));
 +      BRCMF_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__));
 +      BRCMF_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__));
 +      BRCMF_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;
        }
  
 -      DHD_TRACE(("%s: Disconnected\n", __func__));
 +      BRCMF_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__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        if (bus) {
 -              ASSERT(bus->dhd);
 -              dhdsdio_release(bus);
 +              brcmf_sdbrcm_release(bus);
        }
  
 -      DHD_TRACE(("%s: Disconnected\n", __func__));
 +      BRCMF_TRACE(("%s: Disconnected\n", __func__));
  }
  
  /* Register/Unregister functions are called by the main DHD entry
   * order to look for or await the device.
   */
  
 -static bcmsdh_driver_t dhd_sdio = {
 -      dhdsdio_probe,
 -      dhdsdio_disconnect
 +static struct brcmf_sdioh_driver brcmf_sdio = {
 +      brcmf_sdbrcm_probe,
 +      brcmf_sdbrcm_disconnect
  };
  
 -int dhd_bus_register(void)
 +int brcmf_bus_register(void)
  {
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_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;
 +
 +              BRCMF_ERROR(("Invalid module parameters.\n"));
 +              return -EINVAL;
 +      } while (0);
  
 -      bcmsdh_unregister();
 +      return brcmf_sdio_register(&brcmf_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;
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
 -              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 */
 -
 -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));
 +      BRCMF_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) {
 +              BRCMF_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));
 +              BRCMF_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) {
 -                      DHD_ERROR(("%s: error %d on writing %d membytes at "
 -                      "0x%08x\n", __func__, bcmerror, MEMBLOCK, offset));
 +              brcmf_sdbrcm_get_image((char *)memptr, MEMBLOCK, bus))) {
 +              ret = brcmf_sdbrcm_membytes(bus, true, offset, memptr, len);
 +              if (ret) {
 +                      BRCMF_ERROR(("%s: error %d on writing %d membytes at "
 +                                   "0x%08x\n", __func__, ret, MEMBLOCK,
 +                                   offset));
                        goto err;
                }
  
  err:
        kfree(memblock);
  
 -      if (image)
 -              dhd_os_close_image(image);
 +      release_firmware(bus->firmware);
 +      bus->fw_ptr = 0;
  
 -      return bcmerror;
 +      return ret;
  }
  
  /*
   * 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;
        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) {
 +              BRCMF_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));
 +              BRCMF_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) {
 -                      DHD_ERROR(("%s: error downloading vars: %d\n",
 -                                 __func__, bcmerror));
 -              }
 +                      ret = brcmf_sdbrcm_downloadvars(bus, memblock, len + 1);
 +              if (ret)
 +                      BRCMF_ERROR(("%s: error downloading vars: %d\n",
 +                                   __func__, ret));
        } else {
 -              DHD_ERROR(("%s: error reading nvram file: %d\n",
 -                         __func__, len));
 -              bcmerror = -EIO;
 +              BRCMF_ERROR(("%s: error reading nvram file: %d\n",
 +                           __func__, len));
 +              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)) {
 -              DHD_ERROR(("%s: error placing ARM core in reset\n", __func__));
 +      if (brcmf_sdbrcm_download_state(bus, true)) {
 +              BRCMF_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)) {
 +              BRCMF_ERROR(("%s: dongle image file download failed\n",
 +                           __func__));
                goto err;
        }
  
 -      /* EXAMPLE: nvram_array */
 -      /* If a valid nvram_arry is specified as above, it can be passed
 -               down to dongle */
 -      /* dhd_bus_set_nvram_params(bus, (char *)&nvram_array); */
 -
        /* External nvram takes precedence if specified */
 -      if (dhdsdio_download_nvram(bus)) {
 -              DHD_ERROR(("%s: dongle nvram file download failed\n",
 -                         __func__));
 +      if (brcmf_sdbrcm_download_nvram(bus)) {
 +              BRCMF_ERROR(("%s: dongle nvram file download failed\n",
 +                           __func__));
        }
  
        /* Take arm out of reset */
 -      if (dhdsdio_download_state(bus, false)) {
 -              DHD_ERROR(("%s: error getting out of ARM core reset\n",
 -                         __func__));
 +      if (brcmf_sdbrcm_download_state(bus, false)) {
 +              BRCMF_ERROR(("%s: error getting out of ARM core reset\n",
 +                           __func__));
                goto 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)
 -{
 -      ASSERT(bus->ci != NULL);
 -      return bus->ci->chip;
 -}
 -
 -void *dhd_bus_pub(struct dhd_bus *bus)
 -{
 -      return bus->dhd;
 -}
 -
 -void *dhd_bus_txq(struct dhd_bus *bus)
 -{
 -      return &bus->txq;
 -}
 -
 -uint dhd_bus_hdrlen(struct dhd_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__));
 +                      BRCMF_TRACE(("%s:  WLAN OFF DONE\n", __func__));
                        /* App can now remove power from device */
                } else
                        bcmerror = -EIO;
        } else {
                /* App must have restored power to device before calling */
  
 -              DHD_TRACE(("\n\n%s: == WLAN ON ==\n", __func__));
 +              BRCMF_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,
 -                                               (u32 *) SI_ENUM_BASE,
 -                                               bus->cl_devid)) {
 +                      if (brcmf_sdbrcm_probe_attach(bus, bus->card,
 +                                                    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);
 +                                      brcmf_sdbrcm_bus_init(bus->drvr, false);
  
 -#if defined(OOB_INTR_ONLY)
 -                                      dhd_enable_oob_intr(bus, true);
 -#endif                                /* defined(OOB_INTR_ONLY) */
 +                                      bus->drvr->dongle_reset = false;
 +                                      bus->drvr->up = true;
  
 -                                      bus->dhd->dongle_reset = false;
 -                                      bus->dhd->up = true;
 -
 -                                      DHD_TRACE(("%s: WLAN ON DONE\n",
 -                                                 __func__));
 +                                      BRCMF_TRACE(("%s: WLAN ON DONE\n",
 +                                                   __func__));
                                } else
                                        bcmerror = -EIO;
                        } else
                                bcmerror = -EIO;
                } else {
                        bcmerror = -EISCONN;
 -                      DHD_ERROR(("%s: Set DEVRESET=false invoked when device "
 -                              "is on\n", __func__));
 +                      BRCMF_ERROR(("%s: Set DEVRESET=false invoked when"
 +                                   " device 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, u32 regs)
  {
        u32 regdata;
  
         * For different chiptypes or old sdio hosts w/o chipcommon,
         * other ways of recognition should be added here.
         */
 -      ci->cccorebase = (u32)regs;
 -      regdata = bcmsdh_reg_read(sdh, CORE_CC_REG(ci->cccorebase, chipid), 4);
 +      ci->cccorebase = regs;
 +      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;
  
 -      DHD_INFO(("%s: chipid=0x%x chiprev=%d\n",
 -              __func__, ci->chip, ci->chiprev));
 +      BRCMF_INFO(("%s: chipid=0x%x chiprev=%d\n",
 +                  __func__, ci->chip, ci->chiprev));
  
        /* Address of cores for new chips should be added here */
        switch (ci->chip) {
                ci->ramsize = BCM4329_RAMSIZE;
                break;
        default:
 -              DHD_ERROR(("%s: chipid 0x%x is not supported\n",
 -                      __func__, ci->chip));
 +              BRCMF_ERROR(("%s: chipid 0x%x is not supported\n",
 +                           __func__, ci->chip));
                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;
  
 -      DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n",
 -              __func__, ci->ccrev, ci->pmurev,
 -              ci->buscorerev, ci->buscoretype));
 +      BRCMF_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n",
 +                  __func__, ci->ccrev, ci->pmurev,
 +                  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__));
 +                      BRCMF_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, u32 regs)
  {
        struct chip_info *ci;
        int err;
        u8 clkval, clkset;
  
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_TRACE(("%s: Enter\n", __func__));
  
        /* alloc chip_info_t */
        ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC);
        if (NULL == ci) {
 -              DHD_ERROR(("%s: malloc failed!\n", __func__));
 +              BRCMF_ERROR(("%s: malloc failed!\n", __func__));
                return -ENOMEM;
        }
  
        /* 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__));
 +              BRCMF_ERROR(("%s: error writing for HT off\n", __func__));
                goto fail;
        }
  
        /* 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)),
                                PMU_MAX_TRANSITION_DLY);
                if (!SBSDIO_ALPAV(clkval)) {
 -                      DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n",
 -                              __func__, clkval));
 +                      BRCMF_ERROR(("%s: timeout on ALPAV wait,"
 +                                   " clkval 0x%02x\n", __func__, clkval));
                        err = -EBUSY;
                        goto fail;
                }
                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);
        } else {
 -              DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n",
 -                      __func__, clkset, clkval));
 +              BRCMF_ERROR(("%s: ChipClkCSR access: wrote 0x%02x"
 +                           " read 0x%02x\n", __func__, clkset, clkval));
                err = -EACCES;
                goto fail;
        }
  
        /* 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;
  
         * 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;
@@@ -6414,7 -6232,7 +6361,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;
  
         * 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);
  }
@@@ -6500,7 -6316,7 +6447,7 @@@ static const struct sdiod_drive_str sdi
  #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;
                str_shift = 11;
                break;
        default:
 -              DHD_ERROR(("No SDIO Drive strength init"
 -                      "done for chip %s rev %d pmurev %d\n",
 -                      bcm_chipname(bus->ci->chip, chn, 8),
 -                      bus->ci->chiprev, bus->ci->pmurev));
 +              BRCMF_ERROR(("No SDIO Drive strength init"
 +                           "done for chip %s rev %d pmurev %d\n",
 +                           brcmu_chipname(bus->ci->chip, chn, 8),
 +                           bus->ci->chiprev, bus->ci->pmurev));
                break;
        }
  
                        }
                }
  
 -              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);
  
 -              DHD_INFO(("SDIO: %dmA drive strength selected, set to 0x%08x\n",
 -                      drivestrength, cc_data_temp));
 +              BRCMF_INFO(("SDIO: %dmA drive strength selected, "
 +                          "set to 0x%08x\n", drivestrength, cc_data_temp));
        }
  }
  
  static void
 -dhdsdio_chip_detach(struct dhd_bus *bus)
 +brcmf_sdbrcm_chip_detach(struct brcmf_bus *bus)
  {
 -      DHD_TRACE(("%s: Enter\n", __func__));
 +      BRCMF_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 == BRCMF_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 != BRCMF_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 != BRCMF_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);
  #ifndef _wl_cfg80211_h_
  #define _wl_cfg80211_h_
  
- struct brcmf_cfg80211_conf;
- struct brcmf_cfg80211_iface;
- struct brcmf_cfg80211_priv;
- struct brcmf_cfg80211_security;
- struct brcmf_cfg80211_ibss;
+ #include <linux/wireless.h>
+ #include <net/cfg80211.h>
+ #include <wlioctl.h>
+ struct wl_conf;
+ struct wl_iface;
+ struct wl_priv;
+ struct wl_security;
+ struct wl_ibss;
  
  #define WL_DBG_NONE           0
  #define WL_DBG_CONN           (1 << 5)
@@@ -34,7 -38,7 +38,7 @@@
  
  #define       WL_ERR(fmt, args...)                                    \
  do {                                                          \
 -      if (wl_dbg_level & WL_DBG_ERR) {                        \
 +      if (brcmf_dbg_level & WL_DBG_ERR) {                     \
                if (net_ratelimit()) {                          \
                        printk(KERN_ERR "ERROR @%s : " fmt,     \
                                __func__, ##args);              \
@@@ -45,7 -49,7 +49,7 @@@
  #if (defined BCMDBG)
  #define       WL_INFO(fmt, args...)                                   \
  do {                                                          \
 -      if (wl_dbg_level & WL_DBG_INFO) {                       \
 +      if (brcmf_dbg_level & WL_DBG_INFO) {                    \
                if (net_ratelimit()) {                          \
                        printk(KERN_ERR "INFO @%s : " fmt,      \
                                __func__, ##args);              \
@@@ -55,7 -59,7 +59,7 @@@
  
  #define       WL_TRACE(fmt, args...)                                  \
  do {                                                          \
 -      if (wl_dbg_level & WL_DBG_TRACE) {                      \
 +      if (brcmf_dbg_level & WL_DBG_TRACE) {                   \
                if (net_ratelimit()) {                          \
                        printk(KERN_ERR "TRACE @%s : " fmt,     \
                                __func__, ##args);              \
@@@ -65,7 -69,7 +69,7 @@@
  
  #define       WL_SCAN(fmt, args...)                                   \
  do {                                                          \
 -      if (wl_dbg_level & WL_DBG_SCAN) {                       \
 +      if (brcmf_dbg_level & WL_DBG_SCAN) {                    \
                if (net_ratelimit()) {                          \
                        printk(KERN_ERR "SCAN @%s : " fmt,      \
                                __func__, ##args);              \
@@@ -75,7 -79,7 +79,7 @@@
  
  #define       WL_CONN(fmt, args...)                                   \
  do {                                                          \
 -      if (wl_dbg_level & WL_DBG_CONN) {                       \
 +      if (brcmf_dbg_level & WL_DBG_CONN) {                    \
                if (net_ratelimit()) {                          \
                        printk(KERN_ERR "CONN @%s : " fmt,      \
                                __func__, ##args);              \
  #define       WL_CONN(fmt, args...)
  #endif /* (defined BCMDBG) */
  
 -
 -#define WL_SCAN_RETRY_MAX     3       /* used for ibss scan */
  #define WL_NUM_SCAN_MAX               1
  #define WL_NUM_PMKIDS_MAX     MAXPMKID        /* will be used
                                                 * for 2.6.33 kernel
                                                 * or later
                                                 */
 -#define WL_SCAN_BUF_MAX               (1024 * 8)
 -#define WL_TLV_INFO_MAX               1024
 +#define WL_SCAN_BUF_MAX                       (1024 * 8)
 +#define WL_TLV_INFO_MAX                       1024
  #define WL_BSS_INFO_MAX                       2048
  #define WL_ASSOC_INFO_MAX     512     /*
                                 * needs to grab assoc info from dongle to
  #define WL_IOCTL_LEN_MAX      1024
  #define WL_EXTRA_BUF_MAX      2048
  #define WL_ISCAN_BUF_MAX      2048    /*
 -                               * the buf lengh can be WLC_IOCTL_MAXLEN (8K)
 +                               * the buf length can be BRCMF_C_IOCTL_MAXLEN
                                 * to reduce iteration
                                 */
  #define WL_ISCAN_TIMER_INTERVAL_MS    3000
 -#define WL_SCAN_ERSULTS_LAST  (WL_SCAN_RESULTS_NO_MEM+1)
 +#define WL_SCAN_ERSULTS_LAST  (BRCMF_SCAN_RESULTS_NO_MEM+1)
  #define WL_AP_MAX     256     /* virtually unlimitted as long
                                 * as kernel memory allows
                                 */
 -#define WL_FILE_NAME_MAX              256
  
  #define WL_ROAM_TRIGGER_LEVEL         -75
  #define WL_ROAM_DELTA                 20
@@@ -158,8 -165,22 +162,8 @@@ enum wl_iscan_state 
        WL_ISCAN_STATE_SCANING
  };
  
 -/* fw downloading status */
 -enum wl_fw_status {
 -      WL_FW_LOADING_DONE,
 -      WL_NVRAM_LOADING_DONE
 -};
 -
 -/* beacon / probe_response */
 -struct beacon_proberesp {
 -      __le64 timestamp;
 -      __le16 beacon_int;
 -      __le16 capab_info;
 -      u8 variable[0];
 -} __attribute__ ((packed));
 -
  /* dongle configuration */
 -struct wl_conf {
 +struct brcmf_cfg80211_conf {
        u32 mode;               /* adhoc , infrastructure or ap */
        u32 frag_threshold;
        u32 rts_threshold;
  };
  
  /* cfg80211 main event loop */
 -struct wl_event_loop {
 -      s32(*handler[WLC_E_LAST]) (struct wl_priv *wl,
 +struct brcmf_cfg80211_event_loop {
 +      s32(*handler[BRCMF_E_LAST]) (struct brcmf_cfg80211_priv *cfg_priv,
                                     struct net_device *ndev,
 -                                   const wl_event_msg_t *e, void *data);
 +                                   const struct brcmf_event_msg *e,
 +                                   void *data);
  };
  
  /* representing interface of cfg80211 plane */
 -struct wl_iface {
 -      struct wl_priv *wl;
 +struct brcmf_cfg80211_iface {
 +      struct brcmf_cfg80211_priv *cfg_priv;
  };
  
 -struct wl_dev {
 +struct brcmf_cfg80211_dev {
        void *driver_data;      /* to store cfg80211 object information */
  };
  
 -/* bss inform structure for cfg80211 interface */
 -struct wl_cfg80211_bss_info {
 -      u16 band;
 -      u16 channel;
 -      s16 rssi;
 -      u16 frame_len;
 -      u8 frame_buf[1];
 -};
 -
  /* basic structure of scan request */
 -struct wl_scan_req {
 -      struct wlc_ssid ssid;
 +struct brcmf_cfg80211_scan_req {
 +      struct brcmf_ssid ssid;
  };
  
  /* basic structure of information element */
 -struct wl_ie {
 +struct brcmf_cfg80211_ie {
        u16 offset;
        u8 buf[WL_TLV_INFO_MAX];
  };
  
  /* event queue for cfg80211 main event */
 -struct wl_event_q {
 +struct brcmf_cfg80211_event_q {
        struct list_head eq_list;
        u32 etype;
 -      wl_event_msg_t emsg;
 +      struct brcmf_event_msg emsg;
        s8 edata[1];
  };
  
  /* security information with currently associated ap */
 -struct wl_security {
 +struct brcmf_cfg80211_security {
        u32 wpa_versions;
        u32 auth_type;
        u32 cipher_pairwise;
  };
  
  /* ibss information for currently joined ibss network */
 -struct wl_ibss {
 +struct brcmf_cfg80211_ibss {
        u8 beacon_interval;     /* in millisecond */
        u8 atim;                /* in millisecond */
        s8 join_only;
  };
  
  /* dongle profile */
 -struct wl_profile {
 +struct brcmf_cfg80211_profile {
        u32 mode;
 -      struct wlc_ssid ssid;
 +      struct brcmf_ssid ssid;
        u8 bssid[ETH_ALEN];
        u16 beacon_interval;
        u8 dtim_period;
 -      struct wl_security sec;
 -      struct wl_ibss ibss;
 +      struct brcmf_cfg80211_security sec;
 +      struct brcmf_cfg80211_ibss ibss;
        s32 band;
  };
  
  /* dongle iscan event loop */
 -struct wl_iscan_eloop {
 -      s32(*handler[WL_SCAN_ERSULTS_LAST]) (struct wl_priv *wl);
 +struct brcmf_cfg80211_iscan_eloop {
 +      s32 (*handler[WL_SCAN_ERSULTS_LAST])
 +              (struct brcmf_cfg80211_priv *cfg_priv);
  };
  
  /* dongle iscan controller */
 -struct wl_iscan_ctrl {
 +struct brcmf_cfg80211_iscan_ctrl {
        struct net_device *dev;
        struct timer_list timer;
        u32 timer_ms;
        s32 state;
        struct task_struct *tsk;
        struct semaphore sync;
 -      struct wl_iscan_eloop el;
 +      struct brcmf_cfg80211_iscan_eloop el;
        void *data;
 -      s8 ioctl_buf[WLC_IOCTL_SMLEN];
 +      s8 ioctl_buf[BRCMF_C_IOCTL_SMLEN];
        s8 scan_buf[WL_ISCAN_BUF_MAX];
  };
  
  /* association inform */
 -struct wl_connect_info {
 +struct brcmf_cfg80211_connect_info {
        u8 *req_ie;
        s32 req_ie_len;
        u8 *resp_ie;
        s32 resp_ie_len;
  };
  
 -/* firmware /nvram downloading controller */
 -struct wl_fw_ctrl {
 -      const struct firmware *fw_entry;
 -      unsigned long status;
 -      u32 ptr;
 -      s8 fw_name[WL_FILE_NAME_MAX];
 -      s8 nvram_name[WL_FILE_NAME_MAX];
 -};
 -
  /* assoc ie length */
 -struct wl_assoc_ielen {
 +struct brcmf_cfg80211_assoc_ielen {
        u32 req_len;
        u32 resp_len;
  };
  
  /* wpa2 pmk list */
 -struct wl_pmk_list {
 +struct brcmf_cfg80211_pmk_list {
        pmkid_list_t pmkids;
        pmkid_t foo[MAXPMKID - 1];
  };
  
  /* dongle private data of cfg80211 interface */
 -struct wl_priv {
 +struct brcmf_cfg80211_priv {
        struct wireless_dev *wdev;      /* representing wl cfg80211 device */
 -      struct wl_conf *conf;   /* dongle configuration */
 +      struct brcmf_cfg80211_conf *conf;       /* dongle configuration */
        struct cfg80211_scan_request *scan_request;     /* scan request
                                                         object */
 -      struct wl_event_loop el;        /* main event loop */
 +      struct brcmf_cfg80211_event_loop el;    /* main event loop */
        struct list_head eq_list;       /* used for event queue */
        spinlock_t eq_lock;     /* for event queue synchronization */
        struct mutex usr_sync;  /* maily for dongle up/down synchronization */
 -      struct wl_scan_results *bss_list;       /* bss_list holding scanned
 +      struct brcmf_scan_results *bss_list;    /* bss_list holding scanned
                                                 ap information */
 -      struct wl_scan_results *scan_results;
 -      struct wl_scan_req *scan_req_int;       /* scan request object for
 -                                               internal purpose */
 +      struct brcmf_scan_results *scan_results;
 +      struct brcmf_cfg80211_scan_req *scan_req_int;   /* scan request object
 +                                               for internal purpose */
        struct wl_cfg80211_bss_info *bss_info;  /* bss information for
                                                 cfg80211 layer */
 -      struct wl_ie ie;        /* information element object for
 +      struct brcmf_cfg80211_ie ie;    /* information element object for
                                         internal purpose */
        struct semaphore event_sync;    /* for synchronization of main event
                                         thread */
 -      struct wl_profile *profile;     /* holding dongle profile */
 -      struct wl_iscan_ctrl *iscan;    /* iscan controller */
 -      struct wl_connect_info conn_info;       /* association information
 -                                               container */
 -      struct wl_fw_ctrl *fw;  /* control firwmare / nvram paramter
 -                               downloading */
 -      struct wl_pmk_list *pmk_list;   /* wpa2 pmk list */
 +      struct brcmf_cfg80211_profile *profile; /* holding dongle profile */
 +      struct brcmf_cfg80211_iscan_ctrl *iscan;        /* iscan controller */
 +      struct brcmf_cfg80211_connect_info conn_info; /* association info */
 +      struct brcmf_cfg80211_pmk_list *pmk_list;       /* wpa2 pmk list */
        struct task_struct *event_tsk;  /* task of main event handler thread */
        unsigned long status;           /* current dongle status */
        void *pub;
        u8 ci[0] __attribute__ ((__aligned__(NETDEV_ALIGN)));
  };
  
 -#define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy))
 -#define wl_to_wiphy(w) (w->wdev->wiphy)
 -#define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w)))
 -#define wl_to_wdev(w) (w->wdev)
 -#define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w)))
 -#define wl_to_ndev(w) (w->wdev->netdev)
 -#define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
 -#define ci_to_wl(c) (ci->wl)
 -#define wl_to_ci(w) (&w->ci)
 -#define wl_to_sr(w) (w->scan_req_int)
 -#define wl_to_ie(w) (&w->ie)
 -#define iscan_to_wl(i) ((struct wl_priv *)(i->data))
 -#define wl_to_iscan(w) (w->iscan)
 -#define wl_to_conn(w) (&w->conn_info)
 -
 -static inline struct wl_bss_info *next_bss(struct wl_scan_results *list,
 -                                         struct wl_bss_info *bss)
 +#define cfg_to_wiphy(w) (w->wdev->wiphy)
 +#define wiphy_to_cfg(w) ((struct brcmf_cfg80211_priv *)(wiphy_priv(w)))
 +#define cfg_to_wdev(w) (w->wdev)
 +#define wdev_to_cfg(w) ((struct brcmf_cfg80211_priv *)(wdev_priv(w)))
 +#define cfg_to_ndev(w) (w->wdev->netdev)
 +#define ndev_to_cfg(n) (wdev_to_cfg(n->ieee80211_ptr))
 +#define iscan_to_cfg(i) ((struct brcmf_cfg80211_priv *)(i->data))
 +#define cfg_to_iscan(w) (w->iscan)
 +#define cfg_to_conn(w) (&w->conn_info)
 +
 +static inline struct brcmf_bss_info *next_bss(struct brcmf_scan_results *list,
 +                                         struct brcmf_bss_info *bss)
  {
        return bss = bss ?
 -              (struct wl_bss_info *)((unsigned long)bss +
 +              (struct brcmf_bss_info *)((unsigned long)bss +
                                       le32_to_cpu(bss->length)) :
                list->bss_info;
  }
  #define for_each_bss(list, bss, __i)  \
        for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
  
 -extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
 -extern void wl_cfg80211_detach(void);
 +extern s32 brcmf_cfg80211_attach(struct net_device *ndev, void *data);
 +extern void brcmf_cfg80211_detach(void);
  /* event handler from dongle */
 -extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
 -                            void *data);
 -extern void wl_cfg80211_sdio_func(void *func);        /* set sdio function info */
 -extern struct sdio_func *wl_cfg80211_get_sdio_func(void);     /* set sdio function info */
 -extern s32 wl_cfg80211_up(void);      /* dongle up */
 -extern s32 wl_cfg80211_down(void);    /* dongle down */
 -extern void wl_cfg80211_dbg_level(u32 level); /* set dongle
 -                                                       debugging level */
 -extern void *wl_cfg80211_request_fw(s8 *file_name);   /* request fw /nvram
 -                                                       downloading */
 -extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size);    /* read fw
 -                                                               image */
 -extern void wl_cfg80211_release_fw(void);     /* release fw */
 -extern s8 *wl_cfg80211_get_fwname(void);      /* get firmware name for
 -                                               the dongle */
 -extern s8 *wl_cfg80211_get_nvramname(void);   /* get nvram name for
 -                                               the dongle */
 -extern void wl_os_wd_timer(struct net_device *ndev, uint wdtick);
 +extern void brcmf_cfg80211_event(struct net_device *ndev,
 +                               const struct brcmf_event_msg *e, void *data);
 +extern void brcmf_cfg80211_sdio_func(void *func); /* set sdio function info */
 +extern struct sdio_func *brcmf_cfg80211_get_sdio_func(void);
 +extern s32 brcmf_cfg80211_up(void);   /* dongle up */
 +extern s32 brcmf_cfg80211_down(void); /* dongle down */
  
  #endif                                /* _wl_cfg80211_h_ */
index 84245b9,0000000..d6de44e
mode 100644,000000..100644
--- /dev/null
@@@ -1,1933 -1,0 +1,1934 @@@
 +/*
 + * Copyright (c) 2010 Broadcom Corporation
 + *
 + * Permission to use, copy, modify, and/or distribute this software for any
 + * purpose with or without fee is hereby granted, provided that the above
 + * copyright notice and this permission notice appear in all copies.
 + *
 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 + */
 +
 +#define __UNDEF_NO_VERSION__
 +
 +#include <linux/etherdevice.h>
 +#include <linux/pci.h>
 +#include <linux/sched.h>
 +#include <linux/firmware.h>
++#include <linux/interrupt.h>
 +#include <net/mac80211.h>
 +#include <defs.h>
 +#include "nicpci.h"
 +#include "phy/phy_int.h"
 +#include "d11.h"
 +#include "channel.h"
 +#include "scb.h"
 +#include "pub.h"
 +#include "ucode_loader.h"
 +#include "mac80211_if.h"
 +
 +#define N_TX_QUEUES   4 /* #tx queues on mac80211<->driver interface */
 +
 +#define LOCK(wl)      spin_lock_bh(&(wl)->lock)
 +#define UNLOCK(wl)    spin_unlock_bh(&(wl)->lock)
 +
 +/* locking from inside brcms_isr */
 +#define ISR_LOCK(wl, flags)\
 +      do {\
 +              spin_lock(&(wl)->isr_lock);\
 +              (void)(flags); } \
 +      while (0)
 +
 +#define ISR_UNLOCK(wl, flags)\
 +      do {\
 +              spin_unlock(&(wl)->isr_lock);\
 +              (void)(flags); } \
 +      while (0)
 +
 +/* locking under LOCK() to synchronize with brcms_isr */
 +#define INT_LOCK(wl, flags)   spin_lock_irqsave(&(wl)->isr_lock, flags)
 +#define INT_UNLOCK(wl, flags) spin_unlock_irqrestore(&(wl)->isr_lock, flags)
 +
 +static void brcms_timer(unsigned long data);
 +static void _brcms_timer(struct brcms_timer *t);
 +
 +
 +static int ieee_hw_init(struct ieee80211_hw *hw);
 +static int ieee_hw_rate_init(struct ieee80211_hw *hw);
 +
 +static int wl_linux_watchdog(void *ctx);
 +
 +/* Flags we support */
 +#define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
 +      FIF_ALLMULTI | \
 +      FIF_FCSFAIL | \
 +      FIF_PLCPFAIL | \
 +      FIF_CONTROL | \
 +      FIF_OTHER_BSS | \
 +      FIF_BCN_PRBRESP_PROMISC)
 +
 +static int n_adapters_found;
 +
 +static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev);
 +static void brcms_release_fw(struct brcms_info *wl);
 +
 +/* local prototypes */
 +static void brcms_dpc(unsigned long data);
 +static irqreturn_t brcms_isr(int irq, void *dev_id);
 +
 +static int __devinit brcms_pci_probe(struct pci_dev *pdev,
 +                                const struct pci_device_id *ent);
 +static void brcms_remove(struct pci_dev *pdev);
 +static void brcms_free(struct brcms_info *wl);
 +static void brcms_set_basic_rate(struct wl_rateset *rs, u16 rate, bool is_br);
 +
 +MODULE_AUTHOR("Broadcom Corporation");
 +MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
 +MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
 +MODULE_LICENSE("Dual BSD/GPL");
 +
 +/* recognized PCI IDs */
 +static DEFINE_PCI_DEVICE_TABLE(brcms_pci_id_table) = {
 +      {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},      /* 43225 2G */
 +      {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},      /* 43224 DUAL */
 +      {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},      /* 4313 DUAL */
 +      /* 43224 Ven */
 +      {PCI_VENDOR_ID_BROADCOM, 0x0576, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
 +      {0}
 +};
 +
 +MODULE_DEVICE_TABLE(pci, brcms_pci_id_table);
 +
 +#ifdef BCMDBG
 +static int msglevel = 0xdeadbeef;
 +module_param(msglevel, int, 0);
 +static int phymsglevel = 0xdeadbeef;
 +module_param(phymsglevel, int, 0);
 +#endif                                /* BCMDBG */
 +
 +#define HW_TO_WL(hw)   (hw->priv)
 +#define WL_TO_HW(wl)    (wl->pub->ieee_hw)
 +
 +/* MAC80211 callback functions */
 +static int brcms_ops_start(struct ieee80211_hw *hw);
 +static void brcms_ops_stop(struct ieee80211_hw *hw);
 +static int brcms_ops_add_interface(struct ieee80211_hw *hw,
 +                              struct ieee80211_vif *vif);
 +static void brcms_ops_remove_interface(struct ieee80211_hw *hw,
 +                                  struct ieee80211_vif *vif);
 +static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed);
 +static void brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
 +                                  struct ieee80211_vif *vif,
 +                                  struct ieee80211_bss_conf *info,
 +                                  u32 changed);
 +static void brcms_ops_configure_filter(struct ieee80211_hw *hw,
 +                                  unsigned int changed_flags,
 +                                  unsigned int *total_flags, u64 multicast);
 +static int brcms_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
 +                        bool set);
 +static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw);
 +static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw);
 +static void brcms_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
 +static int brcms_ops_get_stats(struct ieee80211_hw *hw,
 +                          struct ieee80211_low_level_stats *stats);
 +static void brcms_ops_sta_notify(struct ieee80211_hw *hw,
 +                            struct ieee80211_vif *vif,
 +                            enum sta_notify_cmd cmd,
 +                            struct ieee80211_sta *sta);
 +static int brcms_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
 +                        const struct ieee80211_tx_queue_params *params);
 +static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw);
 +static int brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 +                    struct ieee80211_sta *sta);
 +static int brcms_ops_sta_remove(struct ieee80211_hw *hw,
 +                              struct ieee80211_vif *vif,
 +                              struct ieee80211_sta *sta);
 +static int brcms_ops_ampdu_action(struct ieee80211_hw *hw,
 +                             struct ieee80211_vif *vif,
 +                             enum ieee80211_ampdu_mlme_action action,
 +                             struct ieee80211_sta *sta, u16 tid, u16 *ssn,
 +                             u8 buf_size);
 +static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw);
 +static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop);
 +
 +static void brcms_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 +{
 +      struct brcms_info *wl = hw->priv;
 +
 +      LOCK(wl);
 +      if (!wl->pub->up) {
 +              wiphy_err(wl->wiphy, "ops->tx called while down\n");
 +              kfree_skb(skb);
 +              goto done;
 +      }
 +      brcms_c_sendpkt_mac80211(wl->wlc, skb, hw);
 + done:
 +      UNLOCK(wl);
 +}
 +
 +static int brcms_ops_start(struct ieee80211_hw *hw)
 +{
 +      struct brcms_info *wl = hw->priv;
 +      bool blocked;
 +      /*
 +        struct ieee80211_channel *curchan = hw->conf.channel;
 +      */
 +
 +      ieee80211_wake_queues(hw);
 +      LOCK(wl);
 +      blocked = brcms_rfkill_set_hw_state(wl);
 +      UNLOCK(wl);
 +      if (!blocked)
 +              wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
 +
 +      return 0;
 +}
 +
 +static void brcms_ops_stop(struct ieee80211_hw *hw)
 +{
 +      ieee80211_stop_queues(hw);
 +}
 +
 +static int
 +brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 +{
 +      struct brcms_info *wl;
 +      int err;
 +
 +      /* Just STA for now */
 +      if (vif->type != NL80211_IFTYPE_AP &&
 +          vif->type != NL80211_IFTYPE_MESH_POINT &&
 +          vif->type != NL80211_IFTYPE_STATION &&
 +          vif->type != NL80211_IFTYPE_WDS &&
 +          vif->type != NL80211_IFTYPE_ADHOC) {
 +              wiphy_err(hw->wiphy, "%s: Attempt to add type %d, only"
 +                        " STA for now\n", __func__, vif->type);
 +              return -EOPNOTSUPP;
 +      }
 +
 +      wl = HW_TO_WL(hw);
 +      LOCK(wl);
 +      err = brcms_up(wl);
 +      UNLOCK(wl);
 +
 +      if (err != 0) {
 +              wiphy_err(hw->wiphy, "%s: brcms_up() returned %d\n", __func__,
 +                        err);
 +      }
 +      return err;
 +}
 +
 +static void
 +brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 +{
 +      struct brcms_info *wl;
 +
 +      wl = HW_TO_WL(hw);
 +
 +      /* put driver in down state */
 +      LOCK(wl);
 +      brcms_down(wl);
 +      UNLOCK(wl);
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +static int
 +ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
 +               enum nl80211_channel_type type)
 +{
 +      struct brcms_info *wl = HW_TO_WL(hw);
 +      int err = 0;
 +
 +      switch (type) {
 +      case NL80211_CHAN_HT20:
 +      case NL80211_CHAN_NO_HT:
 +              err = brcms_c_set(wl->wlc, BRCM_SET_CHANNEL, chan->hw_value);
 +              break;
 +      case NL80211_CHAN_HT40MINUS:
 +      case NL80211_CHAN_HT40PLUS:
 +              wiphy_err(hw->wiphy,
 +                        "%s: Need to implement 40 Mhz Channels!\n", __func__);
 +              err = 1;
 +              break;
 +      }
 +
 +      if (err)
 +              return -EIO;
 +      return err;
 +}
 +
 +static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
 +{
 +      struct ieee80211_conf *conf = &hw->conf;
 +      struct brcms_info *wl = HW_TO_WL(hw);
 +      int err = 0;
 +      int new_int;
 +      struct wiphy *wiphy = hw->wiphy;
 +
 +      LOCK(wl);
 +      if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
 +              if (brcms_c_set_par(wl->wlc, IOV_BCN_LI_BCN,
 +                                  conf->listen_interval) < 0) {
 +                      wiphy_err(wiphy, "%s: Error setting listen_interval\n",
 +                                __func__);
 +                      err = -EIO;
 +                      goto config_out;
 +              }
 +              brcms_c_get_par(wl->wlc, IOV_BCN_LI_BCN, &new_int);
 +      }
 +      if (changed & IEEE80211_CONF_CHANGE_MONITOR)
 +              wiphy_err(wiphy, "%s: change monitor mode: %s (implement)\n",
 +                        __func__, conf->flags & IEEE80211_CONF_MONITOR ?
 +                        "true" : "false");
 +      if (changed & IEEE80211_CONF_CHANGE_PS)
 +              wiphy_err(wiphy, "%s: change power-save mode: %s (implement)\n",
 +                        __func__, conf->flags & IEEE80211_CONF_PS ?
 +                        "true" : "false");
 +
 +      if (changed & IEEE80211_CONF_CHANGE_POWER) {
 +              if (brcms_c_set_par(wl->wlc, IOV_QTXPOWER,
 +                                  conf->power_level * 4) < 0) {
 +                      wiphy_err(wiphy, "%s: Error setting power_level\n",
 +                                __func__);
 +                      err = -EIO;
 +                      goto config_out;
 +              }
 +              brcms_c_get_par(wl->wlc, IOV_QTXPOWER, &new_int);
 +              if (new_int != (conf->power_level * 4))
 +                      wiphy_err(wiphy, "%s: Power level req != actual, %d %d"
 +                                "\n", __func__, conf->power_level * 4,
 +                                new_int);
 +      }
 +      if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
 +              err = ieee_set_channel(hw, conf->channel, conf->channel_type);
 +      }
 +      if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
 +              if (brcms_c_set
 +                  (wl->wlc, BRCM_SET_SRL,
 +                   conf->short_frame_max_tx_count) < 0) {
 +                      wiphy_err(wiphy, "%s: Error setting srl\n", __func__);
 +                      err = -EIO;
 +                      goto config_out;
 +              }
 +              if (brcms_c_set(wl->wlc, BRCM_SET_LRL,
 +                              conf->long_frame_max_tx_count) < 0) {
 +                      wiphy_err(wiphy, "%s: Error setting lrl\n", __func__);
 +                      err = -EIO;
 +                      goto config_out;
 +              }
 +      }
 +
 + config_out:
 +      UNLOCK(wl);
 +      return err;
 +}
 +
 +static void
 +brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
 +                      struct ieee80211_vif *vif,
 +                      struct ieee80211_bss_conf *info, u32 changed)
 +{
 +      struct brcms_info *wl = HW_TO_WL(hw);
 +      struct wiphy *wiphy = hw->wiphy;
 +      int val;
 +
 +      if (changed & BSS_CHANGED_ASSOC) {
 +              /* association status changed (associated/disassociated)
 +               * also implies a change in the AID.
 +               */
 +              wiphy_err(wiphy, "%s: %s: %sassociated\n", KBUILD_MODNAME,
 +                        __func__, info->assoc ? "" : "dis");
 +              LOCK(wl);
 +              brcms_c_associate_upd(wl->wlc, info->assoc);
 +              UNLOCK(wl);
 +      }
 +      if (changed & BSS_CHANGED_ERP_SLOT) {
 +              /* slot timing changed */
 +              if (info->use_short_slot)
 +                      val = 1;
 +              else
 +                      val = 0;
 +              LOCK(wl);
 +              brcms_c_set(wl->wlc, BRCMS_SET_SHORTSLOT_OVERRIDE, val);
 +              UNLOCK(wl);
 +      }
 +
 +      if (changed & BSS_CHANGED_HT) {
 +              /* 802.11n parameters changed */
 +              u16 mode = info->ht_operation_mode;
 +
 +              LOCK(wl);
 +              brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
 +                      mode & IEEE80211_HT_OP_MODE_PROTECTION);
 +              brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
 +                      mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
 +              brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
 +                      mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
 +              UNLOCK(wl);
 +      }
 +      if (changed & BSS_CHANGED_BASIC_RATES) {
 +              struct ieee80211_supported_band *bi;
 +              u32 br_mask, i;
 +              u16 rate;
 +              struct wl_rateset rs;
 +              int error;
 +
 +              /* retrieve the current rates */
 +              LOCK(wl);
 +              error = brcms_c_ioctl(wl->wlc, BRCM_GET_CURR_RATESET,
 +                                &rs, sizeof(rs), NULL);
 +              UNLOCK(wl);
 +              if (error) {
 +                      wiphy_err(wiphy, "%s: retrieve rateset failed: %d\n",
 +                                __func__, error);
 +                      return;
 +              }
 +              br_mask = info->basic_rates;
 +              bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
 +              for (i = 0; i < bi->n_bitrates; i++) {
 +                      /* convert to internal rate value */
 +                      rate = (bi->bitrates[i].bitrate << 1) / 10;
 +
 +                      /* set/clear basic rate flag */
 +                      brcms_set_basic_rate(&rs, rate, br_mask & 1);
 +                      br_mask >>= 1;
 +              }
 +
 +              /* update the rate set */
 +              LOCK(wl);
 +              brcms_c_ioctl(wl->wlc, BRCM_SET_RATESET, &rs, sizeof(rs), NULL);
 +              UNLOCK(wl);
 +      }
 +      if (changed & BSS_CHANGED_BEACON_INT) {
 +              /* Beacon interval changed */
 +              LOCK(wl);
 +              brcms_c_set(wl->wlc, BRCM_SET_BCNPRD, info->beacon_int);
 +              UNLOCK(wl);
 +      }
 +      if (changed & BSS_CHANGED_BSSID) {
 +              /* BSSID changed, for whatever reason (IBSS and managed mode) */
 +              LOCK(wl);
 +              brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
 +                                info->bssid);
 +              UNLOCK(wl);
 +      }
 +      if (changed & BSS_CHANGED_BEACON) {
 +              /* Beacon data changed, retrieve new beacon (beaconing modes) */
 +              wiphy_err(wiphy, "%s: beacon changed\n", __func__);
 +      }
 +      if (changed & BSS_CHANGED_BEACON_ENABLED) {
 +              /* Beaconing should be enabled/disabled (beaconing modes) */
 +              wiphy_err(wiphy, "%s: Beacon enabled: %s\n", __func__,
 +                        info->enable_beacon ? "true" : "false");
 +      }
 +      if (changed & BSS_CHANGED_CQM) {
 +              /* Connection quality monitor config changed */
 +              wiphy_err(wiphy, "%s: cqm change: threshold %d, hys %d "
 +                        " (implement)\n", __func__, info->cqm_rssi_thold,
 +                        info->cqm_rssi_hyst);
 +      }
 +      if (changed & BSS_CHANGED_IBSS) {
 +              /* IBSS join status changed */
 +              wiphy_err(wiphy, "%s: IBSS joined: %s (implement)\n", __func__,
 +                        info->ibss_joined ? "true" : "false");
 +      }
 +      if (changed & BSS_CHANGED_ARP_FILTER) {
 +              /* Hardware ARP filter address list or state changed */
 +              wiphy_err(wiphy, "%s: arp filtering: enabled %s, count %d"
 +                        " (implement)\n", __func__, info->arp_filter_enabled ?
 +                        "true" : "false", info->arp_addr_cnt);
 +      }
 +      if (changed & BSS_CHANGED_QOS) {
 +              /*
 +               * QoS for this association was enabled/disabled.
 +               * Note that it is only ever disabled for station mode.
 +               */
 +              wiphy_err(wiphy, "%s: qos enabled: %s (implement)\n", __func__,
 +                        info->qos ? "true" : "false");
 +      }
 +      return;
 +}
 +
 +static void
 +brcms_ops_configure_filter(struct ieee80211_hw *hw,
 +                      unsigned int changed_flags,
 +                      unsigned int *total_flags, u64 multicast)
 +{
 +      struct brcms_info *wl = hw->priv;
 +      struct wiphy *wiphy = hw->wiphy;
 +
 +      changed_flags &= MAC_FILTERS;
 +      *total_flags &= MAC_FILTERS;
 +      if (changed_flags & FIF_PROMISC_IN_BSS)
 +              wiphy_err(wiphy, "FIF_PROMISC_IN_BSS\n");
 +      if (changed_flags & FIF_ALLMULTI)
 +              wiphy_err(wiphy, "FIF_ALLMULTI\n");
 +      if (changed_flags & FIF_FCSFAIL)
 +              wiphy_err(wiphy, "FIF_FCSFAIL\n");
 +      if (changed_flags & FIF_PLCPFAIL)
 +              wiphy_err(wiphy, "FIF_PLCPFAIL\n");
 +      if (changed_flags & FIF_CONTROL)
 +              wiphy_err(wiphy, "FIF_CONTROL\n");
 +      if (changed_flags & FIF_OTHER_BSS)
 +              wiphy_err(wiphy, "FIF_OTHER_BSS\n");
 +      if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
 +              LOCK(wl);
 +              if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
 +                      wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
 +                      brcms_c_mac_bcn_promisc_change(wl->wlc, 1);
 +              } else {
 +                      brcms_c_mac_bcn_promisc_change(wl->wlc, 0);
 +                      wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
 +              }
 +              UNLOCK(wl);
 +      }
 +      return;
 +}
 +
 +static int
 +brcms_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
 +{
 +      return 0;
 +}
 +
 +static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
 +{
 +      struct brcms_info *wl = hw->priv;
 +      LOCK(wl);
 +      brcms_c_scan_start(wl->wlc);
 +      UNLOCK(wl);
 +      return;
 +}
 +
 +static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
 +{
 +      struct brcms_info *wl = hw->priv;
 +      LOCK(wl);
 +      brcms_c_scan_stop(wl->wlc);
 +      UNLOCK(wl);
 +      return;
 +}
 +
 +static void brcms_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
 +{
 +      wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
 +      return;
 +}
 +
 +static int
 +brcms_ops_get_stats(struct ieee80211_hw *hw,
 +               struct ieee80211_low_level_stats *stats)
 +{
 +      struct brcms_info *wl = hw->priv;
 +      struct wl_cnt *cnt;
 +
 +      LOCK(wl);
 +      cnt = wl->pub->_cnt;
 +      stats->dot11ACKFailureCount = 0;
 +      stats->dot11RTSFailureCount = 0;
 +      stats->dot11FCSErrorCount = 0;
 +      stats->dot11RTSSuccessCount = 0;
 +      UNLOCK(wl);
 +      return 0;
 +}
 +
 +static void
 +brcms_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 +                enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
 +{
 +      switch (cmd) {
 +      default:
 +              wiphy_err(hw->wiphy, "%s: Unknown cmd = %d\n", __func__,
 +                        cmd);
 +              break;
 +      }
 +      return;
 +}
 +
 +static int
 +brcms_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
 +             const struct ieee80211_tx_queue_params *params)
 +{
 +      struct brcms_info *wl = hw->priv;
 +
 +      LOCK(wl);
 +      brcms_c_wme_setparams(wl->wlc, queue, params, true);
 +      UNLOCK(wl);
 +
 +      return 0;
 +}
 +
 +static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw)
 +{
 +      wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
 +      return 0;
 +}
 +
 +static int
 +brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 +             struct ieee80211_sta *sta)
 +{
 +      struct scb *scb;
 +
 +      int i;
 +      struct brcms_info *wl = hw->priv;
 +
 +      /* Init the scb */
 +      scb = (struct scb *)sta->drv_priv;
 +      memset(scb, 0, sizeof(struct scb));
 +      for (i = 0; i < NUMPRIO; i++)
 +              scb->seqctl[i] = 0xFFFF;
 +      scb->seqctl_nonqos = 0xFFFF;
 +      scb->magic = SCB_MAGIC;
 +
 +      wl->pub->global_scb = scb;
 +      wl->pub->global_ampdu = &(scb->scb_ampdu);
 +      wl->pub->global_ampdu->scb = scb;
 +      wl->pub->global_ampdu->max_pdu = 16;
 +      brcmu_pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
 +                AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
 +
 +      sta->ht_cap.ht_supported = true;
 +      sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
 +      sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
 +      sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
 +          IEEE80211_HT_CAP_SGI_20 |
 +          IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
 +
 +      /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
 +      return 0;
 +}
 +
 +static int
 +brcms_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 +                struct ieee80211_sta *sta)
 +{
 +      return 0;
 +}
 +
 +static int
 +brcms_ops_ampdu_action(struct ieee80211_hw *hw,
 +                  struct ieee80211_vif *vif,
 +                  enum ieee80211_ampdu_mlme_action action,
 +                  struct ieee80211_sta *sta, u16 tid, u16 *ssn,
 +                  u8 buf_size)
 +{
 +      struct scb *scb = (struct scb *)sta->drv_priv;
 +      struct brcms_info *wl = hw->priv;
 +      int status;
 +
 +      if (WARN_ON(scb->magic != SCB_MAGIC))
 +              return -EIDRM;
 +      switch (action) {
 +      case IEEE80211_AMPDU_RX_START:
 +              break;
 +      case IEEE80211_AMPDU_RX_STOP:
 +              break;
 +      case IEEE80211_AMPDU_TX_START:
 +              LOCK(wl);
 +              status = brcms_c_aggregatable(wl->wlc, tid);
 +              UNLOCK(wl);
 +              if (!status) {
 +                      wiphy_err(wl->wiphy, "START: tid %d is not agg\'able\n",
 +                                tid);
 +                      return -EINVAL;
 +              }
 +              /* Future improvement: Use the starting sequence number provided ... */
 +              *ssn = 0;
 +              ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
 +              break;
 +
 +      case IEEE80211_AMPDU_TX_STOP:
 +              LOCK(wl);
 +              brcms_c_ampdu_flush(wl->wlc, sta, tid);
 +              UNLOCK(wl);
 +              ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
 +              break;
 +      case IEEE80211_AMPDU_TX_OPERATIONAL:
 +              /*
 +               * BA window size from ADDBA response ('buf_size') defines how
 +               * many outstanding MPDUs are allowed for the BA stream by
 +               * recipient and traffic class. 'ampdu_factor' gives maximum
 +               * AMPDU size.
 +               */
 +              LOCK(wl);
 +              brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
 +                      (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
 +                       sta->ht_cap.ampdu_factor)) - 1);
 +              UNLOCK(wl);
 +              /* Power save wakeup */
 +              break;
 +      default:
 +              wiphy_err(wl->wiphy, "%s: Invalid command, ignoring\n",
 +                        __func__);
 +      }
 +
 +      return 0;
 +}
 +
 +static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
 +{
 +      struct brcms_info *wl = HW_TO_WL(hw);
 +      bool blocked;
 +
 +      LOCK(wl);
 +      blocked = brcms_c_check_radio_disabled(wl->wlc);
 +      UNLOCK(wl);
 +
 +      wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
 +}
 +
 +static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
 +{
 +      struct brcms_info *wl = HW_TO_WL(hw);
 +
 +      no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
 +
 +      /* wait for packet queue and dma fifos to run empty */
 +      LOCK(wl);
 +      brcms_c_wait_for_tx_completion(wl->wlc, drop);
 +      UNLOCK(wl);
 +}
 +
 +static const struct ieee80211_ops brcms_ops = {
 +      .tx = brcms_ops_tx,
 +      .start = brcms_ops_start,
 +      .stop = brcms_ops_stop,
 +      .add_interface = brcms_ops_add_interface,
 +      .remove_interface = brcms_ops_remove_interface,
 +      .config = brcms_ops_config,
 +      .bss_info_changed = brcms_ops_bss_info_changed,
 +      .configure_filter = brcms_ops_configure_filter,
 +      .set_tim = brcms_ops_set_tim,
 +      .sw_scan_start = brcms_ops_sw_scan_start,
 +      .sw_scan_complete = brcms_ops_sw_scan_complete,
 +      .set_tsf = brcms_ops_set_tsf,
 +      .get_stats = brcms_ops_get_stats,
 +      .sta_notify = brcms_ops_sta_notify,
 +      .conf_tx = brcms_ops_conf_tx,
 +      .get_tsf = brcms_ops_get_tsf,
 +      .sta_add = brcms_ops_sta_add,
 +      .sta_remove = brcms_ops_sta_remove,
 +      .ampdu_action = brcms_ops_ampdu_action,
 +      .rfkill_poll = brcms_ops_rfkill_poll,
 +      .flush = brcms_ops_flush,
 +};
 +
 +/*
 + * is called in brcms_pci_probe() context, therefore no locking required.
 + */
 +static int brcms_set_hint(struct brcms_info *wl, char *abbrev)
 +{
 +      return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
 +}
 +
 +/**
 + * attach to the WL device.
 + *
 + * Attach to the WL device identified by vendor and device parameters.
 + * regs is a host accessible memory address pointing to WL device registers.
 + *
 + * brcms_attach is not defined as static because in the case where no bus
 + * is defined, wl_attach will never be called, and thus, gcc will issue
 + * a warning that this function is defined but not used if we declare
 + * it as static.
 + *
 + *
 + * is called in brcms_pci_probe() context, therefore no locking required.
 + */
 +static struct brcms_info *brcms_attach(u16 vendor, u16 device,
 +                                     unsigned long regs,
 +                          uint bustype, void *btparam, uint irq)
 +{
 +      struct brcms_info *wl = NULL;
 +      int unit, err;
 +      unsigned long base_addr;
 +      struct ieee80211_hw *hw;
 +      u8 perm[ETH_ALEN];
 +
 +      unit = n_adapters_found;
 +      err = 0;
 +
 +      if (unit < 0) {
 +              return NULL;
 +      }
 +
 +      /* allocate private info */
 +      hw = pci_get_drvdata(btparam);  /* btparam == pdev */
 +      if (hw != NULL)
 +              wl = hw->priv;
 +      if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
 +              return NULL;
 +      wl->wiphy = hw->wiphy;
 +
 +      atomic_set(&wl->callbacks, 0);
 +
 +      /* setup the bottom half handler */
 +      tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
 +
 +
 +
 +      base_addr = regs;
 +
 +      if (bustype == PCI_BUS || bustype == RPC_BUS) {
 +              /* Do nothing */
 +      } else {
 +              bustype = PCI_BUS;
 +              BCMMSG(wl->wiphy, "force to PCI\n");
 +      }
 +      wl->bcm_bustype = bustype;
 +
 +      wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
 +      if (wl->regsva == NULL) {
 +              wiphy_err(wl->wiphy, "wl%d: ioremap() failed\n", unit);
 +              goto fail;
 +      }
 +      spin_lock_init(&wl->lock);
 +      spin_lock_init(&wl->isr_lock);
 +
 +      /* prepare ucode */
 +      if (brcms_request_fw(wl, (struct pci_dev *)btparam) < 0) {
 +              wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
 +                        "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
 +              brcms_release_fw(wl);
 +              brcms_remove((struct pci_dev *)btparam);
 +              return NULL;
 +      }
 +
 +      /* common load-time initialization */
 +      wl->wlc = brcms_c_attach((void *)wl, vendor, device, unit, false,
 +                           wl->regsva, wl->bcm_bustype, btparam, &err);
 +      brcms_release_fw(wl);
 +      if (!wl->wlc) {
 +              wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
 +                        KBUILD_MODNAME, err);
 +              goto fail;
 +      }
 +      wl->pub = brcms_c_pub(wl->wlc);
 +
 +      wl->pub->ieee_hw = hw;
 +
 +      if (brcms_c_set_par(wl->wlc, IOV_MPC, 0) < 0) {
 +              wiphy_err(wl->wiphy, "wl%d: Error setting MPC variable to 0\n",
 +                        unit);
 +      }
 +
 +      /* register our interrupt handler */
 +      if (request_irq(irq, brcms_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
 +              wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
 +              goto fail;
 +      }
 +      wl->irq = irq;
 +
 +      /* register module */
 +      brcms_c_module_register(wl->pub, "linux", wl, wl_linux_watchdog, NULL);
 +
 +      if (ieee_hw_init(hw)) {
 +              wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
 +                        __func__);
 +              goto fail;
 +      }
 +
 +      memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
 +      if (WARN_ON(!is_valid_ether_addr(perm)))
 +              goto fail;
 +      SET_IEEE80211_PERM_ADDR(hw, perm);
 +
 +      err = ieee80211_register_hw(hw);
 +      if (err) {
 +              wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
 +                        "%d\n", __func__, err);
 +      }
 +
 +      if (wl->pub->srom_ccode[0])
 +              err = brcms_set_hint(wl, wl->pub->srom_ccode);
 +      else
 +              err = brcms_set_hint(wl, "US");
 +      if (err) {
 +              wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n",
 +                        __func__, err);
 +      }
 +
 +      n_adapters_found++;
 +      return wl;
 +
 +fail:
 +      brcms_free(wl);
 +      return NULL;
 +}
 +
 +
 +
 +#define CHAN2GHZ(channel, freqency, chflags)  { \
 +      .band = IEEE80211_BAND_2GHZ, \
 +      .center_freq = (freqency), \
 +      .hw_value = (channel), \
 +      .flags = chflags, \
 +      .max_antenna_gain = 0, \
 +      .max_power = 19, \
 +}
 +
 +static struct ieee80211_channel brcms_2ghz_chantable[] = {
 +      CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN2GHZ(5, 2432, 0),
 +      CHAN2GHZ(6, 2437, 0),
 +      CHAN2GHZ(7, 2442, 0),
 +      CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN2GHZ(12, 2467,
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN2GHZ(13, 2472,
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN2GHZ(14, 2484,
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
 +};
 +
 +#define CHAN5GHZ(channel, chflags)  { \
 +      .band = IEEE80211_BAND_5GHZ, \
 +      .center_freq = 5000 + 5*(channel), \
 +      .hw_value = (channel), \
 +      .flags = chflags, \
 +      .max_antenna_gain = 0, \
 +      .max_power = 21, \
 +}
 +
 +static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
 +      /* UNII-1 */
 +      CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
 +      /* UNII-2 */
 +      CHAN5GHZ(52,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(56,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(60,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(64,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
 +      /* MID */
 +      CHAN5GHZ(100,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(104,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(108,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(112,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(116,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(120,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(124,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(128,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(132,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(136,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(140,
 +               IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
 +               IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
 +               IEEE80211_CHAN_NO_HT40MINUS),
 +      /* UNII-3 */
 +      CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
 +      CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
 +      CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
 +};
 +
 +#define RATE(rate100m, _flags) { \
 +      .bitrate = (rate100m), \
 +      .flags = (_flags), \
 +      .hw_value = (rate100m / 5), \
 +}
 +
 +static struct ieee80211_rate legacy_ratetable[] = {
 +      RATE(10, 0),
 +      RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
 +      RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
 +      RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
 +      RATE(60, 0),
 +      RATE(90, 0),
 +      RATE(120, 0),
 +      RATE(180, 0),
 +      RATE(240, 0),
 +      RATE(360, 0),
 +      RATE(480, 0),
 +      RATE(540, 0),
 +};
 +
 +static struct ieee80211_supported_band brcms_band_2GHz_nphy = {
 +      .band = IEEE80211_BAND_2GHZ,
 +      .channels = brcms_2ghz_chantable,
 +      .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
 +      .bitrates = legacy_ratetable,
 +      .n_bitrates = ARRAY_SIZE(legacy_ratetable),
 +      .ht_cap = {
 +                 /* from include/linux/ieee80211.h */
 +                 .cap = IEEE80211_HT_CAP_GRN_FLD |
 +                 IEEE80211_HT_CAP_SGI_20 |
 +                 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
 +                 .ht_supported = true,
 +                 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
 +                 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
 +                 .mcs = {
 +                         /* placeholders for now */
 +                         .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
 +                         .rx_highest = 500,
 +                         .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
 +                 }
 +};
 +
 +static struct ieee80211_supported_band brcms_band_5GHz_nphy = {
 +      .band = IEEE80211_BAND_5GHZ,
 +      .channels = brcms_5ghz_nphy_chantable,
 +      .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
 +      .bitrates = legacy_ratetable + 4,
 +      .n_bitrates = ARRAY_SIZE(legacy_ratetable) - 4,
 +      .ht_cap = {
 +                 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
 +                 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,     /* No 40 mhz yet */
 +                 .ht_supported = true,
 +                 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
 +                 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
 +                 .mcs = {
 +                         /* placeholders for now */
 +                         .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
 +                         .rx_highest = 500,
 +                         .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
 +                 }
 +};
 +
 +/*
 + * is called in brcms_pci_probe() context, therefore no locking required.
 + */
 +static int ieee_hw_rate_init(struct ieee80211_hw *hw)
 +{
 +      struct brcms_info *wl = HW_TO_WL(hw);
 +      int has_5g;
 +      char phy_list[4];
 +
 +      has_5g = 0;
 +
 +      hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
 +      hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
 +
 +      if (brcms_c_get(wl->wlc, BRCM_GET_PHYLIST, (int *)&phy_list) < 0)
 +              wiphy_err(hw->wiphy, "Phy list failed\n");
 +
 +      if (phy_list[0] == 'n' || phy_list[0] == 'c') {
 +              if (phy_list[0] == 'c') {
 +                      /* Single stream */
 +                      brcms_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
 +                      brcms_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
 +              }
 +              hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &brcms_band_2GHz_nphy;
 +      } else {
 +              return -EPERM;
 +      }
 +
 +      /* Assume all bands use the same phy.  True for 11n devices. */
 +      if (NBANDS_PUB(wl->pub) > 1) {
 +              has_5g++;
 +              if (phy_list[0] == 'n' || phy_list[0] == 'c') {
 +                      hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
 +                          &brcms_band_5GHz_nphy;
 +              } else {
 +                      return -EPERM;
 +              }
 +      }
 +      return 0;
 +}
 +
 +/*
 + * is called in brcms_pci_probe() context, therefore no locking required.
 + */
 +static int ieee_hw_init(struct ieee80211_hw *hw)
 +{
 +      hw->flags = IEEE80211_HW_SIGNAL_DBM
 +          /* | IEEE80211_HW_CONNECTION_MONITOR  What is this? */
 +          | IEEE80211_HW_REPORTS_TX_ACK_STATUS
 +          | IEEE80211_HW_AMPDU_AGGREGATION;
 +
 +      hw->extra_tx_headroom = brcms_c_get_header_len();
 +      hw->queues = N_TX_QUEUES;
 +      hw->max_rates = 2;      /* Primary rate and 1 fallback rate */
 +
 +      hw->channel_change_time = 7 * 1000;     /* channel change time is dependent on chip and band  */
 +      hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
 +
 +      hw->rate_control_algorithm = "minstrel_ht";
 +
 +      hw->sta_data_size = sizeof(struct scb);
 +      return ieee_hw_rate_init(hw);
 +}
 +
 +/**
 + * determines if a device is a WL device, and if so, attaches it.
 + *
 + * This function determines if a device pointed to by pdev is a WL device,
 + * and if so, performs a brcms_attach() on it.
 + *
 + * Perimeter lock is initialized in the course of this function.
 + */
 +static int __devinit
 +brcms_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 +{
 +      int rc;
 +      struct brcms_info *wl;
 +      struct ieee80211_hw *hw;
 +      u32 val;
 +
 +      dev_info(&pdev->dev, "bus %d slot %d func %d irq %d\n",
 +             pdev->bus->number, PCI_SLOT(pdev->devfn),
 +             PCI_FUNC(pdev->devfn), pdev->irq);
 +
 +      if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
 +          ((pdev->device != 0x0576) &&
 +           ((pdev->device & 0xff00) != 0x4300) &&
 +           ((pdev->device & 0xff00) != 0x4700) &&
 +           ((pdev->device < 43000) || (pdev->device > 43999))))
 +              return -ENODEV;
 +
 +      rc = pci_enable_device(pdev);
 +      if (rc) {
 +              pr_err("%s: Cannot enable device %d-%d_%d\n",
 +                     __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
 +                     PCI_FUNC(pdev->devfn));
 +              return -ENODEV;
 +      }
 +      pci_set_master(pdev);
 +
 +      pci_read_config_dword(pdev, 0x40, &val);
 +      if ((val & 0x0000ff00) != 0)
 +              pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
 +
 +      hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
 +      if (!hw) {
 +              pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
 +              return -ENOMEM;
 +      }
 +
 +      SET_IEEE80211_DEV(hw, &pdev->dev);
 +
 +      pci_set_drvdata(pdev, hw);
 +
 +      memset(hw->priv, 0, sizeof(*wl));
 +
 +      wl = brcms_attach(pdev->vendor, pdev->device,
 +                        pci_resource_start(pdev, 0), PCI_BUS, pdev,
 +                        pdev->irq);
 +
 +      if (!wl) {
 +              pr_err("%s: %s: brcms_attach failed!\n", KBUILD_MODNAME,
 +                     __func__);
 +              return -ENODEV;
 +      }
 +      return 0;
 +}
 +
 +static int brcms_suspend(struct pci_dev *pdev, pm_message_t state)
 +{
 +      struct brcms_info *wl;
 +      struct ieee80211_hw *hw;
 +
 +      hw = pci_get_drvdata(pdev);
 +      wl = HW_TO_WL(hw);
 +      if (!wl) {
 +              wiphy_err(wl->wiphy,
 +                        "brcms_suspend: pci_get_drvdata failed\n");
 +              return -ENODEV;
 +      }
 +
 +      /* only need to flag hw is down for proper resume */
 +      LOCK(wl);
 +      wl->pub->hw_up = false;
 +      UNLOCK(wl);
 +
 +      pci_save_state(pdev);
 +      pci_disable_device(pdev);
 +      return pci_set_power_state(pdev, PCI_D3hot);
 +}
 +
 +static int brcms_resume(struct pci_dev *pdev)
 +{
 +      struct brcms_info *wl;
 +      struct ieee80211_hw *hw;
 +      int err = 0;
 +      u32 val;
 +
 +      hw = pci_get_drvdata(pdev);
 +      wl = HW_TO_WL(hw);
 +      if (!wl) {
 +              wiphy_err(wl->wiphy,
 +                        "wl: brcms_resume: pci_get_drvdata failed\n");
 +              return -ENODEV;
 +      }
 +
 +      err = pci_set_power_state(pdev, PCI_D0);
 +      if (err)
 +              return err;
 +
 +      pci_restore_state(pdev);
 +
 +      err = pci_enable_device(pdev);
 +      if (err)
 +              return err;
 +
 +      pci_set_master(pdev);
 +
 +      pci_read_config_dword(pdev, 0x40, &val);
 +      if ((val & 0x0000ff00) != 0)
 +              pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
 +
 +      /*
 +      *  done. driver will be put in up state
 +      *  in brcms_ops_add_interface() call.
 +      */
 +      return err;
 +}
 +
 +/*
 +* called from both kernel as from this kernel module.
 +* precondition: perimeter lock is not acquired.
 +*/
 +static void brcms_remove(struct pci_dev *pdev)
 +{
 +      struct brcms_info *wl;
 +      struct ieee80211_hw *hw;
 +      int status;
 +
 +      hw = pci_get_drvdata(pdev);
 +      wl = HW_TO_WL(hw);
 +      if (!wl) {
 +              pr_err("wl: brcms_remove: pci_get_drvdata failed\n");
 +              return;
 +      }
 +
 +      LOCK(wl);
 +      status = brcms_c_chipmatch(pdev->vendor, pdev->device);
 +      UNLOCK(wl);
 +      if (!status) {
 +              wiphy_err(wl->wiphy, "wl: brcms_remove: chipmatch "
 +                                   "failed\n");
 +              return;
 +      }
 +      if (wl->wlc) {
 +              wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
 +              wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
 +              ieee80211_unregister_hw(hw);
 +              LOCK(wl);
 +              brcms_down(wl);
 +              UNLOCK(wl);
 +      }
 +      pci_disable_device(pdev);
 +
 +      brcms_free(wl);
 +
 +      pci_set_drvdata(pdev, NULL);
 +      ieee80211_free_hw(hw);
 +}
 +
 +static struct pci_driver brcms_pci_driver = {
 +      .name     = KBUILD_MODNAME,
 +      .probe    = brcms_pci_probe,
 +      .suspend  = brcms_suspend,
 +      .resume   = brcms_resume,
 +      .remove   = __devexit_p(brcms_remove),
 +      .id_table = brcms_pci_id_table,
 +};
 +
 +/**
 + * This is the main entry point for the WL driver.
 + *
 + * This function determines if a device pointed to by pdev is a WL device,
 + * and if so, performs a brcms_attach() on it.
 + *
 + */
 +static int __init brcms_module_init(void)
 +{
 +      int error = -ENODEV;
 +
 +#ifdef BCMDBG
 +      if (msglevel != 0xdeadbeef)
 +              brcm_msg_level = msglevel;
 +      if (phymsglevel != 0xdeadbeef)
 +              phyhal_msg_level = phymsglevel;
 +#endif                                /* BCMDBG */
 +
 +      error = pci_register_driver(&brcms_pci_driver);
 +      if (!error)
 +              return 0;
 +
 +
 +
 +      return error;
 +}
 +
 +/**
 + * This function unloads the WL driver from the system.
 + *
 + * This function unconditionally unloads the WL driver module from the
 + * system.
 + *
 + */
 +static void __exit brcms_module_exit(void)
 +{
 +      pci_unregister_driver(&brcms_pci_driver);
 +
 +}
 +
 +module_init(brcms_module_init);
 +module_exit(brcms_module_exit);
 +
 +/**
 + * This function frees the WL per-device resources.
 + *
 + * This function frees resources owned by the WL device pointed to
 + * by the wl parameter.
 + *
 + * precondition: can both be called locked and unlocked
 + *
 + */
 +static void brcms_free(struct brcms_info *wl)
 +{
 +      struct brcms_timer *t, *next;
 +
 +      /* free ucode data */
 +      if (wl->fw.fw_cnt)
 +              brcms_ucode_data_free();
 +      if (wl->irq)
 +              free_irq(wl->irq, wl);
 +
 +      /* kill dpc */
 +      tasklet_kill(&wl->tasklet);
 +
 +      if (wl->pub) {
 +              brcms_c_module_unregister(wl->pub, "linux", wl);
 +      }
 +
 +      /* free common resources */
 +      if (wl->wlc) {
 +              brcms_c_detach(wl->wlc);
 +              wl->wlc = NULL;
 +              wl->pub = NULL;
 +      }
 +
 +      /* virtual interface deletion is deferred so we cannot spinwait */
 +
 +      /* wait for all pending callbacks to complete */
 +      while (atomic_read(&wl->callbacks) > 0)
 +              schedule();
 +
 +      /* free timers */
 +      for (t = wl->timers; t; t = next) {
 +              next = t->next;
 +#ifdef BCMDBG
 +              kfree(t->name);
 +#endif
 +              kfree(t);
 +      }
 +
 +      /*
 +       * unregister_netdev() calls get_stats() which may read chip registers
 +       * so we cannot unmap the chip registers until after calling unregister_netdev() .
 +       */
 +      if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
 +          wl->bcm_bustype != JTAG_BUS) {
 +              iounmap((void *)wl->regsva);
 +      }
 +      wl->regsva = NULL;
 +}
 +
 +/* flags the given rate in rateset as requested */
 +static void brcms_set_basic_rate(struct wl_rateset *rs, u16 rate, bool is_br)
 +{
 +      u32 i;
 +
 +      for (i = 0; i < rs->count; i++) {
 +              if (rate != (rs->rates[i] & 0x7f))
 +                      continue;
 +
 +              if (is_br)
 +                      rs->rates[i] |= BRCMS_RATE_FLAG;
 +              else
 +                      rs->rates[i] &= BRCMS_RATE_MASK;
 +              return;
 +      }
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
 +                       bool state, int prio)
 +{
 +      wiphy_err(wl->wiphy, "Shouldn't be here %s\n", __func__);
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +void brcms_init(struct brcms_info *wl)
 +{
 +      BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
 +      brcms_reset(wl);
 +
 +      brcms_c_init(wl->wlc);
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +uint brcms_reset(struct brcms_info *wl)
 +{
 +      BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
 +      brcms_c_reset(wl->wlc);
 +
 +      /* dpc will not be rescheduled */
 +      wl->resched = 0;
 +
 +      return 0;
 +}
 +
 +/*
 + * These are interrupt on/off entry points. Disable interrupts
 + * during interrupt state transition.
 + */
 +void brcms_intrson(struct brcms_info *wl)
 +{
 +      unsigned long flags;
 +
 +      INT_LOCK(wl, flags);
 +      brcms_c_intrson(wl->wlc);
 +      INT_UNLOCK(wl, flags);
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +bool wl_alloc_dma_resources(struct brcms_info *wl, uint addrwidth)
 +{
 +      return true;
 +}
 +
 +u32 brcms_intrsoff(struct brcms_info *wl)
 +{
 +      unsigned long flags;
 +      u32 status;
 +
 +      INT_LOCK(wl, flags);
 +      status = brcms_c_intrsoff(wl->wlc);
 +      INT_UNLOCK(wl, flags);
 +      return status;
 +}
 +
 +void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
 +{
 +      unsigned long flags;
 +
 +      INT_LOCK(wl, flags);
 +      brcms_c_intrsrestore(wl->wlc, macintmask);
 +      INT_UNLOCK(wl, flags);
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +int brcms_up(struct brcms_info *wl)
 +{
 +      int error = 0;
 +
 +      if (wl->pub->up)
 +              return 0;
 +
 +      error = brcms_c_up(wl->wlc);
 +
 +      return error;
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +void brcms_down(struct brcms_info *wl)
 +{
 +      uint callbacks, ret_val = 0;
 +
 +      /* call common down function */
 +      ret_val = brcms_c_down(wl->wlc);
 +      callbacks = atomic_read(&wl->callbacks) - ret_val;
 +
 +      /* wait for down callbacks to complete */
 +      UNLOCK(wl);
 +
 +      /* For HIGH_only driver, it's important to actually schedule other work,
 +       * not just spin wait since everything runs at schedule level
 +       */
 +      SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
 +
 +      LOCK(wl);
 +}
 +
 +static irqreturn_t brcms_isr(int irq, void *dev_id)
 +{
 +      struct brcms_info *wl;
 +      bool ours, wantdpc;
 +      unsigned long flags;
 +
 +      wl = (struct brcms_info *) dev_id;
 +
 +      ISR_LOCK(wl, flags);
 +
 +      /* call common first level interrupt handler */
 +      ours = brcms_c_isr(wl->wlc, &wantdpc);
 +      if (ours) {
 +              /* if more to do... */
 +              if (wantdpc) {
 +
 +                      /* ...and call the second level interrupt handler */
 +                      /* schedule dpc */
 +                      tasklet_schedule(&wl->tasklet);
 +              }
 +      }
 +
 +      ISR_UNLOCK(wl, flags);
 +
 +      return IRQ_RETVAL(ours);
 +}
 +
 +static void brcms_dpc(unsigned long data)
 +{
 +      struct brcms_info *wl;
 +
 +      wl = (struct brcms_info *) data;
 +
 +      LOCK(wl);
 +
 +      /* call the common second level interrupt handler */
 +      if (wl->pub->up) {
 +              if (wl->resched) {
 +                      unsigned long flags;
 +
 +                      INT_LOCK(wl, flags);
 +                      brcms_c_intrsupd(wl->wlc);
 +                      INT_UNLOCK(wl, flags);
 +              }
 +
 +              wl->resched = brcms_c_dpc(wl->wlc, true);
 +      }
 +
 +      /* brcms_c_dpc() may bring the driver down */
 +      if (!wl->pub->up)
 +              goto done;
 +
 +      /* re-schedule dpc */
 +      if (wl->resched)
 +              tasklet_schedule(&wl->tasklet);
 +      else {
 +              /* re-enable interrupts */
 +              brcms_intrson(wl);
 +      }
 +
 + done:
 +      UNLOCK(wl);
 +}
 +
 +/*
 + * is called by the kernel from software irq context
 + */
 +static void brcms_timer(unsigned long data)
 +{
 +      _brcms_timer((struct brcms_timer *) data);
 +}
 +
 +/*
 +* precondition: perimeter lock is not acquired
 + */
 +static void _brcms_timer(struct brcms_timer *t)
 +{
 +      LOCK(t->wl);
 +
 +      if (t->set) {
 +              if (t->periodic) {
 +                      t->timer.expires = jiffies + t->ms * HZ / 1000;
 +                      atomic_inc(&t->wl->callbacks);
 +                      add_timer(&t->timer);
 +                      t->set = true;
 +              } else
 +                      t->set = false;
 +
 +              t->fn(t->arg);
 +      }
 +
 +      atomic_dec(&t->wl->callbacks);
 +
 +      UNLOCK(t->wl);
 +}
 +
 +/*
 + * Adds a timer to the list. Caller supplies a timer function.
 + * Is called from wlc.
 + *
 + * precondition: perimeter lock has been acquired
 + */
 +struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
 +                                   void (*fn) (void *arg),
 +                                   void *arg, const char *name)
 +{
 +      struct brcms_timer *t;
 +
 +      t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
 +      if (!t) {
 +              wiphy_err(wl->wiphy, "wl%d: brcms_init_timer: out of memory\n",
 +                        wl->pub->unit);
 +              return 0;
 +      }
 +
 +      init_timer(&t->timer);
 +      t->timer.data = (unsigned long) t;
 +      t->timer.function = brcms_timer;
 +      t->wl = wl;
 +      t->fn = fn;
 +      t->arg = arg;
 +      t->next = wl->timers;
 +      wl->timers = t;
 +
 +#ifdef BCMDBG
 +      t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
 +      if (t->name)
 +              strcpy(t->name, name);
 +#endif
 +
 +      return t;
 +}
 +
 +/* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
 + * as well as it's easier to make it periodic
 + *
 + * precondition: perimeter lock has been acquired
 + */
 +void brcms_add_timer(struct brcms_info *wl, struct brcms_timer *t, uint ms,
 +                   int periodic)
 +{
 +#ifdef BCMDBG
 +      if (t->set) {
 +              wiphy_err(wl->wiphy, "%s: Already set. Name: %s, per %d\n",
 +                        __func__, t->name, periodic);
 +      }
 +#endif
 +      t->ms = ms;
 +      t->periodic = (bool) periodic;
 +      t->set = true;
 +      t->timer.expires = jiffies + ms * HZ / 1000;
 +
 +      atomic_inc(&wl->callbacks);
 +      add_timer(&t->timer);
 +}
 +
 +/*
 + * return true if timer successfully deleted, false if still pending
 + *
 + * precondition: perimeter lock has been acquired
 + */
 +bool brcms_del_timer(struct brcms_info *wl, struct brcms_timer *t)
 +{
 +      if (t->set) {
 +              t->set = false;
 +              if (!del_timer(&t->timer)) {
 +                      return false;
 +              }
 +              atomic_dec(&wl->callbacks);
 +      }
 +
 +      return true;
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +void brcms_free_timer(struct brcms_info *wl, struct brcms_timer *t)
 +{
 +      struct brcms_timer *tmp;
 +
 +      /* delete the timer in case it is active */
 +      brcms_del_timer(wl, t);
 +
 +      if (wl->timers == t) {
 +              wl->timers = wl->timers->next;
 +#ifdef BCMDBG
 +              kfree(t->name);
 +#endif
 +              kfree(t);
 +              return;
 +
 +      }
 +
 +      tmp = wl->timers;
 +      while (tmp) {
 +              if (tmp->next == t) {
 +                      tmp->next = t->next;
 +#ifdef BCMDBG
 +                      kfree(t->name);
 +#endif
 +                      kfree(t);
 +                      return;
 +              }
 +              tmp = tmp->next;
 +      }
 +
 +}
 +
 +/*
 + * runs in software irq context
 + *
 + * precondition: perimeter lock is not acquired
 + */
 +static int wl_linux_watchdog(void *ctx)
 +{
 +      return 0;
 +}
 +
 +struct firmware_hdr {
 +      u32 offset;
 +      u32 len;
 +      u32 idx;
 +};
 +
 +char *brcms_firmwares[MAX_FW_IMAGES] = {
 +      "brcm/bcm43xx",
 +      NULL
 +};
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
 +{
 +      int i, entry;
 +      const u8 *pdata;
 +      struct firmware_hdr *hdr;
 +      for (i = 0; i < wl->fw.fw_cnt; i++) {
 +              hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
 +              for (entry = 0; entry < wl->fw.hdr_num_entries[i];
 +                   entry++, hdr++) {
 +                      if (hdr->idx == idx) {
 +                              pdata = wl->fw.fw_bin[i]->data + hdr->offset;
 +                              *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
 +                              if (*pbuf == NULL) {
 +                                      wiphy_err(wl->wiphy, "fail to alloc %d"
 +                                                " bytes\n", hdr->len);
 +                                      goto fail;
 +                              }
 +                              memcpy(*pbuf, pdata, hdr->len);
 +                              return 0;
 +                      }
 +              }
 +      }
 +      wiphy_err(wl->wiphy, "ERROR: ucode buf tag:%d can not be found!\n",
 +                idx);
 +      *pbuf = NULL;
 +fail:
 +      return -ENODATA;
 +}
 +
 +/*
 + * Precondition: Since this function is called in brcms_pci_probe() context,
 + * no locking is required.
 + */
 +int brcms_ucode_init_uint(struct brcms_info *wl, u32 *data, u32 idx)
 +{
 +      int i, entry;
 +      const u8 *pdata;
 +      struct firmware_hdr *hdr;
 +      for (i = 0; i < wl->fw.fw_cnt; i++) {
 +              hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
 +              for (entry = 0; entry < wl->fw.hdr_num_entries[i];
 +                   entry++, hdr++) {
 +                      if (hdr->idx == idx) {
 +                              pdata = wl->fw.fw_bin[i]->data + hdr->offset;
 +                              if (hdr->len != 4) {
 +                                      wiphy_err(wl->wiphy,
 +                                                "ERROR: fw hdr len\n");
 +                                      return -ENOMSG;
 +                              }
 +                              *data = *((u32 *) pdata);
 +                              return 0;
 +                      }
 +              }
 +      }
 +      wiphy_err(wl->wiphy, "ERROR: ucode tag:%d can not be found!\n", idx);
 +      return -ENOMSG;
 +}
 +
 +/*
 + * Precondition: Since this function is called in brcms_pci_probe() context,
 + * no locking is required.
 + */
 +static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev)
 +{
 +      int status;
 +      struct device *device = &pdev->dev;
 +      char fw_name[100];
 +      int i;
 +
 +      memset((void *)&wl->fw, 0, sizeof(struct brcms_firmware));
 +      for (i = 0; i < MAX_FW_IMAGES; i++) {
 +              if (brcms_firmwares[i] == NULL)
 +                      break;
 +              sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
 +                      UCODE_LOADER_API_VER);
 +              status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
 +              if (status) {
 +                      wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
 +                                KBUILD_MODNAME, fw_name);
 +                      return status;
 +              }
 +              sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
 +                      UCODE_LOADER_API_VER);
 +              status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
 +              if (status) {
 +                      wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
 +                                KBUILD_MODNAME, fw_name);
 +                      return status;
 +              }
 +              wl->fw.hdr_num_entries[i] =
 +                  wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
 +      }
 +      wl->fw.fw_cnt = i;
 +      return brcms_ucode_data_init(wl);
 +}
 +
 +/*
 + * precondition: can both be called locked and unlocked
 + */
 +void brcms_ucode_free_buf(void *p)
 +{
 +      kfree(p);
 +}
 +
 +/*
 + * Precondition: Since this function is called in brcms_pci_probe() context,
 + * no locking is required.
 + */
 +static void brcms_release_fw(struct brcms_info *wl)
 +{
 +      int i;
 +      for (i = 0; i < MAX_FW_IMAGES; i++) {
 +              release_firmware(wl->fw.fw_bin[i]);
 +              release_firmware(wl->fw.fw_hdr[i]);
 +      }
 +}
 +
 +
 +/*
 + * checks validity of all firmware images loaded from user space
 + *
 + * Precondition: Since this function is called in brcms_pci_probe() context,
 + * no locking is required.
 + */
 +int brcms_check_firmwares(struct brcms_info *wl)
 +{
 +      int i;
 +      int entry;
 +      int rc = 0;
 +      const struct firmware *fw;
 +      const struct firmware *fw_hdr;
 +      struct firmware_hdr *ucode_hdr;
 +      for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
 +              fw =  wl->fw.fw_bin[i];
 +              fw_hdr = wl->fw.fw_hdr[i];
 +              if (fw == NULL && fw_hdr == NULL) {
 +                      break;
 +              } else if (fw == NULL || fw_hdr == NULL) {
 +                      wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
 +                                __func__);
 +                      rc = -EBADF;
 +              } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
 +                      wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
 +                              "size %zu/%zu\n", __func__, fw_hdr->size,
 +                              sizeof(struct firmware_hdr));
 +                      rc = -EBADF;
 +              } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
 +                      wiphy_err(wl->wiphy, "%s: out of bounds fw file size "
 +                                "%zu\n", __func__, fw->size);
 +                      rc = -EBADF;
 +              } else {
 +                      /* check if ucode section overruns firmware image */
 +                      ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
 +                      for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
 +                           !rc; entry++, ucode_hdr++) {
 +                              if (ucode_hdr->offset + ucode_hdr->len >
 +                                  fw->size) {
 +                                      wiphy_err(wl->wiphy,
 +                                                "%s: conflicting bin/hdr\n",
 +                                                __func__);
 +                                      rc = -EBADF;
 +                              }
 +                      }
 +              }
 +      }
 +      if (rc == 0 && wl->fw.fw_cnt != i) {
 +              wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
 +                      wl->fw.fw_cnt);
 +              rc = -EBADF;
 +      }
 +      return rc;
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
 +{
 +      bool blocked = brcms_c_check_radio_disabled(wl->wlc);
 +
 +      UNLOCK(wl);
 +      wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
 +      if (blocked)
 +              wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
 +      LOCK(wl);
 +      return blocked;
 +}
 +
 +/*
 + * precondition: perimeter lock has been acquired
 + */
 +void brcms_msleep(struct brcms_info *wl, uint ms)
 +{
 +      UNLOCK(wl);
 +      msleep(ms);
 +      LOCK(wl);
 +}
index 40e3d37,0000000..5711e7c
mode 100644,000000..100644
--- /dev/null
@@@ -1,108 -1,0 +1,110 @@@
 +/*
 + * Copyright (c) 2010 Broadcom Corporation
 + *
 + * Permission to use, copy, modify, and/or distribute this software for any
 + * purpose with or without fee is hereby granted, provided that the above
 + * copyright notice and this permission notice appear in all copies.
 + *
 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 + */
 +
 +#ifndef _BRCM_MAC80211_IF_H_
 +#define _BRCM_MAC80211_IF_H_
 +
 +#include <linux/timer.h>
 +#include <linux/interrupt.h>
 +
 +/* softmac ioctl definitions */
 +#define BRCMS_SET_SHORTSLOT_OVERRIDE          146
 +
 +
++#include <linux/interrupt.h>
++
 +/* BMAC Note: High-only driver is no longer working in softirq context as it needs to block and
 + * sleep so perimeter lock has to be a semaphore instead of spinlock. This requires timers to be
 + * submitted to workqueue instead of being on kernel timer
 + */
 +struct brcms_timer {
 +      struct timer_list timer;
 +      struct brcms_info *wl;
 +      void (*fn) (void *);
 +      void *arg;              /* argument to fn */
 +      uint ms;
 +      bool periodic;
 +      bool set;
 +      struct brcms_timer *next;
 +#ifdef BCMDBG
 +      char *name;             /* Description of the timer */
 +#endif
 +};
 +
 +struct brcms_if {
 +      uint subunit;           /* WDS/BSS unit */
 +      struct pci_dev *pci_dev;
 +};
 +
 +#define MAX_FW_IMAGES         4
 +struct brcms_firmware {
 +      u32 fw_cnt;
 +      const struct firmware *fw_bin[MAX_FW_IMAGES];
 +      const struct firmware *fw_hdr[MAX_FW_IMAGES];
 +      u32 hdr_num_entries[MAX_FW_IMAGES];
 +};
 +
 +struct brcms_info {
 +      struct brcms_pub *pub;          /* pointer to public wlc state */
 +      void *wlc;              /* pointer to private common os-independent data */
 +      u32 magic;
 +
 +      int irq;
 +
 +      spinlock_t lock;        /* per-device perimeter lock */
 +      spinlock_t isr_lock;    /* per-device ISR synchronization lock */
 +
 +      /* bus type and regsva for unmap in brcms_free() */
 +      uint bcm_bustype;       /* bus type */
 +      void *regsva;           /* opaque chip registers virtual address */
 +
 +      /* timer related fields */
 +      atomic_t callbacks;     /* # outstanding callback functions */
 +      struct brcms_timer *timers;     /* timer cleanup queue */
 +
 +      struct tasklet_struct tasklet;  /* dpc tasklet */
 +      bool resched;           /* dpc needs to be and is rescheduled */
 +#ifdef LINUXSTA_PS
 +      u32 pci_psstate[16];    /* pci ps-state save/restore */
 +#endif
 +      struct brcms_firmware fw;
 +      struct wiphy *wiphy;
 +};
 +
 +/* misc callbacks */
 +extern void brcms_init(struct brcms_info *wl);
 +extern uint brcms_reset(struct brcms_info *wl);
 +extern void brcms_intrson(struct brcms_info *wl);
 +extern u32 brcms_intrsoff(struct brcms_info *wl);
 +extern void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask);
 +extern int brcms_up(struct brcms_info *wl);
 +extern void brcms_down(struct brcms_info *wl);
 +extern void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
 +                              bool state, int prio);
 +extern bool wl_alloc_dma_resources(struct brcms_info *wl, uint dmaddrwidth);
 +extern bool brcms_rfkill_set_hw_state(struct brcms_info *wl);
 +
 +/* timer functions */
 +extern struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
 +                                    void (*fn) (void *arg), void *arg,
 +                                    const char *name);
 +extern void brcms_free_timer(struct brcms_info *wl, struct brcms_timer *timer);
 +extern void brcms_add_timer(struct brcms_info *wl, struct brcms_timer *timer,
 +                          uint ms, int periodic);
 +extern bool brcms_del_timer(struct brcms_info *wl, struct brcms_timer *timer);
 +extern void brcms_msleep(struct brcms_info *wl, uint ms);
 +
 +#endif                                /* _BRCM_MAC80211_IF_H_ */
  #include "et131x_adapter.h"
  #include "et131x.h"
  
+ struct net_device_stats *et131x_stats(struct net_device *netdev);
+ int et131x_open(struct net_device *netdev);
+ int et131x_close(struct net_device *netdev);
+ int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, int cmd);
+ void et131x_multicast(struct net_device *netdev);
+ int et131x_tx(struct sk_buff *skb, struct net_device *netdev);
+ void et131x_tx_timeout(struct net_device *netdev);
+ int et131x_change_mtu(struct net_device *netdev, int new_mtu);
+ int et131x_set_mac_addr(struct net_device *netdev, void *new_mac);
+ void et131x_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
+ void et131x_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
+ static const struct net_device_ops et131x_netdev_ops = {
+       .ndo_open               = et131x_open,
+       .ndo_stop               = et131x_close,
+       .ndo_start_xmit         = et131x_tx,
+       .ndo_set_multicast_list = et131x_multicast,
+       .ndo_tx_timeout         = et131x_tx_timeout,
+       .ndo_change_mtu         = et131x_change_mtu,
+       .ndo_set_mac_address    = et131x_set_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_get_stats          = et131x_stats,
+       .ndo_do_ioctl           = et131x_ioctl,
+ };
+ /**
+  * et131x_device_alloc
+  *
+  * Returns pointer to the allocated and initialized net_device struct for
+  * this device.
+  *
+  * Create instances of net_device and wl_private for the new adapter and
+  * register the device's entry points in the net_device structure.
+  */
+ struct net_device *et131x_device_alloc(void)
+ {
+       struct net_device *netdev;
+       /* Alloc net_device and adapter structs */
+       netdev = alloc_etherdev(sizeof(struct et131x_adapter));
+       if (netdev == NULL) {
+               printk(KERN_ERR "et131x: Alloc of net_device struct failed\n");
+               return NULL;
+       }
+       /* Setup the function registration table (and other data) for a
+        * net_device
+        */
+       /* netdev->init               = &et131x_init; */
+       /* netdev->set_config = &et131x_config; */
+       netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
+       netdev->netdev_ops = &et131x_netdev_ops;
+       /* netdev->ethtool_ops        = &et131x_ethtool_ops; */
+       /* Poll? */
+       /* netdev->poll               = &et131x_poll; */
+       /* netdev->poll_controller    = &et131x_poll_controller; */
+       return netdev;
+ }
  /**
   * et131x_stats - Return the current device statistics.
   * @netdev: device whose stats are being queried
   *
   * Returns 0 on success, errno on failure (as defined in errno.h)
   */
 -struct net_device_stats *et131x_stats(struct net_device *netdev)
 +static struct net_device_stats *et131x_stats(struct net_device *netdev)
  {
        struct et131x_adapter *adapter = netdev_priv(netdev);
        struct net_device_stats *stats = &adapter->net_stats;
 -      CE_STATS_t *devstat = &adapter->Stats;
 +      struct ce_stats *devstat = &adapter->stats;
  
 -      stats->rx_packets = devstat->ipackets;
 -      stats->tx_packets = devstat->opackets;
        stats->rx_errors = devstat->length_err + devstat->alignment_err +
            devstat->crc_err + devstat->code_violations + devstat->other_errors;
        stats->tx_errors = devstat->max_pkt_error;
@@@ -162,7 -226,7 +224,7 @@@ int et131x_open(struct net_device *netd
        /* Enable device interrupts */
        et131x_enable_interrupts(adapter);
  
 -      adapter->Flags |= fMP_ADAPTER_INTERRUPT_IN_USE;
 +      adapter->flags |= fMP_ADAPTER_INTERRUPT_IN_USE;
  
        /* We're ready to move some data, so start the queue */
        netif_start_queue(netdev);
@@@ -190,7 -254,7 +252,7 @@@ int et131x_close(struct net_device *net
        et131x_disable_interrupts(adapter);
  
        /* Deregistering ISR */
 -      adapter->Flags &= ~fMP_ADAPTER_INTERRUPT_IN_USE;
 +      adapter->flags &= ~fMP_ADAPTER_INTERRUPT_IN_USE;
        free_irq(netdev->irq, netdev);
  
        /* Stop the error timer */
@@@ -214,7 -278,7 +276,7 @@@ int et131x_ioctl_mii(struct net_device 
  
        switch (cmd) {
        case SIOCGMIIPHY:
 -              data->phy_id = etdev->Stats.xcvr_addr;
 +              data->phy_id = etdev->stats.xcvr_addr;
                break;
  
        case SIOCGMIIREG:
@@@ -446,14 -510,18 +508,14 @@@ void et131x_tx_timeout(struct net_devic
        struct tcb *tcb;
        unsigned long flags;
  
 -      /* Just skip this part if the adapter is doing link detection */
 -      if (etdev->Flags & fMP_ADAPTER_LINK_DETECTION)
 -              return;
 -
        /* Any nonrecoverable hardware error?
         * Checks adapter->flags for any failure in phy reading
         */
 -      if (etdev->Flags & fMP_ADAPTER_NON_RECOVER_ERROR)
 +      if (etdev->flags & fMP_ADAPTER_NON_RECOVER_ERROR)
                return;
  
        /* Hardware failure? */
 -      if (etdev->Flags & fMP_ADAPTER_HARDWARE_ERROR) {
 +      if (etdev->flags & fMP_ADAPTER_HARDWARE_ERROR) {
                dev_err(&etdev->pdev->dev, "hardware error - reset\n");
                return;
        }
                                               flags);
  
                        dev_warn(&etdev->pdev->dev,
 -                              "Send stuck - reset.  tcb->WrIndex %x, Flags 0x%08x\n",
 +                              "Send stuck - reset.  tcb->WrIndex %x, flags 0x%08x\n",
                                tcb->index,
                                tcb->flags);
  
@@@ -540,7 -608,7 +602,7 @@@ int et131x_change_mtu(struct net_devic
        et131x_adapter_setup(adapter);
  
        /* Enable interrupts */
 -      if (adapter->Flags & fMP_ADAPTER_INTERRUPT_IN_USE)
 +      if (adapter->flags & fMP_ADAPTER_INTERRUPT_IN_USE)
                et131x_enable_interrupts(adapter);
  
        /* Restart the Tx and Rx DMA engines */
@@@ -622,7 -690,7 +684,7 @@@ int et131x_set_mac_addr(struct net_devi
        et131x_adapter_setup(adapter);
  
        /* Enable interrupts */
 -      if (adapter->Flags & fMP_ADAPTER_INTERRUPT_IN_USE)
 +      if (adapter->flags & fMP_ADAPTER_INTERRUPT_IN_USE)
                et131x_enable_interrupts(adapter);
  
        /* Restart the Tx and Rx DMA engines */
        netif_wake_queue(netdev);
        return result;
  }
 +
 +static const struct net_device_ops et131x_netdev_ops = {
 +      .ndo_open               = et131x_open,
 +      .ndo_stop               = et131x_close,
 +      .ndo_start_xmit         = et131x_tx,
 +      .ndo_set_multicast_list = et131x_multicast,
 +      .ndo_tx_timeout         = et131x_tx_timeout,
 +      .ndo_change_mtu         = et131x_change_mtu,
 +      .ndo_set_mac_address    = et131x_set_mac_addr,
 +      .ndo_validate_addr      = eth_validate_addr,
 +      .ndo_get_stats          = et131x_stats,
 +      .ndo_do_ioctl           = et131x_ioctl,
 +};
 +
 +/**
 + * et131x_device_alloc
 + *
 + * Returns pointer to the allocated and initialized net_device struct for
 + * this device.
 + *
 + * Create instances of net_device and wl_private for the new adapter and
 + * register the device's entry points in the net_device structure.
 + */
 +struct net_device *et131x_device_alloc(void)
 +{
 +      struct net_device *netdev;
 +
 +      /* Alloc net_device and adapter structs */
 +      netdev = alloc_etherdev(sizeof(struct et131x_adapter));
 +
 +      if (netdev == NULL) {
 +              printk(KERN_ERR "et131x: Alloc of net_device struct failed\n");
 +              return NULL;
 +      }
 +
 +      /* Setup the function registration table (and other data) for a
 +       * net_device
 +       */
 +      /* netdev->init               = &et131x_init; */
 +      /* netdev->set_config = &et131x_config; */
 +      netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
 +      netdev->netdev_ops = &et131x_netdev_ops;
 +
 +      /* netdev->ethtool_ops        = &et131x_ethtool_ops; */
 +
 +      /* Poll? */
 +      /* netdev->poll               = &et131x_poll; */
 +      /* netdev->poll_controller    = &et131x_poll_controller; */
 +      return netdev;
 +}
 +
@@@ -1,5 -1,5 +1,5 @@@
  /*
 - * Copyright Ã‚© 2006-2007 Intel Corporation
 + * Copyright Ã‚© 2006-2011 Intel Corporation
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms and conditions of the GNU General Public License,
  #include <linux/pm_runtime.h>
  
  #include <drm/drmP.h>
 -#include "psb_fb.h"
 +#include "framebuffer.h"
  #include "psb_drv.h"
  #include "psb_intel_drv.h"
  #include "psb_intel_reg.h"
  #include "psb_intel_display.h"
 -#include "psb_powermgmt.h"
 +#include "power.h"
  
 +#include "mdfld_output.h"
  
  struct psb_intel_clock_t {
        /* given values */
@@@ -332,7 -331,7 +332,7 @@@ static bool psb_intel_find_best_PLL(str
  void psb_intel_wait_for_vblank(struct drm_device *dev)
  {
        /* Wait for 20ms, i.e. one cycle at 50hz. */
-       udelay(20000);
+       mdelay(20);
  }
  
  int psb_intel_pipe_set_base(struct drm_crtc *crtc,
        u32 dspcntr;
        int ret = 0;
  
 -      PSB_DEBUG_ENTRY("\n");
 +      if (!gma_power_begin(dev, true))
 +              return 0;
  
        /* no fb bound */
        if (!crtc->fb) {
 -              DRM_DEBUG("No FB bound\n");
 -              return 0;
 +              dev_dbg(dev->dev, "No FB bound\n");
 +              goto psb_intel_pipe_cleaner;
        }
  
 -      if (!gma_power_begin(dev, true))
 -              return 0;
 -
        /* We are displaying this buffer, make sure it is actually loaded
           into the GTT */
        ret = psb_gtt_pin(psbfb->gtt);
                dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
                break;
        default:
 -              DRM_ERROR("Unknown color depth\n");
 +              dev_err(dev->dev, "Unknown color depth\n");
                ret = -EINVAL;
                psb_gtt_unpin(psbfb->gtt);
                goto psb_intel_pipe_set_base_exit;
        REG_WRITE(dspcntr_reg, dspcntr);
  
  
 -      DRM_DEBUG("Writing base %08lX %08lX %d %d\n", start, offset, x, y);
        if (0 /* FIXMEAC - check what PSB needs */) {
                REG_WRITE(dspbase, offset);
                REG_READ(dspbase);
                REG_READ(dspbase);
        }
  
 +psb_intel_pipe_cleaner:
        /* If there was a previous display we can now unpin it */
        if (old_fb)
                psb_gtt_unpin(to_psb_fb(old_fb)->gtt);
@@@ -587,7 -588,6 +587,7 @@@ static int psb_intel_crtc_mode_set(stru
  {
        struct drm_device *dev = crtc->dev;
        struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
 +      struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
        int pipe = psb_intel_crtc->pipe;
        int fp_reg = (pipe == 0) ? FPA0 : FPB0;
        int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
        struct drm_mode_config *mode_config = &dev->mode_config;
        struct drm_connector *connector;
  
 +      /* No scan out no play */
 +      if (crtc->fb == NULL) {
 +              crtc_funcs->mode_set_base(crtc, x, y, old_fb);
 +              return 0;
 +      }
 +
        list_for_each_entry(connector, &mode_config->connector_list, head) {
                struct psb_intel_output *psb_intel_output =
                    to_psb_intel_output(connector);
        ok = psb_intel_find_best_PLL(crtc, adjusted_mode->clock, refclk,
                                 &clock);
        if (!ok) {
 -              DRM_ERROR("Couldn't find PLL settings for mode!\n");
 +              dev_err(dev->dev, "Couldn't find PLL settings for mode!\n");
                return 0;
        }
  
        if (psb_intel_panel_fitter_pipe(dev) == pipe)
                REG_WRITE(PFIT_CONTROL, 0);
  
 -      DRM_DEBUG("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
        drm_mode_debug_printmodeline(mode);
  
        if (dpll & DPLL_VCO_ENABLE) {
        if (is_lvds) {
                u32 lvds = REG_READ(LVDS);
  
 -              lvds |=
 -                  LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP |
 -                  LVDS_PIPEB_SELECT;
 +              lvds &= ~LVDS_PIPEB_SELECT;
 +              if (pipe == 1)
 +                      lvds |= LVDS_PIPEB_SELECT;
 +
 +              lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
                /* Set the B0-B3 data pairs corresponding to
                 * whether we're going to
                 * set the DPLLs for dual-channel mode or not.
                 */
 +              lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
                if (clock.p2 == 7)
                        lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
 -              else
 -                      lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  
                /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
                 * appropriately here, but we need to look more
        REG_WRITE(dspcntr_reg, dspcntr);
  
        /* Flush the plane changes */
 -      {
 -              struct drm_crtc_helper_funcs *crtc_funcs =
 -                  crtc->helper_private;
 -              crtc_funcs->mode_set_base(crtc, x, y, old_fb);
 -      }
 +      crtc_funcs->mode_set_base(crtc, x, y, old_fb);
  
        psb_intel_wait_for_vblank(dev);
  
@@@ -822,7 -820,7 +822,7 @@@ void psb_intel_crtc_load_lut(struct drm
                palreg = PALETTE_C;
                break;
        default:
 -              DRM_ERROR("Illegal Pipe Number.\n");
 +              dev_err(dev->dev, "Illegal Pipe Number.\n");
                return;
        }
  
@@@ -865,8 -863,10 +865,8 @@@ static void psb_intel_crtc_save(struct 
        uint32_t paletteReg;
        int i;
  
 -      DRM_DEBUG("\n");
 -
        if (!crtc_state) {
 -              DRM_DEBUG("No CRTC state found\n");
 +              dev_err(dev->dev, "No CRTC state found\n");
                return;
        }
  
  
        crtc_state->saveDSPBASE = REG_READ(pipeA ? DSPABASE : DSPBBASE);
  
 -      DRM_DEBUG("(%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
 -                      crtc_state->saveDSPCNTR,
 -                      crtc_state->savePIPECONF,
 -                      crtc_state->savePIPESRC,
 -                      crtc_state->saveFP0,
 -                      crtc_state->saveFP1,
 -                      crtc_state->saveDPLL,
 -                      crtc_state->saveHTOTAL,
 -                      crtc_state->saveHBLANK,
 -                      crtc_state->saveHSYNC,
 -                      crtc_state->saveVTOTAL,
 -                      crtc_state->saveVBLANK,
 -                      crtc_state->saveVSYNC,
 -                      crtc_state->saveDSPSTRIDE,
 -                      crtc_state->saveDSPSIZE,
 -                      crtc_state->saveDSPPOS,
 -                      crtc_state->saveDSPBASE
 -              );
 -
        paletteReg = pipeA ? PALETTE_A : PALETTE_B;
        for (i = 0; i < 256; ++i)
                crtc_state->savePalette[i] = REG_READ(paletteReg + (i << 2));
@@@ -910,15 -929,60 +910,15 @@@ static void psb_intel_crtc_restore(stru
        uint32_t paletteReg;
        int i;
  
 -      DRM_DEBUG("\n");
 -
        if (!crtc_state) {
 -              DRM_DEBUG("No crtc state\n");
 +              dev_err(dev->dev, "No crtc state\n");
                return;
        }
  
 -      DRM_DEBUG(
 -              "current:(%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
 -              REG_READ(pipeA ? DSPACNTR : DSPBCNTR),
 -              REG_READ(pipeA ? PIPEACONF : PIPEBCONF),
 -              REG_READ(pipeA ? PIPEASRC : PIPEBSRC),
 -              REG_READ(pipeA ? FPA0 : FPB0),
 -              REG_READ(pipeA ? FPA1 : FPB1),
 -              REG_READ(pipeA ? DPLL_A : DPLL_B),
 -              REG_READ(pipeA ? HTOTAL_A : HTOTAL_B),
 -              REG_READ(pipeA ? HBLANK_A : HBLANK_B),
 -              REG_READ(pipeA ? HSYNC_A : HSYNC_B),
 -              REG_READ(pipeA ? VTOTAL_A : VTOTAL_B),
 -              REG_READ(pipeA ? VBLANK_A : VBLANK_B),
 -              REG_READ(pipeA ? VSYNC_A : VSYNC_B),
 -              REG_READ(pipeA ? DSPASTRIDE : DSPBSTRIDE),
 -              REG_READ(pipeA ? DSPASIZE : DSPBSIZE),
 -              REG_READ(pipeA ? DSPAPOS : DSPBPOS),
 -              REG_READ(pipeA ? DSPABASE : DSPBBASE)
 -              );
 -
 -      DRM_DEBUG(
 -              "saved: (%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
 -              crtc_state->saveDSPCNTR,
 -              crtc_state->savePIPECONF,
 -              crtc_state->savePIPESRC,
 -              crtc_state->saveFP0,
 -              crtc_state->saveFP1,
 -              crtc_state->saveDPLL,
 -              crtc_state->saveHTOTAL,
 -              crtc_state->saveHBLANK,
 -              crtc_state->saveHSYNC,
 -              crtc_state->saveVTOTAL,
 -              crtc_state->saveVBLANK,
 -              crtc_state->saveVSYNC,
 -              crtc_state->saveDSPSTRIDE,
 -              crtc_state->saveDSPSIZE,
 -              crtc_state->saveDSPPOS,
 -              crtc_state->saveDSPBASE
 -              );
 -
 -
        if (crtc_state->saveDPLL & DPLL_VCO_ENABLE) {
                REG_WRITE(pipeA ? DPLL_A : DPLL_B,
                        crtc_state->saveDPLL & ~DPLL_VCO_ENABLE);
                REG_READ(pipeA ? DPLL_A : DPLL_B);
 -              DRM_DEBUG("write dpll: %x\n",
 -                              REG_READ(pipeA ? DPLL_A : DPLL_B));
                udelay(150);
        }
  
@@@ -975,8 -1039,11 +975,8 @@@ static int psb_intel_crtc_cursor_set(st
        struct drm_gem_object *obj;
        int ret;
  
 -      DRM_DEBUG("\n");
 -
        /* if we want to turn of the cursor ignore width and height */
        if (!handle) {
 -              DRM_DEBUG("cursor off\n");
                /* turn off the cursor */
                temp = CURSOR_MODE_DISABLE;
  
  
        /* Currently we only support 64x64 cursors */
        if (width != 64 || height != 64) {
 -              DRM_ERROR("we currently only support 64x64 cursors\n");
 +              dev_dbg(dev->dev, "we currently only support 64x64 cursors\n");
                return -EINVAL;
        }
  
                return -ENOENT;
  
        if (obj->size < width * height * 4) {
 -              DRM_ERROR("buffer is to small\n");
 +              dev_dbg(dev->dev, "buffer is to small\n");
                return -ENOMEM;
        }
  
        /* Pin the memory into the GTT */
        ret = psb_gtt_pin(gt);
        if (ret) {
 -              DRM_ERROR("Can not pin down handle 0x%x\n", handle);
 +              dev_err(dev->dev, "Can not pin down handle 0x%x\n", handle);
                return ret;
        }
  
        }
  
        /* unpin the old bo */
 -      if (psb_intel_crtc->cursor_obj && psb_intel_crtc->cursor_obj != obj) {
 +      if (psb_intel_crtc->cursor_obj) {
                gt = container_of(psb_intel_crtc->cursor_obj,
                                                        struct gtt_range, gem);
                psb_gtt_unpin(gt);
                drm_gem_object_unreference(psb_intel_crtc->cursor_obj);
                psb_intel_crtc->cursor_obj = obj;
        }
 -
        return 0;
  }
  
@@@ -1080,7 -1148,7 +1080,7 @@@ static int psb_intel_crtc_cursor_move(s
        return 0;
  }
  
 -static void psb_intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red,
 +void psb_intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red,
                         u16 *green, u16 *blue, uint32_t type, uint32_t size)
  {
        struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
@@@ -1241,7 -1309,7 +1241,7 @@@ struct drm_display_mode *psb_intel_crtc
        return mode;
  }
  
 -static void psb_intel_crtc_destroy(struct drm_crtc *crtc)
 +void psb_intel_crtc_destroy(struct drm_crtc *crtc)
  {
        struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
        struct gtt_range *gt;
        kfree(psb_intel_crtc);
  }
  
 -static const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
 +const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
        .dpms = psb_intel_crtc_dpms,
        .mode_fixup = psb_intel_crtc_mode_fixup,
        .mode_set = psb_intel_crtc_mode_set,
@@@ -1278,19 -1346,6 +1278,19 @@@ const struct drm_crtc_funcs psb_intel_c
        .destroy = psb_intel_crtc_destroy,
  };
  
 +/*
 + * Set the default value of cursor control and base register
 + * to zero. This is a workaround for h/w defect on Oaktrail
 + */
 +static void psb_intel_cursor_init(struct drm_device *dev, int pipe)
 +{
 +      u32 control[3] = { CURACNTR, CURBCNTR, CURCCNTR };
 +      u32 base[3] = { CURABASE, CURBBASE, CURCBASE };
 +
 +      REG_WRITE(control[pipe], 0);
 +      REG_WRITE(base[pipe], 0);
 +}
 +
  void psb_intel_crtc_init(struct drm_device *dev, int pipe,
                     struct psb_intel_mode_device *mode_dev)
  {
        int i;
        uint16_t *r_base, *g_base, *b_base;
  
 -      PSB_DEBUG_ENTRY("\n");
 -
        /* We allocate a extra array of drm_connector pointers
         * for fbdev after the crtc */
        psb_intel_crtc =
        psb_intel_crtc->crtc_state =
                kzalloc(sizeof(struct psb_intel_crtc_state), GFP_KERNEL);
        if (!psb_intel_crtc->crtc_state) {
 -              DRM_INFO("Crtc state error: No memory\n");
 +              dev_err(dev->dev, "Crtc state error: No memory\n");
                kfree(psb_intel_crtc);
                return;
        }
  
 -      drm_crtc_init(dev, &psb_intel_crtc->base, &psb_intel_crtc_funcs);
 +      /* Set the CRTC operations from the chip specific data */
 +      drm_crtc_init(dev, &psb_intel_crtc->base, dev_priv->ops->crtc_funcs);
  
        drm_mode_crtc_set_gamma_size(&psb_intel_crtc->base, 256);
        psb_intel_crtc->pipe = pipe;
        psb_intel_crtc->mode_dev = mode_dev;
        psb_intel_crtc->cursor_addr = 0;
  
 -      if (IS_MRST(dev))
 -              drm_crtc_helper_add(&psb_intel_crtc->base,
 -                                  &mrst_helper_funcs);
 -      else
 -              drm_crtc_helper_add(&psb_intel_crtc->base,
 -                                  &psb_intel_helper_funcs);
 +      drm_crtc_helper_add(&psb_intel_crtc->base,
 +                                              dev_priv->ops->crtc_helper);
  
        /* Setup the array of drm_connector pointer array */
        psb_intel_crtc->mode_set.crtc = &psb_intel_crtc->base;
        psb_intel_crtc->mode_set.connectors =
            (struct drm_connector **) (psb_intel_crtc + 1);
        psb_intel_crtc->mode_set.num_connectors = 0;
 +      psb_intel_cursor_init(dev, pipe);
  }
  
  int psb_intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
        struct psb_intel_crtc *crtc;
  
        if (!dev_priv) {
 -              DRM_ERROR("called with no initialization\n");
 +              dev_err(dev->dev, "called with no initialization\n");
                return -EINVAL;
        }
  
                        DRM_MODE_OBJECT_CRTC);
  
        if (!drmmode_obj) {
 -              DRM_ERROR("no such CRTC id\n");
 +              dev_err(dev->dev, "no such CRTC id\n");
                return -EINVAL;
        }
  
@@@ -24,7 -24,6 +24,6 @@@
  #include <linux/hiddev.h>
  #include <linux/pci.h>
  #include <linux/dmi.h>
- #include <linux/delay.h>
  
  #include "hyperv.h"
  
@@@ -936,6 -935,7 +935,6 @@@ static int __init mousevsc_init(void
               sizeof(struct hv_guid));
  
        drv->driver.name = driver_name;
 -      drv->name = driver_name;
  
        /* The driver belongs to vmbus */
        vmbus_child_driver_register(&drv->driver);
@@@ -39,6 -39,8 +39,6 @@@
   *
   */
  
 -
 -#include <linux/version.h>
  #include <linux/module.h>
  #include <linux/kmod.h>
  #include <linux/kernel.h>
@@@ -473,14 -475,14 +473,14 @@@ static int lirc_thread(void *arg
        dprintk("poll thread started\n");
  
        while (!kthread_should_stop()) {
+               set_current_state(TASK_INTERRUPTIBLE);
                /* if device not opened, we can sleep half a second */
                if (atomic_read(&ir->open_count) == 0) {
                        schedule_timeout(HZ/2);
                        continue;
                }
  
-               set_current_state(TASK_INTERRUPTIBLE);
                /*
                 * This is ~113*2 + 24 + jitter (2*repeat gap + code length).
                 * We use this interval as the chip resets every time you poll
  #define IEEE80211_H
  #include <linux/if_ether.h> /* ETH_ALEN */
  #include <linux/kernel.h>   /* ARRAY_SIZE */
 -#include <linux/version.h>
  #include <linux/jiffies.h>
  #include <linux/timer.h>
  #include <linux/sched.h>
  #include <linux/semaphore.h>
  #include <linux/wireless.h>
  #include <linux/ieee80211.h>
+ #include <linux/interrupt.h>
  
  #define KEY_TYPE_NA           0x0
  #define KEY_TYPE_WEP40                0x1
@@@ -19,6 -19,8 +19,8 @@@
  #include <linux/random.h>
  #include <linux/delay.h>
  #include <linux/slab.h>
+ #include <linux/version.h>
+ #include <linux/interrupt.h>
  #include <asm/uaccess.h>
  
  #include "dot11d.h"
@@@ -820,7 -822,7 +822,7 @@@ static struct sk_buff* ieee80211_probe_
                cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
  
        if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
 -              cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
 +              beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
  
        crypt = ieee->crypt[ieee->tx_keyidx];
  
@@@ -2567,8 -2569,11 +2569,8 @@@ void ieee80211_softmac_init(struct ieee
        ieee->beacon_timer.data = (unsigned long) ieee;
        ieee->beacon_timer.function = ieee80211_send_beacon_cb;
  
 -#ifdef PF_SYNCTHREAD
 -      ieee->wq = create_workqueue(DRV_NAME,0);
 -#else
        ieee->wq = create_workqueue(DRV_NAME);
 -#endif
 +
        INIT_DELAYED_WORK(&ieee->start_ibss_wq,(void*) ieee80211_start_ibss_wq);
        INIT_WORK(&ieee->associate_complete_wq,(void*) ieee80211_associate_complete_wq);
        INIT_WORK(&ieee->associate_procedure_wq,(void*) ieee80211_associate_procedure_wq);
  #define IEEE80211_H
  #include <linux/if_ether.h> /* ETH_ALEN */
  #include <linux/kernel.h>   /* ARRAY_SIZE */
 -#include <linux/version.h>
  #include <linux/module.h>
  #include <linux/jiffies.h>
  #include <linux/timer.h>
  #include <linux/sched.h>
  #include <linux/semaphore.h>
+ #include <linux/interrupt.h>
  
  #include <linux/delay.h>
  #include <linux/wireless.h>
@@@ -45,6 -45,7 +45,6 @@@
  #include <linux/slab.h>
  #include <linux/tcp.h>
  #include <linux/types.h>
 -#include <linux/version.h>
  #include <linux/wireless.h>
  #include <linux/etherdevice.h>
  #include <asm/uaccess.h>
@@@ -310,7 -311,7 +310,7 @@@ int __init ieee80211_rtl_init(void
        }
  
        ieee80211_debug_level = debug;
-       ieee80211_proc = create_proc_entry(DRV_NAME, S_IFDIR, init_net.proc_net);
+       ieee80211_proc = proc_mkdir(DRV_NAME, init_net.proc_net);
        if (ieee80211_proc == NULL) {
                IEEE80211_ERROR("Unable to create " DRV_NAME
                                " proc directory\n");
@@@ -27,6 -27,8 +27,8 @@@
  
  #include <linux/vmalloc.h>
  #include <linux/slab.h>
+ #include <linux/interrupt.h>
+ #include <linux/hardirq.h>
  #include <asm/uaccess.h>
  #include "r8192E_hw.h"
  #include "r8192E.h"
@@@ -506,7 -508,7 +508,7 @@@ static int proc_get_stats_rx(char *page
  static void rtl8192_proc_module_init(void)
  {
        RT_TRACE(COMP_INIT, "Initializing proc filesystem\n");
-       rtl8192_proc=create_proc_entry(RTL819xE_MODULE_NAME, S_IFDIR, init_net.proc_net);
+       rtl8192_proc = proc_mkdir(RTL819xE_MODULE_NAME, init_net.proc_net);
  }
  
  
@@@ -538,9 -540,7 +540,7 @@@ static void rtl8192_proc_init_one(struc
        struct net_device *dev = priv->ieee80211->dev;
        struct proc_dir_entry *e;
  
-       priv->dir_dev = create_proc_entry(dev->name,
-                                         S_IFDIR | S_IRUGO | S_IXUGO,
-                                         rtl8192_proc);
+       priv->dir_dev = proc_mkdir(dev->name, rtl8192_proc);
        if (!priv->dir_dev) {
                RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
                      dev->name);
@@@ -4532,7 -4532,6 +4532,7 @@@ static int __devinit rtl8192_pci_probe(
        u8 unit = 0;
        int ret = -ENODEV;
        unsigned long pmem_start, pmem_len, pmem_flags;
 +      u8 revisionid;
  
        RT_TRACE(COMP_INIT,"Configuring chip resources\n");
  
           pci_write_config_byte(pdev, 0x41, 0x00);
  
  
 +      pci_read_config_byte(pdev, 0x08, &revisionid);
 +      /* If the revisionid is 0x10, the device uses rtl8192se. */
 +      if (pdev->device == 0x8192 && revisionid == 0x10)
 +              goto fail1;
 +
        pci_read_config_byte(pdev, 0x05, &unit);
        pci_write_config_byte(pdev, 0x05, unit & (~0x04));
  
  #define IEEE80211_H
  #include <linux/if_ether.h> /* ETH_ALEN */
  #include <linux/kernel.h>   /* ARRAY_SIZE */
 -#include <linux/version.h>
  #include <linux/module.h>
  #include <linux/jiffies.h>
  #include <linux/timer.h>
  #include <linux/sched.h>
  #include <linux/semaphore.h>
+ #include <linux/interrupt.h>
  
  #include <linux/delay.h>
  #include <linux/wireless.h>
@@@ -46,6 -46,7 +46,6 @@@
  #include <linux/slab.h>
  #include <linux/tcp.h>
  #include <linux/types.h>
 -#include <linux/version.h>
  #include <linux/wireless.h>
  #include <linux/etherdevice.h>
  #include <asm/uaccess.h>
@@@ -282,7 -283,7 +282,7 @@@ int __init ieee80211_debug_init(void
  
        ieee80211_debug_level = debug;
  
-       ieee80211_proc = create_proc_entry(DRV_NAME, S_IFDIR, init_net.proc_net);
+       ieee80211_proc = proc_mkdir(DRV_NAME, init_net.proc_net);
        if (ieee80211_proc == NULL) {
                IEEE80211_ERROR("Unable to create " DRV_NAME
                                " proc directory\n");
@@@ -671,7 -671,7 +671,7 @@@ static int proc_get_stats_rx(char *page
  void rtl8192_proc_module_init(void)
  {
        RT_TRACE(COMP_INIT, "Initializing proc filesystem");
-       rtl8192_proc=create_proc_entry(RTL819xU_MODULE_NAME, S_IFDIR, init_net.proc_net);
+       rtl8192_proc = proc_mkdir(RTL819xU_MODULE_NAME, init_net.proc_net);
  }
  
  
@@@ -706,9 -706,7 +706,7 @@@ void rtl8192_proc_init_one(struct net_d
  {
        struct proc_dir_entry *e;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
-       priv->dir_dev = create_proc_entry(dev->name,
-                                         S_IFDIR | S_IRUGO | S_IXUGO,
-                                         rtl8192_proc);
+       priv->dir_dev = proc_mkdir(dev->name, rtl8192_proc);
        if (!priv->dir_dev) {
                RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
                      dev->name);
@@@ -2852,7 -2850,11 +2850,7 @@@ static void rtl8192_init_priv_task(stru
  {
        struct r8192_priv *priv = ieee80211_priv(dev);
  
 -#ifdef PF_SYNCTHREAD
 -      priv->priv_wq = create_workqueue(DRV_NAME,0);
 -#else
        priv->priv_wq = create_workqueue(DRV_NAME);
 -#endif
  
        INIT_WORK(&priv->reset_wq, rtl8192_restart);
  
@@@ -5,7 -5,9 +5,7 @@@
  #define _FAIL         0
  
  #include "basic_types.h"
 -#include <linux/version.h>
  #include <linux/spinlock.h>
 -
  #include <linux/semaphore.h>
  #include <linux/sem.h>
  #include <linux/netdevice.h>
@@@ -20,7 -22,6 +20,6 @@@
  #include <linux/module.h>
  #include <linux/sched.h>
  #include <linux/kref.h>
- #include <linux/netdevice.h>
  #include <linux/skbuff.h>
  #include <linux/usb.h>
  #include <linux/usb/ch9.h>
@@@ -28,7 -29,7 +27,7 @@@
  #include <linux/circ_buf.h>
  #include <linux/uaccess.h>
  #include <asm/byteorder.h>
 -#include <asm/atomic.h>
 +#include <linux/atomic.h>
  #include <linux/wireless.h>
  #include <linux/rtnetlink.h>
  #include "ethernet.h"
@@@ -234,5 -235,7 +233,5 @@@ static inline u32 _RND512(u32 sz
        return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
  }
  
 -#define STRUCT_PACKED __attribute__ ((packed))
 -
  #endif
  
@@@ -50,7 -50,6 +50,6 @@@
  #include <linux/interrupt.h>
  #include <linux/pagemap.h>
  #include <asm/cacheflush.h>
- #include <linux/sched.h>
  #include <linux/delay.h>
  #include <linux/jiffies.h>
  #include <linux/rar_register.h>
@@@ -201,7 -200,7 +200,7 @@@ static int sep_singleton_release(struc
  }
  
  /**
 - *    sep_request_daemonopen - request daemon open method
 + *    sep_request_daemon_open - request daemon open method
   *    @inode: inode of SEP device
   *    @filp: file handle to SEP device
   *
@@@ -1102,9 -1101,9 +1101,9 @@@ static int sep_lock_user_pages(struct s
                        "lli_array[%x].bus_address is "
                        "%08lx, lli_array[%x].block_size is %x\n",
                        num_pages - 1,
 -                      (unsigned long)lli_array[num_pages -1].bus_address,
 +                      (unsigned long)lli_array[num_pages - 1].bus_address,
                        num_pages - 1,
 -                      lli_array[num_pages -1].block_size);
 +                      lli_array[num_pages - 1].block_size);
        }
  
        /* Set output params according to the in_out flag */
@@@ -1,24 -1,37 +1,50 @@@
 +/*
 + * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
 + *               2005-2007 Takahiro Hirofuchi
 + *
 + * This program is free software: you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation, either version 2 of the License, or
 + * (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
 + */
  
 -#ifdef HAVE_CONFIG_H
 -#include "../config.h"
 -#endif
 +#ifndef __UTILS_H
 +#define __UTILS_H
  
 -#define _GNU_SOURCE
 -#include <string.h>
 -#include <sys/un.h>
 -#include <sys/types.h>
 -#include <sys/socket.h>
 +int modify_match_busid(char *busid, int add);
  
 +#endif /* __UTILS_H */
+ #include <sysfs/libsysfs.h>
+ #include <glib.h>
+ #include <unistd.h>
+ #include <stdio.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #include <stdlib.h>
+ #include <time.h>
+ #include <errno.h>
+ /* Be sync to kernel header */
+ #define BUS_ID_SIZE 20
+ int read_string(char *path, char *, size_t len);
+ int read_integer(char *path);
+ int getdevicename(char *busid, char *name, size_t len);
+ int getdriver(char *busid, int conf, int infnum, char *driver, size_t len);
+ int read_bNumInterfaces(char *busid);
+ int read_bConfigurationValue(char *busid);
+ int write_integer(char *path, int value);
+ int write_bConfigurationValue(char *busid, int config);
+ int read_bDeviceClass(char *busid);
+ int readline(int sockfd, char *str, int strlen);
+ int writeline(int sockfd, char *buff, int bufflen);
@@@ -67,6 -67,7 +67,6 @@@
  /*******************************************************************************
   *  include files
   ******************************************************************************/
 -#include <linux/version.h>
  #ifdef BUS_PCMCIA
  #include <pcmcia/cistpl.h>
  #include <pcmcia/cisreg.h>
@@@ -989,14 -990,7 +989,7 @@@ struct wl_privat
  #endif // USE_WDS
  }; // wl_private
  
- #ifdef HAVE_NETDEV_PRIV
  #define wl_priv(dev) ((struct wl_private *) netdev_priv(dev))
- #else
- extern inline struct wl_private *wl_priv(struct net_device *dev)
- {
-     return dev->priv;
- }
- #endif
  
  /********************************************************************/
  /* Locking and synchronization functions                            */