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/init.h>
18 #include <linux/kernel.h>
19 #include <linux/kthread.h>
20 #include <linux/slab.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/mmc/sdio_func.h>
25 #include <linux/random.h>
26 #include <linux/spinlock.h>
27 #include <linux/ethtool.h>
28 #include <linux/fcntl.h>
30 #include <linux/uaccess.h>
31 #include <net/cfg80211.h>
33 #include <brcmu_utils.h>
34 #include <brcmu_wifi.h>
36 #include "dngl_stats.h"
39 #include "dhd_proto.h"
41 #include "wl_cfg80211.h"
44 #if defined(CONFIG_PM_SLEEP)
45 #include <linux/suspend.h>
46 atomic_t brcmf_mmc_suspend
;
47 #endif /* defined(CONFIG_PM_SLEEP) */
49 MODULE_AUTHOR("Broadcom Corporation");
50 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
51 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
52 MODULE_LICENSE("Dual BSD/GPL");
55 /* Interface control information */
57 struct brcmf_info
*info
; /* back pointer to brcmf_info */
58 /* OS/stack specifics */
59 struct net_device
*net
;
60 struct net_device_stats stats
;
61 int idx
; /* iface idx in dongle */
62 int state
; /* interface state */
63 uint subunit
; /* subunit */
64 u8 mac_addr
[ETH_ALEN
]; /* assigned MAC address */
65 bool attached
; /* Delayed attachment when unset */
66 bool txflowcontrol
; /* Per interface flow control indicator */
67 char name
[IFNAMSIZ
]; /* linux interface name */
70 /* Local private structure (extension of pub) */
74 /* OS/stack specifics */
75 struct brcmf_if
*iflist
[BRCMF_MAX_IFS
];
77 struct semaphore proto_sem
;
78 wait_queue_head_t ioctl_resp_wait
;
80 /* Thread to issue ioctl for multicast */
81 struct task_struct
*sysioc_tsk
;
82 struct semaphore sysioc_sem
;
85 u8 macvalue
[ETH_ALEN
];
86 atomic_t pend_8021x_cnt
;
90 module_param(brcmf_msg_level
, int, 0);
92 /* Spawn a thread for system ioctls (set mac, set mcast) */
93 uint brcmf_sysioc
= true;
94 module_param(brcmf_sysioc
, uint
, 0);
96 /* ARP offload agent mode : Enable ARP Host Auto-Reply
97 and ARP Peer Auto-Reply */
98 uint brcmf_arp_mode
= 0xb;
99 module_param(brcmf_arp_mode
, uint
, 0);
101 /* ARP offload enable */
102 uint brcmf_arp_enable
= true;
103 module_param(brcmf_arp_enable
, uint
, 0);
105 /* Global Pkt filter enable control */
106 uint brcmf_pkt_filter_enable
= true;
107 module_param(brcmf_pkt_filter_enable
, uint
, 0);
109 /* Pkt filter init setup */
110 uint brcmf_pkt_filter_init
;
111 module_param(brcmf_pkt_filter_init
, uint
, 0);
113 /* Pkt filter mode control */
114 uint brcmf_master_mode
= true;
115 module_param(brcmf_master_mode
, uint
, 1);
117 extern int brcmf_dongle_memsize
;
118 module_param(brcmf_dongle_memsize
, int, 0);
120 /* Contorl fw roaming */
123 /* Control radio state */
124 uint brcmf_radio_up
= 1;
126 /* Network inteface name */
127 char iface_name
[IFNAMSIZ
] = "wlan";
128 module_param_string(iface_name
, iface_name
, IFNAMSIZ
, 0);
130 /* The following are specific to the SDIO dongle */
132 /* IOCTL response timeout */
133 int brcmf_ioctl_timeout_msec
= IOCTL_RESP_TIMEOUT
;
135 /* Idle timeout for backplane clock */
136 int brcmf_idletime
= BRCMF_IDLETIME_TICKS
;
137 module_param(brcmf_idletime
, int, 0);
141 module_param(brcmf_poll
, uint
, 0);
144 uint brcmf_intr
= true;
145 module_param(brcmf_intr
, uint
, 0);
147 /* SDIO Drive Strength (in milliamps) */
148 uint brcmf_sdiod_drive_strength
= 6;
149 module_param(brcmf_sdiod_drive_strength
, uint
, 0);
152 extern uint brcmf_txbound
;
153 extern uint brcmf_rxbound
;
154 module_param(brcmf_txbound
, uint
, 0);
155 module_param(brcmf_rxbound
, uint
, 0);
158 /* Echo packet generator (pkts/s) */
160 module_param(brcmf_pktgen
, uint
, 0);
162 /* Echo packet len (0 => sawtooth, max 2040) */
163 uint brcmf_pktgen_len
;
164 module_param(brcmf_pktgen_len
, uint
, 0);
167 static int brcmf_toe_get(struct brcmf_info
*drvr_priv
, int idx
, u32
*toe_ol
);
168 static int brcmf_toe_set(struct brcmf_info
*drvr_priv
, int idx
, u32 toe_ol
);
169 static int brcmf_host_event(struct brcmf_info
*drvr_priv
, int *ifidx
, void *pktdata
,
170 struct brcmf_event_msg
*event_ptr
,
174 * Generalized timeout mechanism. Uses spin sleep with exponential
176 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
178 * brcmf_timeout_start(&tmo, usec);
179 * while (!brcmf_timeout_expired(&tmo))
180 * if (poll_something())
182 * if (brcmf_timeout_expired(&tmo))
186 void brcmf_timeout_start(struct brcmf_timeout
*tmo
, uint usec
)
191 tmo
->tick
= 1000000 / HZ
;
194 int brcmf_timeout_expired(struct brcmf_timeout
*tmo
)
196 /* Does nothing the first call */
197 if (tmo
->increment
== 0) {
202 if (tmo
->elapsed
>= tmo
->limit
)
205 /* Add the delay that's about to take place */
206 tmo
->elapsed
+= tmo
->increment
;
208 if (tmo
->increment
< tmo
->tick
) {
209 udelay(tmo
->increment
);
211 if (tmo
->increment
> tmo
->tick
)
212 tmo
->increment
= tmo
->tick
;
214 wait_queue_head_t delay_wait
;
215 DECLARE_WAITQUEUE(wait
, current
);
217 init_waitqueue_head(&delay_wait
);
218 add_wait_queue(&delay_wait
, &wait
);
219 set_current_state(TASK_INTERRUPTIBLE
);
221 pending
= signal_pending(current
);
222 remove_wait_queue(&delay_wait
, &wait
);
223 set_current_state(TASK_RUNNING
);
225 return 1; /* Interrupted */
231 static int brcmf_net2idx(struct brcmf_info
*drvr_priv
, struct net_device
*net
)
235 while (i
< BRCMF_MAX_IFS
) {
236 if (drvr_priv
->iflist
[i
] && (drvr_priv
->iflist
[i
]->net
== net
))
244 int brcmf_ifname2idx(struct brcmf_info
*drvr_priv
, char *name
)
246 int i
= BRCMF_MAX_IFS
;
248 if (name
== NULL
|| *name
== '\0')
252 if (drvr_priv
->iflist
[i
]
253 && !strncmp(drvr_priv
->iflist
[i
]->name
, name
, IFNAMSIZ
))
256 BRCMF_TRACE(("%s: return idx %d for \"%s\"\n", __func__
, i
, name
));
258 return i
; /* default - the primary interface */
261 char *brcmf_ifname(struct brcmf_pub
*drvr
, int ifidx
)
263 struct brcmf_info
*drvr_priv
= drvr
->info
;
265 if (ifidx
< 0 || ifidx
>= BRCMF_MAX_IFS
) {
266 BRCMF_ERROR(("%s: ifidx %d out of range\n", __func__
, ifidx
));
270 if (drvr_priv
->iflist
[ifidx
] == NULL
) {
271 BRCMF_ERROR(("%s: null i/f %d\n", __func__
, ifidx
));
275 if (drvr_priv
->iflist
[ifidx
]->net
)
276 return drvr_priv
->iflist
[ifidx
]->net
->name
;
281 static void _brcmf_set_multicast_list(struct brcmf_info
*drvr_priv
, int ifidx
)
283 struct net_device
*dev
;
284 struct netdev_hw_addr
*ha
;
287 struct brcmf_ioctl ioc
;
292 dev
= drvr_priv
->iflist
[ifidx
]->net
;
293 cnt
= netdev_mc_count(dev
);
295 /* Determine initial value of allmulti flag */
296 allmulti
= (dev
->flags
& IFF_ALLMULTI
) ? true : false;
298 /* Send down the multicast list first. */
300 buflen
= sizeof("mcast_list") + sizeof(cnt
) + (cnt
* ETH_ALEN
);
301 bufp
= buf
= kmalloc(buflen
, GFP_ATOMIC
);
303 BRCMF_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
304 brcmf_ifname(&drvr_priv
->pub
, ifidx
), cnt
));
308 strcpy(bufp
, "mcast_list");
309 bufp
+= strlen("mcast_list") + 1;
311 cnt
= cpu_to_le32(cnt
);
312 memcpy(bufp
, &cnt
, sizeof(cnt
));
315 netdev_for_each_mc_addr(ha
, dev
) {
318 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
323 memset(&ioc
, 0, sizeof(ioc
));
324 ioc
.cmd
= BRCMF_C_SET_VAR
;
329 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
331 BRCMF_ERROR(("%s: set mcast_list failed, cnt %d\n",
332 brcmf_ifname(&drvr_priv
->pub
, ifidx
), cnt
));
333 allmulti
= cnt
? true : allmulti
;
338 /* Now send the allmulti setting. This is based on the setting in the
339 * net_device flags, but might be modified above to be turned on if we
340 * were trying to set some addresses and dongle rejected it...
343 buflen
= sizeof("allmulti") + sizeof(allmulti
);
344 buf
= kmalloc(buflen
, GFP_ATOMIC
);
346 BRCMF_ERROR(("%s: out of memory for allmulti\n",
347 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
350 allmulti
= cpu_to_le32(allmulti
);
353 ("allmulti", (void *)&allmulti
, sizeof(allmulti
), buf
, buflen
)) {
354 BRCMF_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
356 brcmf_ifname(&drvr_priv
->pub
, ifidx
),
357 (int)sizeof(allmulti
), buflen
));
362 memset(&ioc
, 0, sizeof(ioc
));
363 ioc
.cmd
= BRCMF_C_SET_VAR
;
368 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
370 BRCMF_ERROR(("%s: set allmulti %d failed\n",
371 brcmf_ifname(&drvr_priv
->pub
, ifidx
),
372 le32_to_cpu(allmulti
)));
377 /* Finally, pick up the PROMISC flag as well, like the NIC
380 allmulti
= (dev
->flags
& IFF_PROMISC
) ? true : false;
381 allmulti
= cpu_to_le32(allmulti
);
383 memset(&ioc
, 0, sizeof(ioc
));
384 ioc
.cmd
= BRCMF_C_SET_PROMISC
;
386 ioc
.len
= sizeof(allmulti
);
389 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
391 BRCMF_ERROR(("%s: set promisc %d failed\n",
392 brcmf_ifname(&drvr_priv
->pub
, ifidx
),
393 le32_to_cpu(allmulti
)));
397 static int _brcmf_set_mac_address(struct brcmf_info
*drvr_priv
, int ifidx
, u8
*addr
)
400 struct brcmf_ioctl ioc
;
403 BRCMF_TRACE(("%s enter\n", __func__
));
405 ("cur_etheraddr", (char *)addr
, ETH_ALEN
, buf
, 32)) {
406 BRCMF_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
407 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
410 memset(&ioc
, 0, sizeof(ioc
));
411 ioc
.cmd
= BRCMF_C_SET_VAR
;
416 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
418 BRCMF_ERROR(("%s: set cur_etheraddr failed\n",
419 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
421 memcpy(drvr_priv
->iflist
[ifidx
]->net
->dev_addr
, addr
, ETH_ALEN
);
428 extern struct net_device
*ap_net_dev
;
431 /* Virtual interfaces only ((ifp && ifp->info && ifp->idx == true) */
432 static void brcmf_op_if(struct brcmf_if
*ifp
)
434 struct brcmf_info
*drvr_priv
;
435 int ret
= 0, err
= 0;
437 drvr_priv
= ifp
->info
;
439 BRCMF_TRACE(("%s: idx %d, state %d\n", __func__
, ifp
->idx
, ifp
->state
));
441 switch (ifp
->state
) {
444 * Delete the existing interface before overwriting it
445 * in case we missed the BRCMF_E_IF_DEL event.
447 if (ifp
->net
!= NULL
) {
448 BRCMF_ERROR(("%s: ERROR: netdev:%s already exists, "
449 "try free & unregister\n",
450 __func__
, ifp
->net
->name
));
451 netif_stop_queue(ifp
->net
);
452 unregister_netdev(ifp
->net
);
453 free_netdev(ifp
->net
);
455 /* Allocate etherdev, including space for private structure */
456 ifp
->net
= alloc_etherdev(sizeof(drvr_priv
));
458 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
462 strcpy(ifp
->net
->name
, ifp
->name
);
463 memcpy(netdev_priv(ifp
->net
), &drvr_priv
, sizeof(drvr_priv
));
464 err
= brcmf_net_attach(&drvr_priv
->pub
, ifp
->idx
);
466 BRCMF_ERROR(("%s: brcmf_net_attach failed, "
472 /* semaphore that the soft AP CODE
474 extern struct semaphore ap_eth_sema
;
476 /* save ptr to wl0.1 netdev for use
478 ap_net_dev
= ifp
->net
;
479 /* signal to the SOFTAP 'sleeper' thread,
483 BRCMF_TRACE(("\n ==== pid:%x, net_device for "
484 "if:%s created ===\n\n",
485 current
->pid
, ifp
->net
->name
));
491 if (ifp
->net
!= NULL
) {
492 BRCMF_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
494 netif_stop_queue(ifp
->net
);
495 unregister_netdev(ifp
->net
);
496 ret
= BRCMF_DEL_IF
; /* Make sure the free_netdev()
501 BRCMF_ERROR(("%s: bad op %d\n", __func__
, ifp
->state
));
507 free_netdev(ifp
->net
);
509 drvr_priv
->iflist
[ifp
->idx
] = NULL
;
512 if (ifp
->net
== ap_net_dev
)
513 ap_net_dev
= NULL
; /* NULL SOFTAP global
519 static int _brcmf_sysioc_thread(void *data
)
521 struct brcmf_info
*drvr_priv
= (struct brcmf_info
*) data
;
527 allow_signal(SIGTERM
);
529 while (down_interruptible(&drvr_priv
->sysioc_sem
) == 0) {
530 if (kthread_should_stop())
532 for (i
= 0; i
< BRCMF_MAX_IFS
; i
++) {
533 struct brcmf_if
*ifentry
= drvr_priv
->iflist
[i
];
536 in_ap
= (ap_net_dev
!= NULL
);
539 brcmf_op_if(ifentry
);
541 if (drvr_priv
->iflist
[i
] == NULL
) {
542 BRCMF_TRACE(("\n\n %s: interface %d "
543 "removed!\n", __func__
,
548 if (in_ap
&& drvr_priv
->set_macaddress
) {
549 BRCMF_TRACE(("attempt to set MAC for"
552 ifentry
->net
->name
));
553 drvr_priv
->set_macaddress
= false;
557 if (in_ap
&& drvr_priv
->set_multicast
) {
558 BRCMF_TRACE(("attempt to set MULTICAST "
559 "list for %s in AP Mode, "
561 ifentry
->net
->name
));
562 drvr_priv
->set_multicast
= false;
566 if (drvr_priv
->set_multicast
) {
567 drvr_priv
->set_multicast
= false;
568 _brcmf_set_multicast_list(drvr_priv
, i
);
570 if (drvr_priv
->set_macaddress
) {
571 drvr_priv
->set_macaddress
= false;
572 _brcmf_set_mac_address(drvr_priv
, i
,
573 drvr_priv
->macvalue
);
581 static int brcmf_netdev_set_mac_address(struct net_device
*dev
, void *addr
)
585 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(dev
);
586 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
589 ifidx
= brcmf_net2idx(drvr_priv
, dev
);
590 if (ifidx
== BRCMF_BAD_IF
)
593 memcpy(&drvr_priv
->macvalue
, sa
->sa_data
, ETH_ALEN
);
594 drvr_priv
->set_macaddress
= true;
595 up(&drvr_priv
->sysioc_sem
);
600 static void brcmf_netdev_set_multicast_list(struct net_device
*dev
)
602 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(dev
);
605 ifidx
= brcmf_net2idx(drvr_priv
, dev
);
606 if (ifidx
== BRCMF_BAD_IF
)
609 drvr_priv
->set_multicast
= true;
610 up(&drvr_priv
->sysioc_sem
);
613 int brcmf_sendpkt(struct brcmf_pub
*drvr
, int ifidx
, struct sk_buff
*pktbuf
)
615 struct brcmf_info
*drvr_priv
= drvr
->info
;
618 if (!drvr
->up
|| (drvr
->busstate
== BRCMF_BUS_DOWN
))
621 /* Update multicast statistic */
622 if (pktbuf
->len
>= ETH_ALEN
) {
623 u8
*pktdata
= (u8
*) (pktbuf
->data
);
624 struct ethhdr
*eh
= (struct ethhdr
*)pktdata
;
626 if (is_multicast_ether_addr(eh
->h_dest
))
627 drvr
->tx_multicast
++;
628 if (ntohs(eh
->h_proto
) == ETH_P_PAE
)
629 atomic_inc(&drvr_priv
->pend_8021x_cnt
);
632 /* If the protocol uses a data header, apply it */
633 brcmf_proto_hdrpush(drvr
, ifidx
, pktbuf
);
635 /* Use bus module to send data frame */
636 return brcmf_sdbrcm_bus_txdata(drvr
->bus
, pktbuf
);
639 static int brcmf_netdev_start_xmit(struct sk_buff
*skb
, struct net_device
*net
)
642 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
645 BRCMF_TRACE(("%s: Enter\n", __func__
));
648 if (!drvr_priv
->pub
.up
|| (drvr_priv
->pub
.busstate
== BRCMF_BUS_DOWN
)) {
649 BRCMF_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
650 __func__
, drvr_priv
->pub
.up
,
651 drvr_priv
->pub
.busstate
));
652 netif_stop_queue(net
);
656 ifidx
= brcmf_net2idx(drvr_priv
, net
);
657 if (ifidx
== BRCMF_BAD_IF
) {
658 BRCMF_ERROR(("%s: bad ifidx %d\n", __func__
, ifidx
));
659 netif_stop_queue(net
);
663 /* Make sure there's enough room for any header */
664 if (skb_headroom(skb
) < drvr_priv
->pub
.hdrlen
) {
665 struct sk_buff
*skb2
;
667 BRCMF_INFO(("%s: insufficient headroom\n",
668 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
669 drvr_priv
->pub
.tx_realloc
++;
670 skb2
= skb_realloc_headroom(skb
, drvr_priv
->pub
.hdrlen
);
674 BRCMF_ERROR(("%s: skb_realloc_headroom failed\n",
675 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
681 ret
= brcmf_sendpkt(&drvr_priv
->pub
, ifidx
, skb
);
685 drvr_priv
->pub
.dstats
.tx_dropped
++;
687 drvr_priv
->pub
.tx_packets
++;
689 /* Return ok: we always eat the packet */
693 void brcmf_txflowcontrol(struct brcmf_pub
*drvr
, int ifidx
, bool state
)
695 struct net_device
*net
;
696 struct brcmf_info
*drvr_priv
= drvr
->info
;
698 BRCMF_TRACE(("%s: Enter\n", __func__
));
701 net
= drvr_priv
->iflist
[ifidx
]->net
;
703 netif_stop_queue(net
);
705 netif_wake_queue(net
);
708 void brcmf_rx_frame(struct brcmf_pub
*drvr
, int ifidx
, struct sk_buff
*skb
,
711 struct brcmf_info
*drvr_priv
= drvr
->info
;
715 struct sk_buff
*pnext
, *save_pktbuf
;
717 struct brcmf_if
*ifp
;
718 struct brcmf_event_msg event
;
720 BRCMF_TRACE(("%s: Enter\n", __func__
));
724 for (i
= 0; skb
&& i
< numpkt
; i
++, skb
= pnext
) {
729 /* Get the protocol, maintain skb around eth_type_trans()
730 * The main reason for this hack is for the limitation of
731 * Linux 2.4 where 'eth_type_trans' uses the
732 * 'net->hard_header_len'
733 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
734 * coping of the packet coming from the network stack to add
735 * BDC, Hardware header etc, during network interface
737 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
739 * for BDC, Hardware header etc. and not just the ETH_HLEN
744 ifp
= drvr_priv
->iflist
[ifidx
];
746 ifp
= drvr_priv
->iflist
[0];
749 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
751 if (skb
->pkt_type
== PACKET_MULTICAST
)
752 drvr_priv
->pub
.rx_multicast
++;
757 /* Strip header, count, deliver upward */
758 skb_pull(skb
, ETH_HLEN
);
760 /* Process special event packets and then discard them */
761 if (ntohs(skb
->protocol
) == ETH_P_LINK_CTL
)
762 brcmf_host_event(drvr_priv
, &ifidx
,
766 if (drvr_priv
->iflist
[ifidx
] &&
767 !drvr_priv
->iflist
[ifidx
]->state
)
768 ifp
= drvr_priv
->iflist
[ifidx
];
771 ifp
->net
->last_rx
= jiffies
;
773 drvr
->dstats
.rx_bytes
+= skb
->len
;
774 drvr
->rx_packets
++; /* Local count */
776 if (in_interrupt()) {
779 /* If the receive is not processed inside an ISR,
780 * the softirqd must be woken explicitly to service
781 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
782 * by netif_rx_ni(), but in earlier kernels, we need
790 void brcmf_txcomplete(struct brcmf_pub
*drvr
, struct sk_buff
*txp
, bool success
)
793 struct brcmf_info
*drvr_priv
= drvr
->info
;
797 brcmf_proto_hdrpull(drvr
, &ifidx
, txp
);
799 eh
= (struct ethhdr
*)(txp
->data
);
800 type
= ntohs(eh
->h_proto
);
802 if (type
== ETH_P_PAE
)
803 atomic_dec(&drvr_priv
->pend_8021x_cnt
);
807 static struct net_device_stats
*brcmf_netdev_get_stats(struct net_device
*net
)
809 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
810 struct brcmf_if
*ifp
;
813 BRCMF_TRACE(("%s: Enter\n", __func__
));
815 ifidx
= brcmf_net2idx(drvr_priv
, net
);
816 if (ifidx
== BRCMF_BAD_IF
)
819 ifp
= drvr_priv
->iflist
[ifidx
];
821 if (drvr_priv
->pub
.up
) {
822 /* Use the protocol to get dongle stats */
823 brcmf_proto_dstats(&drvr_priv
->pub
);
826 /* Copy dongle stats to net device stats */
827 ifp
->stats
.rx_packets
= drvr_priv
->pub
.dstats
.rx_packets
;
828 ifp
->stats
.tx_packets
= drvr_priv
->pub
.dstats
.tx_packets
;
829 ifp
->stats
.rx_bytes
= drvr_priv
->pub
.dstats
.rx_bytes
;
830 ifp
->stats
.tx_bytes
= drvr_priv
->pub
.dstats
.tx_bytes
;
831 ifp
->stats
.rx_errors
= drvr_priv
->pub
.dstats
.rx_errors
;
832 ifp
->stats
.tx_errors
= drvr_priv
->pub
.dstats
.tx_errors
;
833 ifp
->stats
.rx_dropped
= drvr_priv
->pub
.dstats
.rx_dropped
;
834 ifp
->stats
.tx_dropped
= drvr_priv
->pub
.dstats
.tx_dropped
;
835 ifp
->stats
.multicast
= drvr_priv
->pub
.dstats
.multicast
;
840 /* Retrieve current toe component enables, which are kept
841 as a bitmap in toe_ol iovar */
842 static int brcmf_toe_get(struct brcmf_info
*drvr_priv
, int ifidx
, u32
*toe_ol
)
844 struct brcmf_ioctl ioc
;
848 memset(&ioc
, 0, sizeof(ioc
));
850 ioc
.cmd
= BRCMF_C_GET_VAR
;
852 ioc
.len
= (uint
) sizeof(buf
);
855 strcpy(buf
, "toe_ol");
856 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
858 /* Check for older dongle image that doesn't support toe_ol */
860 BRCMF_ERROR(("%s: toe not supported by device\n",
861 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
865 BRCMF_INFO(("%s: could not get toe_ol: ret=%d\n",
866 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
));
870 memcpy(toe_ol
, buf
, sizeof(u32
));
874 /* Set current toe component enables in toe_ol iovar,
875 and set toe global enable iovar */
876 static int brcmf_toe_set(struct brcmf_info
*drvr_priv
, int ifidx
, u32 toe_ol
)
878 struct brcmf_ioctl ioc
;
882 memset(&ioc
, 0, sizeof(ioc
));
884 ioc
.cmd
= BRCMF_C_SET_VAR
;
886 ioc
.len
= (uint
) sizeof(buf
);
889 /* Set toe_ol as requested */
891 strcpy(buf
, "toe_ol");
892 memcpy(&buf
[sizeof("toe_ol")], &toe_ol
, sizeof(u32
));
894 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
896 BRCMF_ERROR(("%s: could not set toe_ol: ret=%d\n",
897 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
));
901 /* Enable toe globally only if any components are enabled. */
906 memcpy(&buf
[sizeof("toe")], &toe
, sizeof(u32
));
908 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
910 BRCMF_ERROR(("%s: could not set toe: ret=%d\n",
911 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
));
918 static void brcmf_ethtool_get_drvinfo(struct net_device
*net
,
919 struct ethtool_drvinfo
*info
)
921 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
923 sprintf(info
->driver
, KBUILD_MODNAME
);
924 sprintf(info
->version
, "%lu", drvr_priv
->pub
.drv_version
);
925 sprintf(info
->fw_version
, "%s", BCM4329_FW_NAME
);
926 sprintf(info
->bus_info
, "%s",
927 dev_name(&brcmf_cfg80211_get_sdio_func()->dev
));
930 struct ethtool_ops brcmf_ethtool_ops
= {
931 .get_drvinfo
= brcmf_ethtool_get_drvinfo
934 static int brcmf_ethtool(struct brcmf_info
*drvr_priv
, void *uaddr
)
936 struct ethtool_drvinfo info
;
937 char drvname
[sizeof(info
.driver
)];
939 struct ethtool_value edata
;
940 u32 toe_cmpnt
, csum_dir
;
943 BRCMF_TRACE(("%s: Enter\n", __func__
));
945 /* all ethtool calls start with a cmd word */
946 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
950 case ETHTOOL_GDRVINFO
:
951 /* Copy out any request driver name */
952 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
954 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
955 drvname
[sizeof(info
.driver
) - 1] = '\0';
957 /* clear struct for return */
958 memset(&info
, 0, sizeof(info
));
961 /* if requested, identify ourselves */
962 if (strcmp(drvname
, "?dhd") == 0) {
963 sprintf(info
.driver
, "dhd");
964 strcpy(info
.version
, BRCMF_VERSION_STR
);
967 /* otherwise, require dongle to be up */
968 else if (!drvr_priv
->pub
.up
) {
969 BRCMF_ERROR(("%s: dongle is not up\n", __func__
));
973 /* finally, report dongle driver type */
974 else if (drvr_priv
->pub
.iswl
)
975 sprintf(info
.driver
, "wl");
977 sprintf(info
.driver
, "xx");
979 sprintf(info
.version
, "%lu", drvr_priv
->pub
.drv_version
);
980 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
982 BRCMF_CTL(("%s: given %*s, returning %s\n", __func__
,
983 (int)sizeof(drvname
), drvname
, info
.driver
));
986 /* Get toe offload components from dongle */
987 case ETHTOOL_GRXCSUM
:
988 case ETHTOOL_GTXCSUM
:
989 ret
= brcmf_toe_get(drvr_priv
, 0, &toe_cmpnt
);
994 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
997 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
999 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
1003 /* Set toe offload components in dongle */
1004 case ETHTOOL_SRXCSUM
:
1005 case ETHTOOL_STXCSUM
:
1006 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
1009 /* Read the current settings, update and write back */
1010 ret
= brcmf_toe_get(drvr_priv
, 0, &toe_cmpnt
);
1015 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1017 if (edata
.data
!= 0)
1018 toe_cmpnt
|= csum_dir
;
1020 toe_cmpnt
&= ~csum_dir
;
1022 ret
= brcmf_toe_set(drvr_priv
, 0, toe_cmpnt
);
1026 /* If setting TX checksum mode, tell Linux the new mode */
1027 if (cmd
== ETHTOOL_STXCSUM
) {
1029 drvr_priv
->iflist
[0]->net
->features
|=
1032 drvr_priv
->iflist
[0]->net
->features
&=
1045 static int brcmf_netdev_ioctl_entry(struct net_device
*net
, struct ifreq
*ifr
,
1048 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
1049 struct brcmf_c_ioctl ioc
;
1055 bool is_set_key_cmd
;
1057 ifidx
= brcmf_net2idx(drvr_priv
, net
);
1058 BRCMF_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__
, ifidx
, cmd
));
1060 if (ifidx
== BRCMF_BAD_IF
)
1063 if (cmd
== SIOCETHTOOL
)
1064 return brcmf_ethtool(drvr_priv
, (void *)ifr
->ifr_data
);
1066 if (cmd
!= SIOCDEVPRIVATE
)
1069 memset(&ioc
, 0, sizeof(ioc
));
1071 /* Copy the ioc control structure part of ioctl request */
1072 if (copy_from_user(&ioc
, ifr
->ifr_data
, sizeof(struct brcmf_ioctl
))) {
1077 /* Copy out any buffer passed */
1079 buflen
= min_t(int, ioc
.len
, BRCMF_IOCTL_MAXLEN
);
1080 /* optimization for direct ioctl calls from kernel */
1082 if (segment_eq(get_fs(), KERNEL_DS)) {
1087 buf
= kmalloc(buflen
, GFP_ATOMIC
);
1092 if (copy_from_user(buf
, ioc
.buf
, buflen
)) {
1099 /* To differentiate read 4 more byes */
1100 if ((copy_from_user(&driver
, (char *)ifr
->ifr_data
+
1101 sizeof(struct brcmf_ioctl
), sizeof(uint
)) != 0)) {
1106 if (!capable(CAP_NET_ADMIN
)) {
1111 /* check for local brcmf ioctl and handle it */
1112 if (driver
== BRCMF_IOCTL_MAGIC
) {
1113 bcmerror
= brcmf_c_ioctl((void *)&drvr_priv
->pub
, &ioc
, buf
, buflen
);
1115 drvr_priv
->pub
.bcmerror
= bcmerror
;
1119 /* send to dongle (must be up, and wl) */
1120 if ((drvr_priv
->pub
.busstate
!= BRCMF_BUS_DATA
)) {
1121 BRCMF_ERROR(("%s DONGLE_DOWN,__func__\n", __func__
));
1126 if (!drvr_priv
->pub
.iswl
) {
1132 * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
1133 * set key IOCTL to prevent M4 encryption.
1135 is_set_key_cmd
= ((ioc
.cmd
== BRCMF_C_SET_KEY
) ||
1136 ((ioc
.cmd
== BRCMF_C_SET_VAR
) &&
1137 !(strncmp("wsec_key", ioc
.buf
, 9))) ||
1138 ((ioc
.cmd
== BRCMF_C_SET_VAR
) &&
1139 !(strncmp("bsscfg:wsec_key", ioc
.buf
, 15))));
1141 brcmf_netdev_wait_pend8021x(net
);
1144 brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, (struct brcmf_ioctl
*)&ioc
,
1148 if (!bcmerror
&& buf
&& ioc
.buf
) {
1149 if (copy_to_user(ioc
.buf
, buf
, buflen
))
1161 static int brcmf_netdev_stop(struct net_device
*net
)
1163 #if !defined(IGNORE_ETH0_DOWN)
1164 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
1166 BRCMF_TRACE(("%s: Enter\n", __func__
));
1167 brcmf_cfg80211_down();
1168 if (drvr_priv
->pub
.up
== 0)
1171 /* Set state and stop OS transmissions */
1172 drvr_priv
->pub
.up
= 0;
1173 netif_stop_queue(net
);
1175 BRCMF_ERROR(("BYPASS %s:due to BRCM compilation: under investigation\n",
1177 #endif /* !defined(IGNORE_ETH0_DOWN) */
1182 static int brcmf_netdev_open(struct net_device
*net
)
1184 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
1186 int ifidx
= brcmf_net2idx(drvr_priv
, net
);
1189 BRCMF_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
1191 if (ifidx
== 0) { /* do it only for primary eth0 */
1193 /* try to bring up bus */
1194 ret
= brcmf_bus_start(&drvr_priv
->pub
);
1196 BRCMF_ERROR(("%s: failed with code %d\n",
1200 atomic_set(&drvr_priv
->pend_8021x_cnt
, 0);
1202 memcpy(net
->dev_addr
, drvr_priv
->pub
.mac
, ETH_ALEN
);
1204 /* Get current TOE mode from dongle */
1205 if (brcmf_toe_get(drvr_priv
, ifidx
, &toe_ol
) >= 0
1206 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
1207 drvr_priv
->iflist
[ifidx
]->net
->features
|=
1210 drvr_priv
->iflist
[ifidx
]->net
->features
&=
1213 /* Allow transmit calls */
1214 netif_start_queue(net
);
1215 drvr_priv
->pub
.up
= 1;
1216 if (unlikely(brcmf_cfg80211_up())) {
1217 BRCMF_ERROR(("%s: failed to bring up cfg80211\n",
1226 brcmf_add_if(struct brcmf_info
*drvr_priv
, int ifidx
, void *handle
, char *name
,
1227 u8
*mac_addr
, u32 flags
, u8 bssidx
)
1229 struct brcmf_if
*ifp
;
1231 BRCMF_TRACE(("%s: idx %d, handle->%p\n", __func__
, ifidx
, handle
));
1233 ifp
= drvr_priv
->iflist
[ifidx
];
1235 ifp
= kmalloc(sizeof(struct brcmf_if
), GFP_ATOMIC
);
1237 BRCMF_ERROR(("%s: OOM - struct brcmf_if\n", __func__
));
1242 memset(ifp
, 0, sizeof(struct brcmf_if
));
1243 ifp
->info
= drvr_priv
;
1244 drvr_priv
->iflist
[ifidx
] = ifp
;
1245 strlcpy(ifp
->name
, name
, IFNAMSIZ
);
1246 if (mac_addr
!= NULL
)
1247 memcpy(&ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
1249 if (handle
== NULL
) {
1250 ifp
->state
= BRCMF_E_IF_ADD
;
1252 up(&drvr_priv
->sysioc_sem
);
1254 ifp
->net
= (struct net_device
*)handle
;
1259 void brcmf_del_if(struct brcmf_info
*drvr_priv
, int ifidx
)
1261 struct brcmf_if
*ifp
;
1263 BRCMF_TRACE(("%s: idx %d\n", __func__
, ifidx
));
1265 ifp
= drvr_priv
->iflist
[ifidx
];
1267 BRCMF_ERROR(("%s: Null interface\n", __func__
));
1271 ifp
->state
= BRCMF_E_IF_DEL
;
1273 up(&drvr_priv
->sysioc_sem
);
1276 struct brcmf_pub
*brcmf_attach(struct brcmf_bus
*bus
, uint bus_hdrlen
)
1278 struct brcmf_info
*drvr_priv
= NULL
;
1279 struct net_device
*net
;
1281 BRCMF_TRACE(("%s: Enter\n", __func__
));
1283 /* Allocate etherdev, including space for private structure */
1284 net
= alloc_etherdev(sizeof(drvr_priv
));
1286 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
1290 /* Allocate primary brcmf_info */
1291 drvr_priv
= kzalloc(sizeof(struct brcmf_info
), GFP_ATOMIC
);
1293 BRCMF_ERROR(("%s: OOM - alloc brcmf_info\n", __func__
));
1298 * Save the brcmf_info into the priv
1300 memcpy(netdev_priv(net
), &drvr_priv
, sizeof(drvr_priv
));
1302 /* Set network interface name if it was provided as module parameter */
1303 if (iface_name
[0]) {
1306 strncpy(net
->name
, iface_name
, IFNAMSIZ
);
1307 net
->name
[IFNAMSIZ
- 1] = 0;
1308 len
= strlen(net
->name
);
1309 ch
= net
->name
[len
- 1];
1310 if ((ch
> '9' || ch
< '0') && (len
< IFNAMSIZ
- 2))
1311 strcat(net
->name
, "%d");
1314 if (brcmf_add_if(drvr_priv
, 0, (void *)net
, net
->name
, NULL
, 0, 0) ==
1318 net
->netdev_ops
= NULL
;
1319 sema_init(&drvr_priv
->proto_sem
, 1);
1320 /* Initialize other structure content */
1321 init_waitqueue_head(&drvr_priv
->ioctl_resp_wait
);
1323 /* Link to info module */
1324 drvr_priv
->pub
.info
= drvr_priv
;
1326 /* Link to bus module */
1327 drvr_priv
->pub
.bus
= bus
;
1328 drvr_priv
->pub
.hdrlen
= bus_hdrlen
;
1330 /* Attach and link in the protocol */
1331 if (brcmf_proto_attach(&drvr_priv
->pub
) != 0) {
1332 BRCMF_ERROR(("brcmf_prot_attach failed\n"));
1336 /* Attach and link in the cfg80211 */
1337 if (unlikely(brcmf_cfg80211_attach(net
, &drvr_priv
->pub
))) {
1338 BRCMF_ERROR(("wl_cfg80211_attach failed\n"));
1343 sema_init(&drvr_priv
->sysioc_sem
, 0);
1344 drvr_priv
->sysioc_tsk
= kthread_run(_brcmf_sysioc_thread
, drvr_priv
,
1346 if (IS_ERR(drvr_priv
->sysioc_tsk
)) {
1348 "_brcmf_sysioc thread failed to start\n");
1349 drvr_priv
->sysioc_tsk
= NULL
;
1352 drvr_priv
->sysioc_tsk
= NULL
;
1355 * Save the brcmf_info into the priv
1357 memcpy(netdev_priv(net
), &drvr_priv
, sizeof(drvr_priv
));
1359 #if defined(CONFIG_PM_SLEEP)
1360 atomic_set(&brcmf_mmc_suspend
, false);
1361 #endif /* defined(CONFIG_PM_SLEEP) */
1362 return &drvr_priv
->pub
;
1368 brcmf_detach(&drvr_priv
->pub
);
1373 int brcmf_bus_start(struct brcmf_pub
*drvr
)
1376 struct brcmf_info
*drvr_priv
= drvr
->info
;
1377 /* Room for "event_msgs" + '\0' + bitvec */
1378 char iovbuf
[BRCMF_EVENTING_MASK_LEN
+ 12];
1380 BRCMF_TRACE(("%s:\n", __func__
));
1382 /* Bring up the bus */
1383 ret
= brcmf_sdbrcm_bus_init(&drvr_priv
->pub
, true);
1385 BRCMF_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__
,
1390 /* If bus is not ready, can't come up */
1391 if (drvr_priv
->pub
.busstate
!= BRCMF_BUS_DATA
) {
1392 BRCMF_ERROR(("%s failed bus is not ready\n", __func__
));
1396 brcmu_mkiovar("event_msgs", drvr
->eventmask
, BRCMF_EVENTING_MASK_LEN
,
1397 iovbuf
, sizeof(iovbuf
));
1398 brcmf_proto_cdc_query_ioctl(drvr
, 0, BRCMF_C_GET_VAR
, iovbuf
,
1400 memcpy(drvr
->eventmask
, iovbuf
, BRCMF_EVENTING_MASK_LEN
);
1402 setbit(drvr
->eventmask
, BRCMF_E_SET_SSID
);
1403 setbit(drvr
->eventmask
, BRCMF_E_PRUNE
);
1404 setbit(drvr
->eventmask
, BRCMF_E_AUTH
);
1405 setbit(drvr
->eventmask
, BRCMF_E_REASSOC
);
1406 setbit(drvr
->eventmask
, BRCMF_E_REASSOC_IND
);
1407 setbit(drvr
->eventmask
, BRCMF_E_DEAUTH_IND
);
1408 setbit(drvr
->eventmask
, BRCMF_E_DISASSOC_IND
);
1409 setbit(drvr
->eventmask
, BRCMF_E_DISASSOC
);
1410 setbit(drvr
->eventmask
, BRCMF_E_JOIN
);
1411 setbit(drvr
->eventmask
, BRCMF_E_ASSOC_IND
);
1412 setbit(drvr
->eventmask
, BRCMF_E_PSK_SUP
);
1413 setbit(drvr
->eventmask
, BRCMF_E_LINK
);
1414 setbit(drvr
->eventmask
, BRCMF_E_NDIS_LINK
);
1415 setbit(drvr
->eventmask
, BRCMF_E_MIC_ERROR
);
1416 setbit(drvr
->eventmask
, BRCMF_E_PMKID_CACHE
);
1417 setbit(drvr
->eventmask
, BRCMF_E_TXFAIL
);
1418 setbit(drvr
->eventmask
, BRCMF_E_JOIN_START
);
1419 setbit(drvr
->eventmask
, BRCMF_E_SCAN_COMPLETE
);
1421 /* enable dongle roaming event */
1423 drvr
->pktfilter_count
= 1;
1424 /* Setup filter to allow only unicast */
1425 drvr
->pktfilter
[0] = "100 0 0 0 0x01 0x00";
1427 /* Bus is ready, do any protocol initialization */
1428 ret
= brcmf_proto_init(&drvr_priv
->pub
);
1435 static struct net_device_ops brcmf_netdev_ops_pri
= {
1436 .ndo_open
= brcmf_netdev_open
,
1437 .ndo_stop
= brcmf_netdev_stop
,
1438 .ndo_get_stats
= brcmf_netdev_get_stats
,
1439 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
1440 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
1441 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
1442 .ndo_set_multicast_list
= brcmf_netdev_set_multicast_list
1445 int brcmf_net_attach(struct brcmf_pub
*drvr
, int ifidx
)
1447 struct brcmf_info
*drvr_priv
= drvr
->info
;
1448 struct net_device
*net
;
1449 u8 temp_addr
[ETH_ALEN
] = {
1450 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
1452 BRCMF_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
1454 net
= drvr_priv
->iflist
[ifidx
]->net
;
1455 net
->netdev_ops
= &brcmf_netdev_ops_pri
;
1458 * We have to use the primary MAC for virtual interfaces
1461 /* for virtual interfaces use the primary MAC */
1462 memcpy(temp_addr
, drvr_priv
->pub
.mac
, ETH_ALEN
);
1467 BRCMF_TRACE(("%s ACCESS POINT MAC:\n", __func__
));
1468 /* ACCESSPOINT INTERFACE CASE */
1469 temp_addr
[0] |= 0X02; /* set bit 2 ,
1470 - Locally Administered address */
1473 net
->hard_header_len
= ETH_HLEN
+ drvr_priv
->pub
.hdrlen
;
1474 net
->ethtool_ops
= &brcmf_ethtool_ops
;
1476 drvr_priv
->pub
.rxsz
= net
->mtu
+ net
->hard_header_len
+
1477 drvr_priv
->pub
.hdrlen
;
1479 memcpy(net
->dev_addr
, temp_addr
, ETH_ALEN
);
1481 if (register_netdev(net
) != 0) {
1482 BRCMF_ERROR(("%s: couldn't register the net device\n",
1487 BRCMF_INFO(("%s: Broadcom Dongle Host Driver\n", net
->name
));
1492 net
->netdev_ops
= NULL
;
1496 static void brcmf_bus_detach(struct brcmf_pub
*drvr
)
1498 struct brcmf_info
*drvr_priv
;
1500 BRCMF_TRACE(("%s: Enter\n", __func__
));
1503 drvr_priv
= drvr
->info
;
1505 /* Stop the protocol module */
1506 brcmf_proto_stop(&drvr_priv
->pub
);
1508 /* Stop the bus module */
1509 brcmf_sdbrcm_bus_stop(drvr_priv
->pub
.bus
, true);
1514 void brcmf_detach(struct brcmf_pub
*drvr
)
1516 struct brcmf_info
*drvr_priv
;
1518 BRCMF_TRACE(("%s: Enter\n", __func__
));
1521 drvr_priv
= drvr
->info
;
1523 struct brcmf_if
*ifp
;
1526 for (i
= 1; i
< BRCMF_MAX_IFS
; i
++)
1527 if (drvr_priv
->iflist
[i
])
1528 brcmf_del_if(drvr_priv
, i
);
1530 ifp
= drvr_priv
->iflist
[0];
1531 if (ifp
->net
->netdev_ops
== &brcmf_netdev_ops_pri
) {
1532 brcmf_netdev_stop(ifp
->net
);
1533 unregister_netdev(ifp
->net
);
1536 if (drvr_priv
->sysioc_tsk
) {
1537 send_sig(SIGTERM
, drvr_priv
->sysioc_tsk
, 1);
1538 kthread_stop(drvr_priv
->sysioc_tsk
);
1539 drvr_priv
->sysioc_tsk
= NULL
;
1542 brcmf_bus_detach(drvr
);
1545 brcmf_proto_detach(drvr
);
1547 brcmf_cfg80211_detach();
1549 free_netdev(ifp
->net
);
1556 static void __exit
brcmf_module_cleanup(void)
1558 BRCMF_TRACE(("%s: Enter\n", __func__
));
1560 brcmf_bus_unregister();
1563 static int __init
brcmf_module_init(void)
1567 BRCMF_TRACE(("%s: Enter\n", __func__
));
1569 error
= brcmf_bus_register();
1572 BRCMF_ERROR(("%s: brcmf_bus_register failed\n", __func__
));
1581 module_init(brcmf_module_init
);
1582 module_exit(brcmf_module_cleanup
);
1584 int brcmf_os_proto_block(struct brcmf_pub
*drvr
)
1586 struct brcmf_info
*drvr_priv
= drvr
->info
;
1589 down(&drvr_priv
->proto_sem
);
1595 int brcmf_os_proto_unblock(struct brcmf_pub
*drvr
)
1597 struct brcmf_info
*drvr_priv
= drvr
->info
;
1600 up(&drvr_priv
->proto_sem
);
1607 unsigned int brcmf_os_get_ioctl_resp_timeout(void)
1609 return (unsigned int)brcmf_ioctl_timeout_msec
;
1612 void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec
)
1614 brcmf_ioctl_timeout_msec
= (int)timeout_msec
;
1617 int brcmf_os_ioctl_resp_wait(struct brcmf_pub
*drvr
, uint
*condition
,
1620 struct brcmf_info
*drvr_priv
= drvr
->info
;
1621 DECLARE_WAITQUEUE(wait
, current
);
1622 int timeout
= brcmf_ioctl_timeout_msec
;
1624 /* Convert timeout in millsecond to jiffies */
1625 timeout
= timeout
* HZ
/ 1000;
1627 /* Wait until control frame is available */
1628 add_wait_queue(&drvr_priv
->ioctl_resp_wait
, &wait
);
1629 set_current_state(TASK_INTERRUPTIBLE
);
1631 while (!(*condition
) && (!signal_pending(current
) && timeout
))
1632 timeout
= schedule_timeout(timeout
);
1634 if (signal_pending(current
))
1637 set_current_state(TASK_RUNNING
);
1638 remove_wait_queue(&drvr_priv
->ioctl_resp_wait
, &wait
);
1643 int brcmf_os_ioctl_resp_wake(struct brcmf_pub
*drvr
)
1645 struct brcmf_info
*drvr_priv
= drvr
->info
;
1647 if (waitqueue_active(&drvr_priv
->ioctl_resp_wait
))
1648 wake_up_interruptible(&drvr_priv
->ioctl_resp_wait
);
1653 static int brcmf_host_event(struct brcmf_info
*drvr_priv
, int *ifidx
, void *pktdata
,
1654 struct brcmf_event_msg
*event
, void **data
)
1658 bcmerror
= brcmf_c_host_event(drvr_priv
, ifidx
, pktdata
, event
, data
);
1662 if (drvr_priv
->iflist
[*ifidx
]->net
)
1663 brcmf_cfg80211_event(drvr_priv
->iflist
[*ifidx
]->net
,
1669 int brcmf_netdev_reset(struct net_device
*dev
, u8 flag
)
1671 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**)netdev_priv(dev
);
1673 brcmf_bus_devreset(&drvr_priv
->pub
, flag
);
1678 static int brcmf_get_pend_8021x_cnt(struct brcmf_info
*drvr_priv
)
1680 return atomic_read(&drvr_priv
->pend_8021x_cnt
);
1683 #define MAX_WAIT_FOR_8021X_TX 10
1685 int brcmf_netdev_wait_pend8021x(struct net_device
*dev
)
1687 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**)netdev_priv(dev
);
1688 int timeout
= 10 * HZ
/ 1000;
1689 int ntimes
= MAX_WAIT_FOR_8021X_TX
;
1690 int pend
= brcmf_get_pend_8021x_cnt(drvr_priv
);
1692 while (ntimes
&& pend
) {
1694 set_current_state(TASK_INTERRUPTIBLE
);
1695 schedule_timeout(timeout
);
1696 set_current_state(TASK_RUNNING
);
1699 pend
= brcmf_get_pend_8021x_cnt(drvr_priv
);
1705 int brcmf_write_to_file(struct brcmf_pub
*drvr
, u8
*buf
, int size
)
1709 mm_segment_t old_fs
;
1712 /* change to KERNEL_DS address limit */
1716 /* open file to write */
1717 fp
= filp_open("/tmp/mem_dump", O_WRONLY
| O_CREAT
, 0640);
1719 BRCMF_ERROR(("%s: open file error\n", __func__
));
1724 /* Write buf to file */
1725 fp
->f_op
->write(fp
, buf
, size
, &pos
);
1728 /* free buf before return */
1730 /* close file before return */
1732 filp_close(fp
, current
->files
);
1733 /* restore previous address limit */