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 /* Global ASSERT type flag */
47 #if defined(CONFIG_PM_SLEEP)
48 #include <linux/suspend.h>
49 atomic_t brcmf_mmc_suspend
;
50 #endif /* defined(CONFIG_PM_SLEEP) */
52 MODULE_AUTHOR("Broadcom Corporation");
53 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
54 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
55 MODULE_LICENSE("Dual BSD/GPL");
58 /* Interface control information */
60 struct brcmf_info
*info
; /* back pointer to brcmf_info */
61 /* OS/stack specifics */
62 struct net_device
*net
;
63 struct net_device_stats stats
;
64 int idx
; /* iface idx in dongle */
65 int state
; /* interface state */
66 uint subunit
; /* subunit */
67 u8 mac_addr
[ETH_ALEN
]; /* assigned MAC address */
68 bool attached
; /* Delayed attachment when unset */
69 bool txflowcontrol
; /* Per interface flow control indicator */
70 char name
[IFNAMSIZ
]; /* linux interface name */
73 /* Local private structure (extension of pub) */
77 /* OS/stack specifics */
78 struct brcmf_if
*iflist
[BRCMF_MAX_IFS
];
80 struct semaphore proto_sem
;
81 wait_queue_head_t ioctl_resp_wait
;
83 /* Thread to issue ioctl for multicast */
84 struct task_struct
*sysioc_tsk
;
85 struct semaphore sysioc_sem
;
88 u8 macvalue
[ETH_ALEN
];
89 atomic_t pend_8021x_cnt
;
93 module_param(brcmf_msg_level
, int, 0);
95 /* Spawn a thread for system ioctls (set mac, set mcast) */
96 uint brcmf_sysioc
= true;
97 module_param(brcmf_sysioc
, uint
, 0);
99 /* ARP offload agent mode : Enable ARP Host Auto-Reply
100 and ARP Peer Auto-Reply */
101 uint brcmf_arp_mode
= 0xb;
102 module_param(brcmf_arp_mode
, uint
, 0);
104 /* ARP offload enable */
105 uint brcmf_arp_enable
= true;
106 module_param(brcmf_arp_enable
, uint
, 0);
108 /* Global Pkt filter enable control */
109 uint brcmf_pkt_filter_enable
= true;
110 module_param(brcmf_pkt_filter_enable
, uint
, 0);
112 /* Pkt filter init setup */
113 uint brcmf_pkt_filter_init
;
114 module_param(brcmf_pkt_filter_init
, uint
, 0);
116 /* Pkt filter mode control */
117 uint brcmf_master_mode
= true;
118 module_param(brcmf_master_mode
, uint
, 1);
120 extern int brcmf_dongle_memsize
;
121 module_param(brcmf_dongle_memsize
, int, 0);
123 /* Contorl fw roaming */
126 /* Control radio state */
127 uint brcmf_radio_up
= 1;
129 /* Network inteface name */
130 char iface_name
[IFNAMSIZ
] = "wlan";
131 module_param_string(iface_name
, iface_name
, IFNAMSIZ
, 0);
133 /* The following are specific to the SDIO dongle */
135 /* IOCTL response timeout */
136 int brcmf_ioctl_timeout_msec
= IOCTL_RESP_TIMEOUT
;
138 /* Idle timeout for backplane clock */
139 int brcmf_idletime
= BRCMF_IDLETIME_TICKS
;
140 module_param(brcmf_idletime
, int, 0);
144 module_param(brcmf_poll
, uint
, 0);
147 uint brcmf_intr
= true;
148 module_param(brcmf_intr
, uint
, 0);
150 /* SDIO Drive Strength (in milliamps) */
151 uint brcmf_sdiod_drive_strength
= 6;
152 module_param(brcmf_sdiod_drive_strength
, uint
, 0);
155 extern uint brcmf_txbound
;
156 extern uint brcmf_rxbound
;
157 module_param(brcmf_txbound
, uint
, 0);
158 module_param(brcmf_rxbound
, uint
, 0);
161 /* Echo packet generator (pkts/s) */
163 module_param(brcmf_pktgen
, uint
, 0);
165 /* Echo packet len (0 => sawtooth, max 2040) */
166 uint brcmf_pktgen_len
;
167 module_param(brcmf_pktgen_len
, uint
, 0);
170 static int brcmf_toe_get(struct brcmf_info
*drvr_priv
, int idx
, u32
*toe_ol
);
171 static int brcmf_toe_set(struct brcmf_info
*drvr_priv
, int idx
, u32 toe_ol
);
172 static int brcmf_host_event(struct brcmf_info
*drvr_priv
, int *ifidx
, void *pktdata
,
173 struct brcmf_event_msg
*event_ptr
,
177 * Generalized timeout mechanism. Uses spin sleep with exponential
179 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
181 * brcmf_timeout_start(&tmo, usec);
182 * while (!brcmf_timeout_expired(&tmo))
183 * if (poll_something())
185 * if (brcmf_timeout_expired(&tmo))
189 void brcmf_timeout_start(struct brcmf_timeout
*tmo
, uint usec
)
194 tmo
->tick
= 1000000 / HZ
;
197 int brcmf_timeout_expired(struct brcmf_timeout
*tmo
)
199 /* Does nothing the first call */
200 if (tmo
->increment
== 0) {
205 if (tmo
->elapsed
>= tmo
->limit
)
208 /* Add the delay that's about to take place */
209 tmo
->elapsed
+= tmo
->increment
;
211 if (tmo
->increment
< tmo
->tick
) {
212 udelay(tmo
->increment
);
214 if (tmo
->increment
> tmo
->tick
)
215 tmo
->increment
= tmo
->tick
;
217 wait_queue_head_t delay_wait
;
218 DECLARE_WAITQUEUE(wait
, current
);
220 init_waitqueue_head(&delay_wait
);
221 add_wait_queue(&delay_wait
, &wait
);
222 set_current_state(TASK_INTERRUPTIBLE
);
224 pending
= signal_pending(current
);
225 remove_wait_queue(&delay_wait
, &wait
);
226 set_current_state(TASK_RUNNING
);
228 return 1; /* Interrupted */
234 static int brcmf_net2idx(struct brcmf_info
*drvr_priv
, struct net_device
*net
)
238 while (i
< BRCMF_MAX_IFS
) {
239 if (drvr_priv
->iflist
[i
] && (drvr_priv
->iflist
[i
]->net
== net
))
247 int brcmf_ifname2idx(struct brcmf_info
*drvr_priv
, char *name
)
249 int i
= BRCMF_MAX_IFS
;
251 if (name
== NULL
|| *name
== '\0')
255 if (drvr_priv
->iflist
[i
]
256 && !strncmp(drvr_priv
->iflist
[i
]->name
, name
, IFNAMSIZ
))
259 BRCMF_TRACE(("%s: return idx %d for \"%s\"\n", __func__
, i
, name
));
261 return i
; /* default - the primary interface */
264 char *brcmf_ifname(struct brcmf_pub
*drvr
, int ifidx
)
266 struct brcmf_info
*drvr_priv
= drvr
->info
;
268 if (ifidx
< 0 || ifidx
>= BRCMF_MAX_IFS
) {
269 BRCMF_ERROR(("%s: ifidx %d out of range\n", __func__
, ifidx
));
273 if (drvr_priv
->iflist
[ifidx
] == NULL
) {
274 BRCMF_ERROR(("%s: null i/f %d\n", __func__
, ifidx
));
278 if (drvr_priv
->iflist
[ifidx
]->net
)
279 return drvr_priv
->iflist
[ifidx
]->net
->name
;
284 static void _brcmf_set_multicast_list(struct brcmf_info
*drvr_priv
, int ifidx
)
286 struct net_device
*dev
;
287 struct netdev_hw_addr
*ha
;
290 struct brcmf_ioctl ioc
;
295 dev
= drvr_priv
->iflist
[ifidx
]->net
;
296 cnt
= netdev_mc_count(dev
);
298 /* Determine initial value of allmulti flag */
299 allmulti
= (dev
->flags
& IFF_ALLMULTI
) ? true : false;
301 /* Send down the multicast list first. */
303 buflen
= sizeof("mcast_list") + sizeof(cnt
) + (cnt
* ETH_ALEN
);
304 bufp
= buf
= kmalloc(buflen
, GFP_ATOMIC
);
306 BRCMF_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
307 brcmf_ifname(&drvr_priv
->pub
, ifidx
), cnt
));
311 strcpy(bufp
, "mcast_list");
312 bufp
+= strlen("mcast_list") + 1;
314 cnt
= cpu_to_le32(cnt
);
315 memcpy(bufp
, &cnt
, sizeof(cnt
));
318 netdev_for_each_mc_addr(ha
, dev
) {
321 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
326 memset(&ioc
, 0, sizeof(ioc
));
327 ioc
.cmd
= BRCMF_C_SET_VAR
;
332 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
334 BRCMF_ERROR(("%s: set mcast_list failed, cnt %d\n",
335 brcmf_ifname(&drvr_priv
->pub
, ifidx
), cnt
));
336 allmulti
= cnt
? true : allmulti
;
341 /* Now send the allmulti setting. This is based on the setting in the
342 * net_device flags, but might be modified above to be turned on if we
343 * were trying to set some addresses and dongle rejected it...
346 buflen
= sizeof("allmulti") + sizeof(allmulti
);
347 buf
= kmalloc(buflen
, GFP_ATOMIC
);
349 BRCMF_ERROR(("%s: out of memory for allmulti\n",
350 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
353 allmulti
= cpu_to_le32(allmulti
);
356 ("allmulti", (void *)&allmulti
, sizeof(allmulti
), buf
, buflen
)) {
357 BRCMF_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
359 brcmf_ifname(&drvr_priv
->pub
, ifidx
),
360 (int)sizeof(allmulti
), buflen
));
365 memset(&ioc
, 0, sizeof(ioc
));
366 ioc
.cmd
= BRCMF_C_SET_VAR
;
371 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
373 BRCMF_ERROR(("%s: set allmulti %d failed\n",
374 brcmf_ifname(&drvr_priv
->pub
, ifidx
),
375 le32_to_cpu(allmulti
)));
380 /* Finally, pick up the PROMISC flag as well, like the NIC
383 allmulti
= (dev
->flags
& IFF_PROMISC
) ? true : false;
384 allmulti
= cpu_to_le32(allmulti
);
386 memset(&ioc
, 0, sizeof(ioc
));
387 ioc
.cmd
= BRCMF_C_SET_PROMISC
;
389 ioc
.len
= sizeof(allmulti
);
392 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
394 BRCMF_ERROR(("%s: set promisc %d failed\n",
395 brcmf_ifname(&drvr_priv
->pub
, ifidx
),
396 le32_to_cpu(allmulti
)));
400 static int _brcmf_set_mac_address(struct brcmf_info
*drvr_priv
, int ifidx
, u8
*addr
)
403 struct brcmf_ioctl ioc
;
406 BRCMF_TRACE(("%s enter\n", __func__
));
408 ("cur_etheraddr", (char *)addr
, ETH_ALEN
, buf
, 32)) {
409 BRCMF_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
410 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
413 memset(&ioc
, 0, sizeof(ioc
));
414 ioc
.cmd
= BRCMF_C_SET_VAR
;
419 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
421 BRCMF_ERROR(("%s: set cur_etheraddr failed\n",
422 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
424 memcpy(drvr_priv
->iflist
[ifidx
]->net
->dev_addr
, addr
, ETH_ALEN
);
431 extern struct net_device
*ap_net_dev
;
434 /* Virtual interfaces only ((ifp && ifp->info && ifp->idx == true) */
435 static void brcmf_op_if(struct brcmf_if
*ifp
)
437 struct brcmf_info
*drvr_priv
;
438 int ret
= 0, err
= 0;
440 drvr_priv
= ifp
->info
;
442 BRCMF_TRACE(("%s: idx %d, state %d\n", __func__
, ifp
->idx
, ifp
->state
));
444 switch (ifp
->state
) {
447 * Delete the existing interface before overwriting it
448 * in case we missed the BRCMF_E_IF_DEL event.
450 if (ifp
->net
!= NULL
) {
451 BRCMF_ERROR(("%s: ERROR: netdev:%s already exists, "
452 "try free & unregister\n",
453 __func__
, ifp
->net
->name
));
454 netif_stop_queue(ifp
->net
);
455 unregister_netdev(ifp
->net
);
456 free_netdev(ifp
->net
);
458 /* Allocate etherdev, including space for private structure */
459 ifp
->net
= alloc_etherdev(sizeof(drvr_priv
));
461 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
465 strcpy(ifp
->net
->name
, ifp
->name
);
466 memcpy(netdev_priv(ifp
->net
), &drvr_priv
, sizeof(drvr_priv
));
467 err
= brcmf_net_attach(&drvr_priv
->pub
, ifp
->idx
);
469 BRCMF_ERROR(("%s: brcmf_net_attach failed, "
475 /* semaphore that the soft AP CODE
477 extern struct semaphore ap_eth_sema
;
479 /* save ptr to wl0.1 netdev for use
481 ap_net_dev
= ifp
->net
;
482 /* signal to the SOFTAP 'sleeper' thread,
486 BRCMF_TRACE(("\n ==== pid:%x, net_device for "
487 "if:%s created ===\n\n",
488 current
->pid
, ifp
->net
->name
));
494 if (ifp
->net
!= NULL
) {
495 BRCMF_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
497 netif_stop_queue(ifp
->net
);
498 unregister_netdev(ifp
->net
);
499 ret
= BRCMF_DEL_IF
; /* Make sure the free_netdev()
504 BRCMF_ERROR(("%s: bad op %d\n", __func__
, ifp
->state
));
510 free_netdev(ifp
->net
);
512 drvr_priv
->iflist
[ifp
->idx
] = NULL
;
515 if (ifp
->net
== ap_net_dev
)
516 ap_net_dev
= NULL
; /* NULL SOFTAP global
522 static int _brcmf_sysioc_thread(void *data
)
524 struct brcmf_info
*drvr_priv
= (struct brcmf_info
*) data
;
530 allow_signal(SIGTERM
);
532 while (down_interruptible(&drvr_priv
->sysioc_sem
) == 0) {
533 if (kthread_should_stop())
535 for (i
= 0; i
< BRCMF_MAX_IFS
; i
++) {
536 struct brcmf_if
*ifentry
= drvr_priv
->iflist
[i
];
539 in_ap
= (ap_net_dev
!= NULL
);
542 brcmf_op_if(ifentry
);
544 if (drvr_priv
->iflist
[i
] == NULL
) {
545 BRCMF_TRACE(("\n\n %s: interface %d "
546 "removed!\n", __func__
,
551 if (in_ap
&& drvr_priv
->set_macaddress
) {
552 BRCMF_TRACE(("attempt to set MAC for"
555 ifentry
->net
->name
));
556 drvr_priv
->set_macaddress
= false;
560 if (in_ap
&& drvr_priv
->set_multicast
) {
561 BRCMF_TRACE(("attempt to set MULTICAST "
562 "list for %s in AP Mode, "
564 ifentry
->net
->name
));
565 drvr_priv
->set_multicast
= false;
569 if (drvr_priv
->set_multicast
) {
570 drvr_priv
->set_multicast
= false;
571 _brcmf_set_multicast_list(drvr_priv
, i
);
573 if (drvr_priv
->set_macaddress
) {
574 drvr_priv
->set_macaddress
= false;
575 _brcmf_set_mac_address(drvr_priv
, i
,
576 drvr_priv
->macvalue
);
584 static int brcmf_netdev_set_mac_address(struct net_device
*dev
, void *addr
)
588 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(dev
);
589 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
592 ifidx
= brcmf_net2idx(drvr_priv
, dev
);
593 if (ifidx
== BRCMF_BAD_IF
)
596 memcpy(&drvr_priv
->macvalue
, sa
->sa_data
, ETH_ALEN
);
597 drvr_priv
->set_macaddress
= true;
598 up(&drvr_priv
->sysioc_sem
);
603 static void brcmf_netdev_set_multicast_list(struct net_device
*dev
)
605 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(dev
);
608 ifidx
= brcmf_net2idx(drvr_priv
, dev
);
609 if (ifidx
== BRCMF_BAD_IF
)
612 drvr_priv
->set_multicast
= true;
613 up(&drvr_priv
->sysioc_sem
);
616 int brcmf_sendpkt(struct brcmf_pub
*drvr
, int ifidx
, struct sk_buff
*pktbuf
)
618 struct brcmf_info
*drvr_priv
= drvr
->info
;
621 if (!drvr
->up
|| (drvr
->busstate
== BRCMF_BUS_DOWN
))
624 /* Update multicast statistic */
625 if (pktbuf
->len
>= ETH_ALEN
) {
626 u8
*pktdata
= (u8
*) (pktbuf
->data
);
627 struct ethhdr
*eh
= (struct ethhdr
*)pktdata
;
629 if (is_multicast_ether_addr(eh
->h_dest
))
630 drvr
->tx_multicast
++;
631 if (ntohs(eh
->h_proto
) == ETH_P_PAE
)
632 atomic_inc(&drvr_priv
->pend_8021x_cnt
);
635 /* If the protocol uses a data header, apply it */
636 brcmf_proto_hdrpush(drvr
, ifidx
, pktbuf
);
638 /* Use bus module to send data frame */
639 return brcmf_sdbrcm_bus_txdata(drvr
->bus
, pktbuf
);
642 static int brcmf_netdev_start_xmit(struct sk_buff
*skb
, struct net_device
*net
)
645 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
648 BRCMF_TRACE(("%s: Enter\n", __func__
));
651 if (!drvr_priv
->pub
.up
|| (drvr_priv
->pub
.busstate
== BRCMF_BUS_DOWN
)) {
652 BRCMF_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
653 __func__
, drvr_priv
->pub
.up
,
654 drvr_priv
->pub
.busstate
));
655 netif_stop_queue(net
);
659 ifidx
= brcmf_net2idx(drvr_priv
, net
);
660 if (ifidx
== BRCMF_BAD_IF
) {
661 BRCMF_ERROR(("%s: bad ifidx %d\n", __func__
, ifidx
));
662 netif_stop_queue(net
);
666 /* Make sure there's enough room for any header */
667 if (skb_headroom(skb
) < drvr_priv
->pub
.hdrlen
) {
668 struct sk_buff
*skb2
;
670 BRCMF_INFO(("%s: insufficient headroom\n",
671 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
672 drvr_priv
->pub
.tx_realloc
++;
673 skb2
= skb_realloc_headroom(skb
, drvr_priv
->pub
.hdrlen
);
677 BRCMF_ERROR(("%s: skb_realloc_headroom failed\n",
678 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
684 ret
= brcmf_sendpkt(&drvr_priv
->pub
, ifidx
, skb
);
688 drvr_priv
->pub
.dstats
.tx_dropped
++;
690 drvr_priv
->pub
.tx_packets
++;
692 /* Return ok: we always eat the packet */
696 void brcmf_txflowcontrol(struct brcmf_pub
*drvr
, int ifidx
, bool state
)
698 struct net_device
*net
;
699 struct brcmf_info
*drvr_priv
= drvr
->info
;
701 BRCMF_TRACE(("%s: Enter\n", __func__
));
704 net
= drvr_priv
->iflist
[ifidx
]->net
;
706 netif_stop_queue(net
);
708 netif_wake_queue(net
);
711 void brcmf_rx_frame(struct brcmf_pub
*drvr
, int ifidx
, struct sk_buff
*skb
,
714 struct brcmf_info
*drvr_priv
= drvr
->info
;
718 struct sk_buff
*pnext
, *save_pktbuf
;
720 struct brcmf_if
*ifp
;
721 struct brcmf_event_msg event
;
723 BRCMF_TRACE(("%s: Enter\n", __func__
));
727 for (i
= 0; skb
&& i
< numpkt
; i
++, skb
= pnext
) {
732 /* Get the protocol, maintain skb around eth_type_trans()
733 * The main reason for this hack is for the limitation of
734 * Linux 2.4 where 'eth_type_trans' uses the
735 * 'net->hard_header_len'
736 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
737 * coping of the packet coming from the network stack to add
738 * BDC, Hardware header etc, during network interface
740 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
742 * for BDC, Hardware header etc. and not just the ETH_HLEN
747 ifp
= drvr_priv
->iflist
[ifidx
];
749 ifp
= drvr_priv
->iflist
[0];
752 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
754 if (skb
->pkt_type
== PACKET_MULTICAST
)
755 drvr_priv
->pub
.rx_multicast
++;
760 /* Strip header, count, deliver upward */
761 skb_pull(skb
, ETH_HLEN
);
763 /* Process special event packets and then discard them */
764 if (ntohs(skb
->protocol
) == ETH_P_LINK_CTL
)
765 brcmf_host_event(drvr_priv
, &ifidx
,
769 if (drvr_priv
->iflist
[ifidx
] &&
770 !drvr_priv
->iflist
[ifidx
]->state
)
771 ifp
= drvr_priv
->iflist
[ifidx
];
774 ifp
->net
->last_rx
= jiffies
;
776 drvr
->dstats
.rx_bytes
+= skb
->len
;
777 drvr
->rx_packets
++; /* Local count */
779 if (in_interrupt()) {
782 /* If the receive is not processed inside an ISR,
783 * the softirqd must be woken explicitly to service
784 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
785 * by netif_rx_ni(), but in earlier kernels, we need
793 void brcmf_txcomplete(struct brcmf_pub
*drvr
, struct sk_buff
*txp
, bool success
)
796 struct brcmf_info
*drvr_priv
= drvr
->info
;
800 brcmf_proto_hdrpull(drvr
, &ifidx
, txp
);
802 eh
= (struct ethhdr
*)(txp
->data
);
803 type
= ntohs(eh
->h_proto
);
805 if (type
== ETH_P_PAE
)
806 atomic_dec(&drvr_priv
->pend_8021x_cnt
);
810 static struct net_device_stats
*brcmf_netdev_get_stats(struct net_device
*net
)
812 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
813 struct brcmf_if
*ifp
;
816 BRCMF_TRACE(("%s: Enter\n", __func__
));
818 ifidx
= brcmf_net2idx(drvr_priv
, net
);
819 if (ifidx
== BRCMF_BAD_IF
)
822 ifp
= drvr_priv
->iflist
[ifidx
];
824 if (drvr_priv
->pub
.up
) {
825 /* Use the protocol to get dongle stats */
826 brcmf_proto_dstats(&drvr_priv
->pub
);
829 /* Copy dongle stats to net device stats */
830 ifp
->stats
.rx_packets
= drvr_priv
->pub
.dstats
.rx_packets
;
831 ifp
->stats
.tx_packets
= drvr_priv
->pub
.dstats
.tx_packets
;
832 ifp
->stats
.rx_bytes
= drvr_priv
->pub
.dstats
.rx_bytes
;
833 ifp
->stats
.tx_bytes
= drvr_priv
->pub
.dstats
.tx_bytes
;
834 ifp
->stats
.rx_errors
= drvr_priv
->pub
.dstats
.rx_errors
;
835 ifp
->stats
.tx_errors
= drvr_priv
->pub
.dstats
.tx_errors
;
836 ifp
->stats
.rx_dropped
= drvr_priv
->pub
.dstats
.rx_dropped
;
837 ifp
->stats
.tx_dropped
= drvr_priv
->pub
.dstats
.tx_dropped
;
838 ifp
->stats
.multicast
= drvr_priv
->pub
.dstats
.multicast
;
843 /* Retrieve current toe component enables, which are kept
844 as a bitmap in toe_ol iovar */
845 static int brcmf_toe_get(struct brcmf_info
*drvr_priv
, int ifidx
, u32
*toe_ol
)
847 struct brcmf_ioctl ioc
;
851 memset(&ioc
, 0, sizeof(ioc
));
853 ioc
.cmd
= BRCMF_C_GET_VAR
;
855 ioc
.len
= (uint
) sizeof(buf
);
858 strcpy(buf
, "toe_ol");
859 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
861 /* Check for older dongle image that doesn't support toe_ol */
863 BRCMF_ERROR(("%s: toe not supported by device\n",
864 brcmf_ifname(&drvr_priv
->pub
, ifidx
)));
868 BRCMF_INFO(("%s: could not get toe_ol: ret=%d\n",
869 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
));
873 memcpy(toe_ol
, buf
, sizeof(u32
));
877 /* Set current toe component enables in toe_ol iovar,
878 and set toe global enable iovar */
879 static int brcmf_toe_set(struct brcmf_info
*drvr_priv
, int ifidx
, u32 toe_ol
)
881 struct brcmf_ioctl ioc
;
885 memset(&ioc
, 0, sizeof(ioc
));
887 ioc
.cmd
= BRCMF_C_SET_VAR
;
889 ioc
.len
= (uint
) sizeof(buf
);
892 /* Set toe_ol as requested */
894 strcpy(buf
, "toe_ol");
895 memcpy(&buf
[sizeof("toe_ol")], &toe_ol
, sizeof(u32
));
897 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
899 BRCMF_ERROR(("%s: could not set toe_ol: ret=%d\n",
900 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
));
904 /* Enable toe globally only if any components are enabled. */
909 memcpy(&buf
[sizeof("toe")], &toe
, sizeof(u32
));
911 ret
= brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
913 BRCMF_ERROR(("%s: could not set toe: ret=%d\n",
914 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
));
921 static void brcmf_ethtool_get_drvinfo(struct net_device
*net
,
922 struct ethtool_drvinfo
*info
)
924 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
926 sprintf(info
->driver
, KBUILD_MODNAME
);
927 sprintf(info
->version
, "%lu", drvr_priv
->pub
.drv_version
);
928 sprintf(info
->fw_version
, "%s", BCM4329_FW_NAME
);
929 sprintf(info
->bus_info
, "%s",
930 dev_name(&brcmf_cfg80211_get_sdio_func()->dev
));
933 struct ethtool_ops brcmf_ethtool_ops
= {
934 .get_drvinfo
= brcmf_ethtool_get_drvinfo
937 static int brcmf_ethtool(struct brcmf_info
*drvr_priv
, void *uaddr
)
939 struct ethtool_drvinfo info
;
940 char drvname
[sizeof(info
.driver
)];
942 struct ethtool_value edata
;
943 u32 toe_cmpnt
, csum_dir
;
946 BRCMF_TRACE(("%s: Enter\n", __func__
));
948 /* all ethtool calls start with a cmd word */
949 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
953 case ETHTOOL_GDRVINFO
:
954 /* Copy out any request driver name */
955 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
957 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
958 drvname
[sizeof(info
.driver
) - 1] = '\0';
960 /* clear struct for return */
961 memset(&info
, 0, sizeof(info
));
964 /* if requested, identify ourselves */
965 if (strcmp(drvname
, "?dhd") == 0) {
966 sprintf(info
.driver
, "dhd");
967 strcpy(info
.version
, BRCMF_VERSION_STR
);
970 /* otherwise, require dongle to be up */
971 else if (!drvr_priv
->pub
.up
) {
972 BRCMF_ERROR(("%s: dongle is not up\n", __func__
));
976 /* finally, report dongle driver type */
977 else if (drvr_priv
->pub
.iswl
)
978 sprintf(info
.driver
, "wl");
980 sprintf(info
.driver
, "xx");
982 sprintf(info
.version
, "%lu", drvr_priv
->pub
.drv_version
);
983 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
985 BRCMF_CTL(("%s: given %*s, returning %s\n", __func__
,
986 (int)sizeof(drvname
), drvname
, info
.driver
));
989 /* Get toe offload components from dongle */
990 case ETHTOOL_GRXCSUM
:
991 case ETHTOOL_GTXCSUM
:
992 ret
= brcmf_toe_get(drvr_priv
, 0, &toe_cmpnt
);
997 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1000 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
1002 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
1006 /* Set toe offload components in dongle */
1007 case ETHTOOL_SRXCSUM
:
1008 case ETHTOOL_STXCSUM
:
1009 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
1012 /* Read the current settings, update and write back */
1013 ret
= brcmf_toe_get(drvr_priv
, 0, &toe_cmpnt
);
1018 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1020 if (edata
.data
!= 0)
1021 toe_cmpnt
|= csum_dir
;
1023 toe_cmpnt
&= ~csum_dir
;
1025 ret
= brcmf_toe_set(drvr_priv
, 0, toe_cmpnt
);
1029 /* If setting TX checksum mode, tell Linux the new mode */
1030 if (cmd
== ETHTOOL_STXCSUM
) {
1032 drvr_priv
->iflist
[0]->net
->features
|=
1035 drvr_priv
->iflist
[0]->net
->features
&=
1048 static int brcmf_netdev_ioctl_entry(struct net_device
*net
, struct ifreq
*ifr
,
1051 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
1052 struct brcmf_c_ioctl ioc
;
1058 bool is_set_key_cmd
;
1060 ifidx
= brcmf_net2idx(drvr_priv
, net
);
1061 BRCMF_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__
, ifidx
, cmd
));
1063 if (ifidx
== BRCMF_BAD_IF
)
1066 if (cmd
== SIOCETHTOOL
)
1067 return brcmf_ethtool(drvr_priv
, (void *)ifr
->ifr_data
);
1069 if (cmd
!= SIOCDEVPRIVATE
)
1072 memset(&ioc
, 0, sizeof(ioc
));
1074 /* Copy the ioc control structure part of ioctl request */
1075 if (copy_from_user(&ioc
, ifr
->ifr_data
, sizeof(struct brcmf_ioctl
))) {
1080 /* Copy out any buffer passed */
1082 buflen
= min_t(int, ioc
.len
, BRCMF_IOCTL_MAXLEN
);
1083 /* optimization for direct ioctl calls from kernel */
1085 if (segment_eq(get_fs(), KERNEL_DS)) {
1090 buf
= kmalloc(buflen
, GFP_ATOMIC
);
1095 if (copy_from_user(buf
, ioc
.buf
, buflen
)) {
1102 /* To differentiate read 4 more byes */
1103 if ((copy_from_user(&driver
, (char *)ifr
->ifr_data
+
1104 sizeof(struct brcmf_ioctl
), sizeof(uint
)) != 0)) {
1109 if (!capable(CAP_NET_ADMIN
)) {
1114 /* check for local brcmf ioctl and handle it */
1115 if (driver
== BRCMF_IOCTL_MAGIC
) {
1116 bcmerror
= brcmf_c_ioctl((void *)&drvr_priv
->pub
, &ioc
, buf
, buflen
);
1118 drvr_priv
->pub
.bcmerror
= bcmerror
;
1122 /* send to dongle (must be up, and wl) */
1123 if ((drvr_priv
->pub
.busstate
!= BRCMF_BUS_DATA
)) {
1124 BRCMF_ERROR(("%s DONGLE_DOWN,__func__\n", __func__
));
1129 if (!drvr_priv
->pub
.iswl
) {
1135 * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and
1136 * set key IOCTL to prevent M4 encryption.
1138 is_set_key_cmd
= ((ioc
.cmd
== BRCMF_C_SET_KEY
) ||
1139 ((ioc
.cmd
== BRCMF_C_SET_VAR
) &&
1140 !(strncmp("wsec_key", ioc
.buf
, 9))) ||
1141 ((ioc
.cmd
== BRCMF_C_SET_VAR
) &&
1142 !(strncmp("bsscfg:wsec_key", ioc
.buf
, 15))));
1144 brcmf_netdev_wait_pend8021x(net
);
1147 brcmf_proto_ioctl(&drvr_priv
->pub
, ifidx
, (struct brcmf_ioctl
*)&ioc
,
1151 if (!bcmerror
&& buf
&& ioc
.buf
) {
1152 if (copy_to_user(ioc
.buf
, buf
, buflen
))
1164 static int brcmf_netdev_stop(struct net_device
*net
)
1166 #if !defined(IGNORE_ETH0_DOWN)
1167 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
1169 BRCMF_TRACE(("%s: Enter\n", __func__
));
1170 brcmf_cfg80211_down();
1171 if (drvr_priv
->pub
.up
== 0)
1174 /* Set state and stop OS transmissions */
1175 drvr_priv
->pub
.up
= 0;
1176 netif_stop_queue(net
);
1178 BRCMF_ERROR(("BYPASS %s:due to BRCM compilation: under investigation\n",
1180 #endif /* !defined(IGNORE_ETH0_DOWN) */
1185 static int brcmf_netdev_open(struct net_device
*net
)
1187 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**) netdev_priv(net
);
1189 int ifidx
= brcmf_net2idx(drvr_priv
, net
);
1192 BRCMF_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
1194 if (ifidx
== 0) { /* do it only for primary eth0 */
1196 /* try to bring up bus */
1197 ret
= brcmf_bus_start(&drvr_priv
->pub
);
1199 BRCMF_ERROR(("%s: failed with code %d\n",
1203 atomic_set(&drvr_priv
->pend_8021x_cnt
, 0);
1205 memcpy(net
->dev_addr
, drvr_priv
->pub
.mac
, ETH_ALEN
);
1207 /* Get current TOE mode from dongle */
1208 if (brcmf_toe_get(drvr_priv
, ifidx
, &toe_ol
) >= 0
1209 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
1210 drvr_priv
->iflist
[ifidx
]->net
->features
|=
1213 drvr_priv
->iflist
[ifidx
]->net
->features
&=
1216 /* Allow transmit calls */
1217 netif_start_queue(net
);
1218 drvr_priv
->pub
.up
= 1;
1219 if (unlikely(brcmf_cfg80211_up())) {
1220 BRCMF_ERROR(("%s: failed to bring up cfg80211\n",
1229 brcmf_add_if(struct brcmf_info
*drvr_priv
, int ifidx
, void *handle
, char *name
,
1230 u8
*mac_addr
, u32 flags
, u8 bssidx
)
1232 struct brcmf_if
*ifp
;
1234 BRCMF_TRACE(("%s: idx %d, handle->%p\n", __func__
, ifidx
, handle
));
1236 ifp
= drvr_priv
->iflist
[ifidx
];
1238 ifp
= kmalloc(sizeof(struct brcmf_if
), GFP_ATOMIC
);
1240 BRCMF_ERROR(("%s: OOM - struct brcmf_if\n", __func__
));
1245 memset(ifp
, 0, sizeof(struct brcmf_if
));
1246 ifp
->info
= drvr_priv
;
1247 drvr_priv
->iflist
[ifidx
] = ifp
;
1248 strlcpy(ifp
->name
, name
, IFNAMSIZ
);
1249 if (mac_addr
!= NULL
)
1250 memcpy(&ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
1252 if (handle
== NULL
) {
1253 ifp
->state
= BRCMF_E_IF_ADD
;
1255 up(&drvr_priv
->sysioc_sem
);
1257 ifp
->net
= (struct net_device
*)handle
;
1262 void brcmf_del_if(struct brcmf_info
*drvr_priv
, int ifidx
)
1264 struct brcmf_if
*ifp
;
1266 BRCMF_TRACE(("%s: idx %d\n", __func__
, ifidx
));
1268 ifp
= drvr_priv
->iflist
[ifidx
];
1270 BRCMF_ERROR(("%s: Null interface\n", __func__
));
1274 ifp
->state
= BRCMF_E_IF_DEL
;
1276 up(&drvr_priv
->sysioc_sem
);
1279 struct brcmf_pub
*brcmf_attach(struct brcmf_bus
*bus
, uint bus_hdrlen
)
1281 struct brcmf_info
*drvr_priv
= NULL
;
1282 struct net_device
*net
;
1284 BRCMF_TRACE(("%s: Enter\n", __func__
));
1286 /* Allocate etherdev, including space for private structure */
1287 net
= alloc_etherdev(sizeof(drvr_priv
));
1289 BRCMF_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
1293 /* Allocate primary brcmf_info */
1294 drvr_priv
= kzalloc(sizeof(struct brcmf_info
), GFP_ATOMIC
);
1296 BRCMF_ERROR(("%s: OOM - alloc brcmf_info\n", __func__
));
1301 * Save the brcmf_info into the priv
1303 memcpy(netdev_priv(net
), &drvr_priv
, sizeof(drvr_priv
));
1305 /* Set network interface name if it was provided as module parameter */
1306 if (iface_name
[0]) {
1309 strncpy(net
->name
, iface_name
, IFNAMSIZ
);
1310 net
->name
[IFNAMSIZ
- 1] = 0;
1311 len
= strlen(net
->name
);
1312 ch
= net
->name
[len
- 1];
1313 if ((ch
> '9' || ch
< '0') && (len
< IFNAMSIZ
- 2))
1314 strcat(net
->name
, "%d");
1317 if (brcmf_add_if(drvr_priv
, 0, (void *)net
, net
->name
, NULL
, 0, 0) ==
1321 net
->netdev_ops
= NULL
;
1322 sema_init(&drvr_priv
->proto_sem
, 1);
1323 /* Initialize other structure content */
1324 init_waitqueue_head(&drvr_priv
->ioctl_resp_wait
);
1326 /* Link to info module */
1327 drvr_priv
->pub
.info
= drvr_priv
;
1329 /* Link to bus module */
1330 drvr_priv
->pub
.bus
= bus
;
1331 drvr_priv
->pub
.hdrlen
= bus_hdrlen
;
1333 /* Attach and link in the protocol */
1334 if (brcmf_proto_attach(&drvr_priv
->pub
) != 0) {
1335 BRCMF_ERROR(("brcmf_prot_attach failed\n"));
1339 /* Attach and link in the cfg80211 */
1340 if (unlikely(brcmf_cfg80211_attach(net
, &drvr_priv
->pub
))) {
1341 BRCMF_ERROR(("wl_cfg80211_attach failed\n"));
1346 sema_init(&drvr_priv
->sysioc_sem
, 0);
1347 drvr_priv
->sysioc_tsk
= kthread_run(_brcmf_sysioc_thread
, drvr_priv
,
1349 if (IS_ERR(drvr_priv
->sysioc_tsk
)) {
1351 "_brcmf_sysioc thread failed to start\n");
1352 drvr_priv
->sysioc_tsk
= NULL
;
1355 drvr_priv
->sysioc_tsk
= NULL
;
1358 * Save the brcmf_info into the priv
1360 memcpy(netdev_priv(net
), &drvr_priv
, sizeof(drvr_priv
));
1362 #if defined(CONFIG_PM_SLEEP)
1363 atomic_set(&brcmf_mmc_suspend
, false);
1364 #endif /* defined(CONFIG_PM_SLEEP) */
1365 return &drvr_priv
->pub
;
1371 brcmf_detach(&drvr_priv
->pub
);
1376 int brcmf_bus_start(struct brcmf_pub
*drvr
)
1379 struct brcmf_info
*drvr_priv
= drvr
->info
;
1380 /* Room for "event_msgs" + '\0' + bitvec */
1381 char iovbuf
[BRCMF_EVENTING_MASK_LEN
+ 12];
1383 BRCMF_TRACE(("%s:\n", __func__
));
1385 /* Bring up the bus */
1386 ret
= brcmf_sdbrcm_bus_init(&drvr_priv
->pub
, true);
1388 BRCMF_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__
,
1393 /* If bus is not ready, can't come up */
1394 if (drvr_priv
->pub
.busstate
!= BRCMF_BUS_DATA
) {
1395 BRCMF_ERROR(("%s failed bus is not ready\n", __func__
));
1399 brcmu_mkiovar("event_msgs", drvr
->eventmask
, BRCMF_EVENTING_MASK_LEN
,
1400 iovbuf
, sizeof(iovbuf
));
1401 brcmf_proto_cdc_query_ioctl(drvr
, 0, BRCMF_C_GET_VAR
, iovbuf
,
1403 memcpy(drvr
->eventmask
, iovbuf
, BRCMF_EVENTING_MASK_LEN
);
1405 setbit(drvr
->eventmask
, BRCMF_E_SET_SSID
);
1406 setbit(drvr
->eventmask
, BRCMF_E_PRUNE
);
1407 setbit(drvr
->eventmask
, BRCMF_E_AUTH
);
1408 setbit(drvr
->eventmask
, BRCMF_E_REASSOC
);
1409 setbit(drvr
->eventmask
, BRCMF_E_REASSOC_IND
);
1410 setbit(drvr
->eventmask
, BRCMF_E_DEAUTH_IND
);
1411 setbit(drvr
->eventmask
, BRCMF_E_DISASSOC_IND
);
1412 setbit(drvr
->eventmask
, BRCMF_E_DISASSOC
);
1413 setbit(drvr
->eventmask
, BRCMF_E_JOIN
);
1414 setbit(drvr
->eventmask
, BRCMF_E_ASSOC_IND
);
1415 setbit(drvr
->eventmask
, BRCMF_E_PSK_SUP
);
1416 setbit(drvr
->eventmask
, BRCMF_E_LINK
);
1417 setbit(drvr
->eventmask
, BRCMF_E_NDIS_LINK
);
1418 setbit(drvr
->eventmask
, BRCMF_E_MIC_ERROR
);
1419 setbit(drvr
->eventmask
, BRCMF_E_PMKID_CACHE
);
1420 setbit(drvr
->eventmask
, BRCMF_E_TXFAIL
);
1421 setbit(drvr
->eventmask
, BRCMF_E_JOIN_START
);
1422 setbit(drvr
->eventmask
, BRCMF_E_SCAN_COMPLETE
);
1424 /* enable dongle roaming event */
1426 drvr
->pktfilter_count
= 1;
1427 /* Setup filter to allow only unicast */
1428 drvr
->pktfilter
[0] = "100 0 0 0 0x01 0x00";
1430 /* Bus is ready, do any protocol initialization */
1431 ret
= brcmf_proto_init(&drvr_priv
->pub
);
1438 static struct net_device_ops brcmf_netdev_ops_pri
= {
1439 .ndo_open
= brcmf_netdev_open
,
1440 .ndo_stop
= brcmf_netdev_stop
,
1441 .ndo_get_stats
= brcmf_netdev_get_stats
,
1442 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
1443 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
1444 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
1445 .ndo_set_multicast_list
= brcmf_netdev_set_multicast_list
1448 int brcmf_net_attach(struct brcmf_pub
*drvr
, int ifidx
)
1450 struct brcmf_info
*drvr_priv
= drvr
->info
;
1451 struct net_device
*net
;
1452 u8 temp_addr
[ETH_ALEN
] = {
1453 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
1455 BRCMF_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
1457 net
= drvr_priv
->iflist
[ifidx
]->net
;
1458 net
->netdev_ops
= &brcmf_netdev_ops_pri
;
1461 * We have to use the primary MAC for virtual interfaces
1464 /* for virtual interfaces use the primary MAC */
1465 memcpy(temp_addr
, drvr_priv
->pub
.mac
, ETH_ALEN
);
1470 BRCMF_TRACE(("%s ACCESS POINT MAC:\n", __func__
));
1471 /* ACCESSPOINT INTERFACE CASE */
1472 temp_addr
[0] |= 0X02; /* set bit 2 ,
1473 - Locally Administered address */
1476 net
->hard_header_len
= ETH_HLEN
+ drvr_priv
->pub
.hdrlen
;
1477 net
->ethtool_ops
= &brcmf_ethtool_ops
;
1479 drvr_priv
->pub
.rxsz
= net
->mtu
+ net
->hard_header_len
+
1480 drvr_priv
->pub
.hdrlen
;
1482 memcpy(net
->dev_addr
, temp_addr
, ETH_ALEN
);
1484 if (register_netdev(net
) != 0) {
1485 BRCMF_ERROR(("%s: couldn't register the net device\n",
1490 BRCMF_INFO(("%s: Broadcom Dongle Host Driver\n", net
->name
));
1495 net
->netdev_ops
= NULL
;
1499 static void brcmf_bus_detach(struct brcmf_pub
*drvr
)
1501 struct brcmf_info
*drvr_priv
;
1503 BRCMF_TRACE(("%s: Enter\n", __func__
));
1506 drvr_priv
= drvr
->info
;
1508 /* Stop the protocol module */
1509 brcmf_proto_stop(&drvr_priv
->pub
);
1511 /* Stop the bus module */
1512 brcmf_sdbrcm_bus_stop(drvr_priv
->pub
.bus
, true);
1517 void brcmf_detach(struct brcmf_pub
*drvr
)
1519 struct brcmf_info
*drvr_priv
;
1521 BRCMF_TRACE(("%s: Enter\n", __func__
));
1524 drvr_priv
= drvr
->info
;
1526 struct brcmf_if
*ifp
;
1529 for (i
= 1; i
< BRCMF_MAX_IFS
; i
++)
1530 if (drvr_priv
->iflist
[i
])
1531 brcmf_del_if(drvr_priv
, i
);
1533 ifp
= drvr_priv
->iflist
[0];
1534 if (ifp
->net
->netdev_ops
== &brcmf_netdev_ops_pri
) {
1535 brcmf_netdev_stop(ifp
->net
);
1536 unregister_netdev(ifp
->net
);
1539 if (drvr_priv
->sysioc_tsk
) {
1540 send_sig(SIGTERM
, drvr_priv
->sysioc_tsk
, 1);
1541 kthread_stop(drvr_priv
->sysioc_tsk
);
1542 drvr_priv
->sysioc_tsk
= NULL
;
1545 brcmf_bus_detach(drvr
);
1548 brcmf_proto_detach(drvr
);
1550 brcmf_cfg80211_detach();
1552 free_netdev(ifp
->net
);
1559 static void __exit
brcmf_module_cleanup(void)
1561 BRCMF_TRACE(("%s: Enter\n", __func__
));
1563 brcmf_bus_unregister();
1566 static int __init
brcmf_module_init(void)
1570 BRCMF_TRACE(("%s: Enter\n", __func__
));
1572 error
= brcmf_bus_register();
1575 BRCMF_ERROR(("%s: brcmf_bus_register failed\n", __func__
));
1584 module_init(brcmf_module_init
);
1585 module_exit(brcmf_module_cleanup
);
1587 int brcmf_os_proto_block(struct brcmf_pub
*drvr
)
1589 struct brcmf_info
*drvr_priv
= drvr
->info
;
1592 down(&drvr_priv
->proto_sem
);
1598 int brcmf_os_proto_unblock(struct brcmf_pub
*drvr
)
1600 struct brcmf_info
*drvr_priv
= drvr
->info
;
1603 up(&drvr_priv
->proto_sem
);
1610 unsigned int brcmf_os_get_ioctl_resp_timeout(void)
1612 return (unsigned int)brcmf_ioctl_timeout_msec
;
1615 void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec
)
1617 brcmf_ioctl_timeout_msec
= (int)timeout_msec
;
1620 int brcmf_os_ioctl_resp_wait(struct brcmf_pub
*drvr
, uint
*condition
,
1623 struct brcmf_info
*drvr_priv
= drvr
->info
;
1624 DECLARE_WAITQUEUE(wait
, current
);
1625 int timeout
= brcmf_ioctl_timeout_msec
;
1627 /* Convert timeout in millsecond to jiffies */
1628 timeout
= timeout
* HZ
/ 1000;
1630 /* Wait until control frame is available */
1631 add_wait_queue(&drvr_priv
->ioctl_resp_wait
, &wait
);
1632 set_current_state(TASK_INTERRUPTIBLE
);
1634 while (!(*condition
) && (!signal_pending(current
) && timeout
))
1635 timeout
= schedule_timeout(timeout
);
1637 if (signal_pending(current
))
1640 set_current_state(TASK_RUNNING
);
1641 remove_wait_queue(&drvr_priv
->ioctl_resp_wait
, &wait
);
1646 int brcmf_os_ioctl_resp_wake(struct brcmf_pub
*drvr
)
1648 struct brcmf_info
*drvr_priv
= drvr
->info
;
1650 if (waitqueue_active(&drvr_priv
->ioctl_resp_wait
))
1651 wake_up_interruptible(&drvr_priv
->ioctl_resp_wait
);
1656 static int brcmf_host_event(struct brcmf_info
*drvr_priv
, int *ifidx
, void *pktdata
,
1657 struct brcmf_event_msg
*event
, void **data
)
1661 bcmerror
= brcmf_c_host_event(drvr_priv
, ifidx
, pktdata
, event
, data
);
1665 if (drvr_priv
->iflist
[*ifidx
]->net
)
1666 brcmf_cfg80211_event(drvr_priv
->iflist
[*ifidx
]->net
,
1672 int brcmf_netdev_reset(struct net_device
*dev
, u8 flag
)
1674 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**)netdev_priv(dev
);
1676 brcmf_bus_devreset(&drvr_priv
->pub
, flag
);
1681 static int brcmf_get_pend_8021x_cnt(struct brcmf_info
*drvr_priv
)
1683 return atomic_read(&drvr_priv
->pend_8021x_cnt
);
1686 #define MAX_WAIT_FOR_8021X_TX 10
1688 int brcmf_netdev_wait_pend8021x(struct net_device
*dev
)
1690 struct brcmf_info
*drvr_priv
= *(struct brcmf_info
**)netdev_priv(dev
);
1691 int timeout
= 10 * HZ
/ 1000;
1692 int ntimes
= MAX_WAIT_FOR_8021X_TX
;
1693 int pend
= brcmf_get_pend_8021x_cnt(drvr_priv
);
1695 while (ntimes
&& pend
) {
1697 set_current_state(TASK_INTERRUPTIBLE
);
1698 schedule_timeout(timeout
);
1699 set_current_state(TASK_RUNNING
);
1702 pend
= brcmf_get_pend_8021x_cnt(drvr_priv
);
1708 int brcmf_write_to_file(struct brcmf_pub
*drvr
, u8
*buf
, int size
)
1712 mm_segment_t old_fs
;
1715 /* change to KERNEL_DS address limit */
1719 /* open file to write */
1720 fp
= filp_open("/tmp/mem_dump", O_WRONLY
| O_CREAT
, 0640);
1722 BRCMF_ERROR(("%s: open file error\n", __func__
));
1727 /* Write buf to file */
1728 fp
->f_op
->write(fp
, buf
, size
, &pos
);
1731 /* free buf before return */
1733 /* close file before return */
1735 filp_close(fp
, current
->files
);
1736 /* restore previous address limit */
1744 void osl_assert(char *exp
, char *file
, int line
)
1749 basename
= strrchr(file
, '/');
1757 snprintf(tempbuf
, 256,
1758 "assertion \"%s\" failed: file \"%s\", line %d\n", exp
,
1762 * Print assert message and give it time to
1763 * be written to /var/log/messages
1765 if (!in_interrupt()) {
1766 const int delay
= 3;
1767 printk(KERN_ERR
"%s", tempbuf
);
1768 printk(KERN_ERR
"panic in %d seconds\n", delay
);
1769 set_current_state(TASK_INTERRUPTIBLE
);
1770 schedule_timeout(delay
* HZ
);
1773 switch (g_assert_type
) {
1775 panic(KERN_ERR
"%s", tempbuf
);
1778 printk(KERN_ERR
"%s", tempbuf
);
1782 printk(KERN_ERR
"%s", tempbuf
);
1788 #endif /* defined(BCMDBG) */