Merge branches 'irq-core-for-linus' and 'core-locking-for-linus' of git://git.kernel...
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmfmac / dhd_linux.c
index 09a668b..bbbe7c5 100644 (file)
 #ifdef CONFIG_WIFI_CONTROL_FUNC
 #include <linux/platform_device.h>
 #endif
-#include <typedefs.h>
-#include <linuxver.h>
-#include <osl.h>
-
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/kthread.h>
 #include <linux/slab.h>
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
 #include <linux/ethtool.h>
 #include <linux/fcntl.h>
 #include <linux/fs.h>
-
 #include <linux/uaccess.h>
+#include <bcmdefs.h>
+#include <linuxver.h>
+#include <osl.h>
 #include <bcmutils.h>
 #include <bcmendian.h>
 
@@ -45,9 +44,7 @@
 #include <dhd_proto.h>
 #include <dhd_dbg.h>
 
-#ifdef CONFIG_CFG80211
 #include <wl_cfg80211.h>
-#endif
 
 #define EPI_VERSION_STR         "4.218.248.5"
 
@@ -58,8 +55,8 @@ struct semaphore wifi_control_sem;
 
 struct dhd_bus *g_bus;
 
-static struct wifi_platform_data *wifi_control_data = NULL;
-static struct resource *wifi_irqres = NULL;
+static struct wifi_platform_data *wifi_control_data;
+static struct resource *wifi_irqres;
 
 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
 {
@@ -172,7 +169,7 @@ void wifi_del_dev(void)
 
 #if defined(CONFIG_PM_SLEEP)
 #include <linux/suspend.h>
-volatile bool dhd_mmc_suspend = FALSE;
+volatile bool dhd_mmc_suspend = false;
 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
 #endif /*  defined(CONFIG_PM_SLEEP) */
 
@@ -217,7 +214,7 @@ typedef struct dhd_if {
        u8 mac_addr[ETHER_ADDR_LEN];    /* assigned MAC address */
        bool attached;          /* Delayed attachment when unset */
        bool txflowcontrol;     /* Per interface flow control indicator */
-       char name[IFNAMSIZ + 1];        /* linux interface name */
+       char name[IFNAMSIZ];    /* linux interface name */
 } dhd_if_t;
 
 /* Local private structure (extension of pub) */
@@ -241,17 +238,14 @@ typedef struct dhd_info {
        /* Thread based operation */
        bool threads_only;
        struct semaphore sdsem;
-       long watchdog_pid;
+       struct task_struct *watchdog_tsk;
        struct semaphore watchdog_sem;
-       struct completion watchdog_exited;
-       long dpc_pid;
+       struct task_struct *dpc_tsk;
        struct semaphore dpc_sem;
-       struct completion dpc_exited;
 
        /* Thread to issue ioctl for multicast */
-       long sysioc_pid;
+       struct task_struct *sysioc_tsk;
        struct semaphore sysioc_sem;
-       struct completion sysioc_exited;
        bool set_multicast;
        bool set_macaddress;
        struct ether_addr macvalue;
@@ -277,7 +271,7 @@ module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
 module_param(dhd_msg_level, int, 0);
 
 /* Spawn a thread for system ioctls (set mac, set mcast) */
-uint dhd_sysioc = TRUE;
+uint dhd_sysioc = true;
 module_param(dhd_sysioc, uint, 0);
 
 /* Watchdog interval */
@@ -286,7 +280,7 @@ module_param(dhd_watchdog_ms, uint, 0);
 
 #ifdef DHD_DEBUG
 /* Console poll interval */
-uint dhd_console_ms = 0;
+uint dhd_console_ms;
 module_param(dhd_console_ms, uint, 0);
 #endif                         /* DHD_DEBUG */
 
@@ -296,19 +290,19 @@ uint dhd_arp_mode = 0xb;
 module_param(dhd_arp_mode, uint, 0);
 
 /* ARP offload enable */
-uint dhd_arp_enable = TRUE;
+uint dhd_arp_enable = true;
 module_param(dhd_arp_enable, uint, 0);
 
 /* Global Pkt filter enable control */
-uint dhd_pkt_filter_enable = TRUE;
+uint dhd_pkt_filter_enable = true;
 module_param(dhd_pkt_filter_enable, uint, 0);
 
 /*  Pkt filter init setup */
-uint dhd_pkt_filter_init = 0;
+uint dhd_pkt_filter_init;
 module_param(dhd_pkt_filter_init, uint, 0);
 
 /* Pkt filter mode control */
-uint dhd_master_mode = TRUE;
+uint dhd_master_mode = true;
 module_param(dhd_master_mode, uint, 1);
 
 /* Watchdog thread priority, -1 to use kernel timer */
@@ -325,7 +319,7 @@ module_param(dhd_dongle_memsize, int, 0);
 
 /* Contorl fw roaming */
 #ifdef CUSTOMER_HW2
-uint dhd_roam = 0;
+uint dhd_roam;
 #else
 uint dhd_roam = 1;
 #endif
@@ -337,12 +331,6 @@ uint dhd_radio_up = 1;
 char iface_name[IFNAMSIZ];
 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
 
-#define DAEMONIZE(a) daemonize(a); \
-       allow_signal(SIGKILL); \
-       allow_signal(SIGTERM);
-
-#define BLOCKABLE()    (!in_atomic())
-
 /* The following are specific to the SDIO dongle */
 
 /* IOCTL response timeout */
@@ -353,17 +341,15 @@ int dhd_idletime = DHD_IDLETIME_TICKS;
 module_param(dhd_idletime, int, 0);
 
 /* Use polling */
-uint dhd_poll = FALSE;
+uint dhd_poll = false;
 module_param(dhd_poll, uint, 0);
 
-#ifdef CONFIG_CFG80211
 /* Use cfg80211 */
-uint dhd_cfg80211 = TRUE;
+uint dhd_cfg80211 = true;
 module_param(dhd_cfg80211, uint, 0);
-#endif
 
 /* Use interrupts */
-uint dhd_intr = TRUE;
+uint dhd_intr = true;
 module_param(dhd_intr, uint, 0);
 
 /* SDIO Drive Strength (in milliamps) */
@@ -382,20 +368,18 @@ module_param(dhd_deferred_tx, uint, 0);
 
 #ifdef SDTEST
 /* Echo packet generator (pkts/s) */
-uint dhd_pktgen = 0;
+uint dhd_pktgen;
 module_param(dhd_pktgen, uint, 0);
 
 /* Echo packet len (0 => sawtooth, max 2040) */
-uint dhd_pktgen_len = 0;
+uint dhd_pktgen_len;
 module_param(dhd_pktgen_len, uint, 0);
 #endif
 
-#ifdef CONFIG_CFG80211
 #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)
-#endif
 
 /* Version string to report */
 #ifdef DHD_DEBUG
@@ -422,8 +406,8 @@ extern int dhd_wait_pend8021x(struct net_device *dev);
 #ifndef BDC
 #error TOE requires BDC
 #endif                         /* !BDC */
-static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
-static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
+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,
@@ -436,11 +420,11 @@ static int dhd_sleep_pm_callback(struct notifier_block *nfb,
        switch (action) {
        case PM_HIBERNATION_PREPARE:
        case PM_SUSPEND_PREPARE:
-               dhd_mmc_suspend = TRUE;
+               dhd_mmc_suspend = true;
                return NOTIFY_OK;
        case PM_POST_HIBERNATION:
        case PM_POST_SUSPEND:
-               dhd_mmc_suspend = FALSE;
+               dhd_mmc_suspend = false;
                return NOTIFY_OK;
        }
        return 0;
@@ -628,7 +612,7 @@ int dhd_timeout_expired(dhd_timeout_t *tmo)
        tmo->elapsed += tmo->increment;
 
        if (tmo->increment < tmo->tick) {
-               OSL_DELAY(tmo->increment);
+               udelay(tmo->increment);
                tmo->increment *= 2;
                if (tmo->increment > tmo->tick)
                        tmo->increment = tmo->tick;
@@ -709,7 +693,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
 {
        struct net_device *dev;
        struct netdev_hw_addr *ha;
-       uint32 allmulti, cnt;
+       u32 allmulti, cnt;
 
        wl_ioctl_t ioc;
        char *buf, *bufp;
@@ -721,12 +705,12 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
        cnt = netdev_mc_count(dev);
 
        /* Determine initial value of allmulti flag */
-       allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
+       allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
 
        /* Send down the multicast list first. */
 
        buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
-       bufp = buf = MALLOC(dhd->pub.osh, buflen);
+       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));
@@ -752,16 +736,16 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = buflen;
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->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));
-               allmulti = cnt ? TRUE : allmulti;
+               allmulti = cnt ? true : allmulti;
        }
 
-       MFREE(dhd->pub.osh, buf, buflen);
+       kfree(buf);
 
        /* Now send the allmulti setting.  This is based on the setting in the
         * net_device flags, but might be modified above to be turned on if we
@@ -769,7 +753,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
         */
 
        buflen = sizeof("allmulti") + sizeof(allmulti);
-       buf = MALLOC(dhd->pub.osh, buflen);
+       buf = kmalloc(buflen, GFP_ATOMIC);
        if (!buf) {
                DHD_ERROR(("%s: out of memory for allmulti\n",
                           dhd_ifname(&dhd->pub, ifidx)));
@@ -782,7 +766,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
                DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
                        "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
                        (int)sizeof(allmulti), buflen));
-               MFREE(dhd->pub.osh, buf, buflen);
+               kfree(buf);
                return;
        }
 
@@ -790,7 +774,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = buflen;
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -798,19 +782,19 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
                           dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
        }
 
-       MFREE(dhd->pub.osh, buf, buflen);
+       kfree(buf);
 
        /* Finally, pick up the PROMISC flag as well, like the NIC
                 driver does */
 
-       allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
+       allmulti = (dev->flags & IFF_PROMISC) ? true : false;
        allmulti = htol32(allmulti);
 
        memset(&ioc, 0, sizeof(ioc));
        ioc.cmd = WLC_SET_PROMISC;
        ioc.buf = &allmulti;
        ioc.len = sizeof(allmulti);
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -837,7 +821,7 @@ _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = 32;
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -935,7 +919,7 @@ static void dhd_op_if(dhd_if_t *ifp)
                        free_netdev(ifp->net);
 
                dhd->iflist[ifp->idx] = NULL;
-               MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
+               kfree(ifp);
 #ifdef SOFTAP
                if (ifp->net == ap_net_dev)
                        ap_net_dev = NULL;      /*  NULL  SOFTAP global
@@ -949,12 +933,14 @@ static int _dhd_sysioc_thread(void *data)
        dhd_info_t *dhd = (dhd_info_t *) data;
        int i;
 #ifdef SOFTAP
-       bool in_ap = FALSE;
+       bool in_ap = false;
 #endif
 
-       DAEMONIZE("dhd_sysioc");
+       allow_signal(SIGTERM);
 
        while (down_interruptible(&dhd->sysioc_sem) == 0) {
+               if (kthread_should_stop())
+                       break;
                for (i = 0; i < DHD_MAX_IFS; i++) {
                        if (dhd->iflist[i]) {
 #ifdef SOFTAP
@@ -973,30 +959,30 @@ static int _dhd_sysioc_thread(void *data)
                                        DHD_TRACE(("attempt to set MAC for %s "
                                                "in AP Mode," "blocked. \n",
                                                dhd->iflist[i]->net->name));
-                                       dhd->set_macaddress = FALSE;
+                                       dhd->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;
+                                       dhd->set_multicast = false;
                                        continue;
                                }
 #endif                         /* SOFTAP */
                                if (dhd->set_multicast) {
-                                       dhd->set_multicast = FALSE;
+                                       dhd->set_multicast = false;
                                        _dhd_set_multicast_list(dhd, i);
                                }
                                if (dhd->set_macaddress) {
-                                       dhd->set_macaddress = FALSE;
+                                       dhd->set_macaddress = false;
                                        _dhd_set_mac_address(dhd, i,
                                                             &dhd->macvalue);
                                }
                        }
                }
        }
-       complete_and_exit(&dhd->sysioc_exited, 0);
+       return 0;
 }
 
 static int dhd_set_mac_address(struct net_device *dev, void *addr)
@@ -1011,9 +997,9 @@ static int dhd_set_mac_address(struct net_device *dev, void *addr)
        if (ifidx == DHD_BAD_IF)
                return -1;
 
-       ASSERT(dhd->sysioc_pid >= 0);
+       ASSERT(dhd->sysioc_tsk);
        memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
-       dhd->set_macaddress = TRUE;
+       dhd->set_macaddress = true;
        up(&dhd->sysioc_sem);
 
        return ret;
@@ -1028,8 +1014,8 @@ static void dhd_set_multicast_list(struct net_device *dev)
        if (ifidx == DHD_BAD_IF)
                return;
 
-       ASSERT(dhd->sysioc_pid >= 0);
-       dhd->set_multicast = TRUE;
+       ASSERT(dhd->sysioc_tsk);
+       dhd->set_multicast = true;
        up(&dhd->sysioc_sem);
 }
 
@@ -1053,10 +1039,6 @@ int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
                        atomic_inc(&dhd->pend_8021x_cnt);
        }
 
-       /* Look into the packet and update the packet priority */
-       if ((PKTPRIO(pktbuf) == 0))
-               pktsetprio(pktbuf, FALSE);
-
        /* If the protocol uses a data header, apply it */
        dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
 
@@ -1246,7 +1228,7 @@ void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
        uint ifidx;
        dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
        struct ether_header *eh;
-       uint16 type;
+       u16 type;
 
        dhd_prot_hdrpull(dhdp, &ifidx, txp);
 
@@ -1309,12 +1291,13 @@ static int dhd_watchdog_thread(void *data)
        }
 #endif                         /* DHD_SCHED */
 
-       DAEMONIZE("dhd_watchdog");
-
+       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) {
+                       if (dhd->pub.dongle_reset == false) {
                                WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
                                /* Call the bus module watchdog */
                                dhd_bus_watchdog(&dhd->pub);
@@ -1327,14 +1310,14 @@ static int dhd_watchdog_thread(void *data)
        }
 
        WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
-       complete_and_exit(&dhd->watchdog_exited, 0);
+       return 0;
 }
 
 static void dhd_watchdog(unsigned long data)
 {
        dhd_info_t *dhd = (dhd_info_t *) data;
 
-       if (dhd->watchdog_pid >= 0) {
+       if (dhd->watchdog_tsk) {
                up(&dhd->watchdog_sem);
 
                /* Reschedule the watchdog */
@@ -1374,10 +1357,11 @@ static int dhd_dpc_thread(void *data)
        }
 #endif                         /* DHD_SCHED */
 
-       DAEMONIZE("dhd_dpc");
-
+       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) */
@@ -1390,15 +1374,14 @@ static int dhd_dpc_thread(void *data)
                                }
                                WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
                        } else {
-                               dhd_bus_stop(dhd->pub.bus, TRUE);
+                               dhd_bus_stop(dhd->pub.bus, true);
                        }
                } else
                        break;
        }
 
        WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
-
-       complete_and_exit(&dhd->dpc_exited, 0);
+       return 0;
 }
 
 static void dhd_dpc(unsigned long data)
@@ -1412,7 +1395,7 @@ static void dhd_dpc(unsigned long data)
                if (dhd_bus_dpc(dhd->pub.bus))
                        tasklet_schedule(&dhd->tasklet);
        } else {
-               dhd_bus_stop(dhd->pub.bus, TRUE);
+               dhd_bus_stop(dhd->pub.bus, true);
        }
 }
 
@@ -1420,7 +1403,7 @@ void dhd_sched_dpc(dhd_pub_t *dhdp)
 {
        dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
 
-       if (dhd->dpc_pid >= 0) {
+       if (dhd->dpc_tsk) {
                up(&dhd->dpc_sem);
                return;
        }
@@ -1431,7 +1414,7 @@ void dhd_sched_dpc(dhd_pub_t *dhdp)
 #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, uint32 *toe_ol)
+static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
 {
        wl_ioctl_t ioc;
        char buf[32];
@@ -1442,7 +1425,7 @@ static int dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
        ioc.cmd = WLC_GET_VAR;
        ioc.buf = buf;
        ioc.len = (uint) sizeof(buf);
-       ioc.set = FALSE;
+       ioc.set = false;
 
        strcpy(buf, "toe_ol");
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
@@ -1459,13 +1442,13 @@ static int dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
                return ret;
        }
 
-       memcpy(toe_ol, buf, sizeof(uint32));
+       memcpy(toe_ol, buf, sizeof(u32));
        return 0;
 }
 
 /* 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, uint32 toe_ol)
+static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
 {
        wl_ioctl_t ioc;
        char buf[32];
@@ -1476,12 +1459,12 @@ static int dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = (uint) sizeof(buf);
-       ioc.set = TRUE;
+       ioc.set = true;
 
        /* Set toe_ol as requested */
 
        strcpy(buf, "toe_ol");
-       memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
+       memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -1495,7 +1478,7 @@ static int dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
        toe = (toe_ol != 0);
 
        strcpy(buf, "toe");
-       memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
+       memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -1527,17 +1510,17 @@ static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
 {
        struct ethtool_drvinfo info;
        char drvname[sizeof(info.driver)];
-       uint32 cmd;
+       u32 cmd;
 #ifdef TOE
        struct ethtool_value edata;
-       uint32 toe_cmpnt, csum_dir;
+       u32 toe_cmpnt, csum_dir;
        int ret;
 #endif
 
        DHD_TRACE(("%s: Enter\n", __func__));
 
        /* all ethtool calls start with a cmd word */
-       if (copy_from_user(&cmd, uaddr, sizeof(uint32)))
+       if (copy_from_user(&cmd, uaddr, sizeof(u32)))
                return -EFAULT;
 
        switch (cmd) {
@@ -1679,7 +1662,7 @@ static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
 
        /* Copy out any buffer passed */
        if (ioc.buf) {
-               buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
+               buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
                /* optimization for direct ioctl calls from kernel */
                /*
                   if (segment_eq(get_fs(), KERNEL_DS)) {
@@ -1687,7 +1670,7 @@ static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
                   } else {
                 */
                {
-                       buf = (char *)MALLOC(dhd->pub.osh, buflen);
+                       buf = kmalloc(buflen, GFP_ATOMIC);
                        if (!buf) {
                                bcmerror = -BCME_NOMEM;
                                goto done;
@@ -1757,7 +1740,7 @@ done:
        }
 
        if (buf)
-               MFREE(dhd->pub.osh, buf, buflen);
+               kfree(buf);
 
        return OSL_ERROR(bcmerror);
 }
@@ -1768,11 +1751,9 @@ static int dhd_stop(struct net_device *net)
        dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 
        DHD_TRACE(("%s: Enter\n", __func__));
-#ifdef CONFIG_CFG80211
        if (IS_CFG80211_FAVORITE()) {
                wl_cfg80211_down();
        }
-#endif
        if (dhd->pub.up == 0)
                return 0;
 
@@ -1784,7 +1765,6 @@ static int dhd_stop(struct net_device *net)
                __func__));
 #endif                         /* !defined(IGNORE_ETH0_DOWN) */
 
-       OLD_MOD_DEC_USE_COUNT;
        return 0;
 }
 
@@ -1792,10 +1772,10 @@ static int dhd_open(struct net_device *net)
 {
        dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
 #ifdef TOE
-       uint32 toe_ol;
+       u32 toe_ol;
 #endif
        int ifidx = dhd_net2idx(dhd, net);
-       int32 ret = 0;
+       s32 ret = 0;
 
        DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
 
@@ -1823,7 +1803,6 @@ static int dhd_open(struct net_device *net)
        /* Allow transmit calls */
        netif_start_queue(net);
        dhd->pub.up = 1;
-#ifdef CONFIG_CFG80211
        if (IS_CFG80211_FAVORITE()) {
                if (unlikely(wl_cfg80211_up())) {
                        DHD_ERROR(("%s: failed to bring up cfg80211\n",
@@ -1831,29 +1810,23 @@ static int dhd_open(struct net_device *net)
                        return -1;
                }
        }
-#endif
 
-       OLD_MOD_INC_USE_COUNT;
        return ret;
 }
 
 osl_t *dhd_osl_attach(void *pdev, uint bustype)
 {
-       return osl_attach(pdev, bustype, TRUE);
+       return osl_attach(pdev, bustype, true);
 }
 
 void dhd_osl_detach(osl_t *osh)
 {
-       if (MALLOCED(osh)) {
-               DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
-                          MALLOCED(osh)));
-       }
        osl_detach(osh);
 }
 
 int
 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
-          u8 *mac_addr, uint32 flags, u8 bssidx)
+          u8 *mac_addr, u32 flags, u8 bssidx)
 {
        dhd_if_t *ifp;
 
@@ -1862,7 +1835,7 @@ dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
        ASSERT(dhd && (ifidx < DHD_MAX_IFS));
 
        ifp = dhd->iflist[ifidx];
-       if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
+       if (!ifp && !(ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC))) {
                DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
                return -ENOMEM;
        }
@@ -1870,15 +1843,14 @@ dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
        memset(ifp, 0, sizeof(dhd_if_t));
        ifp->info = dhd;
        dhd->iflist[ifidx] = ifp;
-       strncpy(ifp->name, name, IFNAMSIZ);
-       ifp->name[IFNAMSIZ] = '\0';
+       strlcpy(ifp->name, name, IFNAMSIZ);
        if (mac_addr != NULL)
                memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
 
        if (handle == NULL) {
                ifp->state = WLC_E_IF_ADD;
                ifp->idx = ifidx;
-               ASSERT(dhd->sysioc_pid >= 0);
+               ASSERT(dhd->sysioc_tsk);
                up(&dhd->sysioc_sem);
        } else
                ifp->net = (struct net_device *)handle;
@@ -1901,7 +1873,7 @@ void dhd_del_if(dhd_info_t *dhd, int ifidx)
 
        ifp->state = WLC_E_IF_DEL;
        ifp->idx = ifidx;
-       ASSERT(dhd->sysioc_pid >= 0);
+       ASSERT(dhd->sysioc_tsk);
        up(&dhd->sysioc_sem);
 }
 
@@ -1926,7 +1898,7 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
        }
 
        /* Allocate primary dhd_info */
-       dhd = MALLOC(osh, sizeof(dhd_info_t));
+       dhd = kmalloc(sizeof(dhd_info_t), GFP_ATOMIC);
        if (!dhd) {
                DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
                goto fail;
@@ -1957,7 +1929,7 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
                goto fail;
 
        net->netdev_ops = NULL;
-       init_MUTEX(&dhd->proto_sem);
+       sema_init(&dhd->proto_sem, 1);
        /* Initialize other structure content */
        init_waitqueue_head(&dhd->ioctl_resp_wait);
        init_waitqueue_head(&dhd->ctrl_wait);
@@ -1984,9 +1956,8 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
                DHD_ERROR(("wl_iw_attach failed\n"));
                goto fail;
        }
-#endif                         /* defined(CONFIG_WIRELESS_EXT) */
+#endif /* defined(CONFIG_WIRELESS_EXT) */
 
-#ifdef CONFIG_CFG80211
        /* Attach and link in the cfg80211 */
        if (IS_CFG80211_FAVORITE()) {
                if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
@@ -1999,7 +1970,6 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
                }
                wl_cfg80211_dbg_level(DBG_CFG80211_GET());
        }
-#endif
 
        /* Set up the watchdog timer */
        init_timer(&dhd->timer);
@@ -2007,39 +1977,52 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
        dhd->timer.function = dhd_watchdog;
 
        /* Initialize thread based operation and lock */
-       init_MUTEX(&dhd->sdsem);
+       sema_init(&dhd->sdsem, 1);
        if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
-               dhd->threads_only = TRUE;
+               dhd->threads_only = true;
        else
-               dhd->threads_only = FALSE;
+               dhd->threads_only = false;
 
        if (dhd_dpc_prio >= 0) {
                /* Initialize watchdog thread */
                sema_init(&dhd->watchdog_sem, 0);
-               init_completion(&dhd->watchdog_exited);
-               dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 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_pid = -1;
+               dhd->watchdog_tsk = NULL;
        }
 
        /* Set up the bottom half handler */
        if (dhd_dpc_prio >= 0) {
                /* Initialize DPC thread */
                sema_init(&dhd->dpc_sem, 0);
-               init_completion(&dhd->dpc_exited);
-               dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 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_pid = -1;
+               dhd->dpc_tsk = NULL;
        }
 
        if (dhd_sysioc) {
                sema_init(&dhd->sysioc_sem, 0);
-               init_completion(&dhd->sysioc_exited);
-               dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
-       } else {
-               dhd->sysioc_pid = -1;
-       }
+               dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
+                                               "_dhd_sysioc");
+               if (IS_ERR(dhd->sysioc_tsk)) {
+                       printk(KERN_WARNING
+                               "_dhd_sysioc thread failed to start\n");
+                       dhd->sysioc_tsk = NULL;
+               }
+       } else
+               dhd->sysioc_tsk = NULL;
 
        /*
         * Save the dhd_info into the priv
@@ -2113,7 +2096,7 @@ int dhd_bus_start(dhd_pub_t *dhdp)
        dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
 
        /* Bring up the bus */
-       ret = dhd_bus_init(&dhd->pub, TRUE);
+       ret = dhd_bus_init(&dhd->pub, true);
        if (ret != 0) {
                DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
                return ret;
@@ -2122,19 +2105,19 @@ int dhd_bus_start(dhd_pub_t *dhdp)
        /* Host registration for OOB interrupt */
        if (bcmsdh_register_oob_intr(dhdp)) {
                del_timer_sync(&dhd->timer);
-               dhd->wd_timer_valid = FALSE;
+               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);
+       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->wd_timer_valid = false;
                DHD_ERROR(("%s failed bus is not ready\n", __func__));
                return -ENODEV;
        }
@@ -2263,9 +2246,7 @@ int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
        net->ethtool_ops = &dhd_ethtool_ops;
 
 #if defined(CONFIG_WIRELESS_EXT)
-#if defined(CONFIG_CFG80211)
        if (!IS_CFG80211_FAVORITE()) {
-#endif
 #if WIRELESS_EXT < 19
                net->get_wireless_stats = dhd_get_wireless_stats;
 #endif                         /* WIRELESS_EXT < 19 */
@@ -2273,9 +2254,7 @@ int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
                net->wireless_handlers =
                    (struct iw_handler_def *)&wl_iw_handler_def;
 #endif                         /* WIRELESS_EXT > 12 */
-#if defined(CONFIG_CFG80211)
        }
-#endif
 #endif                         /* defined(CONFIG_WIRELESS_EXT) */
 
        dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
@@ -2310,14 +2289,14 @@ void dhd_bus_detach(dhd_pub_t *dhdp)
                        dhd_prot_stop(&dhd->pub);
 
                        /* Stop the bus module */
-                       dhd_bus_stop(dhd->pub.bus, TRUE);
+                       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;
+                       dhd->wd_timer_valid = false;
                }
        }
 }
@@ -2350,20 +2329,23 @@ void dhd_detach(dhd_pub_t *dhdp)
                                unregister_netdev(ifp->net);
                        }
 
-                       if (dhd->watchdog_pid >= 0) {
-                               KILL_PROC(dhd->watchdog_pid, SIGTERM);
-                               wait_for_completion(&dhd->watchdog_exited);
+                       if (dhd->watchdog_tsk) {
+                               send_sig(SIGTERM, dhd->watchdog_tsk, 1);
+                               kthread_stop(dhd->watchdog_tsk);
+                               dhd->watchdog_tsk = NULL;
                        }
 
-                       if (dhd->dpc_pid >= 0) {
-                               KILL_PROC(dhd->dpc_pid, SIGTERM);
-                               wait_for_completion(&dhd->dpc_exited);
+                       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_pid >= 0) {
-                               KILL_PROC(dhd->sysioc_pid, SIGTERM);
-                               wait_for_completion(&dhd->sysioc_exited);
+                       if (dhd->sysioc_tsk) {
+                               send_sig(SIGTERM, dhd->sysioc_tsk, 1);
+                               kthread_stop(dhd->sysioc_tsk);
+                               dhd->sysioc_tsk = NULL;
                        }
 
                        dhd_bus_detach(dhdp);
@@ -2375,10 +2357,8 @@ void dhd_detach(dhd_pub_t *dhdp)
                        wl_iw_detach();
 #endif                         /* (CONFIG_WIRELESS_EXT) */
 
-#ifdef CONFIG_CFG80211
                        if (IS_CFG80211_FAVORITE())
                                wl_cfg80211_detach();
-#endif                         /* CONFIG_CFG80211 */
 
 #if defined(CONFIG_PM_SLEEP)
                        unregister_pm_notifier(&dhd_sleep_pm_notifier);
@@ -2388,8 +2368,8 @@ void dhd_detach(dhd_pub_t *dhdp)
                        WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
                        WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
                        free_netdev(ifp->net);
-                       MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
-                       MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
+                       kfree(ifp);
+                       kfree(dhd);
                }
        }
 }
@@ -2521,7 +2501,7 @@ int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
                timeout = schedule_timeout(timeout);
 
        if (signal_pending(current))
-               *pending = TRUE;
+               *pending = true;
 
        set_current_state(TASK_RUNNING);
        remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
@@ -2542,7 +2522,7 @@ int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
 void dhd_os_wd_timer(void *bus, uint wdtick)
 {
        dhd_pub_t *pub = bus;
-       static uint save_dhd_watchdog_ms = 0;
+       static uint save_dhd_watchdog_ms;
        dhd_info_t *dhd = (dhd_info_t *) pub->info;
 
        /* don't start the wd until fw is loaded */
@@ -2550,9 +2530,9 @@ void dhd_os_wd_timer(void *bus, uint wdtick)
                return;
 
        /* Totally stop the timer */
-       if (!wdtick && dhd->wd_timer_valid == TRUE) {
+       if (!wdtick && dhd->wd_timer_valid == true) {
                del_timer_sync(&dhd->timer);
-               dhd->wd_timer_valid = FALSE;
+               dhd->wd_timer_valid = false;
                save_dhd_watchdog_ms = wdtick;
                return;
        }
@@ -2562,7 +2542,7 @@ void dhd_os_wd_timer(void *bus, uint wdtick)
 
                if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
 
-                       if (dhd->wd_timer_valid == TRUE)
+                       if (dhd->wd_timer_valid == true)
                                /* Stop timer and restart at new value */
                                del_timer_sync(&dhd->timer);
 
@@ -2579,7 +2559,7 @@ void dhd_os_wd_timer(void *bus, uint wdtick)
                                  jiffies + dhd_watchdog_ms * HZ / 1000);
                }
 
-               dhd->wd_timer_valid = TRUE;
+               dhd->wd_timer_valid = true;
                save_dhd_watchdog_ms = wdtick;
        }
 }
@@ -2588,10 +2568,8 @@ void *dhd_os_open_image(char *filename)
 {
        struct file *fp;
 
-#ifdef CONFIG_CFG80211
        if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
                return wl_cfg80211_request_fw(filename);
-#endif
 
        fp = filp_open(filename, O_RDONLY, 0);
        /*
@@ -2611,10 +2589,8 @@ int dhd_os_get_image_block(char *buf, int len, void *image)
        struct file *fp = (struct file *)image;
        int rdlen;
 
-#ifdef CONFIG_CFG80211
        if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
                return wl_cfg80211_read_fw(buf, len);
-#endif
 
        if (!image)
                return 0;
@@ -2628,10 +2604,8 @@ int dhd_os_get_image_block(char *buf, int len, void *image)
 
 void dhd_os_close_image(void *image)
 {
-#ifdef CONFIG_CFG80211
        if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
                return wl_cfg80211_release_fw();
-#endif
        if (image)
                filp_close((struct file *)image, NULL);
 }
@@ -2694,27 +2668,6 @@ void dhd_os_sdtxunlock(dhd_pub_t *pub)
        dhd_os_sdunlock(pub);
 }
 
-#ifdef DHD_USE_STATIC_BUF
-void *dhd_os_prealloc(int section, unsigned long size)
-{
-#if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
-       void *alloc_ptr = NULL;
-       if (wifi_control_data && wifi_control_data->mem_prealloc) {
-               alloc_ptr = wifi_control_data->mem_prealloc(section, size);
-               if (alloc_ptr) {
-                       DHD_INFO(("success alloc section %d\n", section));
-                       bzero(alloc_ptr, size);
-                       return alloc_ptr;
-               }
-       }
-
-       DHD_ERROR(("can't alloc section %d\n", section));
-       return 0;
-#else
-       return MALLOC(0, size);
-#endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
-}
-#endif /* DHD_USE_STATIC_BUF */
 #if defined(CONFIG_WIRELESS_EXT)
 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
 {
@@ -2743,9 +2696,7 @@ dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
                return bcmerror;
 
 #if defined(CONFIG_WIRELESS_EXT)
-#if defined(CONFIG_CFG80211)
        if (!IS_CFG80211_FAVORITE()) {
-#endif
                if ((dhd->iflist[*ifidx] == NULL)
                    || (dhd->iflist[*ifidx]->net == NULL)) {
                        DHD_ERROR(("%s Exit null pointer\n", __func__));
@@ -2754,12 +2705,9 @@ dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
 
                if (dhd->iflist[*ifidx]->net)
                        wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
-#if defined(CONFIG_CFG80211)
        }
-#endif
 #endif                         /* defined(CONFIG_WIRELESS_EXT)  */
 
-#ifdef CONFIG_CFG80211
        if (IS_CFG80211_FAVORITE()) {
                ASSERT(dhd->iflist[*ifidx] != NULL);
                ASSERT(dhd->iflist[*ifidx]->net != NULL);
@@ -2767,7 +2715,6 @@ dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
                        wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
                                          *data);
        }
-#endif
 
        return bcmerror;
 }
@@ -2786,7 +2733,7 @@ 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);
+                                        (*lockvar == false), HZ * 2);
        dhd_os_sdlock(dhd);
        return;
 }
@@ -2970,7 +2917,7 @@ int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
 
 exit:
        /* free buf before return */
-       MFREE(dhd->osh, buf, size);
+       kfree(buf);
        /* close file before return */
        if (fp)
                filp_close(fp, current->files);