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 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/kthread.h>
20 #include <linux/slab.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/mmc/sdio_func.h>
25 #include <linux/random.h>
26 #include <linux/spinlock.h>
27 #include <linux/ethtool.h>
28 #include <linux/fcntl.h>
30 #include <linux/uaccess.h>
31 #include <net/cfg80211.h>
32 #if defined(CONFIG_HAS_EARLYSUSPEND)
33 #include <linux/earlysuspend.h>
36 #include <brcmu_utils.h>
37 #include <brcmu_wifi.h>
39 #include "dngl_stats.h"
42 #include "dhd_proto.h"
44 #include "wl_cfg80211.h"
47 /* Global ASSERT type flag */
50 #if defined(CONFIG_PM_SLEEP)
51 #include <linux/suspend.h>
52 atomic_t brcmf_mmc_suspend;
53 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
54 #endif /* defined(CONFIG_PM_SLEEP) */
56 MODULE_AUTHOR("Broadcom Corporation");
57 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
58 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
59 MODULE_LICENSE("Dual BSD/GPL");
62 /* Interface control information */
63 typedef struct dhd_if {
64 struct dhd_info *info; /* back pointer to dhd_info */
65 /* OS/stack specifics */
66 struct net_device *net;
67 struct net_device_stats stats;
68 int idx; /* iface idx in dongle */
69 int state; /* interface state */
70 uint subunit; /* subunit */
71 u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
72 bool attached; /* Delayed attachment when unset */
73 bool txflowcontrol; /* Per interface flow control indicator */
74 char name[IFNAMSIZ]; /* linux interface name */
77 /* Local private structure (extension of pub) */
78 typedef struct dhd_info {
81 /* OS/stack specifics */
82 dhd_if_t *iflist[BRCMF_MAX_IFS];
84 struct semaphore proto_sem;
85 wait_queue_head_t ioctl_resp_wait;
87 /* Thread to issue ioctl for multicast */
88 struct task_struct *sysioc_tsk;
89 struct semaphore sysioc_sem;
92 u8 macvalue[ETH_ALEN];
93 atomic_t pend_8021x_cnt;
95 #ifdef CONFIG_HAS_EARLYSUSPEND
96 struct early_suspend early_suspend;
97 #endif /* CONFIG_HAS_EARLYSUSPEND */
101 module_param(brcmf_msg_level, int, 0);
103 /* Spawn a thread for system ioctls (set mac, set mcast) */
104 uint brcmf_sysioc = true;
105 module_param(brcmf_sysioc, uint, 0);
107 /* ARP offload agent mode : Enable ARP Host Auto-Reply
108 and ARP Peer Auto-Reply */
109 uint brcmf_arp_mode = 0xb;
110 module_param(brcmf_arp_mode, uint, 0);
112 /* ARP offload enable */
113 uint brcmf_arp_enable = true;
114 module_param(brcmf_arp_enable, uint, 0);
116 /* Global Pkt filter enable control */
117 uint brcmf_pkt_filter_enable = true;
118 module_param(brcmf_pkt_filter_enable, uint, 0);
120 /* Pkt filter init setup */
121 uint brcmf_pkt_filter_init;
122 module_param(brcmf_pkt_filter_init, uint, 0);
124 /* Pkt filter mode control */
125 uint brcmf_master_mode = true;
126 module_param(brcmf_master_mode, uint, 1);
128 extern int brcmf_dongle_memsize;
129 module_param(brcmf_dongle_memsize, int, 0);
131 /* Contorl fw roaming */
134 /* Control radio state */
135 uint brcmf_radio_up = 1;
137 /* Network inteface name */
138 char iface_name[IFNAMSIZ] = "wlan";
139 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
141 /* The following are specific to the SDIO dongle */
143 /* IOCTL response timeout */
144 int brcmf_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
146 /* Idle timeout for backplane clock */
147 int brcmf_idletime = BRCMF_IDLETIME_TICKS;
148 module_param(brcmf_idletime, int, 0);
152 module_param(brcmf_poll, uint, 0);
155 uint brcmf_intr = true;
156 module_param(brcmf_intr, uint, 0);
158 /* SDIO Drive Strength (in milliamps) */
159 uint brcmf_sdiod_drive_strength = 6;
160 module_param(brcmf_sdiod_drive_strength, uint, 0);
163 extern uint brcmf_txbound;
164 extern uint brcmf_rxbound;
165 module_param(brcmf_txbound, uint, 0);
166 module_param(brcmf_rxbound, uint, 0);
169 /* Echo packet generator (pkts/s) */
171 module_param(brcmf_pktgen, uint, 0);
173 /* Echo packet len (0 => sawtooth, max 2040) */
174 uint brcmf_pktgen_len;
175 module_param(brcmf_pktgen_len, uint, 0);
178 /* Version string to report */
180 #define DHD_COMPILED "\nCompiled in " SRCBASE
185 static int brcmf_toe_get(dhd_info_t *drvr_priv, int idx, u32 *toe_ol);
186 static int brcmf_toe_set(dhd_info_t *drvr_priv, int idx, u32 toe_ol);
187 static int brcmf_host_event(dhd_info_t *drvr_priv, int *ifidx, void *pktdata,
188 brcmf_event_msg_t *event_ptr, void **data_ptr);
190 static void brcmf_set_packet_filter(int value, dhd_pub_t *drvr)
192 DHD_TRACE(("%s: %d\n", __func__, value));
193 /* 1 - Enable packet filter, only allow unicast packet to send up */
194 /* 0 - Disable packet filter */
195 if (brcmf_pkt_filter_enable) {
198 for (i = 0; i < drvr->pktfilter_count; i++) {
199 brcmf_c_pktfilter_offload_set(drvr, drvr->pktfilter[i]);
200 brcmf_c_pktfilter_offload_enable(drvr,
208 #if defined(CONFIG_HAS_EARLYSUSPEND)
209 static int brcmf_set_suspend(int value, dhd_pub_t *drvr)
211 int power_mode = PM_MAX;
212 /* struct wl_pkt_filter_enable enable_parm; */
216 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
217 __func__, value, drvr->in_suspend));
219 if (drvr && drvr->up) {
220 if (value && drvr->in_suspend) {
222 /* Kernel suspended */
223 DHD_TRACE(("%s: force extra Suspend setting\n",
226 brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_PM,
230 /* Enable packet filter, only allow unicast
232 brcmf_set_packet_filter(1, drvr);
234 /* if dtim skip setup as default force it
235 * to wake each third dtim
236 * for better power saving.
237 * Note that side effect is chance to miss BC/MC
240 if ((drvr->dtim_skip == 0) || (drvr->dtim_skip == 1))
243 bcn_li_dtim = drvr->dtim_skip;
244 brcmu_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
245 4, iovbuf, sizeof(iovbuf));
246 brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR,
247 iovbuf, sizeof(iovbuf));
251 DHD_TRACE(("%s: Remove extra suspend setting\n",
254 power_mode = PM_FAST;
255 brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_PM,
259 /* disable pkt filter */
260 brcmf_set_packet_filter(0, drvr);
262 /* restore pre-suspend setting for dtim_skip */
263 brcmu_mkiovar("bcn_li_dtim", (char *)&drvr->dtim_skip,
264 4, iovbuf, sizeof(iovbuf));
266 brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR,
267 iovbuf, sizeof(iovbuf));
274 static void brcmf_suspend_resume_helper(struct dhd_info *drvr_priv, int val)
276 dhd_pub_t *drvr = &drvr_priv->pub;
278 brcmf_os_proto_block(drvr);
279 /* Set flag when early suspend was called */
280 drvr->in_suspend = val;
281 if (!drvr->suspend_disable_flag)
282 brcmf_set_suspend(val, drvr);
283 brcmf_os_proto_unblock(drvr);
286 static void brcmf_early_suspend(struct early_suspend *h)
288 struct dhd_info *drvr_priv =
289 container_of(h, struct dhd_info, early_suspend);
291 DHD_TRACE(("%s: enter\n", __func__));
294 dhd_suspend_resume_helper(drvr_priv, 1);
298 static void brcmf_late_resume(struct early_suspend *h)
300 struct dhd_info *drvr_priv =
301 container_of(h, struct dhd_info, early_suspend);
303 DHD_TRACE(("%s: enter\n", __func__));
306 dhd_suspend_resume_helper(drvr_priv, 0);
308 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
311 * Generalized timeout mechanism. Uses spin sleep with exponential
313 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
315 * brcmf_timeout_start(&tmo, usec);
316 * while (!brcmf_timeout_expired(&tmo))
317 * if (poll_something())
319 * if (brcmf_timeout_expired(&tmo))
323 void brcmf_timeout_start(dhd_timeout_t *tmo, uint usec)
328 tmo->tick = 1000000 / HZ;
331 int brcmf_timeout_expired(dhd_timeout_t *tmo)
333 /* Does nothing the first call */
334 if (tmo->increment == 0) {
339 if (tmo->elapsed >= tmo->limit)
342 /* Add the delay that's about to take place */
343 tmo->elapsed += tmo->increment;
345 if (tmo->increment < tmo->tick) {
346 udelay(tmo->increment);
348 if (tmo->increment > tmo->tick)
349 tmo->increment = tmo->tick;
351 wait_queue_head_t delay_wait;
352 DECLARE_WAITQUEUE(wait, current);
354 init_waitqueue_head(&delay_wait);
355 add_wait_queue(&delay_wait, &wait);
356 set_current_state(TASK_INTERRUPTIBLE);
358 pending = signal_pending(current);
359 remove_wait_queue(&delay_wait, &wait);
360 set_current_state(TASK_RUNNING);
362 return 1; /* Interrupted */
368 static int brcmf_net2idx(dhd_info_t *drvr_priv, struct net_device *net)
373 while (i < BRCMF_MAX_IFS) {
374 if (drvr_priv->iflist[i] && (drvr_priv->iflist[i]->net == net))
382 int brcmf_ifname2idx(dhd_info_t *drvr_priv, char *name)
384 int i = BRCMF_MAX_IFS;
388 if (name == NULL || *name == '\0')
392 if (drvr_priv->iflist[i]
393 && !strncmp(drvr_priv->iflist[i]->name, name, IFNAMSIZ))
396 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
398 return i; /* default - the primary interface */
401 char *brcmf_ifname(dhd_pub_t *drvr, int ifidx)
403 dhd_info_t *drvr_priv = drvr->info;
407 if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
408 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
412 if (drvr_priv->iflist[ifidx] == NULL) {
413 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
417 if (drvr_priv->iflist[ifidx]->net)
418 return drvr_priv->iflist[ifidx]->net->name;
423 static void _brcmf_set_multicast_list(dhd_info_t *drvr_priv, int ifidx)
425 struct net_device *dev;
426 struct netdev_hw_addr *ha;
429 struct brcmf_ioctl ioc;
434 ASSERT(drvr_priv && drvr_priv->iflist[ifidx]);
435 dev = drvr_priv->iflist[ifidx]->net;
436 cnt = netdev_mc_count(dev);
438 /* Determine initial value of allmulti flag */
439 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
441 /* Send down the multicast list first. */
443 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
444 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
446 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
447 brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
451 strcpy(bufp, "mcast_list");
452 bufp += strlen("mcast_list") + 1;
454 cnt = cpu_to_le32(cnt);
455 memcpy(bufp, &cnt, sizeof(cnt));
458 netdev_for_each_mc_addr(ha, dev) {
461 memcpy(bufp, ha->addr, ETH_ALEN);
466 memset(&ioc, 0, sizeof(ioc));
467 ioc.cmd = BRCMF_C_SET_VAR;
472 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
474 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
475 brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
476 allmulti = cnt ? true : allmulti;
481 /* Now send the allmulti setting. This is based on the setting in the
482 * net_device flags, but might be modified above to be turned on if we
483 * were trying to set some addresses and dongle rejected it...
486 buflen = sizeof("allmulti") + sizeof(allmulti);
487 buf = kmalloc(buflen, GFP_ATOMIC);
489 DHD_ERROR(("%s: out of memory for allmulti\n",
490 brcmf_ifname(&drvr_priv->pub, ifidx)));
493 allmulti = cpu_to_le32(allmulti);
496 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
497 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
498 "buflen %u\n", brcmf_ifname(&drvr_priv->pub, ifidx),
499 (int)sizeof(allmulti), buflen));
504 memset(&ioc, 0, sizeof(ioc));
505 ioc.cmd = BRCMF_C_SET_VAR;
510 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
512 DHD_ERROR(("%s: set allmulti %d failed\n",
513 brcmf_ifname(&drvr_priv->pub, ifidx),
514 le32_to_cpu(allmulti)));
519 /* Finally, pick up the PROMISC flag as well, like the NIC
522 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
523 allmulti = cpu_to_le32(allmulti);
525 memset(&ioc, 0, sizeof(ioc));
526 ioc.cmd = BRCMF_C_SET_PROMISC;
528 ioc.len = sizeof(allmulti);
531 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
533 DHD_ERROR(("%s: set promisc %d failed\n",
534 brcmf_ifname(&drvr_priv->pub, ifidx),
535 le32_to_cpu(allmulti)));
539 static int _brcmf_set_mac_address(dhd_info_t *drvr_priv, int ifidx, u8 *addr)
542 struct brcmf_ioctl ioc;
545 DHD_TRACE(("%s enter\n", __func__));
547 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
548 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
549 brcmf_ifname(&drvr_priv->pub, ifidx)));
552 memset(&ioc, 0, sizeof(ioc));
553 ioc.cmd = BRCMF_C_SET_VAR;
558 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
560 DHD_ERROR(("%s: set cur_etheraddr failed\n",
561 brcmf_ifname(&drvr_priv->pub, ifidx)));
563 memcpy(drvr_priv->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
570 extern struct net_device *ap_net_dev;
573 static void brcmf_op_if(dhd_if_t *ifp)
575 dhd_info_t *drvr_priv;
576 int ret = 0, err = 0;
578 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
580 drvr_priv = ifp->info;
582 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
584 switch (ifp->state) {
587 * Delete the existing interface before overwriting it
588 * in case we missed the BRCMF_E_IF_DEL event.
590 if (ifp->net != NULL) {
591 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
592 "try free & unregister\n",
593 __func__, ifp->net->name));
594 netif_stop_queue(ifp->net);
595 unregister_netdev(ifp->net);
596 free_netdev(ifp->net);
598 /* Allocate etherdev, including space for private structure */
599 ifp->net = alloc_etherdev(sizeof(drvr_priv));
601 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
605 strcpy(ifp->net->name, ifp->name);
606 memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv));
607 err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
609 DHD_ERROR(("%s: dhd_net_attach failed, "
615 /* semaphore that the soft AP CODE
617 extern struct semaphore ap_eth_sema;
619 /* save ptr to wl0.1 netdev for use
621 ap_net_dev = ifp->net;
622 /* signal to the SOFTAP 'sleeper' thread,
626 DHD_TRACE(("\n ==== pid:%x, net_device for "
627 "if:%s created ===\n\n",
628 current->pid, ifp->net->name));
634 if (ifp->net != NULL) {
635 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
637 netif_stop_queue(ifp->net);
638 unregister_netdev(ifp->net);
639 ret = BRCMF_DEL_IF; /* Make sure the free_netdev()
644 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
651 free_netdev(ifp->net);
653 drvr_priv->iflist[ifp->idx] = NULL;
656 if (ifp->net == ap_net_dev)
657 ap_net_dev = NULL; /* NULL SOFTAP global
663 static int _brcmf_sysioc_thread(void *data)
665 dhd_info_t *drvr_priv = (dhd_info_t *) data;
671 allow_signal(SIGTERM);
673 while (down_interruptible(&drvr_priv->sysioc_sem) == 0) {
674 if (kthread_should_stop())
676 for (i = 0; i < BRCMF_MAX_IFS; i++) {
677 if (drvr_priv->iflist[i]) {
679 in_ap = (ap_net_dev != NULL);
681 if (drvr_priv->iflist[i]->state)
682 brcmf_op_if(drvr_priv->iflist[i]);
684 if (drvr_priv->iflist[i] == NULL) {
685 DHD_TRACE(("\n\n %s: interface %d "
686 "removed!\n", __func__, i));
690 if (in_ap && drvr_priv->set_macaddress) {
691 DHD_TRACE(("attempt to set MAC for %s "
692 "in AP Mode," "blocked.\n",
693 drvr_priv->iflist[i]->net->name));
694 drvr_priv->set_macaddress = false;
698 if (in_ap && drvr_priv->set_multicast) {
699 DHD_TRACE(("attempt to set MULTICAST "
700 "list for %s in AP Mode, "
702 drvr_priv->iflist[i]->net->name));
703 drvr_priv->set_multicast = false;
707 if (drvr_priv->set_multicast) {
708 drvr_priv->set_multicast = false;
709 _brcmf_set_multicast_list(drvr_priv, i);
711 if (drvr_priv->set_macaddress) {
712 drvr_priv->set_macaddress = false;
713 _brcmf_set_mac_address(drvr_priv, i,
714 drvr_priv->macvalue);
722 static int brcmf_netdev_set_mac_address(struct net_device *dev, void *addr)
726 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(dev);
727 struct sockaddr *sa = (struct sockaddr *)addr;
730 ifidx = brcmf_net2idx(drvr_priv, dev);
731 if (ifidx == BRCMF_BAD_IF)
734 ASSERT(drvr_priv->sysioc_tsk);
735 memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN);
736 drvr_priv->set_macaddress = true;
737 up(&drvr_priv->sysioc_sem);
742 static void brcmf_netdev_set_multicast_list(struct net_device *dev)
744 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(dev);
747 ifidx = brcmf_net2idx(drvr_priv, dev);
748 if (ifidx == BRCMF_BAD_IF)
751 ASSERT(drvr_priv->sysioc_tsk);
752 drvr_priv->set_multicast = true;
753 up(&drvr_priv->sysioc_sem);
756 int brcmf_sendpkt(dhd_pub_t *drvr, int ifidx, struct sk_buff *pktbuf)
758 dhd_info_t *drvr_priv = drvr->info;
761 if (!drvr->up || (drvr->busstate == DHD_BUS_DOWN))
764 /* Update multicast statistic */
765 if (pktbuf->len >= ETH_ALEN) {
766 u8 *pktdata = (u8 *) (pktbuf->data);
767 struct ethhdr *eh = (struct ethhdr *)pktdata;
769 if (is_multicast_ether_addr(eh->h_dest))
770 drvr->tx_multicast++;
771 if (ntohs(eh->h_proto) == ETH_P_PAE)
772 atomic_inc(&drvr_priv->pend_8021x_cnt);
775 /* If the protocol uses a data header, apply it */
776 brcmf_proto_hdrpush(drvr, ifidx, pktbuf);
778 /* Use bus module to send data frame */
779 return brcmf_sdbrcm_bus_txdata(drvr->bus, pktbuf);
782 static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *net)
785 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(net);
788 DHD_TRACE(("%s: Enter\n", __func__));
791 if (!drvr_priv->pub.up || (drvr_priv->pub.busstate == DHD_BUS_DOWN)) {
792 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
793 __func__, drvr_priv->pub.up, drvr_priv->pub.busstate));
794 netif_stop_queue(net);
798 ifidx = brcmf_net2idx(drvr_priv, net);
799 if (ifidx == BRCMF_BAD_IF) {
800 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
801 netif_stop_queue(net);
805 /* Make sure there's enough room for any header */
806 if (skb_headroom(skb) < drvr_priv->pub.hdrlen) {
807 struct sk_buff *skb2;
809 DHD_INFO(("%s: insufficient headroom\n",
810 brcmf_ifname(&drvr_priv->pub, ifidx)));
811 drvr_priv->pub.tx_realloc++;
812 skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen);
816 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
817 brcmf_ifname(&drvr_priv->pub, ifidx)));
823 ret = brcmf_sendpkt(&drvr_priv->pub, ifidx, skb);
827 drvr_priv->pub.dstats.tx_dropped++;
829 drvr_priv->pub.tx_packets++;
831 /* Return ok: we always eat the packet */
835 void brcmf_txflowcontrol(dhd_pub_t *drvr, int ifidx, bool state)
837 struct net_device *net;
838 dhd_info_t *drvr_priv = drvr->info;
840 DHD_TRACE(("%s: Enter\n", __func__));
843 ASSERT(drvr_priv && drvr_priv->iflist[ifidx]);
844 net = drvr_priv->iflist[ifidx]->net;
846 netif_stop_queue(net);
848 netif_wake_queue(net);
851 void brcmf_rx_frame(dhd_pub_t *drvr, int ifidx, struct sk_buff *skb,
854 dhd_info_t *drvr_priv = drvr->info;
858 struct sk_buff *pnext, *save_pktbuf;
861 brcmf_event_msg_t event;
863 DHD_TRACE(("%s: Enter\n", __func__));
867 for (i = 0; skb && i < numpkt; i++, skb = pnext) {
872 /* Get the protocol, maintain skb around eth_type_trans()
873 * The main reason for this hack is for the limitation of
874 * Linux 2.4 where 'eth_type_trans' uses the
875 * 'net->hard_header_len'
876 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
877 * coping of the packet coming from the network stack to add
878 * BDC, Hardware header etc, during network interface
880 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
882 * for BDC, Hardware header etc. and not just the ETH_HLEN
887 ifp = drvr_priv->iflist[ifidx];
889 ifp = drvr_priv->iflist[0];
893 skb->protocol = eth_type_trans(skb, skb->dev);
895 if (skb->pkt_type == PACKET_MULTICAST)
896 drvr_priv->pub.rx_multicast++;
901 /* Strip header, count, deliver upward */
902 skb_pull(skb, ETH_HLEN);
904 /* Process special event packets and then discard them */
905 if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
906 brcmf_host_event(drvr_priv, &ifidx,
910 ASSERT(ifidx < BRCMF_MAX_IFS && drvr_priv->iflist[ifidx]);
911 if (drvr_priv->iflist[ifidx] &&
912 !drvr_priv->iflist[ifidx]->state)
913 ifp = drvr_priv->iflist[ifidx];
916 ifp->net->last_rx = jiffies;
918 drvr->dstats.rx_bytes += skb->len;
919 drvr->rx_packets++; /* Local count */
921 if (in_interrupt()) {
924 /* If the receive is not processed inside an ISR,
925 * the softirqd must be woken explicitly to service
926 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
927 * by netif_rx_ni(), but in earlier kernels, we need
935 void brcmf_event(struct dhd_info *drvr_priv, char *evpkt, int evlen, int ifidx)
937 /* Linux version has nothing to do */
941 void brcmf_txcomplete(dhd_pub_t *drvr, struct sk_buff *txp, bool success)
944 dhd_info_t *drvr_priv = drvr->info;
948 brcmf_proto_hdrpull(drvr, &ifidx, txp);
950 eh = (struct ethhdr *)(txp->data);
951 type = ntohs(eh->h_proto);
953 if (type == ETH_P_PAE)
954 atomic_dec(&drvr_priv->pend_8021x_cnt);
958 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *net)
960 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(net);
964 DHD_TRACE(("%s: Enter\n", __func__));
966 ifidx = brcmf_net2idx(drvr_priv, net);
967 if (ifidx == BRCMF_BAD_IF)
970 ifp = drvr_priv->iflist[ifidx];
971 ASSERT(drvr_priv && ifp);
973 if (drvr_priv->pub.up) {
974 /* Use the protocol to get dongle stats */
975 brcmf_proto_dstats(&drvr_priv->pub);
978 /* Copy dongle stats to net device stats */
979 ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets;
980 ifp->stats.tx_packets = drvr_priv->pub.dstats.tx_packets;
981 ifp->stats.rx_bytes = drvr_priv->pub.dstats.rx_bytes;
982 ifp->stats.tx_bytes = drvr_priv->pub.dstats.tx_bytes;
983 ifp->stats.rx_errors = drvr_priv->pub.dstats.rx_errors;
984 ifp->stats.tx_errors = drvr_priv->pub.dstats.tx_errors;
985 ifp->stats.rx_dropped = drvr_priv->pub.dstats.rx_dropped;
986 ifp->stats.tx_dropped = drvr_priv->pub.dstats.tx_dropped;
987 ifp->stats.multicast = drvr_priv->pub.dstats.multicast;
992 /* Retrieve current toe component enables, which are kept
993 as a bitmap in toe_ol iovar */
994 static int brcmf_toe_get(dhd_info_t *drvr_priv, int ifidx, u32 *toe_ol)
996 struct brcmf_ioctl ioc;
1000 memset(&ioc, 0, sizeof(ioc));
1002 ioc.cmd = BRCMF_C_GET_VAR;
1004 ioc.len = (uint) sizeof(buf);
1007 strcpy(buf, "toe_ol");
1008 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
1010 /* Check for older dongle image that doesn't support toe_ol */
1012 DHD_ERROR(("%s: toe not supported by device\n",
1013 brcmf_ifname(&drvr_priv->pub, ifidx)));
1017 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1018 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
1022 memcpy(toe_ol, buf, sizeof(u32));
1026 /* Set current toe component enables in toe_ol iovar,
1027 and set toe global enable iovar */
1028 static int brcmf_toe_set(dhd_info_t *drvr_priv, int ifidx, u32 toe_ol)
1030 struct brcmf_ioctl ioc;
1034 memset(&ioc, 0, sizeof(ioc));
1036 ioc.cmd = BRCMF_C_SET_VAR;
1038 ioc.len = (uint) sizeof(buf);
1041 /* Set toe_ol as requested */
1043 strcpy(buf, "toe_ol");
1044 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1046 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
1048 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1049 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
1053 /* Enable toe globally only if any components are enabled. */
1055 toe = (toe_ol != 0);
1058 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1060 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
1062 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1063 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
1070 static void brcmf_ethtool_get_drvinfo(struct net_device *net,
1071 struct ethtool_drvinfo *info)
1073 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(net);
1075 sprintf(info->driver, KBUILD_MODNAME);
1076 sprintf(info->version, "%lu", drvr_priv->pub.drv_version);
1077 sprintf(info->fw_version, "%s", BCM4329_FW_NAME);
1078 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1081 struct ethtool_ops brcmf_ethtool_ops = {
1082 .get_drvinfo = brcmf_ethtool_get_drvinfo
1085 static int brcmf_ethtool(dhd_info_t *drvr_priv, void *uaddr)
1087 struct ethtool_drvinfo info;
1088 char drvname[sizeof(info.driver)];
1090 struct ethtool_value edata;
1091 u32 toe_cmpnt, csum_dir;
1094 DHD_TRACE(("%s: Enter\n", __func__));
1096 /* all ethtool calls start with a cmd word */
1097 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1101 case ETHTOOL_GDRVINFO:
1102 /* Copy out any request driver name */
1103 if (copy_from_user(&info, uaddr, sizeof(info)))
1105 strncpy(drvname, info.driver, sizeof(info.driver));
1106 drvname[sizeof(info.driver) - 1] = '\0';
1108 /* clear struct for return */
1109 memset(&info, 0, sizeof(info));
1112 /* if dhd requested, identify ourselves */
1113 if (strcmp(drvname, "?dhd") == 0) {
1114 sprintf(info.driver, "dhd");
1115 strcpy(info.version, BRCMF_VERSION_STR);
1118 /* otherwise, require dongle to be up */
1119 else if (!drvr_priv->pub.up) {
1120 DHD_ERROR(("%s: dongle is not up\n", __func__));
1124 /* finally, report dongle driver type */
1125 else if (drvr_priv->pub.iswl)
1126 sprintf(info.driver, "wl");
1128 sprintf(info.driver, "xx");
1130 sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
1131 if (copy_to_user(uaddr, &info, sizeof(info)))
1133 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1134 (int)sizeof(drvname), drvname, info.driver));
1137 /* Get toe offload components from dongle */
1138 case ETHTOOL_GRXCSUM:
1139 case ETHTOOL_GTXCSUM:
1140 ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
1145 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1148 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1150 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1154 /* Set toe offload components in dongle */
1155 case ETHTOOL_SRXCSUM:
1156 case ETHTOOL_STXCSUM:
1157 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1160 /* Read the current settings, update and write back */
1161 ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
1166 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1168 if (edata.data != 0)
1169 toe_cmpnt |= csum_dir;
1171 toe_cmpnt &= ~csum_dir;
1173 ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt);
1177 /* If setting TX checksum mode, tell Linux the new mode */
1178 if (cmd == ETHTOOL_STXCSUM) {
1180 drvr_priv->iflist[0]->net->features |=
1183 drvr_priv->iflist[0]->net->features &=
1196 static int brcmf_netdev_ioctl_entry(struct net_device *net, struct ifreq *ifr,
1199 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(net);
1206 bool is_set_key_cmd;
1208 ifidx = brcmf_net2idx(drvr_priv, net);
1209 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1211 if (ifidx == BRCMF_BAD_IF)
1214 if (cmd == SIOCETHTOOL)
1215 return brcmf_ethtool(drvr_priv, (void *)ifr->ifr_data);
1217 if (cmd != SIOCDEVPRIVATE)
1220 memset(&ioc, 0, sizeof(ioc));
1222 /* Copy the ioc control structure part of ioctl request */
1223 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(struct brcmf_ioctl))) {
1228 /* Copy out any buffer passed */
1230 buflen = min_t(int, ioc.len, BRCMF_IOCTL_MAXLEN);
1231 /* optimization for direct ioctl calls from kernel */
1233 if (segment_eq(get_fs(), KERNEL_DS)) {
1238 buf = kmalloc(buflen, GFP_ATOMIC);
1243 if (copy_from_user(buf, ioc.buf, buflen)) {
1250 /* To differentiate between wl and dhd read 4 more byes */
1251 if ((copy_from_user(&driver, (char *)ifr->ifr_data +
1252 sizeof(struct brcmf_ioctl), sizeof(uint)) != 0)) {
1257 if (!capable(CAP_NET_ADMIN)) {
1262 /* check for local dhd ioctl and handle it */
1263 if (driver == BRCMF_IOCTL_MAGIC) {
1264 bcmerror = brcmf_c_ioctl((void *)&drvr_priv->pub, &ioc, buf, buflen);
1266 drvr_priv->pub.bcmerror = bcmerror;
1270 /* send to dongle (must be up, and wl) */
1271 if ((drvr_priv->pub.busstate != DHD_BUS_DATA)) {
1272 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1277 if (!drvr_priv->pub.iswl) {
1283 * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
1284 * set key IOCTL to prevent M4 encryption.
1286 is_set_key_cmd = ((ioc.cmd == BRCMF_C_SET_KEY) ||
1287 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1288 !(strncmp("wsec_key", ioc.buf, 9))) ||
1289 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1290 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1292 brcmf_netdev_wait_pend8021x(net);
1295 brcmf_proto_ioctl(&drvr_priv->pub, ifidx, (struct brcmf_ioctl *)&ioc,
1299 if (!bcmerror && buf && ioc.buf) {
1300 if (copy_to_user(ioc.buf, buf, buflen))
1312 static int brcmf_netdev_stop(struct net_device *net)
1314 #if !defined(IGNORE_ETH0_DOWN)
1315 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(net);
1317 DHD_TRACE(("%s: Enter\n", __func__));
1319 if (drvr_priv->pub.up == 0)
1322 /* Set state and stop OS transmissions */
1323 drvr_priv->pub.up = 0;
1324 netif_stop_queue(net);
1326 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1328 #endif /* !defined(IGNORE_ETH0_DOWN) */
1333 static int brcmf_netdev_open(struct net_device *net)
1335 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(net);
1337 int ifidx = brcmf_net2idx(drvr_priv, net);
1340 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1342 if (ifidx == 0) { /* do it only for primary eth0 */
1344 /* try to bring up bus */
1345 ret = brcmf_bus_start(&drvr_priv->pub);
1347 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1350 atomic_set(&drvr_priv->pend_8021x_cnt, 0);
1352 memcpy(net->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
1354 /* Get current TOE mode from dongle */
1355 if (brcmf_toe_get(drvr_priv, ifidx, &toe_ol) >= 0
1356 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1357 drvr_priv->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1359 drvr_priv->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1361 /* Allow transmit calls */
1362 netif_start_queue(net);
1363 drvr_priv->pub.up = 1;
1364 if (unlikely(wl_cfg80211_up())) {
1365 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1374 brcmf_add_if(dhd_info_t *drvr_priv, int ifidx, void *handle, char *name,
1375 u8 *mac_addr, u32 flags, u8 bssidx)
1379 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1381 ASSERT(drvr_priv && (ifidx < BRCMF_MAX_IFS));
1383 ifp = drvr_priv->iflist[ifidx];
1385 ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC);
1387 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1392 memset(ifp, 0, sizeof(dhd_if_t));
1393 ifp->info = drvr_priv;
1394 drvr_priv->iflist[ifidx] = ifp;
1395 strlcpy(ifp->name, name, IFNAMSIZ);
1396 if (mac_addr != NULL)
1397 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1399 if (handle == NULL) {
1400 ifp->state = BRCMF_E_IF_ADD;
1402 ASSERT(drvr_priv->sysioc_tsk);
1403 up(&drvr_priv->sysioc_sem);
1405 ifp->net = (struct net_device *)handle;
1410 void brcmf_del_if(dhd_info_t *drvr_priv, int ifidx)
1414 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1416 ASSERT(drvr_priv && ifidx && (ifidx < BRCMF_MAX_IFS));
1417 ifp = drvr_priv->iflist[ifidx];
1419 DHD_ERROR(("%s: Null interface\n", __func__));
1423 ifp->state = BRCMF_E_IF_DEL;
1425 ASSERT(drvr_priv->sysioc_tsk);
1426 up(&drvr_priv->sysioc_sem);
1429 dhd_pub_t *brcmf_attach(struct dhd_bus *bus, uint bus_hdrlen)
1431 dhd_info_t *drvr_priv = NULL;
1432 struct net_device *net;
1434 DHD_TRACE(("%s: Enter\n", __func__));
1436 /* Allocate etherdev, including space for private structure */
1437 net = alloc_etherdev(sizeof(drvr_priv));
1439 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1443 /* Allocate primary dhd_info */
1444 drvr_priv = kzalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1446 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1451 * Save the dhd_info into the priv
1453 memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
1455 /* Set network interface name if it was provided as module parameter */
1456 if (iface_name[0]) {
1459 strncpy(net->name, iface_name, IFNAMSIZ);
1460 net->name[IFNAMSIZ - 1] = 0;
1461 len = strlen(net->name);
1462 ch = net->name[len - 1];
1463 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1464 strcat(net->name, "%d");
1467 if (brcmf_add_if(drvr_priv, 0, (void *)net, net->name, NULL, 0, 0) ==
1471 net->netdev_ops = NULL;
1472 sema_init(&drvr_priv->proto_sem, 1);
1473 /* Initialize other structure content */
1474 init_waitqueue_head(&drvr_priv->ioctl_resp_wait);
1476 /* Link to info module */
1477 drvr_priv->pub.info = drvr_priv;
1479 /* Link to bus module */
1480 drvr_priv->pub.bus = bus;
1481 drvr_priv->pub.hdrlen = bus_hdrlen;
1483 /* Attach and link in the protocol */
1484 if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
1485 DHD_ERROR(("dhd_prot_attach failed\n"));
1489 /* Attach and link in the cfg80211 */
1490 if (unlikely(wl_cfg80211_attach(net, &drvr_priv->pub))) {
1491 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1496 sema_init(&drvr_priv->sysioc_sem, 0);
1497 drvr_priv->sysioc_tsk = kthread_run(_brcmf_sysioc_thread, drvr_priv,
1499 if (IS_ERR(drvr_priv->sysioc_tsk)) {
1501 "_dhd_sysioc thread failed to start\n");
1502 drvr_priv->sysioc_tsk = NULL;
1505 drvr_priv->sysioc_tsk = NULL;
1508 * Save the dhd_info into the priv
1510 memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
1512 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
1515 #if defined(CONFIG_PM_SLEEP)
1516 atomic_set(&brcmf_mmc_suspend, false);
1517 #endif /* defined(CONFIG_PM_SLEEP) */
1518 /* && defined(DHD_GPL) */
1519 /* Init lock suspend to prevent kernel going to suspend */
1520 #ifdef CONFIG_HAS_EARLYSUSPEND
1521 drvr_priv->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
1522 drvr_priv->early_suspend.suspend = brcmf_early_suspend;
1523 drvr_priv->early_suspend.resume = brcmf_late_resume;
1524 register_early_suspend(&drvr_priv->early_suspend);
1527 return &drvr_priv->pub;
1533 brcmf_detach(&drvr_priv->pub);
1538 int brcmf_bus_start(dhd_pub_t *drvr)
1541 dhd_info_t *drvr_priv = drvr->info;
1542 /* Room for "event_msgs" + '\0' + bitvec */
1543 char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
1547 DHD_TRACE(("%s:\n", __func__));
1549 /* Bring up the bus */
1550 ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub, true);
1552 DHD_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__,
1557 /* If bus is not ready, can't come up */
1558 if (drvr_priv->pub.busstate != DHD_BUS_DATA) {
1559 DHD_ERROR(("%s failed bus is not ready\n", __func__));
1563 brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
1564 iovbuf, sizeof(iovbuf));
1565 brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
1567 memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
1569 setbit(drvr->eventmask, BRCMF_E_SET_SSID);
1570 setbit(drvr->eventmask, BRCMF_E_PRUNE);
1571 setbit(drvr->eventmask, BRCMF_E_AUTH);
1572 setbit(drvr->eventmask, BRCMF_E_REASSOC);
1573 setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
1574 setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
1575 setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
1576 setbit(drvr->eventmask, BRCMF_E_DISASSOC);
1577 setbit(drvr->eventmask, BRCMF_E_JOIN);
1578 setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
1579 setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
1580 setbit(drvr->eventmask, BRCMF_E_LINK);
1581 setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
1582 setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
1583 setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
1584 setbit(drvr->eventmask, BRCMF_E_TXFAIL);
1585 setbit(drvr->eventmask, BRCMF_E_JOIN_START);
1586 setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
1588 /* enable dongle roaming event */
1590 drvr->pktfilter_count = 1;
1591 /* Setup filter to allow only unicast */
1592 drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
1594 /* Bus is ready, do any protocol initialization */
1595 ret = brcmf_proto_init(&drvr_priv->pub);
1602 int brcmf_iovar(dhd_pub_t *drvr, int ifidx, char *name, char *cmd_buf,
1603 uint cmd_len, int set)
1605 char buf[strlen(name) + 1 + cmd_len];
1606 int len = sizeof(buf);
1607 struct brcmf_ioctl ioc;
1610 len = brcmu_mkiovar(name, cmd_buf, cmd_len, buf, len);
1612 memset(&ioc, 0, sizeof(ioc));
1614 ioc.cmd = set ? BRCMF_C_SET_VAR : BRCMF_C_GET_VAR;
1619 ret = brcmf_proto_ioctl(drvr, ifidx, &ioc, ioc.buf, ioc.len);
1620 if (!set && ret >= 0)
1621 memcpy(cmd_buf, buf, cmd_len);
1626 static struct net_device_ops brcmf_netdev_ops_pri = {
1627 .ndo_open = brcmf_netdev_open,
1628 .ndo_stop = brcmf_netdev_stop,
1629 .ndo_get_stats = brcmf_netdev_get_stats,
1630 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
1631 .ndo_start_xmit = brcmf_netdev_start_xmit,
1632 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
1633 .ndo_set_multicast_list = brcmf_netdev_set_multicast_list
1636 int brcmf_net_attach(dhd_pub_t *drvr, int ifidx)
1638 dhd_info_t *drvr_priv = drvr->info;
1639 struct net_device *net;
1640 u8 temp_addr[ETH_ALEN] = {
1641 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
1643 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1645 ASSERT(drvr_priv && drvr_priv->iflist[ifidx]);
1647 net = drvr_priv->iflist[ifidx]->net;
1650 ASSERT(!net->netdev_ops);
1651 net->netdev_ops = &brcmf_netdev_ops_pri;
1654 * We have to use the primary MAC for virtual interfaces
1657 /* for virtual interfaces use the primary MAC */
1658 memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
1663 DHD_TRACE(("%s ACCESS POINT MAC:\n", __func__));
1664 /* ACCESSPOINT INTERFACE CASE */
1665 temp_addr[0] |= 0X02; /* set bit 2 ,
1666 - Locally Administered address */
1669 net->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
1670 net->ethtool_ops = &brcmf_ethtool_ops;
1672 drvr_priv->pub.rxsz = net->mtu + net->hard_header_len +
1673 drvr_priv->pub.hdrlen;
1675 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
1677 if (register_netdev(net) != 0) {
1678 DHD_ERROR(("%s: couldn't register the net device\n",
1683 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
1688 net->netdev_ops = NULL;
1692 static void brcmf_bus_detach(dhd_pub_t *drvr)
1694 dhd_info_t *drvr_priv;
1696 DHD_TRACE(("%s: Enter\n", __func__));
1699 drvr_priv = drvr->info;
1701 /* Stop the protocol module */
1702 brcmf_proto_stop(&drvr_priv->pub);
1704 /* Stop the bus module */
1705 brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus, true);
1710 void brcmf_detach(dhd_pub_t *drvr)
1712 dhd_info_t *drvr_priv;
1714 DHD_TRACE(("%s: Enter\n", __func__));
1717 drvr_priv = drvr->info;
1722 #if defined(CONFIG_HAS_EARLYSUSPEND)
1723 if (drvr_priv->early_suspend.suspend)
1724 unregister_early_suspend(
1725 &drvr_priv->early_suspend);
1726 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
1728 for (i = 1; i < BRCMF_MAX_IFS; i++)
1729 if (drvr_priv->iflist[i])
1730 brcmf_del_if(drvr_priv, i);
1732 ifp = drvr_priv->iflist[0];
1734 if (ifp->net->netdev_ops == &brcmf_netdev_ops_pri) {
1735 brcmf_netdev_stop(ifp->net);
1736 unregister_netdev(ifp->net);
1739 if (drvr_priv->sysioc_tsk) {
1740 send_sig(SIGTERM, drvr_priv->sysioc_tsk, 1);
1741 kthread_stop(drvr_priv->sysioc_tsk);
1742 drvr_priv->sysioc_tsk = NULL;
1745 brcmf_bus_detach(drvr);
1748 brcmf_proto_detach(drvr);
1750 wl_cfg80211_detach();
1752 /* && defined(DHD_GPL) */
1753 free_netdev(ifp->net);
1760 static void __exit brcmf_module_cleanup(void)
1762 DHD_TRACE(("%s: Enter\n", __func__));
1764 dhd_bus_unregister();
1767 static int __init brcmf_module_init(void)
1771 DHD_TRACE(("%s: Enter\n", __func__));
1773 error = dhd_bus_register();
1776 DHD_ERROR(("%s: dhd_bus_register failed\n", __func__));
1785 module_init(brcmf_module_init);
1786 module_exit(brcmf_module_cleanup);
1789 * OS specific functions required to implement DHD driver in OS independent way
1791 int brcmf_os_proto_block(dhd_pub_t *drvr)
1793 dhd_info_t *drvr_priv = drvr->info;
1796 down(&drvr_priv->proto_sem);
1802 int brcmf_os_proto_unblock(dhd_pub_t *drvr)
1804 dhd_info_t *drvr_priv = drvr->info;
1807 up(&drvr_priv->proto_sem);
1814 unsigned int brcmf_os_get_ioctl_resp_timeout(void)
1816 return (unsigned int)brcmf_ioctl_timeout_msec;
1819 void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
1821 brcmf_ioctl_timeout_msec = (int)timeout_msec;
1824 int brcmf_os_ioctl_resp_wait(dhd_pub_t *drvr, uint *condition, bool *pending)
1826 dhd_info_t *drvr_priv = drvr->info;
1827 DECLARE_WAITQUEUE(wait, current);
1828 int timeout = brcmf_ioctl_timeout_msec;
1830 /* Convert timeout in millsecond to jiffies */
1831 timeout = timeout * HZ / 1000;
1833 /* Wait until control frame is available */
1834 add_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
1835 set_current_state(TASK_INTERRUPTIBLE);
1837 while (!(*condition) && (!signal_pending(current) && timeout))
1838 timeout = schedule_timeout(timeout);
1840 if (signal_pending(current))
1843 set_current_state(TASK_RUNNING);
1844 remove_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
1849 int brcmf_os_ioctl_resp_wake(dhd_pub_t *drvr)
1851 dhd_info_t *drvr_priv = drvr->info;
1853 if (waitqueue_active(&drvr_priv->ioctl_resp_wait))
1854 wake_up_interruptible(&drvr_priv->ioctl_resp_wait);
1859 static int brcmf_host_event(dhd_info_t *drvr_priv, int *ifidx, void *pktdata,
1860 brcmf_event_msg_t *event, void **data)
1864 ASSERT(drvr_priv != NULL);
1866 bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
1870 ASSERT(drvr_priv->iflist[*ifidx] != NULL);
1871 ASSERT(drvr_priv->iflist[*ifidx]->net != NULL);
1872 if (drvr_priv->iflist[*ifidx]->net)
1873 wl_cfg80211_event(drvr_priv->iflist[*ifidx]->net, event, *data);
1878 int brcmf_netdev_reset(struct net_device *dev, u8 flag)
1880 dhd_info_t *drvr_priv = *(dhd_info_t **)netdev_priv(dev);
1882 brcmf_bus_devreset(&drvr_priv->pub, flag);
1887 int brcmf_netdev_set_suspend_disable(struct net_device *dev, int val)
1889 dhd_info_t *drvr_priv = *(dhd_info_t **)netdev_priv(dev);
1893 ret = drvr_priv->pub.suspend_disable_flag;
1894 drvr_priv->pub.suspend_disable_flag = val;
1899 int brcmf_netdev_set_suspend(struct net_device *dev, int val)
1902 #if defined(CONFIG_HAS_EARLYSUSPEND)
1903 dhd_info_t *drvr_priv = *(dhd_info_t **)netdev_priv(dev);
1906 brcmf_os_proto_block(&drvr_priv->pub);
1907 ret = brcmf_set_suspend(val, &drvr_priv->pub);
1908 brcmf_os_proto_unblock(&drvr_priv->pub);
1910 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
1914 int brcmf_netdev_set_dtim_skip(struct net_device *dev, int val)
1916 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(dev);
1919 drvr_priv->pub.dtim_skip = val;
1924 int brcmf_netdev_set_packet_filter(struct net_device *dev, int val)
1926 dhd_info_t *drvr_priv = *(dhd_info_t **) netdev_priv(dev);
1929 /* Packet filtering is set only if we still in early-suspend and
1930 * we need either to turn it ON or turn it OFF
1931 * We can always turn it OFF in case of early-suspend, but we turn it
1932 * back ON only if suspend_disable_flag was not set
1934 if (drvr_priv && drvr_priv->pub.up) {
1935 brcmf_os_proto_block(&drvr_priv->pub);
1936 if (drvr_priv->pub.in_suspend) {
1937 if (!val || (val && !drvr_priv->pub.suspend_disable_flag))
1938 brcmf_set_packet_filter(val, &drvr_priv->pub);
1940 brcmf_os_proto_unblock(&drvr_priv->pub);
1945 void brcmf_netdev_init_ioctl(struct net_device *dev)
1947 dhd_info_t *drvr_priv = *(dhd_info_t **)netdev_priv(dev);
1949 brcmf_c_preinit_ioctls(&drvr_priv->pub);
1952 static int brcmf_get_pend_8021x_cnt(dhd_info_t *drvr_priv)
1954 return atomic_read(&drvr_priv->pend_8021x_cnt);
1957 #define MAX_WAIT_FOR_8021X_TX 10
1959 int brcmf_netdev_wait_pend8021x(struct net_device *dev)
1961 dhd_info_t *drvr_priv = *(dhd_info_t **)netdev_priv(dev);
1962 int timeout = 10 * HZ / 1000;
1963 int ntimes = MAX_WAIT_FOR_8021X_TX;
1964 int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
1966 while (ntimes && pend) {
1968 set_current_state(TASK_INTERRUPTIBLE);
1969 schedule_timeout(timeout);
1970 set_current_state(TASK_RUNNING);
1973 pend = brcmf_get_pend_8021x_cnt(drvr_priv);
1979 int brcmf_write_to_file(dhd_pub_t *drvr, u8 *buf, int size)
1983 mm_segment_t old_fs;
1986 /* change to KERNEL_DS address limit */
1990 /* open file to write */
1991 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
1993 DHD_ERROR(("%s: open file error\n", __func__));
1998 /* Write buf to file */
1999 fp->f_op->write(fp, buf, size, &pos);
2002 /* free buf before return */
2004 /* close file before return */
2006 filp_close(fp, current->files);
2007 /* restore previous address limit */
2015 void osl_assert(char *exp, char *file, int line)
2020 basename = strrchr(file, '/');
2028 snprintf(tempbuf, 256,
2029 "assertion \"%s\" failed: file \"%s\", line %d\n", exp,
2033 * Print assert message and give it time to
2034 * be written to /var/log/messages
2036 if (!in_interrupt()) {
2037 const int delay = 3;
2038 printk(KERN_ERR "%s", tempbuf);
2039 printk(KERN_ERR "panic in %d seconds\n", delay);
2040 set_current_state(TASK_INTERRUPTIBLE);
2041 schedule_timeout(delay * HZ);
2044 switch (g_assert_type) {
2046 panic(KERN_ERR "%s", tempbuf);
2049 printk(KERN_ERR "%s", tempbuf);
2053 printk(KERN_ERR "%s", tempbuf);
2059 #endif /* defined(BCMDBG) */