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/slab.h>
27 #include <linux/skbuff.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
30 #include <linux/mmc/sdio_func.h>
31 #include <linux/random.h>
32 #include <linux/spinlock.h>
33 #include <linux/ethtool.h>
34 #include <linux/fcntl.h>
37 #include <linux/uaccess.h>
39 #include <bcmendian.h>
41 #include <proto/ethernet.h>
42 #include <dngl_stats.h>
45 #include <dhd_proto.h>
48 #ifdef CONFIG_CFG80211
49 #include <wl_cfg80211.h>
52 #define EPI_VERSION_STR "4.218.248.5"
54 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
55 #include <linux/wifi_tiwlan.h>
57 struct semaphore wifi_control_sem;
59 struct dhd_bus *g_bus;
61 static struct wifi_platform_data *wifi_control_data;
62 static struct resource *wifi_irqres;
64 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
67 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
68 return (int)wifi_irqres->start;
70 #ifdef CUSTOM_OOB_GPIO_NUM
71 return CUSTOM_OOB_GPIO_NUM;
77 int wifi_set_carddetect(int on)
79 printk(KERN_ERR "%s = %d\n", __func__, on);
80 if (wifi_control_data && wifi_control_data->set_carddetect)
81 wifi_control_data->set_carddetect(on);
85 int wifi_set_power(int on, unsigned long msec)
87 printk(KERN_ERR "%s = %d\n", __func__, on);
88 if (wifi_control_data && wifi_control_data->set_power)
89 wifi_control_data->set_power(on);
95 int wifi_set_reset(int on, unsigned long msec)
97 printk(KERN_ERR "%s = %d\n", __func__, on);
98 if (wifi_control_data && wifi_control_data->set_reset)
99 wifi_control_data->set_reset(on);
105 static int wifi_probe(struct platform_device *pdev)
107 struct wifi_platform_data *wifi_ctrl =
108 (struct wifi_platform_data *)(pdev->dev.platform_data);
110 printk(KERN_ERR "## %s\n", __func__);
112 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
114 wifi_control_data = wifi_ctrl;
116 wifi_set_power(1, 0); /* Power On */
117 wifi_set_carddetect(1); /* CardDetect (0->1) */
119 up(&wifi_control_sem);
123 static int wifi_remove(struct platform_device *pdev)
125 struct wifi_platform_data *wifi_ctrl =
126 (struct wifi_platform_data *)(pdev->dev.platform_data);
128 printk(KERN_ERR "## %s\n", __func__);
129 wifi_control_data = wifi_ctrl;
131 wifi_set_carddetect(0); /* CardDetect (1->0) */
132 wifi_set_power(0, 0); /* Power Off */
134 up(&wifi_control_sem);
138 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
140 DHD_TRACE(("##> %s\n", __func__));
144 static int wifi_resume(struct platform_device *pdev)
146 DHD_TRACE(("##> %s\n", __func__));
150 static struct platform_driver wifi_device = {
152 .remove = wifi_remove,
153 .suspend = wifi_suspend,
154 .resume = wifi_resume,
156 .name = "bcm4329_wlan",
160 int wifi_add_dev(void)
162 DHD_TRACE(("## Calling platform_driver_register\n"));
163 return platform_driver_register(&wifi_device);
166 void wifi_del_dev(void)
168 DHD_TRACE(("## Unregister platform_driver_register\n"));
169 platform_driver_unregister(&wifi_device);
171 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
173 #if defined(CONFIG_PM_SLEEP)
174 #include <linux/suspend.h>
175 volatile bool dhd_mmc_suspend = FALSE;
176 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
177 #endif /* defined(CONFIG_PM_SLEEP) */
179 #if defined(OOB_INTR_ONLY)
180 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
181 #endif /* defined(OOB_INTR_ONLY) */
183 MODULE_AUTHOR("Broadcom Corporation");
184 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
185 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
186 MODULE_LICENSE("Dual BSD/GPL");
188 #define DRV_MODULE_NAME "brcmfmac"
190 /* Linux wireless extension support */
191 #if defined(CONFIG_WIRELESS_EXT)
193 extern wl_iw_extra_params_t g_wl_iw_params;
194 #endif /* defined(CONFIG_WIRELESS_EXT) */
196 #if defined(CONFIG_HAS_EARLYSUSPEND)
197 #include <linux/earlysuspend.h>
198 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
200 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
202 #ifdef PKT_FILTER_SUPPORT
203 extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
204 extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
208 /* Interface control information */
209 typedef struct dhd_if {
210 struct dhd_info *info; /* back pointer to dhd_info */
211 /* OS/stack specifics */
212 struct net_device *net;
213 struct net_device_stats stats;
214 int idx; /* iface idx in dongle */
215 int state; /* interface state */
216 uint subunit; /* subunit */
217 u8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
218 bool attached; /* Delayed attachment when unset */
219 bool txflowcontrol; /* Per interface flow control indicator */
220 char name[IFNAMSIZ + 1]; /* linux interface name */
223 /* Local private structure (extension of pub) */
224 typedef struct dhd_info {
225 #if defined(CONFIG_WIRELESS_EXT)
226 wl_iw_t iw; /* wireless extensions state (must be first) */
227 #endif /* defined(CONFIG_WIRELESS_EXT) */
231 /* OS/stack specifics */
232 dhd_if_t *iflist[DHD_MAX_IFS];
234 struct semaphore proto_sem;
235 wait_queue_head_t ioctl_resp_wait;
236 struct timer_list timer;
238 struct tasklet_struct tasklet;
241 /* Thread based operation */
243 struct semaphore sdsem;
245 struct semaphore watchdog_sem;
246 struct completion watchdog_exited;
248 struct semaphore dpc_sem;
249 struct completion dpc_exited;
251 /* Thread to issue ioctl for multicast */
253 struct semaphore sysioc_sem;
254 struct completion sysioc_exited;
257 struct ether_addr macvalue;
258 wait_queue_head_t ctrl_wait;
259 atomic_t pend_8021x_cnt;
261 #ifdef CONFIG_HAS_EARLYSUSPEND
262 struct early_suspend early_suspend;
263 #endif /* CONFIG_HAS_EARLYSUSPEND */
266 /* Definitions to provide path to the firmware and nvram
267 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
269 char firmware_path[MOD_PARAM_PATHLEN];
270 char nvram_path[MOD_PARAM_PATHLEN];
272 /* load firmware and/or nvram values from the filesystem */
273 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
274 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
277 module_param(dhd_msg_level, int, 0);
279 /* Spawn a thread for system ioctls (set mac, set mcast) */
280 uint dhd_sysioc = TRUE;
281 module_param(dhd_sysioc, uint, 0);
283 /* Watchdog interval */
284 uint dhd_watchdog_ms = 10;
285 module_param(dhd_watchdog_ms, uint, 0);
288 /* Console poll interval */
290 module_param(dhd_console_ms, uint, 0);
291 #endif /* DHD_DEBUG */
293 /* ARP offload agent mode : Enable ARP Host Auto-Reply
294 and ARP Peer Auto-Reply */
295 uint dhd_arp_mode = 0xb;
296 module_param(dhd_arp_mode, uint, 0);
298 /* ARP offload enable */
299 uint dhd_arp_enable = TRUE;
300 module_param(dhd_arp_enable, uint, 0);
302 /* Global Pkt filter enable control */
303 uint dhd_pkt_filter_enable = TRUE;
304 module_param(dhd_pkt_filter_enable, uint, 0);
306 /* Pkt filter init setup */
307 uint dhd_pkt_filter_init;
308 module_param(dhd_pkt_filter_init, uint, 0);
310 /* Pkt filter mode control */
311 uint dhd_master_mode = TRUE;
312 module_param(dhd_master_mode, uint, 1);
314 /* Watchdog thread priority, -1 to use kernel timer */
315 int dhd_watchdog_prio = 97;
316 module_param(dhd_watchdog_prio, int, 0);
318 /* DPC thread priority, -1 to use tasklet */
319 int dhd_dpc_prio = 98;
320 module_param(dhd_dpc_prio, int, 0);
322 /* DPC thread priority, -1 to use tasklet */
323 extern int dhd_dongle_memsize;
324 module_param(dhd_dongle_memsize, int, 0);
326 /* Contorl fw roaming */
333 /* Control radio state */
334 uint dhd_radio_up = 1;
336 /* Network inteface name */
337 char iface_name[IFNAMSIZ];
338 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
340 #define DAEMONIZE(a) \
343 allow_signal(SIGKILL); \
344 allow_signal(SIGTERM); \
347 #define BLOCKABLE() (!in_atomic())
349 /* The following are specific to the SDIO dongle */
351 /* IOCTL response timeout */
352 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
354 /* Idle timeout for backplane clock */
355 int dhd_idletime = DHD_IDLETIME_TICKS;
356 module_param(dhd_idletime, int, 0);
359 uint dhd_poll = FALSE;
360 module_param(dhd_poll, uint, 0);
362 #ifdef CONFIG_CFG80211
364 uint dhd_cfg80211 = TRUE;
365 module_param(dhd_cfg80211, uint, 0);
369 uint dhd_intr = TRUE;
370 module_param(dhd_intr, uint, 0);
372 /* SDIO Drive Strength (in milliamps) */
373 uint dhd_sdiod_drive_strength = 6;
374 module_param(dhd_sdiod_drive_strength, uint, 0);
377 extern uint dhd_txbound;
378 extern uint dhd_rxbound;
379 module_param(dhd_txbound, uint, 0);
380 module_param(dhd_rxbound, uint, 0);
382 /* Deferred transmits */
383 extern uint dhd_deferred_tx;
384 module_param(dhd_deferred_tx, uint, 0);
387 /* Echo packet generator (pkts/s) */
389 module_param(dhd_pktgen, uint, 0);
391 /* Echo packet len (0 => sawtooth, max 2040) */
393 module_param(dhd_pktgen_len, uint, 0);
396 #ifdef CONFIG_CFG80211
397 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
398 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
399 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
400 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
403 /* Version string to report */
405 #define DHD_COMPILED "\nCompiled in " SRCBASE
410 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
412 "\nCompiled in " " on " __DATE__ " at " __TIME__
416 #if defined(CONFIG_WIRELESS_EXT)
417 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
418 #endif /* defined(CONFIG_WIRELESS_EXT) */
420 static void dhd_dpc(unsigned long data);
422 extern int dhd_wait_pend8021x(struct net_device *dev);
426 #error TOE requires BDC
428 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
429 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
432 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
433 wl_event_msg_t *event_ptr, void **data_ptr);
435 #if defined(CONFIG_PM_SLEEP)
436 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
437 unsigned long action, void *ignored)
440 case PM_HIBERNATION_PREPARE:
441 case PM_SUSPEND_PREPARE:
442 dhd_mmc_suspend = TRUE;
444 case PM_POST_HIBERNATION:
445 case PM_POST_SUSPEND:
446 dhd_mmc_suspend = FALSE;
452 static struct notifier_block dhd_sleep_pm_notifier = {
453 .notifier_call = dhd_sleep_pm_callback,
457 extern int register_pm_notifier(struct notifier_block *nb);
458 extern int unregister_pm_notifier(struct notifier_block *nb);
459 #endif /* defined(CONFIG_PM_SLEEP) */
460 /* && defined(DHD_GPL) */
461 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
463 #ifdef PKT_FILTER_SUPPORT
464 DHD_TRACE(("%s: %d\n", __func__, value));
465 /* 1 - Enable packet filter, only allow unicast packet to send up */
466 /* 0 - Disable packet filter */
467 if (dhd_pkt_filter_enable) {
470 for (i = 0; i < dhd->pktfilter_count; i++) {
471 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
472 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
473 value, dhd_master_mode);
479 #if defined(CONFIG_HAS_EARLYSUSPEND)
480 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
482 int power_mode = PM_MAX;
483 /* wl_pkt_filter_enable_t enable_parm; */
488 #endif /* CUSTOMER_HW2 */
490 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
491 __func__, value, dhd->in_suspend));
493 if (dhd && dhd->up) {
494 if (value && dhd->in_suspend) {
496 /* Kernel suspended */
497 DHD_TRACE(("%s: force extra Suspend setting\n",
500 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
504 /* Enable packet filter, only allow unicast
506 dhd_set_packet_filter(1, dhd);
508 /* if dtim skip setup as default force it
509 * to wake each thrid dtim
510 * for better power saving.
511 * Note that side effect is chance to miss BC/MC
514 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
517 bcn_li_dtim = dhd->dtim_skip;
518 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
519 4, iovbuf, sizeof(iovbuf));
520 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
523 /* Disable build-in roaming to allowed \
524 * supplicant to take of romaing
526 bcm_mkiovar("roam_off", (char *)&roamvar, 4,
527 iovbuf, sizeof(iovbuf));
528 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
530 #endif /* CUSTOMER_HW2 */
534 DHD_TRACE(("%s: Remove extra suspend setting\n",
537 power_mode = PM_FAST;
538 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
542 /* disable pkt filter */
543 dhd_set_packet_filter(0, dhd);
545 /* restore pre-suspend setting for dtim_skip */
546 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
547 4, iovbuf, sizeof(iovbuf));
549 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
553 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
555 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
557 #endif /* CUSTOMER_HW2 */
564 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
566 dhd_pub_t *dhdp = &dhd->pub;
568 dhd_os_proto_block(dhdp);
569 /* Set flag when early suspend was called */
570 dhdp->in_suspend = val;
571 if (!dhdp->suspend_disable_flag)
572 dhd_set_suspend(val, dhdp);
573 dhd_os_proto_unblock(dhdp);
576 static void dhd_early_suspend(struct early_suspend *h)
578 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
580 DHD_TRACE(("%s: enter\n", __func__));
583 dhd_suspend_resume_helper(dhd, 1);
587 static void dhd_late_resume(struct early_suspend *h)
589 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
591 DHD_TRACE(("%s: enter\n", __func__));
594 dhd_suspend_resume_helper(dhd, 0);
596 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
599 * Generalized timeout mechanism. Uses spin sleep with exponential
601 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
603 * dhd_timeout_start(&tmo, usec);
604 * while (!dhd_timeout_expired(&tmo))
605 * if (poll_something())
607 * if (dhd_timeout_expired(&tmo))
611 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
616 tmo->tick = 1000000 / HZ;
619 int dhd_timeout_expired(dhd_timeout_t *tmo)
621 /* Does nothing the first call */
622 if (tmo->increment == 0) {
627 if (tmo->elapsed >= tmo->limit)
630 /* Add the delay that's about to take place */
631 tmo->elapsed += tmo->increment;
633 if (tmo->increment < tmo->tick) {
634 OSL_DELAY(tmo->increment);
636 if (tmo->increment > tmo->tick)
637 tmo->increment = tmo->tick;
639 wait_queue_head_t delay_wait;
640 DECLARE_WAITQUEUE(wait, current);
642 init_waitqueue_head(&delay_wait);
643 add_wait_queue(&delay_wait, &wait);
644 set_current_state(TASK_INTERRUPTIBLE);
646 pending = signal_pending(current);
647 remove_wait_queue(&delay_wait, &wait);
648 set_current_state(TASK_RUNNING);
650 return 1; /* Interrupted */
656 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
661 while (i < DHD_MAX_IFS) {
662 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
670 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
676 if (name == NULL || *name == '\0')
681 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
684 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
686 return i; /* default - the primary interface */
689 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
691 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
695 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
696 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
700 if (dhd->iflist[ifidx] == NULL) {
701 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
705 if (dhd->iflist[ifidx]->net)
706 return dhd->iflist[ifidx]->net->name;
711 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
713 struct net_device *dev;
714 struct netdev_hw_addr *ha;
722 ASSERT(dhd && dhd->iflist[ifidx]);
723 dev = dhd->iflist[ifidx]->net;
724 cnt = netdev_mc_count(dev);
726 /* Determine initial value of allmulti flag */
727 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
729 /* Send down the multicast list first. */
731 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
732 bufp = buf = MALLOC(dhd->pub.osh, buflen);
734 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
735 dhd_ifname(&dhd->pub, ifidx), cnt));
739 strcpy(bufp, "mcast_list");
740 bufp += strlen("mcast_list") + 1;
743 memcpy(bufp, &cnt, sizeof(cnt));
746 netdev_for_each_mc_addr(ha, dev) {
749 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
750 bufp += ETHER_ADDR_LEN;
754 memset(&ioc, 0, sizeof(ioc));
755 ioc.cmd = WLC_SET_VAR;
760 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
762 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
763 dhd_ifname(&dhd->pub, ifidx), cnt));
764 allmulti = cnt ? TRUE : allmulti;
767 MFREE(dhd->pub.osh, buf, buflen);
769 /* Now send the allmulti setting. This is based on the setting in the
770 * net_device flags, but might be modified above to be turned on if we
771 * were trying to set some addresses and dongle rejected it...
774 buflen = sizeof("allmulti") + sizeof(allmulti);
775 buf = MALLOC(dhd->pub.osh, buflen);
777 DHD_ERROR(("%s: out of memory for allmulti\n",
778 dhd_ifname(&dhd->pub, ifidx)));
781 allmulti = htol32(allmulti);
784 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
785 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
786 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
787 (int)sizeof(allmulti), buflen));
788 MFREE(dhd->pub.osh, buf, buflen);
792 memset(&ioc, 0, sizeof(ioc));
793 ioc.cmd = WLC_SET_VAR;
798 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
800 DHD_ERROR(("%s: set allmulti %d failed\n",
801 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
804 MFREE(dhd->pub.osh, buf, buflen);
806 /* Finally, pick up the PROMISC flag as well, like the NIC
809 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
810 allmulti = htol32(allmulti);
812 memset(&ioc, 0, sizeof(ioc));
813 ioc.cmd = WLC_SET_PROMISC;
815 ioc.len = sizeof(allmulti);
818 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
820 DHD_ERROR(("%s: set promisc %d failed\n",
821 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
826 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
832 DHD_TRACE(("%s enter\n", __func__));
834 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) {
835 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
836 dhd_ifname(&dhd->pub, ifidx)));
839 memset(&ioc, 0, sizeof(ioc));
840 ioc.cmd = WLC_SET_VAR;
845 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
847 DHD_ERROR(("%s: set cur_etheraddr failed\n",
848 dhd_ifname(&dhd->pub, ifidx)));
850 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
857 extern struct net_device *ap_net_dev;
860 static void dhd_op_if(dhd_if_t *ifp)
863 int ret = 0, err = 0;
865 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
869 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
871 switch (ifp->state) {
874 * Delete the existing interface before overwriting it
875 * in case we missed the WLC_E_IF_DEL event.
877 if (ifp->net != NULL) {
878 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
879 "try free & unregister\n",
880 __func__, ifp->net->name));
881 netif_stop_queue(ifp->net);
882 unregister_netdev(ifp->net);
883 free_netdev(ifp->net);
885 /* Allocate etherdev, including space for private structure */
886 ifp->net = alloc_etherdev(sizeof(dhd));
888 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
892 strcpy(ifp->net->name, ifp->name);
893 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
894 err = dhd_net_attach(&dhd->pub, ifp->idx);
896 DHD_ERROR(("%s: dhd_net_attach failed, "
902 /* semaphore that the soft AP CODE
904 extern struct semaphore ap_eth_sema;
906 /* save ptr to wl0.1 netdev for use
908 ap_net_dev = ifp->net;
909 /* signal to the SOFTAP 'sleeper' thread,
913 DHD_TRACE(("\n ==== pid:%x, net_device for "
914 "if:%s created ===\n\n",
915 current->pid, ifp->net->name));
921 if (ifp->net != NULL) {
922 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
924 netif_stop_queue(ifp->net);
925 unregister_netdev(ifp->net);
926 ret = DHD_DEL_IF; /* Make sure the free_netdev()
931 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
938 free_netdev(ifp->net);
940 dhd->iflist[ifp->idx] = NULL;
941 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
943 if (ifp->net == ap_net_dev)
944 ap_net_dev = NULL; /* NULL SOFTAP global
950 static int _dhd_sysioc_thread(void *data)
952 dhd_info_t *dhd = (dhd_info_t *) data;
958 DAEMONIZE("dhd_sysioc");
960 while (down_interruptible(&dhd->sysioc_sem) == 0) {
961 for (i = 0; i < DHD_MAX_IFS; i++) {
962 if (dhd->iflist[i]) {
964 in_ap = (ap_net_dev != NULL);
966 if (dhd->iflist[i]->state)
967 dhd_op_if(dhd->iflist[i]);
969 if (dhd->iflist[i] == NULL) {
970 DHD_TRACE(("\n\n %s: interface %d "
971 "removed!\n", __func__, i));
975 if (in_ap && dhd->set_macaddress) {
976 DHD_TRACE(("attempt to set MAC for %s "
977 "in AP Mode," "blocked. \n",
978 dhd->iflist[i]->net->name));
979 dhd->set_macaddress = FALSE;
983 if (in_ap && dhd->set_multicast) {
984 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
985 dhd->iflist[i]->net->name));
986 dhd->set_multicast = FALSE;
990 if (dhd->set_multicast) {
991 dhd->set_multicast = FALSE;
992 _dhd_set_multicast_list(dhd, i);
994 if (dhd->set_macaddress) {
995 dhd->set_macaddress = FALSE;
996 _dhd_set_mac_address(dhd, i,
1002 complete_and_exit(&dhd->sysioc_exited, 0);
1005 static int dhd_set_mac_address(struct net_device *dev, void *addr)
1009 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1010 struct sockaddr *sa = (struct sockaddr *)addr;
1013 ifidx = dhd_net2idx(dhd, dev);
1014 if (ifidx == DHD_BAD_IF)
1017 ASSERT(dhd->sysioc_pid >= 0);
1018 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1019 dhd->set_macaddress = TRUE;
1020 up(&dhd->sysioc_sem);
1025 static void dhd_set_multicast_list(struct net_device *dev)
1027 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1030 ifidx = dhd_net2idx(dhd, dev);
1031 if (ifidx == DHD_BAD_IF)
1034 ASSERT(dhd->sysioc_pid >= 0);
1035 dhd->set_multicast = TRUE;
1036 up(&dhd->sysioc_sem);
1039 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1042 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1044 /* Reject if down */
1045 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1048 /* Update multicast statistic */
1049 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1050 u8 *pktdata = (u8 *) PKTDATA(pktbuf);
1051 struct ether_header *eh = (struct ether_header *)pktdata;
1053 if (ETHER_ISMULTI(eh->ether_dhost))
1054 dhdp->tx_multicast++;
1055 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1056 atomic_inc(&dhd->pend_8021x_cnt);
1059 /* Look into the packet and update the packet priority */
1060 if ((PKTPRIO(pktbuf) == 0))
1061 pktsetprio(pktbuf, FALSE);
1063 /* If the protocol uses a data header, apply it */
1064 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1066 /* Use bus module to send data frame */
1068 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1070 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1071 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1072 #endif /* BCMDBUS */
1077 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1081 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1084 DHD_TRACE(("%s: Enter\n", __func__));
1086 /* Reject if down */
1087 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1088 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1089 __func__, dhd->pub.up, dhd->pub.busstate));
1090 netif_stop_queue(net);
1094 ifidx = dhd_net2idx(dhd, net);
1095 if (ifidx == DHD_BAD_IF) {
1096 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1097 netif_stop_queue(net);
1101 /* Make sure there's enough room for any header */
1102 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1103 struct sk_buff *skb2;
1105 DHD_INFO(("%s: insufficient headroom\n",
1106 dhd_ifname(&dhd->pub, ifidx)));
1107 dhd->pub.tx_realloc++;
1108 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1112 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1113 dhd_ifname(&dhd->pub, ifidx)));
1119 /* Convert to packet */
1120 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1122 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1123 dhd_ifname(&dhd->pub, ifidx)));
1124 dev_kfree_skb_any(skb);
1129 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1133 dhd->pub.dstats.tx_dropped++;
1135 dhd->pub.tx_packets++;
1137 /* Return ok: we always eat the packet */
1141 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1143 struct net_device *net;
1144 dhd_info_t *dhd = dhdp->info;
1146 DHD_TRACE(("%s: Enter\n", __func__));
1148 dhdp->txoff = state;
1149 ASSERT(dhd && dhd->iflist[ifidx]);
1150 net = dhd->iflist[ifidx]->net;
1152 netif_stop_queue(net);
1154 netif_wake_queue(net);
1157 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1159 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1160 struct sk_buff *skb;
1163 void *data, *pnext, *save_pktbuf;
1166 wl_event_msg_t event;
1168 DHD_TRACE(("%s: Enter\n", __func__));
1170 save_pktbuf = pktbuf;
1172 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1174 pnext = PKTNEXT(pktbuf);
1175 PKTSETNEXT(pktbuf, NULL);
1177 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1179 /* Get the protocol, maintain skb around eth_type_trans()
1180 * The main reason for this hack is for the limitation of
1181 * Linux 2.4 where 'eth_type_trans' uses the
1182 * 'net->hard_header_len'
1183 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1184 * coping of the packet coming from the network stack to add
1185 * BDC, Hardware header etc, during network interface
1187 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1189 * for BDC, Hardware header etc. and not just the ETH_HLEN
1194 ifp = dhd->iflist[ifidx];
1196 ifp = dhd->iflist[0];
1199 skb->dev = ifp->net;
1200 skb->protocol = eth_type_trans(skb, skb->dev);
1202 if (skb->pkt_type == PACKET_MULTICAST)
1203 dhd->pub.rx_multicast++;
1208 /* Strip header, count, deliver upward */
1209 skb_pull(skb, ETH_HLEN);
1211 /* Process special event packets and then discard them */
1212 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1213 dhd_wl_host_event(dhd, &ifidx,
1217 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1218 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1219 ifp = dhd->iflist[ifidx];
1222 ifp->net->last_rx = jiffies;
1224 dhdp->dstats.rx_bytes += skb->len;
1225 dhdp->rx_packets++; /* Local count */
1227 if (in_interrupt()) {
1230 /* If the receive is not processed inside an ISR,
1231 * the softirqd must be woken explicitly to service
1232 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1233 * by netif_rx_ni(), but in earlier kernels, we need
1234 * to do it manually.
1241 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1243 /* Linux version has nothing to do */
1247 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1250 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1251 struct ether_header *eh;
1254 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1256 eh = (struct ether_header *)PKTDATA(txp);
1257 type = ntoh16(eh->ether_type);
1259 if (type == ETHER_TYPE_802_1X)
1260 atomic_dec(&dhd->pend_8021x_cnt);
1264 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1266 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1270 DHD_TRACE(("%s: Enter\n", __func__));
1272 ifidx = dhd_net2idx(dhd, net);
1273 if (ifidx == DHD_BAD_IF)
1276 ifp = dhd->iflist[ifidx];
1280 /* Use the protocol to get dongle stats */
1281 dhd_prot_dstats(&dhd->pub);
1284 /* Copy dongle stats to net device stats */
1285 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1286 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1287 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1288 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1289 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1290 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1291 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1292 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1293 ifp->stats.multicast = dhd->pub.dstats.multicast;
1298 static int dhd_watchdog_thread(void *data)
1300 dhd_info_t *dhd = (dhd_info_t *) data;
1301 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1303 /* This thread doesn't need any user-level access,
1304 * so get rid of all our resources
1307 if (dhd_watchdog_prio > 0) {
1308 struct sched_param param;
1309 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1310 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1311 setScheduler(current, SCHED_FIFO, ¶m);
1313 #endif /* DHD_SCHED */
1315 DAEMONIZE("dhd_watchdog");
1317 /* Run until signal received */
1319 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1320 if (dhd->pub.dongle_reset == FALSE) {
1321 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1322 /* Call the bus module watchdog */
1323 dhd_bus_watchdog(&dhd->pub);
1324 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1326 /* Count the tick for reference */
1332 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1333 complete_and_exit(&dhd->watchdog_exited, 0);
1336 static void dhd_watchdog(unsigned long data)
1338 dhd_info_t *dhd = (dhd_info_t *) data;
1340 if (dhd->watchdog_pid >= 0) {
1341 up(&dhd->watchdog_sem);
1343 /* Reschedule the watchdog */
1344 if (dhd->wd_timer_valid) {
1345 mod_timer(&dhd->timer,
1346 jiffies + dhd_watchdog_ms * HZ / 1000);
1351 /* Call the bus module watchdog */
1352 dhd_bus_watchdog(&dhd->pub);
1354 /* Count the tick for reference */
1357 /* Reschedule the watchdog */
1358 if (dhd->wd_timer_valid)
1359 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1362 static int dhd_dpc_thread(void *data)
1364 dhd_info_t *dhd = (dhd_info_t *) data;
1366 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1367 /* This thread doesn't need any user-level access,
1368 * so get rid of all our resources
1371 if (dhd_dpc_prio > 0) {
1372 struct sched_param param;
1373 param.sched_priority =
1375 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1376 setScheduler(current, SCHED_FIFO, ¶m);
1378 #endif /* DHD_SCHED */
1380 DAEMONIZE("dhd_dpc");
1382 /* Run until signal received */
1384 if (down_interruptible(&dhd->dpc_sem) == 0) {
1385 /* Call bus dpc unless it indicated down
1386 (then clean stop) */
1387 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1388 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1389 if (dhd_bus_dpc(dhd->pub.bus)) {
1391 WAKE_LOCK_TIMEOUT(&dhd->pub,
1392 WAKE_LOCK_TMOUT, 25);
1394 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1396 dhd_bus_stop(dhd->pub.bus, TRUE);
1402 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1404 complete_and_exit(&dhd->dpc_exited, 0);
1407 static void dhd_dpc(unsigned long data)
1411 dhd = (dhd_info_t *) data;
1413 /* Call bus dpc unless it indicated down (then clean stop) */
1414 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1415 if (dhd_bus_dpc(dhd->pub.bus))
1416 tasklet_schedule(&dhd->tasklet);
1418 dhd_bus_stop(dhd->pub.bus, TRUE);
1422 void dhd_sched_dpc(dhd_pub_t *dhdp)
1424 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1426 if (dhd->dpc_pid >= 0) {
1431 tasklet_schedule(&dhd->tasklet);
1435 /* Retrieve current toe component enables, which are kept
1436 as a bitmap in toe_ol iovar */
1437 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1443 memset(&ioc, 0, sizeof(ioc));
1445 ioc.cmd = WLC_GET_VAR;
1447 ioc.len = (uint) sizeof(buf);
1450 strcpy(buf, "toe_ol");
1451 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1453 /* Check for older dongle image that doesn't support toe_ol */
1455 DHD_ERROR(("%s: toe not supported by device\n",
1456 dhd_ifname(&dhd->pub, ifidx)));
1460 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1461 dhd_ifname(&dhd->pub, ifidx), ret));
1465 memcpy(toe_ol, buf, sizeof(u32));
1469 /* Set current toe component enables in toe_ol iovar,
1470 and set toe global enable iovar */
1471 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1477 memset(&ioc, 0, sizeof(ioc));
1479 ioc.cmd = WLC_SET_VAR;
1481 ioc.len = (uint) sizeof(buf);
1484 /* Set toe_ol as requested */
1486 strcpy(buf, "toe_ol");
1487 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1489 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1491 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1492 dhd_ifname(&dhd->pub, ifidx), ret));
1496 /* Enable toe globally only if any components are enabled. */
1498 toe = (toe_ol != 0);
1501 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1503 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1505 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1506 dhd_ifname(&dhd->pub, ifidx), ret));
1514 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1515 struct ethtool_drvinfo *info)
1517 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1519 sprintf(info->driver, DRV_MODULE_NAME);
1520 sprintf(info->version, "%lu", dhd->pub.drv_version);
1521 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1522 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1525 struct ethtool_ops dhd_ethtool_ops = {
1526 .get_drvinfo = dhd_ethtool_get_drvinfo
1529 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1531 struct ethtool_drvinfo info;
1532 char drvname[sizeof(info.driver)];
1535 struct ethtool_value edata;
1536 u32 toe_cmpnt, csum_dir;
1540 DHD_TRACE(("%s: Enter\n", __func__));
1542 /* all ethtool calls start with a cmd word */
1543 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1547 case ETHTOOL_GDRVINFO:
1548 /* Copy out any request driver name */
1549 if (copy_from_user(&info, uaddr, sizeof(info)))
1551 strncpy(drvname, info.driver, sizeof(info.driver));
1552 drvname[sizeof(info.driver) - 1] = '\0';
1554 /* clear struct for return */
1555 memset(&info, 0, sizeof(info));
1558 /* if dhd requested, identify ourselves */
1559 if (strcmp(drvname, "?dhd") == 0) {
1560 sprintf(info.driver, "dhd");
1561 strcpy(info.version, EPI_VERSION_STR);
1564 /* otherwise, require dongle to be up */
1565 else if (!dhd->pub.up) {
1566 DHD_ERROR(("%s: dongle is not up\n", __func__));
1570 /* finally, report dongle driver type */
1571 else if (dhd->pub.iswl)
1572 sprintf(info.driver, "wl");
1574 sprintf(info.driver, "xx");
1576 sprintf(info.version, "%lu", dhd->pub.drv_version);
1577 if (copy_to_user(uaddr, &info, sizeof(info)))
1579 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1580 (int)sizeof(drvname), drvname, info.driver));
1584 /* Get toe offload components from dongle */
1585 case ETHTOOL_GRXCSUM:
1586 case ETHTOOL_GTXCSUM:
1587 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1592 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1595 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1597 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1601 /* Set toe offload components in dongle */
1602 case ETHTOOL_SRXCSUM:
1603 case ETHTOOL_STXCSUM:
1604 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1607 /* Read the current settings, update and write back */
1608 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1613 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1615 if (edata.data != 0)
1616 toe_cmpnt |= csum_dir;
1618 toe_cmpnt &= ~csum_dir;
1620 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1624 /* If setting TX checksum mode, tell Linux the new mode */
1625 if (cmd == ETHTOOL_STXCSUM) {
1627 dhd->iflist[0]->net->features |=
1630 dhd->iflist[0]->net->features &=
1644 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1646 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1653 bool is_set_key_cmd;
1655 ifidx = dhd_net2idx(dhd, net);
1656 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1658 if (ifidx == DHD_BAD_IF)
1661 #if defined(CONFIG_WIRELESS_EXT)
1662 /* linux wireless extensions */
1663 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1664 /* may recurse, do NOT lock */
1665 return wl_iw_ioctl(net, ifr, cmd);
1667 #endif /* defined(CONFIG_WIRELESS_EXT) */
1669 if (cmd == SIOCETHTOOL)
1670 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1672 if (cmd != SIOCDEVPRIVATE)
1675 memset(&ioc, 0, sizeof(ioc));
1677 /* Copy the ioc control structure part of ioctl request */
1678 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1679 bcmerror = -BCME_BADADDR;
1683 /* Copy out any buffer passed */
1685 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1686 /* optimization for direct ioctl calls from kernel */
1688 if (segment_eq(get_fs(), KERNEL_DS)) {
1693 buf = (char *)MALLOC(dhd->pub.osh, buflen);
1695 bcmerror = -BCME_NOMEM;
1698 if (copy_from_user(buf, ioc.buf, buflen)) {
1699 bcmerror = -BCME_BADADDR;
1705 /* To differentiate between wl and dhd read 4 more byes */
1706 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1707 sizeof(uint)) != 0)) {
1708 bcmerror = -BCME_BADADDR;
1712 if (!capable(CAP_NET_ADMIN)) {
1713 bcmerror = -BCME_EPERM;
1717 /* check for local dhd ioctl and handle it */
1718 if (driver == DHD_IOCTL_MAGIC) {
1719 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1721 dhd->pub.bcmerror = bcmerror;
1725 /* send to dongle (must be up, and wl) */
1726 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1727 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1728 bcmerror = BCME_DONGLE_DOWN;
1732 if (!dhd->pub.iswl) {
1733 bcmerror = BCME_DONGLE_DOWN;
1737 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1738 * prevent M4 encryption.
1740 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1741 ((ioc.cmd == WLC_SET_VAR) &&
1742 !(strncmp("wsec_key", ioc.buf, 9))) ||
1743 ((ioc.cmd == WLC_SET_VAR) &&
1744 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1746 dhd_wait_pend8021x(net);
1748 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1749 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1752 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1754 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1755 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1757 if (!bcmerror && buf && ioc.buf) {
1758 if (copy_to_user(ioc.buf, buf, buflen))
1763 MFREE(dhd->pub.osh, buf, buflen);
1765 return OSL_ERROR(bcmerror);
1768 static int dhd_stop(struct net_device *net)
1770 #if !defined(IGNORE_ETH0_DOWN)
1771 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1773 DHD_TRACE(("%s: Enter\n", __func__));
1774 #ifdef CONFIG_CFG80211
1775 if (IS_CFG80211_FAVORITE()) {
1779 if (dhd->pub.up == 0)
1782 /* Set state and stop OS transmissions */
1784 netif_stop_queue(net);
1786 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1788 #endif /* !defined(IGNORE_ETH0_DOWN) */
1793 static int dhd_open(struct net_device *net)
1795 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1799 int ifidx = dhd_net2idx(dhd, net);
1802 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1804 if (ifidx == 0) { /* do it only for primary eth0 */
1806 /* try to bring up bus */
1807 ret = dhd_bus_start(&dhd->pub);
1809 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1812 atomic_set(&dhd->pend_8021x_cnt, 0);
1814 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1817 /* Get current TOE mode from dongle */
1818 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1819 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1820 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1822 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1825 /* Allow transmit calls */
1826 netif_start_queue(net);
1828 #ifdef CONFIG_CFG80211
1829 if (IS_CFG80211_FAVORITE()) {
1830 if (unlikely(wl_cfg80211_up())) {
1831 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1841 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1843 return osl_attach(pdev, bustype, TRUE);
1846 void dhd_osl_detach(osl_t *osh)
1848 if (MALLOCED(osh)) {
1849 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1856 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1857 u8 *mac_addr, u32 flags, u8 bssidx)
1861 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1863 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1865 ifp = dhd->iflist[ifidx];
1866 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1867 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1871 memset(ifp, 0, sizeof(dhd_if_t));
1873 dhd->iflist[ifidx] = ifp;
1874 strncpy(ifp->name, name, IFNAMSIZ);
1875 ifp->name[IFNAMSIZ] = '\0';
1876 if (mac_addr != NULL)
1877 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1879 if (handle == NULL) {
1880 ifp->state = WLC_E_IF_ADD;
1882 ASSERT(dhd->sysioc_pid >= 0);
1883 up(&dhd->sysioc_sem);
1885 ifp->net = (struct net_device *)handle;
1890 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1894 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1896 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1897 ifp = dhd->iflist[ifidx];
1899 DHD_ERROR(("%s: Null interface\n", __func__));
1903 ifp->state = WLC_E_IF_DEL;
1905 ASSERT(dhd->sysioc_pid >= 0);
1906 up(&dhd->sysioc_sem);
1909 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1911 dhd_info_t *dhd = NULL;
1912 struct net_device *net;
1914 DHD_TRACE(("%s: Enter\n", __func__));
1915 /* updates firmware nvram path if it was provided as module
1917 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1918 strcpy(fw_path, firmware_path);
1919 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1920 strcpy(nv_path, nvram_path);
1922 /* Allocate etherdev, including space for private structure */
1923 net = alloc_etherdev(sizeof(dhd));
1925 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1929 /* Allocate primary dhd_info */
1930 dhd = MALLOC(osh, sizeof(dhd_info_t));
1932 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1936 memset(dhd, 0, sizeof(dhd_info_t));
1939 * Save the dhd_info into the priv
1941 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1944 /* Set network interface name if it was provided as module parameter */
1945 if (iface_name[0]) {
1948 strncpy(net->name, iface_name, IFNAMSIZ);
1949 net->name[IFNAMSIZ - 1] = 0;
1950 len = strlen(net->name);
1951 ch = net->name[len - 1];
1952 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1953 strcat(net->name, "%d");
1956 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1960 net->netdev_ops = NULL;
1961 init_MUTEX(&dhd->proto_sem);
1962 /* Initialize other structure content */
1963 init_waitqueue_head(&dhd->ioctl_resp_wait);
1964 init_waitqueue_head(&dhd->ctrl_wait);
1966 /* Initialize the spinlocks */
1967 spin_lock_init(&dhd->sdlock);
1968 spin_lock_init(&dhd->txqlock);
1970 /* Link to info module */
1971 dhd->pub.info = dhd;
1973 /* Link to bus module */
1975 dhd->pub.hdrlen = bus_hdrlen;
1977 /* Attach and link in the protocol */
1978 if (dhd_prot_attach(&dhd->pub) != 0) {
1979 DHD_ERROR(("dhd_prot_attach failed\n"));
1982 #if defined(CONFIG_WIRELESS_EXT)
1983 /* Attach and link in the iw */
1984 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1985 DHD_ERROR(("wl_iw_attach failed\n"));
1988 #endif /* defined(CONFIG_WIRELESS_EXT) */
1990 #ifdef CONFIG_CFG80211
1991 /* Attach and link in the cfg80211 */
1992 if (IS_CFG80211_FAVORITE()) {
1993 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1994 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1998 strcpy(fw_path, wl_cfg80211_get_fwname());
1999 strcpy(nv_path, wl_cfg80211_get_nvramname());
2001 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
2005 /* Set up the watchdog timer */
2006 init_timer(&dhd->timer);
2007 dhd->timer.data = (unsigned long) dhd;
2008 dhd->timer.function = dhd_watchdog;
2010 /* Initialize thread based operation and lock */
2011 init_MUTEX(&dhd->sdsem);
2012 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
2013 dhd->threads_only = TRUE;
2015 dhd->threads_only = FALSE;
2017 if (dhd_dpc_prio >= 0) {
2018 /* Initialize watchdog thread */
2019 sema_init(&dhd->watchdog_sem, 0);
2020 init_completion(&dhd->watchdog_exited);
2021 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2023 dhd->watchdog_pid = -1;
2026 /* Set up the bottom half handler */
2027 if (dhd_dpc_prio >= 0) {
2028 /* Initialize DPC thread */
2029 sema_init(&dhd->dpc_sem, 0);
2030 init_completion(&dhd->dpc_exited);
2031 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2033 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2038 sema_init(&dhd->sysioc_sem, 0);
2039 init_completion(&dhd->sysioc_exited);
2040 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2042 dhd->sysioc_pid = -1;
2046 * Save the dhd_info into the priv
2048 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2050 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2053 #if defined(CONFIG_PM_SLEEP)
2054 register_pm_notifier(&dhd_sleep_pm_notifier);
2055 #endif /* defined(CONFIG_PM_SLEEP) */
2056 /* && defined(DHD_GPL) */
2057 /* Init lock suspend to prevent kernel going to suspend */
2058 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2059 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2060 "dhd_wake_lock_link_dw_event");
2061 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2062 "dhd_wake_lock_link_pno_find_event");
2063 #ifdef CONFIG_HAS_EARLYSUSPEND
2064 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2065 dhd->early_suspend.suspend = dhd_early_suspend;
2066 dhd->early_suspend.resume = dhd_late_resume;
2067 register_early_suspend(&dhd->early_suspend);
2076 dhd_detach(&dhd->pub);
2081 int dhd_bus_start(dhd_pub_t *dhdp)
2084 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2085 #ifdef EMBEDDED_PLATFORM
2086 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2088 #endif /* EMBEDDED_PLATFORM */
2092 DHD_TRACE(("%s:\n", __func__));
2094 /* try to download image and nvram to the dongle */
2095 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2096 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2097 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2098 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2099 fw_path, nv_path))) {
2100 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2101 "firmware = %s nvram = %s\n",
2102 __func__, fw_path, nv_path));
2103 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2104 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2108 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2109 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2112 /* Start the watchdog timer */
2113 dhd->pub.tickcnt = 0;
2114 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2116 /* Bring up the bus */
2117 ret = dhd_bus_init(&dhd->pub, TRUE);
2119 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2122 #if defined(OOB_INTR_ONLY)
2123 /* Host registration for OOB interrupt */
2124 if (bcmsdh_register_oob_intr(dhdp)) {
2125 del_timer_sync(&dhd->timer);
2126 dhd->wd_timer_valid = FALSE;
2127 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2131 /* Enable oob at firmware */
2132 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2133 #endif /* defined(OOB_INTR_ONLY) */
2135 /* If bus is not ready, can't come up */
2136 if (dhd->pub.busstate != DHD_BUS_DATA) {
2137 del_timer_sync(&dhd->timer);
2138 dhd->wd_timer_valid = FALSE;
2139 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2142 #ifdef EMBEDDED_PLATFORM
2143 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2145 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2146 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2148 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2149 setbit(dhdp->eventmask, WLC_E_PRUNE);
2150 setbit(dhdp->eventmask, WLC_E_AUTH);
2151 setbit(dhdp->eventmask, WLC_E_REASSOC);
2152 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2153 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2154 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2155 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2156 setbit(dhdp->eventmask, WLC_E_JOIN);
2157 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2158 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2159 setbit(dhdp->eventmask, WLC_E_LINK);
2160 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2161 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2162 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2163 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2164 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2165 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2167 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2168 #endif /* PNO_SUPPORT */
2170 /* enable dongle roaming event */
2172 dhdp->pktfilter_count = 1;
2173 /* Setup filter to allow only unicast */
2174 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2175 #endif /* EMBEDDED_PLATFORM */
2177 /* Bus is ready, do any protocol initialization */
2178 ret = dhd_prot_init(&dhd->pub);
2186 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2189 char buf[strlen(name) + 1 + cmd_len];
2190 int len = sizeof(buf);
2194 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2196 memset(&ioc, 0, sizeof(ioc));
2198 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2203 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2204 if (!set && ret >= 0)
2205 memcpy(cmd_buf, buf, cmd_len);
2210 static struct net_device_ops dhd_ops_pri = {
2211 .ndo_open = dhd_open,
2212 .ndo_stop = dhd_stop,
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 static struct net_device_ops dhd_ops_virt = {
2221 .ndo_get_stats = dhd_get_stats,
2222 .ndo_do_ioctl = dhd_ioctl_entry,
2223 .ndo_start_xmit = dhd_start_xmit,
2224 .ndo_set_mac_address = dhd_set_mac_address,
2225 .ndo_set_multicast_list = dhd_set_multicast_list
2228 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2230 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2231 struct net_device *net;
2232 u8 temp_addr[ETHER_ADDR_LEN] = {
2233 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2235 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2237 ASSERT(dhd && dhd->iflist[ifidx]);
2239 net = dhd->iflist[ifidx]->net;
2242 ASSERT(!net->netdev_ops);
2243 net->netdev_ops = &dhd_ops_virt;
2245 net->netdev_ops = &dhd_ops_pri;
2248 * We have to use the primary MAC for virtual interfaces
2251 /* for virtual interfaces use the primary MAC */
2252 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2257 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2258 /* ACCESSPOINT INTERFACE CASE */
2259 temp_addr[0] |= 0X02; /* set bit 2 ,
2260 - Locally Administered address */
2263 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2264 net->ethtool_ops = &dhd_ethtool_ops;
2266 #if defined(CONFIG_WIRELESS_EXT)
2267 #if defined(CONFIG_CFG80211)
2268 if (!IS_CFG80211_FAVORITE()) {
2270 #if WIRELESS_EXT < 19
2271 net->get_wireless_stats = dhd_get_wireless_stats;
2272 #endif /* WIRELESS_EXT < 19 */
2273 #if WIRELESS_EXT > 12
2274 net->wireless_handlers =
2275 (struct iw_handler_def *)&wl_iw_handler_def;
2276 #endif /* WIRELESS_EXT > 12 */
2277 #if defined(CONFIG_CFG80211)
2280 #endif /* defined(CONFIG_WIRELESS_EXT) */
2282 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2284 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2286 if (register_netdev(net) != 0) {
2287 DHD_ERROR(("%s: couldn't register the net device\n",
2292 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2297 net->netdev_ops = NULL;
2301 void dhd_bus_detach(dhd_pub_t *dhdp)
2305 DHD_TRACE(("%s: Enter\n", __func__));
2308 dhd = (dhd_info_t *) dhdp->info;
2310 /* Stop the protocol module */
2311 dhd_prot_stop(&dhd->pub);
2313 /* Stop the bus module */
2314 dhd_bus_stop(dhd->pub.bus, TRUE);
2315 #if defined(OOB_INTR_ONLY)
2316 bcmsdh_unregister_oob_intr();
2317 #endif /* defined(OOB_INTR_ONLY) */
2319 /* Clear the watchdog timer */
2320 del_timer_sync(&dhd->timer);
2321 dhd->wd_timer_valid = FALSE;
2326 void dhd_detach(dhd_pub_t *dhdp)
2330 DHD_TRACE(("%s: Enter\n", __func__));
2333 dhd = (dhd_info_t *) dhdp->info;
2338 #if defined(CONFIG_HAS_EARLYSUSPEND)
2339 if (dhd->early_suspend.suspend)
2340 unregister_early_suspend(&dhd->early_suspend);
2341 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2343 for (i = 1; i < DHD_MAX_IFS; i++)
2347 ifp = dhd->iflist[0];
2349 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2351 unregister_netdev(ifp->net);
2354 if (dhd->watchdog_pid >= 0) {
2355 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2356 wait_for_completion(&dhd->watchdog_exited);
2359 if (dhd->dpc_pid >= 0) {
2360 KILL_PROC(dhd->dpc_pid, SIGTERM);
2361 wait_for_completion(&dhd->dpc_exited);
2363 tasklet_kill(&dhd->tasklet);
2365 if (dhd->sysioc_pid >= 0) {
2366 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2367 wait_for_completion(&dhd->sysioc_exited);
2370 dhd_bus_detach(dhdp);
2373 dhd_prot_detach(dhdp);
2375 #if defined(CONFIG_WIRELESS_EXT)
2377 #endif /* (CONFIG_WIRELESS_EXT) */
2379 #ifdef CONFIG_CFG80211
2380 if (IS_CFG80211_FAVORITE())
2381 wl_cfg80211_detach();
2382 #endif /* CONFIG_CFG80211 */
2384 #if defined(CONFIG_PM_SLEEP)
2385 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2386 #endif /* defined(CONFIG_PM_SLEEP) */
2387 /* && defined(DHD_GPL) */
2388 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2389 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2390 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2391 free_netdev(ifp->net);
2392 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2393 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2398 static void __exit dhd_module_cleanup(void)
2400 DHD_TRACE(("%s: Enter\n", __func__));
2402 dhd_bus_unregister();
2403 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2406 /* Call customer gpio to turn off power with WL_REG_ON signal */
2407 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2410 static int __init dhd_module_init(void)
2414 DHD_TRACE(("%s: Enter\n", __func__));
2416 /* Sanity check on the module parameters */
2418 /* Both watchdog and DPC as tasklets are ok */
2419 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2422 /* If both watchdog and DPC are threads, TX must be deferred */
2423 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2427 DHD_ERROR(("Invalid module parameters.\n"));
2430 /* Call customer gpio to turn on power with WL_REG_ON signal */
2431 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2433 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2434 sema_init(&wifi_control_sem, 0);
2436 error = wifi_add_dev();
2438 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2442 /* Waiting callback after platform_driver_register is done or
2444 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2445 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2451 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2453 error = dhd_bus_register();
2456 printf("\n%s\n", dhd_version);
2458 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2464 /* turn off power and exit */
2465 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2469 module_init(dhd_module_init);
2470 module_exit(dhd_module_cleanup);
2473 * OS specific functions required to implement DHD driver in OS independent way
2475 int dhd_os_proto_block(dhd_pub_t *pub)
2477 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2480 down(&dhd->proto_sem);
2486 int dhd_os_proto_unblock(dhd_pub_t *pub)
2488 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2491 up(&dhd->proto_sem);
2498 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2500 return (unsigned int)dhd_ioctl_timeout_msec;
2503 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2505 dhd_ioctl_timeout_msec = (int)timeout_msec;
2508 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2510 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2511 DECLARE_WAITQUEUE(wait, current);
2512 int timeout = dhd_ioctl_timeout_msec;
2514 /* Convert timeout in millsecond to jiffies */
2515 timeout = timeout * HZ / 1000;
2517 /* Wait until control frame is available */
2518 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2519 set_current_state(TASK_INTERRUPTIBLE);
2521 while (!(*condition) && (!signal_pending(current) && timeout))
2522 timeout = schedule_timeout(timeout);
2524 if (signal_pending(current))
2527 set_current_state(TASK_RUNNING);
2528 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2533 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2535 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2537 if (waitqueue_active(&dhd->ioctl_resp_wait))
2538 wake_up_interruptible(&dhd->ioctl_resp_wait);
2543 void dhd_os_wd_timer(void *bus, uint wdtick)
2545 dhd_pub_t *pub = bus;
2546 static uint save_dhd_watchdog_ms;
2547 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2549 /* don't start the wd until fw is loaded */
2550 if (pub->busstate == DHD_BUS_DOWN)
2553 /* Totally stop the timer */
2554 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2555 del_timer_sync(&dhd->timer);
2556 dhd->wd_timer_valid = FALSE;
2557 save_dhd_watchdog_ms = wdtick;
2562 dhd_watchdog_ms = (uint) wdtick;
2564 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2566 if (dhd->wd_timer_valid == TRUE)
2567 /* Stop timer and restart at new value */
2568 del_timer_sync(&dhd->timer);
2570 /* Create timer again when watchdog period is
2571 dynamically changed or in the first instance
2573 dhd->timer.expires =
2574 jiffies + dhd_watchdog_ms * HZ / 1000;
2575 add_timer(&dhd->timer);
2578 /* Re arm the timer, at last watchdog period */
2579 mod_timer(&dhd->timer,
2580 jiffies + dhd_watchdog_ms * HZ / 1000);
2583 dhd->wd_timer_valid = TRUE;
2584 save_dhd_watchdog_ms = wdtick;
2588 void *dhd_os_open_image(char *filename)
2592 #ifdef CONFIG_CFG80211
2593 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2594 return wl_cfg80211_request_fw(filename);
2597 fp = filp_open(filename, O_RDONLY, 0);
2599 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2601 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2610 int dhd_os_get_image_block(char *buf, int len, void *image)
2612 struct file *fp = (struct file *)image;
2615 #ifdef CONFIG_CFG80211
2616 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2617 return wl_cfg80211_read_fw(buf, len);
2623 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2630 void dhd_os_close_image(void *image)
2632 #ifdef CONFIG_CFG80211
2633 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2634 return wl_cfg80211_release_fw();
2637 filp_close((struct file *)image, NULL);
2640 void dhd_os_sdlock(dhd_pub_t *pub)
2644 dhd = (dhd_info_t *) (pub->info);
2646 if (dhd->threads_only)
2649 spin_lock_bh(&dhd->sdlock);
2652 void dhd_os_sdunlock(dhd_pub_t *pub)
2656 dhd = (dhd_info_t *) (pub->info);
2658 if (dhd->threads_only)
2661 spin_unlock_bh(&dhd->sdlock);
2664 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2668 dhd = (dhd_info_t *) (pub->info);
2669 spin_lock_bh(&dhd->txqlock);
2672 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2676 dhd = (dhd_info_t *) (pub->info);
2677 spin_unlock_bh(&dhd->txqlock);
2680 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2684 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2688 void dhd_os_sdtxlock(dhd_pub_t *pub)
2693 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2695 dhd_os_sdunlock(pub);
2698 #ifdef DHD_USE_STATIC_BUF
2699 void *dhd_os_prealloc(int section, unsigned long size)
2701 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2702 void *alloc_ptr = NULL;
2703 if (wifi_control_data && wifi_control_data->mem_prealloc) {
2704 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2706 DHD_INFO(("success alloc section %d\n", section));
2707 bzero(alloc_ptr, size);
2712 DHD_ERROR(("can't alloc section %d\n", section));
2715 return MALLOC(0, size);
2716 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2718 #endif /* DHD_USE_STATIC_BUF */
2719 #if defined(CONFIG_WIRELESS_EXT)
2720 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2723 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2725 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2728 return &dhd->iw.wstats;
2732 #endif /* defined(CONFIG_WIRELESS_EXT) */
2735 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2736 wl_event_msg_t *event, void **data)
2740 ASSERT(dhd != NULL);
2742 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2743 if (bcmerror != BCME_OK)
2746 #if defined(CONFIG_WIRELESS_EXT)
2747 #if defined(CONFIG_CFG80211)
2748 if (!IS_CFG80211_FAVORITE()) {
2750 if ((dhd->iflist[*ifidx] == NULL)
2751 || (dhd->iflist[*ifidx]->net == NULL)) {
2752 DHD_ERROR(("%s Exit null pointer\n", __func__));
2756 if (dhd->iflist[*ifidx]->net)
2757 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2758 #if defined(CONFIG_CFG80211)
2761 #endif /* defined(CONFIG_WIRELESS_EXT) */
2763 #ifdef CONFIG_CFG80211
2764 if (IS_CFG80211_FAVORITE()) {
2765 ASSERT(dhd->iflist[*ifidx] != NULL);
2766 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2767 if (dhd->iflist[*ifidx]->net)
2768 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2776 /* send up locally generated event */
2777 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2779 switch (ntoh32(event->event_type)) {
2785 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2787 struct dhd_info *dhdinfo = dhd->info;
2788 dhd_os_sdunlock(dhd);
2789 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2790 (*lockvar == FALSE), HZ * 2);
2795 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2797 struct dhd_info *dhdinfo = dhd->info;
2798 if (waitqueue_active(&dhdinfo->ctrl_wait))
2799 wake_up_interruptible(&dhdinfo->ctrl_wait);
2803 int dhd_dev_reset(struct net_device *dev, u8 flag)
2805 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2807 /* Turning off watchdog */
2809 dhd_os_wd_timer(&dhd->pub, 0);
2811 dhd_bus_devreset(&dhd->pub, flag);
2813 /* Turning on watchdog back */
2815 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2816 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2821 int net_os_set_suspend_disable(struct net_device *dev, int val)
2823 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2827 ret = dhd->pub.suspend_disable_flag;
2828 dhd->pub.suspend_disable_flag = val;
2833 int net_os_set_suspend(struct net_device *dev, int val)
2836 #if defined(CONFIG_HAS_EARLYSUSPEND)
2837 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2840 dhd_os_proto_block(&dhd->pub);
2841 ret = dhd_set_suspend(val, &dhd->pub);
2842 dhd_os_proto_unblock(&dhd->pub);
2844 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2848 int net_os_set_dtim_skip(struct net_device *dev, int val)
2850 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2853 dhd->pub.dtim_skip = val;
2858 int net_os_set_packet_filter(struct net_device *dev, int val)
2860 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2863 /* Packet filtering is set only if we still in early-suspend and
2864 * we need either to turn it ON or turn it OFF
2865 * We can always turn it OFF in case of early-suspend, but we turn it
2866 * back ON only if suspend_disable_flag was not set
2868 if (dhd && dhd->pub.up) {
2869 dhd_os_proto_block(&dhd->pub);
2870 if (dhd->pub.in_suspend) {
2871 if (!val || (val && !dhd->pub.suspend_disable_flag))
2872 dhd_set_packet_filter(val, &dhd->pub);
2874 dhd_os_proto_unblock(&dhd->pub);
2879 void dhd_dev_init_ioctl(struct net_device *dev)
2881 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2883 dhd_preinit_ioctls(&dhd->pub);
2887 /* Linux wrapper to call common dhd_pno_clean */
2888 int dhd_dev_pno_reset(struct net_device *dev)
2890 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2892 return dhd_pno_clean(&dhd->pub);
2895 /* Linux wrapper to call common dhd_pno_enable */
2896 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2898 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2900 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2903 /* Linux wrapper to call common dhd_pno_set */
2905 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2906 unsigned char scan_fr)
2908 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2910 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2913 /* Linux wrapper to get pno status */
2914 int dhd_dev_get_pno_status(struct net_device *dev)
2916 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2918 return dhd_pno_get_status(&dhd->pub);
2921 #endif /* PNO_SUPPORT */
2923 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2925 return atomic_read(&dhd->pend_8021x_cnt);
2928 #define MAX_WAIT_FOR_8021X_TX 10
2930 int dhd_wait_pend8021x(struct net_device *dev)
2932 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2933 int timeout = 10 * HZ / 1000;
2934 int ntimes = MAX_WAIT_FOR_8021X_TX;
2935 int pend = dhd_get_pend_8021x_cnt(dhd);
2937 while (ntimes && pend) {
2939 set_current_state(TASK_INTERRUPTIBLE);
2940 schedule_timeout(timeout);
2941 set_current_state(TASK_RUNNING);
2944 pend = dhd_get_pend_8021x_cnt(dhd);
2950 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2954 mm_segment_t old_fs;
2957 /* change to KERNEL_DS address limit */
2961 /* open file to write */
2962 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2964 printf("%s: open file error\n", __func__);
2969 /* Write buf to file */
2970 fp->f_op->write(fp, buf, size, &pos);
2973 /* free buf before return */
2974 MFREE(dhd->osh, buf, size);
2975 /* close file before return */
2977 filp_close(fp, current->files);
2978 /* restore previous address limit */
2983 #endif /* DHD_DEBUG */