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 OSL_DELAY(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 while (down_interruptible(&dhd->sysioc_sem) == 0) {
942 if (kthread_should_stop())
944 for (i = 0; i < DHD_MAX_IFS; i++) {
945 if (dhd->iflist[i]) {
947 in_ap = (ap_net_dev != NULL);
949 if (dhd->iflist[i]->state)
950 dhd_op_if(dhd->iflist[i]);
952 if (dhd->iflist[i] == NULL) {
953 DHD_TRACE(("\n\n %s: interface %d "
954 "removed!\n", __func__, i));
958 if (in_ap && dhd->set_macaddress) {
959 DHD_TRACE(("attempt to set MAC for %s "
960 "in AP Mode," "blocked. \n",
961 dhd->iflist[i]->net->name));
962 dhd->set_macaddress = false;
966 if (in_ap && dhd->set_multicast) {
967 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
968 dhd->iflist[i]->net->name));
969 dhd->set_multicast = false;
973 if (dhd->set_multicast) {
974 dhd->set_multicast = false;
975 _dhd_set_multicast_list(dhd, i);
977 if (dhd->set_macaddress) {
978 dhd->set_macaddress = false;
979 _dhd_set_mac_address(dhd, i,
988 static int dhd_set_mac_address(struct net_device *dev, void *addr)
992 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
993 struct sockaddr *sa = (struct sockaddr *)addr;
996 ifidx = dhd_net2idx(dhd, dev);
997 if (ifidx == DHD_BAD_IF)
1000 ASSERT(dhd->sysioc_tsk);
1001 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1002 dhd->set_macaddress = true;
1003 up(&dhd->sysioc_sem);
1008 static void dhd_set_multicast_list(struct net_device *dev)
1010 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1013 ifidx = dhd_net2idx(dhd, dev);
1014 if (ifidx == DHD_BAD_IF)
1017 ASSERT(dhd->sysioc_tsk);
1018 dhd->set_multicast = true;
1019 up(&dhd->sysioc_sem);
1022 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1025 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1027 /* Reject if down */
1028 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1031 /* Update multicast statistic */
1032 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1033 u8 *pktdata = (u8 *) PKTDATA(pktbuf);
1034 struct ether_header *eh = (struct ether_header *)pktdata;
1036 if (ETHER_ISMULTI(eh->ether_dhost))
1037 dhdp->tx_multicast++;
1038 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1039 atomic_inc(&dhd->pend_8021x_cnt);
1042 /* Look into the packet and update the packet priority */
1043 if ((PKTPRIO(pktbuf) == 0))
1044 pktsetprio(pktbuf, false);
1046 /* If the protocol uses a data header, apply it */
1047 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1049 /* Use bus module to send data frame */
1051 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1053 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1054 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1055 #endif /* BCMDBUS */
1060 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1064 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1067 DHD_TRACE(("%s: Enter\n", __func__));
1069 /* Reject if down */
1070 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1071 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1072 __func__, dhd->pub.up, dhd->pub.busstate));
1073 netif_stop_queue(net);
1077 ifidx = dhd_net2idx(dhd, net);
1078 if (ifidx == DHD_BAD_IF) {
1079 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1080 netif_stop_queue(net);
1084 /* Make sure there's enough room for any header */
1085 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1086 struct sk_buff *skb2;
1088 DHD_INFO(("%s: insufficient headroom\n",
1089 dhd_ifname(&dhd->pub, ifidx)));
1090 dhd->pub.tx_realloc++;
1091 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1095 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1096 dhd_ifname(&dhd->pub, ifidx)));
1102 /* Convert to packet */
1103 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1105 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1106 dhd_ifname(&dhd->pub, ifidx)));
1107 dev_kfree_skb_any(skb);
1112 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1116 dhd->pub.dstats.tx_dropped++;
1118 dhd->pub.tx_packets++;
1120 /* Return ok: we always eat the packet */
1124 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1126 struct net_device *net;
1127 dhd_info_t *dhd = dhdp->info;
1129 DHD_TRACE(("%s: Enter\n", __func__));
1131 dhdp->txoff = state;
1132 ASSERT(dhd && dhd->iflist[ifidx]);
1133 net = dhd->iflist[ifidx]->net;
1135 netif_stop_queue(net);
1137 netif_wake_queue(net);
1140 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1142 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1143 struct sk_buff *skb;
1146 void *data, *pnext, *save_pktbuf;
1149 wl_event_msg_t event;
1151 DHD_TRACE(("%s: Enter\n", __func__));
1153 save_pktbuf = pktbuf;
1155 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1157 pnext = PKTNEXT(pktbuf);
1158 PKTSETNEXT(pktbuf, NULL);
1160 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1162 /* Get the protocol, maintain skb around eth_type_trans()
1163 * The main reason for this hack is for the limitation of
1164 * Linux 2.4 where 'eth_type_trans' uses the
1165 * 'net->hard_header_len'
1166 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1167 * coping of the packet coming from the network stack to add
1168 * BDC, Hardware header etc, during network interface
1170 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1172 * for BDC, Hardware header etc. and not just the ETH_HLEN
1177 ifp = dhd->iflist[ifidx];
1179 ifp = dhd->iflist[0];
1182 skb->dev = ifp->net;
1183 skb->protocol = eth_type_trans(skb, skb->dev);
1185 if (skb->pkt_type == PACKET_MULTICAST)
1186 dhd->pub.rx_multicast++;
1191 /* Strip header, count, deliver upward */
1192 skb_pull(skb, ETH_HLEN);
1194 /* Process special event packets and then discard them */
1195 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1196 dhd_wl_host_event(dhd, &ifidx,
1200 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1201 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1202 ifp = dhd->iflist[ifidx];
1205 ifp->net->last_rx = jiffies;
1207 dhdp->dstats.rx_bytes += skb->len;
1208 dhdp->rx_packets++; /* Local count */
1210 if (in_interrupt()) {
1213 /* If the receive is not processed inside an ISR,
1214 * the softirqd must be woken explicitly to service
1215 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1216 * by netif_rx_ni(), but in earlier kernels, we need
1217 * to do it manually.
1224 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1226 /* Linux version has nothing to do */
1230 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1233 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1234 struct ether_header *eh;
1237 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1239 eh = (struct ether_header *)PKTDATA(txp);
1240 type = ntoh16(eh->ether_type);
1242 if (type == ETHER_TYPE_802_1X)
1243 atomic_dec(&dhd->pend_8021x_cnt);
1247 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1249 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1253 DHD_TRACE(("%s: Enter\n", __func__));
1255 ifidx = dhd_net2idx(dhd, net);
1256 if (ifidx == DHD_BAD_IF)
1259 ifp = dhd->iflist[ifidx];
1263 /* Use the protocol to get dongle stats */
1264 dhd_prot_dstats(&dhd->pub);
1267 /* Copy dongle stats to net device stats */
1268 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1269 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1270 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1271 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1272 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1273 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1274 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1275 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1276 ifp->stats.multicast = dhd->pub.dstats.multicast;
1281 static int dhd_watchdog_thread(void *data)
1283 dhd_info_t *dhd = (dhd_info_t *) data;
1284 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1286 /* This thread doesn't need any user-level access,
1287 * so get rid of all our resources
1290 if (dhd_watchdog_prio > 0) {
1291 struct sched_param param;
1292 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1293 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1294 setScheduler(current, SCHED_FIFO, ¶m);
1296 #endif /* DHD_SCHED */
1298 /* Run until signal received */
1300 if (kthread_should_stop())
1302 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1303 if (dhd->pub.dongle_reset == false) {
1304 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1305 /* Call the bus module watchdog */
1306 dhd_bus_watchdog(&dhd->pub);
1307 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1309 /* Count the tick for reference */
1315 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1319 static void dhd_watchdog(unsigned long data)
1321 dhd_info_t *dhd = (dhd_info_t *) data;
1323 if (dhd->watchdog_tsk) {
1324 up(&dhd->watchdog_sem);
1326 /* Reschedule the watchdog */
1327 if (dhd->wd_timer_valid) {
1328 mod_timer(&dhd->timer,
1329 jiffies + dhd_watchdog_ms * HZ / 1000);
1334 /* Call the bus module watchdog */
1335 dhd_bus_watchdog(&dhd->pub);
1337 /* Count the tick for reference */
1340 /* Reschedule the watchdog */
1341 if (dhd->wd_timer_valid)
1342 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1345 static int dhd_dpc_thread(void *data)
1347 dhd_info_t *dhd = (dhd_info_t *) data;
1349 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1350 /* This thread doesn't need any user-level access,
1351 * so get rid of all our resources
1354 if (dhd_dpc_prio > 0) {
1355 struct sched_param param;
1356 param.sched_priority =
1358 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1359 setScheduler(current, SCHED_FIFO, ¶m);
1361 #endif /* DHD_SCHED */
1363 /* Run until signal received */
1365 if (kthread_should_stop())
1367 if (down_interruptible(&dhd->dpc_sem) == 0) {
1368 /* Call bus dpc unless it indicated down
1369 (then clean stop) */
1370 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1371 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1372 if (dhd_bus_dpc(dhd->pub.bus)) {
1374 WAKE_LOCK_TIMEOUT(&dhd->pub,
1375 WAKE_LOCK_TMOUT, 25);
1377 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1379 dhd_bus_stop(dhd->pub.bus, true);
1385 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1389 static void dhd_dpc(unsigned long data)
1393 dhd = (dhd_info_t *) data;
1395 /* Call bus dpc unless it indicated down (then clean stop) */
1396 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1397 if (dhd_bus_dpc(dhd->pub.bus))
1398 tasklet_schedule(&dhd->tasklet);
1400 dhd_bus_stop(dhd->pub.bus, true);
1404 void dhd_sched_dpc(dhd_pub_t *dhdp)
1406 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1413 tasklet_schedule(&dhd->tasklet);
1417 /* Retrieve current toe component enables, which are kept
1418 as a bitmap in toe_ol iovar */
1419 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1425 memset(&ioc, 0, sizeof(ioc));
1427 ioc.cmd = WLC_GET_VAR;
1429 ioc.len = (uint) sizeof(buf);
1432 strcpy(buf, "toe_ol");
1433 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1435 /* Check for older dongle image that doesn't support toe_ol */
1437 DHD_ERROR(("%s: toe not supported by device\n",
1438 dhd_ifname(&dhd->pub, ifidx)));
1442 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1443 dhd_ifname(&dhd->pub, ifidx), ret));
1447 memcpy(toe_ol, buf, sizeof(u32));
1451 /* Set current toe component enables in toe_ol iovar,
1452 and set toe global enable iovar */
1453 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1459 memset(&ioc, 0, sizeof(ioc));
1461 ioc.cmd = WLC_SET_VAR;
1463 ioc.len = (uint) sizeof(buf);
1466 /* Set toe_ol as requested */
1468 strcpy(buf, "toe_ol");
1469 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1471 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1473 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1474 dhd_ifname(&dhd->pub, ifidx), ret));
1478 /* Enable toe globally only if any components are enabled. */
1480 toe = (toe_ol != 0);
1483 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1485 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1487 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1488 dhd_ifname(&dhd->pub, ifidx), ret));
1496 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1497 struct ethtool_drvinfo *info)
1499 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1501 sprintf(info->driver, DRV_MODULE_NAME);
1502 sprintf(info->version, "%lu", dhd->pub.drv_version);
1503 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1504 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1507 struct ethtool_ops dhd_ethtool_ops = {
1508 .get_drvinfo = dhd_ethtool_get_drvinfo
1511 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1513 struct ethtool_drvinfo info;
1514 char drvname[sizeof(info.driver)];
1517 struct ethtool_value edata;
1518 u32 toe_cmpnt, csum_dir;
1522 DHD_TRACE(("%s: Enter\n", __func__));
1524 /* all ethtool calls start with a cmd word */
1525 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1529 case ETHTOOL_GDRVINFO:
1530 /* Copy out any request driver name */
1531 if (copy_from_user(&info, uaddr, sizeof(info)))
1533 strncpy(drvname, info.driver, sizeof(info.driver));
1534 drvname[sizeof(info.driver) - 1] = '\0';
1536 /* clear struct for return */
1537 memset(&info, 0, sizeof(info));
1540 /* if dhd requested, identify ourselves */
1541 if (strcmp(drvname, "?dhd") == 0) {
1542 sprintf(info.driver, "dhd");
1543 strcpy(info.version, EPI_VERSION_STR);
1546 /* otherwise, require dongle to be up */
1547 else if (!dhd->pub.up) {
1548 DHD_ERROR(("%s: dongle is not up\n", __func__));
1552 /* finally, report dongle driver type */
1553 else if (dhd->pub.iswl)
1554 sprintf(info.driver, "wl");
1556 sprintf(info.driver, "xx");
1558 sprintf(info.version, "%lu", dhd->pub.drv_version);
1559 if (copy_to_user(uaddr, &info, sizeof(info)))
1561 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1562 (int)sizeof(drvname), drvname, info.driver));
1566 /* Get toe offload components from dongle */
1567 case ETHTOOL_GRXCSUM:
1568 case ETHTOOL_GTXCSUM:
1569 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1574 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1577 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1579 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1583 /* Set toe offload components in dongle */
1584 case ETHTOOL_SRXCSUM:
1585 case ETHTOOL_STXCSUM:
1586 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1589 /* Read the current settings, update and write back */
1590 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1595 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1597 if (edata.data != 0)
1598 toe_cmpnt |= csum_dir;
1600 toe_cmpnt &= ~csum_dir;
1602 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1606 /* If setting TX checksum mode, tell Linux the new mode */
1607 if (cmd == ETHTOOL_STXCSUM) {
1609 dhd->iflist[0]->net->features |=
1612 dhd->iflist[0]->net->features &=
1626 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1628 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1635 bool is_set_key_cmd;
1637 ifidx = dhd_net2idx(dhd, net);
1638 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1640 if (ifidx == DHD_BAD_IF)
1643 #if defined(CONFIG_WIRELESS_EXT)
1644 /* linux wireless extensions */
1645 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1646 /* may recurse, do NOT lock */
1647 return wl_iw_ioctl(net, ifr, cmd);
1649 #endif /* defined(CONFIG_WIRELESS_EXT) */
1651 if (cmd == SIOCETHTOOL)
1652 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1654 if (cmd != SIOCDEVPRIVATE)
1657 memset(&ioc, 0, sizeof(ioc));
1659 /* Copy the ioc control structure part of ioctl request */
1660 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1661 bcmerror = -BCME_BADADDR;
1665 /* Copy out any buffer passed */
1667 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1668 /* optimization for direct ioctl calls from kernel */
1670 if (segment_eq(get_fs(), KERNEL_DS)) {
1675 buf = (char *)MALLOC(dhd->pub.osh, buflen);
1677 bcmerror = -BCME_NOMEM;
1680 if (copy_from_user(buf, ioc.buf, buflen)) {
1681 bcmerror = -BCME_BADADDR;
1687 /* To differentiate between wl and dhd read 4 more byes */
1688 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1689 sizeof(uint)) != 0)) {
1690 bcmerror = -BCME_BADADDR;
1694 if (!capable(CAP_NET_ADMIN)) {
1695 bcmerror = -BCME_EPERM;
1699 /* check for local dhd ioctl and handle it */
1700 if (driver == DHD_IOCTL_MAGIC) {
1701 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1703 dhd->pub.bcmerror = bcmerror;
1707 /* send to dongle (must be up, and wl) */
1708 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1709 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1710 bcmerror = BCME_DONGLE_DOWN;
1714 if (!dhd->pub.iswl) {
1715 bcmerror = BCME_DONGLE_DOWN;
1719 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1720 * prevent M4 encryption.
1722 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1723 ((ioc.cmd == WLC_SET_VAR) &&
1724 !(strncmp("wsec_key", ioc.buf, 9))) ||
1725 ((ioc.cmd == WLC_SET_VAR) &&
1726 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1728 dhd_wait_pend8021x(net);
1730 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1731 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1734 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1736 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1737 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1739 if (!bcmerror && buf && ioc.buf) {
1740 if (copy_to_user(ioc.buf, buf, buflen))
1745 MFREE(dhd->pub.osh, buf, buflen);
1747 return OSL_ERROR(bcmerror);
1750 static int dhd_stop(struct net_device *net)
1752 #if !defined(IGNORE_ETH0_DOWN)
1753 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1755 DHD_TRACE(("%s: Enter\n", __func__));
1756 if (IS_CFG80211_FAVORITE()) {
1759 if (dhd->pub.up == 0)
1762 /* Set state and stop OS transmissions */
1764 netif_stop_queue(net);
1766 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1768 #endif /* !defined(IGNORE_ETH0_DOWN) */
1773 static int dhd_open(struct net_device *net)
1775 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1779 int ifidx = dhd_net2idx(dhd, net);
1782 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1784 if (ifidx == 0) { /* do it only for primary eth0 */
1786 /* try to bring up bus */
1787 ret = dhd_bus_start(&dhd->pub);
1789 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1792 atomic_set(&dhd->pend_8021x_cnt, 0);
1794 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1797 /* Get current TOE mode from dongle */
1798 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1799 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1800 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1802 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1805 /* Allow transmit calls */
1806 netif_start_queue(net);
1808 if (IS_CFG80211_FAVORITE()) {
1809 if (unlikely(wl_cfg80211_up())) {
1810 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1819 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1821 return osl_attach(pdev, bustype, true);
1824 void dhd_osl_detach(osl_t *osh)
1826 if (MALLOCED(osh)) {
1827 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1834 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1835 u8 *mac_addr, u32 flags, u8 bssidx)
1839 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1841 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1843 ifp = dhd->iflist[ifidx];
1844 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1845 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1849 memset(ifp, 0, sizeof(dhd_if_t));
1851 dhd->iflist[ifidx] = ifp;
1852 strlcpy(ifp->name, name, IFNAMSIZ);
1853 if (mac_addr != NULL)
1854 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1856 if (handle == NULL) {
1857 ifp->state = WLC_E_IF_ADD;
1859 ASSERT(dhd->sysioc_tsk);
1860 up(&dhd->sysioc_sem);
1862 ifp->net = (struct net_device *)handle;
1867 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1871 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1873 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1874 ifp = dhd->iflist[ifidx];
1876 DHD_ERROR(("%s: Null interface\n", __func__));
1880 ifp->state = WLC_E_IF_DEL;
1882 ASSERT(dhd->sysioc_tsk);
1883 up(&dhd->sysioc_sem);
1886 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1888 dhd_info_t *dhd = NULL;
1889 struct net_device *net;
1891 DHD_TRACE(("%s: Enter\n", __func__));
1892 /* updates firmware nvram path if it was provided as module
1894 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1895 strcpy(fw_path, firmware_path);
1896 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1897 strcpy(nv_path, nvram_path);
1899 /* Allocate etherdev, including space for private structure */
1900 net = alloc_etherdev(sizeof(dhd));
1902 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1906 /* Allocate primary dhd_info */
1907 dhd = MALLOC(osh, sizeof(dhd_info_t));
1909 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1913 memset(dhd, 0, sizeof(dhd_info_t));
1916 * Save the dhd_info into the priv
1918 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1921 /* Set network interface name if it was provided as module parameter */
1922 if (iface_name[0]) {
1925 strncpy(net->name, iface_name, IFNAMSIZ);
1926 net->name[IFNAMSIZ - 1] = 0;
1927 len = strlen(net->name);
1928 ch = net->name[len - 1];
1929 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1930 strcat(net->name, "%d");
1933 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1937 net->netdev_ops = NULL;
1938 init_MUTEX(&dhd->proto_sem);
1939 /* Initialize other structure content */
1940 init_waitqueue_head(&dhd->ioctl_resp_wait);
1941 init_waitqueue_head(&dhd->ctrl_wait);
1943 /* Initialize the spinlocks */
1944 spin_lock_init(&dhd->sdlock);
1945 spin_lock_init(&dhd->txqlock);
1947 /* Link to info module */
1948 dhd->pub.info = dhd;
1950 /* Link to bus module */
1952 dhd->pub.hdrlen = bus_hdrlen;
1954 /* Attach and link in the protocol */
1955 if (dhd_prot_attach(&dhd->pub) != 0) {
1956 DHD_ERROR(("dhd_prot_attach failed\n"));
1959 #if defined(CONFIG_WIRELESS_EXT)
1960 /* Attach and link in the iw */
1961 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1962 DHD_ERROR(("wl_iw_attach failed\n"));
1965 #endif /* defined(CONFIG_WIRELESS_EXT) */
1967 /* Attach and link in the cfg80211 */
1968 if (IS_CFG80211_FAVORITE()) {
1969 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1970 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1974 strcpy(fw_path, wl_cfg80211_get_fwname());
1975 strcpy(nv_path, wl_cfg80211_get_nvramname());
1977 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
1980 /* Set up the watchdog timer */
1981 init_timer(&dhd->timer);
1982 dhd->timer.data = (unsigned long) dhd;
1983 dhd->timer.function = dhd_watchdog;
1985 /* Initialize thread based operation and lock */
1986 init_MUTEX(&dhd->sdsem);
1987 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1988 dhd->threads_only = true;
1990 dhd->threads_only = false;
1992 if (dhd_dpc_prio >= 0) {
1993 /* Initialize watchdog thread */
1994 sema_init(&dhd->watchdog_sem, 0);
1995 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1997 if (IS_ERR(dhd->watchdog_tsk)) {
1999 "dhd_watchdog thread failed to start\n");
2000 dhd->watchdog_tsk = NULL;
2003 dhd->watchdog_tsk = NULL;
2006 /* Set up the bottom half handler */
2007 if (dhd_dpc_prio >= 0) {
2008 /* Initialize DPC thread */
2009 sema_init(&dhd->dpc_sem, 0);
2010 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
2011 if (IS_ERR(dhd->dpc_tsk)) {
2013 "dhd_dpc thread failed to start\n");
2014 dhd->dpc_tsk = NULL;
2017 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2018 dhd->dpc_tsk = NULL;
2022 sema_init(&dhd->sysioc_sem, 0);
2023 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
2025 if (IS_ERR(dhd->sysioc_tsk)) {
2027 "_dhd_sysioc thread failed to start\n");
2028 dhd->sysioc_tsk = NULL;
2031 dhd->sysioc_tsk = NULL;
2034 * Save the dhd_info into the priv
2036 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2038 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2041 #if defined(CONFIG_PM_SLEEP)
2042 register_pm_notifier(&dhd_sleep_pm_notifier);
2043 #endif /* defined(CONFIG_PM_SLEEP) */
2044 /* && defined(DHD_GPL) */
2045 /* Init lock suspend to prevent kernel going to suspend */
2046 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2047 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2048 "dhd_wake_lock_link_dw_event");
2049 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2050 "dhd_wake_lock_link_pno_find_event");
2051 #ifdef CONFIG_HAS_EARLYSUSPEND
2052 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2053 dhd->early_suspend.suspend = dhd_early_suspend;
2054 dhd->early_suspend.resume = dhd_late_resume;
2055 register_early_suspend(&dhd->early_suspend);
2064 dhd_detach(&dhd->pub);
2069 int dhd_bus_start(dhd_pub_t *dhdp)
2072 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2073 #ifdef EMBEDDED_PLATFORM
2074 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2076 #endif /* EMBEDDED_PLATFORM */
2080 DHD_TRACE(("%s:\n", __func__));
2082 /* try to download image and nvram to the dongle */
2083 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2084 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2085 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2086 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2087 fw_path, nv_path))) {
2088 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2089 "firmware = %s nvram = %s\n",
2090 __func__, fw_path, nv_path));
2091 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2092 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2096 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2097 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2100 /* Start the watchdog timer */
2101 dhd->pub.tickcnt = 0;
2102 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2104 /* Bring up the bus */
2105 ret = dhd_bus_init(&dhd->pub, true);
2107 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2110 #if defined(OOB_INTR_ONLY)
2111 /* Host registration for OOB interrupt */
2112 if (bcmsdh_register_oob_intr(dhdp)) {
2113 del_timer_sync(&dhd->timer);
2114 dhd->wd_timer_valid = false;
2115 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2119 /* Enable oob at firmware */
2120 dhd_enable_oob_intr(dhd->pub.bus, true);
2121 #endif /* defined(OOB_INTR_ONLY) */
2123 /* If bus is not ready, can't come up */
2124 if (dhd->pub.busstate != DHD_BUS_DATA) {
2125 del_timer_sync(&dhd->timer);
2126 dhd->wd_timer_valid = false;
2127 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2130 #ifdef EMBEDDED_PLATFORM
2131 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2133 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2134 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2136 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2137 setbit(dhdp->eventmask, WLC_E_PRUNE);
2138 setbit(dhdp->eventmask, WLC_E_AUTH);
2139 setbit(dhdp->eventmask, WLC_E_REASSOC);
2140 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2141 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2142 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2143 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2144 setbit(dhdp->eventmask, WLC_E_JOIN);
2145 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2146 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2147 setbit(dhdp->eventmask, WLC_E_LINK);
2148 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2149 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2150 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2151 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2152 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2153 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2155 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2156 #endif /* PNO_SUPPORT */
2158 /* enable dongle roaming event */
2160 dhdp->pktfilter_count = 1;
2161 /* Setup filter to allow only unicast */
2162 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2163 #endif /* EMBEDDED_PLATFORM */
2165 /* Bus is ready, do any protocol initialization */
2166 ret = dhd_prot_init(&dhd->pub);
2174 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2177 char buf[strlen(name) + 1 + cmd_len];
2178 int len = sizeof(buf);
2182 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2184 memset(&ioc, 0, sizeof(ioc));
2186 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2191 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2192 if (!set && ret >= 0)
2193 memcpy(cmd_buf, buf, cmd_len);
2198 static struct net_device_ops dhd_ops_pri = {
2199 .ndo_open = dhd_open,
2200 .ndo_stop = dhd_stop,
2201 .ndo_get_stats = dhd_get_stats,
2202 .ndo_do_ioctl = dhd_ioctl_entry,
2203 .ndo_start_xmit = dhd_start_xmit,
2204 .ndo_set_mac_address = dhd_set_mac_address,
2205 .ndo_set_multicast_list = dhd_set_multicast_list
2208 static struct net_device_ops dhd_ops_virt = {
2209 .ndo_get_stats = dhd_get_stats,
2210 .ndo_do_ioctl = dhd_ioctl_entry,
2211 .ndo_start_xmit = dhd_start_xmit,
2212 .ndo_set_mac_address = dhd_set_mac_address,
2213 .ndo_set_multicast_list = dhd_set_multicast_list
2216 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2218 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2219 struct net_device *net;
2220 u8 temp_addr[ETHER_ADDR_LEN] = {
2221 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2223 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2225 ASSERT(dhd && dhd->iflist[ifidx]);
2227 net = dhd->iflist[ifidx]->net;
2230 ASSERT(!net->netdev_ops);
2231 net->netdev_ops = &dhd_ops_virt;
2233 net->netdev_ops = &dhd_ops_pri;
2236 * We have to use the primary MAC for virtual interfaces
2239 /* for virtual interfaces use the primary MAC */
2240 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2245 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2246 /* ACCESSPOINT INTERFACE CASE */
2247 temp_addr[0] |= 0X02; /* set bit 2 ,
2248 - Locally Administered address */
2251 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2252 net->ethtool_ops = &dhd_ethtool_ops;
2254 #if defined(CONFIG_WIRELESS_EXT)
2255 if (!IS_CFG80211_FAVORITE()) {
2256 #if WIRELESS_EXT < 19
2257 net->get_wireless_stats = dhd_get_wireless_stats;
2258 #endif /* WIRELESS_EXT < 19 */
2259 #if WIRELESS_EXT > 12
2260 net->wireless_handlers =
2261 (struct iw_handler_def *)&wl_iw_handler_def;
2262 #endif /* WIRELESS_EXT > 12 */
2264 #endif /* defined(CONFIG_WIRELESS_EXT) */
2266 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2268 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2270 if (register_netdev(net) != 0) {
2271 DHD_ERROR(("%s: couldn't register the net device\n",
2276 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2281 net->netdev_ops = NULL;
2285 void dhd_bus_detach(dhd_pub_t *dhdp)
2289 DHD_TRACE(("%s: Enter\n", __func__));
2292 dhd = (dhd_info_t *) dhdp->info;
2294 /* Stop the protocol module */
2295 dhd_prot_stop(&dhd->pub);
2297 /* Stop the bus module */
2298 dhd_bus_stop(dhd->pub.bus, true);
2299 #if defined(OOB_INTR_ONLY)
2300 bcmsdh_unregister_oob_intr();
2301 #endif /* defined(OOB_INTR_ONLY) */
2303 /* Clear the watchdog timer */
2304 del_timer_sync(&dhd->timer);
2305 dhd->wd_timer_valid = false;
2310 void dhd_detach(dhd_pub_t *dhdp)
2314 DHD_TRACE(("%s: Enter\n", __func__));
2317 dhd = (dhd_info_t *) dhdp->info;
2322 #if defined(CONFIG_HAS_EARLYSUSPEND)
2323 if (dhd->early_suspend.suspend)
2324 unregister_early_suspend(&dhd->early_suspend);
2325 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2327 for (i = 1; i < DHD_MAX_IFS; i++)
2331 ifp = dhd->iflist[0];
2333 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2335 unregister_netdev(ifp->net);
2338 if (dhd->watchdog_tsk) {
2339 kthread_stop(dhd->watchdog_tsk);
2340 dhd->watchdog_tsk = NULL;
2344 kthread_stop(dhd->dpc_tsk);
2345 dhd->dpc_tsk = NULL;
2347 tasklet_kill(&dhd->tasklet);
2349 if (dhd->sysioc_tsk) {
2350 kthread_stop(dhd->sysioc_tsk);
2351 dhd->sysioc_tsk = NULL;
2354 dhd_bus_detach(dhdp);
2357 dhd_prot_detach(dhdp);
2359 #if defined(CONFIG_WIRELESS_EXT)
2361 #endif /* (CONFIG_WIRELESS_EXT) */
2363 if (IS_CFG80211_FAVORITE())
2364 wl_cfg80211_detach();
2366 #if defined(CONFIG_PM_SLEEP)
2367 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2368 #endif /* defined(CONFIG_PM_SLEEP) */
2369 /* && defined(DHD_GPL) */
2370 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2371 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2372 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2373 free_netdev(ifp->net);
2374 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2375 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2380 static void __exit dhd_module_cleanup(void)
2382 DHD_TRACE(("%s: Enter\n", __func__));
2384 dhd_bus_unregister();
2385 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2388 /* Call customer gpio to turn off power with WL_REG_ON signal */
2389 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2392 static int __init dhd_module_init(void)
2396 DHD_TRACE(("%s: Enter\n", __func__));
2398 /* Sanity check on the module parameters */
2400 /* Both watchdog and DPC as tasklets are ok */
2401 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2404 /* If both watchdog and DPC are threads, TX must be deferred */
2405 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2409 DHD_ERROR(("Invalid module parameters.\n"));
2412 /* Call customer gpio to turn on power with WL_REG_ON signal */
2413 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2415 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2416 sema_init(&wifi_control_sem, 0);
2418 error = wifi_add_dev();
2420 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2424 /* Waiting callback after platform_driver_register is done or
2426 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2427 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2433 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2435 error = dhd_bus_register();
2438 printf("\n%s\n", dhd_version);
2440 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2446 /* turn off power and exit */
2447 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2451 module_init(dhd_module_init);
2452 module_exit(dhd_module_cleanup);
2455 * OS specific functions required to implement DHD driver in OS independent way
2457 int dhd_os_proto_block(dhd_pub_t *pub)
2459 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2462 down(&dhd->proto_sem);
2468 int dhd_os_proto_unblock(dhd_pub_t *pub)
2470 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2473 up(&dhd->proto_sem);
2480 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2482 return (unsigned int)dhd_ioctl_timeout_msec;
2485 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2487 dhd_ioctl_timeout_msec = (int)timeout_msec;
2490 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2492 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2493 DECLARE_WAITQUEUE(wait, current);
2494 int timeout = dhd_ioctl_timeout_msec;
2496 /* Convert timeout in millsecond to jiffies */
2497 timeout = timeout * HZ / 1000;
2499 /* Wait until control frame is available */
2500 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2501 set_current_state(TASK_INTERRUPTIBLE);
2503 while (!(*condition) && (!signal_pending(current) && timeout))
2504 timeout = schedule_timeout(timeout);
2506 if (signal_pending(current))
2509 set_current_state(TASK_RUNNING);
2510 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2515 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2517 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2519 if (waitqueue_active(&dhd->ioctl_resp_wait))
2520 wake_up_interruptible(&dhd->ioctl_resp_wait);
2525 void dhd_os_wd_timer(void *bus, uint wdtick)
2527 dhd_pub_t *pub = bus;
2528 static uint save_dhd_watchdog_ms;
2529 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2531 /* don't start the wd until fw is loaded */
2532 if (pub->busstate == DHD_BUS_DOWN)
2535 /* Totally stop the timer */
2536 if (!wdtick && dhd->wd_timer_valid == true) {
2537 del_timer_sync(&dhd->timer);
2538 dhd->wd_timer_valid = false;
2539 save_dhd_watchdog_ms = wdtick;
2544 dhd_watchdog_ms = (uint) wdtick;
2546 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2548 if (dhd->wd_timer_valid == true)
2549 /* Stop timer and restart at new value */
2550 del_timer_sync(&dhd->timer);
2552 /* Create timer again when watchdog period is
2553 dynamically changed or in the first instance
2555 dhd->timer.expires =
2556 jiffies + dhd_watchdog_ms * HZ / 1000;
2557 add_timer(&dhd->timer);
2560 /* Re arm the timer, at last watchdog period */
2561 mod_timer(&dhd->timer,
2562 jiffies + dhd_watchdog_ms * HZ / 1000);
2565 dhd->wd_timer_valid = true;
2566 save_dhd_watchdog_ms = wdtick;
2570 void *dhd_os_open_image(char *filename)
2574 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2575 return wl_cfg80211_request_fw(filename);
2577 fp = filp_open(filename, O_RDONLY, 0);
2579 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2581 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2590 int dhd_os_get_image_block(char *buf, int len, void *image)
2592 struct file *fp = (struct file *)image;
2595 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2596 return wl_cfg80211_read_fw(buf, len);
2601 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2608 void dhd_os_close_image(void *image)
2610 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2611 return wl_cfg80211_release_fw();
2613 filp_close((struct file *)image, NULL);
2616 void dhd_os_sdlock(dhd_pub_t *pub)
2620 dhd = (dhd_info_t *) (pub->info);
2622 if (dhd->threads_only)
2625 spin_lock_bh(&dhd->sdlock);
2628 void dhd_os_sdunlock(dhd_pub_t *pub)
2632 dhd = (dhd_info_t *) (pub->info);
2634 if (dhd->threads_only)
2637 spin_unlock_bh(&dhd->sdlock);
2640 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2644 dhd = (dhd_info_t *) (pub->info);
2645 spin_lock_bh(&dhd->txqlock);
2648 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2652 dhd = (dhd_info_t *) (pub->info);
2653 spin_unlock_bh(&dhd->txqlock);
2656 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2660 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2664 void dhd_os_sdtxlock(dhd_pub_t *pub)
2669 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2671 dhd_os_sdunlock(pub);
2674 #ifdef DHD_USE_STATIC_BUF
2675 void *dhd_os_prealloc(int section, unsigned long size)
2677 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2678 void *alloc_ptr = NULL;
2679 if (wifi_control_data && wifi_control_data->mem_prealloc) {
2680 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2682 DHD_INFO(("success alloc section %d\n", section));
2683 bzero(alloc_ptr, size);
2688 DHD_ERROR(("can't alloc section %d\n", section));
2691 return MALLOC(0, size);
2692 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2694 #endif /* DHD_USE_STATIC_BUF */
2695 #if defined(CONFIG_WIRELESS_EXT)
2696 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2699 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2701 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2704 return &dhd->iw.wstats;
2708 #endif /* defined(CONFIG_WIRELESS_EXT) */
2711 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2712 wl_event_msg_t *event, void **data)
2716 ASSERT(dhd != NULL);
2718 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2719 if (bcmerror != BCME_OK)
2722 #if defined(CONFIG_WIRELESS_EXT)
2723 if (!IS_CFG80211_FAVORITE()) {
2724 if ((dhd->iflist[*ifidx] == NULL)
2725 || (dhd->iflist[*ifidx]->net == NULL)) {
2726 DHD_ERROR(("%s Exit null pointer\n", __func__));
2730 if (dhd->iflist[*ifidx]->net)
2731 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2733 #endif /* defined(CONFIG_WIRELESS_EXT) */
2735 if (IS_CFG80211_FAVORITE()) {
2736 ASSERT(dhd->iflist[*ifidx] != NULL);
2737 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2738 if (dhd->iflist[*ifidx]->net)
2739 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2746 /* send up locally generated event */
2747 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2749 switch (ntoh32(event->event_type)) {
2755 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2757 struct dhd_info *dhdinfo = dhd->info;
2758 dhd_os_sdunlock(dhd);
2759 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2760 (*lockvar == false), HZ * 2);
2765 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2767 struct dhd_info *dhdinfo = dhd->info;
2768 if (waitqueue_active(&dhdinfo->ctrl_wait))
2769 wake_up_interruptible(&dhdinfo->ctrl_wait);
2773 int dhd_dev_reset(struct net_device *dev, u8 flag)
2775 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2777 /* Turning off watchdog */
2779 dhd_os_wd_timer(&dhd->pub, 0);
2781 dhd_bus_devreset(&dhd->pub, flag);
2783 /* Turning on watchdog back */
2785 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2786 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2791 int net_os_set_suspend_disable(struct net_device *dev, int val)
2793 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2797 ret = dhd->pub.suspend_disable_flag;
2798 dhd->pub.suspend_disable_flag = val;
2803 int net_os_set_suspend(struct net_device *dev, int val)
2806 #if defined(CONFIG_HAS_EARLYSUSPEND)
2807 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2810 dhd_os_proto_block(&dhd->pub);
2811 ret = dhd_set_suspend(val, &dhd->pub);
2812 dhd_os_proto_unblock(&dhd->pub);
2814 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2818 int net_os_set_dtim_skip(struct net_device *dev, int val)
2820 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2823 dhd->pub.dtim_skip = val;
2828 int net_os_set_packet_filter(struct net_device *dev, int val)
2830 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2833 /* Packet filtering is set only if we still in early-suspend and
2834 * we need either to turn it ON or turn it OFF
2835 * We can always turn it OFF in case of early-suspend, but we turn it
2836 * back ON only if suspend_disable_flag was not set
2838 if (dhd && dhd->pub.up) {
2839 dhd_os_proto_block(&dhd->pub);
2840 if (dhd->pub.in_suspend) {
2841 if (!val || (val && !dhd->pub.suspend_disable_flag))
2842 dhd_set_packet_filter(val, &dhd->pub);
2844 dhd_os_proto_unblock(&dhd->pub);
2849 void dhd_dev_init_ioctl(struct net_device *dev)
2851 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2853 dhd_preinit_ioctls(&dhd->pub);
2857 /* Linux wrapper to call common dhd_pno_clean */
2858 int dhd_dev_pno_reset(struct net_device *dev)
2860 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2862 return dhd_pno_clean(&dhd->pub);
2865 /* Linux wrapper to call common dhd_pno_enable */
2866 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2868 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2870 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2873 /* Linux wrapper to call common dhd_pno_set */
2875 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2876 unsigned char scan_fr)
2878 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2880 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2883 /* Linux wrapper to get pno status */
2884 int dhd_dev_get_pno_status(struct net_device *dev)
2886 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2888 return dhd_pno_get_status(&dhd->pub);
2891 #endif /* PNO_SUPPORT */
2893 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2895 return atomic_read(&dhd->pend_8021x_cnt);
2898 #define MAX_WAIT_FOR_8021X_TX 10
2900 int dhd_wait_pend8021x(struct net_device *dev)
2902 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2903 int timeout = 10 * HZ / 1000;
2904 int ntimes = MAX_WAIT_FOR_8021X_TX;
2905 int pend = dhd_get_pend_8021x_cnt(dhd);
2907 while (ntimes && pend) {
2909 set_current_state(TASK_INTERRUPTIBLE);
2910 schedule_timeout(timeout);
2911 set_current_state(TASK_RUNNING);
2914 pend = dhd_get_pend_8021x_cnt(dhd);
2920 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2924 mm_segment_t old_fs;
2927 /* change to KERNEL_DS address limit */
2931 /* open file to write */
2932 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2934 printf("%s: open file error\n", __func__);
2939 /* Write buf to file */
2940 fp->f_op->write(fp, buf, size, &pos);
2943 /* free buf before return */
2944 MFREE(dhd->osh, buf, size);
2945 /* close file before return */
2947 filp_close(fp, current->files);
2948 /* restore previous address limit */
2953 #endif /* DHD_DEBUG */