2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifdef CONFIG_WIFI_CONTROL_FUNC
18 #include <linux/platform_device.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <linux/skbuff.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/mmc/sdio_func.h>
28 #include <linux/random.h>
29 #include <linux/spinlock.h>
30 #include <linux/ethtool.h>
31 #include <linux/fcntl.h>
33 #include <linux/uaccess.h>
38 #include <bcmendian.h>
40 #include <proto/ethernet.h>
41 #include <dngl_stats.h>
44 #include <dhd_proto.h>
47 #include <wl_cfg80211.h>
49 #define EPI_VERSION_STR "4.218.248.5"
51 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
52 #include <linux/wifi_tiwlan.h>
54 struct semaphore wifi_control_sem;
56 struct dhd_bus *g_bus;
58 static struct wifi_platform_data *wifi_control_data;
59 static struct resource *wifi_irqres;
61 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
64 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
65 return (int)wifi_irqres->start;
67 #ifdef CUSTOM_OOB_GPIO_NUM
68 return CUSTOM_OOB_GPIO_NUM;
74 int wifi_set_carddetect(int on)
76 printk(KERN_ERR "%s = %d\n", __func__, on);
77 if (wifi_control_data && wifi_control_data->set_carddetect)
78 wifi_control_data->set_carddetect(on);
82 int wifi_set_power(int on, unsigned long msec)
84 printk(KERN_ERR "%s = %d\n", __func__, on);
85 if (wifi_control_data && wifi_control_data->set_power)
86 wifi_control_data->set_power(on);
92 int wifi_set_reset(int on, unsigned long msec)
94 printk(KERN_ERR "%s = %d\n", __func__, on);
95 if (wifi_control_data && wifi_control_data->set_reset)
96 wifi_control_data->set_reset(on);
102 static int wifi_probe(struct platform_device *pdev)
104 struct wifi_platform_data *wifi_ctrl =
105 (struct wifi_platform_data *)(pdev->dev.platform_data);
107 printk(KERN_ERR "## %s\n", __func__);
109 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
111 wifi_control_data = wifi_ctrl;
113 wifi_set_power(1, 0); /* Power On */
114 wifi_set_carddetect(1); /* CardDetect (0->1) */
116 up(&wifi_control_sem);
120 static int wifi_remove(struct platform_device *pdev)
122 struct wifi_platform_data *wifi_ctrl =
123 (struct wifi_platform_data *)(pdev->dev.platform_data);
125 printk(KERN_ERR "## %s\n", __func__);
126 wifi_control_data = wifi_ctrl;
128 wifi_set_carddetect(0); /* CardDetect (1->0) */
129 wifi_set_power(0, 0); /* Power Off */
131 up(&wifi_control_sem);
135 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
137 DHD_TRACE(("##> %s\n", __func__));
141 static int wifi_resume(struct platform_device *pdev)
143 DHD_TRACE(("##> %s\n", __func__));
147 static struct platform_driver wifi_device = {
149 .remove = wifi_remove,
150 .suspend = wifi_suspend,
151 .resume = wifi_resume,
153 .name = "bcm4329_wlan",
157 int wifi_add_dev(void)
159 DHD_TRACE(("## Calling platform_driver_register\n"));
160 return platform_driver_register(&wifi_device);
163 void wifi_del_dev(void)
165 DHD_TRACE(("## Unregister platform_driver_register\n"));
166 platform_driver_unregister(&wifi_device);
168 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
170 #if defined(CONFIG_PM_SLEEP)
171 #include <linux/suspend.h>
172 volatile bool dhd_mmc_suspend = false;
173 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
174 #endif /* defined(CONFIG_PM_SLEEP) */
176 #if defined(OOB_INTR_ONLY)
177 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
178 #endif /* defined(OOB_INTR_ONLY) */
180 MODULE_AUTHOR("Broadcom Corporation");
181 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
182 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
183 MODULE_LICENSE("Dual BSD/GPL");
185 #define DRV_MODULE_NAME "brcmfmac"
187 /* Linux wireless extension support */
188 #if defined(CONFIG_WIRELESS_EXT)
190 extern wl_iw_extra_params_t g_wl_iw_params;
191 #endif /* defined(CONFIG_WIRELESS_EXT) */
193 #if defined(CONFIG_HAS_EARLYSUSPEND)
194 #include <linux/earlysuspend.h>
195 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
197 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
199 #ifdef PKT_FILTER_SUPPORT
200 extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
201 extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
205 /* Interface control information */
206 typedef struct dhd_if {
207 struct dhd_info *info; /* back pointer to dhd_info */
208 /* OS/stack specifics */
209 struct net_device *net;
210 struct net_device_stats stats;
211 int idx; /* iface idx in dongle */
212 int state; /* interface state */
213 uint subunit; /* subunit */
214 u8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
215 bool attached; /* Delayed attachment when unset */
216 bool txflowcontrol; /* Per interface flow control indicator */
217 char name[IFNAMSIZ]; /* linux interface name */
220 /* Local private structure (extension of pub) */
221 typedef struct dhd_info {
222 #if defined(CONFIG_WIRELESS_EXT)
223 wl_iw_t iw; /* wireless extensions state (must be first) */
224 #endif /* defined(CONFIG_WIRELESS_EXT) */
228 /* OS/stack specifics */
229 dhd_if_t *iflist[DHD_MAX_IFS];
231 struct semaphore proto_sem;
232 wait_queue_head_t ioctl_resp_wait;
233 struct timer_list timer;
235 struct tasklet_struct tasklet;
238 /* Thread based operation */
240 struct semaphore sdsem;
241 struct task_struct *watchdog_tsk;
242 struct semaphore watchdog_sem;
243 struct task_struct *dpc_tsk;
244 struct semaphore dpc_sem;
246 /* Thread to issue ioctl for multicast */
247 struct task_struct *sysioc_tsk;
248 struct semaphore sysioc_sem;
251 struct ether_addr macvalue;
252 wait_queue_head_t ctrl_wait;
253 atomic_t pend_8021x_cnt;
255 #ifdef CONFIG_HAS_EARLYSUSPEND
256 struct early_suspend early_suspend;
257 #endif /* CONFIG_HAS_EARLYSUSPEND */
260 /* Definitions to provide path to the firmware and nvram
261 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
263 char firmware_path[MOD_PARAM_PATHLEN];
264 char nvram_path[MOD_PARAM_PATHLEN];
266 /* load firmware and/or nvram values from the filesystem */
267 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
268 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
271 module_param(dhd_msg_level, int, 0);
273 /* Spawn a thread for system ioctls (set mac, set mcast) */
274 uint dhd_sysioc = true;
275 module_param(dhd_sysioc, uint, 0);
277 /* Watchdog interval */
278 uint dhd_watchdog_ms = 10;
279 module_param(dhd_watchdog_ms, uint, 0);
282 /* Console poll interval */
284 module_param(dhd_console_ms, uint, 0);
285 #endif /* DHD_DEBUG */
287 /* ARP offload agent mode : Enable ARP Host Auto-Reply
288 and ARP Peer Auto-Reply */
289 uint dhd_arp_mode = 0xb;
290 module_param(dhd_arp_mode, uint, 0);
292 /* ARP offload enable */
293 uint dhd_arp_enable = true;
294 module_param(dhd_arp_enable, uint, 0);
296 /* Global Pkt filter enable control */
297 uint dhd_pkt_filter_enable = true;
298 module_param(dhd_pkt_filter_enable, uint, 0);
300 /* Pkt filter init setup */
301 uint dhd_pkt_filter_init;
302 module_param(dhd_pkt_filter_init, uint, 0);
304 /* Pkt filter mode control */
305 uint dhd_master_mode = true;
306 module_param(dhd_master_mode, uint, 1);
308 /* Watchdog thread priority, -1 to use kernel timer */
309 int dhd_watchdog_prio = 97;
310 module_param(dhd_watchdog_prio, int, 0);
312 /* DPC thread priority, -1 to use tasklet */
313 int dhd_dpc_prio = 98;
314 module_param(dhd_dpc_prio, int, 0);
316 /* DPC thread priority, -1 to use tasklet */
317 extern int dhd_dongle_memsize;
318 module_param(dhd_dongle_memsize, int, 0);
320 /* Contorl fw roaming */
327 /* Control radio state */
328 uint dhd_radio_up = 1;
330 /* Network inteface name */
331 char iface_name[IFNAMSIZ];
332 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
334 /* The following are specific to the SDIO dongle */
336 /* IOCTL response timeout */
337 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
339 /* Idle timeout for backplane clock */
340 int dhd_idletime = DHD_IDLETIME_TICKS;
341 module_param(dhd_idletime, int, 0);
344 uint dhd_poll = false;
345 module_param(dhd_poll, uint, 0);
348 uint dhd_cfg80211 = true;
349 module_param(dhd_cfg80211, uint, 0);
352 uint dhd_intr = true;
353 module_param(dhd_intr, uint, 0);
355 /* SDIO Drive Strength (in milliamps) */
356 uint dhd_sdiod_drive_strength = 6;
357 module_param(dhd_sdiod_drive_strength, uint, 0);
360 extern uint dhd_txbound;
361 extern uint dhd_rxbound;
362 module_param(dhd_txbound, uint, 0);
363 module_param(dhd_rxbound, uint, 0);
365 /* Deferred transmits */
366 extern uint dhd_deferred_tx;
367 module_param(dhd_deferred_tx, uint, 0);
370 /* Echo packet generator (pkts/s) */
372 module_param(dhd_pktgen, uint, 0);
374 /* Echo packet len (0 => sawtooth, max 2040) */
376 module_param(dhd_pktgen_len, uint, 0);
379 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
380 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
381 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
382 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
384 /* Version string to report */
386 #define DHD_COMPILED "\nCompiled in " SRCBASE
391 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
393 "\nCompiled in " " on " __DATE__ " at " __TIME__
397 #if defined(CONFIG_WIRELESS_EXT)
398 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
399 #endif /* defined(CONFIG_WIRELESS_EXT) */
401 static void dhd_dpc(unsigned long data);
403 extern int dhd_wait_pend8021x(struct net_device *dev);
407 #error TOE requires BDC
409 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
410 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
413 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
414 wl_event_msg_t *event_ptr, void **data_ptr);
416 #if defined(CONFIG_PM_SLEEP)
417 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
418 unsigned long action, void *ignored)
421 case PM_HIBERNATION_PREPARE:
422 case PM_SUSPEND_PREPARE:
423 dhd_mmc_suspend = true;
425 case PM_POST_HIBERNATION:
426 case PM_POST_SUSPEND:
427 dhd_mmc_suspend = false;
433 static struct notifier_block dhd_sleep_pm_notifier = {
434 .notifier_call = dhd_sleep_pm_callback,
438 extern int register_pm_notifier(struct notifier_block *nb);
439 extern int unregister_pm_notifier(struct notifier_block *nb);
440 #endif /* defined(CONFIG_PM_SLEEP) */
441 /* && defined(DHD_GPL) */
442 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
444 #ifdef PKT_FILTER_SUPPORT
445 DHD_TRACE(("%s: %d\n", __func__, value));
446 /* 1 - Enable packet filter, only allow unicast packet to send up */
447 /* 0 - Disable packet filter */
448 if (dhd_pkt_filter_enable) {
451 for (i = 0; i < dhd->pktfilter_count; i++) {
452 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
453 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
454 value, dhd_master_mode);
460 #if defined(CONFIG_HAS_EARLYSUSPEND)
461 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
463 int power_mode = PM_MAX;
464 /* wl_pkt_filter_enable_t enable_parm; */
469 #endif /* CUSTOMER_HW2 */
471 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
472 __func__, value, dhd->in_suspend));
474 if (dhd && dhd->up) {
475 if (value && dhd->in_suspend) {
477 /* Kernel suspended */
478 DHD_TRACE(("%s: force extra Suspend setting\n",
481 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
485 /* Enable packet filter, only allow unicast
487 dhd_set_packet_filter(1, dhd);
489 /* if dtim skip setup as default force it
490 * to wake each thrid dtim
491 * for better power saving.
492 * Note that side effect is chance to miss BC/MC
495 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
498 bcn_li_dtim = dhd->dtim_skip;
499 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
500 4, iovbuf, sizeof(iovbuf));
501 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
504 /* Disable build-in roaming to allowed \
505 * supplicant to take of romaing
507 bcm_mkiovar("roam_off", (char *)&roamvar, 4,
508 iovbuf, sizeof(iovbuf));
509 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
511 #endif /* CUSTOMER_HW2 */
515 DHD_TRACE(("%s: Remove extra suspend setting\n",
518 power_mode = PM_FAST;
519 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
523 /* disable pkt filter */
524 dhd_set_packet_filter(0, dhd);
526 /* restore pre-suspend setting for dtim_skip */
527 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
528 4, iovbuf, sizeof(iovbuf));
530 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
534 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
536 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
538 #endif /* CUSTOMER_HW2 */
545 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
547 dhd_pub_t *dhdp = &dhd->pub;
549 dhd_os_proto_block(dhdp);
550 /* Set flag when early suspend was called */
551 dhdp->in_suspend = val;
552 if (!dhdp->suspend_disable_flag)
553 dhd_set_suspend(val, dhdp);
554 dhd_os_proto_unblock(dhdp);
557 static void dhd_early_suspend(struct early_suspend *h)
559 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
561 DHD_TRACE(("%s: enter\n", __func__));
564 dhd_suspend_resume_helper(dhd, 1);
568 static void dhd_late_resume(struct early_suspend *h)
570 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
572 DHD_TRACE(("%s: enter\n", __func__));
575 dhd_suspend_resume_helper(dhd, 0);
577 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
580 * Generalized timeout mechanism. Uses spin sleep with exponential
582 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
584 * dhd_timeout_start(&tmo, usec);
585 * while (!dhd_timeout_expired(&tmo))
586 * if (poll_something())
588 * if (dhd_timeout_expired(&tmo))
592 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
597 tmo->tick = 1000000 / HZ;
600 int dhd_timeout_expired(dhd_timeout_t *tmo)
602 /* Does nothing the first call */
603 if (tmo->increment == 0) {
608 if (tmo->elapsed >= tmo->limit)
611 /* Add the delay that's about to take place */
612 tmo->elapsed += tmo->increment;
614 if (tmo->increment < tmo->tick) {
615 udelay(tmo->increment);
617 if (tmo->increment > tmo->tick)
618 tmo->increment = tmo->tick;
620 wait_queue_head_t delay_wait;
621 DECLARE_WAITQUEUE(wait, current);
623 init_waitqueue_head(&delay_wait);
624 add_wait_queue(&delay_wait, &wait);
625 set_current_state(TASK_INTERRUPTIBLE);
627 pending = signal_pending(current);
628 remove_wait_queue(&delay_wait, &wait);
629 set_current_state(TASK_RUNNING);
631 return 1; /* Interrupted */
637 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
642 while (i < DHD_MAX_IFS) {
643 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
651 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
657 if (name == NULL || *name == '\0')
662 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
665 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
667 return i; /* default - the primary interface */
670 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
672 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
676 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
677 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
681 if (dhd->iflist[ifidx] == NULL) {
682 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
686 if (dhd->iflist[ifidx]->net)
687 return dhd->iflist[ifidx]->net->name;
692 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
694 struct net_device *dev;
695 struct netdev_hw_addr *ha;
703 ASSERT(dhd && dhd->iflist[ifidx]);
704 dev = dhd->iflist[ifidx]->net;
705 cnt = netdev_mc_count(dev);
707 /* Determine initial value of allmulti flag */
708 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
710 /* Send down the multicast list first. */
712 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
713 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
715 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
716 dhd_ifname(&dhd->pub, ifidx), cnt));
720 strcpy(bufp, "mcast_list");
721 bufp += strlen("mcast_list") + 1;
724 memcpy(bufp, &cnt, sizeof(cnt));
727 netdev_for_each_mc_addr(ha, dev) {
730 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
731 bufp += ETHER_ADDR_LEN;
735 memset(&ioc, 0, sizeof(ioc));
736 ioc.cmd = WLC_SET_VAR;
741 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
743 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
744 dhd_ifname(&dhd->pub, ifidx), cnt));
745 allmulti = cnt ? true : allmulti;
750 /* Now send the allmulti setting. This is based on the setting in the
751 * net_device flags, but might be modified above to be turned on if we
752 * were trying to set some addresses and dongle rejected it...
755 buflen = sizeof("allmulti") + sizeof(allmulti);
756 buf = kmalloc(buflen, GFP_ATOMIC);
758 DHD_ERROR(("%s: out of memory for allmulti\n",
759 dhd_ifname(&dhd->pub, ifidx)));
762 allmulti = htol32(allmulti);
765 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
766 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
767 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
768 (int)sizeof(allmulti), buflen));
773 memset(&ioc, 0, sizeof(ioc));
774 ioc.cmd = WLC_SET_VAR;
779 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
781 DHD_ERROR(("%s: set allmulti %d failed\n",
782 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
787 /* Finally, pick up the PROMISC flag as well, like the NIC
790 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
791 allmulti = htol32(allmulti);
793 memset(&ioc, 0, sizeof(ioc));
794 ioc.cmd = WLC_SET_PROMISC;
796 ioc.len = sizeof(allmulti);
799 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
801 DHD_ERROR(("%s: set promisc %d failed\n",
802 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
807 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
813 DHD_TRACE(("%s enter\n", __func__));
815 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) {
816 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
817 dhd_ifname(&dhd->pub, ifidx)));
820 memset(&ioc, 0, sizeof(ioc));
821 ioc.cmd = WLC_SET_VAR;
826 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
828 DHD_ERROR(("%s: set cur_etheraddr failed\n",
829 dhd_ifname(&dhd->pub, ifidx)));
831 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
838 extern struct net_device *ap_net_dev;
841 static void dhd_op_if(dhd_if_t *ifp)
844 int ret = 0, err = 0;
846 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
850 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
852 switch (ifp->state) {
855 * Delete the existing interface before overwriting it
856 * in case we missed the WLC_E_IF_DEL event.
858 if (ifp->net != NULL) {
859 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
860 "try free & unregister\n",
861 __func__, ifp->net->name));
862 netif_stop_queue(ifp->net);
863 unregister_netdev(ifp->net);
864 free_netdev(ifp->net);
866 /* Allocate etherdev, including space for private structure */
867 ifp->net = alloc_etherdev(sizeof(dhd));
869 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
873 strcpy(ifp->net->name, ifp->name);
874 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
875 err = dhd_net_attach(&dhd->pub, ifp->idx);
877 DHD_ERROR(("%s: dhd_net_attach failed, "
883 /* semaphore that the soft AP CODE
885 extern struct semaphore ap_eth_sema;
887 /* save ptr to wl0.1 netdev for use
889 ap_net_dev = ifp->net;
890 /* signal to the SOFTAP 'sleeper' thread,
894 DHD_TRACE(("\n ==== pid:%x, net_device for "
895 "if:%s created ===\n\n",
896 current->pid, ifp->net->name));
902 if (ifp->net != NULL) {
903 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
905 netif_stop_queue(ifp->net);
906 unregister_netdev(ifp->net);
907 ret = DHD_DEL_IF; /* Make sure the free_netdev()
912 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
919 free_netdev(ifp->net);
921 dhd->iflist[ifp->idx] = NULL;
924 if (ifp->net == ap_net_dev)
925 ap_net_dev = NULL; /* NULL SOFTAP global
931 static int _dhd_sysioc_thread(void *data)
933 dhd_info_t *dhd = (dhd_info_t *) data;
939 allow_signal(SIGTERM);
941 while (down_interruptible(&dhd->sysioc_sem) == 0) {
942 if (kthread_should_stop())
944 for (i = 0; i < DHD_MAX_IFS; i++) {
945 if (dhd->iflist[i]) {
947 in_ap = (ap_net_dev != NULL);
949 if (dhd->iflist[i]->state)
950 dhd_op_if(dhd->iflist[i]);
952 if (dhd->iflist[i] == NULL) {
953 DHD_TRACE(("\n\n %s: interface %d "
954 "removed!\n", __func__, i));
958 if (in_ap && dhd->set_macaddress) {
959 DHD_TRACE(("attempt to set MAC for %s "
960 "in AP Mode," "blocked. \n",
961 dhd->iflist[i]->net->name));
962 dhd->set_macaddress = false;
966 if (in_ap && dhd->set_multicast) {
967 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
968 dhd->iflist[i]->net->name));
969 dhd->set_multicast = false;
973 if (dhd->set_multicast) {
974 dhd->set_multicast = false;
975 _dhd_set_multicast_list(dhd, i);
977 if (dhd->set_macaddress) {
978 dhd->set_macaddress = false;
979 _dhd_set_mac_address(dhd, i,
988 static int dhd_set_mac_address(struct net_device *dev, void *addr)
992 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
993 struct sockaddr *sa = (struct sockaddr *)addr;
996 ifidx = dhd_net2idx(dhd, dev);
997 if (ifidx == DHD_BAD_IF)
1000 ASSERT(dhd->sysioc_tsk);
1001 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1002 dhd->set_macaddress = true;
1003 up(&dhd->sysioc_sem);
1008 static void dhd_set_multicast_list(struct net_device *dev)
1010 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1013 ifidx = dhd_net2idx(dhd, dev);
1014 if (ifidx == DHD_BAD_IF)
1017 ASSERT(dhd->sysioc_tsk);
1018 dhd->set_multicast = true;
1019 up(&dhd->sysioc_sem);
1022 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1025 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1027 /* Reject if down */
1028 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1031 /* Update multicast statistic */
1032 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1033 u8 *pktdata = (u8 *) PKTDATA(pktbuf);
1034 struct ether_header *eh = (struct ether_header *)pktdata;
1036 if (ETHER_ISMULTI(eh->ether_dhost))
1037 dhdp->tx_multicast++;
1038 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1039 atomic_inc(&dhd->pend_8021x_cnt);
1042 /* Look into the packet and update the packet priority */
1043 if ((PKTPRIO(pktbuf) == 0))
1044 pktsetprio(pktbuf, false);
1046 /* If the protocol uses a data header, apply it */
1047 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1049 /* Use bus module to send data frame */
1051 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1053 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1054 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1055 #endif /* BCMDBUS */
1060 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1064 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1067 DHD_TRACE(("%s: Enter\n", __func__));
1069 /* Reject if down */
1070 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1071 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1072 __func__, dhd->pub.up, dhd->pub.busstate));
1073 netif_stop_queue(net);
1077 ifidx = dhd_net2idx(dhd, net);
1078 if (ifidx == DHD_BAD_IF) {
1079 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1080 netif_stop_queue(net);
1084 /* Make sure there's enough room for any header */
1085 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1086 struct sk_buff *skb2;
1088 DHD_INFO(("%s: insufficient headroom\n",
1089 dhd_ifname(&dhd->pub, ifidx)));
1090 dhd->pub.tx_realloc++;
1091 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1095 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1096 dhd_ifname(&dhd->pub, ifidx)));
1102 /* Convert to packet */
1103 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1105 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1106 dhd_ifname(&dhd->pub, ifidx)));
1107 dev_kfree_skb_any(skb);
1112 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1116 dhd->pub.dstats.tx_dropped++;
1118 dhd->pub.tx_packets++;
1120 /* Return ok: we always eat the packet */
1124 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1126 struct net_device *net;
1127 dhd_info_t *dhd = dhdp->info;
1129 DHD_TRACE(("%s: Enter\n", __func__));
1131 dhdp->txoff = state;
1132 ASSERT(dhd && dhd->iflist[ifidx]);
1133 net = dhd->iflist[ifidx]->net;
1135 netif_stop_queue(net);
1137 netif_wake_queue(net);
1140 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1142 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1143 struct sk_buff *skb;
1146 void *data, *pnext, *save_pktbuf;
1149 wl_event_msg_t event;
1151 DHD_TRACE(("%s: Enter\n", __func__));
1153 save_pktbuf = pktbuf;
1155 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1157 pnext = PKTNEXT(pktbuf);
1158 PKTSETNEXT(pktbuf, NULL);
1160 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1162 /* Get the protocol, maintain skb around eth_type_trans()
1163 * The main reason for this hack is for the limitation of
1164 * Linux 2.4 where 'eth_type_trans' uses the
1165 * 'net->hard_header_len'
1166 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1167 * coping of the packet coming from the network stack to add
1168 * BDC, Hardware header etc, during network interface
1170 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1172 * for BDC, Hardware header etc. and not just the ETH_HLEN
1177 ifp = dhd->iflist[ifidx];
1179 ifp = dhd->iflist[0];
1182 skb->dev = ifp->net;
1183 skb->protocol = eth_type_trans(skb, skb->dev);
1185 if (skb->pkt_type == PACKET_MULTICAST)
1186 dhd->pub.rx_multicast++;
1191 /* Strip header, count, deliver upward */
1192 skb_pull(skb, ETH_HLEN);
1194 /* Process special event packets and then discard them */
1195 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1196 dhd_wl_host_event(dhd, &ifidx,
1200 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1201 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1202 ifp = dhd->iflist[ifidx];
1205 ifp->net->last_rx = jiffies;
1207 dhdp->dstats.rx_bytes += skb->len;
1208 dhdp->rx_packets++; /* Local count */
1210 if (in_interrupt()) {
1213 /* If the receive is not processed inside an ISR,
1214 * the softirqd must be woken explicitly to service
1215 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1216 * by netif_rx_ni(), but in earlier kernels, we need
1217 * to do it manually.
1224 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1226 /* Linux version has nothing to do */
1230 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1233 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1234 struct ether_header *eh;
1237 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1239 eh = (struct ether_header *)PKTDATA(txp);
1240 type = ntoh16(eh->ether_type);
1242 if (type == ETHER_TYPE_802_1X)
1243 atomic_dec(&dhd->pend_8021x_cnt);
1247 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1249 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1253 DHD_TRACE(("%s: Enter\n", __func__));
1255 ifidx = dhd_net2idx(dhd, net);
1256 if (ifidx == DHD_BAD_IF)
1259 ifp = dhd->iflist[ifidx];
1263 /* Use the protocol to get dongle stats */
1264 dhd_prot_dstats(&dhd->pub);
1267 /* Copy dongle stats to net device stats */
1268 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1269 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1270 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1271 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1272 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1273 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1274 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1275 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1276 ifp->stats.multicast = dhd->pub.dstats.multicast;
1281 static int dhd_watchdog_thread(void *data)
1283 dhd_info_t *dhd = (dhd_info_t *) data;
1284 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1286 /* This thread doesn't need any user-level access,
1287 * so get rid of all our resources
1290 if (dhd_watchdog_prio > 0) {
1291 struct sched_param param;
1292 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1293 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1294 setScheduler(current, SCHED_FIFO, ¶m);
1296 #endif /* DHD_SCHED */
1298 allow_signal(SIGTERM);
1299 /* Run until signal received */
1301 if (kthread_should_stop())
1303 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1304 if (dhd->pub.dongle_reset == false) {
1305 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1306 /* Call the bus module watchdog */
1307 dhd_bus_watchdog(&dhd->pub);
1308 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1310 /* Count the tick for reference */
1316 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1320 static void dhd_watchdog(unsigned long data)
1322 dhd_info_t *dhd = (dhd_info_t *) data;
1324 if (dhd->watchdog_tsk) {
1325 up(&dhd->watchdog_sem);
1327 /* Reschedule the watchdog */
1328 if (dhd->wd_timer_valid) {
1329 mod_timer(&dhd->timer,
1330 jiffies + dhd_watchdog_ms * HZ / 1000);
1335 /* Call the bus module watchdog */
1336 dhd_bus_watchdog(&dhd->pub);
1338 /* Count the tick for reference */
1341 /* Reschedule the watchdog */
1342 if (dhd->wd_timer_valid)
1343 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1346 static int dhd_dpc_thread(void *data)
1348 dhd_info_t *dhd = (dhd_info_t *) data;
1350 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1351 /* This thread doesn't need any user-level access,
1352 * so get rid of all our resources
1355 if (dhd_dpc_prio > 0) {
1356 struct sched_param param;
1357 param.sched_priority =
1359 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1360 setScheduler(current, SCHED_FIFO, ¶m);
1362 #endif /* DHD_SCHED */
1364 allow_signal(SIGTERM);
1365 /* Run until signal received */
1367 if (kthread_should_stop())
1369 if (down_interruptible(&dhd->dpc_sem) == 0) {
1370 /* Call bus dpc unless it indicated down
1371 (then clean stop) */
1372 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1373 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1374 if (dhd_bus_dpc(dhd->pub.bus)) {
1376 WAKE_LOCK_TIMEOUT(&dhd->pub,
1377 WAKE_LOCK_TMOUT, 25);
1379 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1381 dhd_bus_stop(dhd->pub.bus, true);
1387 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1391 static void dhd_dpc(unsigned long data)
1395 dhd = (dhd_info_t *) data;
1397 /* Call bus dpc unless it indicated down (then clean stop) */
1398 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1399 if (dhd_bus_dpc(dhd->pub.bus))
1400 tasklet_schedule(&dhd->tasklet);
1402 dhd_bus_stop(dhd->pub.bus, true);
1406 void dhd_sched_dpc(dhd_pub_t *dhdp)
1408 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1415 tasklet_schedule(&dhd->tasklet);
1419 /* Retrieve current toe component enables, which are kept
1420 as a bitmap in toe_ol iovar */
1421 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1427 memset(&ioc, 0, sizeof(ioc));
1429 ioc.cmd = WLC_GET_VAR;
1431 ioc.len = (uint) sizeof(buf);
1434 strcpy(buf, "toe_ol");
1435 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1437 /* Check for older dongle image that doesn't support toe_ol */
1439 DHD_ERROR(("%s: toe not supported by device\n",
1440 dhd_ifname(&dhd->pub, ifidx)));
1444 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1445 dhd_ifname(&dhd->pub, ifidx), ret));
1449 memcpy(toe_ol, buf, sizeof(u32));
1453 /* Set current toe component enables in toe_ol iovar,
1454 and set toe global enable iovar */
1455 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1461 memset(&ioc, 0, sizeof(ioc));
1463 ioc.cmd = WLC_SET_VAR;
1465 ioc.len = (uint) sizeof(buf);
1468 /* Set toe_ol as requested */
1470 strcpy(buf, "toe_ol");
1471 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1473 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1475 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1476 dhd_ifname(&dhd->pub, ifidx), ret));
1480 /* Enable toe globally only if any components are enabled. */
1482 toe = (toe_ol != 0);
1485 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1487 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1489 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1490 dhd_ifname(&dhd->pub, ifidx), ret));
1498 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1499 struct ethtool_drvinfo *info)
1501 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1503 sprintf(info->driver, DRV_MODULE_NAME);
1504 sprintf(info->version, "%lu", dhd->pub.drv_version);
1505 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1506 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1509 struct ethtool_ops dhd_ethtool_ops = {
1510 .get_drvinfo = dhd_ethtool_get_drvinfo
1513 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1515 struct ethtool_drvinfo info;
1516 char drvname[sizeof(info.driver)];
1519 struct ethtool_value edata;
1520 u32 toe_cmpnt, csum_dir;
1524 DHD_TRACE(("%s: Enter\n", __func__));
1526 /* all ethtool calls start with a cmd word */
1527 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1531 case ETHTOOL_GDRVINFO:
1532 /* Copy out any request driver name */
1533 if (copy_from_user(&info, uaddr, sizeof(info)))
1535 strncpy(drvname, info.driver, sizeof(info.driver));
1536 drvname[sizeof(info.driver) - 1] = '\0';
1538 /* clear struct for return */
1539 memset(&info, 0, sizeof(info));
1542 /* if dhd requested, identify ourselves */
1543 if (strcmp(drvname, "?dhd") == 0) {
1544 sprintf(info.driver, "dhd");
1545 strcpy(info.version, EPI_VERSION_STR);
1548 /* otherwise, require dongle to be up */
1549 else if (!dhd->pub.up) {
1550 DHD_ERROR(("%s: dongle is not up\n", __func__));
1554 /* finally, report dongle driver type */
1555 else if (dhd->pub.iswl)
1556 sprintf(info.driver, "wl");
1558 sprintf(info.driver, "xx");
1560 sprintf(info.version, "%lu", dhd->pub.drv_version);
1561 if (copy_to_user(uaddr, &info, sizeof(info)))
1563 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1564 (int)sizeof(drvname), drvname, info.driver));
1568 /* Get toe offload components from dongle */
1569 case ETHTOOL_GRXCSUM:
1570 case ETHTOOL_GTXCSUM:
1571 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1576 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1579 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1581 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1585 /* Set toe offload components in dongle */
1586 case ETHTOOL_SRXCSUM:
1587 case ETHTOOL_STXCSUM:
1588 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1591 /* Read the current settings, update and write back */
1592 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1597 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1599 if (edata.data != 0)
1600 toe_cmpnt |= csum_dir;
1602 toe_cmpnt &= ~csum_dir;
1604 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1608 /* If setting TX checksum mode, tell Linux the new mode */
1609 if (cmd == ETHTOOL_STXCSUM) {
1611 dhd->iflist[0]->net->features |=
1614 dhd->iflist[0]->net->features &=
1628 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1630 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1637 bool is_set_key_cmd;
1639 ifidx = dhd_net2idx(dhd, net);
1640 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1642 if (ifidx == DHD_BAD_IF)
1645 #if defined(CONFIG_WIRELESS_EXT)
1646 /* linux wireless extensions */
1647 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1648 /* may recurse, do NOT lock */
1649 return wl_iw_ioctl(net, ifr, cmd);
1651 #endif /* defined(CONFIG_WIRELESS_EXT) */
1653 if (cmd == SIOCETHTOOL)
1654 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1656 if (cmd != SIOCDEVPRIVATE)
1659 memset(&ioc, 0, sizeof(ioc));
1661 /* Copy the ioc control structure part of ioctl request */
1662 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1663 bcmerror = -BCME_BADADDR;
1667 /* Copy out any buffer passed */
1669 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1670 /* optimization for direct ioctl calls from kernel */
1672 if (segment_eq(get_fs(), KERNEL_DS)) {
1677 buf = kmalloc(buflen, GFP_ATOMIC);
1679 bcmerror = -BCME_NOMEM;
1682 if (copy_from_user(buf, ioc.buf, buflen)) {
1683 bcmerror = -BCME_BADADDR;
1689 /* To differentiate between wl and dhd read 4 more byes */
1690 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1691 sizeof(uint)) != 0)) {
1692 bcmerror = -BCME_BADADDR;
1696 if (!capable(CAP_NET_ADMIN)) {
1697 bcmerror = -BCME_EPERM;
1701 /* check for local dhd ioctl and handle it */
1702 if (driver == DHD_IOCTL_MAGIC) {
1703 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1705 dhd->pub.bcmerror = bcmerror;
1709 /* send to dongle (must be up, and wl) */
1710 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1711 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1712 bcmerror = BCME_DONGLE_DOWN;
1716 if (!dhd->pub.iswl) {
1717 bcmerror = BCME_DONGLE_DOWN;
1721 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1722 * prevent M4 encryption.
1724 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1725 ((ioc.cmd == WLC_SET_VAR) &&
1726 !(strncmp("wsec_key", ioc.buf, 9))) ||
1727 ((ioc.cmd == WLC_SET_VAR) &&
1728 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1730 dhd_wait_pend8021x(net);
1732 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1733 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1736 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1738 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1739 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1741 if (!bcmerror && buf && ioc.buf) {
1742 if (copy_to_user(ioc.buf, buf, buflen))
1749 return OSL_ERROR(bcmerror);
1752 static int dhd_stop(struct net_device *net)
1754 #if !defined(IGNORE_ETH0_DOWN)
1755 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1757 DHD_TRACE(("%s: Enter\n", __func__));
1758 if (IS_CFG80211_FAVORITE()) {
1761 if (dhd->pub.up == 0)
1764 /* Set state and stop OS transmissions */
1766 netif_stop_queue(net);
1768 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1770 #endif /* !defined(IGNORE_ETH0_DOWN) */
1775 static int dhd_open(struct net_device *net)
1777 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1781 int ifidx = dhd_net2idx(dhd, net);
1784 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1786 if (ifidx == 0) { /* do it only for primary eth0 */
1788 /* try to bring up bus */
1789 ret = dhd_bus_start(&dhd->pub);
1791 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1794 atomic_set(&dhd->pend_8021x_cnt, 0);
1796 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1799 /* Get current TOE mode from dongle */
1800 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1801 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1802 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1804 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1807 /* Allow transmit calls */
1808 netif_start_queue(net);
1810 if (IS_CFG80211_FAVORITE()) {
1811 if (unlikely(wl_cfg80211_up())) {
1812 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1821 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1823 return osl_attach(pdev, bustype, true);
1826 void dhd_osl_detach(osl_t *osh)
1832 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1833 u8 *mac_addr, u32 flags, u8 bssidx)
1837 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1839 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1841 ifp = dhd->iflist[ifidx];
1842 if (!ifp && !(ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC))) {
1843 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1847 memset(ifp, 0, sizeof(dhd_if_t));
1849 dhd->iflist[ifidx] = ifp;
1850 strlcpy(ifp->name, name, IFNAMSIZ);
1851 if (mac_addr != NULL)
1852 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1854 if (handle == NULL) {
1855 ifp->state = WLC_E_IF_ADD;
1857 ASSERT(dhd->sysioc_tsk);
1858 up(&dhd->sysioc_sem);
1860 ifp->net = (struct net_device *)handle;
1865 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1869 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1871 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1872 ifp = dhd->iflist[ifidx];
1874 DHD_ERROR(("%s: Null interface\n", __func__));
1878 ifp->state = WLC_E_IF_DEL;
1880 ASSERT(dhd->sysioc_tsk);
1881 up(&dhd->sysioc_sem);
1884 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1886 dhd_info_t *dhd = NULL;
1887 struct net_device *net;
1889 DHD_TRACE(("%s: Enter\n", __func__));
1890 /* updates firmware nvram path if it was provided as module
1892 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1893 strcpy(fw_path, firmware_path);
1894 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1895 strcpy(nv_path, nvram_path);
1897 /* Allocate etherdev, including space for private structure */
1898 net = alloc_etherdev(sizeof(dhd));
1900 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1904 /* Allocate primary dhd_info */
1905 dhd = kmalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1907 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1911 memset(dhd, 0, sizeof(dhd_info_t));
1914 * Save the dhd_info into the priv
1916 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1919 /* Set network interface name if it was provided as module parameter */
1920 if (iface_name[0]) {
1923 strncpy(net->name, iface_name, IFNAMSIZ);
1924 net->name[IFNAMSIZ - 1] = 0;
1925 len = strlen(net->name);
1926 ch = net->name[len - 1];
1927 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1928 strcat(net->name, "%d");
1931 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1935 net->netdev_ops = NULL;
1936 init_MUTEX(&dhd->proto_sem);
1937 /* Initialize other structure content */
1938 init_waitqueue_head(&dhd->ioctl_resp_wait);
1939 init_waitqueue_head(&dhd->ctrl_wait);
1941 /* Initialize the spinlocks */
1942 spin_lock_init(&dhd->sdlock);
1943 spin_lock_init(&dhd->txqlock);
1945 /* Link to info module */
1946 dhd->pub.info = dhd;
1948 /* Link to bus module */
1950 dhd->pub.hdrlen = bus_hdrlen;
1952 /* Attach and link in the protocol */
1953 if (dhd_prot_attach(&dhd->pub) != 0) {
1954 DHD_ERROR(("dhd_prot_attach failed\n"));
1957 #if defined(CONFIG_WIRELESS_EXT)
1958 /* Attach and link in the iw */
1959 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1960 DHD_ERROR(("wl_iw_attach failed\n"));
1963 #endif /* defined(CONFIG_WIRELESS_EXT) */
1965 /* Attach and link in the cfg80211 */
1966 if (IS_CFG80211_FAVORITE()) {
1967 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1968 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1972 strcpy(fw_path, wl_cfg80211_get_fwname());
1973 strcpy(nv_path, wl_cfg80211_get_nvramname());
1975 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
1978 /* Set up the watchdog timer */
1979 init_timer(&dhd->timer);
1980 dhd->timer.data = (unsigned long) dhd;
1981 dhd->timer.function = dhd_watchdog;
1983 /* Initialize thread based operation and lock */
1984 init_MUTEX(&dhd->sdsem);
1985 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1986 dhd->threads_only = true;
1988 dhd->threads_only = false;
1990 if (dhd_dpc_prio >= 0) {
1991 /* Initialize watchdog thread */
1992 sema_init(&dhd->watchdog_sem, 0);
1993 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1995 if (IS_ERR(dhd->watchdog_tsk)) {
1997 "dhd_watchdog thread failed to start\n");
1998 dhd->watchdog_tsk = NULL;
2001 dhd->watchdog_tsk = NULL;
2004 /* Set up the bottom half handler */
2005 if (dhd_dpc_prio >= 0) {
2006 /* Initialize DPC thread */
2007 sema_init(&dhd->dpc_sem, 0);
2008 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
2009 if (IS_ERR(dhd->dpc_tsk)) {
2011 "dhd_dpc thread failed to start\n");
2012 dhd->dpc_tsk = NULL;
2015 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2016 dhd->dpc_tsk = NULL;
2020 sema_init(&dhd->sysioc_sem, 0);
2021 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
2023 if (IS_ERR(dhd->sysioc_tsk)) {
2025 "_dhd_sysioc thread failed to start\n");
2026 dhd->sysioc_tsk = NULL;
2029 dhd->sysioc_tsk = NULL;
2032 * Save the dhd_info into the priv
2034 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2036 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2039 #if defined(CONFIG_PM_SLEEP)
2040 register_pm_notifier(&dhd_sleep_pm_notifier);
2041 #endif /* defined(CONFIG_PM_SLEEP) */
2042 /* && defined(DHD_GPL) */
2043 /* Init lock suspend to prevent kernel going to suspend */
2044 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2045 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2046 "dhd_wake_lock_link_dw_event");
2047 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2048 "dhd_wake_lock_link_pno_find_event");
2049 #ifdef CONFIG_HAS_EARLYSUSPEND
2050 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2051 dhd->early_suspend.suspend = dhd_early_suspend;
2052 dhd->early_suspend.resume = dhd_late_resume;
2053 register_early_suspend(&dhd->early_suspend);
2062 dhd_detach(&dhd->pub);
2067 int dhd_bus_start(dhd_pub_t *dhdp)
2070 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2071 #ifdef EMBEDDED_PLATFORM
2072 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2074 #endif /* EMBEDDED_PLATFORM */
2078 DHD_TRACE(("%s:\n", __func__));
2080 /* try to download image and nvram to the dongle */
2081 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2082 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2083 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2084 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2085 fw_path, nv_path))) {
2086 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2087 "firmware = %s nvram = %s\n",
2088 __func__, fw_path, nv_path));
2089 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2090 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2094 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2095 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2098 /* Start the watchdog timer */
2099 dhd->pub.tickcnt = 0;
2100 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2102 /* Bring up the bus */
2103 ret = dhd_bus_init(&dhd->pub, true);
2105 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2108 #if defined(OOB_INTR_ONLY)
2109 /* Host registration for OOB interrupt */
2110 if (bcmsdh_register_oob_intr(dhdp)) {
2111 del_timer_sync(&dhd->timer);
2112 dhd->wd_timer_valid = false;
2113 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2117 /* Enable oob at firmware */
2118 dhd_enable_oob_intr(dhd->pub.bus, true);
2119 #endif /* defined(OOB_INTR_ONLY) */
2121 /* If bus is not ready, can't come up */
2122 if (dhd->pub.busstate != DHD_BUS_DATA) {
2123 del_timer_sync(&dhd->timer);
2124 dhd->wd_timer_valid = false;
2125 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2128 #ifdef EMBEDDED_PLATFORM
2129 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2131 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2132 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2134 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2135 setbit(dhdp->eventmask, WLC_E_PRUNE);
2136 setbit(dhdp->eventmask, WLC_E_AUTH);
2137 setbit(dhdp->eventmask, WLC_E_REASSOC);
2138 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2139 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2140 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2141 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2142 setbit(dhdp->eventmask, WLC_E_JOIN);
2143 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2144 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2145 setbit(dhdp->eventmask, WLC_E_LINK);
2146 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2147 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2148 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2149 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2150 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2151 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2153 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2154 #endif /* PNO_SUPPORT */
2156 /* enable dongle roaming event */
2158 dhdp->pktfilter_count = 1;
2159 /* Setup filter to allow only unicast */
2160 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2161 #endif /* EMBEDDED_PLATFORM */
2163 /* Bus is ready, do any protocol initialization */
2164 ret = dhd_prot_init(&dhd->pub);
2172 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2175 char buf[strlen(name) + 1 + cmd_len];
2176 int len = sizeof(buf);
2180 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2182 memset(&ioc, 0, sizeof(ioc));
2184 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2189 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2190 if (!set && ret >= 0)
2191 memcpy(cmd_buf, buf, cmd_len);
2196 static struct net_device_ops dhd_ops_pri = {
2197 .ndo_open = dhd_open,
2198 .ndo_stop = dhd_stop,
2199 .ndo_get_stats = dhd_get_stats,
2200 .ndo_do_ioctl = dhd_ioctl_entry,
2201 .ndo_start_xmit = dhd_start_xmit,
2202 .ndo_set_mac_address = dhd_set_mac_address,
2203 .ndo_set_multicast_list = dhd_set_multicast_list
2206 static struct net_device_ops dhd_ops_virt = {
2207 .ndo_get_stats = dhd_get_stats,
2208 .ndo_do_ioctl = dhd_ioctl_entry,
2209 .ndo_start_xmit = dhd_start_xmit,
2210 .ndo_set_mac_address = dhd_set_mac_address,
2211 .ndo_set_multicast_list = dhd_set_multicast_list
2214 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2216 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2217 struct net_device *net;
2218 u8 temp_addr[ETHER_ADDR_LEN] = {
2219 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2221 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2223 ASSERT(dhd && dhd->iflist[ifidx]);
2225 net = dhd->iflist[ifidx]->net;
2228 ASSERT(!net->netdev_ops);
2229 net->netdev_ops = &dhd_ops_virt;
2231 net->netdev_ops = &dhd_ops_pri;
2234 * We have to use the primary MAC for virtual interfaces
2237 /* for virtual interfaces use the primary MAC */
2238 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2243 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2244 /* ACCESSPOINT INTERFACE CASE */
2245 temp_addr[0] |= 0X02; /* set bit 2 ,
2246 - Locally Administered address */
2249 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2250 net->ethtool_ops = &dhd_ethtool_ops;
2252 #if defined(CONFIG_WIRELESS_EXT)
2253 if (!IS_CFG80211_FAVORITE()) {
2254 #if WIRELESS_EXT < 19
2255 net->get_wireless_stats = dhd_get_wireless_stats;
2256 #endif /* WIRELESS_EXT < 19 */
2257 #if WIRELESS_EXT > 12
2258 net->wireless_handlers =
2259 (struct iw_handler_def *)&wl_iw_handler_def;
2260 #endif /* WIRELESS_EXT > 12 */
2262 #endif /* defined(CONFIG_WIRELESS_EXT) */
2264 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2266 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2268 if (register_netdev(net) != 0) {
2269 DHD_ERROR(("%s: couldn't register the net device\n",
2274 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2279 net->netdev_ops = NULL;
2283 void dhd_bus_detach(dhd_pub_t *dhdp)
2287 DHD_TRACE(("%s: Enter\n", __func__));
2290 dhd = (dhd_info_t *) dhdp->info;
2292 /* Stop the protocol module */
2293 dhd_prot_stop(&dhd->pub);
2295 /* Stop the bus module */
2296 dhd_bus_stop(dhd->pub.bus, true);
2297 #if defined(OOB_INTR_ONLY)
2298 bcmsdh_unregister_oob_intr();
2299 #endif /* defined(OOB_INTR_ONLY) */
2301 /* Clear the watchdog timer */
2302 del_timer_sync(&dhd->timer);
2303 dhd->wd_timer_valid = false;
2308 void dhd_detach(dhd_pub_t *dhdp)
2312 DHD_TRACE(("%s: Enter\n", __func__));
2315 dhd = (dhd_info_t *) dhdp->info;
2320 #if defined(CONFIG_HAS_EARLYSUSPEND)
2321 if (dhd->early_suspend.suspend)
2322 unregister_early_suspend(&dhd->early_suspend);
2323 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2325 for (i = 1; i < DHD_MAX_IFS; i++)
2329 ifp = dhd->iflist[0];
2331 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2333 unregister_netdev(ifp->net);
2336 if (dhd->watchdog_tsk) {
2337 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2338 kthread_stop(dhd->watchdog_tsk);
2339 dhd->watchdog_tsk = NULL;
2343 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2344 kthread_stop(dhd->dpc_tsk);
2345 dhd->dpc_tsk = NULL;
2347 tasklet_kill(&dhd->tasklet);
2349 if (dhd->sysioc_tsk) {
2350 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2351 kthread_stop(dhd->sysioc_tsk);
2352 dhd->sysioc_tsk = NULL;
2355 dhd_bus_detach(dhdp);
2358 dhd_prot_detach(dhdp);
2360 #if defined(CONFIG_WIRELESS_EXT)
2362 #endif /* (CONFIG_WIRELESS_EXT) */
2364 if (IS_CFG80211_FAVORITE())
2365 wl_cfg80211_detach();
2367 #if defined(CONFIG_PM_SLEEP)
2368 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2369 #endif /* defined(CONFIG_PM_SLEEP) */
2370 /* && defined(DHD_GPL) */
2371 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2372 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2373 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2374 free_netdev(ifp->net);
2381 static void __exit dhd_module_cleanup(void)
2383 DHD_TRACE(("%s: Enter\n", __func__));
2385 dhd_bus_unregister();
2386 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2389 /* Call customer gpio to turn off power with WL_REG_ON signal */
2390 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2393 static int __init dhd_module_init(void)
2397 DHD_TRACE(("%s: Enter\n", __func__));
2399 /* Sanity check on the module parameters */
2401 /* Both watchdog and DPC as tasklets are ok */
2402 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2405 /* If both watchdog and DPC are threads, TX must be deferred */
2406 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2410 DHD_ERROR(("Invalid module parameters.\n"));
2413 /* Call customer gpio to turn on power with WL_REG_ON signal */
2414 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2416 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2417 sema_init(&wifi_control_sem, 0);
2419 error = wifi_add_dev();
2421 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2425 /* Waiting callback after platform_driver_register is done or
2427 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2428 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2434 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2436 error = dhd_bus_register();
2439 printf("\n%s\n", dhd_version);
2441 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2447 /* turn off power and exit */
2448 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2452 module_init(dhd_module_init);
2453 module_exit(dhd_module_cleanup);
2456 * OS specific functions required to implement DHD driver in OS independent way
2458 int dhd_os_proto_block(dhd_pub_t *pub)
2460 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2463 down(&dhd->proto_sem);
2469 int dhd_os_proto_unblock(dhd_pub_t *pub)
2471 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2474 up(&dhd->proto_sem);
2481 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2483 return (unsigned int)dhd_ioctl_timeout_msec;
2486 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2488 dhd_ioctl_timeout_msec = (int)timeout_msec;
2491 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2493 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2494 DECLARE_WAITQUEUE(wait, current);
2495 int timeout = dhd_ioctl_timeout_msec;
2497 /* Convert timeout in millsecond to jiffies */
2498 timeout = timeout * HZ / 1000;
2500 /* Wait until control frame is available */
2501 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2502 set_current_state(TASK_INTERRUPTIBLE);
2504 while (!(*condition) && (!signal_pending(current) && timeout))
2505 timeout = schedule_timeout(timeout);
2507 if (signal_pending(current))
2510 set_current_state(TASK_RUNNING);
2511 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2516 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2518 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2520 if (waitqueue_active(&dhd->ioctl_resp_wait))
2521 wake_up_interruptible(&dhd->ioctl_resp_wait);
2526 void dhd_os_wd_timer(void *bus, uint wdtick)
2528 dhd_pub_t *pub = bus;
2529 static uint save_dhd_watchdog_ms;
2530 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2532 /* don't start the wd until fw is loaded */
2533 if (pub->busstate == DHD_BUS_DOWN)
2536 /* Totally stop the timer */
2537 if (!wdtick && dhd->wd_timer_valid == true) {
2538 del_timer_sync(&dhd->timer);
2539 dhd->wd_timer_valid = false;
2540 save_dhd_watchdog_ms = wdtick;
2545 dhd_watchdog_ms = (uint) wdtick;
2547 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2549 if (dhd->wd_timer_valid == true)
2550 /* Stop timer and restart at new value */
2551 del_timer_sync(&dhd->timer);
2553 /* Create timer again when watchdog period is
2554 dynamically changed or in the first instance
2556 dhd->timer.expires =
2557 jiffies + dhd_watchdog_ms * HZ / 1000;
2558 add_timer(&dhd->timer);
2561 /* Re arm the timer, at last watchdog period */
2562 mod_timer(&dhd->timer,
2563 jiffies + dhd_watchdog_ms * HZ / 1000);
2566 dhd->wd_timer_valid = true;
2567 save_dhd_watchdog_ms = wdtick;
2571 void *dhd_os_open_image(char *filename)
2575 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2576 return wl_cfg80211_request_fw(filename);
2578 fp = filp_open(filename, O_RDONLY, 0);
2580 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2582 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2591 int dhd_os_get_image_block(char *buf, int len, void *image)
2593 struct file *fp = (struct file *)image;
2596 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2597 return wl_cfg80211_read_fw(buf, len);
2602 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2609 void dhd_os_close_image(void *image)
2611 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2612 return wl_cfg80211_release_fw();
2614 filp_close((struct file *)image, NULL);
2617 void dhd_os_sdlock(dhd_pub_t *pub)
2621 dhd = (dhd_info_t *) (pub->info);
2623 if (dhd->threads_only)
2626 spin_lock_bh(&dhd->sdlock);
2629 void dhd_os_sdunlock(dhd_pub_t *pub)
2633 dhd = (dhd_info_t *) (pub->info);
2635 if (dhd->threads_only)
2638 spin_unlock_bh(&dhd->sdlock);
2641 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2645 dhd = (dhd_info_t *) (pub->info);
2646 spin_lock_bh(&dhd->txqlock);
2649 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2653 dhd = (dhd_info_t *) (pub->info);
2654 spin_unlock_bh(&dhd->txqlock);
2657 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2661 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2665 void dhd_os_sdtxlock(dhd_pub_t *pub)
2670 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2672 dhd_os_sdunlock(pub);
2675 #if defined(CONFIG_WIRELESS_EXT)
2676 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2679 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2681 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2684 return &dhd->iw.wstats;
2688 #endif /* defined(CONFIG_WIRELESS_EXT) */
2691 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2692 wl_event_msg_t *event, void **data)
2696 ASSERT(dhd != NULL);
2698 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2699 if (bcmerror != BCME_OK)
2702 #if defined(CONFIG_WIRELESS_EXT)
2703 if (!IS_CFG80211_FAVORITE()) {
2704 if ((dhd->iflist[*ifidx] == NULL)
2705 || (dhd->iflist[*ifidx]->net == NULL)) {
2706 DHD_ERROR(("%s Exit null pointer\n", __func__));
2710 if (dhd->iflist[*ifidx]->net)
2711 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2713 #endif /* defined(CONFIG_WIRELESS_EXT) */
2715 if (IS_CFG80211_FAVORITE()) {
2716 ASSERT(dhd->iflist[*ifidx] != NULL);
2717 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2718 if (dhd->iflist[*ifidx]->net)
2719 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2726 /* send up locally generated event */
2727 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2729 switch (ntoh32(event->event_type)) {
2735 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2737 struct dhd_info *dhdinfo = dhd->info;
2738 dhd_os_sdunlock(dhd);
2739 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2740 (*lockvar == false), HZ * 2);
2745 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2747 struct dhd_info *dhdinfo = dhd->info;
2748 if (waitqueue_active(&dhdinfo->ctrl_wait))
2749 wake_up_interruptible(&dhdinfo->ctrl_wait);
2753 int dhd_dev_reset(struct net_device *dev, u8 flag)
2755 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2757 /* Turning off watchdog */
2759 dhd_os_wd_timer(&dhd->pub, 0);
2761 dhd_bus_devreset(&dhd->pub, flag);
2763 /* Turning on watchdog back */
2765 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2766 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2771 int net_os_set_suspend_disable(struct net_device *dev, int val)
2773 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2777 ret = dhd->pub.suspend_disable_flag;
2778 dhd->pub.suspend_disable_flag = val;
2783 int net_os_set_suspend(struct net_device *dev, int val)
2786 #if defined(CONFIG_HAS_EARLYSUSPEND)
2787 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2790 dhd_os_proto_block(&dhd->pub);
2791 ret = dhd_set_suspend(val, &dhd->pub);
2792 dhd_os_proto_unblock(&dhd->pub);
2794 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2798 int net_os_set_dtim_skip(struct net_device *dev, int val)
2800 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2803 dhd->pub.dtim_skip = val;
2808 int net_os_set_packet_filter(struct net_device *dev, int val)
2810 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2813 /* Packet filtering is set only if we still in early-suspend and
2814 * we need either to turn it ON or turn it OFF
2815 * We can always turn it OFF in case of early-suspend, but we turn it
2816 * back ON only if suspend_disable_flag was not set
2818 if (dhd && dhd->pub.up) {
2819 dhd_os_proto_block(&dhd->pub);
2820 if (dhd->pub.in_suspend) {
2821 if (!val || (val && !dhd->pub.suspend_disable_flag))
2822 dhd_set_packet_filter(val, &dhd->pub);
2824 dhd_os_proto_unblock(&dhd->pub);
2829 void dhd_dev_init_ioctl(struct net_device *dev)
2831 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2833 dhd_preinit_ioctls(&dhd->pub);
2837 /* Linux wrapper to call common dhd_pno_clean */
2838 int dhd_dev_pno_reset(struct net_device *dev)
2840 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2842 return dhd_pno_clean(&dhd->pub);
2845 /* Linux wrapper to call common dhd_pno_enable */
2846 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2848 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2850 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2853 /* Linux wrapper to call common dhd_pno_set */
2855 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2856 unsigned char scan_fr)
2858 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2860 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2863 /* Linux wrapper to get pno status */
2864 int dhd_dev_get_pno_status(struct net_device *dev)
2866 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2868 return dhd_pno_get_status(&dhd->pub);
2871 #endif /* PNO_SUPPORT */
2873 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2875 return atomic_read(&dhd->pend_8021x_cnt);
2878 #define MAX_WAIT_FOR_8021X_TX 10
2880 int dhd_wait_pend8021x(struct net_device *dev)
2882 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2883 int timeout = 10 * HZ / 1000;
2884 int ntimes = MAX_WAIT_FOR_8021X_TX;
2885 int pend = dhd_get_pend_8021x_cnt(dhd);
2887 while (ntimes && pend) {
2889 set_current_state(TASK_INTERRUPTIBLE);
2890 schedule_timeout(timeout);
2891 set_current_state(TASK_RUNNING);
2894 pend = dhd_get_pend_8021x_cnt(dhd);
2900 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2904 mm_segment_t old_fs;
2907 /* change to KERNEL_DS address limit */
2911 /* open file to write */
2912 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2914 printf("%s: open file error\n", __func__);
2919 /* Write buf to file */
2920 fp->f_op->write(fp, buf, size, &pos);
2923 /* free buf before return */
2925 /* close file before return */
2927 filp_close(fp, current->files);
2928 /* restore previous address limit */
2933 #endif /* DHD_DEBUG */