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 ret
= brcmf_fws_process_skb(ifp
, skb
);
230 ifp
->stats
.tx_dropped
++;
232 ifp
->stats
.tx_packets
++;
233 ifp
->stats
.tx_bytes
+= skb
->len
;
236 /* Return ok: we always eat the packet */
240 void brcmf_txflowblock_if(struct brcmf_if
*ifp
,
241 enum brcmf_netif_stop_reason reason
, bool state
)
246 brcmf_dbg(TRACE
, "enter: idx=%d stop=0x%X reason=%d state=%d\n",
247 ifp
->bssidx
, ifp
->netif_stop
, reason
, state
);
249 if (!ifp
->netif_stop
)
250 netif_stop_queue(ifp
->ndev
);
251 ifp
->netif_stop
|= reason
;
253 ifp
->netif_stop
&= ~reason
;
254 if (!ifp
->netif_stop
)
255 netif_wake_queue(ifp
->ndev
);
259 void brcmf_txflowblock(struct device
*dev
, bool state
)
261 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
262 struct brcmf_pub
*drvr
= bus_if
->drvr
;
265 brcmf_dbg(TRACE
, "Enter\n");
267 for (i
= 0; i
< BRCMF_MAX_IFS
; i
++)
268 brcmf_txflowblock_if(drvr
->iflist
[i
],
269 BRCMF_NETIF_STOP_REASON_BLOCK_BUS
, state
);
272 void brcmf_rx_frames(struct device
*dev
, struct sk_buff_head
*skb_list
)
276 struct sk_buff
*skb
, *pnext
;
277 struct brcmf_if
*ifp
;
278 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
279 struct brcmf_pub
*drvr
= bus_if
->drvr
;
283 brcmf_dbg(TRACE
, "Enter\n");
285 skb_queue_walk_safe(skb_list
, skb
, pnext
) {
286 skb_unlink(skb
, skb_list
);
288 /* process and remove protocol-specific header */
289 ret
= brcmf_proto_hdrpull(drvr
, drvr
->fw_signals
, &ifidx
, skb
);
290 ifp
= drvr
->iflist
[ifidx
];
292 if (ret
|| !ifp
|| !ifp
->ndev
) {
293 if ((ret
!= -ENODATA
) && ifp
)
294 ifp
->stats
.rx_errors
++;
295 brcmu_pkt_buf_free_skb(skb
);
299 /* Get the protocol, maintain skb around eth_type_trans()
300 * The main reason for this hack is for the limitation of
301 * Linux 2.4 where 'eth_type_trans' uses the
302 * 'net->hard_header_len'
303 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
304 * coping of the packet coming from the network stack to add
305 * BDC, Hardware header etc, during network interface
307 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
309 * for BDC, Hardware header etc. and not just the ETH_HLEN
314 skb
->dev
= ifp
->ndev
;
315 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
317 if (skb
->pkt_type
== PACKET_MULTICAST
)
318 ifp
->stats
.multicast
++;
323 /* Strip header, count, deliver upward */
324 skb_pull(skb
, ETH_HLEN
);
326 /* Process special event packets */
327 brcmf_fweh_process_skb(drvr
, skb
);
329 if (!(ifp
->ndev
->flags
& IFF_UP
)) {
330 brcmu_pkt_buf_free_skb(skb
);
334 ifp
->stats
.rx_bytes
+= skb
->len
;
335 ifp
->stats
.rx_packets
++;
340 /* If the receive is not processed inside an ISR,
341 * the softirqd must be woken explicitly to service
342 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
343 * by netif_rx_ni(), but in earlier kernels, we need
350 void brcmf_txfinalize(struct brcmf_pub
*drvr
, struct sk_buff
*txp
,
353 struct brcmf_if
*ifp
;
359 res
= brcmf_proto_hdrpull(drvr
, false, &ifidx
, txp
);
361 ifp
= drvr
->iflist
[ifidx
];
366 eh
= (struct ethhdr
*)(txp
->data
);
367 type
= ntohs(eh
->h_proto
);
369 if (type
== ETH_P_PAE
) {
370 atomic_dec(&ifp
->pend_8021x_cnt
);
371 if (waitqueue_active(&ifp
->pend_8021x_wait
))
372 wake_up(&ifp
->pend_8021x_wait
);
376 ifp
->stats
.tx_errors
++;
378 brcmu_pkt_buf_free_skb(txp
);
381 void brcmf_txcomplete(struct device
*dev
, struct sk_buff
*txp
, bool success
)
383 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
384 struct brcmf_pub
*drvr
= bus_if
->drvr
;
386 /* await txstatus signal for firmware if active */
387 if (brcmf_fws_fc_active(drvr
->fws
)) {
389 brcmf_fws_bustxfail(drvr
->fws
, txp
);
391 brcmf_txfinalize(drvr
, txp
, success
);
395 static struct net_device_stats
*brcmf_netdev_get_stats(struct net_device
*ndev
)
397 struct brcmf_if
*ifp
= netdev_priv(ndev
);
399 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
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_err("Setting toe_ol failed, %d\n", err
);
418 err
= brcmf_fil_iovar_int_set(ifp
, "toe", (toe_ol
!= 0));
420 brcmf_err("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 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
433 snprintf(info
->version
, sizeof(info
->version
), "%lu",
435 strlcpy(info
->bus_info
, dev_name(drvr
->bus_if
->dev
),
436 sizeof(info
->bus_info
));
439 static const struct ethtool_ops brcmf_ethtool_ops
= {
440 .get_drvinfo
= brcmf_ethtool_get_drvinfo
,
443 static int brcmf_ethtool(struct brcmf_if
*ifp
, void __user
*uaddr
)
445 struct brcmf_pub
*drvr
= ifp
->drvr
;
446 struct ethtool_drvinfo info
;
447 char drvname
[sizeof(info
.driver
)];
449 struct ethtool_value edata
;
450 u32 toe_cmpnt
, csum_dir
;
453 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
455 /* all ethtool calls start with a cmd word */
456 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
460 case ETHTOOL_GDRVINFO
:
461 /* Copy out any request driver name */
462 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
464 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
465 drvname
[sizeof(info
.driver
) - 1] = '\0';
467 /* clear struct for return */
468 memset(&info
, 0, sizeof(info
));
471 /* if requested, identify ourselves */
472 if (strcmp(drvname
, "?dhd") == 0) {
473 sprintf(info
.driver
, "dhd");
474 strcpy(info
.version
, BRCMF_VERSION_STR
);
476 /* report dongle driver type */
478 sprintf(info
.driver
, "wl");
480 sprintf(info
.version
, "%lu", drvr
->drv_version
);
481 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
483 brcmf_dbg(TRACE
, "given %*s, returning %s\n",
484 (int)sizeof(drvname
), drvname
, info
.driver
);
487 /* Get toe offload components from dongle */
488 case ETHTOOL_GRXCSUM
:
489 case ETHTOOL_GTXCSUM
:
490 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
495 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
498 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
500 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
504 /* Set toe offload components in dongle */
505 case ETHTOOL_SRXCSUM
:
506 case ETHTOOL_STXCSUM
:
507 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
510 /* Read the current settings, update and write back */
511 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
516 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
519 toe_cmpnt
|= csum_dir
;
521 toe_cmpnt
&= ~csum_dir
;
523 ret
= brcmf_toe_set(ifp
, toe_cmpnt
);
527 /* If setting TX checksum mode, tell Linux the new mode */
528 if (cmd
== ETHTOOL_STXCSUM
) {
530 ifp
->ndev
->features
|= NETIF_F_IP_CSUM
;
532 ifp
->ndev
->features
&= ~NETIF_F_IP_CSUM
;
544 static int brcmf_netdev_ioctl_entry(struct net_device
*ndev
, struct ifreq
*ifr
,
547 struct brcmf_if
*ifp
= netdev_priv(ndev
);
548 struct brcmf_pub
*drvr
= ifp
->drvr
;
550 brcmf_dbg(TRACE
, "Enter, idx=%d, cmd=0x%04x\n", ifp
->bssidx
, cmd
);
552 if (!drvr
->iflist
[ifp
->bssidx
])
555 if (cmd
== SIOCETHTOOL
)
556 return brcmf_ethtool(ifp
, ifr
->ifr_data
);
561 static int brcmf_netdev_stop(struct net_device
*ndev
)
563 struct brcmf_if
*ifp
= netdev_priv(ndev
);
565 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
567 brcmf_cfg80211_down(ndev
);
569 /* Set state and stop OS transmissions */
570 netif_stop_queue(ndev
);
575 static int brcmf_netdev_open(struct net_device
*ndev
)
577 struct brcmf_if
*ifp
= netdev_priv(ndev
);
578 struct brcmf_pub
*drvr
= ifp
->drvr
;
579 struct brcmf_bus
*bus_if
= drvr
->bus_if
;
583 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
585 /* If bus is not ready, can't continue */
586 if (bus_if
->state
!= BRCMF_BUS_DATA
) {
587 brcmf_err("failed bus is not ready\n");
591 atomic_set(&ifp
->pend_8021x_cnt
, 0);
593 /* Get current TOE mode from dongle */
594 if (brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_ol
) >= 0
595 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
596 ndev
->features
|= NETIF_F_IP_CSUM
;
598 ndev
->features
&= ~NETIF_F_IP_CSUM
;
600 /* Allow transmit calls */
601 netif_start_queue(ndev
);
602 if (brcmf_cfg80211_up(ndev
)) {
603 brcmf_err("failed to bring up cfg80211\n");
610 static const struct net_device_ops brcmf_netdev_ops_pri
= {
611 .ndo_open
= brcmf_netdev_open
,
612 .ndo_stop
= brcmf_netdev_stop
,
613 .ndo_get_stats
= brcmf_netdev_get_stats
,
614 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
615 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
616 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
617 .ndo_set_rx_mode
= brcmf_netdev_set_multicast_list
620 int brcmf_net_attach(struct brcmf_if
*ifp
, bool rtnl_locked
)
622 struct brcmf_pub
*drvr
= ifp
->drvr
;
623 struct net_device
*ndev
;
626 brcmf_dbg(TRACE
, "Enter, idx=%d mac=%pM\n", ifp
->bssidx
,
630 /* set appropriate operations */
631 ndev
->netdev_ops
= &brcmf_netdev_ops_pri
;
633 ndev
->hard_header_len
= ETH_HLEN
+ drvr
->hdrlen
;
634 ndev
->ethtool_ops
= &brcmf_ethtool_ops
;
636 drvr
->rxsz
= ndev
->mtu
+ ndev
->hard_header_len
+
639 /* set the mac address */
640 memcpy(ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
642 INIT_WORK(&ifp
->setmacaddr_work
, _brcmf_set_mac_address
);
643 INIT_WORK(&ifp
->multicast_work
, _brcmf_set_multicast_list
);
646 err
= register_netdevice(ndev
);
648 err
= register_netdev(ndev
);
650 brcmf_err("couldn't register the net device\n");
654 brcmf_dbg(INFO
, "%s: Broadcom Dongle Host Driver\n", ndev
->name
);
659 ndev
->netdev_ops
= NULL
;
663 static int brcmf_net_p2p_open(struct net_device
*ndev
)
665 brcmf_dbg(TRACE
, "Enter\n");
667 return brcmf_cfg80211_up(ndev
);
670 static int brcmf_net_p2p_stop(struct net_device
*ndev
)
672 brcmf_dbg(TRACE
, "Enter\n");
674 return brcmf_cfg80211_down(ndev
);
677 static int brcmf_net_p2p_do_ioctl(struct net_device
*ndev
,
678 struct ifreq
*ifr
, int cmd
)
680 brcmf_dbg(TRACE
, "Enter\n");
684 static netdev_tx_t
brcmf_net_p2p_start_xmit(struct sk_buff
*skb
,
685 struct net_device
*ndev
)
688 dev_kfree_skb_any(skb
);
693 static const struct net_device_ops brcmf_netdev_ops_p2p
= {
694 .ndo_open
= brcmf_net_p2p_open
,
695 .ndo_stop
= brcmf_net_p2p_stop
,
696 .ndo_do_ioctl
= brcmf_net_p2p_do_ioctl
,
697 .ndo_start_xmit
= brcmf_net_p2p_start_xmit
700 static int brcmf_net_p2p_attach(struct brcmf_if
*ifp
)
702 struct net_device
*ndev
;
704 brcmf_dbg(TRACE
, "Enter, idx=%d mac=%pM\n", ifp
->bssidx
,
708 ndev
->netdev_ops
= &brcmf_netdev_ops_p2p
;
710 /* set the mac address */
711 memcpy(ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
713 if (register_netdev(ndev
) != 0) {
714 brcmf_err("couldn't register the p2p net device\n");
718 brcmf_dbg(INFO
, "%s: Broadcom Dongle Host Driver\n", ndev
->name
);
726 struct brcmf_if
*brcmf_add_if(struct brcmf_pub
*drvr
, s32 bssidx
, s32 ifidx
,
727 char *name
, u8
*mac_addr
)
729 struct brcmf_if
*ifp
;
730 struct net_device
*ndev
;
732 brcmf_dbg(TRACE
, "Enter, idx=%d, ifidx=%d\n", bssidx
, ifidx
);
734 ifp
= drvr
->iflist
[bssidx
];
736 * Delete the existing interface before overwriting it
737 * in case we missed the BRCMF_E_IF_DEL event.
740 brcmf_err("ERROR: netdev:%s already exists\n",
743 netif_stop_queue(ifp
->ndev
);
744 unregister_netdev(ifp
->ndev
);
745 free_netdev(ifp
->ndev
);
746 drvr
->iflist
[bssidx
] = NULL
;
748 brcmf_err("ignore IF event\n");
749 return ERR_PTR(-EINVAL
);
753 if (!brcmf_p2p_enable
&& bssidx
== 1) {
754 /* this is P2P_DEVICE interface */
755 brcmf_dbg(INFO
, "allocate non-netdev interface\n");
756 ifp
= kzalloc(sizeof(*ifp
), GFP_KERNEL
);
758 brcmf_dbg(INFO
, "allocate netdev interface\n");
759 /* Allocate netdev, including space for private structure */
760 ndev
= alloc_netdev(sizeof(*ifp
), name
, ether_setup
);
762 brcmf_err("OOM - alloc_netdev\n");
763 return ERR_PTR(-ENOMEM
);
766 ifp
= netdev_priv(ndev
);
771 drvr
->iflist
[bssidx
] = ifp
;
773 ifp
->bssidx
= bssidx
;
775 init_waitqueue_head(&ifp
->pend_8021x_wait
);
777 if (mac_addr
!= NULL
)
778 memcpy(ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
780 brcmf_dbg(TRACE
, " ==== pid:%x, if:%s (%pM) created ===\n",
781 current
->pid
, name
, ifp
->mac_addr
);
786 void brcmf_del_if(struct brcmf_pub
*drvr
, s32 bssidx
)
788 struct brcmf_if
*ifp
;
790 ifp
= drvr
->iflist
[bssidx
];
792 brcmf_err("Null interface, idx=%d\n", bssidx
);
795 brcmf_dbg(TRACE
, "Enter, idx=%d, ifidx=%d\n", bssidx
, ifp
->ifidx
);
798 if (ifp
->ndev
->netdev_ops
== &brcmf_netdev_ops_pri
) {
800 brcmf_netdev_stop(ifp
->ndev
);
804 netif_stop_queue(ifp
->ndev
);
807 if (ifp
->ndev
->netdev_ops
== &brcmf_netdev_ops_pri
) {
808 cancel_work_sync(&ifp
->setmacaddr_work
);
809 cancel_work_sync(&ifp
->multicast_work
);
812 unregister_netdev(ifp
->ndev
);
814 brcmf_cfg80211_detach(drvr
->config
);
815 free_netdev(ifp
->ndev
);
819 drvr
->iflist
[bssidx
] = NULL
;
822 int brcmf_attach(uint bus_hdrlen
, struct device
*dev
)
824 struct brcmf_pub
*drvr
= NULL
;
827 brcmf_dbg(TRACE
, "Enter\n");
829 /* Allocate primary brcmf_info */
830 drvr
= kzalloc(sizeof(struct brcmf_pub
), GFP_ATOMIC
);
834 mutex_init(&drvr
->proto_block
);
836 /* Link to bus module */
837 drvr
->hdrlen
= bus_hdrlen
;
838 drvr
->bus_if
= dev_get_drvdata(dev
);
839 drvr
->bus_if
->drvr
= drvr
;
841 /* create device debugfs folder */
842 brcmf_debugfs_attach(drvr
);
844 /* Attach and link in the protocol */
845 ret
= brcmf_proto_attach(drvr
);
847 brcmf_err("brcmf_prot_attach failed\n");
851 /* attach firmware event handler */
852 brcmf_fweh_attach(drvr
);
854 INIT_LIST_HEAD(&drvr
->bus_if
->dcmd_list
);
864 int brcmf_bus_start(struct device
*dev
)
867 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
868 struct brcmf_pub
*drvr
= bus_if
->drvr
;
869 struct brcmf_if
*ifp
;
870 struct brcmf_if
*p2p_ifp
;
872 brcmf_dbg(TRACE
, "\n");
874 /* Bring up the bus */
875 ret
= brcmf_bus_init(bus_if
);
877 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret
);
881 /* add primary networking interface */
882 ifp
= brcmf_add_if(drvr
, 0, 0, "wlan%d", NULL
);
886 if (brcmf_p2p_enable
)
887 p2p_ifp
= brcmf_add_if(drvr
, 1, 0, "p2p%d", NULL
);
893 /* signal bus ready */
894 bus_if
->state
= BRCMF_BUS_DATA
;
896 /* Bus is ready, do any initialization */
897 ret
= brcmf_c_preinit_dcmds(ifp
);
901 drvr
->fw_signals
= true;
902 (void)brcmf_fws_init(drvr
);
903 brcmf_fws_add_interface(ifp
);
905 drvr
->config
= brcmf_cfg80211_attach(drvr
, bus_if
->dev
);
906 if (drvr
->config
== NULL
) {
911 ret
= brcmf_fweh_activate_events(ifp
);
915 ret
= brcmf_net_attach(ifp
, false);
918 brcmf_err("failed: %d\n", ret
);
920 brcmf_cfg80211_detach(drvr
->config
);
922 brcmf_fws_del_interface(ifp
);
923 brcmf_fws_deinit(drvr
);
925 free_netdev(ifp
->ndev
);
926 drvr
->iflist
[0] = NULL
;
928 free_netdev(p2p_ifp
->ndev
);
929 drvr
->iflist
[1] = NULL
;
933 if ((brcmf_p2p_enable
) && (p2p_ifp
))
934 brcmf_net_p2p_attach(p2p_ifp
);
939 static void brcmf_bus_detach(struct brcmf_pub
*drvr
)
941 brcmf_dbg(TRACE
, "Enter\n");
944 /* Stop the protocol module */
945 brcmf_proto_stop(drvr
);
947 /* Stop the bus module */
948 brcmf_bus_stop(drvr
->bus_if
);
952 void brcmf_dev_reset(struct device
*dev
)
954 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
955 struct brcmf_pub
*drvr
= bus_if
->drvr
;
961 brcmf_fil_cmd_int_set(drvr
->iflist
[0], BRCMF_C_TERMINATED
, 1);
964 void brcmf_detach(struct device
*dev
)
967 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
968 struct brcmf_pub
*drvr
= bus_if
->drvr
;
970 brcmf_dbg(TRACE
, "Enter\n");
975 /* stop firmware event handling */
976 brcmf_fweh_detach(drvr
);
978 /* make sure primary interface removed last */
979 for (i
= BRCMF_MAX_IFS
-1; i
> -1; i
--)
980 if (drvr
->iflist
[i
]) {
981 brcmf_fws_del_interface(drvr
->iflist
[i
]);
982 brcmf_del_if(drvr
, i
);
985 brcmf_bus_detach(drvr
);
988 brcmf_proto_detach(drvr
);
990 brcmf_fws_deinit(drvr
);
992 brcmf_debugfs_detach(drvr
);
997 static int brcmf_get_pend_8021x_cnt(struct brcmf_if
*ifp
)
999 return atomic_read(&ifp
->pend_8021x_cnt
);
1002 int brcmf_netdev_wait_pend8021x(struct net_device
*ndev
)
1004 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1007 err
= wait_event_timeout(ifp
->pend_8021x_wait
,
1008 !brcmf_get_pend_8021x_cnt(ifp
),
1009 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX
));
1017 * return chip id and rev of the device encoded in u32.
1019 u32
brcmf_get_chip_info(struct brcmf_if
*ifp
)
1021 struct brcmf_bus
*bus
= ifp
->drvr
->bus_if
;
1023 return bus
->chip
<< 4 | bus
->chiprev
;
1026 static void brcmf_driver_init(struct work_struct
*work
)
1028 brcmf_debugfs_init();
1030 #ifdef CONFIG_BRCMFMAC_SDIO
1033 #ifdef CONFIG_BRCMFMAC_USB
1037 static DECLARE_WORK(brcmf_driver_work
, brcmf_driver_init
);
1039 static int __init
brcmfmac_module_init(void)
1041 if (!schedule_work(&brcmf_driver_work
))
1047 static void __exit
brcmfmac_module_exit(void)
1049 cancel_work_sync(&brcmf_driver_work
);
1051 #ifdef CONFIG_BRCMFMAC_SDIO
1054 #ifdef CONFIG_BRCMFMAC_USB
1057 brcmf_debugfs_exit();
1060 module_init(brcmfmac_module_init
);
1061 module_exit(brcmfmac_module_exit
);