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 "fwil_types.h"
31 #include "wl_cfg80211.h"
35 MODULE_AUTHOR("Broadcom Corporation");
36 MODULE_DESCRIPTION("Broadcom 802.11 wireless LAN fullmac driver.");
37 MODULE_LICENSE("Dual BSD/GPL");
39 #define MAX_WAIT_FOR_8021X_TX 50 /* msecs */
43 module_param_named(debug, brcmf_msg_level, int, S_IRUSR | S_IWUSR);
44 MODULE_PARM_DESC(debug, "level of debug output");
47 static int brcmf_p2p_enable;
49 module_param_named(p2pon, brcmf_p2p_enable, int, 0);
50 MODULE_PARM_DESC(p2pon, "enable p2p management functionality");
53 char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
55 if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
56 brcmf_err("ifidx %d out of range\n", ifidx);
60 if (drvr->iflist[ifidx] == NULL) {
61 brcmf_err("null i/f %d\n", ifidx);
65 if (drvr->iflist[ifidx]->ndev)
66 return drvr->iflist[ifidx]->ndev->name;
71 static void _brcmf_set_multicast_list(struct work_struct *work)
74 struct net_device *ndev;
75 struct netdev_hw_addr *ha;
82 ifp = container_of(work, struct brcmf_if, multicast_work);
84 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
88 /* Determine initial value of allmulti flag */
89 cmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false;
91 /* Send down the multicast list first. */
92 cnt = netdev_mc_count(ndev);
93 buflen = sizeof(cnt) + (cnt * ETH_ALEN);
94 buf = kmalloc(buflen, GFP_ATOMIC);
99 cnt_le = cpu_to_le32(cnt);
100 memcpy(bufp, &cnt_le, sizeof(cnt_le));
101 bufp += sizeof(cnt_le);
103 netdev_for_each_mc_addr(ha, ndev) {
106 memcpy(bufp, ha->addr, ETH_ALEN);
111 err = brcmf_fil_iovar_data_set(ifp, "mcast_list", buf, buflen);
113 brcmf_err("Setting mcast_list failed, %d\n", err);
114 cmd_value = cnt ? true : cmd_value;
120 * Now send the allmulti setting. This is based on the setting in the
121 * net_device flags, but might be modified above to be turned on if we
122 * were trying to set some addresses and dongle rejected it...
124 err = brcmf_fil_iovar_int_set(ifp, "allmulti", cmd_value);
126 brcmf_err("Setting allmulti failed, %d\n", err);
128 /*Finally, pick up the PROMISC flag */
129 cmd_value = (ndev->flags & IFF_PROMISC) ? true : false;
130 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PROMISC, cmd_value);
132 brcmf_err("Setting BRCMF_C_SET_PROMISC failed, %d\n",
137 _brcmf_set_mac_address(struct work_struct *work)
139 struct brcmf_if *ifp;
142 ifp = container_of(work, struct brcmf_if, setmacaddr_work);
144 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
146 err = brcmf_fil_iovar_data_set(ifp, "cur_etheraddr", ifp->mac_addr,
149 brcmf_err("Setting cur_etheraddr failed, %d\n", err);
151 brcmf_dbg(TRACE, "MAC address updated to %pM\n",
153 memcpy(ifp->ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
157 static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr)
159 struct brcmf_if *ifp = netdev_priv(ndev);
160 struct sockaddr *sa = (struct sockaddr *)addr;
162 memcpy(&ifp->mac_addr, sa->sa_data, ETH_ALEN);
163 schedule_work(&ifp->setmacaddr_work);
167 static void brcmf_netdev_set_multicast_list(struct net_device *ndev)
169 struct brcmf_if *ifp = netdev_priv(ndev);
171 schedule_work(&ifp->multicast_work);
174 static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb,
175 struct net_device *ndev)
178 struct brcmf_if *ifp = netdev_priv(ndev);
179 struct brcmf_pub *drvr = ifp->drvr;
182 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
184 /* Can the device send data? */
185 if (drvr->bus_if->state != BRCMF_BUS_DATA) {
186 brcmf_err("xmit rejected state=%d\n", drvr->bus_if->state);
187 netif_stop_queue(ndev);
193 if (!drvr->iflist[ifp->bssidx]) {
194 brcmf_err("bad ifidx %d\n", ifp->bssidx);
195 netif_stop_queue(ndev);
201 /* Make sure there's enough room for any header */
202 if (skb_headroom(skb) < drvr->hdrlen) {
203 struct sk_buff *skb2;
205 brcmf_dbg(INFO, "%s: insufficient headroom\n",
206 brcmf_ifname(drvr, ifp->bssidx));
207 drvr->bus_if->tx_realloc++;
208 skb2 = skb_realloc_headroom(skb, drvr->hdrlen);
212 brcmf_err("%s: skb_realloc_headroom failed\n",
213 brcmf_ifname(drvr, ifp->bssidx));
219 /* validate length for ether packet */
220 if (skb->len < sizeof(*eh)) {
226 /* handle ethernet header */
227 eh = (struct ethhdr *)(skb->data);
228 if (is_multicast_ether_addr(eh->h_dest))
229 drvr->tx_multicast++;
230 if (ntohs(eh->h_proto) == ETH_P_PAE)
231 atomic_inc(&ifp->pend_8021x_cnt);
233 /* If the protocol uses a data header, apply it */
234 brcmf_proto_hdrpush(drvr, ifp->ifidx, 0, skb);
236 /* Use bus module to send data frame */
237 ret = brcmf_bus_txdata(drvr->bus_if, skb);
241 ifp->stats.tx_dropped++;
243 ifp->stats.tx_packets++;
244 ifp->stats.tx_bytes += skb->len;
247 /* Return ok: we always eat the packet */
251 void brcmf_txflowblock(struct device *dev, bool state)
253 struct net_device *ndev;
254 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
255 struct brcmf_pub *drvr = bus_if->drvr;
258 brcmf_dbg(TRACE, "Enter\n");
260 for (i = 0; i < BRCMF_MAX_IFS; i++)
261 if (drvr->iflist[i]) {
262 ndev = drvr->iflist[i]->ndev;
264 netif_stop_queue(ndev);
266 netif_wake_queue(ndev);
270 void brcmf_rx_frames(struct device *dev, struct sk_buff_head *skb_list)
274 struct sk_buff *skb, *pnext;
275 struct brcmf_if *ifp;
276 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
277 struct brcmf_pub *drvr = bus_if->drvr;
281 brcmf_dbg(TRACE, "Enter\n");
283 skb_queue_walk_safe(skb_list, skb, pnext) {
284 skb_unlink(skb, skb_list);
286 /* process and remove protocol-specific header */
287 ret = brcmf_proto_hdrpull(drvr, drvr->fw_signals, &ifidx, skb);
288 ifp = drvr->iflist[ifidx];
290 if (ret || !ifp || !ifp->ndev) {
291 if ((ret != -ENODATA) && ifp)
292 ifp->stats.rx_errors++;
293 brcmu_pkt_buf_free_skb(skb);
297 /* Get the protocol, maintain skb around eth_type_trans()
298 * The main reason for this hack is for the limitation of
299 * Linux 2.4 where 'eth_type_trans' uses the
300 * 'net->hard_header_len'
301 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
302 * coping of the packet coming from the network stack to add
303 * BDC, Hardware header etc, during network interface
305 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
307 * for BDC, Hardware header etc. and not just the ETH_HLEN
312 skb->dev = ifp->ndev;
313 skb->protocol = eth_type_trans(skb, skb->dev);
315 if (skb->pkt_type == PACKET_MULTICAST)
316 ifp->stats.multicast++;
321 /* Strip header, count, deliver upward */
322 skb_pull(skb, ETH_HLEN);
324 /* Process special event packets and then discard them */
325 brcmf_fweh_process_skb(drvr, skb, &ifidx);
327 if (drvr->iflist[ifidx]) {
328 ifp = drvr->iflist[ifidx];
329 ifp->ndev->last_rx = jiffies;
332 if (!(ifp->ndev->flags & IFF_UP)) {
333 brcmu_pkt_buf_free_skb(skb);
337 ifp->stats.rx_bytes += skb->len;
338 ifp->stats.rx_packets++;
343 /* If the receive is not processed inside an ISR,
344 * the softirqd must be woken explicitly to service
345 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
346 * by netif_rx_ni(), but in earlier kernels, we need
353 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success)
358 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
359 struct brcmf_pub *drvr = bus_if->drvr;
360 struct brcmf_if *ifp;
363 res = brcmf_proto_hdrpull(drvr, false, &ifidx, txp);
365 ifp = drvr->iflist[ifidx];
370 eh = (struct ethhdr *)(txp->data);
371 type = ntohs(eh->h_proto);
373 if (type == ETH_P_PAE) {
374 atomic_dec(&ifp->pend_8021x_cnt);
375 if (waitqueue_active(&ifp->pend_8021x_wait))
376 wake_up(&ifp->pend_8021x_wait);
380 ifp->stats.tx_errors++;
383 brcmu_pkt_buf_free_skb(txp);
386 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
388 struct brcmf_if *ifp = netdev_priv(ndev);
390 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
396 * Set current toe component enables in toe_ol iovar,
397 * and set toe global enable iovar
399 static int brcmf_toe_set(struct brcmf_if *ifp, u32 toe_ol)
403 err = brcmf_fil_iovar_int_set(ifp, "toe_ol", toe_ol);
405 brcmf_err("Setting toe_ol failed, %d\n", err);
409 err = brcmf_fil_iovar_int_set(ifp, "toe", (toe_ol != 0));
411 brcmf_err("Setting toe failed, %d\n", err);
417 static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
418 struct ethtool_drvinfo *info)
420 struct brcmf_if *ifp = netdev_priv(ndev);
421 struct brcmf_pub *drvr = ifp->drvr;
423 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
424 snprintf(info->version, sizeof(info->version), "%lu",
426 strlcpy(info->bus_info, dev_name(drvr->bus_if->dev),
427 sizeof(info->bus_info));
430 static const struct ethtool_ops brcmf_ethtool_ops = {
431 .get_drvinfo = brcmf_ethtool_get_drvinfo,
434 static int brcmf_ethtool(struct brcmf_if *ifp, void __user *uaddr)
436 struct brcmf_pub *drvr = ifp->drvr;
437 struct ethtool_drvinfo info;
438 char drvname[sizeof(info.driver)];
440 struct ethtool_value edata;
441 u32 toe_cmpnt, csum_dir;
444 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
446 /* all ethtool calls start with a cmd word */
447 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
451 case ETHTOOL_GDRVINFO:
452 /* Copy out any request driver name */
453 if (copy_from_user(&info, uaddr, sizeof(info)))
455 strncpy(drvname, info.driver, sizeof(info.driver));
456 drvname[sizeof(info.driver) - 1] = '\0';
458 /* clear struct for return */
459 memset(&info, 0, sizeof(info));
462 /* if requested, identify ourselves */
463 if (strcmp(drvname, "?dhd") == 0) {
464 sprintf(info.driver, "dhd");
465 strcpy(info.version, BRCMF_VERSION_STR);
467 /* report dongle driver type */
469 sprintf(info.driver, "wl");
471 sprintf(info.version, "%lu", drvr->drv_version);
472 if (copy_to_user(uaddr, &info, sizeof(info)))
474 brcmf_dbg(TRACE, "given %*s, returning %s\n",
475 (int)sizeof(drvname), drvname, info.driver);
478 /* Get toe offload components from dongle */
479 case ETHTOOL_GRXCSUM:
480 case ETHTOOL_GTXCSUM:
481 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
486 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
489 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
491 if (copy_to_user(uaddr, &edata, sizeof(edata)))
495 /* Set toe offload components in dongle */
496 case ETHTOOL_SRXCSUM:
497 case ETHTOOL_STXCSUM:
498 if (copy_from_user(&edata, uaddr, sizeof(edata)))
501 /* Read the current settings, update and write back */
502 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
507 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
510 toe_cmpnt |= csum_dir;
512 toe_cmpnt &= ~csum_dir;
514 ret = brcmf_toe_set(ifp, toe_cmpnt);
518 /* If setting TX checksum mode, tell Linux the new mode */
519 if (cmd == ETHTOOL_STXCSUM) {
521 ifp->ndev->features |= NETIF_F_IP_CSUM;
523 ifp->ndev->features &= ~NETIF_F_IP_CSUM;
535 static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
538 struct brcmf_if *ifp = netdev_priv(ndev);
539 struct brcmf_pub *drvr = ifp->drvr;
541 brcmf_dbg(TRACE, "Enter, idx=%d, cmd=0x%04x\n", ifp->bssidx, cmd);
543 if (!drvr->iflist[ifp->bssidx])
546 if (cmd == SIOCETHTOOL)
547 return brcmf_ethtool(ifp, ifr->ifr_data);
552 static int brcmf_netdev_stop(struct net_device *ndev)
554 struct brcmf_if *ifp = netdev_priv(ndev);
556 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
558 brcmf_cfg80211_down(ndev);
560 /* Set state and stop OS transmissions */
561 netif_stop_queue(ndev);
566 static int brcmf_netdev_open(struct net_device *ndev)
568 struct brcmf_if *ifp = netdev_priv(ndev);
569 struct brcmf_pub *drvr = ifp->drvr;
570 struct brcmf_bus *bus_if = drvr->bus_if;
574 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
576 /* If bus is not ready, can't continue */
577 if (bus_if->state != BRCMF_BUS_DATA) {
578 brcmf_err("failed bus is not ready\n");
582 atomic_set(&ifp->pend_8021x_cnt, 0);
584 /* Get current TOE mode from dongle */
585 if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0
586 && (toe_ol & TOE_TX_CSUM_OL) != 0)
587 ndev->features |= NETIF_F_IP_CSUM;
589 ndev->features &= ~NETIF_F_IP_CSUM;
591 /* Allow transmit calls */
592 netif_start_queue(ndev);
593 if (brcmf_cfg80211_up(ndev)) {
594 brcmf_err("failed to bring up cfg80211\n");
601 static const struct net_device_ops brcmf_netdev_ops_pri = {
602 .ndo_open = brcmf_netdev_open,
603 .ndo_stop = brcmf_netdev_stop,
604 .ndo_get_stats = brcmf_netdev_get_stats,
605 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
606 .ndo_start_xmit = brcmf_netdev_start_xmit,
607 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
608 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
611 int brcmf_net_attach(struct brcmf_if *ifp, bool rtnl_locked)
613 struct brcmf_pub *drvr = ifp->drvr;
614 struct net_device *ndev;
617 brcmf_dbg(TRACE, "Enter, idx=%d mac=%pM\n", ifp->bssidx,
621 /* set appropriate operations */
622 ndev->netdev_ops = &brcmf_netdev_ops_pri;
624 ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
625 ndev->ethtool_ops = &brcmf_ethtool_ops;
627 drvr->rxsz = ndev->mtu + ndev->hard_header_len +
630 /* set the mac address */
631 memcpy(ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
633 INIT_WORK(&ifp->setmacaddr_work, _brcmf_set_mac_address);
634 INIT_WORK(&ifp->multicast_work, _brcmf_set_multicast_list);
637 err = register_netdevice(ndev);
639 err = register_netdev(ndev);
641 brcmf_err("couldn't register the net device\n");
645 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
650 ndev->netdev_ops = NULL;
654 static int brcmf_net_p2p_open(struct net_device *ndev)
656 brcmf_dbg(TRACE, "Enter\n");
658 return brcmf_cfg80211_up(ndev);
661 static int brcmf_net_p2p_stop(struct net_device *ndev)
663 brcmf_dbg(TRACE, "Enter\n");
665 return brcmf_cfg80211_down(ndev);
668 static int brcmf_net_p2p_do_ioctl(struct net_device *ndev,
669 struct ifreq *ifr, int cmd)
671 brcmf_dbg(TRACE, "Enter\n");
675 static netdev_tx_t brcmf_net_p2p_start_xmit(struct sk_buff *skb,
676 struct net_device *ndev)
679 dev_kfree_skb_any(skb);
684 static const struct net_device_ops brcmf_netdev_ops_p2p = {
685 .ndo_open = brcmf_net_p2p_open,
686 .ndo_stop = brcmf_net_p2p_stop,
687 .ndo_do_ioctl = brcmf_net_p2p_do_ioctl,
688 .ndo_start_xmit = brcmf_net_p2p_start_xmit
691 static int brcmf_net_p2p_attach(struct brcmf_if *ifp)
693 struct net_device *ndev;
695 brcmf_dbg(TRACE, "Enter, idx=%d mac=%pM\n", ifp->bssidx,
699 ndev->netdev_ops = &brcmf_netdev_ops_p2p;
701 /* set the mac address */
702 memcpy(ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
704 if (register_netdev(ndev) != 0) {
705 brcmf_err("couldn't register the p2p net device\n");
709 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
717 struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bssidx, s32 ifidx,
718 char *name, u8 *mac_addr)
720 struct brcmf_if *ifp;
721 struct net_device *ndev;
723 brcmf_dbg(TRACE, "Enter, idx=%d, ifidx=%d\n", bssidx, ifidx);
725 ifp = drvr->iflist[bssidx];
727 * Delete the existing interface before overwriting it
728 * in case we missed the BRCMF_E_IF_DEL event.
731 brcmf_err("ERROR: netdev:%s already exists\n",
734 netif_stop_queue(ifp->ndev);
735 unregister_netdev(ifp->ndev);
736 free_netdev(ifp->ndev);
737 drvr->iflist[bssidx] = NULL;
739 brcmf_err("ignore IF event\n");
740 return ERR_PTR(-EINVAL);
744 /* Allocate netdev, including space for private structure */
745 ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
747 brcmf_err("OOM - alloc_netdev\n");
748 return ERR_PTR(-ENOMEM);
751 ifp = netdev_priv(ndev);
754 drvr->iflist[bssidx] = ifp;
756 ifp->bssidx = bssidx;
759 init_waitqueue_head(&ifp->pend_8021x_wait);
761 if (mac_addr != NULL)
762 memcpy(ifp->mac_addr, mac_addr, ETH_ALEN);
764 brcmf_dbg(TRACE, " ==== pid:%x, if:%s (%pM) created ===\n",
765 current->pid, ifp->ndev->name, ifp->mac_addr);
770 void brcmf_del_if(struct brcmf_pub *drvr, s32 bssidx)
772 struct brcmf_if *ifp;
774 ifp = drvr->iflist[bssidx];
776 brcmf_err("Null interface, idx=%d\n", bssidx);
779 brcmf_dbg(TRACE, "Enter, idx=%d, ifidx=%d\n", bssidx, ifp->ifidx);
782 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
784 brcmf_netdev_stop(ifp->ndev);
788 netif_stop_queue(ifp->ndev);
791 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
792 cancel_work_sync(&ifp->setmacaddr_work);
793 cancel_work_sync(&ifp->multicast_work);
796 unregister_netdev(ifp->ndev);
797 drvr->iflist[bssidx] = NULL;
799 brcmf_cfg80211_detach(drvr->config);
800 free_netdev(ifp->ndev);
804 int brcmf_attach(uint bus_hdrlen, struct device *dev)
806 struct brcmf_pub *drvr = NULL;
809 brcmf_dbg(TRACE, "Enter\n");
811 /* Allocate primary brcmf_info */
812 drvr = kzalloc(sizeof(struct brcmf_pub), GFP_ATOMIC);
816 mutex_init(&drvr->proto_block);
818 /* Link to bus module */
819 drvr->hdrlen = bus_hdrlen;
820 drvr->bus_if = dev_get_drvdata(dev);
821 drvr->bus_if->drvr = drvr;
823 /* create device debugfs folder */
824 brcmf_debugfs_attach(drvr);
826 /* Attach and link in the protocol */
827 ret = brcmf_proto_attach(drvr);
829 brcmf_err("brcmf_prot_attach failed\n");
833 /* attach firmware event handler */
834 brcmf_fweh_attach(drvr);
836 INIT_LIST_HEAD(&drvr->bus_if->dcmd_list);
846 int brcmf_bus_start(struct device *dev)
849 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
850 struct brcmf_pub *drvr = bus_if->drvr;
851 struct brcmf_if *ifp;
852 struct brcmf_if *p2p_ifp;
854 brcmf_dbg(TRACE, "\n");
856 /* Bring up the bus */
857 ret = brcmf_bus_init(bus_if);
859 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret);
863 /* add primary networking interface */
864 ifp = brcmf_add_if(drvr, 0, 0, "wlan%d", NULL);
868 if (brcmf_p2p_enable)
869 p2p_ifp = brcmf_add_if(drvr, 1, 0, "p2p%d", NULL);
875 /* signal bus ready */
876 bus_if->state = BRCMF_BUS_DATA;
878 /* Bus is ready, do any initialization */
879 ret = brcmf_c_preinit_dcmds(ifp);
883 drvr->fw_signals = true;
884 (void)brcmf_fws_init(drvr);
886 drvr->config = brcmf_cfg80211_attach(drvr, bus_if->dev);
887 if (drvr->config == NULL) {
892 ret = brcmf_fweh_activate_events(ifp);
896 ret = brcmf_net_attach(ifp, false);
899 brcmf_err("failed: %d\n", ret);
901 brcmf_cfg80211_detach(drvr->config);
903 brcmf_fws_deinit(drvr);
904 free_netdev(ifp->ndev);
905 drvr->iflist[0] = NULL;
907 free_netdev(p2p_ifp->ndev);
908 drvr->iflist[1] = NULL;
912 if ((brcmf_p2p_enable) && (p2p_ifp))
913 brcmf_net_p2p_attach(p2p_ifp);
918 static void brcmf_bus_detach(struct brcmf_pub *drvr)
920 brcmf_dbg(TRACE, "Enter\n");
923 /* Stop the protocol module */
924 brcmf_proto_stop(drvr);
926 /* Stop the bus module */
927 brcmf_bus_stop(drvr->bus_if);
931 void brcmf_dev_reset(struct device *dev)
933 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
934 struct brcmf_pub *drvr = bus_if->drvr;
940 brcmf_fil_cmd_int_set(drvr->iflist[0], BRCMF_C_TERMINATED, 1);
943 void brcmf_detach(struct device *dev)
946 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
947 struct brcmf_pub *drvr = bus_if->drvr;
949 brcmf_dbg(TRACE, "Enter\n");
954 /* stop firmware event handling */
955 brcmf_fweh_detach(drvr);
957 /* make sure primary interface removed last */
958 for (i = BRCMF_MAX_IFS-1; i > -1; i--)
960 brcmf_del_if(drvr, i);
962 brcmf_bus_detach(drvr);
965 brcmf_proto_detach(drvr);
968 brcmf_fws_deinit(drvr);
970 brcmf_debugfs_detach(drvr);
975 static int brcmf_get_pend_8021x_cnt(struct brcmf_if *ifp)
977 return atomic_read(&ifp->pend_8021x_cnt);
980 int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
982 struct brcmf_if *ifp = netdev_priv(ndev);
985 err = wait_event_timeout(ifp->pend_8021x_wait,
986 !brcmf_get_pend_8021x_cnt(ifp),
987 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX));
995 * return chip id and rev of the device encoded in u32.
997 u32 brcmf_get_chip_info(struct brcmf_if *ifp)
999 struct brcmf_bus *bus = ifp->drvr->bus_if;
1001 return bus->chip << 4 | bus->chiprev;
1004 static void brcmf_driver_init(struct work_struct *work)
1006 brcmf_debugfs_init();
1008 #ifdef CONFIG_BRCMFMAC_SDIO
1011 #ifdef CONFIG_BRCMFMAC_USB
1015 static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init);
1017 static int __init brcmfmac_module_init(void)
1019 if (!schedule_work(&brcmf_driver_work))
1025 static void __exit brcmfmac_module_exit(void)
1027 cancel_work_sync(&brcmf_driver_work);
1029 #ifdef CONFIG_BRCMFMAC_SDIO
1032 #ifdef CONFIG_BRCMFMAC_USB
1035 brcmf_debugfs_exit();
1038 module_init(brcmfmac_module_init);
1039 module_exit(brcmfmac_module_exit);