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 static int brcmf_host_event(struct brcmf_pub *drvr, int *ifidx,
298 void *pktdata, struct brcmf_event_msg *event,
303 bcmerror = brcmf_c_host_event(drvr, ifidx, pktdata, event, data);
307 if (drvr->iflist[*ifidx]->ndev)
308 brcmf_cfg80211_event(drvr->iflist[*ifidx]->ndev,
314 void brcmf_rx_frame(struct device *dev, int ifidx,
315 struct sk_buff_head *skb_list)
320 struct sk_buff *skb, *pnext;
321 struct brcmf_if *ifp;
322 struct brcmf_event_msg event;
323 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
324 struct brcmf_pub *drvr = bus_if->drvr;
326 brcmf_dbg(TRACE, "Enter\n");
328 skb_queue_walk_safe(skb_list, skb, pnext) {
329 skb_unlink(skb, skb_list);
331 /* Get the protocol, maintain skb around eth_type_trans()
332 * The main reason for this hack is for the limitation of
333 * Linux 2.4 where 'eth_type_trans' uses the
334 * 'net->hard_header_len'
335 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
336 * coping of the packet coming from the network stack to add
337 * BDC, Hardware header etc, during network interface
339 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
341 * for BDC, Hardware header etc. and not just the ETH_HLEN
346 ifp = drvr->iflist[ifidx];
348 ifp = drvr->iflist[0];
350 if (!ifp || !ifp->ndev ||
351 ifp->ndev->reg_state != NETREG_REGISTERED) {
352 brcmu_pkt_buf_free_skb(skb);
356 skb->dev = ifp->ndev;
357 skb->protocol = eth_type_trans(skb, skb->dev);
359 if (skb->pkt_type == PACKET_MULTICAST)
360 bus_if->dstats.multicast++;
365 /* Strip header, count, deliver upward */
366 skb_pull(skb, ETH_HLEN);
368 /* Process special event packets and then discard them */
369 if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
370 brcmf_host_event(drvr, &ifidx,
374 if (drvr->iflist[ifidx]) {
375 ifp = drvr->iflist[ifidx];
376 ifp->ndev->last_rx = jiffies;
379 bus_if->dstats.rx_bytes += skb->len;
380 bus_if->dstats.rx_packets++; /* Local count */
385 /* If the receive is not processed inside an ISR,
386 * the softirqd must be woken explicitly to service
387 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
388 * by netif_rx_ni(), but in earlier kernels, we need
395 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success)
400 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
401 struct brcmf_pub *drvr = bus_if->drvr;
403 brcmf_proto_hdrpull(dev, &ifidx, txp);
405 eh = (struct ethhdr *)(txp->data);
406 type = ntohs(eh->h_proto);
408 if (type == ETH_P_PAE) {
409 atomic_dec(&drvr->pend_8021x_cnt);
410 if (waitqueue_active(&drvr->pend_8021x_wait))
411 wake_up(&drvr->pend_8021x_wait);
415 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
417 struct brcmf_if *ifp = netdev_priv(ndev);
418 struct brcmf_bus *bus_if = ifp->drvr->bus_if;
420 brcmf_dbg(TRACE, "Enter\n");
422 /* Copy dongle stats to net device stats */
423 ifp->stats.rx_packets = bus_if->dstats.rx_packets;
424 ifp->stats.tx_packets = bus_if->dstats.tx_packets;
425 ifp->stats.rx_bytes = bus_if->dstats.rx_bytes;
426 ifp->stats.tx_bytes = bus_if->dstats.tx_bytes;
427 ifp->stats.rx_errors = bus_if->dstats.rx_errors;
428 ifp->stats.tx_errors = bus_if->dstats.tx_errors;
429 ifp->stats.rx_dropped = bus_if->dstats.rx_dropped;
430 ifp->stats.tx_dropped = bus_if->dstats.tx_dropped;
431 ifp->stats.multicast = bus_if->dstats.multicast;
437 * Set current toe component enables in toe_ol iovar,
438 * and set toe global enable iovar
440 static int brcmf_toe_set(struct brcmf_if *ifp, u32 toe_ol)
444 err = brcmf_fil_iovar_int_set(ifp, "toe_ol", toe_ol);
446 brcmf_dbg(ERROR, "Setting toe_ol failed, %d\n", err);
450 err = brcmf_fil_iovar_int_set(ifp, "toe", (toe_ol != 0));
452 brcmf_dbg(ERROR, "Setting toe failed, %d\n", err);
458 static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
459 struct ethtool_drvinfo *info)
461 struct brcmf_if *ifp = netdev_priv(ndev);
462 struct brcmf_pub *drvr = ifp->drvr;
464 sprintf(info->driver, KBUILD_MODNAME);
465 sprintf(info->version, "%lu", drvr->drv_version);
466 sprintf(info->bus_info, "%s", dev_name(drvr->dev));
469 static const struct ethtool_ops brcmf_ethtool_ops = {
470 .get_drvinfo = brcmf_ethtool_get_drvinfo,
473 static int brcmf_ethtool(struct brcmf_if *ifp, void __user *uaddr)
475 struct brcmf_pub *drvr = ifp->drvr;
476 struct ethtool_drvinfo info;
477 char drvname[sizeof(info.driver)];
479 struct ethtool_value edata;
480 u32 toe_cmpnt, csum_dir;
483 brcmf_dbg(TRACE, "Enter\n");
485 /* all ethtool calls start with a cmd word */
486 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
490 case ETHTOOL_GDRVINFO:
491 /* Copy out any request driver name */
492 if (copy_from_user(&info, uaddr, sizeof(info)))
494 strncpy(drvname, info.driver, sizeof(info.driver));
495 drvname[sizeof(info.driver) - 1] = '\0';
497 /* clear struct for return */
498 memset(&info, 0, sizeof(info));
501 /* if requested, identify ourselves */
502 if (strcmp(drvname, "?dhd") == 0) {
503 sprintf(info.driver, "dhd");
504 strcpy(info.version, BRCMF_VERSION_STR);
507 /* otherwise, require dongle to be up */
508 else if (!drvr->bus_if->drvr_up) {
509 brcmf_dbg(ERROR, "dongle is not up\n");
512 /* finally, report dongle driver type */
514 sprintf(info.driver, "wl");
516 sprintf(info.version, "%lu", drvr->drv_version);
517 if (copy_to_user(uaddr, &info, sizeof(info)))
519 brcmf_dbg(CTL, "given %*s, returning %s\n",
520 (int)sizeof(drvname), drvname, info.driver);
523 /* Get toe offload components from dongle */
524 case ETHTOOL_GRXCSUM:
525 case ETHTOOL_GTXCSUM:
526 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
531 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
534 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
536 if (copy_to_user(uaddr, &edata, sizeof(edata)))
540 /* Set toe offload components in dongle */
541 case ETHTOOL_SRXCSUM:
542 case ETHTOOL_STXCSUM:
543 if (copy_from_user(&edata, uaddr, sizeof(edata)))
546 /* Read the current settings, update and write back */
547 ret = brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_cmpnt);
552 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
555 toe_cmpnt |= csum_dir;
557 toe_cmpnt &= ~csum_dir;
559 ret = brcmf_toe_set(ifp, toe_cmpnt);
563 /* If setting TX checksum mode, tell Linux the new mode */
564 if (cmd == ETHTOOL_STXCSUM) {
566 ifp->ndev->features |= NETIF_F_IP_CSUM;
568 ifp->ndev->features &= ~NETIF_F_IP_CSUM;
580 static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
583 struct brcmf_if *ifp = netdev_priv(ndev);
584 struct brcmf_pub *drvr = ifp->drvr;
586 brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd);
588 if (!drvr->iflist[ifp->idx])
591 if (cmd == SIOCETHTOOL)
592 return brcmf_ethtool(ifp, ifr->ifr_data);
597 static int brcmf_netdev_stop(struct net_device *ndev)
599 struct brcmf_if *ifp = netdev_priv(ndev);
600 struct brcmf_pub *drvr = ifp->drvr;
602 brcmf_dbg(TRACE, "Enter\n");
603 brcmf_cfg80211_down(drvr->config);
604 if (drvr->bus_if->drvr_up == 0)
607 /* Set state and stop OS transmissions */
608 drvr->bus_if->drvr_up = false;
609 netif_stop_queue(ndev);
614 static int brcmf_netdev_open(struct net_device *ndev)
616 struct brcmf_if *ifp = netdev_priv(ndev);
617 struct brcmf_pub *drvr = ifp->drvr;
618 struct brcmf_bus *bus_if = drvr->bus_if;
622 brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
624 if (ifp->idx == 0) { /* do it only for primary eth0 */
625 /* If bus is not ready, can't continue */
626 if (bus_if->state != BRCMF_BUS_DATA) {
627 brcmf_dbg(ERROR, "failed bus is not ready\n");
631 atomic_set(&drvr->pend_8021x_cnt, 0);
633 memcpy(ndev->dev_addr, drvr->mac, ETH_ALEN);
635 /* Get current TOE mode from dongle */
636 if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0
637 && (toe_ol & TOE_TX_CSUM_OL) != 0)
638 drvr->iflist[ifp->idx]->ndev->features |=
641 drvr->iflist[ifp->idx]->ndev->features &=
645 /* make sure RF is ready for work */
646 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
648 /* Allow transmit calls */
649 netif_start_queue(ndev);
650 drvr->bus_if->drvr_up = true;
651 if (brcmf_cfg80211_up(drvr->config)) {
652 brcmf_dbg(ERROR, "failed to bring up cfg80211\n");
659 static const struct net_device_ops brcmf_netdev_ops_pri = {
660 .ndo_open = brcmf_netdev_open,
661 .ndo_stop = brcmf_netdev_stop,
662 .ndo_get_stats = brcmf_netdev_get_stats,
663 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
664 .ndo_start_xmit = brcmf_netdev_start_xmit,
665 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
666 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
669 int brcmf_net_attach(struct brcmf_if *ifp)
671 struct brcmf_pub *drvr = ifp->drvr;
672 struct net_device *ndev;
673 u8 temp_addr[ETH_ALEN];
675 brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
677 ndev = drvr->iflist[ifp->idx]->ndev;
678 ndev->netdev_ops = &brcmf_netdev_ops_pri;
681 * determine mac address to use
683 if (is_valid_ether_addr(ifp->mac_addr))
684 memcpy(temp_addr, ifp->mac_addr, ETH_ALEN);
686 memcpy(temp_addr, drvr->mac, ETH_ALEN);
689 brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
690 /* ACCESSPOINT INTERFACE CASE */
691 temp_addr[0] |= 0X02; /* set bit 2 ,
692 - Locally Administered address */
695 ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
696 ndev->ethtool_ops = &brcmf_ethtool_ops;
698 drvr->rxsz = ndev->mtu + ndev->hard_header_len +
701 memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
703 if (register_netdev(ndev) != 0) {
704 brcmf_dbg(ERROR, "couldn't register the net device\n");
708 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
713 ndev->netdev_ops = NULL;
717 struct brcmf_if *brcmf_add_if(struct device *dev, int ifidx, s32 bssidx,
718 char *name, u8 *mac_addr)
720 struct brcmf_if *ifp;
721 struct net_device *ndev;
722 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
723 struct brcmf_pub *drvr = bus_if->drvr;
725 brcmf_dbg(TRACE, "idx %d\n", ifidx);
727 ifp = drvr->iflist[ifidx];
729 * Delete the existing interface before overwriting it
730 * in case we missed the BRCMF_E_IF_DEL event.
733 brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n",
735 netif_stop_queue(ifp->ndev);
736 unregister_netdev(ifp->ndev);
737 free_netdev(ifp->ndev);
738 drvr->iflist[ifidx] = NULL;
741 /* Allocate netdev, including space for private structure */
742 ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
744 brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
745 return ERR_PTR(-ENOMEM);
748 ifp = netdev_priv(ndev);
751 drvr->iflist[ifidx] = ifp;
753 ifp->bssidx = bssidx;
754 if (mac_addr != NULL)
755 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
757 brcmf_dbg(TRACE, " ==== pid:%x, net_device for if:%s created ===\n",
758 current->pid, ifp->ndev->name);
763 void brcmf_del_if(struct brcmf_pub *drvr, int ifidx)
765 struct brcmf_if *ifp;
767 brcmf_dbg(TRACE, "idx %d\n", ifidx);
769 ifp = drvr->iflist[ifidx];
771 brcmf_dbg(ERROR, "Null interface\n");
776 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
778 brcmf_netdev_stop(ifp->ndev);
782 netif_stop_queue(ifp->ndev);
785 unregister_netdev(ifp->ndev);
786 drvr->iflist[ifidx] = NULL;
788 brcmf_cfg80211_detach(drvr->config);
789 free_netdev(ifp->ndev);
793 int brcmf_attach(uint bus_hdrlen, struct device *dev)
795 struct brcmf_pub *drvr = NULL;
798 brcmf_dbg(TRACE, "Enter\n");
800 /* Allocate primary brcmf_info */
801 drvr = kzalloc(sizeof(struct brcmf_pub), GFP_ATOMIC);
805 mutex_init(&drvr->proto_block);
807 /* Link to bus module */
808 drvr->hdrlen = bus_hdrlen;
809 drvr->bus_if = dev_get_drvdata(dev);
810 drvr->bus_if->drvr = drvr;
813 /* create device debugfs folder */
814 brcmf_debugfs_attach(drvr);
816 /* Attach and link in the protocol */
817 ret = brcmf_proto_attach(drvr);
819 brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
823 INIT_WORK(&drvr->setmacaddr_work, _brcmf_set_mac_address);
824 INIT_WORK(&drvr->multicast_work, _brcmf_set_multicast_list);
826 INIT_LIST_HEAD(&drvr->bus_if->dcmd_list);
828 init_waitqueue_head(&drvr->pend_8021x_wait);
838 int brcmf_bus_start(struct device *dev)
841 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
842 struct brcmf_pub *drvr = bus_if->drvr;
843 struct brcmf_if *ifp;
845 brcmf_dbg(TRACE, "\n");
847 /* Bring up the bus */
848 ret = bus_if->brcmf_bus_init(dev);
850 brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
854 /* add primary networking interface */
855 ifp = brcmf_add_if(dev, 0, 0, "wlan%d", NULL);
859 /* signal bus ready */
860 bus_if->state = BRCMF_BUS_DATA;
862 /* Bus is ready, do any initialization */
863 ret = brcmf_c_preinit_dcmds(ifp);
867 drvr->config = brcmf_cfg80211_attach(drvr);
868 if (drvr->config == NULL) {
873 ret = brcmf_net_attach(ifp);
876 brcmf_dbg(ERROR, "brcmf_net_attach failed");
878 brcmf_cfg80211_detach(drvr->config);
879 free_netdev(drvr->iflist[0]->ndev);
880 drvr->iflist[0] = NULL;
887 static void brcmf_bus_detach(struct brcmf_pub *drvr)
889 brcmf_dbg(TRACE, "Enter\n");
892 /* Stop the protocol module */
893 brcmf_proto_stop(drvr);
895 /* Stop the bus module */
896 drvr->bus_if->brcmf_bus_stop(drvr->dev);
900 void brcmf_detach(struct device *dev)
903 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
904 struct brcmf_pub *drvr = bus_if->drvr;
906 brcmf_dbg(TRACE, "Enter\n");
909 /* make sure primary interface removed last */
910 for (i = BRCMF_MAX_IFS-1; i > -1; i--)
912 brcmf_del_if(drvr, i);
914 brcmf_bus_detach(drvr);
917 cancel_work_sync(&drvr->setmacaddr_work);
918 cancel_work_sync(&drvr->multicast_work);
919 brcmf_proto_detach(drvr);
922 brcmf_debugfs_detach(drvr);
927 static int brcmf_get_pend_8021x_cnt(struct brcmf_pub *drvr)
929 return atomic_read(&drvr->pend_8021x_cnt);
932 int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
934 struct brcmf_if *ifp = netdev_priv(ndev);
935 struct brcmf_pub *drvr = ifp->drvr;
938 err = wait_event_timeout(drvr->pend_8021x_wait,
939 !brcmf_get_pend_8021x_cnt(drvr),
940 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX));
947 static void brcmf_driver_init(struct work_struct *work)
949 brcmf_debugfs_init();
951 #ifdef CONFIG_BRCMFMAC_SDIO
954 #ifdef CONFIG_BRCMFMAC_USB
958 static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init);
960 static int __init brcmfmac_module_init(void)
962 if (!schedule_work(&brcmf_driver_work))
968 static void __exit brcmfmac_module_exit(void)
970 cancel_work_sync(&brcmf_driver_work);
972 #ifdef CONFIG_BRCMFMAC_SDIO
975 #ifdef CONFIG_BRCMFMAC_USB
978 brcmf_debugfs_exit();
981 module_init(brcmfmac_module_init);
982 module_exit(brcmfmac_module_exit);