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.4.35 2010/11/17 03:13:21 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>
66 #include <mach/board.h>
68 struct semaphore wifi_control_sem;
70 struct dhd_bus *g_bus;
72 static struct wifi_platform_data *wifi_control_data = NULL;
73 static struct resource *wifi_irqres = NULL;
75 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
78 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
79 return (int)wifi_irqres->start;
81 #ifdef CUSTOM_OOB_GPIO_NUM
82 return CUSTOM_OOB_GPIO_NUM;
88 int wifi_set_carddetect(int on)
90 printk("%s = %d\n", __FUNCTION__, on);
91 if (wifi_control_data && wifi_control_data->set_carddetect) {
92 wifi_control_data->set_carddetect(on);
97 int wifi_set_power(int on, unsigned long msec)
99 printk("%s = %d\n", __FUNCTION__, on);
100 if (wifi_control_data && wifi_control_data->set_power) {
101 wifi_control_data->set_power(on);
108 int wifi_set_reset(int on, unsigned long msec)
110 DHD_TRACE(("%s = %d\n", __FUNCTION__, on));
111 if (wifi_control_data && wifi_control_data->set_reset) {
112 wifi_control_data->set_reset(on);
119 int wifi_get_mac_addr(unsigned char *buf)
121 DHD_TRACE(("%s\n", __FUNCTION__));
124 if (wifi_control_data && wifi_control_data->get_mac_addr) {
125 return wifi_control_data->get_mac_addr(buf);
130 static int wifi_probe(struct platform_device *pdev)
132 struct wifi_platform_data *wifi_ctrl =
133 (struct wifi_platform_data *)(pdev->dev.platform_data);
135 DHD_TRACE(("## %s\n", __FUNCTION__));
136 wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcm4329_wlan_irq");
137 wifi_control_data = wifi_ctrl;
139 wifi_set_power(1, 0); /* Power On */
140 wifi_set_carddetect(1); /* CardDetect (0->1) */
142 up(&wifi_control_sem);
146 static int wifi_remove(struct platform_device *pdev)
148 struct wifi_platform_data *wifi_ctrl =
149 (struct wifi_platform_data *)(pdev->dev.platform_data);
151 DHD_TRACE(("## %s\n", __FUNCTION__));
152 wifi_control_data = wifi_ctrl;
154 wifi_set_power(0, 0); /* Power Off */
155 wifi_set_carddetect(0); /* CardDetect (1->0) */
157 up(&wifi_control_sem);
160 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
162 DHD_TRACE(("##> %s\n", __FUNCTION__));
165 static int wifi_resume(struct platform_device *pdev)
167 DHD_TRACE(("##> %s\n", __FUNCTION__));
171 static struct platform_driver wifi_device = {
173 .remove = wifi_remove,
174 .suspend = wifi_suspend,
175 .resume = wifi_resume,
177 .name = "bcm4329_wlan",
181 int wifi_add_dev(void)
183 DHD_TRACE(("## Calling platform_driver_register\n"));
184 return platform_driver_register(&wifi_device);
187 void wifi_del_dev(void)
189 DHD_TRACE(("## Unregister platform_driver_register\n"));
190 platform_driver_unregister(&wifi_device);
192 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
195 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
196 #include <linux/suspend.h>
197 volatile bool dhd_mmc_suspend = FALSE;
198 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
199 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
201 #if defined(OOB_INTR_ONLY)
202 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
203 #endif /* defined(OOB_INTR_ONLY) */
204 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
205 MODULE_LICENSE("GPL v2");
206 #endif /* LinuxVer */
208 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15)
214 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15) */
216 /* Linux wireless extension support */
217 #if defined(CONFIG_WIRELESS_EXT)
219 #endif /* defined(CONFIG_WIRELESS_EXT) */
221 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
223 #if defined(CONFIG_HAS_EARLYSUSPEND)
224 #include <linux/earlysuspend.h>
225 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
227 #ifdef PKT_FILTER_SUPPORT
228 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
229 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
232 /* Interface control information */
233 typedef struct dhd_if {
234 struct dhd_info *info; /* back pointer to dhd_info */
235 /* OS/stack specifics */
236 struct net_device *net;
237 struct net_device_stats stats;
238 int idx; /* iface idx in dongle */
239 int state; /* interface state */
240 uint subunit; /* subunit */
241 uint8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
242 bool attached; /* Delayed attachment when unset */
243 bool txflowcontrol; /* Per interface flow control indicator */
244 char name[IFNAMSIZ+1]; /* linux interface name */
247 /* Local private structure (extension of pub) */
248 typedef struct dhd_info {
249 #if defined(CONFIG_WIRELESS_EXT)
250 wl_iw_t iw; /* wireless extensions state (must be first) */
251 #endif /* defined(CONFIG_WIRELESS_EXT) */
255 /* OS/stack specifics */
256 dhd_if_t *iflist[DHD_MAX_IFS];
258 struct semaphore proto_sem;
259 wait_queue_head_t ioctl_resp_wait;
260 struct timer_list timer;
262 struct tasklet_struct tasklet;
267 /* Thread based operation */
269 struct semaphore sdsem;
271 struct semaphore watchdog_sem;
272 struct completion watchdog_exited;
274 struct semaphore dpc_sem;
275 struct completion dpc_exited;
278 #ifdef CONFIG_HAS_WAKELOCK
279 struct wake_lock wl_wifi; /* Wifi wakelock */
280 struct wake_lock wl_rxwake; /* Wifi rx wakelock */
286 int hang_was_sent; /* flag that message was send at least once */
287 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
288 struct mutex wl_start_lock; /* mutex when START called to prevent any other Linux calls */
290 /* Thread to issue ioctl for multicast */
292 struct semaphore sysioc_sem;
293 struct completion sysioc_exited;
296 struct ether_addr macvalue;
297 wait_queue_head_t ctrl_wait;
298 atomic_t pend_8021x_cnt;
300 #ifdef CONFIG_HAS_EARLYSUSPEND
301 struct early_suspend early_suspend;
302 #endif /* CONFIG_HAS_EARLYSUSPEND */
305 /* Definitions to provide path to the firmware and nvram
306 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
308 char firmware_path[MOD_PARAM_PATHLEN];
309 char nvram_path[MOD_PARAM_PATHLEN];
311 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
312 struct semaphore dhd_registration_sem;
313 #define DHD_REGISTRATION_TIMEOUT 12000 /* msec : allowed time to finished dhd registration */
314 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
315 /* load firmware and/or nvram values from the filesystem */
316 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
317 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
320 module_param(dhd_msg_level, int, 0);
322 /* Spawn a thread for system ioctls (set mac, set mcast) */
323 uint dhd_sysioc = TRUE;
324 module_param(dhd_sysioc, uint, 0);
326 /* Watchdog interval */
327 uint dhd_watchdog_ms = 10;
328 module_param(dhd_watchdog_ms, uint, 0);
331 /* Console poll interval */
332 uint dhd_console_ms = 0;
333 module_param(dhd_console_ms, uint, 0);
334 #endif /* DHD_DEBUG */
336 /* ARP offload agent mode : Enable ARP Host Auto-Reply and ARP Peer Auto-Reply */
337 uint dhd_arp_mode = 0xb;
338 module_param(dhd_arp_mode, uint, 0);
340 /* ARP offload enable */
341 uint dhd_arp_enable = TRUE;
342 module_param(dhd_arp_enable, uint, 0);
344 /* Global Pkt filter enable control */
345 uint dhd_pkt_filter_enable = TRUE;
346 module_param(dhd_pkt_filter_enable, uint, 0);
348 /* Pkt filter init setup */
349 uint dhd_pkt_filter_init = 0;
350 module_param(dhd_pkt_filter_init, uint, 0);
352 /* Pkt filter mode control */
353 uint dhd_master_mode = TRUE;
354 module_param(dhd_master_mode, uint, 1);
356 /* Watchdog thread priority, -1 to use kernel timer */
357 int dhd_watchdog_prio = 97;
358 module_param(dhd_watchdog_prio, int, 0);
360 /* DPC thread priority, -1 to use tasklet */
361 int dhd_dpc_prio = 98;
362 module_param(dhd_dpc_prio, int, 0);
364 /* DPC thread priority, -1 to use tasklet */
365 extern int dhd_dongle_memsize;
366 module_param(dhd_dongle_memsize, int, 0);
368 /* Control fw roaming */
375 /* Control radio state */
376 uint dhd_radio_up = 1;
378 /* Network inteface name */
379 char iface_name[IFNAMSIZ] = "wlan0";
380 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
382 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
383 #define DAEMONIZE(a) daemonize(a); \
384 allow_signal(SIGKILL); \
385 allow_signal(SIGTERM);
386 #else /* Linux 2.4 (w/o preemption patch) */
387 #define RAISE_RX_SOFTIRQ() \
388 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
389 #define DAEMONIZE(a) daemonize(); \
391 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
393 #endif /* LINUX_VERSION_CODE */
395 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
396 #define BLOCKABLE() (!in_atomic())
398 #define BLOCKABLE() (!in_interrupt())
401 /* The following are specific to the SDIO dongle */
403 /* IOCTL response timeout */
404 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
406 /* Idle timeout for backplane clock */
407 int dhd_idletime = DHD_IDLETIME_TICKS;
408 module_param(dhd_idletime, int, 0);
411 uint dhd_poll = FALSE;
412 module_param(dhd_poll, uint, 0);
415 uint dhd_intr = TRUE;
416 module_param(dhd_intr, uint, 0);
418 /* SDIO Drive Strength (in milliamps) */
419 uint dhd_sdiod_drive_strength = 6;
420 module_param(dhd_sdiod_drive_strength, uint, 0);
423 extern uint dhd_txbound;
424 extern uint dhd_rxbound;
425 module_param(dhd_txbound, uint, 0);
426 module_param(dhd_rxbound, uint, 0);
428 /* Deferred transmits */
429 extern uint dhd_deferred_tx;
430 module_param(dhd_deferred_tx, uint, 0);
435 /* Echo packet generator (pkts/s) */
437 module_param(dhd_pktgen, uint, 0);
439 /* Echo packet len (0 => sawtooth, max 2040) */
440 uint dhd_pktgen_len = 0;
441 module_param(dhd_pktgen_len, uint, 0);
444 /* Version string to report */
447 #define SRCBASE "drivers/net/wireless/bcm4329"
449 #define DHD_COMPILED "\nCompiled in " SRCBASE
454 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
456 "\nCompiled in " SRCBASE " on " __DATE__ " at " __TIME__
461 #if defined(CONFIG_WIRELESS_EXT)
462 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
463 #endif /* defined(CONFIG_WIRELESS_EXT) */
465 static void dhd_dpc(ulong data);
467 extern int dhd_wait_pend8021x(struct net_device *dev);
471 #error TOE requires BDC
473 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
474 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
477 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
478 wl_event_msg_t *event_ptr, void **data_ptr);
480 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
481 static int dhd_sleep_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
483 int ret = NOTIFY_DONE;
486 case PM_HIBERNATION_PREPARE:
487 case PM_SUSPEND_PREPARE:
488 dhd_mmc_suspend = TRUE;
491 case PM_POST_HIBERNATION:
492 case PM_POST_SUSPEND:
493 dhd_mmc_suspend = FALSE;
501 static struct notifier_block dhd_sleep_pm_notifier = {
502 .notifier_call = dhd_sleep_pm_callback,
505 extern int register_pm_notifier(struct notifier_block *nb);
506 extern int unregister_pm_notifier(struct notifier_block *nb);
507 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
509 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
511 #ifdef PKT_FILTER_SUPPORT
512 DHD_TRACE(("%s: %d\n", __FUNCTION__, value));
513 /* 1 - Enable packet filter, only allow unicast packet to send up */
514 /* 0 - Disable packet filter */
515 if (dhd_pkt_filter_enable) {
518 for (i = 0; i < dhd->pktfilter_count; i++) {
519 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
520 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
521 value, dhd_master_mode);
529 #if defined(CONFIG_HAS_EARLYSUSPEND)
530 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
532 int power_mode = PM_MAX;
533 /* wl_pkt_filter_enable_t enable_parm; */
538 #endif /* CUSTOMER_HW2 */
540 DHD_TRACE(("%s: enter, value = %d in_suspend = %d\n",
541 __FUNCTION__, value, dhd->in_suspend));
543 if (dhd && dhd->up) {
544 if (value && dhd->in_suspend) {
546 /* Kernel suspended */
547 DHD_TRACE(("%s: force extra Suspend setting \n", __FUNCTION__));
549 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
550 (char *)&power_mode, sizeof(power_mode));
552 /* Enable packet filter, only allow unicast packet to send up */
553 dhd_set_packet_filter(1, dhd);
555 /* if dtim skip setup as default force it to wake each thrid dtim
556 * for better power saving.
557 * Note that side effect is chance to miss BC/MC packet
559 bcn_li_dtim = dhd_get_dtim_skip(dhd);
560 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
561 4, iovbuf, sizeof(iovbuf));
562 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
564 /* Disable build-in roaming during suspend */
565 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
566 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
567 #endif /* CUSTOMER_HW2 */
572 DHD_TRACE(("%s: Remove extra suspend setting \n", __FUNCTION__));
574 power_mode = PM_FAST;
575 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
578 /* disable pkt filter */
579 dhd_set_packet_filter(0, dhd);
581 /* restore pre-suspend setting for dtim_skip */
582 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
583 4, iovbuf, sizeof(iovbuf));
585 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
588 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
589 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
590 #endif /* CUSTOMER_HW2 */
597 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
599 dhd_pub_t *dhdp = &dhd->pub;
601 dhd_os_wake_lock(dhdp);
602 dhd_os_proto_block(dhdp);
603 /* Set flag when early suspend was called */
604 dhdp->in_suspend = val;
605 if (!dhdp->suspend_disable_flag)
606 dhd_set_suspend(val, dhdp);
607 dhd_os_proto_unblock(dhdp);
608 dhd_os_wake_unlock(dhdp);
611 static void dhd_early_suspend(struct early_suspend *h)
613 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
615 DHD_TRACE(("%s: enter\n", __FUNCTION__));
618 dhd_suspend_resume_helper(dhd, 1);
621 static void dhd_late_resume(struct early_suspend *h)
623 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
625 DHD_TRACE(("%s: enter\n", __FUNCTION__));
628 dhd_suspend_resume_helper(dhd, 0);
630 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
633 * Generalized timeout mechanism. Uses spin sleep with exponential back-off until
634 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
636 * dhd_timeout_start(&tmo, usec);
637 * while (!dhd_timeout_expired(&tmo))
638 * if (poll_something())
640 * if (dhd_timeout_expired(&tmo))
645 dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
650 tmo->tick = 1000000 / HZ;
654 dhd_timeout_expired(dhd_timeout_t *tmo)
656 /* Does nothing the first call */
657 if (tmo->increment == 0) {
662 if (tmo->elapsed >= tmo->limit)
665 /* Add the delay that's about to take place */
666 tmo->elapsed += tmo->increment;
668 if (tmo->increment < tmo->tick) {
669 OSL_DELAY(tmo->increment);
671 if (tmo->increment > tmo->tick)
672 tmo->increment = tmo->tick;
674 wait_queue_head_t delay_wait;
675 DECLARE_WAITQUEUE(wait, current);
677 init_waitqueue_head(&delay_wait);
678 add_wait_queue(&delay_wait, &wait);
679 set_current_state(TASK_INTERRUPTIBLE);
681 pending = signal_pending(current);
682 remove_wait_queue(&delay_wait, &wait);
683 set_current_state(TASK_RUNNING);
685 return 1; /* Interrupted */
692 dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
697 while (i < DHD_MAX_IFS) {
698 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
707 dhd_ifname2idx(dhd_info_t *dhd, char *name)
713 if (name == NULL || *name == '\0')
717 if (dhd->iflist[i] && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
720 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __FUNCTION__, i, name));
722 return i; /* default - the primary interface */
726 dhd_ifname(dhd_pub_t *dhdp, int ifidx)
728 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
732 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
733 DHD_ERROR(("%s: ifidx %d out of range\n", __FUNCTION__, ifidx));
737 if (dhd->iflist[ifidx] == NULL) {
738 DHD_ERROR(("%s: null i/f %d\n", __FUNCTION__, ifidx));
742 if (dhd->iflist[ifidx]->net)
743 return dhd->iflist[ifidx]->net->name;
749 _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
751 struct net_device *dev;
752 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
753 struct netdev_hw_addr *ha;
755 struct dev_mc_list *mclist;
757 uint32 allmulti, cnt;
764 ASSERT(dhd && dhd->iflist[ifidx]);
765 dev = dhd->iflist[ifidx]->net;
767 netif_addr_lock_bh(dev);
768 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
769 cnt = netdev_mc_count(dev);
773 netif_addr_unlock_bh(dev);
775 /* Determine initial value of allmulti flag */
776 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
778 /* Send down the multicast list first. */
779 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
780 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
781 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
782 dhd_ifname(&dhd->pub, ifidx), cnt));
786 strcpy(bufp, "mcast_list");
787 bufp += strlen("mcast_list") + 1;
790 memcpy(bufp, &cnt, sizeof(cnt));
793 netif_addr_lock_bh(dev);
794 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
795 netdev_for_each_mc_addr(ha, dev) {
798 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
799 bufp += ETHER_ADDR_LEN;
803 for (mclist = dev->mc_list;(mclist && (cnt > 0)); cnt--, mclist = mclist->next) {
804 memcpy(bufp, (void *)mclist->dmi_addr, ETHER_ADDR_LEN);
805 bufp += ETHER_ADDR_LEN;
808 netif_addr_unlock_bh(dev);
810 memset(&ioc, 0, sizeof(ioc));
811 ioc.cmd = WLC_SET_VAR;
816 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
818 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
819 dhd_ifname(&dhd->pub, ifidx), cnt));
820 allmulti = cnt ? TRUE : allmulti;
823 MFREE(dhd->pub.osh, buf, buflen);
825 /* Now send the allmulti setting. This is based on the setting in the
826 * net_device flags, but might be modified above to be turned on if we
827 * were trying to set some addresses and dongle rejected it...
830 buflen = sizeof("allmulti") + sizeof(allmulti);
831 if (!(buf = MALLOC(dhd->pub.osh, buflen))) {
832 DHD_ERROR(("%s: out of memory for allmulti\n", dhd_ifname(&dhd->pub, ifidx)));
835 allmulti = htol32(allmulti);
837 if (!bcm_mkiovar("allmulti", (void*)&allmulti, sizeof(allmulti), buf, buflen)) {
838 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
839 dhd_ifname(&dhd->pub, ifidx), (int)sizeof(allmulti), buflen));
840 MFREE(dhd->pub.osh, buf, buflen);
845 memset(&ioc, 0, sizeof(ioc));
846 ioc.cmd = WLC_SET_VAR;
851 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
853 DHD_ERROR(("%s: set allmulti %d failed\n",
854 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
857 MFREE(dhd->pub.osh, buf, buflen);
859 /* Finally, pick up the PROMISC flag as well, like the NIC driver does */
861 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
862 allmulti = htol32(allmulti);
864 memset(&ioc, 0, sizeof(ioc));
865 ioc.cmd = WLC_SET_PROMISC;
867 ioc.len = sizeof(allmulti);
870 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
872 DHD_ERROR(("%s: set promisc %d failed\n",
873 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
878 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
884 DHD_TRACE(("%s enter\n", __FUNCTION__));
885 if (!bcm_mkiovar("cur_etheraddr", (char*)addr, ETHER_ADDR_LEN, buf, 32)) {
886 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", dhd_ifname(&dhd->pub, ifidx)));
889 memset(&ioc, 0, sizeof(ioc));
890 ioc.cmd = WLC_SET_VAR;
895 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
897 DHD_ERROR(("%s: set cur_etheraddr failed\n", dhd_ifname(&dhd->pub, ifidx)));
899 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
906 extern struct net_device *ap_net_dev;
907 /* semaphore that the soft AP CODE waits on */
908 extern struct semaphore ap_eth_sema;
912 dhd_op_if(dhd_if_t *ifp)
915 int ret = 0, err = 0;
920 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
924 DHD_TRACE(("%s: idx %d, state %d\n", __FUNCTION__, ifp->idx, ifp->state));
926 switch (ifp->state) {
929 * Delete the existing interface before overwriting it
930 * in case we missed the WLC_E_IF_DEL event.
932 if (ifp->net != NULL) {
933 DHD_ERROR(("%s: ERROR: netdev:%s already exists, try free & unregister \n",
934 __FUNCTION__, ifp->net->name));
935 netif_stop_queue(ifp->net);
936 unregister_netdev(ifp->net);
937 free_netdev(ifp->net);
939 /* Allocate etherdev, including space for private structure */
940 if (!(ifp->net = alloc_etherdev(sizeof(dhd)))) {
941 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
945 strcpy(ifp->net->name, ifp->name);
946 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
947 if ((err = dhd_net_attach(&dhd->pub, ifp->idx)) != 0) {
948 DHD_ERROR(("%s: dhd_net_attach failed, err %d\n",
953 flags = dhd_os_spin_lock(&dhd->pub);
954 /* save ptr to wl0.1 netdev for use in wl_iw.c */
955 ap_net_dev = ifp->net;
956 /* signal to the SOFTAP 'sleeper' thread, wl0.1 is ready */
958 dhd_os_spin_unlock(&dhd->pub, flags);
960 DHD_TRACE(("\n ==== pid:%x, net_device for if:%s created ===\n\n",
961 current->pid, ifp->net->name));
967 if (ifp->net != NULL) {
968 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n", __FUNCTION__));
969 netif_stop_queue(ifp->net);
970 unregister_netdev(ifp->net);
971 ret = DHD_DEL_IF; /* Make sure the free_netdev() is called */
975 DHD_ERROR(("%s: bad op %d\n", __FUNCTION__, ifp->state));
982 free_netdev(ifp->net);
984 dhd->iflist[ifp->idx] = NULL;
985 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
987 flags = dhd_os_spin_lock(&dhd->pub);
988 if (ifp->net == ap_net_dev)
989 ap_net_dev = NULL; /* NULL SOFTAP global as well */
990 dhd_os_spin_unlock(&dhd->pub, flags);
996 _dhd_sysioc_thread(void *data)
998 dhd_info_t *dhd = (dhd_info_t *)data;
1002 unsigned long flags;
1005 DAEMONIZE("dhd_sysioc");
1007 while (down_interruptible(&dhd->sysioc_sem) == 0) {
1008 dhd_os_start_lock(&dhd->pub);
1009 dhd_os_wake_lock(&dhd->pub);
1010 for (i = 0; i < DHD_MAX_IFS; i++) {
1011 if (dhd->iflist[i]) {
1012 DHD_TRACE(("%s: interface %d\n",__FUNCTION__, i));
1014 flags = dhd_os_spin_lock(&dhd->pub);
1015 in_ap = (ap_net_dev != NULL);
1016 dhd_os_spin_unlock(&dhd->pub, flags);
1018 if (dhd->iflist[i]->state)
1019 dhd_op_if(dhd->iflist[i]);
1021 if (dhd->iflist[i] == NULL) {
1022 DHD_TRACE(("%s: interface %d just been removed!\n\n", __FUNCTION__, i));
1026 if (in_ap && dhd->set_macaddress) {
1027 DHD_TRACE(("attempt to set MAC for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
1028 dhd->set_macaddress = FALSE;
1032 if (in_ap && dhd->set_multicast) {
1033 DHD_TRACE(("attempt to set MULTICAST list for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
1034 dhd->set_multicast = FALSE;
1038 if (dhd->set_multicast) {
1039 dhd->set_multicast = FALSE;
1040 _dhd_set_multicast_list(dhd, i);
1042 if (dhd->set_macaddress) {
1043 dhd->set_macaddress = FALSE;
1044 _dhd_set_mac_address(dhd, i, &dhd->macvalue);
1048 dhd_os_wake_unlock(&dhd->pub);
1049 dhd_os_start_unlock(&dhd->pub);
1051 DHD_TRACE(("%s: stopped\n",__FUNCTION__));
1052 complete_and_exit(&dhd->sysioc_exited, 0);
1056 dhd_set_mac_address(struct net_device *dev, void *addr)
1060 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1061 struct sockaddr *sa = (struct sockaddr *)addr;
1064 DHD_TRACE(("%s: Enter\n",__FUNCTION__));
1065 ifidx = dhd_net2idx(dhd, dev);
1066 if (ifidx == DHD_BAD_IF)
1069 ASSERT(dhd->sysioc_pid >= 0);
1070 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1071 dhd->set_macaddress = TRUE;
1072 up(&dhd->sysioc_sem);
1078 dhd_set_multicast_list(struct net_device *dev)
1080 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1083 DHD_TRACE(("%s: Enter\n",__FUNCTION__));
1084 ifidx = dhd_net2idx(dhd, dev);
1085 if (ifidx == DHD_BAD_IF)
1088 ASSERT(dhd->sysioc_pid >= 0);
1089 dhd->set_multicast = TRUE;
1090 up(&dhd->sysioc_sem);
1094 dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1097 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1099 /* Reject if down */
1100 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN)) {
1104 /* Update multicast statistic */
1105 if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_ADDR_LEN) {
1106 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
1107 struct ether_header *eh = (struct ether_header *)pktdata;
1109 if (ETHER_ISMULTI(eh->ether_dhost))
1110 dhdp->tx_multicast++;
1111 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1112 atomic_inc(&dhd->pend_8021x_cnt);
1115 /* Look into the packet and update the packet priority */
1116 if ((PKTPRIO(pktbuf) == 0))
1117 pktsetprio(pktbuf, FALSE);
1119 /* If the protocol uses a data header, apply it */
1120 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1122 /* Use bus module to send data frame */
1124 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1126 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1127 #endif /* BCMDBUS */
1133 dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1137 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1140 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1142 dhd_os_wake_lock(&dhd->pub);
1144 /* Reject if down */
1145 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1146 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1147 __FUNCTION__, dhd->pub.up, dhd->pub.busstate));
1148 netif_stop_queue(net);
1149 /* Send Event when bus down detected during data session */
1150 if (dhd->pub.busstate == DHD_BUS_DOWN) {
1151 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1152 net_os_send_hang_message(net);
1154 dhd_os_wake_unlock(&dhd->pub);
1158 ifidx = dhd_net2idx(dhd, net);
1159 if (ifidx == DHD_BAD_IF) {
1160 DHD_ERROR(("%s: bad ifidx %d\n", __FUNCTION__, ifidx));
1161 netif_stop_queue(net);
1162 dhd_os_wake_unlock(&dhd->pub);
1166 /* Make sure there's enough room for any header */
1167 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1168 struct sk_buff *skb2;
1170 DHD_INFO(("%s: insufficient headroom\n",
1171 dhd_ifname(&dhd->pub, ifidx)));
1172 dhd->pub.tx_realloc++;
1173 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1175 if ((skb = skb2) == NULL) {
1176 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1177 dhd_ifname(&dhd->pub, ifidx)));
1183 /* Convert to packet */
1184 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
1185 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1186 dhd_ifname(&dhd->pub, ifidx)));
1187 dev_kfree_skb_any(skb);
1192 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1196 dhd->pub.dstats.tx_dropped++;
1198 dhd->pub.tx_packets++;
1200 dhd_os_wake_unlock(&dhd->pub);
1202 /* Return ok: we always eat the packet */
1207 dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1209 struct net_device *net;
1210 dhd_info_t *dhd = dhdp->info;
1212 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1214 dhdp->txoff = state;
1215 ASSERT(dhd && dhd->iflist[ifidx]);
1216 net = dhd->iflist[ifidx]->net;
1218 netif_stop_queue(net);
1220 netif_wake_queue(net);
1224 dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1226 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1227 struct sk_buff *skb;
1230 void * data, *pnext, *save_pktbuf;
1233 wl_event_msg_t event;
1235 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1237 save_pktbuf = pktbuf;
1239 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1241 pnext = PKTNEXT(dhdp->osh, pktbuf);
1242 PKTSETNEXT(wl->sh.osh, pktbuf, NULL);
1245 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1247 /* Get the protocol, maintain skb around eth_type_trans()
1248 * The main reason for this hack is for the limitation of
1249 * Linux 2.4 where 'eth_type_trans' uses the 'net->hard_header_len'
1250 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1251 * coping of the packet coming from the network stack to add
1252 * BDC, Hardware header etc, during network interface registration
1253 * we set the 'net->hard_header_len' to ETH_HLEN + extra space required
1254 * for BDC, Hardware header etc. and not just the ETH_HLEN
1259 ifp = dhd->iflist[ifidx];
1261 ifp = dhd->iflist[0];
1264 skb->dev = ifp->net;
1265 skb->protocol = eth_type_trans(skb, skb->dev);
1267 if (skb->pkt_type == PACKET_MULTICAST) {
1268 dhd->pub.rx_multicast++;
1274 /* Strip header, count, deliver upward */
1275 skb_pull(skb, ETH_HLEN);
1277 /* Process special event packets and then discard them */
1278 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1279 dhd_wl_host_event(dhd, &ifidx,
1280 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1288 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1289 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1290 ifp = dhd->iflist[ifidx];
1293 ifp->net->last_rx = jiffies;
1295 dhdp->dstats.rx_bytes += skb->len;
1296 dhdp->rx_packets++; /* Local count */
1298 if (in_interrupt()) {
1301 /* If the receive is not processed inside an ISR,
1302 * the softirqd must be woken explicitly to service
1303 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1304 * by netif_rx_ni(), but in earlier kernels, we need
1305 * to do it manually.
1307 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1312 local_irq_save(flags);
1314 local_irq_restore(flags);
1315 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
1318 dhd_os_wake_lock_timeout_enable(dhdp);
1322 dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1324 /* Linux version has nothing to do */
1329 dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1332 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1333 struct ether_header *eh;
1336 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1338 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
1339 type = ntoh16(eh->ether_type);
1341 if (type == ETHER_TYPE_802_1X)
1342 atomic_dec(&dhd->pend_8021x_cnt);
1346 static struct net_device_stats *
1347 dhd_get_stats(struct net_device *net)
1349 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1353 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1355 ifidx = dhd_net2idx(dhd, net);
1356 if (ifidx == DHD_BAD_IF)
1359 ifp = dhd->iflist[ifidx];
1363 /* Use the protocol to get dongle stats */
1364 dhd_prot_dstats(&dhd->pub);
1367 /* Copy dongle stats to net device stats */
1368 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1369 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1370 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1371 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1372 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1373 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1374 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1375 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1376 ifp->stats.multicast = dhd->pub.dstats.multicast;
1382 dhd_watchdog_thread(void *data)
1384 dhd_info_t *dhd = (dhd_info_t *)data;
1386 /* This thread doesn't need any user-level access,
1387 * so get rid of all our resources
1390 if (dhd_watchdog_prio > 0) {
1391 struct sched_param param;
1392 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO)?
1393 dhd_watchdog_prio:(MAX_RT_PRIO-1);
1394 setScheduler(current, SCHED_FIFO, ¶m);
1396 #endif /* DHD_SCHED */
1398 DAEMONIZE("dhd_watchdog");
1400 /* Run until signal received */
1402 if (down_interruptible (&dhd->watchdog_sem) == 0) {
1403 dhd_os_sdlock(&dhd->pub);
1404 if (dhd->pub.dongle_reset == FALSE) {
1405 DHD_TIMER(("%s:\n", __FUNCTION__));
1406 /* Call the bus module watchdog */
1407 dhd_bus_watchdog(&dhd->pub);
1409 /* Count the tick for reference */
1412 /* Reschedule the watchdog */
1413 if (dhd->wd_timer_valid)
1414 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1416 dhd_os_sdunlock(&dhd->pub);
1417 dhd_os_wake_unlock(&dhd->pub);
1423 complete_and_exit(&dhd->watchdog_exited, 0);
1427 dhd_watchdog(ulong data)
1429 dhd_info_t *dhd = (dhd_info_t *)data;
1431 dhd_os_wake_lock(&dhd->pub);
1432 if (dhd->pub.dongle_reset) {
1433 dhd_os_wake_unlock(&dhd->pub);
1437 if (dhd->watchdog_pid >= 0) {
1438 up(&dhd->watchdog_sem);
1442 dhd_os_sdlock(&dhd->pub);
1443 /* Call the bus module watchdog */
1444 dhd_bus_watchdog(&dhd->pub);
1446 /* Count the tick for reference */
1449 /* Reschedule the watchdog */
1450 if (dhd->wd_timer_valid)
1451 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1452 dhd_os_sdunlock(&dhd->pub);
1453 dhd_os_wake_unlock(&dhd->pub);
1457 dhd_dpc_thread(void *data)
1459 dhd_info_t *dhd = (dhd_info_t *)data;
1461 /* This thread doesn't need any user-level access,
1462 * so get rid of all our resources
1465 if (dhd_dpc_prio > 0)
1467 struct sched_param param;
1468 param.sched_priority = (dhd_dpc_prio < MAX_RT_PRIO)?dhd_dpc_prio:(MAX_RT_PRIO-1);
1469 setScheduler(current, SCHED_FIFO, ¶m);
1471 #endif /* DHD_SCHED */
1473 DAEMONIZE("dhd_dpc");
1475 /* Run until signal received */
1477 if (down_interruptible(&dhd->dpc_sem) == 0) {
1478 /* Call bus dpc unless it indicated down (then clean stop) */
1479 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1480 if (dhd_bus_dpc(dhd->pub.bus)) {
1484 dhd_os_wake_unlock(&dhd->pub);
1487 dhd_bus_stop(dhd->pub.bus, TRUE);
1488 dhd_os_wake_unlock(&dhd->pub);
1495 complete_and_exit(&dhd->dpc_exited, 0);
1503 dhd = (dhd_info_t *)data;
1505 /* Call bus dpc unless it indicated down (then clean stop) */
1506 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1507 if (dhd_bus_dpc(dhd->pub.bus))
1508 tasklet_schedule(&dhd->tasklet);
1510 dhd_bus_stop(dhd->pub.bus, TRUE);
1515 dhd_sched_dpc(dhd_pub_t *dhdp)
1517 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1519 dhd_os_wake_lock(dhdp);
1520 if (dhd->dpc_pid >= 0) {
1525 tasklet_schedule(&dhd->tasklet);
1529 /* Retrieve current toe component enables, which are kept as a bitmap in toe_ol iovar */
1531 dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
1537 memset(&ioc, 0, sizeof(ioc));
1539 ioc.cmd = WLC_GET_VAR;
1541 ioc.len = (uint)sizeof(buf);
1544 strcpy(buf, "toe_ol");
1545 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1546 /* Check for older dongle image that doesn't support toe_ol */
1548 DHD_ERROR(("%s: toe not supported by device\n",
1549 dhd_ifname(&dhd->pub, ifidx)));
1553 DHD_INFO(("%s: could not get toe_ol: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1557 memcpy(toe_ol, buf, sizeof(uint32));
1561 /* Set current toe component enables in toe_ol iovar, and set toe global enable iovar */
1563 dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
1569 memset(&ioc, 0, sizeof(ioc));
1571 ioc.cmd = WLC_SET_VAR;
1573 ioc.len = (uint)sizeof(buf);
1576 /* Set toe_ol as requested */
1578 strcpy(buf, "toe_ol");
1579 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
1581 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1582 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1583 dhd_ifname(&dhd->pub, ifidx), ret));
1587 /* Enable toe globally only if any components are enabled. */
1589 toe = (toe_ol != 0);
1592 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
1594 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1595 DHD_ERROR(("%s: could not set toe: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1603 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1604 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1605 struct ethtool_drvinfo *info)
1607 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1609 sprintf(info->driver, "wl");
1610 sprintf(info->version, "%lu", dhd->pub.drv_version);
1613 struct ethtool_ops dhd_ethtool_ops = {
1614 .get_drvinfo = dhd_ethtool_get_drvinfo
1616 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
1619 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1621 dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1623 struct ethtool_drvinfo info;
1624 char drvname[sizeof(info.driver)];
1627 struct ethtool_value edata;
1628 uint32 toe_cmpnt, csum_dir;
1632 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1634 /* all ethtool calls start with a cmd word */
1635 if (copy_from_user(&cmd, uaddr, sizeof (uint32)))
1639 case ETHTOOL_GDRVINFO:
1640 /* Copy out any request driver name */
1641 if (copy_from_user(&info, uaddr, sizeof(info)))
1643 strncpy(drvname, info.driver, sizeof(info.driver));
1644 drvname[sizeof(info.driver)-1] = '\0';
1646 /* clear struct for return */
1647 memset(&info, 0, sizeof(info));
1650 /* if dhd requested, identify ourselves */
1651 if (strcmp(drvname, "?dhd") == 0) {
1652 sprintf(info.driver, "dhd");
1653 strcpy(info.version, EPI_VERSION_STR);
1656 /* otherwise, require dongle to be up */
1657 else if (!dhd->pub.up) {
1658 DHD_ERROR(("%s: dongle is not up\n", __FUNCTION__));
1662 /* finally, report dongle driver type */
1663 else if (dhd->pub.iswl)
1664 sprintf(info.driver, "wl");
1666 sprintf(info.driver, "xx");
1668 sprintf(info.version, "%lu", dhd->pub.drv_version);
1669 if (copy_to_user(uaddr, &info, sizeof(info)))
1671 DHD_CTL(("%s: given %*s, returning %s\n", __FUNCTION__,
1672 (int)sizeof(drvname), drvname, info.driver));
1676 /* Get toe offload components from dongle */
1677 case ETHTOOL_GRXCSUM:
1678 case ETHTOOL_GTXCSUM:
1679 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1682 csum_dir = (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1685 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1687 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1691 /* Set toe offload components in dongle */
1692 case ETHTOOL_SRXCSUM:
1693 case ETHTOOL_STXCSUM:
1694 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1697 /* Read the current settings, update and write back */
1698 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1701 csum_dir = (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1703 if (edata.data != 0)
1704 toe_cmpnt |= csum_dir;
1706 toe_cmpnt &= ~csum_dir;
1708 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
1711 /* If setting TX checksum mode, tell Linux the new mode */
1712 if (cmd == ETHTOOL_STXCSUM) {
1714 dhd->iflist[0]->net->features |= NETIF_F_IP_CSUM;
1716 dhd->iflist[0]->net->features &= ~NETIF_F_IP_CSUM;
1728 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1731 dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1733 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1740 bool is_set_key_cmd;
1743 dhd_os_wake_lock(&dhd->pub);
1745 ifidx = dhd_net2idx(dhd, net);
1746 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
1748 if (ifidx == DHD_BAD_IF) {
1749 dhd_os_wake_unlock(&dhd->pub);
1753 #if defined(CONFIG_WIRELESS_EXT)
1754 /* linux wireless extensions */
1755 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1756 /* may recurse, do NOT lock */
1757 ret = wl_iw_ioctl(net, ifr, cmd);
1758 dhd_os_wake_unlock(&dhd->pub);
1761 #endif /* defined(CONFIG_WIRELESS_EXT) */
1763 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1764 if (cmd == SIOCETHTOOL) {
1765 ret = dhd_ethtool(dhd, (void*)ifr->ifr_data);
1766 dhd_os_wake_unlock(&dhd->pub);
1769 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1771 if (cmd != SIOCDEVPRIVATE) {
1772 dhd_os_wake_unlock(&dhd->pub);
1776 memset(&ioc, 0, sizeof(ioc));
1778 /* Copy the ioc control structure part of ioctl request */
1779 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1780 bcmerror = -BCME_BADADDR;
1784 /* Copy out any buffer passed */
1786 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1787 /* optimization for direct ioctl calls from kernel */
1789 if (segment_eq(get_fs(), KERNEL_DS)) {
1794 if (!(buf = (char*)MALLOC(dhd->pub.osh, buflen))) {
1795 bcmerror = -BCME_NOMEM;
1798 if (copy_from_user(buf, ioc.buf, buflen)) {
1799 bcmerror = -BCME_BADADDR;
1805 /* To differentiate between wl and dhd read 4 more byes */
1806 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1807 sizeof(uint)) != 0)) {
1808 bcmerror = -BCME_BADADDR;
1812 if (!capable(CAP_NET_ADMIN)) {
1813 bcmerror = -BCME_EPERM;
1817 /* check for local dhd ioctl and handle it */
1818 if (driver == DHD_IOCTL_MAGIC) {
1819 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1821 dhd->pub.bcmerror = bcmerror;
1825 /* send to dongle (must be up, and wl) */
1826 if (dhd->pub.busstate != DHD_BUS_DATA) {
1827 DHD_ERROR(("%s DONGLE_DOWN\n", __FUNCTION__));
1828 bcmerror = BCME_DONGLE_DOWN;
1832 if (!dhd->pub.iswl) {
1833 bcmerror = BCME_DONGLE_DOWN;
1837 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1838 * prevent M4 encryption.
1840 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1841 ((ioc.cmd == WLC_SET_VAR) &&
1842 !(strncmp("wsec_key", ioc.buf, 9))) ||
1843 ((ioc.cmd == WLC_SET_VAR) &&
1844 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1845 if (is_set_key_cmd) {
1846 dhd_wait_pend8021x(net);
1849 bcmerror = dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1852 if ((bcmerror == -ETIMEDOUT) || ((dhd->pub.busstate == DHD_BUS_DOWN) &&
1853 (!dhd->pub.dongle_reset))) {
1854 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1855 net_os_send_hang_message(net);
1858 if (!bcmerror && buf && ioc.buf) {
1859 if (copy_to_user(ioc.buf, buf, buflen))
1864 MFREE(dhd->pub.osh, buf, buflen);
1866 dhd_os_wake_unlock(&dhd->pub);
1868 return OSL_ERROR(bcmerror);
1872 dhd_stop(struct net_device *net)
1874 #if !defined(IGNORE_ETH0_DOWN)
1875 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1877 DHD_TRACE(("%s: Enter %s\n", __FUNCTION__, net->name));
1878 if (dhd->pub.up == 0) {
1882 /* Set state and stop OS transmissions */
1884 netif_stop_queue(net);
1886 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation ...\n", __FUNCTION__));
1887 #endif /* !defined(IGNORE_ETH0_DOWN) */
1889 OLD_MOD_DEC_USE_COUNT;
1894 dhd_open(struct net_device *net)
1896 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1902 /* Force start if ifconfig_up gets called before START command */
1903 wl_control_wl_start(net);
1905 ifidx = dhd_net2idx(dhd, net);
1906 if (ifidx == DHD_BAD_IF)
1908 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
1910 if ((dhd->iflist[ifidx]) && (dhd->iflist[ifidx]->state == WLC_E_IF_DEL)) {
1911 DHD_ERROR(("%s: Error: called when IF already deleted\n", __FUNCTION__));
1915 if (ifidx == 0) { /* do it only for primary eth0 */
1917 atomic_set(&dhd->pend_8021x_cnt, 0);
1919 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1922 /* Get current TOE mode from dongle */
1923 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1924 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1926 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1929 /* Allow transmit calls */
1930 netif_start_queue(net);
1933 OLD_MOD_INC_USE_COUNT;
1938 dhd_osl_attach(void *pdev, uint bustype)
1940 return osl_attach(pdev, bustype, TRUE);
1944 dhd_osl_detach(osl_t *osh)
1946 if (MALLOCED(osh)) {
1947 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __FUNCTION__, MALLOCED(osh)));
1950 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && 1
1951 up(&dhd_registration_sem);
1952 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
1956 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1957 uint8 *mac_addr, uint32 flags, uint8 bssidx)
1961 DHD_TRACE(("%s: idx %d, handle->%p\n", __FUNCTION__, ifidx, handle));
1963 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1965 ifp = dhd->iflist[ifidx];
1966 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1967 DHD_ERROR(("%s: OOM - dhd_if_t\n", __FUNCTION__));
1971 memset(ifp, 0, sizeof(dhd_if_t));
1973 dhd->iflist[ifidx] = ifp;
1974 strncpy(ifp->name, name, IFNAMSIZ);
1975 ifp->name[IFNAMSIZ] = '\0';
1976 if (mac_addr != NULL)
1977 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1979 if (handle == NULL) {
1980 ifp->state = WLC_E_IF_ADD;
1982 ASSERT(dhd->sysioc_pid >= 0);
1983 up(&dhd->sysioc_sem);
1985 ifp->net = (struct net_device *)handle;
1991 dhd_del_if(dhd_info_t *dhd, int ifidx)
1995 DHD_TRACE(("%s: idx %d\n", __FUNCTION__, ifidx));
1997 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1998 ifp = dhd->iflist[ifidx];
2000 DHD_ERROR(("%s: Null interface\n", __FUNCTION__));
2004 ifp->state = WLC_E_IF_DEL;
2006 ASSERT(dhd->sysioc_pid >= 0);
2007 up(&dhd->sysioc_sem);
2011 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
2013 dhd_info_t *dhd = NULL;
2014 struct net_device *net;
2016 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2017 /* updates firmware nvram path if it was provided as module paramters */
2018 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
2019 strcpy(fw_path, firmware_path);
2020 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
2021 strcpy(nv_path, nvram_path);
2023 /* Allocate etherdev, including space for private structure */
2024 if (!(net = alloc_etherdev(sizeof(dhd)))) {
2025 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
2029 /* Allocate primary dhd_info */
2030 if (!(dhd = MALLOC(osh, sizeof(dhd_info_t)))) {
2031 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __FUNCTION__));
2035 memset(dhd, 0, sizeof(dhd_info_t));
2038 * Save the dhd_info into the priv
2040 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2043 /* Set network interface name if it was provided as module parameter */
2044 if (iface_name[0]) {
2047 strncpy(net->name, iface_name, IFNAMSIZ);
2048 net->name[IFNAMSIZ - 1] = 0;
2049 len = strlen(net->name);
2050 ch = net->name[len - 1];
2051 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
2052 strcat(net->name, "%d");
2055 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) == DHD_BAD_IF)
2058 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2061 net->netdev_ops = NULL;
2064 init_MUTEX(&dhd->proto_sem);
2065 /* Initialize other structure content */
2066 init_waitqueue_head(&dhd->ioctl_resp_wait);
2067 init_waitqueue_head(&dhd->ctrl_wait);
2069 /* Initialize the spinlocks */
2070 spin_lock_init(&dhd->sdlock);
2071 spin_lock_init(&dhd->txqlock);
2072 spin_lock_init(&dhd->dhd_lock);
2074 /* Initialize Wakelock stuff */
2075 spin_lock_init(&dhd->wl_lock);
2078 #ifdef CONFIG_HAS_WAKELOCK
2079 wake_lock_init(&dhd->wl_wifi, WAKE_LOCK_SUSPEND, "wlan_wake");
2080 wake_lock_init(&dhd->wl_rxwake, WAKE_LOCK_SUSPEND, "wlan_rx_wake");
2082 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
2083 mutex_init(&dhd->wl_start_lock);
2085 /* Link to info module */
2086 dhd->pub.info = dhd;
2088 /* Link to bus module */
2090 dhd->pub.hdrlen = bus_hdrlen;
2092 /* Attach and link in the protocol */
2093 if (dhd_prot_attach(&dhd->pub) != 0) {
2094 DHD_ERROR(("dhd_prot_attach failed\n"));
2097 #if defined(CONFIG_WIRELESS_EXT)
2098 /* Attach and link in the iw */
2099 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
2100 DHD_ERROR(("wl_iw_attach failed\n"));
2103 #endif /* defined(CONFIG_WIRELESS_EXT) */
2105 /* Set up the watchdog timer */
2106 init_timer(&dhd->timer);
2107 dhd->timer.data = (ulong)dhd;
2108 dhd->timer.function = dhd_watchdog;
2110 /* Initialize thread based operation and lock */
2111 init_MUTEX(&dhd->sdsem);
2112 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)) {
2113 dhd->threads_only = TRUE;
2116 dhd->threads_only = FALSE;
2119 if (dhd_dpc_prio >= 0) {
2120 /* Initialize watchdog thread */
2121 sema_init(&dhd->watchdog_sem, 0);
2122 init_completion(&dhd->watchdog_exited);
2123 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2125 dhd->watchdog_pid = -1;
2128 /* Set up the bottom half handler */
2129 if (dhd_dpc_prio >= 0) {
2130 /* Initialize DPC thread */
2131 sema_init(&dhd->dpc_sem, 0);
2132 init_completion(&dhd->dpc_exited);
2133 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2135 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
2140 sema_init(&dhd->sysioc_sem, 0);
2141 init_completion(&dhd->sysioc_exited);
2142 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2144 dhd->sysioc_pid = -1;
2148 * Save the dhd_info into the priv
2150 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2152 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2155 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2156 register_pm_notifier(&dhd_sleep_pm_notifier);
2157 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2159 #ifdef CONFIG_HAS_EARLYSUSPEND
2160 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2161 dhd->early_suspend.suspend = dhd_early_suspend;
2162 dhd->early_suspend.resume = dhd_late_resume;
2163 register_early_suspend(&dhd->early_suspend);
2172 dhd_detach(&dhd->pub);
2179 dhd_bus_start(dhd_pub_t *dhdp)
2182 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
2183 #ifdef EMBEDDED_PLATFORM
2184 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
2185 #endif /* EMBEDDED_PLATFORM */
2189 DHD_TRACE(("%s: \n", __FUNCTION__));
2191 /* try to download image and nvram to the dongle */
2192 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2193 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2194 fw_path, nv_path))) {
2195 DHD_ERROR(("%s: dhdsdio_probe_download failed. firmware = %s nvram = %s\n",
2196 __FUNCTION__, fw_path, nv_path));
2201 /* Start the watchdog timer */
2202 dhd->pub.tickcnt = 0;
2203 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2205 /* Bring up the bus */
2206 if ((ret = dhd_bus_init(&dhd->pub, TRUE)) != 0) {
2207 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
2210 #if defined(OOB_INTR_ONLY)
2211 /* Host registration for OOB interrupt */
2212 if (bcmsdh_register_oob_intr(dhdp)) {
2213 dhd->wd_timer_valid = FALSE;
2214 del_timer_sync(&dhd->timer);
2215 DHD_ERROR(("%s Host failed to resgister for OOB\n", __FUNCTION__));
2219 /* Enable oob at firmware */
2220 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2221 #endif /* defined(OOB_INTR_ONLY) */
2223 /* If bus is not ready, can't come up */
2224 if (dhd->pub.busstate != DHD_BUS_DATA) {
2225 dhd->wd_timer_valid = FALSE;
2226 del_timer_sync(&dhd->timer);
2227 DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
2231 #ifdef EMBEDDED_PLATFORM
2232 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
2233 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2234 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2236 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2237 setbit(dhdp->eventmask, WLC_E_PRUNE);
2238 setbit(dhdp->eventmask, WLC_E_AUTH);
2239 setbit(dhdp->eventmask, WLC_E_REASSOC);
2240 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2241 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2242 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2243 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2244 setbit(dhdp->eventmask, WLC_E_JOIN);
2245 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2246 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2247 setbit(dhdp->eventmask, WLC_E_LINK);
2248 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2249 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2250 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2251 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2252 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2253 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2254 setbit(dhdp->eventmask, WLC_E_RELOAD);
2256 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2257 #endif /* PNO_SUPPORT */
2259 /* enable dongle roaming event */
2260 setbit(dhdp->eventmask, WLC_E_ROAM);
2262 dhdp->pktfilter_count = 1;
2263 /* Setup filter to allow only unicast */
2264 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2265 #endif /* EMBEDDED_PLATFORM */
2267 /* Bus is ready, do any protocol initialization */
2268 if ((ret = dhd_prot_init(&dhd->pub)) < 0)
2275 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len, int set)
2277 char buf[strlen(name) + 1 + cmd_len];
2278 int len = sizeof(buf);
2282 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2284 memset(&ioc, 0, sizeof(ioc));
2286 ioc.cmd = set? WLC_SET_VAR : WLC_GET_VAR;
2291 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2292 if (!set && ret >= 0)
2293 memcpy(cmd_buf, buf, cmd_len);
2298 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 31))
2299 static struct net_device_ops dhd_ops_pri = {
2300 .ndo_open = dhd_open,
2301 .ndo_stop = dhd_stop,
2302 .ndo_get_stats = dhd_get_stats,
2303 .ndo_do_ioctl = dhd_ioctl_entry,
2304 .ndo_start_xmit = dhd_start_xmit,
2305 .ndo_set_mac_address = dhd_set_mac_address,
2306 .ndo_set_multicast_list = dhd_set_multicast_list,
2309 static struct net_device_ops dhd_ops_virt = {
2310 .ndo_get_stats = dhd_get_stats,
2311 .ndo_do_ioctl = dhd_ioctl_entry,
2312 .ndo_start_xmit = dhd_start_xmit,
2313 .ndo_set_mac_address = dhd_set_mac_address,
2314 .ndo_set_multicast_list = dhd_set_multicast_list,
2319 dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2321 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2322 struct net_device *net;
2323 uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33 };
2325 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
2327 ASSERT(dhd && dhd->iflist[ifidx]);
2328 net = dhd->iflist[ifidx]->net;
2331 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2333 net->get_stats = dhd_get_stats;
2334 net->do_ioctl = dhd_ioctl_entry;
2335 net->hard_start_xmit = dhd_start_xmit;
2336 net->set_mac_address = dhd_set_mac_address;
2337 net->set_multicast_list = dhd_set_multicast_list;
2338 net->open = net->stop = NULL;
2340 ASSERT(!net->netdev_ops);
2341 net->netdev_ops = &dhd_ops_virt;
2344 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2345 net->open = dhd_open;
2346 net->stop = dhd_stop;
2348 net->netdev_ops = &dhd_ops_pri;
2352 * We have to use the primary MAC for virtual interfaces
2355 /* for virtual interfaces use the primary MAC */
2356 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2360 DHD_TRACE(("%s ACCESS POINT MAC: \n", __FUNCTION__));
2361 /* ACCESSPOINT INTERFACE CASE */
2362 temp_addr[0] |= 0x02; /* set bit 2 , - Locally Administered address */
2364 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2365 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2366 net->ethtool_ops = &dhd_ethtool_ops;
2367 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
2369 #if defined(CONFIG_WIRELESS_EXT)
2370 #if WIRELESS_EXT < 19
2371 net->get_wireless_stats = dhd_get_wireless_stats;
2372 #endif /* WIRELESS_EXT < 19 */
2373 #if WIRELESS_EXT > 12
2374 net->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
2375 #endif /* WIRELESS_EXT > 12 */
2376 #endif /* defined(CONFIG_WIRELESS_EXT) */
2378 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2380 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2382 if (register_netdev(net) != 0) {
2383 DHD_ERROR(("%s: couldn't register the net device\n", __FUNCTION__));
2387 printf("%s: Broadcom Dongle Host Driver mac=%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", net->name,
2388 dhd->pub.mac.octet[0], dhd->pub.mac.octet[1], dhd->pub.mac.octet[2],
2389 dhd->pub.mac.octet[3], dhd->pub.mac.octet[4], dhd->pub.mac.octet[5]);
2391 #if defined(CONFIG_WIRELESS_EXT)
2392 #if defined(CONFIG_FIRST_SCAN)
2395 /* Don't call for SOFTAP Interface in SOFTAP MODE */
2396 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2398 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2400 #endif /* CONFIG_FIRST_SCAN */
2401 #endif /* CONFIG_WIRELESS_EXT */
2403 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2404 up(&dhd_registration_sem);
2405 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
2409 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2412 net->netdev_ops = NULL;
2418 dhd_bus_detach(dhd_pub_t *dhdp)
2422 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2425 dhd = (dhd_info_t *)dhdp->info;
2427 /* Stop the protocol module */
2428 dhd_prot_stop(&dhd->pub);
2430 /* Stop the bus module */
2431 dhd_bus_stop(dhd->pub.bus, TRUE);
2432 #if defined(OOB_INTR_ONLY)
2433 bcmsdh_unregister_oob_intr();
2434 #endif /* defined(OOB_INTR_ONLY) */
2436 /* Clear the watchdog timer */
2437 dhd->wd_timer_valid = FALSE;
2438 del_timer_sync(&dhd->timer);
2444 dhd_detach(dhd_pub_t *dhdp)
2448 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2451 dhd = (dhd_info_t *)dhdp->info;
2456 #if defined(CONFIG_HAS_EARLYSUSPEND)
2457 if (dhd->early_suspend.suspend)
2458 unregister_early_suspend(&dhd->early_suspend);
2459 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2460 #if defined(CONFIG_WIRELESS_EXT)
2461 /* Attach and link in the iw */
2464 if (dhd->sysioc_pid >= 0) {
2465 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2466 wait_for_completion(&dhd->sysioc_exited);
2469 for (i = 1; i < DHD_MAX_IFS; i++)
2470 if (dhd->iflist[i]) {
2471 dhd->iflist[i]->state = WLC_E_IF_DEL;
2472 dhd->iflist[i]->idx = i;
2473 dhd_op_if(dhd->iflist[i]);
2476 ifp = dhd->iflist[0];
2478 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2479 if (ifp->net->open) {
2481 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2484 unregister_netdev(ifp->net);
2487 if (dhd->watchdog_pid >= 0)
2489 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2490 wait_for_completion(&dhd->watchdog_exited);
2493 if (dhd->dpc_pid >= 0)
2495 KILL_PROC(dhd->dpc_pid, SIGTERM);
2496 wait_for_completion(&dhd->dpc_exited);
2499 tasklet_kill(&dhd->tasklet);
2501 dhd_bus_detach(dhdp);
2504 dhd_prot_detach(dhdp);
2506 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2507 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2508 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2509 free_netdev(ifp->net);
2510 #ifdef CONFIG_HAS_WAKELOCK
2511 wake_lock_destroy(&dhd->wl_wifi);
2512 wake_lock_destroy(&dhd->wl_rxwake);
2514 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2515 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2521 rockchip_wifi_exit_module(void)
2523 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2525 dhd_bus_unregister();
2526 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2529 /* Call customer gpio to turn off power with WL_REG_ON signal */
2530 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2534 rockchip_wifi_init_module(void)
2538 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2540 /* Sanity check on the module parameters */
2542 /* Both watchdog and DPC as tasklets are ok */
2543 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2546 /* If both watchdog and DPC are threads, TX must be deferred */
2547 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0) && dhd_deferred_tx)
2550 DHD_ERROR(("Invalid module parameters.\n"));
2554 /* Call customer gpio to turn on power with WL_REG_ON signal */
2555 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2557 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2558 sema_init(&wifi_control_sem, 0);
2560 error = wifi_add_dev();
2562 DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__));
2566 /* Waiting callback after platform_driver_register is done or exit with error */
2567 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(5000)) != 0) {
2569 DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__));
2572 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2574 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2575 sema_init(&dhd_registration_sem, 0);
2578 error = dhd_bus_register();
2581 printf("\n%s\n", dhd_version);
2583 DHD_ERROR(("%s: sdio_register_driver failed\n", __FUNCTION__));
2586 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2588 * Wait till MMC sdio_register_driver callback called and made driver attach.
2589 * It's needed to make sync up exit from dhd insmod and
2590 * Kernel MMC sdio device callback registration
2592 if (down_timeout(&dhd_registration_sem, msecs_to_jiffies(DHD_REGISTRATION_TIMEOUT)) != 0) {
2594 DHD_ERROR(("%s: sdio_register_driver timeout\n", __FUNCTION__));
2599 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2601 dhd_bus_unregister();
2604 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2607 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2609 /* Call customer gpio to turn off power with WL_REG_ON signal */
2610 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2615 //module_init(dhd_module_init);
2616 //module_exit(dhd_module_cleanup);
2617 int mv88w8686_if_sdio_init_module(void)
2619 return rockchip_wifi_init_module();
2622 void mv88w8686_if_sdio_exit_module(void)
2624 rockchip_wifi_exit_module();
2627 EXPORT_SYMBOL(rockchip_wifi_init_module);
2628 EXPORT_SYMBOL(rockchip_wifi_exit_module);
2629 EXPORT_SYMBOL(mv88w8686_if_sdio_init_module);
2630 EXPORT_SYMBOL(mv88w8686_if_sdio_exit_module);
2634 * OS specific functions required to implement DHD driver in OS independent way
2637 dhd_os_proto_block(dhd_pub_t *pub)
2639 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2642 down(&dhd->proto_sem);
2650 dhd_os_proto_unblock(dhd_pub_t *pub)
2652 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2655 up(&dhd->proto_sem);
2663 dhd_os_get_ioctl_resp_timeout(void)
2665 return ((unsigned int)dhd_ioctl_timeout_msec);
2669 dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2671 dhd_ioctl_timeout_msec = (int)timeout_msec;
2675 dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2677 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2678 DECLARE_WAITQUEUE(wait, current);
2679 int timeout = dhd_ioctl_timeout_msec;
2681 /* Convert timeout in millsecond to jiffies */
2682 /* timeout = timeout * HZ / 1000; */
2683 timeout = msecs_to_jiffies(timeout);
2685 /* Wait until control frame is available */
2686 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2687 set_current_state(TASK_INTERRUPTIBLE);
2689 while (!(*condition) && (!signal_pending(current) && timeout)) {
2690 timeout = schedule_timeout(timeout);
2694 if (signal_pending(current))
2697 set_current_state(TASK_RUNNING);
2698 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2704 dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2706 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2708 if (waitqueue_active(&dhd->ioctl_resp_wait)) {
2709 wake_up_interruptible(&dhd->ioctl_resp_wait);
2716 dhd_os_wd_timer(void *bus, uint wdtick)
2718 dhd_pub_t *pub = bus;
2719 dhd_info_t *dhd = (dhd_info_t *)pub->info;
2720 unsigned long flags;
2721 int del_timer_flag = FALSE;
2723 flags = dhd_os_spin_lock(pub);
2725 /* don't start the wd until fw is loaded */
2726 if (pub->busstate != DHD_BUS_DOWN) {
2728 dhd_watchdog_ms = (uint)wdtick;
2729 dhd->wd_timer_valid = TRUE;
2730 /* Re arm the timer, at last watchdog period */
2731 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
2732 } else if (dhd->wd_timer_valid == TRUE) {
2733 /* Totally stop the timer */
2734 dhd->wd_timer_valid = FALSE;
2735 del_timer_flag = TRUE;
2738 dhd_os_spin_unlock(pub, flags);
2739 if (del_timer_flag) {
2740 del_timer_sync(&dhd->timer);
2745 dhd_os_open_image(char *filename)
2749 fp = filp_open(filename, O_RDONLY, 0);
2751 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2753 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2763 dhd_os_get_image_block(char *buf, int len, void *image)
2765 struct file *fp = (struct file *)image;
2771 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2779 dhd_os_close_image(void *image)
2782 filp_close((struct file *)image, NULL);
2787 dhd_os_sdlock(dhd_pub_t *pub)
2791 dhd = (dhd_info_t *)(pub->info);
2793 if (dhd->threads_only)
2796 spin_lock_bh(&dhd->sdlock);
2800 dhd_os_sdunlock(dhd_pub_t *pub)
2804 dhd = (dhd_info_t *)(pub->info);
2806 if (dhd->threads_only)
2809 spin_unlock_bh(&dhd->sdlock);
2813 dhd_os_sdlock_txq(dhd_pub_t *pub)
2817 dhd = (dhd_info_t *)(pub->info);
2818 spin_lock_bh(&dhd->txqlock);
2822 dhd_os_sdunlock_txq(dhd_pub_t *pub)
2826 dhd = (dhd_info_t *)(pub->info);
2827 spin_unlock_bh(&dhd->txqlock);
2830 dhd_os_sdlock_rxq(dhd_pub_t *pub)
2834 dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2839 dhd_os_sdtxlock(dhd_pub_t *pub)
2845 dhd_os_sdtxunlock(dhd_pub_t *pub)
2847 dhd_os_sdunlock(pub);
2850 #ifdef DHD_USE_STATIC_BUF
2851 void * dhd_os_prealloc(int section, unsigned long size)
2853 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2854 void *alloc_ptr = NULL;
2855 if (wifi_control_data && wifi_control_data->mem_prealloc)
2857 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2860 DHD_INFO(("success alloc section %d\n", section));
2861 bzero(alloc_ptr, size);
2866 DHD_ERROR(("can't alloc section %d\n", section));
2869 return MALLOC(0, size);
2870 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2872 #endif /* DHD_USE_STATIC_BUF */
2873 #if defined(CONFIG_WIRELESS_EXT)
2874 struct iw_statistics *
2875 dhd_get_wireless_stats(struct net_device *dev)
2878 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2880 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2883 return &dhd->iw.wstats;
2887 #endif /* defined(CONFIG_WIRELESS_EXT) */
2890 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2891 wl_event_msg_t *event, void **data)
2895 ASSERT(dhd != NULL);
2897 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2898 if (bcmerror != BCME_OK)
2901 #if defined(CONFIG_WIRELESS_EXT)
2902 ASSERT(dhd->iflist[*ifidx] != NULL);
2904 if (ntoh32(event->event_type) == WLC_E_IF) {
2905 DHD_INFO(("<0> interface:%d OP:%d don't pass to wext,"
2906 "net_device might not be created yet\n",
2907 *ifidx, ntoh32(event->event_type)));
2911 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2913 if (dhd->iflist[*ifidx]->net)
2914 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2915 #endif /* defined(CONFIG_WIRELESS_EXT) */
2920 /* send up locally generated event */
2922 dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2924 switch (ntoh32(event->event_type)) {
2930 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2932 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2933 struct dhd_info *dhdinfo = dhd->info;
2934 dhd_os_sdunlock(dhd);
2935 wait_event_interruptible_timeout(dhdinfo->ctrl_wait, (*lockvar == FALSE), HZ * 2);
2941 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2943 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2944 struct dhd_info *dhdinfo = dhd->info;
2945 if (waitqueue_active(&dhdinfo->ctrl_wait))
2946 wake_up_interruptible(&dhdinfo->ctrl_wait);
2952 dhd_dev_reset(struct net_device *dev, uint8 flag)
2956 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2958 ret = dhd_bus_devreset(&dhd->pub, flag);
2960 DHD_ERROR(("%s: dhd_bus_devreset: %d\n", __FUNCTION__, ret));
2963 DHD_ERROR(("%s: WLAN %s DONE\n", __FUNCTION__, flag ? "OFF" : "ON"));
2968 int net_os_set_suspend_disable(struct net_device *dev, int val)
2970 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2974 ret = dhd->pub.suspend_disable_flag;
2975 dhd->pub.suspend_disable_flag = val;
2980 int net_os_set_suspend(struct net_device *dev, int val)
2983 #if defined(CONFIG_HAS_EARLYSUSPEND)
2984 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2987 dhd_os_proto_block(&dhd->pub);
2988 ret = dhd_set_suspend(val, &dhd->pub);
2989 dhd_os_proto_unblock(&dhd->pub);
2991 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2995 int net_os_set_dtim_skip(struct net_device *dev, int val)
2997 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3000 dhd->pub.dtim_skip = val;
3005 int net_os_set_packet_filter(struct net_device *dev, int val)
3007 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3010 /* Packet filtering is set only if we still in early-suspend and
3011 * we need either to turn it ON or turn it OFF
3012 * We can always turn it OFF in case of early-suspend, but we turn it
3013 * back ON only if suspend_disable_flag was not set
3015 if (dhd && dhd->pub.up) {
3016 dhd_os_proto_block(&dhd->pub);
3017 if (dhd->pub.in_suspend) {
3018 if (!val || (val && !dhd->pub.suspend_disable_flag))
3019 dhd_set_packet_filter(val, &dhd->pub);
3021 dhd_os_proto_unblock(&dhd->pub);
3028 dhd_dev_init_ioctl(struct net_device *dev)
3030 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3032 dhd_preinit_ioctls(&dhd->pub);
3036 /* Linux wrapper to call common dhd_pno_clean */
3038 dhd_dev_pno_reset(struct net_device *dev)
3040 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3042 return (dhd_pno_clean(&dhd->pub));
3046 /* Linux wrapper to call common dhd_pno_enable */
3048 dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
3050 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3052 return (dhd_pno_enable(&dhd->pub, pfn_enabled));
3056 /* Linux wrapper to call common dhd_pno_set */
3058 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t* ssids_local, int nssid, ushort scan_fr)
3060 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3062 return (dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr));
3065 /* Linux wrapper to get pno status */
3067 dhd_dev_get_pno_status(struct net_device *dev)
3069 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3071 return (dhd_pno_get_status(&dhd->pub));
3074 #endif /* PNO_SUPPORT */
3076 int net_os_send_hang_message(struct net_device *dev)
3078 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3082 if (!dhd->hang_was_sent) {
3083 dhd->hang_was_sent = 1;
3084 ret = wl_iw_send_priv_event(dev, "HANG");
3090 void dhd_bus_country_set(struct net_device *dev, char *country_code)
3092 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3094 if (dhd && dhd->pub.up)
3095 strncpy(dhd->pub.country_code, country_code, WLC_CNTRY_BUF_SZ);
3098 char *dhd_bus_country_get(struct net_device *dev)
3100 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3102 if (dhd && (dhd->pub.country_code[0] != 0))
3103 return dhd->pub.country_code;
3107 void dhd_os_start_lock(dhd_pub_t *pub)
3109 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
3110 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3113 mutex_lock(&dhd->wl_start_lock);
3117 void dhd_os_start_unlock(dhd_pub_t *pub)
3119 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
3120 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3123 mutex_unlock(&dhd->wl_start_lock);
3128 dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
3130 return (atomic_read(&dhd->pend_8021x_cnt));
3133 #define MAX_WAIT_FOR_8021X_TX 10
3136 dhd_wait_pend8021x(struct net_device *dev)
3138 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3139 int timeout = 10 * HZ / 1000;
3140 int ntimes = MAX_WAIT_FOR_8021X_TX;
3141 int pend = dhd_get_pend_8021x_cnt(dhd);
3143 while (ntimes && pend) {
3145 set_current_state(TASK_INTERRUPTIBLE);
3146 schedule_timeout(timeout);
3147 set_current_state(TASK_RUNNING);
3150 pend = dhd_get_pend_8021x_cnt(dhd);
3157 write_to_file(dhd_pub_t *dhd, uint8 *buf, int size)
3161 mm_segment_t old_fs;
3164 /* change to KERNEL_DS address limit */
3168 /* open file to write */
3169 fp = filp_open("/tmp/mem_dump", O_WRONLY|O_CREAT, 0640);
3171 printf("%s: open file error\n", __FUNCTION__);
3176 /* Write buf to file */
3177 fp->f_op->write(fp, buf, size, &pos);
3180 /* free buf before return */
3181 MFREE(dhd->osh, buf, size);
3182 /* close file before return */
3184 filp_close(fp, current->files);
3185 /* restore previous address limit */
3190 #endif /* DHD_DEBUG */
3192 int dhd_os_wake_lock_timeout(dhd_pub_t *pub)
3194 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3195 unsigned long flags;
3199 spin_lock_irqsave(&dhd->wl_lock, flags);
3200 ret = dhd->wl_packet;
3201 #ifdef CONFIG_HAS_WAKELOCK
3203 wake_lock_timeout(&dhd->wl_rxwake, HZ);
3206 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3208 /* printk("%s: %d\n", __FUNCTION__, ret); */
3212 int net_os_wake_lock_timeout(struct net_device *dev)
3214 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3218 ret = dhd_os_wake_lock_timeout(&dhd->pub);
3222 int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub)
3224 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3225 unsigned long flags;
3228 spin_lock_irqsave(&dhd->wl_lock, flags);
3230 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3232 /* printk("%s\n",__func__); */
3236 int net_os_wake_lock_timeout_enable(struct net_device *dev)
3238 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3242 ret = dhd_os_wake_lock_timeout_enable(&dhd->pub);
3246 int dhd_os_wake_lock(dhd_pub_t *pub)
3248 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3249 unsigned long flags;
3253 spin_lock_irqsave(&dhd->wl_lock, flags);
3254 #ifdef CONFIG_HAS_WAKELOCK
3256 wake_lock(&dhd->wl_wifi);
3259 ret = dhd->wl_count;
3260 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3262 /* printk("%s: %d\n", __FUNCTION__, ret); */
3266 int net_os_wake_lock(struct net_device *dev)
3268 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3272 ret = dhd_os_wake_lock(&dhd->pub);
3276 int dhd_os_wake_unlock(dhd_pub_t *pub)
3278 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3279 unsigned long flags;
3282 dhd_os_wake_lock_timeout(pub);
3284 spin_lock_irqsave(&dhd->wl_lock, flags);
3285 if (dhd->wl_count) {
3287 #ifdef CONFIG_HAS_WAKELOCK
3289 wake_unlock(&dhd->wl_wifi);
3291 ret = dhd->wl_count;
3293 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3295 /* printk("%s: %d\n", __FUNCTION__, ret); */
3299 int net_os_wake_unlock(struct net_device *dev)
3301 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3305 ret = dhd_os_wake_unlock(&dhd->pub);
3309 unsigned long dhd_os_spin_lock(dhd_pub_t *pub)
3311 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3312 unsigned long flags = 0;
3315 spin_lock_irqsave(&dhd->dhd_lock, flags);
3320 void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags)
3322 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3325 spin_unlock_irqrestore(&dhd->dhd_lock, flags);