2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifdef CONFIG_WIFI_CONTROL_FUNC
18 #include <linux/platform_device.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <linux/skbuff.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/mmc/sdio_func.h>
28 #include <linux/random.h>
29 #include <linux/spinlock.h>
30 #include <linux/ethtool.h>
31 #include <linux/fcntl.h>
33 #include <linux/uaccess.h>
34 #include <net/cfg80211.h>
36 #include <brcmu_utils.h>
37 #include <brcmu_wifi.h>
39 #include "dngl_stats.h"
42 #include "dhd_proto.h"
44 #include "wl_cfg80211.h"
46 #define EPI_VERSION_STR "4.218.248.5"
47 #define ETH_P_BRCM 0x886c
49 /* Global ASSERT type flag */
52 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
53 #include <linux/wifi_tiwlan.h>
55 struct semaphore wifi_control_sem;
57 struct dhd_bus *g_bus;
59 static struct wifi_platform_data *wifi_control_data;
60 static struct resource *wifi_irqres;
62 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
65 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
66 return (int)wifi_irqres->start;
68 #ifdef CUSTOM_OOB_GPIO_NUM
69 return CUSTOM_OOB_GPIO_NUM;
75 int wifi_set_carddetect(int on)
77 printk(KERN_ERR "%s = %d\n", __func__, on);
78 if (wifi_control_data && wifi_control_data->set_carddetect)
79 wifi_control_data->set_carddetect(on);
83 int wifi_set_power(int on, unsigned long msec)
85 printk(KERN_ERR "%s = %d\n", __func__, on);
86 if (wifi_control_data && wifi_control_data->set_power)
87 wifi_control_data->set_power(on);
93 int wifi_set_reset(int on, unsigned long msec)
95 printk(KERN_ERR "%s = %d\n", __func__, on);
96 if (wifi_control_data && wifi_control_data->set_reset)
97 wifi_control_data->set_reset(on);
103 static int wifi_probe(struct platform_device *pdev)
105 struct wifi_platform_data *wifi_ctrl =
106 (struct wifi_platform_data *)(pdev->dev.platform_data);
108 printk(KERN_ERR "## %s\n", __func__);
110 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
112 wifi_control_data = wifi_ctrl;
114 wifi_set_power(1, 0); /* Power On */
115 wifi_set_carddetect(1); /* CardDetect (0->1) */
117 up(&wifi_control_sem);
121 static int wifi_remove(struct platform_device *pdev)
123 struct wifi_platform_data *wifi_ctrl =
124 (struct wifi_platform_data *)(pdev->dev.platform_data);
126 printk(KERN_ERR "## %s\n", __func__);
127 wifi_control_data = wifi_ctrl;
129 wifi_set_carddetect(0); /* CardDetect (1->0) */
130 wifi_set_power(0, 0); /* Power Off */
132 up(&wifi_control_sem);
136 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
138 DHD_TRACE(("##> %s\n", __func__));
142 static int wifi_resume(struct platform_device *pdev)
144 DHD_TRACE(("##> %s\n", __func__));
148 static struct platform_driver wifi_device = {
150 .remove = wifi_remove,
151 .suspend = wifi_suspend,
152 .resume = wifi_resume,
154 .name = KBUILD_MODNAME,
158 int wifi_add_dev(void)
160 DHD_TRACE(("## Calling platform_driver_register\n"));
161 return platform_driver_register(&wifi_device);
164 void wifi_del_dev(void)
166 DHD_TRACE(("## Unregister platform_driver_register\n"));
167 platform_driver_unregister(&wifi_device);
169 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
171 #if defined(CONFIG_PM_SLEEP)
172 #include <linux/suspend.h>
173 atomic_t dhd_mmc_suspend;
174 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
175 #endif /* defined(CONFIG_PM_SLEEP) */
177 #if defined(OOB_INTR_ONLY)
178 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
179 #endif /* defined(OOB_INTR_ONLY) */
181 MODULE_AUTHOR("Broadcom Corporation");
182 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
183 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
184 MODULE_LICENSE("Dual BSD/GPL");
186 /* 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;
236 /* Thread based operation */
238 struct semaphore sdsem;
239 struct task_struct *watchdog_tsk;
240 struct semaphore watchdog_sem;
241 struct task_struct *dpc_tsk;
242 struct semaphore dpc_sem;
244 /* Thread to issue ioctl for multicast */
245 struct task_struct *sysioc_tsk;
246 struct semaphore sysioc_sem;
249 u8 macvalue[ETH_ALEN];
250 wait_queue_head_t ctrl_wait;
251 atomic_t pend_8021x_cnt;
253 #ifdef CONFIG_HAS_EARLYSUSPEND
254 struct early_suspend early_suspend;
255 #endif /* CONFIG_HAS_EARLYSUSPEND */
258 /* Definitions to provide path to the firmware and nvram
259 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
261 char firmware_path[MOD_PARAM_PATHLEN];
262 char nvram_path[MOD_PARAM_PATHLEN];
264 /* load firmware and/or nvram values from the filesystem */
265 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
266 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
268 /* No firmware required */
270 module_param(dhd_no_fw_req, bool, 0);
273 module_param(dhd_msg_level, int, 0);
275 /* Spawn a thread for system ioctls (set mac, set mcast) */
276 uint dhd_sysioc = true;
277 module_param(dhd_sysioc, uint, 0);
279 /* Watchdog interval */
280 uint dhd_watchdog_ms = 10;
281 module_param(dhd_watchdog_ms, uint, 0);
284 /* Console poll interval */
286 module_param(dhd_console_ms, uint, 0);
287 #endif /* DHD_DEBUG */
289 /* ARP offload agent mode : Enable ARP Host Auto-Reply
290 and ARP Peer Auto-Reply */
291 uint dhd_arp_mode = 0xb;
292 module_param(dhd_arp_mode, uint, 0);
294 /* ARP offload enable */
295 uint dhd_arp_enable = true;
296 module_param(dhd_arp_enable, uint, 0);
298 /* Global Pkt filter enable control */
299 uint dhd_pkt_filter_enable = true;
300 module_param(dhd_pkt_filter_enable, uint, 0);
302 /* Pkt filter init setup */
303 uint dhd_pkt_filter_init;
304 module_param(dhd_pkt_filter_init, uint, 0);
306 /* Pkt filter mode control */
307 uint dhd_master_mode = true;
308 module_param(dhd_master_mode, uint, 1);
310 /* Watchdog thread priority, -1 to use kernel timer */
311 int dhd_watchdog_prio = 97;
312 module_param(dhd_watchdog_prio, int, 0);
314 /* DPC thread priority, -1 to use tasklet */
315 int dhd_dpc_prio = 98;
316 module_param(dhd_dpc_prio, int, 0);
318 /* DPC thread priority, -1 to use tasklet */
319 extern int dhd_dongle_memsize;
320 module_param(dhd_dongle_memsize, int, 0);
322 /* Contorl fw roaming */
329 /* Control radio state */
330 uint dhd_radio_up = 1;
332 /* Network inteface name */
333 char iface_name[IFNAMSIZ] = "wlan";
334 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
336 /* The following are specific to the SDIO dongle */
338 /* IOCTL response timeout */
339 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
341 /* Idle timeout for backplane clock */
342 int dhd_idletime = DHD_IDLETIME_TICKS;
343 module_param(dhd_idletime, int, 0);
347 module_param(dhd_poll, uint, 0);
350 uint dhd_intr = true;
351 module_param(dhd_intr, uint, 0);
353 /* SDIO Drive Strength (in milliamps) */
354 uint dhd_sdiod_drive_strength = 6;
355 module_param(dhd_sdiod_drive_strength, uint, 0);
358 extern uint dhd_txbound;
359 extern uint dhd_rxbound;
360 module_param(dhd_txbound, uint, 0);
361 module_param(dhd_rxbound, uint, 0);
363 /* Deferred transmits */
364 extern uint dhd_deferred_tx;
365 module_param(dhd_deferred_tx, uint, 0);
368 /* Echo packet generator (pkts/s) */
370 module_param(dhd_pktgen, uint, 0);
372 /* Echo packet len (0 => sawtooth, max 2040) */
374 module_param(dhd_pktgen_len, uint, 0);
377 /* Version string to report */
379 #define DHD_COMPILED "\nCompiled in " SRCBASE
384 static void dhd_dpc(unsigned long data);
386 extern int dhd_wait_pend8021x(struct net_device *dev);
390 #error TOE requires BDC
392 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
393 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
396 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
397 wl_event_msg_t *event_ptr, void **data_ptr);
399 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
401 #ifdef PKT_FILTER_SUPPORT
402 DHD_TRACE(("%s: %d\n", __func__, value));
403 /* 1 - Enable packet filter, only allow unicast packet to send up */
404 /* 0 - Disable packet filter */
405 if (dhd_pkt_filter_enable) {
408 for (i = 0; i < dhd->pktfilter_count; i++) {
409 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
410 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
411 value, dhd_master_mode);
417 #if defined(CONFIG_HAS_EARLYSUSPEND)
418 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
420 int power_mode = PM_MAX;
421 /* wl_pkt_filter_enable_t enable_parm; */
426 #endif /* CUSTOMER_HW2 */
428 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
429 __func__, value, dhd->in_suspend));
431 if (dhd && dhd->up) {
432 if (value && dhd->in_suspend) {
434 /* Kernel suspended */
435 DHD_TRACE(("%s: force extra Suspend setting\n",
438 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
442 /* Enable packet filter, only allow unicast
444 dhd_set_packet_filter(1, dhd);
446 /* if dtim skip setup as default force it
447 * to wake each third dtim
448 * for better power saving.
449 * Note that side effect is chance to miss BC/MC
452 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
455 bcn_li_dtim = dhd->dtim_skip;
456 brcmu_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
457 4, iovbuf, sizeof(iovbuf));
458 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
461 /* Disable build-in roaming to allowed \
462 * supplicant to take of romaing
464 brcmu_mkiovar("roam_off", (char *)&roamvar, 4,
465 iovbuf, sizeof(iovbuf));
466 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
468 #endif /* CUSTOMER_HW2 */
472 DHD_TRACE(("%s: Remove extra suspend setting\n",
475 power_mode = PM_FAST;
476 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
480 /* disable pkt filter */
481 dhd_set_packet_filter(0, dhd);
483 /* restore pre-suspend setting for dtim_skip */
484 brcmu_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
485 4, iovbuf, sizeof(iovbuf));
487 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
491 brcmu_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
493 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
495 #endif /* CUSTOMER_HW2 */
502 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
504 dhd_pub_t *dhdp = &dhd->pub;
506 dhd_os_proto_block(dhdp);
507 /* Set flag when early suspend was called */
508 dhdp->in_suspend = val;
509 if (!dhdp->suspend_disable_flag)
510 dhd_set_suspend(val, dhdp);
511 dhd_os_proto_unblock(dhdp);
514 static void dhd_early_suspend(struct early_suspend *h)
516 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
518 DHD_TRACE(("%s: enter\n", __func__));
521 dhd_suspend_resume_helper(dhd, 1);
525 static void dhd_late_resume(struct early_suspend *h)
527 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
529 DHD_TRACE(("%s: enter\n", __func__));
532 dhd_suspend_resume_helper(dhd, 0);
534 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
537 * Generalized timeout mechanism. Uses spin sleep with exponential
539 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
541 * dhd_timeout_start(&tmo, usec);
542 * while (!dhd_timeout_expired(&tmo))
543 * if (poll_something())
545 * if (dhd_timeout_expired(&tmo))
549 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
554 tmo->tick = 1000000 / HZ;
557 int dhd_timeout_expired(dhd_timeout_t *tmo)
559 /* Does nothing the first call */
560 if (tmo->increment == 0) {
565 if (tmo->elapsed >= tmo->limit)
568 /* Add the delay that's about to take place */
569 tmo->elapsed += tmo->increment;
571 if (tmo->increment < tmo->tick) {
572 udelay(tmo->increment);
574 if (tmo->increment > tmo->tick)
575 tmo->increment = tmo->tick;
577 wait_queue_head_t delay_wait;
578 DECLARE_WAITQUEUE(wait, current);
580 init_waitqueue_head(&delay_wait);
581 add_wait_queue(&delay_wait, &wait);
582 set_current_state(TASK_INTERRUPTIBLE);
584 pending = signal_pending(current);
585 remove_wait_queue(&delay_wait, &wait);
586 set_current_state(TASK_RUNNING);
588 return 1; /* Interrupted */
594 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
599 while (i < DHD_MAX_IFS) {
600 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
608 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
614 if (name == NULL || *name == '\0')
619 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
622 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
624 return i; /* default - the primary interface */
627 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
629 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
633 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
634 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
638 if (dhd->iflist[ifidx] == NULL) {
639 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
643 if (dhd->iflist[ifidx]->net)
644 return dhd->iflist[ifidx]->net->name;
649 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
651 struct net_device *dev;
652 struct netdev_hw_addr *ha;
660 ASSERT(dhd && dhd->iflist[ifidx]);
661 dev = dhd->iflist[ifidx]->net;
662 cnt = netdev_mc_count(dev);
664 /* Determine initial value of allmulti flag */
665 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
667 /* Send down the multicast list first. */
669 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
670 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
672 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
673 dhd_ifname(&dhd->pub, ifidx), cnt));
677 strcpy(bufp, "mcast_list");
678 bufp += strlen("mcast_list") + 1;
680 cnt = cpu_to_le32(cnt);
681 memcpy(bufp, &cnt, sizeof(cnt));
684 netdev_for_each_mc_addr(ha, dev) {
687 memcpy(bufp, ha->addr, ETH_ALEN);
692 memset(&ioc, 0, sizeof(ioc));
693 ioc.cmd = WLC_SET_VAR;
698 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
700 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
701 dhd_ifname(&dhd->pub, ifidx), cnt));
702 allmulti = cnt ? true : allmulti;
707 /* Now send the allmulti setting. This is based on the setting in the
708 * net_device flags, but might be modified above to be turned on if we
709 * were trying to set some addresses and dongle rejected it...
712 buflen = sizeof("allmulti") + sizeof(allmulti);
713 buf = kmalloc(buflen, GFP_ATOMIC);
715 DHD_ERROR(("%s: out of memory for allmulti\n",
716 dhd_ifname(&dhd->pub, ifidx)));
719 allmulti = cpu_to_le32(allmulti);
722 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
723 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
724 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
725 (int)sizeof(allmulti), buflen));
730 memset(&ioc, 0, sizeof(ioc));
731 ioc.cmd = WLC_SET_VAR;
736 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
738 DHD_ERROR(("%s: set allmulti %d failed\n",
739 dhd_ifname(&dhd->pub, ifidx),
740 le32_to_cpu(allmulti)));
745 /* Finally, pick up the PROMISC flag as well, like the NIC
748 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
749 allmulti = cpu_to_le32(allmulti);
751 memset(&ioc, 0, sizeof(ioc));
752 ioc.cmd = WLC_SET_PROMISC;
754 ioc.len = sizeof(allmulti);
757 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
759 DHD_ERROR(("%s: set promisc %d failed\n",
760 dhd_ifname(&dhd->pub, ifidx),
761 le32_to_cpu(allmulti)));
766 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, u8 *addr)
772 DHD_TRACE(("%s enter\n", __func__));
774 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
775 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
776 dhd_ifname(&dhd->pub, ifidx)));
779 memset(&ioc, 0, sizeof(ioc));
780 ioc.cmd = WLC_SET_VAR;
785 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
787 DHD_ERROR(("%s: set cur_etheraddr failed\n",
788 dhd_ifname(&dhd->pub, ifidx)));
790 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
797 extern struct net_device *ap_net_dev;
800 static void dhd_op_if(dhd_if_t *ifp)
803 int ret = 0, err = 0;
805 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
809 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
811 switch (ifp->state) {
814 * Delete the existing interface before overwriting it
815 * in case we missed the WLC_E_IF_DEL event.
817 if (ifp->net != NULL) {
818 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
819 "try free & unregister\n",
820 __func__, ifp->net->name));
821 netif_stop_queue(ifp->net);
822 unregister_netdev(ifp->net);
823 free_netdev(ifp->net);
825 /* Allocate etherdev, including space for private structure */
826 ifp->net = alloc_etherdev(sizeof(dhd));
828 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
832 strcpy(ifp->net->name, ifp->name);
833 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
834 err = dhd_net_attach(&dhd->pub, ifp->idx);
836 DHD_ERROR(("%s: dhd_net_attach failed, "
842 /* semaphore that the soft AP CODE
844 extern struct semaphore ap_eth_sema;
846 /* save ptr to wl0.1 netdev for use
848 ap_net_dev = ifp->net;
849 /* signal to the SOFTAP 'sleeper' thread,
853 DHD_TRACE(("\n ==== pid:%x, net_device for "
854 "if:%s created ===\n\n",
855 current->pid, ifp->net->name));
861 if (ifp->net != NULL) {
862 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
864 netif_stop_queue(ifp->net);
865 unregister_netdev(ifp->net);
866 ret = DHD_DEL_IF; /* Make sure the free_netdev()
871 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
878 free_netdev(ifp->net);
880 dhd->iflist[ifp->idx] = NULL;
883 if (ifp->net == ap_net_dev)
884 ap_net_dev = NULL; /* NULL SOFTAP global
890 static int _dhd_sysioc_thread(void *data)
892 dhd_info_t *dhd = (dhd_info_t *) data;
898 allow_signal(SIGTERM);
900 while (down_interruptible(&dhd->sysioc_sem) == 0) {
901 if (kthread_should_stop())
903 for (i = 0; i < DHD_MAX_IFS; i++) {
904 if (dhd->iflist[i]) {
906 in_ap = (ap_net_dev != NULL);
908 if (dhd->iflist[i]->state)
909 dhd_op_if(dhd->iflist[i]);
911 if (dhd->iflist[i] == NULL) {
912 DHD_TRACE(("\n\n %s: interface %d "
913 "removed!\n", __func__, i));
917 if (in_ap && dhd->set_macaddress) {
918 DHD_TRACE(("attempt to set MAC for %s "
919 "in AP Mode," "blocked. \n",
920 dhd->iflist[i]->net->name));
921 dhd->set_macaddress = false;
925 if (in_ap && dhd->set_multicast) {
926 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
927 dhd->iflist[i]->net->name));
928 dhd->set_multicast = false;
932 if (dhd->set_multicast) {
933 dhd->set_multicast = false;
934 _dhd_set_multicast_list(dhd, i);
936 if (dhd->set_macaddress) {
937 dhd->set_macaddress = false;
938 _dhd_set_mac_address(dhd, i,
947 static int dhd_set_mac_address(struct net_device *dev, void *addr)
951 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
952 struct sockaddr *sa = (struct sockaddr *)addr;
955 ifidx = dhd_net2idx(dhd, dev);
956 if (ifidx == DHD_BAD_IF)
959 ASSERT(dhd->sysioc_tsk);
960 memcpy(&dhd->macvalue, sa->sa_data, ETH_ALEN);
961 dhd->set_macaddress = true;
962 up(&dhd->sysioc_sem);
967 static void dhd_set_multicast_list(struct net_device *dev)
969 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
972 ifidx = dhd_net2idx(dhd, dev);
973 if (ifidx == DHD_BAD_IF)
976 ASSERT(dhd->sysioc_tsk);
977 dhd->set_multicast = true;
978 up(&dhd->sysioc_sem);
981 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf)
984 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
987 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
990 /* Update multicast statistic */
991 if (pktbuf->len >= ETH_ALEN) {
992 u8 *pktdata = (u8 *) (pktbuf->data);
993 struct ethhdr *eh = (struct ethhdr *)pktdata;
995 if (is_multicast_ether_addr(eh->h_dest))
996 dhdp->tx_multicast++;
997 if (ntohs(eh->h_proto) == ETH_P_PAE)
998 atomic_inc(&dhd->pend_8021x_cnt);
1001 /* If the protocol uses a data header, apply it */
1002 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1004 /* Use bus module to send data frame */
1006 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1008 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1009 #endif /* BCMDBUS */
1014 static inline void *
1015 osl_pkt_frmnative(struct sk_buff *skb)
1019 #define PKTFRMNATIVE(osh, skb) \
1020 osl_pkt_frmnative((struct sk_buff *)(skb))
1022 static inline struct sk_buff *
1023 osl_pkt_tonative(void *pkt)
1025 return (struct sk_buff *)pkt;
1027 #define PKTTONATIVE(osh, pkt) \
1028 osl_pkt_tonative((pkt))
1030 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1034 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1037 DHD_TRACE(("%s: Enter\n", __func__));
1039 /* Reject if down */
1040 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1041 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1042 __func__, dhd->pub.up, dhd->pub.busstate));
1043 netif_stop_queue(net);
1047 ifidx = dhd_net2idx(dhd, net);
1048 if (ifidx == DHD_BAD_IF) {
1049 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1050 netif_stop_queue(net);
1054 /* Make sure there's enough room for any header */
1055 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1056 struct sk_buff *skb2;
1058 DHD_INFO(("%s: insufficient headroom\n",
1059 dhd_ifname(&dhd->pub, ifidx)));
1060 dhd->pub.tx_realloc++;
1061 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1065 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1066 dhd_ifname(&dhd->pub, ifidx)));
1072 /* Convert to packet */
1073 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1075 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1076 dhd_ifname(&dhd->pub, ifidx)));
1077 dev_kfree_skb_any(skb);
1082 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1086 dhd->pub.dstats.tx_dropped++;
1088 dhd->pub.tx_packets++;
1090 /* Return ok: we always eat the packet */
1094 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1096 struct net_device *net;
1097 dhd_info_t *dhd = dhdp->info;
1099 DHD_TRACE(("%s: Enter\n", __func__));
1101 dhdp->txoff = state;
1102 ASSERT(dhd && dhd->iflist[ifidx]);
1103 net = dhd->iflist[ifidx]->net;
1105 netif_stop_queue(net);
1107 netif_wake_queue(net);
1110 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf,
1113 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1114 struct sk_buff *skb;
1118 struct sk_buff *pnext, *save_pktbuf;
1121 wl_event_msg_t event;
1123 DHD_TRACE(("%s: Enter\n", __func__));
1125 save_pktbuf = pktbuf;
1127 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1129 pnext = pktbuf->next;
1130 pktbuf->next = NULL;
1132 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1134 /* Get the protocol, maintain skb around eth_type_trans()
1135 * The main reason for this hack is for the limitation of
1136 * Linux 2.4 where 'eth_type_trans' uses the
1137 * 'net->hard_header_len'
1138 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1139 * coping of the packet coming from the network stack to add
1140 * BDC, Hardware header etc, during network interface
1142 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1144 * for BDC, Hardware header etc. and not just the ETH_HLEN
1149 ifp = dhd->iflist[ifidx];
1151 ifp = dhd->iflist[0];
1154 skb->dev = ifp->net;
1155 skb->protocol = eth_type_trans(skb, skb->dev);
1157 if (skb->pkt_type == PACKET_MULTICAST)
1158 dhd->pub.rx_multicast++;
1163 /* Strip header, count, deliver upward */
1164 skb_pull(skb, ETH_HLEN);
1166 /* Process special event packets and then discard them */
1167 if (ntohs(skb->protocol) == ETH_P_BRCM)
1168 dhd_wl_host_event(dhd, &ifidx,
1169 skb_mac_header(skb),
1172 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1173 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1174 ifp = dhd->iflist[ifidx];
1177 ifp->net->last_rx = jiffies;
1179 dhdp->dstats.rx_bytes += skb->len;
1180 dhdp->rx_packets++; /* Local count */
1182 if (in_interrupt()) {
1185 /* If the receive is not processed inside an ISR,
1186 * the softirqd must be woken explicitly to service
1187 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1188 * by netif_rx_ni(), but in earlier kernels, we need
1189 * to do it manually.
1196 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1198 /* Linux version has nothing to do */
1202 void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success)
1205 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1209 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1211 eh = (struct ethhdr *)(txp->data);
1212 type = ntohs(eh->h_proto);
1214 if (type == ETH_P_PAE)
1215 atomic_dec(&dhd->pend_8021x_cnt);
1219 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1221 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1225 DHD_TRACE(("%s: Enter\n", __func__));
1227 ifidx = dhd_net2idx(dhd, net);
1228 if (ifidx == DHD_BAD_IF)
1231 ifp = dhd->iflist[ifidx];
1235 /* Use the protocol to get dongle stats */
1236 dhd_prot_dstats(&dhd->pub);
1239 /* Copy dongle stats to net device stats */
1240 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1241 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1242 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1243 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1244 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1245 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1246 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1247 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1248 ifp->stats.multicast = dhd->pub.dstats.multicast;
1253 static int dhd_watchdog_thread(void *data)
1255 dhd_info_t *dhd = (dhd_info_t *) data;
1257 /* This thread doesn't need any user-level access,
1258 * so get rid of all our resources
1261 if (dhd_watchdog_prio > 0) {
1262 struct sched_param param;
1263 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1264 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1265 setScheduler(current, SCHED_FIFO, ¶m);
1267 #endif /* DHD_SCHED */
1269 allow_signal(SIGTERM);
1270 /* Run until signal received */
1272 if (kthread_should_stop())
1274 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1275 if (dhd->pub.dongle_reset == false) {
1276 /* Call the bus module watchdog */
1277 dhd_bus_watchdog(&dhd->pub);
1279 /* Count the tick for reference */
1287 static void dhd_watchdog(unsigned long data)
1289 dhd_info_t *dhd = (dhd_info_t *) data;
1291 if (dhd->watchdog_tsk) {
1292 up(&dhd->watchdog_sem);
1294 /* Reschedule the watchdog */
1295 if (dhd->wd_timer_valid) {
1296 mod_timer(&dhd->timer,
1297 jiffies + dhd_watchdog_ms * HZ / 1000);
1302 /* Call the bus module watchdog */
1303 dhd_bus_watchdog(&dhd->pub);
1305 /* Count the tick for reference */
1308 /* Reschedule the watchdog */
1309 if (dhd->wd_timer_valid)
1310 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1313 static int dhd_dpc_thread(void *data)
1315 dhd_info_t *dhd = (dhd_info_t *) data;
1317 /* This thread doesn't need any user-level access,
1318 * so get rid of all our resources
1321 if (dhd_dpc_prio > 0) {
1322 struct sched_param param;
1323 param.sched_priority =
1325 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1326 setScheduler(current, SCHED_FIFO, ¶m);
1328 #endif /* DHD_SCHED */
1330 allow_signal(SIGTERM);
1331 /* Run until signal received */
1333 if (kthread_should_stop())
1335 if (down_interruptible(&dhd->dpc_sem) == 0) {
1336 /* Call bus dpc unless it indicated down
1337 (then clean stop) */
1338 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1339 if (dhd_bus_dpc(dhd->pub.bus)) {
1343 dhd_bus_stop(dhd->pub.bus, true);
1351 static void dhd_dpc(unsigned long data)
1355 dhd = (dhd_info_t *) data;
1357 /* Call bus dpc unless it indicated down (then clean stop) */
1358 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1359 if (dhd_bus_dpc(dhd->pub.bus))
1360 tasklet_schedule(&dhd->tasklet);
1362 dhd_bus_stop(dhd->pub.bus, true);
1366 void dhd_sched_dpc(dhd_pub_t *dhdp)
1368 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1375 tasklet_schedule(&dhd->tasklet);
1379 /* Retrieve current toe component enables, which are kept
1380 as a bitmap in toe_ol iovar */
1381 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1387 memset(&ioc, 0, sizeof(ioc));
1389 ioc.cmd = WLC_GET_VAR;
1391 ioc.len = (uint) sizeof(buf);
1394 strcpy(buf, "toe_ol");
1395 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1397 /* Check for older dongle image that doesn't support toe_ol */
1399 DHD_ERROR(("%s: toe not supported by device\n",
1400 dhd_ifname(&dhd->pub, ifidx)));
1404 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1405 dhd_ifname(&dhd->pub, ifidx), ret));
1409 memcpy(toe_ol, buf, sizeof(u32));
1413 /* Set current toe component enables in toe_ol iovar,
1414 and set toe global enable iovar */
1415 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1421 memset(&ioc, 0, sizeof(ioc));
1423 ioc.cmd = WLC_SET_VAR;
1425 ioc.len = (uint) sizeof(buf);
1428 /* Set toe_ol as requested */
1430 strcpy(buf, "toe_ol");
1431 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1433 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1435 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1436 dhd_ifname(&dhd->pub, ifidx), ret));
1440 /* Enable toe globally only if any components are enabled. */
1442 toe = (toe_ol != 0);
1445 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1447 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1449 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1450 dhd_ifname(&dhd->pub, ifidx), ret));
1458 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1459 struct ethtool_drvinfo *info)
1461 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1463 sprintf(info->driver, KBUILD_MODNAME);
1464 sprintf(info->version, "%lu", dhd->pub.drv_version);
1465 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1466 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1469 struct ethtool_ops dhd_ethtool_ops = {
1470 .get_drvinfo = dhd_ethtool_get_drvinfo
1473 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1475 struct ethtool_drvinfo info;
1476 char drvname[sizeof(info.driver)];
1479 struct ethtool_value edata;
1480 u32 toe_cmpnt, csum_dir;
1484 DHD_TRACE(("%s: Enter\n", __func__));
1486 /* all ethtool calls start with a cmd word */
1487 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1491 case ETHTOOL_GDRVINFO:
1492 /* Copy out any request driver name */
1493 if (copy_from_user(&info, uaddr, sizeof(info)))
1495 strncpy(drvname, info.driver, sizeof(info.driver));
1496 drvname[sizeof(info.driver) - 1] = '\0';
1498 /* clear struct for return */
1499 memset(&info, 0, sizeof(info));
1502 /* if dhd requested, identify ourselves */
1503 if (strcmp(drvname, "?dhd") == 0) {
1504 sprintf(info.driver, "dhd");
1505 strcpy(info.version, EPI_VERSION_STR);
1508 /* otherwise, require dongle to be up */
1509 else if (!dhd->pub.up) {
1510 DHD_ERROR(("%s: dongle is not up\n", __func__));
1514 /* finally, report dongle driver type */
1515 else if (dhd->pub.iswl)
1516 sprintf(info.driver, "wl");
1518 sprintf(info.driver, "xx");
1520 sprintf(info.version, "%lu", dhd->pub.drv_version);
1521 if (copy_to_user(uaddr, &info, sizeof(info)))
1523 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1524 (int)sizeof(drvname), drvname, info.driver));
1528 /* Get toe offload components from dongle */
1529 case ETHTOOL_GRXCSUM:
1530 case ETHTOOL_GTXCSUM:
1531 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1536 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1539 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1541 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1545 /* Set toe offload components in dongle */
1546 case ETHTOOL_SRXCSUM:
1547 case ETHTOOL_STXCSUM:
1548 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1551 /* Read the current settings, update and write back */
1552 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1557 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1559 if (edata.data != 0)
1560 toe_cmpnt |= csum_dir;
1562 toe_cmpnt &= ~csum_dir;
1564 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1568 /* If setting TX checksum mode, tell Linux the new mode */
1569 if (cmd == ETHTOOL_STXCSUM) {
1571 dhd->iflist[0]->net->features |=
1574 dhd->iflist[0]->net->features &=
1588 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1590 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1597 bool is_set_key_cmd;
1599 ifidx = dhd_net2idx(dhd, net);
1600 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1602 if (ifidx == DHD_BAD_IF)
1605 #if defined(CONFIG_WIRELESS_EXT)
1606 /* linux wireless extensions */
1607 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1608 /* may recurse, do NOT lock */
1609 return wl_iw_ioctl(net, ifr, cmd);
1611 #endif /* defined(CONFIG_WIRELESS_EXT) */
1613 if (cmd == SIOCETHTOOL)
1614 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1616 if (cmd != SIOCDEVPRIVATE)
1619 memset(&ioc, 0, sizeof(ioc));
1621 /* Copy the ioc control structure part of ioctl request */
1622 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1627 /* Copy out any buffer passed */
1629 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1630 /* optimization for direct ioctl calls from kernel */
1632 if (segment_eq(get_fs(), KERNEL_DS)) {
1637 buf = kmalloc(buflen, GFP_ATOMIC);
1642 if (copy_from_user(buf, ioc.buf, buflen)) {
1649 /* To differentiate between wl and dhd read 4 more byes */
1650 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1651 sizeof(uint)) != 0)) {
1656 if (!capable(CAP_NET_ADMIN)) {
1661 /* check for local dhd ioctl and handle it */
1662 if (driver == DHD_IOCTL_MAGIC) {
1663 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1665 dhd->pub.bcmerror = bcmerror;
1669 /* send to dongle (must be up, and wl) */
1670 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1671 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1676 if (!dhd->pub.iswl) {
1681 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1682 * prevent M4 encryption.
1684 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1685 ((ioc.cmd == WLC_SET_VAR) &&
1686 !(strncmp("wsec_key", ioc.buf, 9))) ||
1687 ((ioc.cmd == WLC_SET_VAR) &&
1688 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1690 dhd_wait_pend8021x(net);
1693 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1696 if (!bcmerror && buf && ioc.buf) {
1697 if (copy_to_user(ioc.buf, buf, buflen))
1709 static int dhd_stop(struct net_device *net)
1711 #if !defined(IGNORE_ETH0_DOWN)
1712 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1714 DHD_TRACE(("%s: Enter\n", __func__));
1716 if (dhd->pub.up == 0)
1719 /* Set state and stop OS transmissions */
1721 netif_stop_queue(net);
1723 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1725 #endif /* !defined(IGNORE_ETH0_DOWN) */
1730 static int dhd_open(struct net_device *net)
1732 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1736 int ifidx = dhd_net2idx(dhd, net);
1739 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1741 if (ifidx == 0) { /* do it only for primary eth0 */
1743 /* try to bring up bus */
1744 ret = dhd_bus_start(&dhd->pub);
1746 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1749 atomic_set(&dhd->pend_8021x_cnt, 0);
1751 memcpy(net->dev_addr, dhd->pub.mac, ETH_ALEN);
1754 /* Get current TOE mode from dongle */
1755 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1756 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1757 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1759 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1762 /* Allow transmit calls */
1763 netif_start_queue(net);
1765 if (unlikely(wl_cfg80211_up())) {
1766 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1775 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1776 u8 *mac_addr, u32 flags, u8 bssidx)
1780 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1782 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1784 ifp = dhd->iflist[ifidx];
1786 ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC);
1788 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1793 memset(ifp, 0, sizeof(dhd_if_t));
1795 dhd->iflist[ifidx] = ifp;
1796 strlcpy(ifp->name, name, IFNAMSIZ);
1797 if (mac_addr != NULL)
1798 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1800 if (handle == NULL) {
1801 ifp->state = WLC_E_IF_ADD;
1803 ASSERT(dhd->sysioc_tsk);
1804 up(&dhd->sysioc_sem);
1806 ifp->net = (struct net_device *)handle;
1811 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1815 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1817 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1818 ifp = dhd->iflist[ifidx];
1820 DHD_ERROR(("%s: Null interface\n", __func__));
1824 ifp->state = WLC_E_IF_DEL;
1826 ASSERT(dhd->sysioc_tsk);
1827 up(&dhd->sysioc_sem);
1830 dhd_pub_t *dhd_attach(struct dhd_bus *bus, uint bus_hdrlen)
1832 dhd_info_t *dhd = NULL;
1833 struct net_device *net;
1835 DHD_TRACE(("%s: Enter\n", __func__));
1836 /* updates firmware nvram path if it was provided as module
1838 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1839 strcpy(fw_path, firmware_path);
1840 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1841 strcpy(nv_path, nvram_path);
1843 /* Allocate etherdev, including space for private structure */
1844 net = alloc_etherdev(sizeof(dhd));
1846 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1850 /* Allocate primary dhd_info */
1851 dhd = kzalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1853 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1858 * Save the dhd_info into the priv
1860 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1862 /* Set network interface name if it was provided as module parameter */
1863 if (iface_name[0]) {
1866 strncpy(net->name, iface_name, IFNAMSIZ);
1867 net->name[IFNAMSIZ - 1] = 0;
1868 len = strlen(net->name);
1869 ch = net->name[len - 1];
1870 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1871 strcat(net->name, "%d");
1874 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1878 net->netdev_ops = NULL;
1879 sema_init(&dhd->proto_sem, 1);
1880 /* Initialize other structure content */
1881 init_waitqueue_head(&dhd->ioctl_resp_wait);
1882 init_waitqueue_head(&dhd->ctrl_wait);
1884 /* Initialize the spinlocks */
1885 spin_lock_init(&dhd->sdlock);
1887 /* Link to info module */
1888 dhd->pub.info = dhd;
1890 /* Link to bus module */
1892 dhd->pub.hdrlen = bus_hdrlen;
1894 /* Attach and link in the protocol */
1895 if (dhd_prot_attach(&dhd->pub) != 0) {
1896 DHD_ERROR(("dhd_prot_attach failed\n"));
1899 #if defined(CONFIG_WIRELESS_EXT)
1900 /* Attach and link in the iw */
1901 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1902 DHD_ERROR(("wl_iw_attach failed\n"));
1905 #endif /* defined(CONFIG_WIRELESS_EXT) */
1907 /* Attach and link in the cfg80211 */
1908 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1909 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1912 if (!dhd_no_fw_req) {
1913 strcpy(fw_path, wl_cfg80211_get_fwname());
1914 strcpy(nv_path, wl_cfg80211_get_nvramname());
1917 /* Set up the watchdog timer */
1918 init_timer(&dhd->timer);
1919 dhd->timer.data = (unsigned long) dhd;
1920 dhd->timer.function = dhd_watchdog;
1922 /* Initialize thread based operation and lock */
1923 sema_init(&dhd->sdsem, 1);
1924 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1925 dhd->threads_only = true;
1927 dhd->threads_only = false;
1929 if (dhd_dpc_prio >= 0) {
1930 /* Initialize watchdog thread */
1931 sema_init(&dhd->watchdog_sem, 0);
1932 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1934 if (IS_ERR(dhd->watchdog_tsk)) {
1936 "dhd_watchdog thread failed to start\n");
1937 dhd->watchdog_tsk = NULL;
1940 dhd->watchdog_tsk = NULL;
1943 /* Set up the bottom half handler */
1944 if (dhd_dpc_prio >= 0) {
1945 /* Initialize DPC thread */
1946 sema_init(&dhd->dpc_sem, 0);
1947 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
1948 if (IS_ERR(dhd->dpc_tsk)) {
1950 "dhd_dpc thread failed to start\n");
1951 dhd->dpc_tsk = NULL;
1954 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
1955 dhd->dpc_tsk = NULL;
1959 sema_init(&dhd->sysioc_sem, 0);
1960 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
1962 if (IS_ERR(dhd->sysioc_tsk)) {
1964 "_dhd_sysioc thread failed to start\n");
1965 dhd->sysioc_tsk = NULL;
1968 dhd->sysioc_tsk = NULL;
1971 * Save the dhd_info into the priv
1973 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1975 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
1978 #if defined(CONFIG_PM_SLEEP)
1979 atomic_set(&dhd_mmc_suspend, false);
1980 #endif /* defined(CONFIG_PM_SLEEP) */
1981 /* && defined(DHD_GPL) */
1982 /* Init lock suspend to prevent kernel going to suspend */
1983 #ifdef CONFIG_HAS_EARLYSUSPEND
1984 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
1985 dhd->early_suspend.suspend = dhd_early_suspend;
1986 dhd->early_suspend.resume = dhd_late_resume;
1987 register_early_suspend(&dhd->early_suspend);
1996 dhd_detach(&dhd->pub);
2001 int dhd_bus_start(dhd_pub_t *dhdp)
2004 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2005 #ifdef EMBEDDED_PLATFORM
2006 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2008 #endif /* EMBEDDED_PLATFORM */
2012 DHD_TRACE(("%s:\n", __func__));
2014 /* try to download image and nvram to the dongle */
2015 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2016 if (!(dhd_bus_download_firmware(dhd->pub.bus,
2017 fw_path, nv_path))) {
2018 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2019 "firmware = %s nvram = %s\n",
2020 __func__, fw_path, nv_path));
2025 /* Start the watchdog timer */
2026 dhd->pub.tickcnt = 0;
2027 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2029 /* Bring up the bus */
2030 ret = dhd_bus_init(&dhd->pub, true);
2032 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2035 #if defined(OOB_INTR_ONLY)
2036 /* Host registration for OOB interrupt */
2037 if (bcmsdh_register_oob_intr(dhdp)) {
2038 del_timer_sync(&dhd->timer);
2039 dhd->wd_timer_valid = false;
2040 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2044 /* Enable oob at firmware */
2045 dhd_enable_oob_intr(dhd->pub.bus, true);
2046 #endif /* defined(OOB_INTR_ONLY) */
2048 /* If bus is not ready, can't come up */
2049 if (dhd->pub.busstate != DHD_BUS_DATA) {
2050 del_timer_sync(&dhd->timer);
2051 dhd->wd_timer_valid = false;
2052 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2055 #ifdef EMBEDDED_PLATFORM
2056 brcmu_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN,
2057 iovbuf, sizeof(iovbuf));
2058 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2059 memcpy(dhdp->eventmask, iovbuf, WL_EVENTING_MASK_LEN);
2061 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2062 setbit(dhdp->eventmask, WLC_E_PRUNE);
2063 setbit(dhdp->eventmask, WLC_E_AUTH);
2064 setbit(dhdp->eventmask, WLC_E_REASSOC);
2065 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2066 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2067 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2068 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2069 setbit(dhdp->eventmask, WLC_E_JOIN);
2070 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2071 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2072 setbit(dhdp->eventmask, WLC_E_LINK);
2073 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2074 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2075 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2076 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2077 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2078 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2080 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2081 #endif /* PNO_SUPPORT */
2083 /* enable dongle roaming event */
2085 dhdp->pktfilter_count = 1;
2086 /* Setup filter to allow only unicast */
2087 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2088 #endif /* EMBEDDED_PLATFORM */
2090 /* Bus is ready, do any protocol initialization */
2091 ret = dhd_prot_init(&dhd->pub);
2099 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2102 char buf[strlen(name) + 1 + cmd_len];
2103 int len = sizeof(buf);
2107 len = brcmu_mkiovar(name, cmd_buf, cmd_len, buf, len);
2109 memset(&ioc, 0, sizeof(ioc));
2111 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2116 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2117 if (!set && ret >= 0)
2118 memcpy(cmd_buf, buf, cmd_len);
2123 static struct net_device_ops dhd_ops_pri = {
2124 .ndo_open = dhd_open,
2125 .ndo_stop = dhd_stop,
2126 .ndo_get_stats = dhd_get_stats,
2127 .ndo_do_ioctl = dhd_ioctl_entry,
2128 .ndo_start_xmit = dhd_start_xmit,
2129 .ndo_set_mac_address = dhd_set_mac_address,
2130 .ndo_set_multicast_list = dhd_set_multicast_list
2133 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2135 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2136 struct net_device *net;
2137 u8 temp_addr[ETH_ALEN] = {
2138 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2140 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2142 ASSERT(dhd && dhd->iflist[ifidx]);
2144 net = dhd->iflist[ifidx]->net;
2147 ASSERT(!net->netdev_ops);
2148 net->netdev_ops = &dhd_ops_pri;
2151 * We have to use the primary MAC for virtual interfaces
2154 /* for virtual interfaces use the primary MAC */
2155 memcpy(temp_addr, dhd->pub.mac, ETH_ALEN);
2160 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2161 /* ACCESSPOINT INTERFACE CASE */
2162 temp_addr[0] |= 0X02; /* set bit 2 ,
2163 - Locally Administered address */
2166 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2167 net->ethtool_ops = &dhd_ethtool_ops;
2169 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2171 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
2173 if (register_netdev(net) != 0) {
2174 DHD_ERROR(("%s: couldn't register the net device\n",
2179 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
2184 net->netdev_ops = NULL;
2188 void dhd_bus_detach(dhd_pub_t *dhdp)
2192 DHD_TRACE(("%s: Enter\n", __func__));
2195 dhd = (dhd_info_t *) dhdp->info;
2197 /* Stop the protocol module */
2198 dhd_prot_stop(&dhd->pub);
2200 /* Stop the bus module */
2201 dhd_bus_stop(dhd->pub.bus, true);
2202 #if defined(OOB_INTR_ONLY)
2203 bcmsdh_unregister_oob_intr();
2204 #endif /* defined(OOB_INTR_ONLY) */
2206 /* Clear the watchdog timer */
2207 del_timer_sync(&dhd->timer);
2208 dhd->wd_timer_valid = false;
2213 void dhd_detach(dhd_pub_t *dhdp)
2217 DHD_TRACE(("%s: Enter\n", __func__));
2220 dhd = (dhd_info_t *) dhdp->info;
2225 #if defined(CONFIG_HAS_EARLYSUSPEND)
2226 if (dhd->early_suspend.suspend)
2227 unregister_early_suspend(&dhd->early_suspend);
2228 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2230 for (i = 1; i < DHD_MAX_IFS; i++)
2234 ifp = dhd->iflist[0];
2236 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2238 unregister_netdev(ifp->net);
2241 if (dhd->watchdog_tsk) {
2242 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2243 kthread_stop(dhd->watchdog_tsk);
2244 dhd->watchdog_tsk = NULL;
2248 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2249 kthread_stop(dhd->dpc_tsk);
2250 dhd->dpc_tsk = NULL;
2252 tasklet_kill(&dhd->tasklet);
2254 if (dhd->sysioc_tsk) {
2255 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2256 kthread_stop(dhd->sysioc_tsk);
2257 dhd->sysioc_tsk = NULL;
2260 dhd_bus_detach(dhdp);
2263 dhd_prot_detach(dhdp);
2265 #if defined(CONFIG_WIRELESS_EXT)
2267 #endif /* (CONFIG_WIRELESS_EXT) */
2269 wl_cfg80211_detach();
2271 /* && defined(DHD_GPL) */
2272 free_netdev(ifp->net);
2279 static void __exit dhd_module_cleanup(void)
2281 DHD_TRACE(("%s: Enter\n", __func__));
2283 dhd_bus_unregister();
2284 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2287 /* Call customer gpio to turn off power with WL_REG_ON signal */
2288 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2291 static int __init dhd_module_init(void)
2295 DHD_TRACE(("%s: Enter\n", __func__));
2297 /* Sanity check on the module parameters */
2299 /* Both watchdog and DPC as tasklets are ok */
2300 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2303 /* If both watchdog and DPC are threads, TX must be deferred */
2304 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2308 DHD_ERROR(("Invalid module parameters.\n"));
2311 /* Call customer gpio to turn on power with WL_REG_ON signal */
2312 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2314 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2315 sema_init(&wifi_control_sem, 0);
2317 error = wifi_add_dev();
2319 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2323 /* Waiting callback after platform_driver_register is done or
2325 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2326 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2332 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2334 error = dhd_bus_register();
2337 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2343 /* turn off power and exit */
2344 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2348 module_init(dhd_module_init);
2349 module_exit(dhd_module_cleanup);
2352 * OS specific functions required to implement DHD driver in OS independent way
2354 int dhd_os_proto_block(dhd_pub_t *pub)
2356 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2359 down(&dhd->proto_sem);
2365 int dhd_os_proto_unblock(dhd_pub_t *pub)
2367 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2370 up(&dhd->proto_sem);
2377 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2379 return (unsigned int)dhd_ioctl_timeout_msec;
2382 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2384 dhd_ioctl_timeout_msec = (int)timeout_msec;
2387 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2389 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2390 DECLARE_WAITQUEUE(wait, current);
2391 int timeout = dhd_ioctl_timeout_msec;
2393 /* Convert timeout in millsecond to jiffies */
2394 timeout = timeout * HZ / 1000;
2396 /* Wait until control frame is available */
2397 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2398 set_current_state(TASK_INTERRUPTIBLE);
2400 while (!(*condition) && (!signal_pending(current) && timeout))
2401 timeout = schedule_timeout(timeout);
2403 if (signal_pending(current))
2406 set_current_state(TASK_RUNNING);
2407 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2412 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2414 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2416 if (waitqueue_active(&dhd->ioctl_resp_wait))
2417 wake_up_interruptible(&dhd->ioctl_resp_wait);
2422 void dhd_os_wd_timer(void *bus, uint wdtick)
2424 dhd_pub_t *pub = bus;
2425 static uint save_dhd_watchdog_ms;
2426 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2428 /* don't start the wd until fw is loaded */
2429 if (pub->busstate == DHD_BUS_DOWN)
2432 /* Totally stop the timer */
2433 if (!wdtick && dhd->wd_timer_valid == true) {
2434 del_timer_sync(&dhd->timer);
2435 dhd->wd_timer_valid = false;
2436 save_dhd_watchdog_ms = wdtick;
2441 dhd_watchdog_ms = (uint) wdtick;
2443 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2445 if (dhd->wd_timer_valid == true)
2446 /* Stop timer and restart at new value */
2447 del_timer_sync(&dhd->timer);
2449 /* Create timer again when watchdog period is
2450 dynamically changed or in the first instance
2452 dhd->timer.expires =
2453 jiffies + dhd_watchdog_ms * HZ / 1000;
2454 add_timer(&dhd->timer);
2457 /* Re arm the timer, at last watchdog period */
2458 mod_timer(&dhd->timer,
2459 jiffies + dhd_watchdog_ms * HZ / 1000);
2462 dhd->wd_timer_valid = true;
2463 save_dhd_watchdog_ms = wdtick;
2467 void *dhd_os_open_image(char *filename)
2472 return wl_cfg80211_request_fw(filename);
2474 fp = filp_open(filename, O_RDONLY, 0);
2476 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2478 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2487 int dhd_os_get_image_block(char *buf, int len, void *image)
2489 struct file *fp = (struct file *)image;
2493 return wl_cfg80211_read_fw(buf, len);
2498 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2505 void dhd_os_close_image(void *image)
2508 return wl_cfg80211_release_fw();
2510 filp_close((struct file *)image, NULL);
2513 void dhd_os_sdlock(dhd_pub_t *pub)
2517 dhd = (dhd_info_t *) (pub->info);
2519 if (dhd->threads_only)
2522 spin_lock_bh(&dhd->sdlock);
2525 void dhd_os_sdunlock(dhd_pub_t *pub)
2529 dhd = (dhd_info_t *) (pub->info);
2531 if (dhd->threads_only)
2534 spin_unlock_bh(&dhd->sdlock);
2538 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2539 wl_event_msg_t *event, void **data)
2543 ASSERT(dhd != NULL);
2545 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2549 ASSERT(dhd->iflist[*ifidx] != NULL);
2550 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2551 if (dhd->iflist[*ifidx]->net)
2552 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event, *data);
2557 /* send up locally generated event */
2558 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2560 switch (be32_to_cpu(event->event_type)) {
2566 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2568 struct dhd_info *dhdinfo = dhd->info;
2569 dhd_os_sdunlock(dhd);
2570 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2571 (*lockvar == false), HZ * 2);
2576 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2578 struct dhd_info *dhdinfo = dhd->info;
2579 if (waitqueue_active(&dhdinfo->ctrl_wait))
2580 wake_up_interruptible(&dhdinfo->ctrl_wait);
2584 int dhd_dev_reset(struct net_device *dev, u8 flag)
2586 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2588 /* Turning off watchdog */
2590 dhd_os_wd_timer(&dhd->pub, 0);
2592 dhd_bus_devreset(&dhd->pub, flag);
2594 /* Turning on watchdog back */
2596 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2597 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2602 int net_os_set_suspend_disable(struct net_device *dev, int val)
2604 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2608 ret = dhd->pub.suspend_disable_flag;
2609 dhd->pub.suspend_disable_flag = val;
2614 int net_os_set_suspend(struct net_device *dev, int val)
2617 #if defined(CONFIG_HAS_EARLYSUSPEND)
2618 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2621 dhd_os_proto_block(&dhd->pub);
2622 ret = dhd_set_suspend(val, &dhd->pub);
2623 dhd_os_proto_unblock(&dhd->pub);
2625 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2629 int net_os_set_dtim_skip(struct net_device *dev, int val)
2631 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2634 dhd->pub.dtim_skip = val;
2639 int net_os_set_packet_filter(struct net_device *dev, int val)
2641 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2644 /* Packet filtering is set only if we still in early-suspend and
2645 * we need either to turn it ON or turn it OFF
2646 * We can always turn it OFF in case of early-suspend, but we turn it
2647 * back ON only if suspend_disable_flag was not set
2649 if (dhd && dhd->pub.up) {
2650 dhd_os_proto_block(&dhd->pub);
2651 if (dhd->pub.in_suspend) {
2652 if (!val || (val && !dhd->pub.suspend_disable_flag))
2653 dhd_set_packet_filter(val, &dhd->pub);
2655 dhd_os_proto_unblock(&dhd->pub);
2660 void dhd_dev_init_ioctl(struct net_device *dev)
2662 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2664 dhd_preinit_ioctls(&dhd->pub);
2668 /* Linux wrapper to call common dhd_pno_clean */
2669 int dhd_dev_pno_reset(struct net_device *dev)
2671 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2673 return dhd_pno_clean(&dhd->pub);
2676 /* Linux wrapper to call common dhd_pno_enable */
2677 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2679 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2681 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2684 /* Linux wrapper to call common dhd_pno_set */
2686 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2687 unsigned char scan_fr)
2689 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2691 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2694 /* Linux wrapper to get pno status */
2695 int dhd_dev_get_pno_status(struct net_device *dev)
2697 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2699 return dhd_pno_get_status(&dhd->pub);
2702 #endif /* PNO_SUPPORT */
2704 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2706 return atomic_read(&dhd->pend_8021x_cnt);
2709 #define MAX_WAIT_FOR_8021X_TX 10
2711 int dhd_wait_pend8021x(struct net_device *dev)
2713 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2714 int timeout = 10 * HZ / 1000;
2715 int ntimes = MAX_WAIT_FOR_8021X_TX;
2716 int pend = dhd_get_pend_8021x_cnt(dhd);
2718 while (ntimes && pend) {
2720 set_current_state(TASK_INTERRUPTIBLE);
2721 schedule_timeout(timeout);
2722 set_current_state(TASK_RUNNING);
2725 pend = dhd_get_pend_8021x_cnt(dhd);
2730 void wl_os_wd_timer(struct net_device *ndev, uint wdtick)
2732 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(ndev);
2734 dhd_os_wd_timer(&dhd->pub, wdtick);
2738 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2742 mm_segment_t old_fs;
2745 /* change to KERNEL_DS address limit */
2749 /* open file to write */
2750 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2752 DHD_ERROR(("%s: open file error\n", __func__));
2757 /* Write buf to file */
2758 fp->f_op->write(fp, buf, size, &pos);
2761 /* free buf before return */
2763 /* close file before return */
2765 filp_close(fp, current->files);
2766 /* restore previous address limit */
2771 #endif /* DHD_DEBUG */
2774 void osl_assert(char *exp, char *file, int line)
2779 basename = strrchr(file, '/');
2787 snprintf(tempbuf, 256,
2788 "assertion \"%s\" failed: file \"%s\", line %d\n", exp,
2792 * Print assert message and give it time to
2793 * be written to /var/log/messages
2795 if (!in_interrupt()) {
2796 const int delay = 3;
2797 printk(KERN_ERR "%s", tempbuf);
2798 printk(KERN_ERR "panic in %d seconds\n", delay);
2799 set_current_state(TASK_INTERRUPTIBLE);
2800 schedule_timeout(delay * HZ);
2803 switch (g_assert_type) {
2805 panic(KERN_ERR "%s", tempbuf);
2808 printk(KERN_ERR "%s", tempbuf);
2812 printk(KERN_ERR "%s", tempbuf);
2818 #endif /* defined(BCMDBG) */