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 #include <wl_cfg80211.h>
50 #define EPI_VERSION_STR "4.218.248.5"
52 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
53 #include <linux/wifi_tiwlan.h>
55 struct semaphore wifi_control_sem;
57 struct dhd_bus *g_bus;
59 static struct wifi_platform_data *wifi_control_data;
60 static struct resource *wifi_irqres;
62 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
65 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
66 return (int)wifi_irqres->start;
68 #ifdef CUSTOM_OOB_GPIO_NUM
69 return CUSTOM_OOB_GPIO_NUM;
75 int wifi_set_carddetect(int on)
77 printk(KERN_ERR "%s = %d\n", __func__, on);
78 if (wifi_control_data && wifi_control_data->set_carddetect)
79 wifi_control_data->set_carddetect(on);
83 int wifi_set_power(int on, unsigned long msec)
85 printk(KERN_ERR "%s = %d\n", __func__, on);
86 if (wifi_control_data && wifi_control_data->set_power)
87 wifi_control_data->set_power(on);
93 int wifi_set_reset(int on, unsigned long msec)
95 printk(KERN_ERR "%s = %d\n", __func__, on);
96 if (wifi_control_data && wifi_control_data->set_reset)
97 wifi_control_data->set_reset(on);
103 static int wifi_probe(struct platform_device *pdev)
105 struct wifi_platform_data *wifi_ctrl =
106 (struct wifi_platform_data *)(pdev->dev.platform_data);
108 printk(KERN_ERR "## %s\n", __func__);
110 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
112 wifi_control_data = wifi_ctrl;
114 wifi_set_power(1, 0); /* Power On */
115 wifi_set_carddetect(1); /* CardDetect (0->1) */
117 up(&wifi_control_sem);
121 static int wifi_remove(struct platform_device *pdev)
123 struct wifi_platform_data *wifi_ctrl =
124 (struct wifi_platform_data *)(pdev->dev.platform_data);
126 printk(KERN_ERR "## %s\n", __func__);
127 wifi_control_data = wifi_ctrl;
129 wifi_set_carddetect(0); /* CardDetect (1->0) */
130 wifi_set_power(0, 0); /* Power Off */
132 up(&wifi_control_sem);
136 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
138 DHD_TRACE(("##> %s\n", __func__));
142 static int wifi_resume(struct platform_device *pdev)
144 DHD_TRACE(("##> %s\n", __func__));
148 static struct platform_driver wifi_device = {
150 .remove = wifi_remove,
151 .suspend = wifi_suspend,
152 .resume = wifi_resume,
154 .name = "bcm4329_wlan",
158 int wifi_add_dev(void)
160 DHD_TRACE(("## Calling platform_driver_register\n"));
161 return platform_driver_register(&wifi_device);
164 void wifi_del_dev(void)
166 DHD_TRACE(("## Unregister platform_driver_register\n"));
167 platform_driver_unregister(&wifi_device);
169 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
171 #if defined(CONFIG_PM_SLEEP)
172 #include <linux/suspend.h>
173 volatile bool dhd_mmc_suspend = FALSE;
174 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
175 #endif /* defined(CONFIG_PM_SLEEP) */
177 #if defined(OOB_INTR_ONLY)
178 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
179 #endif /* defined(OOB_INTR_ONLY) */
181 MODULE_AUTHOR("Broadcom Corporation");
182 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
183 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
184 MODULE_LICENSE("Dual BSD/GPL");
186 #define DRV_MODULE_NAME "brcmfmac"
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]; /* 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 */
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;
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) \
341 allow_signal(SIGKILL); \
342 allow_signal(SIGTERM); \
345 #define BLOCKABLE() (!in_atomic())
347 /* The following are specific to the SDIO dongle */
349 /* IOCTL response timeout */
350 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
352 /* Idle timeout for backplane clock */
353 int dhd_idletime = DHD_IDLETIME_TICKS;
354 module_param(dhd_idletime, int, 0);
357 uint dhd_poll = FALSE;
358 module_param(dhd_poll, uint, 0);
361 uint dhd_cfg80211 = TRUE;
362 module_param(dhd_cfg80211, uint, 0);
365 uint dhd_intr = TRUE;
366 module_param(dhd_intr, uint, 0);
368 /* SDIO Drive Strength (in milliamps) */
369 uint dhd_sdiod_drive_strength = 6;
370 module_param(dhd_sdiod_drive_strength, uint, 0);
373 extern uint dhd_txbound;
374 extern uint dhd_rxbound;
375 module_param(dhd_txbound, uint, 0);
376 module_param(dhd_rxbound, uint, 0);
378 /* Deferred transmits */
379 extern uint dhd_deferred_tx;
380 module_param(dhd_deferred_tx, uint, 0);
383 /* Echo packet generator (pkts/s) */
385 module_param(dhd_pktgen, uint, 0);
387 /* Echo packet len (0 => sawtooth, max 2040) */
389 module_param(dhd_pktgen_len, uint, 0);
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)
397 /* Version string to report */
399 #define DHD_COMPILED "\nCompiled in " SRCBASE
404 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
406 "\nCompiled in " " on " __DATE__ " at " __TIME__
410 #if defined(CONFIG_WIRELESS_EXT)
411 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
412 #endif /* defined(CONFIG_WIRELESS_EXT) */
414 static void dhd_dpc(unsigned long data);
416 extern int dhd_wait_pend8021x(struct net_device *dev);
420 #error TOE requires BDC
422 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
423 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
426 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
427 wl_event_msg_t *event_ptr, void **data_ptr);
429 #if defined(CONFIG_PM_SLEEP)
430 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
431 unsigned long action, void *ignored)
434 case PM_HIBERNATION_PREPARE:
435 case PM_SUSPEND_PREPARE:
436 dhd_mmc_suspend = TRUE;
438 case PM_POST_HIBERNATION:
439 case PM_POST_SUSPEND:
440 dhd_mmc_suspend = FALSE;
446 static struct notifier_block dhd_sleep_pm_notifier = {
447 .notifier_call = dhd_sleep_pm_callback,
451 extern int register_pm_notifier(struct notifier_block *nb);
452 extern int unregister_pm_notifier(struct notifier_block *nb);
453 #endif /* defined(CONFIG_PM_SLEEP) */
454 /* && defined(DHD_GPL) */
455 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
457 #ifdef PKT_FILTER_SUPPORT
458 DHD_TRACE(("%s: %d\n", __func__, value));
459 /* 1 - Enable packet filter, only allow unicast packet to send up */
460 /* 0 - Disable packet filter */
461 if (dhd_pkt_filter_enable) {
464 for (i = 0; i < dhd->pktfilter_count; i++) {
465 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
466 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
467 value, dhd_master_mode);
473 #if defined(CONFIG_HAS_EARLYSUSPEND)
474 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
476 int power_mode = PM_MAX;
477 /* wl_pkt_filter_enable_t enable_parm; */
482 #endif /* CUSTOMER_HW2 */
484 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
485 __func__, value, dhd->in_suspend));
487 if (dhd && dhd->up) {
488 if (value && dhd->in_suspend) {
490 /* Kernel suspended */
491 DHD_TRACE(("%s: force extra Suspend setting\n",
494 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
498 /* Enable packet filter, only allow unicast
500 dhd_set_packet_filter(1, dhd);
502 /* if dtim skip setup as default force it
503 * to wake each thrid dtim
504 * for better power saving.
505 * Note that side effect is chance to miss BC/MC
508 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
511 bcn_li_dtim = dhd->dtim_skip;
512 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
513 4, iovbuf, sizeof(iovbuf));
514 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
517 /* Disable build-in roaming to allowed \
518 * supplicant to take of romaing
520 bcm_mkiovar("roam_off", (char *)&roamvar, 4,
521 iovbuf, sizeof(iovbuf));
522 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
524 #endif /* CUSTOMER_HW2 */
528 DHD_TRACE(("%s: Remove extra suspend setting\n",
531 power_mode = PM_FAST;
532 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
536 /* disable pkt filter */
537 dhd_set_packet_filter(0, dhd);
539 /* restore pre-suspend setting for dtim_skip */
540 bcm_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
541 4, iovbuf, sizeof(iovbuf));
543 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
547 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
549 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
551 #endif /* CUSTOMER_HW2 */
558 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
560 dhd_pub_t *dhdp = &dhd->pub;
562 dhd_os_proto_block(dhdp);
563 /* Set flag when early suspend was called */
564 dhdp->in_suspend = val;
565 if (!dhdp->suspend_disable_flag)
566 dhd_set_suspend(val, dhdp);
567 dhd_os_proto_unblock(dhdp);
570 static void dhd_early_suspend(struct early_suspend *h)
572 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
574 DHD_TRACE(("%s: enter\n", __func__));
577 dhd_suspend_resume_helper(dhd, 1);
581 static void dhd_late_resume(struct early_suspend *h)
583 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
585 DHD_TRACE(("%s: enter\n", __func__));
588 dhd_suspend_resume_helper(dhd, 0);
590 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
593 * Generalized timeout mechanism. Uses spin sleep with exponential
595 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
597 * dhd_timeout_start(&tmo, usec);
598 * while (!dhd_timeout_expired(&tmo))
599 * if (poll_something())
601 * if (dhd_timeout_expired(&tmo))
605 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
610 tmo->tick = 1000000 / HZ;
613 int dhd_timeout_expired(dhd_timeout_t *tmo)
615 /* Does nothing the first call */
616 if (tmo->increment == 0) {
621 if (tmo->elapsed >= tmo->limit)
624 /* Add the delay that's about to take place */
625 tmo->elapsed += tmo->increment;
627 if (tmo->increment < tmo->tick) {
628 OSL_DELAY(tmo->increment);
630 if (tmo->increment > tmo->tick)
631 tmo->increment = tmo->tick;
633 wait_queue_head_t delay_wait;
634 DECLARE_WAITQUEUE(wait, current);
636 init_waitqueue_head(&delay_wait);
637 add_wait_queue(&delay_wait, &wait);
638 set_current_state(TASK_INTERRUPTIBLE);
640 pending = signal_pending(current);
641 remove_wait_queue(&delay_wait, &wait);
642 set_current_state(TASK_RUNNING);
644 return 1; /* Interrupted */
650 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
655 while (i < DHD_MAX_IFS) {
656 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
664 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
670 if (name == NULL || *name == '\0')
675 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
678 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
680 return i; /* default - the primary interface */
683 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
685 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
689 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
690 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
694 if (dhd->iflist[ifidx] == NULL) {
695 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
699 if (dhd->iflist[ifidx]->net)
700 return dhd->iflist[ifidx]->net->name;
705 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
707 struct net_device *dev;
708 struct netdev_hw_addr *ha;
716 ASSERT(dhd && dhd->iflist[ifidx]);
717 dev = dhd->iflist[ifidx]->net;
718 cnt = netdev_mc_count(dev);
720 /* Determine initial value of allmulti flag */
721 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
723 /* Send down the multicast list first. */
725 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
726 bufp = buf = MALLOC(dhd->pub.osh, buflen);
728 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
729 dhd_ifname(&dhd->pub, ifidx), cnt));
733 strcpy(bufp, "mcast_list");
734 bufp += strlen("mcast_list") + 1;
737 memcpy(bufp, &cnt, sizeof(cnt));
740 netdev_for_each_mc_addr(ha, dev) {
743 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
744 bufp += ETHER_ADDR_LEN;
748 memset(&ioc, 0, sizeof(ioc));
749 ioc.cmd = WLC_SET_VAR;
754 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
756 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
757 dhd_ifname(&dhd->pub, ifidx), cnt));
758 allmulti = cnt ? TRUE : allmulti;
761 MFREE(dhd->pub.osh, buf, buflen);
763 /* Now send the allmulti setting. This is based on the setting in the
764 * net_device flags, but might be modified above to be turned on if we
765 * were trying to set some addresses and dongle rejected it...
768 buflen = sizeof("allmulti") + sizeof(allmulti);
769 buf = MALLOC(dhd->pub.osh, buflen);
771 DHD_ERROR(("%s: out of memory for allmulti\n",
772 dhd_ifname(&dhd->pub, ifidx)));
775 allmulti = htol32(allmulti);
778 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
779 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
780 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
781 (int)sizeof(allmulti), buflen));
782 MFREE(dhd->pub.osh, buf, buflen);
786 memset(&ioc, 0, sizeof(ioc));
787 ioc.cmd = WLC_SET_VAR;
792 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
794 DHD_ERROR(("%s: set allmulti %d failed\n",
795 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
798 MFREE(dhd->pub.osh, buf, buflen);
800 /* Finally, pick up the PROMISC flag as well, like the NIC
803 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
804 allmulti = htol32(allmulti);
806 memset(&ioc, 0, sizeof(ioc));
807 ioc.cmd = WLC_SET_PROMISC;
809 ioc.len = sizeof(allmulti);
812 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
814 DHD_ERROR(("%s: set promisc %d failed\n",
815 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
820 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
826 DHD_TRACE(("%s enter\n", __func__));
828 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) {
829 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
830 dhd_ifname(&dhd->pub, ifidx)));
833 memset(&ioc, 0, sizeof(ioc));
834 ioc.cmd = WLC_SET_VAR;
839 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
841 DHD_ERROR(("%s: set cur_etheraddr failed\n",
842 dhd_ifname(&dhd->pub, ifidx)));
844 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
851 extern struct net_device *ap_net_dev;
854 static void dhd_op_if(dhd_if_t *ifp)
857 int ret = 0, err = 0;
859 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
863 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
865 switch (ifp->state) {
868 * Delete the existing interface before overwriting it
869 * in case we missed the WLC_E_IF_DEL event.
871 if (ifp->net != NULL) {
872 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
873 "try free & unregister\n",
874 __func__, ifp->net->name));
875 netif_stop_queue(ifp->net);
876 unregister_netdev(ifp->net);
877 free_netdev(ifp->net);
879 /* Allocate etherdev, including space for private structure */
880 ifp->net = alloc_etherdev(sizeof(dhd));
882 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
886 strcpy(ifp->net->name, ifp->name);
887 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
888 err = dhd_net_attach(&dhd->pub, ifp->idx);
890 DHD_ERROR(("%s: dhd_net_attach failed, "
896 /* semaphore that the soft AP CODE
898 extern struct semaphore ap_eth_sema;
900 /* save ptr to wl0.1 netdev for use
902 ap_net_dev = ifp->net;
903 /* signal to the SOFTAP 'sleeper' thread,
907 DHD_TRACE(("\n ==== pid:%x, net_device for "
908 "if:%s created ===\n\n",
909 current->pid, ifp->net->name));
915 if (ifp->net != NULL) {
916 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
918 netif_stop_queue(ifp->net);
919 unregister_netdev(ifp->net);
920 ret = DHD_DEL_IF; /* Make sure the free_netdev()
925 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
932 free_netdev(ifp->net);
934 dhd->iflist[ifp->idx] = NULL;
935 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
937 if (ifp->net == ap_net_dev)
938 ap_net_dev = NULL; /* NULL SOFTAP global
944 static int _dhd_sysioc_thread(void *data)
946 dhd_info_t *dhd = (dhd_info_t *) data;
952 DAEMONIZE("dhd_sysioc");
954 while (down_interruptible(&dhd->sysioc_sem) == 0) {
955 for (i = 0; i < DHD_MAX_IFS; i++) {
956 if (dhd->iflist[i]) {
958 in_ap = (ap_net_dev != NULL);
960 if (dhd->iflist[i]->state)
961 dhd_op_if(dhd->iflist[i]);
963 if (dhd->iflist[i] == NULL) {
964 DHD_TRACE(("\n\n %s: interface %d "
965 "removed!\n", __func__, i));
969 if (in_ap && dhd->set_macaddress) {
970 DHD_TRACE(("attempt to set MAC for %s "
971 "in AP Mode," "blocked. \n",
972 dhd->iflist[i]->net->name));
973 dhd->set_macaddress = FALSE;
977 if (in_ap && dhd->set_multicast) {
978 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
979 dhd->iflist[i]->net->name));
980 dhd->set_multicast = FALSE;
984 if (dhd->set_multicast) {
985 dhd->set_multicast = FALSE;
986 _dhd_set_multicast_list(dhd, i);
988 if (dhd->set_macaddress) {
989 dhd->set_macaddress = FALSE;
990 _dhd_set_mac_address(dhd, i,
996 complete_and_exit(&dhd->sysioc_exited, 0);
999 static int dhd_set_mac_address(struct net_device *dev, void *addr)
1003 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1004 struct sockaddr *sa = (struct sockaddr *)addr;
1007 ifidx = dhd_net2idx(dhd, dev);
1008 if (ifidx == DHD_BAD_IF)
1011 ASSERT(dhd->sysioc_pid >= 0);
1012 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1013 dhd->set_macaddress = TRUE;
1014 up(&dhd->sysioc_sem);
1019 static void dhd_set_multicast_list(struct net_device *dev)
1021 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1024 ifidx = dhd_net2idx(dhd, dev);
1025 if (ifidx == DHD_BAD_IF)
1028 ASSERT(dhd->sysioc_pid >= 0);
1029 dhd->set_multicast = TRUE;
1030 up(&dhd->sysioc_sem);
1033 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1036 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1038 /* Reject if down */
1039 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1042 /* Update multicast statistic */
1043 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) {
1044 u8 *pktdata = (u8 *) PKTDATA(pktbuf);
1045 struct ether_header *eh = (struct ether_header *)pktdata;
1047 if (ETHER_ISMULTI(eh->ether_dhost))
1048 dhdp->tx_multicast++;
1049 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1050 atomic_inc(&dhd->pend_8021x_cnt);
1053 /* Look into the packet and update the packet priority */
1054 if ((PKTPRIO(pktbuf) == 0))
1055 pktsetprio(pktbuf, FALSE);
1057 /* If the protocol uses a data header, apply it */
1058 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1060 /* Use bus module to send data frame */
1062 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1064 WAKE_LOCK_TIMEOUT(dhdp, WAKE_LOCK_TMOUT, 25);
1065 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1066 #endif /* BCMDBUS */
1071 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1075 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1078 DHD_TRACE(("%s: Enter\n", __func__));
1080 /* Reject if down */
1081 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1082 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1083 __func__, dhd->pub.up, dhd->pub.busstate));
1084 netif_stop_queue(net);
1088 ifidx = dhd_net2idx(dhd, net);
1089 if (ifidx == DHD_BAD_IF) {
1090 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1091 netif_stop_queue(net);
1095 /* Make sure there's enough room for any header */
1096 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1097 struct sk_buff *skb2;
1099 DHD_INFO(("%s: insufficient headroom\n",
1100 dhd_ifname(&dhd->pub, ifidx)));
1101 dhd->pub.tx_realloc++;
1102 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1106 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1107 dhd_ifname(&dhd->pub, ifidx)));
1113 /* Convert to packet */
1114 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1116 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1117 dhd_ifname(&dhd->pub, ifidx)));
1118 dev_kfree_skb_any(skb);
1123 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1127 dhd->pub.dstats.tx_dropped++;
1129 dhd->pub.tx_packets++;
1131 /* Return ok: we always eat the packet */
1135 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1137 struct net_device *net;
1138 dhd_info_t *dhd = dhdp->info;
1140 DHD_TRACE(("%s: Enter\n", __func__));
1142 dhdp->txoff = state;
1143 ASSERT(dhd && dhd->iflist[ifidx]);
1144 net = dhd->iflist[ifidx]->net;
1146 netif_stop_queue(net);
1148 netif_wake_queue(net);
1151 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1153 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1154 struct sk_buff *skb;
1157 void *data, *pnext, *save_pktbuf;
1160 wl_event_msg_t event;
1162 DHD_TRACE(("%s: Enter\n", __func__));
1164 save_pktbuf = pktbuf;
1166 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1168 pnext = PKTNEXT(pktbuf);
1169 PKTSETNEXT(pktbuf, NULL);
1171 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1173 /* Get the protocol, maintain skb around eth_type_trans()
1174 * The main reason for this hack is for the limitation of
1175 * Linux 2.4 where 'eth_type_trans' uses the
1176 * 'net->hard_header_len'
1177 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1178 * coping of the packet coming from the network stack to add
1179 * BDC, Hardware header etc, during network interface
1181 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1183 * for BDC, Hardware header etc. and not just the ETH_HLEN
1188 ifp = dhd->iflist[ifidx];
1190 ifp = dhd->iflist[0];
1193 skb->dev = ifp->net;
1194 skb->protocol = eth_type_trans(skb, skb->dev);
1196 if (skb->pkt_type == PACKET_MULTICAST)
1197 dhd->pub.rx_multicast++;
1202 /* Strip header, count, deliver upward */
1203 skb_pull(skb, ETH_HLEN);
1205 /* Process special event packets and then discard them */
1206 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1207 dhd_wl_host_event(dhd, &ifidx,
1211 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1212 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1213 ifp = dhd->iflist[ifidx];
1216 ifp->net->last_rx = jiffies;
1218 dhdp->dstats.rx_bytes += skb->len;
1219 dhdp->rx_packets++; /* Local count */
1221 if (in_interrupt()) {
1224 /* If the receive is not processed inside an ISR,
1225 * the softirqd must be woken explicitly to service
1226 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1227 * by netif_rx_ni(), but in earlier kernels, we need
1228 * to do it manually.
1235 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1237 /* Linux version has nothing to do */
1241 void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1244 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1245 struct ether_header *eh;
1248 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1250 eh = (struct ether_header *)PKTDATA(txp);
1251 type = ntoh16(eh->ether_type);
1253 if (type == ETHER_TYPE_802_1X)
1254 atomic_dec(&dhd->pend_8021x_cnt);
1258 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1260 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1264 DHD_TRACE(("%s: Enter\n", __func__));
1266 ifidx = dhd_net2idx(dhd, net);
1267 if (ifidx == DHD_BAD_IF)
1270 ifp = dhd->iflist[ifidx];
1274 /* Use the protocol to get dongle stats */
1275 dhd_prot_dstats(&dhd->pub);
1278 /* Copy dongle stats to net device stats */
1279 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1280 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1281 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1282 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1283 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1284 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1285 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1286 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1287 ifp->stats.multicast = dhd->pub.dstats.multicast;
1292 static int dhd_watchdog_thread(void *data)
1294 dhd_info_t *dhd = (dhd_info_t *) data;
1295 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_WATCHDOG, "dhd_watchdog_thread");
1297 /* This thread doesn't need any user-level access,
1298 * so get rid of all our resources
1301 if (dhd_watchdog_prio > 0) {
1302 struct sched_param param;
1303 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1304 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1305 setScheduler(current, SCHED_FIFO, ¶m);
1307 #endif /* DHD_SCHED */
1309 DAEMONIZE("dhd_watchdog");
1311 /* Run until signal received */
1313 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1314 if (dhd->pub.dongle_reset == FALSE) {
1315 WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1316 /* Call the bus module watchdog */
1317 dhd_bus_watchdog(&dhd->pub);
1318 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
1320 /* Count the tick for reference */
1326 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_WATCHDOG);
1327 complete_and_exit(&dhd->watchdog_exited, 0);
1330 static void dhd_watchdog(unsigned long data)
1332 dhd_info_t *dhd = (dhd_info_t *) data;
1334 if (dhd->watchdog_pid >= 0) {
1335 up(&dhd->watchdog_sem);
1337 /* Reschedule the watchdog */
1338 if (dhd->wd_timer_valid) {
1339 mod_timer(&dhd->timer,
1340 jiffies + dhd_watchdog_ms * HZ / 1000);
1345 /* Call the bus module watchdog */
1346 dhd_bus_watchdog(&dhd->pub);
1348 /* Count the tick for reference */
1351 /* Reschedule the watchdog */
1352 if (dhd->wd_timer_valid)
1353 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1356 static int dhd_dpc_thread(void *data)
1358 dhd_info_t *dhd = (dhd_info_t *) data;
1360 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_DPC, "dhd_dpc_thread");
1361 /* This thread doesn't need any user-level access,
1362 * so get rid of all our resources
1365 if (dhd_dpc_prio > 0) {
1366 struct sched_param param;
1367 param.sched_priority =
1369 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1370 setScheduler(current, SCHED_FIFO, ¶m);
1372 #endif /* DHD_SCHED */
1374 DAEMONIZE("dhd_dpc");
1376 /* Run until signal received */
1378 if (down_interruptible(&dhd->dpc_sem) == 0) {
1379 /* Call bus dpc unless it indicated down
1380 (then clean stop) */
1381 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1382 WAKE_LOCK(&dhd->pub, WAKE_LOCK_DPC);
1383 if (dhd_bus_dpc(dhd->pub.bus)) {
1385 WAKE_LOCK_TIMEOUT(&dhd->pub,
1386 WAKE_LOCK_TMOUT, 25);
1388 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
1390 dhd_bus_stop(dhd->pub.bus, TRUE);
1396 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_DPC);
1398 complete_and_exit(&dhd->dpc_exited, 0);
1401 static void dhd_dpc(unsigned long data)
1405 dhd = (dhd_info_t *) data;
1407 /* Call bus dpc unless it indicated down (then clean stop) */
1408 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1409 if (dhd_bus_dpc(dhd->pub.bus))
1410 tasklet_schedule(&dhd->tasklet);
1412 dhd_bus_stop(dhd->pub.bus, TRUE);
1416 void dhd_sched_dpc(dhd_pub_t *dhdp)
1418 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1420 if (dhd->dpc_pid >= 0) {
1425 tasklet_schedule(&dhd->tasklet);
1429 /* Retrieve current toe component enables, which are kept
1430 as a bitmap in toe_ol iovar */
1431 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1437 memset(&ioc, 0, sizeof(ioc));
1439 ioc.cmd = WLC_GET_VAR;
1441 ioc.len = (uint) sizeof(buf);
1444 strcpy(buf, "toe_ol");
1445 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1447 /* Check for older dongle image that doesn't support toe_ol */
1449 DHD_ERROR(("%s: toe not supported by device\n",
1450 dhd_ifname(&dhd->pub, ifidx)));
1454 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1455 dhd_ifname(&dhd->pub, ifidx), ret));
1459 memcpy(toe_ol, buf, sizeof(u32));
1463 /* Set current toe component enables in toe_ol iovar,
1464 and set toe global enable iovar */
1465 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1471 memset(&ioc, 0, sizeof(ioc));
1473 ioc.cmd = WLC_SET_VAR;
1475 ioc.len = (uint) sizeof(buf);
1478 /* Set toe_ol as requested */
1480 strcpy(buf, "toe_ol");
1481 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1483 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1485 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1486 dhd_ifname(&dhd->pub, ifidx), ret));
1490 /* Enable toe globally only if any components are enabled. */
1492 toe = (toe_ol != 0);
1495 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1497 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1499 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1500 dhd_ifname(&dhd->pub, ifidx), ret));
1508 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1509 struct ethtool_drvinfo *info)
1511 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1513 sprintf(info->driver, DRV_MODULE_NAME);
1514 sprintf(info->version, "%lu", dhd->pub.drv_version);
1515 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1516 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1519 struct ethtool_ops dhd_ethtool_ops = {
1520 .get_drvinfo = dhd_ethtool_get_drvinfo
1523 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1525 struct ethtool_drvinfo info;
1526 char drvname[sizeof(info.driver)];
1529 struct ethtool_value edata;
1530 u32 toe_cmpnt, csum_dir;
1534 DHD_TRACE(("%s: Enter\n", __func__));
1536 /* all ethtool calls start with a cmd word */
1537 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1541 case ETHTOOL_GDRVINFO:
1542 /* Copy out any request driver name */
1543 if (copy_from_user(&info, uaddr, sizeof(info)))
1545 strncpy(drvname, info.driver, sizeof(info.driver));
1546 drvname[sizeof(info.driver) - 1] = '\0';
1548 /* clear struct for return */
1549 memset(&info, 0, sizeof(info));
1552 /* if dhd requested, identify ourselves */
1553 if (strcmp(drvname, "?dhd") == 0) {
1554 sprintf(info.driver, "dhd");
1555 strcpy(info.version, EPI_VERSION_STR);
1558 /* otherwise, require dongle to be up */
1559 else if (!dhd->pub.up) {
1560 DHD_ERROR(("%s: dongle is not up\n", __func__));
1564 /* finally, report dongle driver type */
1565 else if (dhd->pub.iswl)
1566 sprintf(info.driver, "wl");
1568 sprintf(info.driver, "xx");
1570 sprintf(info.version, "%lu", dhd->pub.drv_version);
1571 if (copy_to_user(uaddr, &info, sizeof(info)))
1573 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1574 (int)sizeof(drvname), drvname, info.driver));
1578 /* Get toe offload components from dongle */
1579 case ETHTOOL_GRXCSUM:
1580 case ETHTOOL_GTXCSUM:
1581 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1586 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1589 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1591 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1595 /* Set toe offload components in dongle */
1596 case ETHTOOL_SRXCSUM:
1597 case ETHTOOL_STXCSUM:
1598 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1601 /* Read the current settings, update and write back */
1602 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1607 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1609 if (edata.data != 0)
1610 toe_cmpnt |= csum_dir;
1612 toe_cmpnt &= ~csum_dir;
1614 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1618 /* If setting TX checksum mode, tell Linux the new mode */
1619 if (cmd == ETHTOOL_STXCSUM) {
1621 dhd->iflist[0]->net->features |=
1624 dhd->iflist[0]->net->features &=
1638 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1640 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1647 bool is_set_key_cmd;
1649 ifidx = dhd_net2idx(dhd, net);
1650 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1652 if (ifidx == DHD_BAD_IF)
1655 #if defined(CONFIG_WIRELESS_EXT)
1656 /* linux wireless extensions */
1657 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1658 /* may recurse, do NOT lock */
1659 return wl_iw_ioctl(net, ifr, cmd);
1661 #endif /* defined(CONFIG_WIRELESS_EXT) */
1663 if (cmd == SIOCETHTOOL)
1664 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1666 if (cmd != SIOCDEVPRIVATE)
1669 memset(&ioc, 0, sizeof(ioc));
1671 /* Copy the ioc control structure part of ioctl request */
1672 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1673 bcmerror = -BCME_BADADDR;
1677 /* Copy out any buffer passed */
1679 buflen = min(ioc.len, DHD_IOCTL_MAXLEN);
1680 /* optimization for direct ioctl calls from kernel */
1682 if (segment_eq(get_fs(), KERNEL_DS)) {
1687 buf = (char *)MALLOC(dhd->pub.osh, buflen);
1689 bcmerror = -BCME_NOMEM;
1692 if (copy_from_user(buf, ioc.buf, buflen)) {
1693 bcmerror = -BCME_BADADDR;
1699 /* To differentiate between wl and dhd read 4 more byes */
1700 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1701 sizeof(uint)) != 0)) {
1702 bcmerror = -BCME_BADADDR;
1706 if (!capable(CAP_NET_ADMIN)) {
1707 bcmerror = -BCME_EPERM;
1711 /* check for local dhd ioctl and handle it */
1712 if (driver == DHD_IOCTL_MAGIC) {
1713 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1715 dhd->pub.bcmerror = bcmerror;
1719 /* send to dongle (must be up, and wl) */
1720 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1721 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1722 bcmerror = BCME_DONGLE_DOWN;
1726 if (!dhd->pub.iswl) {
1727 bcmerror = BCME_DONGLE_DOWN;
1731 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1732 * prevent M4 encryption.
1734 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1735 ((ioc.cmd == WLC_SET_VAR) &&
1736 !(strncmp("wsec_key", ioc.buf, 9))) ||
1737 ((ioc.cmd == WLC_SET_VAR) &&
1738 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1740 dhd_wait_pend8021x(net);
1742 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_IOCTL, "dhd_ioctl_entry");
1743 WAKE_LOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1746 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1748 WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_IOCTL);
1749 WAKE_LOCK_DESTROY(&dhd->pub, WAKE_LOCK_IOCTL);
1751 if (!bcmerror && buf && ioc.buf) {
1752 if (copy_to_user(ioc.buf, buf, buflen))
1757 MFREE(dhd->pub.osh, buf, buflen);
1759 return OSL_ERROR(bcmerror);
1762 static int dhd_stop(struct net_device *net)
1764 #if !defined(IGNORE_ETH0_DOWN)
1765 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1767 DHD_TRACE(("%s: Enter\n", __func__));
1768 if (IS_CFG80211_FAVORITE()) {
1771 if (dhd->pub.up == 0)
1774 /* Set state and stop OS transmissions */
1776 netif_stop_queue(net);
1778 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1780 #endif /* !defined(IGNORE_ETH0_DOWN) */
1785 static int dhd_open(struct net_device *net)
1787 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1791 int ifidx = dhd_net2idx(dhd, net);
1794 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1796 if (ifidx == 0) { /* do it only for primary eth0 */
1798 /* try to bring up bus */
1799 ret = dhd_bus_start(&dhd->pub);
1801 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1804 atomic_set(&dhd->pend_8021x_cnt, 0);
1806 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
1809 /* Get current TOE mode from dongle */
1810 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1811 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1812 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1814 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1817 /* Allow transmit calls */
1818 netif_start_queue(net);
1820 if (IS_CFG80211_FAVORITE()) {
1821 if (unlikely(wl_cfg80211_up())) {
1822 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1831 osl_t *dhd_osl_attach(void *pdev, uint bustype)
1833 return osl_attach(pdev, bustype, TRUE);
1836 void dhd_osl_detach(osl_t *osh)
1838 if (MALLOCED(osh)) {
1839 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
1846 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1847 u8 *mac_addr, u32 flags, u8 bssidx)
1851 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1853 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1855 ifp = dhd->iflist[ifidx];
1856 if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
1857 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1861 memset(ifp, 0, sizeof(dhd_if_t));
1863 dhd->iflist[ifidx] = ifp;
1864 strlcpy(ifp->name, name, IFNAMSIZ);
1865 if (mac_addr != NULL)
1866 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
1868 if (handle == NULL) {
1869 ifp->state = WLC_E_IF_ADD;
1871 ASSERT(dhd->sysioc_pid >= 0);
1872 up(&dhd->sysioc_sem);
1874 ifp->net = (struct net_device *)handle;
1879 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1883 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1885 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1886 ifp = dhd->iflist[ifidx];
1888 DHD_ERROR(("%s: Null interface\n", __func__));
1892 ifp->state = WLC_E_IF_DEL;
1894 ASSERT(dhd->sysioc_pid >= 0);
1895 up(&dhd->sysioc_sem);
1898 dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
1900 dhd_info_t *dhd = NULL;
1901 struct net_device *net;
1903 DHD_TRACE(("%s: Enter\n", __func__));
1904 /* updates firmware nvram path if it was provided as module
1906 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1907 strcpy(fw_path, firmware_path);
1908 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1909 strcpy(nv_path, nvram_path);
1911 /* Allocate etherdev, including space for private structure */
1912 net = alloc_etherdev(sizeof(dhd));
1914 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1918 /* Allocate primary dhd_info */
1919 dhd = MALLOC(osh, sizeof(dhd_info_t));
1921 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1925 memset(dhd, 0, sizeof(dhd_info_t));
1928 * Save the dhd_info into the priv
1930 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1933 /* Set network interface name if it was provided as module parameter */
1934 if (iface_name[0]) {
1937 strncpy(net->name, iface_name, IFNAMSIZ);
1938 net->name[IFNAMSIZ - 1] = 0;
1939 len = strlen(net->name);
1940 ch = net->name[len - 1];
1941 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1942 strcat(net->name, "%d");
1945 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1949 net->netdev_ops = NULL;
1950 init_MUTEX(&dhd->proto_sem);
1951 /* Initialize other structure content */
1952 init_waitqueue_head(&dhd->ioctl_resp_wait);
1953 init_waitqueue_head(&dhd->ctrl_wait);
1955 /* Initialize the spinlocks */
1956 spin_lock_init(&dhd->sdlock);
1957 spin_lock_init(&dhd->txqlock);
1959 /* Link to info module */
1960 dhd->pub.info = dhd;
1962 /* Link to bus module */
1964 dhd->pub.hdrlen = bus_hdrlen;
1966 /* Attach and link in the protocol */
1967 if (dhd_prot_attach(&dhd->pub) != 0) {
1968 DHD_ERROR(("dhd_prot_attach failed\n"));
1971 #if defined(CONFIG_WIRELESS_EXT)
1972 /* Attach and link in the iw */
1973 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1974 DHD_ERROR(("wl_iw_attach failed\n"));
1977 #endif /* defined(CONFIG_WIRELESS_EXT) */
1979 /* Attach and link in the cfg80211 */
1980 if (IS_CFG80211_FAVORITE()) {
1981 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1982 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1986 strcpy(fw_path, wl_cfg80211_get_fwname());
1987 strcpy(nv_path, wl_cfg80211_get_nvramname());
1989 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
1992 /* Set up the watchdog timer */
1993 init_timer(&dhd->timer);
1994 dhd->timer.data = (unsigned long) dhd;
1995 dhd->timer.function = dhd_watchdog;
1997 /* Initialize thread based operation and lock */
1998 init_MUTEX(&dhd->sdsem);
1999 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
2000 dhd->threads_only = TRUE;
2002 dhd->threads_only = FALSE;
2004 if (dhd_dpc_prio >= 0) {
2005 /* Initialize watchdog thread */
2006 sema_init(&dhd->watchdog_sem, 0);
2007 init_completion(&dhd->watchdog_exited);
2008 dhd->watchdog_pid = kernel_thread(dhd_watchdog_thread, dhd, 0);
2010 dhd->watchdog_pid = -1;
2013 /* Set up the bottom half handler */
2014 if (dhd_dpc_prio >= 0) {
2015 /* Initialize DPC thread */
2016 sema_init(&dhd->dpc_sem, 0);
2017 init_completion(&dhd->dpc_exited);
2018 dhd->dpc_pid = kernel_thread(dhd_dpc_thread, dhd, 0);
2020 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
2025 sema_init(&dhd->sysioc_sem, 0);
2026 init_completion(&dhd->sysioc_exited);
2027 dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
2029 dhd->sysioc_pid = -1;
2033 * Save the dhd_info into the priv
2035 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2037 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2040 #if defined(CONFIG_PM_SLEEP)
2041 register_pm_notifier(&dhd_sleep_pm_notifier);
2042 #endif /* defined(CONFIG_PM_SLEEP) */
2043 /* && defined(DHD_GPL) */
2044 /* Init lock suspend to prevent kernel going to suspend */
2045 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_TMOUT, "dhd_wake_lock");
2046 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
2047 "dhd_wake_lock_link_dw_event");
2048 WAKE_LOCK_INIT(&dhd->pub, WAKE_LOCK_PNO_FIND_TMOUT,
2049 "dhd_wake_lock_link_pno_find_event");
2050 #ifdef CONFIG_HAS_EARLYSUSPEND
2051 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2052 dhd->early_suspend.suspend = dhd_early_suspend;
2053 dhd->early_suspend.resume = dhd_late_resume;
2054 register_early_suspend(&dhd->early_suspend);
2063 dhd_detach(&dhd->pub);
2068 int dhd_bus_start(dhd_pub_t *dhdp)
2071 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2072 #ifdef EMBEDDED_PLATFORM
2073 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2075 #endif /* EMBEDDED_PLATFORM */
2079 DHD_TRACE(("%s:\n", __func__));
2081 /* try to download image and nvram to the dongle */
2082 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2083 WAKE_LOCK_INIT(dhdp, WAKE_LOCK_DOWNLOAD, "dhd_bus_start");
2084 WAKE_LOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2085 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
2086 fw_path, nv_path))) {
2087 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2088 "firmware = %s nvram = %s\n",
2089 __func__, fw_path, nv_path));
2090 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2091 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2095 WAKE_UNLOCK(dhdp, WAKE_LOCK_DOWNLOAD);
2096 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_DOWNLOAD);
2099 /* Start the watchdog timer */
2100 dhd->pub.tickcnt = 0;
2101 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2103 /* Bring up the bus */
2104 ret = dhd_bus_init(&dhd->pub, TRUE);
2106 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2109 #if defined(OOB_INTR_ONLY)
2110 /* Host registration for OOB interrupt */
2111 if (bcmsdh_register_oob_intr(dhdp)) {
2112 del_timer_sync(&dhd->timer);
2113 dhd->wd_timer_valid = FALSE;
2114 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2118 /* Enable oob at firmware */
2119 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
2120 #endif /* defined(OOB_INTR_ONLY) */
2122 /* If bus is not ready, can't come up */
2123 if (dhd->pub.busstate != DHD_BUS_DATA) {
2124 del_timer_sync(&dhd->timer);
2125 dhd->wd_timer_valid = FALSE;
2126 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2129 #ifdef EMBEDDED_PLATFORM
2130 bcm_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
2132 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2133 bcopy(iovbuf, dhdp->eventmask, WL_EVENTING_MASK_LEN);
2135 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2136 setbit(dhdp->eventmask, WLC_E_PRUNE);
2137 setbit(dhdp->eventmask, WLC_E_AUTH);
2138 setbit(dhdp->eventmask, WLC_E_REASSOC);
2139 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2140 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2141 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2142 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2143 setbit(dhdp->eventmask, WLC_E_JOIN);
2144 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2145 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2146 setbit(dhdp->eventmask, WLC_E_LINK);
2147 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2148 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2149 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2150 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2151 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2152 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2154 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2155 #endif /* PNO_SUPPORT */
2157 /* enable dongle roaming event */
2159 dhdp->pktfilter_count = 1;
2160 /* Setup filter to allow only unicast */
2161 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2162 #endif /* EMBEDDED_PLATFORM */
2164 /* Bus is ready, do any protocol initialization */
2165 ret = dhd_prot_init(&dhd->pub);
2173 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2176 char buf[strlen(name) + 1 + cmd_len];
2177 int len = sizeof(buf);
2181 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
2183 memset(&ioc, 0, sizeof(ioc));
2185 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2190 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2191 if (!set && ret >= 0)
2192 memcpy(cmd_buf, buf, cmd_len);
2197 static struct net_device_ops dhd_ops_pri = {
2198 .ndo_open = dhd_open,
2199 .ndo_stop = dhd_stop,
2200 .ndo_get_stats = dhd_get_stats,
2201 .ndo_do_ioctl = dhd_ioctl_entry,
2202 .ndo_start_xmit = dhd_start_xmit,
2203 .ndo_set_mac_address = dhd_set_mac_address,
2204 .ndo_set_multicast_list = dhd_set_multicast_list
2207 static struct net_device_ops dhd_ops_virt = {
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 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2217 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2218 struct net_device *net;
2219 u8 temp_addr[ETHER_ADDR_LEN] = {
2220 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2222 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2224 ASSERT(dhd && dhd->iflist[ifidx]);
2226 net = dhd->iflist[ifidx]->net;
2229 ASSERT(!net->netdev_ops);
2230 net->netdev_ops = &dhd_ops_virt;
2232 net->netdev_ops = &dhd_ops_pri;
2235 * We have to use the primary MAC for virtual interfaces
2238 /* for virtual interfaces use the primary MAC */
2239 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2244 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2245 /* ACCESSPOINT INTERFACE CASE */
2246 temp_addr[0] |= 0X02; /* set bit 2 ,
2247 - Locally Administered address */
2250 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2251 net->ethtool_ops = &dhd_ethtool_ops;
2253 #if defined(CONFIG_WIRELESS_EXT)
2254 if (!IS_CFG80211_FAVORITE()) {
2255 #if WIRELESS_EXT < 19
2256 net->get_wireless_stats = dhd_get_wireless_stats;
2257 #endif /* WIRELESS_EXT < 19 */
2258 #if WIRELESS_EXT > 12
2259 net->wireless_handlers =
2260 (struct iw_handler_def *)&wl_iw_handler_def;
2261 #endif /* WIRELESS_EXT > 12 */
2263 #endif /* defined(CONFIG_WIRELESS_EXT) */
2265 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2267 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
2269 if (register_netdev(net) != 0) {
2270 DHD_ERROR(("%s: couldn't register the net device\n",
2275 printf("%s: Broadcom Dongle Host Driver\n", net->name);
2280 net->netdev_ops = NULL;
2284 void dhd_bus_detach(dhd_pub_t *dhdp)
2288 DHD_TRACE(("%s: Enter\n", __func__));
2291 dhd = (dhd_info_t *) dhdp->info;
2293 /* Stop the protocol module */
2294 dhd_prot_stop(&dhd->pub);
2296 /* Stop the bus module */
2297 dhd_bus_stop(dhd->pub.bus, TRUE);
2298 #if defined(OOB_INTR_ONLY)
2299 bcmsdh_unregister_oob_intr();
2300 #endif /* defined(OOB_INTR_ONLY) */
2302 /* Clear the watchdog timer */
2303 del_timer_sync(&dhd->timer);
2304 dhd->wd_timer_valid = FALSE;
2309 void dhd_detach(dhd_pub_t *dhdp)
2313 DHD_TRACE(("%s: Enter\n", __func__));
2316 dhd = (dhd_info_t *) dhdp->info;
2321 #if defined(CONFIG_HAS_EARLYSUSPEND)
2322 if (dhd->early_suspend.suspend)
2323 unregister_early_suspend(&dhd->early_suspend);
2324 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2326 for (i = 1; i < DHD_MAX_IFS; i++)
2330 ifp = dhd->iflist[0];
2332 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2334 unregister_netdev(ifp->net);
2337 if (dhd->watchdog_pid >= 0) {
2338 KILL_PROC(dhd->watchdog_pid, SIGTERM);
2339 wait_for_completion(&dhd->watchdog_exited);
2342 if (dhd->dpc_pid >= 0) {
2343 KILL_PROC(dhd->dpc_pid, SIGTERM);
2344 wait_for_completion(&dhd->dpc_exited);
2346 tasklet_kill(&dhd->tasklet);
2348 if (dhd->sysioc_pid >= 0) {
2349 KILL_PROC(dhd->sysioc_pid, SIGTERM);
2350 wait_for_completion(&dhd->sysioc_exited);
2353 dhd_bus_detach(dhdp);
2356 dhd_prot_detach(dhdp);
2358 #if defined(CONFIG_WIRELESS_EXT)
2360 #endif /* (CONFIG_WIRELESS_EXT) */
2362 if (IS_CFG80211_FAVORITE())
2363 wl_cfg80211_detach();
2365 #if defined(CONFIG_PM_SLEEP)
2366 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2367 #endif /* defined(CONFIG_PM_SLEEP) */
2368 /* && defined(DHD_GPL) */
2369 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_TMOUT);
2370 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
2371 WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
2372 free_netdev(ifp->net);
2373 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
2374 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
2379 static void __exit dhd_module_cleanup(void)
2381 DHD_TRACE(("%s: Enter\n", __func__));
2383 dhd_bus_unregister();
2384 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2387 /* Call customer gpio to turn off power with WL_REG_ON signal */
2388 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2391 static int __init dhd_module_init(void)
2395 DHD_TRACE(("%s: Enter\n", __func__));
2397 /* Sanity check on the module parameters */
2399 /* Both watchdog and DPC as tasklets are ok */
2400 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2403 /* If both watchdog and DPC are threads, TX must be deferred */
2404 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2408 DHD_ERROR(("Invalid module parameters.\n"));
2411 /* Call customer gpio to turn on power with WL_REG_ON signal */
2412 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2414 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2415 sema_init(&wifi_control_sem, 0);
2417 error = wifi_add_dev();
2419 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2423 /* Waiting callback after platform_driver_register is done or
2425 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2426 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2432 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2434 error = dhd_bus_register();
2437 printf("\n%s\n", dhd_version);
2439 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2445 /* turn off power and exit */
2446 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2450 module_init(dhd_module_init);
2451 module_exit(dhd_module_cleanup);
2454 * OS specific functions required to implement DHD driver in OS independent way
2456 int dhd_os_proto_block(dhd_pub_t *pub)
2458 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2461 down(&dhd->proto_sem);
2467 int dhd_os_proto_unblock(dhd_pub_t *pub)
2469 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2472 up(&dhd->proto_sem);
2479 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2481 return (unsigned int)dhd_ioctl_timeout_msec;
2484 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2486 dhd_ioctl_timeout_msec = (int)timeout_msec;
2489 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2491 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2492 DECLARE_WAITQUEUE(wait, current);
2493 int timeout = dhd_ioctl_timeout_msec;
2495 /* Convert timeout in millsecond to jiffies */
2496 timeout = timeout * HZ / 1000;
2498 /* Wait until control frame is available */
2499 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2500 set_current_state(TASK_INTERRUPTIBLE);
2502 while (!(*condition) && (!signal_pending(current) && timeout))
2503 timeout = schedule_timeout(timeout);
2505 if (signal_pending(current))
2508 set_current_state(TASK_RUNNING);
2509 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2514 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2516 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2518 if (waitqueue_active(&dhd->ioctl_resp_wait))
2519 wake_up_interruptible(&dhd->ioctl_resp_wait);
2524 void dhd_os_wd_timer(void *bus, uint wdtick)
2526 dhd_pub_t *pub = bus;
2527 static uint save_dhd_watchdog_ms;
2528 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2530 /* don't start the wd until fw is loaded */
2531 if (pub->busstate == DHD_BUS_DOWN)
2534 /* Totally stop the timer */
2535 if (!wdtick && dhd->wd_timer_valid == TRUE) {
2536 del_timer_sync(&dhd->timer);
2537 dhd->wd_timer_valid = FALSE;
2538 save_dhd_watchdog_ms = wdtick;
2543 dhd_watchdog_ms = (uint) wdtick;
2545 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2547 if (dhd->wd_timer_valid == TRUE)
2548 /* Stop timer and restart at new value */
2549 del_timer_sync(&dhd->timer);
2551 /* Create timer again when watchdog period is
2552 dynamically changed or in the first instance
2554 dhd->timer.expires =
2555 jiffies + dhd_watchdog_ms * HZ / 1000;
2556 add_timer(&dhd->timer);
2559 /* Re arm the timer, at last watchdog period */
2560 mod_timer(&dhd->timer,
2561 jiffies + dhd_watchdog_ms * HZ / 1000);
2564 dhd->wd_timer_valid = TRUE;
2565 save_dhd_watchdog_ms = wdtick;
2569 void *dhd_os_open_image(char *filename)
2573 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2574 return wl_cfg80211_request_fw(filename);
2576 fp = filp_open(filename, O_RDONLY, 0);
2578 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2580 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2589 int dhd_os_get_image_block(char *buf, int len, void *image)
2591 struct file *fp = (struct file *)image;
2594 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2595 return wl_cfg80211_read_fw(buf, len);
2600 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2607 void dhd_os_close_image(void *image)
2609 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2610 return wl_cfg80211_release_fw();
2612 filp_close((struct file *)image, NULL);
2615 void dhd_os_sdlock(dhd_pub_t *pub)
2619 dhd = (dhd_info_t *) (pub->info);
2621 if (dhd->threads_only)
2624 spin_lock_bh(&dhd->sdlock);
2627 void dhd_os_sdunlock(dhd_pub_t *pub)
2631 dhd = (dhd_info_t *) (pub->info);
2633 if (dhd->threads_only)
2636 spin_unlock_bh(&dhd->sdlock);
2639 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2643 dhd = (dhd_info_t *) (pub->info);
2644 spin_lock_bh(&dhd->txqlock);
2647 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2651 dhd = (dhd_info_t *) (pub->info);
2652 spin_unlock_bh(&dhd->txqlock);
2655 void dhd_os_sdlock_rxq(dhd_pub_t *pub)
2659 void dhd_os_sdunlock_rxq(dhd_pub_t *pub)
2663 void dhd_os_sdtxlock(dhd_pub_t *pub)
2668 void dhd_os_sdtxunlock(dhd_pub_t *pub)
2670 dhd_os_sdunlock(pub);
2673 #ifdef DHD_USE_STATIC_BUF
2674 void *dhd_os_prealloc(int section, unsigned long size)
2676 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2677 void *alloc_ptr = NULL;
2678 if (wifi_control_data && wifi_control_data->mem_prealloc) {
2679 alloc_ptr = wifi_control_data->mem_prealloc(section, size);
2681 DHD_INFO(("success alloc section %d\n", section));
2682 bzero(alloc_ptr, size);
2687 DHD_ERROR(("can't alloc section %d\n", section));
2690 return MALLOC(0, size);
2691 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2693 #endif /* DHD_USE_STATIC_BUF */
2694 #if defined(CONFIG_WIRELESS_EXT)
2695 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
2698 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2700 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
2703 return &dhd->iw.wstats;
2707 #endif /* defined(CONFIG_WIRELESS_EXT) */
2710 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2711 wl_event_msg_t *event, void **data)
2715 ASSERT(dhd != NULL);
2717 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2718 if (bcmerror != BCME_OK)
2721 #if defined(CONFIG_WIRELESS_EXT)
2722 if (!IS_CFG80211_FAVORITE()) {
2723 if ((dhd->iflist[*ifidx] == NULL)
2724 || (dhd->iflist[*ifidx]->net == NULL)) {
2725 DHD_ERROR(("%s Exit null pointer\n", __func__));
2729 if (dhd->iflist[*ifidx]->net)
2730 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2732 #endif /* defined(CONFIG_WIRELESS_EXT) */
2734 if (IS_CFG80211_FAVORITE()) {
2735 ASSERT(dhd->iflist[*ifidx] != NULL);
2736 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2737 if (dhd->iflist[*ifidx]->net)
2738 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2745 /* send up locally generated event */
2746 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2748 switch (ntoh32(event->event_type)) {
2754 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2756 struct dhd_info *dhdinfo = dhd->info;
2757 dhd_os_sdunlock(dhd);
2758 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2759 (*lockvar == FALSE), HZ * 2);
2764 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2766 struct dhd_info *dhdinfo = dhd->info;
2767 if (waitqueue_active(&dhdinfo->ctrl_wait))
2768 wake_up_interruptible(&dhdinfo->ctrl_wait);
2772 int dhd_dev_reset(struct net_device *dev, u8 flag)
2774 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2776 /* Turning off watchdog */
2778 dhd_os_wd_timer(&dhd->pub, 0);
2780 dhd_bus_devreset(&dhd->pub, flag);
2782 /* Turning on watchdog back */
2784 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2785 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2790 int net_os_set_suspend_disable(struct net_device *dev, int val)
2792 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2796 ret = dhd->pub.suspend_disable_flag;
2797 dhd->pub.suspend_disable_flag = val;
2802 int net_os_set_suspend(struct net_device *dev, int val)
2805 #if defined(CONFIG_HAS_EARLYSUSPEND)
2806 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2809 dhd_os_proto_block(&dhd->pub);
2810 ret = dhd_set_suspend(val, &dhd->pub);
2811 dhd_os_proto_unblock(&dhd->pub);
2813 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2817 int net_os_set_dtim_skip(struct net_device *dev, int val)
2819 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2822 dhd->pub.dtim_skip = val;
2827 int net_os_set_packet_filter(struct net_device *dev, int val)
2829 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2832 /* Packet filtering is set only if we still in early-suspend and
2833 * we need either to turn it ON or turn it OFF
2834 * We can always turn it OFF in case of early-suspend, but we turn it
2835 * back ON only if suspend_disable_flag was not set
2837 if (dhd && dhd->pub.up) {
2838 dhd_os_proto_block(&dhd->pub);
2839 if (dhd->pub.in_suspend) {
2840 if (!val || (val && !dhd->pub.suspend_disable_flag))
2841 dhd_set_packet_filter(val, &dhd->pub);
2843 dhd_os_proto_unblock(&dhd->pub);
2848 void dhd_dev_init_ioctl(struct net_device *dev)
2850 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2852 dhd_preinit_ioctls(&dhd->pub);
2856 /* Linux wrapper to call common dhd_pno_clean */
2857 int dhd_dev_pno_reset(struct net_device *dev)
2859 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2861 return dhd_pno_clean(&dhd->pub);
2864 /* Linux wrapper to call common dhd_pno_enable */
2865 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2867 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2869 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2872 /* Linux wrapper to call common dhd_pno_set */
2874 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2875 unsigned char scan_fr)
2877 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2879 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2882 /* Linux wrapper to get pno status */
2883 int dhd_dev_get_pno_status(struct net_device *dev)
2885 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2887 return dhd_pno_get_status(&dhd->pub);
2890 #endif /* PNO_SUPPORT */
2892 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2894 return atomic_read(&dhd->pend_8021x_cnt);
2897 #define MAX_WAIT_FOR_8021X_TX 10
2899 int dhd_wait_pend8021x(struct net_device *dev)
2901 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2902 int timeout = 10 * HZ / 1000;
2903 int ntimes = MAX_WAIT_FOR_8021X_TX;
2904 int pend = dhd_get_pend_8021x_cnt(dhd);
2906 while (ntimes && pend) {
2908 set_current_state(TASK_INTERRUPTIBLE);
2909 schedule_timeout(timeout);
2910 set_current_state(TASK_RUNNING);
2913 pend = dhd_get_pend_8021x_cnt(dhd);
2919 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2923 mm_segment_t old_fs;
2926 /* change to KERNEL_DS address limit */
2930 /* open file to write */
2931 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2933 printf("%s: open file error\n", __func__);
2938 /* Write buf to file */
2939 fp->f_op->write(fp, buf, size, &pos);
2942 /* free buf before return */
2943 MFREE(dhd->osh, buf, size);
2944 /* close file before return */
2946 filp_close(fp, current->files);
2947 /* restore previous address limit */
2952 #endif /* DHD_DEBUG */