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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/kthread.h>
22 #include <linux/slab.h>
23 #include <linux/skbuff.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/mmc/sdio_func.h>
27 #include <linux/random.h>
28 #include <linux/spinlock.h>
29 #include <linux/ethtool.h>
30 #include <linux/fcntl.h>
32 #include <linux/uaccess.h>
33 #include <linux/hardirq.h>
34 #include <linux/mutex.h>
35 #include <linux/wait.h>
36 #include <linux/module.h>
37 #include <net/cfg80211.h>
38 #include <net/rtnetlink.h>
40 #include <brcmu_utils.h>
41 #include <brcmu_wifi.h>
45 #include "dhd_proto.h"
47 #include "wl_cfg80211.h"
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");
55 #define MAX_WAIT_FOR_8021X_TX 50 /* msecs */
58 int brcmf_msg_level = BRCMF_ERROR_VAL;
59 module_param(brcmf_msg_level, int, 0);
61 int brcmf_ifname2idx(struct brcmf_pub *drvr, char *name)
63 int i = BRCMF_MAX_IFS;
66 if (name == NULL || *name == '\0')
70 ifp = drvr->iflist[i];
71 if (ifp && !strncmp(ifp->ndev->name, name, IFNAMSIZ))
75 brcmf_dbg(TRACE, "return idx %d for \"%s\"\n", i, name);
77 return i; /* default - the primary interface */
80 char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
82 if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
83 brcmf_dbg(ERROR, "ifidx %d out of range\n", ifidx);
87 if (drvr->iflist[ifidx] == NULL) {
88 brcmf_dbg(ERROR, "null i/f %d\n", ifidx);
92 if (drvr->iflist[ifidx]->ndev)
93 return drvr->iflist[ifidx]->ndev->name;
98 static void _brcmf_set_multicast_list(struct work_struct *work)
100 struct brcmf_if *ifp;
101 struct net_device *ndev;
102 struct netdev_hw_addr *ha;
108 struct brcmf_pub *drvr = container_of(work, struct brcmf_pub,
111 brcmf_dbg(TRACE, "enter\n");
113 ifp = drvr->iflist[0];
116 /* Determine initial value of allmulti flag */
117 cmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false;
119 /* Send down the multicast list first. */
120 cnt = netdev_mc_count(ndev);
121 buflen = sizeof(cnt) + (cnt * ETH_ALEN);
122 buf = kmalloc(buflen, GFP_ATOMIC);
127 cnt_le = cpu_to_le32(cnt);
128 memcpy(bufp, &cnt_le, sizeof(cnt_le));
129 bufp += sizeof(cnt_le);
131 netdev_for_each_mc_addr(ha, ndev) {
134 memcpy(bufp, ha->addr, ETH_ALEN);
139 err = brcmf_fil_iovar_data_set(ifp, "mcast_list", buf, buflen);
141 brcmf_dbg(ERROR, "Setting mcast_list failed, %d\n", err);
142 cmd_value = cnt ? true : cmd_value;
148 * Now send the allmulti setting. This is based on the setting in the
149 * net_device flags, but might be modified above to be turned on if we
150 * were trying to set some addresses and dongle rejected it...
152 err = brcmf_fil_iovar_int_set(ifp, "allmulti", cmd_value);
154 brcmf_dbg(ERROR, "Setting allmulti failed, %d\n", err);
156 /*Finally, pick up the PROMISC flag */
157 cmd_value = (ndev->flags & IFF_PROMISC) ? true : false;
158 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PROMISC, cmd_value);
160 brcmf_dbg(ERROR, "Setting BRCMF_C_SET_PROMISC failed, %d\n",
165 _brcmf_set_mac_address(struct work_struct *work)
167 struct brcmf_if *ifp;
168 struct net_device *ndev;
171 struct brcmf_pub *drvr = container_of(work, struct brcmf_pub,
174 brcmf_dbg(TRACE, "enter\n");
176 ifp = drvr->iflist[0];
179 err = brcmf_fil_iovar_data_set(ifp, "cur_etheraddr", drvr->macvalue,
182 brcmf_dbg(ERROR, "Setting cur_etheraddr failed, %d\n", err);
184 brcmf_dbg(TRACE, "MAC address updated to %pM\n",
186 memcpy(ndev->dev_addr, drvr->macvalue, ETH_ALEN);
190 static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr)
192 struct brcmf_if *ifp = netdev_priv(ndev);
193 struct brcmf_pub *drvr = ifp->drvr;
194 struct sockaddr *sa = (struct sockaddr *)addr;
196 memcpy(&drvr->macvalue, sa->sa_data, ETH_ALEN);
197 schedule_work(&drvr->setmacaddr_work);
201 static void brcmf_netdev_set_multicast_list(struct net_device *ndev)
203 struct brcmf_if *ifp = netdev_priv(ndev);
204 struct brcmf_pub *drvr = ifp->drvr;
206 schedule_work(&drvr->multicast_work);
209 static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *ndev)
212 struct brcmf_if *ifp = netdev_priv(ndev);
213 struct brcmf_pub *drvr = ifp->drvr;
215 brcmf_dbg(TRACE, "Enter\n");
218 if (!drvr->bus_if->drvr_up ||
219 (drvr->bus_if->state != BRCMF_BUS_DATA)) {
220 brcmf_dbg(ERROR, "xmit rejected drvup=%d state=%d\n",
221 drvr->bus_if->drvr_up,
222 drvr->bus_if->state);
223 netif_stop_queue(ndev);
227 if (!drvr->iflist[ifp->idx]) {
228 brcmf_dbg(ERROR, "bad ifidx %d\n", ifp->idx);
229 netif_stop_queue(ndev);
233 /* Make sure there's enough room for any header */
234 if (skb_headroom(skb) < drvr->hdrlen) {
235 struct sk_buff *skb2;
237 brcmf_dbg(INFO, "%s: insufficient headroom\n",
238 brcmf_ifname(drvr, ifp->idx));
239 drvr->bus_if->tx_realloc++;
240 skb2 = skb_realloc_headroom(skb, drvr->hdrlen);
244 brcmf_dbg(ERROR, "%s: skb_realloc_headroom failed\n",
245 brcmf_ifname(drvr, ifp->idx));
251 /* Update multicast statistic */
252 if (skb->len >= ETH_ALEN) {
253 u8 *pktdata = (u8 *)(skb->data);
254 struct ethhdr *eh = (struct ethhdr *)pktdata;
256 if (is_multicast_ether_addr(eh->h_dest))
257 drvr->tx_multicast++;
258 if (ntohs(eh->h_proto) == ETH_P_PAE)
259 atomic_inc(&drvr->pend_8021x_cnt);
262 /* If the protocol uses a data header, apply it */
263 brcmf_proto_hdrpush(drvr, ifp->idx, skb);
265 /* Use bus module to send data frame */
266 ret = drvr->bus_if->brcmf_bus_txdata(drvr->dev, skb);
270 drvr->bus_if->dstats.tx_dropped++;
272 drvr->bus_if->dstats.tx_packets++;
274 /* Return ok: we always eat the packet */
278 void brcmf_txflowblock(struct device *dev, bool state)
280 struct net_device *ndev;
281 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
282 struct brcmf_pub *drvr = bus_if->drvr;
285 brcmf_dbg(TRACE, "Enter\n");
287 for (i = 0; i < BRCMF_MAX_IFS; i++)
288 if (drvr->iflist[i]) {
289 ndev = drvr->iflist[i]->ndev;
291 netif_stop_queue(ndev);
293 netif_wake_queue(ndev);
297 void brcmf_rx_frame(struct device *dev, u8 ifidx,
298 struct sk_buff_head *skb_list)
302 struct sk_buff *skb, *pnext;
303 struct brcmf_if *ifp;
304 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
305 struct brcmf_pub *drvr = bus_if->drvr;
307 brcmf_dbg(TRACE, "Enter\n");
309 skb_queue_walk_safe(skb_list, skb, pnext) {
310 skb_unlink(skb, skb_list);
312 /* Get the protocol, maintain skb around eth_type_trans()
313 * The main reason for this hack is for the limitation of
314 * Linux 2.4 where 'eth_type_trans' uses the
315 * 'net->hard_header_len'
316 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
317 * coping of the packet coming from the network stack to add
318 * BDC, Hardware header etc, during network interface
320 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
322 * for BDC, Hardware header etc. and not just the ETH_HLEN
327 ifp = drvr->iflist[ifidx];
329 ifp = drvr->iflist[0];
331 if (!ifp || !ifp->ndev ||
332 ifp->ndev->reg_state != NETREG_REGISTERED) {
333 brcmu_pkt_buf_free_skb(skb);
337 skb->dev = ifp->ndev;
338 skb->protocol = eth_type_trans(skb, skb->dev);
340 if (skb->pkt_type == PACKET_MULTICAST)
341 bus_if->dstats.multicast++;
346 /* Strip header, count, deliver upward */
347 skb_pull(skb, ETH_HLEN);
349 /* Process special event packets and then discard them */
350 brcmf_fweh_process_skb(drvr, skb, &ifidx);
352 if (drvr->iflist[ifidx]) {
353 ifp = drvr->iflist[ifidx];
354 ifp->ndev->last_rx = jiffies;
357 bus_if->dstats.rx_bytes += skb->len;
358 bus_if->dstats.rx_packets++; /* Local count */
363 /* If the receive is not processed inside an ISR,
364 * the softirqd must be woken explicitly to service
365 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
366 * by netif_rx_ni(), but in earlier kernels, we need
373 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success)
378 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
379 struct brcmf_pub *drvr = bus_if->drvr;
381 brcmf_proto_hdrpull(dev, &ifidx, txp);
383 eh = (struct ethhdr *)(txp->data);
384 type = ntohs(eh->h_proto);
386 if (type == ETH_P_PAE) {
387 atomic_dec(&drvr->pend_8021x_cnt);
388 if (waitqueue_active(&drvr->pend_8021x_wait))
389 wake_up(&drvr->pend_8021x_wait);
393 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
395 struct brcmf_if *ifp = netdev_priv(ndev);
396 struct brcmf_bus *bus_if = ifp->drvr->bus_if;
398 brcmf_dbg(TRACE, "Enter\n");
400 /* Copy dongle stats to net device stats */
401 ifp->stats.rx_packets = bus_if->dstats.rx_packets;
402 ifp->stats.tx_packets = bus_if->dstats.tx_packets;
403 ifp->stats.rx_bytes = bus_if->dstats.rx_bytes;
404 ifp->stats.tx_bytes = bus_if->dstats.tx_bytes;
405 ifp->stats.rx_errors = bus_if->dstats.rx_errors;
406 ifp->stats.tx_errors = bus_if->dstats.tx_errors;
407 ifp->stats.rx_dropped = bus_if->dstats.rx_dropped;
408 ifp->stats.tx_dropped = bus_if->dstats.tx_dropped;
409 ifp->stats.multicast = bus_if->dstats.multicast;
415 * Set current toe component enables in toe_ol iovar,
416 * and set toe global enable iovar
418 static int brcmf_toe_set(struct brcmf_if *ifp, u32 toe_ol)
422 err = brcmf_fil_iovar_int_set(ifp, "toe_ol", toe_ol);
424 brcmf_dbg(ERROR, "Setting toe_ol failed, %d\n", err);
428 err = brcmf_fil_iovar_int_set(ifp, "toe", (toe_ol != 0));
430 brcmf_dbg(ERROR, "Setting toe failed, %d\n", err);
436 static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
437 struct ethtool_drvinfo *info)
439 struct brcmf_if *ifp = netdev_priv(ndev);
440 struct brcmf_pub *drvr = ifp->drvr;
442 sprintf(info->driver, KBUILD_MODNAME);
443 sprintf(info->version, "%lu", drvr->drv_version);
444 sprintf(info->bus_info, "%s", dev_name(drvr->dev));
447 static const struct ethtool_ops brcmf_ethtool_ops = {
448 .get_drvinfo = brcmf_ethtool_get_drvinfo,
451 static int brcmf_ethtool(struct brcmf_if *ifp, void __user *uaddr)
453 struct brcmf_pub *drvr = ifp->drvr;
454 struct ethtool_drvinfo info;
455 char drvname[sizeof(info.driver)];
457 struct ethtool_value edata;
458 u32 toe_cmpnt, csum_dir;
461 brcmf_dbg(TRACE, "Enter\n");
463 /* all ethtool calls start with a cmd word */
464 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
468 case ETHTOOL_GDRVINFO:
469 /* Copy out any request driver name */
470 if (copy_from_user(&info, uaddr, sizeof(info)))
472 strncpy(drvname, info.driver, sizeof(info.driver));
473 drvname[sizeof(info.driver) - 1] = '\0';
475 /* clear struct for return */
476 memset(&info, 0, sizeof(info));
479 /* if requested, identify ourselves */
480 if (strcmp(drvname, "?dhd") == 0) {
481 sprintf(info.driver, "dhd");
482 strcpy(info.version, BRCMF_VERSION_STR);
485 /* otherwise, require dongle to be up */
486 else if (!drvr->bus_if->drvr_up) {
487 brcmf_dbg(ERROR, "dongle is not up\n");
490 /* finally, report dongle driver type */
492 sprintf(info.driver, "wl");
494 sprintf(info.version, "%lu", drvr->drv_version);
495 if (copy_to_user(uaddr, &info, sizeof(info)))
497 brcmf_dbg(CTL, "given %*s, returning %s\n",
498 (int)sizeof(drvname), drvname, info.driver);
501 /* Get toe offload components from dongle */
502 case ETHTOOL_GRXCSUM:
503 case ETHTOOL_GTXCSUM:
504 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
509 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
512 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
514 if (copy_to_user(uaddr, &edata, sizeof(edata)))
518 /* Set toe offload components in dongle */
519 case ETHTOOL_SRXCSUM:
520 case ETHTOOL_STXCSUM:
521 if (copy_from_user(&edata, uaddr, sizeof(edata)))
524 /* Read the current settings, update and write back */
525 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
530 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
533 toe_cmpnt |= csum_dir;
535 toe_cmpnt &= ~csum_dir;
537 ret = brcmf_toe_set(ifp, toe_cmpnt);
541 /* If setting TX checksum mode, tell Linux the new mode */
542 if (cmd == ETHTOOL_STXCSUM) {
544 ifp->ndev->features |= NETIF_F_IP_CSUM;
546 ifp->ndev->features &= ~NETIF_F_IP_CSUM;
558 static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
561 struct brcmf_if *ifp = netdev_priv(ndev);
562 struct brcmf_pub *drvr = ifp->drvr;
564 brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd);
566 if (!drvr->iflist[ifp->idx])
569 if (cmd == SIOCETHTOOL)
570 return brcmf_ethtool(ifp, ifr->ifr_data);
575 static int brcmf_netdev_stop(struct net_device *ndev)
577 struct brcmf_if *ifp = netdev_priv(ndev);
578 struct brcmf_pub *drvr = ifp->drvr;
580 brcmf_dbg(TRACE, "Enter\n");
582 if (drvr->bus_if->drvr_up == 0)
585 brcmf_cfg80211_down(drvr->config);
587 /* Set state and stop OS transmissions */
588 drvr->bus_if->drvr_up = false;
589 netif_stop_queue(ndev);
594 static int brcmf_netdev_open(struct net_device *ndev)
596 struct brcmf_if *ifp = netdev_priv(ndev);
597 struct brcmf_pub *drvr = ifp->drvr;
598 struct brcmf_bus *bus_if = drvr->bus_if;
602 brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
604 if (ifp->idx == 0) { /* do it only for primary eth0 */
605 /* If bus is not ready, can't continue */
606 if (bus_if->state != BRCMF_BUS_DATA) {
607 brcmf_dbg(ERROR, "failed bus is not ready\n");
611 atomic_set(&drvr->pend_8021x_cnt, 0);
613 memcpy(ndev->dev_addr, drvr->mac, ETH_ALEN);
615 /* Get current TOE mode from dongle */
616 if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0
617 && (toe_ol & TOE_TX_CSUM_OL) != 0)
618 drvr->iflist[ifp->idx]->ndev->features |=
621 drvr->iflist[ifp->idx]->ndev->features &=
625 /* make sure RF is ready for work */
626 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
628 /* Allow transmit calls */
629 netif_start_queue(ndev);
630 drvr->bus_if->drvr_up = true;
631 if (brcmf_cfg80211_up(drvr->config)) {
632 brcmf_dbg(ERROR, "failed to bring up cfg80211\n");
639 static const struct net_device_ops brcmf_netdev_ops_pri = {
640 .ndo_open = brcmf_netdev_open,
641 .ndo_stop = brcmf_netdev_stop,
642 .ndo_get_stats = brcmf_netdev_get_stats,
643 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
644 .ndo_start_xmit = brcmf_netdev_start_xmit,
645 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
646 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
649 int brcmf_net_attach(struct brcmf_if *ifp)
651 struct brcmf_pub *drvr = ifp->drvr;
652 struct net_device *ndev;
653 u8 temp_addr[ETH_ALEN];
655 brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
657 ndev = drvr->iflist[ifp->idx]->ndev;
658 ndev->netdev_ops = &brcmf_netdev_ops_pri;
661 * determine mac address to use
663 if (is_valid_ether_addr(ifp->mac_addr))
664 memcpy(temp_addr, ifp->mac_addr, ETH_ALEN);
666 memcpy(temp_addr, drvr->mac, ETH_ALEN);
669 brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
670 /* ACCESSPOINT INTERFACE CASE */
671 temp_addr[0] |= 0X02; /* set bit 2 ,
672 - Locally Administered address */
675 ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
676 ndev->ethtool_ops = &brcmf_ethtool_ops;
678 drvr->rxsz = ndev->mtu + ndev->hard_header_len +
681 memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
683 if (register_netdev(ndev) != 0) {
684 brcmf_dbg(ERROR, "couldn't register the net device\n");
688 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
693 ndev->netdev_ops = NULL;
697 struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, int ifidx, s32 bssidx,
698 char *name, u8 *mac_addr)
700 struct brcmf_if *ifp;
701 struct net_device *ndev;
703 brcmf_dbg(TRACE, "idx %d\n", ifidx);
705 ifp = drvr->iflist[ifidx];
707 * Delete the existing interface before overwriting it
708 * in case we missed the BRCMF_E_IF_DEL event.
711 brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n",
713 netif_stop_queue(ifp->ndev);
714 unregister_netdev(ifp->ndev);
715 free_netdev(ifp->ndev);
716 drvr->iflist[ifidx] = NULL;
719 /* Allocate netdev, including space for private structure */
720 ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
722 brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
723 return ERR_PTR(-ENOMEM);
726 ifp = netdev_priv(ndev);
729 drvr->iflist[ifidx] = ifp;
731 ifp->bssidx = bssidx;
732 if (mac_addr != NULL)
733 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
735 brcmf_dbg(TRACE, " ==== pid:%x, net_device for if:%s created ===\n",
736 current->pid, ifp->ndev->name);
741 void brcmf_del_if(struct brcmf_pub *drvr, int ifidx)
743 struct brcmf_if *ifp;
745 brcmf_dbg(TRACE, "idx %d\n", ifidx);
747 ifp = drvr->iflist[ifidx];
749 brcmf_dbg(ERROR, "Null interface\n");
754 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
756 brcmf_netdev_stop(ifp->ndev);
760 netif_stop_queue(ifp->ndev);
763 unregister_netdev(ifp->ndev);
764 drvr->iflist[ifidx] = NULL;
766 brcmf_cfg80211_detach(drvr->config);
767 free_netdev(ifp->ndev);
771 int brcmf_attach(uint bus_hdrlen, struct device *dev)
773 struct brcmf_pub *drvr = NULL;
776 brcmf_dbg(TRACE, "Enter\n");
778 /* Allocate primary brcmf_info */
779 drvr = kzalloc(sizeof(struct brcmf_pub), GFP_ATOMIC);
783 mutex_init(&drvr->proto_block);
785 /* Link to bus module */
786 drvr->hdrlen = bus_hdrlen;
787 drvr->bus_if = dev_get_drvdata(dev);
788 drvr->bus_if->drvr = drvr;
791 /* create device debugfs folder */
792 brcmf_debugfs_attach(drvr);
794 /* Attach and link in the protocol */
795 ret = brcmf_proto_attach(drvr);
797 brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
801 /* attach firmware event handler */
802 brcmf_fweh_attach(drvr);
804 INIT_WORK(&drvr->setmacaddr_work, _brcmf_set_mac_address);
805 INIT_WORK(&drvr->multicast_work, _brcmf_set_multicast_list);
807 INIT_LIST_HEAD(&drvr->bus_if->dcmd_list);
809 init_waitqueue_head(&drvr->pend_8021x_wait);
819 int brcmf_bus_start(struct device *dev)
822 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
823 struct brcmf_pub *drvr = bus_if->drvr;
824 struct brcmf_if *ifp;
826 brcmf_dbg(TRACE, "\n");
828 /* Bring up the bus */
829 ret = bus_if->brcmf_bus_init(dev);
831 brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
835 /* add primary networking interface */
836 ifp = brcmf_add_if(drvr, 0, 0, "wlan%d", NULL);
840 /* signal bus ready */
841 bus_if->state = BRCMF_BUS_DATA;
843 /* Bus is ready, do any initialization */
844 ret = brcmf_c_preinit_dcmds(ifp);
848 drvr->config = brcmf_cfg80211_attach(drvr);
849 if (drvr->config == NULL) {
854 ret = brcmf_fweh_activate_events(ifp);
858 ret = brcmf_net_attach(ifp);
861 brcmf_dbg(ERROR, "failed: %d\n", ret);
863 brcmf_cfg80211_detach(drvr->config);
864 free_netdev(drvr->iflist[0]->ndev);
865 drvr->iflist[0] = NULL;
872 static void brcmf_bus_detach(struct brcmf_pub *drvr)
874 brcmf_dbg(TRACE, "Enter\n");
877 /* Stop the protocol module */
878 brcmf_proto_stop(drvr);
880 /* Stop the bus module */
881 drvr->bus_if->brcmf_bus_stop(drvr->dev);
885 void brcmf_detach(struct device *dev)
888 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
889 struct brcmf_pub *drvr = bus_if->drvr;
891 brcmf_dbg(TRACE, "Enter\n");
896 /* stop firmware event handling */
897 brcmf_fweh_detach(drvr);
899 /* make sure primary interface removed last */
900 for (i = BRCMF_MAX_IFS-1; i > -1; i--)
902 brcmf_del_if(drvr, i);
904 brcmf_bus_detach(drvr);
907 cancel_work_sync(&drvr->setmacaddr_work);
908 cancel_work_sync(&drvr->multicast_work);
909 brcmf_proto_detach(drvr);
912 brcmf_debugfs_detach(drvr);
917 static int brcmf_get_pend_8021x_cnt(struct brcmf_pub *drvr)
919 return atomic_read(&drvr->pend_8021x_cnt);
922 int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
924 struct brcmf_if *ifp = netdev_priv(ndev);
925 struct brcmf_pub *drvr = ifp->drvr;
928 err = wait_event_timeout(drvr->pend_8021x_wait,
929 !brcmf_get_pend_8021x_cnt(drvr),
930 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX));
937 static void brcmf_driver_init(struct work_struct *work)
939 brcmf_debugfs_init();
941 #ifdef CONFIG_BRCMFMAC_SDIO
944 #ifdef CONFIG_BRCMFMAC_USB
948 static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init);
950 static int __init brcmfmac_module_init(void)
952 if (!schedule_work(&brcmf_driver_work))
958 static void __exit brcmfmac_module_exit(void)
960 cancel_work_sync(&brcmf_driver_work);
962 #ifdef CONFIG_BRCMFMAC_SDIO
965 #ifdef CONFIG_BRCMFMAC_USB
968 brcmf_debugfs_exit();
971 module_init(brcmfmac_module_init);
972 module_exit(brcmfmac_module_exit);