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 <linux/hardirq.h>
32 #include <linux/mutex.h>
33 #include <linux/wait.h>
34 #include <linux/module.h>
35 #include <net/cfg80211.h>
36 #include <net/rtnetlink.h>
38 #include <brcmu_utils.h>
39 #include <brcmu_wifi.h>
43 #include "dhd_proto.h"
45 #include "wl_cfg80211.h"
47 MODULE_AUTHOR("Broadcom Corporation");
48 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
49 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
50 MODULE_LICENSE("Dual BSD/GPL");
53 /* Interface control information */
55 struct brcmf_info
*info
; /* back pointer to brcmf_info */
56 /* OS/stack specifics */
57 struct net_device
*ndev
;
58 struct net_device_stats stats
;
59 int idx
; /* iface idx in dongle */
60 u8 mac_addr
[ETH_ALEN
]; /* assigned MAC address */
63 /* Local private structure (extension of pub) */
67 /* OS/stack specifics */
68 struct brcmf_if
*iflist
[BRCMF_MAX_IFS
];
70 struct mutex proto_block
;
72 struct work_struct setmacaddr_work
;
73 struct work_struct multicast_work
;
74 u8 macvalue
[ETH_ALEN
];
75 atomic_t pend_8021x_cnt
;
79 module_param(brcmf_msg_level
, int, 0);
81 int brcmf_ifname2idx(struct brcmf_info
*drvr_priv
, char *name
)
83 int i
= BRCMF_MAX_IFS
;
86 if (name
== NULL
|| *name
== '\0')
90 ifp
= drvr_priv
->iflist
[i
];
91 if (ifp
&& !strncmp(ifp
->ndev
->name
, name
, IFNAMSIZ
))
95 brcmf_dbg(TRACE
, "return idx %d for \"%s\"\n", i
, name
);
97 return i
; /* default - the primary interface */
100 char *brcmf_ifname(struct brcmf_pub
*drvr
, int ifidx
)
102 struct brcmf_info
*drvr_priv
= drvr
->info
;
104 if (ifidx
< 0 || ifidx
>= BRCMF_MAX_IFS
) {
105 brcmf_dbg(ERROR
, "ifidx %d out of range\n", ifidx
);
109 if (drvr_priv
->iflist
[ifidx
] == NULL
) {
110 brcmf_dbg(ERROR
, "null i/f %d\n", ifidx
);
114 if (drvr_priv
->iflist
[ifidx
]->ndev
)
115 return drvr_priv
->iflist
[ifidx
]->ndev
->name
;
120 static void _brcmf_set_multicast_list(struct work_struct
*work
)
122 struct net_device
*ndev
;
123 struct netdev_hw_addr
*ha
;
126 __le32 dcmd_le_value
;
128 struct brcmf_dcmd dcmd
;
133 struct brcmf_info
*drvr_priv
= container_of(work
, struct brcmf_info
,
136 ndev
= drvr_priv
->iflist
[0]->ndev
;
137 cnt
= netdev_mc_count(ndev
);
139 /* Determine initial value of allmulti flag */
140 dcmd_value
= (ndev
->flags
& IFF_ALLMULTI
) ? true : false;
142 /* Send down the multicast list first. */
144 buflen
= sizeof("mcast_list") + sizeof(cnt
) + (cnt
* ETH_ALEN
);
145 bufp
= buf
= kmalloc(buflen
, GFP_ATOMIC
);
149 strcpy(bufp
, "mcast_list");
150 bufp
+= strlen("mcast_list") + 1;
152 cnt_le
= cpu_to_le32(cnt
);
153 memcpy(bufp
, &cnt_le
, sizeof(cnt
));
154 bufp
+= sizeof(cnt_le
);
156 netdev_for_each_mc_addr(ha
, ndev
) {
159 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
164 memset(&dcmd
, 0, sizeof(dcmd
));
165 dcmd
.cmd
= BRCMF_C_SET_VAR
;
170 ret
= brcmf_proto_dcmd(&drvr_priv
->pub
, 0, &dcmd
, dcmd
.len
);
172 brcmf_dbg(ERROR
, "%s: set mcast_list failed, cnt %d\n",
173 brcmf_ifname(&drvr_priv
->pub
, 0), cnt
);
174 dcmd_value
= cnt
? true : dcmd_value
;
179 /* Now send the allmulti setting. This is based on the setting in the
180 * net_device flags, but might be modified above to be turned on if we
181 * were trying to set some addresses and dongle rejected it...
184 buflen
= sizeof("allmulti") + sizeof(dcmd_value
);
185 buf
= kmalloc(buflen
, GFP_ATOMIC
);
189 dcmd_le_value
= cpu_to_le32(dcmd_value
);
192 ("allmulti", (void *)&dcmd_le_value
,
193 sizeof(dcmd_le_value
), buf
, buflen
)) {
194 brcmf_dbg(ERROR
, "%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
195 brcmf_ifname(&drvr_priv
->pub
, 0),
196 (int)sizeof(dcmd_value
), buflen
);
201 memset(&dcmd
, 0, sizeof(dcmd
));
202 dcmd
.cmd
= BRCMF_C_SET_VAR
;
207 ret
= brcmf_proto_dcmd(&drvr_priv
->pub
, 0, &dcmd
, dcmd
.len
);
209 brcmf_dbg(ERROR
, "%s: set allmulti %d failed\n",
210 brcmf_ifname(&drvr_priv
->pub
, 0),
211 le32_to_cpu(dcmd_le_value
));
216 /* Finally, pick up the PROMISC flag as well, like the NIC
219 dcmd_value
= (ndev
->flags
& IFF_PROMISC
) ? true : false;
220 dcmd_le_value
= cpu_to_le32(dcmd_value
);
222 memset(&dcmd
, 0, sizeof(dcmd
));
223 dcmd
.cmd
= BRCMF_C_SET_PROMISC
;
224 dcmd
.buf
= &dcmd_le_value
;
225 dcmd
.len
= sizeof(dcmd_le_value
);
228 ret
= brcmf_proto_dcmd(&drvr_priv
->pub
, 0, &dcmd
, dcmd
.len
);
230 brcmf_dbg(ERROR
, "%s: set promisc %d failed\n",
231 brcmf_ifname(&drvr_priv
->pub
, 0),
232 le32_to_cpu(dcmd_le_value
));
237 _brcmf_set_mac_address(struct work_struct
*work
)
240 struct brcmf_dcmd dcmd
;
243 struct brcmf_info
*drvr_priv
= container_of(work
, struct brcmf_info
,
246 brcmf_dbg(TRACE
, "enter\n");
247 if (!brcmf_c_mkiovar("cur_etheraddr", (char *)drvr_priv
->macvalue
,
248 ETH_ALEN
, buf
, 32)) {
249 brcmf_dbg(ERROR
, "%s: mkiovar failed for cur_etheraddr\n",
250 brcmf_ifname(&drvr_priv
->pub
, 0));
253 memset(&dcmd
, 0, sizeof(dcmd
));
254 dcmd
.cmd
= BRCMF_C_SET_VAR
;
259 ret
= brcmf_proto_dcmd(&drvr_priv
->pub
, 0, &dcmd
, dcmd
.len
);
261 brcmf_dbg(ERROR
, "%s: set cur_etheraddr failed\n",
262 brcmf_ifname(&drvr_priv
->pub
, 0));
264 memcpy(drvr_priv
->iflist
[0]->ndev
->dev_addr
,
265 drvr_priv
->macvalue
, ETH_ALEN
);
270 static int brcmf_netdev_set_mac_address(struct net_device
*ndev
, void *addr
)
272 struct brcmf_if
*ifp
= netdev_priv(ndev
);
273 struct brcmf_info
*drvr_priv
= ifp
->info
;
274 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
276 memcpy(&drvr_priv
->macvalue
, sa
->sa_data
, ETH_ALEN
);
277 schedule_work(&drvr_priv
->setmacaddr_work
);
281 static void brcmf_netdev_set_multicast_list(struct net_device
*ndev
)
283 struct brcmf_if
*ifp
= netdev_priv(ndev
);
284 struct brcmf_info
*drvr_priv
= ifp
->info
;
286 schedule_work(&drvr_priv
->multicast_work
);
289 int brcmf_sendpkt(struct brcmf_pub
*drvr
, int ifidx
, struct sk_buff
*pktbuf
)
291 struct brcmf_info
*drvr_priv
= drvr
->info
;
294 if (!drvr
->up
|| (drvr
->busstate
== BRCMF_BUS_DOWN
))
297 /* Update multicast statistic */
298 if (pktbuf
->len
>= ETH_ALEN
) {
299 u8
*pktdata
= (u8
*) (pktbuf
->data
);
300 struct ethhdr
*eh
= (struct ethhdr
*)pktdata
;
302 if (is_multicast_ether_addr(eh
->h_dest
))
303 drvr
->tx_multicast
++;
304 if (ntohs(eh
->h_proto
) == ETH_P_PAE
)
305 atomic_inc(&drvr_priv
->pend_8021x_cnt
);
308 /* If the protocol uses a data header, apply it */
309 brcmf_proto_hdrpush(drvr
, ifidx
, pktbuf
);
311 /* Use bus module to send data frame */
312 return brcmf_sdbrcm_bus_txdata(drvr
->bus
, pktbuf
);
315 static int brcmf_netdev_start_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
318 struct brcmf_if
*ifp
= netdev_priv(ndev
);
319 struct brcmf_info
*drvr_priv
= ifp
->info
;
321 brcmf_dbg(TRACE
, "Enter\n");
324 if (!drvr_priv
->pub
.up
|| (drvr_priv
->pub
.busstate
== BRCMF_BUS_DOWN
)) {
325 brcmf_dbg(ERROR
, "xmit rejected pub.up=%d busstate=%d\n",
326 drvr_priv
->pub
.up
, drvr_priv
->pub
.busstate
);
327 netif_stop_queue(ndev
);
331 if (!drvr_priv
->iflist
[ifp
->idx
]) {
332 brcmf_dbg(ERROR
, "bad ifidx %d\n", ifp
->idx
);
333 netif_stop_queue(ndev
);
337 /* Make sure there's enough room for any header */
338 if (skb_headroom(skb
) < drvr_priv
->pub
.hdrlen
) {
339 struct sk_buff
*skb2
;
341 brcmf_dbg(INFO
, "%s: insufficient headroom\n",
342 brcmf_ifname(&drvr_priv
->pub
, ifp
->idx
));
343 drvr_priv
->pub
.tx_realloc
++;
344 skb2
= skb_realloc_headroom(skb
, drvr_priv
->pub
.hdrlen
);
348 brcmf_dbg(ERROR
, "%s: skb_realloc_headroom failed\n",
349 brcmf_ifname(&drvr_priv
->pub
, ifp
->idx
));
355 ret
= brcmf_sendpkt(&drvr_priv
->pub
, ifp
->idx
, skb
);
359 drvr_priv
->pub
.dstats
.tx_dropped
++;
361 drvr_priv
->pub
.tx_packets
++;
363 /* Return ok: we always eat the packet */
367 void brcmf_txflowcontrol(struct brcmf_pub
*drvr
, int ifidx
, bool state
)
369 struct net_device
*ndev
;
370 struct brcmf_info
*drvr_priv
= drvr
->info
;
372 brcmf_dbg(TRACE
, "Enter\n");
375 ndev
= drvr_priv
->iflist
[ifidx
]->ndev
;
377 netif_stop_queue(ndev
);
379 netif_wake_queue(ndev
);
382 static int brcmf_host_event(struct brcmf_info
*drvr_priv
, int *ifidx
,
383 void *pktdata
, struct brcmf_event_msg
*event
,
388 bcmerror
= brcmf_c_host_event(drvr_priv
, ifidx
, pktdata
, event
, data
);
392 if (drvr_priv
->iflist
[*ifidx
]->ndev
)
393 brcmf_cfg80211_event(drvr_priv
->iflist
[*ifidx
]->ndev
,
399 void brcmf_rx_frame(struct brcmf_pub
*drvr
, int ifidx
,
400 struct sk_buff_head
*skb_list
)
402 struct brcmf_info
*drvr_priv
= drvr
->info
;
406 struct sk_buff
*skb
, *pnext
;
407 struct brcmf_if
*ifp
;
408 struct brcmf_event_msg event
;
410 brcmf_dbg(TRACE
, "Enter\n");
412 skb_queue_walk_safe(skb_list
, skb
, pnext
) {
413 skb_unlink(skb
, skb_list
);
415 /* Get the protocol, maintain skb around eth_type_trans()
416 * The main reason for this hack is for the limitation of
417 * Linux 2.4 where 'eth_type_trans' uses the
418 * 'net->hard_header_len'
419 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
420 * coping of the packet coming from the network stack to add
421 * BDC, Hardware header etc, during network interface
423 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
425 * for BDC, Hardware header etc. and not just the ETH_HLEN
430 ifp
= drvr_priv
->iflist
[ifidx
];
432 ifp
= drvr_priv
->iflist
[0];
434 if (!ifp
|| !ifp
->ndev
||
435 ifp
->ndev
->reg_state
!= NETREG_REGISTERED
) {
436 brcmu_pkt_buf_free_skb(skb
);
440 skb
->dev
= ifp
->ndev
;
441 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
443 if (skb
->pkt_type
== PACKET_MULTICAST
)
444 drvr_priv
->pub
.rx_multicast
++;
449 /* Strip header, count, deliver upward */
450 skb_pull(skb
, ETH_HLEN
);
452 /* Process special event packets and then discard them */
453 if (ntohs(skb
->protocol
) == ETH_P_LINK_CTL
)
454 brcmf_host_event(drvr_priv
, &ifidx
,
458 if (drvr_priv
->iflist
[ifidx
]) {
459 ifp
= drvr_priv
->iflist
[ifidx
];
460 ifp
->ndev
->last_rx
= jiffies
;
463 drvr
->dstats
.rx_bytes
+= skb
->len
;
464 drvr
->rx_packets
++; /* Local count */
469 /* If the receive is not processed inside an ISR,
470 * the softirqd must be woken explicitly to service
471 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
472 * by netif_rx_ni(), but in earlier kernels, we need
479 void brcmf_txcomplete(struct brcmf_pub
*drvr
, struct sk_buff
*txp
, bool success
)
482 struct brcmf_info
*drvr_priv
= drvr
->info
;
486 brcmf_proto_hdrpull(drvr
, &ifidx
, txp
);
488 eh
= (struct ethhdr
*)(txp
->data
);
489 type
= ntohs(eh
->h_proto
);
491 if (type
== ETH_P_PAE
)
492 atomic_dec(&drvr_priv
->pend_8021x_cnt
);
496 static struct net_device_stats
*brcmf_netdev_get_stats(struct net_device
*ndev
)
498 struct brcmf_if
*ifp
= netdev_priv(ndev
);
499 struct brcmf_info
*drvr_priv
= ifp
->info
;
501 brcmf_dbg(TRACE
, "Enter\n");
503 if (drvr_priv
->pub
.up
)
504 /* Use the protocol to get dongle stats */
505 brcmf_proto_dstats(&drvr_priv
->pub
);
507 /* Copy dongle stats to net device stats */
508 ifp
->stats
.rx_packets
= drvr_priv
->pub
.dstats
.rx_packets
;
509 ifp
->stats
.tx_packets
= drvr_priv
->pub
.dstats
.tx_packets
;
510 ifp
->stats
.rx_bytes
= drvr_priv
->pub
.dstats
.rx_bytes
;
511 ifp
->stats
.tx_bytes
= drvr_priv
->pub
.dstats
.tx_bytes
;
512 ifp
->stats
.rx_errors
= drvr_priv
->pub
.dstats
.rx_errors
;
513 ifp
->stats
.tx_errors
= drvr_priv
->pub
.dstats
.tx_errors
;
514 ifp
->stats
.rx_dropped
= drvr_priv
->pub
.dstats
.rx_dropped
;
515 ifp
->stats
.tx_dropped
= drvr_priv
->pub
.dstats
.tx_dropped
;
516 ifp
->stats
.multicast
= drvr_priv
->pub
.dstats
.multicast
;
521 /* Retrieve current toe component enables, which are kept
522 as a bitmap in toe_ol iovar */
523 static int brcmf_toe_get(struct brcmf_info
*drvr_priv
, int ifidx
, u32
*toe_ol
)
525 struct brcmf_dcmd dcmd
;
530 memset(&dcmd
, 0, sizeof(dcmd
));
532 dcmd
.cmd
= BRCMF_C_GET_VAR
;
534 dcmd
.len
= (uint
) sizeof(buf
);
537 strcpy(buf
, "toe_ol");
538 ret
= brcmf_proto_dcmd(&drvr_priv
->pub
, ifidx
, &dcmd
, dcmd
.len
);
540 /* Check for older dongle image that doesn't support toe_ol */
542 brcmf_dbg(ERROR
, "%s: toe not supported by device\n",
543 brcmf_ifname(&drvr_priv
->pub
, ifidx
));
547 brcmf_dbg(INFO
, "%s: could not get toe_ol: ret=%d\n",
548 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
);
552 memcpy(&toe_le
, buf
, sizeof(u32
));
553 *toe_ol
= le32_to_cpu(toe_le
);
557 /* Set current toe component enables in toe_ol iovar,
558 and set toe global enable iovar */
559 static int brcmf_toe_set(struct brcmf_info
*drvr_priv
, int ifidx
, u32 toe_ol
)
561 struct brcmf_dcmd dcmd
;
564 __le32 toe_le
= cpu_to_le32(toe_ol
);
566 memset(&dcmd
, 0, sizeof(dcmd
));
568 dcmd
.cmd
= BRCMF_C_SET_VAR
;
570 dcmd
.len
= (uint
) sizeof(buf
);
573 /* Set toe_ol as requested */
574 strcpy(buf
, "toe_ol");
575 memcpy(&buf
[sizeof("toe_ol")], &toe_le
, sizeof(u32
));
577 ret
= brcmf_proto_dcmd(&drvr_priv
->pub
, ifidx
, &dcmd
, dcmd
.len
);
579 brcmf_dbg(ERROR
, "%s: could not set toe_ol: ret=%d\n",
580 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
);
584 /* Enable toe globally only if any components are enabled. */
585 toe_le
= cpu_to_le32(toe_ol
!= 0);
588 memcpy(&buf
[sizeof("toe")], &toe_le
, sizeof(u32
));
590 ret
= brcmf_proto_dcmd(&drvr_priv
->pub
, ifidx
, &dcmd
, dcmd
.len
);
592 brcmf_dbg(ERROR
, "%s: could not set toe: ret=%d\n",
593 brcmf_ifname(&drvr_priv
->pub
, ifidx
), ret
);
600 static void brcmf_ethtool_get_drvinfo(struct net_device
*ndev
,
601 struct ethtool_drvinfo
*info
)
603 struct brcmf_if
*ifp
= netdev_priv(ndev
);
604 struct brcmf_info
*drvr_priv
= ifp
->info
;
606 sprintf(info
->driver
, KBUILD_MODNAME
);
607 sprintf(info
->version
, "%lu", drvr_priv
->pub
.drv_version
);
608 sprintf(info
->bus_info
, "%s",
609 dev_name(brcmf_bus_get_device(drvr_priv
->pub
.bus
)));
612 static struct ethtool_ops brcmf_ethtool_ops
= {
613 .get_drvinfo
= brcmf_ethtool_get_drvinfo
616 static int brcmf_ethtool(struct brcmf_info
*drvr_priv
, void __user
*uaddr
)
618 struct ethtool_drvinfo info
;
619 char drvname
[sizeof(info
.driver
)];
621 struct ethtool_value edata
;
622 u32 toe_cmpnt
, csum_dir
;
625 brcmf_dbg(TRACE
, "Enter\n");
627 /* all ethtool calls start with a cmd word */
628 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
632 case ETHTOOL_GDRVINFO
:
633 /* Copy out any request driver name */
634 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
636 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
637 drvname
[sizeof(info
.driver
) - 1] = '\0';
639 /* clear struct for return */
640 memset(&info
, 0, sizeof(info
));
643 /* if requested, identify ourselves */
644 if (strcmp(drvname
, "?dhd") == 0) {
645 sprintf(info
.driver
, "dhd");
646 strcpy(info
.version
, BRCMF_VERSION_STR
);
649 /* otherwise, require dongle to be up */
650 else if (!drvr_priv
->pub
.up
) {
651 brcmf_dbg(ERROR
, "dongle is not up\n");
655 /* finally, report dongle driver type */
656 else if (drvr_priv
->pub
.iswl
)
657 sprintf(info
.driver
, "wl");
659 sprintf(info
.driver
, "xx");
661 sprintf(info
.version
, "%lu", drvr_priv
->pub
.drv_version
);
662 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
664 brcmf_dbg(CTL
, "given %*s, returning %s\n",
665 (int)sizeof(drvname
), drvname
, info
.driver
);
668 /* Get toe offload components from dongle */
669 case ETHTOOL_GRXCSUM
:
670 case ETHTOOL_GTXCSUM
:
671 ret
= brcmf_toe_get(drvr_priv
, 0, &toe_cmpnt
);
676 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
679 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
681 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
685 /* Set toe offload components in dongle */
686 case ETHTOOL_SRXCSUM
:
687 case ETHTOOL_STXCSUM
:
688 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
691 /* Read the current settings, update and write back */
692 ret
= brcmf_toe_get(drvr_priv
, 0, &toe_cmpnt
);
697 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
700 toe_cmpnt
|= csum_dir
;
702 toe_cmpnt
&= ~csum_dir
;
704 ret
= brcmf_toe_set(drvr_priv
, 0, toe_cmpnt
);
708 /* If setting TX checksum mode, tell Linux the new mode */
709 if (cmd
== ETHTOOL_STXCSUM
) {
711 drvr_priv
->iflist
[0]->ndev
->features
|=
714 drvr_priv
->iflist
[0]->ndev
->features
&=
727 static int brcmf_netdev_ioctl_entry(struct net_device
*ndev
, struct ifreq
*ifr
,
730 struct brcmf_if
*ifp
= netdev_priv(ndev
);
731 struct brcmf_info
*drvr_priv
= ifp
->info
;
733 brcmf_dbg(TRACE
, "ifidx %d, cmd 0x%04x\n", ifp
->idx
, cmd
);
735 if (!drvr_priv
->iflist
[ifp
->idx
])
738 if (cmd
== SIOCETHTOOL
)
739 return brcmf_ethtool(drvr_priv
, ifr
->ifr_data
);
744 /* called only from within this driver. Sends a command to the dongle. */
745 s32
brcmf_exec_dcmd(struct net_device
*ndev
, u32 cmd
, void *arg
, u32 len
)
747 struct brcmf_dcmd dcmd
;
751 struct brcmf_if
*ifp
= netdev_priv(ndev
);
752 struct brcmf_info
*drvr_priv
= ifp
->info
;
754 memset(&dcmd
, 0, sizeof(dcmd
));
759 if (dcmd
.buf
!= NULL
)
760 buflen
= min_t(uint
, dcmd
.len
, BRCMF_DCMD_MAXLEN
);
762 /* send to dongle (must be up, and wl) */
763 if ((drvr_priv
->pub
.busstate
!= BRCMF_BUS_DATA
)) {
764 brcmf_dbg(ERROR
, "DONGLE_DOWN\n");
769 if (!drvr_priv
->pub
.iswl
) {
775 * Intercept BRCMF_C_SET_KEY CMD - serialize M4 send and
776 * set key CMD to prevent M4 encryption.
778 is_set_key_cmd
= ((dcmd
.cmd
== BRCMF_C_SET_KEY
) ||
779 ((dcmd
.cmd
== BRCMF_C_SET_VAR
) &&
780 !(strncmp("wsec_key", dcmd
.buf
, 9))) ||
781 ((dcmd
.cmd
== BRCMF_C_SET_VAR
) &&
782 !(strncmp("bsscfg:wsec_key", dcmd
.buf
, 15))));
784 brcmf_netdev_wait_pend8021x(ndev
);
786 err
= brcmf_proto_dcmd(&drvr_priv
->pub
, ifp
->idx
, &dcmd
, buflen
);
795 static int brcmf_netdev_stop(struct net_device
*ndev
)
797 struct brcmf_if
*ifp
= netdev_priv(ndev
);
798 struct brcmf_pub
*drvr
= &ifp
->info
->pub
;
800 brcmf_dbg(TRACE
, "Enter\n");
801 brcmf_cfg80211_down(drvr
->config
);
805 /* Set state and stop OS transmissions */
807 netif_stop_queue(ndev
);
812 static int brcmf_netdev_open(struct net_device
*ndev
)
814 struct brcmf_if
*ifp
= netdev_priv(ndev
);
815 struct brcmf_info
*drvr_priv
= ifp
->info
;
819 brcmf_dbg(TRACE
, "ifidx %d\n", ifp
->idx
);
821 if (ifp
->idx
== 0) { /* do it only for primary eth0 */
822 /* try to bring up bus */
823 ret
= brcmf_bus_start(&drvr_priv
->pub
);
825 brcmf_dbg(ERROR
, "failed with code %d\n", ret
);
828 atomic_set(&drvr_priv
->pend_8021x_cnt
, 0);
830 memcpy(ndev
->dev_addr
, drvr_priv
->pub
.mac
, ETH_ALEN
);
832 /* Get current TOE mode from dongle */
833 if (brcmf_toe_get(drvr_priv
, ifp
->idx
, &toe_ol
) >= 0
834 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
835 drvr_priv
->iflist
[ifp
->idx
]->ndev
->features
|=
838 drvr_priv
->iflist
[ifp
->idx
]->ndev
->features
&=
841 /* Allow transmit calls */
842 netif_start_queue(ndev
);
843 drvr_priv
->pub
.up
= 1;
844 if (brcmf_cfg80211_up(drvr_priv
->pub
.config
)) {
845 brcmf_dbg(ERROR
, "failed to bring up cfg80211\n");
852 static const struct net_device_ops brcmf_netdev_ops_pri
= {
853 .ndo_open
= brcmf_netdev_open
,
854 .ndo_stop
= brcmf_netdev_stop
,
855 .ndo_get_stats
= brcmf_netdev_get_stats
,
856 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
857 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
858 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
859 .ndo_set_rx_mode
= brcmf_netdev_set_multicast_list
863 brcmf_add_if(struct brcmf_info
*drvr_priv
, int ifidx
, char *name
, u8
*mac_addr
)
865 struct brcmf_if
*ifp
;
866 struct net_device
*ndev
;
868 brcmf_dbg(TRACE
, "idx %d\n", ifidx
);
870 ifp
= drvr_priv
->iflist
[ifidx
];
872 * Delete the existing interface before overwriting it
873 * in case we missed the BRCMF_E_IF_DEL event.
876 brcmf_dbg(ERROR
, "ERROR: netdev:%s already exists, try free & unregister\n",
878 netif_stop_queue(ifp
->ndev
);
879 unregister_netdev(ifp
->ndev
);
880 free_netdev(ifp
->ndev
);
881 drvr_priv
->iflist
[ifidx
] = NULL
;
884 /* Allocate netdev, including space for private structure */
885 ndev
= alloc_netdev(sizeof(struct brcmf_if
), name
, ether_setup
);
887 brcmf_dbg(ERROR
, "OOM - alloc_netdev\n");
891 ifp
= netdev_priv(ndev
);
893 ifp
->info
= drvr_priv
;
894 drvr_priv
->iflist
[ifidx
] = ifp
;
896 if (mac_addr
!= NULL
)
897 memcpy(&ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
899 if (brcmf_net_attach(&drvr_priv
->pub
, ifp
->idx
)) {
900 brcmf_dbg(ERROR
, "brcmf_net_attach failed");
901 free_netdev(ifp
->ndev
);
902 drvr_priv
->iflist
[ifidx
] = NULL
;
906 brcmf_dbg(TRACE
, " ==== pid:%x, net_device for if:%s created ===\n",
907 current
->pid
, ifp
->ndev
->name
);
912 void brcmf_del_if(struct brcmf_info
*drvr_priv
, int ifidx
)
914 struct brcmf_if
*ifp
;
916 brcmf_dbg(TRACE
, "idx %d\n", ifidx
);
918 ifp
= drvr_priv
->iflist
[ifidx
];
920 brcmf_dbg(ERROR
, "Null interface\n");
925 if (ifp
->ndev
->netdev_ops
== &brcmf_netdev_ops_pri
) {
927 brcmf_netdev_stop(ifp
->ndev
);
931 netif_stop_queue(ifp
->ndev
);
934 unregister_netdev(ifp
->ndev
);
935 drvr_priv
->iflist
[ifidx
] = NULL
;
937 brcmf_cfg80211_detach(drvr_priv
->pub
.config
);
938 free_netdev(ifp
->ndev
);
942 struct brcmf_pub
*brcmf_attach(struct brcmf_bus
*bus
, uint bus_hdrlen
)
944 struct brcmf_info
*drvr_priv
= NULL
;
946 brcmf_dbg(TRACE
, "Enter\n");
948 /* Allocate primary brcmf_info */
949 drvr_priv
= kzalloc(sizeof(struct brcmf_info
), GFP_ATOMIC
);
953 mutex_init(&drvr_priv
->proto_block
);
955 /* Link to info module */
956 drvr_priv
->pub
.info
= drvr_priv
;
958 /* Link to bus module */
959 drvr_priv
->pub
.bus
= bus
;
960 drvr_priv
->pub
.hdrlen
= bus_hdrlen
;
962 /* Attach and link in the protocol */
963 if (brcmf_proto_attach(&drvr_priv
->pub
) != 0) {
964 brcmf_dbg(ERROR
, "brcmf_prot_attach failed\n");
968 INIT_WORK(&drvr_priv
->setmacaddr_work
, _brcmf_set_mac_address
);
969 INIT_WORK(&drvr_priv
->multicast_work
, _brcmf_set_multicast_list
);
971 return &drvr_priv
->pub
;
975 brcmf_detach(&drvr_priv
->pub
);
980 int brcmf_bus_start(struct brcmf_pub
*drvr
)
983 struct brcmf_info
*drvr_priv
= drvr
->info
;
984 /* Room for "event_msgs" + '\0' + bitvec */
985 char iovbuf
[BRCMF_EVENTING_MASK_LEN
+ 12];
987 brcmf_dbg(TRACE
, "\n");
989 /* Bring up the bus */
990 ret
= brcmf_sdbrcm_bus_init(&drvr_priv
->pub
);
992 brcmf_dbg(ERROR
, "brcmf_sdbrcm_bus_init failed %d\n", ret
);
996 /* If bus is not ready, can't come up */
997 if (drvr_priv
->pub
.busstate
!= BRCMF_BUS_DATA
) {
998 brcmf_dbg(ERROR
, "failed bus is not ready\n");
1002 brcmf_c_mkiovar("event_msgs", drvr
->eventmask
, BRCMF_EVENTING_MASK_LEN
,
1003 iovbuf
, sizeof(iovbuf
));
1004 brcmf_proto_cdc_query_dcmd(drvr
, 0, BRCMF_C_GET_VAR
, iovbuf
,
1006 memcpy(drvr
->eventmask
, iovbuf
, BRCMF_EVENTING_MASK_LEN
);
1008 setbit(drvr
->eventmask
, BRCMF_E_SET_SSID
);
1009 setbit(drvr
->eventmask
, BRCMF_E_PRUNE
);
1010 setbit(drvr
->eventmask
, BRCMF_E_AUTH
);
1011 setbit(drvr
->eventmask
, BRCMF_E_REASSOC
);
1012 setbit(drvr
->eventmask
, BRCMF_E_REASSOC_IND
);
1013 setbit(drvr
->eventmask
, BRCMF_E_DEAUTH_IND
);
1014 setbit(drvr
->eventmask
, BRCMF_E_DISASSOC_IND
);
1015 setbit(drvr
->eventmask
, BRCMF_E_DISASSOC
);
1016 setbit(drvr
->eventmask
, BRCMF_E_JOIN
);
1017 setbit(drvr
->eventmask
, BRCMF_E_ASSOC_IND
);
1018 setbit(drvr
->eventmask
, BRCMF_E_PSK_SUP
);
1019 setbit(drvr
->eventmask
, BRCMF_E_LINK
);
1020 setbit(drvr
->eventmask
, BRCMF_E_NDIS_LINK
);
1021 setbit(drvr
->eventmask
, BRCMF_E_MIC_ERROR
);
1022 setbit(drvr
->eventmask
, BRCMF_E_PMKID_CACHE
);
1023 setbit(drvr
->eventmask
, BRCMF_E_TXFAIL
);
1024 setbit(drvr
->eventmask
, BRCMF_E_JOIN_START
);
1025 setbit(drvr
->eventmask
, BRCMF_E_SCAN_COMPLETE
);
1027 /* enable dongle roaming event */
1029 drvr
->pktfilter_count
= 1;
1030 /* Setup filter to allow only unicast */
1031 drvr
->pktfilter
[0] = "100 0 0 0 0x01 0x00";
1033 /* Bus is ready, do any protocol initialization */
1034 ret
= brcmf_proto_init(&drvr_priv
->pub
);
1041 int brcmf_net_attach(struct brcmf_pub
*drvr
, int ifidx
)
1043 struct brcmf_info
*drvr_priv
= drvr
->info
;
1044 struct net_device
*ndev
;
1045 u8 temp_addr
[ETH_ALEN
] = {
1046 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
1048 brcmf_dbg(TRACE
, "ifidx %d\n", ifidx
);
1050 ndev
= drvr_priv
->iflist
[ifidx
]->ndev
;
1051 ndev
->netdev_ops
= &brcmf_netdev_ops_pri
;
1054 * We have to use the primary MAC for virtual interfaces
1057 /* for virtual interfaces use the primary MAC */
1058 memcpy(temp_addr
, drvr_priv
->pub
.mac
, ETH_ALEN
);
1063 brcmf_dbg(TRACE
, "ACCESS POINT MAC:\n");
1064 /* ACCESSPOINT INTERFACE CASE */
1065 temp_addr
[0] |= 0X02; /* set bit 2 ,
1066 - Locally Administered address */
1069 ndev
->hard_header_len
= ETH_HLEN
+ drvr_priv
->pub
.hdrlen
;
1070 ndev
->ethtool_ops
= &brcmf_ethtool_ops
;
1072 drvr_priv
->pub
.rxsz
= ndev
->mtu
+ ndev
->hard_header_len
+
1073 drvr_priv
->pub
.hdrlen
;
1075 memcpy(ndev
->dev_addr
, temp_addr
, ETH_ALEN
);
1077 /* attach to cfg80211 for primary interface */
1080 brcmf_cfg80211_attach(ndev
,
1081 brcmf_bus_get_device(drvr
->bus
),
1083 if (drvr
->config
== NULL
) {
1084 brcmf_dbg(ERROR
, "wl_cfg80211_attach failed\n");
1089 if (register_netdev(ndev
) != 0) {
1090 brcmf_dbg(ERROR
, "couldn't register the net device\n");
1094 brcmf_dbg(INFO
, "%s: Broadcom Dongle Host Driver\n", ndev
->name
);
1099 ndev
->netdev_ops
= NULL
;
1103 static void brcmf_bus_detach(struct brcmf_pub
*drvr
)
1105 struct brcmf_info
*drvr_priv
;
1107 brcmf_dbg(TRACE
, "Enter\n");
1110 drvr_priv
= drvr
->info
;
1112 /* Stop the protocol module */
1113 brcmf_proto_stop(&drvr_priv
->pub
);
1115 /* Stop the bus module */
1116 brcmf_sdbrcm_bus_stop(drvr_priv
->pub
.bus
);
1121 void brcmf_detach(struct brcmf_pub
*drvr
)
1123 struct brcmf_info
*drvr_priv
;
1125 brcmf_dbg(TRACE
, "Enter\n");
1128 drvr_priv
= drvr
->info
;
1132 /* make sure primary interface removed last */
1133 for (i
= BRCMF_MAX_IFS
-1; i
> -1; i
--)
1134 if (drvr_priv
->iflist
[i
])
1135 brcmf_del_if(drvr_priv
, i
);
1137 cancel_work_sync(&drvr_priv
->setmacaddr_work
);
1138 cancel_work_sync(&drvr_priv
->multicast_work
);
1140 brcmf_bus_detach(drvr
);
1143 brcmf_proto_detach(drvr
);
1150 int brcmf_os_proto_block(struct brcmf_pub
*drvr
)
1152 struct brcmf_info
*drvr_priv
= drvr
->info
;
1155 mutex_lock(&drvr_priv
->proto_block
);
1161 int brcmf_os_proto_unblock(struct brcmf_pub
*drvr
)
1163 struct brcmf_info
*drvr_priv
= drvr
->info
;
1166 mutex_unlock(&drvr_priv
->proto_block
);
1173 static int brcmf_get_pend_8021x_cnt(struct brcmf_info
*drvr_priv
)
1175 return atomic_read(&drvr_priv
->pend_8021x_cnt
);
1178 #define MAX_WAIT_FOR_8021X_TX 10
1180 int brcmf_netdev_wait_pend8021x(struct net_device
*ndev
)
1182 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1183 struct brcmf_info
*drvr_priv
= ifp
->info
;
1184 int timeout
= 10 * HZ
/ 1000;
1185 int ntimes
= MAX_WAIT_FOR_8021X_TX
;
1186 int pend
= brcmf_get_pend_8021x_cnt(drvr_priv
);
1188 while (ntimes
&& pend
) {
1190 set_current_state(TASK_INTERRUPTIBLE
);
1191 schedule_timeout(timeout
);
1192 set_current_state(TASK_RUNNING
);
1195 pend
= brcmf_get_pend_8021x_cnt(drvr_priv
);
1201 int brcmf_write_to_file(struct brcmf_pub
*drvr
, const u8
*buf
, int size
)
1205 mm_segment_t old_fs
;
1208 /* change to KERNEL_DS address limit */
1212 /* open file to write */
1213 fp
= filp_open("/tmp/mem_dump", O_WRONLY
| O_CREAT
, 0640);
1215 brcmf_dbg(ERROR
, "open file error\n");
1220 /* Write buf to file */
1221 fp
->f_op
->write(fp
, (char __user
*)buf
, size
, &pos
);
1224 /* free buf before return */
1226 /* close file before return */
1228 filp_close(fp
, current
->files
);
1229 /* restore previous address limit */