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/random.h>
31 #include <linux/spinlock.h>
32 #include <linux/ethtool.h>
33 #include <linux/fcntl.h>
36 #include <asm/uaccess.h>
37 #include <asm/unaligned.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 = NULL;
62 static struct resource *wifi_irqres = NULL;
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 /* Linux wireless extension support */
189 #if defined(CONFIG_WIRELESS_EXT)
191 extern wl_iw_extra_params_t g_wl_iw_params;
192 #endif /* defined(CONFIG_WIRELESS_EXT) */
194 #if defined(CONFIG_HAS_EARLYSUSPEND)
195 #include <linux/earlysuspend.h>
196 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
198 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
200 #ifdef PKT_FILTER_SUPPORT
201 extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
202 extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
206 /* Interface control information */
207 typedef struct dhd_if {
208 struct dhd_info *info; /* back pointer to dhd_info */
209 /* OS/stack specifics */
210 struct net_device *net;
211 struct net_device_stats stats;
212 int idx; /* iface idx in dongle */
213 int state; /* interface state */
214 uint subunit; /* subunit */
215 uint8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
216 bool attached; /* Delayed attachment when unset */
217 bool txflowcontrol; /* Per interface flow control indicator */
218 char name[IFNAMSIZ + 1]; /* linux interface name */
221 /* Local private structure (extension of pub) */
222 typedef struct dhd_info {
223 #if defined(CONFIG_WIRELESS_EXT)
224 wl_iw_t iw; /* wireless extensions state (must be first) */
225 #endif /* defined(CONFIG_WIRELESS_EXT) */
229 /* OS/stack specifics */
230 dhd_if_t *iflist[DHD_MAX_IFS];
232 struct semaphore proto_sem;
233 wait_queue_head_t ioctl_resp_wait;
234 struct timer_list timer;
236 struct tasklet_struct tasklet;
239 /* Thread based operation */
241 struct semaphore sdsem;
243 struct semaphore watchdog_sem;
244 struct completion watchdog_exited;
246 struct semaphore dpc_sem;
247 struct completion dpc_exited;
249 /* Thread to issue ioctl for multicast */
251 struct semaphore sysioc_sem;
252 struct completion sysioc_exited;
255 struct ether_addr macvalue;
256 wait_queue_head_t ctrl_wait;
257 atomic_t pend_8021x_cnt;
259 #ifdef CONFIG_HAS_EARLYSUSPEND
260 struct early_suspend early_suspend;
261 #endif /* CONFIG_HAS_EARLYSUSPEND */
264 /* Definitions to provide path to the firmware and nvram
265 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
267 char firmware_path[MOD_PARAM_PATHLEN];
268 char nvram_path[MOD_PARAM_PATHLEN];
270 /* load firmware and/or nvram values from the filesystem */
271 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
272 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
275 module_param(dhd_msg_level, int, 0);
277 /* Spawn a thread for system ioctls (set mac, set mcast) */
278 uint dhd_sysioc = TRUE;
279 module_param(dhd_sysioc, uint, 0);
281 /* Watchdog interval */
282 uint dhd_watchdog_ms = 10;
283 module_param(dhd_watchdog_ms, uint, 0);
286 /* Console poll interval */
287 uint dhd_console_ms = 0;
288 module_param(dhd_console_ms, uint, 0);
289 #endif /* DHD_DEBUG */
291 /* ARP offload agent mode : Enable ARP Host Auto-Reply
292 and ARP Peer Auto-Reply */
293 uint dhd_arp_mode = 0xb;
294 module_param(dhd_arp_mode, uint, 0);
296 /* ARP offload enable */
297 uint dhd_arp_enable = TRUE;
298 module_param(dhd_arp_enable, uint, 0);
300 /* Global Pkt filter enable control */
301 uint dhd_pkt_filter_enable = TRUE;
302 module_param(dhd_pkt_filter_enable, uint, 0);
304 /* Pkt filter init setup */
305 uint dhd_pkt_filter_init = 0;
306 module_param(dhd_pkt_filter_init, uint, 0);
308 /* Pkt filter mode control */
309 uint dhd_master_mode = TRUE;
310 module_param(dhd_master_mode, uint, 1);
312 /* Watchdog thread priority, -1 to use kernel timer */
313 int dhd_watchdog_prio = 97;
314 module_param(dhd_watchdog_prio, int, 0);
316 /* DPC thread priority, -1 to use tasklet */
317 int dhd_dpc_prio = 98;
318 module_param(dhd_dpc_prio, int, 0);
320 /* DPC thread priority, -1 to use tasklet */
321 extern int dhd_dongle_memsize;
322 module_param(dhd_dongle_memsize, int, 0);
324 /* Contorl fw roaming */
331 /* Control radio state */
332 uint dhd_radio_up = 1;
334 /* Network inteface name */
335 char iface_name[IFNAMSIZ];
336 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
338 #define DAEMONIZE(a) daemonize(a); \
339 allow_signal(SIGKILL); \
340 allow_signal(SIGTERM);
342 #define BLOCKABLE() (!in_atomic())
344 /* The following are specific to the SDIO dongle */
346 /* IOCTL response timeout */
347 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
349 /* Idle timeout for backplane clock */
350 int dhd_idletime = DHD_IDLETIME_TICKS;
351 module_param(dhd_idletime, int, 0);
354 uint dhd_poll = FALSE;
355 module_param(dhd_poll, uint, 0);
357 #ifdef CONFIG_CFG80211
359 uint dhd_cfg80211 = TRUE;
360 module_param(dhd_cfg80211, uint, 0);
364 uint dhd_intr = TRUE;
365 module_param(dhd_intr, uint, 0);
367 /* SDIO Drive Strength (in milliamps) */
368 uint dhd_sdiod_drive_strength = 6;
369 module_param(dhd_sdiod_drive_strength, uint, 0);
372 extern uint dhd_txbound;
373 extern uint dhd_rxbound;
374 module_param(dhd_txbound, uint, 0);
375 module_param(dhd_rxbound, uint, 0);
377 /* Deferred transmits */
378 extern uint dhd_deferred_tx;
379 module_param(dhd_deferred_tx, uint, 0);
382 /* Echo packet generator (pkts/s) */
384 module_param(dhd_pktgen, uint, 0);
386 /* Echo packet len (0 => sawtooth, max 2040) */
387 uint dhd_pktgen_len = 0;
388 module_param(dhd_pktgen_len, uint, 0);
391 #ifdef CONFIG_CFG80211
392 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
393 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
394 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
395 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
398 /* Version string to report */
400 #define DHD_COMPILED "\nCompiled in " SRCBASE
405 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
407 "\nCompiled in " " on " __DATE__ " at " __TIME__
411 #if defined(CONFIG_WIRELESS_EXT)
412 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
413 #endif /* defined(CONFIG_WIRELESS_EXT) */
415 static void dhd_dpc(ulong data);
417 extern int dhd_wait_pend8021x(struct net_device *dev);
421 #error TOE requires BDC
423 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
424 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
427 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
428 wl_event_msg_t *event_ptr, void **data_ptr);
430 #if defined(CONFIG_PM_SLEEP)
431 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
432 unsigned long action, void *ignored)
435 case PM_HIBERNATION_PREPARE:
436 case PM_SUSPEND_PREPARE:
437 dhd_mmc_suspend = TRUE;
439 case PM_POST_HIBERNATION:
440 case PM_POST_SUSPEND:
441 dhd_mmc_suspend = FALSE;
447 static struct notifier_block dhd_sleep_pm_notifier = {
448 .notifier_call = dhd_sleep_pm_callback,
452 extern int register_pm_notifier(struct notifier_block *nb);
453 extern int unregister_pm_notifier(struct notifier_block *nb);
454 #endif /* defined(CONFIG_PM_SLEEP) */
455 /* && defined(DHD_GPL) */
456 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
458 #ifdef PKT_FILTER_SUPPORT
459 DHD_TRACE(("%s: %d\n", __func__, value));
460 /* 1 - Enable packet filter, only allow unicast packet to send up */
461 /* 0 - Disable packet filter */
462 if (dhd_pkt_filter_enable) {
465 for (i = 0; i < dhd->pktfilter_count; i++) {
466 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
467 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
468 value, dhd_master_mode);
474 #if defined(CONFIG_HAS_EARLYSUSPEND)
475 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
477 int power_mode = PM_MAX;
478 /* wl_pkt_filter_enable_t enable_parm; */
483 #endif /* CUSTOMER_HW2 */
485 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
486 __func__, value, dhd->in_suspend));
488 if (dhd && dhd->up) {
489 if (value && dhd->in_suspend) {
491 /* Kernel suspended */
492 DHD_TRACE(("%s: force extra Suspend setting\n",
495 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
499 /* Enable packet filter, only allow unicast
501 dhd_set_packet_filter(1, dhd);
503 /* if dtim skip setup as default force it
504 * to wake each thrid dtim
505 * for better power saving.
506 * Note that side effect is chance to miss BC/MC
509 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
512 bcn_li_dtim = dhd->dtim_skip;
513 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
514 4, iovbuf, sizeof(iovbuf));
515 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
518 /* Disable build-in roaming to allowed \
519 * supplicant to take of romaing
521 bcm_mkiovar("roam_off", (char *)&roamvar, 4,
522 iovbuf, sizeof(iovbuf));
523 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
525 #endif /* CUSTOMER_HW2 */
529 DHD_TRACE(("%s: Remove extra suspend setting\n",
532 power_mode = PM_FAST;
533 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
537 /* disable pkt filter */
538 dhd_set_packet_filter(0, dhd);
540 /* restore pre-suspend setting for dtim_skip */
541 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
542 4, iovbuf, sizeof(iovbuf));
544 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
548 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
550 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
552 #endif /* CUSTOMER_HW2 */
559 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
561 dhd_pub_t *dhdp = &dhd->pub;
563 dhd_os_proto_block(dhdp);
564 /* Set flag when early suspend was called */
565 dhdp->in_suspend = val;
566 if (!dhdp->suspend_disable_flag)
567 dhd_set_suspend(val, dhdp);
568 dhd_os_proto_unblock(dhdp);
571 static void dhd_early_suspend(struct early_suspend *h)
573 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
575 DHD_TRACE(("%s: enter\n", __func__));
578 dhd_suspend_resume_helper(dhd, 1);
582 static void dhd_late_resume(struct early_suspend *h)
584 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
586 DHD_TRACE(("%s: enter\n", __func__));
589 dhd_suspend_resume_helper(dhd, 0);
591 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
594 * Generalized timeout mechanism. Uses spin sleep with exponential
596 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
598 * dhd_timeout_start(&tmo, usec);
599 * while (!dhd_timeout_expired(&tmo))
600 * if (poll_something())
602 * if (dhd_timeout_expired(&tmo))
606 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
611 tmo->tick = 1000000 / HZ;
614 int dhd_timeout_expired(dhd_timeout_t *tmo)
616 /* Does nothing the first call */
617 if (tmo->increment == 0) {
622 if (tmo->elapsed >= tmo->limit)
625 /* Add the delay that's about to take place */
626 tmo->elapsed += tmo->increment;
628 if (tmo->increment < tmo->tick) {
629 OSL_DELAY(tmo->increment);
631 if (tmo->increment > tmo->tick)
632 tmo->increment = tmo->tick;
634 wait_queue_head_t delay_wait;
635 DECLARE_WAITQUEUE(wait, current);
637 init_waitqueue_head(&delay_wait);
638 add_wait_queue(&delay_wait, &wait);
639 set_current_state(TASK_INTERRUPTIBLE);
641 pending = signal_pending(current);
642 remove_wait_queue(&delay_wait, &wait);
643 set_current_state(TASK_RUNNING);
645 return 1; /* Interrupted */
651 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
656 while (i < DHD_MAX_IFS) {
657 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
665 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
671 if (name == NULL || *name == '\0')
676 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
679 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
681 return i; /* default - the primary interface */
684 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
686 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
690 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
691 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
695 if (dhd->iflist[ifidx] == NULL) {
696 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
700 if (dhd->iflist[ifidx]->net)
701 return dhd->iflist[ifidx]->net->name;
706 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
708 struct net_device *dev;
709 struct netdev_hw_addr *ha;
710 uint32 allmulti, cnt;
717 ASSERT(dhd && dhd->iflist[ifidx]);
718 dev = dhd->iflist[ifidx]->net;
719 cnt = netdev_mc_count(dev);
721 /* Determine initial value of allmulti flag */
722 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
724 /* Send down the multicast list first. */
726 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
727 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
728 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
729 dhd_ifname(&dhd->pub, ifidx), cnt));
733 strcpy(bufp, "mcast_list");
734 bufp += strlen("mcast_list") + 1;
737 memcpy(bufp, &cnt, sizeof(cnt));
740 netdev_for_each_mc_addr(ha, dev) {
743 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
744 bufp += ETHER_ADDR_LEN;
748 memset(&ioc, 0, sizeof(ioc));
749 ioc.cmd = WLC_SET_VAR;
754 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
756 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
757 dhd_ifname(&dhd->pub, ifidx), cnt));
758 allmulti = cnt ? TRUE : allmulti;
761 MFREE(dhd->pub.osh, buf, buflen);
763 /* Now send the allmulti setting. This is based on the setting in the
764 * net_device flags, but might be modified above to be turned on if we
765 * were trying to set some addresses and dongle rejected it...
768 buflen = sizeof("allmulti") + sizeof(allmulti);
769 if (!(buf = MALLOC(dhd->pub.osh, buflen))) {
770 DHD_ERROR(("%s: out of memory for allmulti\n",
771 dhd_ifname(&dhd->pub, ifidx)));
774 allmulti = htol32(allmulti);
777 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
778 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
779 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
780 (int)sizeof(allmulti), buflen));
781 MFREE(dhd->pub.osh, buf, buflen);
785 memset(&ioc, 0, sizeof(ioc));
786 ioc.cmd = WLC_SET_VAR;
791 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
793 DHD_ERROR(("%s: set allmulti %d failed\n",
794 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
797 MFREE(dhd->pub.osh, buf, buflen);
799 /* Finally, pick up the PROMISC flag as well, like the NIC
802 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
803 allmulti = htol32(allmulti);
805 memset(&ioc, 0, sizeof(ioc));
806 ioc.cmd = WLC_SET_PROMISC;
808 ioc.len = sizeof(allmulti);
811 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
813 DHD_ERROR(("%s: set promisc %d failed\n",
814 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
819 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
825 DHD_TRACE(("%s enter\n", __func__));
827 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) {
828 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
829 dhd_ifname(&dhd->pub, ifidx)));
832 memset(&ioc, 0, sizeof(ioc));
833 ioc.cmd = WLC_SET_VAR;
838 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
840 DHD_ERROR(("%s: set cur_etheraddr failed\n",
841 dhd_ifname(&dhd->pub, ifidx)));
843 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
850 extern struct net_device *ap_net_dev;
853 static void dhd_op_if(dhd_if_t *ifp)
856 int ret = 0, err = 0;
858 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
862 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
864 switch (ifp->state) {
867 * Delete the existing interface before overwriting it
868 * in case we missed the WLC_E_IF_DEL event.
870 if (ifp->net != NULL) {
871 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
872 "try free & unregister\n",
873 __func__, ifp->net->name));
874 netif_stop_queue(ifp->net);
875 unregister_netdev(ifp->net);
876 free_netdev(ifp->net);
878 /* Allocate etherdev, including space for private structure */
879 if (!(ifp->net = alloc_etherdev(sizeof(dhd)))) {
880 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
884 strcpy(ifp->net->name, ifp->name);
885 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
886 if ((err = dhd_net_attach(&dhd->pub, ifp->idx)) != 0) {
887 DHD_ERROR(("%s: dhd_net_attach failed, "
893 /* semaphore that the soft AP CODE
895 extern struct semaphore ap_eth_sema;
897 /* save ptr to wl0.1 netdev for use
899 ap_net_dev = ifp->net;
900 /* signal to the SOFTAP 'sleeper' thread,
904 DHD_TRACE(("\n ==== pid:%x, net_device for "
905 "if:%s created ===\n\n",
906 current->pid, ifp->net->name));
912 if (ifp->net != NULL) {
913 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
915 netif_stop_queue(ifp->net);
916 unregister_netdev(ifp->net);
917 ret = DHD_DEL_IF; /* Make sure the free_netdev()
922 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
929 free_netdev(ifp->net);
931 dhd->iflist[ifp->idx] = NULL;
932 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
934 if (ifp->net == ap_net_dev)
935 ap_net_dev = NULL; /* NULL SOFTAP global
941 static int _dhd_sysioc_thread(void *data)
943 dhd_info_t *dhd = (dhd_info_t *) data;
949 DAEMONIZE("dhd_sysioc");
951 while (down_interruptible(&dhd->sysioc_sem) == 0) {
952 for (i = 0; i < DHD_MAX_IFS; i++) {
953 if (dhd->iflist[i]) {
955 in_ap = (ap_net_dev != NULL);
957 if (dhd->iflist[i]->state)
958 dhd_op_if(dhd->iflist[i]);
960 if (dhd->iflist[i] == NULL) {
961 DHD_TRACE(("\n\n %s: interface %d "
962 "removed!\n", __func__, i));
966 if (in_ap && dhd->set_macaddress) {
967 DHD_TRACE(("attempt to set MAC for %s "
968 "in AP Mode," "blocked. \n",
969 dhd->iflist[i]->net->name));
970 dhd->set_macaddress = FALSE;
974 if (in_ap && dhd->set_multicast) {
975 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
976 dhd->iflist[i]->net->name));
977 dhd->set_multicast = FALSE;
981 if (dhd->set_multicast) {
982 dhd->set_multicast = FALSE;
983 _dhd_set_multicast_list(dhd, i);
985 if (dhd->set_macaddress) {
986 dhd->set_macaddress = FALSE;
987 _dhd_set_mac_address(dhd, i,
993 complete_and_exit(&dhd->sysioc_exited, 0);
996 static int dhd_set_mac_address(struct net_device *dev, void *addr)
1000 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1001 struct sockaddr *sa = (struct sockaddr *)addr;
1004 ifidx = dhd_net2idx(dhd, dev);
1005 if (ifidx == DHD_BAD_IF)
1008 ASSERT(dhd->sysioc_pid >= 0);
1009 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1010 dhd->set_macaddress = TRUE;
1011 up(&dhd->sysioc_sem);
1016 static void dhd_set_multicast_list(struct net_device *dev)
1018 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1021 ifidx = dhd_net2idx(dhd, dev);
1022 if (ifidx == DHD_BAD_IF)
1025 ASSERT(dhd->sysioc_pid >= 0);
1026 dhd->set_multicast = TRUE;
1027 up(&dhd->sysioc_sem);
1030 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1033 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1035 /* Reject if down */
1036 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1039 /* Update multicast statistic */
1040 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1041 uint8 *pktdata = (uint8 *) PKTDATA(pktbuf);
1042 struct ether_header *eh = (struct ether_header *)pktdata;
1044 if (ETHER_ISMULTI(eh->ether_dhost))
1045 dhdp->tx_multicast++;
1046 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1047 atomic_inc(&dhd->pend_8021x_cnt);
1050 /* Look into the packet and update the packet priority */
1051 if ((PKTPRIO(pktbuf) == 0))
1052 pktsetprio(pktbuf, FALSE);
1054 /* If the protocol uses a data header, apply it */
1055 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1057 /* Use bus module to send data frame */
1059 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1061 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1062 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1063 #endif /* BCMDBUS */
1068 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1072 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1075 DHD_TRACE(("%s: Enter\n", __func__));
1077 /* Reject if down */
1078 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1079 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1080 __func__, dhd->pub.up, dhd->pub.busstate));
1081 netif_stop_queue(net);
1085 ifidx = dhd_net2idx(dhd, net);
1086 if (ifidx == DHD_BAD_IF) {
1087 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1088 netif_stop_queue(net);
1092 /* Make sure there's enough room for any header */
1093 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1094 struct sk_buff *skb2;
1096 DHD_INFO(("%s: insufficient headroom\n",
1097 dhd_ifname(&dhd->pub, ifidx)));
1098 dhd->pub.tx_realloc++;
1099 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1101 if ((skb = skb2) == NULL) {
1102 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1103 dhd_ifname(&dhd->pub, ifidx)));
1109 /* Convert to packet */
1110 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
1111 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1112 dhd_ifname(&dhd->pub, ifidx)));
1113 dev_kfree_skb_any(skb);
1118 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1122 dhd->pub.dstats.tx_dropped++;
1124 dhd->pub.tx_packets++;
1126 /* Return ok: we always eat the packet */
1130 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1132 struct net_device *net;
1133 dhd_info_t *dhd = dhdp->info;
1135 DHD_TRACE(("%s: Enter\n", __func__));
1137 dhdp->txoff = state;
1138 ASSERT(dhd && dhd->iflist[ifidx]);
1139 net = dhd->iflist[ifidx]->net;
1141 netif_stop_queue(net);
1143 netif_wake_queue(net);
1146 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1148 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1149 struct sk_buff *skb;
1152 void *data, *pnext, *save_pktbuf;
1155 wl_event_msg_t event;
1157 DHD_TRACE(("%s: Enter\n", __func__));
1159 save_pktbuf = pktbuf;
1161 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1163 pnext = PKTNEXT(pktbuf);
1164 PKTSETNEXT(pktbuf, NULL);
1166 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1168 /* Get the protocol, maintain skb around eth_type_trans()
1169 * The main reason for this hack is for the limitation of
1170 * Linux 2.4 where 'eth_type_trans' uses the
1171 * 'net->hard_header_len'
1172 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1173 * coping of the packet coming from the network stack to add
1174 * BDC, Hardware header etc, during network interface
1176 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1178 * for BDC, Hardware header etc. and not just the ETH_HLEN
1183 ifp = dhd->iflist[ifidx];
1185 ifp = dhd->iflist[0];
1188 skb->dev = ifp->net;
1189 skb->protocol = eth_type_trans(skb, skb->dev);
1191 if (skb->pkt_type == PACKET_MULTICAST)
1192 dhd->pub.rx_multicast++;
1197 /* Strip header, count, deliver upward */
1198 skb_pull(skb, ETH_HLEN);
1200 /* Process special event packets and then discard them */
1201 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1202 dhd_wl_host_event(dhd, &ifidx,
1206 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1207 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1208 ifp = dhd->iflist[ifidx];
1211 ifp->net->last_rx = jiffies;
1213 dhdp->dstats.rx_bytes += skb->len;
1214 dhdp->rx_packets++; /* Local count */
1216 if (in_interrupt()) {
1219 /* If the receive is not processed inside an ISR,
1220 * the softirqd must be woken explicitly to service
1221 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1222 * by netif_rx_ni(), but in earlier kernels, we need
1223 * to do it manually.
1230 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1232 /* Linux version has nothing to do */
1236 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1239 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1240 struct ether_header *eh;
1243 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1245 eh = (struct ether_header *)PKTDATA(txp);
1246 type = ntoh16(eh->ether_type);
1248 if (type == ETHER_TYPE_802_1X)
1249 atomic_dec(&dhd->pend_8021x_cnt);
1253 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1255 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1259 DHD_TRACE(("%s: Enter\n", __func__));
1261 ifidx = dhd_net2idx(dhd, net);
1262 if (ifidx == DHD_BAD_IF)
1265 ifp = dhd->iflist[ifidx];
1269 /* Use the protocol to get dongle stats */
1270 dhd_prot_dstats(&dhd->pub);
1273 /* Copy dongle stats to net device stats */
1274 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1275 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1276 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1277 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1278 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1279 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1280 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1281 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1282 ifp->stats.multicast = dhd->pub.dstats.multicast;
1287 static int dhd_watchdog_thread(void *data)
1289 dhd_info_t *dhd = (dhd_info_t *) data;
1290 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1292 /* This thread doesn't need any user-level access,
1293 * so get rid of all our resources
1296 if (dhd_watchdog_prio > 0) {
1297 struct sched_param param;
1298 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1299 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1300 setScheduler(current, SCHED_FIFO, ¶m);
1302 #endif /* DHD_SCHED */
1304 DAEMONIZE("dhd_watchdog");
1306 /* Run until signal received */
1308 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1309 if (dhd->pub.dongle_reset == FALSE) {
1310 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1311 /* Call the bus module watchdog */
1312 dhd_bus_watchdog(&dhd->pub);
1313 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1315 /* Count the tick for reference */
1321 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1322 complete_and_exit(&dhd->watchdog_exited, 0);
1325 static void dhd_watchdog(ulong data)
1327 dhd_info_t *dhd = (dhd_info_t *) data;
1329 if (dhd->watchdog_pid >= 0) {
1330 up(&dhd->watchdog_sem);
1332 /* Reschedule the watchdog */
1333 if (dhd->wd_timer_valid) {
1334 mod_timer(&dhd->timer,
1335 jiffies + dhd_watchdog_ms * HZ / 1000);
1340 /* Call the bus module watchdog */
1341 dhd_bus_watchdog(&dhd->pub);
1343 /* Count the tick for reference */
1346 /* Reschedule the watchdog */
1347 if (dhd->wd_timer_valid)
1348 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1351 static int dhd_dpc_thread(void *data)
1353 dhd_info_t *dhd = (dhd_info_t *) data;
1355 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1356 /* This thread doesn't need any user-level access,
1357 * so get rid of all our resources
1360 if (dhd_dpc_prio > 0) {
1361 struct sched_param param;
1362 param.sched_priority =
1364 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1365 setScheduler(current, SCHED_FIFO, ¶m);
1367 #endif /* DHD_SCHED */
1369 DAEMONIZE("dhd_dpc");
1371 /* Run until signal received */
1373 if (down_interruptible(&dhd->dpc_sem) == 0) {
1374 /* Call bus dpc unless it indicated down
1375 (then clean stop) */
1376 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1377 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1378 if (dhd_bus_dpc(dhd->pub.bus)) {
1380 WAKE_LOCK_TIMEOUT(&dhd->pub,
1381 WAKE_LOCK_TMOUT, 25);
1383 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1385 dhd_bus_stop(dhd->pub.bus, TRUE);
1391 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1393 complete_and_exit(&dhd->dpc_exited, 0);
1396 static void dhd_dpc(ulong data)
1400 dhd = (dhd_info_t *) data;
1402 /* Call bus dpc unless it indicated down (then clean stop) */
1403 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1404 if (dhd_bus_dpc(dhd->pub.bus))
1405 tasklet_schedule(&dhd->tasklet);
1407 dhd_bus_stop(dhd->pub.bus, TRUE);
1411 void dhd_sched_dpc(dhd_pub_t *dhdp)
1413 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1415 if (dhd->dpc_pid >= 0) {
1420 tasklet_schedule(&dhd->tasklet);
1424 /* Retrieve current toe component enables, which are kept
1425 as a bitmap in toe_ol iovar */
1426 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
1432 memset(&ioc, 0, sizeof(ioc));
1434 ioc.cmd = WLC_GET_VAR;
1436 ioc.len = (uint) sizeof(buf);
1439 strcpy(buf, "toe_ol");
1441 dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1442 /* Check for older dongle image that doesn't support toe_ol */
1444 DHD_ERROR(("%s: toe not supported by device\n",
1445 dhd_ifname(&dhd->pub, ifidx)));
1449 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1450 dhd_ifname(&dhd->pub, ifidx), ret));
1454 memcpy(toe_ol, buf, sizeof(uint32));
1458 /* Set current toe component enables in toe_ol iovar,
1459 and set toe global enable iovar */
1460 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
1466 memset(&ioc, 0, sizeof(ioc));
1468 ioc.cmd = WLC_SET_VAR;
1470 ioc.len = (uint) sizeof(buf);
1473 /* Set toe_ol as requested */
1475 strcpy(buf, "toe_ol");
1476 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
1479 dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1480 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1481 dhd_ifname(&dhd->pub, ifidx), ret));
1485 /* Enable toe globally only if any components are enabled. */
1487 toe = (toe_ol != 0);
1490 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
1493 dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
1494 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1495 dhd_ifname(&dhd->pub, ifidx), ret));
1503 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1504 struct ethtool_drvinfo *info)
1506 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1508 sprintf(info->driver, "wl");
1509 sprintf(info->version, "%lu", dhd->pub.drv_version);
1512 struct ethtool_ops dhd_ethtool_ops = {
1513 .get_drvinfo = dhd_ethtool_get_drvinfo
1516 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1518 struct ethtool_drvinfo info;
1519 char drvname[sizeof(info.driver)];
1522 struct ethtool_value edata;
1523 uint32 toe_cmpnt, csum_dir;
1527 DHD_TRACE(("%s: Enter\n", __func__));
1529 /* all ethtool calls start with a cmd word */
1530 if (copy_from_user(&cmd, uaddr, sizeof(uint32)))
1534 case ETHTOOL_GDRVINFO:
1535 /* Copy out any request driver name */
1536 if (copy_from_user(&info, uaddr, sizeof(info)))
1538 strncpy(drvname, info.driver, sizeof(info.driver));
1539 drvname[sizeof(info.driver) - 1] = '\0';
1541 /* clear struct for return */
1542 memset(&info, 0, sizeof(info));
1545 /* if dhd requested, identify ourselves */
1546 if (strcmp(drvname, "?dhd") == 0) {
1547 sprintf(info.driver, "dhd");
1548 strcpy(info.version, EPI_VERSION_STR);
1551 /* otherwise, require dongle to be up */
1552 else if (!dhd->pub.up) {
1553 DHD_ERROR(("%s: dongle is not up\n", __func__));
1557 /* finally, report dongle driver type */
1558 else if (dhd->pub.iswl)
1559 sprintf(info.driver, "wl");
1561 sprintf(info.driver, "xx");
1563 sprintf(info.version, "%lu", dhd->pub.drv_version);
1564 if (copy_to_user(uaddr, &info, sizeof(info)))
1566 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1567 (int)sizeof(drvname), drvname, info.driver));
1571 /* Get toe offload components from dongle */
1572 case ETHTOOL_GRXCSUM:
1573 case ETHTOOL_GTXCSUM:
1574 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1578 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1581 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1583 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1587 /* Set toe offload components in dongle */
1588 case ETHTOOL_SRXCSUM:
1589 case ETHTOOL_STXCSUM:
1590 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1593 /* Read the current settings, update and write back */
1594 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
1598 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1600 if (edata.data != 0)
1601 toe_cmpnt |= csum_dir;
1603 toe_cmpnt &= ~csum_dir;
1605 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
1608 /* If setting TX checksum mode, tell Linux the new mode */
1609 if (cmd == ETHTOOL_STXCSUM) {
1611 dhd->iflist[0]->net->features |=
1614 dhd->iflist[0]->net->features &=
1628 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1630 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1637 bool is_set_key_cmd;
1639 ifidx = dhd_net2idx(dhd, net);
1640 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1642 if (ifidx == DHD_BAD_IF)
1645 #if defined(CONFIG_WIRELESS_EXT)
1646 /* linux wireless extensions */
1647 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1648 /* may recurse, do NOT lock */
1649 return wl_iw_ioctl(net, ifr, cmd);
1651 #endif /* defined(CONFIG_WIRELESS_EXT) */
1653 if (cmd == SIOCETHTOOL)
1654 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1656 if (cmd != SIOCDEVPRIVATE)
1659 memset(&ioc, 0, sizeof(ioc));
1661 /* Copy the ioc control structure part of ioctl request */
1662 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1663 bcmerror = -BCME_BADADDR;
1667 /* Copy out any buffer passed */
1669 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1670 /* optimization for direct ioctl calls from kernel */
1672 if (segment_eq(get_fs(), KERNEL_DS)) {
1677 if (!(buf = (char *)MALLOC(dhd->pub.osh, buflen))) {
1678 bcmerror = -BCME_NOMEM;
1681 if (copy_from_user(buf, ioc.buf, buflen)) {
1682 bcmerror = -BCME_BADADDR;
1688 /* To differentiate between wl and dhd read 4 more byes */
1689 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1690 sizeof(uint)) != 0)) {
1691 bcmerror = -BCME_BADADDR;
1695 if (!capable(CAP_NET_ADMIN)) {
1696 bcmerror = -BCME_EPERM;
1700 /* check for local dhd ioctl and handle it */
1701 if (driver == DHD_IOCTL_MAGIC) {
1702 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1704 dhd->pub.bcmerror = bcmerror;
1708 /* send to dongle (must be up, and wl) */
1709 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1710 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1711 bcmerror = BCME_DONGLE_DOWN;
1715 if (!dhd->pub.iswl) {
1716 bcmerror = BCME_DONGLE_DOWN;
1720 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1721 * prevent M4 encryption.
1723 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1724 ((ioc.cmd == WLC_SET_VAR) &&
1725 !(strncmp("wsec_key", ioc.buf, 9))) ||
1726 ((ioc.cmd == WLC_SET_VAR) &&
1727 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1729 dhd_wait_pend8021x(net);
1731 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1732 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1735 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1737 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1738 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1740 if (!bcmerror && buf && ioc.buf) {
1741 if (copy_to_user(ioc.buf, buf, buflen))
1746 MFREE(dhd->pub.osh, buf, buflen);
1748 return OSL_ERROR(bcmerror);
1751 static int dhd_stop(struct net_device *net)
1753 #if !defined(IGNORE_ETH0_DOWN)
1754 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1756 DHD_TRACE(("%s: Enter\n", __func__));
1757 #ifdef CONFIG_CFG80211
1758 if (IS_CFG80211_FAVORITE()) {
1762 if (dhd->pub.up == 0)
1765 /* Set state and stop OS transmissions */
1767 netif_stop_queue(net);
1769 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1771 #endif /* !defined(IGNORE_ETH0_DOWN) */
1773 OLD_MOD_DEC_USE_COUNT;
1777 static int dhd_open(struct net_device *net)
1779 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1783 int ifidx = dhd_net2idx(dhd, net);
1786 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1788 if (ifidx == 0) { /* do it only for primary eth0 */
1790 /* try to bring up bus */
1791 if ((ret = dhd_bus_start(&dhd->pub)) != 0) {
1792 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1795 atomic_set(&dhd->pend_8021x_cnt, 0);
1797 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1800 /* Get current TOE mode from dongle */
1801 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1802 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1803 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1805 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1808 /* Allow transmit calls */
1809 netif_start_queue(net);
1811 #ifdef CONFIG_CFG80211
1812 if (IS_CFG80211_FAVORITE()) {
1813 if (unlikely(wl_cfg80211_up())) {
1814 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1821 OLD_MOD_INC_USE_COUNT;
1825 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1827 return osl_attach(pdev, bustype, TRUE);
1830 void dhd_osl_detach(osl_t *osh)
1832 if (MALLOCED(osh)) {
1833 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1840 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1841 uint8 *mac_addr, uint32 flags, uint8 bssidx)
1845 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1847 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1849 ifp = dhd->iflist[ifidx];
1850 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1851 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1855 memset(ifp, 0, sizeof(dhd_if_t));
1857 dhd->iflist[ifidx] = ifp;
1858 strncpy(ifp->name, name, IFNAMSIZ);
1859 ifp->name[IFNAMSIZ] = '\0';
1860 if (mac_addr != NULL)
1861 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1863 if (handle == NULL) {
1864 ifp->state = WLC_E_IF_ADD;
1866 ASSERT(dhd->sysioc_pid >= 0);
1867 up(&dhd->sysioc_sem);
1869 ifp->net = (struct net_device *)handle;
1874 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1878 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1880 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1881 ifp = dhd->iflist[ifidx];
1883 DHD_ERROR(("%s: Null interface\n", __func__));
1887 ifp->state = WLC_E_IF_DEL;
1889 ASSERT(dhd->sysioc_pid >= 0);
1890 up(&dhd->sysioc_sem);
1893 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1895 dhd_info_t *dhd = NULL;
1896 struct net_device *net;
1898 DHD_TRACE(("%s: Enter\n", __func__));
1899 /* updates firmware nvram path if it was provided as module
1901 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1902 strcpy(fw_path, firmware_path);
1903 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1904 strcpy(nv_path, nvram_path);
1906 /* Allocate etherdev, including space for private structure */
1907 if (!(net = alloc_etherdev(sizeof(dhd)))) {
1908 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1912 /* Allocate primary dhd_info */
1913 if (!(dhd = MALLOC(osh, sizeof(dhd_info_t)))) {
1914 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1918 memset(dhd, 0, sizeof(dhd_info_t));
1921 * Save the dhd_info into the priv
1923 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1926 /* Set network interface name if it was provided as module parameter */
1927 if (iface_name[0]) {
1930 strncpy(net->name, iface_name, IFNAMSIZ);
1931 net->name[IFNAMSIZ - 1] = 0;
1932 len = strlen(net->name);
1933 ch = net->name[len - 1];
1934 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1935 strcat(net->name, "%d");
1938 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1942 net->netdev_ops = NULL;
1943 init_MUTEX(&dhd->proto_sem);
1944 /* Initialize other structure content */
1945 init_waitqueue_head(&dhd->ioctl_resp_wait);
1946 init_waitqueue_head(&dhd->ctrl_wait);
1948 /* Initialize the spinlocks */
1949 spin_lock_init(&dhd->sdlock);
1950 spin_lock_init(&dhd->txqlock);
1952 /* Link to info module */
1953 dhd->pub.info = dhd;
1955 /* Link to bus module */
1957 dhd->pub.hdrlen = bus_hdrlen;
1959 /* Attach and link in the protocol */
1960 if (dhd_prot_attach(&dhd->pub) != 0) {
1961 DHD_ERROR(("dhd_prot_attach failed\n"));
1964 #if defined(CONFIG_WIRELESS_EXT)
1965 /* Attach and link in the iw */
1966 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1967 DHD_ERROR(("wl_iw_attach failed\n"));
1970 #endif /* defined(CONFIG_WIRELESS_EXT) */
1972 #ifdef CONFIG_CFG80211
1973 /* Attach and link in the cfg80211 */
1974 if (IS_CFG80211_FAVORITE()) {
1975 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1976 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1980 strcpy(fw_path, wl_cfg80211_get_fwname());
1981 strcpy(nv_path, wl_cfg80211_get_nvramname());
1983 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
1987 /* Set up the watchdog timer */
1988 init_timer(&dhd->timer);
1989 dhd->timer.data = (ulong) dhd;
1990 dhd->timer.function = dhd_watchdog;
1992 /* Initialize thread based operation and lock */
1993 init_MUTEX(&dhd->sdsem);
1994 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1995 dhd->threads_only = TRUE;
1997 dhd->threads_only = FALSE;
1999 if (dhd_dpc_prio >= 0) {
2000 /* Initialize watchdog thread */
2001 sema_init(&dhd->watchdog_sem, 0);
2002 init_completion(&dhd->watchdog_exited);
2003 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2005 dhd->watchdog_pid = -1;
2008 /* Set up the bottom half handler */
2009 if (dhd_dpc_prio >= 0) {
2010 /* Initialize DPC thread */
2011 sema_init(&dhd->dpc_sem, 0);
2012 init_completion(&dhd->dpc_exited);
2013 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2015 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong) dhd);
2020 sema_init(&dhd->sysioc_sem, 0);
2021 init_completion(&dhd->sysioc_exited);
2022 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2024 dhd->sysioc_pid = -1;
2028 * Save the dhd_info into the priv
2030 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2032 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2035 #if defined(CONFIG_PM_SLEEP)
2036 register_pm_notifier(&dhd_sleep_pm_notifier);
2037 #endif /* defined(CONFIG_PM_SLEEP) */
2038 /* && defined(DHD_GPL) */
2039 /* Init lock suspend to prevent kernel going to suspend */
2040 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2041 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2042 "dhd_wake_lock_link_dw_event");
2043 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2044 "dhd_wake_lock_link_pno_find_event");
2045 #ifdef CONFIG_HAS_EARLYSUSPEND
2046 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2047 dhd->early_suspend.suspend = dhd_early_suspend;
2048 dhd->early_suspend.resume = dhd_late_resume;
2049 register_early_suspend(&dhd->early_suspend);
2058 dhd_detach(&dhd->pub);
2063 int dhd_bus_start(dhd_pub_t *dhdp)
2066 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2067 #ifdef EMBEDDED_PLATFORM
2068 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2070 #endif /* EMBEDDED_PLATFORM */
2074 DHD_TRACE(("%s:\n", __func__));
2076 /* try to download image and nvram to the dongle */
2077 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2078 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2079 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2080 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2081 fw_path, nv_path))) {
2082 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2083 "firmware = %s nvram = %s\n",
2084 __func__, fw_path, nv_path));
2085 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2086 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2090 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2091 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2094 /* Start the watchdog timer */
2095 dhd->pub.tickcnt = 0;
2096 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2098 /* Bring up the bus */
2099 if ((ret = dhd_bus_init(&dhd->pub, TRUE)) != 0) {
2100 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2103 #if defined(OOB_INTR_ONLY)
2104 /* Host registration for OOB interrupt */
2105 if (bcmsdh_register_oob_intr(dhdp)) {
2106 del_timer_sync(&dhd->timer);
2107 dhd->wd_timer_valid = FALSE;
2108 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2112 /* Enable oob at firmware */
2113 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2114 #endif /* defined(OOB_INTR_ONLY) */
2116 /* If bus is not ready, can't come up */
2117 if (dhd->pub.busstate != DHD_BUS_DATA) {
2118 del_timer_sync(&dhd->timer);
2119 dhd->wd_timer_valid = FALSE;
2120 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2123 #ifdef EMBEDDED_PLATFORM
2124 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2126 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2127 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2129 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2130 setbit(dhdp->eventmask, WLC_E_PRUNE);
2131 setbit(dhdp->eventmask, WLC_E_AUTH);
2132 setbit(dhdp->eventmask, WLC_E_REASSOC);
2133 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2134 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2135 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2136 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2137 setbit(dhdp->eventmask, WLC_E_JOIN);
2138 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2139 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2140 setbit(dhdp->eventmask, WLC_E_LINK);
2141 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2142 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2143 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2144 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2145 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2146 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2148 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2149 #endif /* PNO_SUPPORT */
2151 /* enable dongle roaming event */
2153 dhdp->pktfilter_count = 1;
2154 /* Setup filter to allow only unicast */
2155 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2156 #endif /* EMBEDDED_PLATFORM */
2158 /* Bus is ready, do any protocol initialization */
2159 if ((ret = dhd_prot_init(&dhd->pub)) < 0)
2166 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2169 char buf[strlen(name) + 1 + cmd_len];
2170 int len = sizeof(buf);
2174 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2176 memset(&ioc, 0, sizeof(ioc));
2178 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2183 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2184 if (!set && ret >= 0)
2185 memcpy(cmd_buf, buf, cmd_len);
2190 static struct net_device_ops dhd_ops_pri = {
2191 .ndo_open = dhd_open,
2192 .ndo_stop = dhd_stop,
2193 .ndo_get_stats = dhd_get_stats,
2194 .ndo_do_ioctl = dhd_ioctl_entry,
2195 .ndo_start_xmit = dhd_start_xmit,
2196 .ndo_set_mac_address = dhd_set_mac_address,
2197 .ndo_set_multicast_list = dhd_set_multicast_list
2200 static struct net_device_ops dhd_ops_virt = {
2201 .ndo_get_stats = dhd_get_stats,
2202 .ndo_do_ioctl = dhd_ioctl_entry,
2203 .ndo_start_xmit = dhd_start_xmit,
2204 .ndo_set_mac_address = dhd_set_mac_address,
2205 .ndo_set_multicast_list = dhd_set_multicast_list
2208 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2210 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2211 struct net_device *net;
2212 uint8 temp_addr[ETHER_ADDR_LEN] = {
2213 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2215 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2217 ASSERT(dhd && dhd->iflist[ifidx]);
2219 net = dhd->iflist[ifidx]->net;
2222 ASSERT(!net->netdev_ops);
2223 net->netdev_ops = &dhd_ops_virt;
2225 net->netdev_ops = &dhd_ops_pri;
2228 * We have to use the primary MAC for virtual interfaces
2231 /* for virtual interfaces use the primary MAC */
2232 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2237 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2238 /* ACCESSPOINT INTERFACE CASE */
2239 temp_addr[0] |= 0X02; /* set bit 2 ,
2240 - Locally Administered address */
2243 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2244 net->ethtool_ops = &dhd_ethtool_ops;
2246 #if defined(CONFIG_WIRELESS_EXT)
2247 #if defined(CONFIG_CFG80211)
2248 if (!IS_CFG80211_FAVORITE()) {
2250 #if WIRELESS_EXT < 19
2251 net->get_wireless_stats = dhd_get_wireless_stats;
2252 #endif /* WIRELESS_EXT < 19 */
2253 #if WIRELESS_EXT > 12
2254 net->wireless_handlers =
2255 (struct iw_handler_def *)&wl_iw_handler_def;
2256 #endif /* WIRELESS_EXT > 12 */
2257 #if defined(CONFIG_CFG80211)
2260 #endif /* defined(CONFIG_WIRELESS_EXT) */
2262 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2264 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2266 if (register_netdev(net) != 0) {
2267 DHD_ERROR(("%s: couldn't register the net device\n",
2272 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2277 net->netdev_ops = NULL;
2281 void dhd_bus_detach(dhd_pub_t *dhdp)
2285 DHD_TRACE(("%s: Enter\n", __func__));
2288 dhd = (dhd_info_t *) dhdp->info;
2290 /* Stop the protocol module */
2291 dhd_prot_stop(&dhd->pub);
2293 /* Stop the bus module */
2294 dhd_bus_stop(dhd->pub.bus, TRUE);
2295 #if defined(OOB_INTR_ONLY)
2296 bcmsdh_unregister_oob_intr();
2297 #endif /* defined(OOB_INTR_ONLY) */
2299 /* Clear the watchdog timer */
2300 del_timer_sync(&dhd->timer);
2301 dhd->wd_timer_valid = FALSE;
2306 void dhd_detach(dhd_pub_t *dhdp)
2310 DHD_TRACE(("%s: Enter\n", __func__));
2313 dhd = (dhd_info_t *) dhdp->info;
2318 #if defined(CONFIG_HAS_EARLYSUSPEND)
2319 if (dhd->early_suspend.suspend)
2320 unregister_early_suspend(&dhd->early_suspend);
2321 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2323 for (i = 1; i < DHD_MAX_IFS; i++)
2327 ifp = dhd->iflist[0];
2329 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2331 unregister_netdev(ifp->net);
2334 if (dhd->watchdog_pid >= 0) {
2335 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2336 wait_for_completion(&dhd->watchdog_exited);
2339 if (dhd->dpc_pid >= 0) {
2340 KILL_PROC(dhd->dpc_pid, SIGTERM);
2341 wait_for_completion(&dhd->dpc_exited);
2343 tasklet_kill(&dhd->tasklet);
2345 if (dhd->sysioc_pid >= 0) {
2346 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2347 wait_for_completion(&dhd->sysioc_exited);
2350 dhd_bus_detach(dhdp);
2353 dhd_prot_detach(dhdp);
2355 #if defined(CONFIG_WIRELESS_EXT)
2357 #endif /* (CONFIG_WIRELESS_EXT) */
2359 #ifdef CONFIG_CFG80211
2360 if (IS_CFG80211_FAVORITE())
2361 wl_cfg80211_detach();
2362 #endif /* CONFIG_CFG80211 */
2364 #if defined(CONFIG_PM_SLEEP)
2365 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2366 #endif /* defined(CONFIG_PM_SLEEP) */
2367 /* && defined(DHD_GPL) */
2368 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2369 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2370 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2371 free_netdev(ifp->net);
2372 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2373 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2378 static void __exit dhd_module_cleanup(void)
2380 DHD_TRACE(("%s: Enter\n", __func__));
2382 dhd_bus_unregister();
2383 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2386 /* Call customer gpio to turn off power with WL_REG_ON signal */
2387 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2390 static int __init dhd_module_init(void)
2394 DHD_TRACE(("%s: Enter\n", __func__));
2396 /* Sanity check on the module parameters */
2398 /* Both watchdog and DPC as tasklets are ok */
2399 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2402 /* If both watchdog and DPC are threads, TX must be deferred */
2403 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2407 DHD_ERROR(("Invalid module parameters.\n"));
2410 /* Call customer gpio to turn on power with WL_REG_ON signal */
2411 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2413 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2414 sema_init(&wifi_control_sem, 0);
2416 error = wifi_add_dev();
2418 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2422 /* Waiting callback after platform_driver_register is done or
2424 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2425 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2431 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2433 error = dhd_bus_register();
2436 printf("\n%s\n", dhd_version);
2438 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2444 /* turn off power and exit */
2445 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2449 module_init(dhd_module_init);
2450 module_exit(dhd_module_cleanup);
2453 * OS specific functions required to implement DHD driver in OS independent way
2455 int dhd_os_proto_block(dhd_pub_t *pub)
2457 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2460 down(&dhd->proto_sem);
2466 int dhd_os_proto_unblock(dhd_pub_t *pub)
2468 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2471 up(&dhd->proto_sem);
2478 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2480 return (unsigned int)dhd_ioctl_timeout_msec;
2483 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2485 dhd_ioctl_timeout_msec = (int)timeout_msec;
2488 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2490 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2491 DECLARE_WAITQUEUE(wait, current);
2492 int timeout = dhd_ioctl_timeout_msec;
2494 /* Convert timeout in millsecond to jiffies */
2495 timeout = timeout * HZ / 1000;
2497 /* Wait until control frame is available */
2498 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2499 set_current_state(TASK_INTERRUPTIBLE);
2501 while (!(*condition) && (!signal_pending(current) && timeout))
2502 timeout = schedule_timeout(timeout);
2504 if (signal_pending(current))
2507 set_current_state(TASK_RUNNING);
2508 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2513 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2515 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2517 if (waitqueue_active(&dhd->ioctl_resp_wait))
2518 wake_up_interruptible(&dhd->ioctl_resp_wait);
2523 void dhd_os_wd_timer(void *bus, uint wdtick)
2525 dhd_pub_t *pub = bus;
2526 static uint save_dhd_watchdog_ms = 0;
2527 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2529 /* don't start the wd until fw is loaded */
2530 if (pub->busstate == DHD_BUS_DOWN)
2533 /* Totally stop the timer */
2534 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2535 del_timer_sync(&dhd->timer);
2536 dhd->wd_timer_valid = FALSE;
2537 save_dhd_watchdog_ms = wdtick;
2542 dhd_watchdog_ms = (uint) wdtick;
2544 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2546 if (dhd->wd_timer_valid == TRUE)
2547 /* Stop timer and restart at new value */
2548 del_timer_sync(&dhd->timer);
2550 /* Create timer again when watchdog period is
2551 dynamically changed or in the first instance
2553 dhd->timer.expires =
2554 jiffies + dhd_watchdog_ms * HZ / 1000;
2555 add_timer(&dhd->timer);
2558 /* Re arm the timer, at last watchdog period */
2559 mod_timer(&dhd->timer,
2560 jiffies + dhd_watchdog_ms * HZ / 1000);
2563 dhd->wd_timer_valid = TRUE;
2564 save_dhd_watchdog_ms = wdtick;
2568 void *dhd_os_open_image(char *filename)
2572 #ifdef CONFIG_CFG80211
2573 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2574 return wl_cfg80211_request_fw(filename);
2577 fp = filp_open(filename, O_RDONLY, 0);
2579 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2581 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2590 int dhd_os_get_image_block(char *buf, int len, void *image)
2592 struct file *fp = (struct file *)image;
2595 #ifdef CONFIG_CFG80211
2596 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2597 return wl_cfg80211_read_fw(buf, len);
2603 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2610 void dhd_os_close_image(void *image)
2612 #ifdef CONFIG_CFG80211
2613 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2614 return wl_cfg80211_release_fw();
2617 filp_close((struct file *)image, NULL);
2620 void dhd_os_sdlock(dhd_pub_t *pub)
2624 dhd = (dhd_info_t *) (pub->info);
2626 if (dhd->threads_only)
2629 spin_lock_bh(&dhd->sdlock);
2632 void dhd_os_sdunlock(dhd_pub_t *pub)
2636 dhd = (dhd_info_t *) (pub->info);
2638 if (dhd->threads_only)
2641 spin_unlock_bh(&dhd->sdlock);
2644 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2648 dhd = (dhd_info_t *) (pub->info);
2649 spin_lock_bh(&dhd->txqlock);
2652 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2656 dhd = (dhd_info_t *) (pub->info);
2657 spin_unlock_bh(&dhd->txqlock);
2660 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2664 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2668 void dhd_os_sdtxlock(dhd_pub_t *pub)
2673 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2675 dhd_os_sdunlock(pub);
2678 #ifdef DHD_USE_STATIC_BUF
2679 void *dhd_os_prealloc(int section, unsigned long size)
2681 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2682 void *alloc_ptr = NULL;
2683 if (wifi_control_data && wifi_control_data->mem_prealloc) {
2684 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2686 DHD_INFO(("success alloc section %d\n", section));
2687 bzero(alloc_ptr, size);
2692 DHD_ERROR(("can't alloc section %d\n", section));
2695 return MALLOC(0, size);
2696 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2698 #endif /* DHD_USE_STATIC_BUF */
2699 #if defined(CONFIG_WIRELESS_EXT)
2700 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2703 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2705 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2708 return &dhd->iw.wstats;
2712 #endif /* defined(CONFIG_WIRELESS_EXT) */
2715 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2716 wl_event_msg_t *event, void **data)
2720 ASSERT(dhd != NULL);
2722 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2723 if (bcmerror != BCME_OK)
2726 #if defined(CONFIG_WIRELESS_EXT)
2727 #if defined(CONFIG_CFG80211)
2728 if (!IS_CFG80211_FAVORITE()) {
2730 if ((dhd->iflist[*ifidx] == NULL)
2731 || (dhd->iflist[*ifidx]->net == NULL)) {
2732 DHD_ERROR(("%s Exit null pointer\n", __func__));
2736 if (dhd->iflist[*ifidx]->net)
2737 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2738 #if defined(CONFIG_CFG80211)
2741 #endif /* defined(CONFIG_WIRELESS_EXT) */
2743 #ifdef CONFIG_CFG80211
2744 if (IS_CFG80211_FAVORITE()) {
2745 ASSERT(dhd->iflist[*ifidx] != NULL);
2746 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2747 if (dhd->iflist[*ifidx]->net)
2748 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2756 /* send up locally generated event */
2757 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2759 switch (ntoh32(event->event_type)) {
2765 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2767 struct dhd_info *dhdinfo = dhd->info;
2768 dhd_os_sdunlock(dhd);
2769 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2770 (*lockvar == FALSE), HZ * 2);
2775 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2777 struct dhd_info *dhdinfo = dhd->info;
2778 if (waitqueue_active(&dhdinfo->ctrl_wait))
2779 wake_up_interruptible(&dhdinfo->ctrl_wait);
2783 int dhd_dev_reset(struct net_device *dev, uint8 flag)
2785 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2787 /* Turning off watchdog */
2789 dhd_os_wd_timer(&dhd->pub, 0);
2791 dhd_bus_devreset(&dhd->pub, flag);
2793 /* Turning on watchdog back */
2795 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2796 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2801 int net_os_set_suspend_disable(struct net_device *dev, int val)
2803 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2807 ret = dhd->pub.suspend_disable_flag;
2808 dhd->pub.suspend_disable_flag = val;
2813 int net_os_set_suspend(struct net_device *dev, int val)
2816 #if defined(CONFIG_HAS_EARLYSUSPEND)
2817 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2820 dhd_os_proto_block(&dhd->pub);
2821 ret = dhd_set_suspend(val, &dhd->pub);
2822 dhd_os_proto_unblock(&dhd->pub);
2824 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2828 int net_os_set_dtim_skip(struct net_device *dev, int val)
2830 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2833 dhd->pub.dtim_skip = val;
2838 int net_os_set_packet_filter(struct net_device *dev, int val)
2840 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2843 /* Packet filtering is set only if we still in early-suspend and
2844 * we need either to turn it ON or turn it OFF
2845 * We can always turn it OFF in case of early-suspend, but we turn it
2846 * back ON only if suspend_disable_flag was not set
2848 if (dhd && dhd->pub.up) {
2849 dhd_os_proto_block(&dhd->pub);
2850 if (dhd->pub.in_suspend) {
2851 if (!val || (val && !dhd->pub.suspend_disable_flag))
2852 dhd_set_packet_filter(val, &dhd->pub);
2854 dhd_os_proto_unblock(&dhd->pub);
2859 void dhd_dev_init_ioctl(struct net_device *dev)
2861 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2863 dhd_preinit_ioctls(&dhd->pub);
2867 /* Linux wrapper to call common dhd_pno_clean */
2868 int dhd_dev_pno_reset(struct net_device *dev)
2870 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2872 return dhd_pno_clean(&dhd->pub);
2875 /* Linux wrapper to call common dhd_pno_enable */
2876 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2878 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2880 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2883 /* Linux wrapper to call common dhd_pno_set */
2885 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2888 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2890 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2893 /* Linux wrapper to get pno status */
2894 int dhd_dev_get_pno_status(struct net_device *dev)
2896 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2898 return dhd_pno_get_status(&dhd->pub);
2901 #endif /* PNO_SUPPORT */
2903 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2905 return atomic_read(&dhd->pend_8021x_cnt);
2908 #define MAX_WAIT_FOR_8021X_TX 10
2910 int dhd_wait_pend8021x(struct net_device *dev)
2912 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2913 int timeout = 10 * HZ / 1000;
2914 int ntimes = MAX_WAIT_FOR_8021X_TX;
2915 int pend = dhd_get_pend_8021x_cnt(dhd);
2917 while (ntimes && pend) {
2919 set_current_state(TASK_INTERRUPTIBLE);
2920 schedule_timeout(timeout);
2921 set_current_state(TASK_RUNNING);
2924 pend = dhd_get_pend_8021x_cnt(dhd);
2930 int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size)
2934 mm_segment_t old_fs;
2937 /* change to KERNEL_DS address limit */
2941 /* open file to write */
2942 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2944 printf("%s: open file error\n", __func__);
2949 /* Write buf to file */
2950 fp->f_op->write(fp, buf, size, &pos);
2953 /* free buf before return */
2954 MFREE(dhd->osh, buf, size);
2955 /* close file before return */
2957 filp_close(fp, current->files);
2958 /* restore previous address limit */
2963 #endif /* DHD_DEBUG */