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>
35 #if defined(CONFIG_HAS_EARLYSUSPEND)
36 #include <linux/earlysuspend.h>
39 #include <brcmu_utils.h>
40 #include <brcmu_wifi.h>
42 #include "dngl_stats.h"
45 #include "dhd_proto.h"
47 #include "wl_cfg80211.h"
49 #define EPI_VERSION_STR "4.218.248.5"
50 #define ETH_P_BRCM 0x886c
52 /* Global ASSERT type flag */
55 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
56 #include <linux/wifi_tiwlan.h>
58 struct semaphore wifi_control_sem;
60 struct dhd_bus *g_bus;
62 static struct wifi_platform_data *wifi_control_data;
63 static struct resource *wifi_irqres;
65 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
68 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
69 return (int)wifi_irqres->start;
71 #ifdef CUSTOM_OOB_GPIO_NUM
72 return CUSTOM_OOB_GPIO_NUM;
78 int wifi_set_carddetect(int on)
80 printk(KERN_ERR "%s = %d\n", __func__, on);
81 if (wifi_control_data && wifi_control_data->set_carddetect)
82 wifi_control_data->set_carddetect(on);
86 int wifi_set_power(int on, unsigned long msec)
88 printk(KERN_ERR "%s = %d\n", __func__, on);
89 if (wifi_control_data && wifi_control_data->set_power)
90 wifi_control_data->set_power(on);
96 int wifi_set_reset(int on, unsigned long msec)
98 printk(KERN_ERR "%s = %d\n", __func__, on);
99 if (wifi_control_data && wifi_control_data->set_reset)
100 wifi_control_data->set_reset(on);
106 static int wifi_probe(struct platform_device *pdev)
108 struct wifi_platform_data *wifi_ctrl =
109 (struct wifi_platform_data *)(pdev->dev.platform_data);
111 printk(KERN_ERR "## %s\n", __func__);
113 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
115 wifi_control_data = wifi_ctrl;
117 wifi_set_power(1, 0); /* Power On */
118 wifi_set_carddetect(1); /* CardDetect (0->1) */
120 up(&wifi_control_sem);
124 static int wifi_remove(struct platform_device *pdev)
126 struct wifi_platform_data *wifi_ctrl =
127 (struct wifi_platform_data *)(pdev->dev.platform_data);
129 printk(KERN_ERR "## %s\n", __func__);
130 wifi_control_data = wifi_ctrl;
132 wifi_set_carddetect(0); /* CardDetect (1->0) */
133 wifi_set_power(0, 0); /* Power Off */
135 up(&wifi_control_sem);
139 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
141 DHD_TRACE(("##> %s\n", __func__));
145 static int wifi_resume(struct platform_device *pdev)
147 DHD_TRACE(("##> %s\n", __func__));
151 static struct platform_driver wifi_device = {
153 .remove = wifi_remove,
154 .suspend = wifi_suspend,
155 .resume = wifi_resume,
157 .name = KBUILD_MODNAME,
161 int wifi_add_dev(void)
163 DHD_TRACE(("## Calling platform_driver_register\n"));
164 return platform_driver_register(&wifi_device);
167 void wifi_del_dev(void)
169 DHD_TRACE(("## Unregister platform_driver_register\n"));
170 platform_driver_unregister(&wifi_device);
172 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
174 #if defined(CONFIG_PM_SLEEP)
175 #include <linux/suspend.h>
176 atomic_t dhd_mmc_suspend;
177 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
178 #endif /* defined(CONFIG_PM_SLEEP) */
180 #if defined(OOB_INTR_ONLY)
181 extern void brcmf_sdbrcm_enable_oob_intr(struct dhd_bus *bus, bool enable);
182 #endif /* defined(OOB_INTR_ONLY) */
184 MODULE_AUTHOR("Broadcom Corporation");
185 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
186 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
187 MODULE_LICENSE("Dual BSD/GPL");
190 /* Interface control information */
191 typedef struct dhd_if {
192 struct dhd_info *info; /* back pointer to dhd_info */
193 /* OS/stack specifics */
194 struct net_device *net;
195 struct net_device_stats stats;
196 int idx; /* iface idx in dongle */
197 int state; /* interface state */
198 uint subunit; /* subunit */
199 u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
200 bool attached; /* Delayed attachment when unset */
201 bool txflowcontrol; /* Per interface flow control indicator */
202 char name[IFNAMSIZ]; /* linux interface name */
205 /* Local private structure (extension of pub) */
206 typedef struct dhd_info {
209 /* OS/stack specifics */
210 dhd_if_t *iflist[DHD_MAX_IFS];
212 struct semaphore proto_sem;
213 wait_queue_head_t ioctl_resp_wait;
214 struct timer_list timer;
216 struct tasklet_struct tasklet;
218 /* Thread based operation */
220 struct semaphore sdsem;
221 struct task_struct *watchdog_tsk;
222 struct semaphore watchdog_sem;
223 struct task_struct *dpc_tsk;
224 struct semaphore dpc_sem;
226 /* Thread to issue ioctl for multicast */
227 struct task_struct *sysioc_tsk;
228 struct semaphore sysioc_sem;
231 u8 macvalue[ETH_ALEN];
232 wait_queue_head_t ctrl_wait;
233 atomic_t pend_8021x_cnt;
235 #ifdef CONFIG_HAS_EARLYSUSPEND
236 struct early_suspend early_suspend;
237 #endif /* CONFIG_HAS_EARLYSUSPEND */
240 /* Definitions to provide path to the firmware and nvram
241 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
243 char firmware_path[MOD_PARAM_PATHLEN];
244 char nvram_path[MOD_PARAM_PATHLEN];
246 /* load firmware and/or nvram values from the filesystem */
247 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
248 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
250 /* No firmware required */
252 module_param(dhd_no_fw_req, bool, 0);
255 module_param(brcmf_msg_level, int, 0);
257 /* Spawn a thread for system ioctls (set mac, set mcast) */
258 uint dhd_sysioc = true;
259 module_param(dhd_sysioc, uint, 0);
261 /* Watchdog interval */
262 uint brcmf_watchdog_ms = 10;
263 module_param(brcmf_watchdog_ms, uint, 0);
266 /* Console poll interval */
267 uint brcmf_console_ms;
268 module_param(brcmf_console_ms, uint, 0);
269 #endif /* DHD_DEBUG */
271 /* ARP offload agent mode : Enable ARP Host Auto-Reply
272 and ARP Peer Auto-Reply */
273 uint brcmf_arp_mode = 0xb;
274 module_param(brcmf_arp_mode, uint, 0);
276 /* ARP offload enable */
277 uint brcmf_arp_enable = true;
278 module_param(brcmf_arp_enable, uint, 0);
280 /* Global Pkt filter enable control */
281 uint brcmf_pkt_filter_enable = true;
282 module_param(brcmf_pkt_filter_enable, uint, 0);
284 /* Pkt filter init setup */
285 uint brcmf_pkt_filter_init;
286 module_param(brcmf_pkt_filter_init, uint, 0);
288 /* Pkt filter mode control */
289 uint brcmf_master_mode = true;
290 module_param(brcmf_master_mode, uint, 1);
292 /* Watchdog thread priority, -1 to use kernel timer */
293 int dhd_watchdog_prio = 97;
294 module_param(dhd_watchdog_prio, int, 0);
296 /* DPC thread priority, -1 to use tasklet */
297 int dhd_dpc_prio = 98;
298 module_param(dhd_dpc_prio, int, 0);
300 /* DPC thread priority, -1 to use tasklet */
301 extern int dhd_dongle_memsize;
302 module_param(dhd_dongle_memsize, int, 0);
304 /* Contorl fw roaming */
311 /* Control radio state */
312 uint brcmf_radio_up = 1;
314 /* Network inteface name */
315 char iface_name[IFNAMSIZ] = "wlan";
316 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
318 /* The following are specific to the SDIO dongle */
320 /* IOCTL response timeout */
321 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
323 /* Idle timeout for backplane clock */
324 int brcmf_idletime = BRCMF_IDLETIME_TICKS;
325 module_param(brcmf_idletime, int, 0);
329 module_param(brcmf_poll, uint, 0);
332 uint brcmf_intr = true;
333 module_param(brcmf_intr, uint, 0);
335 /* SDIO Drive Strength (in milliamps) */
336 uint brcmf_sdiod_drive_strength = 6;
337 module_param(brcmf_sdiod_drive_strength, uint, 0);
340 extern uint dhd_txbound;
341 extern uint dhd_rxbound;
342 module_param(dhd_txbound, uint, 0);
343 module_param(dhd_rxbound, uint, 0);
345 /* Deferred transmits */
346 extern uint dhd_deferred_tx;
347 module_param(dhd_deferred_tx, uint, 0);
350 /* Echo packet generator (pkts/s) */
352 module_param(brcmf_pktgen, uint, 0);
354 /* Echo packet len (0 => sawtooth, max 2040) */
355 uint brcmf_pktgen_len;
356 module_param(brcmf_pktgen_len, uint, 0);
359 /* Version string to report */
361 #define DHD_COMPILED "\nCompiled in " SRCBASE
366 static void dhd_dpc(unsigned long data);
368 extern int dhd_wait_pend8021x(struct net_device *dev);
371 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
372 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
375 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
376 brcmf_event_msg_t *event_ptr, void **data_ptr);
378 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
380 #ifdef PKT_FILTER_SUPPORT
381 DHD_TRACE(("%s: %d\n", __func__, value));
382 /* 1 - Enable packet filter, only allow unicast packet to send up */
383 /* 0 - Disable packet filter */
384 if (brcmf_pkt_filter_enable) {
387 for (i = 0; i < dhd->pktfilter_count; i++) {
388 brcmf_c_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
389 brcmf_c_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
390 value, brcmf_master_mode);
396 #if defined(CONFIG_HAS_EARLYSUSPEND)
397 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
399 int power_mode = PM_MAX;
400 /* wl_pkt_filter_enable_t enable_parm; */
405 #endif /* CUSTOMER_HW2 */
407 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
408 __func__, value, dhd->in_suspend));
410 if (dhd && dhd->up) {
411 if (value && dhd->in_suspend) {
413 /* Kernel suspended */
414 DHD_TRACE(("%s: force extra Suspend setting\n",
417 brcmf_proto_cdc_set_ioctl(dhd, 0, BRCMF_C_SET_PM,
421 /* Enable packet filter, only allow unicast
423 dhd_set_packet_filter(1, dhd);
425 /* if dtim skip setup as default force it
426 * to wake each third dtim
427 * for better power saving.
428 * Note that side effect is chance to miss BC/MC
431 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
434 bcn_li_dtim = dhd->dtim_skip;
435 brcmu_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
436 4, iovbuf, sizeof(iovbuf));
437 brcmf_proto_cdc_set_ioctl(dhd, 0, BRCMF_C_SET_VAR,
438 iovbuf, sizeof(iovbuf));
440 /* Disable build-in roaming to allowed \
441 * supplicant to take of romaing
443 brcmu_mkiovar("roam_off", (char *)&roamvar, 4,
444 iovbuf, sizeof(iovbuf));
445 brcmf_proto_cdc_set_ioctl(dhd, 0, BRCMF_C_SET_VAR,
446 iovbuf, sizeof(iovbuf));
447 #endif /* CUSTOMER_HW2 */
451 DHD_TRACE(("%s: Remove extra suspend setting\n",
454 power_mode = PM_FAST;
455 brcmf_proto_cdc_set_ioctl(dhd, 0, BRCMF_C_SET_PM,
459 /* disable pkt filter */
460 dhd_set_packet_filter(0, dhd);
462 /* restore pre-suspend setting for dtim_skip */
463 brcmu_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
464 4, iovbuf, sizeof(iovbuf));
466 brcmf_proto_cdc_set_ioctl(dhd, 0, BRCMF_C_SET_VAR,
467 iovbuf, sizeof(iovbuf));
470 brcmu_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
472 brcmf_proto_cdc_set_ioctl(dhd, 0, BRCMF_C_SET_VAR,
473 iovbuf, sizeof(iovbuf));
474 #endif /* CUSTOMER_HW2 */
481 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
483 dhd_pub_t *dhdp = &dhd->pub;
485 brcmf_os_proto_block(dhdp);
486 /* Set flag when early suspend was called */
487 dhdp->in_suspend = val;
488 if (!dhdp->suspend_disable_flag)
489 dhd_set_suspend(val, dhdp);
490 brcmf_os_proto_unblock(dhdp);
493 static void dhd_early_suspend(struct early_suspend *h)
495 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
497 DHD_TRACE(("%s: enter\n", __func__));
500 dhd_suspend_resume_helper(dhd, 1);
504 static void dhd_late_resume(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, 0);
513 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
516 * Generalized timeout mechanism. Uses spin sleep with exponential
518 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
520 * brcmf_timeout_start(&tmo, usec);
521 * while (!brcmf_timeout_expired(&tmo))
522 * if (poll_something())
524 * if (brcmf_timeout_expired(&tmo))
528 void brcmf_timeout_start(dhd_timeout_t *tmo, uint usec)
533 tmo->tick = 1000000 / HZ;
536 int brcmf_timeout_expired(dhd_timeout_t *tmo)
538 /* Does nothing the first call */
539 if (tmo->increment == 0) {
544 if (tmo->elapsed >= tmo->limit)
547 /* Add the delay that's about to take place */
548 tmo->elapsed += tmo->increment;
550 if (tmo->increment < tmo->tick) {
551 udelay(tmo->increment);
553 if (tmo->increment > tmo->tick)
554 tmo->increment = tmo->tick;
556 wait_queue_head_t delay_wait;
557 DECLARE_WAITQUEUE(wait, current);
559 init_waitqueue_head(&delay_wait);
560 add_wait_queue(&delay_wait, &wait);
561 set_current_state(TASK_INTERRUPTIBLE);
563 pending = signal_pending(current);
564 remove_wait_queue(&delay_wait, &wait);
565 set_current_state(TASK_RUNNING);
567 return 1; /* Interrupted */
573 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
578 while (i < DHD_MAX_IFS) {
579 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
587 int brcmf_ifname2idx(dhd_info_t *dhd, char *name)
593 if (name == NULL || *name == '\0')
598 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
601 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
603 return i; /* default - the primary interface */
606 char *brcmf_ifname(dhd_pub_t *dhdp, int ifidx)
608 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
612 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
613 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
617 if (dhd->iflist[ifidx] == NULL) {
618 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
622 if (dhd->iflist[ifidx]->net)
623 return dhd->iflist[ifidx]->net->name;
628 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
630 struct net_device *dev;
631 struct netdev_hw_addr *ha;
639 ASSERT(dhd && dhd->iflist[ifidx]);
640 dev = dhd->iflist[ifidx]->net;
641 cnt = netdev_mc_count(dev);
643 /* Determine initial value of allmulti flag */
644 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
646 /* Send down the multicast list first. */
648 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
649 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
651 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
652 brcmf_ifname(&dhd->pub, ifidx), cnt));
656 strcpy(bufp, "mcast_list");
657 bufp += strlen("mcast_list") + 1;
659 cnt = cpu_to_le32(cnt);
660 memcpy(bufp, &cnt, sizeof(cnt));
663 netdev_for_each_mc_addr(ha, dev) {
666 memcpy(bufp, ha->addr, ETH_ALEN);
671 memset(&ioc, 0, sizeof(ioc));
672 ioc.cmd = BRCMF_C_SET_VAR;
677 ret = brcmf_proto_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
679 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
680 brcmf_ifname(&dhd->pub, ifidx), cnt));
681 allmulti = cnt ? true : allmulti;
686 /* Now send the allmulti setting. This is based on the setting in the
687 * net_device flags, but might be modified above to be turned on if we
688 * were trying to set some addresses and dongle rejected it...
691 buflen = sizeof("allmulti") + sizeof(allmulti);
692 buf = kmalloc(buflen, GFP_ATOMIC);
694 DHD_ERROR(("%s: out of memory for allmulti\n",
695 brcmf_ifname(&dhd->pub, ifidx)));
698 allmulti = cpu_to_le32(allmulti);
701 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
702 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
703 "buflen %u\n", brcmf_ifname(&dhd->pub, ifidx),
704 (int)sizeof(allmulti), buflen));
709 memset(&ioc, 0, sizeof(ioc));
710 ioc.cmd = BRCMF_C_SET_VAR;
715 ret = brcmf_proto_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
717 DHD_ERROR(("%s: set allmulti %d failed\n",
718 brcmf_ifname(&dhd->pub, ifidx),
719 le32_to_cpu(allmulti)));
724 /* Finally, pick up the PROMISC flag as well, like the NIC
727 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
728 allmulti = cpu_to_le32(allmulti);
730 memset(&ioc, 0, sizeof(ioc));
731 ioc.cmd = BRCMF_C_SET_PROMISC;
733 ioc.len = sizeof(allmulti);
736 ret = brcmf_proto_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
738 DHD_ERROR(("%s: set promisc %d failed\n",
739 brcmf_ifname(&dhd->pub, ifidx),
740 le32_to_cpu(allmulti)));
745 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, u8 *addr)
751 DHD_TRACE(("%s enter\n", __func__));
753 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
754 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
755 brcmf_ifname(&dhd->pub, ifidx)));
758 memset(&ioc, 0, sizeof(ioc));
759 ioc.cmd = BRCMF_C_SET_VAR;
764 ret = brcmf_proto_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
766 DHD_ERROR(("%s: set cur_etheraddr failed\n",
767 brcmf_ifname(&dhd->pub, ifidx)));
769 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
776 extern struct net_device *ap_net_dev;
779 static void dhd_op_if(dhd_if_t *ifp)
782 int ret = 0, err = 0;
784 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
788 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
790 switch (ifp->state) {
793 * Delete the existing interface before overwriting it
794 * in case we missed the BRCMF_E_IF_DEL event.
796 if (ifp->net != NULL) {
797 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
798 "try free & unregister\n",
799 __func__, ifp->net->name));
800 netif_stop_queue(ifp->net);
801 unregister_netdev(ifp->net);
802 free_netdev(ifp->net);
804 /* Allocate etherdev, including space for private structure */
805 ifp->net = alloc_etherdev(sizeof(dhd));
807 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
811 strcpy(ifp->net->name, ifp->name);
812 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
813 err = brcmf_net_attach(&dhd->pub, ifp->idx);
815 DHD_ERROR(("%s: dhd_net_attach failed, "
821 /* semaphore that the soft AP CODE
823 extern struct semaphore ap_eth_sema;
825 /* save ptr to wl0.1 netdev for use
827 ap_net_dev = ifp->net;
828 /* signal to the SOFTAP 'sleeper' thread,
832 DHD_TRACE(("\n ==== pid:%x, net_device for "
833 "if:%s created ===\n\n",
834 current->pid, ifp->net->name));
840 if (ifp->net != NULL) {
841 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
843 netif_stop_queue(ifp->net);
844 unregister_netdev(ifp->net);
845 ret = DHD_DEL_IF; /* Make sure the free_netdev()
850 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
857 free_netdev(ifp->net);
859 dhd->iflist[ifp->idx] = NULL;
862 if (ifp->net == ap_net_dev)
863 ap_net_dev = NULL; /* NULL SOFTAP global
869 static int _dhd_sysioc_thread(void *data)
871 dhd_info_t *dhd = (dhd_info_t *) data;
877 allow_signal(SIGTERM);
879 while (down_interruptible(&dhd->sysioc_sem) == 0) {
880 if (kthread_should_stop())
882 for (i = 0; i < DHD_MAX_IFS; i++) {
883 if (dhd->iflist[i]) {
885 in_ap = (ap_net_dev != NULL);
887 if (dhd->iflist[i]->state)
888 dhd_op_if(dhd->iflist[i]);
890 if (dhd->iflist[i] == NULL) {
891 DHD_TRACE(("\n\n %s: interface %d "
892 "removed!\n", __func__, i));
896 if (in_ap && dhd->set_macaddress) {
897 DHD_TRACE(("attempt to set MAC for %s "
898 "in AP Mode," "blocked.\n",
899 dhd->iflist[i]->net->name));
900 dhd->set_macaddress = false;
904 if (in_ap && dhd->set_multicast) {
905 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked.\n",
906 dhd->iflist[i]->net->name));
907 dhd->set_multicast = false;
911 if (dhd->set_multicast) {
912 dhd->set_multicast = false;
913 _dhd_set_multicast_list(dhd, i);
915 if (dhd->set_macaddress) {
916 dhd->set_macaddress = false;
917 _dhd_set_mac_address(dhd, i,
926 static int dhd_set_mac_address(struct net_device *dev, void *addr)
930 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
931 struct sockaddr *sa = (struct sockaddr *)addr;
934 ifidx = dhd_net2idx(dhd, dev);
935 if (ifidx == DHD_BAD_IF)
938 ASSERT(dhd->sysioc_tsk);
939 memcpy(&dhd->macvalue, sa->sa_data, ETH_ALEN);
940 dhd->set_macaddress = true;
941 up(&dhd->sysioc_sem);
946 static void dhd_set_multicast_list(struct net_device *dev)
948 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
951 ifidx = dhd_net2idx(dhd, dev);
952 if (ifidx == DHD_BAD_IF)
955 ASSERT(dhd->sysioc_tsk);
956 dhd->set_multicast = true;
957 up(&dhd->sysioc_sem);
960 int brcmf_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf)
963 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
966 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
969 /* Update multicast statistic */
970 if (pktbuf->len >= ETH_ALEN) {
971 u8 *pktdata = (u8 *) (pktbuf->data);
972 struct ethhdr *eh = (struct ethhdr *)pktdata;
974 if (is_multicast_ether_addr(eh->h_dest))
975 dhdp->tx_multicast++;
976 if (ntohs(eh->h_proto) == ETH_P_PAE)
977 atomic_inc(&dhd->pend_8021x_cnt);
980 /* If the protocol uses a data header, apply it */
981 brcmf_proto_hdrpush(dhdp, ifidx, pktbuf);
983 /* Use bus module to send data frame */
985 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
987 ret = brcmf_sdbrcm_bus_txdata(dhdp->bus, pktbuf);
994 osl_pkt_frmnative(struct sk_buff *skb)
998 #define PKTFRMNATIVE(osh, skb) \
999 osl_pkt_frmnative((struct sk_buff *)(skb))
1001 static inline struct sk_buff *
1002 osl_pkt_tonative(void *pkt)
1004 return (struct sk_buff *)pkt;
1006 #define PKTTONATIVE(osh, pkt) \
1007 osl_pkt_tonative((pkt))
1009 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1013 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1016 DHD_TRACE(("%s: Enter\n", __func__));
1018 /* Reject if down */
1019 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1020 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1021 __func__, dhd->pub.up, dhd->pub.busstate));
1022 netif_stop_queue(net);
1026 ifidx = dhd_net2idx(dhd, net);
1027 if (ifidx == DHD_BAD_IF) {
1028 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1029 netif_stop_queue(net);
1033 /* Make sure there's enough room for any header */
1034 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1035 struct sk_buff *skb2;
1037 DHD_INFO(("%s: insufficient headroom\n",
1038 brcmf_ifname(&dhd->pub, ifidx)));
1039 dhd->pub.tx_realloc++;
1040 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1044 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1045 brcmf_ifname(&dhd->pub, ifidx)));
1051 /* Convert to packet */
1052 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1054 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1055 brcmf_ifname(&dhd->pub, ifidx)));
1056 dev_kfree_skb_any(skb);
1061 ret = brcmf_sendpkt(&dhd->pub, ifidx, pktbuf);
1065 dhd->pub.dstats.tx_dropped++;
1067 dhd->pub.tx_packets++;
1069 /* Return ok: we always eat the packet */
1073 void brcmf_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1075 struct net_device *net;
1076 dhd_info_t *dhd = dhdp->info;
1078 DHD_TRACE(("%s: Enter\n", __func__));
1080 dhdp->txoff = state;
1081 ASSERT(dhd && dhd->iflist[ifidx]);
1082 net = dhd->iflist[ifidx]->net;
1084 netif_stop_queue(net);
1086 netif_wake_queue(net);
1089 void brcmf_rx_frame(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf,
1092 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1093 struct sk_buff *skb;
1097 struct sk_buff *pnext, *save_pktbuf;
1100 brcmf_event_msg_t event;
1102 DHD_TRACE(("%s: Enter\n", __func__));
1104 save_pktbuf = pktbuf;
1106 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1108 pnext = pktbuf->next;
1109 pktbuf->next = NULL;
1111 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1113 /* Get the protocol, maintain skb around eth_type_trans()
1114 * The main reason for this hack is for the limitation of
1115 * Linux 2.4 where 'eth_type_trans' uses the
1116 * 'net->hard_header_len'
1117 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1118 * coping of the packet coming from the network stack to add
1119 * BDC, Hardware header etc, during network interface
1121 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1123 * for BDC, Hardware header etc. and not just the ETH_HLEN
1128 ifp = dhd->iflist[ifidx];
1130 ifp = dhd->iflist[0];
1133 skb->dev = ifp->net;
1134 skb->protocol = eth_type_trans(skb, skb->dev);
1136 if (skb->pkt_type == PACKET_MULTICAST)
1137 dhd->pub.rx_multicast++;
1142 /* Strip header, count, deliver upward */
1143 skb_pull(skb, ETH_HLEN);
1145 /* Process special event packets and then discard them */
1146 if (ntohs(skb->protocol) == ETH_P_BRCM)
1147 dhd_wl_host_event(dhd, &ifidx,
1148 skb_mac_header(skb),
1151 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1152 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1153 ifp = dhd->iflist[ifidx];
1156 ifp->net->last_rx = jiffies;
1158 dhdp->dstats.rx_bytes += skb->len;
1159 dhdp->rx_packets++; /* Local count */
1161 if (in_interrupt()) {
1164 /* If the receive is not processed inside an ISR,
1165 * the softirqd must be woken explicitly to service
1166 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1167 * by netif_rx_ni(), but in earlier kernels, we need
1168 * to do it manually.
1175 void brcmf_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1177 /* Linux version has nothing to do */
1181 void brcmf_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success)
1184 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1188 brcmf_proto_hdrpull(dhdp, &ifidx, txp);
1190 eh = (struct ethhdr *)(txp->data);
1191 type = ntohs(eh->h_proto);
1193 if (type == ETH_P_PAE)
1194 atomic_dec(&dhd->pend_8021x_cnt);
1198 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1200 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1204 DHD_TRACE(("%s: Enter\n", __func__));
1206 ifidx = dhd_net2idx(dhd, net);
1207 if (ifidx == DHD_BAD_IF)
1210 ifp = dhd->iflist[ifidx];
1214 /* Use the protocol to get dongle stats */
1215 brcmf_proto_dstats(&dhd->pub);
1218 /* Copy dongle stats to net device stats */
1219 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1220 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1221 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1222 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1223 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1224 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1225 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1226 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1227 ifp->stats.multicast = dhd->pub.dstats.multicast;
1232 static int dhd_watchdog_thread(void *data)
1234 dhd_info_t *dhd = (dhd_info_t *) data;
1236 /* This thread doesn't need any user-level access,
1237 * so get rid of all our resources
1240 if (dhd_watchdog_prio > 0) {
1241 struct sched_param param;
1242 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1243 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1244 sched_setscheduler(current, SCHED_FIFO, ¶m);
1246 #endif /* DHD_SCHED */
1248 allow_signal(SIGTERM);
1249 /* Run until signal received */
1251 if (kthread_should_stop())
1253 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1254 if (dhd->pub.dongle_reset == false) {
1255 /* Call the bus module watchdog */
1256 brcmf_sdbrcm_bus_watchdog(&dhd->pub);
1258 /* Count the tick for reference */
1266 static void dhd_watchdog(unsigned long data)
1268 dhd_info_t *dhd = (dhd_info_t *) data;
1270 if (dhd->watchdog_tsk) {
1271 up(&dhd->watchdog_sem);
1273 /* Reschedule the watchdog */
1274 if (dhd->wd_timer_valid) {
1275 mod_timer(&dhd->timer,
1276 jiffies + brcmf_watchdog_ms * HZ / 1000);
1281 /* Call the bus module watchdog */
1282 brcmf_sdbrcm_bus_watchdog(&dhd->pub);
1284 /* Count the tick for reference */
1287 /* Reschedule the watchdog */
1288 if (dhd->wd_timer_valid)
1289 mod_timer(&dhd->timer, jiffies + brcmf_watchdog_ms * HZ / 1000);
1292 static int dhd_dpc_thread(void *data)
1294 dhd_info_t *dhd = (dhd_info_t *) data;
1296 /* This thread doesn't need any user-level access,
1297 * so get rid of all our resources
1300 if (dhd_dpc_prio > 0) {
1301 struct sched_param param;
1302 param.sched_priority =
1304 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1305 sched_setscheduler(current, SCHED_FIFO, ¶m);
1307 #endif /* DHD_SCHED */
1309 allow_signal(SIGTERM);
1310 /* Run until signal received */
1312 if (kthread_should_stop())
1314 if (down_interruptible(&dhd->dpc_sem) == 0) {
1315 /* Call bus dpc unless it indicated down
1316 (then clean stop) */
1317 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1318 if (dhd_bus_dpc(dhd->pub.bus)) {
1322 brcmf_sdbrcm_bus_stop(dhd->pub.bus, true);
1330 static void dhd_dpc(unsigned long data)
1334 dhd = (dhd_info_t *) data;
1336 /* Call bus dpc unless it indicated down (then clean stop) */
1337 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1338 if (dhd_bus_dpc(dhd->pub.bus))
1339 tasklet_schedule(&dhd->tasklet);
1341 brcmf_sdbrcm_bus_stop(dhd->pub.bus, true);
1345 void brcmf_sched_dpc(dhd_pub_t *dhdp)
1347 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1354 tasklet_schedule(&dhd->tasklet);
1358 /* Retrieve current toe component enables, which are kept
1359 as a bitmap in toe_ol iovar */
1360 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1366 memset(&ioc, 0, sizeof(ioc));
1368 ioc.cmd = BRCMF_C_GET_VAR;
1370 ioc.len = (uint) sizeof(buf);
1373 strcpy(buf, "toe_ol");
1374 ret = brcmf_proto_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1376 /* Check for older dongle image that doesn't support toe_ol */
1378 DHD_ERROR(("%s: toe not supported by device\n",
1379 brcmf_ifname(&dhd->pub, ifidx)));
1383 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1384 brcmf_ifname(&dhd->pub, ifidx), ret));
1388 memcpy(toe_ol, buf, sizeof(u32));
1392 /* Set current toe component enables in toe_ol iovar,
1393 and set toe global enable iovar */
1394 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1400 memset(&ioc, 0, sizeof(ioc));
1402 ioc.cmd = BRCMF_C_SET_VAR;
1404 ioc.len = (uint) sizeof(buf);
1407 /* Set toe_ol as requested */
1409 strcpy(buf, "toe_ol");
1410 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1412 ret = brcmf_proto_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1414 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1415 brcmf_ifname(&dhd->pub, ifidx), ret));
1419 /* Enable toe globally only if any components are enabled. */
1421 toe = (toe_ol != 0);
1424 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1426 ret = brcmf_proto_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1428 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1429 brcmf_ifname(&dhd->pub, ifidx), ret));
1437 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1438 struct ethtool_drvinfo *info)
1440 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1442 sprintf(info->driver, KBUILD_MODNAME);
1443 sprintf(info->version, "%lu", dhd->pub.drv_version);
1444 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1445 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1448 struct ethtool_ops dhd_ethtool_ops = {
1449 .get_drvinfo = dhd_ethtool_get_drvinfo
1452 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1454 struct ethtool_drvinfo info;
1455 char drvname[sizeof(info.driver)];
1458 struct ethtool_value edata;
1459 u32 toe_cmpnt, csum_dir;
1463 DHD_TRACE(("%s: Enter\n", __func__));
1465 /* all ethtool calls start with a cmd word */
1466 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1470 case ETHTOOL_GDRVINFO:
1471 /* Copy out any request driver name */
1472 if (copy_from_user(&info, uaddr, sizeof(info)))
1474 strncpy(drvname, info.driver, sizeof(info.driver));
1475 drvname[sizeof(info.driver) - 1] = '\0';
1477 /* clear struct for return */
1478 memset(&info, 0, sizeof(info));
1481 /* if dhd requested, identify ourselves */
1482 if (strcmp(drvname, "?dhd") == 0) {
1483 sprintf(info.driver, "dhd");
1484 strcpy(info.version, EPI_VERSION_STR);
1487 /* otherwise, require dongle to be up */
1488 else if (!dhd->pub.up) {
1489 DHD_ERROR(("%s: dongle is not up\n", __func__));
1493 /* finally, report dongle driver type */
1494 else if (dhd->pub.iswl)
1495 sprintf(info.driver, "wl");
1497 sprintf(info.driver, "xx");
1499 sprintf(info.version, "%lu", dhd->pub.drv_version);
1500 if (copy_to_user(uaddr, &info, sizeof(info)))
1502 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1503 (int)sizeof(drvname), drvname, info.driver));
1507 /* Get toe offload components from dongle */
1508 case ETHTOOL_GRXCSUM:
1509 case ETHTOOL_GTXCSUM:
1510 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1515 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1518 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1520 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1524 /* Set toe offload components in dongle */
1525 case ETHTOOL_SRXCSUM:
1526 case ETHTOOL_STXCSUM:
1527 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1530 /* Read the current settings, update and write back */
1531 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1536 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1538 if (edata.data != 0)
1539 toe_cmpnt |= csum_dir;
1541 toe_cmpnt &= ~csum_dir;
1543 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1547 /* If setting TX checksum mode, tell Linux the new mode */
1548 if (cmd == ETHTOOL_STXCSUM) {
1550 dhd->iflist[0]->net->features |=
1553 dhd->iflist[0]->net->features &=
1567 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1569 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1576 bool is_set_key_cmd;
1578 ifidx = dhd_net2idx(dhd, net);
1579 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1581 if (ifidx == DHD_BAD_IF)
1584 if (cmd == SIOCETHTOOL)
1585 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1587 if (cmd != SIOCDEVPRIVATE)
1590 memset(&ioc, 0, sizeof(ioc));
1592 /* Copy the ioc control structure part of ioctl request */
1593 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1598 /* Copy out any buffer passed */
1600 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1601 /* optimization for direct ioctl calls from kernel */
1603 if (segment_eq(get_fs(), KERNEL_DS)) {
1608 buf = kmalloc(buflen, GFP_ATOMIC);
1613 if (copy_from_user(buf, ioc.buf, buflen)) {
1620 /* To differentiate between wl and dhd read 4 more byes */
1621 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1622 sizeof(uint)) != 0)) {
1627 if (!capable(CAP_NET_ADMIN)) {
1632 /* check for local dhd ioctl and handle it */
1633 if (driver == DHD_IOCTL_MAGIC) {
1634 bcmerror = brcmf_c_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1636 dhd->pub.bcmerror = bcmerror;
1640 /* send to dongle (must be up, and wl) */
1641 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1642 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1647 if (!dhd->pub.iswl) {
1653 * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
1654 * set key IOCTL to prevent M4 encryption.
1656 is_set_key_cmd = ((ioc.cmd == BRCMF_C_SET_KEY) ||
1657 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1658 !(strncmp("wsec_key", ioc.buf, 9))) ||
1659 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1660 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1662 dhd_wait_pend8021x(net);
1665 brcmf_proto_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf,
1669 if (!bcmerror && buf && ioc.buf) {
1670 if (copy_to_user(ioc.buf, buf, buflen))
1682 static int dhd_stop(struct net_device *net)
1684 #if !defined(IGNORE_ETH0_DOWN)
1685 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1687 DHD_TRACE(("%s: Enter\n", __func__));
1689 if (dhd->pub.up == 0)
1692 /* Set state and stop OS transmissions */
1694 netif_stop_queue(net);
1696 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1698 #endif /* !defined(IGNORE_ETH0_DOWN) */
1703 static int dhd_open(struct net_device *net)
1705 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1709 int ifidx = dhd_net2idx(dhd, net);
1712 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1714 if (ifidx == 0) { /* do it only for primary eth0 */
1716 /* try to bring up bus */
1717 ret = brcmf_bus_start(&dhd->pub);
1719 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1722 atomic_set(&dhd->pend_8021x_cnt, 0);
1724 memcpy(net->dev_addr, dhd->pub.mac, ETH_ALEN);
1727 /* Get current TOE mode from dongle */
1728 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1729 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1730 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1732 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1735 /* Allow transmit calls */
1736 netif_start_queue(net);
1738 if (unlikely(wl_cfg80211_up())) {
1739 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1748 brcmf_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1749 u8 *mac_addr, u32 flags, u8 bssidx)
1753 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1755 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1757 ifp = dhd->iflist[ifidx];
1759 ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC);
1761 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1766 memset(ifp, 0, sizeof(dhd_if_t));
1768 dhd->iflist[ifidx] = ifp;
1769 strlcpy(ifp->name, name, IFNAMSIZ);
1770 if (mac_addr != NULL)
1771 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1773 if (handle == NULL) {
1774 ifp->state = BRCMF_E_IF_ADD;
1776 ASSERT(dhd->sysioc_tsk);
1777 up(&dhd->sysioc_sem);
1779 ifp->net = (struct net_device *)handle;
1784 void brcmf_del_if(dhd_info_t *dhd, int ifidx)
1788 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1790 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1791 ifp = dhd->iflist[ifidx];
1793 DHD_ERROR(("%s: Null interface\n", __func__));
1797 ifp->state = BRCMF_E_IF_DEL;
1799 ASSERT(dhd->sysioc_tsk);
1800 up(&dhd->sysioc_sem);
1803 dhd_pub_t *brcmf_attach(struct dhd_bus *bus, uint bus_hdrlen)
1805 dhd_info_t *dhd = NULL;
1806 struct net_device *net;
1808 DHD_TRACE(("%s: Enter\n", __func__));
1809 /* updates firmware nvram path if it was provided as module
1811 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1812 strcpy(brcmf_fw_path, firmware_path);
1813 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1814 strcpy(brcmf_nv_path, nvram_path);
1816 /* Allocate etherdev, including space for private structure */
1817 net = alloc_etherdev(sizeof(dhd));
1819 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1823 /* Allocate primary dhd_info */
1824 dhd = kzalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1826 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1831 * Save the dhd_info into the priv
1833 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1835 /* Set network interface name if it was provided as module parameter */
1836 if (iface_name[0]) {
1839 strncpy(net->name, iface_name, IFNAMSIZ);
1840 net->name[IFNAMSIZ - 1] = 0;
1841 len = strlen(net->name);
1842 ch = net->name[len - 1];
1843 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1844 strcat(net->name, "%d");
1847 if (brcmf_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1851 net->netdev_ops = NULL;
1852 sema_init(&dhd->proto_sem, 1);
1853 /* Initialize other structure content */
1854 init_waitqueue_head(&dhd->ioctl_resp_wait);
1855 init_waitqueue_head(&dhd->ctrl_wait);
1857 /* Initialize the spinlocks */
1858 spin_lock_init(&dhd->sdlock);
1860 /* Link to info module */
1861 dhd->pub.info = dhd;
1863 /* Link to bus module */
1865 dhd->pub.hdrlen = bus_hdrlen;
1867 /* Attach and link in the protocol */
1868 if (brcmf_proto_attach(&dhd->pub) != 0) {
1869 DHD_ERROR(("dhd_prot_attach failed\n"));
1873 /* Attach and link in the cfg80211 */
1874 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1875 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1878 if (!dhd_no_fw_req) {
1879 strcpy(brcmf_fw_path, wl_cfg80211_get_fwname());
1880 strcpy(brcmf_nv_path, wl_cfg80211_get_nvramname());
1883 /* Set up the watchdog timer */
1884 init_timer(&dhd->timer);
1885 dhd->timer.data = (unsigned long) dhd;
1886 dhd->timer.function = dhd_watchdog;
1888 /* Initialize thread based operation and lock */
1889 sema_init(&dhd->sdsem, 1);
1890 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1891 dhd->threads_only = true;
1893 dhd->threads_only = false;
1895 if (dhd_dpc_prio >= 0) {
1896 /* Initialize watchdog thread */
1897 sema_init(&dhd->watchdog_sem, 0);
1898 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1900 if (IS_ERR(dhd->watchdog_tsk)) {
1902 "dhd_watchdog thread failed to start\n");
1903 dhd->watchdog_tsk = NULL;
1906 dhd->watchdog_tsk = NULL;
1909 /* Set up the bottom half handler */
1910 if (dhd_dpc_prio >= 0) {
1911 /* Initialize DPC thread */
1912 sema_init(&dhd->dpc_sem, 0);
1913 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
1914 if (IS_ERR(dhd->dpc_tsk)) {
1916 "dhd_dpc thread failed to start\n");
1917 dhd->dpc_tsk = NULL;
1920 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
1921 dhd->dpc_tsk = NULL;
1925 sema_init(&dhd->sysioc_sem, 0);
1926 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
1928 if (IS_ERR(dhd->sysioc_tsk)) {
1930 "_dhd_sysioc thread failed to start\n");
1931 dhd->sysioc_tsk = NULL;
1934 dhd->sysioc_tsk = NULL;
1937 * Save the dhd_info into the priv
1939 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1941 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
1944 #if defined(CONFIG_PM_SLEEP)
1945 atomic_set(&dhd_mmc_suspend, false);
1946 #endif /* defined(CONFIG_PM_SLEEP) */
1947 /* && defined(DHD_GPL) */
1948 /* Init lock suspend to prevent kernel going to suspend */
1949 #ifdef CONFIG_HAS_EARLYSUSPEND
1950 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
1951 dhd->early_suspend.suspend = dhd_early_suspend;
1952 dhd->early_suspend.resume = dhd_late_resume;
1953 register_early_suspend(&dhd->early_suspend);
1962 brcmf_detach(&dhd->pub);
1967 int brcmf_bus_start(dhd_pub_t *dhdp)
1970 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1971 #ifdef EMBEDDED_PLATFORM
1972 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
1974 #endif /* EMBEDDED_PLATFORM */
1978 DHD_TRACE(("%s:\n", __func__));
1980 /* try to download image and nvram to the dongle */
1981 if (dhd->pub.busstate == DHD_BUS_DOWN) {
1982 if (!(dhd_bus_download_firmware(dhd->pub.bus, brcmf_fw_path,
1984 DHD_ERROR(("%s: dhd_bus_download_firmware failed. "
1985 "firmware = %s nvram = %s\n",
1986 __func__, brcmf_fw_path, brcmf_nv_path));
1991 /* Start the watchdog timer */
1992 dhd->pub.tickcnt = 0;
1993 brcmf_os_wd_timer(&dhd->pub, brcmf_watchdog_ms);
1995 /* Bring up the bus */
1996 ret = brcmf_sdbrcm_bus_init(&dhd->pub, true);
1998 DHD_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__,
2002 #if defined(OOB_INTR_ONLY)
2003 /* Host registration for OOB interrupt */
2004 if (brcmf_sdio_register_oob_intr(dhdp)) {
2005 del_timer_sync(&dhd->timer);
2006 dhd->wd_timer_valid = false;
2007 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2011 /* Enable oob at firmware */
2012 brcmf_sdbrcm_enable_oob_intr(dhd->pub.bus, true);
2013 #endif /* defined(OOB_INTR_ONLY) */
2015 /* If bus is not ready, can't come up */
2016 if (dhd->pub.busstate != DHD_BUS_DATA) {
2017 del_timer_sync(&dhd->timer);
2018 dhd->wd_timer_valid = false;
2019 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2022 #ifdef EMBEDDED_PLATFORM
2023 brcmu_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN,
2024 iovbuf, sizeof(iovbuf));
2025 brcmf_proto_cdc_query_ioctl(dhdp, 0, BRCMF_C_GET_VAR, iovbuf,
2027 memcpy(dhdp->eventmask, iovbuf, WL_EVENTING_MASK_LEN);
2029 setbit(dhdp->eventmask, BRCMF_E_SET_SSID);
2030 setbit(dhdp->eventmask, BRCMF_E_PRUNE);
2031 setbit(dhdp->eventmask, BRCMF_E_AUTH);
2032 setbit(dhdp->eventmask, BRCMF_E_REASSOC);
2033 setbit(dhdp->eventmask, BRCMF_E_REASSOC_IND);
2034 setbit(dhdp->eventmask, BRCMF_E_DEAUTH_IND);
2035 setbit(dhdp->eventmask, BRCMF_E_DISASSOC_IND);
2036 setbit(dhdp->eventmask, BRCMF_E_DISASSOC);
2037 setbit(dhdp->eventmask, BRCMF_E_JOIN);
2038 setbit(dhdp->eventmask, BRCMF_E_ASSOC_IND);
2039 setbit(dhdp->eventmask, BRCMF_E_PSK_SUP);
2040 setbit(dhdp->eventmask, BRCMF_E_LINK);
2041 setbit(dhdp->eventmask, BRCMF_E_NDIS_LINK);
2042 setbit(dhdp->eventmask, BRCMF_E_MIC_ERROR);
2043 setbit(dhdp->eventmask, BRCMF_E_PMKID_CACHE);
2044 setbit(dhdp->eventmask, BRCMF_E_TXFAIL);
2045 setbit(dhdp->eventmask, BRCMF_E_JOIN_START);
2046 setbit(dhdp->eventmask, BRCMF_E_SCAN_COMPLETE);
2048 setbit(dhdp->eventmask, BRCMF_E_PFN_NET_FOUND);
2049 #endif /* PNO_SUPPORT */
2051 /* enable dongle roaming event */
2053 dhdp->pktfilter_count = 1;
2054 /* Setup filter to allow only unicast */
2055 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2056 #endif /* EMBEDDED_PLATFORM */
2058 /* Bus is ready, do any protocol initialization */
2059 ret = brcmf_proto_init(&dhd->pub);
2067 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2070 char buf[strlen(name) + 1 + cmd_len];
2071 int len = sizeof(buf);
2075 len = brcmu_mkiovar(name, cmd_buf, cmd_len, buf, len);
2077 memset(&ioc, 0, sizeof(ioc));
2079 ioc.cmd = set ? BRCMF_C_SET_VAR : BRCMF_C_GET_VAR;
2084 ret = brcmf_proto_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2085 if (!set && ret >= 0)
2086 memcpy(cmd_buf, buf, cmd_len);
2091 static struct net_device_ops dhd_ops_pri = {
2092 .ndo_open = dhd_open,
2093 .ndo_stop = dhd_stop,
2094 .ndo_get_stats = dhd_get_stats,
2095 .ndo_do_ioctl = dhd_ioctl_entry,
2096 .ndo_start_xmit = dhd_start_xmit,
2097 .ndo_set_mac_address = dhd_set_mac_address,
2098 .ndo_set_multicast_list = dhd_set_multicast_list
2101 int brcmf_net_attach(dhd_pub_t *dhdp, int ifidx)
2103 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2104 struct net_device *net;
2105 u8 temp_addr[ETH_ALEN] = {
2106 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2108 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2110 ASSERT(dhd && dhd->iflist[ifidx]);
2112 net = dhd->iflist[ifidx]->net;
2115 ASSERT(!net->netdev_ops);
2116 net->netdev_ops = &dhd_ops_pri;
2119 * We have to use the primary MAC for virtual interfaces
2122 /* for virtual interfaces use the primary MAC */
2123 memcpy(temp_addr, dhd->pub.mac, ETH_ALEN);
2128 DHD_TRACE(("%s ACCESS POINT MAC:\n", __func__));
2129 /* ACCESSPOINT INTERFACE CASE */
2130 temp_addr[0] |= 0X02; /* set bit 2 ,
2131 - Locally Administered address */
2134 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2135 net->ethtool_ops = &dhd_ethtool_ops;
2137 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2139 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
2141 if (register_netdev(net) != 0) {
2142 DHD_ERROR(("%s: couldn't register the net device\n",
2147 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
2152 net->netdev_ops = NULL;
2156 void dhd_bus_detach(dhd_pub_t *dhdp)
2160 DHD_TRACE(("%s: Enter\n", __func__));
2163 dhd = (dhd_info_t *) dhdp->info;
2165 /* Stop the protocol module */
2166 brcmf_proto_stop(&dhd->pub);
2168 /* Stop the bus module */
2169 brcmf_sdbrcm_bus_stop(dhd->pub.bus, true);
2170 #if defined(OOB_INTR_ONLY)
2171 brcmf_sdio_unregister_oob_intr();
2172 #endif /* defined(OOB_INTR_ONLY) */
2174 /* Clear the watchdog timer */
2175 del_timer_sync(&dhd->timer);
2176 dhd->wd_timer_valid = false;
2181 void brcmf_detach(dhd_pub_t *dhdp)
2185 DHD_TRACE(("%s: Enter\n", __func__));
2188 dhd = (dhd_info_t *) dhdp->info;
2193 #if defined(CONFIG_HAS_EARLYSUSPEND)
2194 if (dhd->early_suspend.suspend)
2195 unregister_early_suspend(&dhd->early_suspend);
2196 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2198 for (i = 1; i < DHD_MAX_IFS; i++)
2200 brcmf_del_if(dhd, i);
2202 ifp = dhd->iflist[0];
2204 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2206 unregister_netdev(ifp->net);
2209 if (dhd->watchdog_tsk) {
2210 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2211 kthread_stop(dhd->watchdog_tsk);
2212 dhd->watchdog_tsk = NULL;
2216 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2217 kthread_stop(dhd->dpc_tsk);
2218 dhd->dpc_tsk = NULL;
2220 tasklet_kill(&dhd->tasklet);
2222 if (dhd->sysioc_tsk) {
2223 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2224 kthread_stop(dhd->sysioc_tsk);
2225 dhd->sysioc_tsk = NULL;
2228 dhd_bus_detach(dhdp);
2231 brcmf_proto_detach(dhdp);
2233 wl_cfg80211_detach();
2235 /* && defined(DHD_GPL) */
2236 free_netdev(ifp->net);
2243 static void __exit dhd_module_cleanup(void)
2245 DHD_TRACE(("%s: Enter\n", __func__));
2247 dhd_bus_unregister();
2248 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2251 /* Call customer gpio to turn off power with WL_REG_ON signal */
2252 brcmf_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2255 static int __init dhd_module_init(void)
2259 DHD_TRACE(("%s: Enter\n", __func__));
2261 /* Sanity check on the module parameters */
2263 /* Both watchdog and DPC as tasklets are ok */
2264 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2267 /* If both watchdog and DPC are threads, TX must be deferred */
2268 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2272 DHD_ERROR(("Invalid module parameters.\n"));
2275 /* Call customer gpio to turn on power with WL_REG_ON signal */
2276 brcmf_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2278 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2279 sema_init(&wifi_control_sem, 0);
2281 error = wifi_add_dev();
2283 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2287 /* Waiting callback after platform_driver_register is done or
2289 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2290 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2296 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2298 error = dhd_bus_register();
2301 DHD_ERROR(("%s: dhd_bus_register failed\n", __func__));
2307 /* turn off power and exit */
2308 brcmf_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2312 module_init(dhd_module_init);
2313 module_exit(dhd_module_cleanup);
2316 * OS specific functions required to implement DHD driver in OS independent way
2318 int brcmf_os_proto_block(dhd_pub_t *pub)
2320 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2323 down(&dhd->proto_sem);
2329 int brcmf_os_proto_unblock(dhd_pub_t *pub)
2331 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2334 up(&dhd->proto_sem);
2341 unsigned int brcmf_os_get_ioctl_resp_timeout(void)
2343 return (unsigned int)dhd_ioctl_timeout_msec;
2346 void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2348 dhd_ioctl_timeout_msec = (int)timeout_msec;
2351 int brcmf_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2353 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2354 DECLARE_WAITQUEUE(wait, current);
2355 int timeout = dhd_ioctl_timeout_msec;
2357 /* Convert timeout in millsecond to jiffies */
2358 timeout = timeout * HZ / 1000;
2360 /* Wait until control frame is available */
2361 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2362 set_current_state(TASK_INTERRUPTIBLE);
2364 while (!(*condition) && (!signal_pending(current) && timeout))
2365 timeout = schedule_timeout(timeout);
2367 if (signal_pending(current))
2370 set_current_state(TASK_RUNNING);
2371 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2376 int brcmf_os_ioctl_resp_wake(dhd_pub_t *pub)
2378 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2380 if (waitqueue_active(&dhd->ioctl_resp_wait))
2381 wake_up_interruptible(&dhd->ioctl_resp_wait);
2386 void brcmf_os_wd_timer(void *bus, uint wdtick)
2388 dhd_pub_t *pub = bus;
2389 static uint save_dhd_watchdog_ms;
2390 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2392 /* don't start the wd until fw is loaded */
2393 if (pub->busstate == DHD_BUS_DOWN)
2396 /* Totally stop the timer */
2397 if (!wdtick && dhd->wd_timer_valid == true) {
2398 del_timer_sync(&dhd->timer);
2399 dhd->wd_timer_valid = false;
2400 save_dhd_watchdog_ms = wdtick;
2405 brcmf_watchdog_ms = (uint) wdtick;
2407 if (save_dhd_watchdog_ms != brcmf_watchdog_ms) {
2409 if (dhd->wd_timer_valid == true)
2410 /* Stop timer and restart at new value */
2411 del_timer_sync(&dhd->timer);
2413 /* Create timer again when watchdog period is
2414 dynamically changed or in the first instance
2416 dhd->timer.expires =
2417 jiffies + brcmf_watchdog_ms * HZ / 1000;
2418 add_timer(&dhd->timer);
2421 /* Re arm the timer, at last watchdog period */
2422 mod_timer(&dhd->timer,
2423 jiffies + brcmf_watchdog_ms * HZ / 1000);
2426 dhd->wd_timer_valid = true;
2427 save_dhd_watchdog_ms = wdtick;
2431 void *brcmf_os_open_image(char *filename)
2436 return wl_cfg80211_request_fw(filename);
2438 fp = filp_open(filename, O_RDONLY, 0);
2440 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2442 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2451 int brcmf_os_get_image_block(char *buf, int len, void *image)
2453 struct file *fp = (struct file *)image;
2457 return wl_cfg80211_read_fw(buf, len);
2462 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2469 void brcmf_os_close_image(void *image)
2472 return wl_cfg80211_release_fw();
2474 filp_close((struct file *)image, NULL);
2477 void brcmf_os_sdlock(dhd_pub_t *pub)
2481 dhd = (dhd_info_t *) (pub->info);
2483 if (dhd->threads_only)
2486 spin_lock_bh(&dhd->sdlock);
2489 void brcmf_os_sdunlock(dhd_pub_t *pub)
2493 dhd = (dhd_info_t *) (pub->info);
2495 if (dhd->threads_only)
2498 spin_unlock_bh(&dhd->sdlock);
2502 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2503 brcmf_event_msg_t *event, void **data)
2507 ASSERT(dhd != NULL);
2509 bcmerror = brcmf_c_host_event(dhd, ifidx, pktdata, event, data);
2513 ASSERT(dhd->iflist[*ifidx] != NULL);
2514 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2515 if (dhd->iflist[*ifidx]->net)
2516 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event, *data);
2521 void brcmf_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2523 struct dhd_info *dhdinfo = dhd->info;
2524 brcmf_os_sdunlock(dhd);
2525 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2526 (*lockvar == false), HZ * 2);
2527 brcmf_os_sdlock(dhd);
2531 void brcmf_wait_event_wakeup(dhd_pub_t *dhd)
2533 struct dhd_info *dhdinfo = dhd->info;
2534 if (waitqueue_active(&dhdinfo->ctrl_wait))
2535 wake_up_interruptible(&dhdinfo->ctrl_wait);
2539 int dhd_dev_reset(struct net_device *dev, u8 flag)
2541 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2543 /* Turning off watchdog */
2545 brcmf_os_wd_timer(&dhd->pub, 0);
2547 brcmf_bus_devreset(&dhd->pub, flag);
2549 /* Turning on watchdog back */
2551 brcmf_os_wd_timer(&dhd->pub, brcmf_watchdog_ms);
2552 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2557 int net_os_set_suspend_disable(struct net_device *dev, int val)
2559 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2563 ret = dhd->pub.suspend_disable_flag;
2564 dhd->pub.suspend_disable_flag = val;
2569 int net_os_set_suspend(struct net_device *dev, int val)
2572 #if defined(CONFIG_HAS_EARLYSUSPEND)
2573 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2576 brcmf_os_proto_block(&dhd->pub);
2577 ret = dhd_set_suspend(val, &dhd->pub);
2578 brcmf_os_proto_unblock(&dhd->pub);
2580 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2584 int net_os_set_dtim_skip(struct net_device *dev, int val)
2586 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2589 dhd->pub.dtim_skip = val;
2594 int net_os_set_packet_filter(struct net_device *dev, int val)
2596 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2599 /* Packet filtering is set only if we still in early-suspend and
2600 * we need either to turn it ON or turn it OFF
2601 * We can always turn it OFF in case of early-suspend, but we turn it
2602 * back ON only if suspend_disable_flag was not set
2604 if (dhd && dhd->pub.up) {
2605 brcmf_os_proto_block(&dhd->pub);
2606 if (dhd->pub.in_suspend) {
2607 if (!val || (val && !dhd->pub.suspend_disable_flag))
2608 dhd_set_packet_filter(val, &dhd->pub);
2610 brcmf_os_proto_unblock(&dhd->pub);
2615 void dhd_dev_init_ioctl(struct net_device *dev)
2617 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2619 brcmf_c_preinit_ioctls(&dhd->pub);
2623 /* Linux wrapper to call common dhd_pno_clean */
2624 int dhd_dev_pno_reset(struct net_device *dev)
2626 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2628 return dhd_pno_clean(&dhd->pub);
2631 /* Linux wrapper to call common dhd_pno_enable */
2632 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2634 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2636 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2639 /* Linux wrapper to call common dhd_pno_set */
2641 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2642 unsigned char scan_fr)
2644 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2646 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2649 /* Linux wrapper to get pno status */
2650 int dhd_dev_get_pno_status(struct net_device *dev)
2652 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2654 return dhd_pno_get_status(&dhd->pub);
2657 #endif /* PNO_SUPPORT */
2659 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2661 return atomic_read(&dhd->pend_8021x_cnt);
2664 #define MAX_WAIT_FOR_8021X_TX 10
2666 int dhd_wait_pend8021x(struct net_device *dev)
2668 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2669 int timeout = 10 * HZ / 1000;
2670 int ntimes = MAX_WAIT_FOR_8021X_TX;
2671 int pend = dhd_get_pend_8021x_cnt(dhd);
2673 while (ntimes && pend) {
2675 set_current_state(TASK_INTERRUPTIBLE);
2676 schedule_timeout(timeout);
2677 set_current_state(TASK_RUNNING);
2680 pend = dhd_get_pend_8021x_cnt(dhd);
2685 void wl_os_wd_timer(struct net_device *ndev, uint wdtick)
2687 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(ndev);
2689 brcmf_os_wd_timer(&dhd->pub, wdtick);
2693 int brcmf_write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2697 mm_segment_t old_fs;
2700 /* change to KERNEL_DS address limit */
2704 /* open file to write */
2705 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2707 DHD_ERROR(("%s: open file error\n", __func__));
2712 /* Write buf to file */
2713 fp->f_op->write(fp, buf, size, &pos);
2716 /* free buf before return */
2718 /* close file before return */
2720 filp_close(fp, current->files);
2721 /* restore previous address limit */
2726 #endif /* DHD_DEBUG */
2729 void osl_assert(char *exp, char *file, int line)
2734 basename = strrchr(file, '/');
2742 snprintf(tempbuf, 256,
2743 "assertion \"%s\" failed: file \"%s\", line %d\n", exp,
2747 * Print assert message and give it time to
2748 * be written to /var/log/messages
2750 if (!in_interrupt()) {
2751 const int delay = 3;
2752 printk(KERN_ERR "%s", tempbuf);
2753 printk(KERN_ERR "panic in %d seconds\n", delay);
2754 set_current_state(TASK_INTERRUPTIBLE);
2755 schedule_timeout(delay * HZ);
2758 switch (g_assert_type) {
2760 panic(KERN_ERR "%s", tempbuf);
2763 printk(KERN_ERR "%s", tempbuf);
2767 printk(KERN_ERR "%s", tempbuf);
2773 #endif /* defined(BCMDBG) */