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_if(struct brcmf_if *ifp,
252 enum brcmf_netif_stop_reason reason, bool state)
257 brcmf_dbg(TRACE, "enter: idx=%d stop=0x%X reason=%d state=%d\n",
258 ifp->bssidx, ifp->netif_stop, reason, state);
260 if (!ifp->netif_stop)
261 netif_stop_queue(ifp->ndev);
262 ifp->netif_stop |= reason;
264 ifp->netif_stop &= ~reason;
265 if (!ifp->netif_stop)
266 netif_wake_queue(ifp->ndev);
270 void brcmf_txflowblock(struct device *dev, bool state)
272 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
273 struct brcmf_pub *drvr = bus_if->drvr;
276 brcmf_dbg(TRACE, "Enter\n");
278 for (i = 0; i < BRCMF_MAX_IFS; i++)
279 brcmf_txflowblock_if(drvr->iflist[i],
280 BRCMF_NETIF_STOP_REASON_BLOCK_BUS, state);
283 void brcmf_rx_frames(struct device *dev, struct sk_buff_head *skb_list)
287 struct sk_buff *skb, *pnext;
288 struct brcmf_if *ifp;
289 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
290 struct brcmf_pub *drvr = bus_if->drvr;
294 brcmf_dbg(TRACE, "Enter\n");
296 skb_queue_walk_safe(skb_list, skb, pnext) {
297 skb_unlink(skb, skb_list);
299 /* process and remove protocol-specific header */
300 ret = brcmf_proto_hdrpull(drvr, drvr->fw_signals, &ifidx, skb);
301 ifp = drvr->iflist[ifidx];
303 if (ret || !ifp || !ifp->ndev) {
304 if ((ret != -ENODATA) && ifp)
305 ifp->stats.rx_errors++;
306 brcmu_pkt_buf_free_skb(skb);
310 /* Get the protocol, maintain skb around eth_type_trans()
311 * The main reason for this hack is for the limitation of
312 * Linux 2.4 where 'eth_type_trans' uses the
313 * 'net->hard_header_len'
314 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
315 * coping of the packet coming from the network stack to add
316 * BDC, Hardware header etc, during network interface
318 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
320 * for BDC, Hardware header etc. and not just the ETH_HLEN
325 skb->dev = ifp->ndev;
326 skb->protocol = eth_type_trans(skb, skb->dev);
328 if (skb->pkt_type == PACKET_MULTICAST)
329 ifp->stats.multicast++;
334 /* Strip header, count, deliver upward */
335 skb_pull(skb, ETH_HLEN);
337 /* Process special event packets and then discard them */
338 brcmf_fweh_process_skb(drvr, skb, &ifidx);
340 if (drvr->iflist[ifidx]) {
341 ifp = drvr->iflist[ifidx];
342 ifp->ndev->last_rx = jiffies;
345 if (!(ifp->ndev->flags & IFF_UP)) {
346 brcmu_pkt_buf_free_skb(skb);
350 ifp->stats.rx_bytes += skb->len;
351 ifp->stats.rx_packets++;
356 /* If the receive is not processed inside an ISR,
357 * the softirqd must be woken explicitly to service
358 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
359 * by netif_rx_ni(), but in earlier kernels, we need
366 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success)
371 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
372 struct brcmf_pub *drvr = bus_if->drvr;
373 struct brcmf_if *ifp;
376 res = brcmf_proto_hdrpull(drvr, false, &ifidx, txp);
378 ifp = drvr->iflist[ifidx];
383 eh = (struct ethhdr *)(txp->data);
384 type = ntohs(eh->h_proto);
386 if (type == ETH_P_PAE) {
387 atomic_dec(&ifp->pend_8021x_cnt);
388 if (waitqueue_active(&ifp->pend_8021x_wait))
389 wake_up(&ifp->pend_8021x_wait);
393 ifp->stats.tx_errors++;
396 brcmu_pkt_buf_free_skb(txp);
399 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
401 struct brcmf_if *ifp = netdev_priv(ndev);
403 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
409 * Set current toe component enables in toe_ol iovar,
410 * and set toe global enable iovar
412 static int brcmf_toe_set(struct brcmf_if *ifp, u32 toe_ol)
416 err = brcmf_fil_iovar_int_set(ifp, "toe_ol", toe_ol);
418 brcmf_err("Setting toe_ol failed, %d\n", err);
422 err = brcmf_fil_iovar_int_set(ifp, "toe", (toe_ol != 0));
424 brcmf_err("Setting toe failed, %d\n", err);
430 static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
431 struct ethtool_drvinfo *info)
433 struct brcmf_if *ifp = netdev_priv(ndev);
434 struct brcmf_pub *drvr = ifp->drvr;
436 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
437 snprintf(info->version, sizeof(info->version), "%lu",
439 strlcpy(info->bus_info, dev_name(drvr->bus_if->dev),
440 sizeof(info->bus_info));
443 static const struct ethtool_ops brcmf_ethtool_ops = {
444 .get_drvinfo = brcmf_ethtool_get_drvinfo,
447 static int brcmf_ethtool(struct brcmf_if *ifp, void __user *uaddr)
449 struct brcmf_pub *drvr = ifp->drvr;
450 struct ethtool_drvinfo info;
451 char drvname[sizeof(info.driver)];
453 struct ethtool_value edata;
454 u32 toe_cmpnt, csum_dir;
457 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
459 /* all ethtool calls start with a cmd word */
460 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
464 case ETHTOOL_GDRVINFO:
465 /* Copy out any request driver name */
466 if (copy_from_user(&info, uaddr, sizeof(info)))
468 strncpy(drvname, info.driver, sizeof(info.driver));
469 drvname[sizeof(info.driver) - 1] = '\0';
471 /* clear struct for return */
472 memset(&info, 0, sizeof(info));
475 /* if requested, identify ourselves */
476 if (strcmp(drvname, "?dhd") == 0) {
477 sprintf(info.driver, "dhd");
478 strcpy(info.version, BRCMF_VERSION_STR);
480 /* report dongle driver type */
482 sprintf(info.driver, "wl");
484 sprintf(info.version, "%lu", drvr->drv_version);
485 if (copy_to_user(uaddr, &info, sizeof(info)))
487 brcmf_dbg(TRACE, "given %*s, returning %s\n",
488 (int)sizeof(drvname), drvname, info.driver);
491 /* Get toe offload components from dongle */
492 case ETHTOOL_GRXCSUM:
493 case ETHTOOL_GTXCSUM:
494 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
499 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
502 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
504 if (copy_to_user(uaddr, &edata, sizeof(edata)))
508 /* Set toe offload components in dongle */
509 case ETHTOOL_SRXCSUM:
510 case ETHTOOL_STXCSUM:
511 if (copy_from_user(&edata, uaddr, sizeof(edata)))
514 /* Read the current settings, update and write back */
515 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
520 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
523 toe_cmpnt |= csum_dir;
525 toe_cmpnt &= ~csum_dir;
527 ret = brcmf_toe_set(ifp, toe_cmpnt);
531 /* If setting TX checksum mode, tell Linux the new mode */
532 if (cmd == ETHTOOL_STXCSUM) {
534 ifp->ndev->features |= NETIF_F_IP_CSUM;
536 ifp->ndev->features &= ~NETIF_F_IP_CSUM;
548 static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
551 struct brcmf_if *ifp = netdev_priv(ndev);
552 struct brcmf_pub *drvr = ifp->drvr;
554 brcmf_dbg(TRACE, "Enter, idx=%d, cmd=0x%04x\n", ifp->bssidx, cmd);
556 if (!drvr->iflist[ifp->bssidx])
559 if (cmd == SIOCETHTOOL)
560 return brcmf_ethtool(ifp, ifr->ifr_data);
565 static int brcmf_netdev_stop(struct net_device *ndev)
567 struct brcmf_if *ifp = netdev_priv(ndev);
569 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
571 brcmf_cfg80211_down(ndev);
573 /* Set state and stop OS transmissions */
574 netif_stop_queue(ndev);
579 static int brcmf_netdev_open(struct net_device *ndev)
581 struct brcmf_if *ifp = netdev_priv(ndev);
582 struct brcmf_pub *drvr = ifp->drvr;
583 struct brcmf_bus *bus_if = drvr->bus_if;
587 brcmf_dbg(TRACE, "Enter, idx=%d\n", ifp->bssidx);
589 /* If bus is not ready, can't continue */
590 if (bus_if->state != BRCMF_BUS_DATA) {
591 brcmf_err("failed bus is not ready\n");
595 atomic_set(&ifp->pend_8021x_cnt, 0);
597 /* Get current TOE mode from dongle */
598 if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0
599 && (toe_ol & TOE_TX_CSUM_OL) != 0)
600 ndev->features |= NETIF_F_IP_CSUM;
602 ndev->features &= ~NETIF_F_IP_CSUM;
604 /* Allow transmit calls */
605 netif_start_queue(ndev);
606 if (brcmf_cfg80211_up(ndev)) {
607 brcmf_err("failed to bring up cfg80211\n");
614 static const struct net_device_ops brcmf_netdev_ops_pri = {
615 .ndo_open = brcmf_netdev_open,
616 .ndo_stop = brcmf_netdev_stop,
617 .ndo_get_stats = brcmf_netdev_get_stats,
618 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
619 .ndo_start_xmit = brcmf_netdev_start_xmit,
620 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
621 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
624 int brcmf_net_attach(struct brcmf_if *ifp, bool rtnl_locked)
626 struct brcmf_pub *drvr = ifp->drvr;
627 struct net_device *ndev;
630 brcmf_dbg(TRACE, "Enter, idx=%d mac=%pM\n", ifp->bssidx,
634 /* set appropriate operations */
635 ndev->netdev_ops = &brcmf_netdev_ops_pri;
637 ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
638 ndev->ethtool_ops = &brcmf_ethtool_ops;
640 drvr->rxsz = ndev->mtu + ndev->hard_header_len +
643 /* set the mac address */
644 memcpy(ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
646 INIT_WORK(&ifp->setmacaddr_work, _brcmf_set_mac_address);
647 INIT_WORK(&ifp->multicast_work, _brcmf_set_multicast_list);
650 err = register_netdevice(ndev);
652 err = register_netdev(ndev);
654 brcmf_err("couldn't register the net device\n");
658 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
663 ndev->netdev_ops = NULL;
667 static int brcmf_net_p2p_open(struct net_device *ndev)
669 brcmf_dbg(TRACE, "Enter\n");
671 return brcmf_cfg80211_up(ndev);
674 static int brcmf_net_p2p_stop(struct net_device *ndev)
676 brcmf_dbg(TRACE, "Enter\n");
678 return brcmf_cfg80211_down(ndev);
681 static int brcmf_net_p2p_do_ioctl(struct net_device *ndev,
682 struct ifreq *ifr, int cmd)
684 brcmf_dbg(TRACE, "Enter\n");
688 static netdev_tx_t brcmf_net_p2p_start_xmit(struct sk_buff *skb,
689 struct net_device *ndev)
692 dev_kfree_skb_any(skb);
697 static const struct net_device_ops brcmf_netdev_ops_p2p = {
698 .ndo_open = brcmf_net_p2p_open,
699 .ndo_stop = brcmf_net_p2p_stop,
700 .ndo_do_ioctl = brcmf_net_p2p_do_ioctl,
701 .ndo_start_xmit = brcmf_net_p2p_start_xmit
704 static int brcmf_net_p2p_attach(struct brcmf_if *ifp)
706 struct net_device *ndev;
708 brcmf_dbg(TRACE, "Enter, idx=%d mac=%pM\n", ifp->bssidx,
712 ndev->netdev_ops = &brcmf_netdev_ops_p2p;
714 /* set the mac address */
715 memcpy(ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
717 if (register_netdev(ndev) != 0) {
718 brcmf_err("couldn't register the p2p net device\n");
722 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
730 struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bssidx, s32 ifidx,
731 char *name, u8 *mac_addr)
733 struct brcmf_if *ifp;
734 struct net_device *ndev;
736 brcmf_dbg(TRACE, "Enter, idx=%d, ifidx=%d\n", bssidx, ifidx);
738 ifp = drvr->iflist[bssidx];
740 * Delete the existing interface before overwriting it
741 * in case we missed the BRCMF_E_IF_DEL event.
744 brcmf_err("ERROR: netdev:%s already exists\n",
747 netif_stop_queue(ifp->ndev);
748 unregister_netdev(ifp->ndev);
749 free_netdev(ifp->ndev);
750 drvr->iflist[bssidx] = NULL;
752 brcmf_err("ignore IF event\n");
753 return ERR_PTR(-EINVAL);
757 /* Allocate netdev, including space for private structure */
758 ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
760 brcmf_err("OOM - alloc_netdev\n");
761 return ERR_PTR(-ENOMEM);
764 ifp = netdev_priv(ndev);
767 drvr->iflist[bssidx] = ifp;
769 ifp->bssidx = bssidx;
771 init_waitqueue_head(&ifp->pend_8021x_wait);
773 if (mac_addr != NULL)
774 memcpy(ifp->mac_addr, mac_addr, ETH_ALEN);
776 brcmf_dbg(TRACE, " ==== pid:%x, if:%s (%pM) created ===\n",
777 current->pid, ifp->ndev->name, ifp->mac_addr);
782 void brcmf_del_if(struct brcmf_pub *drvr, s32 bssidx)
784 struct brcmf_if *ifp;
786 ifp = drvr->iflist[bssidx];
788 brcmf_err("Null interface, idx=%d\n", bssidx);
791 brcmf_dbg(TRACE, "Enter, idx=%d, ifidx=%d\n", bssidx, ifp->ifidx);
794 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
796 brcmf_netdev_stop(ifp->ndev);
800 netif_stop_queue(ifp->ndev);
803 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
804 cancel_work_sync(&ifp->setmacaddr_work);
805 cancel_work_sync(&ifp->multicast_work);
808 unregister_netdev(ifp->ndev);
809 drvr->iflist[bssidx] = NULL;
811 brcmf_cfg80211_detach(drvr->config);
812 free_netdev(ifp->ndev);
816 int brcmf_attach(uint bus_hdrlen, struct device *dev)
818 struct brcmf_pub *drvr = NULL;
821 brcmf_dbg(TRACE, "Enter\n");
823 /* Allocate primary brcmf_info */
824 drvr = kzalloc(sizeof(struct brcmf_pub), GFP_ATOMIC);
828 mutex_init(&drvr->proto_block);
830 /* Link to bus module */
831 drvr->hdrlen = bus_hdrlen;
832 drvr->bus_if = dev_get_drvdata(dev);
833 drvr->bus_if->drvr = drvr;
835 /* create device debugfs folder */
836 brcmf_debugfs_attach(drvr);
838 /* Attach and link in the protocol */
839 ret = brcmf_proto_attach(drvr);
841 brcmf_err("brcmf_prot_attach failed\n");
845 /* attach firmware event handler */
846 brcmf_fweh_attach(drvr);
848 INIT_LIST_HEAD(&drvr->bus_if->dcmd_list);
858 int brcmf_bus_start(struct device *dev)
861 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
862 struct brcmf_pub *drvr = bus_if->drvr;
863 struct brcmf_if *ifp;
864 struct brcmf_if *p2p_ifp;
866 brcmf_dbg(TRACE, "\n");
868 /* Bring up the bus */
869 ret = brcmf_bus_init(bus_if);
871 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret);
875 /* add primary networking interface */
876 ifp = brcmf_add_if(drvr, 0, 0, "wlan%d", NULL);
880 if (brcmf_p2p_enable)
881 p2p_ifp = brcmf_add_if(drvr, 1, 0, "p2p%d", NULL);
887 /* signal bus ready */
888 bus_if->state = BRCMF_BUS_DATA;
890 /* Bus is ready, do any initialization */
891 ret = brcmf_c_preinit_dcmds(ifp);
895 drvr->fw_signals = true;
896 (void)brcmf_fws_init(drvr);
897 brcmf_fws_add_interface(ifp);
899 drvr->config = brcmf_cfg80211_attach(drvr, bus_if->dev);
900 if (drvr->config == NULL) {
905 ret = brcmf_fweh_activate_events(ifp);
909 ret = brcmf_net_attach(ifp, false);
912 brcmf_err("failed: %d\n", ret);
914 brcmf_cfg80211_detach(drvr->config);
916 brcmf_fws_del_interface(ifp);
917 brcmf_fws_deinit(drvr);
919 free_netdev(ifp->ndev);
920 drvr->iflist[0] = NULL;
922 free_netdev(p2p_ifp->ndev);
923 drvr->iflist[1] = NULL;
927 if ((brcmf_p2p_enable) && (p2p_ifp))
928 brcmf_net_p2p_attach(p2p_ifp);
933 static void brcmf_bus_detach(struct brcmf_pub *drvr)
935 brcmf_dbg(TRACE, "Enter\n");
938 /* Stop the protocol module */
939 brcmf_proto_stop(drvr);
941 /* Stop the bus module */
942 brcmf_bus_stop(drvr->bus_if);
946 void brcmf_dev_reset(struct device *dev)
948 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
949 struct brcmf_pub *drvr = bus_if->drvr;
955 brcmf_fil_cmd_int_set(drvr->iflist[0], BRCMF_C_TERMINATED, 1);
958 void brcmf_detach(struct device *dev)
961 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
962 struct brcmf_pub *drvr = bus_if->drvr;
964 brcmf_dbg(TRACE, "Enter\n");
969 /* stop firmware event handling */
970 brcmf_fweh_detach(drvr);
972 /* make sure primary interface removed last */
973 for (i = BRCMF_MAX_IFS-1; i > -1; i--)
974 if (drvr->iflist[i]) {
975 brcmf_fws_del_interface(drvr->iflist[i]);
976 brcmf_del_if(drvr, i);
979 brcmf_bus_detach(drvr);
982 brcmf_proto_detach(drvr);
985 brcmf_fws_deinit(drvr);
987 brcmf_debugfs_detach(drvr);
992 static int brcmf_get_pend_8021x_cnt(struct brcmf_if *ifp)
994 return atomic_read(&ifp->pend_8021x_cnt);
997 int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
999 struct brcmf_if *ifp = netdev_priv(ndev);
1002 err = wait_event_timeout(ifp->pend_8021x_wait,
1003 !brcmf_get_pend_8021x_cnt(ifp),
1004 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX));
1012 * return chip id and rev of the device encoded in u32.
1014 u32 brcmf_get_chip_info(struct brcmf_if *ifp)
1016 struct brcmf_bus *bus = ifp->drvr->bus_if;
1018 return bus->chip << 4 | bus->chiprev;
1021 static void brcmf_driver_init(struct work_struct *work)
1023 brcmf_debugfs_init();
1025 #ifdef CONFIG_BRCMFMAC_SDIO
1028 #ifdef CONFIG_BRCMFMAC_USB
1032 static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init);
1034 static int __init brcmfmac_module_init(void)
1036 if (!schedule_work(&brcmf_driver_work))
1042 static void __exit brcmfmac_module_exit(void)
1044 cancel_work_sync(&brcmf_driver_work);
1046 #ifdef CONFIG_BRCMFMAC_SDIO
1049 #ifdef CONFIG_BRCMFMAC_USB
1052 brcmf_debugfs_exit();
1055 module_init(brcmfmac_module_init);
1056 module_exit(brcmfmac_module_exit);