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 <linux/hardirq.h>
32 #include <linux/mutex.h>
33 #include <net/cfg80211.h>
35 #include <brcmu_utils.h>
36 #include <brcmu_wifi.h>
40 #include "dhd_proto.h"
42 #include "wl_cfg80211.h"
45 #if defined(CONFIG_PM_SLEEP)
46 #include <linux/suspend.h>
47 atomic_t brcmf_mmc_suspend;
48 #endif /* defined(CONFIG_PM_SLEEP) */
50 MODULE_AUTHOR("Broadcom Corporation");
51 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
52 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
53 MODULE_LICENSE("Dual BSD/GPL");
56 /* Interface control information */
58 struct brcmf_info *info; /* back pointer to brcmf_info */
59 /* OS/stack specifics */
60 struct net_device *net;
61 struct net_device_stats stats;
62 int idx; /* iface idx in dongle */
63 int state; /* interface state */
64 uint subunit; /* subunit */
65 u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
66 bool attached; /* Delayed attachment when unset */
67 bool txflowcontrol; /* Per interface flow control indicator */
68 char name[IFNAMSIZ]; /* linux interface name */
71 /* Local private structure (extension of pub) */
75 /* OS/stack specifics */
76 struct brcmf_if *iflist[BRCMF_MAX_IFS];
78 struct mutex proto_block;
79 wait_queue_head_t ioctl_resp_wait;
81 /* Thread to issue ioctl for multicast */
82 struct task_struct *sysioc_tsk;
83 struct semaphore sysioc_sem;
86 u8 macvalue[ETH_ALEN];
87 atomic_t pend_8021x_cnt;
91 module_param(brcmf_msg_level, int, 0);
93 /* Spawn a thread for system ioctls (set mac, set mcast) */
94 uint brcmf_sysioc = true;
95 module_param(brcmf_sysioc, uint, 0);
97 /* ARP offload agent mode : Enable ARP Host Auto-Reply
98 and ARP Peer Auto-Reply */
99 uint brcmf_arp_mode = 0xb;
100 module_param(brcmf_arp_mode, uint, 0);
102 /* ARP offload enable */
103 uint brcmf_arp_enable = true;
104 module_param(brcmf_arp_enable, uint, 0);
106 /* Global Pkt filter enable control */
107 uint brcmf_pkt_filter_enable = true;
108 module_param(brcmf_pkt_filter_enable, uint, 0);
110 /* Pkt filter init setup */
111 uint brcmf_pkt_filter_init;
112 module_param(brcmf_pkt_filter_init, uint, 0);
114 /* Pkt filter mode control */
115 uint brcmf_master_mode = true;
116 module_param(brcmf_master_mode, uint, 0);
118 /* Contorl fw roaming */
121 /* Control radio state */
122 uint brcmf_radio_up = 1;
124 /* Network inteface name */
125 char iface_name[IFNAMSIZ] = "wlan";
126 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
128 /* The following are specific to the SDIO dongle */
130 /* IOCTL response timeout */
131 int brcmf_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
134 /* Echo packet generator (pkts/s) */
136 module_param(brcmf_pktgen, uint, 0);
138 /* Echo packet len (0 => sawtooth, max 2040) */
139 uint brcmf_pktgen_len;
140 module_param(brcmf_pktgen_len, uint, 0);
143 static int brcmf_toe_get(struct brcmf_info *drvr_priv, int idx, u32 *toe_ol);
144 static int brcmf_toe_set(struct brcmf_info *drvr_priv, int idx, u32 toe_ol);
145 static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
146 struct brcmf_event_msg *event_ptr,
150 * Generalized timeout mechanism. Uses spin sleep with exponential
152 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
154 * brcmf_timeout_start(&tmo, usec);
155 * while (!brcmf_timeout_expired(&tmo))
156 * if (poll_something())
158 * if (brcmf_timeout_expired(&tmo))
162 void brcmf_timeout_start(struct brcmf_timeout *tmo, uint usec)
167 tmo->tick = 1000000 / HZ;
170 int brcmf_timeout_expired(struct brcmf_timeout *tmo)
172 /* Does nothing the first call */
173 if (tmo->increment == 0) {
178 if (tmo->elapsed >= tmo->limit)
181 /* Add the delay that's about to take place */
182 tmo->elapsed += tmo->increment;
184 if (tmo->increment < tmo->tick) {
185 udelay(tmo->increment);
187 if (tmo->increment > tmo->tick)
188 tmo->increment = tmo->tick;
190 wait_queue_head_t delay_wait;
191 DECLARE_WAITQUEUE(wait, current);
193 init_waitqueue_head(&delay_wait);
194 add_wait_queue(&delay_wait, &wait);
195 set_current_state(TASK_INTERRUPTIBLE);
197 pending = signal_pending(current);
198 remove_wait_queue(&delay_wait, &wait);
199 set_current_state(TASK_RUNNING);
201 return 1; /* Interrupted */
207 static int brcmf_net2idx(struct brcmf_info *drvr_priv, struct net_device *net)
211 while (i < BRCMF_MAX_IFS) {
212 if (drvr_priv->iflist[i] && (drvr_priv->iflist[i]->net == net))
220 int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name)
222 int i = BRCMF_MAX_IFS;
224 if (name == NULL || *name == '\0')
228 if (drvr_priv->iflist[i]
229 && !strncmp(drvr_priv->iflist[i]->name, name, IFNAMSIZ))
232 BRCMF_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
234 return i; /* default - the primary interface */
237 char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
239 struct brcmf_info *drvr_priv = drvr->info;
241 if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
242 BRCMF_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
246 if (drvr_priv->iflist[ifidx] == NULL) {
247 BRCMF_ERROR(("%s: null i/f %d\n", __func__, ifidx));
251 if (drvr_priv->iflist[ifidx]->net)
252 return drvr_priv->iflist[ifidx]->net->name;
257 static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx)
259 struct net_device *dev;
260 struct netdev_hw_addr *ha;
263 struct brcmf_ioctl ioc;
268 dev = drvr_priv->iflist[ifidx]->net;
269 cnt = netdev_mc_count(dev);
271 /* Determine initial value of allmulti flag */
272 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
274 /* Send down the multicast list first. */
276 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
277 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
279 BRCMF_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
280 brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
284 strcpy(bufp, "mcast_list");
285 bufp += strlen("mcast_list") + 1;
287 cnt = cpu_to_le32(cnt);
288 memcpy(bufp, &cnt, sizeof(cnt));
291 netdev_for_each_mc_addr(ha, dev) {
294 memcpy(bufp, ha->addr, ETH_ALEN);
299 memset(&ioc, 0, sizeof(ioc));
300 ioc.cmd = BRCMF_C_SET_VAR;
305 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
307 BRCMF_ERROR(("%s: set mcast_list failed, cnt %d\n",
308 brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
309 allmulti = cnt ? true : allmulti;
314 /* Now send the allmulti setting. This is based on the setting in the
315 * net_device flags, but might be modified above to be turned on if we
316 * were trying to set some addresses and dongle rejected it...
319 buflen = sizeof("allmulti") + sizeof(allmulti);
320 buf = kmalloc(buflen, GFP_ATOMIC);
322 BRCMF_ERROR(("%s: out of memory for allmulti\n",
323 brcmf_ifname(&drvr_priv->pub, ifidx)));
326 allmulti = cpu_to_le32(allmulti);
329 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
330 BRCMF_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
332 brcmf_ifname(&drvr_priv->pub, ifidx),
333 (int)sizeof(allmulti), buflen));
338 memset(&ioc, 0, sizeof(ioc));
339 ioc.cmd = BRCMF_C_SET_VAR;
344 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
346 BRCMF_ERROR(("%s: set allmulti %d failed\n",
347 brcmf_ifname(&drvr_priv->pub, ifidx),
348 le32_to_cpu(allmulti)));
353 /* Finally, pick up the PROMISC flag as well, like the NIC
356 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
357 allmulti = cpu_to_le32(allmulti);
359 memset(&ioc, 0, sizeof(ioc));
360 ioc.cmd = BRCMF_C_SET_PROMISC;
362 ioc.len = sizeof(allmulti);
365 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
367 BRCMF_ERROR(("%s: set promisc %d failed\n",
368 brcmf_ifname(&drvr_priv->pub, ifidx),
369 le32_to_cpu(allmulti)));
373 static int _brcmf_set_mac_address(struct brcmf_info *drvr_priv, int ifidx, u8 *addr)
376 struct brcmf_ioctl ioc;
379 BRCMF_TRACE(("%s enter\n", __func__));
381 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
382 BRCMF_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
383 brcmf_ifname(&drvr_priv->pub, ifidx)));
386 memset(&ioc, 0, sizeof(ioc));
387 ioc.cmd = BRCMF_C_SET_VAR;
392 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
394 BRCMF_ERROR(("%s: set cur_etheraddr failed\n",
395 brcmf_ifname(&drvr_priv->pub, ifidx)));
397 memcpy(drvr_priv->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
403 static struct net_device *ap_net_dev;
406 /* Virtual interfaces only ((ifp && ifp->info && ifp->idx == true) */
407 static void brcmf_op_if(struct brcmf_if *ifp)
409 struct brcmf_info *drvr_priv;
410 int ret = 0, err = 0;
412 drvr_priv = ifp->info;
414 BRCMF_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
416 switch (ifp->state) {
419 * Delete the existing interface before overwriting it
420 * in case we missed the BRCMF_E_IF_DEL event.
422 if (ifp->net != NULL) {
423 BRCMF_ERROR(("%s: ERROR: netdev:%s already exists, "
424 "try free & unregister\n",
425 __func__, ifp->net->name));
426 netif_stop_queue(ifp->net);
427 unregister_netdev(ifp->net);
428 free_netdev(ifp->net);
430 /* Allocate etherdev, including space for private structure */
431 ifp->net = alloc_etherdev(sizeof(drvr_priv));
433 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
437 strcpy(ifp->net->name, ifp->name);
438 memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv));
439 err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
441 BRCMF_ERROR(("%s: brcmf_net_attach failed, "
447 /* semaphore that the soft AP CODE
449 struct semaphore ap_eth_sema;
451 /* save ptr to wl0.1 netdev for use
453 ap_net_dev = ifp->net;
454 /* signal to the SOFTAP 'sleeper' thread,
458 BRCMF_TRACE(("\n ==== pid:%x, net_device for "
459 "if:%s created ===\n\n",
460 current->pid, ifp->net->name));
466 if (ifp->net != NULL) {
467 BRCMF_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
469 netif_stop_queue(ifp->net);
470 unregister_netdev(ifp->net);
471 ret = BRCMF_DEL_IF; /* Make sure the free_netdev()
476 BRCMF_ERROR(("%s: bad op %d\n", __func__, ifp->state));
482 free_netdev(ifp->net);
484 drvr_priv->iflist[ifp->idx] = NULL;
487 if (ifp->net == ap_net_dev)
488 ap_net_dev = NULL; /* NULL SOFTAP global
494 static int _brcmf_sysioc_thread(void *data)
496 struct brcmf_info *drvr_priv = (struct brcmf_info *) data;
502 allow_signal(SIGTERM);
504 while (down_interruptible(&drvr_priv->sysioc_sem) == 0) {
505 if (kthread_should_stop())
507 for (i = 0; i < BRCMF_MAX_IFS; i++) {
508 struct brcmf_if *ifentry = drvr_priv->iflist[i];
511 in_ap = (ap_net_dev != NULL);
514 brcmf_op_if(ifentry);
516 if (drvr_priv->iflist[i] == NULL) {
517 BRCMF_TRACE(("\n\n %s: interface %d "
518 "removed!\n", __func__,
523 if (in_ap && drvr_priv->set_macaddress) {
524 BRCMF_TRACE(("attempt to set MAC for"
527 ifentry->net->name));
528 drvr_priv->set_macaddress = false;
532 if (in_ap && drvr_priv->set_multicast) {
533 BRCMF_TRACE(("attempt to set MULTICAST "
534 "list for %s in AP Mode, "
536 ifentry->net->name));
537 drvr_priv->set_multicast = false;
541 if (drvr_priv->set_multicast) {
542 drvr_priv->set_multicast = false;
543 _brcmf_set_multicast_list(drvr_priv, i);
545 if (drvr_priv->set_macaddress) {
546 drvr_priv->set_macaddress = false;
547 _brcmf_set_mac_address(drvr_priv, i,
548 drvr_priv->macvalue);
556 static int brcmf_netdev_set_mac_address(struct net_device *dev, void *addr)
560 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
561 struct sockaddr *sa = (struct sockaddr *)addr;
564 ifidx = brcmf_net2idx(drvr_priv, dev);
565 if (ifidx == BRCMF_BAD_IF)
568 memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN);
569 drvr_priv->set_macaddress = true;
570 up(&drvr_priv->sysioc_sem);
575 static void brcmf_netdev_set_multicast_list(struct net_device *dev)
577 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
580 ifidx = brcmf_net2idx(drvr_priv, dev);
581 if (ifidx == BRCMF_BAD_IF)
584 drvr_priv->set_multicast = true;
585 up(&drvr_priv->sysioc_sem);
588 int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf)
590 struct brcmf_info *drvr_priv = drvr->info;
593 if (!drvr->up || (drvr->busstate == BRCMF_BUS_DOWN))
596 /* Update multicast statistic */
597 if (pktbuf->len >= ETH_ALEN) {
598 u8 *pktdata = (u8 *) (pktbuf->data);
599 struct ethhdr *eh = (struct ethhdr *)pktdata;
601 if (is_multicast_ether_addr(eh->h_dest))
602 drvr->tx_multicast++;
603 if (ntohs(eh->h_proto) == ETH_P_PAE)
604 atomic_inc(&drvr_priv->pend_8021x_cnt);
607 /* If the protocol uses a data header, apply it */
608 brcmf_proto_hdrpush(drvr, ifidx, pktbuf);
610 /* Use bus module to send data frame */
611 return brcmf_sdbrcm_bus_txdata(drvr->bus, pktbuf);
614 static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *net)
617 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
620 BRCMF_TRACE(("%s: Enter\n", __func__));
623 if (!drvr_priv->pub.up || (drvr_priv->pub.busstate == BRCMF_BUS_DOWN)) {
624 BRCMF_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
625 __func__, drvr_priv->pub.up,
626 drvr_priv->pub.busstate));
627 netif_stop_queue(net);
631 ifidx = brcmf_net2idx(drvr_priv, net);
632 if (ifidx == BRCMF_BAD_IF) {
633 BRCMF_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
634 netif_stop_queue(net);
638 /* Make sure there's enough room for any header */
639 if (skb_headroom(skb) < drvr_priv->pub.hdrlen) {
640 struct sk_buff *skb2;
642 BRCMF_INFO(("%s: insufficient headroom\n",
643 brcmf_ifname(&drvr_priv->pub, ifidx)));
644 drvr_priv->pub.tx_realloc++;
645 skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen);
649 BRCMF_ERROR(("%s: skb_realloc_headroom failed\n",
650 brcmf_ifname(&drvr_priv->pub, ifidx)));
656 ret = brcmf_sendpkt(&drvr_priv->pub, ifidx, skb);
660 drvr_priv->pub.dstats.tx_dropped++;
662 drvr_priv->pub.tx_packets++;
664 /* Return ok: we always eat the packet */
668 void brcmf_txflowcontrol(struct brcmf_pub *drvr, int ifidx, bool state)
670 struct net_device *net;
671 struct brcmf_info *drvr_priv = drvr->info;
673 BRCMF_TRACE(("%s: Enter\n", __func__));
676 net = drvr_priv->iflist[ifidx]->net;
678 netif_stop_queue(net);
680 netif_wake_queue(net);
683 void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
686 struct brcmf_info *drvr_priv = drvr->info;
690 struct sk_buff *pnext, *save_pktbuf;
692 struct brcmf_if *ifp;
693 struct brcmf_event_msg event;
695 BRCMF_TRACE(("%s: Enter\n", __func__));
699 for (i = 0; skb && i < numpkt; i++, skb = pnext) {
704 /* Get the protocol, maintain skb around eth_type_trans()
705 * The main reason for this hack is for the limitation of
706 * Linux 2.4 where 'eth_type_trans' uses the
707 * 'net->hard_header_len'
708 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
709 * coping of the packet coming from the network stack to add
710 * BDC, Hardware header etc, during network interface
712 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
714 * for BDC, Hardware header etc. and not just the ETH_HLEN
719 ifp = drvr_priv->iflist[ifidx];
721 ifp = drvr_priv->iflist[0];
724 skb->protocol = eth_type_trans(skb, skb->dev);
726 if (skb->pkt_type == PACKET_MULTICAST)
727 drvr_priv->pub.rx_multicast++;
732 /* Strip header, count, deliver upward */
733 skb_pull(skb, ETH_HLEN);
735 /* Process special event packets and then discard them */
736 if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
737 brcmf_host_event(drvr_priv, &ifidx,
741 if (drvr_priv->iflist[ifidx] &&
742 !drvr_priv->iflist[ifidx]->state)
743 ifp = drvr_priv->iflist[ifidx];
746 ifp->net->last_rx = jiffies;
748 drvr->dstats.rx_bytes += skb->len;
749 drvr->rx_packets++; /* Local count */
754 /* If the receive is not processed inside an ISR,
755 * the softirqd must be woken explicitly to service
756 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
757 * by netif_rx_ni(), but in earlier kernels, we need
764 void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp, bool success)
767 struct brcmf_info *drvr_priv = drvr->info;
771 brcmf_proto_hdrpull(drvr, &ifidx, txp);
773 eh = (struct ethhdr *)(txp->data);
774 type = ntohs(eh->h_proto);
776 if (type == ETH_P_PAE)
777 atomic_dec(&drvr_priv->pend_8021x_cnt);
781 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *net)
783 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
784 struct brcmf_if *ifp;
787 BRCMF_TRACE(("%s: Enter\n", __func__));
789 ifidx = brcmf_net2idx(drvr_priv, net);
790 if (ifidx == BRCMF_BAD_IF)
793 ifp = drvr_priv->iflist[ifidx];
795 if (drvr_priv->pub.up)
796 /* Use the protocol to get dongle stats */
797 brcmf_proto_dstats(&drvr_priv->pub);
799 /* Copy dongle stats to net device stats */
800 ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets;
801 ifp->stats.tx_packets = drvr_priv->pub.dstats.tx_packets;
802 ifp->stats.rx_bytes = drvr_priv->pub.dstats.rx_bytes;
803 ifp->stats.tx_bytes = drvr_priv->pub.dstats.tx_bytes;
804 ifp->stats.rx_errors = drvr_priv->pub.dstats.rx_errors;
805 ifp->stats.tx_errors = drvr_priv->pub.dstats.tx_errors;
806 ifp->stats.rx_dropped = drvr_priv->pub.dstats.rx_dropped;
807 ifp->stats.tx_dropped = drvr_priv->pub.dstats.tx_dropped;
808 ifp->stats.multicast = drvr_priv->pub.dstats.multicast;
813 /* Retrieve current toe component enables, which are kept
814 as a bitmap in toe_ol iovar */
815 static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol)
817 struct brcmf_ioctl ioc;
821 memset(&ioc, 0, sizeof(ioc));
823 ioc.cmd = BRCMF_C_GET_VAR;
825 ioc.len = (uint) sizeof(buf);
828 strcpy(buf, "toe_ol");
829 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
831 /* Check for older dongle image that doesn't support toe_ol */
833 BRCMF_ERROR(("%s: toe not supported by device\n",
834 brcmf_ifname(&drvr_priv->pub, ifidx)));
838 BRCMF_INFO(("%s: could not get toe_ol: ret=%d\n",
839 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
843 memcpy(toe_ol, buf, sizeof(u32));
847 /* Set current toe component enables in toe_ol iovar,
848 and set toe global enable iovar */
849 static int brcmf_toe_set(struct brcmf_info *drvr_priv, int ifidx, u32 toe_ol)
851 struct brcmf_ioctl ioc;
855 memset(&ioc, 0, sizeof(ioc));
857 ioc.cmd = BRCMF_C_SET_VAR;
859 ioc.len = (uint) sizeof(buf);
862 /* Set toe_ol as requested */
864 strcpy(buf, "toe_ol");
865 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
867 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
869 BRCMF_ERROR(("%s: could not set toe_ol: ret=%d\n",
870 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
874 /* Enable toe globally only if any components are enabled. */
879 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
881 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
883 BRCMF_ERROR(("%s: could not set toe: ret=%d\n",
884 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
891 static void brcmf_ethtool_get_drvinfo(struct net_device *net,
892 struct ethtool_drvinfo *info)
894 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
896 sprintf(info->driver, KBUILD_MODNAME);
897 sprintf(info->version, "%lu", drvr_priv->pub.drv_version);
898 sprintf(info->fw_version, "%s", BCM4329_FW_NAME);
899 sprintf(info->bus_info, "%s",
900 dev_name(&brcmf_cfg80211_get_sdio_func()->dev));
903 struct ethtool_ops brcmf_ethtool_ops = {
904 .get_drvinfo = brcmf_ethtool_get_drvinfo
907 static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
909 struct ethtool_drvinfo info;
910 char drvname[sizeof(info.driver)];
912 struct ethtool_value edata;
913 u32 toe_cmpnt, csum_dir;
916 BRCMF_TRACE(("%s: Enter\n", __func__));
918 /* all ethtool calls start with a cmd word */
919 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
923 case ETHTOOL_GDRVINFO:
924 /* Copy out any request driver name */
925 if (copy_from_user(&info, uaddr, sizeof(info)))
927 strncpy(drvname, info.driver, sizeof(info.driver));
928 drvname[sizeof(info.driver) - 1] = '\0';
930 /* clear struct for return */
931 memset(&info, 0, sizeof(info));
934 /* if requested, identify ourselves */
935 if (strcmp(drvname, "?dhd") == 0) {
936 sprintf(info.driver, "dhd");
937 strcpy(info.version, BRCMF_VERSION_STR);
940 /* otherwise, require dongle to be up */
941 else if (!drvr_priv->pub.up) {
942 BRCMF_ERROR(("%s: dongle is not up\n", __func__));
946 /* finally, report dongle driver type */
947 else if (drvr_priv->pub.iswl)
948 sprintf(info.driver, "wl");
950 sprintf(info.driver, "xx");
952 sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
953 if (copy_to_user(uaddr, &info, sizeof(info)))
955 BRCMF_CTL(("%s: given %*s, returning %s\n", __func__,
956 (int)sizeof(drvname), drvname, info.driver));
959 /* Get toe offload components from dongle */
960 case ETHTOOL_GRXCSUM:
961 case ETHTOOL_GTXCSUM:
962 ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
967 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
970 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
972 if (copy_to_user(uaddr, &edata, sizeof(edata)))
976 /* Set toe offload components in dongle */
977 case ETHTOOL_SRXCSUM:
978 case ETHTOOL_STXCSUM:
979 if (copy_from_user(&edata, uaddr, sizeof(edata)))
982 /* Read the current settings, update and write back */
983 ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
988 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
991 toe_cmpnt |= csum_dir;
993 toe_cmpnt &= ~csum_dir;
995 ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt);
999 /* If setting TX checksum mode, tell Linux the new mode */
1000 if (cmd == ETHTOOL_STXCSUM) {
1002 drvr_priv->iflist[0]->net->features |=
1005 drvr_priv->iflist[0]->net->features &=
1018 static int brcmf_netdev_ioctl_entry(struct net_device *net, struct ifreq *ifr,
1021 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
1022 struct brcmf_c_ioctl ioc;
1028 bool is_set_key_cmd;
1030 ifidx = brcmf_net2idx(drvr_priv, net);
1031 BRCMF_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1033 if (ifidx == BRCMF_BAD_IF)
1036 if (cmd == SIOCETHTOOL)
1037 return brcmf_ethtool(drvr_priv, (void *)ifr->ifr_data);
1039 if (cmd != SIOCDEVPRIVATE)
1042 memset(&ioc, 0, sizeof(ioc));
1044 /* Copy the ioc control structure part of ioctl request */
1045 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(struct brcmf_ioctl))) {
1050 /* Copy out any buffer passed */
1052 buflen = min_t(int, ioc.len, BRCMF_IOCTL_MAXLEN);
1053 /* optimization for direct ioctl calls from kernel */
1055 if (segment_eq(get_fs(), KERNEL_DS)) {
1060 buf = kmalloc(buflen, GFP_ATOMIC);
1065 if (copy_from_user(buf, ioc.buf, buflen)) {
1072 /* To differentiate read 4 more byes */
1073 if ((copy_from_user(&driver, (char *)ifr->ifr_data +
1074 sizeof(struct brcmf_ioctl), sizeof(uint)) != 0)) {
1079 if (!capable(CAP_NET_ADMIN)) {
1084 /* check for local brcmf ioctl and handle it */
1085 if (driver == BRCMF_IOCTL_MAGIC) {
1086 bcmerror = brcmf_c_ioctl((void *)&drvr_priv->pub, &ioc, buf, buflen);
1088 drvr_priv->pub.bcmerror = bcmerror;
1092 /* send to dongle (must be up, and wl) */
1093 if ((drvr_priv->pub.busstate != BRCMF_BUS_DATA)) {
1094 BRCMF_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1099 if (!drvr_priv->pub.iswl) {
1105 * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
1106 * set key IOCTL to prevent M4 encryption.
1108 is_set_key_cmd = ((ioc.cmd == BRCMF_C_SET_KEY) ||
1109 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1110 !(strncmp("wsec_key", ioc.buf, 9))) ||
1111 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1112 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1114 brcmf_netdev_wait_pend8021x(net);
1117 brcmf_proto_ioctl(&drvr_priv->pub, ifidx, (struct brcmf_ioctl *)&ioc,
1121 if (!bcmerror && buf && ioc.buf) {
1122 if (copy_to_user(ioc.buf, buf, buflen))
1134 static int brcmf_netdev_stop(struct net_device *net)
1136 #if !defined(IGNORE_ETH0_DOWN)
1137 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
1139 BRCMF_TRACE(("%s: Enter\n", __func__));
1140 brcmf_cfg80211_down();
1141 if (drvr_priv->pub.up == 0)
1144 /* Set state and stop OS transmissions */
1145 drvr_priv->pub.up = 0;
1146 netif_stop_queue(net);
1148 BRCMF_ERROR(("BYPASS %s:due to BRCM compilation: under investigation\n",
1150 #endif /* !defined(IGNORE_ETH0_DOWN) */
1155 static int brcmf_netdev_open(struct net_device *net)
1157 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
1159 int ifidx = brcmf_net2idx(drvr_priv, net);
1162 BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1164 if (ifidx == 0) { /* do it only for primary eth0 */
1166 /* try to bring up bus */
1167 ret = brcmf_bus_start(&drvr_priv->pub);
1169 BRCMF_ERROR(("%s: failed with code %d\n",
1173 atomic_set(&drvr_priv->pend_8021x_cnt, 0);
1175 memcpy(net->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
1177 /* Get current TOE mode from dongle */
1178 if (brcmf_toe_get(drvr_priv, ifidx, &toe_ol) >= 0
1179 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1180 drvr_priv->iflist[ifidx]->net->features |=
1183 drvr_priv->iflist[ifidx]->net->features &=
1186 /* Allow transmit calls */
1187 netif_start_queue(net);
1188 drvr_priv->pub.up = 1;
1189 if (unlikely(brcmf_cfg80211_up())) {
1190 BRCMF_ERROR(("%s: failed to bring up cfg80211\n",
1199 brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, void *handle, char *name,
1200 u8 *mac_addr, u32 flags, u8 bssidx)
1202 struct brcmf_if *ifp;
1204 BRCMF_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1206 ifp = drvr_priv->iflist[ifidx];
1208 ifp = kmalloc(sizeof(struct brcmf_if), GFP_ATOMIC);
1210 BRCMF_ERROR(("%s: OOM - struct brcmf_if\n", __func__));
1215 memset(ifp, 0, sizeof(struct brcmf_if));
1216 ifp->info = drvr_priv;
1217 drvr_priv->iflist[ifidx] = ifp;
1218 strlcpy(ifp->name, name, IFNAMSIZ);
1219 if (mac_addr != NULL)
1220 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1222 if (handle == NULL) {
1223 ifp->state = BRCMF_E_IF_ADD;
1225 up(&drvr_priv->sysioc_sem);
1227 ifp->net = (struct net_device *)handle;
1232 void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx)
1234 struct brcmf_if *ifp;
1236 BRCMF_TRACE(("%s: idx %d\n", __func__, ifidx));
1238 ifp = drvr_priv->iflist[ifidx];
1240 BRCMF_ERROR(("%s: Null interface\n", __func__));
1244 ifp->state = BRCMF_E_IF_DEL;
1246 up(&drvr_priv->sysioc_sem);
1249 struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
1251 struct brcmf_info *drvr_priv = NULL;
1252 struct net_device *net;
1254 BRCMF_TRACE(("%s: Enter\n", __func__));
1256 /* Allocate etherdev, including space for private structure */
1257 net = alloc_etherdev(sizeof(drvr_priv));
1259 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1263 /* Allocate primary brcmf_info */
1264 drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC);
1266 BRCMF_ERROR(("%s: OOM - alloc brcmf_info\n", __func__));
1271 * Save the brcmf_info into the priv
1273 memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
1275 /* Set network interface name if it was provided as module parameter */
1276 if (iface_name[0]) {
1279 strncpy(net->name, iface_name, IFNAMSIZ);
1280 net->name[IFNAMSIZ - 1] = 0;
1281 len = strlen(net->name);
1282 ch = net->name[len - 1];
1283 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1284 strcat(net->name, "%d");
1287 if (brcmf_add_if(drvr_priv, 0, (void *)net, net->name, NULL, 0, 0) ==
1291 net->netdev_ops = NULL;
1292 mutex_init(&drvr_priv->proto_block);
1293 /* Initialize other structure content */
1294 init_waitqueue_head(&drvr_priv->ioctl_resp_wait);
1296 /* Link to info module */
1297 drvr_priv->pub.info = drvr_priv;
1299 /* Link to bus module */
1300 drvr_priv->pub.bus = bus;
1301 drvr_priv->pub.hdrlen = bus_hdrlen;
1303 /* Attach and link in the protocol */
1304 if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
1305 BRCMF_ERROR(("brcmf_prot_attach failed\n"));
1309 /* Attach and link in the cfg80211 */
1310 if (unlikely(brcmf_cfg80211_attach(net, &drvr_priv->pub))) {
1311 BRCMF_ERROR(("wl_cfg80211_attach failed\n"));
1316 sema_init(&drvr_priv->sysioc_sem, 0);
1317 drvr_priv->sysioc_tsk = kthread_run(_brcmf_sysioc_thread, drvr_priv,
1319 if (IS_ERR(drvr_priv->sysioc_tsk)) {
1321 "_brcmf_sysioc thread failed to start\n");
1322 drvr_priv->sysioc_tsk = NULL;
1325 drvr_priv->sysioc_tsk = NULL;
1328 * Save the brcmf_info into the priv
1330 memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
1332 #if defined(CONFIG_PM_SLEEP)
1333 atomic_set(&brcmf_mmc_suspend, false);
1334 #endif /* defined(CONFIG_PM_SLEEP) */
1335 return &drvr_priv->pub;
1341 brcmf_detach(&drvr_priv->pub);
1346 int brcmf_bus_start(struct brcmf_pub *drvr)
1349 struct brcmf_info *drvr_priv = drvr->info;
1350 /* Room for "event_msgs" + '\0' + bitvec */
1351 char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
1353 BRCMF_TRACE(("%s:\n", __func__));
1355 /* Bring up the bus */
1356 ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub, true);
1358 BRCMF_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__,
1363 /* If bus is not ready, can't come up */
1364 if (drvr_priv->pub.busstate != BRCMF_BUS_DATA) {
1365 BRCMF_ERROR(("%s failed bus is not ready\n", __func__));
1369 brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
1370 iovbuf, sizeof(iovbuf));
1371 brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
1373 memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
1375 setbit(drvr->eventmask, BRCMF_E_SET_SSID);
1376 setbit(drvr->eventmask, BRCMF_E_PRUNE);
1377 setbit(drvr->eventmask, BRCMF_E_AUTH);
1378 setbit(drvr->eventmask, BRCMF_E_REASSOC);
1379 setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
1380 setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
1381 setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
1382 setbit(drvr->eventmask, BRCMF_E_DISASSOC);
1383 setbit(drvr->eventmask, BRCMF_E_JOIN);
1384 setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
1385 setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
1386 setbit(drvr->eventmask, BRCMF_E_LINK);
1387 setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
1388 setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
1389 setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
1390 setbit(drvr->eventmask, BRCMF_E_TXFAIL);
1391 setbit(drvr->eventmask, BRCMF_E_JOIN_START);
1392 setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
1394 /* enable dongle roaming event */
1396 drvr->pktfilter_count = 1;
1397 /* Setup filter to allow only unicast */
1398 drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
1400 /* Bus is ready, do any protocol initialization */
1401 ret = brcmf_proto_init(&drvr_priv->pub);
1408 static struct net_device_ops brcmf_netdev_ops_pri = {
1409 .ndo_open = brcmf_netdev_open,
1410 .ndo_stop = brcmf_netdev_stop,
1411 .ndo_get_stats = brcmf_netdev_get_stats,
1412 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
1413 .ndo_start_xmit = brcmf_netdev_start_xmit,
1414 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
1415 .ndo_set_multicast_list = brcmf_netdev_set_multicast_list
1418 int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
1420 struct brcmf_info *drvr_priv = drvr->info;
1421 struct net_device *net;
1422 u8 temp_addr[ETH_ALEN] = {
1423 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
1425 BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1427 net = drvr_priv->iflist[ifidx]->net;
1428 net->netdev_ops = &brcmf_netdev_ops_pri;
1431 * We have to use the primary MAC for virtual interfaces
1434 /* for virtual interfaces use the primary MAC */
1435 memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
1440 BRCMF_TRACE(("%s ACCESS POINT MAC:\n", __func__));
1441 /* ACCESSPOINT INTERFACE CASE */
1442 temp_addr[0] |= 0X02; /* set bit 2 ,
1443 - Locally Administered address */
1446 net->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
1447 net->ethtool_ops = &brcmf_ethtool_ops;
1449 drvr_priv->pub.rxsz = net->mtu + net->hard_header_len +
1450 drvr_priv->pub.hdrlen;
1452 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
1454 if (register_netdev(net) != 0) {
1455 BRCMF_ERROR(("%s: couldn't register the net device\n",
1460 BRCMF_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
1465 net->netdev_ops = NULL;
1469 static void brcmf_bus_detach(struct brcmf_pub *drvr)
1471 struct brcmf_info *drvr_priv;
1473 BRCMF_TRACE(("%s: Enter\n", __func__));
1476 drvr_priv = drvr->info;
1478 /* Stop the protocol module */
1479 brcmf_proto_stop(&drvr_priv->pub);
1481 /* Stop the bus module */
1482 brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus, true);
1487 void brcmf_detach(struct brcmf_pub *drvr)
1489 struct brcmf_info *drvr_priv;
1491 BRCMF_TRACE(("%s: Enter\n", __func__));
1494 drvr_priv = drvr->info;
1496 struct brcmf_if *ifp;
1499 for (i = 1; i < BRCMF_MAX_IFS; i++)
1500 if (drvr_priv->iflist[i])
1501 brcmf_del_if(drvr_priv, i);
1503 ifp = drvr_priv->iflist[0];
1504 if (ifp->net->netdev_ops == &brcmf_netdev_ops_pri) {
1505 brcmf_netdev_stop(ifp->net);
1506 unregister_netdev(ifp->net);
1509 if (drvr_priv->sysioc_tsk) {
1510 send_sig(SIGTERM, drvr_priv->sysioc_tsk, 1);
1511 kthread_stop(drvr_priv->sysioc_tsk);
1512 drvr_priv->sysioc_tsk = NULL;
1515 brcmf_bus_detach(drvr);
1518 brcmf_proto_detach(drvr);
1520 brcmf_cfg80211_detach();
1522 free_netdev(ifp->net);
1529 static void __exit brcmf_module_cleanup(void)
1531 BRCMF_TRACE(("%s: Enter\n", __func__));
1533 brcmf_bus_unregister();
1536 static int __init brcmf_module_init(void)
1540 BRCMF_TRACE(("%s: Enter\n", __func__));
1542 error = brcmf_bus_register();
1545 BRCMF_ERROR(("%s: brcmf_bus_register failed\n", __func__));
1554 module_init(brcmf_module_init);
1555 module_exit(brcmf_module_cleanup);
1557 int brcmf_os_proto_block(struct brcmf_pub *drvr)
1559 struct brcmf_info *drvr_priv = drvr->info;
1562 mutex_lock(&drvr_priv->proto_block);
1568 int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
1570 struct brcmf_info *drvr_priv = drvr->info;
1573 mutex_unlock(&drvr_priv->proto_block);
1580 unsigned int brcmf_os_get_ioctl_resp_timeout(void)
1582 return (unsigned int)brcmf_ioctl_timeout_msec;
1585 void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
1587 brcmf_ioctl_timeout_msec = (int)timeout_msec;
1590 int brcmf_os_ioctl_resp_wait(struct brcmf_pub *drvr, uint *condition,
1593 struct brcmf_info *drvr_priv = drvr->info;
1594 DECLARE_WAITQUEUE(wait, current);
1595 int timeout = brcmf_ioctl_timeout_msec;
1597 /* Convert timeout in millsecond to jiffies */
1598 timeout = timeout * HZ / 1000;
1600 /* Wait until control frame is available */
1601 add_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
1602 set_current_state(TASK_INTERRUPTIBLE);
1604 while (!(*condition) && (!signal_pending(current) && timeout))
1605 timeout = schedule_timeout(timeout);
1607 if (signal_pending(current))
1610 set_current_state(TASK_RUNNING);
1611 remove_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
1616 int brcmf_os_ioctl_resp_wake(struct brcmf_pub *drvr)
1618 struct brcmf_info *drvr_priv = drvr->info;
1620 if (waitqueue_active(&drvr_priv->ioctl_resp_wait))
1621 wake_up_interruptible(&drvr_priv->ioctl_resp_wait);
1626 static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
1627 struct brcmf_event_msg *event, void **data)
1631 bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
1635 if (drvr_priv->iflist[*ifidx]->net)
1636 brcmf_cfg80211_event(drvr_priv->iflist[*ifidx]->net,
1642 int brcmf_netdev_reset(struct net_device *dev, u8 flag)
1644 struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
1646 brcmf_bus_devreset(&drvr_priv->pub, flag);
1651 static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
1653 return atomic_read(&drvr_priv->pend_8021x_cnt);
1656 #define MAX_WAIT_FOR_8021X_TX 10
1658 int brcmf_netdev_wait_pend8021x(struct net_device *dev)
1660 struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
1661 int timeout = 10 * HZ / 1000;
1662 int ntimes = MAX_WAIT_FOR_8021X_TX;
1663 int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
1665 while (ntimes && pend) {
1667 set_current_state(TASK_INTERRUPTIBLE);
1668 schedule_timeout(timeout);
1669 set_current_state(TASK_RUNNING);
1672 pend = brcmf_get_pend_8021x_cnt(drvr_priv);
1678 int brcmf_write_to_file(struct brcmf_pub *drvr, u8 *buf, int size)
1682 mm_segment_t old_fs;
1685 /* change to KERNEL_DS address limit */
1689 /* open file to write */
1690 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
1692 BRCMF_ERROR(("%s: open file error\n", __func__));
1697 /* Write buf to file */
1698 fp->f_op->write(fp, buf, size, &pos);
1701 /* free buf before return */
1703 /* close file before return */
1705 filp_close(fp, current->files);
1706 /* restore previous address limit */