2 * Broadcom Dongle Host Driver (DHD), Linux-specific network interface
3 * Basically selected code segments from usb-cdc.c and usb-rndis.c
5 * Copyright (C) 1999-2010, Broadcom Corporation
7 * Unless you and Broadcom execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
25 * $Id: dhd_linux.c,v 1.65.4.9.2.12.2.104 2010/08/20 19:15:40 Exp $
28 #ifdef CONFIG_WIFI_CONTROL_FUNC
29 #include <linux/platform_device.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/slab.h>
38 #include <linux/skbuff.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/random.h>
42 #include <linux/spinlock.h>
43 #include <linux/ethtool.h>
44 #include <linux/fcntl.h>
47 #include <asm/uaccess.h>
48 #include <asm/unaligned.h>
52 #include <bcmendian.h>
54 #include <proto/ethernet.h>
55 #include <dngl_stats.h>
58 #include <dhd_proto.h>
61 #ifdef CONFIG_HAS_WAKELOCK
62 #include <linux/wakelock.h>
64 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
65 #include <linux/wlan_plat.h>
67 struct semaphore wifi_control_sem;
69 struct dhd_bus *g_bus;
71 static struct wifi_platform_data *wifi_control_data = NULL;
72 static struct resource *wifi_irqres = NULL;
74 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
77 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
78 return (int)wifi_irqres->start;
80 #ifdef CUSTOM_OOB_GPIO_NUM
81 return CUSTOM_OOB_GPIO_NUM;
87 int wifi_set_carddetect(int on)
89 printk("%s = %d\n", __FUNCTION__, on);
90 if (wifi_control_data && wifi_control_data->set_carddetect) {
91 wifi_control_data->set_carddetect(on);
96 int wifi_set_power(int on, unsigned long msec)
98 printk("%s = %d\n", __FUNCTION__, on);
99 if (wifi_control_data && wifi_control_data->set_power) {
100 wifi_control_data->set_power(on);
107 int wifi_set_reset(int on, unsigned long msec)
109 printk("%s = %d\n", __FUNCTION__, on);
110 if (wifi_control_data && wifi_control_data->set_reset) {
111 wifi_control_data->set_reset(on);
118 int wifi_get_mac_addr(unsigned char *buf)
120 printk("%s\n", __FUNCTION__);
123 if (wifi_control_data && wifi_control_data->get_mac_addr) {
124 return wifi_control_data->get_mac_addr(buf);
129 static int wifi_probe(struct platform_device *pdev)
131 struct wifi_platform_data *wifi_ctrl =
132 (struct wifi_platform_data *)(pdev->dev.platform_data);
134 DHD_TRACE(("## %s\n", __FUNCTION__));
135 wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcm4329_wlan_irq");
136 wifi_control_data = wifi_ctrl;
138 wifi_set_power(1, 0); /* Power On */
139 wifi_set_carddetect(1); /* CardDetect (0->1) */
141 up(&wifi_control_sem);
145 static int wifi_remove(struct platform_device *pdev)
147 struct wifi_platform_data *wifi_ctrl =
148 (struct wifi_platform_data *)(pdev->dev.platform_data);
150 DHD_TRACE(("## %s\n", __FUNCTION__));
151 wifi_control_data = wifi_ctrl;
153 wifi_set_power(0, 0); /* Power Off */
154 wifi_set_carddetect(0); /* CardDetect (1->0) */
156 up(&wifi_control_sem);
159 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
161 DHD_TRACE(("##> %s\n", __FUNCTION__));
164 static int wifi_resume(struct platform_device *pdev)
166 DHD_TRACE(("##> %s\n", __FUNCTION__));
170 static struct platform_driver wifi_device = {
172 .remove = wifi_remove,
173 .suspend = wifi_suspend,
174 .resume = wifi_resume,
176 .name = "bcm4329_wlan",
180 int wifi_add_dev(void)
182 DHD_TRACE(("## Calling platform_driver_register\n"));
183 return platform_driver_register(&wifi_device);
186 void wifi_del_dev(void)
188 DHD_TRACE(("## Unregister platform_driver_register\n"));
189 platform_driver_unregister(&wifi_device);
191 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
194 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
195 #include <linux/suspend.h>
196 volatile bool dhd_mmc_suspend = FALSE;
197 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
198 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
200 #if defined(OOB_INTR_ONLY)
201 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
202 #endif /* defined(OOB_INTR_ONLY) */
203 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
204 MODULE_LICENSE("GPL v2");
205 #endif /* LinuxVer */
207 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15)
213 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15) */
215 /* Linux wireless extension support */
216 #if defined(CONFIG_WIRELESS_EXT)
218 #endif /* defined(CONFIG_WIRELESS_EXT) */
220 #if defined(CONFIG_HAS_EARLYSUSPEND)
221 #include <linux/earlysuspend.h>
222 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
223 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
225 #ifdef PKT_FILTER_SUPPORT
226 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
227 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
230 /* Interface control information */
231 typedef struct dhd_if {
232 struct dhd_info *info; /* back pointer to dhd_info */
233 /* OS/stack specifics */
234 struct net_device *net;
235 struct net_device_stats stats;
236 int idx; /* iface idx in dongle */
237 int state; /* interface state */
238 uint subunit; /* subunit */
239 uint8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
240 bool attached; /* Delayed attachment when unset */
241 bool txflowcontrol; /* Per interface flow control indicator */
242 char name[IFNAMSIZ+1]; /* linux interface name */
245 /* Local private structure (extension of pub) */
246 typedef struct dhd_info {
247 #if defined(CONFIG_WIRELESS_EXT)
248 wl_iw_t iw; /* wireless extensions state (must be first) */
249 #endif /* defined(CONFIG_WIRELESS_EXT) */
253 /* OS/stack specifics */
254 dhd_if_t *iflist[DHD_MAX_IFS];
256 struct semaphore proto_sem;
257 wait_queue_head_t ioctl_resp_wait;
258 struct timer_list timer;
260 struct tasklet_struct tasklet;
263 /* Thread based operation */
265 struct semaphore sdsem;
267 struct semaphore watchdog_sem;
268 struct completion watchdog_exited;
270 struct semaphore dpc_sem;
271 struct completion dpc_exited;
274 #ifdef CONFIG_HAS_WAKELOCK
275 struct wake_lock wl_wifi; /* Wifi wakelock */
276 struct wake_lock wl_rxwake; /* Wifi rx wakelock */
284 /* Thread to issue ioctl for multicast */
286 struct semaphore sysioc_sem;
287 struct completion sysioc_exited;
290 struct ether_addr macvalue;
291 wait_queue_head_t ctrl_wait;
292 atomic_t pend_8021x_cnt;
294 #ifdef CONFIG_HAS_EARLYSUSPEND
295 struct early_suspend early_suspend;
296 #endif /* CONFIG_HAS_EARLYSUSPEND */
299 /* Definitions to provide path to the firmware and nvram
300 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
302 char firmware_path[MOD_PARAM_PATHLEN];
303 char nvram_path[MOD_PARAM_PATHLEN];
305 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
306 struct semaphore dhd_registration_sem;
307 #define DHD_REGISTRATION_TIMEOUT 8000 /* msec : allowed time to finished dhd registration */
308 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
309 /* load firmware and/or nvram values from the filesystem */
310 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
311 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
314 module_param(dhd_msg_level, int, 0);
316 /* Spawn a thread for system ioctls (set mac, set mcast) */
317 uint dhd_sysioc = TRUE;
318 module_param(dhd_sysioc, uint, 0);
320 /* Watchdog interval */
321 uint dhd_watchdog_ms = 10;
322 module_param(dhd_watchdog_ms, uint, 0);
325 /* Console poll interval */
326 uint dhd_console_ms = 0;
327 module_param(dhd_console_ms, uint, 0);
328 #endif /* DHD_DEBUG */
330 /* ARP offload agent mode : Enable ARP Host Auto-Reply and ARP Peer Auto-Reply */
331 uint dhd_arp_mode = 0xb;
332 module_param(dhd_arp_mode, uint, 0);
334 /* ARP offload enable */
335 uint dhd_arp_enable = TRUE;
336 module_param(dhd_arp_enable, uint, 0);
338 /* Global Pkt filter enable control */
339 uint dhd_pkt_filter_enable = TRUE;
340 module_param(dhd_pkt_filter_enable, uint, 0);
342 /* Pkt filter init setup */
343 uint dhd_pkt_filter_init = 0;
344 module_param(dhd_pkt_filter_init, uint, 0);
346 /* Pkt filter mode control */
347 uint dhd_master_mode = TRUE;
348 module_param(dhd_master_mode, uint, 1);
350 /* Watchdog thread priority, -1 to use kernel timer */
351 int dhd_watchdog_prio = 97;
352 module_param(dhd_watchdog_prio, int, 0);
354 /* DPC thread priority, -1 to use tasklet */
355 int dhd_dpc_prio = 98;
356 module_param(dhd_dpc_prio, int, 0);
358 /* DPC thread priority, -1 to use tasklet */
359 extern int dhd_dongle_memsize;
360 module_param(dhd_dongle_memsize, int, 0);
362 /* Control fw roaming */
369 /* Control radio state */
370 uint dhd_radio_up = 1;
372 /* Network inteface name */
373 char iface_name[IFNAMSIZ];
374 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
376 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
377 #define DAEMONIZE(a) daemonize(a); \
378 allow_signal(SIGKILL); \
379 allow_signal(SIGTERM);
380 #else /* Linux 2.4 (w/o preemption patch) */
381 #define RAISE_RX_SOFTIRQ() \
382 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
383 #define DAEMONIZE(a) daemonize(); \
385 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
387 #endif /* LINUX_VERSION_CODE */
389 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
390 #define BLOCKABLE() (!in_atomic())
392 #define BLOCKABLE() (!in_interrupt())
395 /* The following are specific to the SDIO dongle */
397 /* IOCTL response timeout */
398 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
400 /* Idle timeout for backplane clock */
401 int dhd_idletime = DHD_IDLETIME_TICKS;
402 module_param(dhd_idletime, int, 0);
405 uint dhd_poll = FALSE;
406 module_param(dhd_poll, uint, 0);
409 uint dhd_intr = TRUE;
410 module_param(dhd_intr, uint, 0);
412 /* SDIO Drive Strength (in milliamps) */
413 uint dhd_sdiod_drive_strength = 6;
414 module_param(dhd_sdiod_drive_strength, uint, 0);
417 extern uint dhd_txbound;
418 extern uint dhd_rxbound;
419 module_param(dhd_txbound, uint, 0);
420 module_param(dhd_rxbound, uint, 0);
422 /* Deferred transmits */
423 extern uint dhd_deferred_tx;
424 module_param(dhd_deferred_tx, uint, 0);
429 /* Echo packet generator (pkts/s) */
431 module_param(dhd_pktgen, uint, 0);
433 /* Echo packet len (0 => sawtooth, max 2040) */
434 uint dhd_pktgen_len = 0;
435 module_param(dhd_pktgen_len, uint, 0);
438 /* Version string to report */
441 #define SRCBASE "drivers/net/wireless/bcm4329"
443 #define DHD_COMPILED "\nCompiled in " SRCBASE
448 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
450 "\nCompiled in " SRCBASE " on " __DATE__ " at " __TIME__
455 #if defined(CONFIG_WIRELESS_EXT)
456 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
457 #endif /* defined(CONFIG_WIRELESS_EXT) */
459 static void dhd_dpc(ulong data);
461 extern int dhd_wait_pend8021x(struct net_device *dev);
465 #error TOE requires BDC
467 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
468 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
471 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
472 wl_event_msg_t *event_ptr, void **data_ptr);
474 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
475 static int dhd_sleep_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
477 int ret = NOTIFY_DONE;
480 case PM_HIBERNATION_PREPARE:
481 case PM_SUSPEND_PREPARE:
482 dhd_mmc_suspend = TRUE;
485 case PM_POST_HIBERNATION:
486 case PM_POST_SUSPEND:
487 dhd_mmc_suspend = FALSE;
495 static struct notifier_block dhd_sleep_pm_notifier = {
496 .notifier_call = dhd_sleep_pm_callback,
499 extern int register_pm_notifier(struct notifier_block *nb);
500 extern int unregister_pm_notifier(struct notifier_block *nb);
501 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
503 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
505 #ifdef PKT_FILTER_SUPPORT
506 DHD_TRACE(("%s: %d\n", __FUNCTION__, value));
507 /* 1 - Enable packet filter, only allow unicast packet to send up */
508 /* 0 - Disable packet filter */
509 if (dhd_pkt_filter_enable) {
512 for (i = 0; i < dhd->pktfilter_count; i++) {
513 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
514 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
515 value, dhd_master_mode);
521 #if defined(CONFIG_HAS_EARLYSUSPEND)
522 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
524 int power_mode = PM_MAX;
525 /* wl_pkt_filter_enable_t enable_parm; */
530 #endif /* CUSTOMER_HW2 */
532 DHD_TRACE(("%s: enter, value = %d in_suspend = %d\n",
533 __FUNCTION__, value, dhd->in_suspend));
535 if (dhd && dhd->up) {
536 if (value && dhd->in_suspend) {
538 /* Kernel suspended */
539 DHD_TRACE(("%s: force extra Suspend setting \n", __FUNCTION__));
541 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
542 (char *)&power_mode, sizeof(power_mode));
544 /* Enable packet filter, only allow unicast packet to send up */
545 dhd_set_packet_filter(1, dhd);
547 /* if dtim skip setup as default force it to wake each thrid dtim
548 * for better power saving.
549 * Note that side effect is chance to miss BC/MC packet
551 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
554 bcn_li_dtim = dhd->dtim_skip;
555 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
556 4, iovbuf, sizeof(iovbuf));
557 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
559 /* Disable build-in roaming to allowed ext supplicant to take of romaing */
560 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
561 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
562 #endif /* CUSTOMER_HW2 */
566 DHD_TRACE(("%s: Remove extra suspend setting \n", __FUNCTION__));
568 power_mode = PM_FAST;
569 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
572 /* disable pkt filter */
573 dhd_set_packet_filter(0, dhd);
575 /* restore pre-suspend setting for dtim_skip */
576 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
577 4, iovbuf, sizeof(iovbuf));
579 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
582 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
583 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
584 #endif /* CUSTOMER_HW2 */
591 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
593 dhd_pub_t *dhdp = &dhd->pub;
595 dhd_os_wake_lock(dhdp);
596 dhd_os_proto_block(dhdp);
597 /* Set flag when early suspend was called */
598 dhdp->in_suspend = val;
599 if (!dhdp->suspend_disable_flag)
600 dhd_set_suspend(val, dhdp);
601 dhd_os_proto_unblock(dhdp);
602 dhd_os_wake_unlock(dhdp);
605 static void dhd_early_suspend(struct early_suspend *h)
607 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
609 DHD_TRACE(("%s: enter\n", __FUNCTION__));
612 dhd_suspend_resume_helper(dhd, 1);
615 static void dhd_late_resume(struct early_suspend *h)
617 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
619 DHD_TRACE(("%s: enter\n", __FUNCTION__));
622 dhd_suspend_resume_helper(dhd, 0);
624 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
627 * Generalized timeout mechanism. Uses spin sleep with exponential back-off until
628 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
630 * dhd_timeout_start(&tmo, usec);
631 * while (!dhd_timeout_expired(&tmo))
632 * if (poll_something())
634 * if (dhd_timeout_expired(&tmo))
639 dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
644 tmo->tick = 1000000 / HZ;
648 dhd_timeout_expired(dhd_timeout_t *tmo)
650 /* Does nothing the first call */
651 if (tmo->increment == 0) {
656 if (tmo->elapsed >= tmo->limit)
659 /* Add the delay that's about to take place */
660 tmo->elapsed += tmo->increment;
662 if (tmo->increment < tmo->tick) {
663 OSL_DELAY(tmo->increment);
665 if (tmo->increment > tmo->tick)
666 tmo->increment = tmo->tick;
668 wait_queue_head_t delay_wait;
669 DECLARE_WAITQUEUE(wait, current);
671 init_waitqueue_head(&delay_wait);
672 add_wait_queue(&delay_wait, &wait);
673 set_current_state(TASK_INTERRUPTIBLE);
675 pending = signal_pending(current);
676 remove_wait_queue(&delay_wait, &wait);
677 set_current_state(TASK_RUNNING);
679 return 1; /* Interrupted */
686 dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
691 while (i < DHD_MAX_IFS) {
692 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
701 dhd_ifname2idx(dhd_info_t *dhd, char *name)
707 if (name == NULL || *name == '\0')
711 if (dhd->iflist[i] && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
714 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __FUNCTION__, i, name));
716 return i; /* default - the primary interface */
720 dhd_ifname(dhd_pub_t *dhdp, int ifidx)
722 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
726 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
727 DHD_ERROR(("%s: ifidx %d out of range\n", __FUNCTION__, ifidx));
731 if (dhd->iflist[ifidx] == NULL) {
732 DHD_ERROR(("%s: null i/f %d\n", __FUNCTION__, ifidx));
736 if (dhd->iflist[ifidx]->net)
737 return dhd->iflist[ifidx]->net->name;
743 _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
745 struct net_device *dev;
746 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
747 struct netdev_hw_addr *ha;
749 struct dev_mc_list *mclist;
751 uint32 allmulti, cnt;
758 ASSERT(dhd && dhd->iflist[ifidx]);
759 dev = dhd->iflist[ifidx]->net;
761 netif_addr_lock_bh(dev);
762 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
763 cnt = netdev_mc_count(dev);
767 netif_addr_unlock_bh(dev);
769 /* Determine initial value of allmulti flag */
770 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
772 /* Send down the multicast list first. */
773 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
774 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
775 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
776 dhd_ifname(&dhd->pub, ifidx), cnt));
780 strcpy(bufp, "mcast_list");
781 bufp += strlen("mcast_list") + 1;
784 memcpy(bufp, &cnt, sizeof(cnt));
787 netif_addr_lock_bh(dev);
788 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
789 netdev_for_each_mc_addr(ha, dev) {
792 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
793 bufp += ETHER_ADDR_LEN;
797 for (mclist = dev->mc_list;(mclist && (cnt > 0)); cnt--, mclist = mclist->next) {
798 memcpy(bufp, (void *)mclist->dmi_addr, ETHER_ADDR_LEN);
799 bufp += ETHER_ADDR_LEN;
802 netif_addr_unlock_bh(dev);
804 memset(&ioc, 0, sizeof(ioc));
805 ioc.cmd = WLC_SET_VAR;
810 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
812 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
813 dhd_ifname(&dhd->pub, ifidx), cnt));
814 allmulti = cnt ? TRUE : allmulti;
817 MFREE(dhd->pub.osh, buf, buflen);
819 /* Now send the allmulti setting. This is based on the setting in the
820 * net_device flags, but might be modified above to be turned on if we
821 * were trying to set some addresses and dongle rejected it...
824 buflen = sizeof("allmulti") + sizeof(allmulti);
825 if (!(buf = MALLOC(dhd->pub.osh, buflen))) {
826 DHD_ERROR(("%s: out of memory for allmulti\n", dhd_ifname(&dhd->pub, ifidx)));
829 allmulti = htol32(allmulti);
831 if (!bcm_mkiovar("allmulti", (void*)&allmulti, sizeof(allmulti), buf, buflen)) {
832 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
833 dhd_ifname(&dhd->pub, ifidx), (int)sizeof(allmulti), buflen));
834 MFREE(dhd->pub.osh, buf, buflen);
839 memset(&ioc, 0, sizeof(ioc));
840 ioc.cmd = WLC_SET_VAR;
845 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
847 DHD_ERROR(("%s: set allmulti %d failed\n",
848 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
851 MFREE(dhd->pub.osh, buf, buflen);
853 /* Finally, pick up the PROMISC flag as well, like the NIC driver does */
855 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
856 allmulti = htol32(allmulti);
858 memset(&ioc, 0, sizeof(ioc));
859 ioc.cmd = WLC_SET_PROMISC;
861 ioc.len = sizeof(allmulti);
864 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
866 DHD_ERROR(("%s: set promisc %d failed\n",
867 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
872 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
878 DHD_TRACE(("%s enter\n", __FUNCTION__));
879 if (!bcm_mkiovar("cur_etheraddr", (char*)addr, ETHER_ADDR_LEN, buf, 32)) {
880 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", dhd_ifname(&dhd->pub, ifidx)));
883 memset(&ioc, 0, sizeof(ioc));
884 ioc.cmd = WLC_SET_VAR;
889 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
891 DHD_ERROR(("%s: set cur_etheraddr failed\n", dhd_ifname(&dhd->pub, ifidx)));
893 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
900 extern struct net_device *ap_net_dev;
904 dhd_op_if(dhd_if_t *ifp)
907 int ret = 0, err = 0;
909 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
913 DHD_TRACE(("%s: idx %d, state %d\n", __FUNCTION__, ifp->idx, ifp->state));
915 switch (ifp->state) {
918 * Delete the existing interface before overwriting it
919 * in case we missed the WLC_E_IF_DEL event.
921 if (ifp->net != NULL) {
922 DHD_ERROR(("%s: ERROR: netdev:%s already exists, try free & unregister \n",
923 __FUNCTION__, ifp->net->name));
924 netif_stop_queue(ifp->net);
925 unregister_netdev(ifp->net);
926 free_netdev(ifp->net);
928 /* Allocate etherdev, including space for private structure */
929 if (!(ifp->net = alloc_etherdev(sizeof(dhd)))) {
930 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
934 strcpy(ifp->net->name, ifp->name);
935 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
936 if ((err = dhd_net_attach(&dhd->pub, ifp->idx)) != 0) {
937 DHD_ERROR(("%s: dhd_net_attach failed, err %d\n",
942 /* semaphore that the soft AP CODE waits on */
943 extern struct semaphore ap_eth_sema;
945 /* save ptr to wl0.1 netdev for use in wl_iw.c */
946 ap_net_dev = ifp->net;
947 /* signal to the SOFTAP 'sleeper' thread, wl0.1 is ready */
950 DHD_TRACE(("\n ==== pid:%x, net_device for if:%s created ===\n\n",
951 current->pid, ifp->net->name));
957 if (ifp->net != NULL) {
958 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n", __FUNCTION__));
959 netif_stop_queue(ifp->net);
960 unregister_netdev(ifp->net);
961 ret = DHD_DEL_IF; /* Make sure the free_netdev() is called */
965 DHD_ERROR(("%s: bad op %d\n", __FUNCTION__, ifp->state));
972 free_netdev(ifp->net);
974 dhd->iflist[ifp->idx] = NULL;
975 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
977 if (ifp->net == ap_net_dev)
978 ap_net_dev = NULL; /* NULL SOFTAP global as well */
984 _dhd_sysioc_thread(void *data)
986 dhd_info_t *dhd = (dhd_info_t *)data;
992 DAEMONIZE("dhd_sysioc");
994 while (down_interruptible(&dhd->sysioc_sem) == 0) {
995 dhd_os_wake_lock(&dhd->pub);
996 for (i = 0; i < DHD_MAX_IFS; i++) {
997 if (dhd->iflist[i]) {
999 in_ap = (ap_net_dev != NULL);
1001 if (dhd->iflist[i]->state)
1002 dhd_op_if(dhd->iflist[i]);
1004 if (dhd->iflist[i] == NULL) {
1005 DHD_TRACE(("%s: interface %d just been removed!\n\n", __FUNCTION__, i));
1009 if (in_ap && dhd->set_macaddress) {
1010 DHD_TRACE(("attempt to set MAC for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
1011 dhd->set_macaddress = FALSE;
1015 if (in_ap && dhd->set_multicast) {
1016 DHD_TRACE(("attempt to set MULTICAST list for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
1017 dhd->set_multicast = FALSE;
1021 if (dhd->set_multicast) {
1022 dhd->set_multicast = FALSE;
1023 _dhd_set_multicast_list(dhd, i);
1025 if (dhd->set_macaddress) {
1026 dhd->set_macaddress = FALSE;
1027 _dhd_set_mac_address(dhd, i, &dhd->macvalue);
1031 dhd_os_wake_unlock(&dhd->pub);
1033 complete_and_exit(&dhd->sysioc_exited, 0);
1037 dhd_set_mac_address(struct net_device *dev, void *addr)
1041 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1042 struct sockaddr *sa = (struct sockaddr *)addr;
1045 ifidx = dhd_net2idx(dhd, dev);
1046 if (ifidx == DHD_BAD_IF)
1049 ASSERT(dhd->sysioc_pid >= 0);
1050 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1051 dhd->set_macaddress = TRUE;
1052 up(&dhd->sysioc_sem);
1058 dhd_set_multicast_list(struct net_device *dev)
1060 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1063 ifidx = dhd_net2idx(dhd, dev);
1064 if (ifidx == DHD_BAD_IF)
1067 ASSERT(dhd->sysioc_pid >= 0);
1068 dhd->set_multicast = TRUE;
1069 up(&dhd->sysioc_sem);
1073 dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1076 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1078 /* Reject if down */
1079 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN)) {
1083 /* Update multicast statistic */
1084 if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_ADDR_LEN) {
1085 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
1086 struct ether_header *eh = (struct ether_header *)pktdata;
1088 if (ETHER_ISMULTI(eh->ether_dhost))
1089 dhdp->tx_multicast++;
1090 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1091 atomic_inc(&dhd->pend_8021x_cnt);
1094 /* Look into the packet and update the packet priority */
1095 if ((PKTPRIO(pktbuf) == 0))
1096 pktsetprio(pktbuf, FALSE);
1098 /* If the protocol uses a data header, apply it */
1099 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1101 /* Use bus module to send data frame */
1103 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1105 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1106 #endif /* BCMDBUS */
1112 dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1116 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1119 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1121 dhd_os_wake_lock(&dhd->pub);
1123 /* Reject if down */
1124 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1125 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1126 __FUNCTION__, dhd->pub.up, dhd->pub.busstate));
1127 netif_stop_queue(net);
1128 /* Send Event when bus down detected during data session */
1129 if (dhd->pub.busstate == DHD_BUS_DOWN) {
1130 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1131 net_os_send_hang_message(net);
1133 dhd_os_wake_unlock(&dhd->pub);
1137 ifidx = dhd_net2idx(dhd, net);
1138 if (ifidx == DHD_BAD_IF) {
1139 DHD_ERROR(("%s: bad ifidx %d\n", __FUNCTION__, ifidx));
1140 netif_stop_queue(net);
1141 dhd_os_wake_unlock(&dhd->pub);
1145 /* Make sure there's enough room for any header */
1146 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1147 struct sk_buff *skb2;
1149 DHD_INFO(("%s: insufficient headroom\n",
1150 dhd_ifname(&dhd->pub, ifidx)));
1151 dhd->pub.tx_realloc++;
1152 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1154 if ((skb = skb2) == NULL) {
1155 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1156 dhd_ifname(&dhd->pub, ifidx)));
1162 /* Convert to packet */
1163 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
1164 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1165 dhd_ifname(&dhd->pub, ifidx)));
1166 dev_kfree_skb_any(skb);
1171 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1175 dhd->pub.dstats.tx_dropped++;
1177 dhd->pub.tx_packets++;
1179 dhd_os_wake_unlock(&dhd->pub);
1181 /* Return ok: we always eat the packet */
1186 dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1188 struct net_device *net;
1189 dhd_info_t *dhd = dhdp->info;
1191 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1193 dhdp->txoff = state;
1194 ASSERT(dhd && dhd->iflist[ifidx]);
1195 net = dhd->iflist[ifidx]->net;
1197 netif_stop_queue(net);
1199 netif_wake_queue(net);
1203 dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1205 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1206 struct sk_buff *skb;
1209 void * data, *pnext, *save_pktbuf;
1212 wl_event_msg_t event;
1214 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1216 save_pktbuf = pktbuf;
1218 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1220 pnext = PKTNEXT(dhdp->osh, pktbuf);
1221 PKTSETNEXT(wl->sh.osh, pktbuf, NULL);
1224 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1226 /* Get the protocol, maintain skb around eth_type_trans()
1227 * The main reason for this hack is for the limitation of
1228 * Linux 2.4 where 'eth_type_trans' uses the 'net->hard_header_len'
1229 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1230 * coping of the packet coming from the network stack to add
1231 * BDC, Hardware header etc, during network interface registration
1232 * we set the 'net->hard_header_len' to ETH_HLEN + extra space required
1233 * for BDC, Hardware header etc. and not just the ETH_HLEN
1238 ifp = dhd->iflist[ifidx];
1240 ifp = dhd->iflist[0];
1243 skb->dev = ifp->net;
1244 skb->protocol = eth_type_trans(skb, skb->dev);
1246 if (skb->pkt_type == PACKET_MULTICAST) {
1247 dhd->pub.rx_multicast++;
1253 /* Strip header, count, deliver upward */
1254 skb_pull(skb, ETH_HLEN);
1256 /* Process special event packets and then discard them */
1257 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1258 dhd_wl_host_event(dhd, &ifidx,
1259 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1267 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1268 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1269 ifp = dhd->iflist[ifidx];
1272 ifp->net->last_rx = jiffies;
1274 dhdp->dstats.rx_bytes += skb->len;
1275 dhdp->rx_packets++; /* Local count */
1277 if (in_interrupt()) {
1280 /* If the receive is not processed inside an ISR,
1281 * the softirqd must be woken explicitly to service
1282 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1283 * by netif_rx_ni(), but in earlier kernels, we need
1284 * to do it manually.
1286 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1291 local_irq_save(flags);
1293 local_irq_restore(flags);
1294 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
1297 dhd_os_wake_lock_timeout_enable(dhdp);
1301 dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1303 /* Linux version has nothing to do */
1308 dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1311 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1312 struct ether_header *eh;
1315 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1317 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
1318 type = ntoh16(eh->ether_type);
1320 if (type == ETHER_TYPE_802_1X)
1321 atomic_dec(&dhd->pend_8021x_cnt);
1325 static struct net_device_stats *
1326 dhd_get_stats(struct net_device *net)
1328 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1332 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1334 ifidx = dhd_net2idx(dhd, net);
1335 if (ifidx == DHD_BAD_IF)
1338 ifp = dhd->iflist[ifidx];
1342 /* Use the protocol to get dongle stats */
1343 dhd_prot_dstats(&dhd->pub);
1346 /* Copy dongle stats to net device stats */
1347 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1348 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1349 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1350 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1351 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1352 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1353 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1354 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1355 ifp->stats.multicast = dhd->pub.dstats.multicast;
1361 dhd_watchdog_thread(void *data)
1363 dhd_info_t *dhd = (dhd_info_t *)data;
1365 /* This thread doesn't need any user-level access,
1366 * so get rid of all our resources
1369 if (dhd_watchdog_prio > 0) {
1370 struct sched_param param;
1371 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO)?
1372 dhd_watchdog_prio:(MAX_RT_PRIO-1);
1373 setScheduler(current, SCHED_FIFO, ¶m);
1375 #endif /* DHD_SCHED */
1377 DAEMONIZE("dhd_watchdog");
1379 /* Run until signal received */
1381 if (down_interruptible (&dhd->watchdog_sem) == 0) {
1382 dhd_os_wake_lock(&dhd->pub);
1384 if (dhd->pub.dongle_reset == FALSE) {
1385 /* Call the bus module watchdog */
1386 dhd_bus_watchdog(&dhd->pub);
1388 /* Count the tick for reference */
1391 /* Reschedule the watchdog */
1392 if (dhd->wd_timer_valid) {
1393 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1395 dhd_os_wake_unlock(&dhd->pub);
1401 complete_and_exit(&dhd->watchdog_exited, 0);
1405 dhd_watchdog(ulong data)
1407 dhd_info_t *dhd = (dhd_info_t *)data;
1409 if (dhd->watchdog_pid >= 0) {
1410 up(&dhd->watchdog_sem);
1414 /* Call the bus module watchdog */
1415 dhd_bus_watchdog(&dhd->pub);
1417 /* Count the tick for reference */
1420 /* Reschedule the watchdog */
1421 if (dhd->wd_timer_valid)
1422 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1426 dhd_dpc_thread(void *data)
1428 dhd_info_t *dhd = (dhd_info_t *)data;
1430 /* This thread doesn't need any user-level access,
1431 * so get rid of all our resources
1434 if (dhd_dpc_prio > 0)
1436 struct sched_param param;
1437 param.sched_priority = (dhd_dpc_prio < MAX_RT_PRIO)?dhd_dpc_prio:(MAX_RT_PRIO-1);
1438 setScheduler(current, SCHED_FIFO, ¶m);
1440 #endif /* DHD_SCHED */
1442 DAEMONIZE("dhd_dpc");
1444 /* Run until signal received */
1446 if (down_interruptible(&dhd->dpc_sem) == 0) {
1447 /* Call bus dpc unless it indicated down (then clean stop) */
1448 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1449 if (dhd_bus_dpc(dhd->pub.bus)) {
1453 dhd_os_wake_unlock(&dhd->pub);
1456 dhd_bus_stop(dhd->pub.bus, TRUE);
1457 dhd_os_wake_unlock(&dhd->pub);
1464 complete_and_exit(&dhd->dpc_exited, 0);
1472 dhd = (dhd_info_t *)data;
1474 /* Call bus dpc unless it indicated down (then clean stop) */
1475 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1476 if (dhd_bus_dpc(dhd->pub.bus))
1477 tasklet_schedule(&dhd->tasklet);
1479 dhd_bus_stop(dhd->pub.bus, TRUE);
1484 dhd_sched_dpc(dhd_pub_t *dhdp)
1486 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1488 dhd_os_wake_lock(dhdp);
1489 if (dhd->dpc_pid >= 0) {
1494 tasklet_schedule(&dhd->tasklet);
1498 /* Retrieve current toe component enables, which are kept as a bitmap in toe_ol iovar */
1500 dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
1506 memset(&ioc, 0, sizeof(ioc));
1508 ioc.cmd = WLC_GET_VAR;
1510 ioc.len = (uint)sizeof(buf);
1513 strcpy(buf, "toe_ol");
1514 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1515 /* Check for older dongle image that doesn't support toe_ol */
1517 DHD_ERROR(("%s: toe not supported by device\n",
1518 dhd_ifname(&dhd->pub, ifidx)));
1522 DHD_INFO(("%s: could not get toe_ol: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1526 memcpy(toe_ol, buf, sizeof(uint32));
1530 /* Set current toe component enables in toe_ol iovar, and set toe global enable iovar */
1532 dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
1538 memset(&ioc, 0, sizeof(ioc));
1540 ioc.cmd = WLC_SET_VAR;
1542 ioc.len = (uint)sizeof(buf);
1545 /* Set toe_ol as requested */
1547 strcpy(buf, "toe_ol");
1548 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
1550 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1551 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1552 dhd_ifname(&dhd->pub, ifidx), ret));
1556 /* Enable toe globally only if any components are enabled. */
1558 toe = (toe_ol != 0);
1561 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
1563 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1564 DHD_ERROR(("%s: could not set toe: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1572 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1573 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1574 struct ethtool_drvinfo *info)
1576 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1578 sprintf(info->driver, "wl");
1579 sprintf(info->version, "%lu", dhd->pub.drv_version);
1582 struct ethtool_ops dhd_ethtool_ops = {
1583 .get_drvinfo = dhd_ethtool_get_drvinfo
1585 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
1588 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1590 dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1592 struct ethtool_drvinfo info;
1593 char drvname[sizeof(info.driver)];
1596 struct ethtool_value edata;
1597 uint32 toe_cmpnt, csum_dir;
1601 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1603 /* all ethtool calls start with a cmd word */
1604 if (copy_from_user(&cmd, uaddr, sizeof (uint32)))
1608 case ETHTOOL_GDRVINFO:
1609 /* Copy out any request driver name */
1610 if (copy_from_user(&info, uaddr, sizeof(info)))
1612 strncpy(drvname, info.driver, sizeof(info.driver));
1613 drvname[sizeof(info.driver)-1] = '\0';
1615 /* clear struct for return */
1616 memset(&info, 0, sizeof(info));
1619 /* if dhd requested, identify ourselves */
1620 if (strcmp(drvname, "?dhd") == 0) {
1621 sprintf(info.driver, "dhd");
1622 strcpy(info.version, EPI_VERSION_STR);
1625 /* otherwise, require dongle to be up */
1626 else if (!dhd->pub.up) {
1627 DHD_ERROR(("%s: dongle is not up\n", __FUNCTION__));
1631 /* finally, report dongle driver type */
1632 else if (dhd->pub.iswl)
1633 sprintf(info.driver, "wl");
1635 sprintf(info.driver, "xx");
1637 sprintf(info.version, "%lu", dhd->pub.drv_version);
1638 if (copy_to_user(uaddr, &info, sizeof(info)))
1640 DHD_CTL(("%s: given %*s, returning %s\n", __FUNCTION__,
1641 (int)sizeof(drvname), drvname, info.driver));
1645 /* Get toe offload components from dongle */
1646 case ETHTOOL_GRXCSUM:
1647 case ETHTOOL_GTXCSUM:
1648 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1651 csum_dir = (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1654 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1656 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1660 /* Set toe offload components in dongle */
1661 case ETHTOOL_SRXCSUM:
1662 case ETHTOOL_STXCSUM:
1663 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1666 /* Read the current settings, update and write back */
1667 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1670 csum_dir = (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1672 if (edata.data != 0)
1673 toe_cmpnt |= csum_dir;
1675 toe_cmpnt &= ~csum_dir;
1677 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
1680 /* If setting TX checksum mode, tell Linux the new mode */
1681 if (cmd == ETHTOOL_STXCSUM) {
1683 dhd->iflist[0]->net->features |= NETIF_F_IP_CSUM;
1685 dhd->iflist[0]->net->features &= ~NETIF_F_IP_CSUM;
1697 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1700 dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1702 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1709 bool is_set_key_cmd;
1712 dhd_os_wake_lock(&dhd->pub);
1714 ifidx = dhd_net2idx(dhd, net);
1715 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
1717 if (ifidx == DHD_BAD_IF) {
1718 dhd_os_wake_unlock(&dhd->pub);
1722 #if defined(CONFIG_WIRELESS_EXT)
1723 /* linux wireless extensions */
1724 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1725 /* may recurse, do NOT lock */
1726 ret = wl_iw_ioctl(net, ifr, cmd);
1727 dhd_os_wake_unlock(&dhd->pub);
1730 #endif /* defined(CONFIG_WIRELESS_EXT) */
1732 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1733 if (cmd == SIOCETHTOOL) {
1734 ret = dhd_ethtool(dhd, (void*)ifr->ifr_data);
1735 dhd_os_wake_unlock(&dhd->pub);
1738 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1740 if (cmd != SIOCDEVPRIVATE) {
1741 dhd_os_wake_unlock(&dhd->pub);
1745 memset(&ioc, 0, sizeof(ioc));
1747 /* Copy the ioc control structure part of ioctl request */
1748 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1749 bcmerror = -BCME_BADADDR;
1753 /* Copy out any buffer passed */
1755 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1756 /* optimization for direct ioctl calls from kernel */
1758 if (segment_eq(get_fs(), KERNEL_DS)) {
1763 if (!(buf = (char*)MALLOC(dhd->pub.osh, buflen))) {
1764 bcmerror = -BCME_NOMEM;
1767 if (copy_from_user(buf, ioc.buf, buflen)) {
1768 bcmerror = -BCME_BADADDR;
1774 /* To differentiate between wl and dhd read 4 more byes */
1775 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1776 sizeof(uint)) != 0)) {
1777 bcmerror = -BCME_BADADDR;
1781 if (!capable(CAP_NET_ADMIN)) {
1782 bcmerror = -BCME_EPERM;
1786 /* check for local dhd ioctl and handle it */
1787 if (driver == DHD_IOCTL_MAGIC) {
1788 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1790 dhd->pub.bcmerror = bcmerror;
1794 /* send to dongle (must be up, and wl) */
1795 if (dhd->pub.busstate != DHD_BUS_DATA) {
1796 DHD_ERROR(("%s DONGLE_DOWN\n", __FUNCTION__));
1797 bcmerror = BCME_DONGLE_DOWN;
1801 if (!dhd->pub.iswl) {
1802 bcmerror = BCME_DONGLE_DOWN;
1806 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1807 * prevent M4 encryption.
1809 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1810 ((ioc.cmd == WLC_SET_VAR) &&
1811 !(strncmp("wsec_key", ioc.buf, 9))) ||
1812 ((ioc.cmd == WLC_SET_VAR) &&
1813 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1814 if (is_set_key_cmd) {
1815 dhd_wait_pend8021x(net);
1818 bcmerror = dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1821 if ((bcmerror == -ETIMEDOUT) || ((dhd->pub.busstate == DHD_BUS_DOWN) &&
1822 (!dhd->pub.dongle_reset))) {
1823 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1824 net_os_send_hang_message(net);
1827 if (!bcmerror && buf && ioc.buf) {
1828 if (copy_to_user(ioc.buf, buf, buflen))
1833 MFREE(dhd->pub.osh, buf, buflen);
1835 dhd_os_wake_unlock(&dhd->pub);
1837 return OSL_ERROR(bcmerror);
1841 dhd_stop(struct net_device *net)
1843 #if !defined(IGNORE_ETH0_DOWN)
1844 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1846 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1847 if (dhd->pub.up == 0) {
1851 /* Set state and stop OS transmissions */
1853 netif_stop_queue(net);
1855 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation ...\n", __FUNCTION__));
1856 #endif /* !defined(IGNORE_ETH0_DOWN) */
1858 OLD_MOD_DEC_USE_COUNT;
1863 dhd_open(struct net_device *net)
1865 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1871 wl_control_wl_start(net); /* start if needed */
1873 ifidx = dhd_net2idx(dhd, net);
1874 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
1876 /* ASSERT(ifidx == 0); */
1878 if (ifidx == 0) { /* do it only for primary eth0 */
1880 atomic_set(&dhd->pend_8021x_cnt, 0);
1882 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1885 /* Get current TOE mode from dongle */
1886 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1887 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1889 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1892 /* Allow transmit calls */
1893 netif_start_queue(net);
1896 OLD_MOD_INC_USE_COUNT;
1901 dhd_osl_attach(void *pdev, uint bustype)
1903 return osl_attach(pdev, bustype, TRUE);
1907 dhd_osl_detach(osl_t *osh)
1909 if (MALLOCED(osh)) {
1910 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __FUNCTION__, MALLOCED(osh)));
1913 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && 1
1914 up(&dhd_registration_sem);
1915 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
1919 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1920 uint8 *mac_addr, uint32 flags, uint8 bssidx)
1924 DHD_TRACE(("%s: idx %d, handle->%p\n", __FUNCTION__, ifidx, handle));
1926 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1928 ifp = dhd->iflist[ifidx];
1929 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1930 DHD_ERROR(("%s: OOM - dhd_if_t\n", __FUNCTION__));
1934 memset(ifp, 0, sizeof(dhd_if_t));
1936 dhd->iflist[ifidx] = ifp;
1937 strncpy(ifp->name, name, IFNAMSIZ);
1938 ifp->name[IFNAMSIZ] = '\0';
1939 if (mac_addr != NULL)
1940 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1942 if (handle == NULL) {
1943 ifp->state = WLC_E_IF_ADD;
1945 ASSERT(dhd->sysioc_pid >= 0);
1946 up(&dhd->sysioc_sem);
1948 ifp->net = (struct net_device *)handle;
1954 dhd_del_if(dhd_info_t *dhd, int ifidx)
1958 DHD_TRACE(("%s: idx %d\n", __FUNCTION__, ifidx));
1960 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1961 ifp = dhd->iflist[ifidx];
1963 DHD_ERROR(("%s: Null interface\n", __FUNCTION__));
1967 ifp->state = WLC_E_IF_DEL;
1969 ASSERT(dhd->sysioc_pid >= 0);
1970 up(&dhd->sysioc_sem);
1974 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1976 dhd_info_t *dhd = NULL;
1977 struct net_device *net;
1979 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1980 /* updates firmware nvram path if it was provided as module paramters */
1981 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1982 strcpy(fw_path, firmware_path);
1983 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1984 strcpy(nv_path, nvram_path);
1986 /* Allocate etherdev, including space for private structure */
1987 if (!(net = alloc_etherdev(sizeof(dhd)))) {
1988 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
1992 /* Allocate primary dhd_info */
1993 if (!(dhd = MALLOC(osh, sizeof(dhd_info_t)))) {
1994 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __FUNCTION__));
1998 memset(dhd, 0, sizeof(dhd_info_t));
2001 * Save the dhd_info into the priv
2003 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2006 /* Set network interface name if it was provided as module parameter */
2007 if (iface_name[0]) {
2010 strncpy(net->name, iface_name, IFNAMSIZ);
2011 net->name[IFNAMSIZ - 1] = 0;
2012 len = strlen(net->name);
2013 ch = net->name[len - 1];
2014 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
2015 strcat(net->name, "%d");
2018 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) == DHD_BAD_IF)
2021 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2024 net->netdev_ops = NULL;
2027 init_MUTEX(&dhd->proto_sem);
2028 /* Initialize other structure content */
2029 init_waitqueue_head(&dhd->ioctl_resp_wait);
2030 init_waitqueue_head(&dhd->ctrl_wait);
2032 /* Initialize the spinlocks */
2033 spin_lock_init(&dhd->sdlock);
2034 spin_lock_init(&dhd->txqlock);
2036 /* Initialize Wakelock stuff */
2037 spin_lock_init(&dhd->wl_lock);
2040 #ifdef CONFIG_HAS_WAKELOCK
2041 wake_lock_init(&dhd->wl_wifi, WAKE_LOCK_SUSPEND, "wlan_wake");
2042 wake_lock_init(&dhd->wl_rxwake, WAKE_LOCK_SUSPEND, "wlan_rx_wake");
2045 /* Link to info module */
2046 dhd->pub.info = dhd;
2048 /* Link to bus module */
2050 dhd->pub.hdrlen = bus_hdrlen;
2052 /* Attach and link in the protocol */
2053 if (dhd_prot_attach(&dhd->pub) != 0) {
2054 DHD_ERROR(("dhd_prot_attach failed\n"));
2057 #if defined(CONFIG_WIRELESS_EXT)
2058 /* Attach and link in the iw */
2059 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
2060 DHD_ERROR(("wl_iw_attach failed\n"));
2063 #endif /* defined(CONFIG_WIRELESS_EXT) */
2065 /* Set up the watchdog timer */
2066 init_timer(&dhd->timer);
2067 dhd->timer.data = (ulong)dhd;
2068 dhd->timer.function = dhd_watchdog;
2070 /* Initialize thread based operation and lock */
2071 init_MUTEX(&dhd->sdsem);
2072 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)) {
2073 dhd->threads_only = TRUE;
2076 dhd->threads_only = FALSE;
2079 if (dhd_dpc_prio >= 0) {
2080 /* Initialize watchdog thread */
2081 sema_init(&dhd->watchdog_sem, 0);
2082 init_completion(&dhd->watchdog_exited);
2083 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2085 dhd->watchdog_pid = -1;
2088 /* Set up the bottom half handler */
2089 if (dhd_dpc_prio >= 0) {
2090 /* Initialize DPC thread */
2091 sema_init(&dhd->dpc_sem, 0);
2092 init_completion(&dhd->dpc_exited);
2093 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2095 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
2100 sema_init(&dhd->sysioc_sem, 0);
2101 init_completion(&dhd->sysioc_exited);
2102 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2104 dhd->sysioc_pid = -1;
2108 * Save the dhd_info into the priv
2110 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2112 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2115 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2116 register_pm_notifier(&dhd_sleep_pm_notifier);
2117 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2119 #ifdef CONFIG_HAS_EARLYSUSPEND
2120 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2121 dhd->early_suspend.suspend = dhd_early_suspend;
2122 dhd->early_suspend.resume = dhd_late_resume;
2123 register_early_suspend(&dhd->early_suspend);
2132 dhd_detach(&dhd->pub);
2139 dhd_bus_start(dhd_pub_t *dhdp)
2142 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
2143 #ifdef EMBEDDED_PLATFORM
2144 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
2145 #endif /* EMBEDDED_PLATFORM */
2149 DHD_TRACE(("%s: \n", __FUNCTION__));
2151 /* try to download image and nvram to the dongle */
2152 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2153 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2154 fw_path, nv_path))) {
2155 DHD_ERROR(("%s: dhdsdio_probe_download failed. firmware = %s nvram = %s\n",
2156 __FUNCTION__, fw_path, nv_path));
2161 /* Start the watchdog timer */
2162 dhd->pub.tickcnt = 0;
2163 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2165 /* Bring up the bus */
2166 if ((ret = dhd_bus_init(&dhd->pub, TRUE)) != 0) {
2167 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
2170 #if defined(OOB_INTR_ONLY)
2171 /* Host registration for OOB interrupt */
2172 if (bcmsdh_register_oob_intr(dhdp)) {
2173 del_timer_sync(&dhd->timer);
2174 dhd->wd_timer_valid = FALSE;
2175 DHD_ERROR(("%s Host failed to resgister for OOB\n", __FUNCTION__));
2179 /* Enable oob at firmware */
2180 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2181 #endif /* defined(OOB_INTR_ONLY) */
2183 /* If bus is not ready, can't come up */
2184 if (dhd->pub.busstate != DHD_BUS_DATA) {
2185 del_timer_sync(&dhd->timer);
2186 dhd->wd_timer_valid = FALSE;
2187 DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
2191 #ifdef EMBEDDED_PLATFORM
2192 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
2193 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2194 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2196 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2197 setbit(dhdp->eventmask, WLC_E_PRUNE);
2198 setbit(dhdp->eventmask, WLC_E_AUTH);
2199 setbit(dhdp->eventmask, WLC_E_REASSOC);
2200 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2201 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2202 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2203 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2204 setbit(dhdp->eventmask, WLC_E_JOIN);
2205 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2206 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2207 setbit(dhdp->eventmask, WLC_E_LINK);
2208 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2209 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2210 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2211 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2212 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2213 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2215 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2216 #endif /* PNO_SUPPORT */
2218 /* enable dongle roaming event */
2219 setbit(dhdp->eventmask, WLC_E_ROAM);
2221 dhdp->pktfilter_count = 1;
2222 /* Setup filter to allow only unicast */
2223 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2224 #endif /* EMBEDDED_PLATFORM */
2226 /* Bus is ready, do any protocol initialization */
2227 if ((ret = dhd_prot_init(&dhd->pub)) < 0)
2234 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len, int set)
2236 char buf[strlen(name) + 1 + cmd_len];
2237 int len = sizeof(buf);
2241 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2243 memset(&ioc, 0, sizeof(ioc));
2245 ioc.cmd = set? WLC_SET_VAR : WLC_GET_VAR;
2250 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2251 if (!set && ret >= 0)
2252 memcpy(cmd_buf, buf, cmd_len);
2257 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 31))
2258 static struct net_device_ops dhd_ops_pri = {
2259 .ndo_open = dhd_open,
2260 .ndo_stop = dhd_stop,
2261 .ndo_get_stats = dhd_get_stats,
2262 .ndo_do_ioctl = dhd_ioctl_entry,
2263 .ndo_start_xmit = dhd_start_xmit,
2264 .ndo_set_mac_address = dhd_set_mac_address,
2265 .ndo_set_multicast_list = dhd_set_multicast_list,
2268 static struct net_device_ops dhd_ops_virt = {
2269 .ndo_get_stats = dhd_get_stats,
2270 .ndo_do_ioctl = dhd_ioctl_entry,
2271 .ndo_start_xmit = dhd_start_xmit,
2272 .ndo_set_mac_address = dhd_set_mac_address,
2273 .ndo_set_multicast_list = dhd_set_multicast_list,
2278 dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2280 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2281 struct net_device *net;
2282 uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33 };
2284 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
2286 ASSERT(dhd && dhd->iflist[ifidx]);
2287 net = dhd->iflist[ifidx]->net;
2290 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2292 net->get_stats = dhd_get_stats;
2293 net->do_ioctl = dhd_ioctl_entry;
2294 net->hard_start_xmit = dhd_start_xmit;
2295 net->set_mac_address = dhd_set_mac_address;
2296 net->set_multicast_list = dhd_set_multicast_list;
2297 net->open = net->stop = NULL;
2299 ASSERT(!net->netdev_ops);
2300 net->netdev_ops = &dhd_ops_virt;
2303 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2304 net->open = dhd_open;
2305 net->stop = dhd_stop;
2307 net->netdev_ops = &dhd_ops_pri;
2311 * We have to use the primary MAC for virtual interfaces
2314 /* for virtual interfaces use the primary MAC */
2315 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2319 DHD_TRACE(("%s ACCESS POINT MAC: \n", __FUNCTION__));
2320 /* ACCESSPOINT INTERFACE CASE */
2321 temp_addr[0] |= 0x02; /* set bit 2 , - Locally Administered address */
2323 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2324 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2325 net->ethtool_ops = &dhd_ethtool_ops;
2326 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
2328 #if defined(CONFIG_WIRELESS_EXT)
2329 #if WIRELESS_EXT < 19
2330 net->get_wireless_stats = dhd_get_wireless_stats;
2331 #endif /* WIRELESS_EXT < 19 */
2332 #if WIRELESS_EXT > 12
2333 net->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
2334 #endif /* WIRELESS_EXT > 12 */
2335 #endif /* defined(CONFIG_WIRELESS_EXT) */
2337 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2339 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2341 if (register_netdev(net) != 0) {
2342 DHD_ERROR(("%s: couldn't register the net device\n", __FUNCTION__));
2346 printf("%s: Broadcom Dongle Host Driver mac=%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", net->name,
2347 dhd->pub.mac.octet[0], dhd->pub.mac.octet[1], dhd->pub.mac.octet[2],
2348 dhd->pub.mac.octet[3], dhd->pub.mac.octet[4], dhd->pub.mac.octet[5]);
2350 #if defined(CONFIG_WIRELESS_EXT)
2353 /* Don't call for SOFTAP Interface in SOFTAP MODE */
2354 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2356 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2358 #endif /* CONFIG_WIRELESS_EXT */
2360 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2361 up(&dhd_registration_sem);
2362 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
2366 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2369 net->netdev_ops = NULL;
2375 dhd_bus_detach(dhd_pub_t *dhdp)
2379 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2382 dhd = (dhd_info_t *)dhdp->info;
2384 /* Stop the protocol module */
2385 dhd_prot_stop(&dhd->pub);
2387 /* Stop the bus module */
2388 dhd_bus_stop(dhd->pub.bus, TRUE);
2389 #if defined(OOB_INTR_ONLY)
2390 bcmsdh_unregister_oob_intr();
2391 #endif /* defined(OOB_INTR_ONLY) */
2393 /* Clear the watchdog timer */
2394 del_timer_sync(&dhd->timer);
2395 dhd->wd_timer_valid = FALSE;
2401 dhd_detach(dhd_pub_t *dhdp)
2405 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2408 dhd = (dhd_info_t *)dhdp->info;
2413 #if defined(CONFIG_HAS_EARLYSUSPEND)
2414 if (dhd->early_suspend.suspend)
2415 unregister_early_suspend(&dhd->early_suspend);
2416 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2417 #if defined(CONFIG_WIRELESS_EXT)
2418 /* Attach and link in the iw */
2422 for (i = 1; i < DHD_MAX_IFS; i++)
2426 if (dhd->sysioc_pid >= 0) {
2427 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2428 wait_for_completion(&dhd->sysioc_exited);
2431 ifp = dhd->iflist[0];
2433 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2434 if (ifp->net->open) {
2436 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2439 unregister_netdev(ifp->net);
2442 if (dhd->watchdog_pid >= 0)
2444 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2445 wait_for_completion(&dhd->watchdog_exited);
2448 if (dhd->dpc_pid >= 0)
2450 KILL_PROC(dhd->dpc_pid, SIGTERM);
2451 wait_for_completion(&dhd->dpc_exited);
2454 tasklet_kill(&dhd->tasklet);
2456 dhd_bus_detach(dhdp);
2459 dhd_prot_detach(dhdp);
2461 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2462 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2463 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2464 free_netdev(ifp->net);
2465 #ifdef CONFIG_HAS_WAKELOCK
2466 wake_lock_destroy(&dhd->wl_wifi);
2467 wake_lock_destroy(&dhd->wl_rxwake);
2469 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2470 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2476 dhd_module_cleanup(void)
2478 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2480 dhd_bus_unregister();
2481 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2484 /* Call customer gpio to turn off power with WL_REG_ON signal */
2485 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2489 dhd_module_init(void)
2493 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2495 /* Sanity check on the module parameters */
2497 /* Both watchdog and DPC as tasklets are ok */
2498 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2501 /* If both watchdog and DPC are threads, TX must be deferred */
2502 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0) && dhd_deferred_tx)
2505 DHD_ERROR(("Invalid module parameters.\n"));
2509 /* Call customer gpio to turn on power with WL_REG_ON signal */
2510 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2512 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2513 sema_init(&wifi_control_sem, 0);
2515 error = wifi_add_dev();
2517 DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__));
2521 /* Waiting callback after platform_driver_register is done or exit with error */
2522 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(5000)) != 0) {
2524 DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__));
2527 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2529 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2530 sema_init(&dhd_registration_sem, 0);
2533 error = dhd_bus_register();
2536 printf("\n%s\n", dhd_version);
2538 DHD_ERROR(("%s: sdio_register_driver failed\n", __FUNCTION__));
2541 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2543 * Wait till MMC sdio_register_driver callback called and made driver attach.
2544 * It's needed to make sync up exit from dhd insmod and
2545 * Kernel MMC sdio device callback registration
2547 if (down_timeout(&dhd_registration_sem, msecs_to_jiffies(DHD_REGISTRATION_TIMEOUT)) != 0) {
2549 DHD_ERROR(("%s: sdio_register_driver timeout\n", __FUNCTION__));
2554 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2556 dhd_bus_unregister();
2559 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2562 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2564 /* Call customer gpio to turn off power with WL_REG_ON signal */
2565 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2570 module_init(dhd_module_init);
2571 module_exit(dhd_module_cleanup);
2574 * OS specific functions required to implement DHD driver in OS independent way
2577 dhd_os_proto_block(dhd_pub_t *pub)
2579 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2582 down(&dhd->proto_sem);
2590 dhd_os_proto_unblock(dhd_pub_t *pub)
2592 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2595 up(&dhd->proto_sem);
2603 dhd_os_get_ioctl_resp_timeout(void)
2605 return ((unsigned int)dhd_ioctl_timeout_msec);
2609 dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2611 dhd_ioctl_timeout_msec = (int)timeout_msec;
2615 dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2617 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2618 DECLARE_WAITQUEUE(wait, current);
2619 int timeout = dhd_ioctl_timeout_msec;
2621 /* Convert timeout in millsecond to jiffies */
2622 /* timeout = timeout * HZ / 1000; */
2623 timeout = msecs_to_jiffies(timeout);
2625 /* Wait until control frame is available */
2626 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2627 set_current_state(TASK_INTERRUPTIBLE);
2629 while (!(*condition) && (!signal_pending(current) && timeout)) {
2630 timeout = schedule_timeout(timeout);
2634 if (signal_pending(current))
2637 set_current_state(TASK_RUNNING);
2638 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2644 dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2646 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2648 if (waitqueue_active(&dhd->ioctl_resp_wait)) {
2649 wake_up_interruptible(&dhd->ioctl_resp_wait);
2656 dhd_os_wd_timer(void *bus, uint wdtick)
2658 dhd_pub_t *pub = bus;
2659 static uint save_dhd_watchdog_ms = 0;
2660 dhd_info_t *dhd = (dhd_info_t *)pub->info;
2662 /* don't start the wd until fw is loaded */
2663 if (pub->busstate == DHD_BUS_DOWN)
2666 /* Totally stop the timer */
2667 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2668 del_timer_sync(&dhd->timer);
2669 dhd->wd_timer_valid = FALSE;
2670 save_dhd_watchdog_ms = wdtick;
2675 dhd_watchdog_ms = (uint)wdtick;
2677 /* Re arm the timer, at last watchdog period */
2678 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
2680 dhd->wd_timer_valid = TRUE;
2681 save_dhd_watchdog_ms = wdtick;
2686 dhd_os_open_image(char *filename)
2690 fp = filp_open(filename, O_RDONLY, 0);
2692 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2694 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2704 dhd_os_get_image_block(char *buf, int len, void *image)
2706 struct file *fp = (struct file *)image;
2712 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2720 dhd_os_close_image(void *image)
2723 filp_close((struct file *)image, NULL);
2728 dhd_os_sdlock(dhd_pub_t *pub)
2732 dhd = (dhd_info_t *)(pub->info);
2734 if (dhd->threads_only)
2737 spin_lock_bh(&dhd->sdlock);
2741 dhd_os_sdunlock(dhd_pub_t *pub)
2745 dhd = (dhd_info_t *)(pub->info);
2747 if (dhd->threads_only)
2750 spin_unlock_bh(&dhd->sdlock);
2754 dhd_os_sdlock_txq(dhd_pub_t *pub)
2758 dhd = (dhd_info_t *)(pub->info);
2759 spin_lock_bh(&dhd->txqlock);
2763 dhd_os_sdunlock_txq(dhd_pub_t *pub)
2767 dhd = (dhd_info_t *)(pub->info);
2768 spin_unlock_bh(&dhd->txqlock);
2771 dhd_os_sdlock_rxq(dhd_pub_t *pub)
2775 dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2780 dhd_os_sdtxlock(dhd_pub_t *pub)
2786 dhd_os_sdtxunlock(dhd_pub_t *pub)
2788 dhd_os_sdunlock(pub);
2791 #ifdef DHD_USE_STATIC_BUF
2792 void * dhd_os_prealloc(int section, unsigned long size)
2794 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2795 void *alloc_ptr = NULL;
2796 if (wifi_control_data && wifi_control_data->mem_prealloc)
2798 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2801 DHD_INFO(("success alloc section %d\n", section));
2802 bzero(alloc_ptr, size);
2807 DHD_ERROR(("can't alloc section %d\n", section));
2810 return MALLOC(0, size);
2811 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2813 #endif /* DHD_USE_STATIC_BUF */
2814 #if defined(CONFIG_WIRELESS_EXT)
2815 struct iw_statistics *
2816 dhd_get_wireless_stats(struct net_device *dev)
2819 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2821 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2824 return &dhd->iw.wstats;
2828 #endif /* defined(CONFIG_WIRELESS_EXT) */
2831 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2832 wl_event_msg_t *event, void **data)
2836 ASSERT(dhd != NULL);
2838 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2839 if (bcmerror != BCME_OK)
2842 #if defined(CONFIG_WIRELESS_EXT)
2843 ASSERT(dhd->iflist[*ifidx] != NULL);
2844 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2846 if (dhd->iflist[*ifidx]->net)
2847 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2848 #endif /* defined(CONFIG_WIRELESS_EXT) */
2853 /* send up locally generated event */
2855 dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2857 switch (ntoh32(event->event_type)) {
2863 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2865 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2866 struct dhd_info *dhdinfo = dhd->info;
2867 dhd_os_sdunlock(dhd);
2868 wait_event_interruptible_timeout(dhdinfo->ctrl_wait, (*lockvar == FALSE), HZ * 2);
2874 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2876 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2877 struct dhd_info *dhdinfo = dhd->info;
2878 if (waitqueue_active(&dhdinfo->ctrl_wait))
2879 wake_up_interruptible(&dhdinfo->ctrl_wait);
2885 dhd_dev_reset(struct net_device *dev, uint8 flag)
2887 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2889 /* Turning off watchdog */
2891 dhd_os_wd_timer(&dhd->pub, 0);
2893 dhd_bus_devreset(&dhd->pub, flag);
2895 /* Turning on watchdog back */
2897 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2898 DHD_ERROR(("%s: WLAN OFF DONE\n", __FUNCTION__));
2903 int net_os_set_suspend_disable(struct net_device *dev, int val)
2905 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2909 ret = dhd->pub.suspend_disable_flag;
2910 dhd->pub.suspend_disable_flag = val;
2915 int net_os_set_suspend(struct net_device *dev, int val)
2918 #if defined(CONFIG_HAS_EARLYSUSPEND)
2919 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2922 dhd_os_proto_block(&dhd->pub);
2923 ret = dhd_set_suspend(val, &dhd->pub);
2924 dhd_os_proto_unblock(&dhd->pub);
2926 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2930 int net_os_set_dtim_skip(struct net_device *dev, int val)
2932 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2935 dhd->pub.dtim_skip = val;
2940 int net_os_set_packet_filter(struct net_device *dev, int val)
2942 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2945 /* Packet filtering is set only if we still in early-suspend and
2946 * we need either to turn it ON or turn it OFF
2947 * We can always turn it OFF in case of early-suspend, but we turn it
2948 * back ON only if suspend_disable_flag was not set
2950 if (dhd && dhd->pub.up) {
2951 dhd_os_proto_block(&dhd->pub);
2952 if (dhd->pub.in_suspend) {
2953 if (!val || (val && !dhd->pub.suspend_disable_flag))
2954 dhd_set_packet_filter(val, &dhd->pub);
2956 dhd_os_proto_unblock(&dhd->pub);
2963 dhd_dev_init_ioctl(struct net_device *dev)
2965 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2967 dhd_preinit_ioctls(&dhd->pub);
2971 /* Linux wrapper to call common dhd_pno_clean */
2973 dhd_dev_pno_reset(struct net_device *dev)
2975 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2977 return (dhd_pno_clean(&dhd->pub));
2981 /* Linux wrapper to call common dhd_pno_enable */
2983 dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2985 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2987 return (dhd_pno_enable(&dhd->pub, pfn_enabled));
2991 /* Linux wrapper to call common dhd_pno_set */
2993 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t* ssids_local, int nssid, uchar scan_fr)
2995 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2997 return (dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr));
3000 /* Linux wrapper to get pno status */
3002 dhd_dev_get_pno_status(struct net_device *dev)
3004 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3006 return (dhd_pno_get_status(&dhd->pub));
3009 #endif /* PNO_SUPPORT */
3012 dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
3014 return (atomic_read(&dhd->pend_8021x_cnt));
3017 #define MAX_WAIT_FOR_8021X_TX 10
3020 dhd_wait_pend8021x(struct net_device *dev)
3022 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3023 int timeout = 10 * HZ / 1000;
3024 int ntimes = MAX_WAIT_FOR_8021X_TX;
3025 int pend = dhd_get_pend_8021x_cnt(dhd);
3027 while (ntimes && pend) {
3029 set_current_state(TASK_INTERRUPTIBLE);
3030 schedule_timeout(timeout);
3031 set_current_state(TASK_RUNNING);
3034 pend = dhd_get_pend_8021x_cnt(dhd);
3041 write_to_file(dhd_pub_t *dhd, uint8 *buf, int size)
3045 mm_segment_t old_fs;
3048 /* change to KERNEL_DS address limit */
3052 /* open file to write */
3053 fp = filp_open("/tmp/mem_dump", O_WRONLY|O_CREAT, 0640);
3055 printf("%s: open file error\n", __FUNCTION__);
3060 /* Write buf to file */
3061 fp->f_op->write(fp, buf, size, &pos);
3064 /* free buf before return */
3065 MFREE(dhd->osh, buf, size);
3066 /* close file before return */
3068 filp_close(fp, current->files);
3069 /* restore previous address limit */
3074 #endif /* DHD_DEBUG */
3076 int dhd_os_wake_lock_timeout(dhd_pub_t *pub)
3078 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3079 unsigned long flags;
3083 spin_lock_irqsave(&dhd->wl_lock, flags);
3084 ret = dhd->wl_packet;
3085 #ifdef CONFIG_HAS_WAKELOCK
3087 wake_lock_timeout(&dhd->wl_rxwake, HZ);
3090 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3092 /* printk("%s: %d\n", __FUNCTION__, ret); */
3096 int net_os_wake_lock_timeout(struct net_device *dev)
3098 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3102 ret = dhd_os_wake_lock_timeout(&dhd->pub);
3106 int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub)
3108 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3109 unsigned long flags;
3112 spin_lock_irqsave(&dhd->wl_lock, flags);
3114 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3116 /* printk("%s\n",__func__); */
3120 int net_os_wake_lock_timeout_enable(struct net_device *dev)
3122 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3126 ret = dhd_os_wake_lock_timeout_enable(&dhd->pub);
3130 int dhd_os_wake_lock(dhd_pub_t *pub)
3132 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3133 unsigned long flags;
3137 spin_lock_irqsave(&dhd->wl_lock, flags);
3138 #ifdef CONFIG_HAS_WAKELOCK
3140 wake_lock(&dhd->wl_wifi);
3143 ret = dhd->wl_count;
3144 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3146 /* printk("%s: %d\n", __FUNCTION__, ret); */
3150 int net_os_wake_lock(struct net_device *dev)
3152 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3156 ret = dhd_os_wake_lock(&dhd->pub);
3160 int dhd_os_wake_unlock(dhd_pub_t *pub)
3162 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3163 unsigned long flags;
3166 dhd_os_wake_lock_timeout(pub);
3168 spin_lock_irqsave(&dhd->wl_lock, flags);
3169 if (dhd->wl_count) {
3171 #ifdef CONFIG_HAS_WAKELOCK
3173 wake_unlock(&dhd->wl_wifi);
3175 ret = dhd->wl_count;
3177 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3179 /* printk("%s: %d\n", __FUNCTION__, ret); */
3183 int net_os_wake_unlock(struct net_device *dev)
3185 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3189 ret = dhd_os_wake_unlock(&dhd->pub);
3193 int net_os_send_hang_message(struct net_device *dev)
3195 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3199 if (!dhd->hang_was_sent) {
3200 dhd->hang_was_sent = 1;
3201 ret = wl_iw_send_priv_event(dev, "HANG");