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/kernel.h>
20 #include <linux/etherdevice.h>
21 #include <linux/module.h>
22 #include <net/cfg80211.h>
23 #include <net/rtnetlink.h>
24 #include <brcmu_utils.h>
25 #include <brcmu_wifi.h>
29 #include "dhd_proto.h"
31 #include "wl_cfg80211.h"
34 MODULE_AUTHOR("Broadcom Corporation");
35 MODULE_DESCRIPTION("Broadcom 802.11 wireless LAN fullmac driver.");
36 MODULE_SUPPORTED_DEVICE("Broadcom 802.11 WLAN fullmac cards");
37 MODULE_LICENSE("Dual BSD/GPL");
39 #define MAX_WAIT_FOR_8021X_TX 50 /* msecs */
43 module_param(brcmf_msg_level
, int, 0);
46 char *brcmf_ifname(struct brcmf_pub
*drvr
, int ifidx
)
48 if (ifidx
< 0 || ifidx
>= BRCMF_MAX_IFS
) {
49 brcmf_err("ifidx %d out of range\n", ifidx
);
53 if (drvr
->iflist
[ifidx
] == NULL
) {
54 brcmf_err("null i/f %d\n", ifidx
);
58 if (drvr
->iflist
[ifidx
]->ndev
)
59 return drvr
->iflist
[ifidx
]->ndev
->name
;
64 static void _brcmf_set_multicast_list(struct work_struct
*work
)
67 struct net_device
*ndev
;
68 struct netdev_hw_addr
*ha
;
75 brcmf_dbg(TRACE
, "enter\n");
77 ifp
= container_of(work
, struct brcmf_if
, multicast_work
);
80 /* Determine initial value of allmulti flag */
81 cmd_value
= (ndev
->flags
& IFF_ALLMULTI
) ? true : false;
83 /* Send down the multicast list first. */
84 cnt
= netdev_mc_count(ndev
);
85 buflen
= sizeof(cnt
) + (cnt
* ETH_ALEN
);
86 buf
= kmalloc(buflen
, GFP_ATOMIC
);
91 cnt_le
= cpu_to_le32(cnt
);
92 memcpy(bufp
, &cnt_le
, sizeof(cnt_le
));
93 bufp
+= sizeof(cnt_le
);
95 netdev_for_each_mc_addr(ha
, ndev
) {
98 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
103 err
= brcmf_fil_iovar_data_set(ifp
, "mcast_list", buf
, buflen
);
105 brcmf_err("Setting mcast_list failed, %d\n", err
);
106 cmd_value
= cnt
? true : cmd_value
;
112 * Now send the allmulti setting. This is based on the setting in the
113 * net_device flags, but might be modified above to be turned on if we
114 * were trying to set some addresses and dongle rejected it...
116 err
= brcmf_fil_iovar_int_set(ifp
, "allmulti", cmd_value
);
118 brcmf_err("Setting allmulti failed, %d\n", err
);
120 /*Finally, pick up the PROMISC flag */
121 cmd_value
= (ndev
->flags
& IFF_PROMISC
) ? true : false;
122 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PROMISC
, cmd_value
);
124 brcmf_err("Setting BRCMF_C_SET_PROMISC failed, %d\n",
129 _brcmf_set_mac_address(struct work_struct
*work
)
131 struct brcmf_if
*ifp
;
134 brcmf_dbg(TRACE
, "enter\n");
136 ifp
= container_of(work
, struct brcmf_if
, setmacaddr_work
);
137 err
= brcmf_fil_iovar_data_set(ifp
, "cur_etheraddr", ifp
->mac_addr
,
140 brcmf_err("Setting cur_etheraddr failed, %d\n", err
);
142 brcmf_dbg(TRACE
, "MAC address updated to %pM\n",
144 memcpy(ifp
->ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
148 static int brcmf_netdev_set_mac_address(struct net_device
*ndev
, void *addr
)
150 struct brcmf_if
*ifp
= netdev_priv(ndev
);
151 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
153 memcpy(&ifp
->mac_addr
, sa
->sa_data
, ETH_ALEN
);
154 schedule_work(&ifp
->setmacaddr_work
);
158 static void brcmf_netdev_set_multicast_list(struct net_device
*ndev
)
160 struct brcmf_if
*ifp
= netdev_priv(ndev
);
162 schedule_work(&ifp
->multicast_work
);
165 static int brcmf_netdev_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
168 struct brcmf_if
*ifp
= netdev_priv(ndev
);
169 struct brcmf_pub
*drvr
= ifp
->drvr
;
171 brcmf_dbg(TRACE
, "Enter\n");
174 if (!drvr
->bus_if
->drvr_up
||
175 (drvr
->bus_if
->state
!= BRCMF_BUS_DATA
)) {
176 brcmf_err("xmit rejected drvup=%d state=%d\n",
177 drvr
->bus_if
->drvr_up
,
178 drvr
->bus_if
->state
);
179 netif_stop_queue(ndev
);
183 if (!drvr
->iflist
[ifp
->idx
]) {
184 brcmf_err("bad ifidx %d\n", ifp
->idx
);
185 netif_stop_queue(ndev
);
189 /* Make sure there's enough room for any header */
190 if (skb_headroom(skb
) < drvr
->hdrlen
) {
191 struct sk_buff
*skb2
;
193 brcmf_dbg(INFO
, "%s: insufficient headroom\n",
194 brcmf_ifname(drvr
, ifp
->idx
));
195 drvr
->bus_if
->tx_realloc
++;
196 skb2
= skb_realloc_headroom(skb
, drvr
->hdrlen
);
200 brcmf_err("%s: skb_realloc_headroom failed\n",
201 brcmf_ifname(drvr
, ifp
->idx
));
207 /* Update multicast statistic */
208 if (skb
->len
>= ETH_ALEN
) {
209 u8
*pktdata
= (u8
*)(skb
->data
);
210 struct ethhdr
*eh
= (struct ethhdr
*)pktdata
;
212 if (is_multicast_ether_addr(eh
->h_dest
))
213 drvr
->tx_multicast
++;
214 if (ntohs(eh
->h_proto
) == ETH_P_PAE
)
215 atomic_inc(&drvr
->pend_8021x_cnt
);
218 /* If the protocol uses a data header, apply it */
219 brcmf_proto_hdrpush(drvr
, ifp
->idx
, skb
);
221 /* Use bus module to send data frame */
222 ret
= brcmf_bus_txdata(drvr
->bus_if
, skb
);
226 drvr
->bus_if
->dstats
.tx_dropped
++;
228 drvr
->bus_if
->dstats
.tx_packets
++;
230 /* Return ok: we always eat the packet */
234 void brcmf_txflowblock(struct device
*dev
, bool state
)
236 struct net_device
*ndev
;
237 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
238 struct brcmf_pub
*drvr
= bus_if
->drvr
;
241 brcmf_dbg(TRACE
, "Enter\n");
243 for (i
= 0; i
< BRCMF_MAX_IFS
; i
++)
244 if (drvr
->iflist
[i
]) {
245 ndev
= drvr
->iflist
[i
]->ndev
;
247 netif_stop_queue(ndev
);
249 netif_wake_queue(ndev
);
253 void brcmf_rx_frame(struct device
*dev
, u8 ifidx
,
254 struct sk_buff_head
*skb_list
)
258 struct sk_buff
*skb
, *pnext
;
259 struct brcmf_if
*ifp
;
260 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
261 struct brcmf_pub
*drvr
= bus_if
->drvr
;
263 brcmf_dbg(TRACE
, "Enter\n");
265 skb_queue_walk_safe(skb_list
, skb
, pnext
) {
266 skb_unlink(skb
, skb_list
);
268 /* Get the protocol, maintain skb around eth_type_trans()
269 * The main reason for this hack is for the limitation of
270 * Linux 2.4 where 'eth_type_trans' uses the
271 * 'net->hard_header_len'
272 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
273 * coping of the packet coming from the network stack to add
274 * BDC, Hardware header etc, during network interface
276 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
278 * for BDC, Hardware header etc. and not just the ETH_HLEN
283 ifp
= drvr
->iflist
[ifidx
];
285 ifp
= drvr
->iflist
[0];
287 if (!ifp
|| !ifp
->ndev
||
288 ifp
->ndev
->reg_state
!= NETREG_REGISTERED
) {
289 brcmu_pkt_buf_free_skb(skb
);
293 skb
->dev
= ifp
->ndev
;
294 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
296 if (skb
->pkt_type
== PACKET_MULTICAST
)
297 bus_if
->dstats
.multicast
++;
302 /* Strip header, count, deliver upward */
303 skb_pull(skb
, ETH_HLEN
);
305 /* Process special event packets and then discard them */
306 brcmf_fweh_process_skb(drvr
, skb
, &ifidx
);
308 if (drvr
->iflist
[ifidx
]) {
309 ifp
= drvr
->iflist
[ifidx
];
310 ifp
->ndev
->last_rx
= jiffies
;
313 bus_if
->dstats
.rx_bytes
+= skb
->len
;
314 bus_if
->dstats
.rx_packets
++; /* Local count */
319 /* If the receive is not processed inside an ISR,
320 * the softirqd must be woken explicitly to service
321 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
322 * by netif_rx_ni(), but in earlier kernels, we need
329 void brcmf_txcomplete(struct device
*dev
, struct sk_buff
*txp
, bool success
)
334 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
335 struct brcmf_pub
*drvr
= bus_if
->drvr
;
337 brcmf_proto_hdrpull(dev
, &ifidx
, txp
);
339 eh
= (struct ethhdr
*)(txp
->data
);
340 type
= ntohs(eh
->h_proto
);
342 if (type
== ETH_P_PAE
) {
343 atomic_dec(&drvr
->pend_8021x_cnt
);
344 if (waitqueue_active(&drvr
->pend_8021x_wait
))
345 wake_up(&drvr
->pend_8021x_wait
);
349 static struct net_device_stats
*brcmf_netdev_get_stats(struct net_device
*ndev
)
351 struct brcmf_if
*ifp
= netdev_priv(ndev
);
352 struct brcmf_bus
*bus_if
= ifp
->drvr
->bus_if
;
354 brcmf_dbg(TRACE
, "Enter\n");
356 /* Copy dongle stats to net device stats */
357 ifp
->stats
.rx_packets
= bus_if
->dstats
.rx_packets
;
358 ifp
->stats
.tx_packets
= bus_if
->dstats
.tx_packets
;
359 ifp
->stats
.rx_bytes
= bus_if
->dstats
.rx_bytes
;
360 ifp
->stats
.tx_bytes
= bus_if
->dstats
.tx_bytes
;
361 ifp
->stats
.rx_errors
= bus_if
->dstats
.rx_errors
;
362 ifp
->stats
.tx_errors
= bus_if
->dstats
.tx_errors
;
363 ifp
->stats
.rx_dropped
= bus_if
->dstats
.rx_dropped
;
364 ifp
->stats
.tx_dropped
= bus_if
->dstats
.tx_dropped
;
365 ifp
->stats
.multicast
= bus_if
->dstats
.multicast
;
371 * Set current toe component enables in toe_ol iovar,
372 * and set toe global enable iovar
374 static int brcmf_toe_set(struct brcmf_if
*ifp
, u32 toe_ol
)
378 err
= brcmf_fil_iovar_int_set(ifp
, "toe_ol", toe_ol
);
380 brcmf_err("Setting toe_ol failed, %d\n", err
);
384 err
= brcmf_fil_iovar_int_set(ifp
, "toe", (toe_ol
!= 0));
386 brcmf_err("Setting toe failed, %d\n", err
);
392 static void brcmf_ethtool_get_drvinfo(struct net_device
*ndev
,
393 struct ethtool_drvinfo
*info
)
395 struct brcmf_if
*ifp
= netdev_priv(ndev
);
396 struct brcmf_pub
*drvr
= ifp
->drvr
;
398 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
399 snprintf(info
->version
, sizeof(info
->version
), "%lu",
401 strlcpy(info
->bus_info
, dev_name(drvr
->bus_if
->dev
),
402 sizeof(info
->bus_info
));
405 static const struct ethtool_ops brcmf_ethtool_ops
= {
406 .get_drvinfo
= brcmf_ethtool_get_drvinfo
,
409 static int brcmf_ethtool(struct brcmf_if
*ifp
, void __user
*uaddr
)
411 struct brcmf_pub
*drvr
= ifp
->drvr
;
412 struct ethtool_drvinfo info
;
413 char drvname
[sizeof(info
.driver
)];
415 struct ethtool_value edata
;
416 u32 toe_cmpnt
, csum_dir
;
419 brcmf_dbg(TRACE
, "Enter\n");
421 /* all ethtool calls start with a cmd word */
422 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
426 case ETHTOOL_GDRVINFO
:
427 /* Copy out any request driver name */
428 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
430 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
431 drvname
[sizeof(info
.driver
) - 1] = '\0';
433 /* clear struct for return */
434 memset(&info
, 0, sizeof(info
));
437 /* if requested, identify ourselves */
438 if (strcmp(drvname
, "?dhd") == 0) {
439 sprintf(info
.driver
, "dhd");
440 strcpy(info
.version
, BRCMF_VERSION_STR
);
443 /* otherwise, require dongle to be up */
444 else if (!drvr
->bus_if
->drvr_up
) {
445 brcmf_err("dongle is not up\n");
448 /* finally, report dongle driver type */
450 sprintf(info
.driver
, "wl");
452 sprintf(info
.version
, "%lu", drvr
->drv_version
);
453 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
455 brcmf_dbg(CTL
, "given %*s, returning %s\n",
456 (int)sizeof(drvname
), drvname
, info
.driver
);
459 /* Get toe offload components from dongle */
460 case ETHTOOL_GRXCSUM
:
461 case ETHTOOL_GTXCSUM
:
462 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
467 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
470 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
472 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
476 /* Set toe offload components in dongle */
477 case ETHTOOL_SRXCSUM
:
478 case ETHTOOL_STXCSUM
:
479 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
482 /* Read the current settings, update and write back */
483 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
488 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
491 toe_cmpnt
|= csum_dir
;
493 toe_cmpnt
&= ~csum_dir
;
495 ret
= brcmf_toe_set(ifp
, toe_cmpnt
);
499 /* If setting TX checksum mode, tell Linux the new mode */
500 if (cmd
== ETHTOOL_STXCSUM
) {
502 ifp
->ndev
->features
|= NETIF_F_IP_CSUM
;
504 ifp
->ndev
->features
&= ~NETIF_F_IP_CSUM
;
516 static int brcmf_netdev_ioctl_entry(struct net_device
*ndev
, struct ifreq
*ifr
,
519 struct brcmf_if
*ifp
= netdev_priv(ndev
);
520 struct brcmf_pub
*drvr
= ifp
->drvr
;
522 brcmf_dbg(TRACE
, "ifidx %d, cmd 0x%04x\n", ifp
->idx
, cmd
);
524 if (!drvr
->iflist
[ifp
->idx
])
527 if (cmd
== SIOCETHTOOL
)
528 return brcmf_ethtool(ifp
, ifr
->ifr_data
);
533 static int brcmf_netdev_stop(struct net_device
*ndev
)
535 struct brcmf_if
*ifp
= netdev_priv(ndev
);
536 struct brcmf_pub
*drvr
= ifp
->drvr
;
538 brcmf_dbg(TRACE
, "Enter\n");
540 if (drvr
->bus_if
->drvr_up
== 0)
543 brcmf_cfg80211_down(ndev
);
545 /* Set state and stop OS transmissions */
546 drvr
->bus_if
->drvr_up
= false;
547 netif_stop_queue(ndev
);
552 static int brcmf_netdev_open(struct net_device
*ndev
)
554 struct brcmf_if
*ifp
= netdev_priv(ndev
);
555 struct brcmf_pub
*drvr
= ifp
->drvr
;
556 struct brcmf_bus
*bus_if
= drvr
->bus_if
;
560 brcmf_dbg(TRACE
, "ifidx %d\n", ifp
->idx
);
562 /* If bus is not ready, can't continue */
563 if (bus_if
->state
!= BRCMF_BUS_DATA
) {
564 brcmf_err("failed bus is not ready\n");
568 atomic_set(&drvr
->pend_8021x_cnt
, 0);
570 memcpy(ndev
->dev_addr
, drvr
->mac
, ETH_ALEN
);
572 /* Get current TOE mode from dongle */
573 if (brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_ol
) >= 0
574 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
575 drvr
->iflist
[ifp
->idx
]->ndev
->features
|=
578 drvr
->iflist
[ifp
->idx
]->ndev
->features
&=
581 /* make sure RF is ready for work */
582 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 0);
584 /* Allow transmit calls */
585 netif_start_queue(ndev
);
586 drvr
->bus_if
->drvr_up
= true;
587 if (brcmf_cfg80211_up(ndev
)) {
588 brcmf_err("failed to bring up cfg80211\n");
595 static const struct net_device_ops brcmf_netdev_ops_pri
= {
596 .ndo_open
= brcmf_netdev_open
,
597 .ndo_stop
= brcmf_netdev_stop
,
598 .ndo_get_stats
= brcmf_netdev_get_stats
,
599 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
600 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
601 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
602 .ndo_set_rx_mode
= brcmf_netdev_set_multicast_list
605 static const struct net_device_ops brcmf_netdev_ops_virt
= {
606 .ndo_open
= brcmf_cfg80211_up
,
607 .ndo_stop
= brcmf_cfg80211_down
,
608 .ndo_get_stats
= brcmf_netdev_get_stats
,
609 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
610 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
611 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
612 .ndo_set_rx_mode
= brcmf_netdev_set_multicast_list
615 int brcmf_net_attach(struct brcmf_if
*ifp
)
617 struct brcmf_pub
*drvr
= ifp
->drvr
;
618 struct net_device
*ndev
;
620 brcmf_dbg(TRACE
, "ifidx %d mac %pM\n", ifp
->idx
, ifp
->mac_addr
);
623 /* set appropriate operations */
625 ndev
->netdev_ops
= &brcmf_netdev_ops_pri
;
627 ndev
->netdev_ops
= &brcmf_netdev_ops_virt
;
629 ndev
->hard_header_len
= ETH_HLEN
+ drvr
->hdrlen
;
630 ndev
->ethtool_ops
= &brcmf_ethtool_ops
;
632 drvr
->rxsz
= ndev
->mtu
+ ndev
->hard_header_len
+
635 /* set the mac address */
636 memcpy(ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
638 if (register_netdev(ndev
) != 0) {
639 brcmf_err("couldn't register the net device\n");
643 brcmf_dbg(INFO
, "%s: Broadcom Dongle Host Driver\n", ndev
->name
);
648 ndev
->netdev_ops
= NULL
;
652 struct brcmf_if
*brcmf_add_if(struct brcmf_pub
*drvr
, int ifidx
, s32 bssidx
,
653 char *name
, u8
*addr_mask
)
655 struct brcmf_if
*ifp
;
656 struct net_device
*ndev
;
659 brcmf_dbg(TRACE
, "idx %d\n", ifidx
);
661 ifp
= drvr
->iflist
[ifidx
];
663 * Delete the existing interface before overwriting it
664 * in case we missed the BRCMF_E_IF_DEL event.
667 brcmf_err("ERROR: netdev:%s already exists\n",
670 netif_stop_queue(ifp
->ndev
);
671 unregister_netdev(ifp
->ndev
);
672 free_netdev(ifp
->ndev
);
673 drvr
->iflist
[ifidx
] = NULL
;
675 brcmf_err("ignore IF event\n");
676 return ERR_PTR(-EINVAL
);
680 /* Allocate netdev, including space for private structure */
681 ndev
= alloc_netdev(sizeof(struct brcmf_if
), name
, ether_setup
);
683 brcmf_err("OOM - alloc_netdev\n");
684 return ERR_PTR(-ENOMEM
);
687 ifp
= netdev_priv(ndev
);
690 drvr
->iflist
[ifidx
] = ifp
;
692 ifp
->bssidx
= bssidx
;
694 INIT_WORK(&ifp
->setmacaddr_work
, _brcmf_set_mac_address
);
695 INIT_WORK(&ifp
->multicast_work
, _brcmf_set_multicast_list
);
697 if (addr_mask
!= NULL
)
698 for (i
= 0; i
< ETH_ALEN
; i
++)
699 ifp
->mac_addr
[i
] = drvr
->mac
[i
] ^ addr_mask
[i
];
701 brcmf_dbg(TRACE
, " ==== pid:%x, if:%s (%pM) created ===\n",
702 current
->pid
, ifp
->ndev
->name
, ifp
->mac_addr
);
707 void brcmf_del_if(struct brcmf_pub
*drvr
, int ifidx
)
709 struct brcmf_if
*ifp
;
711 brcmf_dbg(TRACE
, "idx %d\n", ifidx
);
713 ifp
= drvr
->iflist
[ifidx
];
715 brcmf_err("Null interface\n");
720 if (ifp
->ndev
->netdev_ops
== &brcmf_netdev_ops_pri
) {
722 brcmf_netdev_stop(ifp
->ndev
);
726 netif_stop_queue(ifp
->ndev
);
729 cancel_work_sync(&ifp
->setmacaddr_work
);
730 cancel_work_sync(&ifp
->multicast_work
);
732 unregister_netdev(ifp
->ndev
);
733 drvr
->iflist
[ifidx
] = NULL
;
735 brcmf_cfg80211_detach(drvr
->config
);
736 free_netdev(ifp
->ndev
);
740 int brcmf_attach(uint bus_hdrlen
, struct device
*dev
)
742 struct brcmf_pub
*drvr
= NULL
;
745 brcmf_dbg(TRACE
, "Enter\n");
747 /* Allocate primary brcmf_info */
748 drvr
= kzalloc(sizeof(struct brcmf_pub
), GFP_ATOMIC
);
752 mutex_init(&drvr
->proto_block
);
754 /* Link to bus module */
755 drvr
->hdrlen
= bus_hdrlen
;
756 drvr
->bus_if
= dev_get_drvdata(dev
);
757 drvr
->bus_if
->drvr
= drvr
;
759 /* create device debugfs folder */
760 brcmf_debugfs_attach(drvr
);
762 /* Attach and link in the protocol */
763 ret
= brcmf_proto_attach(drvr
);
765 brcmf_err("brcmf_prot_attach failed\n");
769 /* attach firmware event handler */
770 brcmf_fweh_attach(drvr
);
772 INIT_LIST_HEAD(&drvr
->bus_if
->dcmd_list
);
774 init_waitqueue_head(&drvr
->pend_8021x_wait
);
784 int brcmf_bus_start(struct device
*dev
)
787 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
788 struct brcmf_pub
*drvr
= bus_if
->drvr
;
789 struct brcmf_if
*ifp
;
791 brcmf_dbg(TRACE
, "\n");
793 /* Bring up the bus */
794 ret
= brcmf_bus_init(bus_if
);
796 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret
);
800 /* add primary networking interface */
801 ifp
= brcmf_add_if(drvr
, 0, 0, "wlan%d", NULL
);
805 /* signal bus ready */
806 bus_if
->state
= BRCMF_BUS_DATA
;
808 /* Bus is ready, do any initialization */
809 ret
= brcmf_c_preinit_dcmds(ifp
);
813 drvr
->config
= brcmf_cfg80211_attach(drvr
, bus_if
->dev
);
814 if (drvr
->config
== NULL
) {
819 ret
= brcmf_fweh_activate_events(ifp
);
823 ret
= brcmf_net_attach(ifp
);
826 brcmf_err("failed: %d\n", ret
);
828 brcmf_cfg80211_detach(drvr
->config
);
829 free_netdev(drvr
->iflist
[0]->ndev
);
830 drvr
->iflist
[0] = NULL
;
837 static void brcmf_bus_detach(struct brcmf_pub
*drvr
)
839 brcmf_dbg(TRACE
, "Enter\n");
842 /* Stop the protocol module */
843 brcmf_proto_stop(drvr
);
845 /* Stop the bus module */
846 brcmf_bus_stop(drvr
->bus_if
);
850 void brcmf_detach(struct device
*dev
)
853 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
854 struct brcmf_pub
*drvr
= bus_if
->drvr
;
856 brcmf_dbg(TRACE
, "Enter\n");
861 /* stop firmware event handling */
862 brcmf_fweh_detach(drvr
);
864 /* make sure primary interface removed last */
865 for (i
= BRCMF_MAX_IFS
-1; i
> -1; i
--)
867 brcmf_del_if(drvr
, i
);
869 brcmf_bus_detach(drvr
);
872 brcmf_proto_detach(drvr
);
875 brcmf_debugfs_detach(drvr
);
880 static int brcmf_get_pend_8021x_cnt(struct brcmf_pub
*drvr
)
882 return atomic_read(&drvr
->pend_8021x_cnt
);
885 int brcmf_netdev_wait_pend8021x(struct net_device
*ndev
)
887 struct brcmf_if
*ifp
= netdev_priv(ndev
);
888 struct brcmf_pub
*drvr
= ifp
->drvr
;
891 err
= wait_event_timeout(drvr
->pend_8021x_wait
,
892 !brcmf_get_pend_8021x_cnt(drvr
),
893 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX
));
900 static void brcmf_driver_init(struct work_struct
*work
)
902 brcmf_debugfs_init();
904 #ifdef CONFIG_BRCMFMAC_SDIO
907 #ifdef CONFIG_BRCMFMAC_USB
911 static DECLARE_WORK(brcmf_driver_work
, brcmf_driver_init
);
913 static int __init
brcmfmac_module_init(void)
915 if (!schedule_work(&brcmf_driver_work
))
921 static void __exit
brcmfmac_module_exit(void)
923 cancel_work_sync(&brcmf_driver_work
);
925 #ifdef CONFIG_BRCMFMAC_SDIO
928 #ifdef CONFIG_BRCMFMAC_USB
931 brcmf_debugfs_exit();
934 module_init(brcmfmac_module_init
);
935 module_exit(brcmfmac_module_exit
);