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/kernel.h>
18 #include <linux/etherdevice.h>
19 #include <linux/module.h>
20 #include <net/cfg80211.h>
21 #include <net/rtnetlink.h>
22 #include <brcmu_utils.h>
23 #include <brcmu_wifi.h>
27 #include "dhd_proto.h"
29 #include "wl_cfg80211.h"
32 MODULE_AUTHOR("Broadcom Corporation");
33 MODULE_DESCRIPTION("Broadcom 802.11 wireless LAN fullmac driver.");
34 MODULE_SUPPORTED_DEVICE("Broadcom 802.11 WLAN fullmac cards");
35 MODULE_LICENSE("Dual BSD/GPL");
37 #define MAX_WAIT_FOR_8021X_TX 50 /* msecs */
41 module_param(brcmf_msg_level, int, 0);
44 char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
46 if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
47 brcmf_err("ifidx %d out of range\n", ifidx);
51 if (drvr->iflist[ifidx] == NULL) {
52 brcmf_err("null i/f %d\n", ifidx);
56 if (drvr->iflist[ifidx]->ndev)
57 return drvr->iflist[ifidx]->ndev->name;
62 static void _brcmf_set_multicast_list(struct work_struct *work)
65 struct net_device *ndev;
66 struct netdev_hw_addr *ha;
73 brcmf_dbg(TRACE, "enter\n");
75 ifp = container_of(work, struct brcmf_if, multicast_work);
78 /* Determine initial value of allmulti flag */
79 cmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false;
81 /* Send down the multicast list first. */
82 cnt = netdev_mc_count(ndev);
83 buflen = sizeof(cnt) + (cnt * ETH_ALEN);
84 buf = kmalloc(buflen, GFP_ATOMIC);
89 cnt_le = cpu_to_le32(cnt);
90 memcpy(bufp, &cnt_le, sizeof(cnt_le));
91 bufp += sizeof(cnt_le);
93 netdev_for_each_mc_addr(ha, ndev) {
96 memcpy(bufp, ha->addr, ETH_ALEN);
101 err = brcmf_fil_iovar_data_set(ifp, "mcast_list", buf, buflen);
103 brcmf_err("Setting mcast_list failed, %d\n", err);
104 cmd_value = cnt ? true : cmd_value;
110 * Now send the allmulti setting. This is based on the setting in the
111 * net_device flags, but might be modified above to be turned on if we
112 * were trying to set some addresses and dongle rejected it...
114 err = brcmf_fil_iovar_int_set(ifp, "allmulti", cmd_value);
116 brcmf_err("Setting allmulti failed, %d\n", err);
118 /*Finally, pick up the PROMISC flag */
119 cmd_value = (ndev->flags & IFF_PROMISC) ? true : false;
120 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PROMISC, cmd_value);
122 brcmf_err("Setting BRCMF_C_SET_PROMISC failed, %d\n",
127 _brcmf_set_mac_address(struct work_struct *work)
129 struct brcmf_if *ifp;
132 brcmf_dbg(TRACE, "enter\n");
134 ifp = container_of(work, struct brcmf_if, setmacaddr_work);
135 err = brcmf_fil_iovar_data_set(ifp, "cur_etheraddr", ifp->mac_addr,
138 brcmf_err("Setting cur_etheraddr failed, %d\n", err);
140 brcmf_dbg(TRACE, "MAC address updated to %pM\n",
142 memcpy(ifp->ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
146 static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr)
148 struct brcmf_if *ifp = netdev_priv(ndev);
149 struct sockaddr *sa = (struct sockaddr *)addr;
151 memcpy(&ifp->mac_addr, sa->sa_data, ETH_ALEN);
152 schedule_work(&ifp->setmacaddr_work);
156 static void brcmf_netdev_set_multicast_list(struct net_device *ndev)
158 struct brcmf_if *ifp = netdev_priv(ndev);
160 schedule_work(&ifp->multicast_work);
163 static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *ndev)
166 struct brcmf_if *ifp = netdev_priv(ndev);
167 struct brcmf_pub *drvr = ifp->drvr;
169 brcmf_dbg(TRACE, "Enter\n");
172 if (!drvr->bus_if->drvr_up ||
173 (drvr->bus_if->state != BRCMF_BUS_DATA)) {
174 brcmf_err("xmit rejected drvup=%d state=%d\n",
175 drvr->bus_if->drvr_up,
176 drvr->bus_if->state);
177 netif_stop_queue(ndev);
181 if (!drvr->iflist[ifp->idx]) {
182 brcmf_err("bad ifidx %d\n", ifp->idx);
183 netif_stop_queue(ndev);
187 /* Make sure there's enough room for any header */
188 if (skb_headroom(skb) < drvr->hdrlen) {
189 struct sk_buff *skb2;
191 brcmf_dbg(INFO, "%s: insufficient headroom\n",
192 brcmf_ifname(drvr, ifp->idx));
193 drvr->bus_if->tx_realloc++;
194 skb2 = skb_realloc_headroom(skb, drvr->hdrlen);
198 brcmf_err("%s: skb_realloc_headroom failed\n",
199 brcmf_ifname(drvr, ifp->idx));
205 /* Update multicast statistic */
206 if (skb->len >= ETH_ALEN) {
207 u8 *pktdata = (u8 *)(skb->data);
208 struct ethhdr *eh = (struct ethhdr *)pktdata;
210 if (is_multicast_ether_addr(eh->h_dest))
211 drvr->tx_multicast++;
212 if (ntohs(eh->h_proto) == ETH_P_PAE)
213 atomic_inc(&drvr->pend_8021x_cnt);
216 /* If the protocol uses a data header, apply it */
217 brcmf_proto_hdrpush(drvr, ifp->idx, skb);
219 /* Use bus module to send data frame */
220 ret = brcmf_bus_txdata(drvr->bus_if, skb);
224 drvr->bus_if->dstats.tx_dropped++;
226 drvr->bus_if->dstats.tx_packets++;
228 /* Return ok: we always eat the packet */
232 void brcmf_txflowblock(struct device *dev, bool state)
234 struct net_device *ndev;
235 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
236 struct brcmf_pub *drvr = bus_if->drvr;
239 brcmf_dbg(TRACE, "Enter\n");
241 for (i = 0; i < BRCMF_MAX_IFS; i++)
242 if (drvr->iflist[i]) {
243 ndev = drvr->iflist[i]->ndev;
245 netif_stop_queue(ndev);
247 netif_wake_queue(ndev);
251 void brcmf_rx_frames(struct device *dev, struct sk_buff_head *skb_list)
255 struct sk_buff *skb, *pnext;
256 struct brcmf_if *ifp;
257 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
258 struct brcmf_pub *drvr = bus_if->drvr;
262 brcmf_dbg(TRACE, "Enter\n");
264 skb_queue_walk_safe(skb_list, skb, pnext) {
265 skb_unlink(skb, skb_list);
267 /* process and remove protocol-specific header
269 ret = brcmf_proto_hdrpull(drvr, &ifidx, skb);
272 bus_if->dstats.rx_errors++;
273 brcmu_pkt_buf_free_skb(skb);
277 /* Get the protocol, maintain skb around eth_type_trans()
278 * The main reason for this hack is for the limitation of
279 * Linux 2.4 where 'eth_type_trans' uses the
280 * 'net->hard_header_len'
281 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
282 * coping of the packet coming from the network stack to add
283 * BDC, Hardware header etc, during network interface
285 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
287 * for BDC, Hardware header etc. and not just the ETH_HLEN
292 ifp = drvr->iflist[ifidx];
294 ifp = drvr->iflist[0];
296 if (!ifp || !ifp->ndev ||
297 ifp->ndev->reg_state != NETREG_REGISTERED) {
298 brcmu_pkt_buf_free_skb(skb);
302 skb->dev = ifp->ndev;
303 skb->protocol = eth_type_trans(skb, skb->dev);
305 if (skb->pkt_type == PACKET_MULTICAST)
306 bus_if->dstats.multicast++;
311 /* Strip header, count, deliver upward */
312 skb_pull(skb, ETH_HLEN);
314 /* Process special event packets and then discard them */
315 brcmf_fweh_process_skb(drvr, skb, &ifidx);
317 if (drvr->iflist[ifidx]) {
318 ifp = drvr->iflist[ifidx];
319 ifp->ndev->last_rx = jiffies;
322 bus_if->dstats.rx_bytes += skb->len;
323 bus_if->dstats.rx_packets++; /* Local count */
328 /* If the receive is not processed inside an ISR,
329 * the softirqd must be woken explicitly to service
330 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
331 * by netif_rx_ni(), but in earlier kernels, we need
338 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success)
343 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
344 struct brcmf_pub *drvr = bus_if->drvr;
346 brcmf_proto_hdrpull(drvr, &ifidx, txp);
348 eh = (struct ethhdr *)(txp->data);
349 type = ntohs(eh->h_proto);
351 if (type == ETH_P_PAE) {
352 atomic_dec(&drvr->pend_8021x_cnt);
353 if (waitqueue_active(&drvr->pend_8021x_wait))
354 wake_up(&drvr->pend_8021x_wait);
358 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
360 struct brcmf_if *ifp = netdev_priv(ndev);
361 struct brcmf_bus *bus_if = ifp->drvr->bus_if;
363 brcmf_dbg(TRACE, "Enter\n");
365 /* Copy dongle stats to net device stats */
366 ifp->stats.rx_packets = bus_if->dstats.rx_packets;
367 ifp->stats.tx_packets = bus_if->dstats.tx_packets;
368 ifp->stats.rx_bytes = bus_if->dstats.rx_bytes;
369 ifp->stats.tx_bytes = bus_if->dstats.tx_bytes;
370 ifp->stats.rx_errors = bus_if->dstats.rx_errors;
371 ifp->stats.tx_errors = bus_if->dstats.tx_errors;
372 ifp->stats.rx_dropped = bus_if->dstats.rx_dropped;
373 ifp->stats.tx_dropped = bus_if->dstats.tx_dropped;
374 ifp->stats.multicast = bus_if->dstats.multicast;
380 * Set current toe component enables in toe_ol iovar,
381 * and set toe global enable iovar
383 static int brcmf_toe_set(struct brcmf_if *ifp, u32 toe_ol)
387 err = brcmf_fil_iovar_int_set(ifp, "toe_ol", toe_ol);
389 brcmf_err("Setting toe_ol failed, %d\n", err);
393 err = brcmf_fil_iovar_int_set(ifp, "toe", (toe_ol != 0));
395 brcmf_err("Setting toe failed, %d\n", err);
401 static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
402 struct ethtool_drvinfo *info)
404 struct brcmf_if *ifp = netdev_priv(ndev);
405 struct brcmf_pub *drvr = ifp->drvr;
407 sprintf(info->driver, KBUILD_MODNAME);
408 sprintf(info->version, "%lu", drvr->drv_version);
409 sprintf(info->bus_info, "%s", dev_name(drvr->bus_if->dev));
412 static const struct ethtool_ops brcmf_ethtool_ops = {
413 .get_drvinfo = brcmf_ethtool_get_drvinfo,
416 static int brcmf_ethtool(struct brcmf_if *ifp, void __user *uaddr)
418 struct brcmf_pub *drvr = ifp->drvr;
419 struct ethtool_drvinfo info;
420 char drvname[sizeof(info.driver)];
422 struct ethtool_value edata;
423 u32 toe_cmpnt, csum_dir;
426 brcmf_dbg(TRACE, "Enter\n");
428 /* all ethtool calls start with a cmd word */
429 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
433 case ETHTOOL_GDRVINFO:
434 /* Copy out any request driver name */
435 if (copy_from_user(&info, uaddr, sizeof(info)))
437 strncpy(drvname, info.driver, sizeof(info.driver));
438 drvname[sizeof(info.driver) - 1] = '\0';
440 /* clear struct for return */
441 memset(&info, 0, sizeof(info));
444 /* if requested, identify ourselves */
445 if (strcmp(drvname, "?dhd") == 0) {
446 sprintf(info.driver, "dhd");
447 strcpy(info.version, BRCMF_VERSION_STR);
450 /* otherwise, require dongle to be up */
451 else if (!drvr->bus_if->drvr_up) {
452 brcmf_err("dongle is not up\n");
455 /* finally, report dongle driver type */
457 sprintf(info.driver, "wl");
459 sprintf(info.version, "%lu", drvr->drv_version);
460 if (copy_to_user(uaddr, &info, sizeof(info)))
462 brcmf_dbg(TRACE, "given %*s, returning %s\n",
463 (int)sizeof(drvname), drvname, info.driver);
466 /* Get toe offload components from dongle */
467 case ETHTOOL_GRXCSUM:
468 case ETHTOOL_GTXCSUM:
469 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
474 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
477 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
479 if (copy_to_user(uaddr, &edata, sizeof(edata)))
483 /* Set toe offload components in dongle */
484 case ETHTOOL_SRXCSUM:
485 case ETHTOOL_STXCSUM:
486 if (copy_from_user(&edata, uaddr, sizeof(edata)))
489 /* Read the current settings, update and write back */
490 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
495 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
498 toe_cmpnt |= csum_dir;
500 toe_cmpnt &= ~csum_dir;
502 ret = brcmf_toe_set(ifp, toe_cmpnt);
506 /* If setting TX checksum mode, tell Linux the new mode */
507 if (cmd == ETHTOOL_STXCSUM) {
509 ifp->ndev->features |= NETIF_F_IP_CSUM;
511 ifp->ndev->features &= ~NETIF_F_IP_CSUM;
523 static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
526 struct brcmf_if *ifp = netdev_priv(ndev);
527 struct brcmf_pub *drvr = ifp->drvr;
529 brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd);
531 if (!drvr->iflist[ifp->idx])
534 if (cmd == SIOCETHTOOL)
535 return brcmf_ethtool(ifp, ifr->ifr_data);
540 static int brcmf_netdev_stop(struct net_device *ndev)
542 struct brcmf_if *ifp = netdev_priv(ndev);
543 struct brcmf_pub *drvr = ifp->drvr;
545 brcmf_dbg(TRACE, "Enter\n");
547 if (drvr->bus_if->drvr_up == 0)
550 brcmf_cfg80211_down(ndev);
552 /* Set state and stop OS transmissions */
553 drvr->bus_if->drvr_up = false;
554 netif_stop_queue(ndev);
559 static int brcmf_netdev_open(struct net_device *ndev)
561 struct brcmf_if *ifp = netdev_priv(ndev);
562 struct brcmf_pub *drvr = ifp->drvr;
563 struct brcmf_bus *bus_if = drvr->bus_if;
567 brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
569 /* If bus is not ready, can't continue */
570 if (bus_if->state != BRCMF_BUS_DATA) {
571 brcmf_err("failed bus is not ready\n");
575 atomic_set(&drvr->pend_8021x_cnt, 0);
577 memcpy(ndev->dev_addr, drvr->mac, ETH_ALEN);
579 /* Get current TOE mode from dongle */
580 if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0
581 && (toe_ol & TOE_TX_CSUM_OL) != 0)
582 drvr->iflist[ifp->idx]->ndev->features |=
585 drvr->iflist[ifp->idx]->ndev->features &=
588 /* make sure RF is ready for work */
589 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
591 /* Allow transmit calls */
592 netif_start_queue(ndev);
593 drvr->bus_if->drvr_up = true;
594 if (brcmf_cfg80211_up(ndev)) {
595 brcmf_err("failed to bring up cfg80211\n");
602 static const struct net_device_ops brcmf_netdev_ops_pri = {
603 .ndo_open = brcmf_netdev_open,
604 .ndo_stop = brcmf_netdev_stop,
605 .ndo_get_stats = brcmf_netdev_get_stats,
606 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
607 .ndo_start_xmit = brcmf_netdev_start_xmit,
608 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
609 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
612 static const struct net_device_ops brcmf_netdev_ops_virt = {
613 .ndo_open = brcmf_cfg80211_up,
614 .ndo_stop = brcmf_cfg80211_down,
615 .ndo_get_stats = brcmf_netdev_get_stats,
616 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
617 .ndo_start_xmit = brcmf_netdev_start_xmit,
618 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
619 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
622 int brcmf_net_attach(struct brcmf_if *ifp)
624 struct brcmf_pub *drvr = ifp->drvr;
625 struct net_device *ndev;
627 brcmf_dbg(TRACE, "ifidx %d mac %pM\n", ifp->idx, ifp->mac_addr);
630 /* set appropriate operations */
632 ndev->netdev_ops = &brcmf_netdev_ops_pri;
634 ndev->netdev_ops = &brcmf_netdev_ops_virt;
636 ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
637 ndev->ethtool_ops = &brcmf_ethtool_ops;
639 drvr->rxsz = ndev->mtu + ndev->hard_header_len +
642 /* set the mac address */
643 memcpy(ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
645 if (register_netdev(ndev) != 0) {
646 brcmf_err("couldn't register the net device\n");
650 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
655 ndev->netdev_ops = NULL;
659 struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, int ifidx, s32 bssidx,
660 char *name, u8 *addr_mask)
662 struct brcmf_if *ifp;
663 struct net_device *ndev;
666 brcmf_dbg(TRACE, "idx %d\n", ifidx);
668 ifp = drvr->iflist[ifidx];
670 * Delete the existing interface before overwriting it
671 * in case we missed the BRCMF_E_IF_DEL event.
674 brcmf_err("ERROR: netdev:%s already exists\n",
677 netif_stop_queue(ifp->ndev);
678 unregister_netdev(ifp->ndev);
679 free_netdev(ifp->ndev);
680 drvr->iflist[ifidx] = NULL;
682 brcmf_err("ignore IF event\n");
683 return ERR_PTR(-EINVAL);
687 /* Allocate netdev, including space for private structure */
688 ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
690 brcmf_err("OOM - alloc_netdev\n");
691 return ERR_PTR(-ENOMEM);
694 ifp = netdev_priv(ndev);
697 drvr->iflist[ifidx] = ifp;
699 ifp->bssidx = bssidx;
701 INIT_WORK(&ifp->setmacaddr_work, _brcmf_set_mac_address);
702 INIT_WORK(&ifp->multicast_work, _brcmf_set_multicast_list);
704 if (addr_mask != NULL)
705 for (i = 0; i < ETH_ALEN; i++)
706 ifp->mac_addr[i] = drvr->mac[i] ^ addr_mask[i];
708 brcmf_dbg(TRACE, " ==== pid:%x, if:%s (%pM) created ===\n",
709 current->pid, ifp->ndev->name, ifp->mac_addr);
714 void brcmf_del_if(struct brcmf_pub *drvr, int ifidx)
716 struct brcmf_if *ifp;
718 brcmf_dbg(TRACE, "idx %d\n", ifidx);
720 ifp = drvr->iflist[ifidx];
722 brcmf_err("Null interface\n");
727 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
729 brcmf_netdev_stop(ifp->ndev);
733 netif_stop_queue(ifp->ndev);
736 cancel_work_sync(&ifp->setmacaddr_work);
737 cancel_work_sync(&ifp->multicast_work);
739 unregister_netdev(ifp->ndev);
740 drvr->iflist[ifidx] = NULL;
742 brcmf_cfg80211_detach(drvr->config);
743 free_netdev(ifp->ndev);
747 int brcmf_attach(uint bus_hdrlen, struct device *dev)
749 struct brcmf_pub *drvr = NULL;
752 brcmf_dbg(TRACE, "Enter\n");
754 /* Allocate primary brcmf_info */
755 drvr = kzalloc(sizeof(struct brcmf_pub), GFP_ATOMIC);
759 mutex_init(&drvr->proto_block);
761 /* Link to bus module */
762 drvr->hdrlen = bus_hdrlen;
763 drvr->bus_if = dev_get_drvdata(dev);
764 drvr->bus_if->drvr = drvr;
766 /* create device debugfs folder */
767 brcmf_debugfs_attach(drvr);
769 /* Attach and link in the protocol */
770 ret = brcmf_proto_attach(drvr);
772 brcmf_err("brcmf_prot_attach failed\n");
776 /* attach firmware event handler */
777 brcmf_fweh_attach(drvr);
779 INIT_LIST_HEAD(&drvr->bus_if->dcmd_list);
781 init_waitqueue_head(&drvr->pend_8021x_wait);
791 int brcmf_bus_start(struct device *dev)
794 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
795 struct brcmf_pub *drvr = bus_if->drvr;
796 struct brcmf_if *ifp;
798 brcmf_dbg(TRACE, "\n");
800 /* Bring up the bus */
801 ret = brcmf_bus_init(bus_if);
803 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret);
807 /* add primary networking interface */
808 ifp = brcmf_add_if(drvr, 0, 0, "wlan%d", NULL);
812 /* signal bus ready */
813 bus_if->state = BRCMF_BUS_DATA;
815 /* Bus is ready, do any initialization */
816 ret = brcmf_c_preinit_dcmds(ifp);
820 drvr->config = brcmf_cfg80211_attach(drvr, bus_if->dev);
821 if (drvr->config == NULL) {
826 ret = brcmf_fweh_activate_events(ifp);
830 ret = brcmf_net_attach(ifp);
833 brcmf_err("failed: %d\n", ret);
835 brcmf_cfg80211_detach(drvr->config);
836 free_netdev(drvr->iflist[0]->ndev);
837 drvr->iflist[0] = NULL;
844 static void brcmf_bus_detach(struct brcmf_pub *drvr)
846 brcmf_dbg(TRACE, "Enter\n");
849 /* Stop the protocol module */
850 brcmf_proto_stop(drvr);
852 /* Stop the bus module */
853 brcmf_bus_stop(drvr->bus_if);
857 void brcmf_dev_reset(struct device *dev)
859 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
860 struct brcmf_pub *drvr = bus_if->drvr;
865 brcmf_fil_cmd_int_set(drvr->iflist[0], BRCMF_C_TERMINATED, 1);
868 void brcmf_detach(struct device *dev)
871 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
872 struct brcmf_pub *drvr = bus_if->drvr;
874 brcmf_dbg(TRACE, "Enter\n");
879 /* stop firmware event handling */
880 brcmf_fweh_detach(drvr);
882 /* make sure primary interface removed last */
883 for (i = BRCMF_MAX_IFS-1; i > -1; i--)
885 brcmf_del_if(drvr, i);
887 brcmf_bus_detach(drvr);
890 brcmf_proto_detach(drvr);
893 brcmf_debugfs_detach(drvr);
898 static int brcmf_get_pend_8021x_cnt(struct brcmf_pub *drvr)
900 return atomic_read(&drvr->pend_8021x_cnt);
903 int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
905 struct brcmf_if *ifp = netdev_priv(ndev);
906 struct brcmf_pub *drvr = ifp->drvr;
909 err = wait_event_timeout(drvr->pend_8021x_wait,
910 !brcmf_get_pend_8021x_cnt(drvr),
911 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX));
918 static void brcmf_driver_init(struct work_struct *work)
920 brcmf_debugfs_init();
922 #ifdef CONFIG_BRCMFMAC_SDIO
925 #ifdef CONFIG_BRCMFMAC_USB
929 static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init);
931 static int __init brcmfmac_module_init(void)
933 if (!schedule_work(&brcmf_driver_work))
939 static void __exit brcmfmac_module_exit(void)
941 cancel_work_sync(&brcmf_driver_work);
943 #ifdef CONFIG_BRCMFMAC_SDIO
946 #ifdef CONFIG_BRCMFMAC_USB
949 brcmf_debugfs_exit();
952 module_init(brcmfmac_module_init);
953 module_exit(brcmfmac_module_exit);