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 /* If the protocol uses a data header, apply it */
1043 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1045 /* Use bus module to send data frame */
1047 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1049 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1050 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1051 #endif /* BCMDBUS */
1056 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1060 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1063 DHD_TRACE(("%s: Enter\n", __func__));
1065 /* Reject if down */
1066 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1067 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1068 __func__, dhd->pub.up, dhd->pub.busstate));
1069 netif_stop_queue(net);
1073 ifidx = dhd_net2idx(dhd, net);
1074 if (ifidx == DHD_BAD_IF) {
1075 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1076 netif_stop_queue(net);
1080 /* Make sure there's enough room for any header */
1081 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1082 struct sk_buff *skb2;
1084 DHD_INFO(("%s: insufficient headroom\n",
1085 dhd_ifname(&dhd->pub, ifidx)));
1086 dhd->pub.tx_realloc++;
1087 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1091 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1092 dhd_ifname(&dhd->pub, ifidx)));
1098 /* Convert to packet */
1099 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1101 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1102 dhd_ifname(&dhd->pub, ifidx)));
1103 dev_kfree_skb_any(skb);
1108 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1112 dhd->pub.dstats.tx_dropped++;
1114 dhd->pub.tx_packets++;
1116 /* Return ok: we always eat the packet */
1120 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1122 struct net_device *net;
1123 dhd_info_t *dhd = dhdp->info;
1125 DHD_TRACE(("%s: Enter\n", __func__));
1127 dhdp->txoff = state;
1128 ASSERT(dhd && dhd->iflist[ifidx]);
1129 net = dhd->iflist[ifidx]->net;
1131 netif_stop_queue(net);
1133 netif_wake_queue(net);
1136 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1138 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1139 struct sk_buff *skb;
1142 void *data, *pnext, *save_pktbuf;
1145 wl_event_msg_t event;
1147 DHD_TRACE(("%s: Enter\n", __func__));
1149 save_pktbuf = pktbuf;
1151 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1153 pnext = PKTNEXT(pktbuf);
1154 PKTSETNEXT(pktbuf, NULL);
1156 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1158 /* Get the protocol, maintain skb around eth_type_trans()
1159 * The main reason for this hack is for the limitation of
1160 * Linux 2.4 where 'eth_type_trans' uses the
1161 * 'net->hard_header_len'
1162 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1163 * coping of the packet coming from the network stack to add
1164 * BDC, Hardware header etc, during network interface
1166 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1168 * for BDC, Hardware header etc. and not just the ETH_HLEN
1173 ifp = dhd->iflist[ifidx];
1175 ifp = dhd->iflist[0];
1178 skb->dev = ifp->net;
1179 skb->protocol = eth_type_trans(skb, skb->dev);
1181 if (skb->pkt_type == PACKET_MULTICAST)
1182 dhd->pub.rx_multicast++;
1187 /* Strip header, count, deliver upward */
1188 skb_pull(skb, ETH_HLEN);
1190 /* Process special event packets and then discard them */
1191 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1192 dhd_wl_host_event(dhd, &ifidx,
1196 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1197 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1198 ifp = dhd->iflist[ifidx];
1201 ifp->net->last_rx = jiffies;
1203 dhdp->dstats.rx_bytes += skb->len;
1204 dhdp->rx_packets++; /* Local count */
1206 if (in_interrupt()) {
1209 /* If the receive is not processed inside an ISR,
1210 * the softirqd must be woken explicitly to service
1211 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1212 * by netif_rx_ni(), but in earlier kernels, we need
1213 * to do it manually.
1220 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1222 /* Linux version has nothing to do */
1226 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1229 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1230 struct ether_header *eh;
1233 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1235 eh = (struct ether_header *)PKTDATA(txp);
1236 type = ntoh16(eh->ether_type);
1238 if (type == ETHER_TYPE_802_1X)
1239 atomic_dec(&dhd->pend_8021x_cnt);
1243 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1245 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1249 DHD_TRACE(("%s: Enter\n", __func__));
1251 ifidx = dhd_net2idx(dhd, net);
1252 if (ifidx == DHD_BAD_IF)
1255 ifp = dhd->iflist[ifidx];
1259 /* Use the protocol to get dongle stats */
1260 dhd_prot_dstats(&dhd->pub);
1263 /* Copy dongle stats to net device stats */
1264 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1265 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1266 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1267 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1268 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1269 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1270 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1271 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1272 ifp->stats.multicast = dhd->pub.dstats.multicast;
1277 static int dhd_watchdog_thread(void *data)
1279 dhd_info_t *dhd = (dhd_info_t *) data;
1280 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1282 /* This thread doesn't need any user-level access,
1283 * so get rid of all our resources
1286 if (dhd_watchdog_prio > 0) {
1287 struct sched_param param;
1288 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1289 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1290 setScheduler(current, SCHED_FIFO, ¶m);
1292 #endif /* DHD_SCHED */
1294 allow_signal(SIGTERM);
1295 /* Run until signal received */
1297 if (kthread_should_stop())
1299 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1300 if (dhd->pub.dongle_reset == false) {
1301 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1302 /* Call the bus module watchdog */
1303 dhd_bus_watchdog(&dhd->pub);
1304 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1306 /* Count the tick for reference */
1312 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1316 static void dhd_watchdog(unsigned long data)
1318 dhd_info_t *dhd = (dhd_info_t *) data;
1320 if (dhd->watchdog_tsk) {
1321 up(&dhd->watchdog_sem);
1323 /* Reschedule the watchdog */
1324 if (dhd->wd_timer_valid) {
1325 mod_timer(&dhd->timer,
1326 jiffies + dhd_watchdog_ms * HZ / 1000);
1331 /* Call the bus module watchdog */
1332 dhd_bus_watchdog(&dhd->pub);
1334 /* Count the tick for reference */
1337 /* Reschedule the watchdog */
1338 if (dhd->wd_timer_valid)
1339 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1342 static int dhd_dpc_thread(void *data)
1344 dhd_info_t *dhd = (dhd_info_t *) data;
1346 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1347 /* This thread doesn't need any user-level access,
1348 * so get rid of all our resources
1351 if (dhd_dpc_prio > 0) {
1352 struct sched_param param;
1353 param.sched_priority =
1355 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1356 setScheduler(current, SCHED_FIFO, ¶m);
1358 #endif /* DHD_SCHED */
1360 allow_signal(SIGTERM);
1361 /* Run until signal received */
1363 if (kthread_should_stop())
1365 if (down_interruptible(&dhd->dpc_sem) == 0) {
1366 /* Call bus dpc unless it indicated down
1367 (then clean stop) */
1368 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1369 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1370 if (dhd_bus_dpc(dhd->pub.bus)) {
1372 WAKE_LOCK_TIMEOUT(&dhd->pub,
1373 WAKE_LOCK_TMOUT, 25);
1375 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1377 dhd_bus_stop(dhd->pub.bus, true);
1383 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1387 static void dhd_dpc(unsigned long data)
1391 dhd = (dhd_info_t *) data;
1393 /* Call bus dpc unless it indicated down (then clean stop) */
1394 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1395 if (dhd_bus_dpc(dhd->pub.bus))
1396 tasklet_schedule(&dhd->tasklet);
1398 dhd_bus_stop(dhd->pub.bus, true);
1402 void dhd_sched_dpc(dhd_pub_t *dhdp)
1404 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1411 tasklet_schedule(&dhd->tasklet);
1415 /* Retrieve current toe component enables, which are kept
1416 as a bitmap in toe_ol iovar */
1417 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1423 memset(&ioc, 0, sizeof(ioc));
1425 ioc.cmd = WLC_GET_VAR;
1427 ioc.len = (uint) sizeof(buf);
1430 strcpy(buf, "toe_ol");
1431 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1433 /* Check for older dongle image that doesn't support toe_ol */
1435 DHD_ERROR(("%s: toe not supported by device\n",
1436 dhd_ifname(&dhd->pub, ifidx)));
1440 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1441 dhd_ifname(&dhd->pub, ifidx), ret));
1445 memcpy(toe_ol, buf, sizeof(u32));
1449 /* Set current toe component enables in toe_ol iovar,
1450 and set toe global enable iovar */
1451 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1457 memset(&ioc, 0, sizeof(ioc));
1459 ioc.cmd = WLC_SET_VAR;
1461 ioc.len = (uint) sizeof(buf);
1464 /* Set toe_ol as requested */
1466 strcpy(buf, "toe_ol");
1467 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1469 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1471 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1472 dhd_ifname(&dhd->pub, ifidx), ret));
1476 /* Enable toe globally only if any components are enabled. */
1478 toe = (toe_ol != 0);
1481 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1483 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1485 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1486 dhd_ifname(&dhd->pub, ifidx), ret));
1494 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1495 struct ethtool_drvinfo *info)
1497 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1499 sprintf(info->driver, DRV_MODULE_NAME);
1500 sprintf(info->version, "%lu", dhd->pub.drv_version);
1501 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1502 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1505 struct ethtool_ops dhd_ethtool_ops = {
1506 .get_drvinfo = dhd_ethtool_get_drvinfo
1509 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1511 struct ethtool_drvinfo info;
1512 char drvname[sizeof(info.driver)];
1515 struct ethtool_value edata;
1516 u32 toe_cmpnt, csum_dir;
1520 DHD_TRACE(("%s: Enter\n", __func__));
1522 /* all ethtool calls start with a cmd word */
1523 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1527 case ETHTOOL_GDRVINFO:
1528 /* Copy out any request driver name */
1529 if (copy_from_user(&info, uaddr, sizeof(info)))
1531 strncpy(drvname, info.driver, sizeof(info.driver));
1532 drvname[sizeof(info.driver) - 1] = '\0';
1534 /* clear struct for return */
1535 memset(&info, 0, sizeof(info));
1538 /* if dhd requested, identify ourselves */
1539 if (strcmp(drvname, "?dhd") == 0) {
1540 sprintf(info.driver, "dhd");
1541 strcpy(info.version, EPI_VERSION_STR);
1544 /* otherwise, require dongle to be up */
1545 else if (!dhd->pub.up) {
1546 DHD_ERROR(("%s: dongle is not up\n", __func__));
1550 /* finally, report dongle driver type */
1551 else if (dhd->pub.iswl)
1552 sprintf(info.driver, "wl");
1554 sprintf(info.driver, "xx");
1556 sprintf(info.version, "%lu", dhd->pub.drv_version);
1557 if (copy_to_user(uaddr, &info, sizeof(info)))
1559 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1560 (int)sizeof(drvname), drvname, info.driver));
1564 /* Get toe offload components from dongle */
1565 case ETHTOOL_GRXCSUM:
1566 case ETHTOOL_GTXCSUM:
1567 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1572 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1575 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1577 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1581 /* Set toe offload components in dongle */
1582 case ETHTOOL_SRXCSUM:
1583 case ETHTOOL_STXCSUM:
1584 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1587 /* Read the current settings, update and write back */
1588 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1593 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1595 if (edata.data != 0)
1596 toe_cmpnt |= csum_dir;
1598 toe_cmpnt &= ~csum_dir;
1600 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1604 /* If setting TX checksum mode, tell Linux the new mode */
1605 if (cmd == ETHTOOL_STXCSUM) {
1607 dhd->iflist[0]->net->features |=
1610 dhd->iflist[0]->net->features &=
1624 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1626 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1633 bool is_set_key_cmd;
1635 ifidx = dhd_net2idx(dhd, net);
1636 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1638 if (ifidx == DHD_BAD_IF)
1641 #if defined(CONFIG_WIRELESS_EXT)
1642 /* linux wireless extensions */
1643 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1644 /* may recurse, do NOT lock */
1645 return wl_iw_ioctl(net, ifr, cmd);
1647 #endif /* defined(CONFIG_WIRELESS_EXT) */
1649 if (cmd == SIOCETHTOOL)
1650 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1652 if (cmd != SIOCDEVPRIVATE)
1655 memset(&ioc, 0, sizeof(ioc));
1657 /* Copy the ioc control structure part of ioctl request */
1658 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1659 bcmerror = -BCME_BADADDR;
1663 /* Copy out any buffer passed */
1665 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1666 /* optimization for direct ioctl calls from kernel */
1668 if (segment_eq(get_fs(), KERNEL_DS)) {
1673 buf = kmalloc(buflen, GFP_ATOMIC);
1675 bcmerror = -BCME_NOMEM;
1678 if (copy_from_user(buf, ioc.buf, buflen)) {
1679 bcmerror = -BCME_BADADDR;
1685 /* To differentiate between wl and dhd read 4 more byes */
1686 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1687 sizeof(uint)) != 0)) {
1688 bcmerror = -BCME_BADADDR;
1692 if (!capable(CAP_NET_ADMIN)) {
1693 bcmerror = -BCME_EPERM;
1697 /* check for local dhd ioctl and handle it */
1698 if (driver == DHD_IOCTL_MAGIC) {
1699 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1701 dhd->pub.bcmerror = bcmerror;
1705 /* send to dongle (must be up, and wl) */
1706 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1707 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1708 bcmerror = BCME_DONGLE_DOWN;
1712 if (!dhd->pub.iswl) {
1713 bcmerror = BCME_DONGLE_DOWN;
1717 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1718 * prevent M4 encryption.
1720 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1721 ((ioc.cmd == WLC_SET_VAR) &&
1722 !(strncmp("wsec_key", ioc.buf, 9))) ||
1723 ((ioc.cmd == WLC_SET_VAR) &&
1724 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1726 dhd_wait_pend8021x(net);
1728 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1729 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1732 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1734 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1735 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1737 if (!bcmerror && buf && ioc.buf) {
1738 if (copy_to_user(ioc.buf, buf, buflen))
1745 return OSL_ERROR(bcmerror);
1748 static int dhd_stop(struct net_device *net)
1750 #if !defined(IGNORE_ETH0_DOWN)
1751 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1753 DHD_TRACE(("%s: Enter\n", __func__));
1754 if (IS_CFG80211_FAVORITE()) {
1757 if (dhd->pub.up == 0)
1760 /* Set state and stop OS transmissions */
1762 netif_stop_queue(net);
1764 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1766 #endif /* !defined(IGNORE_ETH0_DOWN) */
1771 static int dhd_open(struct net_device *net)
1773 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1777 int ifidx = dhd_net2idx(dhd, net);
1780 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1782 if (ifidx == 0) { /* do it only for primary eth0 */
1784 /* try to bring up bus */
1785 ret = dhd_bus_start(&dhd->pub);
1787 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1790 atomic_set(&dhd->pend_8021x_cnt, 0);
1792 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1795 /* Get current TOE mode from dongle */
1796 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1797 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1798 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1800 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1803 /* Allow transmit calls */
1804 netif_start_queue(net);
1806 if (IS_CFG80211_FAVORITE()) {
1807 if (unlikely(wl_cfg80211_up())) {
1808 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1817 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1819 return osl_attach(pdev, bustype, true);
1822 void dhd_osl_detach(osl_t *osh)
1828 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1829 u8 *mac_addr, u32 flags, u8 bssidx)
1833 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1835 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1837 ifp = dhd->iflist[ifidx];
1838 if (!ifp && !(ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC))) {
1839 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1843 memset(ifp, 0, sizeof(dhd_if_t));
1845 dhd->iflist[ifidx] = ifp;
1846 strlcpy(ifp->name, name, IFNAMSIZ);
1847 if (mac_addr != NULL)
1848 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1850 if (handle == NULL) {
1851 ifp->state = WLC_E_IF_ADD;
1853 ASSERT(dhd->sysioc_tsk);
1854 up(&dhd->sysioc_sem);
1856 ifp->net = (struct net_device *)handle;
1861 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1865 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1867 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1868 ifp = dhd->iflist[ifidx];
1870 DHD_ERROR(("%s: Null interface\n", __func__));
1874 ifp->state = WLC_E_IF_DEL;
1876 ASSERT(dhd->sysioc_tsk);
1877 up(&dhd->sysioc_sem);
1880 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1882 dhd_info_t *dhd = NULL;
1883 struct net_device *net;
1885 DHD_TRACE(("%s: Enter\n", __func__));
1886 /* updates firmware nvram path if it was provided as module
1888 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1889 strcpy(fw_path, firmware_path);
1890 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1891 strcpy(nv_path, nvram_path);
1893 /* Allocate etherdev, including space for private structure */
1894 net = alloc_etherdev(sizeof(dhd));
1896 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1900 /* Allocate primary dhd_info */
1901 dhd = kmalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1903 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1907 memset(dhd, 0, sizeof(dhd_info_t));
1910 * Save the dhd_info into the priv
1912 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1915 /* Set network interface name if it was provided as module parameter */
1916 if (iface_name[0]) {
1919 strncpy(net->name, iface_name, IFNAMSIZ);
1920 net->name[IFNAMSIZ - 1] = 0;
1921 len = strlen(net->name);
1922 ch = net->name[len - 1];
1923 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1924 strcat(net->name, "%d");
1927 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1931 net->netdev_ops = NULL;
1932 sema_init(&dhd->proto_sem, 1);
1933 /* Initialize other structure content */
1934 init_waitqueue_head(&dhd->ioctl_resp_wait);
1935 init_waitqueue_head(&dhd->ctrl_wait);
1937 /* Initialize the spinlocks */
1938 spin_lock_init(&dhd->sdlock);
1939 spin_lock_init(&dhd->txqlock);
1941 /* Link to info module */
1942 dhd->pub.info = dhd;
1944 /* Link to bus module */
1946 dhd->pub.hdrlen = bus_hdrlen;
1948 /* Attach and link in the protocol */
1949 if (dhd_prot_attach(&dhd->pub) != 0) {
1950 DHD_ERROR(("dhd_prot_attach failed\n"));
1953 #if defined(CONFIG_WIRELESS_EXT)
1954 /* Attach and link in the iw */
1955 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1956 DHD_ERROR(("wl_iw_attach failed\n"));
1959 #endif /* defined(CONFIG_WIRELESS_EXT) */
1961 /* Attach and link in the cfg80211 */
1962 if (IS_CFG80211_FAVORITE()) {
1963 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1964 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1968 strcpy(fw_path, wl_cfg80211_get_fwname());
1969 strcpy(nv_path, wl_cfg80211_get_nvramname());
1971 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
1974 /* Set up the watchdog timer */
1975 init_timer(&dhd->timer);
1976 dhd->timer.data = (unsigned long) dhd;
1977 dhd->timer.function = dhd_watchdog;
1979 /* Initialize thread based operation and lock */
1980 sema_init(&dhd->sdsem, 1);
1981 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1982 dhd->threads_only = true;
1984 dhd->threads_only = false;
1986 if (dhd_dpc_prio >= 0) {
1987 /* Initialize watchdog thread */
1988 sema_init(&dhd->watchdog_sem, 0);
1989 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1991 if (IS_ERR(dhd->watchdog_tsk)) {
1993 "dhd_watchdog thread failed to start\n");
1994 dhd->watchdog_tsk = NULL;
1997 dhd->watchdog_tsk = NULL;
2000 /* Set up the bottom half handler */
2001 if (dhd_dpc_prio >= 0) {
2002 /* Initialize DPC thread */
2003 sema_init(&dhd->dpc_sem, 0);
2004 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
2005 if (IS_ERR(dhd->dpc_tsk)) {
2007 "dhd_dpc thread failed to start\n");
2008 dhd->dpc_tsk = NULL;
2011 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2012 dhd->dpc_tsk = NULL;
2016 sema_init(&dhd->sysioc_sem, 0);
2017 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
2019 if (IS_ERR(dhd->sysioc_tsk)) {
2021 "_dhd_sysioc thread failed to start\n");
2022 dhd->sysioc_tsk = NULL;
2025 dhd->sysioc_tsk = NULL;
2028 * Save the dhd_info into the priv
2030 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2032 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2035 #if defined(CONFIG_PM_SLEEP)
2036 register_pm_notifier(&dhd_sleep_pm_notifier);
2037 #endif /* defined(CONFIG_PM_SLEEP) */
2038 /* && defined(DHD_GPL) */
2039 /* Init lock suspend to prevent kernel going to suspend */
2040 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2041 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2042 "dhd_wake_lock_link_dw_event");
2043 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2044 "dhd_wake_lock_link_pno_find_event");
2045 #ifdef CONFIG_HAS_EARLYSUSPEND
2046 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2047 dhd->early_suspend.suspend = dhd_early_suspend;
2048 dhd->early_suspend.resume = dhd_late_resume;
2049 register_early_suspend(&dhd->early_suspend);
2058 dhd_detach(&dhd->pub);
2063 int dhd_bus_start(dhd_pub_t *dhdp)
2066 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2067 #ifdef EMBEDDED_PLATFORM
2068 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2070 #endif /* EMBEDDED_PLATFORM */
2074 DHD_TRACE(("%s:\n", __func__));
2076 /* try to download image and nvram to the dongle */
2077 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2078 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2079 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2080 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2081 fw_path, nv_path))) {
2082 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2083 "firmware = %s nvram = %s\n",
2084 __func__, fw_path, nv_path));
2085 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2086 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2090 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2091 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2094 /* Start the watchdog timer */
2095 dhd->pub.tickcnt = 0;
2096 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2098 /* Bring up the bus */
2099 ret = dhd_bus_init(&dhd->pub, true);
2101 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2104 #if defined(OOB_INTR_ONLY)
2105 /* Host registration for OOB interrupt */
2106 if (bcmsdh_register_oob_intr(dhdp)) {
2107 del_timer_sync(&dhd->timer);
2108 dhd->wd_timer_valid = false;
2109 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2113 /* Enable oob at firmware */
2114 dhd_enable_oob_intr(dhd->pub.bus, true);
2115 #endif /* defined(OOB_INTR_ONLY) */
2117 /* If bus is not ready, can't come up */
2118 if (dhd->pub.busstate != DHD_BUS_DATA) {
2119 del_timer_sync(&dhd->timer);
2120 dhd->wd_timer_valid = false;
2121 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2124 #ifdef EMBEDDED_PLATFORM
2125 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2127 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2128 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2130 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2131 setbit(dhdp->eventmask, WLC_E_PRUNE);
2132 setbit(dhdp->eventmask, WLC_E_AUTH);
2133 setbit(dhdp->eventmask, WLC_E_REASSOC);
2134 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2135 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2136 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2137 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2138 setbit(dhdp->eventmask, WLC_E_JOIN);
2139 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2140 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2141 setbit(dhdp->eventmask, WLC_E_LINK);
2142 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2143 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2144 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2145 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2146 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2147 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2149 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2150 #endif /* PNO_SUPPORT */
2152 /* enable dongle roaming event */
2154 dhdp->pktfilter_count = 1;
2155 /* Setup filter to allow only unicast */
2156 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2157 #endif /* EMBEDDED_PLATFORM */
2159 /* Bus is ready, do any protocol initialization */
2160 ret = dhd_prot_init(&dhd->pub);
2168 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2171 char buf[strlen(name) + 1 + cmd_len];
2172 int len = sizeof(buf);
2176 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2178 memset(&ioc, 0, sizeof(ioc));
2180 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2185 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2186 if (!set && ret >= 0)
2187 memcpy(cmd_buf, buf, cmd_len);
2192 static struct net_device_ops dhd_ops_pri = {
2193 .ndo_open = dhd_open,
2194 .ndo_stop = dhd_stop,
2195 .ndo_get_stats = dhd_get_stats,
2196 .ndo_do_ioctl = dhd_ioctl_entry,
2197 .ndo_start_xmit = dhd_start_xmit,
2198 .ndo_set_mac_address = dhd_set_mac_address,
2199 .ndo_set_multicast_list = dhd_set_multicast_list
2202 static struct net_device_ops dhd_ops_virt = {
2203 .ndo_get_stats = dhd_get_stats,
2204 .ndo_do_ioctl = dhd_ioctl_entry,
2205 .ndo_start_xmit = dhd_start_xmit,
2206 .ndo_set_mac_address = dhd_set_mac_address,
2207 .ndo_set_multicast_list = dhd_set_multicast_list
2210 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2212 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2213 struct net_device *net;
2214 u8 temp_addr[ETHER_ADDR_LEN] = {
2215 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2217 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2219 ASSERT(dhd && dhd->iflist[ifidx]);
2221 net = dhd->iflist[ifidx]->net;
2224 ASSERT(!net->netdev_ops);
2225 net->netdev_ops = &dhd_ops_pri;
2228 * We have to use the primary MAC for virtual interfaces
2231 /* for virtual interfaces use the primary MAC */
2232 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2237 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2238 /* ACCESSPOINT INTERFACE CASE */
2239 temp_addr[0] |= 0X02; /* set bit 2 ,
2240 - Locally Administered address */
2243 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2244 net->ethtool_ops = &dhd_ethtool_ops;
2246 #if defined(CONFIG_WIRELESS_EXT)
2247 if (!IS_CFG80211_FAVORITE()) {
2248 #if WIRELESS_EXT < 19
2249 net->get_wireless_stats = dhd_get_wireless_stats;
2250 #endif /* WIRELESS_EXT < 19 */
2251 #if WIRELESS_EXT > 12
2252 net->wireless_handlers =
2253 (struct iw_handler_def *)&wl_iw_handler_def;
2254 #endif /* WIRELESS_EXT > 12 */
2256 #endif /* defined(CONFIG_WIRELESS_EXT) */
2258 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2260 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2262 if (register_netdev(net) != 0) {
2263 DHD_ERROR(("%s: couldn't register the net device\n",
2268 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2273 net->netdev_ops = NULL;
2277 void dhd_bus_detach(dhd_pub_t *dhdp)
2281 DHD_TRACE(("%s: Enter\n", __func__));
2284 dhd = (dhd_info_t *) dhdp->info;
2286 /* Stop the protocol module */
2287 dhd_prot_stop(&dhd->pub);
2289 /* Stop the bus module */
2290 dhd_bus_stop(dhd->pub.bus, true);
2291 #if defined(OOB_INTR_ONLY)
2292 bcmsdh_unregister_oob_intr();
2293 #endif /* defined(OOB_INTR_ONLY) */
2295 /* Clear the watchdog timer */
2296 del_timer_sync(&dhd->timer);
2297 dhd->wd_timer_valid = false;
2302 void dhd_detach(dhd_pub_t *dhdp)
2306 DHD_TRACE(("%s: Enter\n", __func__));
2309 dhd = (dhd_info_t *) dhdp->info;
2314 #if defined(CONFIG_HAS_EARLYSUSPEND)
2315 if (dhd->early_suspend.suspend)
2316 unregister_early_suspend(&dhd->early_suspend);
2317 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2319 for (i = 1; i < DHD_MAX_IFS; i++)
2323 ifp = dhd->iflist[0];
2325 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2327 unregister_netdev(ifp->net);
2330 if (dhd->watchdog_tsk) {
2331 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2332 kthread_stop(dhd->watchdog_tsk);
2333 dhd->watchdog_tsk = NULL;
2337 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2338 kthread_stop(dhd->dpc_tsk);
2339 dhd->dpc_tsk = NULL;
2341 tasklet_kill(&dhd->tasklet);
2343 if (dhd->sysioc_tsk) {
2344 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2345 kthread_stop(dhd->sysioc_tsk);
2346 dhd->sysioc_tsk = NULL;
2349 dhd_bus_detach(dhdp);
2352 dhd_prot_detach(dhdp);
2354 #if defined(CONFIG_WIRELESS_EXT)
2356 #endif /* (CONFIG_WIRELESS_EXT) */
2358 if (IS_CFG80211_FAVORITE())
2359 wl_cfg80211_detach();
2361 #if defined(CONFIG_PM_SLEEP)
2362 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2363 #endif /* defined(CONFIG_PM_SLEEP) */
2364 /* && defined(DHD_GPL) */
2365 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2366 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2367 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2368 free_netdev(ifp->net);
2375 static void __exit dhd_module_cleanup(void)
2377 DHD_TRACE(("%s: Enter\n", __func__));
2379 dhd_bus_unregister();
2380 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2383 /* Call customer gpio to turn off power with WL_REG_ON signal */
2384 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2387 static int __init dhd_module_init(void)
2391 DHD_TRACE(("%s: Enter\n", __func__));
2393 /* Sanity check on the module parameters */
2395 /* Both watchdog and DPC as tasklets are ok */
2396 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2399 /* If both watchdog and DPC are threads, TX must be deferred */
2400 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2404 DHD_ERROR(("Invalid module parameters.\n"));
2407 /* Call customer gpio to turn on power with WL_REG_ON signal */
2408 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2410 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2411 sema_init(&wifi_control_sem, 0);
2413 error = wifi_add_dev();
2415 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2419 /* Waiting callback after platform_driver_register is done or
2421 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2422 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2428 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2430 error = dhd_bus_register();
2433 printf("\n%s\n", dhd_version);
2435 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2441 /* turn off power and exit */
2442 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2446 module_init(dhd_module_init);
2447 module_exit(dhd_module_cleanup);
2450 * OS specific functions required to implement DHD driver in OS independent way
2452 int dhd_os_proto_block(dhd_pub_t *pub)
2454 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2457 down(&dhd->proto_sem);
2463 int dhd_os_proto_unblock(dhd_pub_t *pub)
2465 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2468 up(&dhd->proto_sem);
2475 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2477 return (unsigned int)dhd_ioctl_timeout_msec;
2480 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2482 dhd_ioctl_timeout_msec = (int)timeout_msec;
2485 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2487 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2488 DECLARE_WAITQUEUE(wait, current);
2489 int timeout = dhd_ioctl_timeout_msec;
2491 /* Convert timeout in millsecond to jiffies */
2492 timeout = timeout * HZ / 1000;
2494 /* Wait until control frame is available */
2495 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2496 set_current_state(TASK_INTERRUPTIBLE);
2498 while (!(*condition) && (!signal_pending(current) && timeout))
2499 timeout = schedule_timeout(timeout);
2501 if (signal_pending(current))
2504 set_current_state(TASK_RUNNING);
2505 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2510 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2512 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2514 if (waitqueue_active(&dhd->ioctl_resp_wait))
2515 wake_up_interruptible(&dhd->ioctl_resp_wait);
2520 void dhd_os_wd_timer(void *bus, uint wdtick)
2522 dhd_pub_t *pub = bus;
2523 static uint save_dhd_watchdog_ms;
2524 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2526 /* don't start the wd until fw is loaded */
2527 if (pub->busstate == DHD_BUS_DOWN)
2530 /* Totally stop the timer */
2531 if (!wdtick && dhd->wd_timer_valid == true) {
2532 del_timer_sync(&dhd->timer);
2533 dhd->wd_timer_valid = false;
2534 save_dhd_watchdog_ms = wdtick;
2539 dhd_watchdog_ms = (uint) wdtick;
2541 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2543 if (dhd->wd_timer_valid == true)
2544 /* Stop timer and restart at new value */
2545 del_timer_sync(&dhd->timer);
2547 /* Create timer again when watchdog period is
2548 dynamically changed or in the first instance
2550 dhd->timer.expires =
2551 jiffies + dhd_watchdog_ms * HZ / 1000;
2552 add_timer(&dhd->timer);
2555 /* Re arm the timer, at last watchdog period */
2556 mod_timer(&dhd->timer,
2557 jiffies + dhd_watchdog_ms * HZ / 1000);
2560 dhd->wd_timer_valid = true;
2561 save_dhd_watchdog_ms = wdtick;
2565 void *dhd_os_open_image(char *filename)
2569 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2570 return wl_cfg80211_request_fw(filename);
2572 fp = filp_open(filename, O_RDONLY, 0);
2574 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2576 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2585 int dhd_os_get_image_block(char *buf, int len, void *image)
2587 struct file *fp = (struct file *)image;
2590 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2591 return wl_cfg80211_read_fw(buf, len);
2596 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2603 void dhd_os_close_image(void *image)
2605 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2606 return wl_cfg80211_release_fw();
2608 filp_close((struct file *)image, NULL);
2611 void dhd_os_sdlock(dhd_pub_t *pub)
2615 dhd = (dhd_info_t *) (pub->info);
2617 if (dhd->threads_only)
2620 spin_lock_bh(&dhd->sdlock);
2623 void dhd_os_sdunlock(dhd_pub_t *pub)
2627 dhd = (dhd_info_t *) (pub->info);
2629 if (dhd->threads_only)
2632 spin_unlock_bh(&dhd->sdlock);
2635 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2639 dhd = (dhd_info_t *) (pub->info);
2640 spin_lock_bh(&dhd->txqlock);
2643 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2647 dhd = (dhd_info_t *) (pub->info);
2648 spin_unlock_bh(&dhd->txqlock);
2651 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2655 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2659 void dhd_os_sdtxlock(dhd_pub_t *pub)
2664 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2666 dhd_os_sdunlock(pub);
2669 #if defined(CONFIG_WIRELESS_EXT)
2670 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2673 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2675 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2678 return &dhd->iw.wstats;
2682 #endif /* defined(CONFIG_WIRELESS_EXT) */
2685 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2686 wl_event_msg_t *event, void **data)
2690 ASSERT(dhd != NULL);
2692 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2693 if (bcmerror != BCME_OK)
2696 #if defined(CONFIG_WIRELESS_EXT)
2697 if (!IS_CFG80211_FAVORITE()) {
2698 if ((dhd->iflist[*ifidx] == NULL)
2699 || (dhd->iflist[*ifidx]->net == NULL)) {
2700 DHD_ERROR(("%s Exit null pointer\n", __func__));
2704 if (dhd->iflist[*ifidx]->net)
2705 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2707 #endif /* defined(CONFIG_WIRELESS_EXT) */
2709 if (IS_CFG80211_FAVORITE()) {
2710 ASSERT(dhd->iflist[*ifidx] != NULL);
2711 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2712 if (dhd->iflist[*ifidx]->net)
2713 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2720 /* send up locally generated event */
2721 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2723 switch (ntoh32(event->event_type)) {
2729 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2731 struct dhd_info *dhdinfo = dhd->info;
2732 dhd_os_sdunlock(dhd);
2733 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2734 (*lockvar == false), HZ * 2);
2739 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2741 struct dhd_info *dhdinfo = dhd->info;
2742 if (waitqueue_active(&dhdinfo->ctrl_wait))
2743 wake_up_interruptible(&dhdinfo->ctrl_wait);
2747 int dhd_dev_reset(struct net_device *dev, u8 flag)
2749 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2751 /* Turning off watchdog */
2753 dhd_os_wd_timer(&dhd->pub, 0);
2755 dhd_bus_devreset(&dhd->pub, flag);
2757 /* Turning on watchdog back */
2759 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2760 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2765 int net_os_set_suspend_disable(struct net_device *dev, int val)
2767 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2771 ret = dhd->pub.suspend_disable_flag;
2772 dhd->pub.suspend_disable_flag = val;
2777 int net_os_set_suspend(struct net_device *dev, int val)
2780 #if defined(CONFIG_HAS_EARLYSUSPEND)
2781 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2784 dhd_os_proto_block(&dhd->pub);
2785 ret = dhd_set_suspend(val, &dhd->pub);
2786 dhd_os_proto_unblock(&dhd->pub);
2788 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2792 int net_os_set_dtim_skip(struct net_device *dev, int val)
2794 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2797 dhd->pub.dtim_skip = val;
2802 int net_os_set_packet_filter(struct net_device *dev, int val)
2804 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2807 /* Packet filtering is set only if we still in early-suspend and
2808 * we need either to turn it ON or turn it OFF
2809 * We can always turn it OFF in case of early-suspend, but we turn it
2810 * back ON only if suspend_disable_flag was not set
2812 if (dhd && dhd->pub.up) {
2813 dhd_os_proto_block(&dhd->pub);
2814 if (dhd->pub.in_suspend) {
2815 if (!val || (val && !dhd->pub.suspend_disable_flag))
2816 dhd_set_packet_filter(val, &dhd->pub);
2818 dhd_os_proto_unblock(&dhd->pub);
2823 void dhd_dev_init_ioctl(struct net_device *dev)
2825 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2827 dhd_preinit_ioctls(&dhd->pub);
2831 /* Linux wrapper to call common dhd_pno_clean */
2832 int dhd_dev_pno_reset(struct net_device *dev)
2834 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2836 return dhd_pno_clean(&dhd->pub);
2839 /* Linux wrapper to call common dhd_pno_enable */
2840 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2842 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2844 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2847 /* Linux wrapper to call common dhd_pno_set */
2849 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2850 unsigned char scan_fr)
2852 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2854 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2857 /* Linux wrapper to get pno status */
2858 int dhd_dev_get_pno_status(struct net_device *dev)
2860 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2862 return dhd_pno_get_status(&dhd->pub);
2865 #endif /* PNO_SUPPORT */
2867 static int 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
2874 int dhd_wait_pend8021x(struct net_device *dev)
2876 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2877 int timeout = 10 * HZ / 1000;
2878 int ntimes = MAX_WAIT_FOR_8021X_TX;
2879 int pend = dhd_get_pend_8021x_cnt(dhd);
2881 while (ntimes && pend) {
2883 set_current_state(TASK_INTERRUPTIBLE);
2884 schedule_timeout(timeout);
2885 set_current_state(TASK_RUNNING);
2888 pend = dhd_get_pend_8021x_cnt(dhd);
2894 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2898 mm_segment_t old_fs;
2901 /* change to KERNEL_DS address limit */
2905 /* open file to write */
2906 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2908 printf("%s: open file error\n", __func__);
2913 /* Write buf to file */
2914 fp->f_op->write(fp, buf, size, &pos);
2917 /* free buf before return */
2919 /* close file before return */
2921 filp_close(fp, current->files);
2922 /* restore previous address limit */
2927 #endif /* DHD_DEBUG */