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 module_param(brcmf_dongle_memsize, int, 0);
120 /* Contorl fw roaming */
123 /* Control radio state */
124 uint brcmf_radio_up = 1;
126 /* Network inteface name */
127 char iface_name[IFNAMSIZ] = "wlan";
128 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
130 /* The following are specific to the SDIO dongle */
132 /* IOCTL response timeout */
133 int brcmf_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
135 /* Idle timeout for backplane clock */
136 int brcmf_idletime = BRCMF_IDLETIME_TICKS;
137 module_param(brcmf_idletime, int, 0);
141 module_param(brcmf_poll, uint, 0);
144 uint brcmf_intr = true;
145 module_param(brcmf_intr, uint, 0);
147 /* SDIO Drive Strength (in milliamps) */
148 uint brcmf_sdiod_drive_strength = 6;
149 module_param(brcmf_sdiod_drive_strength, uint, 0);
152 module_param(brcmf_txbound, uint, 0);
153 module_param(brcmf_rxbound, uint, 0);
156 /* Echo packet generator (pkts/s) */
158 module_param(brcmf_pktgen, uint, 0);
160 /* Echo packet len (0 => sawtooth, max 2040) */
161 uint brcmf_pktgen_len;
162 module_param(brcmf_pktgen_len, uint, 0);
165 static int brcmf_toe_get(struct brcmf_info *drvr_priv, int idx, u32 *toe_ol);
166 static int brcmf_toe_set(struct brcmf_info *drvr_priv, int idx, u32 toe_ol);
167 static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
168 struct brcmf_event_msg *event_ptr,
172 * Generalized timeout mechanism. Uses spin sleep with exponential
174 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
176 * brcmf_timeout_start(&tmo, usec);
177 * while (!brcmf_timeout_expired(&tmo))
178 * if (poll_something())
180 * if (brcmf_timeout_expired(&tmo))
184 void brcmf_timeout_start(struct brcmf_timeout *tmo, uint usec)
189 tmo->tick = 1000000 / HZ;
192 int brcmf_timeout_expired(struct brcmf_timeout *tmo)
194 /* Does nothing the first call */
195 if (tmo->increment == 0) {
200 if (tmo->elapsed >= tmo->limit)
203 /* Add the delay that's about to take place */
204 tmo->elapsed += tmo->increment;
206 if (tmo->increment < tmo->tick) {
207 udelay(tmo->increment);
209 if (tmo->increment > tmo->tick)
210 tmo->increment = tmo->tick;
212 wait_queue_head_t delay_wait;
213 DECLARE_WAITQUEUE(wait, current);
215 init_waitqueue_head(&delay_wait);
216 add_wait_queue(&delay_wait, &wait);
217 set_current_state(TASK_INTERRUPTIBLE);
219 pending = signal_pending(current);
220 remove_wait_queue(&delay_wait, &wait);
221 set_current_state(TASK_RUNNING);
223 return 1; /* Interrupted */
229 static int brcmf_net2idx(struct brcmf_info *drvr_priv, struct net_device *net)
233 while (i < BRCMF_MAX_IFS) {
234 if (drvr_priv->iflist[i] && (drvr_priv->iflist[i]->net == net))
242 int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name)
244 int i = BRCMF_MAX_IFS;
246 if (name == NULL || *name == '\0')
250 if (drvr_priv->iflist[i]
251 && !strncmp(drvr_priv->iflist[i]->name, name, IFNAMSIZ))
254 BRCMF_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
256 return i; /* default - the primary interface */
259 char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
261 struct brcmf_info *drvr_priv = drvr->info;
263 if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
264 BRCMF_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
268 if (drvr_priv->iflist[ifidx] == NULL) {
269 BRCMF_ERROR(("%s: null i/f %d\n", __func__, ifidx));
273 if (drvr_priv->iflist[ifidx]->net)
274 return drvr_priv->iflist[ifidx]->net->name;
279 static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx)
281 struct net_device *dev;
282 struct netdev_hw_addr *ha;
285 struct brcmf_ioctl ioc;
290 dev = drvr_priv->iflist[ifidx]->net;
291 cnt = netdev_mc_count(dev);
293 /* Determine initial value of allmulti flag */
294 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
296 /* Send down the multicast list first. */
298 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
299 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
301 BRCMF_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
302 brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
306 strcpy(bufp, "mcast_list");
307 bufp += strlen("mcast_list") + 1;
309 cnt = cpu_to_le32(cnt);
310 memcpy(bufp, &cnt, sizeof(cnt));
313 netdev_for_each_mc_addr(ha, dev) {
316 memcpy(bufp, ha->addr, ETH_ALEN);
321 memset(&ioc, 0, sizeof(ioc));
322 ioc.cmd = BRCMF_C_SET_VAR;
327 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
329 BRCMF_ERROR(("%s: set mcast_list failed, cnt %d\n",
330 brcmf_ifname(&drvr_priv->pub, ifidx), cnt));
331 allmulti = cnt ? true : allmulti;
336 /* Now send the allmulti setting. This is based on the setting in the
337 * net_device flags, but might be modified above to be turned on if we
338 * were trying to set some addresses and dongle rejected it...
341 buflen = sizeof("allmulti") + sizeof(allmulti);
342 buf = kmalloc(buflen, GFP_ATOMIC);
344 BRCMF_ERROR(("%s: out of memory for allmulti\n",
345 brcmf_ifname(&drvr_priv->pub, ifidx)));
348 allmulti = cpu_to_le32(allmulti);
351 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
352 BRCMF_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
354 brcmf_ifname(&drvr_priv->pub, ifidx),
355 (int)sizeof(allmulti), buflen));
360 memset(&ioc, 0, sizeof(ioc));
361 ioc.cmd = BRCMF_C_SET_VAR;
366 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
368 BRCMF_ERROR(("%s: set allmulti %d failed\n",
369 brcmf_ifname(&drvr_priv->pub, ifidx),
370 le32_to_cpu(allmulti)));
375 /* Finally, pick up the PROMISC flag as well, like the NIC
378 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
379 allmulti = cpu_to_le32(allmulti);
381 memset(&ioc, 0, sizeof(ioc));
382 ioc.cmd = BRCMF_C_SET_PROMISC;
384 ioc.len = sizeof(allmulti);
387 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
389 BRCMF_ERROR(("%s: set promisc %d failed\n",
390 brcmf_ifname(&drvr_priv->pub, ifidx),
391 le32_to_cpu(allmulti)));
395 static int _brcmf_set_mac_address(struct brcmf_info *drvr_priv, int ifidx, u8 *addr)
398 struct brcmf_ioctl ioc;
401 BRCMF_TRACE(("%s enter\n", __func__));
403 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
404 BRCMF_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
405 brcmf_ifname(&drvr_priv->pub, ifidx)));
408 memset(&ioc, 0, sizeof(ioc));
409 ioc.cmd = BRCMF_C_SET_VAR;
414 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
416 BRCMF_ERROR(("%s: set cur_etheraddr failed\n",
417 brcmf_ifname(&drvr_priv->pub, ifidx)));
419 memcpy(drvr_priv->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
426 extern struct net_device *ap_net_dev;
429 /* Virtual interfaces only ((ifp && ifp->info && ifp->idx == true) */
430 static void brcmf_op_if(struct brcmf_if *ifp)
432 struct brcmf_info *drvr_priv;
433 int ret = 0, err = 0;
435 drvr_priv = ifp->info;
437 BRCMF_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
439 switch (ifp->state) {
442 * Delete the existing interface before overwriting it
443 * in case we missed the BRCMF_E_IF_DEL event.
445 if (ifp->net != NULL) {
446 BRCMF_ERROR(("%s: ERROR: netdev:%s already exists, "
447 "try free & unregister\n",
448 __func__, ifp->net->name));
449 netif_stop_queue(ifp->net);
450 unregister_netdev(ifp->net);
451 free_netdev(ifp->net);
453 /* Allocate etherdev, including space for private structure */
454 ifp->net = alloc_etherdev(sizeof(drvr_priv));
456 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
460 strcpy(ifp->net->name, ifp->name);
461 memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv));
462 err = brcmf_net_attach(&drvr_priv->pub, ifp->idx);
464 BRCMF_ERROR(("%s: brcmf_net_attach failed, "
470 /* semaphore that the soft AP CODE
472 extern struct semaphore ap_eth_sema;
474 /* save ptr to wl0.1 netdev for use
476 ap_net_dev = ifp->net;
477 /* signal to the SOFTAP 'sleeper' thread,
481 BRCMF_TRACE(("\n ==== pid:%x, net_device for "
482 "if:%s created ===\n\n",
483 current->pid, ifp->net->name));
489 if (ifp->net != NULL) {
490 BRCMF_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
492 netif_stop_queue(ifp->net);
493 unregister_netdev(ifp->net);
494 ret = BRCMF_DEL_IF; /* Make sure the free_netdev()
499 BRCMF_ERROR(("%s: bad op %d\n", __func__, ifp->state));
505 free_netdev(ifp->net);
507 drvr_priv->iflist[ifp->idx] = NULL;
510 if (ifp->net == ap_net_dev)
511 ap_net_dev = NULL; /* NULL SOFTAP global
517 static int _brcmf_sysioc_thread(void *data)
519 struct brcmf_info *drvr_priv = (struct brcmf_info *) data;
525 allow_signal(SIGTERM);
527 while (down_interruptible(&drvr_priv->sysioc_sem) == 0) {
528 if (kthread_should_stop())
530 for (i = 0; i < BRCMF_MAX_IFS; i++) {
531 struct brcmf_if *ifentry = drvr_priv->iflist[i];
534 in_ap = (ap_net_dev != NULL);
537 brcmf_op_if(ifentry);
539 if (drvr_priv->iflist[i] == NULL) {
540 BRCMF_TRACE(("\n\n %s: interface %d "
541 "removed!\n", __func__,
546 if (in_ap && drvr_priv->set_macaddress) {
547 BRCMF_TRACE(("attempt to set MAC for"
550 ifentry->net->name));
551 drvr_priv->set_macaddress = false;
555 if (in_ap && drvr_priv->set_multicast) {
556 BRCMF_TRACE(("attempt to set MULTICAST "
557 "list for %s in AP Mode, "
559 ifentry->net->name));
560 drvr_priv->set_multicast = false;
564 if (drvr_priv->set_multicast) {
565 drvr_priv->set_multicast = false;
566 _brcmf_set_multicast_list(drvr_priv, i);
568 if (drvr_priv->set_macaddress) {
569 drvr_priv->set_macaddress = false;
570 _brcmf_set_mac_address(drvr_priv, i,
571 drvr_priv->macvalue);
579 static int brcmf_netdev_set_mac_address(struct net_device *dev, void *addr)
583 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
584 struct sockaddr *sa = (struct sockaddr *)addr;
587 ifidx = brcmf_net2idx(drvr_priv, dev);
588 if (ifidx == BRCMF_BAD_IF)
591 memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN);
592 drvr_priv->set_macaddress = true;
593 up(&drvr_priv->sysioc_sem);
598 static void brcmf_netdev_set_multicast_list(struct net_device *dev)
600 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev);
603 ifidx = brcmf_net2idx(drvr_priv, dev);
604 if (ifidx == BRCMF_BAD_IF)
607 drvr_priv->set_multicast = true;
608 up(&drvr_priv->sysioc_sem);
611 int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf)
613 struct brcmf_info *drvr_priv = drvr->info;
616 if (!drvr->up || (drvr->busstate == BRCMF_BUS_DOWN))
619 /* Update multicast statistic */
620 if (pktbuf->len >= ETH_ALEN) {
621 u8 *pktdata = (u8 *) (pktbuf->data);
622 struct ethhdr *eh = (struct ethhdr *)pktdata;
624 if (is_multicast_ether_addr(eh->h_dest))
625 drvr->tx_multicast++;
626 if (ntohs(eh->h_proto) == ETH_P_PAE)
627 atomic_inc(&drvr_priv->pend_8021x_cnt);
630 /* If the protocol uses a data header, apply it */
631 brcmf_proto_hdrpush(drvr, ifidx, pktbuf);
633 /* Use bus module to send data frame */
634 return brcmf_sdbrcm_bus_txdata(drvr->bus, pktbuf);
637 static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *net)
640 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
643 BRCMF_TRACE(("%s: Enter\n", __func__));
646 if (!drvr_priv->pub.up || (drvr_priv->pub.busstate == BRCMF_BUS_DOWN)) {
647 BRCMF_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
648 __func__, drvr_priv->pub.up,
649 drvr_priv->pub.busstate));
650 netif_stop_queue(net);
654 ifidx = brcmf_net2idx(drvr_priv, net);
655 if (ifidx == BRCMF_BAD_IF) {
656 BRCMF_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
657 netif_stop_queue(net);
661 /* Make sure there's enough room for any header */
662 if (skb_headroom(skb) < drvr_priv->pub.hdrlen) {
663 struct sk_buff *skb2;
665 BRCMF_INFO(("%s: insufficient headroom\n",
666 brcmf_ifname(&drvr_priv->pub, ifidx)));
667 drvr_priv->pub.tx_realloc++;
668 skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen);
672 BRCMF_ERROR(("%s: skb_realloc_headroom failed\n",
673 brcmf_ifname(&drvr_priv->pub, ifidx)));
679 ret = brcmf_sendpkt(&drvr_priv->pub, ifidx, skb);
683 drvr_priv->pub.dstats.tx_dropped++;
685 drvr_priv->pub.tx_packets++;
687 /* Return ok: we always eat the packet */
691 void brcmf_txflowcontrol(struct brcmf_pub *drvr, int ifidx, bool state)
693 struct net_device *net;
694 struct brcmf_info *drvr_priv = drvr->info;
696 BRCMF_TRACE(("%s: Enter\n", __func__));
699 net = drvr_priv->iflist[ifidx]->net;
701 netif_stop_queue(net);
703 netif_wake_queue(net);
706 void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb,
709 struct brcmf_info *drvr_priv = drvr->info;
713 struct sk_buff *pnext, *save_pktbuf;
715 struct brcmf_if *ifp;
716 struct brcmf_event_msg event;
718 BRCMF_TRACE(("%s: Enter\n", __func__));
722 for (i = 0; skb && i < numpkt; i++, skb = pnext) {
727 /* Get the protocol, maintain skb around eth_type_trans()
728 * The main reason for this hack is for the limitation of
729 * Linux 2.4 where 'eth_type_trans' uses the
730 * 'net->hard_header_len'
731 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
732 * coping of the packet coming from the network stack to add
733 * BDC, Hardware header etc, during network interface
735 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
737 * for BDC, Hardware header etc. and not just the ETH_HLEN
742 ifp = drvr_priv->iflist[ifidx];
744 ifp = drvr_priv->iflist[0];
747 skb->protocol = eth_type_trans(skb, skb->dev);
749 if (skb->pkt_type == PACKET_MULTICAST)
750 drvr_priv->pub.rx_multicast++;
755 /* Strip header, count, deliver upward */
756 skb_pull(skb, ETH_HLEN);
758 /* Process special event packets and then discard them */
759 if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
760 brcmf_host_event(drvr_priv, &ifidx,
764 if (drvr_priv->iflist[ifidx] &&
765 !drvr_priv->iflist[ifidx]->state)
766 ifp = drvr_priv->iflist[ifidx];
769 ifp->net->last_rx = jiffies;
771 drvr->dstats.rx_bytes += skb->len;
772 drvr->rx_packets++; /* Local count */
774 if (in_interrupt()) {
777 /* If the receive is not processed inside an ISR,
778 * the softirqd must be woken explicitly to service
779 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
780 * by netif_rx_ni(), but in earlier kernels, we need
788 void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp, bool success)
791 struct brcmf_info *drvr_priv = drvr->info;
795 brcmf_proto_hdrpull(drvr, &ifidx, txp);
797 eh = (struct ethhdr *)(txp->data);
798 type = ntohs(eh->h_proto);
800 if (type == ETH_P_PAE)
801 atomic_dec(&drvr_priv->pend_8021x_cnt);
805 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *net)
807 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
808 struct brcmf_if *ifp;
811 BRCMF_TRACE(("%s: Enter\n", __func__));
813 ifidx = brcmf_net2idx(drvr_priv, net);
814 if (ifidx == BRCMF_BAD_IF)
817 ifp = drvr_priv->iflist[ifidx];
819 if (drvr_priv->pub.up) {
820 /* Use the protocol to get dongle stats */
821 brcmf_proto_dstats(&drvr_priv->pub);
824 /* Copy dongle stats to net device stats */
825 ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets;
826 ifp->stats.tx_packets = drvr_priv->pub.dstats.tx_packets;
827 ifp->stats.rx_bytes = drvr_priv->pub.dstats.rx_bytes;
828 ifp->stats.tx_bytes = drvr_priv->pub.dstats.tx_bytes;
829 ifp->stats.rx_errors = drvr_priv->pub.dstats.rx_errors;
830 ifp->stats.tx_errors = drvr_priv->pub.dstats.tx_errors;
831 ifp->stats.rx_dropped = drvr_priv->pub.dstats.rx_dropped;
832 ifp->stats.tx_dropped = drvr_priv->pub.dstats.tx_dropped;
833 ifp->stats.multicast = drvr_priv->pub.dstats.multicast;
838 /* Retrieve current toe component enables, which are kept
839 as a bitmap in toe_ol iovar */
840 static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol)
842 struct brcmf_ioctl ioc;
846 memset(&ioc, 0, sizeof(ioc));
848 ioc.cmd = BRCMF_C_GET_VAR;
850 ioc.len = (uint) sizeof(buf);
853 strcpy(buf, "toe_ol");
854 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
856 /* Check for older dongle image that doesn't support toe_ol */
858 BRCMF_ERROR(("%s: toe not supported by device\n",
859 brcmf_ifname(&drvr_priv->pub, ifidx)));
863 BRCMF_INFO(("%s: could not get toe_ol: ret=%d\n",
864 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
868 memcpy(toe_ol, buf, sizeof(u32));
872 /* Set current toe component enables in toe_ol iovar,
873 and set toe global enable iovar */
874 static int brcmf_toe_set(struct brcmf_info *drvr_priv, int ifidx, u32 toe_ol)
876 struct brcmf_ioctl ioc;
880 memset(&ioc, 0, sizeof(ioc));
882 ioc.cmd = BRCMF_C_SET_VAR;
884 ioc.len = (uint) sizeof(buf);
887 /* Set toe_ol as requested */
889 strcpy(buf, "toe_ol");
890 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
892 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
894 BRCMF_ERROR(("%s: could not set toe_ol: ret=%d\n",
895 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
899 /* Enable toe globally only if any components are enabled. */
904 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
906 ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len);
908 BRCMF_ERROR(("%s: could not set toe: ret=%d\n",
909 brcmf_ifname(&drvr_priv->pub, ifidx), ret));
916 static void brcmf_ethtool_get_drvinfo(struct net_device *net,
917 struct ethtool_drvinfo *info)
919 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
921 sprintf(info->driver, KBUILD_MODNAME);
922 sprintf(info->version, "%lu", drvr_priv->pub.drv_version);
923 sprintf(info->fw_version, "%s", BCM4329_FW_NAME);
924 sprintf(info->bus_info, "%s",
925 dev_name(&brcmf_cfg80211_get_sdio_func()->dev));
928 struct ethtool_ops brcmf_ethtool_ops = {
929 .get_drvinfo = brcmf_ethtool_get_drvinfo
932 static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr)
934 struct ethtool_drvinfo info;
935 char drvname[sizeof(info.driver)];
937 struct ethtool_value edata;
938 u32 toe_cmpnt, csum_dir;
941 BRCMF_TRACE(("%s: Enter\n", __func__));
943 /* all ethtool calls start with a cmd word */
944 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
948 case ETHTOOL_GDRVINFO:
949 /* Copy out any request driver name */
950 if (copy_from_user(&info, uaddr, sizeof(info)))
952 strncpy(drvname, info.driver, sizeof(info.driver));
953 drvname[sizeof(info.driver) - 1] = '\0';
955 /* clear struct for return */
956 memset(&info, 0, sizeof(info));
959 /* if requested, identify ourselves */
960 if (strcmp(drvname, "?dhd") == 0) {
961 sprintf(info.driver, "dhd");
962 strcpy(info.version, BRCMF_VERSION_STR);
965 /* otherwise, require dongle to be up */
966 else if (!drvr_priv->pub.up) {
967 BRCMF_ERROR(("%s: dongle is not up\n", __func__));
971 /* finally, report dongle driver type */
972 else if (drvr_priv->pub.iswl)
973 sprintf(info.driver, "wl");
975 sprintf(info.driver, "xx");
977 sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
978 if (copy_to_user(uaddr, &info, sizeof(info)))
980 BRCMF_CTL(("%s: given %*s, returning %s\n", __func__,
981 (int)sizeof(drvname), drvname, info.driver));
984 /* Get toe offload components from dongle */
985 case ETHTOOL_GRXCSUM:
986 case ETHTOOL_GTXCSUM:
987 ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
992 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
995 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
997 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1001 /* Set toe offload components in dongle */
1002 case ETHTOOL_SRXCSUM:
1003 case ETHTOOL_STXCSUM:
1004 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1007 /* Read the current settings, update and write back */
1008 ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
1013 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1015 if (edata.data != 0)
1016 toe_cmpnt |= csum_dir;
1018 toe_cmpnt &= ~csum_dir;
1020 ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt);
1024 /* If setting TX checksum mode, tell Linux the new mode */
1025 if (cmd == ETHTOOL_STXCSUM) {
1027 drvr_priv->iflist[0]->net->features |=
1030 drvr_priv->iflist[0]->net->features &=
1043 static int brcmf_netdev_ioctl_entry(struct net_device *net, struct ifreq *ifr,
1046 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
1047 struct brcmf_c_ioctl ioc;
1053 bool is_set_key_cmd;
1055 ifidx = brcmf_net2idx(drvr_priv, net);
1056 BRCMF_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1058 if (ifidx == BRCMF_BAD_IF)
1061 if (cmd == SIOCETHTOOL)
1062 return brcmf_ethtool(drvr_priv, (void *)ifr->ifr_data);
1064 if (cmd != SIOCDEVPRIVATE)
1067 memset(&ioc, 0, sizeof(ioc));
1069 /* Copy the ioc control structure part of ioctl request */
1070 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(struct brcmf_ioctl))) {
1075 /* Copy out any buffer passed */
1077 buflen = min_t(int, ioc.len, BRCMF_IOCTL_MAXLEN);
1078 /* optimization for direct ioctl calls from kernel */
1080 if (segment_eq(get_fs(), KERNEL_DS)) {
1085 buf = kmalloc(buflen, GFP_ATOMIC);
1090 if (copy_from_user(buf, ioc.buf, buflen)) {
1097 /* To differentiate read 4 more byes */
1098 if ((copy_from_user(&driver, (char *)ifr->ifr_data +
1099 sizeof(struct brcmf_ioctl), sizeof(uint)) != 0)) {
1104 if (!capable(CAP_NET_ADMIN)) {
1109 /* check for local brcmf ioctl and handle it */
1110 if (driver == BRCMF_IOCTL_MAGIC) {
1111 bcmerror = brcmf_c_ioctl((void *)&drvr_priv->pub, &ioc, buf, buflen);
1113 drvr_priv->pub.bcmerror = bcmerror;
1117 /* send to dongle (must be up, and wl) */
1118 if ((drvr_priv->pub.busstate != BRCMF_BUS_DATA)) {
1119 BRCMF_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1124 if (!drvr_priv->pub.iswl) {
1130 * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
1131 * set key IOCTL to prevent M4 encryption.
1133 is_set_key_cmd = ((ioc.cmd == BRCMF_C_SET_KEY) ||
1134 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1135 !(strncmp("wsec_key", ioc.buf, 9))) ||
1136 ((ioc.cmd == BRCMF_C_SET_VAR) &&
1137 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1139 brcmf_netdev_wait_pend8021x(net);
1142 brcmf_proto_ioctl(&drvr_priv->pub, ifidx, (struct brcmf_ioctl *)&ioc,
1146 if (!bcmerror && buf && ioc.buf) {
1147 if (copy_to_user(ioc.buf, buf, buflen))
1159 static int brcmf_netdev_stop(struct net_device *net)
1161 #if !defined(IGNORE_ETH0_DOWN)
1162 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
1164 BRCMF_TRACE(("%s: Enter\n", __func__));
1165 brcmf_cfg80211_down();
1166 if (drvr_priv->pub.up == 0)
1169 /* Set state and stop OS transmissions */
1170 drvr_priv->pub.up = 0;
1171 netif_stop_queue(net);
1173 BRCMF_ERROR(("BYPASS %s:due to BRCM compilation: under investigation\n",
1175 #endif /* !defined(IGNORE_ETH0_DOWN) */
1180 static int brcmf_netdev_open(struct net_device *net)
1182 struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net);
1184 int ifidx = brcmf_net2idx(drvr_priv, net);
1187 BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1189 if (ifidx == 0) { /* do it only for primary eth0 */
1191 /* try to bring up bus */
1192 ret = brcmf_bus_start(&drvr_priv->pub);
1194 BRCMF_ERROR(("%s: failed with code %d\n",
1198 atomic_set(&drvr_priv->pend_8021x_cnt, 0);
1200 memcpy(net->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
1202 /* Get current TOE mode from dongle */
1203 if (brcmf_toe_get(drvr_priv, ifidx, &toe_ol) >= 0
1204 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1205 drvr_priv->iflist[ifidx]->net->features |=
1208 drvr_priv->iflist[ifidx]->net->features &=
1211 /* Allow transmit calls */
1212 netif_start_queue(net);
1213 drvr_priv->pub.up = 1;
1214 if (unlikely(brcmf_cfg80211_up())) {
1215 BRCMF_ERROR(("%s: failed to bring up cfg80211\n",
1224 brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, void *handle, char *name,
1225 u8 *mac_addr, u32 flags, u8 bssidx)
1227 struct brcmf_if *ifp;
1229 BRCMF_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1231 ifp = drvr_priv->iflist[ifidx];
1233 ifp = kmalloc(sizeof(struct brcmf_if), GFP_ATOMIC);
1235 BRCMF_ERROR(("%s: OOM - struct brcmf_if\n", __func__));
1240 memset(ifp, 0, sizeof(struct brcmf_if));
1241 ifp->info = drvr_priv;
1242 drvr_priv->iflist[ifidx] = ifp;
1243 strlcpy(ifp->name, name, IFNAMSIZ);
1244 if (mac_addr != NULL)
1245 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1247 if (handle == NULL) {
1248 ifp->state = BRCMF_E_IF_ADD;
1250 up(&drvr_priv->sysioc_sem);
1252 ifp->net = (struct net_device *)handle;
1257 void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx)
1259 struct brcmf_if *ifp;
1261 BRCMF_TRACE(("%s: idx %d\n", __func__, ifidx));
1263 ifp = drvr_priv->iflist[ifidx];
1265 BRCMF_ERROR(("%s: Null interface\n", __func__));
1269 ifp->state = BRCMF_E_IF_DEL;
1271 up(&drvr_priv->sysioc_sem);
1274 struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
1276 struct brcmf_info *drvr_priv = NULL;
1277 struct net_device *net;
1279 BRCMF_TRACE(("%s: Enter\n", __func__));
1281 /* Allocate etherdev, including space for private structure */
1282 net = alloc_etherdev(sizeof(drvr_priv));
1284 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1288 /* Allocate primary brcmf_info */
1289 drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC);
1291 BRCMF_ERROR(("%s: OOM - alloc brcmf_info\n", __func__));
1296 * Save the brcmf_info into the priv
1298 memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
1300 /* Set network interface name if it was provided as module parameter */
1301 if (iface_name[0]) {
1304 strncpy(net->name, iface_name, IFNAMSIZ);
1305 net->name[IFNAMSIZ - 1] = 0;
1306 len = strlen(net->name);
1307 ch = net->name[len - 1];
1308 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1309 strcat(net->name, "%d");
1312 if (brcmf_add_if(drvr_priv, 0, (void *)net, net->name, NULL, 0, 0) ==
1316 net->netdev_ops = NULL;
1317 mutex_init(&drvr_priv->proto_block);
1318 /* Initialize other structure content */
1319 init_waitqueue_head(&drvr_priv->ioctl_resp_wait);
1321 /* Link to info module */
1322 drvr_priv->pub.info = drvr_priv;
1324 /* Link to bus module */
1325 drvr_priv->pub.bus = bus;
1326 drvr_priv->pub.hdrlen = bus_hdrlen;
1328 /* Attach and link in the protocol */
1329 if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
1330 BRCMF_ERROR(("brcmf_prot_attach failed\n"));
1334 /* Attach and link in the cfg80211 */
1335 if (unlikely(brcmf_cfg80211_attach(net, &drvr_priv->pub))) {
1336 BRCMF_ERROR(("wl_cfg80211_attach failed\n"));
1341 sema_init(&drvr_priv->sysioc_sem, 0);
1342 drvr_priv->sysioc_tsk = kthread_run(_brcmf_sysioc_thread, drvr_priv,
1344 if (IS_ERR(drvr_priv->sysioc_tsk)) {
1346 "_brcmf_sysioc thread failed to start\n");
1347 drvr_priv->sysioc_tsk = NULL;
1350 drvr_priv->sysioc_tsk = NULL;
1353 * Save the brcmf_info into the priv
1355 memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv));
1357 #if defined(CONFIG_PM_SLEEP)
1358 atomic_set(&brcmf_mmc_suspend, false);
1359 #endif /* defined(CONFIG_PM_SLEEP) */
1360 return &drvr_priv->pub;
1366 brcmf_detach(&drvr_priv->pub);
1371 int brcmf_bus_start(struct brcmf_pub *drvr)
1374 struct brcmf_info *drvr_priv = drvr->info;
1375 /* Room for "event_msgs" + '\0' + bitvec */
1376 char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
1378 BRCMF_TRACE(("%s:\n", __func__));
1380 /* Bring up the bus */
1381 ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub, true);
1383 BRCMF_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__,
1388 /* If bus is not ready, can't come up */
1389 if (drvr_priv->pub.busstate != BRCMF_BUS_DATA) {
1390 BRCMF_ERROR(("%s failed bus is not ready\n", __func__));
1394 brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
1395 iovbuf, sizeof(iovbuf));
1396 brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
1398 memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
1400 setbit(drvr->eventmask, BRCMF_E_SET_SSID);
1401 setbit(drvr->eventmask, BRCMF_E_PRUNE);
1402 setbit(drvr->eventmask, BRCMF_E_AUTH);
1403 setbit(drvr->eventmask, BRCMF_E_REASSOC);
1404 setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
1405 setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
1406 setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
1407 setbit(drvr->eventmask, BRCMF_E_DISASSOC);
1408 setbit(drvr->eventmask, BRCMF_E_JOIN);
1409 setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
1410 setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
1411 setbit(drvr->eventmask, BRCMF_E_LINK);
1412 setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
1413 setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
1414 setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
1415 setbit(drvr->eventmask, BRCMF_E_TXFAIL);
1416 setbit(drvr->eventmask, BRCMF_E_JOIN_START);
1417 setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
1419 /* enable dongle roaming event */
1421 drvr->pktfilter_count = 1;
1422 /* Setup filter to allow only unicast */
1423 drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
1425 /* Bus is ready, do any protocol initialization */
1426 ret = brcmf_proto_init(&drvr_priv->pub);
1433 static struct net_device_ops brcmf_netdev_ops_pri = {
1434 .ndo_open = brcmf_netdev_open,
1435 .ndo_stop = brcmf_netdev_stop,
1436 .ndo_get_stats = brcmf_netdev_get_stats,
1437 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
1438 .ndo_start_xmit = brcmf_netdev_start_xmit,
1439 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
1440 .ndo_set_multicast_list = brcmf_netdev_set_multicast_list
1443 int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
1445 struct brcmf_info *drvr_priv = drvr->info;
1446 struct net_device *net;
1447 u8 temp_addr[ETH_ALEN] = {
1448 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
1450 BRCMF_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1452 net = drvr_priv->iflist[ifidx]->net;
1453 net->netdev_ops = &brcmf_netdev_ops_pri;
1456 * We have to use the primary MAC for virtual interfaces
1459 /* for virtual interfaces use the primary MAC */
1460 memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
1465 BRCMF_TRACE(("%s ACCESS POINT MAC:\n", __func__));
1466 /* ACCESSPOINT INTERFACE CASE */
1467 temp_addr[0] |= 0X02; /* set bit 2 ,
1468 - Locally Administered address */
1471 net->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
1472 net->ethtool_ops = &brcmf_ethtool_ops;
1474 drvr_priv->pub.rxsz = net->mtu + net->hard_header_len +
1475 drvr_priv->pub.hdrlen;
1477 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
1479 if (register_netdev(net) != 0) {
1480 BRCMF_ERROR(("%s: couldn't register the net device\n",
1485 BRCMF_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
1490 net->netdev_ops = NULL;
1494 static void brcmf_bus_detach(struct brcmf_pub *drvr)
1496 struct brcmf_info *drvr_priv;
1498 BRCMF_TRACE(("%s: Enter\n", __func__));
1501 drvr_priv = drvr->info;
1503 /* Stop the protocol module */
1504 brcmf_proto_stop(&drvr_priv->pub);
1506 /* Stop the bus module */
1507 brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus, true);
1512 void brcmf_detach(struct brcmf_pub *drvr)
1514 struct brcmf_info *drvr_priv;
1516 BRCMF_TRACE(("%s: Enter\n", __func__));
1519 drvr_priv = drvr->info;
1521 struct brcmf_if *ifp;
1524 for (i = 1; i < BRCMF_MAX_IFS; i++)
1525 if (drvr_priv->iflist[i])
1526 brcmf_del_if(drvr_priv, i);
1528 ifp = drvr_priv->iflist[0];
1529 if (ifp->net->netdev_ops == &brcmf_netdev_ops_pri) {
1530 brcmf_netdev_stop(ifp->net);
1531 unregister_netdev(ifp->net);
1534 if (drvr_priv->sysioc_tsk) {
1535 send_sig(SIGTERM, drvr_priv->sysioc_tsk, 1);
1536 kthread_stop(drvr_priv->sysioc_tsk);
1537 drvr_priv->sysioc_tsk = NULL;
1540 brcmf_bus_detach(drvr);
1543 brcmf_proto_detach(drvr);
1545 brcmf_cfg80211_detach();
1547 free_netdev(ifp->net);
1554 static void __exit brcmf_module_cleanup(void)
1556 BRCMF_TRACE(("%s: Enter\n", __func__));
1558 brcmf_bus_unregister();
1561 static int __init brcmf_module_init(void)
1565 BRCMF_TRACE(("%s: Enter\n", __func__));
1567 error = brcmf_bus_register();
1570 BRCMF_ERROR(("%s: brcmf_bus_register failed\n", __func__));
1579 module_init(brcmf_module_init);
1580 module_exit(brcmf_module_cleanup);
1582 int brcmf_os_proto_block(struct brcmf_pub *drvr)
1584 struct brcmf_info *drvr_priv = drvr->info;
1587 mutex_lock(&drvr_priv->proto_block);
1593 int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
1595 struct brcmf_info *drvr_priv = drvr->info;
1598 mutex_unlock(&drvr_priv->proto_block);
1605 unsigned int brcmf_os_get_ioctl_resp_timeout(void)
1607 return (unsigned int)brcmf_ioctl_timeout_msec;
1610 void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
1612 brcmf_ioctl_timeout_msec = (int)timeout_msec;
1615 int brcmf_os_ioctl_resp_wait(struct brcmf_pub *drvr, uint *condition,
1618 struct brcmf_info *drvr_priv = drvr->info;
1619 DECLARE_WAITQUEUE(wait, current);
1620 int timeout = brcmf_ioctl_timeout_msec;
1622 /* Convert timeout in millsecond to jiffies */
1623 timeout = timeout * HZ / 1000;
1625 /* Wait until control frame is available */
1626 add_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
1627 set_current_state(TASK_INTERRUPTIBLE);
1629 while (!(*condition) && (!signal_pending(current) && timeout))
1630 timeout = schedule_timeout(timeout);
1632 if (signal_pending(current))
1635 set_current_state(TASK_RUNNING);
1636 remove_wait_queue(&drvr_priv->ioctl_resp_wait, &wait);
1641 int brcmf_os_ioctl_resp_wake(struct brcmf_pub *drvr)
1643 struct brcmf_info *drvr_priv = drvr->info;
1645 if (waitqueue_active(&drvr_priv->ioctl_resp_wait))
1646 wake_up_interruptible(&drvr_priv->ioctl_resp_wait);
1651 static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata,
1652 struct brcmf_event_msg *event, void **data)
1656 bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
1660 if (drvr_priv->iflist[*ifidx]->net)
1661 brcmf_cfg80211_event(drvr_priv->iflist[*ifidx]->net,
1667 int brcmf_netdev_reset(struct net_device *dev, u8 flag)
1669 struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
1671 brcmf_bus_devreset(&drvr_priv->pub, flag);
1676 static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
1678 return atomic_read(&drvr_priv->pend_8021x_cnt);
1681 #define MAX_WAIT_FOR_8021X_TX 10
1683 int brcmf_netdev_wait_pend8021x(struct net_device *dev)
1685 struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev);
1686 int timeout = 10 * HZ / 1000;
1687 int ntimes = MAX_WAIT_FOR_8021X_TX;
1688 int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
1690 while (ntimes && pend) {
1692 set_current_state(TASK_INTERRUPTIBLE);
1693 schedule_timeout(timeout);
1694 set_current_state(TASK_RUNNING);
1697 pend = brcmf_get_pend_8021x_cnt(drvr_priv);
1703 int brcmf_write_to_file(struct brcmf_pub *drvr, u8 *buf, int size)
1707 mm_segment_t old_fs;
1710 /* change to KERNEL_DS address limit */
1714 /* open file to write */
1715 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
1717 BRCMF_ERROR(("%s: open file error\n", __func__));
1722 /* Write buf to file */
1723 fp->f_op->write(fp, buf, size, &pos);
1726 /* free buf before return */
1728 /* close file before return */
1730 filp_close(fp, current->files);
1731 /* restore previous address limit */