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>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/kthread.h>
27 #include <linux/slab.h>
28 #include <linux/skbuff.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/mmc/sdio_func.h>
32 #include <linux/random.h>
33 #include <linux/spinlock.h>
34 #include <linux/ethtool.h>
35 #include <linux/fcntl.h>
38 #include <linux/uaccess.h>
40 #include <bcmendian.h>
42 #include <proto/ethernet.h>
43 #include <dngl_stats.h>
46 #include <dhd_proto.h>
49 #include <wl_cfg80211.h>
51 #define EPI_VERSION_STR "4.218.248.5"
53 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
54 #include <linux/wifi_tiwlan.h>
56 struct semaphore wifi_control_sem;
58 struct dhd_bus *g_bus;
60 static struct wifi_platform_data *wifi_control_data;
61 static struct resource *wifi_irqres;
63 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
66 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
67 return (int)wifi_irqres->start;
69 #ifdef CUSTOM_OOB_GPIO_NUM
70 return CUSTOM_OOB_GPIO_NUM;
76 int wifi_set_carddetect(int on)
78 printk(KERN_ERR "%s = %d\n", __func__, on);
79 if (wifi_control_data && wifi_control_data->set_carddetect)
80 wifi_control_data->set_carddetect(on);
84 int wifi_set_power(int on, unsigned long msec)
86 printk(KERN_ERR "%s = %d\n", __func__, on);
87 if (wifi_control_data && wifi_control_data->set_power)
88 wifi_control_data->set_power(on);
94 int wifi_set_reset(int on, unsigned long msec)
96 printk(KERN_ERR "%s = %d\n", __func__, on);
97 if (wifi_control_data && wifi_control_data->set_reset)
98 wifi_control_data->set_reset(on);
104 static int wifi_probe(struct platform_device *pdev)
106 struct wifi_platform_data *wifi_ctrl =
107 (struct wifi_platform_data *)(pdev->dev.platform_data);
109 printk(KERN_ERR "## %s\n", __func__);
111 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
113 wifi_control_data = wifi_ctrl;
115 wifi_set_power(1, 0); /* Power On */
116 wifi_set_carddetect(1); /* CardDetect (0->1) */
118 up(&wifi_control_sem);
122 static int wifi_remove(struct platform_device *pdev)
124 struct wifi_platform_data *wifi_ctrl =
125 (struct wifi_platform_data *)(pdev->dev.platform_data);
127 printk(KERN_ERR "## %s\n", __func__);
128 wifi_control_data = wifi_ctrl;
130 wifi_set_carddetect(0); /* CardDetect (1->0) */
131 wifi_set_power(0, 0); /* Power Off */
133 up(&wifi_control_sem);
137 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
139 DHD_TRACE(("##> %s\n", __func__));
143 static int wifi_resume(struct platform_device *pdev)
145 DHD_TRACE(("##> %s\n", __func__));
149 static struct platform_driver wifi_device = {
151 .remove = wifi_remove,
152 .suspend = wifi_suspend,
153 .resume = wifi_resume,
155 .name = "bcm4329_wlan",
159 int wifi_add_dev(void)
161 DHD_TRACE(("## Calling platform_driver_register\n"));
162 return platform_driver_register(&wifi_device);
165 void wifi_del_dev(void)
167 DHD_TRACE(("## Unregister platform_driver_register\n"));
168 platform_driver_unregister(&wifi_device);
170 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
172 #if defined(CONFIG_PM_SLEEP)
173 #include <linux/suspend.h>
174 volatile bool dhd_mmc_suspend = false;
175 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
176 #endif /* defined(CONFIG_PM_SLEEP) */
178 #if defined(OOB_INTR_ONLY)
179 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
180 #endif /* defined(OOB_INTR_ONLY) */
182 MODULE_AUTHOR("Broadcom Corporation");
183 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
184 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
185 MODULE_LICENSE("Dual BSD/GPL");
187 #define DRV_MODULE_NAME "brcmfmac"
189 /* Linux wireless extension support */
190 #if defined(CONFIG_WIRELESS_EXT)
192 extern wl_iw_extra_params_t g_wl_iw_params;
193 #endif /* defined(CONFIG_WIRELESS_EXT) */
195 #if defined(CONFIG_HAS_EARLYSUSPEND)
196 #include <linux/earlysuspend.h>
197 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
199 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
201 #ifdef PKT_FILTER_SUPPORT
202 extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
203 extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
207 /* Interface control information */
208 typedef struct dhd_if {
209 struct dhd_info *info; /* back pointer to dhd_info */
210 /* OS/stack specifics */
211 struct net_device *net;
212 struct net_device_stats stats;
213 int idx; /* iface idx in dongle */
214 int state; /* interface state */
215 uint subunit; /* subunit */
216 u8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
217 bool attached; /* Delayed attachment when unset */
218 bool txflowcontrol; /* Per interface flow control indicator */
219 char name[IFNAMSIZ]; /* linux interface name */
222 /* Local private structure (extension of pub) */
223 typedef struct dhd_info {
224 #if defined(CONFIG_WIRELESS_EXT)
225 wl_iw_t iw; /* wireless extensions state (must be first) */
226 #endif /* defined(CONFIG_WIRELESS_EXT) */
230 /* OS/stack specifics */
231 dhd_if_t *iflist[DHD_MAX_IFS];
233 struct semaphore proto_sem;
234 wait_queue_head_t ioctl_resp_wait;
235 struct timer_list timer;
237 struct tasklet_struct tasklet;
240 /* Thread based operation */
242 struct semaphore sdsem;
243 struct task_struct *watchdog_tsk;
244 struct semaphore watchdog_sem;
245 struct task_struct *dpc_tsk;
246 struct semaphore dpc_sem;
248 /* Thread to issue ioctl for multicast */
249 struct task_struct *sysioc_tsk;
250 struct semaphore sysioc_sem;
253 struct ether_addr macvalue;
254 wait_queue_head_t ctrl_wait;
255 atomic_t pend_8021x_cnt;
257 #ifdef CONFIG_HAS_EARLYSUSPEND
258 struct early_suspend early_suspend;
259 #endif /* CONFIG_HAS_EARLYSUSPEND */
262 /* Definitions to provide path to the firmware and nvram
263 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
265 char firmware_path[MOD_PARAM_PATHLEN];
266 char nvram_path[MOD_PARAM_PATHLEN];
268 /* load firmware and/or nvram values from the filesystem */
269 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
270 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
273 module_param(dhd_msg_level, int, 0);
275 /* Spawn a thread for system ioctls (set mac, set mcast) */
276 uint dhd_sysioc = true;
277 module_param(dhd_sysioc, uint, 0);
279 /* Watchdog interval */
280 uint dhd_watchdog_ms = 10;
281 module_param(dhd_watchdog_ms, uint, 0);
284 /* Console poll interval */
286 module_param(dhd_console_ms, uint, 0);
287 #endif /* DHD_DEBUG */
289 /* ARP offload agent mode : Enable ARP Host Auto-Reply
290 and ARP Peer Auto-Reply */
291 uint dhd_arp_mode = 0xb;
292 module_param(dhd_arp_mode, uint, 0);
294 /* ARP offload enable */
295 uint dhd_arp_enable = true;
296 module_param(dhd_arp_enable, uint, 0);
298 /* Global Pkt filter enable control */
299 uint dhd_pkt_filter_enable = true;
300 module_param(dhd_pkt_filter_enable, uint, 0);
302 /* Pkt filter init setup */
303 uint dhd_pkt_filter_init;
304 module_param(dhd_pkt_filter_init, uint, 0);
306 /* Pkt filter mode control */
307 uint dhd_master_mode = true;
308 module_param(dhd_master_mode, uint, 1);
310 /* Watchdog thread priority, -1 to use kernel timer */
311 int dhd_watchdog_prio = 97;
312 module_param(dhd_watchdog_prio, int, 0);
314 /* DPC thread priority, -1 to use tasklet */
315 int dhd_dpc_prio = 98;
316 module_param(dhd_dpc_prio, int, 0);
318 /* DPC thread priority, -1 to use tasklet */
319 extern int dhd_dongle_memsize;
320 module_param(dhd_dongle_memsize, int, 0);
322 /* Contorl fw roaming */
329 /* Control radio state */
330 uint dhd_radio_up = 1;
332 /* Network inteface name */
333 char iface_name[IFNAMSIZ];
334 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
336 /* The following are specific to the SDIO dongle */
338 /* IOCTL response timeout */
339 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
341 /* Idle timeout for backplane clock */
342 int dhd_idletime = DHD_IDLETIME_TICKS;
343 module_param(dhd_idletime, int, 0);
346 uint dhd_poll = false;
347 module_param(dhd_poll, uint, 0);
350 uint dhd_cfg80211 = true;
351 module_param(dhd_cfg80211, uint, 0);
354 uint dhd_intr = true;
355 module_param(dhd_intr, uint, 0);
357 /* SDIO Drive Strength (in milliamps) */
358 uint dhd_sdiod_drive_strength = 6;
359 module_param(dhd_sdiod_drive_strength, uint, 0);
362 extern uint dhd_txbound;
363 extern uint dhd_rxbound;
364 module_param(dhd_txbound, uint, 0);
365 module_param(dhd_rxbound, uint, 0);
367 /* Deferred transmits */
368 extern uint dhd_deferred_tx;
369 module_param(dhd_deferred_tx, uint, 0);
372 /* Echo packet generator (pkts/s) */
374 module_param(dhd_pktgen, uint, 0);
376 /* Echo packet len (0 => sawtooth, max 2040) */
378 module_param(dhd_pktgen_len, uint, 0);
381 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
382 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
383 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
384 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
386 /* Version string to report */
388 #define DHD_COMPILED "\nCompiled in " SRCBASE
393 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
395 "\nCompiled in " " on " __DATE__ " at " __TIME__
399 #if defined(CONFIG_WIRELESS_EXT)
400 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
401 #endif /* defined(CONFIG_WIRELESS_EXT) */
403 static void dhd_dpc(unsigned long data);
405 extern int dhd_wait_pend8021x(struct net_device *dev);
409 #error TOE requires BDC
411 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
412 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
415 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
416 wl_event_msg_t *event_ptr, void **data_ptr);
418 #if defined(CONFIG_PM_SLEEP)
419 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
420 unsigned long action, void *ignored)
423 case PM_HIBERNATION_PREPARE:
424 case PM_SUSPEND_PREPARE:
425 dhd_mmc_suspend = true;
427 case PM_POST_HIBERNATION:
428 case PM_POST_SUSPEND:
429 dhd_mmc_suspend = false;
435 static struct notifier_block dhd_sleep_pm_notifier = {
436 .notifier_call = dhd_sleep_pm_callback,
440 extern int register_pm_notifier(struct notifier_block *nb);
441 extern int unregister_pm_notifier(struct notifier_block *nb);
442 #endif /* defined(CONFIG_PM_SLEEP) */
443 /* && defined(DHD_GPL) */
444 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
446 #ifdef PKT_FILTER_SUPPORT
447 DHD_TRACE(("%s: %d\n", __func__, value));
448 /* 1 - Enable packet filter, only allow unicast packet to send up */
449 /* 0 - Disable packet filter */
450 if (dhd_pkt_filter_enable) {
453 for (i = 0; i < dhd->pktfilter_count; i++) {
454 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
455 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
456 value, dhd_master_mode);
462 #if defined(CONFIG_HAS_EARLYSUSPEND)
463 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
465 int power_mode = PM_MAX;
466 /* wl_pkt_filter_enable_t enable_parm; */
471 #endif /* CUSTOMER_HW2 */
473 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
474 __func__, value, dhd->in_suspend));
476 if (dhd && dhd->up) {
477 if (value && dhd->in_suspend) {
479 /* Kernel suspended */
480 DHD_TRACE(("%s: force extra Suspend setting\n",
483 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
487 /* Enable packet filter, only allow unicast
489 dhd_set_packet_filter(1, dhd);
491 /* if dtim skip setup as default force it
492 * to wake each thrid dtim
493 * for better power saving.
494 * Note that side effect is chance to miss BC/MC
497 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
500 bcn_li_dtim = dhd->dtim_skip;
501 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
502 4, iovbuf, sizeof(iovbuf));
503 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
506 /* Disable build-in roaming to allowed \
507 * supplicant to take of romaing
509 bcm_mkiovar("roam_off", (char *)&roamvar, 4,
510 iovbuf, sizeof(iovbuf));
511 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
513 #endif /* CUSTOMER_HW2 */
517 DHD_TRACE(("%s: Remove extra suspend setting\n",
520 power_mode = PM_FAST;
521 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
525 /* disable pkt filter */
526 dhd_set_packet_filter(0, dhd);
528 /* restore pre-suspend setting for dtim_skip */
529 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
530 4, iovbuf, sizeof(iovbuf));
532 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
536 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
538 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
540 #endif /* CUSTOMER_HW2 */
547 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
549 dhd_pub_t *dhdp = &dhd->pub;
551 dhd_os_proto_block(dhdp);
552 /* Set flag when early suspend was called */
553 dhdp->in_suspend = val;
554 if (!dhdp->suspend_disable_flag)
555 dhd_set_suspend(val, dhdp);
556 dhd_os_proto_unblock(dhdp);
559 static void dhd_early_suspend(struct early_suspend *h)
561 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
563 DHD_TRACE(("%s: enter\n", __func__));
566 dhd_suspend_resume_helper(dhd, 1);
570 static void dhd_late_resume(struct early_suspend *h)
572 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
574 DHD_TRACE(("%s: enter\n", __func__));
577 dhd_suspend_resume_helper(dhd, 0);
579 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
582 * Generalized timeout mechanism. Uses spin sleep with exponential
584 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
586 * dhd_timeout_start(&tmo, usec);
587 * while (!dhd_timeout_expired(&tmo))
588 * if (poll_something())
590 * if (dhd_timeout_expired(&tmo))
594 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
599 tmo->tick = 1000000 / HZ;
602 int dhd_timeout_expired(dhd_timeout_t *tmo)
604 /* Does nothing the first call */
605 if (tmo->increment == 0) {
610 if (tmo->elapsed >= tmo->limit)
613 /* Add the delay that's about to take place */
614 tmo->elapsed += tmo->increment;
616 if (tmo->increment < tmo->tick) {
617 udelay(tmo->increment);
619 if (tmo->increment > tmo->tick)
620 tmo->increment = tmo->tick;
622 wait_queue_head_t delay_wait;
623 DECLARE_WAITQUEUE(wait, current);
625 init_waitqueue_head(&delay_wait);
626 add_wait_queue(&delay_wait, &wait);
627 set_current_state(TASK_INTERRUPTIBLE);
629 pending = signal_pending(current);
630 remove_wait_queue(&delay_wait, &wait);
631 set_current_state(TASK_RUNNING);
633 return 1; /* Interrupted */
639 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
644 while (i < DHD_MAX_IFS) {
645 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
653 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
659 if (name == NULL || *name == '\0')
664 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
667 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
669 return i; /* default - the primary interface */
672 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
674 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
678 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
679 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
683 if (dhd->iflist[ifidx] == NULL) {
684 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
688 if (dhd->iflist[ifidx]->net)
689 return dhd->iflist[ifidx]->net->name;
694 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
696 struct net_device *dev;
697 struct netdev_hw_addr *ha;
705 ASSERT(dhd && dhd->iflist[ifidx]);
706 dev = dhd->iflist[ifidx]->net;
707 cnt = netdev_mc_count(dev);
709 /* Determine initial value of allmulti flag */
710 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
712 /* Send down the multicast list first. */
714 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
715 bufp = buf = MALLOC(dhd->pub.osh, buflen);
717 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
718 dhd_ifname(&dhd->pub, ifidx), cnt));
722 strcpy(bufp, "mcast_list");
723 bufp += strlen("mcast_list") + 1;
726 memcpy(bufp, &cnt, sizeof(cnt));
729 netdev_for_each_mc_addr(ha, dev) {
732 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
733 bufp += ETHER_ADDR_LEN;
737 memset(&ioc, 0, sizeof(ioc));
738 ioc.cmd = WLC_SET_VAR;
743 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
745 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
746 dhd_ifname(&dhd->pub, ifidx), cnt));
747 allmulti = cnt ? true : allmulti;
750 MFREE(dhd->pub.osh, buf, buflen);
752 /* Now send the allmulti setting. This is based on the setting in the
753 * net_device flags, but might be modified above to be turned on if we
754 * were trying to set some addresses and dongle rejected it...
757 buflen = sizeof("allmulti") + sizeof(allmulti);
758 buf = MALLOC(dhd->pub.osh, buflen);
760 DHD_ERROR(("%s: out of memory for allmulti\n",
761 dhd_ifname(&dhd->pub, ifidx)));
764 allmulti = htol32(allmulti);
767 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
768 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
769 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
770 (int)sizeof(allmulti), buflen));
771 MFREE(dhd->pub.osh, buf, buflen);
775 memset(&ioc, 0, sizeof(ioc));
776 ioc.cmd = WLC_SET_VAR;
781 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
783 DHD_ERROR(("%s: set allmulti %d failed\n",
784 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
787 MFREE(dhd->pub.osh, buf, buflen);
789 /* Finally, pick up the PROMISC flag as well, like the NIC
792 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
793 allmulti = htol32(allmulti);
795 memset(&ioc, 0, sizeof(ioc));
796 ioc.cmd = WLC_SET_PROMISC;
798 ioc.len = sizeof(allmulti);
801 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
803 DHD_ERROR(("%s: set promisc %d failed\n",
804 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
809 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
815 DHD_TRACE(("%s enter\n", __func__));
817 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) {
818 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
819 dhd_ifname(&dhd->pub, ifidx)));
822 memset(&ioc, 0, sizeof(ioc));
823 ioc.cmd = WLC_SET_VAR;
828 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
830 DHD_ERROR(("%s: set cur_etheraddr failed\n",
831 dhd_ifname(&dhd->pub, ifidx)));
833 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
840 extern struct net_device *ap_net_dev;
843 static void dhd_op_if(dhd_if_t *ifp)
846 int ret = 0, err = 0;
848 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
852 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
854 switch (ifp->state) {
857 * Delete the existing interface before overwriting it
858 * in case we missed the WLC_E_IF_DEL event.
860 if (ifp->net != NULL) {
861 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
862 "try free & unregister\n",
863 __func__, ifp->net->name));
864 netif_stop_queue(ifp->net);
865 unregister_netdev(ifp->net);
866 free_netdev(ifp->net);
868 /* Allocate etherdev, including space for private structure */
869 ifp->net = alloc_etherdev(sizeof(dhd));
871 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
875 strcpy(ifp->net->name, ifp->name);
876 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
877 err = dhd_net_attach(&dhd->pub, ifp->idx);
879 DHD_ERROR(("%s: dhd_net_attach failed, "
885 /* semaphore that the soft AP CODE
887 extern struct semaphore ap_eth_sema;
889 /* save ptr to wl0.1 netdev for use
891 ap_net_dev = ifp->net;
892 /* signal to the SOFTAP 'sleeper' thread,
896 DHD_TRACE(("\n ==== pid:%x, net_device for "
897 "if:%s created ===\n\n",
898 current->pid, ifp->net->name));
904 if (ifp->net != NULL) {
905 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
907 netif_stop_queue(ifp->net);
908 unregister_netdev(ifp->net);
909 ret = DHD_DEL_IF; /* Make sure the free_netdev()
914 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
921 free_netdev(ifp->net);
923 dhd->iflist[ifp->idx] = NULL;
924 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
926 if (ifp->net == ap_net_dev)
927 ap_net_dev = NULL; /* NULL SOFTAP global
933 static int _dhd_sysioc_thread(void *data)
935 dhd_info_t *dhd = (dhd_info_t *) data;
941 allow_signal(SIGTERM);
943 while (down_interruptible(&dhd->sysioc_sem) == 0) {
944 if (kthread_should_stop())
946 for (i = 0; i < DHD_MAX_IFS; i++) {
947 if (dhd->iflist[i]) {
949 in_ap = (ap_net_dev != NULL);
951 if (dhd->iflist[i]->state)
952 dhd_op_if(dhd->iflist[i]);
954 if (dhd->iflist[i] == NULL) {
955 DHD_TRACE(("\n\n %s: interface %d "
956 "removed!\n", __func__, i));
960 if (in_ap && dhd->set_macaddress) {
961 DHD_TRACE(("attempt to set MAC for %s "
962 "in AP Mode," "blocked. \n",
963 dhd->iflist[i]->net->name));
964 dhd->set_macaddress = false;
968 if (in_ap && dhd->set_multicast) {
969 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
970 dhd->iflist[i]->net->name));
971 dhd->set_multicast = false;
975 if (dhd->set_multicast) {
976 dhd->set_multicast = false;
977 _dhd_set_multicast_list(dhd, i);
979 if (dhd->set_macaddress) {
980 dhd->set_macaddress = false;
981 _dhd_set_mac_address(dhd, i,
990 static int dhd_set_mac_address(struct net_device *dev, void *addr)
994 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
995 struct sockaddr *sa = (struct sockaddr *)addr;
998 ifidx = dhd_net2idx(dhd, dev);
999 if (ifidx == DHD_BAD_IF)
1002 ASSERT(dhd->sysioc_tsk);
1003 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1004 dhd->set_macaddress = true;
1005 up(&dhd->sysioc_sem);
1010 static void dhd_set_multicast_list(struct net_device *dev)
1012 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1015 ifidx = dhd_net2idx(dhd, dev);
1016 if (ifidx == DHD_BAD_IF)
1019 ASSERT(dhd->sysioc_tsk);
1020 dhd->set_multicast = true;
1021 up(&dhd->sysioc_sem);
1024 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1027 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1029 /* Reject if down */
1030 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1033 /* Update multicast statistic */
1034 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1035 u8 *pktdata = (u8 *) PKTDATA(pktbuf);
1036 struct ether_header *eh = (struct ether_header *)pktdata;
1038 if (ETHER_ISMULTI(eh->ether_dhost))
1039 dhdp->tx_multicast++;
1040 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1041 atomic_inc(&dhd->pend_8021x_cnt);
1044 /* Look into the packet and update the packet priority */
1045 if ((PKTPRIO(pktbuf) == 0))
1046 pktsetprio(pktbuf, false);
1048 /* If the protocol uses a data header, apply it */
1049 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1051 /* Use bus module to send data frame */
1053 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1055 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1056 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1057 #endif /* BCMDBUS */
1062 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1066 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1069 DHD_TRACE(("%s: Enter\n", __func__));
1071 /* Reject if down */
1072 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1073 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1074 __func__, dhd->pub.up, dhd->pub.busstate));
1075 netif_stop_queue(net);
1079 ifidx = dhd_net2idx(dhd, net);
1080 if (ifidx == DHD_BAD_IF) {
1081 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1082 netif_stop_queue(net);
1086 /* Make sure there's enough room for any header */
1087 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1088 struct sk_buff *skb2;
1090 DHD_INFO(("%s: insufficient headroom\n",
1091 dhd_ifname(&dhd->pub, ifidx)));
1092 dhd->pub.tx_realloc++;
1093 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1097 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1098 dhd_ifname(&dhd->pub, ifidx)));
1104 /* Convert to packet */
1105 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1107 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1108 dhd_ifname(&dhd->pub, ifidx)));
1109 dev_kfree_skb_any(skb);
1114 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1118 dhd->pub.dstats.tx_dropped++;
1120 dhd->pub.tx_packets++;
1122 /* Return ok: we always eat the packet */
1126 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1128 struct net_device *net;
1129 dhd_info_t *dhd = dhdp->info;
1131 DHD_TRACE(("%s: Enter\n", __func__));
1133 dhdp->txoff = state;
1134 ASSERT(dhd && dhd->iflist[ifidx]);
1135 net = dhd->iflist[ifidx]->net;
1137 netif_stop_queue(net);
1139 netif_wake_queue(net);
1142 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1144 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1145 struct sk_buff *skb;
1148 void *data, *pnext, *save_pktbuf;
1151 wl_event_msg_t event;
1153 DHD_TRACE(("%s: Enter\n", __func__));
1155 save_pktbuf = pktbuf;
1157 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1159 pnext = PKTNEXT(pktbuf);
1160 PKTSETNEXT(pktbuf, NULL);
1162 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1164 /* Get the protocol, maintain skb around eth_type_trans()
1165 * The main reason for this hack is for the limitation of
1166 * Linux 2.4 where 'eth_type_trans' uses the
1167 * 'net->hard_header_len'
1168 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1169 * coping of the packet coming from the network stack to add
1170 * BDC, Hardware header etc, during network interface
1172 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1174 * for BDC, Hardware header etc. and not just the ETH_HLEN
1179 ifp = dhd->iflist[ifidx];
1181 ifp = dhd->iflist[0];
1184 skb->dev = ifp->net;
1185 skb->protocol = eth_type_trans(skb, skb->dev);
1187 if (skb->pkt_type == PACKET_MULTICAST)
1188 dhd->pub.rx_multicast++;
1193 /* Strip header, count, deliver upward */
1194 skb_pull(skb, ETH_HLEN);
1196 /* Process special event packets and then discard them */
1197 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1198 dhd_wl_host_event(dhd, &ifidx,
1202 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1203 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1204 ifp = dhd->iflist[ifidx];
1207 ifp->net->last_rx = jiffies;
1209 dhdp->dstats.rx_bytes += skb->len;
1210 dhdp->rx_packets++; /* Local count */
1212 if (in_interrupt()) {
1215 /* If the receive is not processed inside an ISR,
1216 * the softirqd must be woken explicitly to service
1217 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1218 * by netif_rx_ni(), but in earlier kernels, we need
1219 * to do it manually.
1226 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1228 /* Linux version has nothing to do */
1232 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1235 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1236 struct ether_header *eh;
1239 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1241 eh = (struct ether_header *)PKTDATA(txp);
1242 type = ntoh16(eh->ether_type);
1244 if (type == ETHER_TYPE_802_1X)
1245 atomic_dec(&dhd->pend_8021x_cnt);
1249 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1251 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1255 DHD_TRACE(("%s: Enter\n", __func__));
1257 ifidx = dhd_net2idx(dhd, net);
1258 if (ifidx == DHD_BAD_IF)
1261 ifp = dhd->iflist[ifidx];
1265 /* Use the protocol to get dongle stats */
1266 dhd_prot_dstats(&dhd->pub);
1269 /* Copy dongle stats to net device stats */
1270 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1271 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1272 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1273 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1274 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1275 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1276 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1277 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1278 ifp->stats.multicast = dhd->pub.dstats.multicast;
1283 static int dhd_watchdog_thread(void *data)
1285 dhd_info_t *dhd = (dhd_info_t *) data;
1286 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1288 /* This thread doesn't need any user-level access,
1289 * so get rid of all our resources
1292 if (dhd_watchdog_prio > 0) {
1293 struct sched_param param;
1294 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1295 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1296 setScheduler(current, SCHED_FIFO, ¶m);
1298 #endif /* DHD_SCHED */
1300 allow_signal(SIGTERM);
1301 /* Run until signal received */
1303 if (kthread_should_stop())
1305 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1306 if (dhd->pub.dongle_reset == false) {
1307 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1308 /* Call the bus module watchdog */
1309 dhd_bus_watchdog(&dhd->pub);
1310 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1312 /* Count the tick for reference */
1318 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1322 static void dhd_watchdog(unsigned long data)
1324 dhd_info_t *dhd = (dhd_info_t *) data;
1326 if (dhd->watchdog_tsk) {
1327 up(&dhd->watchdog_sem);
1329 /* Reschedule the watchdog */
1330 if (dhd->wd_timer_valid) {
1331 mod_timer(&dhd->timer,
1332 jiffies + dhd_watchdog_ms * HZ / 1000);
1337 /* Call the bus module watchdog */
1338 dhd_bus_watchdog(&dhd->pub);
1340 /* Count the tick for reference */
1343 /* Reschedule the watchdog */
1344 if (dhd->wd_timer_valid)
1345 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1348 static int dhd_dpc_thread(void *data)
1350 dhd_info_t *dhd = (dhd_info_t *) data;
1352 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1353 /* This thread doesn't need any user-level access,
1354 * so get rid of all our resources
1357 if (dhd_dpc_prio > 0) {
1358 struct sched_param param;
1359 param.sched_priority =
1361 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1362 setScheduler(current, SCHED_FIFO, ¶m);
1364 #endif /* DHD_SCHED */
1366 allow_signal(SIGTERM);
1367 /* Run until signal received */
1369 if (kthread_should_stop())
1371 if (down_interruptible(&dhd->dpc_sem) == 0) {
1372 /* Call bus dpc unless it indicated down
1373 (then clean stop) */
1374 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1375 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1376 if (dhd_bus_dpc(dhd->pub.bus)) {
1378 WAKE_LOCK_TIMEOUT(&dhd->pub,
1379 WAKE_LOCK_TMOUT, 25);
1381 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1383 dhd_bus_stop(dhd->pub.bus, true);
1389 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1393 static void dhd_dpc(unsigned long data)
1397 dhd = (dhd_info_t *) data;
1399 /* Call bus dpc unless it indicated down (then clean stop) */
1400 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1401 if (dhd_bus_dpc(dhd->pub.bus))
1402 tasklet_schedule(&dhd->tasklet);
1404 dhd_bus_stop(dhd->pub.bus, true);
1408 void dhd_sched_dpc(dhd_pub_t *dhdp)
1410 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1417 tasklet_schedule(&dhd->tasklet);
1421 /* Retrieve current toe component enables, which are kept
1422 as a bitmap in toe_ol iovar */
1423 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1429 memset(&ioc, 0, sizeof(ioc));
1431 ioc.cmd = WLC_GET_VAR;
1433 ioc.len = (uint) sizeof(buf);
1436 strcpy(buf, "toe_ol");
1437 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1439 /* Check for older dongle image that doesn't support toe_ol */
1441 DHD_ERROR(("%s: toe not supported by device\n",
1442 dhd_ifname(&dhd->pub, ifidx)));
1446 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1447 dhd_ifname(&dhd->pub, ifidx), ret));
1451 memcpy(toe_ol, buf, sizeof(u32));
1455 /* Set current toe component enables in toe_ol iovar,
1456 and set toe global enable iovar */
1457 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1463 memset(&ioc, 0, sizeof(ioc));
1465 ioc.cmd = WLC_SET_VAR;
1467 ioc.len = (uint) sizeof(buf);
1470 /* Set toe_ol as requested */
1472 strcpy(buf, "toe_ol");
1473 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1475 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1477 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1478 dhd_ifname(&dhd->pub, ifidx), ret));
1482 /* Enable toe globally only if any components are enabled. */
1484 toe = (toe_ol != 0);
1487 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1489 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1491 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1492 dhd_ifname(&dhd->pub, ifidx), ret));
1500 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1501 struct ethtool_drvinfo *info)
1503 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1505 sprintf(info->driver, DRV_MODULE_NAME);
1506 sprintf(info->version, "%lu", dhd->pub.drv_version);
1507 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1508 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1511 struct ethtool_ops dhd_ethtool_ops = {
1512 .get_drvinfo = dhd_ethtool_get_drvinfo
1515 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1517 struct ethtool_drvinfo info;
1518 char drvname[sizeof(info.driver)];
1521 struct ethtool_value edata;
1522 u32 toe_cmpnt, csum_dir;
1526 DHD_TRACE(("%s: Enter\n", __func__));
1528 /* all ethtool calls start with a cmd word */
1529 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1533 case ETHTOOL_GDRVINFO:
1534 /* Copy out any request driver name */
1535 if (copy_from_user(&info, uaddr, sizeof(info)))
1537 strncpy(drvname, info.driver, sizeof(info.driver));
1538 drvname[sizeof(info.driver) - 1] = '\0';
1540 /* clear struct for return */
1541 memset(&info, 0, sizeof(info));
1544 /* if dhd requested, identify ourselves */
1545 if (strcmp(drvname, "?dhd") == 0) {
1546 sprintf(info.driver, "dhd");
1547 strcpy(info.version, EPI_VERSION_STR);
1550 /* otherwise, require dongle to be up */
1551 else if (!dhd->pub.up) {
1552 DHD_ERROR(("%s: dongle is not up\n", __func__));
1556 /* finally, report dongle driver type */
1557 else if (dhd->pub.iswl)
1558 sprintf(info.driver, "wl");
1560 sprintf(info.driver, "xx");
1562 sprintf(info.version, "%lu", dhd->pub.drv_version);
1563 if (copy_to_user(uaddr, &info, sizeof(info)))
1565 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1566 (int)sizeof(drvname), drvname, info.driver));
1570 /* Get toe offload components from dongle */
1571 case ETHTOOL_GRXCSUM:
1572 case ETHTOOL_GTXCSUM:
1573 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1578 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1581 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1583 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1587 /* Set toe offload components in dongle */
1588 case ETHTOOL_SRXCSUM:
1589 case ETHTOOL_STXCSUM:
1590 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1593 /* Read the current settings, update and write back */
1594 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1599 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1601 if (edata.data != 0)
1602 toe_cmpnt |= csum_dir;
1604 toe_cmpnt &= ~csum_dir;
1606 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1610 /* If setting TX checksum mode, tell Linux the new mode */
1611 if (cmd == ETHTOOL_STXCSUM) {
1613 dhd->iflist[0]->net->features |=
1616 dhd->iflist[0]->net->features &=
1630 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1632 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1639 bool is_set_key_cmd;
1641 ifidx = dhd_net2idx(dhd, net);
1642 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1644 if (ifidx == DHD_BAD_IF)
1647 #if defined(CONFIG_WIRELESS_EXT)
1648 /* linux wireless extensions */
1649 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1650 /* may recurse, do NOT lock */
1651 return wl_iw_ioctl(net, ifr, cmd);
1653 #endif /* defined(CONFIG_WIRELESS_EXT) */
1655 if (cmd == SIOCETHTOOL)
1656 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1658 if (cmd != SIOCDEVPRIVATE)
1661 memset(&ioc, 0, sizeof(ioc));
1663 /* Copy the ioc control structure part of ioctl request */
1664 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1665 bcmerror = -BCME_BADADDR;
1669 /* Copy out any buffer passed */
1671 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1672 /* optimization for direct ioctl calls from kernel */
1674 if (segment_eq(get_fs(), KERNEL_DS)) {
1679 buf = (char *)MALLOC(dhd->pub.osh, buflen);
1681 bcmerror = -BCME_NOMEM;
1684 if (copy_from_user(buf, ioc.buf, buflen)) {
1685 bcmerror = -BCME_BADADDR;
1691 /* To differentiate between wl and dhd read 4 more byes */
1692 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1693 sizeof(uint)) != 0)) {
1694 bcmerror = -BCME_BADADDR;
1698 if (!capable(CAP_NET_ADMIN)) {
1699 bcmerror = -BCME_EPERM;
1703 /* check for local dhd ioctl and handle it */
1704 if (driver == DHD_IOCTL_MAGIC) {
1705 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1707 dhd->pub.bcmerror = bcmerror;
1711 /* send to dongle (must be up, and wl) */
1712 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1713 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1714 bcmerror = BCME_DONGLE_DOWN;
1718 if (!dhd->pub.iswl) {
1719 bcmerror = BCME_DONGLE_DOWN;
1723 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1724 * prevent M4 encryption.
1726 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1727 ((ioc.cmd == WLC_SET_VAR) &&
1728 !(strncmp("wsec_key", ioc.buf, 9))) ||
1729 ((ioc.cmd == WLC_SET_VAR) &&
1730 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1732 dhd_wait_pend8021x(net);
1734 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1735 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1738 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1740 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1741 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1743 if (!bcmerror && buf && ioc.buf) {
1744 if (copy_to_user(ioc.buf, buf, buflen))
1749 MFREE(dhd->pub.osh, buf, buflen);
1751 return OSL_ERROR(bcmerror);
1754 static int dhd_stop(struct net_device *net)
1756 #if !defined(IGNORE_ETH0_DOWN)
1757 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1759 DHD_TRACE(("%s: Enter\n", __func__));
1760 if (IS_CFG80211_FAVORITE()) {
1763 if (dhd->pub.up == 0)
1766 /* Set state and stop OS transmissions */
1768 netif_stop_queue(net);
1770 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1772 #endif /* !defined(IGNORE_ETH0_DOWN) */
1777 static int dhd_open(struct net_device *net)
1779 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1783 int ifidx = dhd_net2idx(dhd, net);
1786 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1788 if (ifidx == 0) { /* do it only for primary eth0 */
1790 /* try to bring up bus */
1791 ret = dhd_bus_start(&dhd->pub);
1793 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1796 atomic_set(&dhd->pend_8021x_cnt, 0);
1798 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1801 /* Get current TOE mode from dongle */
1802 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1803 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1804 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1806 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1809 /* Allow transmit calls */
1810 netif_start_queue(net);
1812 if (IS_CFG80211_FAVORITE()) {
1813 if (unlikely(wl_cfg80211_up())) {
1814 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1823 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1825 return osl_attach(pdev, bustype, true);
1828 void dhd_osl_detach(osl_t *osh)
1830 if (MALLOCED(osh)) {
1831 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1838 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1839 u8 *mac_addr, u32 flags, u8 bssidx)
1843 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1845 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1847 ifp = dhd->iflist[ifidx];
1848 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1849 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1853 memset(ifp, 0, sizeof(dhd_if_t));
1855 dhd->iflist[ifidx] = ifp;
1856 strlcpy(ifp->name, name, IFNAMSIZ);
1857 if (mac_addr != NULL)
1858 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1860 if (handle == NULL) {
1861 ifp->state = WLC_E_IF_ADD;
1863 ASSERT(dhd->sysioc_tsk);
1864 up(&dhd->sysioc_sem);
1866 ifp->net = (struct net_device *)handle;
1871 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1875 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1877 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1878 ifp = dhd->iflist[ifidx];
1880 DHD_ERROR(("%s: Null interface\n", __func__));
1884 ifp->state = WLC_E_IF_DEL;
1886 ASSERT(dhd->sysioc_tsk);
1887 up(&dhd->sysioc_sem);
1890 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1892 dhd_info_t *dhd = NULL;
1893 struct net_device *net;
1895 DHD_TRACE(("%s: Enter\n", __func__));
1896 /* updates firmware nvram path if it was provided as module
1898 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1899 strcpy(fw_path, firmware_path);
1900 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1901 strcpy(nv_path, nvram_path);
1903 /* Allocate etherdev, including space for private structure */
1904 net = alloc_etherdev(sizeof(dhd));
1906 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1910 /* Allocate primary dhd_info */
1911 dhd = MALLOC(osh, sizeof(dhd_info_t));
1913 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1917 memset(dhd, 0, sizeof(dhd_info_t));
1920 * Save the dhd_info into the priv
1922 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1925 /* Set network interface name if it was provided as module parameter */
1926 if (iface_name[0]) {
1929 strncpy(net->name, iface_name, IFNAMSIZ);
1930 net->name[IFNAMSIZ - 1] = 0;
1931 len = strlen(net->name);
1932 ch = net->name[len - 1];
1933 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1934 strcat(net->name, "%d");
1937 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1941 net->netdev_ops = NULL;
1942 init_MUTEX(&dhd->proto_sem);
1943 /* Initialize other structure content */
1944 init_waitqueue_head(&dhd->ioctl_resp_wait);
1945 init_waitqueue_head(&dhd->ctrl_wait);
1947 /* Initialize the spinlocks */
1948 spin_lock_init(&dhd->sdlock);
1949 spin_lock_init(&dhd->txqlock);
1951 /* Link to info module */
1952 dhd->pub.info = dhd;
1954 /* Link to bus module */
1956 dhd->pub.hdrlen = bus_hdrlen;
1958 /* Attach and link in the protocol */
1959 if (dhd_prot_attach(&dhd->pub) != 0) {
1960 DHD_ERROR(("dhd_prot_attach failed\n"));
1963 #if defined(CONFIG_WIRELESS_EXT)
1964 /* Attach and link in the iw */
1965 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1966 DHD_ERROR(("wl_iw_attach failed\n"));
1969 #endif /* defined(CONFIG_WIRELESS_EXT) */
1971 /* Attach and link in the cfg80211 */
1972 if (IS_CFG80211_FAVORITE()) {
1973 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1974 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1978 strcpy(fw_path, wl_cfg80211_get_fwname());
1979 strcpy(nv_path, wl_cfg80211_get_nvramname());
1981 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
1984 /* Set up the watchdog timer */
1985 init_timer(&dhd->timer);
1986 dhd->timer.data = (unsigned long) dhd;
1987 dhd->timer.function = dhd_watchdog;
1989 /* Initialize thread based operation and lock */
1990 init_MUTEX(&dhd->sdsem);
1991 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1992 dhd->threads_only = true;
1994 dhd->threads_only = false;
1996 if (dhd_dpc_prio >= 0) {
1997 /* Initialize watchdog thread */
1998 sema_init(&dhd->watchdog_sem, 0);
1999 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
2001 if (IS_ERR(dhd->watchdog_tsk)) {
2003 "dhd_watchdog thread failed to start\n");
2004 dhd->watchdog_tsk = NULL;
2007 dhd->watchdog_tsk = NULL;
2010 /* Set up the bottom half handler */
2011 if (dhd_dpc_prio >= 0) {
2012 /* Initialize DPC thread */
2013 sema_init(&dhd->dpc_sem, 0);
2014 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
2015 if (IS_ERR(dhd->dpc_tsk)) {
2017 "dhd_dpc thread failed to start\n");
2018 dhd->dpc_tsk = NULL;
2021 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2022 dhd->dpc_tsk = NULL;
2026 sema_init(&dhd->sysioc_sem, 0);
2027 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
2029 if (IS_ERR(dhd->sysioc_tsk)) {
2031 "_dhd_sysioc thread failed to start\n");
2032 dhd->sysioc_tsk = NULL;
2035 dhd->sysioc_tsk = NULL;
2038 * Save the dhd_info into the priv
2040 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2042 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2045 #if defined(CONFIG_PM_SLEEP)
2046 register_pm_notifier(&dhd_sleep_pm_notifier);
2047 #endif /* defined(CONFIG_PM_SLEEP) */
2048 /* && defined(DHD_GPL) */
2049 /* Init lock suspend to prevent kernel going to suspend */
2050 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2051 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2052 "dhd_wake_lock_link_dw_event");
2053 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2054 "dhd_wake_lock_link_pno_find_event");
2055 #ifdef CONFIG_HAS_EARLYSUSPEND
2056 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2057 dhd->early_suspend.suspend = dhd_early_suspend;
2058 dhd->early_suspend.resume = dhd_late_resume;
2059 register_early_suspend(&dhd->early_suspend);
2068 dhd_detach(&dhd->pub);
2073 int dhd_bus_start(dhd_pub_t *dhdp)
2076 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2077 #ifdef EMBEDDED_PLATFORM
2078 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2080 #endif /* EMBEDDED_PLATFORM */
2084 DHD_TRACE(("%s:\n", __func__));
2086 /* try to download image and nvram to the dongle */
2087 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2088 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2089 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2090 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2091 fw_path, nv_path))) {
2092 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2093 "firmware = %s nvram = %s\n",
2094 __func__, fw_path, nv_path));
2095 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2096 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2100 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2101 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2104 /* Start the watchdog timer */
2105 dhd->pub.tickcnt = 0;
2106 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2108 /* Bring up the bus */
2109 ret = dhd_bus_init(&dhd->pub, true);
2111 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2114 #if defined(OOB_INTR_ONLY)
2115 /* Host registration for OOB interrupt */
2116 if (bcmsdh_register_oob_intr(dhdp)) {
2117 del_timer_sync(&dhd->timer);
2118 dhd->wd_timer_valid = false;
2119 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2123 /* Enable oob at firmware */
2124 dhd_enable_oob_intr(dhd->pub.bus, true);
2125 #endif /* defined(OOB_INTR_ONLY) */
2127 /* If bus is not ready, can't come up */
2128 if (dhd->pub.busstate != DHD_BUS_DATA) {
2129 del_timer_sync(&dhd->timer);
2130 dhd->wd_timer_valid = false;
2131 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2134 #ifdef EMBEDDED_PLATFORM
2135 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2137 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2138 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2140 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2141 setbit(dhdp->eventmask, WLC_E_PRUNE);
2142 setbit(dhdp->eventmask, WLC_E_AUTH);
2143 setbit(dhdp->eventmask, WLC_E_REASSOC);
2144 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2145 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2146 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2147 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2148 setbit(dhdp->eventmask, WLC_E_JOIN);
2149 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2150 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2151 setbit(dhdp->eventmask, WLC_E_LINK);
2152 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2153 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2154 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2155 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2156 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2157 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2159 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2160 #endif /* PNO_SUPPORT */
2162 /* enable dongle roaming event */
2164 dhdp->pktfilter_count = 1;
2165 /* Setup filter to allow only unicast */
2166 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2167 #endif /* EMBEDDED_PLATFORM */
2169 /* Bus is ready, do any protocol initialization */
2170 ret = dhd_prot_init(&dhd->pub);
2178 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2181 char buf[strlen(name) + 1 + cmd_len];
2182 int len = sizeof(buf);
2186 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2188 memset(&ioc, 0, sizeof(ioc));
2190 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2195 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2196 if (!set && ret >= 0)
2197 memcpy(cmd_buf, buf, cmd_len);
2202 static struct net_device_ops dhd_ops_pri = {
2203 .ndo_open = dhd_open,
2204 .ndo_stop = dhd_stop,
2205 .ndo_get_stats = dhd_get_stats,
2206 .ndo_do_ioctl = dhd_ioctl_entry,
2207 .ndo_start_xmit = dhd_start_xmit,
2208 .ndo_set_mac_address = dhd_set_mac_address,
2209 .ndo_set_multicast_list = dhd_set_multicast_list
2212 static struct net_device_ops dhd_ops_virt = {
2213 .ndo_get_stats = dhd_get_stats,
2214 .ndo_do_ioctl = dhd_ioctl_entry,
2215 .ndo_start_xmit = dhd_start_xmit,
2216 .ndo_set_mac_address = dhd_set_mac_address,
2217 .ndo_set_multicast_list = dhd_set_multicast_list
2220 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2222 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2223 struct net_device *net;
2224 u8 temp_addr[ETHER_ADDR_LEN] = {
2225 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2227 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2229 ASSERT(dhd && dhd->iflist[ifidx]);
2231 net = dhd->iflist[ifidx]->net;
2234 ASSERT(!net->netdev_ops);
2235 net->netdev_ops = &dhd_ops_virt;
2237 net->netdev_ops = &dhd_ops_pri;
2240 * We have to use the primary MAC for virtual interfaces
2243 /* for virtual interfaces use the primary MAC */
2244 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2249 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2250 /* ACCESSPOINT INTERFACE CASE */
2251 temp_addr[0] |= 0X02; /* set bit 2 ,
2252 - Locally Administered address */
2255 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2256 net->ethtool_ops = &dhd_ethtool_ops;
2258 #if defined(CONFIG_WIRELESS_EXT)
2259 if (!IS_CFG80211_FAVORITE()) {
2260 #if WIRELESS_EXT < 19
2261 net->get_wireless_stats = dhd_get_wireless_stats;
2262 #endif /* WIRELESS_EXT < 19 */
2263 #if WIRELESS_EXT > 12
2264 net->wireless_handlers =
2265 (struct iw_handler_def *)&wl_iw_handler_def;
2266 #endif /* WIRELESS_EXT > 12 */
2268 #endif /* defined(CONFIG_WIRELESS_EXT) */
2270 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2272 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2274 if (register_netdev(net) != 0) {
2275 DHD_ERROR(("%s: couldn't register the net device\n",
2280 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2285 net->netdev_ops = NULL;
2289 void dhd_bus_detach(dhd_pub_t *dhdp)
2293 DHD_TRACE(("%s: Enter\n", __func__));
2296 dhd = (dhd_info_t *) dhdp->info;
2298 /* Stop the protocol module */
2299 dhd_prot_stop(&dhd->pub);
2301 /* Stop the bus module */
2302 dhd_bus_stop(dhd->pub.bus, true);
2303 #if defined(OOB_INTR_ONLY)
2304 bcmsdh_unregister_oob_intr();
2305 #endif /* defined(OOB_INTR_ONLY) */
2307 /* Clear the watchdog timer */
2308 del_timer_sync(&dhd->timer);
2309 dhd->wd_timer_valid = false;
2314 void dhd_detach(dhd_pub_t *dhdp)
2318 DHD_TRACE(("%s: Enter\n", __func__));
2321 dhd = (dhd_info_t *) dhdp->info;
2326 #if defined(CONFIG_HAS_EARLYSUSPEND)
2327 if (dhd->early_suspend.suspend)
2328 unregister_early_suspend(&dhd->early_suspend);
2329 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2331 for (i = 1; i < DHD_MAX_IFS; i++)
2335 ifp = dhd->iflist[0];
2337 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2339 unregister_netdev(ifp->net);
2342 if (dhd->watchdog_tsk) {
2343 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2344 kthread_stop(dhd->watchdog_tsk);
2345 dhd->watchdog_tsk = NULL;
2349 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2350 kthread_stop(dhd->dpc_tsk);
2351 dhd->dpc_tsk = NULL;
2353 tasklet_kill(&dhd->tasklet);
2355 if (dhd->sysioc_tsk) {
2356 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2357 kthread_stop(dhd->sysioc_tsk);
2358 dhd->sysioc_tsk = NULL;
2361 dhd_bus_detach(dhdp);
2364 dhd_prot_detach(dhdp);
2366 #if defined(CONFIG_WIRELESS_EXT)
2368 #endif /* (CONFIG_WIRELESS_EXT) */
2370 if (IS_CFG80211_FAVORITE())
2371 wl_cfg80211_detach();
2373 #if defined(CONFIG_PM_SLEEP)
2374 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2375 #endif /* defined(CONFIG_PM_SLEEP) */
2376 /* && defined(DHD_GPL) */
2377 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2378 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2379 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2380 free_netdev(ifp->net);
2381 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2382 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2387 static void __exit dhd_module_cleanup(void)
2389 DHD_TRACE(("%s: Enter\n", __func__));
2391 dhd_bus_unregister();
2392 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2395 /* Call customer gpio to turn off power with WL_REG_ON signal */
2396 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2399 static int __init dhd_module_init(void)
2403 DHD_TRACE(("%s: Enter\n", __func__));
2405 /* Sanity check on the module parameters */
2407 /* Both watchdog and DPC as tasklets are ok */
2408 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2411 /* If both watchdog and DPC are threads, TX must be deferred */
2412 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2416 DHD_ERROR(("Invalid module parameters.\n"));
2419 /* Call customer gpio to turn on power with WL_REG_ON signal */
2420 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2422 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2423 sema_init(&wifi_control_sem, 0);
2425 error = wifi_add_dev();
2427 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2431 /* Waiting callback after platform_driver_register is done or
2433 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2434 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2440 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2442 error = dhd_bus_register();
2445 printf("\n%s\n", dhd_version);
2447 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2453 /* turn off power and exit */
2454 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2458 module_init(dhd_module_init);
2459 module_exit(dhd_module_cleanup);
2462 * OS specific functions required to implement DHD driver in OS independent way
2464 int dhd_os_proto_block(dhd_pub_t *pub)
2466 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2469 down(&dhd->proto_sem);
2475 int dhd_os_proto_unblock(dhd_pub_t *pub)
2477 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2480 up(&dhd->proto_sem);
2487 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2489 return (unsigned int)dhd_ioctl_timeout_msec;
2492 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2494 dhd_ioctl_timeout_msec = (int)timeout_msec;
2497 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2499 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2500 DECLARE_WAITQUEUE(wait, current);
2501 int timeout = dhd_ioctl_timeout_msec;
2503 /* Convert timeout in millsecond to jiffies */
2504 timeout = timeout * HZ / 1000;
2506 /* Wait until control frame is available */
2507 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2508 set_current_state(TASK_INTERRUPTIBLE);
2510 while (!(*condition) && (!signal_pending(current) && timeout))
2511 timeout = schedule_timeout(timeout);
2513 if (signal_pending(current))
2516 set_current_state(TASK_RUNNING);
2517 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2522 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2524 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2526 if (waitqueue_active(&dhd->ioctl_resp_wait))
2527 wake_up_interruptible(&dhd->ioctl_resp_wait);
2532 void dhd_os_wd_timer(void *bus, uint wdtick)
2534 dhd_pub_t *pub = bus;
2535 static uint save_dhd_watchdog_ms;
2536 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2538 /* don't start the wd until fw is loaded */
2539 if (pub->busstate == DHD_BUS_DOWN)
2542 /* Totally stop the timer */
2543 if (!wdtick && dhd->wd_timer_valid == true) {
2544 del_timer_sync(&dhd->timer);
2545 dhd->wd_timer_valid = false;
2546 save_dhd_watchdog_ms = wdtick;
2551 dhd_watchdog_ms = (uint) wdtick;
2553 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2555 if (dhd->wd_timer_valid == true)
2556 /* Stop timer and restart at new value */
2557 del_timer_sync(&dhd->timer);
2559 /* Create timer again when watchdog period is
2560 dynamically changed or in the first instance
2562 dhd->timer.expires =
2563 jiffies + dhd_watchdog_ms * HZ / 1000;
2564 add_timer(&dhd->timer);
2567 /* Re arm the timer, at last watchdog period */
2568 mod_timer(&dhd->timer,
2569 jiffies + dhd_watchdog_ms * HZ / 1000);
2572 dhd->wd_timer_valid = true;
2573 save_dhd_watchdog_ms = wdtick;
2577 void *dhd_os_open_image(char *filename)
2581 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2582 return wl_cfg80211_request_fw(filename);
2584 fp = filp_open(filename, O_RDONLY, 0);
2586 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2588 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2597 int dhd_os_get_image_block(char *buf, int len, void *image)
2599 struct file *fp = (struct file *)image;
2602 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2603 return wl_cfg80211_read_fw(buf, len);
2608 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2615 void dhd_os_close_image(void *image)
2617 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2618 return wl_cfg80211_release_fw();
2620 filp_close((struct file *)image, NULL);
2623 void dhd_os_sdlock(dhd_pub_t *pub)
2627 dhd = (dhd_info_t *) (pub->info);
2629 if (dhd->threads_only)
2632 spin_lock_bh(&dhd->sdlock);
2635 void dhd_os_sdunlock(dhd_pub_t *pub)
2639 dhd = (dhd_info_t *) (pub->info);
2641 if (dhd->threads_only)
2644 spin_unlock_bh(&dhd->sdlock);
2647 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2651 dhd = (dhd_info_t *) (pub->info);
2652 spin_lock_bh(&dhd->txqlock);
2655 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2659 dhd = (dhd_info_t *) (pub->info);
2660 spin_unlock_bh(&dhd->txqlock);
2663 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2667 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2671 void dhd_os_sdtxlock(dhd_pub_t *pub)
2676 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2678 dhd_os_sdunlock(pub);
2681 #if defined(CONFIG_WIRELESS_EXT)
2682 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2685 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2687 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2690 return &dhd->iw.wstats;
2694 #endif /* defined(CONFIG_WIRELESS_EXT) */
2697 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2698 wl_event_msg_t *event, void **data)
2702 ASSERT(dhd != NULL);
2704 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2705 if (bcmerror != BCME_OK)
2708 #if defined(CONFIG_WIRELESS_EXT)
2709 if (!IS_CFG80211_FAVORITE()) {
2710 if ((dhd->iflist[*ifidx] == NULL)
2711 || (dhd->iflist[*ifidx]->net == NULL)) {
2712 DHD_ERROR(("%s Exit null pointer\n", __func__));
2716 if (dhd->iflist[*ifidx]->net)
2717 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2719 #endif /* defined(CONFIG_WIRELESS_EXT) */
2721 if (IS_CFG80211_FAVORITE()) {
2722 ASSERT(dhd->iflist[*ifidx] != NULL);
2723 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2724 if (dhd->iflist[*ifidx]->net)
2725 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2732 /* send up locally generated event */
2733 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2735 switch (ntoh32(event->event_type)) {
2741 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2743 struct dhd_info *dhdinfo = dhd->info;
2744 dhd_os_sdunlock(dhd);
2745 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2746 (*lockvar == false), HZ * 2);
2751 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2753 struct dhd_info *dhdinfo = dhd->info;
2754 if (waitqueue_active(&dhdinfo->ctrl_wait))
2755 wake_up_interruptible(&dhdinfo->ctrl_wait);
2759 int dhd_dev_reset(struct net_device *dev, u8 flag)
2761 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2763 /* Turning off watchdog */
2765 dhd_os_wd_timer(&dhd->pub, 0);
2767 dhd_bus_devreset(&dhd->pub, flag);
2769 /* Turning on watchdog back */
2771 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2772 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2777 int net_os_set_suspend_disable(struct net_device *dev, int val)
2779 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2783 ret = dhd->pub.suspend_disable_flag;
2784 dhd->pub.suspend_disable_flag = val;
2789 int net_os_set_suspend(struct net_device *dev, int val)
2792 #if defined(CONFIG_HAS_EARLYSUSPEND)
2793 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2796 dhd_os_proto_block(&dhd->pub);
2797 ret = dhd_set_suspend(val, &dhd->pub);
2798 dhd_os_proto_unblock(&dhd->pub);
2800 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2804 int net_os_set_dtim_skip(struct net_device *dev, int val)
2806 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2809 dhd->pub.dtim_skip = val;
2814 int net_os_set_packet_filter(struct net_device *dev, int val)
2816 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2819 /* Packet filtering is set only if we still in early-suspend and
2820 * we need either to turn it ON or turn it OFF
2821 * We can always turn it OFF in case of early-suspend, but we turn it
2822 * back ON only if suspend_disable_flag was not set
2824 if (dhd && dhd->pub.up) {
2825 dhd_os_proto_block(&dhd->pub);
2826 if (dhd->pub.in_suspend) {
2827 if (!val || (val && !dhd->pub.suspend_disable_flag))
2828 dhd_set_packet_filter(val, &dhd->pub);
2830 dhd_os_proto_unblock(&dhd->pub);
2835 void dhd_dev_init_ioctl(struct net_device *dev)
2837 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2839 dhd_preinit_ioctls(&dhd->pub);
2843 /* Linux wrapper to call common dhd_pno_clean */
2844 int dhd_dev_pno_reset(struct net_device *dev)
2846 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2848 return dhd_pno_clean(&dhd->pub);
2851 /* Linux wrapper to call common dhd_pno_enable */
2852 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2854 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2856 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2859 /* Linux wrapper to call common dhd_pno_set */
2861 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2862 unsigned char scan_fr)
2864 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2866 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2869 /* Linux wrapper to get pno status */
2870 int dhd_dev_get_pno_status(struct net_device *dev)
2872 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2874 return dhd_pno_get_status(&dhd->pub);
2877 #endif /* PNO_SUPPORT */
2879 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2881 return atomic_read(&dhd->pend_8021x_cnt);
2884 #define MAX_WAIT_FOR_8021X_TX 10
2886 int dhd_wait_pend8021x(struct net_device *dev)
2888 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2889 int timeout = 10 * HZ / 1000;
2890 int ntimes = MAX_WAIT_FOR_8021X_TX;
2891 int pend = dhd_get_pend_8021x_cnt(dhd);
2893 while (ntimes && pend) {
2895 set_current_state(TASK_INTERRUPTIBLE);
2896 schedule_timeout(timeout);
2897 set_current_state(TASK_RUNNING);
2900 pend = dhd_get_pend_8021x_cnt(dhd);
2906 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2910 mm_segment_t old_fs;
2913 /* change to KERNEL_DS address limit */
2917 /* open file to write */
2918 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2920 printf("%s: open file error\n", __func__);
2925 /* Write buf to file */
2926 fp->f_op->write(fp, buf, size, &pos);
2929 /* free buf before return */
2930 MFREE(dhd->osh, buf, size);
2931 /* close file before return */
2933 filp_close(fp, current->files);
2934 /* restore previous address limit */
2939 #endif /* DHD_DEBUG */