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 5c8224f..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/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>
 
@@ -171,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) */
 
@@ -343,7 +341,7 @@ 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);
 
 /* Use cfg80211 */
@@ -426,7 +424,7 @@ static int dhd_sleep_pm_callback(struct notifier_block *nfb,
                return NOTIFY_OK;
        case PM_POST_HIBERNATION:
        case PM_POST_SUSPEND:
-               dhd_mmc_suspend = FALSE;
+               dhd_mmc_suspend = false;
                return NOTIFY_OK;
        }
        return 0;
@@ -614,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;
@@ -707,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));
@@ -747,7 +745,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
                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
@@ -755,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)));
@@ -768,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;
        }
 
@@ -784,12 +782,12 @@ 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));
@@ -921,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
@@ -935,9 +933,11 @@ 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
 
+       allow_signal(SIGTERM);
+
        while (down_interruptible(&dhd->sysioc_sem) == 0) {
                if (kthread_should_stop())
                        break;
@@ -959,23 +959,23 @@ 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);
                                }
@@ -1039,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);
 
@@ -1295,12 +1291,13 @@ static int dhd_watchdog_thread(void *data)
        }
 #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) {
+                       if (dhd->pub.dongle_reset == false) {
                                WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
                                /* Call the bus module watchdog */
                                dhd_bus_watchdog(&dhd->pub);
@@ -1360,6 +1357,7 @@ static int dhd_dpc_thread(void *data)
        }
 #endif                         /* DHD_SCHED */
 
+       allow_signal(SIGTERM);
        /* Run until signal received */
        while (1) {
                if (kthread_should_stop())
@@ -1427,7 +1425,7 @@ static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *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);
@@ -1672,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;
@@ -1742,7 +1740,7 @@ done:
        }
 
        if (buf)
-               MFREE(dhd->pub.osh, buf, buflen);
+               kfree(buf);
 
        return OSL_ERROR(bcmerror);
 }
@@ -1823,10 +1821,6 @@ osl_t *dhd_osl_attach(void *pdev, uint bustype)
 
 void dhd_osl_detach(osl_t *osh)
 {
-       if (MALLOCED(osh)) {
-               DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
-                          MALLOCED(osh)));
-       }
        osl_detach(osh);
 }
 
@@ -1841,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;
        }
@@ -1904,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;
@@ -1935,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);
@@ -1983,11 +1977,11 @@ 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;
        else
-               dhd->threads_only = FALSE;
+               dhd->threads_only = false;
 
        if (dhd_dpc_prio >= 0) {
                /* Initialize watchdog thread */
@@ -2111,7 +2105,7 @@ 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;
        }
@@ -2123,7 +2117,7 @@ int dhd_bus_start(dhd_pub_t *dhdp)
        /* 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;
        }
@@ -2302,7 +2296,7 @@ void dhd_bus_detach(dhd_pub_t *dhdp)
 
                        /* Clear the watchdog timer */
                        del_timer_sync(&dhd->timer);
-                       dhd->wd_timer_valid = FALSE;
+                       dhd->wd_timer_valid = false;
                }
        }
 }
@@ -2336,17 +2330,20 @@ void dhd_detach(dhd_pub_t *dhdp)
                        }
 
                        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;
                        }
@@ -2371,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);
                }
        }
 }
@@ -2535,7 +2532,7 @@ void dhd_os_wd_timer(void *bus, uint wdtick)
        /* Totally stop the timer */
        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;
        }
@@ -2671,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)
 {
@@ -2757,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;
 }
@@ -2941,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);