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 <linux/interrupt.h>
35 #include <linux/hardirq.h>
39 #include <dngl_stats.h>
42 #include <dhd_proto.h>
45 #include <wl_cfg80211.h>
47 #define EPI_VERSION_STR "4.218.248.5"
48 #define ETH_P_BRCM 0x886c
50 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
51 #include <linux/wifi_tiwlan.h>
53 struct semaphore wifi_control_sem;
55 struct dhd_bus *g_bus;
57 static struct wifi_platform_data *wifi_control_data;
58 static struct resource *wifi_irqres;
60 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
63 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
64 return (int)wifi_irqres->start;
66 #ifdef CUSTOM_OOB_GPIO_NUM
67 return CUSTOM_OOB_GPIO_NUM;
73 int wifi_set_carddetect(int on)
75 printk(KERN_ERR "%s = %d\n", __func__, on);
76 if (wifi_control_data && wifi_control_data->set_carddetect)
77 wifi_control_data->set_carddetect(on);
81 int wifi_set_power(int on, unsigned long msec)
83 printk(KERN_ERR "%s = %d\n", __func__, on);
84 if (wifi_control_data && wifi_control_data->set_power)
85 wifi_control_data->set_power(on);
91 int wifi_set_reset(int on, unsigned long msec)
93 printk(KERN_ERR "%s = %d\n", __func__, on);
94 if (wifi_control_data && wifi_control_data->set_reset)
95 wifi_control_data->set_reset(on);
101 static int wifi_probe(struct platform_device *pdev)
103 struct wifi_platform_data *wifi_ctrl =
104 (struct wifi_platform_data *)(pdev->dev.platform_data);
106 printk(KERN_ERR "## %s\n", __func__);
108 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
110 wifi_control_data = wifi_ctrl;
112 wifi_set_power(1, 0); /* Power On */
113 wifi_set_carddetect(1); /* CardDetect (0->1) */
115 up(&wifi_control_sem);
119 static int wifi_remove(struct platform_device *pdev)
121 struct wifi_platform_data *wifi_ctrl =
122 (struct wifi_platform_data *)(pdev->dev.platform_data);
124 printk(KERN_ERR "## %s\n", __func__);
125 wifi_control_data = wifi_ctrl;
127 wifi_set_carddetect(0); /* CardDetect (1->0) */
128 wifi_set_power(0, 0); /* Power Off */
130 up(&wifi_control_sem);
134 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
136 DHD_TRACE(("##> %s\n", __func__));
140 static int wifi_resume(struct platform_device *pdev)
142 DHD_TRACE(("##> %s\n", __func__));
146 static struct platform_driver wifi_device = {
148 .remove = wifi_remove,
149 .suspend = wifi_suspend,
150 .resume = wifi_resume,
152 .name = KBUILD_MODNAME,
156 int wifi_add_dev(void)
158 DHD_TRACE(("## Calling platform_driver_register\n"));
159 return platform_driver_register(&wifi_device);
162 void wifi_del_dev(void)
164 DHD_TRACE(("## Unregister platform_driver_register\n"));
165 platform_driver_unregister(&wifi_device);
167 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
169 #if defined(CONFIG_PM_SLEEP)
170 #include <linux/suspend.h>
171 atomic_t dhd_mmc_suspend;
172 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
173 #endif /* defined(CONFIG_PM_SLEEP) */
175 #if defined(OOB_INTR_ONLY)
176 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
177 #endif /* defined(OOB_INTR_ONLY) */
179 MODULE_AUTHOR("Broadcom Corporation");
180 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
181 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
182 MODULE_LICENSE("Dual BSD/GPL");
184 #define DRV_MODULE_NAME "brcmfmac"
186 /* Linux wireless extension support */
187 #if defined(CONFIG_WIRELESS_EXT)
189 extern wl_iw_extra_params_t g_wl_iw_params;
190 #endif /* defined(CONFIG_WIRELESS_EXT) */
192 #if defined(CONFIG_HAS_EARLYSUSPEND)
193 #include <linux/earlysuspend.h>
194 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
196 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
198 #ifdef PKT_FILTER_SUPPORT
199 extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
200 extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
204 /* Interface control information */
205 typedef struct dhd_if {
206 struct dhd_info *info; /* back pointer to dhd_info */
207 /* OS/stack specifics */
208 struct net_device *net;
209 struct net_device_stats stats;
210 int idx; /* iface idx in dongle */
211 int state; /* interface state */
212 uint subunit; /* subunit */
213 u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
214 bool attached; /* Delayed attachment when unset */
215 bool txflowcontrol; /* Per interface flow control indicator */
216 char name[IFNAMSIZ]; /* linux interface name */
219 /* Local private structure (extension of pub) */
220 typedef struct dhd_info {
221 #if defined(CONFIG_WIRELESS_EXT)
222 wl_iw_t iw; /* wireless extensions state (must be first) */
223 #endif /* defined(CONFIG_WIRELESS_EXT) */
227 /* OS/stack specifics */
228 dhd_if_t *iflist[DHD_MAX_IFS];
230 struct semaphore proto_sem;
231 wait_queue_head_t ioctl_resp_wait;
232 struct timer_list timer;
234 struct tasklet_struct tasklet;
237 /* Thread based operation */
239 struct semaphore sdsem;
240 struct task_struct *watchdog_tsk;
241 struct semaphore watchdog_sem;
242 struct task_struct *dpc_tsk;
243 struct semaphore dpc_sem;
245 /* Thread to issue ioctl for multicast */
246 struct task_struct *sysioc_tsk;
247 struct semaphore sysioc_sem;
250 u8 macvalue[ETH_ALEN];
251 wait_queue_head_t ctrl_wait;
252 atomic_t pend_8021x_cnt;
254 #ifdef CONFIG_HAS_EARLYSUSPEND
255 struct early_suspend early_suspend;
256 #endif /* CONFIG_HAS_EARLYSUSPEND */
259 /* Definitions to provide path to the firmware and nvram
260 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
262 char firmware_path[MOD_PARAM_PATHLEN];
263 char nvram_path[MOD_PARAM_PATHLEN];
265 /* load firmware and/or nvram values from the filesystem */
266 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
267 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
270 module_param(dhd_msg_level, int, 0);
272 /* Spawn a thread for system ioctls (set mac, set mcast) */
273 uint dhd_sysioc = true;
274 module_param(dhd_sysioc, uint, 0);
276 /* Watchdog interval */
277 uint dhd_watchdog_ms = 10;
278 module_param(dhd_watchdog_ms, uint, 0);
281 /* Console poll interval */
283 module_param(dhd_console_ms, uint, 0);
284 #endif /* DHD_DEBUG */
286 /* ARP offload agent mode : Enable ARP Host Auto-Reply
287 and ARP Peer Auto-Reply */
288 uint dhd_arp_mode = 0xb;
289 module_param(dhd_arp_mode, uint, 0);
291 /* ARP offload enable */
292 uint dhd_arp_enable = true;
293 module_param(dhd_arp_enable, uint, 0);
295 /* Global Pkt filter enable control */
296 uint dhd_pkt_filter_enable = true;
297 module_param(dhd_pkt_filter_enable, uint, 0);
299 /* Pkt filter init setup */
300 uint dhd_pkt_filter_init;
301 module_param(dhd_pkt_filter_init, uint, 0);
303 /* Pkt filter mode control */
304 uint dhd_master_mode = true;
305 module_param(dhd_master_mode, uint, 1);
307 /* Watchdog thread priority, -1 to use kernel timer */
308 int dhd_watchdog_prio = 97;
309 module_param(dhd_watchdog_prio, int, 0);
311 /* DPC thread priority, -1 to use tasklet */
312 int dhd_dpc_prio = 98;
313 module_param(dhd_dpc_prio, int, 0);
315 /* DPC thread priority, -1 to use tasklet */
316 extern int dhd_dongle_memsize;
317 module_param(dhd_dongle_memsize, int, 0);
319 /* Contorl fw roaming */
326 /* Control radio state */
327 uint dhd_radio_up = 1;
329 /* Network inteface name */
330 char iface_name[IFNAMSIZ] = "wlan";
331 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
333 /* The following are specific to the SDIO dongle */
335 /* IOCTL response timeout */
336 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
338 /* Idle timeout for backplane clock */
339 int dhd_idletime = DHD_IDLETIME_TICKS;
340 module_param(dhd_idletime, int, 0);
343 uint dhd_poll = false;
344 module_param(dhd_poll, uint, 0);
347 uint dhd_cfg80211 = true;
348 module_param(dhd_cfg80211, uint, 0);
351 uint dhd_intr = true;
352 module_param(dhd_intr, uint, 0);
354 /* SDIO Drive Strength (in milliamps) */
355 uint dhd_sdiod_drive_strength = 6;
356 module_param(dhd_sdiod_drive_strength, uint, 0);
359 extern uint dhd_txbound;
360 extern uint dhd_rxbound;
361 module_param(dhd_txbound, uint, 0);
362 module_param(dhd_rxbound, uint, 0);
364 /* Deferred transmits */
365 extern uint dhd_deferred_tx;
366 module_param(dhd_deferred_tx, uint, 0);
369 /* Echo packet generator (pkts/s) */
371 module_param(dhd_pktgen, uint, 0);
373 /* Echo packet len (0 => sawtooth, max 2040) */
375 module_param(dhd_pktgen_len, uint, 0);
378 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
379 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
380 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
381 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
383 /* Version string to report */
385 #define DHD_COMPILED "\nCompiled in " SRCBASE
390 static void dhd_dpc(unsigned long data);
392 extern int dhd_wait_pend8021x(struct net_device *dev);
396 #error TOE requires BDC
398 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
399 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
402 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
403 wl_event_msg_t *event_ptr, void **data_ptr);
405 #if defined(CONFIG_PM_SLEEP)
406 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
407 unsigned long action, void *ignored)
410 case PM_HIBERNATION_PREPARE:
411 case PM_SUSPEND_PREPARE:
412 atomic_set(&dhd_mmc_suspend, true);
414 case PM_POST_HIBERNATION:
415 case PM_POST_SUSPEND:
416 atomic_set(&dhd_mmc_suspend, false);
422 static struct notifier_block dhd_sleep_pm_notifier = {
423 .notifier_call = dhd_sleep_pm_callback,
427 extern int register_pm_notifier(struct notifier_block *nb);
428 extern int unregister_pm_notifier(struct notifier_block *nb);
429 #endif /* defined(CONFIG_PM_SLEEP) */
430 /* && defined(DHD_GPL) */
431 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
433 #ifdef PKT_FILTER_SUPPORT
434 DHD_TRACE(("%s: %d\n", __func__, value));
435 /* 1 - Enable packet filter, only allow unicast packet to send up */
436 /* 0 - Disable packet filter */
437 if (dhd_pkt_filter_enable) {
440 for (i = 0; i < dhd->pktfilter_count; i++) {
441 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
442 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
443 value, dhd_master_mode);
449 #if defined(CONFIG_HAS_EARLYSUSPEND)
450 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
452 int power_mode = PM_MAX;
453 /* wl_pkt_filter_enable_t enable_parm; */
458 #endif /* CUSTOMER_HW2 */
460 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
461 __func__, value, dhd->in_suspend));
463 if (dhd && dhd->up) {
464 if (value && dhd->in_suspend) {
466 /* Kernel suspended */
467 DHD_TRACE(("%s: force extra Suspend setting\n",
470 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
474 /* Enable packet filter, only allow unicast
476 dhd_set_packet_filter(1, dhd);
478 /* if dtim skip setup as default force it
479 * to wake each third dtim
480 * for better power saving.
481 * Note that side effect is chance to miss BC/MC
484 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
487 bcn_li_dtim = dhd->dtim_skip;
488 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
489 4, iovbuf, sizeof(iovbuf));
490 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
493 /* Disable build-in roaming to allowed \
494 * supplicant to take of romaing
496 bcm_mkiovar("roam_off", (char *)&roamvar, 4,
497 iovbuf, sizeof(iovbuf));
498 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
500 #endif /* CUSTOMER_HW2 */
504 DHD_TRACE(("%s: Remove extra suspend setting\n",
507 power_mode = PM_FAST;
508 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
512 /* disable pkt filter */
513 dhd_set_packet_filter(0, dhd);
515 /* restore pre-suspend setting for dtim_skip */
516 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
517 4, iovbuf, sizeof(iovbuf));
519 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
523 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
525 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
527 #endif /* CUSTOMER_HW2 */
534 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
536 dhd_pub_t *dhdp = &dhd->pub;
538 dhd_os_proto_block(dhdp);
539 /* Set flag when early suspend was called */
540 dhdp->in_suspend = val;
541 if (!dhdp->suspend_disable_flag)
542 dhd_set_suspend(val, dhdp);
543 dhd_os_proto_unblock(dhdp);
546 static void dhd_early_suspend(struct early_suspend *h)
548 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
550 DHD_TRACE(("%s: enter\n", __func__));
553 dhd_suspend_resume_helper(dhd, 1);
557 static void dhd_late_resume(struct early_suspend *h)
559 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
561 DHD_TRACE(("%s: enter\n", __func__));
564 dhd_suspend_resume_helper(dhd, 0);
566 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
569 * Generalized timeout mechanism. Uses spin sleep with exponential
571 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
573 * dhd_timeout_start(&tmo, usec);
574 * while (!dhd_timeout_expired(&tmo))
575 * if (poll_something())
577 * if (dhd_timeout_expired(&tmo))
581 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
586 tmo->tick = 1000000 / HZ;
589 int dhd_timeout_expired(dhd_timeout_t *tmo)
591 /* Does nothing the first call */
592 if (tmo->increment == 0) {
597 if (tmo->elapsed >= tmo->limit)
600 /* Add the delay that's about to take place */
601 tmo->elapsed += tmo->increment;
603 if (tmo->increment < tmo->tick) {
604 udelay(tmo->increment);
606 if (tmo->increment > tmo->tick)
607 tmo->increment = tmo->tick;
609 wait_queue_head_t delay_wait;
610 DECLARE_WAITQUEUE(wait, current);
612 init_waitqueue_head(&delay_wait);
613 add_wait_queue(&delay_wait, &wait);
614 set_current_state(TASK_INTERRUPTIBLE);
616 pending = signal_pending(current);
617 remove_wait_queue(&delay_wait, &wait);
618 set_current_state(TASK_RUNNING);
620 return 1; /* Interrupted */
626 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
631 while (i < DHD_MAX_IFS) {
632 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
640 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
646 if (name == NULL || *name == '\0')
651 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
654 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
656 return i; /* default - the primary interface */
659 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
661 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
665 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
666 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
670 if (dhd->iflist[ifidx] == NULL) {
671 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
675 if (dhd->iflist[ifidx]->net)
676 return dhd->iflist[ifidx]->net->name;
681 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
683 struct net_device *dev;
684 struct netdev_hw_addr *ha;
692 ASSERT(dhd && dhd->iflist[ifidx]);
693 dev = dhd->iflist[ifidx]->net;
694 cnt = netdev_mc_count(dev);
696 /* Determine initial value of allmulti flag */
697 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
699 /* Send down the multicast list first. */
701 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
702 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
704 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
705 dhd_ifname(&dhd->pub, ifidx), cnt));
709 strcpy(bufp, "mcast_list");
710 bufp += strlen("mcast_list") + 1;
712 cnt = cpu_to_le32(cnt);
713 memcpy(bufp, &cnt, sizeof(cnt));
716 netdev_for_each_mc_addr(ha, dev) {
719 memcpy(bufp, ha->addr, ETH_ALEN);
724 memset(&ioc, 0, sizeof(ioc));
725 ioc.cmd = WLC_SET_VAR;
730 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
732 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
733 dhd_ifname(&dhd->pub, ifidx), cnt));
734 allmulti = cnt ? true : allmulti;
739 /* Now send the allmulti setting. This is based on the setting in the
740 * net_device flags, but might be modified above to be turned on if we
741 * were trying to set some addresses and dongle rejected it...
744 buflen = sizeof("allmulti") + sizeof(allmulti);
745 buf = kmalloc(buflen, GFP_ATOMIC);
747 DHD_ERROR(("%s: out of memory for allmulti\n",
748 dhd_ifname(&dhd->pub, ifidx)));
751 allmulti = cpu_to_le32(allmulti);
754 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
755 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
756 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
757 (int)sizeof(allmulti), buflen));
762 memset(&ioc, 0, sizeof(ioc));
763 ioc.cmd = WLC_SET_VAR;
768 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
770 DHD_ERROR(("%s: set allmulti %d failed\n",
771 dhd_ifname(&dhd->pub, ifidx),
772 le32_to_cpu(allmulti)));
777 /* Finally, pick up the PROMISC flag as well, like the NIC
780 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
781 allmulti = cpu_to_le32(allmulti);
783 memset(&ioc, 0, sizeof(ioc));
784 ioc.cmd = WLC_SET_PROMISC;
786 ioc.len = sizeof(allmulti);
789 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
791 DHD_ERROR(("%s: set promisc %d failed\n",
792 dhd_ifname(&dhd->pub, ifidx),
793 le32_to_cpu(allmulti)));
798 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, u8 *addr)
804 DHD_TRACE(("%s enter\n", __func__));
806 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
807 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
808 dhd_ifname(&dhd->pub, ifidx)));
811 memset(&ioc, 0, sizeof(ioc));
812 ioc.cmd = WLC_SET_VAR;
817 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
819 DHD_ERROR(("%s: set cur_etheraddr failed\n",
820 dhd_ifname(&dhd->pub, ifidx)));
822 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
829 extern struct net_device *ap_net_dev;
832 static void dhd_op_if(dhd_if_t *ifp)
835 int ret = 0, err = 0;
837 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
841 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
843 switch (ifp->state) {
846 * Delete the existing interface before overwriting it
847 * in case we missed the WLC_E_IF_DEL event.
849 if (ifp->net != NULL) {
850 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
851 "try free & unregister\n",
852 __func__, ifp->net->name));
853 netif_stop_queue(ifp->net);
854 unregister_netdev(ifp->net);
855 free_netdev(ifp->net);
857 /* Allocate etherdev, including space for private structure */
858 ifp->net = alloc_etherdev(sizeof(dhd));
860 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
864 strcpy(ifp->net->name, ifp->name);
865 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
866 err = dhd_net_attach(&dhd->pub, ifp->idx);
868 DHD_ERROR(("%s: dhd_net_attach failed, "
874 /* semaphore that the soft AP CODE
876 extern struct semaphore ap_eth_sema;
878 /* save ptr to wl0.1 netdev for use
880 ap_net_dev = ifp->net;
881 /* signal to the SOFTAP 'sleeper' thread,
885 DHD_TRACE(("\n ==== pid:%x, net_device for "
886 "if:%s created ===\n\n",
887 current->pid, ifp->net->name));
893 if (ifp->net != NULL) {
894 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
896 netif_stop_queue(ifp->net);
897 unregister_netdev(ifp->net);
898 ret = DHD_DEL_IF; /* Make sure the free_netdev()
903 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
910 free_netdev(ifp->net);
912 dhd->iflist[ifp->idx] = NULL;
915 if (ifp->net == ap_net_dev)
916 ap_net_dev = NULL; /* NULL SOFTAP global
922 static int _dhd_sysioc_thread(void *data)
924 dhd_info_t *dhd = (dhd_info_t *) data;
930 allow_signal(SIGTERM);
932 while (down_interruptible(&dhd->sysioc_sem) == 0) {
933 if (kthread_should_stop())
935 for (i = 0; i < DHD_MAX_IFS; i++) {
936 if (dhd->iflist[i]) {
938 in_ap = (ap_net_dev != NULL);
940 if (dhd->iflist[i]->state)
941 dhd_op_if(dhd->iflist[i]);
943 if (dhd->iflist[i] == NULL) {
944 DHD_TRACE(("\n\n %s: interface %d "
945 "removed!\n", __func__, i));
949 if (in_ap && dhd->set_macaddress) {
950 DHD_TRACE(("attempt to set MAC for %s "
951 "in AP Mode," "blocked. \n",
952 dhd->iflist[i]->net->name));
953 dhd->set_macaddress = false;
957 if (in_ap && dhd->set_multicast) {
958 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
959 dhd->iflist[i]->net->name));
960 dhd->set_multicast = false;
964 if (dhd->set_multicast) {
965 dhd->set_multicast = false;
966 _dhd_set_multicast_list(dhd, i);
968 if (dhd->set_macaddress) {
969 dhd->set_macaddress = false;
970 _dhd_set_mac_address(dhd, i,
979 static int dhd_set_mac_address(struct net_device *dev, void *addr)
983 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
984 struct sockaddr *sa = (struct sockaddr *)addr;
987 ifidx = dhd_net2idx(dhd, dev);
988 if (ifidx == DHD_BAD_IF)
991 ASSERT(dhd->sysioc_tsk);
992 memcpy(&dhd->macvalue, sa->sa_data, ETH_ALEN);
993 dhd->set_macaddress = true;
994 up(&dhd->sysioc_sem);
999 static void dhd_set_multicast_list(struct net_device *dev)
1001 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1004 ifidx = dhd_net2idx(dhd, dev);
1005 if (ifidx == DHD_BAD_IF)
1008 ASSERT(dhd->sysioc_tsk);
1009 dhd->set_multicast = true;
1010 up(&dhd->sysioc_sem);
1013 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf)
1016 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1018 /* Reject if down */
1019 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1022 /* Update multicast statistic */
1023 if (pktbuf->len >= ETH_ALEN) {
1024 u8 *pktdata = (u8 *) (pktbuf->data);
1025 struct ethhdr *eh = (struct ethhdr *)pktdata;
1027 if (is_multicast_ether_addr(eh->h_dest))
1028 dhdp->tx_multicast++;
1029 if (ntohs(eh->h_proto) == ETH_P_PAE)
1030 atomic_inc(&dhd->pend_8021x_cnt);
1033 /* If the protocol uses a data header, apply it */
1034 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1036 /* Use bus module to send data frame */
1038 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1040 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1041 #endif /* BCMDBUS */
1046 static inline void *
1047 osl_pkt_frmnative(struct sk_buff *skb)
1051 #define PKTFRMNATIVE(osh, skb) \
1052 osl_pkt_frmnative((struct sk_buff *)(skb))
1054 static inline struct sk_buff *
1055 osl_pkt_tonative(void *pkt)
1057 return (struct sk_buff *)pkt;
1059 #define PKTTONATIVE(osh, pkt) \
1060 osl_pkt_tonative((pkt))
1062 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1066 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1069 DHD_TRACE(("%s: Enter\n", __func__));
1071 /* Reject if down */
1072 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1073 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1074 __func__, dhd->pub.up, dhd->pub.busstate));
1075 netif_stop_queue(net);
1079 ifidx = dhd_net2idx(dhd, net);
1080 if (ifidx == DHD_BAD_IF) {
1081 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1082 netif_stop_queue(net);
1086 /* Make sure there's enough room for any header */
1087 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1088 struct sk_buff *skb2;
1090 DHD_INFO(("%s: insufficient headroom\n",
1091 dhd_ifname(&dhd->pub, ifidx)));
1092 dhd->pub.tx_realloc++;
1093 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1097 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1098 dhd_ifname(&dhd->pub, ifidx)));
1104 /* Convert to packet */
1105 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1107 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1108 dhd_ifname(&dhd->pub, ifidx)));
1109 dev_kfree_skb_any(skb);
1114 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1118 dhd->pub.dstats.tx_dropped++;
1120 dhd->pub.tx_packets++;
1122 /* Return ok: we always eat the packet */
1126 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1128 struct net_device *net;
1129 dhd_info_t *dhd = dhdp->info;
1131 DHD_TRACE(("%s: Enter\n", __func__));
1133 dhdp->txoff = state;
1134 ASSERT(dhd && dhd->iflist[ifidx]);
1135 net = dhd->iflist[ifidx]->net;
1137 netif_stop_queue(net);
1139 netif_wake_queue(net);
1142 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf,
1145 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1146 struct sk_buff *skb;
1150 struct sk_buff *pnext, *save_pktbuf;
1153 wl_event_msg_t event;
1155 DHD_TRACE(("%s: Enter\n", __func__));
1157 save_pktbuf = pktbuf;
1159 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1161 pnext = pktbuf->next;
1162 pktbuf->next = NULL;
1164 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1166 /* Get the protocol, maintain skb around eth_type_trans()
1167 * The main reason for this hack is for the limitation of
1168 * Linux 2.4 where 'eth_type_trans' uses the
1169 * 'net->hard_header_len'
1170 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1171 * coping of the packet coming from the network stack to add
1172 * BDC, Hardware header etc, during network interface
1174 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1176 * for BDC, Hardware header etc. and not just the ETH_HLEN
1181 ifp = dhd->iflist[ifidx];
1183 ifp = dhd->iflist[0];
1186 skb->dev = ifp->net;
1187 skb->protocol = eth_type_trans(skb, skb->dev);
1189 if (skb->pkt_type == PACKET_MULTICAST)
1190 dhd->pub.rx_multicast++;
1195 /* Strip header, count, deliver upward */
1196 skb_pull(skb, ETH_HLEN);
1198 /* Process special event packets and then discard them */
1199 if (ntohs(skb->protocol) == ETH_P_BRCM)
1200 dhd_wl_host_event(dhd, &ifidx,
1201 skb_mac_header(skb),
1204 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1205 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1206 ifp = dhd->iflist[ifidx];
1209 ifp->net->last_rx = jiffies;
1211 dhdp->dstats.rx_bytes += skb->len;
1212 dhdp->rx_packets++; /* Local count */
1214 if (in_interrupt()) {
1217 /* If the receive is not processed inside an ISR,
1218 * the softirqd must be woken explicitly to service
1219 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1220 * by netif_rx_ni(), but in earlier kernels, we need
1221 * to do it manually.
1228 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1230 /* Linux version has nothing to do */
1234 void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success)
1237 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1241 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1243 eh = (struct ethhdr *)(txp->data);
1244 type = ntohs(eh->h_proto);
1246 if (type == ETH_P_PAE)
1247 atomic_dec(&dhd->pend_8021x_cnt);
1251 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1253 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1257 DHD_TRACE(("%s: Enter\n", __func__));
1259 ifidx = dhd_net2idx(dhd, net);
1260 if (ifidx == DHD_BAD_IF)
1263 ifp = dhd->iflist[ifidx];
1267 /* Use the protocol to get dongle stats */
1268 dhd_prot_dstats(&dhd->pub);
1271 /* Copy dongle stats to net device stats */
1272 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1273 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1274 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1275 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1276 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1277 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1278 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1279 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1280 ifp->stats.multicast = dhd->pub.dstats.multicast;
1285 static int dhd_watchdog_thread(void *data)
1287 dhd_info_t *dhd = (dhd_info_t *) data;
1289 /* This thread doesn't need any user-level access,
1290 * so get rid of all our resources
1293 if (dhd_watchdog_prio > 0) {
1294 struct sched_param param;
1295 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1296 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1297 setScheduler(current, SCHED_FIFO, ¶m);
1299 #endif /* DHD_SCHED */
1301 allow_signal(SIGTERM);
1302 /* Run until signal received */
1304 if (kthread_should_stop())
1306 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1307 if (dhd->pub.dongle_reset == false) {
1308 /* Call the bus module watchdog */
1309 dhd_bus_watchdog(&dhd->pub);
1311 /* Count the tick for reference */
1319 static void dhd_watchdog(unsigned long data)
1321 dhd_info_t *dhd = (dhd_info_t *) data;
1323 if (dhd->watchdog_tsk) {
1324 up(&dhd->watchdog_sem);
1326 /* Reschedule the watchdog */
1327 if (dhd->wd_timer_valid) {
1328 mod_timer(&dhd->timer,
1329 jiffies + dhd_watchdog_ms * HZ / 1000);
1334 /* Call the bus module watchdog */
1335 dhd_bus_watchdog(&dhd->pub);
1337 /* Count the tick for reference */
1340 /* Reschedule the watchdog */
1341 if (dhd->wd_timer_valid)
1342 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1345 static int dhd_dpc_thread(void *data)
1347 dhd_info_t *dhd = (dhd_info_t *) data;
1349 /* This thread doesn't need any user-level access,
1350 * so get rid of all our resources
1353 if (dhd_dpc_prio > 0) {
1354 struct sched_param param;
1355 param.sched_priority =
1357 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1358 setScheduler(current, SCHED_FIFO, ¶m);
1360 #endif /* DHD_SCHED */
1362 allow_signal(SIGTERM);
1363 /* Run until signal received */
1365 if (kthread_should_stop())
1367 if (down_interruptible(&dhd->dpc_sem) == 0) {
1368 /* Call bus dpc unless it indicated down
1369 (then clean stop) */
1370 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1371 if (dhd_bus_dpc(dhd->pub.bus)) {
1375 dhd_bus_stop(dhd->pub.bus, true);
1383 static void dhd_dpc(unsigned long data)
1387 dhd = (dhd_info_t *) data;
1389 /* Call bus dpc unless it indicated down (then clean stop) */
1390 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1391 if (dhd_bus_dpc(dhd->pub.bus))
1392 tasklet_schedule(&dhd->tasklet);
1394 dhd_bus_stop(dhd->pub.bus, true);
1398 void dhd_sched_dpc(dhd_pub_t *dhdp)
1400 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1407 tasklet_schedule(&dhd->tasklet);
1411 /* Retrieve current toe component enables, which are kept
1412 as a bitmap in toe_ol iovar */
1413 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1419 memset(&ioc, 0, sizeof(ioc));
1421 ioc.cmd = WLC_GET_VAR;
1423 ioc.len = (uint) sizeof(buf);
1426 strcpy(buf, "toe_ol");
1427 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1429 /* Check for older dongle image that doesn't support toe_ol */
1431 DHD_ERROR(("%s: toe not supported by device\n",
1432 dhd_ifname(&dhd->pub, ifidx)));
1436 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1437 dhd_ifname(&dhd->pub, ifidx), ret));
1441 memcpy(toe_ol, buf, sizeof(u32));
1445 /* Set current toe component enables in toe_ol iovar,
1446 and set toe global enable iovar */
1447 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1453 memset(&ioc, 0, sizeof(ioc));
1455 ioc.cmd = WLC_SET_VAR;
1457 ioc.len = (uint) sizeof(buf);
1460 /* Set toe_ol as requested */
1462 strcpy(buf, "toe_ol");
1463 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1465 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1467 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1468 dhd_ifname(&dhd->pub, ifidx), ret));
1472 /* Enable toe globally only if any components are enabled. */
1474 toe = (toe_ol != 0);
1477 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1479 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1481 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1482 dhd_ifname(&dhd->pub, ifidx), ret));
1490 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1491 struct ethtool_drvinfo *info)
1493 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1495 sprintf(info->driver, DRV_MODULE_NAME);
1496 sprintf(info->version, "%lu", dhd->pub.drv_version);
1497 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1498 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1501 struct ethtool_ops dhd_ethtool_ops = {
1502 .get_drvinfo = dhd_ethtool_get_drvinfo
1505 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1507 struct ethtool_drvinfo info;
1508 char drvname[sizeof(info.driver)];
1511 struct ethtool_value edata;
1512 u32 toe_cmpnt, csum_dir;
1516 DHD_TRACE(("%s: Enter\n", __func__));
1518 /* all ethtool calls start with a cmd word */
1519 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1523 case ETHTOOL_GDRVINFO:
1524 /* Copy out any request driver name */
1525 if (copy_from_user(&info, uaddr, sizeof(info)))
1527 strncpy(drvname, info.driver, sizeof(info.driver));
1528 drvname[sizeof(info.driver) - 1] = '\0';
1530 /* clear struct for return */
1531 memset(&info, 0, sizeof(info));
1534 /* if dhd requested, identify ourselves */
1535 if (strcmp(drvname, "?dhd") == 0) {
1536 sprintf(info.driver, "dhd");
1537 strcpy(info.version, EPI_VERSION_STR);
1540 /* otherwise, require dongle to be up */
1541 else if (!dhd->pub.up) {
1542 DHD_ERROR(("%s: dongle is not up\n", __func__));
1546 /* finally, report dongle driver type */
1547 else if (dhd->pub.iswl)
1548 sprintf(info.driver, "wl");
1550 sprintf(info.driver, "xx");
1552 sprintf(info.version, "%lu", dhd->pub.drv_version);
1553 if (copy_to_user(uaddr, &info, sizeof(info)))
1555 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1556 (int)sizeof(drvname), drvname, info.driver));
1560 /* Get toe offload components from dongle */
1561 case ETHTOOL_GRXCSUM:
1562 case ETHTOOL_GTXCSUM:
1563 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1568 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1571 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1573 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1577 /* Set toe offload components in dongle */
1578 case ETHTOOL_SRXCSUM:
1579 case ETHTOOL_STXCSUM:
1580 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1583 /* Read the current settings, update and write back */
1584 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1589 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1591 if (edata.data != 0)
1592 toe_cmpnt |= csum_dir;
1594 toe_cmpnt &= ~csum_dir;
1596 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1600 /* If setting TX checksum mode, tell Linux the new mode */
1601 if (cmd == ETHTOOL_STXCSUM) {
1603 dhd->iflist[0]->net->features |=
1606 dhd->iflist[0]->net->features &=
1620 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1622 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1629 bool is_set_key_cmd;
1631 ifidx = dhd_net2idx(dhd, net);
1632 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1634 if (ifidx == DHD_BAD_IF)
1637 #if defined(CONFIG_WIRELESS_EXT)
1638 /* linux wireless extensions */
1639 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1640 /* may recurse, do NOT lock */
1641 return wl_iw_ioctl(net, ifr, cmd);
1643 #endif /* defined(CONFIG_WIRELESS_EXT) */
1645 if (cmd == SIOCETHTOOL)
1646 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1648 if (cmd != SIOCDEVPRIVATE)
1651 memset(&ioc, 0, sizeof(ioc));
1653 /* Copy the ioc control structure part of ioctl request */
1654 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1659 /* Copy out any buffer passed */
1661 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1662 /* optimization for direct ioctl calls from kernel */
1664 if (segment_eq(get_fs(), KERNEL_DS)) {
1669 buf = kmalloc(buflen, GFP_ATOMIC);
1674 if (copy_from_user(buf, ioc.buf, buflen)) {
1681 /* To differentiate between wl and dhd read 4 more byes */
1682 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1683 sizeof(uint)) != 0)) {
1688 if (!capable(CAP_NET_ADMIN)) {
1693 /* check for local dhd ioctl and handle it */
1694 if (driver == DHD_IOCTL_MAGIC) {
1695 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1697 dhd->pub.bcmerror = bcmerror;
1701 /* send to dongle (must be up, and wl) */
1702 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1703 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1708 if (!dhd->pub.iswl) {
1713 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1714 * prevent M4 encryption.
1716 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1717 ((ioc.cmd == WLC_SET_VAR) &&
1718 !(strncmp("wsec_key", ioc.buf, 9))) ||
1719 ((ioc.cmd == WLC_SET_VAR) &&
1720 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1722 dhd_wait_pend8021x(net);
1725 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1728 if (!bcmerror && buf && ioc.buf) {
1729 if (copy_to_user(ioc.buf, buf, buflen))
1741 static int dhd_stop(struct net_device *net)
1743 #if !defined(IGNORE_ETH0_DOWN)
1744 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1746 DHD_TRACE(("%s: Enter\n", __func__));
1747 if (IS_CFG80211_FAVORITE()) {
1750 if (dhd->pub.up == 0)
1753 /* Set state and stop OS transmissions */
1755 netif_stop_queue(net);
1757 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1759 #endif /* !defined(IGNORE_ETH0_DOWN) */
1764 static int dhd_open(struct net_device *net)
1766 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1770 int ifidx = dhd_net2idx(dhd, net);
1773 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1775 if (ifidx == 0) { /* do it only for primary eth0 */
1777 /* try to bring up bus */
1778 ret = dhd_bus_start(&dhd->pub);
1780 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1783 atomic_set(&dhd->pend_8021x_cnt, 0);
1785 memcpy(net->dev_addr, dhd->pub.mac, ETH_ALEN);
1788 /* Get current TOE mode from dongle */
1789 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1790 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1791 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1793 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1796 /* Allow transmit calls */
1797 netif_start_queue(net);
1799 if (IS_CFG80211_FAVORITE()) {
1800 if (unlikely(wl_cfg80211_up())) {
1801 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1811 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1812 u8 *mac_addr, u32 flags, u8 bssidx)
1816 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1818 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1820 ifp = dhd->iflist[ifidx];
1821 if (!ifp && !(ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC))) {
1822 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1826 memset(ifp, 0, sizeof(dhd_if_t));
1828 dhd->iflist[ifidx] = ifp;
1829 strlcpy(ifp->name, name, IFNAMSIZ);
1830 if (mac_addr != NULL)
1831 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1833 if (handle == NULL) {
1834 ifp->state = WLC_E_IF_ADD;
1836 ASSERT(dhd->sysioc_tsk);
1837 up(&dhd->sysioc_sem);
1839 ifp->net = (struct net_device *)handle;
1844 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1848 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1850 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1851 ifp = dhd->iflist[ifidx];
1853 DHD_ERROR(("%s: Null interface\n", __func__));
1857 ifp->state = WLC_E_IF_DEL;
1859 ASSERT(dhd->sysioc_tsk);
1860 up(&dhd->sysioc_sem);
1863 dhd_pub_t *dhd_attach(struct dhd_bus *bus, uint bus_hdrlen)
1865 dhd_info_t *dhd = NULL;
1866 struct net_device *net;
1868 DHD_TRACE(("%s: Enter\n", __func__));
1869 /* updates firmware nvram path if it was provided as module
1871 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1872 strcpy(fw_path, firmware_path);
1873 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1874 strcpy(nv_path, nvram_path);
1876 /* Allocate etherdev, including space for private structure */
1877 net = alloc_etherdev(sizeof(dhd));
1879 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1883 /* Allocate primary dhd_info */
1884 dhd = kzalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1886 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1891 * Save the dhd_info into the priv
1893 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1895 /* Set network interface name if it was provided as module parameter */
1896 if (iface_name[0]) {
1899 strncpy(net->name, iface_name, IFNAMSIZ);
1900 net->name[IFNAMSIZ - 1] = 0;
1901 len = strlen(net->name);
1902 ch = net->name[len - 1];
1903 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1904 strcat(net->name, "%d");
1907 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1911 net->netdev_ops = NULL;
1912 sema_init(&dhd->proto_sem, 1);
1913 /* Initialize other structure content */
1914 init_waitqueue_head(&dhd->ioctl_resp_wait);
1915 init_waitqueue_head(&dhd->ctrl_wait);
1917 /* Initialize the spinlocks */
1918 spin_lock_init(&dhd->sdlock);
1919 spin_lock_init(&dhd->txqlock);
1921 /* Link to info module */
1922 dhd->pub.info = dhd;
1924 /* Link to bus module */
1926 dhd->pub.hdrlen = bus_hdrlen;
1928 /* Attach and link in the protocol */
1929 if (dhd_prot_attach(&dhd->pub) != 0) {
1930 DHD_ERROR(("dhd_prot_attach failed\n"));
1933 #if defined(CONFIG_WIRELESS_EXT)
1934 /* Attach and link in the iw */
1935 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1936 DHD_ERROR(("wl_iw_attach failed\n"));
1939 #endif /* defined(CONFIG_WIRELESS_EXT) */
1941 /* Attach and link in the cfg80211 */
1942 if (IS_CFG80211_FAVORITE()) {
1943 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1944 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1948 strcpy(fw_path, wl_cfg80211_get_fwname());
1949 strcpy(nv_path, wl_cfg80211_get_nvramname());
1953 /* Set up the watchdog timer */
1954 init_timer(&dhd->timer);
1955 dhd->timer.data = (unsigned long) dhd;
1956 dhd->timer.function = dhd_watchdog;
1958 /* Initialize thread based operation and lock */
1959 sema_init(&dhd->sdsem, 1);
1960 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1961 dhd->threads_only = true;
1963 dhd->threads_only = false;
1965 if (dhd_dpc_prio >= 0) {
1966 /* Initialize watchdog thread */
1967 sema_init(&dhd->watchdog_sem, 0);
1968 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1970 if (IS_ERR(dhd->watchdog_tsk)) {
1972 "dhd_watchdog thread failed to start\n");
1973 dhd->watchdog_tsk = NULL;
1976 dhd->watchdog_tsk = NULL;
1979 /* Set up the bottom half handler */
1980 if (dhd_dpc_prio >= 0) {
1981 /* Initialize DPC thread */
1982 sema_init(&dhd->dpc_sem, 0);
1983 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
1984 if (IS_ERR(dhd->dpc_tsk)) {
1986 "dhd_dpc thread failed to start\n");
1987 dhd->dpc_tsk = NULL;
1990 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
1991 dhd->dpc_tsk = NULL;
1995 sema_init(&dhd->sysioc_sem, 0);
1996 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
1998 if (IS_ERR(dhd->sysioc_tsk)) {
2000 "_dhd_sysioc thread failed to start\n");
2001 dhd->sysioc_tsk = NULL;
2004 dhd->sysioc_tsk = NULL;
2007 * Save the dhd_info into the priv
2009 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2011 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2014 #if defined(CONFIG_PM_SLEEP)
2015 atomic_set(&dhd_mmc_suspend, false);
2016 if (!IS_CFG80211_FAVORITE())
2017 register_pm_notifier(&dhd_sleep_pm_notifier);
2018 #endif /* defined(CONFIG_PM_SLEEP) */
2019 /* && defined(DHD_GPL) */
2020 /* Init lock suspend to prevent kernel going to suspend */
2021 #ifdef CONFIG_HAS_EARLYSUSPEND
2022 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2023 dhd->early_suspend.suspend = dhd_early_suspend;
2024 dhd->early_suspend.resume = dhd_late_resume;
2025 register_early_suspend(&dhd->early_suspend);
2034 dhd_detach(&dhd->pub);
2039 int dhd_bus_start(dhd_pub_t *dhdp)
2042 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2043 #ifdef EMBEDDED_PLATFORM
2044 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2046 #endif /* EMBEDDED_PLATFORM */
2050 DHD_TRACE(("%s:\n", __func__));
2052 /* try to download image and nvram to the dongle */
2053 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2054 if (!(dhd_bus_download_firmware(dhd->pub.bus,
2055 fw_path, nv_path))) {
2056 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2057 "firmware = %s nvram = %s\n",
2058 __func__, fw_path, nv_path));
2063 /* Start the watchdog timer */
2064 dhd->pub.tickcnt = 0;
2065 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2067 /* Bring up the bus */
2068 ret = dhd_bus_init(&dhd->pub, true);
2070 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2073 #if defined(OOB_INTR_ONLY)
2074 /* Host registration for OOB interrupt */
2075 if (bcmsdh_register_oob_intr(dhdp)) {
2076 del_timer_sync(&dhd->timer);
2077 dhd->wd_timer_valid = false;
2078 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2082 /* Enable oob at firmware */
2083 dhd_enable_oob_intr(dhd->pub.bus, true);
2084 #endif /* defined(OOB_INTR_ONLY) */
2086 /* If bus is not ready, can't come up */
2087 if (dhd->pub.busstate != DHD_BUS_DATA) {
2088 del_timer_sync(&dhd->timer);
2089 dhd->wd_timer_valid = false;
2090 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2093 #ifdef EMBEDDED_PLATFORM
2094 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2096 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2097 memcpy(dhdp->eventmask, iovbuf, WL_EVENTING_MASK_LEN);
2099 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2100 setbit(dhdp->eventmask, WLC_E_PRUNE);
2101 setbit(dhdp->eventmask, WLC_E_AUTH);
2102 setbit(dhdp->eventmask, WLC_E_REASSOC);
2103 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2104 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2105 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2106 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2107 setbit(dhdp->eventmask, WLC_E_JOIN);
2108 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2109 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2110 setbit(dhdp->eventmask, WLC_E_LINK);
2111 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2112 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2113 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2114 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2115 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2116 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2118 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2119 #endif /* PNO_SUPPORT */
2121 /* enable dongle roaming event */
2123 dhdp->pktfilter_count = 1;
2124 /* Setup filter to allow only unicast */
2125 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2126 #endif /* EMBEDDED_PLATFORM */
2128 /* Bus is ready, do any protocol initialization */
2129 ret = dhd_prot_init(&dhd->pub);
2137 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2140 char buf[strlen(name) + 1 + cmd_len];
2141 int len = sizeof(buf);
2145 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2147 memset(&ioc, 0, sizeof(ioc));
2149 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2154 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2155 if (!set && ret >= 0)
2156 memcpy(cmd_buf, buf, cmd_len);
2161 static struct net_device_ops dhd_ops_pri = {
2162 .ndo_open = dhd_open,
2163 .ndo_stop = dhd_stop,
2164 .ndo_get_stats = dhd_get_stats,
2165 .ndo_do_ioctl = dhd_ioctl_entry,
2166 .ndo_start_xmit = dhd_start_xmit,
2167 .ndo_set_mac_address = dhd_set_mac_address,
2168 .ndo_set_multicast_list = dhd_set_multicast_list
2171 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2173 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2174 struct net_device *net;
2175 u8 temp_addr[ETH_ALEN] = {
2176 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2178 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2180 ASSERT(dhd && dhd->iflist[ifidx]);
2182 net = dhd->iflist[ifidx]->net;
2185 ASSERT(!net->netdev_ops);
2186 net->netdev_ops = &dhd_ops_pri;
2189 * We have to use the primary MAC for virtual interfaces
2192 /* for virtual interfaces use the primary MAC */
2193 memcpy(temp_addr, dhd->pub.mac, ETH_ALEN);
2198 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2199 /* ACCESSPOINT INTERFACE CASE */
2200 temp_addr[0] |= 0X02; /* set bit 2 ,
2201 - Locally Administered address */
2204 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2205 net->ethtool_ops = &dhd_ethtool_ops;
2207 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2209 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
2211 if (register_netdev(net) != 0) {
2212 DHD_ERROR(("%s: couldn't register the net device\n",
2217 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
2222 net->netdev_ops = NULL;
2226 void dhd_bus_detach(dhd_pub_t *dhdp)
2230 DHD_TRACE(("%s: Enter\n", __func__));
2233 dhd = (dhd_info_t *) dhdp->info;
2235 /* Stop the protocol module */
2236 dhd_prot_stop(&dhd->pub);
2238 /* Stop the bus module */
2239 dhd_bus_stop(dhd->pub.bus, true);
2240 #if defined(OOB_INTR_ONLY)
2241 bcmsdh_unregister_oob_intr();
2242 #endif /* defined(OOB_INTR_ONLY) */
2244 /* Clear the watchdog timer */
2245 del_timer_sync(&dhd->timer);
2246 dhd->wd_timer_valid = false;
2251 void dhd_detach(dhd_pub_t *dhdp)
2255 DHD_TRACE(("%s: Enter\n", __func__));
2258 dhd = (dhd_info_t *) dhdp->info;
2263 #if defined(CONFIG_HAS_EARLYSUSPEND)
2264 if (dhd->early_suspend.suspend)
2265 unregister_early_suspend(&dhd->early_suspend);
2266 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2268 for (i = 1; i < DHD_MAX_IFS; i++)
2272 ifp = dhd->iflist[0];
2274 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2276 unregister_netdev(ifp->net);
2279 if (dhd->watchdog_tsk) {
2280 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2281 kthread_stop(dhd->watchdog_tsk);
2282 dhd->watchdog_tsk = NULL;
2286 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2287 kthread_stop(dhd->dpc_tsk);
2288 dhd->dpc_tsk = NULL;
2290 tasklet_kill(&dhd->tasklet);
2292 if (dhd->sysioc_tsk) {
2293 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2294 kthread_stop(dhd->sysioc_tsk);
2295 dhd->sysioc_tsk = NULL;
2298 dhd_bus_detach(dhdp);
2301 dhd_prot_detach(dhdp);
2303 #if defined(CONFIG_WIRELESS_EXT)
2305 #endif /* (CONFIG_WIRELESS_EXT) */
2307 if (IS_CFG80211_FAVORITE())
2308 wl_cfg80211_detach();
2310 #if defined(CONFIG_PM_SLEEP)
2311 if (!IS_CFG80211_FAVORITE())
2312 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2313 #endif /* defined(CONFIG_PM_SLEEP) */
2314 /* && defined(DHD_GPL) */
2315 free_netdev(ifp->net);
2322 static void __exit dhd_module_cleanup(void)
2324 DHD_TRACE(("%s: Enter\n", __func__));
2326 dhd_bus_unregister();
2327 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2330 /* Call customer gpio to turn off power with WL_REG_ON signal */
2331 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2334 static int __init dhd_module_init(void)
2338 DHD_TRACE(("%s: Enter\n", __func__));
2340 /* Sanity check on the module parameters */
2342 /* Both watchdog and DPC as tasklets are ok */
2343 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2346 /* If both watchdog and DPC are threads, TX must be deferred */
2347 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2351 DHD_ERROR(("Invalid module parameters.\n"));
2354 /* Call customer gpio to turn on power with WL_REG_ON signal */
2355 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2357 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2358 sema_init(&wifi_control_sem, 0);
2360 error = wifi_add_dev();
2362 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2366 /* Waiting callback after platform_driver_register is done or
2368 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2369 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2375 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2377 error = dhd_bus_register();
2380 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2386 /* turn off power and exit */
2387 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2391 module_init(dhd_module_init);
2392 module_exit(dhd_module_cleanup);
2395 * OS specific functions required to implement DHD driver in OS independent way
2397 int dhd_os_proto_block(dhd_pub_t *pub)
2399 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2402 down(&dhd->proto_sem);
2408 int dhd_os_proto_unblock(dhd_pub_t *pub)
2410 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2413 up(&dhd->proto_sem);
2420 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2422 return (unsigned int)dhd_ioctl_timeout_msec;
2425 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2427 dhd_ioctl_timeout_msec = (int)timeout_msec;
2430 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2432 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2433 DECLARE_WAITQUEUE(wait, current);
2434 int timeout = dhd_ioctl_timeout_msec;
2436 /* Convert timeout in millsecond to jiffies */
2437 timeout = timeout * HZ / 1000;
2439 /* Wait until control frame is available */
2440 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2441 set_current_state(TASK_INTERRUPTIBLE);
2443 while (!(*condition) && (!signal_pending(current) && timeout))
2444 timeout = schedule_timeout(timeout);
2446 if (signal_pending(current))
2449 set_current_state(TASK_RUNNING);
2450 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2455 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2457 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2459 if (waitqueue_active(&dhd->ioctl_resp_wait))
2460 wake_up_interruptible(&dhd->ioctl_resp_wait);
2465 void dhd_os_wd_timer(void *bus, uint wdtick)
2467 dhd_pub_t *pub = bus;
2468 static uint save_dhd_watchdog_ms;
2469 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2471 /* don't start the wd until fw is loaded */
2472 if (pub->busstate == DHD_BUS_DOWN)
2475 /* Totally stop the timer */
2476 if (!wdtick && dhd->wd_timer_valid == true) {
2477 del_timer_sync(&dhd->timer);
2478 dhd->wd_timer_valid = false;
2479 save_dhd_watchdog_ms = wdtick;
2484 dhd_watchdog_ms = (uint) wdtick;
2486 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2488 if (dhd->wd_timer_valid == true)
2489 /* Stop timer and restart at new value */
2490 del_timer_sync(&dhd->timer);
2492 /* Create timer again when watchdog period is
2493 dynamically changed or in the first instance
2495 dhd->timer.expires =
2496 jiffies + dhd_watchdog_ms * HZ / 1000;
2497 add_timer(&dhd->timer);
2500 /* Re arm the timer, at last watchdog period */
2501 mod_timer(&dhd->timer,
2502 jiffies + dhd_watchdog_ms * HZ / 1000);
2505 dhd->wd_timer_valid = true;
2506 save_dhd_watchdog_ms = wdtick;
2510 void *dhd_os_open_image(char *filename)
2514 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2515 return wl_cfg80211_request_fw(filename);
2517 fp = filp_open(filename, O_RDONLY, 0);
2519 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2521 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2530 int dhd_os_get_image_block(char *buf, int len, void *image)
2532 struct file *fp = (struct file *)image;
2535 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2536 return wl_cfg80211_read_fw(buf, len);
2541 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2548 void dhd_os_close_image(void *image)
2550 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2551 return wl_cfg80211_release_fw();
2553 filp_close((struct file *)image, NULL);
2556 void dhd_os_sdlock(dhd_pub_t *pub)
2560 dhd = (dhd_info_t *) (pub->info);
2562 if (dhd->threads_only)
2565 spin_lock_bh(&dhd->sdlock);
2568 void dhd_os_sdunlock(dhd_pub_t *pub)
2572 dhd = (dhd_info_t *) (pub->info);
2574 if (dhd->threads_only)
2577 spin_unlock_bh(&dhd->sdlock);
2580 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2584 dhd = (dhd_info_t *) (pub->info);
2585 spin_lock_bh(&dhd->txqlock);
2588 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2592 dhd = (dhd_info_t *) (pub->info);
2593 spin_unlock_bh(&dhd->txqlock);
2596 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2600 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2604 void dhd_os_sdtxlock(dhd_pub_t *pub)
2609 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2611 dhd_os_sdunlock(pub);
2615 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2616 wl_event_msg_t *event, void **data)
2620 ASSERT(dhd != NULL);
2622 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2626 #if defined(CONFIG_WIRELESS_EXT)
2627 if (!IS_CFG80211_FAVORITE()) {
2628 if ((dhd->iflist[*ifidx] == NULL)
2629 || (dhd->iflist[*ifidx]->net == NULL)) {
2630 DHD_ERROR(("%s Exit null pointer\n", __func__));
2634 if (dhd->iflist[*ifidx]->net)
2635 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2637 #endif /* defined(CONFIG_WIRELESS_EXT) */
2639 if (IS_CFG80211_FAVORITE()) {
2640 ASSERT(dhd->iflist[*ifidx] != NULL);
2641 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2642 if (dhd->iflist[*ifidx]->net)
2643 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2650 /* send up locally generated event */
2651 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2653 switch (be32_to_cpu(event->event_type)) {
2659 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2661 struct dhd_info *dhdinfo = dhd->info;
2662 dhd_os_sdunlock(dhd);
2663 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2664 (*lockvar == false), HZ * 2);
2669 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2671 struct dhd_info *dhdinfo = dhd->info;
2672 if (waitqueue_active(&dhdinfo->ctrl_wait))
2673 wake_up_interruptible(&dhdinfo->ctrl_wait);
2677 int dhd_dev_reset(struct net_device *dev, u8 flag)
2679 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2681 /* Turning off watchdog */
2683 dhd_os_wd_timer(&dhd->pub, 0);
2685 dhd_bus_devreset(&dhd->pub, flag);
2687 /* Turning on watchdog back */
2689 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2690 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2695 int net_os_set_suspend_disable(struct net_device *dev, int val)
2697 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2701 ret = dhd->pub.suspend_disable_flag;
2702 dhd->pub.suspend_disable_flag = val;
2707 int net_os_set_suspend(struct net_device *dev, int val)
2710 #if defined(CONFIG_HAS_EARLYSUSPEND)
2711 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2714 dhd_os_proto_block(&dhd->pub);
2715 ret = dhd_set_suspend(val, &dhd->pub);
2716 dhd_os_proto_unblock(&dhd->pub);
2718 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2722 int net_os_set_dtim_skip(struct net_device *dev, int val)
2724 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2727 dhd->pub.dtim_skip = val;
2732 int net_os_set_packet_filter(struct net_device *dev, int val)
2734 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2737 /* Packet filtering is set only if we still in early-suspend and
2738 * we need either to turn it ON or turn it OFF
2739 * We can always turn it OFF in case of early-suspend, but we turn it
2740 * back ON only if suspend_disable_flag was not set
2742 if (dhd && dhd->pub.up) {
2743 dhd_os_proto_block(&dhd->pub);
2744 if (dhd->pub.in_suspend) {
2745 if (!val || (val && !dhd->pub.suspend_disable_flag))
2746 dhd_set_packet_filter(val, &dhd->pub);
2748 dhd_os_proto_unblock(&dhd->pub);
2753 void dhd_dev_init_ioctl(struct net_device *dev)
2755 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2757 dhd_preinit_ioctls(&dhd->pub);
2761 /* Linux wrapper to call common dhd_pno_clean */
2762 int dhd_dev_pno_reset(struct net_device *dev)
2764 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2766 return dhd_pno_clean(&dhd->pub);
2769 /* Linux wrapper to call common dhd_pno_enable */
2770 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2772 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2774 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2777 /* Linux wrapper to call common dhd_pno_set */
2779 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2780 unsigned char scan_fr)
2782 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2784 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2787 /* Linux wrapper to get pno status */
2788 int dhd_dev_get_pno_status(struct net_device *dev)
2790 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2792 return dhd_pno_get_status(&dhd->pub);
2795 #endif /* PNO_SUPPORT */
2797 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2799 return atomic_read(&dhd->pend_8021x_cnt);
2802 #define MAX_WAIT_FOR_8021X_TX 10
2804 int dhd_wait_pend8021x(struct net_device *dev)
2806 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2807 int timeout = 10 * HZ / 1000;
2808 int ntimes = MAX_WAIT_FOR_8021X_TX;
2809 int pend = dhd_get_pend_8021x_cnt(dhd);
2811 while (ntimes && pend) {
2813 set_current_state(TASK_INTERRUPTIBLE);
2814 schedule_timeout(timeout);
2815 set_current_state(TASK_RUNNING);
2818 pend = dhd_get_pend_8021x_cnt(dhd);
2823 void wl_os_wd_timer(struct net_device *ndev, uint wdtick)
2825 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(ndev);
2827 dhd_os_wd_timer(&dhd->pub, wdtick);
2831 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2835 mm_segment_t old_fs;
2838 /* change to KERNEL_DS address limit */
2842 /* open file to write */
2843 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2845 DHD_ERROR(("%s: open file error\n", __func__));
2850 /* Write buf to file */
2851 fp->f_op->write(fp, buf, size, &pos);
2854 /* free buf before return */
2856 /* close file before return */
2858 filp_close(fp, current->files);
2859 /* restore previous address limit */
2864 #endif /* DHD_DEBUG */