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;
109 brcmf_dbg(TRACE, "enter\n");
111 ifp = container_of(work, struct brcmf_if, multicast_work);
114 /* Determine initial value of allmulti flag */
115 cmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false;
117 /* Send down the multicast list first. */
118 cnt = netdev_mc_count(ndev);
119 buflen = sizeof(cnt) + (cnt * ETH_ALEN);
120 buf = kmalloc(buflen, GFP_ATOMIC);
125 cnt_le = cpu_to_le32(cnt);
126 memcpy(bufp, &cnt_le, sizeof(cnt_le));
127 bufp += sizeof(cnt_le);
129 netdev_for_each_mc_addr(ha, ndev) {
132 memcpy(bufp, ha->addr, ETH_ALEN);
137 err = brcmf_fil_iovar_data_set(ifp, "mcast_list", buf, buflen);
139 brcmf_dbg(ERROR, "Setting mcast_list failed, %d\n", err);
140 cmd_value = cnt ? true : cmd_value;
146 * Now send the allmulti setting. This is based on the setting in the
147 * net_device flags, but might be modified above to be turned on if we
148 * were trying to set some addresses and dongle rejected it...
150 err = brcmf_fil_iovar_int_set(ifp, "allmulti", cmd_value);
152 brcmf_dbg(ERROR, "Setting allmulti failed, %d\n", err);
154 /*Finally, pick up the PROMISC flag */
155 cmd_value = (ndev->flags & IFF_PROMISC) ? true : false;
156 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PROMISC, cmd_value);
158 brcmf_dbg(ERROR, "Setting BRCMF_C_SET_PROMISC failed, %d\n",
163 _brcmf_set_mac_address(struct work_struct *work)
165 struct brcmf_if *ifp;
168 brcmf_dbg(TRACE, "enter\n");
170 ifp = container_of(work, struct brcmf_if, setmacaddr_work);
171 err = brcmf_fil_iovar_data_set(ifp, "cur_etheraddr", ifp->mac_addr,
174 brcmf_dbg(ERROR, "Setting cur_etheraddr failed, %d\n", err);
176 brcmf_dbg(TRACE, "MAC address updated to %pM\n",
178 memcpy(ifp->ndev->dev_addr, ifp->mac_addr, ETH_ALEN);
182 static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr)
184 struct brcmf_if *ifp = netdev_priv(ndev);
185 struct sockaddr *sa = (struct sockaddr *)addr;
187 memcpy(&ifp->mac_addr, sa->sa_data, ETH_ALEN);
188 schedule_work(&ifp->setmacaddr_work);
192 static void brcmf_netdev_set_multicast_list(struct net_device *ndev)
194 struct brcmf_if *ifp = netdev_priv(ndev);
196 schedule_work(&ifp->multicast_work);
199 static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *ndev)
202 struct brcmf_if *ifp = netdev_priv(ndev);
203 struct brcmf_pub *drvr = ifp->drvr;
205 brcmf_dbg(TRACE, "Enter\n");
208 if (!drvr->bus_if->drvr_up ||
209 (drvr->bus_if->state != BRCMF_BUS_DATA)) {
210 brcmf_dbg(ERROR, "xmit rejected drvup=%d state=%d\n",
211 drvr->bus_if->drvr_up,
212 drvr->bus_if->state);
213 netif_stop_queue(ndev);
217 if (!drvr->iflist[ifp->idx]) {
218 brcmf_dbg(ERROR, "bad ifidx %d\n", ifp->idx);
219 netif_stop_queue(ndev);
223 /* Make sure there's enough room for any header */
224 if (skb_headroom(skb) < drvr->hdrlen) {
225 struct sk_buff *skb2;
227 brcmf_dbg(INFO, "%s: insufficient headroom\n",
228 brcmf_ifname(drvr, ifp->idx));
229 drvr->bus_if->tx_realloc++;
230 skb2 = skb_realloc_headroom(skb, drvr->hdrlen);
234 brcmf_dbg(ERROR, "%s: skb_realloc_headroom failed\n",
235 brcmf_ifname(drvr, ifp->idx));
241 /* Update multicast statistic */
242 if (skb->len >= ETH_ALEN) {
243 u8 *pktdata = (u8 *)(skb->data);
244 struct ethhdr *eh = (struct ethhdr *)pktdata;
246 if (is_multicast_ether_addr(eh->h_dest))
247 drvr->tx_multicast++;
248 if (ntohs(eh->h_proto) == ETH_P_PAE)
249 atomic_inc(&drvr->pend_8021x_cnt);
252 /* If the protocol uses a data header, apply it */
253 brcmf_proto_hdrpush(drvr, ifp->idx, skb);
255 /* Use bus module to send data frame */
256 ret = drvr->bus_if->brcmf_bus_txdata(drvr->dev, skb);
260 drvr->bus_if->dstats.tx_dropped++;
262 drvr->bus_if->dstats.tx_packets++;
264 /* Return ok: we always eat the packet */
268 void brcmf_txflowblock(struct device *dev, bool state)
270 struct net_device *ndev;
271 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
272 struct brcmf_pub *drvr = bus_if->drvr;
275 brcmf_dbg(TRACE, "Enter\n");
277 for (i = 0; i < BRCMF_MAX_IFS; i++)
278 if (drvr->iflist[i]) {
279 ndev = drvr->iflist[i]->ndev;
281 netif_stop_queue(ndev);
283 netif_wake_queue(ndev);
287 void brcmf_rx_frame(struct device *dev, u8 ifidx,
288 struct sk_buff_head *skb_list)
292 struct sk_buff *skb, *pnext;
293 struct brcmf_if *ifp;
294 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
295 struct brcmf_pub *drvr = bus_if->drvr;
297 brcmf_dbg(TRACE, "Enter\n");
299 skb_queue_walk_safe(skb_list, skb, pnext) {
300 skb_unlink(skb, skb_list);
302 /* Get the protocol, maintain skb around eth_type_trans()
303 * The main reason for this hack is for the limitation of
304 * Linux 2.4 where 'eth_type_trans' uses the
305 * 'net->hard_header_len'
306 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
307 * coping of the packet coming from the network stack to add
308 * BDC, Hardware header etc, during network interface
310 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
312 * for BDC, Hardware header etc. and not just the ETH_HLEN
317 ifp = drvr->iflist[ifidx];
319 ifp = drvr->iflist[0];
321 if (!ifp || !ifp->ndev ||
322 ifp->ndev->reg_state != NETREG_REGISTERED) {
323 brcmu_pkt_buf_free_skb(skb);
327 skb->dev = ifp->ndev;
328 skb->protocol = eth_type_trans(skb, skb->dev);
330 if (skb->pkt_type == PACKET_MULTICAST)
331 bus_if->dstats.multicast++;
336 /* Strip header, count, deliver upward */
337 skb_pull(skb, ETH_HLEN);
339 /* Process special event packets and then discard them */
340 brcmf_fweh_process_skb(drvr, skb, &ifidx);
342 if (drvr->iflist[ifidx]) {
343 ifp = drvr->iflist[ifidx];
344 ifp->ndev->last_rx = jiffies;
347 bus_if->dstats.rx_bytes += skb->len;
348 bus_if->dstats.rx_packets++; /* Local count */
353 /* If the receive is not processed inside an ISR,
354 * the softirqd must be woken explicitly to service
355 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
356 * by netif_rx_ni(), but in earlier kernels, we need
363 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success)
368 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
369 struct brcmf_pub *drvr = bus_if->drvr;
371 brcmf_proto_hdrpull(dev, &ifidx, txp);
373 eh = (struct ethhdr *)(txp->data);
374 type = ntohs(eh->h_proto);
376 if (type == ETH_P_PAE) {
377 atomic_dec(&drvr->pend_8021x_cnt);
378 if (waitqueue_active(&drvr->pend_8021x_wait))
379 wake_up(&drvr->pend_8021x_wait);
383 static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
385 struct brcmf_if *ifp = netdev_priv(ndev);
386 struct brcmf_bus *bus_if = ifp->drvr->bus_if;
388 brcmf_dbg(TRACE, "Enter\n");
390 /* Copy dongle stats to net device stats */
391 ifp->stats.rx_packets = bus_if->dstats.rx_packets;
392 ifp->stats.tx_packets = bus_if->dstats.tx_packets;
393 ifp->stats.rx_bytes = bus_if->dstats.rx_bytes;
394 ifp->stats.tx_bytes = bus_if->dstats.tx_bytes;
395 ifp->stats.rx_errors = bus_if->dstats.rx_errors;
396 ifp->stats.tx_errors = bus_if->dstats.tx_errors;
397 ifp->stats.rx_dropped = bus_if->dstats.rx_dropped;
398 ifp->stats.tx_dropped = bus_if->dstats.tx_dropped;
399 ifp->stats.multicast = bus_if->dstats.multicast;
405 * Set current toe component enables in toe_ol iovar,
406 * and set toe global enable iovar
408 static int brcmf_toe_set(struct brcmf_if *ifp, u32 toe_ol)
412 err = brcmf_fil_iovar_int_set(ifp, "toe_ol", toe_ol);
414 brcmf_dbg(ERROR, "Setting toe_ol failed, %d\n", err);
418 err = brcmf_fil_iovar_int_set(ifp, "toe", (toe_ol != 0));
420 brcmf_dbg(ERROR, "Setting toe failed, %d\n", err);
426 static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
427 struct ethtool_drvinfo *info)
429 struct brcmf_if *ifp = netdev_priv(ndev);
430 struct brcmf_pub *drvr = ifp->drvr;
432 sprintf(info->driver, KBUILD_MODNAME);
433 sprintf(info->version, "%lu", drvr->drv_version);
434 sprintf(info->bus_info, "%s", dev_name(drvr->dev));
437 static const struct ethtool_ops brcmf_ethtool_ops = {
438 .get_drvinfo = brcmf_ethtool_get_drvinfo,
441 static int brcmf_ethtool(struct brcmf_if *ifp, void __user *uaddr)
443 struct brcmf_pub *drvr = ifp->drvr;
444 struct ethtool_drvinfo info;
445 char drvname[sizeof(info.driver)];
447 struct ethtool_value edata;
448 u32 toe_cmpnt, csum_dir;
451 brcmf_dbg(TRACE, "Enter\n");
453 /* all ethtool calls start with a cmd word */
454 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
458 case ETHTOOL_GDRVINFO:
459 /* Copy out any request driver name */
460 if (copy_from_user(&info, uaddr, sizeof(info)))
462 strncpy(drvname, info.driver, sizeof(info.driver));
463 drvname[sizeof(info.driver) - 1] = '\0';
465 /* clear struct for return */
466 memset(&info, 0, sizeof(info));
469 /* if requested, identify ourselves */
470 if (strcmp(drvname, "?dhd") == 0) {
471 sprintf(info.driver, "dhd");
472 strcpy(info.version, BRCMF_VERSION_STR);
475 /* otherwise, require dongle to be up */
476 else if (!drvr->bus_if->drvr_up) {
477 brcmf_dbg(ERROR, "dongle is not up\n");
480 /* finally, 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(CTL, "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, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd);
556 if (!drvr->iflist[ifp->idx])
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);
568 struct brcmf_pub *drvr = ifp->drvr;
570 brcmf_dbg(TRACE, "Enter\n");
572 if (drvr->bus_if->drvr_up == 0)
575 brcmf_cfg80211_down(ndev);
577 /* Set state and stop OS transmissions */
578 drvr->bus_if->drvr_up = false;
579 netif_stop_queue(ndev);
584 static int brcmf_netdev_open(struct net_device *ndev)
586 struct brcmf_if *ifp = netdev_priv(ndev);
587 struct brcmf_pub *drvr = ifp->drvr;
588 struct brcmf_bus *bus_if = drvr->bus_if;
592 brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
594 /* If bus is not ready, can't continue */
595 if (bus_if->state != BRCMF_BUS_DATA) {
596 brcmf_dbg(ERROR, "failed bus is not ready\n");
600 atomic_set(&drvr->pend_8021x_cnt, 0);
602 memcpy(ndev->dev_addr, drvr->mac, ETH_ALEN);
604 /* Get current TOE mode from dongle */
605 if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0
606 && (toe_ol & TOE_TX_CSUM_OL) != 0)
607 drvr->iflist[ifp->idx]->ndev->features |=
610 drvr->iflist[ifp->idx]->ndev->features &=
613 /* make sure RF is ready for work */
614 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
616 /* Allow transmit calls */
617 netif_start_queue(ndev);
618 drvr->bus_if->drvr_up = true;
619 if (brcmf_cfg80211_up(ndev)) {
620 brcmf_dbg(ERROR, "failed to bring up cfg80211\n");
627 static const struct net_device_ops brcmf_netdev_ops_pri = {
628 .ndo_open = brcmf_netdev_open,
629 .ndo_stop = brcmf_netdev_stop,
630 .ndo_get_stats = brcmf_netdev_get_stats,
631 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
632 .ndo_start_xmit = brcmf_netdev_start_xmit,
633 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
634 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
637 static const struct net_device_ops brcmf_netdev_ops_virt = {
638 .ndo_open = brcmf_cfg80211_up,
639 .ndo_stop = brcmf_cfg80211_down,
640 .ndo_get_stats = brcmf_netdev_get_stats,
641 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
642 .ndo_start_xmit = brcmf_netdev_start_xmit,
643 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
644 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
647 int brcmf_net_attach(struct brcmf_if *ifp)
649 struct brcmf_pub *drvr = ifp->drvr;
650 struct net_device *ndev;
651 u8 temp_addr[ETH_ALEN];
653 brcmf_dbg(TRACE, "ifidx %d mac %pM\n", ifp->idx, ifp->mac_addr);
656 /* set appropriate operations */
658 ndev->netdev_ops = &brcmf_netdev_ops_pri;
660 ndev->netdev_ops = &brcmf_netdev_ops_virt;
663 * determine mac address to use
665 if (is_valid_ether_addr(ifp->mac_addr))
666 memcpy(temp_addr, ifp->mac_addr, ETH_ALEN);
668 memcpy(temp_addr, drvr->mac, ETH_ALEN);
670 ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
671 ndev->ethtool_ops = &brcmf_ethtool_ops;
673 drvr->rxsz = ndev->mtu + ndev->hard_header_len +
676 memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
678 if (register_netdev(ndev) != 0) {
679 brcmf_dbg(ERROR, "couldn't register the net device\n");
683 brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
688 ndev->netdev_ops = NULL;
692 struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, int ifidx, s32 bssidx,
693 char *name, u8 *addr_mask)
695 struct brcmf_if *ifp;
696 struct net_device *ndev;
699 brcmf_dbg(TRACE, "idx %d\n", ifidx);
701 ifp = drvr->iflist[ifidx];
703 * Delete the existing interface before overwriting it
704 * in case we missed the BRCMF_E_IF_DEL event.
707 brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n",
709 netif_stop_queue(ifp->ndev);
710 unregister_netdev(ifp->ndev);
711 free_netdev(ifp->ndev);
712 drvr->iflist[ifidx] = NULL;
715 /* Allocate netdev, including space for private structure */
716 ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
718 brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
719 return ERR_PTR(-ENOMEM);
722 ifp = netdev_priv(ndev);
725 drvr->iflist[ifidx] = ifp;
727 ifp->bssidx = bssidx;
729 INIT_WORK(&ifp->setmacaddr_work, _brcmf_set_mac_address);
730 INIT_WORK(&ifp->multicast_work, _brcmf_set_multicast_list);
732 if (addr_mask != NULL)
733 for (i = 0; i < ETH_ALEN; i++)
734 ifp->mac_addr[i] = drvr->mac[i] ^ addr_mask[i];
736 brcmf_dbg(TRACE, " ==== pid:%x, if:%s (%pM) created ===\n",
737 current->pid, ifp->ndev->name, ifp->mac_addr);
742 void brcmf_del_if(struct brcmf_pub *drvr, int ifidx)
744 struct brcmf_if *ifp;
746 brcmf_dbg(TRACE, "idx %d\n", ifidx);
748 ifp = drvr->iflist[ifidx];
750 brcmf_dbg(ERROR, "Null interface\n");
755 if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
757 brcmf_netdev_stop(ifp->ndev);
761 netif_stop_queue(ifp->ndev);
764 cancel_work_sync(&ifp->setmacaddr_work);
765 cancel_work_sync(&ifp->multicast_work);
767 unregister_netdev(ifp->ndev);
768 drvr->iflist[ifidx] = NULL;
770 brcmf_cfg80211_detach(drvr->config);
771 free_netdev(ifp->ndev);
775 int brcmf_attach(uint bus_hdrlen, struct device *dev)
777 struct brcmf_pub *drvr = NULL;
780 brcmf_dbg(TRACE, "Enter\n");
782 /* Allocate primary brcmf_info */
783 drvr = kzalloc(sizeof(struct brcmf_pub), GFP_ATOMIC);
787 mutex_init(&drvr->proto_block);
789 /* Link to bus module */
790 drvr->hdrlen = bus_hdrlen;
791 drvr->bus_if = dev_get_drvdata(dev);
792 drvr->bus_if->drvr = drvr;
795 /* create device debugfs folder */
796 brcmf_debugfs_attach(drvr);
798 /* Attach and link in the protocol */
799 ret = brcmf_proto_attach(drvr);
801 brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
805 /* attach firmware event handler */
806 brcmf_fweh_attach(drvr);
808 INIT_LIST_HEAD(&drvr->bus_if->dcmd_list);
810 init_waitqueue_head(&drvr->pend_8021x_wait);
820 int brcmf_bus_start(struct device *dev)
823 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
824 struct brcmf_pub *drvr = bus_if->drvr;
825 struct brcmf_if *ifp;
827 brcmf_dbg(TRACE, "\n");
829 /* Bring up the bus */
830 ret = bus_if->brcmf_bus_init(dev);
832 brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
836 /* add primary networking interface */
837 ifp = brcmf_add_if(drvr, 0, 0, "wlan%d", NULL);
841 /* signal bus ready */
842 bus_if->state = BRCMF_BUS_DATA;
844 /* Bus is ready, do any initialization */
845 ret = brcmf_c_preinit_dcmds(ifp);
849 drvr->config = brcmf_cfg80211_attach(drvr);
850 if (drvr->config == NULL) {
855 ret = brcmf_fweh_activate_events(ifp);
859 ret = brcmf_net_attach(ifp);
862 brcmf_dbg(ERROR, "failed: %d\n", ret);
864 brcmf_cfg80211_detach(drvr->config);
865 free_netdev(drvr->iflist[0]->ndev);
866 drvr->iflist[0] = NULL;
873 static void brcmf_bus_detach(struct brcmf_pub *drvr)
875 brcmf_dbg(TRACE, "Enter\n");
878 /* Stop the protocol module */
879 brcmf_proto_stop(drvr);
881 /* Stop the bus module */
882 drvr->bus_if->brcmf_bus_stop(drvr->dev);
886 void brcmf_detach(struct device *dev)
889 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
890 struct brcmf_pub *drvr = bus_if->drvr;
892 brcmf_dbg(TRACE, "Enter\n");
897 /* stop firmware event handling */
898 brcmf_fweh_detach(drvr);
900 /* make sure primary interface removed last */
901 for (i = BRCMF_MAX_IFS-1; i > -1; i--)
903 brcmf_del_if(drvr, i);
905 brcmf_bus_detach(drvr);
908 brcmf_proto_detach(drvr);
911 brcmf_debugfs_detach(drvr);
916 static int brcmf_get_pend_8021x_cnt(struct brcmf_pub *drvr)
918 return atomic_read(&drvr->pend_8021x_cnt);
921 int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
923 struct brcmf_if *ifp = netdev_priv(ndev);
924 struct brcmf_pub *drvr = ifp->drvr;
927 err = wait_event_timeout(drvr->pend_8021x_wait,
928 !brcmf_get_pend_8021x_cnt(drvr),
929 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX));
936 static void brcmf_driver_init(struct work_struct *work)
938 brcmf_debugfs_init();
940 #ifdef CONFIG_BRCMFMAC_SDIO
943 #ifdef CONFIG_BRCMFMAC_USB
947 static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init);
949 static int __init brcmfmac_module_init(void)
951 if (!schedule_work(&brcmf_driver_work))
957 static void __exit brcmfmac_module_exit(void)
959 cancel_work_sync(&brcmf_driver_work);
961 #ifdef CONFIG_BRCMFMAC_SDIO
964 #ifdef CONFIG_BRCMFMAC_USB
967 brcmf_debugfs_exit();
970 module_init(brcmfmac_module_init);
971 module_exit(brcmfmac_module_exit);