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, uint32 *toe_ol);
429 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 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;
715 uint32 allmulti, cnt;
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, uint32 *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(uint32));
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, uint32 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(uint32));
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(uint32));
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 uint32 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(uint32)))
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) */
1790 OLD_MOD_DEC_USE_COUNT;
1794 static int dhd_open(struct net_device *net)
1796 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1800 int ifidx = dhd_net2idx(dhd, net);
1803 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1805 if (ifidx == 0) { /* do it only for primary eth0 */
1807 /* try to bring up bus */
1808 ret = dhd_bus_start(&dhd->pub);
1810 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1813 atomic_set(&dhd->pend_8021x_cnt, 0);
1815 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1818 /* Get current TOE mode from dongle */
1819 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1820 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1821 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1823 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1826 /* Allow transmit calls */
1827 netif_start_queue(net);
1829 #ifdef CONFIG_CFG80211
1830 if (IS_CFG80211_FAVORITE()) {
1831 if (unlikely(wl_cfg80211_up())) {
1832 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1839 OLD_MOD_INC_USE_COUNT;
1843 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1845 return osl_attach(pdev, bustype, TRUE);
1848 void dhd_osl_detach(osl_t *osh)
1850 if (MALLOCED(osh)) {
1851 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1858 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1859 u8 *mac_addr, uint32 flags, u8 bssidx)
1863 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1865 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1867 ifp = dhd->iflist[ifidx];
1868 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1869 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1873 memset(ifp, 0, sizeof(dhd_if_t));
1875 dhd->iflist[ifidx] = ifp;
1876 strncpy(ifp->name, name, IFNAMSIZ);
1877 ifp->name[IFNAMSIZ] = '\0';
1878 if (mac_addr != NULL)
1879 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1881 if (handle == NULL) {
1882 ifp->state = WLC_E_IF_ADD;
1884 ASSERT(dhd->sysioc_pid >= 0);
1885 up(&dhd->sysioc_sem);
1887 ifp->net = (struct net_device *)handle;
1892 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1896 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1898 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1899 ifp = dhd->iflist[ifidx];
1901 DHD_ERROR(("%s: Null interface\n", __func__));
1905 ifp->state = WLC_E_IF_DEL;
1907 ASSERT(dhd->sysioc_pid >= 0);
1908 up(&dhd->sysioc_sem);
1911 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1913 dhd_info_t *dhd = NULL;
1914 struct net_device *net;
1916 DHD_TRACE(("%s: Enter\n", __func__));
1917 /* updates firmware nvram path if it was provided as module
1919 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1920 strcpy(fw_path, firmware_path);
1921 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1922 strcpy(nv_path, nvram_path);
1924 /* Allocate etherdev, including space for private structure */
1925 net = alloc_etherdev(sizeof(dhd));
1927 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1931 /* Allocate primary dhd_info */
1932 dhd = MALLOC(osh, sizeof(dhd_info_t));
1934 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1938 memset(dhd, 0, sizeof(dhd_info_t));
1941 * Save the dhd_info into the priv
1943 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1946 /* Set network interface name if it was provided as module parameter */
1947 if (iface_name[0]) {
1950 strncpy(net->name, iface_name, IFNAMSIZ);
1951 net->name[IFNAMSIZ - 1] = 0;
1952 len = strlen(net->name);
1953 ch = net->name[len - 1];
1954 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1955 strcat(net->name, "%d");
1958 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1962 net->netdev_ops = NULL;
1963 init_MUTEX(&dhd->proto_sem);
1964 /* Initialize other structure content */
1965 init_waitqueue_head(&dhd->ioctl_resp_wait);
1966 init_waitqueue_head(&dhd->ctrl_wait);
1968 /* Initialize the spinlocks */
1969 spin_lock_init(&dhd->sdlock);
1970 spin_lock_init(&dhd->txqlock);
1972 /* Link to info module */
1973 dhd->pub.info = dhd;
1975 /* Link to bus module */
1977 dhd->pub.hdrlen = bus_hdrlen;
1979 /* Attach and link in the protocol */
1980 if (dhd_prot_attach(&dhd->pub) != 0) {
1981 DHD_ERROR(("dhd_prot_attach failed\n"));
1984 #if defined(CONFIG_WIRELESS_EXT)
1985 /* Attach and link in the iw */
1986 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1987 DHD_ERROR(("wl_iw_attach failed\n"));
1990 #endif /* defined(CONFIG_WIRELESS_EXT) */
1992 #ifdef CONFIG_CFG80211
1993 /* Attach and link in the cfg80211 */
1994 if (IS_CFG80211_FAVORITE()) {
1995 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1996 DHD_ERROR(("wl_cfg80211_attach failed\n"));
2000 strcpy(fw_path, wl_cfg80211_get_fwname());
2001 strcpy(nv_path, wl_cfg80211_get_nvramname());
2003 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
2007 /* Set up the watchdog timer */
2008 init_timer(&dhd->timer);
2009 dhd->timer.data = (unsigned long) dhd;
2010 dhd->timer.function = dhd_watchdog;
2012 /* Initialize thread based operation and lock */
2013 init_MUTEX(&dhd->sdsem);
2014 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
2015 dhd->threads_only = TRUE;
2017 dhd->threads_only = FALSE;
2019 if (dhd_dpc_prio >= 0) {
2020 /* Initialize watchdog thread */
2021 sema_init(&dhd->watchdog_sem, 0);
2022 init_completion(&dhd->watchdog_exited);
2023 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2025 dhd->watchdog_pid = -1;
2028 /* Set up the bottom half handler */
2029 if (dhd_dpc_prio >= 0) {
2030 /* Initialize DPC thread */
2031 sema_init(&dhd->dpc_sem, 0);
2032 init_completion(&dhd->dpc_exited);
2033 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2035 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2040 sema_init(&dhd->sysioc_sem, 0);
2041 init_completion(&dhd->sysioc_exited);
2042 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2044 dhd->sysioc_pid = -1;
2048 * Save the dhd_info into the priv
2050 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2052 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2055 #if defined(CONFIG_PM_SLEEP)
2056 register_pm_notifier(&dhd_sleep_pm_notifier);
2057 #endif /* defined(CONFIG_PM_SLEEP) */
2058 /* && defined(DHD_GPL) */
2059 /* Init lock suspend to prevent kernel going to suspend */
2060 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2061 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2062 "dhd_wake_lock_link_dw_event");
2063 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2064 "dhd_wake_lock_link_pno_find_event");
2065 #ifdef CONFIG_HAS_EARLYSUSPEND
2066 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2067 dhd->early_suspend.suspend = dhd_early_suspend;
2068 dhd->early_suspend.resume = dhd_late_resume;
2069 register_early_suspend(&dhd->early_suspend);
2078 dhd_detach(&dhd->pub);
2083 int dhd_bus_start(dhd_pub_t *dhdp)
2086 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2087 #ifdef EMBEDDED_PLATFORM
2088 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2090 #endif /* EMBEDDED_PLATFORM */
2094 DHD_TRACE(("%s:\n", __func__));
2096 /* try to download image and nvram to the dongle */
2097 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2098 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2099 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2100 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2101 fw_path, nv_path))) {
2102 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2103 "firmware = %s nvram = %s\n",
2104 __func__, fw_path, nv_path));
2105 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2106 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2110 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2111 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2114 /* Start the watchdog timer */
2115 dhd->pub.tickcnt = 0;
2116 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2118 /* Bring up the bus */
2119 ret = dhd_bus_init(&dhd->pub, TRUE);
2121 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2124 #if defined(OOB_INTR_ONLY)
2125 /* Host registration for OOB interrupt */
2126 if (bcmsdh_register_oob_intr(dhdp)) {
2127 del_timer_sync(&dhd->timer);
2128 dhd->wd_timer_valid = FALSE;
2129 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2133 /* Enable oob at firmware */
2134 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2135 #endif /* defined(OOB_INTR_ONLY) */
2137 /* If bus is not ready, can't come up */
2138 if (dhd->pub.busstate != DHD_BUS_DATA) {
2139 del_timer_sync(&dhd->timer);
2140 dhd->wd_timer_valid = FALSE;
2141 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2144 #ifdef EMBEDDED_PLATFORM
2145 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2147 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2148 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2150 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2151 setbit(dhdp->eventmask, WLC_E_PRUNE);
2152 setbit(dhdp->eventmask, WLC_E_AUTH);
2153 setbit(dhdp->eventmask, WLC_E_REASSOC);
2154 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2155 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2156 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2157 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2158 setbit(dhdp->eventmask, WLC_E_JOIN);
2159 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2160 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2161 setbit(dhdp->eventmask, WLC_E_LINK);
2162 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2163 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2164 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2165 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2166 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2167 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2169 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2170 #endif /* PNO_SUPPORT */
2172 /* enable dongle roaming event */
2174 dhdp->pktfilter_count = 1;
2175 /* Setup filter to allow only unicast */
2176 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2177 #endif /* EMBEDDED_PLATFORM */
2179 /* Bus is ready, do any protocol initialization */
2180 ret = dhd_prot_init(&dhd->pub);
2188 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2191 char buf[strlen(name) + 1 + cmd_len];
2192 int len = sizeof(buf);
2196 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2198 memset(&ioc, 0, sizeof(ioc));
2200 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2205 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2206 if (!set && ret >= 0)
2207 memcpy(cmd_buf, buf, cmd_len);
2212 static struct net_device_ops dhd_ops_pri = {
2213 .ndo_open = dhd_open,
2214 .ndo_stop = dhd_stop,
2215 .ndo_get_stats = dhd_get_stats,
2216 .ndo_do_ioctl = dhd_ioctl_entry,
2217 .ndo_start_xmit = dhd_start_xmit,
2218 .ndo_set_mac_address = dhd_set_mac_address,
2219 .ndo_set_multicast_list = dhd_set_multicast_list
2222 static struct net_device_ops dhd_ops_virt = {
2223 .ndo_get_stats = dhd_get_stats,
2224 .ndo_do_ioctl = dhd_ioctl_entry,
2225 .ndo_start_xmit = dhd_start_xmit,
2226 .ndo_set_mac_address = dhd_set_mac_address,
2227 .ndo_set_multicast_list = dhd_set_multicast_list
2230 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2232 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2233 struct net_device *net;
2234 u8 temp_addr[ETHER_ADDR_LEN] = {
2235 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2237 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2239 ASSERT(dhd && dhd->iflist[ifidx]);
2241 net = dhd->iflist[ifidx]->net;
2244 ASSERT(!net->netdev_ops);
2245 net->netdev_ops = &dhd_ops_virt;
2247 net->netdev_ops = &dhd_ops_pri;
2250 * We have to use the primary MAC for virtual interfaces
2253 /* for virtual interfaces use the primary MAC */
2254 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2259 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2260 /* ACCESSPOINT INTERFACE CASE */
2261 temp_addr[0] |= 0X02; /* set bit 2 ,
2262 - Locally Administered address */
2265 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2266 net->ethtool_ops = &dhd_ethtool_ops;
2268 #if defined(CONFIG_WIRELESS_EXT)
2269 #if defined(CONFIG_CFG80211)
2270 if (!IS_CFG80211_FAVORITE()) {
2272 #if WIRELESS_EXT < 19
2273 net->get_wireless_stats = dhd_get_wireless_stats;
2274 #endif /* WIRELESS_EXT < 19 */
2275 #if WIRELESS_EXT > 12
2276 net->wireless_handlers =
2277 (struct iw_handler_def *)&wl_iw_handler_def;
2278 #endif /* WIRELESS_EXT > 12 */
2279 #if defined(CONFIG_CFG80211)
2282 #endif /* defined(CONFIG_WIRELESS_EXT) */
2284 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2286 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2288 if (register_netdev(net) != 0) {
2289 DHD_ERROR(("%s: couldn't register the net device\n",
2294 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2299 net->netdev_ops = NULL;
2303 void dhd_bus_detach(dhd_pub_t *dhdp)
2307 DHD_TRACE(("%s: Enter\n", __func__));
2310 dhd = (dhd_info_t *) dhdp->info;
2312 /* Stop the protocol module */
2313 dhd_prot_stop(&dhd->pub);
2315 /* Stop the bus module */
2316 dhd_bus_stop(dhd->pub.bus, TRUE);
2317 #if defined(OOB_INTR_ONLY)
2318 bcmsdh_unregister_oob_intr();
2319 #endif /* defined(OOB_INTR_ONLY) */
2321 /* Clear the watchdog timer */
2322 del_timer_sync(&dhd->timer);
2323 dhd->wd_timer_valid = FALSE;
2328 void dhd_detach(dhd_pub_t *dhdp)
2332 DHD_TRACE(("%s: Enter\n", __func__));
2335 dhd = (dhd_info_t *) dhdp->info;
2340 #if defined(CONFIG_HAS_EARLYSUSPEND)
2341 if (dhd->early_suspend.suspend)
2342 unregister_early_suspend(&dhd->early_suspend);
2343 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2345 for (i = 1; i < DHD_MAX_IFS; i++)
2349 ifp = dhd->iflist[0];
2351 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2353 unregister_netdev(ifp->net);
2356 if (dhd->watchdog_pid >= 0) {
2357 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2358 wait_for_completion(&dhd->watchdog_exited);
2361 if (dhd->dpc_pid >= 0) {
2362 KILL_PROC(dhd->dpc_pid, SIGTERM);
2363 wait_for_completion(&dhd->dpc_exited);
2365 tasklet_kill(&dhd->tasklet);
2367 if (dhd->sysioc_pid >= 0) {
2368 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2369 wait_for_completion(&dhd->sysioc_exited);
2372 dhd_bus_detach(dhdp);
2375 dhd_prot_detach(dhdp);
2377 #if defined(CONFIG_WIRELESS_EXT)
2379 #endif /* (CONFIG_WIRELESS_EXT) */
2381 #ifdef CONFIG_CFG80211
2382 if (IS_CFG80211_FAVORITE())
2383 wl_cfg80211_detach();
2384 #endif /* CONFIG_CFG80211 */
2386 #if defined(CONFIG_PM_SLEEP)
2387 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2388 #endif /* defined(CONFIG_PM_SLEEP) */
2389 /* && defined(DHD_GPL) */
2390 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2391 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2392 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2393 free_netdev(ifp->net);
2394 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2395 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2400 static void __exit dhd_module_cleanup(void)
2402 DHD_TRACE(("%s: Enter\n", __func__));
2404 dhd_bus_unregister();
2405 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2408 /* Call customer gpio to turn off power with WL_REG_ON signal */
2409 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2412 static int __init dhd_module_init(void)
2416 DHD_TRACE(("%s: Enter\n", __func__));
2418 /* Sanity check on the module parameters */
2420 /* Both watchdog and DPC as tasklets are ok */
2421 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2424 /* If both watchdog and DPC are threads, TX must be deferred */
2425 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2429 DHD_ERROR(("Invalid module parameters.\n"));
2432 /* Call customer gpio to turn on power with WL_REG_ON signal */
2433 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2435 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2436 sema_init(&wifi_control_sem, 0);
2438 error = wifi_add_dev();
2440 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2444 /* Waiting callback after platform_driver_register is done or
2446 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2447 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2453 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2455 error = dhd_bus_register();
2458 printf("\n%s\n", dhd_version);
2460 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2466 /* turn off power and exit */
2467 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2471 module_init(dhd_module_init);
2472 module_exit(dhd_module_cleanup);
2475 * OS specific functions required to implement DHD driver in OS independent way
2477 int dhd_os_proto_block(dhd_pub_t *pub)
2479 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2482 down(&dhd->proto_sem);
2488 int dhd_os_proto_unblock(dhd_pub_t *pub)
2490 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2493 up(&dhd->proto_sem);
2500 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2502 return (unsigned int)dhd_ioctl_timeout_msec;
2505 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2507 dhd_ioctl_timeout_msec = (int)timeout_msec;
2510 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2512 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2513 DECLARE_WAITQUEUE(wait, current);
2514 int timeout = dhd_ioctl_timeout_msec;
2516 /* Convert timeout in millsecond to jiffies */
2517 timeout = timeout * HZ / 1000;
2519 /* Wait until control frame is available */
2520 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2521 set_current_state(TASK_INTERRUPTIBLE);
2523 while (!(*condition) && (!signal_pending(current) && timeout))
2524 timeout = schedule_timeout(timeout);
2526 if (signal_pending(current))
2529 set_current_state(TASK_RUNNING);
2530 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2535 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2537 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2539 if (waitqueue_active(&dhd->ioctl_resp_wait))
2540 wake_up_interruptible(&dhd->ioctl_resp_wait);
2545 void dhd_os_wd_timer(void *bus, uint wdtick)
2547 dhd_pub_t *pub = bus;
2548 static uint save_dhd_watchdog_ms;
2549 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2551 /* don't start the wd until fw is loaded */
2552 if (pub->busstate == DHD_BUS_DOWN)
2555 /* Totally stop the timer */
2556 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2557 del_timer_sync(&dhd->timer);
2558 dhd->wd_timer_valid = FALSE;
2559 save_dhd_watchdog_ms = wdtick;
2564 dhd_watchdog_ms = (uint) wdtick;
2566 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2568 if (dhd->wd_timer_valid == TRUE)
2569 /* Stop timer and restart at new value */
2570 del_timer_sync(&dhd->timer);
2572 /* Create timer again when watchdog period is
2573 dynamically changed or in the first instance
2575 dhd->timer.expires =
2576 jiffies + dhd_watchdog_ms * HZ / 1000;
2577 add_timer(&dhd->timer);
2580 /* Re arm the timer, at last watchdog period */
2581 mod_timer(&dhd->timer,
2582 jiffies + dhd_watchdog_ms * HZ / 1000);
2585 dhd->wd_timer_valid = TRUE;
2586 save_dhd_watchdog_ms = wdtick;
2590 void *dhd_os_open_image(char *filename)
2594 #ifdef CONFIG_CFG80211
2595 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2596 return wl_cfg80211_request_fw(filename);
2599 fp = filp_open(filename, O_RDONLY, 0);
2601 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2603 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2612 int dhd_os_get_image_block(char *buf, int len, void *image)
2614 struct file *fp = (struct file *)image;
2617 #ifdef CONFIG_CFG80211
2618 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2619 return wl_cfg80211_read_fw(buf, len);
2625 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2632 void dhd_os_close_image(void *image)
2634 #ifdef CONFIG_CFG80211
2635 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2636 return wl_cfg80211_release_fw();
2639 filp_close((struct file *)image, NULL);
2642 void dhd_os_sdlock(dhd_pub_t *pub)
2646 dhd = (dhd_info_t *) (pub->info);
2648 if (dhd->threads_only)
2651 spin_lock_bh(&dhd->sdlock);
2654 void dhd_os_sdunlock(dhd_pub_t *pub)
2658 dhd = (dhd_info_t *) (pub->info);
2660 if (dhd->threads_only)
2663 spin_unlock_bh(&dhd->sdlock);
2666 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2670 dhd = (dhd_info_t *) (pub->info);
2671 spin_lock_bh(&dhd->txqlock);
2674 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2678 dhd = (dhd_info_t *) (pub->info);
2679 spin_unlock_bh(&dhd->txqlock);
2682 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2686 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2690 void dhd_os_sdtxlock(dhd_pub_t *pub)
2695 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2697 dhd_os_sdunlock(pub);
2700 #ifdef DHD_USE_STATIC_BUF
2701 void *dhd_os_prealloc(int section, unsigned long size)
2703 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2704 void *alloc_ptr = NULL;
2705 if (wifi_control_data && wifi_control_data->mem_prealloc) {
2706 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2708 DHD_INFO(("success alloc section %d\n", section));
2709 bzero(alloc_ptr, size);
2714 DHD_ERROR(("can't alloc section %d\n", section));
2717 return MALLOC(0, size);
2718 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2720 #endif /* DHD_USE_STATIC_BUF */
2721 #if defined(CONFIG_WIRELESS_EXT)
2722 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2725 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2727 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2730 return &dhd->iw.wstats;
2734 #endif /* defined(CONFIG_WIRELESS_EXT) */
2737 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2738 wl_event_msg_t *event, void **data)
2742 ASSERT(dhd != NULL);
2744 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2745 if (bcmerror != BCME_OK)
2748 #if defined(CONFIG_WIRELESS_EXT)
2749 #if defined(CONFIG_CFG80211)
2750 if (!IS_CFG80211_FAVORITE()) {
2752 if ((dhd->iflist[*ifidx] == NULL)
2753 || (dhd->iflist[*ifidx]->net == NULL)) {
2754 DHD_ERROR(("%s Exit null pointer\n", __func__));
2758 if (dhd->iflist[*ifidx]->net)
2759 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2760 #if defined(CONFIG_CFG80211)
2763 #endif /* defined(CONFIG_WIRELESS_EXT) */
2765 #ifdef CONFIG_CFG80211
2766 if (IS_CFG80211_FAVORITE()) {
2767 ASSERT(dhd->iflist[*ifidx] != NULL);
2768 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2769 if (dhd->iflist[*ifidx]->net)
2770 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2778 /* send up locally generated event */
2779 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2781 switch (ntoh32(event->event_type)) {
2787 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2789 struct dhd_info *dhdinfo = dhd->info;
2790 dhd_os_sdunlock(dhd);
2791 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2792 (*lockvar == FALSE), HZ * 2);
2797 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2799 struct dhd_info *dhdinfo = dhd->info;
2800 if (waitqueue_active(&dhdinfo->ctrl_wait))
2801 wake_up_interruptible(&dhdinfo->ctrl_wait);
2805 int dhd_dev_reset(struct net_device *dev, u8 flag)
2807 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2809 /* Turning off watchdog */
2811 dhd_os_wd_timer(&dhd->pub, 0);
2813 dhd_bus_devreset(&dhd->pub, flag);
2815 /* Turning on watchdog back */
2817 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2818 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2823 int net_os_set_suspend_disable(struct net_device *dev, int val)
2825 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2829 ret = dhd->pub.suspend_disable_flag;
2830 dhd->pub.suspend_disable_flag = val;
2835 int net_os_set_suspend(struct net_device *dev, int val)
2838 #if defined(CONFIG_HAS_EARLYSUSPEND)
2839 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2842 dhd_os_proto_block(&dhd->pub);
2843 ret = dhd_set_suspend(val, &dhd->pub);
2844 dhd_os_proto_unblock(&dhd->pub);
2846 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2850 int net_os_set_dtim_skip(struct net_device *dev, int val)
2852 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2855 dhd->pub.dtim_skip = val;
2860 int net_os_set_packet_filter(struct net_device *dev, int val)
2862 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2865 /* Packet filtering is set only if we still in early-suspend and
2866 * we need either to turn it ON or turn it OFF
2867 * We can always turn it OFF in case of early-suspend, but we turn it
2868 * back ON only if suspend_disable_flag was not set
2870 if (dhd && dhd->pub.up) {
2871 dhd_os_proto_block(&dhd->pub);
2872 if (dhd->pub.in_suspend) {
2873 if (!val || (val && !dhd->pub.suspend_disable_flag))
2874 dhd_set_packet_filter(val, &dhd->pub);
2876 dhd_os_proto_unblock(&dhd->pub);
2881 void dhd_dev_init_ioctl(struct net_device *dev)
2883 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2885 dhd_preinit_ioctls(&dhd->pub);
2889 /* Linux wrapper to call common dhd_pno_clean */
2890 int dhd_dev_pno_reset(struct net_device *dev)
2892 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2894 return dhd_pno_clean(&dhd->pub);
2897 /* Linux wrapper to call common dhd_pno_enable */
2898 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2900 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2902 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2905 /* Linux wrapper to call common dhd_pno_set */
2907 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2908 unsigned char scan_fr)
2910 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2912 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2915 /* Linux wrapper to get pno status */
2916 int dhd_dev_get_pno_status(struct net_device *dev)
2918 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2920 return dhd_pno_get_status(&dhd->pub);
2923 #endif /* PNO_SUPPORT */
2925 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2927 return atomic_read(&dhd->pend_8021x_cnt);
2930 #define MAX_WAIT_FOR_8021X_TX 10
2932 int dhd_wait_pend8021x(struct net_device *dev)
2934 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2935 int timeout = 10 * HZ / 1000;
2936 int ntimes = MAX_WAIT_FOR_8021X_TX;
2937 int pend = dhd_get_pend_8021x_cnt(dhd);
2939 while (ntimes && pend) {
2941 set_current_state(TASK_INTERRUPTIBLE);
2942 schedule_timeout(timeout);
2943 set_current_state(TASK_RUNNING);
2946 pend = dhd_get_pend_8021x_cnt(dhd);
2952 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2956 mm_segment_t old_fs;
2959 /* change to KERNEL_DS address limit */
2963 /* open file to write */
2964 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2966 printf("%s: open file error\n", __func__);
2971 /* Write buf to file */
2972 fp->f_op->write(fp, buf, size, &pos);
2975 /* free buf before return */
2976 MFREE(dhd->osh, buf, size);
2977 /* close file before return */
2979 filp_close(fp, current->files);
2980 /* restore previous address limit */
2985 #endif /* DHD_DEBUG */