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 = 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 #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 */
289 uint dhd_console_ms = 0;
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 = 0;
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) daemonize(a); \
341 allow_signal(SIGKILL); \
342 allow_signal(SIGTERM);
344 #define BLOCKABLE() (!in_atomic())
346 /* The following are specific to the SDIO dongle */
348 /* IOCTL response timeout */
349 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
351 /* Idle timeout for backplane clock */
352 int dhd_idletime = DHD_IDLETIME_TICKS;
353 module_param(dhd_idletime, int, 0);
356 uint dhd_poll = FALSE;
357 module_param(dhd_poll, uint, 0);
359 #ifdef CONFIG_CFG80211
361 uint dhd_cfg80211 = TRUE;
362 module_param(dhd_cfg80211, uint, 0);
366 uint dhd_intr = TRUE;
367 module_param(dhd_intr, uint, 0);
369 /* SDIO Drive Strength (in milliamps) */
370 uint dhd_sdiod_drive_strength = 6;
371 module_param(dhd_sdiod_drive_strength, uint, 0);
374 extern uint dhd_txbound;
375 extern uint dhd_rxbound;
376 module_param(dhd_txbound, uint, 0);
377 module_param(dhd_rxbound, uint, 0);
379 /* Deferred transmits */
380 extern uint dhd_deferred_tx;
381 module_param(dhd_deferred_tx, uint, 0);
384 /* Echo packet generator (pkts/s) */
386 module_param(dhd_pktgen, uint, 0);
388 /* Echo packet len (0 => sawtooth, max 2040) */
389 uint dhd_pktgen_len = 0;
390 module_param(dhd_pktgen_len, uint, 0);
393 #ifdef CONFIG_CFG80211
394 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
395 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
396 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
397 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
400 /* Version string to report */
402 #define DHD_COMPILED "\nCompiled in " SRCBASE
407 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
409 "\nCompiled in " " on " __DATE__ " at " __TIME__
413 #if defined(CONFIG_WIRELESS_EXT)
414 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
415 #endif /* defined(CONFIG_WIRELESS_EXT) */
417 static void dhd_dpc(unsigned long data);
419 extern int dhd_wait_pend8021x(struct net_device *dev);
423 #error TOE requires BDC
425 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
426 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
429 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
430 wl_event_msg_t *event_ptr, void **data_ptr);
432 #if defined(CONFIG_PM_SLEEP)
433 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
434 unsigned long action, void *ignored)
437 case PM_HIBERNATION_PREPARE:
438 case PM_SUSPEND_PREPARE:
439 dhd_mmc_suspend = TRUE;
441 case PM_POST_HIBERNATION:
442 case PM_POST_SUSPEND:
443 dhd_mmc_suspend = FALSE;
449 static struct notifier_block dhd_sleep_pm_notifier = {
450 .notifier_call = dhd_sleep_pm_callback,
454 extern int register_pm_notifier(struct notifier_block *nb);
455 extern int unregister_pm_notifier(struct notifier_block *nb);
456 #endif /* defined(CONFIG_PM_SLEEP) */
457 /* && defined(DHD_GPL) */
458 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
460 #ifdef PKT_FILTER_SUPPORT
461 DHD_TRACE(("%s: %d\n", __func__, value));
462 /* 1 - Enable packet filter, only allow unicast packet to send up */
463 /* 0 - Disable packet filter */
464 if (dhd_pkt_filter_enable) {
467 for (i = 0; i < dhd->pktfilter_count; i++) {
468 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
469 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
470 value, dhd_master_mode);
476 #if defined(CONFIG_HAS_EARLYSUSPEND)
477 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
479 int power_mode = PM_MAX;
480 /* wl_pkt_filter_enable_t enable_parm; */
485 #endif /* CUSTOMER_HW2 */
487 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
488 __func__, value, dhd->in_suspend));
490 if (dhd && dhd->up) {
491 if (value && dhd->in_suspend) {
493 /* Kernel suspended */
494 DHD_TRACE(("%s: force extra Suspend setting\n",
497 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
501 /* Enable packet filter, only allow unicast
503 dhd_set_packet_filter(1, dhd);
505 /* if dtim skip setup as default force it
506 * to wake each thrid dtim
507 * for better power saving.
508 * Note that side effect is chance to miss BC/MC
511 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
514 bcn_li_dtim = dhd->dtim_skip;
515 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
516 4, iovbuf, sizeof(iovbuf));
517 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
520 /* Disable build-in roaming to allowed \
521 * supplicant to take of romaing
523 bcm_mkiovar("roam_off", (char *)&roamvar, 4,
524 iovbuf, sizeof(iovbuf));
525 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
527 #endif /* CUSTOMER_HW2 */
531 DHD_TRACE(("%s: Remove extra suspend setting\n",
534 power_mode = PM_FAST;
535 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
539 /* disable pkt filter */
540 dhd_set_packet_filter(0, dhd);
542 /* restore pre-suspend setting for dtim_skip */
543 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
544 4, iovbuf, sizeof(iovbuf));
546 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
550 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
552 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
554 #endif /* CUSTOMER_HW2 */
561 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
563 dhd_pub_t *dhdp = &dhd->pub;
565 dhd_os_proto_block(dhdp);
566 /* Set flag when early suspend was called */
567 dhdp->in_suspend = val;
568 if (!dhdp->suspend_disable_flag)
569 dhd_set_suspend(val, dhdp);
570 dhd_os_proto_unblock(dhdp);
573 static void dhd_early_suspend(struct early_suspend *h)
575 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
577 DHD_TRACE(("%s: enter\n", __func__));
580 dhd_suspend_resume_helper(dhd, 1);
584 static void dhd_late_resume(struct early_suspend *h)
586 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
588 DHD_TRACE(("%s: enter\n", __func__));
591 dhd_suspend_resume_helper(dhd, 0);
593 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
596 * Generalized timeout mechanism. Uses spin sleep with exponential
598 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
600 * dhd_timeout_start(&tmo, usec);
601 * while (!dhd_timeout_expired(&tmo))
602 * if (poll_something())
604 * if (dhd_timeout_expired(&tmo))
608 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
613 tmo->tick = 1000000 / HZ;
616 int dhd_timeout_expired(dhd_timeout_t *tmo)
618 /* Does nothing the first call */
619 if (tmo->increment == 0) {
624 if (tmo->elapsed >= tmo->limit)
627 /* Add the delay that's about to take place */
628 tmo->elapsed += tmo->increment;
630 if (tmo->increment < tmo->tick) {
631 OSL_DELAY(tmo->increment);
633 if (tmo->increment > tmo->tick)
634 tmo->increment = tmo->tick;
636 wait_queue_head_t delay_wait;
637 DECLARE_WAITQUEUE(wait, current);
639 init_waitqueue_head(&delay_wait);
640 add_wait_queue(&delay_wait, &wait);
641 set_current_state(TASK_INTERRUPTIBLE);
643 pending = signal_pending(current);
644 remove_wait_queue(&delay_wait, &wait);
645 set_current_state(TASK_RUNNING);
647 return 1; /* Interrupted */
653 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
658 while (i < DHD_MAX_IFS) {
659 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
667 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
673 if (name == NULL || *name == '\0')
678 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
681 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
683 return i; /* default - the primary interface */
686 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
688 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
692 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
693 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
697 if (dhd->iflist[ifidx] == NULL) {
698 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
702 if (dhd->iflist[ifidx]->net)
703 return dhd->iflist[ifidx]->net->name;
708 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
710 struct net_device *dev;
711 struct netdev_hw_addr *ha;
712 uint32 allmulti, cnt;
719 ASSERT(dhd && dhd->iflist[ifidx]);
720 dev = dhd->iflist[ifidx]->net;
721 cnt = netdev_mc_count(dev);
723 /* Determine initial value of allmulti flag */
724 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
726 /* Send down the multicast list first. */
728 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
729 bufp = buf = MALLOC(dhd->pub.osh, buflen);
731 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
732 dhd_ifname(&dhd->pub, ifidx), cnt));
736 strcpy(bufp, "mcast_list");
737 bufp += strlen("mcast_list") + 1;
740 memcpy(bufp, &cnt, sizeof(cnt));
743 netdev_for_each_mc_addr(ha, dev) {
746 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
747 bufp += ETHER_ADDR_LEN;
751 memset(&ioc, 0, sizeof(ioc));
752 ioc.cmd = WLC_SET_VAR;
757 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
759 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
760 dhd_ifname(&dhd->pub, ifidx), cnt));
761 allmulti = cnt ? TRUE : allmulti;
764 MFREE(dhd->pub.osh, buf, buflen);
766 /* Now send the allmulti setting. This is based on the setting in the
767 * net_device flags, but might be modified above to be turned on if we
768 * were trying to set some addresses and dongle rejected it...
771 buflen = sizeof("allmulti") + sizeof(allmulti);
772 buf = MALLOC(dhd->pub.osh, buflen);
774 DHD_ERROR(("%s: out of memory for allmulti\n",
775 dhd_ifname(&dhd->pub, ifidx)));
778 allmulti = htol32(allmulti);
781 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
782 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
783 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
784 (int)sizeof(allmulti), buflen));
785 MFREE(dhd->pub.osh, buf, buflen);
789 memset(&ioc, 0, sizeof(ioc));
790 ioc.cmd = WLC_SET_VAR;
795 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
797 DHD_ERROR(("%s: set allmulti %d failed\n",
798 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
801 MFREE(dhd->pub.osh, buf, buflen);
803 /* Finally, pick up the PROMISC flag as well, like the NIC
806 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
807 allmulti = htol32(allmulti);
809 memset(&ioc, 0, sizeof(ioc));
810 ioc.cmd = WLC_SET_PROMISC;
812 ioc.len = sizeof(allmulti);
815 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
817 DHD_ERROR(("%s: set promisc %d failed\n",
818 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
823 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
829 DHD_TRACE(("%s enter\n", __func__));
831 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) {
832 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
833 dhd_ifname(&dhd->pub, ifidx)));
836 memset(&ioc, 0, sizeof(ioc));
837 ioc.cmd = WLC_SET_VAR;
842 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
844 DHD_ERROR(("%s: set cur_etheraddr failed\n",
845 dhd_ifname(&dhd->pub, ifidx)));
847 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
854 extern struct net_device *ap_net_dev;
857 static void dhd_op_if(dhd_if_t *ifp)
860 int ret = 0, err = 0;
862 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
866 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
868 switch (ifp->state) {
871 * Delete the existing interface before overwriting it
872 * in case we missed the WLC_E_IF_DEL event.
874 if (ifp->net != NULL) {
875 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
876 "try free & unregister\n",
877 __func__, ifp->net->name));
878 netif_stop_queue(ifp->net);
879 unregister_netdev(ifp->net);
880 free_netdev(ifp->net);
882 /* Allocate etherdev, including space for private structure */
883 ifp->net = alloc_etherdev(sizeof(dhd));
885 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
889 strcpy(ifp->net->name, ifp->name);
890 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
891 err = dhd_net_attach(&dhd->pub, ifp->idx);
893 DHD_ERROR(("%s: dhd_net_attach failed, "
899 /* semaphore that the soft AP CODE
901 extern struct semaphore ap_eth_sema;
903 /* save ptr to wl0.1 netdev for use
905 ap_net_dev = ifp->net;
906 /* signal to the SOFTAP 'sleeper' thread,
910 DHD_TRACE(("\n ==== pid:%x, net_device for "
911 "if:%s created ===\n\n",
912 current->pid, ifp->net->name));
918 if (ifp->net != NULL) {
919 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
921 netif_stop_queue(ifp->net);
922 unregister_netdev(ifp->net);
923 ret = DHD_DEL_IF; /* Make sure the free_netdev()
928 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
935 free_netdev(ifp->net);
937 dhd->iflist[ifp->idx] = NULL;
938 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
940 if (ifp->net == ap_net_dev)
941 ap_net_dev = NULL; /* NULL SOFTAP global
947 static int _dhd_sysioc_thread(void *data)
949 dhd_info_t *dhd = (dhd_info_t *) data;
955 DAEMONIZE("dhd_sysioc");
957 while (down_interruptible(&dhd->sysioc_sem) == 0) {
958 for (i = 0; i < DHD_MAX_IFS; i++) {
959 if (dhd->iflist[i]) {
961 in_ap = (ap_net_dev != NULL);
963 if (dhd->iflist[i]->state)
964 dhd_op_if(dhd->iflist[i]);
966 if (dhd->iflist[i] == NULL) {
967 DHD_TRACE(("\n\n %s: interface %d "
968 "removed!\n", __func__, i));
972 if (in_ap && dhd->set_macaddress) {
973 DHD_TRACE(("attempt to set MAC for %s "
974 "in AP Mode," "blocked. \n",
975 dhd->iflist[i]->net->name));
976 dhd->set_macaddress = FALSE;
980 if (in_ap && dhd->set_multicast) {
981 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
982 dhd->iflist[i]->net->name));
983 dhd->set_multicast = FALSE;
987 if (dhd->set_multicast) {
988 dhd->set_multicast = FALSE;
989 _dhd_set_multicast_list(dhd, i);
991 if (dhd->set_macaddress) {
992 dhd->set_macaddress = FALSE;
993 _dhd_set_mac_address(dhd, i,
999 complete_and_exit(&dhd->sysioc_exited, 0);
1002 static int dhd_set_mac_address(struct net_device *dev, void *addr)
1006 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1007 struct sockaddr *sa = (struct sockaddr *)addr;
1010 ifidx = dhd_net2idx(dhd, dev);
1011 if (ifidx == DHD_BAD_IF)
1014 ASSERT(dhd->sysioc_pid >= 0);
1015 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1016 dhd->set_macaddress = TRUE;
1017 up(&dhd->sysioc_sem);
1022 static void dhd_set_multicast_list(struct net_device *dev)
1024 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1027 ifidx = dhd_net2idx(dhd, dev);
1028 if (ifidx == DHD_BAD_IF)
1031 ASSERT(dhd->sysioc_pid >= 0);
1032 dhd->set_multicast = TRUE;
1033 up(&dhd->sysioc_sem);
1036 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1039 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1041 /* Reject if down */
1042 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1045 /* Update multicast statistic */
1046 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1047 u8 *pktdata = (u8 *) PKTDATA(pktbuf);
1048 struct ether_header *eh = (struct ether_header *)pktdata;
1050 if (ETHER_ISMULTI(eh->ether_dhost))
1051 dhdp->tx_multicast++;
1052 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1053 atomic_inc(&dhd->pend_8021x_cnt);
1056 /* Look into the packet and update the packet priority */
1057 if ((PKTPRIO(pktbuf) == 0))
1058 pktsetprio(pktbuf, FALSE);
1060 /* If the protocol uses a data header, apply it */
1061 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1063 /* Use bus module to send data frame */
1065 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1067 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1068 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1069 #endif /* BCMDBUS */
1074 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1078 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1081 DHD_TRACE(("%s: Enter\n", __func__));
1083 /* Reject if down */
1084 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1085 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1086 __func__, dhd->pub.up, dhd->pub.busstate));
1087 netif_stop_queue(net);
1091 ifidx = dhd_net2idx(dhd, net);
1092 if (ifidx == DHD_BAD_IF) {
1093 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1094 netif_stop_queue(net);
1098 /* Make sure there's enough room for any header */
1099 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1100 struct sk_buff *skb2;
1102 DHD_INFO(("%s: insufficient headroom\n",
1103 dhd_ifname(&dhd->pub, ifidx)));
1104 dhd->pub.tx_realloc++;
1105 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1109 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1110 dhd_ifname(&dhd->pub, ifidx)));
1116 /* Convert to packet */
1117 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1119 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1120 dhd_ifname(&dhd->pub, ifidx)));
1121 dev_kfree_skb_any(skb);
1126 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1130 dhd->pub.dstats.tx_dropped++;
1132 dhd->pub.tx_packets++;
1134 /* Return ok: we always eat the packet */
1138 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1140 struct net_device *net;
1141 dhd_info_t *dhd = dhdp->info;
1143 DHD_TRACE(("%s: Enter\n", __func__));
1145 dhdp->txoff = state;
1146 ASSERT(dhd && dhd->iflist[ifidx]);
1147 net = dhd->iflist[ifidx]->net;
1149 netif_stop_queue(net);
1151 netif_wake_queue(net);
1154 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1156 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1157 struct sk_buff *skb;
1160 void *data, *pnext, *save_pktbuf;
1163 wl_event_msg_t event;
1165 DHD_TRACE(("%s: Enter\n", __func__));
1167 save_pktbuf = pktbuf;
1169 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1171 pnext = PKTNEXT(pktbuf);
1172 PKTSETNEXT(pktbuf, NULL);
1174 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1176 /* Get the protocol, maintain skb around eth_type_trans()
1177 * The main reason for this hack is for the limitation of
1178 * Linux 2.4 where 'eth_type_trans' uses the
1179 * 'net->hard_header_len'
1180 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1181 * coping of the packet coming from the network stack to add
1182 * BDC, Hardware header etc, during network interface
1184 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1186 * for BDC, Hardware header etc. and not just the ETH_HLEN
1191 ifp = dhd->iflist[ifidx];
1193 ifp = dhd->iflist[0];
1196 skb->dev = ifp->net;
1197 skb->protocol = eth_type_trans(skb, skb->dev);
1199 if (skb->pkt_type == PACKET_MULTICAST)
1200 dhd->pub.rx_multicast++;
1205 /* Strip header, count, deliver upward */
1206 skb_pull(skb, ETH_HLEN);
1208 /* Process special event packets and then discard them */
1209 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1210 dhd_wl_host_event(dhd, &ifidx,
1214 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1215 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1216 ifp = dhd->iflist[ifidx];
1219 ifp->net->last_rx = jiffies;
1221 dhdp->dstats.rx_bytes += skb->len;
1222 dhdp->rx_packets++; /* Local count */
1224 if (in_interrupt()) {
1227 /* If the receive is not processed inside an ISR,
1228 * the softirqd must be woken explicitly to service
1229 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1230 * by netif_rx_ni(), but in earlier kernels, we need
1231 * to do it manually.
1238 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1240 /* Linux version has nothing to do */
1244 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1247 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1248 struct ether_header *eh;
1251 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1253 eh = (struct ether_header *)PKTDATA(txp);
1254 type = ntoh16(eh->ether_type);
1256 if (type == ETHER_TYPE_802_1X)
1257 atomic_dec(&dhd->pend_8021x_cnt);
1261 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1263 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1267 DHD_TRACE(("%s: Enter\n", __func__));
1269 ifidx = dhd_net2idx(dhd, net);
1270 if (ifidx == DHD_BAD_IF)
1273 ifp = dhd->iflist[ifidx];
1277 /* Use the protocol to get dongle stats */
1278 dhd_prot_dstats(&dhd->pub);
1281 /* Copy dongle stats to net device stats */
1282 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1283 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1284 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1285 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1286 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1287 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1288 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1289 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1290 ifp->stats.multicast = dhd->pub.dstats.multicast;
1295 static int dhd_watchdog_thread(void *data)
1297 dhd_info_t *dhd = (dhd_info_t *) data;
1298 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1300 /* This thread doesn't need any user-level access,
1301 * so get rid of all our resources
1304 if (dhd_watchdog_prio > 0) {
1305 struct sched_param param;
1306 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1307 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1308 setScheduler(current, SCHED_FIFO, ¶m);
1310 #endif /* DHD_SCHED */
1312 DAEMONIZE("dhd_watchdog");
1314 /* Run until signal received */
1316 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1317 if (dhd->pub.dongle_reset == FALSE) {
1318 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1319 /* Call the bus module watchdog */
1320 dhd_bus_watchdog(&dhd->pub);
1321 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1323 /* Count the tick for reference */
1329 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1330 complete_and_exit(&dhd->watchdog_exited, 0);
1333 static void dhd_watchdog(unsigned long data)
1335 dhd_info_t *dhd = (dhd_info_t *) data;
1337 if (dhd->watchdog_pid >= 0) {
1338 up(&dhd->watchdog_sem);
1340 /* Reschedule the watchdog */
1341 if (dhd->wd_timer_valid) {
1342 mod_timer(&dhd->timer,
1343 jiffies + dhd_watchdog_ms * HZ / 1000);
1348 /* Call the bus module watchdog */
1349 dhd_bus_watchdog(&dhd->pub);
1351 /* Count the tick for reference */
1354 /* Reschedule the watchdog */
1355 if (dhd->wd_timer_valid)
1356 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1359 static int dhd_dpc_thread(void *data)
1361 dhd_info_t *dhd = (dhd_info_t *) data;
1363 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1364 /* This thread doesn't need any user-level access,
1365 * so get rid of all our resources
1368 if (dhd_dpc_prio > 0) {
1369 struct sched_param param;
1370 param.sched_priority =
1372 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1373 setScheduler(current, SCHED_FIFO, ¶m);
1375 #endif /* DHD_SCHED */
1377 DAEMONIZE("dhd_dpc");
1379 /* Run until signal received */
1381 if (down_interruptible(&dhd->dpc_sem) == 0) {
1382 /* Call bus dpc unless it indicated down
1383 (then clean stop) */
1384 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1385 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1386 if (dhd_bus_dpc(dhd->pub.bus)) {
1388 WAKE_LOCK_TIMEOUT(&dhd->pub,
1389 WAKE_LOCK_TMOUT, 25);
1391 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1393 dhd_bus_stop(dhd->pub.bus, TRUE);
1399 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1401 complete_and_exit(&dhd->dpc_exited, 0);
1404 static void dhd_dpc(unsigned long data)
1408 dhd = (dhd_info_t *) data;
1410 /* Call bus dpc unless it indicated down (then clean stop) */
1411 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1412 if (dhd_bus_dpc(dhd->pub.bus))
1413 tasklet_schedule(&dhd->tasklet);
1415 dhd_bus_stop(dhd->pub.bus, TRUE);
1419 void dhd_sched_dpc(dhd_pub_t *dhdp)
1421 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1423 if (dhd->dpc_pid >= 0) {
1428 tasklet_schedule(&dhd->tasklet);
1432 /* Retrieve current toe component enables, which are kept
1433 as a bitmap in toe_ol iovar */
1434 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
1440 memset(&ioc, 0, sizeof(ioc));
1442 ioc.cmd = WLC_GET_VAR;
1444 ioc.len = (uint) sizeof(buf);
1447 strcpy(buf, "toe_ol");
1448 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1450 /* Check for older dongle image that doesn't support toe_ol */
1452 DHD_ERROR(("%s: toe not supported by device\n",
1453 dhd_ifname(&dhd->pub, ifidx)));
1457 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1458 dhd_ifname(&dhd->pub, ifidx), ret));
1462 memcpy(toe_ol, buf, sizeof(uint32));
1466 /* Set current toe component enables in toe_ol iovar,
1467 and set toe global enable iovar */
1468 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
1474 memset(&ioc, 0, sizeof(ioc));
1476 ioc.cmd = WLC_SET_VAR;
1478 ioc.len = (uint) sizeof(buf);
1481 /* Set toe_ol as requested */
1483 strcpy(buf, "toe_ol");
1484 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
1486 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1488 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1489 dhd_ifname(&dhd->pub, ifidx), ret));
1493 /* Enable toe globally only if any components are enabled. */
1495 toe = (toe_ol != 0);
1498 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
1500 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1502 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1503 dhd_ifname(&dhd->pub, ifidx), ret));
1511 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1512 struct ethtool_drvinfo *info)
1514 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1516 sprintf(info->driver, DRV_MODULE_NAME);
1517 sprintf(info->version, "%lu", dhd->pub.drv_version);
1518 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1519 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1522 struct ethtool_ops dhd_ethtool_ops = {
1523 .get_drvinfo = dhd_ethtool_get_drvinfo
1526 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1528 struct ethtool_drvinfo info;
1529 char drvname[sizeof(info.driver)];
1532 struct ethtool_value edata;
1533 uint32 toe_cmpnt, csum_dir;
1537 DHD_TRACE(("%s: Enter\n", __func__));
1539 /* all ethtool calls start with a cmd word */
1540 if (copy_from_user(&cmd, uaddr, sizeof(uint32)))
1544 case ETHTOOL_GDRVINFO:
1545 /* Copy out any request driver name */
1546 if (copy_from_user(&info, uaddr, sizeof(info)))
1548 strncpy(drvname, info.driver, sizeof(info.driver));
1549 drvname[sizeof(info.driver) - 1] = '\0';
1551 /* clear struct for return */
1552 memset(&info, 0, sizeof(info));
1555 /* if dhd requested, identify ourselves */
1556 if (strcmp(drvname, "?dhd") == 0) {
1557 sprintf(info.driver, "dhd");
1558 strcpy(info.version, EPI_VERSION_STR);
1561 /* otherwise, require dongle to be up */
1562 else if (!dhd->pub.up) {
1563 DHD_ERROR(("%s: dongle is not up\n", __func__));
1567 /* finally, report dongle driver type */
1568 else if (dhd->pub.iswl)
1569 sprintf(info.driver, "wl");
1571 sprintf(info.driver, "xx");
1573 sprintf(info.version, "%lu", dhd->pub.drv_version);
1574 if (copy_to_user(uaddr, &info, sizeof(info)))
1576 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1577 (int)sizeof(drvname), drvname, info.driver));
1581 /* Get toe offload components from dongle */
1582 case ETHTOOL_GRXCSUM:
1583 case ETHTOOL_GTXCSUM:
1584 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1589 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1592 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1594 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1598 /* Set toe offload components in dongle */
1599 case ETHTOOL_SRXCSUM:
1600 case ETHTOOL_STXCSUM:
1601 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1604 /* Read the current settings, update and write back */
1605 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1610 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1612 if (edata.data != 0)
1613 toe_cmpnt |= csum_dir;
1615 toe_cmpnt &= ~csum_dir;
1617 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1621 /* If setting TX checksum mode, tell Linux the new mode */
1622 if (cmd == ETHTOOL_STXCSUM) {
1624 dhd->iflist[0]->net->features |=
1627 dhd->iflist[0]->net->features &=
1641 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1643 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1650 bool is_set_key_cmd;
1652 ifidx = dhd_net2idx(dhd, net);
1653 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1655 if (ifidx == DHD_BAD_IF)
1658 #if defined(CONFIG_WIRELESS_EXT)
1659 /* linux wireless extensions */
1660 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1661 /* may recurse, do NOT lock */
1662 return wl_iw_ioctl(net, ifr, cmd);
1664 #endif /* defined(CONFIG_WIRELESS_EXT) */
1666 if (cmd == SIOCETHTOOL)
1667 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1669 if (cmd != SIOCDEVPRIVATE)
1672 memset(&ioc, 0, sizeof(ioc));
1674 /* Copy the ioc control structure part of ioctl request */
1675 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1676 bcmerror = -BCME_BADADDR;
1680 /* Copy out any buffer passed */
1682 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1683 /* optimization for direct ioctl calls from kernel */
1685 if (segment_eq(get_fs(), KERNEL_DS)) {
1690 buf = (char *)MALLOC(dhd->pub.osh, buflen);
1692 bcmerror = -BCME_NOMEM;
1695 if (copy_from_user(buf, ioc.buf, buflen)) {
1696 bcmerror = -BCME_BADADDR;
1702 /* To differentiate between wl and dhd read 4 more byes */
1703 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1704 sizeof(uint)) != 0)) {
1705 bcmerror = -BCME_BADADDR;
1709 if (!capable(CAP_NET_ADMIN)) {
1710 bcmerror = -BCME_EPERM;
1714 /* check for local dhd ioctl and handle it */
1715 if (driver == DHD_IOCTL_MAGIC) {
1716 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1718 dhd->pub.bcmerror = bcmerror;
1722 /* send to dongle (must be up, and wl) */
1723 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1724 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1725 bcmerror = BCME_DONGLE_DOWN;
1729 if (!dhd->pub.iswl) {
1730 bcmerror = BCME_DONGLE_DOWN;
1734 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1735 * prevent M4 encryption.
1737 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1738 ((ioc.cmd == WLC_SET_VAR) &&
1739 !(strncmp("wsec_key", ioc.buf, 9))) ||
1740 ((ioc.cmd == WLC_SET_VAR) &&
1741 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1743 dhd_wait_pend8021x(net);
1745 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1746 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1749 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1751 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1752 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1754 if (!bcmerror && buf && ioc.buf) {
1755 if (copy_to_user(ioc.buf, buf, buflen))
1760 MFREE(dhd->pub.osh, buf, buflen);
1762 return OSL_ERROR(bcmerror);
1765 static int dhd_stop(struct net_device *net)
1767 #if !defined(IGNORE_ETH0_DOWN)
1768 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1770 DHD_TRACE(("%s: Enter\n", __func__));
1771 #ifdef CONFIG_CFG80211
1772 if (IS_CFG80211_FAVORITE()) {
1776 if (dhd->pub.up == 0)
1779 /* Set state and stop OS transmissions */
1781 netif_stop_queue(net);
1783 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1785 #endif /* !defined(IGNORE_ETH0_DOWN) */
1787 OLD_MOD_DEC_USE_COUNT;
1791 static int dhd_open(struct net_device *net)
1793 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1797 int ifidx = dhd_net2idx(dhd, net);
1800 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1802 if (ifidx == 0) { /* do it only for primary eth0 */
1804 /* try to bring up bus */
1805 ret = dhd_bus_start(&dhd->pub);
1807 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1810 atomic_set(&dhd->pend_8021x_cnt, 0);
1812 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1815 /* Get current TOE mode from dongle */
1816 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1817 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1818 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1820 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1823 /* Allow transmit calls */
1824 netif_start_queue(net);
1826 #ifdef CONFIG_CFG80211
1827 if (IS_CFG80211_FAVORITE()) {
1828 if (unlikely(wl_cfg80211_up())) {
1829 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1836 OLD_MOD_INC_USE_COUNT;
1840 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1842 return osl_attach(pdev, bustype, TRUE);
1845 void dhd_osl_detach(osl_t *osh)
1847 if (MALLOCED(osh)) {
1848 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1855 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1856 u8 *mac_addr, uint32 flags, u8 bssidx)
1860 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1862 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1864 ifp = dhd->iflist[ifidx];
1865 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1866 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1870 memset(ifp, 0, sizeof(dhd_if_t));
1872 dhd->iflist[ifidx] = ifp;
1873 strncpy(ifp->name, name, IFNAMSIZ);
1874 ifp->name[IFNAMSIZ] = '\0';
1875 if (mac_addr != NULL)
1876 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1878 if (handle == NULL) {
1879 ifp->state = WLC_E_IF_ADD;
1881 ASSERT(dhd->sysioc_pid >= 0);
1882 up(&dhd->sysioc_sem);
1884 ifp->net = (struct net_device *)handle;
1889 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1893 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1895 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1896 ifp = dhd->iflist[ifidx];
1898 DHD_ERROR(("%s: Null interface\n", __func__));
1902 ifp->state = WLC_E_IF_DEL;
1904 ASSERT(dhd->sysioc_pid >= 0);
1905 up(&dhd->sysioc_sem);
1908 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1910 dhd_info_t *dhd = NULL;
1911 struct net_device *net;
1913 DHD_TRACE(("%s: Enter\n", __func__));
1914 /* updates firmware nvram path if it was provided as module
1916 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1917 strcpy(fw_path, firmware_path);
1918 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1919 strcpy(nv_path, nvram_path);
1921 /* Allocate etherdev, including space for private structure */
1922 net = alloc_etherdev(sizeof(dhd));
1924 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1928 /* Allocate primary dhd_info */
1929 dhd = MALLOC(osh, sizeof(dhd_info_t));
1931 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1935 memset(dhd, 0, sizeof(dhd_info_t));
1938 * Save the dhd_info into the priv
1940 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1943 /* Set network interface name if it was provided as module parameter */
1944 if (iface_name[0]) {
1947 strncpy(net->name, iface_name, IFNAMSIZ);
1948 net->name[IFNAMSIZ - 1] = 0;
1949 len = strlen(net->name);
1950 ch = net->name[len - 1];
1951 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1952 strcat(net->name, "%d");
1955 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1959 net->netdev_ops = NULL;
1960 init_MUTEX(&dhd->proto_sem);
1961 /* Initialize other structure content */
1962 init_waitqueue_head(&dhd->ioctl_resp_wait);
1963 init_waitqueue_head(&dhd->ctrl_wait);
1965 /* Initialize the spinlocks */
1966 spin_lock_init(&dhd->sdlock);
1967 spin_lock_init(&dhd->txqlock);
1969 /* Link to info module */
1970 dhd->pub.info = dhd;
1972 /* Link to bus module */
1974 dhd->pub.hdrlen = bus_hdrlen;
1976 /* Attach and link in the protocol */
1977 if (dhd_prot_attach(&dhd->pub) != 0) {
1978 DHD_ERROR(("dhd_prot_attach failed\n"));
1981 #if defined(CONFIG_WIRELESS_EXT)
1982 /* Attach and link in the iw */
1983 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1984 DHD_ERROR(("wl_iw_attach failed\n"));
1987 #endif /* defined(CONFIG_WIRELESS_EXT) */
1989 #ifdef CONFIG_CFG80211
1990 /* Attach and link in the cfg80211 */
1991 if (IS_CFG80211_FAVORITE()) {
1992 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1993 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1997 strcpy(fw_path, wl_cfg80211_get_fwname());
1998 strcpy(nv_path, wl_cfg80211_get_nvramname());
2000 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
2004 /* Set up the watchdog timer */
2005 init_timer(&dhd->timer);
2006 dhd->timer.data = (unsigned long) dhd;
2007 dhd->timer.function = dhd_watchdog;
2009 /* Initialize thread based operation and lock */
2010 init_MUTEX(&dhd->sdsem);
2011 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
2012 dhd->threads_only = TRUE;
2014 dhd->threads_only = FALSE;
2016 if (dhd_dpc_prio >= 0) {
2017 /* Initialize watchdog thread */
2018 sema_init(&dhd->watchdog_sem, 0);
2019 init_completion(&dhd->watchdog_exited);
2020 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2022 dhd->watchdog_pid = -1;
2025 /* Set up the bottom half handler */
2026 if (dhd_dpc_prio >= 0) {
2027 /* Initialize DPC thread */
2028 sema_init(&dhd->dpc_sem, 0);
2029 init_completion(&dhd->dpc_exited);
2030 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2032 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2037 sema_init(&dhd->sysioc_sem, 0);
2038 init_completion(&dhd->sysioc_exited);
2039 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2041 dhd->sysioc_pid = -1;
2045 * Save the dhd_info into the priv
2047 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2049 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2052 #if defined(CONFIG_PM_SLEEP)
2053 register_pm_notifier(&dhd_sleep_pm_notifier);
2054 #endif /* defined(CONFIG_PM_SLEEP) */
2055 /* && defined(DHD_GPL) */
2056 /* Init lock suspend to prevent kernel going to suspend */
2057 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2058 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2059 "dhd_wake_lock_link_dw_event");
2060 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2061 "dhd_wake_lock_link_pno_find_event");
2062 #ifdef CONFIG_HAS_EARLYSUSPEND
2063 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2064 dhd->early_suspend.suspend = dhd_early_suspend;
2065 dhd->early_suspend.resume = dhd_late_resume;
2066 register_early_suspend(&dhd->early_suspend);
2075 dhd_detach(&dhd->pub);
2080 int dhd_bus_start(dhd_pub_t *dhdp)
2083 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2084 #ifdef EMBEDDED_PLATFORM
2085 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2087 #endif /* EMBEDDED_PLATFORM */
2091 DHD_TRACE(("%s:\n", __func__));
2093 /* try to download image and nvram to the dongle */
2094 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2095 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2096 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2097 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2098 fw_path, nv_path))) {
2099 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2100 "firmware = %s nvram = %s\n",
2101 __func__, fw_path, nv_path));
2102 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2103 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2107 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2108 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2111 /* Start the watchdog timer */
2112 dhd->pub.tickcnt = 0;
2113 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2115 /* Bring up the bus */
2116 ret = dhd_bus_init(&dhd->pub, TRUE);
2118 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2121 #if defined(OOB_INTR_ONLY)
2122 /* Host registration for OOB interrupt */
2123 if (bcmsdh_register_oob_intr(dhdp)) {
2124 del_timer_sync(&dhd->timer);
2125 dhd->wd_timer_valid = FALSE;
2126 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2130 /* Enable oob at firmware */
2131 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2132 #endif /* defined(OOB_INTR_ONLY) */
2134 /* If bus is not ready, can't come up */
2135 if (dhd->pub.busstate != DHD_BUS_DATA) {
2136 del_timer_sync(&dhd->timer);
2137 dhd->wd_timer_valid = FALSE;
2138 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2141 #ifdef EMBEDDED_PLATFORM
2142 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2144 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2145 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2147 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2148 setbit(dhdp->eventmask, WLC_E_PRUNE);
2149 setbit(dhdp->eventmask, WLC_E_AUTH);
2150 setbit(dhdp->eventmask, WLC_E_REASSOC);
2151 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2152 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2153 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2154 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2155 setbit(dhdp->eventmask, WLC_E_JOIN);
2156 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2157 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2158 setbit(dhdp->eventmask, WLC_E_LINK);
2159 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2160 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2161 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2162 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2163 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2164 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2166 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2167 #endif /* PNO_SUPPORT */
2169 /* enable dongle roaming event */
2171 dhdp->pktfilter_count = 1;
2172 /* Setup filter to allow only unicast */
2173 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2174 #endif /* EMBEDDED_PLATFORM */
2176 /* Bus is ready, do any protocol initialization */
2177 ret = dhd_prot_init(&dhd->pub);
2185 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2188 char buf[strlen(name) + 1 + cmd_len];
2189 int len = sizeof(buf);
2193 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2195 memset(&ioc, 0, sizeof(ioc));
2197 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2202 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2203 if (!set && ret >= 0)
2204 memcpy(cmd_buf, buf, cmd_len);
2209 static struct net_device_ops dhd_ops_pri = {
2210 .ndo_open = dhd_open,
2211 .ndo_stop = dhd_stop,
2212 .ndo_get_stats = dhd_get_stats,
2213 .ndo_do_ioctl = dhd_ioctl_entry,
2214 .ndo_start_xmit = dhd_start_xmit,
2215 .ndo_set_mac_address = dhd_set_mac_address,
2216 .ndo_set_multicast_list = dhd_set_multicast_list
2219 static struct net_device_ops dhd_ops_virt = {
2220 .ndo_get_stats = dhd_get_stats,
2221 .ndo_do_ioctl = dhd_ioctl_entry,
2222 .ndo_start_xmit = dhd_start_xmit,
2223 .ndo_set_mac_address = dhd_set_mac_address,
2224 .ndo_set_multicast_list = dhd_set_multicast_list
2227 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2229 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2230 struct net_device *net;
2231 u8 temp_addr[ETHER_ADDR_LEN] = {
2232 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2234 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2236 ASSERT(dhd && dhd->iflist[ifidx]);
2238 net = dhd->iflist[ifidx]->net;
2241 ASSERT(!net->netdev_ops);
2242 net->netdev_ops = &dhd_ops_virt;
2244 net->netdev_ops = &dhd_ops_pri;
2247 * We have to use the primary MAC for virtual interfaces
2250 /* for virtual interfaces use the primary MAC */
2251 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2256 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2257 /* ACCESSPOINT INTERFACE CASE */
2258 temp_addr[0] |= 0X02; /* set bit 2 ,
2259 - Locally Administered address */
2262 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2263 net->ethtool_ops = &dhd_ethtool_ops;
2265 #if defined(CONFIG_WIRELESS_EXT)
2266 #if defined(CONFIG_CFG80211)
2267 if (!IS_CFG80211_FAVORITE()) {
2269 #if WIRELESS_EXT < 19
2270 net->get_wireless_stats = dhd_get_wireless_stats;
2271 #endif /* WIRELESS_EXT < 19 */
2272 #if WIRELESS_EXT > 12
2273 net->wireless_handlers =
2274 (struct iw_handler_def *)&wl_iw_handler_def;
2275 #endif /* WIRELESS_EXT > 12 */
2276 #if defined(CONFIG_CFG80211)
2279 #endif /* defined(CONFIG_WIRELESS_EXT) */
2281 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2283 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2285 if (register_netdev(net) != 0) {
2286 DHD_ERROR(("%s: couldn't register the net device\n",
2291 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2296 net->netdev_ops = NULL;
2300 void dhd_bus_detach(dhd_pub_t *dhdp)
2304 DHD_TRACE(("%s: Enter\n", __func__));
2307 dhd = (dhd_info_t *) dhdp->info;
2309 /* Stop the protocol module */
2310 dhd_prot_stop(&dhd->pub);
2312 /* Stop the bus module */
2313 dhd_bus_stop(dhd->pub.bus, TRUE);
2314 #if defined(OOB_INTR_ONLY)
2315 bcmsdh_unregister_oob_intr();
2316 #endif /* defined(OOB_INTR_ONLY) */
2318 /* Clear the watchdog timer */
2319 del_timer_sync(&dhd->timer);
2320 dhd->wd_timer_valid = FALSE;
2325 void dhd_detach(dhd_pub_t *dhdp)
2329 DHD_TRACE(("%s: Enter\n", __func__));
2332 dhd = (dhd_info_t *) dhdp->info;
2337 #if defined(CONFIG_HAS_EARLYSUSPEND)
2338 if (dhd->early_suspend.suspend)
2339 unregister_early_suspend(&dhd->early_suspend);
2340 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2342 for (i = 1; i < DHD_MAX_IFS; i++)
2346 ifp = dhd->iflist[0];
2348 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2350 unregister_netdev(ifp->net);
2353 if (dhd->watchdog_pid >= 0) {
2354 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2355 wait_for_completion(&dhd->watchdog_exited);
2358 if (dhd->dpc_pid >= 0) {
2359 KILL_PROC(dhd->dpc_pid, SIGTERM);
2360 wait_for_completion(&dhd->dpc_exited);
2362 tasklet_kill(&dhd->tasklet);
2364 if (dhd->sysioc_pid >= 0) {
2365 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2366 wait_for_completion(&dhd->sysioc_exited);
2369 dhd_bus_detach(dhdp);
2372 dhd_prot_detach(dhdp);
2374 #if defined(CONFIG_WIRELESS_EXT)
2376 #endif /* (CONFIG_WIRELESS_EXT) */
2378 #ifdef CONFIG_CFG80211
2379 if (IS_CFG80211_FAVORITE())
2380 wl_cfg80211_detach();
2381 #endif /* CONFIG_CFG80211 */
2383 #if defined(CONFIG_PM_SLEEP)
2384 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2385 #endif /* defined(CONFIG_PM_SLEEP) */
2386 /* && defined(DHD_GPL) */
2387 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2388 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2389 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2390 free_netdev(ifp->net);
2391 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2392 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2397 static void __exit dhd_module_cleanup(void)
2399 DHD_TRACE(("%s: Enter\n", __func__));
2401 dhd_bus_unregister();
2402 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2405 /* Call customer gpio to turn off power with WL_REG_ON signal */
2406 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2409 static int __init dhd_module_init(void)
2413 DHD_TRACE(("%s: Enter\n", __func__));
2415 /* Sanity check on the module parameters */
2417 /* Both watchdog and DPC as tasklets are ok */
2418 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2421 /* If both watchdog and DPC are threads, TX must be deferred */
2422 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2426 DHD_ERROR(("Invalid module parameters.\n"));
2429 /* Call customer gpio to turn on power with WL_REG_ON signal */
2430 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2432 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2433 sema_init(&wifi_control_sem, 0);
2435 error = wifi_add_dev();
2437 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2441 /* Waiting callback after platform_driver_register is done or
2443 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2444 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2450 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2452 error = dhd_bus_register();
2455 printf("\n%s\n", dhd_version);
2457 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2463 /* turn off power and exit */
2464 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2468 module_init(dhd_module_init);
2469 module_exit(dhd_module_cleanup);
2472 * OS specific functions required to implement DHD driver in OS independent way
2474 int dhd_os_proto_block(dhd_pub_t *pub)
2476 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2479 down(&dhd->proto_sem);
2485 int dhd_os_proto_unblock(dhd_pub_t *pub)
2487 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2490 up(&dhd->proto_sem);
2497 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2499 return (unsigned int)dhd_ioctl_timeout_msec;
2502 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2504 dhd_ioctl_timeout_msec = (int)timeout_msec;
2507 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2509 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2510 DECLARE_WAITQUEUE(wait, current);
2511 int timeout = dhd_ioctl_timeout_msec;
2513 /* Convert timeout in millsecond to jiffies */
2514 timeout = timeout * HZ / 1000;
2516 /* Wait until control frame is available */
2517 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2518 set_current_state(TASK_INTERRUPTIBLE);
2520 while (!(*condition) && (!signal_pending(current) && timeout))
2521 timeout = schedule_timeout(timeout);
2523 if (signal_pending(current))
2526 set_current_state(TASK_RUNNING);
2527 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2532 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2534 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2536 if (waitqueue_active(&dhd->ioctl_resp_wait))
2537 wake_up_interruptible(&dhd->ioctl_resp_wait);
2542 void dhd_os_wd_timer(void *bus, uint wdtick)
2544 dhd_pub_t *pub = bus;
2545 static uint save_dhd_watchdog_ms = 0;
2546 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2548 /* don't start the wd until fw is loaded */
2549 if (pub->busstate == DHD_BUS_DOWN)
2552 /* Totally stop the timer */
2553 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2554 del_timer_sync(&dhd->timer);
2555 dhd->wd_timer_valid = FALSE;
2556 save_dhd_watchdog_ms = wdtick;
2561 dhd_watchdog_ms = (uint) wdtick;
2563 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2565 if (dhd->wd_timer_valid == TRUE)
2566 /* Stop timer and restart at new value */
2567 del_timer_sync(&dhd->timer);
2569 /* Create timer again when watchdog period is
2570 dynamically changed or in the first instance
2572 dhd->timer.expires =
2573 jiffies + dhd_watchdog_ms * HZ / 1000;
2574 add_timer(&dhd->timer);
2577 /* Re arm the timer, at last watchdog period */
2578 mod_timer(&dhd->timer,
2579 jiffies + dhd_watchdog_ms * HZ / 1000);
2582 dhd->wd_timer_valid = TRUE;
2583 save_dhd_watchdog_ms = wdtick;
2587 void *dhd_os_open_image(char *filename)
2591 #ifdef CONFIG_CFG80211
2592 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2593 return wl_cfg80211_request_fw(filename);
2596 fp = filp_open(filename, O_RDONLY, 0);
2598 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2600 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2609 int dhd_os_get_image_block(char *buf, int len, void *image)
2611 struct file *fp = (struct file *)image;
2614 #ifdef CONFIG_CFG80211
2615 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2616 return wl_cfg80211_read_fw(buf, len);
2622 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2629 void dhd_os_close_image(void *image)
2631 #ifdef CONFIG_CFG80211
2632 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2633 return wl_cfg80211_release_fw();
2636 filp_close((struct file *)image, NULL);
2639 void dhd_os_sdlock(dhd_pub_t *pub)
2643 dhd = (dhd_info_t *) (pub->info);
2645 if (dhd->threads_only)
2648 spin_lock_bh(&dhd->sdlock);
2651 void dhd_os_sdunlock(dhd_pub_t *pub)
2655 dhd = (dhd_info_t *) (pub->info);
2657 if (dhd->threads_only)
2660 spin_unlock_bh(&dhd->sdlock);
2663 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2667 dhd = (dhd_info_t *) (pub->info);
2668 spin_lock_bh(&dhd->txqlock);
2671 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2675 dhd = (dhd_info_t *) (pub->info);
2676 spin_unlock_bh(&dhd->txqlock);
2679 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2683 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2687 void dhd_os_sdtxlock(dhd_pub_t *pub)
2692 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2694 dhd_os_sdunlock(pub);
2697 #ifdef DHD_USE_STATIC_BUF
2698 void *dhd_os_prealloc(int section, unsigned long size)
2700 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2701 void *alloc_ptr = NULL;
2702 if (wifi_control_data && wifi_control_data->mem_prealloc) {
2703 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2705 DHD_INFO(("success alloc section %d\n", section));
2706 bzero(alloc_ptr, size);
2711 DHD_ERROR(("can't alloc section %d\n", section));
2714 return MALLOC(0, size);
2715 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2717 #endif /* DHD_USE_STATIC_BUF */
2718 #if defined(CONFIG_WIRELESS_EXT)
2719 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2722 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2724 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2727 return &dhd->iw.wstats;
2731 #endif /* defined(CONFIG_WIRELESS_EXT) */
2734 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2735 wl_event_msg_t *event, void **data)
2739 ASSERT(dhd != NULL);
2741 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2742 if (bcmerror != BCME_OK)
2745 #if defined(CONFIG_WIRELESS_EXT)
2746 #if defined(CONFIG_CFG80211)
2747 if (!IS_CFG80211_FAVORITE()) {
2749 if ((dhd->iflist[*ifidx] == NULL)
2750 || (dhd->iflist[*ifidx]->net == NULL)) {
2751 DHD_ERROR(("%s Exit null pointer\n", __func__));
2755 if (dhd->iflist[*ifidx]->net)
2756 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2757 #if defined(CONFIG_CFG80211)
2760 #endif /* defined(CONFIG_WIRELESS_EXT) */
2762 #ifdef CONFIG_CFG80211
2763 if (IS_CFG80211_FAVORITE()) {
2764 ASSERT(dhd->iflist[*ifidx] != NULL);
2765 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2766 if (dhd->iflist[*ifidx]->net)
2767 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2775 /* send up locally generated event */
2776 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2778 switch (ntoh32(event->event_type)) {
2784 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2786 struct dhd_info *dhdinfo = dhd->info;
2787 dhd_os_sdunlock(dhd);
2788 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2789 (*lockvar == FALSE), HZ * 2);
2794 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2796 struct dhd_info *dhdinfo = dhd->info;
2797 if (waitqueue_active(&dhdinfo->ctrl_wait))
2798 wake_up_interruptible(&dhdinfo->ctrl_wait);
2802 int dhd_dev_reset(struct net_device *dev, u8 flag)
2804 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2806 /* Turning off watchdog */
2808 dhd_os_wd_timer(&dhd->pub, 0);
2810 dhd_bus_devreset(&dhd->pub, flag);
2812 /* Turning on watchdog back */
2814 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2815 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2820 int net_os_set_suspend_disable(struct net_device *dev, int val)
2822 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2826 ret = dhd->pub.suspend_disable_flag;
2827 dhd->pub.suspend_disable_flag = val;
2832 int net_os_set_suspend(struct net_device *dev, int val)
2835 #if defined(CONFIG_HAS_EARLYSUSPEND)
2836 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2839 dhd_os_proto_block(&dhd->pub);
2840 ret = dhd_set_suspend(val, &dhd->pub);
2841 dhd_os_proto_unblock(&dhd->pub);
2843 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2847 int net_os_set_dtim_skip(struct net_device *dev, int val)
2849 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2852 dhd->pub.dtim_skip = val;
2857 int net_os_set_packet_filter(struct net_device *dev, int val)
2859 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2862 /* Packet filtering is set only if we still in early-suspend and
2863 * we need either to turn it ON or turn it OFF
2864 * We can always turn it OFF in case of early-suspend, but we turn it
2865 * back ON only if suspend_disable_flag was not set
2867 if (dhd && dhd->pub.up) {
2868 dhd_os_proto_block(&dhd->pub);
2869 if (dhd->pub.in_suspend) {
2870 if (!val || (val && !dhd->pub.suspend_disable_flag))
2871 dhd_set_packet_filter(val, &dhd->pub);
2873 dhd_os_proto_unblock(&dhd->pub);
2878 void dhd_dev_init_ioctl(struct net_device *dev)
2880 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2882 dhd_preinit_ioctls(&dhd->pub);
2886 /* Linux wrapper to call common dhd_pno_clean */
2887 int dhd_dev_pno_reset(struct net_device *dev)
2889 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2891 return dhd_pno_clean(&dhd->pub);
2894 /* Linux wrapper to call common dhd_pno_enable */
2895 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2897 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2899 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2902 /* Linux wrapper to call common dhd_pno_set */
2904 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2905 unsigned char scan_fr)
2907 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2909 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2912 /* Linux wrapper to get pno status */
2913 int dhd_dev_get_pno_status(struct net_device *dev)
2915 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2917 return dhd_pno_get_status(&dhd->pub);
2920 #endif /* PNO_SUPPORT */
2922 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2924 return atomic_read(&dhd->pend_8021x_cnt);
2927 #define MAX_WAIT_FOR_8021X_TX 10
2929 int dhd_wait_pend8021x(struct net_device *dev)
2931 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2932 int timeout = 10 * HZ / 1000;
2933 int ntimes = MAX_WAIT_FOR_8021X_TX;
2934 int pend = dhd_get_pend_8021x_cnt(dhd);
2936 while (ntimes && pend) {
2938 set_current_state(TASK_INTERRUPTIBLE);
2939 schedule_timeout(timeout);
2940 set_current_state(TASK_RUNNING);
2943 pend = dhd_get_pend_8021x_cnt(dhd);
2949 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2953 mm_segment_t old_fs;
2956 /* change to KERNEL_DS address limit */
2960 /* open file to write */
2961 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2963 printf("%s: open file error\n", __func__);
2968 /* Write buf to file */
2969 fp->f_op->write(fp, buf, size, &pos);
2972 /* free buf before return */
2973 MFREE(dhd->osh, buf, size);
2974 /* close file before return */
2976 filp_close(fp, current->files);
2977 /* restore previous address limit */
2982 #endif /* DHD_DEBUG */