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>
50 #include <wifi_version.h>
53 #include <bcmendian.h>
55 #include <proto/ethernet.h>
56 #include <dngl_stats.h>
59 #include <dhd_proto.h>
62 #ifdef CONFIG_HAS_WAKELOCK
63 #include <linux/wakelock.h>
65 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
66 //#include <linux/wlan_plat.h>
67 #include <mach/board.h>
69 struct semaphore wifi_control_sem;
71 struct dhd_bus *g_bus;
73 extern void bcm4329_power_save_exit(void);
74 extern void bcm4329_power_save_init(void);
76 static struct wifi_platform_data *wifi_control_data = NULL;
77 static struct resource *wifi_irqres = NULL;
79 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
82 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
83 return (int)wifi_irqres->start;
85 #ifdef CUSTOM_OOB_GPIO_NUM
86 return CUSTOM_OOB_GPIO_NUM;
92 int wifi_set_carddetect(int on)
94 printk("%s = %d\n", __FUNCTION__, on);
95 if (wifi_control_data && wifi_control_data->set_carddetect) {
96 wifi_control_data->set_carddetect(on);
101 int wifi_set_power(int on, unsigned long msec)
103 printk("%s = %d\n", __FUNCTION__, on);
104 if (wifi_control_data && wifi_control_data->set_power) {
105 wifi_control_data->set_power(on);
112 int wifi_set_reset(int on, unsigned long msec)
114 DHD_TRACE(("%s = %d\n", __FUNCTION__, on));
115 if (wifi_control_data && wifi_control_data->set_reset) {
116 wifi_control_data->set_reset(on);
123 int wifi_get_mac_addr(unsigned char *buf)
125 DHD_TRACE(("%s\n", __FUNCTION__));
128 if (wifi_control_data && wifi_control_data->get_mac_addr) {
129 return wifi_control_data->get_mac_addr(buf);
134 static int wifi_probe(struct platform_device *pdev)
136 struct wifi_platform_data *wifi_ctrl =
137 (struct wifi_platform_data *)(pdev->dev.platform_data);
139 DHD_TRACE(("## %s\n", __FUNCTION__));
140 wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcm4329_wlan_irq");
141 wifi_control_data = wifi_ctrl;
143 wifi_set_power(1, 0); /* Power On */
144 wifi_set_carddetect(1); /* CardDetect (0->1) */
146 up(&wifi_control_sem);
150 static int wifi_remove(struct platform_device *pdev)
152 struct wifi_platform_data *wifi_ctrl =
153 (struct wifi_platform_data *)(pdev->dev.platform_data);
155 DHD_TRACE(("## %s\n", __FUNCTION__));
156 wifi_control_data = wifi_ctrl;
158 wifi_set_power(0, 0); /* Power Off */
159 wifi_set_carddetect(0); /* CardDetect (1->0) */
161 up(&wifi_control_sem);
164 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
166 DHD_TRACE(("##> %s\n", __FUNCTION__));
169 static int wifi_resume(struct platform_device *pdev)
171 DHD_TRACE(("##> %s\n", __FUNCTION__));
175 static struct platform_driver wifi_device = {
177 .remove = wifi_remove,
178 .suspend = wifi_suspend,
179 .resume = wifi_resume,
181 .name = "bcm4329_wlan",
185 int wifi_add_dev(void)
187 DHD_TRACE(("## Calling platform_driver_register\n"));
188 return platform_driver_register(&wifi_device);
191 void wifi_del_dev(void)
193 DHD_TRACE(("## Unregister platform_driver_register\n"));
194 platform_driver_unregister(&wifi_device);
196 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
199 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
200 #include <linux/suspend.h>
201 volatile bool dhd_mmc_suspend = FALSE;
202 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
203 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
205 #if defined(OOB_INTR_ONLY)
206 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
207 #endif /* defined(OOB_INTR_ONLY) */
208 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
209 MODULE_LICENSE("GPL v2");
210 #endif /* LinuxVer */
212 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15)
218 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15) */
220 /* Linux wireless extension support */
221 #if defined(CONFIG_WIRELESS_EXT)
223 #endif /* defined(CONFIG_WIRELESS_EXT) */
225 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
227 #if defined(CONFIG_HAS_EARLYSUSPEND)
228 #include <linux/earlysuspend.h>
229 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
231 #ifdef PKT_FILTER_SUPPORT
232 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
233 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
236 /* Interface control information */
237 typedef struct dhd_if {
238 struct dhd_info *info; /* back pointer to dhd_info */
239 /* OS/stack specifics */
240 struct net_device *net;
241 struct net_device_stats stats;
242 int idx; /* iface idx in dongle */
243 int state; /* interface state */
244 uint subunit; /* subunit */
245 uint8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
246 bool attached; /* Delayed attachment when unset */
247 bool txflowcontrol; /* Per interface flow control indicator */
248 char name[IFNAMSIZ+1]; /* linux interface name */
251 /* Local private structure (extension of pub) */
252 typedef struct dhd_info {
253 #if defined(CONFIG_WIRELESS_EXT)
254 wl_iw_t iw; /* wireless extensions state (must be first) */
255 #endif /* defined(CONFIG_WIRELESS_EXT) */
259 /* OS/stack specifics */
260 dhd_if_t *iflist[DHD_MAX_IFS];
262 struct mutex proto_sem;
263 wait_queue_head_t ioctl_resp_wait;
264 struct timer_list timer;
266 struct tasklet_struct tasklet;
271 /* Thread based operation */
275 struct semaphore watchdog_sem;
276 struct completion watchdog_exited;
278 struct semaphore dpc_sem;
279 struct completion dpc_exited;
282 #ifdef CONFIG_HAS_WAKELOCK
283 struct wake_lock wl_wifi; /* Wifi wakelock */
284 struct wake_lock wl_rxwake; /* Wifi rx wakelock */
290 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
291 struct mutex wl_start_lock; /* mutex when START called to prevent any other Linux calls */
293 /* Thread to issue ioctl for multicast */
295 struct semaphore sysioc_sem;
296 struct completion sysioc_exited;
299 struct ether_addr macvalue;
300 wait_queue_head_t ctrl_wait;
301 atomic_t pend_8021x_cnt;
303 #ifdef CONFIG_HAS_EARLYSUSPEND
304 struct early_suspend early_suspend;
305 #endif /* CONFIG_HAS_EARLYSUSPEND */
308 /* Definitions to provide path to the firmware and nvram
309 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
311 char firmware_path[MOD_PARAM_PATHLEN];
312 char nvram_path[MOD_PARAM_PATHLEN];
314 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
315 struct semaphore dhd_registration_sem;
316 #define DHD_REGISTRATION_TIMEOUT 12000 /* msec : allowed time to finished dhd registration */
317 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
318 /* load firmware and/or nvram values from the filesystem */
319 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
320 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
323 module_param(dhd_msg_level, int, 0);
325 /* Spawn a thread for system ioctls (set mac, set mcast) */
326 uint dhd_sysioc = TRUE;
327 module_param(dhd_sysioc, uint, 0);
329 /* Watchdog interval */
330 uint dhd_watchdog_ms = 10;
331 module_param(dhd_watchdog_ms, uint, 0);
334 /* Console poll interval */
335 uint dhd_console_ms = 0;
336 module_param(dhd_console_ms, uint, 0);
337 #endif /* DHD_DEBUG */
339 /* ARP offload agent mode : Enable ARP Host Auto-Reply and ARP Peer Auto-Reply */
340 uint dhd_arp_mode = 0xb;
341 module_param(dhd_arp_mode, uint, 0);
343 /* ARP offload enable */
344 uint dhd_arp_enable = TRUE;
345 module_param(dhd_arp_enable, uint, 0);
347 /* Global Pkt filter enable control */
348 uint dhd_pkt_filter_enable = TRUE;
349 module_param(dhd_pkt_filter_enable, uint, 0);
351 /* Pkt filter init setup */
352 uint dhd_pkt_filter_init = 0;
353 module_param(dhd_pkt_filter_init, uint, 0);
355 /* Pkt filter mode control */
356 uint dhd_master_mode = TRUE;
357 module_param(dhd_master_mode, uint, 1);
359 /* Watchdog thread priority, -1 to use kernel timer */
360 int dhd_watchdog_prio = 97;
361 module_param(dhd_watchdog_prio, int, 0);
363 /* DPC thread priority, -1 to use tasklet */
364 int dhd_dpc_prio = 98;
365 module_param(dhd_dpc_prio, int, 0);
367 /* DPC thread priority, -1 to use tasklet */
368 extern int dhd_dongle_memsize;
369 module_param(dhd_dongle_memsize, int, 0);
371 /* Control fw roaming */
378 /* Control radio state */
379 uint dhd_radio_up = 1;
381 /* Network inteface name */
382 char iface_name[IFNAMSIZ] = "wlan0";
383 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
385 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
386 #define DAEMONIZE(a) daemonize(a); \
387 allow_signal(SIGKILL); \
388 allow_signal(SIGTERM);
389 #else /* Linux 2.4 (w/o preemption patch) */
390 #define RAISE_RX_SOFTIRQ() \
391 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
392 #define DAEMONIZE(a) daemonize(); \
394 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
396 #endif /* LINUX_VERSION_CODE */
398 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
399 #define BLOCKABLE() (!in_atomic())
401 #define BLOCKABLE() (!in_interrupt())
404 /* The following are specific to the SDIO dongle */
406 /* IOCTL response timeout */
407 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
409 /* Idle timeout for backplane clock */
410 int dhd_idletime = DHD_IDLETIME_TICKS;
411 module_param(dhd_idletime, int, 0);
414 uint dhd_poll = FALSE;
415 module_param(dhd_poll, uint, 0);
418 uint dhd_intr = TRUE;
419 module_param(dhd_intr, uint, 0);
421 /* SDIO Drive Strength (in milliamps) */
422 uint dhd_sdiod_drive_strength = 6;
423 module_param(dhd_sdiod_drive_strength, uint, 0);
426 extern uint dhd_txbound;
427 extern uint dhd_rxbound;
428 module_param(dhd_txbound, uint, 0);
429 module_param(dhd_rxbound, uint, 0);
431 /* Deferred transmits */
432 extern uint dhd_deferred_tx;
433 module_param(dhd_deferred_tx, uint, 0);
438 /* Echo packet generator (pkts/s) */
440 module_param(dhd_pktgen, uint, 0);
442 /* Echo packet len (0 => sawtooth, max 2040) */
443 uint dhd_pktgen_len = 0;
444 module_param(dhd_pktgen_len, uint, 0);
447 /* Version string to report */
450 #define SRCBASE "drivers/net/wireless/bcm4329"
452 #define DHD_COMPILED "\nCompiled in " SRCBASE
457 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
459 "\nCompiled in " SRCBASE " on " __DATE__ " at " __TIME__
464 #if defined(CONFIG_WIRELESS_EXT)
465 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
466 #endif /* defined(CONFIG_WIRELESS_EXT) */
468 static void dhd_dpc(ulong data);
470 extern int dhd_wait_pend8021x(struct net_device *dev);
474 #error TOE requires BDC
476 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
477 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
480 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
481 wl_event_msg_t *event_ptr, void **data_ptr);
483 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
484 static int dhd_sleep_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
486 int ret = NOTIFY_DONE;
489 case PM_HIBERNATION_PREPARE:
490 case PM_SUSPEND_PREPARE:
491 dhd_mmc_suspend = TRUE;
494 case PM_POST_HIBERNATION:
495 case PM_POST_SUSPEND:
496 dhd_mmc_suspend = FALSE;
504 static struct notifier_block dhd_sleep_pm_notifier = {
505 .notifier_call = dhd_sleep_pm_callback,
508 extern int register_pm_notifier(struct notifier_block *nb);
509 extern int unregister_pm_notifier(struct notifier_block *nb);
510 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
512 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
514 #ifdef PKT_FILTER_SUPPORT
515 DHD_TRACE(("%s: %d\n", __FUNCTION__, value));
516 /* 1 - Enable packet filter, only allow unicast packet to send up */
517 /* 0 - Disable packet filter */
518 if (dhd_pkt_filter_enable) {
521 for (i = 0; i < dhd->pktfilter_count; i++) {
522 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
523 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
524 value, dhd_master_mode);
532 #if defined(CONFIG_HAS_EARLYSUSPEND)
533 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
535 int power_mode = PM_MAX;
536 /* wl_pkt_filter_enable_t enable_parm; */
541 #endif /* CUSTOMER_HW2 */
543 DHD_TRACE(("%s: enter, value = %d in_suspend = %d\n",
544 __FUNCTION__, value, dhd->in_suspend));
546 if (dhd && dhd->up) {
547 if (value && dhd->in_suspend) {
549 /* Kernel suspended */
550 DHD_TRACE(("%s: force extra Suspend setting \n", __FUNCTION__));
552 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
553 (char *)&power_mode, sizeof(power_mode));
555 /* Enable packet filter, only allow unicast packet to send up */
556 dhd_set_packet_filter(1, dhd);
558 /* if dtim skip setup as default force it to wake each thrid dtim
559 * for better power saving.
560 * Note that side effect is chance to miss BC/MC packet
562 bcn_li_dtim = dhd_get_dtim_skip(dhd);
563 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
564 4, iovbuf, sizeof(iovbuf));
565 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
567 /* Disable build-in roaming during suspend */
568 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
569 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
570 #endif /* CUSTOMER_HW2 */
575 DHD_TRACE(("%s: Remove extra suspend setting \n", __FUNCTION__));
577 power_mode = PM_FAST;
578 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
581 /* disable pkt filter */
582 dhd_set_packet_filter(0, dhd);
584 /* restore pre-suspend setting for dtim_skip */
585 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
586 4, iovbuf, sizeof(iovbuf));
588 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
591 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
592 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
593 #endif /* CUSTOMER_HW2 */
600 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
602 dhd_pub_t *dhdp = &dhd->pub;
604 dhd_os_wake_lock(dhdp);
605 dhd_os_proto_block(dhdp);
606 /* Set flag when early suspend was called */
607 dhdp->in_suspend = val;
608 if (!dhdp->suspend_disable_flag)
609 dhd_set_suspend(val, dhdp);
610 dhd_os_proto_unblock(dhdp);
611 dhd_os_wake_unlock(dhdp);
614 static void dhd_early_suspend(struct early_suspend *h)
616 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
618 DHD_TRACE(("%s: enter\n", __FUNCTION__));
621 dhd_suspend_resume_helper(dhd, 1);
624 static void dhd_late_resume(struct early_suspend *h)
626 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
628 DHD_TRACE(("%s: enter\n", __FUNCTION__));
631 dhd_suspend_resume_helper(dhd, 0);
633 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
636 * Generalized timeout mechanism. Uses spin sleep with exponential back-off until
637 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
639 * dhd_timeout_start(&tmo, usec);
640 * while (!dhd_timeout_expired(&tmo))
641 * if (poll_something())
643 * if (dhd_timeout_expired(&tmo))
648 dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
653 tmo->tick = 1000000 / HZ;
657 dhd_timeout_expired(dhd_timeout_t *tmo)
659 /* Does nothing the first call */
660 if (tmo->increment == 0) {
665 if (tmo->elapsed >= tmo->limit)
668 /* Add the delay that's about to take place */
669 tmo->elapsed += tmo->increment;
671 if (tmo->increment < tmo->tick) {
672 OSL_DELAY(tmo->increment);
674 if (tmo->increment > tmo->tick)
675 tmo->increment = tmo->tick;
677 wait_queue_head_t delay_wait;
678 DECLARE_WAITQUEUE(wait, current);
680 init_waitqueue_head(&delay_wait);
681 add_wait_queue(&delay_wait, &wait);
682 set_current_state(TASK_INTERRUPTIBLE);
684 pending = signal_pending(current);
685 remove_wait_queue(&delay_wait, &wait);
686 set_current_state(TASK_RUNNING);
688 return 1; /* Interrupted */
695 dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
700 while (i < DHD_MAX_IFS) {
701 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
710 dhd_ifname2idx(dhd_info_t *dhd, char *name)
716 if (name == NULL || *name == '\0')
720 if (dhd->iflist[i] && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
723 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __FUNCTION__, i, name));
725 return i; /* default - the primary interface */
729 dhd_ifname(dhd_pub_t *dhdp, int ifidx)
731 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
735 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
736 DHD_ERROR(("%s: ifidx %d out of range\n", __FUNCTION__, ifidx));
740 if (dhd->iflist[ifidx] == NULL) {
741 DHD_ERROR(("%s: null i/f %d\n", __FUNCTION__, ifidx));
745 if (dhd->iflist[ifidx]->net)
746 return dhd->iflist[ifidx]->net->name;
752 _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
754 struct net_device *dev;
755 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
756 struct netdev_hw_addr *ha;
758 struct dev_mc_list *mclist;
760 uint32 allmulti, cnt;
767 ASSERT(dhd && dhd->iflist[ifidx]);
768 dev = dhd->iflist[ifidx]->net;
770 netif_addr_lock_bh(dev);
771 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
772 cnt = netdev_mc_count(dev);
776 netif_addr_unlock_bh(dev);
778 /* Determine initial value of allmulti flag */
779 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
781 /* Send down the multicast list first. */
782 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
783 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
784 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
785 dhd_ifname(&dhd->pub, ifidx), cnt));
789 strcpy(bufp, "mcast_list");
790 bufp += strlen("mcast_list") + 1;
793 memcpy(bufp, &cnt, sizeof(cnt));
796 netif_addr_lock_bh(dev);
797 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
798 netdev_for_each_mc_addr(ha, dev) {
801 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
802 bufp += ETHER_ADDR_LEN;
806 for (mclist = dev->mc_list;(mclist && (cnt > 0)); cnt--, mclist = mclist->next) {
807 memcpy(bufp, (void *)mclist->dmi_addr, ETHER_ADDR_LEN);
808 bufp += ETHER_ADDR_LEN;
811 netif_addr_unlock_bh(dev);
813 memset(&ioc, 0, sizeof(ioc));
814 ioc.cmd = WLC_SET_VAR;
819 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
821 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
822 dhd_ifname(&dhd->pub, ifidx), cnt));
823 allmulti = cnt ? TRUE : allmulti;
826 MFREE(dhd->pub.osh, buf, buflen);
828 /* Now send the allmulti setting. This is based on the setting in the
829 * net_device flags, but might be modified above to be turned on if we
830 * were trying to set some addresses and dongle rejected it...
833 buflen = sizeof("allmulti") + sizeof(allmulti);
834 if (!(buf = MALLOC(dhd->pub.osh, buflen))) {
835 DHD_ERROR(("%s: out of memory for allmulti\n", dhd_ifname(&dhd->pub, ifidx)));
838 allmulti = htol32(allmulti);
840 if (!bcm_mkiovar("allmulti", (void*)&allmulti, sizeof(allmulti), buf, buflen)) {
841 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
842 dhd_ifname(&dhd->pub, ifidx), (int)sizeof(allmulti), buflen));
843 MFREE(dhd->pub.osh, buf, buflen);
848 memset(&ioc, 0, sizeof(ioc));
849 ioc.cmd = WLC_SET_VAR;
854 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
856 DHD_ERROR(("%s: set allmulti %d failed\n",
857 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
860 MFREE(dhd->pub.osh, buf, buflen);
862 /* Finally, pick up the PROMISC flag as well, like the NIC driver does */
864 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
865 allmulti = htol32(allmulti);
867 memset(&ioc, 0, sizeof(ioc));
868 ioc.cmd = WLC_SET_PROMISC;
870 ioc.len = sizeof(allmulti);
873 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
875 DHD_ERROR(("%s: set promisc %d failed\n",
876 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
881 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
887 DHD_TRACE(("%s enter\n", __FUNCTION__));
888 if (!bcm_mkiovar("cur_etheraddr", (char*)addr, ETHER_ADDR_LEN, buf, 32)) {
889 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", dhd_ifname(&dhd->pub, ifidx)));
892 memset(&ioc, 0, sizeof(ioc));
893 ioc.cmd = WLC_SET_VAR;
898 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
900 DHD_ERROR(("%s: set cur_etheraddr failed\n", dhd_ifname(&dhd->pub, ifidx)));
902 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
909 extern struct net_device *ap_net_dev;
910 /* semaphore that the soft AP CODE waits on */
911 extern struct semaphore ap_eth_sema;
915 dhd_op_if(dhd_if_t *ifp)
918 int ret = 0, err = 0;
923 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
927 DHD_TRACE(("%s: idx %d, state %d\n", __FUNCTION__, ifp->idx, ifp->state));
929 switch (ifp->state) {
932 * Delete the existing interface before overwriting it
933 * in case we missed the WLC_E_IF_DEL event.
935 if (ifp->net != NULL) {
936 DHD_ERROR(("%s: ERROR: netdev:%s already exists, try free & unregister \n",
937 __FUNCTION__, ifp->net->name));
938 netif_stop_queue(ifp->net);
939 unregister_netdev(ifp->net);
940 free_netdev(ifp->net);
942 /* Allocate etherdev, including space for private structure */
943 if (!(ifp->net = alloc_etherdev(sizeof(dhd)))) {
944 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
948 strcpy(ifp->net->name, ifp->name);
949 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
950 if ((err = dhd_net_attach(&dhd->pub, ifp->idx)) != 0) {
951 DHD_ERROR(("%s: dhd_net_attach failed, err %d\n",
956 flags = dhd_os_spin_lock(&dhd->pub);
957 /* save ptr to wl0.1 netdev for use in wl_iw.c */
958 ap_net_dev = ifp->net;
959 /* signal to the SOFTAP 'sleeper' thread, wl0.1 is ready */
961 dhd_os_spin_unlock(&dhd->pub, flags);
963 DHD_TRACE(("\n ==== pid:%x, net_device for if:%s created ===\n\n",
964 current->pid, ifp->net->name));
970 if (ifp->net != NULL) {
971 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n", __FUNCTION__));
972 netif_stop_queue(ifp->net);
973 unregister_netdev(ifp->net);
974 ret = DHD_DEL_IF; /* Make sure the free_netdev() is called */
978 DHD_ERROR(("%s: bad op %d\n", __FUNCTION__, ifp->state));
985 free_netdev(ifp->net);
987 dhd->iflist[ifp->idx] = NULL;
988 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
990 flags = dhd_os_spin_lock(&dhd->pub);
991 if (ifp->net == ap_net_dev)
992 ap_net_dev = NULL; /* NULL SOFTAP global as well */
993 dhd_os_spin_unlock(&dhd->pub, flags);
999 _dhd_sysioc_thread(void *data)
1001 dhd_info_t *dhd = (dhd_info_t *)data;
1005 unsigned long flags;
1008 DAEMONIZE("dhd_sysioc");
1010 while (down_interruptible(&dhd->sysioc_sem) == 0) {
1011 dhd_os_start_lock(&dhd->pub);
1012 dhd_os_wake_lock(&dhd->pub);
1013 for (i = 0; i < DHD_MAX_IFS; i++) {
1014 if (dhd->iflist[i]) {
1015 DHD_TRACE(("%s: interface %d\n",__FUNCTION__, i));
1017 flags = dhd_os_spin_lock(&dhd->pub);
1018 in_ap = (ap_net_dev != NULL);
1019 dhd_os_spin_unlock(&dhd->pub, flags);
1021 if (dhd->iflist[i]->state)
1022 dhd_op_if(dhd->iflist[i]);
1024 if (dhd->iflist[i] == NULL) {
1025 DHD_TRACE(("%s: interface %d just been removed!\n\n", __FUNCTION__, i));
1029 if (in_ap && dhd->set_macaddress) {
1030 DHD_TRACE(("attempt to set MAC for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
1031 dhd->set_macaddress = FALSE;
1035 if (in_ap && dhd->set_multicast) {
1036 DHD_TRACE(("attempt to set MULTICAST list for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
1037 dhd->set_multicast = FALSE;
1041 if (dhd->set_multicast) {
1042 dhd->set_multicast = FALSE;
1043 _dhd_set_multicast_list(dhd, i);
1045 if (dhd->set_macaddress) {
1046 dhd->set_macaddress = FALSE;
1047 _dhd_set_mac_address(dhd, i, &dhd->macvalue);
1051 dhd_os_wake_unlock(&dhd->pub);
1052 dhd_os_start_unlock(&dhd->pub);
1054 DHD_TRACE(("%s: stopped\n",__FUNCTION__));
1055 complete_and_exit(&dhd->sysioc_exited, 0);
1059 dhd_set_mac_address(struct net_device *dev, void *addr)
1063 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1064 struct sockaddr *sa = (struct sockaddr *)addr;
1067 DHD_TRACE(("%s: Enter\n",__FUNCTION__));
1068 ifidx = dhd_net2idx(dhd, dev);
1069 if (ifidx == DHD_BAD_IF)
1072 ASSERT(dhd->sysioc_pid >= 0);
1073 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1074 dhd->set_macaddress = TRUE;
1075 up(&dhd->sysioc_sem);
1081 dhd_set_multicast_list(struct net_device *dev)
1083 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1086 DHD_TRACE(("%s: Enter\n",__FUNCTION__));
1087 ifidx = dhd_net2idx(dhd, dev);
1088 if (ifidx == DHD_BAD_IF)
1091 ASSERT(dhd->sysioc_pid >= 0);
1092 dhd->set_multicast = TRUE;
1093 up(&dhd->sysioc_sem);
1097 dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1100 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1102 /* Reject if down */
1103 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN)) {
1107 /* Update multicast statistic */
1108 if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_ADDR_LEN) {
1109 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
1110 struct ether_header *eh = (struct ether_header *)pktdata;
1112 if (ETHER_ISMULTI(eh->ether_dhost))
1113 dhdp->tx_multicast++;
1114 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1115 atomic_inc(&dhd->pend_8021x_cnt);
1118 /* Look into the packet and update the packet priority */
1119 if ((PKTPRIO(pktbuf) == 0))
1120 pktsetprio(pktbuf, FALSE);
1122 /* If the protocol uses a data header, apply it */
1123 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1125 /* Use bus module to send data frame */
1127 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1129 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1130 #endif /* BCMDBUS */
1136 dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1140 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1143 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1145 dhd_os_wake_lock(&dhd->pub);
1147 /* Reject if down */
1148 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1149 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1150 __FUNCTION__, dhd->pub.up, dhd->pub.busstate));
1151 netif_stop_queue(net);
1152 /* Send Event when bus down detected during data session */
1153 if (dhd->pub.busstate == DHD_BUS_DOWN) {
1154 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1155 net_os_send_hang_message(net);
1157 dhd_os_wake_unlock(&dhd->pub);
1161 ifidx = dhd_net2idx(dhd, net);
1162 if (ifidx == DHD_BAD_IF) {
1163 DHD_ERROR(("%s: bad ifidx %d\n", __FUNCTION__, ifidx));
1164 netif_stop_queue(net);
1165 dhd_os_wake_unlock(&dhd->pub);
1169 /* Make sure there's enough room for any header */
1170 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1171 struct sk_buff *skb2;
1173 DHD_INFO(("%s: insufficient headroom\n",
1174 dhd_ifname(&dhd->pub, ifidx)));
1175 dhd->pub.tx_realloc++;
1176 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1178 if ((skb = skb2) == NULL) {
1179 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1180 dhd_ifname(&dhd->pub, ifidx)));
1186 /* Convert to packet */
1187 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
1188 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1189 dhd_ifname(&dhd->pub, ifidx)));
1190 dev_kfree_skb_any(skb);
1195 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1199 dhd->pub.dstats.tx_dropped++;
1201 dhd->pub.tx_packets++;
1203 dhd_os_wake_unlock(&dhd->pub);
1205 /* Return ok: we always eat the packet */
1210 dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1212 struct net_device *net;
1213 dhd_info_t *dhd = dhdp->info;
1215 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1217 dhdp->txoff = state;
1218 ASSERT(dhd && dhd->iflist[ifidx]);
1219 net = dhd->iflist[ifidx]->net;
1221 netif_stop_queue(net);
1223 netif_wake_queue(net);
1227 dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1229 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1230 struct sk_buff *skb;
1233 void * data, *pnext, *save_pktbuf;
1236 wl_event_msg_t event;
1238 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1240 save_pktbuf = pktbuf;
1242 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1244 pnext = PKTNEXT(dhdp->osh, pktbuf);
1245 PKTSETNEXT(wl->sh.osh, pktbuf, NULL);
1248 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1250 /* Get the protocol, maintain skb around eth_type_trans()
1251 * The main reason for this hack is for the limitation of
1252 * Linux 2.4 where 'eth_type_trans' uses the 'net->hard_header_len'
1253 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1254 * coping of the packet coming from the network stack to add
1255 * BDC, Hardware header etc, during network interface registration
1256 * we set the 'net->hard_header_len' to ETH_HLEN + extra space required
1257 * for BDC, Hardware header etc. and not just the ETH_HLEN
1262 ifp = dhd->iflist[ifidx];
1264 ifp = dhd->iflist[0];
1267 skb->dev = ifp->net;
1268 skb->protocol = eth_type_trans(skb, skb->dev);
1270 if (skb->pkt_type == PACKET_MULTICAST) {
1271 dhd->pub.rx_multicast++;
1277 /* Strip header, count, deliver upward */
1278 skb_pull(skb, ETH_HLEN);
1280 /* Process special event packets and then discard them */
1281 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1282 dhd_wl_host_event(dhd, &ifidx,
1283 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1291 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1292 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1293 ifp = dhd->iflist[ifidx];
1296 ifp->net->last_rx = jiffies;
1298 dhdp->dstats.rx_bytes += skb->len;
1299 dhdp->rx_packets++; /* Local count */
1301 if (in_interrupt()) {
1304 /* If the receive is not processed inside an ISR,
1305 * the softirqd must be woken explicitly to service
1306 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1307 * by netif_rx_ni(), but in earlier kernels, we need
1308 * to do it manually.
1310 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1315 local_irq_save(flags);
1317 local_irq_restore(flags);
1318 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
1321 dhd_os_wake_lock_timeout_enable(dhdp);
1325 dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1327 /* Linux version has nothing to do */
1332 dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1335 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1336 struct ether_header *eh;
1339 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1341 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
1342 type = ntoh16(eh->ether_type);
1344 if (type == ETHER_TYPE_802_1X)
1345 atomic_dec(&dhd->pend_8021x_cnt);
1349 static struct net_device_stats *
1350 dhd_get_stats(struct net_device *net)
1352 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1356 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1358 ifidx = dhd_net2idx(dhd, net);
1359 if (ifidx == DHD_BAD_IF)
1362 ifp = dhd->iflist[ifidx];
1366 /* Use the protocol to get dongle stats */
1367 dhd_prot_dstats(&dhd->pub);
1370 /* Copy dongle stats to net device stats */
1371 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1372 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1373 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1374 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1375 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1376 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1377 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1378 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1379 ifp->stats.multicast = dhd->pub.dstats.multicast;
1385 dhd_watchdog_thread(void *data)
1387 dhd_info_t *dhd = (dhd_info_t *)data;
1389 /* This thread doesn't need any user-level access,
1390 * so get rid of all our resources
1393 if (dhd_watchdog_prio > 0) {
1394 struct sched_param param;
1395 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO)?
1396 dhd_watchdog_prio:(MAX_RT_PRIO-1);
1397 setScheduler(current, SCHED_FIFO, ¶m);
1399 #endif /* DHD_SCHED */
1401 DAEMONIZE("dhd_watchdog");
1403 /* Run until signal received */
1405 if (down_interruptible (&dhd->watchdog_sem) == 0) {
1406 dhd_os_sdlock(&dhd->pub);
1407 if (dhd->pub.dongle_reset == FALSE) {
1408 DHD_TIMER(("%s:\n", __FUNCTION__));
1409 /* Call the bus module watchdog */
1410 dhd_bus_watchdog(&dhd->pub);
1412 /* Count the tick for reference */
1415 /* Reschedule the watchdog */
1416 if (dhd->wd_timer_valid)
1417 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1419 dhd_os_sdunlock(&dhd->pub);
1420 dhd_os_wake_unlock(&dhd->pub);
1426 complete_and_exit(&dhd->watchdog_exited, 0);
1430 dhd_watchdog(ulong data)
1432 dhd_info_t *dhd = (dhd_info_t *)data;
1434 dhd_os_wake_lock(&dhd->pub);
1435 if (dhd->pub.dongle_reset) {
1436 dhd_os_wake_unlock(&dhd->pub);
1440 if (dhd->watchdog_pid >= 0) {
1441 up(&dhd->watchdog_sem);
1445 dhd_os_sdlock(&dhd->pub);
1446 /* Call the bus module watchdog */
1447 dhd_bus_watchdog(&dhd->pub);
1449 /* Count the tick for reference */
1452 /* Reschedule the watchdog */
1453 if (dhd->wd_timer_valid)
1454 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1455 dhd_os_sdunlock(&dhd->pub);
1456 dhd_os_wake_unlock(&dhd->pub);
1460 dhd_dpc_thread(void *data)
1462 dhd_info_t *dhd = (dhd_info_t *)data;
1464 /* This thread doesn't need any user-level access,
1465 * so get rid of all our resources
1468 if (dhd_dpc_prio > 0)
1470 struct sched_param param;
1471 param.sched_priority = (dhd_dpc_prio < MAX_RT_PRIO)?dhd_dpc_prio:(MAX_RT_PRIO-1);
1472 setScheduler(current, SCHED_FIFO, ¶m);
1474 #endif /* DHD_SCHED */
1476 DAEMONIZE("dhd_dpc");
1478 /* Run until signal received */
1480 if (down_interruptible(&dhd->dpc_sem) == 0) {
1481 /* Call bus dpc unless it indicated down (then clean stop) */
1482 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1483 if (dhd_bus_dpc(dhd->pub.bus)) {
1487 dhd_os_wake_unlock(&dhd->pub);
1491 dhd_bus_stop(dhd->pub.bus, TRUE);
1492 dhd_os_wake_unlock(&dhd->pub);
1499 complete_and_exit(&dhd->dpc_exited, 0);
1507 dhd = (dhd_info_t *)data;
1509 /* Call bus dpc unless it indicated down (then clean stop) */
1510 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1511 if (dhd_bus_dpc(dhd->pub.bus))
1512 tasklet_schedule(&dhd->tasklet);
1514 dhd_bus_stop(dhd->pub.bus, TRUE);
1519 dhd_sched_dpc(dhd_pub_t *dhdp)
1521 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1523 dhd_os_wake_lock(dhdp);
1524 if (dhd->dpc_pid >= 0) {
1529 tasklet_schedule(&dhd->tasklet);
1533 /* Retrieve current toe component enables, which are kept as a bitmap in toe_ol iovar */
1535 dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
1541 memset(&ioc, 0, sizeof(ioc));
1543 ioc.cmd = WLC_GET_VAR;
1545 ioc.len = (uint)sizeof(buf);
1548 strcpy(buf, "toe_ol");
1549 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1550 /* Check for older dongle image that doesn't support toe_ol */
1552 DHD_ERROR(("%s: toe not supported by device\n",
1553 dhd_ifname(&dhd->pub, ifidx)));
1557 DHD_INFO(("%s: could not get toe_ol: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1561 memcpy(toe_ol, buf, sizeof(uint32));
1565 /* Set current toe component enables in toe_ol iovar, and set toe global enable iovar */
1567 dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
1573 memset(&ioc, 0, sizeof(ioc));
1575 ioc.cmd = WLC_SET_VAR;
1577 ioc.len = (uint)sizeof(buf);
1580 /* Set toe_ol as requested */
1582 strcpy(buf, "toe_ol");
1583 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
1585 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1586 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1587 dhd_ifname(&dhd->pub, ifidx), ret));
1591 /* Enable toe globally only if any components are enabled. */
1593 toe = (toe_ol != 0);
1596 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
1598 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1599 DHD_ERROR(("%s: could not set toe: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1607 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1608 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1609 struct ethtool_drvinfo *info)
1611 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1613 sprintf(info->driver, "wl");
1614 sprintf(info->version, "%lu", dhd->pub.drv_version);
1617 struct ethtool_ops dhd_ethtool_ops = {
1618 .get_drvinfo = dhd_ethtool_get_drvinfo
1620 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
1623 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1625 dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1627 struct ethtool_drvinfo info;
1628 char drvname[sizeof(info.driver)];
1631 struct ethtool_value edata;
1632 uint32 toe_cmpnt, csum_dir;
1636 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1638 /* all ethtool calls start with a cmd word */
1639 if (copy_from_user(&cmd, uaddr, sizeof (uint32)))
1643 case ETHTOOL_GDRVINFO:
1644 /* Copy out any request driver name */
1645 if (copy_from_user(&info, uaddr, sizeof(info)))
1647 strncpy(drvname, info.driver, sizeof(info.driver));
1648 drvname[sizeof(info.driver)-1] = '\0';
1650 /* clear struct for return */
1651 memset(&info, 0, sizeof(info));
1654 /* if dhd requested, identify ourselves */
1655 if (strcmp(drvname, "?dhd") == 0) {
1656 sprintf(info.driver, "dhd");
1657 strcpy(info.version, EPI_VERSION_STR);
1660 /* otherwise, require dongle to be up */
1661 else if (!dhd->pub.up) {
1662 DHD_ERROR(("%s: dongle is not up\n", __FUNCTION__));
1666 /* finally, report dongle driver type */
1667 else if (dhd->pub.iswl)
1668 sprintf(info.driver, "wl");
1670 sprintf(info.driver, "xx");
1672 sprintf(info.version, "%lu", dhd->pub.drv_version);
1673 if (copy_to_user(uaddr, &info, sizeof(info)))
1675 DHD_CTL(("%s: given %*s, returning %s\n", __FUNCTION__,
1676 (int)sizeof(drvname), drvname, info.driver));
1680 /* Get toe offload components from dongle */
1681 case ETHTOOL_GRXCSUM:
1682 case ETHTOOL_GTXCSUM:
1683 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1686 csum_dir = (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1689 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1691 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1695 /* Set toe offload components in dongle */
1696 case ETHTOOL_SRXCSUM:
1697 case ETHTOOL_STXCSUM:
1698 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1701 /* Read the current settings, update and write back */
1702 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1705 csum_dir = (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1707 if (edata.data != 0)
1708 toe_cmpnt |= csum_dir;
1710 toe_cmpnt &= ~csum_dir;
1712 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
1715 /* If setting TX checksum mode, tell Linux the new mode */
1716 if (cmd == ETHTOOL_STXCSUM) {
1718 dhd->iflist[0]->net->features |= NETIF_F_IP_CSUM;
1720 dhd->iflist[0]->net->features &= ~NETIF_F_IP_CSUM;
1732 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1735 dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1737 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1744 bool is_set_key_cmd;
1747 dhd_os_wake_lock(&dhd->pub);
1749 /* send to dongle only if we are not waiting for reload already */
1750 if (dhd->pub.hang_was_sent) {
1751 DHD_ERROR(("%s: HANG was sent up earlier\n", __FUNCTION__));
1752 dhd_os_wake_lock_timeout_enable(&dhd->pub);
1753 dhd_os_wake_unlock(&dhd->pub);
1754 return OSL_ERROR(BCME_DONGLE_DOWN);
1757 ifidx = dhd_net2idx(dhd, net);
1758 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
1760 if (ifidx == DHD_BAD_IF) {
1761 dhd_os_wake_unlock(&dhd->pub);
1765 #if defined(CONFIG_WIRELESS_EXT)
1766 /* linux wireless extensions */
1767 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1768 /* may recurse, do NOT lock */
1769 ret = wl_iw_ioctl(net, ifr, cmd);
1770 dhd_os_wake_unlock(&dhd->pub);
1773 #endif /* defined(CONFIG_WIRELESS_EXT) */
1775 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1776 if (cmd == SIOCETHTOOL) {
1777 ret = dhd_ethtool(dhd, (void*)ifr->ifr_data);
1778 dhd_os_wake_unlock(&dhd->pub);
1781 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1783 if (cmd != SIOCDEVPRIVATE) {
1784 dhd_os_wake_unlock(&dhd->pub);
1788 memset(&ioc, 0, sizeof(ioc));
1790 /* Copy the ioc control structure part of ioctl request */
1791 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1792 bcmerror = -BCME_BADADDR;
1796 /* Copy out any buffer passed */
1798 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1799 /* optimization for direct ioctl calls from kernel */
1801 if (segment_eq(get_fs(), KERNEL_DS)) {
1806 if (!(buf = (char*)MALLOC(dhd->pub.osh, buflen))) {
1807 bcmerror = -BCME_NOMEM;
1810 if (copy_from_user(buf, ioc.buf, buflen)) {
1811 bcmerror = -BCME_BADADDR;
1817 /* To differentiate between wl and dhd read 4 more byes */
1818 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1819 sizeof(uint)) != 0)) {
1820 bcmerror = -BCME_BADADDR;
1824 if (!capable(CAP_NET_ADMIN)) {
1825 bcmerror = -BCME_EPERM;
1829 /* check for local dhd ioctl and handle it */
1830 if (driver == DHD_IOCTL_MAGIC) {
1831 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1833 dhd->pub.bcmerror = bcmerror;
1837 /* send to dongle (must be up, and wl) */
1838 if (dhd->pub.busstate != DHD_BUS_DATA) {
1839 DHD_ERROR(("%s DONGLE_DOWN\n", __FUNCTION__));
1840 bcmerror = BCME_DONGLE_DOWN;
1844 if (!dhd->pub.iswl) {
1845 bcmerror = BCME_DONGLE_DOWN;
1849 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1850 * prevent M4 encryption.
1852 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1853 ((ioc.cmd == WLC_SET_VAR) &&
1854 !(strncmp("wsec_key", ioc.buf, 9))) ||
1855 ((ioc.cmd == WLC_SET_VAR) &&
1856 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1857 if (is_set_key_cmd) {
1858 dhd_wait_pend8021x(net);
1861 bcmerror = dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1864 if ((bcmerror == -ETIMEDOUT) || ((dhd->pub.busstate == DHD_BUS_DOWN) &&
1865 (!dhd->pub.dongle_reset))) {
1866 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1867 net_os_send_hang_message(net);
1870 if (!bcmerror && buf && ioc.buf) {
1871 if (copy_to_user(ioc.buf, buf, buflen))
1876 MFREE(dhd->pub.osh, buf, buflen);
1878 dhd_os_wake_unlock(&dhd->pub);
1880 return OSL_ERROR(bcmerror);
1884 dhd_stop(struct net_device *net)
1886 #if !defined(IGNORE_ETH0_DOWN)
1887 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1889 DHD_TRACE(("%s: Enter %s\n", __FUNCTION__, net->name));
1890 if (dhd->pub.up == 0) {
1894 /* Set state and stop OS transmissions */
1896 netif_stop_queue(net);
1898 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation ...\n", __FUNCTION__));
1899 #endif /* !defined(IGNORE_ETH0_DOWN) */
1900 dhd->pub.hang_was_sent = 0;
1901 OLD_MOD_DEC_USE_COUNT;
1906 dhd_open(struct net_device *net)
1908 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1914 /* Force start if ifconfig_up gets called before START command */
1915 wl_control_wl_start(net);
1917 ifidx = dhd_net2idx(dhd, net);
1918 if (ifidx == DHD_BAD_IF)
1920 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
1922 if ((dhd->iflist[ifidx]) && (dhd->iflist[ifidx]->state == WLC_E_IF_DEL)) {
1923 DHD_ERROR(("%s: Error: called when IF already deleted\n", __FUNCTION__));
1927 if (ifidx == 0) { /* do it only for primary eth0 */
1929 atomic_set(&dhd->pend_8021x_cnt, 0);
1931 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1934 /* Get current TOE mode from dongle */
1935 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1936 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1938 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1941 /* Allow transmit calls */
1942 netif_start_queue(net);
1945 OLD_MOD_INC_USE_COUNT;
1950 dhd_osl_attach(void *pdev, uint bustype)
1952 return osl_attach(pdev, bustype, TRUE);
1956 dhd_osl_detach(osl_t *osh)
1958 if (MALLOCED(osh)) {
1959 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __FUNCTION__, MALLOCED(osh)));
1962 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && 1
1963 up(&dhd_registration_sem);
1964 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
1968 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1969 uint8 *mac_addr, uint32 flags, uint8 bssidx)
1973 DHD_TRACE(("%s: idx %d, handle->%p\n", __FUNCTION__, ifidx, handle));
1975 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1977 ifp = dhd->iflist[ifidx];
1978 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1979 DHD_ERROR(("%s: OOM - dhd_if_t\n", __FUNCTION__));
1983 memset(ifp, 0, sizeof(dhd_if_t));
1985 dhd->iflist[ifidx] = ifp;
1986 strncpy(ifp->name, name, IFNAMSIZ);
1987 ifp->name[IFNAMSIZ] = '\0';
1988 if (mac_addr != NULL)
1989 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1991 if (handle == NULL) {
1992 ifp->state = WLC_E_IF_ADD;
1994 ASSERT(dhd->sysioc_pid >= 0);
1995 up(&dhd->sysioc_sem);
1997 ifp->net = (struct net_device *)handle;
2003 dhd_del_if(dhd_info_t *dhd, int ifidx)
2007 DHD_TRACE(("%s: idx %d\n", __FUNCTION__, ifidx));
2009 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
2010 ifp = dhd->iflist[ifidx];
2012 DHD_ERROR(("%s: Null interface\n", __FUNCTION__));
2016 ifp->state = WLC_E_IF_DEL;
2018 ASSERT(dhd->sysioc_pid >= 0);
2019 up(&dhd->sysioc_sem);
2023 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
2025 dhd_info_t *dhd = NULL;
2026 struct net_device *net;
2028 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2029 /* updates firmware nvram path if it was provided as module paramters */
2030 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
2031 strcpy(fw_path, firmware_path);
2032 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
2033 strcpy(nv_path, nvram_path);
2035 /* Allocate etherdev, including space for private structure */
2036 if (!(net = alloc_etherdev(sizeof(dhd)))) {
2037 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
2041 /* Allocate primary dhd_info */
2042 if (!(dhd = MALLOC(osh, sizeof(dhd_info_t)))) {
2043 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __FUNCTION__));
2047 memset(dhd, 0, sizeof(dhd_info_t));
2050 * Save the dhd_info into the priv
2052 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2055 /* Set network interface name if it was provided as module parameter */
2056 if (iface_name[0]) {
2059 strncpy(net->name, iface_name, IFNAMSIZ);
2060 net->name[IFNAMSIZ - 1] = 0;
2061 len = strlen(net->name);
2062 ch = net->name[len - 1];
2063 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
2064 strcat(net->name, "%d");
2067 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) == DHD_BAD_IF)
2070 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2073 net->netdev_ops = NULL;
2076 mutex_init(&dhd->proto_sem);
2077 /* Initialize other structure content */
2078 init_waitqueue_head(&dhd->ioctl_resp_wait);
2079 init_waitqueue_head(&dhd->ctrl_wait);
2081 /* Initialize the spinlocks */
2082 spin_lock_init(&dhd->sdlock);
2083 spin_lock_init(&dhd->txqlock);
2084 spin_lock_init(&dhd->dhd_lock);
2086 /* Initialize Wakelock stuff */
2087 spin_lock_init(&dhd->wl_lock);
2090 #ifdef CONFIG_HAS_WAKELOCK
2091 wake_lock_init(&dhd->wl_wifi, WAKE_LOCK_SUSPEND, "wlan_wake");
2092 wake_lock_init(&dhd->wl_rxwake, WAKE_LOCK_SUSPEND, "wlan_rx_wake");
2094 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
2095 mutex_init(&dhd->wl_start_lock);
2097 /* Link to info module */
2098 dhd->pub.info = dhd;
2100 /* Link to bus module */
2102 dhd->pub.hdrlen = bus_hdrlen;
2104 /* Attach and link in the protocol */
2105 if (dhd_prot_attach(&dhd->pub) != 0) {
2106 DHD_ERROR(("dhd_prot_attach failed\n"));
2109 #if defined(CONFIG_WIRELESS_EXT)
2110 /* Attach and link in the iw */
2111 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
2112 DHD_ERROR(("wl_iw_attach failed\n"));
2115 #endif /* defined(CONFIG_WIRELESS_EXT) */
2117 /* Set up the watchdog timer */
2118 init_timer(&dhd->timer);
2119 dhd->timer.data = (ulong)dhd;
2120 dhd->timer.function = dhd_watchdog;
2122 /* Initialize thread based operation and lock */
2123 mutex_init(&dhd->sdsem);
2124 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)) {
2125 dhd->threads_only = TRUE;
2128 dhd->threads_only = FALSE;
2131 if (dhd_dpc_prio >= 0) {
2132 /* Initialize watchdog thread */
2133 sema_init(&dhd->watchdog_sem, 0);
2134 init_completion(&dhd->watchdog_exited);
2135 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2137 dhd->watchdog_pid = -1;
2140 /* Set up the bottom half handler */
2141 if (dhd_dpc_prio >= 0) {
2142 /* Initialize DPC thread */
2143 sema_init(&dhd->dpc_sem, 0);
2144 init_completion(&dhd->dpc_exited);
2145 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2147 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
2152 sema_init(&dhd->sysioc_sem, 0);
2153 init_completion(&dhd->sysioc_exited);
2154 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2156 dhd->sysioc_pid = -1;
2160 * Save the dhd_info into the priv
2162 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2164 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2167 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2168 register_pm_notifier(&dhd_sleep_pm_notifier);
2169 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2171 #ifdef CONFIG_HAS_EARLYSUSPEND
2172 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2173 dhd->early_suspend.suspend = dhd_early_suspend;
2174 dhd->early_suspend.resume = dhd_late_resume;
2175 register_early_suspend(&dhd->early_suspend);
2184 dhd_detach(&dhd->pub);
2191 dhd_bus_start(dhd_pub_t *dhdp)
2194 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
2195 #ifdef EMBEDDED_PLATFORM
2196 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
2197 #endif /* EMBEDDED_PLATFORM */
2201 DHD_TRACE(("%s: \n", __FUNCTION__));
2203 /* try to download image and nvram to the dongle */
2204 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2205 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2206 fw_path, nv_path))) {
2207 DHD_ERROR(("%s: dhdsdio_probe_download failed. firmware = %s nvram = %s\n",
2208 __FUNCTION__, fw_path, nv_path));
2213 /* Start the watchdog timer */
2214 dhd->pub.tickcnt = 0;
2215 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2217 /* Bring up the bus */
2218 if ((ret = dhd_bus_init(&dhd->pub, TRUE)) != 0) {
2219 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
2222 #if defined(OOB_INTR_ONLY)
2223 /* Host registration for OOB interrupt */
2224 if (bcmsdh_register_oob_intr(dhdp)) {
2225 dhd->wd_timer_valid = FALSE;
2226 del_timer_sync(&dhd->timer);
2227 DHD_ERROR(("%s Host failed to resgister for OOB\n", __FUNCTION__));
2231 /* Enable oob at firmware */
2232 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2233 #endif /* defined(OOB_INTR_ONLY) */
2235 /* If bus is not ready, can't come up */
2236 if (dhd->pub.busstate != DHD_BUS_DATA) {
2237 dhd->wd_timer_valid = FALSE;
2238 del_timer_sync(&dhd->timer);
2239 DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
2243 #ifdef EMBEDDED_PLATFORM
2244 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
2245 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2246 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2248 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2249 setbit(dhdp->eventmask, WLC_E_PRUNE);
2250 setbit(dhdp->eventmask, WLC_E_AUTH);
2251 setbit(dhdp->eventmask, WLC_E_REASSOC);
2252 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2253 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2254 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2255 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2256 setbit(dhdp->eventmask, WLC_E_JOIN);
2257 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2258 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2259 setbit(dhdp->eventmask, WLC_E_LINK);
2260 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2261 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2262 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2263 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2264 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2265 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2266 setbit(dhdp->eventmask, WLC_E_RELOAD);
2268 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2269 #endif /* PNO_SUPPORT */
2271 /* enable dongle roaming event */
2272 setbit(dhdp->eventmask, WLC_E_ROAM);
2274 dhdp->pktfilter_count = 1;
2275 /* Setup filter to allow only unicast */
2276 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2277 #endif /* EMBEDDED_PLATFORM */
2279 /* Bus is ready, do any protocol initialization */
2280 if ((ret = dhd_prot_init(&dhd->pub)) < 0)
2287 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len, int set)
2289 char buf[strlen(name) + 1 + cmd_len];
2290 int len = sizeof(buf);
2294 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2296 memset(&ioc, 0, sizeof(ioc));
2298 ioc.cmd = set? WLC_SET_VAR : WLC_GET_VAR;
2303 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2304 if (!set && ret >= 0)
2305 memcpy(cmd_buf, buf, cmd_len);
2310 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 31))
2311 static struct net_device_ops dhd_ops_pri = {
2312 .ndo_open = dhd_open,
2313 .ndo_stop = dhd_stop,
2314 .ndo_get_stats = dhd_get_stats,
2315 .ndo_do_ioctl = dhd_ioctl_entry,
2316 .ndo_start_xmit = dhd_start_xmit,
2317 .ndo_set_mac_address = dhd_set_mac_address,
2318 .ndo_set_multicast_list = dhd_set_multicast_list,
2321 static struct net_device_ops dhd_ops_virt = {
2322 .ndo_get_stats = dhd_get_stats,
2323 .ndo_do_ioctl = dhd_ioctl_entry,
2324 .ndo_start_xmit = dhd_start_xmit,
2325 .ndo_set_mac_address = dhd_set_mac_address,
2326 .ndo_set_multicast_list = dhd_set_multicast_list,
2331 dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2333 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2334 struct net_device *net;
2335 uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33 };
2337 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
2339 ASSERT(dhd && dhd->iflist[ifidx]);
2340 net = dhd->iflist[ifidx]->net;
2343 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2345 net->get_stats = dhd_get_stats;
2346 net->do_ioctl = dhd_ioctl_entry;
2347 net->hard_start_xmit = dhd_start_xmit;
2348 net->set_mac_address = dhd_set_mac_address;
2349 net->set_multicast_list = dhd_set_multicast_list;
2350 net->open = net->stop = NULL;
2352 ASSERT(!net->netdev_ops);
2353 net->netdev_ops = &dhd_ops_virt;
2356 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2357 net->open = dhd_open;
2358 net->stop = dhd_stop;
2360 net->netdev_ops = &dhd_ops_pri;
2364 * We have to use the primary MAC for virtual interfaces
2367 /* for virtual interfaces use the primary MAC */
2368 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2372 DHD_TRACE(("%s ACCESS POINT MAC: \n", __FUNCTION__));
2373 /* ACCESSPOINT INTERFACE CASE */
2374 temp_addr[0] |= 0x02; /* set bit 2 , - Locally Administered address */
2376 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2377 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2378 net->ethtool_ops = &dhd_ethtool_ops;
2379 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
2381 #if defined(CONFIG_WIRELESS_EXT)
2382 #if WIRELESS_EXT < 19
2383 net->get_wireless_stats = dhd_get_wireless_stats;
2384 #endif /* WIRELESS_EXT < 19 */
2385 #if WIRELESS_EXT > 12
2386 net->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
2387 #endif /* WIRELESS_EXT > 12 */
2388 #endif /* defined(CONFIG_WIRELESS_EXT) */
2390 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2392 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2394 if (register_netdev(net) != 0) {
2395 DHD_ERROR(("%s: couldn't register the net device\n", __FUNCTION__));
2399 printf("%s: Broadcom Dongle Host Driver mac=%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", net->name,
2400 dhd->pub.mac.octet[0], dhd->pub.mac.octet[1], dhd->pub.mac.octet[2],
2401 dhd->pub.mac.octet[3], dhd->pub.mac.octet[4], dhd->pub.mac.octet[5]);
2403 #if defined(CONFIG_WIRELESS_EXT)
2404 #if defined(CONFIG_FIRST_SCAN)
2407 /* Don't call for SOFTAP Interface in SOFTAP MODE */
2408 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2410 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2412 #endif /* CONFIG_FIRST_SCAN */
2413 #endif /* CONFIG_WIRELESS_EXT */
2415 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2416 up(&dhd_registration_sem);
2417 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
2421 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2424 net->netdev_ops = NULL;
2430 dhd_bus_detach(dhd_pub_t *dhdp)
2434 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2437 dhd = (dhd_info_t *)dhdp->info;
2439 /* Stop the protocol module */
2440 dhd_prot_stop(&dhd->pub);
2442 /* Stop the bus module */
2443 dhd_bus_stop(dhd->pub.bus, TRUE);
2444 #if defined(OOB_INTR_ONLY)
2445 bcmsdh_unregister_oob_intr();
2446 #endif /* defined(OOB_INTR_ONLY) */
2448 /* Clear the watchdog timer */
2449 dhd->wd_timer_valid = FALSE;
2450 del_timer_sync(&dhd->timer);
2456 dhd_detach(dhd_pub_t *dhdp)
2460 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2463 dhd = (dhd_info_t *)dhdp->info;
2468 #if defined(CONFIG_HAS_EARLYSUSPEND)
2469 if (dhd->early_suspend.suspend)
2470 unregister_early_suspend(&dhd->early_suspend);
2471 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2472 #if defined(CONFIG_WIRELESS_EXT)
2473 /* Attach and link in the iw */
2476 if (dhd->sysioc_pid >= 0) {
2477 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2478 wait_for_completion(&dhd->sysioc_exited);
2481 for (i = 1; i < DHD_MAX_IFS; i++)
2482 if (dhd->iflist[i]) {
2483 dhd->iflist[i]->state = WLC_E_IF_DEL;
2484 dhd->iflist[i]->idx = i;
2485 dhd_op_if(dhd->iflist[i]);
2488 ifp = dhd->iflist[0];
2490 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2491 if (ifp->net->open) {
2493 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2496 unregister_netdev(ifp->net);
2499 if (dhd->watchdog_pid >= 0)
2501 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2502 wait_for_completion(&dhd->watchdog_exited);
2505 if (dhd->dpc_pid >= 0)
2507 KILL_PROC(dhd->dpc_pid, SIGTERM);
2508 wait_for_completion(&dhd->dpc_exited);
2511 tasklet_kill(&dhd->tasklet);
2513 dhd_bus_detach(dhdp);
2516 dhd_prot_detach(dhdp);
2518 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2519 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2520 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2521 free_netdev(ifp->net);
2522 #ifdef CONFIG_HAS_WAKELOCK
2523 wake_lock_destroy(&dhd->wl_wifi);
2524 wake_lock_destroy(&dhd->wl_rxwake);
2526 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2527 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2533 rockchip_wifi_exit_module(void)
2535 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2537 dhd_bus_unregister();
2538 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2541 /* Call customer gpio to turn off power with WL_REG_ON signal */
2542 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2543 bcm4329_power_save_exit();
2547 rockchip_wifi_init_module(void)
2551 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2553 printk("BCM4329 Wi-Fi driver (Powered by Rockchip,Ver %s) init.\n", BCM4329_DRV_VERSION);
2554 /* Sanity check on the module parameters */
2556 /* Both watchdog and DPC as tasklets are ok */
2557 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2560 /* If both watchdog and DPC are threads, TX must be deferred */
2561 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0) && dhd_deferred_tx)
2564 DHD_ERROR(("Invalid module parameters.\n"));
2568 /* Call customer gpio to turn on power with WL_REG_ON signal */
2569 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2571 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2572 sema_init(&wifi_control_sem, 0);
2574 error = wifi_add_dev();
2576 DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__));
2580 /* Waiting callback after platform_driver_register is done or exit with error */
2581 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(5000)) != 0) {
2583 DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__));
2586 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2588 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2589 sema_init(&dhd_registration_sem, 0);
2592 error = dhd_bus_register();
2595 printf("\n%s\n", dhd_version);
2597 DHD_ERROR(("%s: sdio_register_driver failed\n", __FUNCTION__));
2600 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2602 * Wait till MMC sdio_register_driver callback called and made driver attach.
2603 * It's needed to make sync up exit from dhd insmod and
2604 * Kernel MMC sdio device callback registration
2606 if (down_timeout(&dhd_registration_sem, msecs_to_jiffies(DHD_REGISTRATION_TIMEOUT)) != 0) {
2608 DHD_ERROR(("%s: sdio_register_driver timeout\n", __FUNCTION__));
2612 bcm4329_power_save_init();
2615 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2617 dhd_bus_unregister();
2620 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2623 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2625 /* Call customer gpio to turn off power with WL_REG_ON signal */
2626 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2631 //module_init(dhd_module_init);
2632 //module_exit(dhd_module_cleanup);
2633 int mv88w8686_if_sdio_init_module(void)
2635 return rockchip_wifi_init_module();
2638 void mv88w8686_if_sdio_exit_module(void)
2640 rockchip_wifi_exit_module();
2643 EXPORT_SYMBOL(rockchip_wifi_init_module);
2644 EXPORT_SYMBOL(rockchip_wifi_exit_module);
2645 EXPORT_SYMBOL(mv88w8686_if_sdio_init_module);
2646 EXPORT_SYMBOL(mv88w8686_if_sdio_exit_module);
2650 * OS specific functions required to implement DHD driver in OS independent way
2653 dhd_os_proto_block(dhd_pub_t *pub)
2655 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2658 mutex_lock(&dhd->proto_sem);
2666 dhd_os_proto_unblock(dhd_pub_t *pub)
2668 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2671 mutex_unlock(&dhd->proto_sem);
2679 dhd_os_get_ioctl_resp_timeout(void)
2681 return ((unsigned int)dhd_ioctl_timeout_msec);
2685 dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2687 dhd_ioctl_timeout_msec = (int)timeout_msec;
2691 dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2693 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2694 DECLARE_WAITQUEUE(wait, current);
2695 int timeout = dhd_ioctl_timeout_msec;
2697 /* Convert timeout in millsecond to jiffies */
2698 /* timeout = timeout * HZ / 1000; */
2699 timeout = msecs_to_jiffies(timeout);
2701 /* Wait until control frame is available */
2702 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2703 set_current_state(TASK_INTERRUPTIBLE);
2705 while (!(*condition) && (!signal_pending(current) && timeout)) {
2706 timeout = schedule_timeout(timeout);
2710 if (signal_pending(current))
2713 set_current_state(TASK_RUNNING);
2714 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2720 dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2722 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2724 if (waitqueue_active(&dhd->ioctl_resp_wait)) {
2725 wake_up_interruptible(&dhd->ioctl_resp_wait);
2732 dhd_os_wd_timer(void *bus, uint wdtick)
2734 dhd_pub_t *pub = bus;
2735 dhd_info_t *dhd = (dhd_info_t *)pub->info;
2736 unsigned long flags;
2737 int del_timer_flag = FALSE;
2739 flags = dhd_os_spin_lock(pub);
2741 /* don't start the wd until fw is loaded */
2742 if (pub->busstate != DHD_BUS_DOWN) {
2744 dhd_watchdog_ms = (uint)wdtick;
2745 dhd->wd_timer_valid = TRUE;
2746 /* Re arm the timer, at last watchdog period */
2747 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
2748 } else if (dhd->wd_timer_valid == TRUE) {
2749 /* Totally stop the timer */
2750 dhd->wd_timer_valid = FALSE;
2751 del_timer_flag = TRUE;
2754 dhd_os_spin_unlock(pub, flags);
2755 if (del_timer_flag) {
2756 del_timer_sync(&dhd->timer);
2761 dhd_os_open_image(char *filename)
2765 fp = filp_open(filename, O_RDONLY, 0);
2767 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2769 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2779 dhd_os_get_image_block(char *buf, int len, void *image)
2781 struct file *fp = (struct file *)image;
2787 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2795 dhd_os_close_image(void *image)
2798 filp_close((struct file *)image, NULL);
2803 dhd_os_sdlock(dhd_pub_t *pub)
2807 dhd = (dhd_info_t *)(pub->info);
2809 if (dhd->threads_only)
2810 mutex_lock(&dhd->sdsem);
2812 spin_lock_bh(&dhd->sdlock);
2816 dhd_os_sdunlock(dhd_pub_t *pub)
2820 dhd = (dhd_info_t *)(pub->info);
2822 if (dhd->threads_only)
2823 mutex_unlock(&dhd->sdsem);
2825 spin_unlock_bh(&dhd->sdlock);
2829 dhd_os_sdlock_txq(dhd_pub_t *pub)
2833 dhd = (dhd_info_t *)(pub->info);
2834 spin_lock_bh(&dhd->txqlock);
2838 dhd_os_sdunlock_txq(dhd_pub_t *pub)
2842 dhd = (dhd_info_t *)(pub->info);
2843 spin_unlock_bh(&dhd->txqlock);
2846 dhd_os_sdlock_rxq(dhd_pub_t *pub)
2850 dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2855 dhd_os_sdtxlock(dhd_pub_t *pub)
2861 dhd_os_sdtxunlock(dhd_pub_t *pub)
2863 dhd_os_sdunlock(pub);
2866 #ifdef DHD_USE_STATIC_BUF
2867 void * dhd_os_prealloc(int section, unsigned long size)
2869 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2870 void *alloc_ptr = NULL;
2871 if (wifi_control_data && wifi_control_data->mem_prealloc)
2873 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2876 DHD_INFO(("success alloc section %d\n", section));
2877 bzero(alloc_ptr, size);
2882 DHD_ERROR(("can't alloc section %d\n", section));
2885 return MALLOC(0, size);
2886 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2888 #endif /* DHD_USE_STATIC_BUF */
2889 #if defined(CONFIG_WIRELESS_EXT)
2890 struct iw_statistics *
2891 dhd_get_wireless_stats(struct net_device *dev)
2894 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2896 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2899 return &dhd->iw.wstats;
2903 #endif /* defined(CONFIG_WIRELESS_EXT) */
2906 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2907 wl_event_msg_t *event, void **data)
2911 ASSERT(dhd != NULL);
2913 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2914 if (bcmerror != BCME_OK)
2917 #if defined(CONFIG_WIRELESS_EXT)
2918 ASSERT(dhd->iflist[*ifidx] != NULL);
2920 if (ntoh32(event->event_type) == WLC_E_IF) {
2921 DHD_INFO(("<0> interface:%d OP:%d don't pass to wext,"
2922 "net_device might not be created yet\n",
2923 *ifidx, ntoh32(event->event_type)));
2927 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2929 if (dhd->iflist[*ifidx]->net)
2930 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2931 #endif /* defined(CONFIG_WIRELESS_EXT) */
2936 /* send up locally generated event */
2938 dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2940 switch (ntoh32(event->event_type)) {
2946 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2948 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2949 struct dhd_info *dhdinfo = dhd->info;
2950 dhd_os_sdunlock(dhd);
2951 wait_event_interruptible_timeout(dhdinfo->ctrl_wait, (*lockvar == FALSE), HZ * 2);
2957 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2959 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2960 struct dhd_info *dhdinfo = dhd->info;
2961 if (waitqueue_active(&dhdinfo->ctrl_wait))
2962 wake_up_interruptible(&dhdinfo->ctrl_wait);
2968 dhd_dev_reset(struct net_device *dev, uint8 flag)
2972 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2974 ret = dhd_bus_devreset(&dhd->pub, flag);
2976 DHD_ERROR(("%s: dhd_bus_devreset: %d\n", __FUNCTION__, ret));
2979 DHD_ERROR(("%s: WLAN %s DONE\n", __FUNCTION__, flag ? "OFF" : "ON"));
2984 int net_os_set_suspend_disable(struct net_device *dev, int val)
2986 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2990 ret = dhd->pub.suspend_disable_flag;
2991 dhd->pub.suspend_disable_flag = val;
2996 int net_os_set_suspend(struct net_device *dev, int val)
2999 #if defined(CONFIG_HAS_EARLYSUSPEND)
3000 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3003 dhd_os_proto_block(&dhd->pub);
3004 ret = dhd_set_suspend(val, &dhd->pub);
3005 dhd_os_proto_unblock(&dhd->pub);
3007 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
3011 int net_os_set_dtim_skip(struct net_device *dev, int val)
3013 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3016 dhd->pub.dtim_skip = val;
3021 int net_os_set_packet_filter(struct net_device *dev, int val)
3023 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3026 /* Packet filtering is set only if we still in early-suspend and
3027 * we need either to turn it ON or turn it OFF
3028 * We can always turn it OFF in case of early-suspend, but we turn it
3029 * back ON only if suspend_disable_flag was not set
3031 if (dhd && dhd->pub.up) {
3032 dhd_os_proto_block(&dhd->pub);
3033 if (dhd->pub.in_suspend) {
3034 if (!val || (val && !dhd->pub.suspend_disable_flag))
3035 dhd_set_packet_filter(val, &dhd->pub);
3037 dhd_os_proto_unblock(&dhd->pub);
3044 dhd_dev_init_ioctl(struct net_device *dev)
3046 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3048 dhd_preinit_ioctls(&dhd->pub);
3052 /* Linux wrapper to call common dhd_pno_clean */
3054 dhd_dev_pno_reset(struct net_device *dev)
3056 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3058 return (dhd_pno_clean(&dhd->pub));
3062 /* Linux wrapper to call common dhd_pno_enable */
3064 dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
3066 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3068 return (dhd_pno_enable(&dhd->pub, pfn_enabled));
3072 /* Linux wrapper to call common dhd_pno_set */
3074 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t* ssids_local, int nssid, ushort scan_fr)
3076 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3078 return (dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr));
3081 /* Linux wrapper to get pno status */
3083 dhd_dev_get_pno_status(struct net_device *dev)
3085 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3087 return (dhd_pno_get_status(&dhd->pub));
3090 #endif /* PNO_SUPPORT */
3092 int net_os_send_hang_message(struct net_device *dev)
3094 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3098 if (!dhd->pub.hang_was_sent) {
3099 dhd->pub.hang_was_sent = 1;
3100 ret = wl_iw_send_priv_event(dev, "HANG");
3106 void dhd_bus_country_set(struct net_device *dev, char *country_code)
3108 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3110 if (dhd && dhd->pub.up)
3111 strncpy(dhd->pub.country_code, country_code, WLC_CNTRY_BUF_SZ);
3114 char *dhd_bus_country_get(struct net_device *dev)
3116 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3118 if (dhd && (dhd->pub.country_code[0] != 0))
3119 return dhd->pub.country_code;
3123 void dhd_os_start_lock(dhd_pub_t *pub)
3125 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
3126 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3129 mutex_lock(&dhd->wl_start_lock);
3133 void dhd_os_start_unlock(dhd_pub_t *pub)
3135 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
3136 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3139 mutex_unlock(&dhd->wl_start_lock);
3144 dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
3146 return (atomic_read(&dhd->pend_8021x_cnt));
3149 #define MAX_WAIT_FOR_8021X_TX 10
3152 dhd_wait_pend8021x(struct net_device *dev)
3154 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3155 int timeout = 10 * HZ / 1000;
3156 int ntimes = MAX_WAIT_FOR_8021X_TX;
3157 int pend = dhd_get_pend_8021x_cnt(dhd);
3159 while (ntimes && pend) {
3161 set_current_state(TASK_INTERRUPTIBLE);
3162 schedule_timeout(timeout);
3163 set_current_state(TASK_RUNNING);
3166 pend = dhd_get_pend_8021x_cnt(dhd);
3173 write_to_file(dhd_pub_t *dhd, uint8 *buf, int size)
3177 mm_segment_t old_fs;
3180 /* change to KERNEL_DS address limit */
3184 /* open file to write */
3185 fp = filp_open("/tmp/mem_dump", O_WRONLY|O_CREAT, 0640);
3187 printf("%s: open file error\n", __FUNCTION__);
3192 /* Write buf to file */
3193 fp->f_op->write(fp, buf, size, &pos);
3196 /* free buf before return */
3197 MFREE(dhd->osh, buf, size);
3198 /* close file before return */
3200 filp_close(fp, current->files);
3201 /* restore previous address limit */
3206 #endif /* DHD_DEBUG */
3208 int dhd_os_wake_lock_timeout(dhd_pub_t *pub)
3210 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3211 unsigned long flags;
3215 spin_lock_irqsave(&dhd->wl_lock, flags);
3216 ret = dhd->wl_packet;
3217 #ifdef CONFIG_HAS_WAKELOCK
3219 wake_lock_timeout(&dhd->wl_rxwake, HZ);
3222 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3224 /* printk("%s: %d\n", __FUNCTION__, ret); */
3228 int net_os_wake_lock_timeout(struct net_device *dev)
3230 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3234 ret = dhd_os_wake_lock_timeout(&dhd->pub);
3238 int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub)
3240 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3241 unsigned long flags;
3244 spin_lock_irqsave(&dhd->wl_lock, flags);
3246 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3248 /* printk("%s\n",__func__); */
3252 int net_os_wake_lock_timeout_enable(struct net_device *dev)
3254 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3258 ret = dhd_os_wake_lock_timeout_enable(&dhd->pub);
3262 int dhd_os_wake_lock(dhd_pub_t *pub)
3264 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3265 unsigned long flags;
3269 spin_lock_irqsave(&dhd->wl_lock, flags);
3270 #ifdef CONFIG_HAS_WAKELOCK
3272 wake_lock(&dhd->wl_wifi);
3275 ret = dhd->wl_count;
3276 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3278 /* printk("%s: %d\n", __FUNCTION__, ret); */
3282 int net_os_wake_lock(struct net_device *dev)
3284 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3288 ret = dhd_os_wake_lock(&dhd->pub);
3292 int dhd_os_wake_unlock(dhd_pub_t *pub)
3294 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3295 unsigned long flags;
3298 dhd_os_wake_lock_timeout(pub);
3300 spin_lock_irqsave(&dhd->wl_lock, flags);
3301 if (dhd->wl_count) {
3303 #ifdef CONFIG_HAS_WAKELOCK
3305 wake_unlock(&dhd->wl_wifi);
3307 ret = dhd->wl_count;
3309 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3311 /* printk("%s: %d\n", __FUNCTION__, ret); */
3315 int net_os_wake_unlock(struct net_device *dev)
3317 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3321 ret = dhd_os_wake_unlock(&dhd->pub);
3325 unsigned long dhd_os_spin_lock(dhd_pub_t *pub)
3327 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3328 unsigned long flags = 0;
3331 spin_lock_irqsave(&dhd->dhd_lock, flags);
3336 void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags)
3338 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3341 spin_unlock_irqrestore(&dhd->dhd_lock, flags);