2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifdef CONFIG_WIFI_CONTROL_FUNC
18 #include <linux/platform_device.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <linux/skbuff.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/mmc/sdio_func.h>
28 #include <linux/random.h>
29 #include <linux/spinlock.h>
30 #include <linux/ethtool.h>
31 #include <linux/fcntl.h>
33 #include <linux/uaccess.h>
34 #include <net/cfg80211.h>
36 #include <brcmu_utils.h>
37 #include <brcmu_wifi.h>
39 #include "dngl_stats.h"
42 #include "dhd_proto.h"
44 #include "wl_cfg80211.h"
46 #define EPI_VERSION_STR "4.218.248.5"
47 #define ETH_P_BRCM 0x886c
49 /* Global ASSERT type flag */
52 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
53 #include <linux/wifi_tiwlan.h>
55 struct semaphore wifi_control_sem;
57 struct dhd_bus *g_bus;
59 static struct wifi_platform_data *wifi_control_data;
60 static struct resource *wifi_irqres;
62 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
65 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
66 return (int)wifi_irqres->start;
68 #ifdef CUSTOM_OOB_GPIO_NUM
69 return CUSTOM_OOB_GPIO_NUM;
75 int wifi_set_carddetect(int on)
77 printk(KERN_ERR "%s = %d\n", __func__, on);
78 if (wifi_control_data && wifi_control_data->set_carddetect)
79 wifi_control_data->set_carddetect(on);
83 int wifi_set_power(int on, unsigned long msec)
85 printk(KERN_ERR "%s = %d\n", __func__, on);
86 if (wifi_control_data && wifi_control_data->set_power)
87 wifi_control_data->set_power(on);
93 int wifi_set_reset(int on, unsigned long msec)
95 printk(KERN_ERR "%s = %d\n", __func__, on);
96 if (wifi_control_data && wifi_control_data->set_reset)
97 wifi_control_data->set_reset(on);
103 static int wifi_probe(struct platform_device *pdev)
105 struct wifi_platform_data *wifi_ctrl =
106 (struct wifi_platform_data *)(pdev->dev.platform_data);
108 printk(KERN_ERR "## %s\n", __func__);
110 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
112 wifi_control_data = wifi_ctrl;
114 wifi_set_power(1, 0); /* Power On */
115 wifi_set_carddetect(1); /* CardDetect (0->1) */
117 up(&wifi_control_sem);
121 static int wifi_remove(struct platform_device *pdev)
123 struct wifi_platform_data *wifi_ctrl =
124 (struct wifi_platform_data *)(pdev->dev.platform_data);
126 printk(KERN_ERR "## %s\n", __func__);
127 wifi_control_data = wifi_ctrl;
129 wifi_set_carddetect(0); /* CardDetect (1->0) */
130 wifi_set_power(0, 0); /* Power Off */
132 up(&wifi_control_sem);
136 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
138 DHD_TRACE(("##> %s\n", __func__));
142 static int wifi_resume(struct platform_device *pdev)
144 DHD_TRACE(("##> %s\n", __func__));
148 static struct platform_driver wifi_device = {
150 .remove = wifi_remove,
151 .suspend = wifi_suspend,
152 .resume = wifi_resume,
154 .name = KBUILD_MODNAME,
158 int wifi_add_dev(void)
160 DHD_TRACE(("## Calling platform_driver_register\n"));
161 return platform_driver_register(&wifi_device);
164 void wifi_del_dev(void)
166 DHD_TRACE(("## Unregister platform_driver_register\n"));
167 platform_driver_unregister(&wifi_device);
169 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
171 #if defined(CONFIG_PM_SLEEP)
172 #include <linux/suspend.h>
173 atomic_t dhd_mmc_suspend;
174 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
175 #endif /* defined(CONFIG_PM_SLEEP) */
177 #if defined(OOB_INTR_ONLY)
178 extern void brcmf_sdbrcm_enable_oob_intr(struct dhd_bus *bus, bool enable);
179 #endif /* defined(OOB_INTR_ONLY) */
181 MODULE_AUTHOR("Broadcom Corporation");
182 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
183 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
184 MODULE_LICENSE("Dual BSD/GPL");
186 #if defined(CONFIG_HAS_EARLYSUSPEND)
187 #include <linux/earlysuspend.h>
188 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
190 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
192 #ifdef PKT_FILTER_SUPPORT
193 extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
194 extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
198 /* Interface control information */
199 typedef struct dhd_if {
200 struct dhd_info *info; /* back pointer to dhd_info */
201 /* OS/stack specifics */
202 struct net_device *net;
203 struct net_device_stats stats;
204 int idx; /* iface idx in dongle */
205 int state; /* interface state */
206 uint subunit; /* subunit */
207 u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
208 bool attached; /* Delayed attachment when unset */
209 bool txflowcontrol; /* Per interface flow control indicator */
210 char name[IFNAMSIZ]; /* linux interface name */
213 /* Local private structure (extension of pub) */
214 typedef struct dhd_info {
217 /* OS/stack specifics */
218 dhd_if_t *iflist[DHD_MAX_IFS];
220 struct semaphore proto_sem;
221 wait_queue_head_t ioctl_resp_wait;
222 struct timer_list timer;
224 struct tasklet_struct tasklet;
226 /* Thread based operation */
228 struct semaphore sdsem;
229 struct task_struct *watchdog_tsk;
230 struct semaphore watchdog_sem;
231 struct task_struct *dpc_tsk;
232 struct semaphore dpc_sem;
234 /* Thread to issue ioctl for multicast */
235 struct task_struct *sysioc_tsk;
236 struct semaphore sysioc_sem;
239 u8 macvalue[ETH_ALEN];
240 wait_queue_head_t ctrl_wait;
241 atomic_t pend_8021x_cnt;
243 #ifdef CONFIG_HAS_EARLYSUSPEND
244 struct early_suspend early_suspend;
245 #endif /* CONFIG_HAS_EARLYSUSPEND */
248 /* Definitions to provide path to the firmware and nvram
249 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
251 char firmware_path[MOD_PARAM_PATHLEN];
252 char nvram_path[MOD_PARAM_PATHLEN];
254 /* load firmware and/or nvram values from the filesystem */
255 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
256 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
258 /* No firmware required */
260 module_param(dhd_no_fw_req, bool, 0);
263 module_param(dhd_msg_level, int, 0);
265 /* Spawn a thread for system ioctls (set mac, set mcast) */
266 uint dhd_sysioc = true;
267 module_param(dhd_sysioc, uint, 0);
269 /* Watchdog interval */
270 uint dhd_watchdog_ms = 10;
271 module_param(dhd_watchdog_ms, uint, 0);
274 /* Console poll interval */
276 module_param(dhd_console_ms, uint, 0);
277 #endif /* DHD_DEBUG */
279 /* ARP offload agent mode : Enable ARP Host Auto-Reply
280 and ARP Peer Auto-Reply */
281 uint dhd_arp_mode = 0xb;
282 module_param(dhd_arp_mode, uint, 0);
284 /* ARP offload enable */
285 uint dhd_arp_enable = true;
286 module_param(dhd_arp_enable, uint, 0);
288 /* Global Pkt filter enable control */
289 uint dhd_pkt_filter_enable = true;
290 module_param(dhd_pkt_filter_enable, uint, 0);
292 /* Pkt filter init setup */
293 uint dhd_pkt_filter_init;
294 module_param(dhd_pkt_filter_init, uint, 0);
296 /* Pkt filter mode control */
297 uint dhd_master_mode = true;
298 module_param(dhd_master_mode, uint, 1);
300 /* Watchdog thread priority, -1 to use kernel timer */
301 int dhd_watchdog_prio = 97;
302 module_param(dhd_watchdog_prio, int, 0);
304 /* DPC thread priority, -1 to use tasklet */
305 int dhd_dpc_prio = 98;
306 module_param(dhd_dpc_prio, int, 0);
308 /* DPC thread priority, -1 to use tasklet */
309 extern int dhd_dongle_memsize;
310 module_param(dhd_dongle_memsize, int, 0);
312 /* Contorl fw roaming */
319 /* Control radio state */
320 uint dhd_radio_up = 1;
322 /* Network inteface name */
323 char iface_name[IFNAMSIZ] = "wlan";
324 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
326 /* The following are specific to the SDIO dongle */
328 /* IOCTL response timeout */
329 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
331 /* Idle timeout for backplane clock */
332 int dhd_idletime = DHD_IDLETIME_TICKS;
333 module_param(dhd_idletime, int, 0);
337 module_param(dhd_poll, uint, 0);
340 uint dhd_intr = true;
341 module_param(dhd_intr, uint, 0);
343 /* SDIO Drive Strength (in milliamps) */
344 uint dhd_sdiod_drive_strength = 6;
345 module_param(dhd_sdiod_drive_strength, uint, 0);
348 extern uint dhd_txbound;
349 extern uint dhd_rxbound;
350 module_param(dhd_txbound, uint, 0);
351 module_param(dhd_rxbound, uint, 0);
353 /* Deferred transmits */
354 extern uint dhd_deferred_tx;
355 module_param(dhd_deferred_tx, uint, 0);
358 /* Echo packet generator (pkts/s) */
360 module_param(dhd_pktgen, uint, 0);
362 /* Echo packet len (0 => sawtooth, max 2040) */
364 module_param(dhd_pktgen_len, uint, 0);
367 /* Version string to report */
369 #define DHD_COMPILED "\nCompiled in " SRCBASE
374 static void dhd_dpc(unsigned long data);
376 extern int dhd_wait_pend8021x(struct net_device *dev);
380 #error TOE requires BDC
382 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
383 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
386 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
387 wl_event_msg_t *event_ptr, void **data_ptr);
389 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
391 #ifdef PKT_FILTER_SUPPORT
392 DHD_TRACE(("%s: %d\n", __func__, value));
393 /* 1 - Enable packet filter, only allow unicast packet to send up */
394 /* 0 - Disable packet filter */
395 if (dhd_pkt_filter_enable) {
398 for (i = 0; i < dhd->pktfilter_count; i++) {
399 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
400 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
401 value, dhd_master_mode);
407 #if defined(CONFIG_HAS_EARLYSUSPEND)
408 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
410 int power_mode = PM_MAX;
411 /* wl_pkt_filter_enable_t enable_parm; */
416 #endif /* CUSTOMER_HW2 */
418 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
419 __func__, value, dhd->in_suspend));
421 if (dhd && dhd->up) {
422 if (value && dhd->in_suspend) {
424 /* Kernel suspended */
425 DHD_TRACE(("%s: force extra Suspend setting\n",
428 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
432 /* Enable packet filter, only allow unicast
434 dhd_set_packet_filter(1, dhd);
436 /* if dtim skip setup as default force it
437 * to wake each third dtim
438 * for better power saving.
439 * Note that side effect is chance to miss BC/MC
442 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
445 bcn_li_dtim = dhd->dtim_skip;
446 brcmu_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
447 4, iovbuf, sizeof(iovbuf));
448 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
451 /* Disable build-in roaming to allowed \
452 * supplicant to take of romaing
454 brcmu_mkiovar("roam_off", (char *)&roamvar, 4,
455 iovbuf, sizeof(iovbuf));
456 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
458 #endif /* CUSTOMER_HW2 */
462 DHD_TRACE(("%s: Remove extra suspend setting\n",
465 power_mode = PM_FAST;
466 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
470 /* disable pkt filter */
471 dhd_set_packet_filter(0, dhd);
473 /* restore pre-suspend setting for dtim_skip */
474 brcmu_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
475 4, iovbuf, sizeof(iovbuf));
477 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
481 brcmu_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
483 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
485 #endif /* CUSTOMER_HW2 */
492 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
494 dhd_pub_t *dhdp = &dhd->pub;
496 dhd_os_proto_block(dhdp);
497 /* Set flag when early suspend was called */
498 dhdp->in_suspend = val;
499 if (!dhdp->suspend_disable_flag)
500 dhd_set_suspend(val, dhdp);
501 dhd_os_proto_unblock(dhdp);
504 static void dhd_early_suspend(struct early_suspend *h)
506 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
508 DHD_TRACE(("%s: enter\n", __func__));
511 dhd_suspend_resume_helper(dhd, 1);
515 static void dhd_late_resume(struct early_suspend *h)
517 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
519 DHD_TRACE(("%s: enter\n", __func__));
522 dhd_suspend_resume_helper(dhd, 0);
524 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
527 * Generalized timeout mechanism. Uses spin sleep with exponential
529 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
531 * dhd_timeout_start(&tmo, usec);
532 * while (!dhd_timeout_expired(&tmo))
533 * if (poll_something())
535 * if (dhd_timeout_expired(&tmo))
539 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
544 tmo->tick = 1000000 / HZ;
547 int dhd_timeout_expired(dhd_timeout_t *tmo)
549 /* Does nothing the first call */
550 if (tmo->increment == 0) {
555 if (tmo->elapsed >= tmo->limit)
558 /* Add the delay that's about to take place */
559 tmo->elapsed += tmo->increment;
561 if (tmo->increment < tmo->tick) {
562 udelay(tmo->increment);
564 if (tmo->increment > tmo->tick)
565 tmo->increment = tmo->tick;
567 wait_queue_head_t delay_wait;
568 DECLARE_WAITQUEUE(wait, current);
570 init_waitqueue_head(&delay_wait);
571 add_wait_queue(&delay_wait, &wait);
572 set_current_state(TASK_INTERRUPTIBLE);
574 pending = signal_pending(current);
575 remove_wait_queue(&delay_wait, &wait);
576 set_current_state(TASK_RUNNING);
578 return 1; /* Interrupted */
584 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
589 while (i < DHD_MAX_IFS) {
590 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
598 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
604 if (name == NULL || *name == '\0')
609 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
612 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
614 return i; /* default - the primary interface */
617 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
619 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
623 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
624 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
628 if (dhd->iflist[ifidx] == NULL) {
629 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
633 if (dhd->iflist[ifidx]->net)
634 return dhd->iflist[ifidx]->net->name;
639 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
641 struct net_device *dev;
642 struct netdev_hw_addr *ha;
650 ASSERT(dhd && dhd->iflist[ifidx]);
651 dev = dhd->iflist[ifidx]->net;
652 cnt = netdev_mc_count(dev);
654 /* Determine initial value of allmulti flag */
655 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
657 /* Send down the multicast list first. */
659 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
660 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
662 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
663 dhd_ifname(&dhd->pub, ifidx), cnt));
667 strcpy(bufp, "mcast_list");
668 bufp += strlen("mcast_list") + 1;
670 cnt = cpu_to_le32(cnt);
671 memcpy(bufp, &cnt, sizeof(cnt));
674 netdev_for_each_mc_addr(ha, dev) {
677 memcpy(bufp, ha->addr, ETH_ALEN);
682 memset(&ioc, 0, sizeof(ioc));
683 ioc.cmd = WLC_SET_VAR;
688 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
690 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
691 dhd_ifname(&dhd->pub, ifidx), cnt));
692 allmulti = cnt ? true : allmulti;
697 /* Now send the allmulti setting. This is based on the setting in the
698 * net_device flags, but might be modified above to be turned on if we
699 * were trying to set some addresses and dongle rejected it...
702 buflen = sizeof("allmulti") + sizeof(allmulti);
703 buf = kmalloc(buflen, GFP_ATOMIC);
705 DHD_ERROR(("%s: out of memory for allmulti\n",
706 dhd_ifname(&dhd->pub, ifidx)));
709 allmulti = cpu_to_le32(allmulti);
712 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
713 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
714 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
715 (int)sizeof(allmulti), buflen));
720 memset(&ioc, 0, sizeof(ioc));
721 ioc.cmd = WLC_SET_VAR;
726 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
728 DHD_ERROR(("%s: set allmulti %d failed\n",
729 dhd_ifname(&dhd->pub, ifidx),
730 le32_to_cpu(allmulti)));
735 /* Finally, pick up the PROMISC flag as well, like the NIC
738 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
739 allmulti = cpu_to_le32(allmulti);
741 memset(&ioc, 0, sizeof(ioc));
742 ioc.cmd = WLC_SET_PROMISC;
744 ioc.len = sizeof(allmulti);
747 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
749 DHD_ERROR(("%s: set promisc %d failed\n",
750 dhd_ifname(&dhd->pub, ifidx),
751 le32_to_cpu(allmulti)));
756 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, u8 *addr)
762 DHD_TRACE(("%s enter\n", __func__));
764 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
765 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
766 dhd_ifname(&dhd->pub, ifidx)));
769 memset(&ioc, 0, sizeof(ioc));
770 ioc.cmd = WLC_SET_VAR;
775 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
777 DHD_ERROR(("%s: set cur_etheraddr failed\n",
778 dhd_ifname(&dhd->pub, ifidx)));
780 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
787 extern struct net_device *ap_net_dev;
790 static void dhd_op_if(dhd_if_t *ifp)
793 int ret = 0, err = 0;
795 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
799 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
801 switch (ifp->state) {
804 * Delete the existing interface before overwriting it
805 * in case we missed the WLC_E_IF_DEL event.
807 if (ifp->net != NULL) {
808 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
809 "try free & unregister\n",
810 __func__, ifp->net->name));
811 netif_stop_queue(ifp->net);
812 unregister_netdev(ifp->net);
813 free_netdev(ifp->net);
815 /* Allocate etherdev, including space for private structure */
816 ifp->net = alloc_etherdev(sizeof(dhd));
818 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
822 strcpy(ifp->net->name, ifp->name);
823 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
824 err = dhd_net_attach(&dhd->pub, ifp->idx);
826 DHD_ERROR(("%s: dhd_net_attach failed, "
832 /* semaphore that the soft AP CODE
834 extern struct semaphore ap_eth_sema;
836 /* save ptr to wl0.1 netdev for use
838 ap_net_dev = ifp->net;
839 /* signal to the SOFTAP 'sleeper' thread,
843 DHD_TRACE(("\n ==== pid:%x, net_device for "
844 "if:%s created ===\n\n",
845 current->pid, ifp->net->name));
851 if (ifp->net != NULL) {
852 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
854 netif_stop_queue(ifp->net);
855 unregister_netdev(ifp->net);
856 ret = DHD_DEL_IF; /* Make sure the free_netdev()
861 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
868 free_netdev(ifp->net);
870 dhd->iflist[ifp->idx] = NULL;
873 if (ifp->net == ap_net_dev)
874 ap_net_dev = NULL; /* NULL SOFTAP global
880 static int _dhd_sysioc_thread(void *data)
882 dhd_info_t *dhd = (dhd_info_t *) data;
888 allow_signal(SIGTERM);
890 while (down_interruptible(&dhd->sysioc_sem) == 0) {
891 if (kthread_should_stop())
893 for (i = 0; i < DHD_MAX_IFS; i++) {
894 if (dhd->iflist[i]) {
896 in_ap = (ap_net_dev != NULL);
898 if (dhd->iflist[i]->state)
899 dhd_op_if(dhd->iflist[i]);
901 if (dhd->iflist[i] == NULL) {
902 DHD_TRACE(("\n\n %s: interface %d "
903 "removed!\n", __func__, i));
907 if (in_ap && dhd->set_macaddress) {
908 DHD_TRACE(("attempt to set MAC for %s "
909 "in AP Mode," "blocked.\n",
910 dhd->iflist[i]->net->name));
911 dhd->set_macaddress = false;
915 if (in_ap && dhd->set_multicast) {
916 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked.\n",
917 dhd->iflist[i]->net->name));
918 dhd->set_multicast = false;
922 if (dhd->set_multicast) {
923 dhd->set_multicast = false;
924 _dhd_set_multicast_list(dhd, i);
926 if (dhd->set_macaddress) {
927 dhd->set_macaddress = false;
928 _dhd_set_mac_address(dhd, i,
937 static int dhd_set_mac_address(struct net_device *dev, void *addr)
941 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
942 struct sockaddr *sa = (struct sockaddr *)addr;
945 ifidx = dhd_net2idx(dhd, dev);
946 if (ifidx == DHD_BAD_IF)
949 ASSERT(dhd->sysioc_tsk);
950 memcpy(&dhd->macvalue, sa->sa_data, ETH_ALEN);
951 dhd->set_macaddress = true;
952 up(&dhd->sysioc_sem);
957 static void dhd_set_multicast_list(struct net_device *dev)
959 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
962 ifidx = dhd_net2idx(dhd, dev);
963 if (ifidx == DHD_BAD_IF)
966 ASSERT(dhd->sysioc_tsk);
967 dhd->set_multicast = true;
968 up(&dhd->sysioc_sem);
971 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf)
974 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
977 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
980 /* Update multicast statistic */
981 if (pktbuf->len >= ETH_ALEN) {
982 u8 *pktdata = (u8 *) (pktbuf->data);
983 struct ethhdr *eh = (struct ethhdr *)pktdata;
985 if (is_multicast_ether_addr(eh->h_dest))
986 dhdp->tx_multicast++;
987 if (ntohs(eh->h_proto) == ETH_P_PAE)
988 atomic_inc(&dhd->pend_8021x_cnt);
991 /* If the protocol uses a data header, apply it */
992 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
994 /* Use bus module to send data frame */
996 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
998 ret = brcmf_sdbrcm_bus_txdata(dhdp->bus, pktbuf);
1004 static inline void *
1005 osl_pkt_frmnative(struct sk_buff *skb)
1009 #define PKTFRMNATIVE(osh, skb) \
1010 osl_pkt_frmnative((struct sk_buff *)(skb))
1012 static inline struct sk_buff *
1013 osl_pkt_tonative(void *pkt)
1015 return (struct sk_buff *)pkt;
1017 #define PKTTONATIVE(osh, pkt) \
1018 osl_pkt_tonative((pkt))
1020 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1024 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1027 DHD_TRACE(("%s: Enter\n", __func__));
1029 /* Reject if down */
1030 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1031 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1032 __func__, dhd->pub.up, dhd->pub.busstate));
1033 netif_stop_queue(net);
1037 ifidx = dhd_net2idx(dhd, net);
1038 if (ifidx == DHD_BAD_IF) {
1039 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1040 netif_stop_queue(net);
1044 /* Make sure there's enough room for any header */
1045 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1046 struct sk_buff *skb2;
1048 DHD_INFO(("%s: insufficient headroom\n",
1049 dhd_ifname(&dhd->pub, ifidx)));
1050 dhd->pub.tx_realloc++;
1051 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1055 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1056 dhd_ifname(&dhd->pub, ifidx)));
1062 /* Convert to packet */
1063 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1065 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1066 dhd_ifname(&dhd->pub, ifidx)));
1067 dev_kfree_skb_any(skb);
1072 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1076 dhd->pub.dstats.tx_dropped++;
1078 dhd->pub.tx_packets++;
1080 /* Return ok: we always eat the packet */
1084 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1086 struct net_device *net;
1087 dhd_info_t *dhd = dhdp->info;
1089 DHD_TRACE(("%s: Enter\n", __func__));
1091 dhdp->txoff = state;
1092 ASSERT(dhd && dhd->iflist[ifidx]);
1093 net = dhd->iflist[ifidx]->net;
1095 netif_stop_queue(net);
1097 netif_wake_queue(net);
1100 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf,
1103 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1104 struct sk_buff *skb;
1108 struct sk_buff *pnext, *save_pktbuf;
1111 wl_event_msg_t event;
1113 DHD_TRACE(("%s: Enter\n", __func__));
1115 save_pktbuf = pktbuf;
1117 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1119 pnext = pktbuf->next;
1120 pktbuf->next = NULL;
1122 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1124 /* Get the protocol, maintain skb around eth_type_trans()
1125 * The main reason for this hack is for the limitation of
1126 * Linux 2.4 where 'eth_type_trans' uses the
1127 * 'net->hard_header_len'
1128 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1129 * coping of the packet coming from the network stack to add
1130 * BDC, Hardware header etc, during network interface
1132 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1134 * for BDC, Hardware header etc. and not just the ETH_HLEN
1139 ifp = dhd->iflist[ifidx];
1141 ifp = dhd->iflist[0];
1144 skb->dev = ifp->net;
1145 skb->protocol = eth_type_trans(skb, skb->dev);
1147 if (skb->pkt_type == PACKET_MULTICAST)
1148 dhd->pub.rx_multicast++;
1153 /* Strip header, count, deliver upward */
1154 skb_pull(skb, ETH_HLEN);
1156 /* Process special event packets and then discard them */
1157 if (ntohs(skb->protocol) == ETH_P_BRCM)
1158 dhd_wl_host_event(dhd, &ifidx,
1159 skb_mac_header(skb),
1162 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1163 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1164 ifp = dhd->iflist[ifidx];
1167 ifp->net->last_rx = jiffies;
1169 dhdp->dstats.rx_bytes += skb->len;
1170 dhdp->rx_packets++; /* Local count */
1172 if (in_interrupt()) {
1175 /* If the receive is not processed inside an ISR,
1176 * the softirqd must be woken explicitly to service
1177 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1178 * by netif_rx_ni(), but in earlier kernels, we need
1179 * to do it manually.
1186 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1188 /* Linux version has nothing to do */
1192 void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success)
1195 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1199 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1201 eh = (struct ethhdr *)(txp->data);
1202 type = ntohs(eh->h_proto);
1204 if (type == ETH_P_PAE)
1205 atomic_dec(&dhd->pend_8021x_cnt);
1209 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1211 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1215 DHD_TRACE(("%s: Enter\n", __func__));
1217 ifidx = dhd_net2idx(dhd, net);
1218 if (ifidx == DHD_BAD_IF)
1221 ifp = dhd->iflist[ifidx];
1225 /* Use the protocol to get dongle stats */
1226 dhd_prot_dstats(&dhd->pub);
1229 /* Copy dongle stats to net device stats */
1230 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1231 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1232 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1233 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1234 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1235 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1236 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1237 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1238 ifp->stats.multicast = dhd->pub.dstats.multicast;
1243 static int dhd_watchdog_thread(void *data)
1245 dhd_info_t *dhd = (dhd_info_t *) data;
1247 /* This thread doesn't need any user-level access,
1248 * so get rid of all our resources
1251 if (dhd_watchdog_prio > 0) {
1252 struct sched_param param;
1253 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1254 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1255 setScheduler(current, SCHED_FIFO, ¶m);
1257 #endif /* DHD_SCHED */
1259 allow_signal(SIGTERM);
1260 /* Run until signal received */
1262 if (kthread_should_stop())
1264 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1265 if (dhd->pub.dongle_reset == false) {
1266 /* Call the bus module watchdog */
1267 brcmf_sdbrcm_bus_watchdog(&dhd->pub);
1269 /* Count the tick for reference */
1277 static void dhd_watchdog(unsigned long data)
1279 dhd_info_t *dhd = (dhd_info_t *) data;
1281 if (dhd->watchdog_tsk) {
1282 up(&dhd->watchdog_sem);
1284 /* Reschedule the watchdog */
1285 if (dhd->wd_timer_valid) {
1286 mod_timer(&dhd->timer,
1287 jiffies + dhd_watchdog_ms * HZ / 1000);
1292 /* Call the bus module watchdog */
1293 brcmf_sdbrcm_bus_watchdog(&dhd->pub);
1295 /* Count the tick for reference */
1298 /* Reschedule the watchdog */
1299 if (dhd->wd_timer_valid)
1300 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1303 static int dhd_dpc_thread(void *data)
1305 dhd_info_t *dhd = (dhd_info_t *) data;
1307 /* This thread doesn't need any user-level access,
1308 * so get rid of all our resources
1311 if (dhd_dpc_prio > 0) {
1312 struct sched_param param;
1313 param.sched_priority =
1315 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1316 setScheduler(current, SCHED_FIFO, ¶m);
1318 #endif /* DHD_SCHED */
1320 allow_signal(SIGTERM);
1321 /* Run until signal received */
1323 if (kthread_should_stop())
1325 if (down_interruptible(&dhd->dpc_sem) == 0) {
1326 /* Call bus dpc unless it indicated down
1327 (then clean stop) */
1328 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1329 if (dhd_bus_dpc(dhd->pub.bus)) {
1333 brcmf_sdbrcm_bus_stop(dhd->pub.bus, true);
1341 static void dhd_dpc(unsigned long data)
1345 dhd = (dhd_info_t *) data;
1347 /* Call bus dpc unless it indicated down (then clean stop) */
1348 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1349 if (dhd_bus_dpc(dhd->pub.bus))
1350 tasklet_schedule(&dhd->tasklet);
1352 brcmf_sdbrcm_bus_stop(dhd->pub.bus, true);
1356 void dhd_sched_dpc(dhd_pub_t *dhdp)
1358 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1365 tasklet_schedule(&dhd->tasklet);
1369 /* Retrieve current toe component enables, which are kept
1370 as a bitmap in toe_ol iovar */
1371 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1377 memset(&ioc, 0, sizeof(ioc));
1379 ioc.cmd = WLC_GET_VAR;
1381 ioc.len = (uint) sizeof(buf);
1384 strcpy(buf, "toe_ol");
1385 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1387 /* Check for older dongle image that doesn't support toe_ol */
1389 DHD_ERROR(("%s: toe not supported by device\n",
1390 dhd_ifname(&dhd->pub, ifidx)));
1394 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1395 dhd_ifname(&dhd->pub, ifidx), ret));
1399 memcpy(toe_ol, buf, sizeof(u32));
1403 /* Set current toe component enables in toe_ol iovar,
1404 and set toe global enable iovar */
1405 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1411 memset(&ioc, 0, sizeof(ioc));
1413 ioc.cmd = WLC_SET_VAR;
1415 ioc.len = (uint) sizeof(buf);
1418 /* Set toe_ol as requested */
1420 strcpy(buf, "toe_ol");
1421 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1423 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1425 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1426 dhd_ifname(&dhd->pub, ifidx), ret));
1430 /* Enable toe globally only if any components are enabled. */
1432 toe = (toe_ol != 0);
1435 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1437 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1439 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1440 dhd_ifname(&dhd->pub, ifidx), ret));
1448 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1449 struct ethtool_drvinfo *info)
1451 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1453 sprintf(info->driver, KBUILD_MODNAME);
1454 sprintf(info->version, "%lu", dhd->pub.drv_version);
1455 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1456 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1459 struct ethtool_ops dhd_ethtool_ops = {
1460 .get_drvinfo = dhd_ethtool_get_drvinfo
1463 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1465 struct ethtool_drvinfo info;
1466 char drvname[sizeof(info.driver)];
1469 struct ethtool_value edata;
1470 u32 toe_cmpnt, csum_dir;
1474 DHD_TRACE(("%s: Enter\n", __func__));
1476 /* all ethtool calls start with a cmd word */
1477 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1481 case ETHTOOL_GDRVINFO:
1482 /* Copy out any request driver name */
1483 if (copy_from_user(&info, uaddr, sizeof(info)))
1485 strncpy(drvname, info.driver, sizeof(info.driver));
1486 drvname[sizeof(info.driver) - 1] = '\0';
1488 /* clear struct for return */
1489 memset(&info, 0, sizeof(info));
1492 /* if dhd requested, identify ourselves */
1493 if (strcmp(drvname, "?dhd") == 0) {
1494 sprintf(info.driver, "dhd");
1495 strcpy(info.version, EPI_VERSION_STR);
1498 /* otherwise, require dongle to be up */
1499 else if (!dhd->pub.up) {
1500 DHD_ERROR(("%s: dongle is not up\n", __func__));
1504 /* finally, report dongle driver type */
1505 else if (dhd->pub.iswl)
1506 sprintf(info.driver, "wl");
1508 sprintf(info.driver, "xx");
1510 sprintf(info.version, "%lu", dhd->pub.drv_version);
1511 if (copy_to_user(uaddr, &info, sizeof(info)))
1513 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1514 (int)sizeof(drvname), drvname, info.driver));
1518 /* Get toe offload components from dongle */
1519 case ETHTOOL_GRXCSUM:
1520 case ETHTOOL_GTXCSUM:
1521 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1526 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1529 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1531 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1535 /* Set toe offload components in dongle */
1536 case ETHTOOL_SRXCSUM:
1537 case ETHTOOL_STXCSUM:
1538 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1541 /* Read the current settings, update and write back */
1542 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1547 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1549 if (edata.data != 0)
1550 toe_cmpnt |= csum_dir;
1552 toe_cmpnt &= ~csum_dir;
1554 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1558 /* If setting TX checksum mode, tell Linux the new mode */
1559 if (cmd == ETHTOOL_STXCSUM) {
1561 dhd->iflist[0]->net->features |=
1564 dhd->iflist[0]->net->features &=
1578 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1580 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1587 bool is_set_key_cmd;
1589 ifidx = dhd_net2idx(dhd, net);
1590 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1592 if (ifidx == DHD_BAD_IF)
1595 if (cmd == SIOCETHTOOL)
1596 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1598 if (cmd != SIOCDEVPRIVATE)
1601 memset(&ioc, 0, sizeof(ioc));
1603 /* Copy the ioc control structure part of ioctl request */
1604 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1609 /* Copy out any buffer passed */
1611 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1612 /* optimization for direct ioctl calls from kernel */
1614 if (segment_eq(get_fs(), KERNEL_DS)) {
1619 buf = kmalloc(buflen, GFP_ATOMIC);
1624 if (copy_from_user(buf, ioc.buf, buflen)) {
1631 /* To differentiate between wl and dhd read 4 more byes */
1632 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1633 sizeof(uint)) != 0)) {
1638 if (!capable(CAP_NET_ADMIN)) {
1643 /* check for local dhd ioctl and handle it */
1644 if (driver == DHD_IOCTL_MAGIC) {
1645 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1647 dhd->pub.bcmerror = bcmerror;
1651 /* send to dongle (must be up, and wl) */
1652 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1653 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1658 if (!dhd->pub.iswl) {
1663 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1664 * prevent M4 encryption.
1666 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1667 ((ioc.cmd == WLC_SET_VAR) &&
1668 !(strncmp("wsec_key", ioc.buf, 9))) ||
1669 ((ioc.cmd == WLC_SET_VAR) &&
1670 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1672 dhd_wait_pend8021x(net);
1675 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1678 if (!bcmerror && buf && ioc.buf) {
1679 if (copy_to_user(ioc.buf, buf, buflen))
1691 static int dhd_stop(struct net_device *net)
1693 #if !defined(IGNORE_ETH0_DOWN)
1694 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1696 DHD_TRACE(("%s: Enter\n", __func__));
1698 if (dhd->pub.up == 0)
1701 /* Set state and stop OS transmissions */
1703 netif_stop_queue(net);
1705 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1707 #endif /* !defined(IGNORE_ETH0_DOWN) */
1712 static int dhd_open(struct net_device *net)
1714 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1718 int ifidx = dhd_net2idx(dhd, net);
1721 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1723 if (ifidx == 0) { /* do it only for primary eth0 */
1725 /* try to bring up bus */
1726 ret = dhd_bus_start(&dhd->pub);
1728 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1731 atomic_set(&dhd->pend_8021x_cnt, 0);
1733 memcpy(net->dev_addr, dhd->pub.mac, ETH_ALEN);
1736 /* Get current TOE mode from dongle */
1737 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1738 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1739 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1741 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1744 /* Allow transmit calls */
1745 netif_start_queue(net);
1747 if (unlikely(wl_cfg80211_up())) {
1748 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1757 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1758 u8 *mac_addr, u32 flags, u8 bssidx)
1762 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1764 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1766 ifp = dhd->iflist[ifidx];
1768 ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC);
1770 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1775 memset(ifp, 0, sizeof(dhd_if_t));
1777 dhd->iflist[ifidx] = ifp;
1778 strlcpy(ifp->name, name, IFNAMSIZ);
1779 if (mac_addr != NULL)
1780 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1782 if (handle == NULL) {
1783 ifp->state = WLC_E_IF_ADD;
1785 ASSERT(dhd->sysioc_tsk);
1786 up(&dhd->sysioc_sem);
1788 ifp->net = (struct net_device *)handle;
1793 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1797 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1799 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1800 ifp = dhd->iflist[ifidx];
1802 DHD_ERROR(("%s: Null interface\n", __func__));
1806 ifp->state = WLC_E_IF_DEL;
1808 ASSERT(dhd->sysioc_tsk);
1809 up(&dhd->sysioc_sem);
1812 dhd_pub_t *dhd_attach(struct dhd_bus *bus, uint bus_hdrlen)
1814 dhd_info_t *dhd = NULL;
1815 struct net_device *net;
1817 DHD_TRACE(("%s: Enter\n", __func__));
1818 /* updates firmware nvram path if it was provided as module
1820 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1821 strcpy(fw_path, firmware_path);
1822 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1823 strcpy(nv_path, nvram_path);
1825 /* Allocate etherdev, including space for private structure */
1826 net = alloc_etherdev(sizeof(dhd));
1828 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1832 /* Allocate primary dhd_info */
1833 dhd = kzalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1835 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1840 * Save the dhd_info into the priv
1842 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1844 /* Set network interface name if it was provided as module parameter */
1845 if (iface_name[0]) {
1848 strncpy(net->name, iface_name, IFNAMSIZ);
1849 net->name[IFNAMSIZ - 1] = 0;
1850 len = strlen(net->name);
1851 ch = net->name[len - 1];
1852 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1853 strcat(net->name, "%d");
1856 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1860 net->netdev_ops = NULL;
1861 sema_init(&dhd->proto_sem, 1);
1862 /* Initialize other structure content */
1863 init_waitqueue_head(&dhd->ioctl_resp_wait);
1864 init_waitqueue_head(&dhd->ctrl_wait);
1866 /* Initialize the spinlocks */
1867 spin_lock_init(&dhd->sdlock);
1869 /* Link to info module */
1870 dhd->pub.info = dhd;
1872 /* Link to bus module */
1874 dhd->pub.hdrlen = bus_hdrlen;
1876 /* Attach and link in the protocol */
1877 if (dhd_prot_attach(&dhd->pub) != 0) {
1878 DHD_ERROR(("dhd_prot_attach failed\n"));
1882 /* Attach and link in the cfg80211 */
1883 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1884 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1887 if (!dhd_no_fw_req) {
1888 strcpy(fw_path, wl_cfg80211_get_fwname());
1889 strcpy(nv_path, wl_cfg80211_get_nvramname());
1892 /* Set up the watchdog timer */
1893 init_timer(&dhd->timer);
1894 dhd->timer.data = (unsigned long) dhd;
1895 dhd->timer.function = dhd_watchdog;
1897 /* Initialize thread based operation and lock */
1898 sema_init(&dhd->sdsem, 1);
1899 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1900 dhd->threads_only = true;
1902 dhd->threads_only = false;
1904 if (dhd_dpc_prio >= 0) {
1905 /* Initialize watchdog thread */
1906 sema_init(&dhd->watchdog_sem, 0);
1907 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1909 if (IS_ERR(dhd->watchdog_tsk)) {
1911 "dhd_watchdog thread failed to start\n");
1912 dhd->watchdog_tsk = NULL;
1915 dhd->watchdog_tsk = NULL;
1918 /* Set up the bottom half handler */
1919 if (dhd_dpc_prio >= 0) {
1920 /* Initialize DPC thread */
1921 sema_init(&dhd->dpc_sem, 0);
1922 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
1923 if (IS_ERR(dhd->dpc_tsk)) {
1925 "dhd_dpc thread failed to start\n");
1926 dhd->dpc_tsk = NULL;
1929 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
1930 dhd->dpc_tsk = NULL;
1934 sema_init(&dhd->sysioc_sem, 0);
1935 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
1937 if (IS_ERR(dhd->sysioc_tsk)) {
1939 "_dhd_sysioc thread failed to start\n");
1940 dhd->sysioc_tsk = NULL;
1943 dhd->sysioc_tsk = NULL;
1946 * Save the dhd_info into the priv
1948 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1950 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
1953 #if defined(CONFIG_PM_SLEEP)
1954 atomic_set(&dhd_mmc_suspend, false);
1955 #endif /* defined(CONFIG_PM_SLEEP) */
1956 /* && defined(DHD_GPL) */
1957 /* Init lock suspend to prevent kernel going to suspend */
1958 #ifdef CONFIG_HAS_EARLYSUSPEND
1959 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
1960 dhd->early_suspend.suspend = dhd_early_suspend;
1961 dhd->early_suspend.resume = dhd_late_resume;
1962 register_early_suspend(&dhd->early_suspend);
1971 dhd_detach(&dhd->pub);
1976 int dhd_bus_start(dhd_pub_t *dhdp)
1979 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1980 #ifdef EMBEDDED_PLATFORM
1981 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
1983 #endif /* EMBEDDED_PLATFORM */
1987 DHD_TRACE(("%s:\n", __func__));
1989 /* try to download image and nvram to the dongle */
1990 if (dhd->pub.busstate == DHD_BUS_DOWN) {
1991 if (!(dhd_bus_download_firmware(dhd->pub.bus,
1992 fw_path, nv_path))) {
1993 DHD_ERROR(("%s: dhd_bus_download_firmware failed. "
1994 "firmware = %s nvram = %s\n",
1995 __func__, fw_path, nv_path));
2000 /* Start the watchdog timer */
2001 dhd->pub.tickcnt = 0;
2002 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2004 /* Bring up the bus */
2005 ret = brcmf_sdbrcm_bus_init(&dhd->pub, true);
2007 DHD_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__,
2011 #if defined(OOB_INTR_ONLY)
2012 /* Host registration for OOB interrupt */
2013 if (brcmf_sdio_register_oob_intr(dhdp)) {
2014 del_timer_sync(&dhd->timer);
2015 dhd->wd_timer_valid = false;
2016 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2020 /* Enable oob at firmware */
2021 brcmf_sdbrcm_enable_oob_intr(dhd->pub.bus, true);
2022 #endif /* defined(OOB_INTR_ONLY) */
2024 /* If bus is not ready, can't come up */
2025 if (dhd->pub.busstate != DHD_BUS_DATA) {
2026 del_timer_sync(&dhd->timer);
2027 dhd->wd_timer_valid = false;
2028 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2031 #ifdef EMBEDDED_PLATFORM
2032 brcmu_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN,
2033 iovbuf, sizeof(iovbuf));
2034 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2035 memcpy(dhdp->eventmask, iovbuf, WL_EVENTING_MASK_LEN);
2037 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2038 setbit(dhdp->eventmask, WLC_E_PRUNE);
2039 setbit(dhdp->eventmask, WLC_E_AUTH);
2040 setbit(dhdp->eventmask, WLC_E_REASSOC);
2041 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2042 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2043 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2044 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2045 setbit(dhdp->eventmask, WLC_E_JOIN);
2046 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2047 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2048 setbit(dhdp->eventmask, WLC_E_LINK);
2049 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2050 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2051 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2052 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2053 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2054 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2056 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2057 #endif /* PNO_SUPPORT */
2059 /* enable dongle roaming event */
2061 dhdp->pktfilter_count = 1;
2062 /* Setup filter to allow only unicast */
2063 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2064 #endif /* EMBEDDED_PLATFORM */
2066 /* Bus is ready, do any protocol initialization */
2067 ret = dhd_prot_init(&dhd->pub);
2075 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2078 char buf[strlen(name) + 1 + cmd_len];
2079 int len = sizeof(buf);
2083 len = brcmu_mkiovar(name, cmd_buf, cmd_len, buf, len);
2085 memset(&ioc, 0, sizeof(ioc));
2087 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2092 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2093 if (!set && ret >= 0)
2094 memcpy(cmd_buf, buf, cmd_len);
2099 static struct net_device_ops dhd_ops_pri = {
2100 .ndo_open = dhd_open,
2101 .ndo_stop = dhd_stop,
2102 .ndo_get_stats = dhd_get_stats,
2103 .ndo_do_ioctl = dhd_ioctl_entry,
2104 .ndo_start_xmit = dhd_start_xmit,
2105 .ndo_set_mac_address = dhd_set_mac_address,
2106 .ndo_set_multicast_list = dhd_set_multicast_list
2109 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2111 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2112 struct net_device *net;
2113 u8 temp_addr[ETH_ALEN] = {
2114 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2116 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2118 ASSERT(dhd && dhd->iflist[ifidx]);
2120 net = dhd->iflist[ifidx]->net;
2123 ASSERT(!net->netdev_ops);
2124 net->netdev_ops = &dhd_ops_pri;
2127 * We have to use the primary MAC for virtual interfaces
2130 /* for virtual interfaces use the primary MAC */
2131 memcpy(temp_addr, dhd->pub.mac, ETH_ALEN);
2136 DHD_TRACE(("%s ACCESS POINT MAC:\n", __func__));
2137 /* ACCESSPOINT INTERFACE CASE */
2138 temp_addr[0] |= 0X02; /* set bit 2 ,
2139 - Locally Administered address */
2142 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2143 net->ethtool_ops = &dhd_ethtool_ops;
2145 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2147 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
2149 if (register_netdev(net) != 0) {
2150 DHD_ERROR(("%s: couldn't register the net device\n",
2155 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
2160 net->netdev_ops = NULL;
2164 void dhd_bus_detach(dhd_pub_t *dhdp)
2168 DHD_TRACE(("%s: Enter\n", __func__));
2171 dhd = (dhd_info_t *) dhdp->info;
2173 /* Stop the protocol module */
2174 dhd_prot_stop(&dhd->pub);
2176 /* Stop the bus module */
2177 brcmf_sdbrcm_bus_stop(dhd->pub.bus, true);
2178 #if defined(OOB_INTR_ONLY)
2179 brcmf_sdio_unregister_oob_intr();
2180 #endif /* defined(OOB_INTR_ONLY) */
2182 /* Clear the watchdog timer */
2183 del_timer_sync(&dhd->timer);
2184 dhd->wd_timer_valid = false;
2189 void dhd_detach(dhd_pub_t *dhdp)
2193 DHD_TRACE(("%s: Enter\n", __func__));
2196 dhd = (dhd_info_t *) dhdp->info;
2201 #if defined(CONFIG_HAS_EARLYSUSPEND)
2202 if (dhd->early_suspend.suspend)
2203 unregister_early_suspend(&dhd->early_suspend);
2204 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2206 for (i = 1; i < DHD_MAX_IFS; i++)
2210 ifp = dhd->iflist[0];
2212 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2214 unregister_netdev(ifp->net);
2217 if (dhd->watchdog_tsk) {
2218 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2219 kthread_stop(dhd->watchdog_tsk);
2220 dhd->watchdog_tsk = NULL;
2224 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2225 kthread_stop(dhd->dpc_tsk);
2226 dhd->dpc_tsk = NULL;
2228 tasklet_kill(&dhd->tasklet);
2230 if (dhd->sysioc_tsk) {
2231 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2232 kthread_stop(dhd->sysioc_tsk);
2233 dhd->sysioc_tsk = NULL;
2236 dhd_bus_detach(dhdp);
2239 dhd_prot_detach(dhdp);
2241 wl_cfg80211_detach();
2243 /* && defined(DHD_GPL) */
2244 free_netdev(ifp->net);
2251 static void __exit dhd_module_cleanup(void)
2253 DHD_TRACE(("%s: Enter\n", __func__));
2255 dhd_bus_unregister();
2256 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2259 /* Call customer gpio to turn off power with WL_REG_ON signal */
2260 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2263 static int __init dhd_module_init(void)
2267 DHD_TRACE(("%s: Enter\n", __func__));
2269 /* Sanity check on the module parameters */
2271 /* Both watchdog and DPC as tasklets are ok */
2272 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2275 /* If both watchdog and DPC are threads, TX must be deferred */
2276 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2280 DHD_ERROR(("Invalid module parameters.\n"));
2283 /* Call customer gpio to turn on power with WL_REG_ON signal */
2284 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2286 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2287 sema_init(&wifi_control_sem, 0);
2289 error = wifi_add_dev();
2291 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2295 /* Waiting callback after platform_driver_register is done or
2297 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2298 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2304 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2306 error = dhd_bus_register();
2309 DHD_ERROR(("%s: dhd_bus_register failed\n", __func__));
2315 /* turn off power and exit */
2316 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2320 module_init(dhd_module_init);
2321 module_exit(dhd_module_cleanup);
2324 * OS specific functions required to implement DHD driver in OS independent way
2326 int dhd_os_proto_block(dhd_pub_t *pub)
2328 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2331 down(&dhd->proto_sem);
2337 int dhd_os_proto_unblock(dhd_pub_t *pub)
2339 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2342 up(&dhd->proto_sem);
2349 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2351 return (unsigned int)dhd_ioctl_timeout_msec;
2354 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2356 dhd_ioctl_timeout_msec = (int)timeout_msec;
2359 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2361 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2362 DECLARE_WAITQUEUE(wait, current);
2363 int timeout = dhd_ioctl_timeout_msec;
2365 /* Convert timeout in millsecond to jiffies */
2366 timeout = timeout * HZ / 1000;
2368 /* Wait until control frame is available */
2369 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2370 set_current_state(TASK_INTERRUPTIBLE);
2372 while (!(*condition) && (!signal_pending(current) && timeout))
2373 timeout = schedule_timeout(timeout);
2375 if (signal_pending(current))
2378 set_current_state(TASK_RUNNING);
2379 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2384 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2386 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2388 if (waitqueue_active(&dhd->ioctl_resp_wait))
2389 wake_up_interruptible(&dhd->ioctl_resp_wait);
2394 void dhd_os_wd_timer(void *bus, uint wdtick)
2396 dhd_pub_t *pub = bus;
2397 static uint save_dhd_watchdog_ms;
2398 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2400 /* don't start the wd until fw is loaded */
2401 if (pub->busstate == DHD_BUS_DOWN)
2404 /* Totally stop the timer */
2405 if (!wdtick && dhd->wd_timer_valid == true) {
2406 del_timer_sync(&dhd->timer);
2407 dhd->wd_timer_valid = false;
2408 save_dhd_watchdog_ms = wdtick;
2413 dhd_watchdog_ms = (uint) wdtick;
2415 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2417 if (dhd->wd_timer_valid == true)
2418 /* Stop timer and restart at new value */
2419 del_timer_sync(&dhd->timer);
2421 /* Create timer again when watchdog period is
2422 dynamically changed or in the first instance
2424 dhd->timer.expires =
2425 jiffies + dhd_watchdog_ms * HZ / 1000;
2426 add_timer(&dhd->timer);
2429 /* Re arm the timer, at last watchdog period */
2430 mod_timer(&dhd->timer,
2431 jiffies + dhd_watchdog_ms * HZ / 1000);
2434 dhd->wd_timer_valid = true;
2435 save_dhd_watchdog_ms = wdtick;
2439 void *dhd_os_open_image(char *filename)
2444 return wl_cfg80211_request_fw(filename);
2446 fp = filp_open(filename, O_RDONLY, 0);
2448 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2450 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2459 int dhd_os_get_image_block(char *buf, int len, void *image)
2461 struct file *fp = (struct file *)image;
2465 return wl_cfg80211_read_fw(buf, len);
2470 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2477 void dhd_os_close_image(void *image)
2480 return wl_cfg80211_release_fw();
2482 filp_close((struct file *)image, NULL);
2485 void dhd_os_sdlock(dhd_pub_t *pub)
2489 dhd = (dhd_info_t *) (pub->info);
2491 if (dhd->threads_only)
2494 spin_lock_bh(&dhd->sdlock);
2497 void dhd_os_sdunlock(dhd_pub_t *pub)
2501 dhd = (dhd_info_t *) (pub->info);
2503 if (dhd->threads_only)
2506 spin_unlock_bh(&dhd->sdlock);
2510 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2511 wl_event_msg_t *event, void **data)
2515 ASSERT(dhd != NULL);
2517 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2521 ASSERT(dhd->iflist[*ifidx] != NULL);
2522 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2523 if (dhd->iflist[*ifidx]->net)
2524 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event, *data);
2529 /* send up locally generated event */
2530 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2532 switch (be32_to_cpu(event->event_type)) {
2538 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2540 struct dhd_info *dhdinfo = dhd->info;
2541 dhd_os_sdunlock(dhd);
2542 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2543 (*lockvar == false), HZ * 2);
2548 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2550 struct dhd_info *dhdinfo = dhd->info;
2551 if (waitqueue_active(&dhdinfo->ctrl_wait))
2552 wake_up_interruptible(&dhdinfo->ctrl_wait);
2556 int dhd_dev_reset(struct net_device *dev, u8 flag)
2558 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2560 /* Turning off watchdog */
2562 dhd_os_wd_timer(&dhd->pub, 0);
2564 dhd_bus_devreset(&dhd->pub, flag);
2566 /* Turning on watchdog back */
2568 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2569 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2574 int net_os_set_suspend_disable(struct net_device *dev, int val)
2576 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2580 ret = dhd->pub.suspend_disable_flag;
2581 dhd->pub.suspend_disable_flag = val;
2586 int net_os_set_suspend(struct net_device *dev, int val)
2589 #if defined(CONFIG_HAS_EARLYSUSPEND)
2590 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2593 dhd_os_proto_block(&dhd->pub);
2594 ret = dhd_set_suspend(val, &dhd->pub);
2595 dhd_os_proto_unblock(&dhd->pub);
2597 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2601 int net_os_set_dtim_skip(struct net_device *dev, int val)
2603 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2606 dhd->pub.dtim_skip = val;
2611 int net_os_set_packet_filter(struct net_device *dev, int val)
2613 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2616 /* Packet filtering is set only if we still in early-suspend and
2617 * we need either to turn it ON or turn it OFF
2618 * We can always turn it OFF in case of early-suspend, but we turn it
2619 * back ON only if suspend_disable_flag was not set
2621 if (dhd && dhd->pub.up) {
2622 dhd_os_proto_block(&dhd->pub);
2623 if (dhd->pub.in_suspend) {
2624 if (!val || (val && !dhd->pub.suspend_disable_flag))
2625 dhd_set_packet_filter(val, &dhd->pub);
2627 dhd_os_proto_unblock(&dhd->pub);
2632 void dhd_dev_init_ioctl(struct net_device *dev)
2634 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2636 dhd_preinit_ioctls(&dhd->pub);
2640 /* Linux wrapper to call common dhd_pno_clean */
2641 int dhd_dev_pno_reset(struct net_device *dev)
2643 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2645 return dhd_pno_clean(&dhd->pub);
2648 /* Linux wrapper to call common dhd_pno_enable */
2649 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2651 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2653 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2656 /* Linux wrapper to call common dhd_pno_set */
2658 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2659 unsigned char scan_fr)
2661 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2663 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2666 /* Linux wrapper to get pno status */
2667 int dhd_dev_get_pno_status(struct net_device *dev)
2669 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2671 return dhd_pno_get_status(&dhd->pub);
2674 #endif /* PNO_SUPPORT */
2676 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2678 return atomic_read(&dhd->pend_8021x_cnt);
2681 #define MAX_WAIT_FOR_8021X_TX 10
2683 int dhd_wait_pend8021x(struct net_device *dev)
2685 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2686 int timeout = 10 * HZ / 1000;
2687 int ntimes = MAX_WAIT_FOR_8021X_TX;
2688 int pend = dhd_get_pend_8021x_cnt(dhd);
2690 while (ntimes && pend) {
2692 set_current_state(TASK_INTERRUPTIBLE);
2693 schedule_timeout(timeout);
2694 set_current_state(TASK_RUNNING);
2697 pend = dhd_get_pend_8021x_cnt(dhd);
2702 void wl_os_wd_timer(struct net_device *ndev, uint wdtick)
2704 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(ndev);
2706 dhd_os_wd_timer(&dhd->pub, wdtick);
2710 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2714 mm_segment_t old_fs;
2717 /* change to KERNEL_DS address limit */
2721 /* open file to write */
2722 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2724 DHD_ERROR(("%s: open file error\n", __func__));
2729 /* Write buf to file */
2730 fp->f_op->write(fp, buf, size, &pos);
2733 /* free buf before return */
2735 /* close file before return */
2737 filp_close(fp, current->files);
2738 /* restore previous address limit */
2743 #endif /* DHD_DEBUG */
2746 void osl_assert(char *exp, char *file, int line)
2751 basename = strrchr(file, '/');
2759 snprintf(tempbuf, 256,
2760 "assertion \"%s\" failed: file \"%s\", line %d\n", exp,
2764 * Print assert message and give it time to
2765 * be written to /var/log/messages
2767 if (!in_interrupt()) {
2768 const int delay = 3;
2769 printk(KERN_ERR "%s", tempbuf);
2770 printk(KERN_ERR "panic in %d seconds\n", delay);
2771 set_current_state(TASK_INTERRUPTIBLE);
2772 schedule_timeout(delay * HZ);
2775 switch (g_assert_type) {
2777 panic(KERN_ERR "%s", tempbuf);
2780 printk(KERN_ERR "%s", tempbuf);
2784 printk(KERN_ERR "%s", tempbuf);
2790 #endif /* defined(BCMDBG) */