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.89 2010/07/21 18:07:11 Exp $
28 #ifdef CONFIG_WIFI_CONTROL_FUNC
29 #include <linux/platform_device.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/slab.h>
38 #include <linux/skbuff.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/random.h>
42 #include <linux/spinlock.h>
43 #include <linux/ethtool.h>
44 #include <linux/fcntl.h>
47 #include <asm/uaccess.h>
48 #include <asm/unaligned.h>
52 #include <bcmendian.h>
54 #include <proto/ethernet.h>
55 #include <dngl_stats.h>
58 #include <dhd_proto.h>
61 #ifdef CONFIG_HAS_WAKELOCK
62 #include <linux/wakelock.h>
64 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
65 #include <linux/wlan_plat.h>
67 struct semaphore wifi_control_sem;
69 struct dhd_bus *g_bus;
71 static struct wifi_platform_data *wifi_control_data = NULL;
72 static struct resource *wifi_irqres = NULL;
74 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
77 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
78 return (int)wifi_irqres->start;
80 #ifdef CUSTOM_OOB_GPIO_NUM
81 return CUSTOM_OOB_GPIO_NUM;
87 int wifi_set_carddetect(int on)
89 printk("%s = %d\n", __FUNCTION__, on);
90 if (wifi_control_data && wifi_control_data->set_carddetect) {
91 wifi_control_data->set_carddetect(on);
96 int wifi_set_power(int on, unsigned long msec)
98 printk("%s = %d\n", __FUNCTION__, on);
99 if (wifi_control_data && wifi_control_data->set_power) {
100 wifi_control_data->set_power(on);
107 int wifi_set_reset(int on, unsigned long msec)
109 printk("%s = %d\n", __FUNCTION__, on);
110 if (wifi_control_data && wifi_control_data->set_reset) {
111 wifi_control_data->set_reset(on);
118 int wifi_get_mac_addr(unsigned char *buf)
120 printk("%s\n", __FUNCTION__);
123 if (wifi_control_data && wifi_control_data->get_mac_addr) {
124 return wifi_control_data->get_mac_addr(buf);
129 static int wifi_probe(struct platform_device *pdev)
131 struct wifi_platform_data *wifi_ctrl =
132 (struct wifi_platform_data *)(pdev->dev.platform_data);
134 DHD_TRACE(("## %s\n", __FUNCTION__));
135 wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcm4329_wlan_irq");
136 wifi_control_data = wifi_ctrl;
138 wifi_set_power(1, 0); /* Power On */
139 wifi_set_carddetect(1); /* CardDetect (0->1) */
141 up(&wifi_control_sem);
145 static int wifi_remove(struct platform_device *pdev)
147 struct wifi_platform_data *wifi_ctrl =
148 (struct wifi_platform_data *)(pdev->dev.platform_data);
150 DHD_TRACE(("## %s\n", __FUNCTION__));
151 wifi_control_data = wifi_ctrl;
153 wifi_set_power(0, 0); /* Power Off */
154 wifi_set_carddetect(0); /* CardDetect (1->0) */
156 up(&wifi_control_sem);
159 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
161 DHD_TRACE(("##> %s\n", __FUNCTION__));
164 static int wifi_resume(struct platform_device *pdev)
166 DHD_TRACE(("##> %s\n", __FUNCTION__));
170 static struct platform_driver wifi_device = {
172 .remove = wifi_remove,
173 .suspend = wifi_suspend,
174 .resume = wifi_resume,
176 .name = "bcm4329_wlan",
180 int wifi_add_dev(void)
182 DHD_TRACE(("## Calling platform_driver_register\n"));
183 return platform_driver_register(&wifi_device);
186 void wifi_del_dev(void)
188 DHD_TRACE(("## Unregister platform_driver_register\n"));
189 platform_driver_unregister(&wifi_device);
191 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
194 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
195 #include <linux/suspend.h>
196 volatile bool dhd_mmc_suspend = FALSE;
197 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
198 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
200 #if defined(OOB_INTR_ONLY)
201 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
202 #endif /* defined(OOB_INTR_ONLY) */
203 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
204 MODULE_LICENSE("GPL v2");
205 #endif /* LinuxVer */
207 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15)
213 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15) */
215 /* Linux wireless extension support */
216 #if defined(CONFIG_WIRELESS_EXT)
218 #endif /* defined(CONFIG_WIRELESS_EXT) */
220 #if defined(CONFIG_HAS_EARLYSUSPEND)
221 #include <linux/earlysuspend.h>
222 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
223 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
224 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
225 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
227 /* Interface control information */
228 typedef struct dhd_if {
229 struct dhd_info *info; /* back pointer to dhd_info */
230 /* OS/stack specifics */
231 struct net_device *net;
232 struct net_device_stats stats;
233 int idx; /* iface idx in dongle */
234 int state; /* interface state */
235 uint subunit; /* subunit */
236 uint8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
237 bool attached; /* Delayed attachment when unset */
238 bool txflowcontrol; /* Per interface flow control indicator */
239 char name[IFNAMSIZ+1]; /* linux interface name */
242 /* Local private structure (extension of pub) */
243 typedef struct dhd_info {
244 #if defined(CONFIG_WIRELESS_EXT)
245 wl_iw_t iw; /* wireless extensions state (must be first) */
246 #endif /* defined(CONFIG_WIRELESS_EXT) */
250 /* OS/stack specifics */
251 dhd_if_t *iflist[DHD_MAX_IFS];
253 struct semaphore proto_sem;
254 wait_queue_head_t ioctl_resp_wait;
255 struct timer_list timer;
257 struct tasklet_struct tasklet;
260 /* Thread based operation */
262 struct semaphore sdsem;
264 struct semaphore watchdog_sem;
265 struct completion watchdog_exited;
267 struct semaphore dpc_sem;
268 struct completion dpc_exited;
271 #ifdef CONFIG_HAS_WAKELOCK
272 struct wake_lock wl_wifi; /* Wifi wakelock */
273 struct wake_lock wl_rxwake; /* Wifi rx wakelock */
279 /* Thread to issue ioctl for multicast */
281 struct semaphore sysioc_sem;
282 struct completion sysioc_exited;
285 struct ether_addr macvalue;
286 wait_queue_head_t ctrl_wait;
287 atomic_t pend_8021x_cnt;
289 #ifdef CONFIG_HAS_EARLYSUSPEND
290 struct early_suspend early_suspend;
291 #endif /* CONFIG_HAS_EARLYSUSPEND */
294 /* Definitions to provide path to the firmware and nvram
295 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
297 char firmware_path[MOD_PARAM_PATHLEN];
298 char nvram_path[MOD_PARAM_PATHLEN];
300 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
301 struct semaphore dhd_registration_sem;
302 #define DHD_REGISTRATION_TIMEOUT 8000 /* msec : allowed time to finished dhd registration */
303 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
304 /* load firmware and/or nvram values from the filesystem */
305 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
306 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
309 module_param(dhd_msg_level, int, 0);
311 /* Spawn a thread for system ioctls (set mac, set mcast) */
312 uint dhd_sysioc = TRUE;
313 module_param(dhd_sysioc, uint, 0);
315 /* Watchdog interval */
316 uint dhd_watchdog_ms = 10;
317 module_param(dhd_watchdog_ms, uint, 0);
320 /* Console poll interval */
321 uint dhd_console_ms = 0;
322 module_param(dhd_console_ms, uint, 0);
323 #endif /* DHD_DEBUG */
325 /* ARP offload agent mode : Enable ARP Host Auto-Reply and ARP Peer Auto-Reply */
326 uint dhd_arp_mode = 0xb;
327 module_param(dhd_arp_mode, uint, 0);
329 /* ARP offload enable */
330 uint dhd_arp_enable = TRUE;
331 module_param(dhd_arp_enable, uint, 0);
333 /* Global Pkt filter enable control */
334 uint dhd_pkt_filter_enable = TRUE;
335 module_param(dhd_pkt_filter_enable, uint, 0);
337 /* Pkt filter init setup */
338 uint dhd_pkt_filter_init = 0;
339 module_param(dhd_pkt_filter_init, uint, 0);
341 /* Pkt filter mode control */
342 uint dhd_master_mode = TRUE;
343 module_param(dhd_master_mode, uint, 1);
345 /* Watchdog thread priority, -1 to use kernel timer */
346 int dhd_watchdog_prio = 97;
347 module_param(dhd_watchdog_prio, int, 0);
349 /* DPC thread priority, -1 to use tasklet */
350 int dhd_dpc_prio = 98;
351 module_param(dhd_dpc_prio, int, 0);
353 /* DPC thread priority, -1 to use tasklet */
354 extern int dhd_dongle_memsize;
355 module_param(dhd_dongle_memsize, int, 0);
357 /* Contorl fw roaming */
364 /* Control radio state */
365 uint dhd_radio_up = 1;
367 /* Network inteface name */
368 char iface_name[IFNAMSIZ];
369 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
371 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
372 #define DAEMONIZE(a) daemonize(a); \
373 allow_signal(SIGKILL); \
374 allow_signal(SIGTERM);
375 #else /* Linux 2.4 (w/o preemption patch) */
376 #define RAISE_RX_SOFTIRQ() \
377 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
378 #define DAEMONIZE(a) daemonize(); \
380 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
382 #endif /* LINUX_VERSION_CODE */
384 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
385 #define BLOCKABLE() (!in_atomic())
387 #define BLOCKABLE() (!in_interrupt())
390 /* The following are specific to the SDIO dongle */
392 /* IOCTL response timeout */
393 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
395 /* Idle timeout for backplane clock */
396 int dhd_idletime = DHD_IDLETIME_TICKS;
397 module_param(dhd_idletime, int, 0);
400 uint dhd_poll = FALSE;
401 module_param(dhd_poll, uint, 0);
404 uint dhd_intr = TRUE;
405 module_param(dhd_intr, uint, 0);
407 /* SDIO Drive Strength (in milliamps) */
408 uint dhd_sdiod_drive_strength = 6;
409 module_param(dhd_sdiod_drive_strength, uint, 0);
412 extern uint dhd_txbound;
413 extern uint dhd_rxbound;
414 module_param(dhd_txbound, uint, 0);
415 module_param(dhd_rxbound, uint, 0);
417 /* Deferred transmits */
418 extern uint dhd_deferred_tx;
419 module_param(dhd_deferred_tx, uint, 0);
424 /* Echo packet generator (pkts/s) */
426 module_param(dhd_pktgen, uint, 0);
428 /* Echo packet len (0 => sawtooth, max 2040) */
429 uint dhd_pktgen_len = 0;
430 module_param(dhd_pktgen_len, uint, 0);
433 /* Version string to report */
436 #define SRCBASE "drivers/net/wireless/bcm4329"
438 #define DHD_COMPILED "\nCompiled in " SRCBASE
443 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
445 "\nCompiled in " SRCBASE " on " __DATE__ " at " __TIME__
450 #if defined(CONFIG_WIRELESS_EXT)
451 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
452 #endif /* defined(CONFIG_WIRELESS_EXT) */
454 static void dhd_dpc(ulong data);
456 extern int dhd_wait_pend8021x(struct net_device *dev);
460 #error TOE requires BDC
462 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
463 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
466 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
467 wl_event_msg_t *event_ptr, void **data_ptr);
469 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
470 static int dhd_sleep_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
474 case PM_HIBERNATION_PREPARE:
475 case PM_SUSPEND_PREPARE:
476 dhd_mmc_suspend = TRUE;
478 case PM_POST_HIBERNATION:
479 case PM_POST_SUSPEND:
480 dhd_mmc_suspend = FALSE;
486 static struct notifier_block dhd_sleep_pm_notifier = {
487 .notifier_call = dhd_sleep_pm_callback,
490 extern int register_pm_notifier(struct notifier_block *nb);
491 extern int unregister_pm_notifier(struct notifier_block *nb);
492 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
495 #if defined(CONFIG_HAS_EARLYSUSPEND)
497 int dhd_set_suspend(int value, dhd_pub_t *dhd)
499 int power_mode = PM_MAX;
500 /* wl_pkt_filter_enable_t enable_parm; */
505 #endif /* CUSTOMER_HW2 */
510 if (dhd && (dhd->up && !dhd->suspend_disable_flag)) {
511 dhd_os_proto_block(dhd);
514 /* Kernel suspended */
515 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
516 (char *)&power_mode, sizeof(power_mode));
518 /* Enable packet filter, only allow unicast packet to send up */
519 if (dhd_pkt_filter_enable) {
520 for (i = 0; i < dhd->pktfilter_count; i++) {
521 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
522 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
527 /* set bcn_li_dtim */
528 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
529 4, iovbuf, sizeof(iovbuf));
530 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
532 /* Disable build-in roaming to allowed ext supplicant to take of romaing */
533 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
534 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
535 #endif /* CUSTOMER_HW2 */
539 power_mode = PM_FAST;
540 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
543 /* disable pkt filter */
544 if (dhd_pkt_filter_enable) {
545 for (i = 0; i < dhd->pktfilter_count; i++) {
546 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
547 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
552 /* set bcn_li_dtim */
554 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
555 4, iovbuf, sizeof(iovbuf));
556 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
559 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
560 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
561 #endif /* CUSTOMER_HW2 */
563 dhd_os_proto_unblock(dhd);
569 static void dhd_early_suspend(struct early_suspend *h)
571 struct dhd_info *dhdp;
572 dhdp = container_of(h, struct dhd_info, early_suspend);
574 DHD_TRACE(("%s: enter\n", __FUNCTION__));
576 dhd_set_suspend(1, &dhdp->pub);
579 static void dhd_late_resume(struct early_suspend *h)
581 struct dhd_info *dhdp;
582 dhdp = container_of(h, struct dhd_info, early_suspend);
584 DHD_TRACE(("%s: enter\n", __FUNCTION__));
586 dhd_set_suspend(0, &dhdp->pub);
588 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
591 * Generalized timeout mechanism. Uses spin sleep with exponential back-off until
592 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
594 * dhd_timeout_start(&tmo, usec);
595 * while (!dhd_timeout_expired(&tmo))
596 * if (poll_something())
598 * if (dhd_timeout_expired(&tmo))
603 dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
608 tmo->tick = 1000000 / HZ;
612 dhd_timeout_expired(dhd_timeout_t *tmo)
614 /* Does nothing the first call */
615 if (tmo->increment == 0) {
620 if (tmo->elapsed >= tmo->limit)
623 /* Add the delay that's about to take place */
624 tmo->elapsed += tmo->increment;
626 if (tmo->increment < tmo->tick) {
627 OSL_DELAY(tmo->increment);
629 if (tmo->increment > tmo->tick)
630 tmo->increment = tmo->tick;
632 wait_queue_head_t delay_wait;
633 DECLARE_WAITQUEUE(wait, current);
635 init_waitqueue_head(&delay_wait);
636 add_wait_queue(&delay_wait, &wait);
637 set_current_state(TASK_INTERRUPTIBLE);
639 pending = signal_pending(current);
640 remove_wait_queue(&delay_wait, &wait);
641 set_current_state(TASK_RUNNING);
643 return 1; /* Interrupted */
650 dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
655 while (i < DHD_MAX_IFS) {
656 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
665 dhd_ifname2idx(dhd_info_t *dhd, char *name)
671 if (name == NULL || *name == '\0')
675 if (dhd->iflist[i] && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
678 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __FUNCTION__, i, name));
680 return i; /* default - the primary interface */
684 dhd_ifname(dhd_pub_t *dhdp, int ifidx)
686 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
690 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
691 DHD_ERROR(("%s: ifidx %d out of range\n", __FUNCTION__, ifidx));
695 if (dhd->iflist[ifidx] == NULL) {
696 DHD_ERROR(("%s: null i/f %d\n", __FUNCTION__, ifidx));
700 if (dhd->iflist[ifidx]->net)
701 return dhd->iflist[ifidx]->net->name;
707 _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
709 struct net_device *dev;
710 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
711 struct netdev_hw_addr *ha;
713 struct dev_mc_list *mclist;
715 uint32 allmulti, cnt;
722 ASSERT(dhd && dhd->iflist[ifidx]);
723 dev = dhd->iflist[ifidx]->net;
725 netif_addr_lock_bh(dev);
726 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
727 cnt = netdev_mc_count(dev);
731 netif_addr_unlock_bh(dev);
733 /* Determine initial value of allmulti flag */
734 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
736 /* Send down the multicast list first. */
737 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
738 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
739 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
740 dhd_ifname(&dhd->pub, ifidx), cnt));
744 strcpy(bufp, "mcast_list");
745 bufp += strlen("mcast_list") + 1;
748 memcpy(bufp, &cnt, sizeof(cnt));
751 netif_addr_lock_bh(dev);
752 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
753 netdev_for_each_mc_addr(ha, dev) {
756 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
757 bufp += ETHER_ADDR_LEN;
761 for (mclist = dev->mc_list;(mclist && (cnt > 0)); cnt--, mclist = mclist->next) {
762 memcpy(bufp, (void *)mclist->dmi_addr, ETHER_ADDR_LEN);
763 bufp += ETHER_ADDR_LEN;
766 netif_addr_unlock_bh(dev);
768 memset(&ioc, 0, sizeof(ioc));
769 ioc.cmd = WLC_SET_VAR;
774 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
776 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
777 dhd_ifname(&dhd->pub, ifidx), cnt));
778 allmulti = cnt ? TRUE : allmulti;
781 MFREE(dhd->pub.osh, buf, buflen);
783 /* Now send the allmulti setting. This is based on the setting in the
784 * net_device flags, but might be modified above to be turned on if we
785 * were trying to set some addresses and dongle rejected it...
788 buflen = sizeof("allmulti") + sizeof(allmulti);
789 if (!(buf = MALLOC(dhd->pub.osh, buflen))) {
790 DHD_ERROR(("%s: out of memory for allmulti\n", dhd_ifname(&dhd->pub, ifidx)));
793 allmulti = htol32(allmulti);
795 if (!bcm_mkiovar("allmulti", (void*)&allmulti, sizeof(allmulti), buf, buflen)) {
796 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
797 dhd_ifname(&dhd->pub, ifidx), (int)sizeof(allmulti), buflen));
798 MFREE(dhd->pub.osh, buf, buflen);
803 memset(&ioc, 0, sizeof(ioc));
804 ioc.cmd = WLC_SET_VAR;
809 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
811 DHD_ERROR(("%s: set allmulti %d failed\n",
812 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
815 MFREE(dhd->pub.osh, buf, buflen);
817 /* Finally, pick up the PROMISC flag as well, like the NIC driver does */
819 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
820 allmulti = htol32(allmulti);
822 memset(&ioc, 0, sizeof(ioc));
823 ioc.cmd = WLC_SET_PROMISC;
825 ioc.len = sizeof(allmulti);
828 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
830 DHD_ERROR(("%s: set promisc %d failed\n",
831 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
836 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
842 DHD_TRACE(("%s enter\n", __FUNCTION__));
843 if (!bcm_mkiovar("cur_etheraddr", (char*)addr, ETHER_ADDR_LEN, buf, 32)) {
844 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", dhd_ifname(&dhd->pub, ifidx)));
847 memset(&ioc, 0, sizeof(ioc));
848 ioc.cmd = WLC_SET_VAR;
853 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
855 DHD_ERROR(("%s: set cur_etheraddr failed\n", dhd_ifname(&dhd->pub, ifidx)));
857 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
864 extern struct net_device *ap_net_dev;
868 dhd_op_if(dhd_if_t *ifp)
871 int ret = 0, err = 0;
873 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
877 DHD_TRACE(("%s: idx %d, state %d\n", __FUNCTION__, ifp->idx, ifp->state));
879 switch (ifp->state) {
882 * Delete the existing interface before overwriting it
883 * in case we missed the WLC_E_IF_DEL event.
885 if (ifp->net != NULL) {
886 DHD_ERROR(("%s: ERROR: netdev:%s already exists, try free & unregister \n",
887 __FUNCTION__, ifp->net->name));
888 netif_stop_queue(ifp->net);
889 unregister_netdev(ifp->net);
890 free_netdev(ifp->net);
892 /* Allocate etherdev, including space for private structure */
893 if (!(ifp->net = alloc_etherdev(sizeof(dhd)))) {
894 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
898 strcpy(ifp->net->name, ifp->name);
899 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
900 if ((err = dhd_net_attach(&dhd->pub, ifp->idx)) != 0) {
901 DHD_ERROR(("%s: dhd_net_attach failed, err %d\n",
906 /* semaphore that the soft AP CODE waits on */
907 extern struct semaphore ap_eth_sema;
909 /* save ptr to wl0.1 netdev for use in wl_iw.c */
910 ap_net_dev = ifp->net;
911 /* signal to the SOFTAP 'sleeper' thread, wl0.1 is ready */
914 DHD_TRACE(("\n ==== pid:%x, net_device for if:%s created ===\n\n",
915 current->pid, ifp->net->name));
921 if (ifp->net != NULL) {
922 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n", __FUNCTION__));
923 netif_stop_queue(ifp->net);
924 unregister_netdev(ifp->net);
925 ret = DHD_DEL_IF; /* Make sure the free_netdev() is called */
929 DHD_ERROR(("%s: bad op %d\n", __FUNCTION__, ifp->state));
936 free_netdev(ifp->net);
938 dhd->iflist[ifp->idx] = NULL;
939 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
941 if (ifp->net == ap_net_dev)
942 ap_net_dev = NULL; /* NULL SOFTAP global as well */
948 _dhd_sysioc_thread(void *data)
950 dhd_info_t *dhd = (dhd_info_t *)data;
956 DAEMONIZE("dhd_sysioc");
958 while (down_interruptible(&dhd->sysioc_sem) == 0) {
959 dhd_os_wake_lock(&dhd->pub);
960 for (i = 0; i < DHD_MAX_IFS; i++) {
961 if (dhd->iflist[i]) {
963 in_ap = (ap_net_dev != NULL);
965 if (dhd->iflist[i]->state)
966 dhd_op_if(dhd->iflist[i]);
968 if (dhd->iflist[i] == NULL) {
969 DHD_TRACE(("%s: interface %d just been removed!\n\n", __FUNCTION__, i));
973 if (in_ap && dhd->set_macaddress) {
974 DHD_TRACE(("attempt to set MAC for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
975 dhd->set_macaddress = FALSE;
979 if (in_ap && dhd->set_multicast) {
980 DHD_TRACE(("attempt to set MULTICAST list for %s in AP Mode blocked.\n", dhd->iflist[i]->net->name));
981 dhd->set_multicast = FALSE;
985 if (dhd->set_multicast) {
986 dhd->set_multicast = FALSE;
987 _dhd_set_multicast_list(dhd, i);
989 if (dhd->set_macaddress) {
990 dhd->set_macaddress = FALSE;
991 _dhd_set_mac_address(dhd, i, &dhd->macvalue);
995 dhd_os_wake_unlock(&dhd->pub);
997 complete_and_exit(&dhd->sysioc_exited, 0);
1001 dhd_set_mac_address(struct net_device *dev, void *addr)
1005 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1006 struct sockaddr *sa = (struct sockaddr *)addr;
1009 ifidx = dhd_net2idx(dhd, dev);
1010 if (ifidx == DHD_BAD_IF)
1013 ASSERT(dhd->sysioc_pid >= 0);
1014 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1015 dhd->set_macaddress = TRUE;
1016 up(&dhd->sysioc_sem);
1022 dhd_set_multicast_list(struct net_device *dev)
1024 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1027 ifidx = dhd_net2idx(dhd, dev);
1028 if (ifidx == DHD_BAD_IF)
1031 ASSERT(dhd->sysioc_pid >= 0);
1032 dhd->set_multicast = TRUE;
1033 up(&dhd->sysioc_sem);
1037 dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1040 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1042 /* Reject if down */
1043 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN)) {
1047 /* Update multicast statistic */
1048 if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_ADDR_LEN) {
1049 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
1050 struct ether_header *eh = (struct ether_header *)pktdata;
1052 if (ETHER_ISMULTI(eh->ether_dhost))
1053 dhdp->tx_multicast++;
1054 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1055 atomic_inc(&dhd->pend_8021x_cnt);
1058 /* Look into the packet and update the packet priority */
1059 if ((PKTPRIO(pktbuf) == 0))
1060 pktsetprio(pktbuf, FALSE);
1062 /* If the protocol uses a data header, apply it */
1063 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1065 /* Use bus module to send data frame */
1067 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1069 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1070 #endif /* BCMDBUS */
1076 dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1080 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1083 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1085 dhd_os_wake_lock(&dhd->pub);
1087 /* Reject if down */
1088 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1089 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1090 __FUNCTION__, dhd->pub.up, dhd->pub.busstate));
1091 netif_stop_queue(net);
1092 /* Send Event when bus down detected during data session */
1093 if (dhd->pub.busstate == DHD_BUS_DOWN) {
1094 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1095 wl_iw_send_priv_event(net, "HANG");
1097 dhd_os_wake_unlock(&dhd->pub);
1101 ifidx = dhd_net2idx(dhd, net);
1102 if (ifidx == DHD_BAD_IF) {
1103 DHD_ERROR(("%s: bad ifidx %d\n", __FUNCTION__, ifidx));
1104 netif_stop_queue(net);
1105 dhd_os_wake_unlock(&dhd->pub);
1109 /* Make sure there's enough room for any header */
1110 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1111 struct sk_buff *skb2;
1113 DHD_INFO(("%s: insufficient headroom\n",
1114 dhd_ifname(&dhd->pub, ifidx)));
1115 dhd->pub.tx_realloc++;
1116 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1118 if ((skb = skb2) == NULL) {
1119 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1120 dhd_ifname(&dhd->pub, ifidx)));
1126 /* Convert to packet */
1127 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
1128 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1129 dhd_ifname(&dhd->pub, ifidx)));
1130 dev_kfree_skb_any(skb);
1135 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1139 dhd->pub.dstats.tx_dropped++;
1141 dhd->pub.tx_packets++;
1143 dhd_os_wake_unlock(&dhd->pub);
1145 /* Return ok: we always eat the packet */
1150 dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1152 struct net_device *net;
1153 dhd_info_t *dhd = dhdp->info;
1155 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1157 dhdp->txoff = state;
1158 ASSERT(dhd && dhd->iflist[ifidx]);
1159 net = dhd->iflist[ifidx]->net;
1161 netif_stop_queue(net);
1163 netif_wake_queue(net);
1167 dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1169 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1170 struct sk_buff *skb;
1173 void * data, *pnext, *save_pktbuf;
1176 wl_event_msg_t event;
1178 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1180 save_pktbuf = pktbuf;
1182 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1184 pnext = PKTNEXT(dhdp->osh, pktbuf);
1185 PKTSETNEXT(wl->sh.osh, pktbuf, NULL);
1188 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1190 /* Get the protocol, maintain skb around eth_type_trans()
1191 * The main reason for this hack is for the limitation of
1192 * Linux 2.4 where 'eth_type_trans' uses the 'net->hard_header_len'
1193 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1194 * coping of the packet coming from the network stack to add
1195 * BDC, Hardware header etc, during network interface registration
1196 * we set the 'net->hard_header_len' to ETH_HLEN + extra space required
1197 * for BDC, Hardware header etc. and not just the ETH_HLEN
1202 ifp = dhd->iflist[ifidx];
1204 ifp = dhd->iflist[0];
1207 skb->dev = ifp->net;
1208 skb->protocol = eth_type_trans(skb, skb->dev);
1210 if (skb->pkt_type == PACKET_MULTICAST) {
1211 dhd->pub.rx_multicast++;
1217 /* Strip header, count, deliver upward */
1218 skb_pull(skb, ETH_HLEN);
1220 /* Process special event packets and then discard them */
1221 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1222 dhd_wl_host_event(dhd, &ifidx,
1223 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1231 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1232 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1233 ifp = dhd->iflist[ifidx];
1236 ifp->net->last_rx = jiffies;
1238 dhdp->dstats.rx_bytes += skb->len;
1239 dhdp->rx_packets++; /* Local count */
1241 if (in_interrupt()) {
1244 /* If the receive is not processed inside an ISR,
1245 * the softirqd must be woken explicitly to service
1246 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1247 * by netif_rx_ni(), but in earlier kernels, we need
1248 * to do it manually.
1250 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1255 local_irq_save(flags);
1257 local_irq_restore(flags);
1258 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
1261 dhd_os_wake_lock_timeout_enable(dhdp);
1265 dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1267 /* Linux version has nothing to do */
1272 dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1275 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1276 struct ether_header *eh;
1279 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1281 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
1282 type = ntoh16(eh->ether_type);
1284 if (type == ETHER_TYPE_802_1X)
1285 atomic_dec(&dhd->pend_8021x_cnt);
1289 static struct net_device_stats *
1290 dhd_get_stats(struct net_device *net)
1292 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1296 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1298 ifidx = dhd_net2idx(dhd, net);
1299 if (ifidx == DHD_BAD_IF)
1302 ifp = dhd->iflist[ifidx];
1306 /* Use the protocol to get dongle stats */
1307 dhd_prot_dstats(&dhd->pub);
1310 /* Copy dongle stats to net device stats */
1311 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1312 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1313 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1314 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1315 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1316 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1317 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1318 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1319 ifp->stats.multicast = dhd->pub.dstats.multicast;
1325 dhd_watchdog_thread(void *data)
1327 dhd_info_t *dhd = (dhd_info_t *)data;
1329 /* This thread doesn't need any user-level access,
1330 * so get rid of all our resources
1333 if (dhd_watchdog_prio > 0) {
1334 struct sched_param param;
1335 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO)?
1336 dhd_watchdog_prio:(MAX_RT_PRIO-1);
1337 setScheduler(current, SCHED_FIFO, ¶m);
1339 #endif /* DHD_SCHED */
1341 DAEMONIZE("dhd_watchdog");
1343 /* Run until signal received */
1345 if (down_interruptible (&dhd->watchdog_sem) == 0) {
1346 dhd_os_wake_lock(&dhd->pub);
1348 if (dhd->pub.dongle_reset == FALSE) {
1349 /* Call the bus module watchdog */
1350 dhd_bus_watchdog(&dhd->pub);
1352 /* Count the tick for reference */
1355 /* Reschedule the watchdog */
1356 if (dhd->wd_timer_valid) {
1357 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1359 dhd_os_wake_unlock(&dhd->pub);
1365 complete_and_exit(&dhd->watchdog_exited, 0);
1369 dhd_watchdog(ulong data)
1371 dhd_info_t *dhd = (dhd_info_t *)data;
1373 if (dhd->watchdog_pid >= 0) {
1374 up(&dhd->watchdog_sem);
1378 /* Call the bus module watchdog */
1379 dhd_bus_watchdog(&dhd->pub);
1381 /* Count the tick for reference */
1384 /* Reschedule the watchdog */
1385 if (dhd->wd_timer_valid)
1386 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1390 dhd_dpc_thread(void *data)
1392 dhd_info_t *dhd = (dhd_info_t *)data;
1394 /* This thread doesn't need any user-level access,
1395 * so get rid of all our resources
1398 if (dhd_dpc_prio > 0)
1400 struct sched_param param;
1401 param.sched_priority = (dhd_dpc_prio < MAX_RT_PRIO)?dhd_dpc_prio:(MAX_RT_PRIO-1);
1402 setScheduler(current, SCHED_FIFO, ¶m);
1404 #endif /* DHD_SCHED */
1406 DAEMONIZE("dhd_dpc");
1408 /* Run until signal received */
1410 if (down_interruptible(&dhd->dpc_sem) == 0) {
1411 /* Call bus dpc unless it indicated down (then clean stop) */
1412 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1413 if (dhd_bus_dpc(dhd->pub.bus)) {
1417 dhd_os_wake_unlock(&dhd->pub);
1420 dhd_bus_stop(dhd->pub.bus, TRUE);
1421 dhd_os_wake_unlock(&dhd->pub);
1428 complete_and_exit(&dhd->dpc_exited, 0);
1436 dhd = (dhd_info_t *)data;
1438 /* Call bus dpc unless it indicated down (then clean stop) */
1439 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1440 if (dhd_bus_dpc(dhd->pub.bus))
1441 tasklet_schedule(&dhd->tasklet);
1443 dhd_bus_stop(dhd->pub.bus, TRUE);
1448 dhd_sched_dpc(dhd_pub_t *dhdp)
1450 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1452 dhd_os_wake_lock(dhdp);
1453 if (dhd->dpc_pid >= 0) {
1458 tasklet_schedule(&dhd->tasklet);
1462 /* Retrieve current toe component enables, which are kept as a bitmap in toe_ol iovar */
1464 dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
1470 memset(&ioc, 0, sizeof(ioc));
1472 ioc.cmd = WLC_GET_VAR;
1474 ioc.len = (uint)sizeof(buf);
1477 strcpy(buf, "toe_ol");
1478 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1479 /* Check for older dongle image that doesn't support toe_ol */
1481 DHD_ERROR(("%s: toe not supported by device\n",
1482 dhd_ifname(&dhd->pub, ifidx)));
1486 DHD_INFO(("%s: could not get toe_ol: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1490 memcpy(toe_ol, buf, sizeof(uint32));
1494 /* Set current toe component enables in toe_ol iovar, and set toe global enable iovar */
1496 dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
1502 memset(&ioc, 0, sizeof(ioc));
1504 ioc.cmd = WLC_SET_VAR;
1506 ioc.len = (uint)sizeof(buf);
1509 /* Set toe_ol as requested */
1511 strcpy(buf, "toe_ol");
1512 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
1514 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1515 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1516 dhd_ifname(&dhd->pub, ifidx), ret));
1520 /* Enable toe globally only if any components are enabled. */
1522 toe = (toe_ol != 0);
1525 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
1527 if ((ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1528 DHD_ERROR(("%s: could not set toe: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
1536 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1537 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1538 struct ethtool_drvinfo *info)
1540 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1542 sprintf(info->driver, "wl");
1543 sprintf(info->version, "%lu", dhd->pub.drv_version);
1546 struct ethtool_ops dhd_ethtool_ops = {
1547 .get_drvinfo = dhd_ethtool_get_drvinfo
1549 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
1552 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1554 dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1556 struct ethtool_drvinfo info;
1557 char drvname[sizeof(info.driver)];
1560 struct ethtool_value edata;
1561 uint32 toe_cmpnt, csum_dir;
1565 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1567 /* all ethtool calls start with a cmd word */
1568 if (copy_from_user(&cmd, uaddr, sizeof (uint32)))
1572 case ETHTOOL_GDRVINFO:
1573 /* Copy out any request driver name */
1574 if (copy_from_user(&info, uaddr, sizeof(info)))
1576 strncpy(drvname, info.driver, sizeof(info.driver));
1577 drvname[sizeof(info.driver)-1] = '\0';
1579 /* clear struct for return */
1580 memset(&info, 0, sizeof(info));
1583 /* if dhd requested, identify ourselves */
1584 if (strcmp(drvname, "?dhd") == 0) {
1585 sprintf(info.driver, "dhd");
1586 strcpy(info.version, EPI_VERSION_STR);
1589 /* otherwise, require dongle to be up */
1590 else if (!dhd->pub.up) {
1591 DHD_ERROR(("%s: dongle is not up\n", __FUNCTION__));
1595 /* finally, report dongle driver type */
1596 else if (dhd->pub.iswl)
1597 sprintf(info.driver, "wl");
1599 sprintf(info.driver, "xx");
1601 sprintf(info.version, "%lu", dhd->pub.drv_version);
1602 if (copy_to_user(uaddr, &info, sizeof(info)))
1604 DHD_CTL(("%s: given %*s, returning %s\n", __FUNCTION__,
1605 (int)sizeof(drvname), drvname, info.driver));
1609 /* Get toe offload components from dongle */
1610 case ETHTOOL_GRXCSUM:
1611 case ETHTOOL_GTXCSUM:
1612 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1615 csum_dir = (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1618 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1620 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1624 /* Set toe offload components in dongle */
1625 case ETHTOOL_SRXCSUM:
1626 case ETHTOOL_STXCSUM:
1627 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1630 /* Read the current settings, update and write back */
1631 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1634 csum_dir = (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1636 if (edata.data != 0)
1637 toe_cmpnt |= csum_dir;
1639 toe_cmpnt &= ~csum_dir;
1641 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
1644 /* If setting TX checksum mode, tell Linux the new mode */
1645 if (cmd == ETHTOOL_STXCSUM) {
1647 dhd->iflist[0]->net->features |= NETIF_F_IP_CSUM;
1649 dhd->iflist[0]->net->features &= ~NETIF_F_IP_CSUM;
1661 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1664 dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1666 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1673 bool is_set_key_cmd;
1676 dhd_os_wake_lock(&dhd->pub);
1678 ifidx = dhd_net2idx(dhd, net);
1679 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
1681 if (ifidx == DHD_BAD_IF) {
1682 dhd_os_wake_unlock(&dhd->pub);
1686 #if defined(CONFIG_WIRELESS_EXT)
1687 /* linux wireless extensions */
1688 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1689 /* may recurse, do NOT lock */
1690 ret = wl_iw_ioctl(net, ifr, cmd);
1691 dhd_os_wake_unlock(&dhd->pub);
1694 #endif /* defined(CONFIG_WIRELESS_EXT) */
1696 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
1697 if (cmd == SIOCETHTOOL) {
1698 ret = dhd_ethtool(dhd, (void*)ifr->ifr_data);
1699 dhd_os_wake_unlock(&dhd->pub);
1702 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
1704 if (cmd != SIOCDEVPRIVATE) {
1705 dhd_os_wake_unlock(&dhd->pub);
1709 memset(&ioc, 0, sizeof(ioc));
1711 /* Copy the ioc control structure part of ioctl request */
1712 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1713 bcmerror = -BCME_BADADDR;
1717 /* Copy out any buffer passed */
1719 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1720 /* optimization for direct ioctl calls from kernel */
1722 if (segment_eq(get_fs(), KERNEL_DS)) {
1727 if (!(buf = (char*)MALLOC(dhd->pub.osh, buflen))) {
1728 bcmerror = -BCME_NOMEM;
1731 if (copy_from_user(buf, ioc.buf, buflen)) {
1732 bcmerror = -BCME_BADADDR;
1738 /* To differentiate between wl and dhd read 4 more byes */
1739 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1740 sizeof(uint)) != 0)) {
1741 bcmerror = -BCME_BADADDR;
1745 if (!capable(CAP_NET_ADMIN)) {
1746 bcmerror = -BCME_EPERM;
1750 /* check for local dhd ioctl and handle it */
1751 if (driver == DHD_IOCTL_MAGIC) {
1752 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1754 dhd->pub.bcmerror = bcmerror;
1758 /* send to dongle (must be up, and wl) */
1759 if (dhd->pub.busstate != DHD_BUS_DATA) {
1760 DHD_ERROR(("%s DONGLE_DOWN\n", __FUNCTION__));
1761 bcmerror = BCME_DONGLE_DOWN;
1765 if (!dhd->pub.iswl) {
1766 bcmerror = BCME_DONGLE_DOWN;
1770 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1771 * prevent M4 encryption.
1773 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1774 ((ioc.cmd == WLC_SET_VAR) &&
1775 !(strncmp("wsec_key", ioc.buf, 9))) ||
1776 ((ioc.cmd == WLC_SET_VAR) &&
1777 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1778 if (is_set_key_cmd) {
1779 dhd_wait_pend8021x(net);
1782 bcmerror = dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1785 if ((bcmerror == -ETIMEDOUT) || ((dhd->pub.busstate == DHD_BUS_DOWN) &&
1786 (!dhd->pub.dongle_reset))) {
1787 DHD_ERROR(("%s: Event HANG send up\n", __FUNCTION__));
1788 wl_iw_send_priv_event(net, "HANG");
1791 if (!bcmerror && buf && ioc.buf) {
1792 if (copy_to_user(ioc.buf, buf, buflen))
1797 MFREE(dhd->pub.osh, buf, buflen);
1799 dhd_os_wake_unlock(&dhd->pub);
1801 return OSL_ERROR(bcmerror);
1805 dhd_stop(struct net_device *net)
1807 #if !defined(IGNORE_ETH0_DOWN)
1808 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1810 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1811 if (dhd->pub.up == 0) {
1815 /* Set state and stop OS transmissions */
1817 netif_stop_queue(net);
1819 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation ...\n", __FUNCTION__));
1820 #endif /* !defined(IGNORE_ETH0_DOWN) */
1822 OLD_MOD_DEC_USE_COUNT;
1827 dhd_open(struct net_device *net)
1829 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1835 wl_control_wl_start(net); /* start if needed */
1837 ifidx = dhd_net2idx(dhd, net);
1838 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
1840 /* ASSERT(ifidx == 0); */
1842 if (ifidx == 0) { /* do it only for primary eth0 */
1844 atomic_set(&dhd->pend_8021x_cnt, 0);
1846 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1849 /* Get current TOE mode from dongle */
1850 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1851 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1853 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1856 /* Allow transmit calls */
1857 netif_start_queue(net);
1860 OLD_MOD_INC_USE_COUNT;
1865 dhd_osl_attach(void *pdev, uint bustype)
1867 return osl_attach(pdev, bustype, TRUE);
1871 dhd_osl_detach(osl_t *osh)
1873 if (MALLOCED(osh)) {
1874 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __FUNCTION__, MALLOCED(osh)));
1877 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && 1
1878 up(&dhd_registration_sem);
1879 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
1883 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1884 uint8 *mac_addr, uint32 flags, uint8 bssidx)
1888 DHD_TRACE(("%s: idx %d, handle->%p\n", __FUNCTION__, ifidx, handle));
1890 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1892 ifp = dhd->iflist[ifidx];
1893 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1894 DHD_ERROR(("%s: OOM - dhd_if_t\n", __FUNCTION__));
1898 memset(ifp, 0, sizeof(dhd_if_t));
1900 dhd->iflist[ifidx] = ifp;
1901 strncpy(ifp->name, name, IFNAMSIZ);
1902 ifp->name[IFNAMSIZ] = '\0';
1903 if (mac_addr != NULL)
1904 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1906 if (handle == NULL) {
1907 ifp->state = WLC_E_IF_ADD;
1909 ASSERT(dhd->sysioc_pid >= 0);
1910 up(&dhd->sysioc_sem);
1912 ifp->net = (struct net_device *)handle;
1918 dhd_del_if(dhd_info_t *dhd, int ifidx)
1922 DHD_TRACE(("%s: idx %d\n", __FUNCTION__, ifidx));
1924 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1925 ifp = dhd->iflist[ifidx];
1927 DHD_ERROR(("%s: Null interface\n", __FUNCTION__));
1931 ifp->state = WLC_E_IF_DEL;
1933 ASSERT(dhd->sysioc_pid >= 0);
1934 up(&dhd->sysioc_sem);
1938 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1940 dhd_info_t *dhd = NULL;
1941 struct net_device *net;
1943 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1944 /* updates firmware nvram path if it was provided as module paramters */
1945 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1946 strcpy(fw_path, firmware_path);
1947 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1948 strcpy(nv_path, nvram_path);
1950 /* Allocate etherdev, including space for private structure */
1951 if (!(net = alloc_etherdev(sizeof(dhd)))) {
1952 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
1956 /* Allocate primary dhd_info */
1957 if (!(dhd = MALLOC(osh, sizeof(dhd_info_t)))) {
1958 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __FUNCTION__));
1962 memset(dhd, 0, sizeof(dhd_info_t));
1965 * Save the dhd_info into the priv
1967 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1970 /* Set network interface name if it was provided as module parameter */
1971 if (iface_name[0]) {
1974 strncpy(net->name, iface_name, IFNAMSIZ);
1975 net->name[IFNAMSIZ - 1] = 0;
1976 len = strlen(net->name);
1977 ch = net->name[len - 1];
1978 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1979 strcat(net->name, "%d");
1982 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) == DHD_BAD_IF)
1985 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
1988 net->netdev_ops = NULL;
1991 init_MUTEX(&dhd->proto_sem);
1992 /* Initialize other structure content */
1993 init_waitqueue_head(&dhd->ioctl_resp_wait);
1994 init_waitqueue_head(&dhd->ctrl_wait);
1996 /* Initialize the spinlocks */
1997 spin_lock_init(&dhd->sdlock);
1998 spin_lock_init(&dhd->txqlock);
2000 /* Initialize Wakelock stuff */
2001 spin_lock_init(&dhd->wl_lock);
2004 #ifdef CONFIG_HAS_WAKELOCK
2005 wake_lock_init(&dhd->wl_wifi, WAKE_LOCK_SUSPEND, "wlan_wake");
2006 wake_lock_init(&dhd->wl_rxwake, WAKE_LOCK_SUSPEND, "wlan_rx_wake");
2009 /* Link to info module */
2010 dhd->pub.info = dhd;
2012 /* Link to bus module */
2014 dhd->pub.hdrlen = bus_hdrlen;
2016 /* Attach and link in the protocol */
2017 if (dhd_prot_attach(&dhd->pub) != 0) {
2018 DHD_ERROR(("dhd_prot_attach failed\n"));
2021 #if defined(CONFIG_WIRELESS_EXT)
2022 /* Attach and link in the iw */
2023 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
2024 DHD_ERROR(("wl_iw_attach failed\n"));
2027 #endif /* defined(CONFIG_WIRELESS_EXT) */
2029 /* Set up the watchdog timer */
2030 init_timer(&dhd->timer);
2031 dhd->timer.data = (ulong)dhd;
2032 dhd->timer.function = dhd_watchdog;
2034 /* Initialize thread based operation and lock */
2035 init_MUTEX(&dhd->sdsem);
2036 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)) {
2037 dhd->threads_only = TRUE;
2040 dhd->threads_only = FALSE;
2043 if (dhd_dpc_prio >= 0) {
2044 /* Initialize watchdog thread */
2045 sema_init(&dhd->watchdog_sem, 0);
2046 init_completion(&dhd->watchdog_exited);
2047 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2049 dhd->watchdog_pid = -1;
2052 /* Set up the bottom half handler */
2053 if (dhd_dpc_prio >= 0) {
2054 /* Initialize DPC thread */
2055 sema_init(&dhd->dpc_sem, 0);
2056 init_completion(&dhd->dpc_exited);
2057 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2059 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
2064 sema_init(&dhd->sysioc_sem, 0);
2065 init_completion(&dhd->sysioc_exited);
2066 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2068 dhd->sysioc_pid = -1;
2072 * Save the dhd_info into the priv
2074 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2076 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2079 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2080 register_pm_notifier(&dhd_sleep_pm_notifier);
2081 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2083 #ifdef CONFIG_HAS_EARLYSUSPEND
2084 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2085 dhd->early_suspend.suspend = dhd_early_suspend;
2086 dhd->early_suspend.resume = dhd_late_resume;
2087 register_early_suspend(&dhd->early_suspend);
2096 dhd_detach(&dhd->pub);
2103 dhd_bus_start(dhd_pub_t *dhdp)
2106 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
2107 #ifdef EMBEDDED_PLATFORM
2108 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
2109 #endif /* EMBEDDED_PLATFORM */
2113 DHD_TRACE(("%s: \n", __FUNCTION__));
2115 /* try to download image and nvram to the dongle */
2116 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2117 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2118 fw_path, nv_path))) {
2119 DHD_ERROR(("%s: dhdsdio_probe_download failed. firmware = %s nvram = %s\n",
2120 __FUNCTION__, fw_path, nv_path));
2125 /* Start the watchdog timer */
2126 dhd->pub.tickcnt = 0;
2127 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2129 /* Bring up the bus */
2130 if ((ret = dhd_bus_init(&dhd->pub, TRUE)) != 0) {
2131 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
2134 #if defined(OOB_INTR_ONLY)
2135 /* Host registration for OOB interrupt */
2136 if (bcmsdh_register_oob_intr(dhdp)) {
2137 del_timer_sync(&dhd->timer);
2138 dhd->wd_timer_valid = FALSE;
2139 DHD_ERROR(("%s Host failed to resgister for OOB\n", __FUNCTION__));
2143 /* Enable oob at firmware */
2144 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2145 #endif /* defined(OOB_INTR_ONLY) */
2147 /* If bus is not ready, can't come up */
2148 if (dhd->pub.busstate != DHD_BUS_DATA) {
2149 del_timer_sync(&dhd->timer);
2150 dhd->wd_timer_valid = FALSE;
2151 DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
2155 #ifdef EMBEDDED_PLATFORM
2156 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
2157 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2158 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2160 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2161 setbit(dhdp->eventmask, WLC_E_PRUNE);
2162 setbit(dhdp->eventmask, WLC_E_AUTH);
2163 setbit(dhdp->eventmask, WLC_E_REASSOC);
2164 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2165 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2166 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2167 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2168 setbit(dhdp->eventmask, WLC_E_JOIN);
2169 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2170 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2171 setbit(dhdp->eventmask, WLC_E_LINK);
2172 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2173 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2174 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2175 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2176 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2177 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2179 dhdp->pktfilter_count = 1;
2180 /* Setup filter to allow only unicast */
2181 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2182 #endif /* EMBEDDED_PLATFORM */
2184 /* Bus is ready, do any protocol initialization */
2185 if ((ret = dhd_prot_init(&dhd->pub)) < 0)
2192 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len, int set)
2194 char buf[strlen(name) + 1 + cmd_len];
2195 int len = sizeof(buf);
2199 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2201 memset(&ioc, 0, sizeof(ioc));
2203 ioc.cmd = set? WLC_SET_VAR : WLC_GET_VAR;
2208 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2209 if (!set && ret >= 0)
2210 memcpy(cmd_buf, buf, cmd_len);
2215 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 31))
2216 static struct net_device_ops dhd_ops_pri = {
2217 .ndo_open = dhd_open,
2218 .ndo_stop = dhd_stop,
2219 .ndo_get_stats = dhd_get_stats,
2220 .ndo_do_ioctl = dhd_ioctl_entry,
2221 .ndo_start_xmit = dhd_start_xmit,
2222 .ndo_set_mac_address = dhd_set_mac_address,
2223 .ndo_set_multicast_list = dhd_set_multicast_list,
2226 static struct net_device_ops dhd_ops_virt = {
2227 .ndo_get_stats = dhd_get_stats,
2228 .ndo_do_ioctl = dhd_ioctl_entry,
2229 .ndo_start_xmit = dhd_start_xmit,
2230 .ndo_set_mac_address = dhd_set_mac_address,
2231 .ndo_set_multicast_list = dhd_set_multicast_list,
2236 dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2238 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2239 struct net_device *net;
2240 uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33 };
2242 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
2244 ASSERT(dhd && dhd->iflist[ifidx]);
2245 net = dhd->iflist[ifidx]->net;
2248 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2250 net->get_stats = dhd_get_stats;
2251 net->do_ioctl = dhd_ioctl_entry;
2252 net->hard_start_xmit = dhd_start_xmit;
2253 net->set_mac_address = dhd_set_mac_address;
2254 net->set_multicast_list = dhd_set_multicast_list;
2255 net->open = net->stop = NULL;
2257 ASSERT(!net->netdev_ops);
2258 net->netdev_ops = &dhd_ops_virt;
2261 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2262 net->open = dhd_open;
2263 net->stop = dhd_stop;
2265 net->netdev_ops = &dhd_ops_pri;
2269 * We have to use the primary MAC for virtual interfaces
2272 /* for virtual interfaces use the primary MAC */
2273 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2277 DHD_TRACE(("%s ACCESS POINT MAC: \n", __FUNCTION__));
2278 /* ACCESSPOINT INTERFACE CASE */
2279 temp_addr[0] |= 0x02; /* set bit 2 , - Locally Administered address */
2281 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2282 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2283 net->ethtool_ops = &dhd_ethtool_ops;
2284 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
2286 #if defined(CONFIG_WIRELESS_EXT)
2287 #if WIRELESS_EXT < 19
2288 net->get_wireless_stats = dhd_get_wireless_stats;
2289 #endif /* WIRELESS_EXT < 19 */
2290 #if WIRELESS_EXT > 12
2291 net->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
2292 #endif /* WIRELESS_EXT > 12 */
2293 #endif /* defined(CONFIG_WIRELESS_EXT) */
2295 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2297 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2299 if (register_netdev(net) != 0) {
2300 DHD_ERROR(("%s: couldn't register the net device\n", __FUNCTION__));
2304 printf("%s: Broadcom Dongle Host Driver mac=%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", net->name,
2305 dhd->pub.mac.octet[0], dhd->pub.mac.octet[1], dhd->pub.mac.octet[2],
2306 dhd->pub.mac.octet[3], dhd->pub.mac.octet[4], dhd->pub.mac.octet[5]);
2308 #if defined(CONFIG_WIRELESS_EXT)
2311 /* Don't call for SOFTAP Interface in SOFTAP MODE */
2312 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2314 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
2316 #endif /* CONFIG_WIRELESS_EXT */
2318 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2319 up(&dhd_registration_sem);
2320 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
2324 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2327 net->netdev_ops = NULL;
2333 dhd_bus_detach(dhd_pub_t *dhdp)
2337 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2340 dhd = (dhd_info_t *)dhdp->info;
2342 /* Stop the protocol module */
2343 dhd_prot_stop(&dhd->pub);
2345 /* Stop the bus module */
2346 dhd_bus_stop(dhd->pub.bus, TRUE);
2347 #if defined(OOB_INTR_ONLY)
2348 bcmsdh_unregister_oob_intr();
2349 #endif /* defined(OOB_INTR_ONLY) */
2351 /* Clear the watchdog timer */
2352 del_timer_sync(&dhd->timer);
2353 dhd->wd_timer_valid = FALSE;
2359 dhd_detach(dhd_pub_t *dhdp)
2363 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2366 dhd = (dhd_info_t *)dhdp->info;
2371 #if defined(CONFIG_HAS_EARLYSUSPEND)
2372 unregister_early_suspend(&dhd->early_suspend);
2373 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2374 #if defined(CONFIG_WIRELESS_EXT)
2375 /* Attach and link in the iw */
2379 for (i = 1; i < DHD_MAX_IFS; i++)
2383 if (dhd->sysioc_pid >= 0) {
2384 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2385 wait_for_completion(&dhd->sysioc_exited);
2388 ifp = dhd->iflist[0];
2390 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 31))
2391 if (ifp->net->open) {
2393 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2396 unregister_netdev(ifp->net);
2399 if (dhd->watchdog_pid >= 0)
2401 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2402 wait_for_completion(&dhd->watchdog_exited);
2405 if (dhd->dpc_pid >= 0)
2407 KILL_PROC(dhd->dpc_pid, SIGTERM);
2408 wait_for_completion(&dhd->dpc_exited);
2411 tasklet_kill(&dhd->tasklet);
2413 dhd_bus_detach(dhdp);
2416 dhd_prot_detach(dhdp);
2418 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
2419 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2420 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
2421 free_netdev(ifp->net);
2422 #ifdef CONFIG_HAS_WAKELOCK
2423 wake_lock_destroy(&dhd->wl_wifi);
2424 wake_lock_destroy(&dhd->wl_rxwake);
2426 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2427 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2433 dhd_module_cleanup(void)
2435 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2437 dhd_bus_unregister();
2438 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2441 /* Call customer gpio to turn off power with WL_REG_ON signal */
2442 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2446 dhd_module_init(void)
2450 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2452 /* Sanity check on the module parameters */
2454 /* Both watchdog and DPC as tasklets are ok */
2455 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2458 /* If both watchdog and DPC are threads, TX must be deferred */
2459 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0) && dhd_deferred_tx)
2462 DHD_ERROR(("Invalid module parameters.\n"));
2466 /* Call customer gpio to turn on power with WL_REG_ON signal */
2467 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2469 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2470 sema_init(&wifi_control_sem, 0);
2472 error = wifi_add_dev();
2474 DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__));
2478 /* Waiting callback after platform_driver_register is done or exit with error */
2479 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(5000)) != 0) {
2481 DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__));
2484 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2486 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2487 sema_init(&dhd_registration_sem, 0);
2490 error = dhd_bus_register();
2493 printf("\n%s\n", dhd_version);
2495 DHD_ERROR(("%s: sdio_register_driver failed\n", __FUNCTION__));
2498 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2500 * Wait till MMC sdio_register_driver callback called and made driver attach.
2501 * It's needed to make sync up exit from dhd insmod and
2502 * Kernel MMC sdio device callback registration
2504 if (down_timeout(&dhd_registration_sem, msecs_to_jiffies(DHD_REGISTRATION_TIMEOUT)) != 0) {
2506 DHD_ERROR(("%s: sdio_register_driver timeout\n", __FUNCTION__));
2511 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2513 dhd_bus_unregister();
2516 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2519 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2521 /* Call customer gpio to turn off power with WL_REG_ON signal */
2522 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2527 module_init(dhd_module_init);
2528 module_exit(dhd_module_cleanup);
2531 * OS specific functions required to implement DHD driver in OS independent way
2534 dhd_os_proto_block(dhd_pub_t *pub)
2536 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2539 down(&dhd->proto_sem);
2547 dhd_os_proto_unblock(dhd_pub_t *pub)
2549 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2552 up(&dhd->proto_sem);
2560 dhd_os_get_ioctl_resp_timeout(void)
2562 return ((unsigned int)dhd_ioctl_timeout_msec);
2566 dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2568 dhd_ioctl_timeout_msec = (int)timeout_msec;
2572 dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2574 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2575 DECLARE_WAITQUEUE(wait, current);
2576 int timeout = dhd_ioctl_timeout_msec;
2578 /* Convert timeout in millsecond to jiffies */
2579 timeout = timeout * HZ / 1000;
2581 /* Wait until control frame is available */
2582 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2583 set_current_state(TASK_INTERRUPTIBLE);
2585 while (!(*condition) && (!signal_pending(current) && timeout))
2586 timeout = schedule_timeout(timeout);
2588 if (signal_pending(current))
2591 set_current_state(TASK_RUNNING);
2592 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2598 dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2600 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2602 if (waitqueue_active(&dhd->ioctl_resp_wait)) {
2603 wake_up_interruptible(&dhd->ioctl_resp_wait);
2610 dhd_os_wd_timer(void *bus, uint wdtick)
2612 dhd_pub_t *pub = bus;
2613 static uint save_dhd_watchdog_ms = 0;
2614 dhd_info_t *dhd = (dhd_info_t *)pub->info;
2616 /* don't start the wd until fw is loaded */
2617 if (pub->busstate == DHD_BUS_DOWN)
2620 /* Totally stop the timer */
2621 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2622 del_timer_sync(&dhd->timer);
2623 dhd->wd_timer_valid = FALSE;
2624 save_dhd_watchdog_ms = wdtick;
2629 dhd_watchdog_ms = (uint)wdtick;
2631 /* Re arm the timer, at last watchdog period */
2632 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
2634 dhd->wd_timer_valid = TRUE;
2635 save_dhd_watchdog_ms = wdtick;
2640 dhd_os_open_image(char *filename)
2644 fp = filp_open(filename, O_RDONLY, 0);
2646 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2648 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2658 dhd_os_get_image_block(char *buf, int len, void *image)
2660 struct file *fp = (struct file *)image;
2666 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2674 dhd_os_close_image(void *image)
2677 filp_close((struct file *)image, NULL);
2682 dhd_os_sdlock(dhd_pub_t *pub)
2686 dhd = (dhd_info_t *)(pub->info);
2688 if (dhd->threads_only)
2691 spin_lock_bh(&dhd->sdlock);
2695 dhd_os_sdunlock(dhd_pub_t *pub)
2699 dhd = (dhd_info_t *)(pub->info);
2701 if (dhd->threads_only)
2704 spin_unlock_bh(&dhd->sdlock);
2708 dhd_os_sdlock_txq(dhd_pub_t *pub)
2712 dhd = (dhd_info_t *)(pub->info);
2713 spin_lock_bh(&dhd->txqlock);
2717 dhd_os_sdunlock_txq(dhd_pub_t *pub)
2721 dhd = (dhd_info_t *)(pub->info);
2722 spin_unlock_bh(&dhd->txqlock);
2725 dhd_os_sdlock_rxq(dhd_pub_t *pub)
2729 dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2734 dhd_os_sdtxlock(dhd_pub_t *pub)
2740 dhd_os_sdtxunlock(dhd_pub_t *pub)
2742 dhd_os_sdunlock(pub);
2745 #ifdef DHD_USE_STATIC_BUF
2746 void * dhd_os_prealloc(int section, unsigned long size)
2748 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2749 void *alloc_ptr = NULL;
2750 if (wifi_control_data && wifi_control_data->mem_prealloc)
2752 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2755 DHD_INFO(("success alloc section %d\n", section));
2756 bzero(alloc_ptr, size);
2761 DHD_ERROR(("can't alloc section %d\n", section));
2764 return MALLOC(0, size);
2765 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2767 #endif /* DHD_USE_STATIC_BUF */
2768 #if defined(CONFIG_WIRELESS_EXT)
2769 struct iw_statistics *
2770 dhd_get_wireless_stats(struct net_device *dev)
2773 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2775 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2778 return &dhd->iw.wstats;
2782 #endif /* defined(CONFIG_WIRELESS_EXT) */
2785 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2786 wl_event_msg_t *event, void **data)
2790 ASSERT(dhd != NULL);
2792 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2793 if (bcmerror != BCME_OK)
2796 #if defined(CONFIG_WIRELESS_EXT)
2797 ASSERT(dhd->iflist[*ifidx] != NULL);
2798 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2800 if (dhd->iflist[*ifidx]->net)
2801 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2802 #endif /* defined(CONFIG_WIRELESS_EXT) */
2807 /* send up locally generated event */
2809 dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2811 switch (ntoh32(event->event_type)) {
2817 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2819 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2820 struct dhd_info *dhdinfo = dhd->info;
2821 dhd_os_sdunlock(dhd);
2822 wait_event_interruptible_timeout(dhdinfo->ctrl_wait, (*lockvar == FALSE), HZ * 2);
2828 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2830 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
2831 struct dhd_info *dhdinfo = dhd->info;
2832 if (waitqueue_active(&dhdinfo->ctrl_wait))
2833 wake_up_interruptible(&dhdinfo->ctrl_wait);
2839 dhd_dev_reset(struct net_device *dev, uint8 flag)
2841 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2843 /* Turning off watchdog */
2845 dhd_os_wd_timer(&dhd->pub, 0);
2847 dhd_bus_devreset(&dhd->pub, flag);
2849 /* Turning on watchdog back */
2851 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2853 DHD_ERROR(("%s: WLAN OFF DONE\n", __FUNCTION__));
2859 dhd_dev_init_ioctl(struct net_device *dev)
2861 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2863 dhd_preinit_ioctls(&dhd->pub);
2867 dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2869 return (atomic_read(&dhd->pend_8021x_cnt));
2872 #define MAX_WAIT_FOR_8021X_TX 10
2875 dhd_wait_pend8021x(struct net_device *dev)
2877 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2878 int timeout = 10 * HZ / 1000;
2879 int ntimes = MAX_WAIT_FOR_8021X_TX;
2880 int pend = dhd_get_pend_8021x_cnt(dhd);
2882 while (ntimes && pend) {
2884 set_current_state(TASK_INTERRUPTIBLE);
2885 schedule_timeout(timeout);
2886 set_current_state(TASK_RUNNING);
2889 pend = dhd_get_pend_8021x_cnt(dhd);
2896 write_to_file(dhd_pub_t *dhd, uint8 *buf, int size)
2900 mm_segment_t old_fs;
2903 /* change to KERNEL_DS address limit */
2907 /* open file to write */
2908 fp = filp_open("/tmp/mem_dump", O_WRONLY|O_CREAT, 0640);
2910 printf("%s: open file error\n", __FUNCTION__);
2915 /* Write buf to file */
2916 fp->f_op->write(fp, buf, size, &pos);
2919 /* free buf before return */
2920 MFREE(dhd->osh, buf, size);
2921 /* close file before return */
2923 filp_close(fp, current->files);
2924 /* restore previous address limit */
2929 #endif /* DHD_DEBUG */
2931 int dhd_os_wake_lock_timeout(dhd_pub_t *pub)
2933 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2934 unsigned long flags;
2938 spin_lock_irqsave(&dhd->wl_lock, flags);
2939 ret = dhd->wl_packet;
2940 #ifdef CONFIG_HAS_WAKELOCK
2942 wake_lock_timeout(&dhd->wl_rxwake, HZ);
2945 spin_unlock_irqrestore(&dhd->wl_lock, flags);
2947 /* printk("%s: %d\n", __FUNCTION__, ret); */
2951 int net_os_wake_lock_timeout(struct net_device *dev)
2953 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2957 ret = dhd_os_wake_lock_timeout(&dhd->pub);
2961 int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub)
2963 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2964 unsigned long flags;
2967 spin_lock_irqsave(&dhd->wl_lock, flags);
2969 spin_unlock_irqrestore(&dhd->wl_lock, flags);
2971 /* printk("%s\n",__func__); */
2975 int net_os_wake_lock_timeout_enable(struct net_device *dev)
2977 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2981 ret = dhd_os_wake_lock_timeout_enable(&dhd->pub);
2985 int dhd_os_wake_lock(dhd_pub_t *pub)
2987 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
2988 unsigned long flags;
2992 spin_lock_irqsave(&dhd->wl_lock, flags);
2993 #ifdef CONFIG_HAS_WAKELOCK
2995 wake_lock(&dhd->wl_wifi);
2998 ret = dhd->wl_count;
2999 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3001 /* printk("%s: %d\n", __FUNCTION__, ret); */
3005 int net_os_wake_lock(struct net_device *dev)
3007 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3011 ret = dhd_os_wake_lock(&dhd->pub);
3015 int dhd_os_wake_unlock(dhd_pub_t *pub)
3017 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
3018 unsigned long flags;
3021 dhd_os_wake_lock_timeout(pub);
3023 spin_lock_irqsave(&dhd->wl_lock, flags);
3024 if (dhd->wl_count) {
3026 #ifdef CONFIG_HAS_WAKELOCK
3028 wake_unlock(&dhd->wl_wifi);
3030 ret = dhd->wl_count;
3032 spin_unlock_irqrestore(&dhd->wl_lock, flags);
3034 /* printk("%s: %d\n", __FUNCTION__, ret); */
3038 int net_os_wake_unlock(struct net_device *dev)
3040 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3044 ret = dhd_os_wake_unlock(&dhd->pub);
3048 int net_os_set_suspend_disable(struct net_device *dev, int val)
3050 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
3053 dhd->pub.suspend_disable_flag = val;