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 u8 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(unsigned long 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 bufp = buf = MALLOC(dhd->pub.osh, buflen);
729 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
730 dhd_ifname(&dhd->pub, ifidx), cnt));
734 strcpy(bufp, "mcast_list");
735 bufp += strlen("mcast_list") + 1;
738 memcpy(bufp, &cnt, sizeof(cnt));
741 netdev_for_each_mc_addr(ha, dev) {
744 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
745 bufp += ETHER_ADDR_LEN;
749 memset(&ioc, 0, sizeof(ioc));
750 ioc.cmd = WLC_SET_VAR;
755 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
757 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
758 dhd_ifname(&dhd->pub, ifidx), cnt));
759 allmulti = cnt ? TRUE : allmulti;
762 MFREE(dhd->pub.osh, buf, buflen);
764 /* Now send the allmulti setting. This is based on the setting in the
765 * net_device flags, but might be modified above to be turned on if we
766 * were trying to set some addresses and dongle rejected it...
769 buflen = sizeof("allmulti") + sizeof(allmulti);
770 buf = MALLOC(dhd->pub.osh, buflen);
772 DHD_ERROR(("%s: out of memory for allmulti\n",
773 dhd_ifname(&dhd->pub, ifidx)));
776 allmulti = htol32(allmulti);
779 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
780 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
781 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
782 (int)sizeof(allmulti), buflen));
783 MFREE(dhd->pub.osh, buf, buflen);
787 memset(&ioc, 0, sizeof(ioc));
788 ioc.cmd = WLC_SET_VAR;
793 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
795 DHD_ERROR(("%s: set allmulti %d failed\n",
796 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
799 MFREE(dhd->pub.osh, buf, buflen);
801 /* Finally, pick up the PROMISC flag as well, like the NIC
804 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
805 allmulti = htol32(allmulti);
807 memset(&ioc, 0, sizeof(ioc));
808 ioc.cmd = WLC_SET_PROMISC;
810 ioc.len = sizeof(allmulti);
813 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
815 DHD_ERROR(("%s: set promisc %d failed\n",
816 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
821 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
827 DHD_TRACE(("%s enter\n", __func__));
829 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) {
830 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
831 dhd_ifname(&dhd->pub, ifidx)));
834 memset(&ioc, 0, sizeof(ioc));
835 ioc.cmd = WLC_SET_VAR;
840 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
842 DHD_ERROR(("%s: set cur_etheraddr failed\n",
843 dhd_ifname(&dhd->pub, ifidx)));
845 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
852 extern struct net_device *ap_net_dev;
855 static void dhd_op_if(dhd_if_t *ifp)
858 int ret = 0, err = 0;
860 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
864 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
866 switch (ifp->state) {
869 * Delete the existing interface before overwriting it
870 * in case we missed the WLC_E_IF_DEL event.
872 if (ifp->net != NULL) {
873 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
874 "try free & unregister\n",
875 __func__, ifp->net->name));
876 netif_stop_queue(ifp->net);
877 unregister_netdev(ifp->net);
878 free_netdev(ifp->net);
880 /* Allocate etherdev, including space for private structure */
881 ifp->net = alloc_etherdev(sizeof(dhd));
883 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
887 strcpy(ifp->net->name, ifp->name);
888 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
889 err = dhd_net_attach(&dhd->pub, ifp->idx);
891 DHD_ERROR(("%s: dhd_net_attach failed, "
897 /* semaphore that the soft AP CODE
899 extern struct semaphore ap_eth_sema;
901 /* save ptr to wl0.1 netdev for use
903 ap_net_dev = ifp->net;
904 /* signal to the SOFTAP 'sleeper' thread,
908 DHD_TRACE(("\n ==== pid:%x, net_device for "
909 "if:%s created ===\n\n",
910 current->pid, ifp->net->name));
916 if (ifp->net != NULL) {
917 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
919 netif_stop_queue(ifp->net);
920 unregister_netdev(ifp->net);
921 ret = DHD_DEL_IF; /* Make sure the free_netdev()
926 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
933 free_netdev(ifp->net);
935 dhd->iflist[ifp->idx] = NULL;
936 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
938 if (ifp->net == ap_net_dev)
939 ap_net_dev = NULL; /* NULL SOFTAP global
945 static int _dhd_sysioc_thread(void *data)
947 dhd_info_t *dhd = (dhd_info_t *) data;
953 DAEMONIZE("dhd_sysioc");
955 while (down_interruptible(&dhd->sysioc_sem) == 0) {
956 for (i = 0; i < DHD_MAX_IFS; i++) {
957 if (dhd->iflist[i]) {
959 in_ap = (ap_net_dev != NULL);
961 if (dhd->iflist[i]->state)
962 dhd_op_if(dhd->iflist[i]);
964 if (dhd->iflist[i] == NULL) {
965 DHD_TRACE(("\n\n %s: interface %d "
966 "removed!\n", __func__, i));
970 if (in_ap && dhd->set_macaddress) {
971 DHD_TRACE(("attempt to set MAC for %s "
972 "in AP Mode," "blocked. \n",
973 dhd->iflist[i]->net->name));
974 dhd->set_macaddress = FALSE;
978 if (in_ap && dhd->set_multicast) {
979 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
980 dhd->iflist[i]->net->name));
981 dhd->set_multicast = FALSE;
985 if (dhd->set_multicast) {
986 dhd->set_multicast = FALSE;
987 _dhd_set_multicast_list(dhd, i);
989 if (dhd->set_macaddress) {
990 dhd->set_macaddress = FALSE;
991 _dhd_set_mac_address(dhd, i,
997 complete_and_exit(&dhd->sysioc_exited, 0);
1000 static int dhd_set_mac_address(struct net_device *dev, void *addr)
1004 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1005 struct sockaddr *sa = (struct sockaddr *)addr;
1008 ifidx = dhd_net2idx(dhd, dev);
1009 if (ifidx == DHD_BAD_IF)
1012 ASSERT(dhd->sysioc_pid >= 0);
1013 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1014 dhd->set_macaddress = TRUE;
1015 up(&dhd->sysioc_sem);
1020 static void dhd_set_multicast_list(struct net_device *dev)
1022 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1025 ifidx = dhd_net2idx(dhd, dev);
1026 if (ifidx == DHD_BAD_IF)
1029 ASSERT(dhd->sysioc_pid >= 0);
1030 dhd->set_multicast = TRUE;
1031 up(&dhd->sysioc_sem);
1034 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1037 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1039 /* Reject if down */
1040 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1043 /* Update multicast statistic */
1044 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1045 u8 *pktdata = (u8 *) PKTDATA(pktbuf);
1046 struct ether_header *eh = (struct ether_header *)pktdata;
1048 if (ETHER_ISMULTI(eh->ether_dhost))
1049 dhdp->tx_multicast++;
1050 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1051 atomic_inc(&dhd->pend_8021x_cnt);
1054 /* Look into the packet and update the packet priority */
1055 if ((PKTPRIO(pktbuf) == 0))
1056 pktsetprio(pktbuf, FALSE);
1058 /* If the protocol uses a data header, apply it */
1059 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1061 /* Use bus module to send data frame */
1063 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1065 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1066 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1067 #endif /* BCMDBUS */
1072 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1076 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1079 DHD_TRACE(("%s: Enter\n", __func__));
1081 /* Reject if down */
1082 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1083 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1084 __func__, dhd->pub.up, dhd->pub.busstate));
1085 netif_stop_queue(net);
1089 ifidx = dhd_net2idx(dhd, net);
1090 if (ifidx == DHD_BAD_IF) {
1091 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1092 netif_stop_queue(net);
1096 /* Make sure there's enough room for any header */
1097 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1098 struct sk_buff *skb2;
1100 DHD_INFO(("%s: insufficient headroom\n",
1101 dhd_ifname(&dhd->pub, ifidx)));
1102 dhd->pub.tx_realloc++;
1103 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1107 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1108 dhd_ifname(&dhd->pub, ifidx)));
1114 /* Convert to packet */
1115 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1117 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1118 dhd_ifname(&dhd->pub, ifidx)));
1119 dev_kfree_skb_any(skb);
1124 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1128 dhd->pub.dstats.tx_dropped++;
1130 dhd->pub.tx_packets++;
1132 /* Return ok: we always eat the packet */
1136 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1138 struct net_device *net;
1139 dhd_info_t *dhd = dhdp->info;
1141 DHD_TRACE(("%s: Enter\n", __func__));
1143 dhdp->txoff = state;
1144 ASSERT(dhd && dhd->iflist[ifidx]);
1145 net = dhd->iflist[ifidx]->net;
1147 netif_stop_queue(net);
1149 netif_wake_queue(net);
1152 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1154 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1155 struct sk_buff *skb;
1158 void *data, *pnext, *save_pktbuf;
1161 wl_event_msg_t event;
1163 DHD_TRACE(("%s: Enter\n", __func__));
1165 save_pktbuf = pktbuf;
1167 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1169 pnext = PKTNEXT(pktbuf);
1170 PKTSETNEXT(pktbuf, NULL);
1172 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1174 /* Get the protocol, maintain skb around eth_type_trans()
1175 * The main reason for this hack is for the limitation of
1176 * Linux 2.4 where 'eth_type_trans' uses the
1177 * 'net->hard_header_len'
1178 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1179 * coping of the packet coming from the network stack to add
1180 * BDC, Hardware header etc, during network interface
1182 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1184 * for BDC, Hardware header etc. and not just the ETH_HLEN
1189 ifp = dhd->iflist[ifidx];
1191 ifp = dhd->iflist[0];
1194 skb->dev = ifp->net;
1195 skb->protocol = eth_type_trans(skb, skb->dev);
1197 if (skb->pkt_type == PACKET_MULTICAST)
1198 dhd->pub.rx_multicast++;
1203 /* Strip header, count, deliver upward */
1204 skb_pull(skb, ETH_HLEN);
1206 /* Process special event packets and then discard them */
1207 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1208 dhd_wl_host_event(dhd, &ifidx,
1212 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1213 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1214 ifp = dhd->iflist[ifidx];
1217 ifp->net->last_rx = jiffies;
1219 dhdp->dstats.rx_bytes += skb->len;
1220 dhdp->rx_packets++; /* Local count */
1222 if (in_interrupt()) {
1225 /* If the receive is not processed inside an ISR,
1226 * the softirqd must be woken explicitly to service
1227 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1228 * by netif_rx_ni(), but in earlier kernels, we need
1229 * to do it manually.
1236 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1238 /* Linux version has nothing to do */
1242 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1245 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1246 struct ether_header *eh;
1249 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1251 eh = (struct ether_header *)PKTDATA(txp);
1252 type = ntoh16(eh->ether_type);
1254 if (type == ETHER_TYPE_802_1X)
1255 atomic_dec(&dhd->pend_8021x_cnt);
1259 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1261 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1265 DHD_TRACE(("%s: Enter\n", __func__));
1267 ifidx = dhd_net2idx(dhd, net);
1268 if (ifidx == DHD_BAD_IF)
1271 ifp = dhd->iflist[ifidx];
1275 /* Use the protocol to get dongle stats */
1276 dhd_prot_dstats(&dhd->pub);
1279 /* Copy dongle stats to net device stats */
1280 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1281 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1282 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1283 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1284 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1285 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1286 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1287 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1288 ifp->stats.multicast = dhd->pub.dstats.multicast;
1293 static int dhd_watchdog_thread(void *data)
1295 dhd_info_t *dhd = (dhd_info_t *) data;
1296 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1298 /* This thread doesn't need any user-level access,
1299 * so get rid of all our resources
1302 if (dhd_watchdog_prio > 0) {
1303 struct sched_param param;
1304 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1305 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1306 setScheduler(current, SCHED_FIFO, ¶m);
1308 #endif /* DHD_SCHED */
1310 DAEMONIZE("dhd_watchdog");
1312 /* Run until signal received */
1314 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1315 if (dhd->pub.dongle_reset == FALSE) {
1316 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1317 /* Call the bus module watchdog */
1318 dhd_bus_watchdog(&dhd->pub);
1319 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1321 /* Count the tick for reference */
1327 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1328 complete_and_exit(&dhd->watchdog_exited, 0);
1331 static void dhd_watchdog(unsigned long data)
1333 dhd_info_t *dhd = (dhd_info_t *) data;
1335 if (dhd->watchdog_pid >= 0) {
1336 up(&dhd->watchdog_sem);
1338 /* Reschedule the watchdog */
1339 if (dhd->wd_timer_valid) {
1340 mod_timer(&dhd->timer,
1341 jiffies + dhd_watchdog_ms * HZ / 1000);
1346 /* Call the bus module watchdog */
1347 dhd_bus_watchdog(&dhd->pub);
1349 /* Count the tick for reference */
1352 /* Reschedule the watchdog */
1353 if (dhd->wd_timer_valid)
1354 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1357 static int dhd_dpc_thread(void *data)
1359 dhd_info_t *dhd = (dhd_info_t *) data;
1361 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1362 /* This thread doesn't need any user-level access,
1363 * so get rid of all our resources
1366 if (dhd_dpc_prio > 0) {
1367 struct sched_param param;
1368 param.sched_priority =
1370 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1371 setScheduler(current, SCHED_FIFO, ¶m);
1373 #endif /* DHD_SCHED */
1375 DAEMONIZE("dhd_dpc");
1377 /* Run until signal received */
1379 if (down_interruptible(&dhd->dpc_sem) == 0) {
1380 /* Call bus dpc unless it indicated down
1381 (then clean stop) */
1382 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1383 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1384 if (dhd_bus_dpc(dhd->pub.bus)) {
1386 WAKE_LOCK_TIMEOUT(&dhd->pub,
1387 WAKE_LOCK_TMOUT, 25);
1389 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1391 dhd_bus_stop(dhd->pub.bus, TRUE);
1397 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1399 complete_and_exit(&dhd->dpc_exited, 0);
1402 static void dhd_dpc(unsigned long data)
1406 dhd = (dhd_info_t *) data;
1408 /* Call bus dpc unless it indicated down (then clean stop) */
1409 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1410 if (dhd_bus_dpc(dhd->pub.bus))
1411 tasklet_schedule(&dhd->tasklet);
1413 dhd_bus_stop(dhd->pub.bus, TRUE);
1417 void dhd_sched_dpc(dhd_pub_t *dhdp)
1419 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1421 if (dhd->dpc_pid >= 0) {
1426 tasklet_schedule(&dhd->tasklet);
1430 /* Retrieve current toe component enables, which are kept
1431 as a bitmap in toe_ol iovar */
1432 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
1438 memset(&ioc, 0, sizeof(ioc));
1440 ioc.cmd = WLC_GET_VAR;
1442 ioc.len = (uint) sizeof(buf);
1445 strcpy(buf, "toe_ol");
1446 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1448 /* Check for older dongle image that doesn't support toe_ol */
1450 DHD_ERROR(("%s: toe not supported by device\n",
1451 dhd_ifname(&dhd->pub, ifidx)));
1455 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1456 dhd_ifname(&dhd->pub, ifidx), ret));
1460 memcpy(toe_ol, buf, sizeof(uint32));
1464 /* Set current toe component enables in toe_ol iovar,
1465 and set toe global enable iovar */
1466 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
1472 memset(&ioc, 0, sizeof(ioc));
1474 ioc.cmd = WLC_SET_VAR;
1476 ioc.len = (uint) sizeof(buf);
1479 /* Set toe_ol as requested */
1481 strcpy(buf, "toe_ol");
1482 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
1484 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1486 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1487 dhd_ifname(&dhd->pub, ifidx), ret));
1491 /* Enable toe globally only if any components are enabled. */
1493 toe = (toe_ol != 0);
1496 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
1498 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1500 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1501 dhd_ifname(&dhd->pub, ifidx), ret));
1509 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1510 struct ethtool_drvinfo *info)
1512 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1514 sprintf(info->driver, "wl");
1515 sprintf(info->version, "%lu", dhd->pub.drv_version);
1518 struct ethtool_ops dhd_ethtool_ops = {
1519 .get_drvinfo = dhd_ethtool_get_drvinfo
1522 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1524 struct ethtool_drvinfo info;
1525 char drvname[sizeof(info.driver)];
1528 struct ethtool_value edata;
1529 uint32 toe_cmpnt, csum_dir;
1533 DHD_TRACE(("%s: Enter\n", __func__));
1535 /* all ethtool calls start with a cmd word */
1536 if (copy_from_user(&cmd, uaddr, sizeof(uint32)))
1540 case ETHTOOL_GDRVINFO:
1541 /* Copy out any request driver name */
1542 if (copy_from_user(&info, uaddr, sizeof(info)))
1544 strncpy(drvname, info.driver, sizeof(info.driver));
1545 drvname[sizeof(info.driver) - 1] = '\0';
1547 /* clear struct for return */
1548 memset(&info, 0, sizeof(info));
1551 /* if dhd requested, identify ourselves */
1552 if (strcmp(drvname, "?dhd") == 0) {
1553 sprintf(info.driver, "dhd");
1554 strcpy(info.version, EPI_VERSION_STR);
1557 /* otherwise, require dongle to be up */
1558 else if (!dhd->pub.up) {
1559 DHD_ERROR(("%s: dongle is not up\n", __func__));
1563 /* finally, report dongle driver type */
1564 else if (dhd->pub.iswl)
1565 sprintf(info.driver, "wl");
1567 sprintf(info.driver, "xx");
1569 sprintf(info.version, "%lu", dhd->pub.drv_version);
1570 if (copy_to_user(uaddr, &info, sizeof(info)))
1572 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1573 (int)sizeof(drvname), drvname, info.driver));
1577 /* Get toe offload components from dongle */
1578 case ETHTOOL_GRXCSUM:
1579 case ETHTOOL_GTXCSUM:
1580 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1585 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1588 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1590 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1594 /* Set toe offload components in dongle */
1595 case ETHTOOL_SRXCSUM:
1596 case ETHTOOL_STXCSUM:
1597 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1600 /* Read the current settings, update and write back */
1601 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1606 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1608 if (edata.data != 0)
1609 toe_cmpnt |= csum_dir;
1611 toe_cmpnt &= ~csum_dir;
1613 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1617 /* If setting TX checksum mode, tell Linux the new mode */
1618 if (cmd == ETHTOOL_STXCSUM) {
1620 dhd->iflist[0]->net->features |=
1623 dhd->iflist[0]->net->features &=
1637 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1639 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1646 bool is_set_key_cmd;
1648 ifidx = dhd_net2idx(dhd, net);
1649 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1651 if (ifidx == DHD_BAD_IF)
1654 #if defined(CONFIG_WIRELESS_EXT)
1655 /* linux wireless extensions */
1656 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1657 /* may recurse, do NOT lock */
1658 return wl_iw_ioctl(net, ifr, cmd);
1660 #endif /* defined(CONFIG_WIRELESS_EXT) */
1662 if (cmd == SIOCETHTOOL)
1663 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1665 if (cmd != SIOCDEVPRIVATE)
1668 memset(&ioc, 0, sizeof(ioc));
1670 /* Copy the ioc control structure part of ioctl request */
1671 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1672 bcmerror = -BCME_BADADDR;
1676 /* Copy out any buffer passed */
1678 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
1679 /* optimization for direct ioctl calls from kernel */
1681 if (segment_eq(get_fs(), KERNEL_DS)) {
1686 buf = (char *)MALLOC(dhd->pub.osh, buflen);
1688 bcmerror = -BCME_NOMEM;
1691 if (copy_from_user(buf, ioc.buf, buflen)) {
1692 bcmerror = -BCME_BADADDR;
1698 /* To differentiate between wl and dhd read 4 more byes */
1699 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1700 sizeof(uint)) != 0)) {
1701 bcmerror = -BCME_BADADDR;
1705 if (!capable(CAP_NET_ADMIN)) {
1706 bcmerror = -BCME_EPERM;
1710 /* check for local dhd ioctl and handle it */
1711 if (driver == DHD_IOCTL_MAGIC) {
1712 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1714 dhd->pub.bcmerror = bcmerror;
1718 /* send to dongle (must be up, and wl) */
1719 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1720 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1721 bcmerror = BCME_DONGLE_DOWN;
1725 if (!dhd->pub.iswl) {
1726 bcmerror = BCME_DONGLE_DOWN;
1730 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1731 * prevent M4 encryption.
1733 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1734 ((ioc.cmd == WLC_SET_VAR) &&
1735 !(strncmp("wsec_key", ioc.buf, 9))) ||
1736 ((ioc.cmd == WLC_SET_VAR) &&
1737 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1739 dhd_wait_pend8021x(net);
1741 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1742 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1745 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1747 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1748 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1750 if (!bcmerror && buf && ioc.buf) {
1751 if (copy_to_user(ioc.buf, buf, buflen))
1756 MFREE(dhd->pub.osh, buf, buflen);
1758 return OSL_ERROR(bcmerror);
1761 static int dhd_stop(struct net_device *net)
1763 #if !defined(IGNORE_ETH0_DOWN)
1764 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1766 DHD_TRACE(("%s: Enter\n", __func__));
1767 #ifdef CONFIG_CFG80211
1768 if (IS_CFG80211_FAVORITE()) {
1772 if (dhd->pub.up == 0)
1775 /* Set state and stop OS transmissions */
1777 netif_stop_queue(net);
1779 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1781 #endif /* !defined(IGNORE_ETH0_DOWN) */
1783 OLD_MOD_DEC_USE_COUNT;
1787 static int dhd_open(struct net_device *net)
1789 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1793 int ifidx = dhd_net2idx(dhd, net);
1796 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1798 if (ifidx == 0) { /* do it only for primary eth0 */
1800 /* try to bring up bus */
1801 ret = dhd_bus_start(&dhd->pub);
1803 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1806 atomic_set(&dhd->pend_8021x_cnt, 0);
1808 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1811 /* Get current TOE mode from dongle */
1812 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1813 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1814 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1816 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1819 /* Allow transmit calls */
1820 netif_start_queue(net);
1822 #ifdef CONFIG_CFG80211
1823 if (IS_CFG80211_FAVORITE()) {
1824 if (unlikely(wl_cfg80211_up())) {
1825 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1832 OLD_MOD_INC_USE_COUNT;
1836 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1838 return osl_attach(pdev, bustype, TRUE);
1841 void dhd_osl_detach(osl_t *osh)
1843 if (MALLOCED(osh)) {
1844 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1851 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1852 u8 *mac_addr, uint32 flags, u8 bssidx)
1856 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1858 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1860 ifp = dhd->iflist[ifidx];
1861 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1862 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1866 memset(ifp, 0, sizeof(dhd_if_t));
1868 dhd->iflist[ifidx] = ifp;
1869 strncpy(ifp->name, name, IFNAMSIZ);
1870 ifp->name[IFNAMSIZ] = '\0';
1871 if (mac_addr != NULL)
1872 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1874 if (handle == NULL) {
1875 ifp->state = WLC_E_IF_ADD;
1877 ASSERT(dhd->sysioc_pid >= 0);
1878 up(&dhd->sysioc_sem);
1880 ifp->net = (struct net_device *)handle;
1885 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1889 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1891 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1892 ifp = dhd->iflist[ifidx];
1894 DHD_ERROR(("%s: Null interface\n", __func__));
1898 ifp->state = WLC_E_IF_DEL;
1900 ASSERT(dhd->sysioc_pid >= 0);
1901 up(&dhd->sysioc_sem);
1904 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1906 dhd_info_t *dhd = NULL;
1907 struct net_device *net;
1909 DHD_TRACE(("%s: Enter\n", __func__));
1910 /* updates firmware nvram path if it was provided as module
1912 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1913 strcpy(fw_path, firmware_path);
1914 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1915 strcpy(nv_path, nvram_path);
1917 /* Allocate etherdev, including space for private structure */
1918 net = alloc_etherdev(sizeof(dhd));
1920 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1924 /* Allocate primary dhd_info */
1925 dhd = MALLOC(osh, sizeof(dhd_info_t));
1927 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1931 memset(dhd, 0, sizeof(dhd_info_t));
1934 * Save the dhd_info into the priv
1936 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1939 /* Set network interface name if it was provided as module parameter */
1940 if (iface_name[0]) {
1943 strncpy(net->name, iface_name, IFNAMSIZ);
1944 net->name[IFNAMSIZ - 1] = 0;
1945 len = strlen(net->name);
1946 ch = net->name[len - 1];
1947 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1948 strcat(net->name, "%d");
1951 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1955 net->netdev_ops = NULL;
1956 init_MUTEX(&dhd->proto_sem);
1957 /* Initialize other structure content */
1958 init_waitqueue_head(&dhd->ioctl_resp_wait);
1959 init_waitqueue_head(&dhd->ctrl_wait);
1961 /* Initialize the spinlocks */
1962 spin_lock_init(&dhd->sdlock);
1963 spin_lock_init(&dhd->txqlock);
1965 /* Link to info module */
1966 dhd->pub.info = dhd;
1968 /* Link to bus module */
1970 dhd->pub.hdrlen = bus_hdrlen;
1972 /* Attach and link in the protocol */
1973 if (dhd_prot_attach(&dhd->pub) != 0) {
1974 DHD_ERROR(("dhd_prot_attach failed\n"));
1977 #if defined(CONFIG_WIRELESS_EXT)
1978 /* Attach and link in the iw */
1979 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1980 DHD_ERROR(("wl_iw_attach failed\n"));
1983 #endif /* defined(CONFIG_WIRELESS_EXT) */
1985 #ifdef CONFIG_CFG80211
1986 /* Attach and link in the cfg80211 */
1987 if (IS_CFG80211_FAVORITE()) {
1988 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1989 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1993 strcpy(fw_path, wl_cfg80211_get_fwname());
1994 strcpy(nv_path, wl_cfg80211_get_nvramname());
1996 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
2000 /* Set up the watchdog timer */
2001 init_timer(&dhd->timer);
2002 dhd->timer.data = (unsigned long) dhd;
2003 dhd->timer.function = dhd_watchdog;
2005 /* Initialize thread based operation and lock */
2006 init_MUTEX(&dhd->sdsem);
2007 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
2008 dhd->threads_only = TRUE;
2010 dhd->threads_only = FALSE;
2012 if (dhd_dpc_prio >= 0) {
2013 /* Initialize watchdog thread */
2014 sema_init(&dhd->watchdog_sem, 0);
2015 init_completion(&dhd->watchdog_exited);
2016 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2018 dhd->watchdog_pid = -1;
2021 /* Set up the bottom half handler */
2022 if (dhd_dpc_prio >= 0) {
2023 /* Initialize DPC thread */
2024 sema_init(&dhd->dpc_sem, 0);
2025 init_completion(&dhd->dpc_exited);
2026 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2028 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2033 sema_init(&dhd->sysioc_sem, 0);
2034 init_completion(&dhd->sysioc_exited);
2035 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2037 dhd->sysioc_pid = -1;
2041 * Save the dhd_info into the priv
2043 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2045 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2048 #if defined(CONFIG_PM_SLEEP)
2049 register_pm_notifier(&dhd_sleep_pm_notifier);
2050 #endif /* defined(CONFIG_PM_SLEEP) */
2051 /* && defined(DHD_GPL) */
2052 /* Init lock suspend to prevent kernel going to suspend */
2053 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2054 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2055 "dhd_wake_lock_link_dw_event");
2056 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2057 "dhd_wake_lock_link_pno_find_event");
2058 #ifdef CONFIG_HAS_EARLYSUSPEND
2059 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2060 dhd->early_suspend.suspend = dhd_early_suspend;
2061 dhd->early_suspend.resume = dhd_late_resume;
2062 register_early_suspend(&dhd->early_suspend);
2071 dhd_detach(&dhd->pub);
2076 int dhd_bus_start(dhd_pub_t *dhdp)
2079 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2080 #ifdef EMBEDDED_PLATFORM
2081 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2083 #endif /* EMBEDDED_PLATFORM */
2087 DHD_TRACE(("%s:\n", __func__));
2089 /* try to download image and nvram to the dongle */
2090 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2091 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2092 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2093 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2094 fw_path, nv_path))) {
2095 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2096 "firmware = %s nvram = %s\n",
2097 __func__, fw_path, nv_path));
2098 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2099 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2103 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2104 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2107 /* Start the watchdog timer */
2108 dhd->pub.tickcnt = 0;
2109 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2111 /* Bring up the bus */
2112 ret = dhd_bus_init(&dhd->pub, TRUE);
2114 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2117 #if defined(OOB_INTR_ONLY)
2118 /* Host registration for OOB interrupt */
2119 if (bcmsdh_register_oob_intr(dhdp)) {
2120 del_timer_sync(&dhd->timer);
2121 dhd->wd_timer_valid = FALSE;
2122 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2126 /* Enable oob at firmware */
2127 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2128 #endif /* defined(OOB_INTR_ONLY) */
2130 /* If bus is not ready, can't come up */
2131 if (dhd->pub.busstate != DHD_BUS_DATA) {
2132 del_timer_sync(&dhd->timer);
2133 dhd->wd_timer_valid = FALSE;
2134 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2137 #ifdef EMBEDDED_PLATFORM
2138 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2140 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2141 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2143 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2144 setbit(dhdp->eventmask, WLC_E_PRUNE);
2145 setbit(dhdp->eventmask, WLC_E_AUTH);
2146 setbit(dhdp->eventmask, WLC_E_REASSOC);
2147 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2148 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2149 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2150 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2151 setbit(dhdp->eventmask, WLC_E_JOIN);
2152 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2153 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2154 setbit(dhdp->eventmask, WLC_E_LINK);
2155 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2156 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2157 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2158 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2159 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2160 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2162 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2163 #endif /* PNO_SUPPORT */
2165 /* enable dongle roaming event */
2167 dhdp->pktfilter_count = 1;
2168 /* Setup filter to allow only unicast */
2169 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2170 #endif /* EMBEDDED_PLATFORM */
2172 /* Bus is ready, do any protocol initialization */
2173 ret = dhd_prot_init(&dhd->pub);
2181 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2184 char buf[strlen(name) + 1 + cmd_len];
2185 int len = sizeof(buf);
2189 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2191 memset(&ioc, 0, sizeof(ioc));
2193 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2198 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2199 if (!set && ret >= 0)
2200 memcpy(cmd_buf, buf, cmd_len);
2205 static struct net_device_ops dhd_ops_pri = {
2206 .ndo_open = dhd_open,
2207 .ndo_stop = dhd_stop,
2208 .ndo_get_stats = dhd_get_stats,
2209 .ndo_do_ioctl = dhd_ioctl_entry,
2210 .ndo_start_xmit = dhd_start_xmit,
2211 .ndo_set_mac_address = dhd_set_mac_address,
2212 .ndo_set_multicast_list = dhd_set_multicast_list
2215 static struct net_device_ops dhd_ops_virt = {
2216 .ndo_get_stats = dhd_get_stats,
2217 .ndo_do_ioctl = dhd_ioctl_entry,
2218 .ndo_start_xmit = dhd_start_xmit,
2219 .ndo_set_mac_address = dhd_set_mac_address,
2220 .ndo_set_multicast_list = dhd_set_multicast_list
2223 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2225 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2226 struct net_device *net;
2227 u8 temp_addr[ETHER_ADDR_LEN] = {
2228 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2230 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2232 ASSERT(dhd && dhd->iflist[ifidx]);
2234 net = dhd->iflist[ifidx]->net;
2237 ASSERT(!net->netdev_ops);
2238 net->netdev_ops = &dhd_ops_virt;
2240 net->netdev_ops = &dhd_ops_pri;
2243 * We have to use the primary MAC for virtual interfaces
2246 /* for virtual interfaces use the primary MAC */
2247 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2252 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2253 /* ACCESSPOINT INTERFACE CASE */
2254 temp_addr[0] |= 0X02; /* set bit 2 ,
2255 - Locally Administered address */
2258 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2259 net->ethtool_ops = &dhd_ethtool_ops;
2261 #if defined(CONFIG_WIRELESS_EXT)
2262 #if defined(CONFIG_CFG80211)
2263 if (!IS_CFG80211_FAVORITE()) {
2265 #if WIRELESS_EXT < 19
2266 net->get_wireless_stats = dhd_get_wireless_stats;
2267 #endif /* WIRELESS_EXT < 19 */
2268 #if WIRELESS_EXT > 12
2269 net->wireless_handlers =
2270 (struct iw_handler_def *)&wl_iw_handler_def;
2271 #endif /* WIRELESS_EXT > 12 */
2272 #if defined(CONFIG_CFG80211)
2275 #endif /* defined(CONFIG_WIRELESS_EXT) */
2277 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2279 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2281 if (register_netdev(net) != 0) {
2282 DHD_ERROR(("%s: couldn't register the net device\n",
2287 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2292 net->netdev_ops = NULL;
2296 void dhd_bus_detach(dhd_pub_t *dhdp)
2300 DHD_TRACE(("%s: Enter\n", __func__));
2303 dhd = (dhd_info_t *) dhdp->info;
2305 /* Stop the protocol module */
2306 dhd_prot_stop(&dhd->pub);
2308 /* Stop the bus module */
2309 dhd_bus_stop(dhd->pub.bus, TRUE);
2310 #if defined(OOB_INTR_ONLY)
2311 bcmsdh_unregister_oob_intr();
2312 #endif /* defined(OOB_INTR_ONLY) */
2314 /* Clear the watchdog timer */
2315 del_timer_sync(&dhd->timer);
2316 dhd->wd_timer_valid = FALSE;
2321 void dhd_detach(dhd_pub_t *dhdp)
2325 DHD_TRACE(("%s: Enter\n", __func__));
2328 dhd = (dhd_info_t *) dhdp->info;
2333 #if defined(CONFIG_HAS_EARLYSUSPEND)
2334 if (dhd->early_suspend.suspend)
2335 unregister_early_suspend(&dhd->early_suspend);
2336 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2338 for (i = 1; i < DHD_MAX_IFS; i++)
2342 ifp = dhd->iflist[0];
2344 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2346 unregister_netdev(ifp->net);
2349 if (dhd->watchdog_pid >= 0) {
2350 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2351 wait_for_completion(&dhd->watchdog_exited);
2354 if (dhd->dpc_pid >= 0) {
2355 KILL_PROC(dhd->dpc_pid, SIGTERM);
2356 wait_for_completion(&dhd->dpc_exited);
2358 tasklet_kill(&dhd->tasklet);
2360 if (dhd->sysioc_pid >= 0) {
2361 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2362 wait_for_completion(&dhd->sysioc_exited);
2365 dhd_bus_detach(dhdp);
2368 dhd_prot_detach(dhdp);
2370 #if defined(CONFIG_WIRELESS_EXT)
2372 #endif /* (CONFIG_WIRELESS_EXT) */
2374 #ifdef CONFIG_CFG80211
2375 if (IS_CFG80211_FAVORITE())
2376 wl_cfg80211_detach();
2377 #endif /* CONFIG_CFG80211 */
2379 #if defined(CONFIG_PM_SLEEP)
2380 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2381 #endif /* defined(CONFIG_PM_SLEEP) */
2382 /* && defined(DHD_GPL) */
2383 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2384 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2385 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2386 free_netdev(ifp->net);
2387 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2388 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2393 static void __exit dhd_module_cleanup(void)
2395 DHD_TRACE(("%s: Enter\n", __func__));
2397 dhd_bus_unregister();
2398 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2401 /* Call customer gpio to turn off power with WL_REG_ON signal */
2402 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2405 static int __init dhd_module_init(void)
2409 DHD_TRACE(("%s: Enter\n", __func__));
2411 /* Sanity check on the module parameters */
2413 /* Both watchdog and DPC as tasklets are ok */
2414 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2417 /* If both watchdog and DPC are threads, TX must be deferred */
2418 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2422 DHD_ERROR(("Invalid module parameters.\n"));
2425 /* Call customer gpio to turn on power with WL_REG_ON signal */
2426 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2428 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2429 sema_init(&wifi_control_sem, 0);
2431 error = wifi_add_dev();
2433 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2437 /* Waiting callback after platform_driver_register is done or
2439 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2440 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2446 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2448 error = dhd_bus_register();
2451 printf("\n%s\n", dhd_version);
2453 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2459 /* turn off power and exit */
2460 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2464 module_init(dhd_module_init);
2465 module_exit(dhd_module_cleanup);
2468 * OS specific functions required to implement DHD driver in OS independent way
2470 int dhd_os_proto_block(dhd_pub_t *pub)
2472 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2475 down(&dhd->proto_sem);
2481 int dhd_os_proto_unblock(dhd_pub_t *pub)
2483 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2486 up(&dhd->proto_sem);
2493 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2495 return (unsigned int)dhd_ioctl_timeout_msec;
2498 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2500 dhd_ioctl_timeout_msec = (int)timeout_msec;
2503 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2505 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2506 DECLARE_WAITQUEUE(wait, current);
2507 int timeout = dhd_ioctl_timeout_msec;
2509 /* Convert timeout in millsecond to jiffies */
2510 timeout = timeout * HZ / 1000;
2512 /* Wait until control frame is available */
2513 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2514 set_current_state(TASK_INTERRUPTIBLE);
2516 while (!(*condition) && (!signal_pending(current) && timeout))
2517 timeout = schedule_timeout(timeout);
2519 if (signal_pending(current))
2522 set_current_state(TASK_RUNNING);
2523 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2528 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2530 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2532 if (waitqueue_active(&dhd->ioctl_resp_wait))
2533 wake_up_interruptible(&dhd->ioctl_resp_wait);
2538 void dhd_os_wd_timer(void *bus, uint wdtick)
2540 dhd_pub_t *pub = bus;
2541 static uint save_dhd_watchdog_ms = 0;
2542 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2544 /* don't start the wd until fw is loaded */
2545 if (pub->busstate == DHD_BUS_DOWN)
2548 /* Totally stop the timer */
2549 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2550 del_timer_sync(&dhd->timer);
2551 dhd->wd_timer_valid = FALSE;
2552 save_dhd_watchdog_ms = wdtick;
2557 dhd_watchdog_ms = (uint) wdtick;
2559 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2561 if (dhd->wd_timer_valid == TRUE)
2562 /* Stop timer and restart at new value */
2563 del_timer_sync(&dhd->timer);
2565 /* Create timer again when watchdog period is
2566 dynamically changed or in the first instance
2568 dhd->timer.expires =
2569 jiffies + dhd_watchdog_ms * HZ / 1000;
2570 add_timer(&dhd->timer);
2573 /* Re arm the timer, at last watchdog period */
2574 mod_timer(&dhd->timer,
2575 jiffies + dhd_watchdog_ms * HZ / 1000);
2578 dhd->wd_timer_valid = TRUE;
2579 save_dhd_watchdog_ms = wdtick;
2583 void *dhd_os_open_image(char *filename)
2587 #ifdef CONFIG_CFG80211
2588 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2589 return wl_cfg80211_request_fw(filename);
2592 fp = filp_open(filename, O_RDONLY, 0);
2594 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2596 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2605 int dhd_os_get_image_block(char *buf, int len, void *image)
2607 struct file *fp = (struct file *)image;
2610 #ifdef CONFIG_CFG80211
2611 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2612 return wl_cfg80211_read_fw(buf, len);
2618 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2625 void dhd_os_close_image(void *image)
2627 #ifdef CONFIG_CFG80211
2628 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2629 return wl_cfg80211_release_fw();
2632 filp_close((struct file *)image, NULL);
2635 void dhd_os_sdlock(dhd_pub_t *pub)
2639 dhd = (dhd_info_t *) (pub->info);
2641 if (dhd->threads_only)
2644 spin_lock_bh(&dhd->sdlock);
2647 void dhd_os_sdunlock(dhd_pub_t *pub)
2651 dhd = (dhd_info_t *) (pub->info);
2653 if (dhd->threads_only)
2656 spin_unlock_bh(&dhd->sdlock);
2659 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2663 dhd = (dhd_info_t *) (pub->info);
2664 spin_lock_bh(&dhd->txqlock);
2667 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2671 dhd = (dhd_info_t *) (pub->info);
2672 spin_unlock_bh(&dhd->txqlock);
2675 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2679 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2683 void dhd_os_sdtxlock(dhd_pub_t *pub)
2688 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2690 dhd_os_sdunlock(pub);
2693 #ifdef DHD_USE_STATIC_BUF
2694 void *dhd_os_prealloc(int section, unsigned long size)
2696 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2697 void *alloc_ptr = NULL;
2698 if (wifi_control_data && wifi_control_data->mem_prealloc) {
2699 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2701 DHD_INFO(("success alloc section %d\n", section));
2702 bzero(alloc_ptr, size);
2707 DHD_ERROR(("can't alloc section %d\n", section));
2710 return MALLOC(0, size);
2711 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2713 #endif /* DHD_USE_STATIC_BUF */
2714 #if defined(CONFIG_WIRELESS_EXT)
2715 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2718 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2720 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2723 return &dhd->iw.wstats;
2727 #endif /* defined(CONFIG_WIRELESS_EXT) */
2730 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2731 wl_event_msg_t *event, void **data)
2735 ASSERT(dhd != NULL);
2737 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2738 if (bcmerror != BCME_OK)
2741 #if defined(CONFIG_WIRELESS_EXT)
2742 #if defined(CONFIG_CFG80211)
2743 if (!IS_CFG80211_FAVORITE()) {
2745 if ((dhd->iflist[*ifidx] == NULL)
2746 || (dhd->iflist[*ifidx]->net == NULL)) {
2747 DHD_ERROR(("%s Exit null pointer\n", __func__));
2751 if (dhd->iflist[*ifidx]->net)
2752 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2753 #if defined(CONFIG_CFG80211)
2756 #endif /* defined(CONFIG_WIRELESS_EXT) */
2758 #ifdef CONFIG_CFG80211
2759 if (IS_CFG80211_FAVORITE()) {
2760 ASSERT(dhd->iflist[*ifidx] != NULL);
2761 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2762 if (dhd->iflist[*ifidx]->net)
2763 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2771 /* send up locally generated event */
2772 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2774 switch (ntoh32(event->event_type)) {
2780 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2782 struct dhd_info *dhdinfo = dhd->info;
2783 dhd_os_sdunlock(dhd);
2784 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2785 (*lockvar == FALSE), HZ * 2);
2790 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2792 struct dhd_info *dhdinfo = dhd->info;
2793 if (waitqueue_active(&dhdinfo->ctrl_wait))
2794 wake_up_interruptible(&dhdinfo->ctrl_wait);
2798 int dhd_dev_reset(struct net_device *dev, u8 flag)
2800 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2802 /* Turning off watchdog */
2804 dhd_os_wd_timer(&dhd->pub, 0);
2806 dhd_bus_devreset(&dhd->pub, flag);
2808 /* Turning on watchdog back */
2810 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2811 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2816 int net_os_set_suspend_disable(struct net_device *dev, int val)
2818 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2822 ret = dhd->pub.suspend_disable_flag;
2823 dhd->pub.suspend_disable_flag = val;
2828 int net_os_set_suspend(struct net_device *dev, int val)
2831 #if defined(CONFIG_HAS_EARLYSUSPEND)
2832 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2835 dhd_os_proto_block(&dhd->pub);
2836 ret = dhd_set_suspend(val, &dhd->pub);
2837 dhd_os_proto_unblock(&dhd->pub);
2839 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2843 int net_os_set_dtim_skip(struct net_device *dev, int val)
2845 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2848 dhd->pub.dtim_skip = val;
2853 int net_os_set_packet_filter(struct net_device *dev, int val)
2855 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2858 /* Packet filtering is set only if we still in early-suspend and
2859 * we need either to turn it ON or turn it OFF
2860 * We can always turn it OFF in case of early-suspend, but we turn it
2861 * back ON only if suspend_disable_flag was not set
2863 if (dhd && dhd->pub.up) {
2864 dhd_os_proto_block(&dhd->pub);
2865 if (dhd->pub.in_suspend) {
2866 if (!val || (val && !dhd->pub.suspend_disable_flag))
2867 dhd_set_packet_filter(val, &dhd->pub);
2869 dhd_os_proto_unblock(&dhd->pub);
2874 void dhd_dev_init_ioctl(struct net_device *dev)
2876 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2878 dhd_preinit_ioctls(&dhd->pub);
2882 /* Linux wrapper to call common dhd_pno_clean */
2883 int dhd_dev_pno_reset(struct net_device *dev)
2885 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2887 return dhd_pno_clean(&dhd->pub);
2890 /* Linux wrapper to call common dhd_pno_enable */
2891 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2893 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2895 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2898 /* Linux wrapper to call common dhd_pno_set */
2900 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2901 unsigned char scan_fr)
2903 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2905 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2908 /* Linux wrapper to get pno status */
2909 int dhd_dev_get_pno_status(struct net_device *dev)
2911 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2913 return dhd_pno_get_status(&dhd->pub);
2916 #endif /* PNO_SUPPORT */
2918 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2920 return atomic_read(&dhd->pend_8021x_cnt);
2923 #define MAX_WAIT_FOR_8021X_TX 10
2925 int dhd_wait_pend8021x(struct net_device *dev)
2927 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2928 int timeout = 10 * HZ / 1000;
2929 int ntimes = MAX_WAIT_FOR_8021X_TX;
2930 int pend = dhd_get_pend_8021x_cnt(dhd);
2932 while (ntimes && pend) {
2934 set_current_state(TASK_INTERRUPTIBLE);
2935 schedule_timeout(timeout);
2936 set_current_state(TASK_RUNNING);
2939 pend = dhd_get_pend_8021x_cnt(dhd);
2945 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2949 mm_segment_t old_fs;
2952 /* change to KERNEL_DS address limit */
2956 /* open file to write */
2957 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2959 printf("%s: open file error\n", __func__);
2964 /* Write buf to file */
2965 fp->f_op->write(fp, buf, size, &pos);
2968 /* free buf before return */
2969 MFREE(dhd->osh, buf, size);
2970 /* close file before return */
2972 filp_close(fp, current->files);
2973 /* restore previous address limit */
2978 #endif /* DHD_DEBUG */