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 sprintf(info
->driver
, KBUILD_MODNAME
);
399 sprintf(info
->version
, "%lu", drvr
->drv_version
);
400 sprintf(info
->bus_info
, "%s", dev_name(drvr
->bus_if
->dev
));
403 static const struct ethtool_ops brcmf_ethtool_ops
= {
404 .get_drvinfo
= brcmf_ethtool_get_drvinfo
,
407 static int brcmf_ethtool(struct brcmf_if
*ifp
, void __user
*uaddr
)
409 struct brcmf_pub
*drvr
= ifp
->drvr
;
410 struct ethtool_drvinfo info
;
411 char drvname
[sizeof(info
.driver
)];
413 struct ethtool_value edata
;
414 u32 toe_cmpnt
, csum_dir
;
417 brcmf_dbg(TRACE
, "Enter\n");
419 /* all ethtool calls start with a cmd word */
420 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
424 case ETHTOOL_GDRVINFO
:
425 /* Copy out any request driver name */
426 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
428 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
429 drvname
[sizeof(info
.driver
) - 1] = '\0';
431 /* clear struct for return */
432 memset(&info
, 0, sizeof(info
));
435 /* if requested, identify ourselves */
436 if (strcmp(drvname
, "?dhd") == 0) {
437 sprintf(info
.driver
, "dhd");
438 strcpy(info
.version
, BRCMF_VERSION_STR
);
441 /* otherwise, require dongle to be up */
442 else if (!drvr
->bus_if
->drvr_up
) {
443 brcmf_err("dongle is not up\n");
446 /* finally, report dongle driver type */
448 sprintf(info
.driver
, "wl");
450 sprintf(info
.version
, "%lu", drvr
->drv_version
);
451 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
453 brcmf_dbg(CTL
, "given %*s, returning %s\n",
454 (int)sizeof(drvname
), drvname
, info
.driver
);
457 /* Get toe offload components from dongle */
458 case ETHTOOL_GRXCSUM
:
459 case ETHTOOL_GTXCSUM
:
460 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
465 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
468 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
470 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
474 /* Set toe offload components in dongle */
475 case ETHTOOL_SRXCSUM
:
476 case ETHTOOL_STXCSUM
:
477 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
480 /* Read the current settings, update and write back */
481 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
486 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
489 toe_cmpnt
|= csum_dir
;
491 toe_cmpnt
&= ~csum_dir
;
493 ret
= brcmf_toe_set(ifp
, toe_cmpnt
);
497 /* If setting TX checksum mode, tell Linux the new mode */
498 if (cmd
== ETHTOOL_STXCSUM
) {
500 ifp
->ndev
->features
|= NETIF_F_IP_CSUM
;
502 ifp
->ndev
->features
&= ~NETIF_F_IP_CSUM
;
514 static int brcmf_netdev_ioctl_entry(struct net_device
*ndev
, struct ifreq
*ifr
,
517 struct brcmf_if
*ifp
= netdev_priv(ndev
);
518 struct brcmf_pub
*drvr
= ifp
->drvr
;
520 brcmf_dbg(TRACE
, "ifidx %d, cmd 0x%04x\n", ifp
->idx
, cmd
);
522 if (!drvr
->iflist
[ifp
->idx
])
525 if (cmd
== SIOCETHTOOL
)
526 return brcmf_ethtool(ifp
, ifr
->ifr_data
);
531 static int brcmf_netdev_stop(struct net_device
*ndev
)
533 struct brcmf_if
*ifp
= netdev_priv(ndev
);
534 struct brcmf_pub
*drvr
= ifp
->drvr
;
536 brcmf_dbg(TRACE
, "Enter\n");
538 if (drvr
->bus_if
->drvr_up
== 0)
541 brcmf_cfg80211_down(ndev
);
543 /* Set state and stop OS transmissions */
544 drvr
->bus_if
->drvr_up
= false;
545 netif_stop_queue(ndev
);
550 static int brcmf_netdev_open(struct net_device
*ndev
)
552 struct brcmf_if
*ifp
= netdev_priv(ndev
);
553 struct brcmf_pub
*drvr
= ifp
->drvr
;
554 struct brcmf_bus
*bus_if
= drvr
->bus_if
;
558 brcmf_dbg(TRACE
, "ifidx %d\n", ifp
->idx
);
560 /* If bus is not ready, can't continue */
561 if (bus_if
->state
!= BRCMF_BUS_DATA
) {
562 brcmf_err("failed bus is not ready\n");
566 atomic_set(&drvr
->pend_8021x_cnt
, 0);
568 memcpy(ndev
->dev_addr
, drvr
->mac
, ETH_ALEN
);
570 /* Get current TOE mode from dongle */
571 if (brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_ol
) >= 0
572 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
573 drvr
->iflist
[ifp
->idx
]->ndev
->features
|=
576 drvr
->iflist
[ifp
->idx
]->ndev
->features
&=
579 /* make sure RF is ready for work */
580 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_UP
, 0);
582 /* Allow transmit calls */
583 netif_start_queue(ndev
);
584 drvr
->bus_if
->drvr_up
= true;
585 if (brcmf_cfg80211_up(ndev
)) {
586 brcmf_err("failed to bring up cfg80211\n");
593 static const struct net_device_ops brcmf_netdev_ops_pri
= {
594 .ndo_open
= brcmf_netdev_open
,
595 .ndo_stop
= brcmf_netdev_stop
,
596 .ndo_get_stats
= brcmf_netdev_get_stats
,
597 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
598 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
599 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
600 .ndo_set_rx_mode
= brcmf_netdev_set_multicast_list
603 static const struct net_device_ops brcmf_netdev_ops_virt
= {
604 .ndo_open
= brcmf_cfg80211_up
,
605 .ndo_stop
= brcmf_cfg80211_down
,
606 .ndo_get_stats
= brcmf_netdev_get_stats
,
607 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
608 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
609 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
610 .ndo_set_rx_mode
= brcmf_netdev_set_multicast_list
613 int brcmf_net_attach(struct brcmf_if
*ifp
)
615 struct brcmf_pub
*drvr
= ifp
->drvr
;
616 struct net_device
*ndev
;
618 brcmf_dbg(TRACE
, "ifidx %d mac %pM\n", ifp
->idx
, ifp
->mac_addr
);
621 /* set appropriate operations */
623 ndev
->netdev_ops
= &brcmf_netdev_ops_pri
;
625 ndev
->netdev_ops
= &brcmf_netdev_ops_virt
;
627 ndev
->hard_header_len
= ETH_HLEN
+ drvr
->hdrlen
;
628 ndev
->ethtool_ops
= &brcmf_ethtool_ops
;
630 drvr
->rxsz
= ndev
->mtu
+ ndev
->hard_header_len
+
633 /* set the mac address */
634 memcpy(ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
636 if (register_netdev(ndev
) != 0) {
637 brcmf_err("couldn't register the net device\n");
641 brcmf_dbg(INFO
, "%s: Broadcom Dongle Host Driver\n", ndev
->name
);
646 ndev
->netdev_ops
= NULL
;
650 struct brcmf_if
*brcmf_add_if(struct brcmf_pub
*drvr
, int ifidx
, s32 bssidx
,
651 char *name
, u8
*addr_mask
)
653 struct brcmf_if
*ifp
;
654 struct net_device
*ndev
;
657 brcmf_dbg(TRACE
, "idx %d\n", ifidx
);
659 ifp
= drvr
->iflist
[ifidx
];
661 * Delete the existing interface before overwriting it
662 * in case we missed the BRCMF_E_IF_DEL event.
665 brcmf_err("ERROR: netdev:%s already exists\n",
668 netif_stop_queue(ifp
->ndev
);
669 unregister_netdev(ifp
->ndev
);
670 free_netdev(ifp
->ndev
);
671 drvr
->iflist
[ifidx
] = NULL
;
673 brcmf_err("ignore IF event\n");
674 return ERR_PTR(-EINVAL
);
678 /* Allocate netdev, including space for private structure */
679 ndev
= alloc_netdev(sizeof(struct brcmf_if
), name
, ether_setup
);
681 brcmf_err("OOM - alloc_netdev\n");
682 return ERR_PTR(-ENOMEM
);
685 ifp
= netdev_priv(ndev
);
688 drvr
->iflist
[ifidx
] = ifp
;
690 ifp
->bssidx
= bssidx
;
692 INIT_WORK(&ifp
->setmacaddr_work
, _brcmf_set_mac_address
);
693 INIT_WORK(&ifp
->multicast_work
, _brcmf_set_multicast_list
);
695 if (addr_mask
!= NULL
)
696 for (i
= 0; i
< ETH_ALEN
; i
++)
697 ifp
->mac_addr
[i
] = drvr
->mac
[i
] ^ addr_mask
[i
];
699 brcmf_dbg(TRACE
, " ==== pid:%x, if:%s (%pM) created ===\n",
700 current
->pid
, ifp
->ndev
->name
, ifp
->mac_addr
);
705 void brcmf_del_if(struct brcmf_pub
*drvr
, int ifidx
)
707 struct brcmf_if
*ifp
;
709 brcmf_dbg(TRACE
, "idx %d\n", ifidx
);
711 ifp
= drvr
->iflist
[ifidx
];
713 brcmf_err("Null interface\n");
718 if (ifp
->ndev
->netdev_ops
== &brcmf_netdev_ops_pri
) {
720 brcmf_netdev_stop(ifp
->ndev
);
724 netif_stop_queue(ifp
->ndev
);
727 cancel_work_sync(&ifp
->setmacaddr_work
);
728 cancel_work_sync(&ifp
->multicast_work
);
730 unregister_netdev(ifp
->ndev
);
731 drvr
->iflist
[ifidx
] = NULL
;
733 brcmf_cfg80211_detach(drvr
->config
);
734 free_netdev(ifp
->ndev
);
738 int brcmf_attach(uint bus_hdrlen
, struct device
*dev
)
740 struct brcmf_pub
*drvr
= NULL
;
743 brcmf_dbg(TRACE
, "Enter\n");
745 /* Allocate primary brcmf_info */
746 drvr
= kzalloc(sizeof(struct brcmf_pub
), GFP_ATOMIC
);
750 mutex_init(&drvr
->proto_block
);
752 /* Link to bus module */
753 drvr
->hdrlen
= bus_hdrlen
;
754 drvr
->bus_if
= dev_get_drvdata(dev
);
755 drvr
->bus_if
->drvr
= drvr
;
757 /* create device debugfs folder */
758 brcmf_debugfs_attach(drvr
);
760 /* Attach and link in the protocol */
761 ret
= brcmf_proto_attach(drvr
);
763 brcmf_err("brcmf_prot_attach failed\n");
767 /* attach firmware event handler */
768 brcmf_fweh_attach(drvr
);
770 INIT_LIST_HEAD(&drvr
->bus_if
->dcmd_list
);
772 init_waitqueue_head(&drvr
->pend_8021x_wait
);
782 int brcmf_bus_start(struct device
*dev
)
785 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
786 struct brcmf_pub
*drvr
= bus_if
->drvr
;
787 struct brcmf_if
*ifp
;
789 brcmf_dbg(TRACE
, "\n");
791 /* Bring up the bus */
792 ret
= brcmf_bus_init(bus_if
);
794 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret
);
798 /* add primary networking interface */
799 ifp
= brcmf_add_if(drvr
, 0, 0, "wlan%d", NULL
);
803 /* signal bus ready */
804 bus_if
->state
= BRCMF_BUS_DATA
;
806 /* Bus is ready, do any initialization */
807 ret
= brcmf_c_preinit_dcmds(ifp
);
811 drvr
->config
= brcmf_cfg80211_attach(drvr
, bus_if
->dev
);
812 if (drvr
->config
== NULL
) {
817 ret
= brcmf_fweh_activate_events(ifp
);
821 ret
= brcmf_net_attach(ifp
);
824 brcmf_err("failed: %d\n", ret
);
826 brcmf_cfg80211_detach(drvr
->config
);
827 free_netdev(drvr
->iflist
[0]->ndev
);
828 drvr
->iflist
[0] = NULL
;
835 static void brcmf_bus_detach(struct brcmf_pub
*drvr
)
837 brcmf_dbg(TRACE
, "Enter\n");
840 /* Stop the protocol module */
841 brcmf_proto_stop(drvr
);
843 /* Stop the bus module */
844 brcmf_bus_stop(drvr
->bus_if
);
848 void brcmf_detach(struct device
*dev
)
851 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
852 struct brcmf_pub
*drvr
= bus_if
->drvr
;
854 brcmf_dbg(TRACE
, "Enter\n");
859 /* stop firmware event handling */
860 brcmf_fweh_detach(drvr
);
862 /* make sure primary interface removed last */
863 for (i
= BRCMF_MAX_IFS
-1; i
> -1; i
--)
865 brcmf_del_if(drvr
, i
);
867 brcmf_bus_detach(drvr
);
870 brcmf_proto_detach(drvr
);
873 brcmf_debugfs_detach(drvr
);
878 static int brcmf_get_pend_8021x_cnt(struct brcmf_pub
*drvr
)
880 return atomic_read(&drvr
->pend_8021x_cnt
);
883 int brcmf_netdev_wait_pend8021x(struct net_device
*ndev
)
885 struct brcmf_if
*ifp
= netdev_priv(ndev
);
886 struct brcmf_pub
*drvr
= ifp
->drvr
;
889 err
= wait_event_timeout(drvr
->pend_8021x_wait
,
890 !brcmf_get_pend_8021x_cnt(drvr
),
891 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX
));
898 static void brcmf_driver_init(struct work_struct
*work
)
900 brcmf_debugfs_init();
902 #ifdef CONFIG_BRCMFMAC_SDIO
905 #ifdef CONFIG_BRCMFMAC_USB
909 static DECLARE_WORK(brcmf_driver_work
, brcmf_driver_init
);
911 static int __init
brcmfmac_module_init(void)
913 if (!schedule_work(&brcmf_driver_work
))
919 static void __exit
brcmfmac_module_exit(void)
921 cancel_work_sync(&brcmf_driver_work
);
923 #ifdef CONFIG_BRCMFMAC_SDIO
926 #ifdef CONFIG_BRCMFMAC_USB
929 brcmf_debugfs_exit();
932 module_init(brcmfmac_module_init
);
933 module_exit(brcmfmac_module_exit
);