2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/kernel.h>
18 #include <linux/etherdevice.h>
19 #include <linux/module.h>
20 #include <net/cfg80211.h>
21 #include <net/rtnetlink.h>
22 #include <brcmu_utils.h>
23 #include <brcmu_wifi.h>
27 #include "dhd_proto.h"
29 #include "fwil_types.h"
31 #include "wl_cfg80211.h"
35 MODULE_AUTHOR("Broadcom Corporation");
36 MODULE_DESCRIPTION("Broadcom 802.11 wireless LAN fullmac driver.");
37 MODULE_LICENSE("Dual BSD/GPL");
39 #define MAX_WAIT_FOR_8021X_TX 50 /* msecs */
41 /* AMPDU rx reordering definitions */
42 #define BRCMF_RXREORDER_FLOWID_OFFSET 0
43 #define BRCMF_RXREORDER_MAXIDX_OFFSET 2
44 #define BRCMF_RXREORDER_FLAGS_OFFSET 4
45 #define BRCMF_RXREORDER_CURIDX_OFFSET 6
46 #define BRCMF_RXREORDER_EXPIDX_OFFSET 8
48 #define BRCMF_RXREORDER_DEL_FLOW 0x01
49 #define BRCMF_RXREORDER_FLUSH_ALL 0x02
50 #define BRCMF_RXREORDER_CURIDX_VALID 0x04
51 #define BRCMF_RXREORDER_EXPIDX_VALID 0x08
52 #define BRCMF_RXREORDER_NEW_HOLE 0x10
56 module_param_named(debug
, brcmf_msg_level
, int, S_IRUSR
| S_IWUSR
);
57 MODULE_PARM_DESC(debug
, "level of debug output");
60 static int brcmf_p2p_enable
;
62 module_param_named(p2pon
, brcmf_p2p_enable
, int, 0);
63 MODULE_PARM_DESC(p2pon
, "enable p2p management functionality");
66 char *brcmf_ifname(struct brcmf_pub
*drvr
, int ifidx
)
68 if (ifidx
< 0 || ifidx
>= BRCMF_MAX_IFS
) {
69 brcmf_err("ifidx %d out of range\n", ifidx
);
73 if (drvr
->iflist
[ifidx
] == NULL
) {
74 brcmf_err("null i/f %d\n", ifidx
);
78 if (drvr
->iflist
[ifidx
]->ndev
)
79 return drvr
->iflist
[ifidx
]->ndev
->name
;
84 static void _brcmf_set_multicast_list(struct work_struct
*work
)
87 struct net_device
*ndev
;
88 struct netdev_hw_addr
*ha
;
95 ifp
= container_of(work
, struct brcmf_if
, multicast_work
);
97 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
101 /* Determine initial value of allmulti flag */
102 cmd_value
= (ndev
->flags
& IFF_ALLMULTI
) ? true : false;
104 /* Send down the multicast list first. */
105 cnt
= netdev_mc_count(ndev
);
106 buflen
= sizeof(cnt
) + (cnt
* ETH_ALEN
);
107 buf
= kmalloc(buflen
, GFP_ATOMIC
);
112 cnt_le
= cpu_to_le32(cnt
);
113 memcpy(bufp
, &cnt_le
, sizeof(cnt_le
));
114 bufp
+= sizeof(cnt_le
);
116 netdev_for_each_mc_addr(ha
, ndev
) {
119 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
124 err
= brcmf_fil_iovar_data_set(ifp
, "mcast_list", buf
, buflen
);
126 brcmf_err("Setting mcast_list failed, %d\n", err
);
127 cmd_value
= cnt
? true : cmd_value
;
133 * Now send the allmulti setting. This is based on the setting in the
134 * net_device flags, but might be modified above to be turned on if we
135 * were trying to set some addresses and dongle rejected it...
137 err
= brcmf_fil_iovar_int_set(ifp
, "allmulti", cmd_value
);
139 brcmf_err("Setting allmulti failed, %d\n", err
);
141 /*Finally, pick up the PROMISC flag */
142 cmd_value
= (ndev
->flags
& IFF_PROMISC
) ? true : false;
143 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_PROMISC
, cmd_value
);
145 brcmf_err("Setting BRCMF_C_SET_PROMISC failed, %d\n",
150 _brcmf_set_mac_address(struct work_struct
*work
)
152 struct brcmf_if
*ifp
;
155 ifp
= container_of(work
, struct brcmf_if
, setmacaddr_work
);
157 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
159 err
= brcmf_fil_iovar_data_set(ifp
, "cur_etheraddr", ifp
->mac_addr
,
162 brcmf_err("Setting cur_etheraddr failed, %d\n", err
);
164 brcmf_dbg(TRACE
, "MAC address updated to %pM\n",
166 memcpy(ifp
->ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
170 static int brcmf_netdev_set_mac_address(struct net_device
*ndev
, void *addr
)
172 struct brcmf_if
*ifp
= netdev_priv(ndev
);
173 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
175 memcpy(&ifp
->mac_addr
, sa
->sa_data
, ETH_ALEN
);
176 schedule_work(&ifp
->setmacaddr_work
);
180 static void brcmf_netdev_set_multicast_list(struct net_device
*ndev
)
182 struct brcmf_if
*ifp
= netdev_priv(ndev
);
184 schedule_work(&ifp
->multicast_work
);
187 static netdev_tx_t
brcmf_netdev_start_xmit(struct sk_buff
*skb
,
188 struct net_device
*ndev
)
191 struct brcmf_if
*ifp
= netdev_priv(ndev
);
192 struct brcmf_pub
*drvr
= ifp
->drvr
;
195 brcmf_dbg(DATA
, "Enter, idx=%d\n", ifp
->bssidx
);
197 /* Can the device send data? */
198 if (drvr
->bus_if
->state
!= BRCMF_BUS_DATA
) {
199 brcmf_err("xmit rejected state=%d\n", drvr
->bus_if
->state
);
200 netif_stop_queue(ndev
);
206 if (!drvr
->iflist
[ifp
->bssidx
]) {
207 brcmf_err("bad ifidx %d\n", ifp
->bssidx
);
208 netif_stop_queue(ndev
);
214 /* Make sure there's enough room for any header */
215 if (skb_headroom(skb
) < drvr
->hdrlen
) {
216 struct sk_buff
*skb2
;
218 brcmf_dbg(INFO
, "%s: insufficient headroom\n",
219 brcmf_ifname(drvr
, ifp
->bssidx
));
220 drvr
->bus_if
->tx_realloc
++;
221 skb2
= skb_realloc_headroom(skb
, drvr
->hdrlen
);
225 brcmf_err("%s: skb_realloc_headroom failed\n",
226 brcmf_ifname(drvr
, ifp
->bssidx
));
232 /* validate length for ether packet */
233 if (skb
->len
< sizeof(*eh
)) {
239 ret
= brcmf_fws_process_skb(ifp
, skb
);
243 ifp
->stats
.tx_dropped
++;
245 ifp
->stats
.tx_packets
++;
246 ifp
->stats
.tx_bytes
+= skb
->len
;
249 /* Return ok: we always eat the packet */
253 void brcmf_txflowblock_if(struct brcmf_if
*ifp
,
254 enum brcmf_netif_stop_reason reason
, bool state
)
258 if (!ifp
|| !ifp
->ndev
)
261 brcmf_dbg(TRACE
, "enter: idx=%d stop=0x%X reason=%d state=%d\n",
262 ifp
->bssidx
, ifp
->netif_stop
, reason
, state
);
264 spin_lock_irqsave(&ifp
->netif_stop_lock
, flags
);
266 if (!ifp
->netif_stop
)
267 netif_stop_queue(ifp
->ndev
);
268 ifp
->netif_stop
|= reason
;
270 ifp
->netif_stop
&= ~reason
;
271 if (!ifp
->netif_stop
)
272 netif_wake_queue(ifp
->ndev
);
274 spin_unlock_irqrestore(&ifp
->netif_stop_lock
, flags
);
277 void brcmf_txflowblock(struct device
*dev
, bool state
)
279 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
280 struct brcmf_pub
*drvr
= bus_if
->drvr
;
282 brcmf_dbg(TRACE
, "Enter\n");
284 brcmf_fws_bus_blocked(drvr
, state
);
287 static void brcmf_netif_rx(struct brcmf_if
*ifp
, struct sk_buff
*skb
)
289 skb
->dev
= ifp
->ndev
;
290 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
292 if (skb
->pkt_type
== PACKET_MULTICAST
)
293 ifp
->stats
.multicast
++;
295 /* Process special event packets */
296 brcmf_fweh_process_skb(ifp
->drvr
, skb
);
298 if (!(ifp
->ndev
->flags
& IFF_UP
)) {
299 brcmu_pkt_buf_free_skb(skb
);
303 ifp
->stats
.rx_bytes
+= skb
->len
;
304 ifp
->stats
.rx_packets
++;
306 brcmf_dbg(DATA
, "rx proto=0x%X\n", ntohs(skb
->protocol
));
310 /* If the receive is not processed inside an ISR,
311 * the softirqd must be woken explicitly to service
312 * the NET_RX_SOFTIRQ. This is handled by netif_rx_ni().
317 static void brcmf_rxreorder_get_skb_list(struct brcmf_ampdu_rx_reorder
*rfi
,
319 struct sk_buff_head
*skb_list
)
321 /* initialize return list */
322 __skb_queue_head_init(skb_list
);
324 if (rfi
->pend_pkts
== 0) {
325 brcmf_dbg(INFO
, "no packets in reorder queue\n");
330 if (rfi
->pktslots
[start
]) {
331 __skb_queue_tail(skb_list
, rfi
->pktslots
[start
]);
332 rfi
->pktslots
[start
] = NULL
;
335 if (start
> rfi
->max_idx
)
337 } while (start
!= end
);
338 rfi
->pend_pkts
-= skb_queue_len(skb_list
);
341 static void brcmf_rxreorder_process_info(struct brcmf_if
*ifp
, u8
*reorder_data
,
344 u8 flow_id
, max_idx
, cur_idx
, exp_idx
, end_idx
;
345 struct brcmf_ampdu_rx_reorder
*rfi
;
346 struct sk_buff_head reorder_list
;
347 struct sk_buff
*pnext
;
351 flow_id
= reorder_data
[BRCMF_RXREORDER_FLOWID_OFFSET
];
352 flags
= reorder_data
[BRCMF_RXREORDER_FLAGS_OFFSET
];
354 /* validate flags and flow id */
356 brcmf_err("invalid flags...so ignore this packet\n");
357 brcmf_netif_rx(ifp
, pkt
);
361 rfi
= ifp
->drvr
->reorder_flows
[flow_id
];
362 if (flags
& BRCMF_RXREORDER_DEL_FLOW
) {
363 brcmf_dbg(INFO
, "flow-%d: delete\n",
367 brcmf_dbg(INFO
, "received flags to cleanup, but no flow (%d) yet\n",
369 brcmf_netif_rx(ifp
, pkt
);
373 brcmf_rxreorder_get_skb_list(rfi
, rfi
->exp_idx
, rfi
->exp_idx
,
375 /* add the last packet */
376 __skb_queue_tail(&reorder_list
, pkt
);
378 ifp
->drvr
->reorder_flows
[flow_id
] = NULL
;
381 /* from here on we need a flow reorder instance */
383 buf_size
= sizeof(*rfi
);
384 max_idx
= reorder_data
[BRCMF_RXREORDER_MAXIDX_OFFSET
];
386 buf_size
+= (max_idx
+ 1) * sizeof(pkt
);
388 /* allocate space for flow reorder info */
389 brcmf_dbg(INFO
, "flow-%d: start, maxidx %d\n",
391 rfi
= kzalloc(buf_size
, GFP_ATOMIC
);
393 brcmf_err("failed to alloc buffer\n");
394 brcmf_netif_rx(ifp
, pkt
);
398 ifp
->drvr
->reorder_flows
[flow_id
] = rfi
;
399 rfi
->pktslots
= (struct sk_buff
**)(rfi
+1);
400 rfi
->max_idx
= max_idx
;
402 if (flags
& BRCMF_RXREORDER_NEW_HOLE
) {
403 if (rfi
->pend_pkts
) {
404 brcmf_rxreorder_get_skb_list(rfi
, rfi
->exp_idx
,
407 WARN_ON(rfi
->pend_pkts
);
409 __skb_queue_head_init(&reorder_list
);
411 rfi
->cur_idx
= reorder_data
[BRCMF_RXREORDER_CURIDX_OFFSET
];
412 rfi
->exp_idx
= reorder_data
[BRCMF_RXREORDER_EXPIDX_OFFSET
];
413 rfi
->max_idx
= reorder_data
[BRCMF_RXREORDER_MAXIDX_OFFSET
];
414 rfi
->pktslots
[rfi
->cur_idx
] = pkt
;
416 brcmf_dbg(DATA
, "flow-%d: new hole %d (%d), pending %d\n",
417 flow_id
, rfi
->cur_idx
, rfi
->exp_idx
, rfi
->pend_pkts
);
418 } else if (flags
& BRCMF_RXREORDER_CURIDX_VALID
) {
419 cur_idx
= reorder_data
[BRCMF_RXREORDER_CURIDX_OFFSET
];
420 exp_idx
= reorder_data
[BRCMF_RXREORDER_EXPIDX_OFFSET
];
422 if ((exp_idx
== rfi
->exp_idx
) && (cur_idx
!= rfi
->exp_idx
)) {
423 /* still in the current hole */
424 /* enqueue the current on the buffer chain */
425 if (rfi
->pktslots
[cur_idx
] != NULL
) {
426 brcmf_dbg(INFO
, "HOLE: ERROR buffer pending..free it\n");
427 brcmu_pkt_buf_free_skb(rfi
->pktslots
[cur_idx
]);
428 rfi
->pktslots
[cur_idx
] = NULL
;
430 rfi
->pktslots
[cur_idx
] = pkt
;
432 rfi
->cur_idx
= cur_idx
;
433 brcmf_dbg(DATA
, "flow-%d: store pkt %d (%d), pending %d\n",
434 flow_id
, cur_idx
, exp_idx
, rfi
->pend_pkts
);
436 /* can return now as there is no reorder
441 if (rfi
->exp_idx
== cur_idx
) {
442 if (rfi
->pktslots
[cur_idx
] != NULL
) {
443 brcmf_dbg(INFO
, "error buffer pending..free it\n");
444 brcmu_pkt_buf_free_skb(rfi
->pktslots
[cur_idx
]);
445 rfi
->pktslots
[cur_idx
] = NULL
;
447 rfi
->pktslots
[cur_idx
] = pkt
;
450 /* got the expected one. flush from current to expected
451 * and update expected
453 brcmf_dbg(DATA
, "flow-%d: expected %d (%d), pending %d\n",
454 flow_id
, cur_idx
, exp_idx
, rfi
->pend_pkts
);
456 rfi
->cur_idx
= cur_idx
;
457 rfi
->exp_idx
= exp_idx
;
459 brcmf_rxreorder_get_skb_list(rfi
, cur_idx
, exp_idx
,
461 brcmf_dbg(DATA
, "flow-%d: freeing buffers %d, pending %d\n",
462 flow_id
, skb_queue_len(&reorder_list
),
467 brcmf_dbg(DATA
, "flow-%d (0x%x): both moved, old %d/%d, new %d/%d\n",
468 flow_id
, flags
, rfi
->cur_idx
, rfi
->exp_idx
,
470 if (flags
& BRCMF_RXREORDER_FLUSH_ALL
)
471 end_idx
= rfi
->exp_idx
;
475 /* flush pkts first */
476 brcmf_rxreorder_get_skb_list(rfi
, rfi
->exp_idx
, end_idx
,
479 if (exp_idx
== ((cur_idx
+ 1) % (rfi
->max_idx
+ 1))) {
480 __skb_queue_tail(&reorder_list
, pkt
);
482 rfi
->pktslots
[cur_idx
] = pkt
;
485 rfi
->exp_idx
= exp_idx
;
486 rfi
->cur_idx
= cur_idx
;
489 /* explicity window move updating the expected index */
490 exp_idx
= reorder_data
[BRCMF_RXREORDER_EXPIDX_OFFSET
];
492 brcmf_dbg(DATA
, "flow-%d (0x%x): change expected: %d -> %d\n",
493 flow_id
, flags
, rfi
->exp_idx
, exp_idx
);
494 if (flags
& BRCMF_RXREORDER_FLUSH_ALL
)
495 end_idx
= rfi
->exp_idx
;
499 brcmf_rxreorder_get_skb_list(rfi
, rfi
->exp_idx
, end_idx
,
501 __skb_queue_tail(&reorder_list
, pkt
);
502 /* set the new expected idx */
503 rfi
->exp_idx
= exp_idx
;
506 skb_queue_walk_safe(&reorder_list
, pkt
, pnext
) {
507 __skb_unlink(pkt
, &reorder_list
);
508 brcmf_netif_rx(ifp
, pkt
);
512 void brcmf_rx_frames(struct device
*dev
, struct sk_buff_head
*skb_list
)
514 struct sk_buff
*skb
, *pnext
;
515 struct brcmf_if
*ifp
;
516 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
517 struct brcmf_pub
*drvr
= bus_if
->drvr
;
518 struct brcmf_skb_reorder_data
*rd
;
522 brcmf_dbg(DATA
, "Enter: %s: count=%u\n", dev_name(dev
),
523 skb_queue_len(skb_list
));
525 skb_queue_walk_safe(skb_list
, skb
, pnext
) {
526 skb_unlink(skb
, skb_list
);
528 /* process and remove protocol-specific header */
529 ret
= brcmf_proto_hdrpull(drvr
, true, &ifidx
, skb
);
530 ifp
= drvr
->iflist
[ifidx
];
532 if (ret
|| !ifp
|| !ifp
->ndev
) {
533 if ((ret
!= -ENODATA
) && ifp
)
534 ifp
->stats
.rx_errors
++;
535 brcmu_pkt_buf_free_skb(skb
);
539 rd
= (struct brcmf_skb_reorder_data
*)skb
->cb
;
541 brcmf_rxreorder_process_info(ifp
, rd
->reorder
, skb
);
543 brcmf_netif_rx(ifp
, skb
);
547 void brcmf_txfinalize(struct brcmf_pub
*drvr
, struct sk_buff
*txp
,
550 struct brcmf_if
*ifp
;
556 res
= brcmf_proto_hdrpull(drvr
, false, &ifidx
, txp
);
558 ifp
= drvr
->iflist
[ifidx
];
563 eh
= (struct ethhdr
*)(txp
->data
);
564 type
= ntohs(eh
->h_proto
);
566 if (type
== ETH_P_PAE
) {
567 atomic_dec(&ifp
->pend_8021x_cnt
);
568 if (waitqueue_active(&ifp
->pend_8021x_wait
))
569 wake_up(&ifp
->pend_8021x_wait
);
573 ifp
->stats
.tx_errors
++;
575 brcmu_pkt_buf_free_skb(txp
);
578 void brcmf_txcomplete(struct device
*dev
, struct sk_buff
*txp
, bool success
)
580 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
581 struct brcmf_pub
*drvr
= bus_if
->drvr
;
583 /* await txstatus signal for firmware if active */
584 if (brcmf_fws_fc_active(drvr
->fws
)) {
586 brcmf_fws_bustxfail(drvr
->fws
, txp
);
588 brcmf_txfinalize(drvr
, txp
, success
);
592 static struct net_device_stats
*brcmf_netdev_get_stats(struct net_device
*ndev
)
594 struct brcmf_if
*ifp
= netdev_priv(ndev
);
596 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
602 * Set current toe component enables in toe_ol iovar,
603 * and set toe global enable iovar
605 static int brcmf_toe_set(struct brcmf_if
*ifp
, u32 toe_ol
)
609 err
= brcmf_fil_iovar_int_set(ifp
, "toe_ol", toe_ol
);
611 brcmf_err("Setting toe_ol failed, %d\n", err
);
615 err
= brcmf_fil_iovar_int_set(ifp
, "toe", (toe_ol
!= 0));
617 brcmf_err("Setting toe failed, %d\n", err
);
623 static void brcmf_ethtool_get_drvinfo(struct net_device
*ndev
,
624 struct ethtool_drvinfo
*info
)
626 struct brcmf_if
*ifp
= netdev_priv(ndev
);
627 struct brcmf_pub
*drvr
= ifp
->drvr
;
629 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
630 snprintf(info
->version
, sizeof(info
->version
), "%lu",
632 strlcpy(info
->bus_info
, dev_name(drvr
->bus_if
->dev
),
633 sizeof(info
->bus_info
));
636 static const struct ethtool_ops brcmf_ethtool_ops
= {
637 .get_drvinfo
= brcmf_ethtool_get_drvinfo
,
640 static int brcmf_ethtool(struct brcmf_if
*ifp
, void __user
*uaddr
)
642 struct brcmf_pub
*drvr
= ifp
->drvr
;
643 struct ethtool_drvinfo info
;
644 char drvname
[sizeof(info
.driver
)];
646 struct ethtool_value edata
;
647 u32 toe_cmpnt
, csum_dir
;
650 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
652 /* all ethtool calls start with a cmd word */
653 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
657 case ETHTOOL_GDRVINFO
:
658 /* Copy out any request driver name */
659 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
661 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
662 drvname
[sizeof(info
.driver
) - 1] = '\0';
664 /* clear struct for return */
665 memset(&info
, 0, sizeof(info
));
668 /* if requested, identify ourselves */
669 if (strcmp(drvname
, "?dhd") == 0) {
670 sprintf(info
.driver
, "dhd");
671 strcpy(info
.version
, BRCMF_VERSION_STR
);
673 /* report dongle driver type */
675 sprintf(info
.driver
, "wl");
677 sprintf(info
.version
, "%lu", drvr
->drv_version
);
678 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
680 brcmf_dbg(TRACE
, "given %*s, returning %s\n",
681 (int)sizeof(drvname
), drvname
, info
.driver
);
684 /* Get toe offload components from dongle */
685 case ETHTOOL_GRXCSUM
:
686 case ETHTOOL_GTXCSUM
:
687 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
692 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
695 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
697 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
701 /* Set toe offload components in dongle */
702 case ETHTOOL_SRXCSUM
:
703 case ETHTOOL_STXCSUM
:
704 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
707 /* Read the current settings, update and write back */
708 ret
= brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_cmpnt
);
713 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
716 toe_cmpnt
|= csum_dir
;
718 toe_cmpnt
&= ~csum_dir
;
720 ret
= brcmf_toe_set(ifp
, toe_cmpnt
);
724 /* If setting TX checksum mode, tell Linux the new mode */
725 if (cmd
== ETHTOOL_STXCSUM
) {
727 ifp
->ndev
->features
|= NETIF_F_IP_CSUM
;
729 ifp
->ndev
->features
&= ~NETIF_F_IP_CSUM
;
741 static int brcmf_netdev_ioctl_entry(struct net_device
*ndev
, struct ifreq
*ifr
,
744 struct brcmf_if
*ifp
= netdev_priv(ndev
);
745 struct brcmf_pub
*drvr
= ifp
->drvr
;
747 brcmf_dbg(TRACE
, "Enter, idx=%d, cmd=0x%04x\n", ifp
->bssidx
, cmd
);
749 if (!drvr
->iflist
[ifp
->bssidx
])
752 if (cmd
== SIOCETHTOOL
)
753 return brcmf_ethtool(ifp
, ifr
->ifr_data
);
758 static int brcmf_netdev_stop(struct net_device
*ndev
)
760 struct brcmf_if
*ifp
= netdev_priv(ndev
);
762 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
764 brcmf_cfg80211_down(ndev
);
766 /* Set state and stop OS transmissions */
767 netif_stop_queue(ndev
);
772 static int brcmf_netdev_open(struct net_device
*ndev
)
774 struct brcmf_if
*ifp
= netdev_priv(ndev
);
775 struct brcmf_pub
*drvr
= ifp
->drvr
;
776 struct brcmf_bus
*bus_if
= drvr
->bus_if
;
780 brcmf_dbg(TRACE
, "Enter, idx=%d\n", ifp
->bssidx
);
782 /* If bus is not ready, can't continue */
783 if (bus_if
->state
!= BRCMF_BUS_DATA
) {
784 brcmf_err("failed bus is not ready\n");
788 atomic_set(&ifp
->pend_8021x_cnt
, 0);
790 /* Get current TOE mode from dongle */
791 if (brcmf_fil_iovar_int_get(ifp
, "toe_ol", &toe_ol
) >= 0
792 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
793 ndev
->features
|= NETIF_F_IP_CSUM
;
795 ndev
->features
&= ~NETIF_F_IP_CSUM
;
797 /* Allow transmit calls */
798 netif_start_queue(ndev
);
799 if (brcmf_cfg80211_up(ndev
)) {
800 brcmf_err("failed to bring up cfg80211\n");
807 static const struct net_device_ops brcmf_netdev_ops_pri
= {
808 .ndo_open
= brcmf_netdev_open
,
809 .ndo_stop
= brcmf_netdev_stop
,
810 .ndo_get_stats
= brcmf_netdev_get_stats
,
811 .ndo_do_ioctl
= brcmf_netdev_ioctl_entry
,
812 .ndo_start_xmit
= brcmf_netdev_start_xmit
,
813 .ndo_set_mac_address
= brcmf_netdev_set_mac_address
,
814 .ndo_set_rx_mode
= brcmf_netdev_set_multicast_list
817 int brcmf_net_attach(struct brcmf_if
*ifp
, bool rtnl_locked
)
819 struct brcmf_pub
*drvr
= ifp
->drvr
;
820 struct net_device
*ndev
;
823 brcmf_dbg(TRACE
, "Enter, idx=%d mac=%pM\n", ifp
->bssidx
,
827 /* set appropriate operations */
828 ndev
->netdev_ops
= &brcmf_netdev_ops_pri
;
830 ndev
->hard_header_len
+= drvr
->hdrlen
;
831 ndev
->ethtool_ops
= &brcmf_ethtool_ops
;
833 drvr
->rxsz
= ndev
->mtu
+ ndev
->hard_header_len
+
836 /* set the mac address */
837 memcpy(ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
839 INIT_WORK(&ifp
->setmacaddr_work
, _brcmf_set_mac_address
);
840 INIT_WORK(&ifp
->multicast_work
, _brcmf_set_multicast_list
);
843 err
= register_netdevice(ndev
);
845 err
= register_netdev(ndev
);
847 brcmf_err("couldn't register the net device\n");
851 brcmf_dbg(INFO
, "%s: Broadcom Dongle Host Driver\n", ndev
->name
);
853 ndev
->destructor
= free_netdev
;
857 drvr
->iflist
[ifp
->bssidx
] = NULL
;
858 ndev
->netdev_ops
= NULL
;
863 static int brcmf_net_p2p_open(struct net_device
*ndev
)
865 brcmf_dbg(TRACE
, "Enter\n");
867 return brcmf_cfg80211_up(ndev
);
870 static int brcmf_net_p2p_stop(struct net_device
*ndev
)
872 brcmf_dbg(TRACE
, "Enter\n");
874 return brcmf_cfg80211_down(ndev
);
877 static int brcmf_net_p2p_do_ioctl(struct net_device
*ndev
,
878 struct ifreq
*ifr
, int cmd
)
880 brcmf_dbg(TRACE
, "Enter\n");
884 static netdev_tx_t
brcmf_net_p2p_start_xmit(struct sk_buff
*skb
,
885 struct net_device
*ndev
)
888 dev_kfree_skb_any(skb
);
893 static const struct net_device_ops brcmf_netdev_ops_p2p
= {
894 .ndo_open
= brcmf_net_p2p_open
,
895 .ndo_stop
= brcmf_net_p2p_stop
,
896 .ndo_do_ioctl
= brcmf_net_p2p_do_ioctl
,
897 .ndo_start_xmit
= brcmf_net_p2p_start_xmit
900 static int brcmf_net_p2p_attach(struct brcmf_if
*ifp
)
902 struct net_device
*ndev
;
904 brcmf_dbg(TRACE
, "Enter, idx=%d mac=%pM\n", ifp
->bssidx
,
908 ndev
->netdev_ops
= &brcmf_netdev_ops_p2p
;
910 /* set the mac address */
911 memcpy(ndev
->dev_addr
, ifp
->mac_addr
, ETH_ALEN
);
913 if (register_netdev(ndev
) != 0) {
914 brcmf_err("couldn't register the p2p net device\n");
918 brcmf_dbg(INFO
, "%s: Broadcom Dongle Host Driver\n", ndev
->name
);
923 ifp
->drvr
->iflist
[ifp
->bssidx
] = NULL
;
924 ndev
->netdev_ops
= NULL
;
929 struct brcmf_if
*brcmf_add_if(struct brcmf_pub
*drvr
, s32 bssidx
, s32 ifidx
,
930 char *name
, u8
*mac_addr
)
932 struct brcmf_if
*ifp
;
933 struct net_device
*ndev
;
935 brcmf_dbg(TRACE
, "Enter, idx=%d, ifidx=%d\n", bssidx
, ifidx
);
937 ifp
= drvr
->iflist
[bssidx
];
939 * Delete the existing interface before overwriting it
940 * in case we missed the BRCMF_E_IF_DEL event.
943 brcmf_err("ERROR: netdev:%s already exists\n",
946 netif_stop_queue(ifp
->ndev
);
947 unregister_netdev(ifp
->ndev
);
948 free_netdev(ifp
->ndev
);
949 drvr
->iflist
[bssidx
] = NULL
;
951 brcmf_err("ignore IF event\n");
952 return ERR_PTR(-EINVAL
);
956 if (!brcmf_p2p_enable
&& bssidx
== 1) {
957 /* this is P2P_DEVICE interface */
958 brcmf_dbg(INFO
, "allocate non-netdev interface\n");
959 ifp
= kzalloc(sizeof(*ifp
), GFP_KERNEL
);
961 return ERR_PTR(-ENOMEM
);
963 brcmf_dbg(INFO
, "allocate netdev interface\n");
964 /* Allocate netdev, including space for private structure */
965 ndev
= alloc_netdev(sizeof(*ifp
), name
, ether_setup
);
967 return ERR_PTR(-ENOMEM
);
969 ifp
= netdev_priv(ndev
);
974 drvr
->iflist
[bssidx
] = ifp
;
976 ifp
->bssidx
= bssidx
;
978 init_waitqueue_head(&ifp
->pend_8021x_wait
);
979 spin_lock_init(&ifp
->netif_stop_lock
);
981 if (mac_addr
!= NULL
)
982 memcpy(ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
984 brcmf_dbg(TRACE
, " ==== pid:%x, if:%s (%pM) created ===\n",
985 current
->pid
, name
, ifp
->mac_addr
);
990 void brcmf_del_if(struct brcmf_pub
*drvr
, s32 bssidx
)
992 struct brcmf_if
*ifp
;
994 ifp
= drvr
->iflist
[bssidx
];
995 drvr
->iflist
[bssidx
] = NULL
;
997 brcmf_err("Null interface, idx=%d\n", bssidx
);
1000 brcmf_dbg(TRACE
, "Enter, idx=%d, ifidx=%d\n", bssidx
, ifp
->ifidx
);
1003 if (ifp
->ndev
->netdev_ops
== &brcmf_netdev_ops_pri
) {
1005 brcmf_netdev_stop(ifp
->ndev
);
1009 netif_stop_queue(ifp
->ndev
);
1012 if (ifp
->ndev
->netdev_ops
== &brcmf_netdev_ops_pri
) {
1013 cancel_work_sync(&ifp
->setmacaddr_work
);
1014 cancel_work_sync(&ifp
->multicast_work
);
1016 /* unregister will take care of freeing it */
1017 unregister_netdev(ifp
->ndev
);
1019 brcmf_cfg80211_detach(drvr
->config
);
1025 int brcmf_attach(uint bus_hdrlen
, struct device
*dev
)
1027 struct brcmf_pub
*drvr
= NULL
;
1030 brcmf_dbg(TRACE
, "Enter\n");
1032 /* Allocate primary brcmf_info */
1033 drvr
= kzalloc(sizeof(struct brcmf_pub
), GFP_ATOMIC
);
1037 mutex_init(&drvr
->proto_block
);
1039 /* Link to bus module */
1040 drvr
->hdrlen
= bus_hdrlen
;
1041 drvr
->bus_if
= dev_get_drvdata(dev
);
1042 drvr
->bus_if
->drvr
= drvr
;
1044 /* create device debugfs folder */
1045 brcmf_debugfs_attach(drvr
);
1047 /* Attach and link in the protocol */
1048 ret
= brcmf_proto_attach(drvr
);
1050 brcmf_err("brcmf_prot_attach failed\n");
1054 /* attach firmware event handler */
1055 brcmf_fweh_attach(drvr
);
1057 INIT_LIST_HEAD(&drvr
->bus_if
->dcmd_list
);
1067 int brcmf_bus_start(struct device
*dev
)
1070 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
1071 struct brcmf_pub
*drvr
= bus_if
->drvr
;
1072 struct brcmf_if
*ifp
;
1073 struct brcmf_if
*p2p_ifp
;
1075 brcmf_dbg(TRACE
, "\n");
1077 /* Bring up the bus */
1078 ret
= brcmf_bus_init(bus_if
);
1080 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret
);
1084 /* add primary networking interface */
1085 ifp
= brcmf_add_if(drvr
, 0, 0, "wlan%d", NULL
);
1087 return PTR_ERR(ifp
);
1089 if (brcmf_p2p_enable
)
1090 p2p_ifp
= brcmf_add_if(drvr
, 1, 0, "p2p%d", NULL
);
1093 if (IS_ERR(p2p_ifp
))
1096 /* signal bus ready */
1097 bus_if
->state
= BRCMF_BUS_DATA
;
1099 /* Bus is ready, do any initialization */
1100 ret
= brcmf_c_preinit_dcmds(ifp
);
1104 ret
= brcmf_fws_init(drvr
);
1108 brcmf_fws_add_interface(ifp
);
1110 drvr
->config
= brcmf_cfg80211_attach(drvr
, bus_if
->dev
);
1111 if (drvr
->config
== NULL
) {
1116 ret
= brcmf_fweh_activate_events(ifp
);
1120 ret
= brcmf_net_attach(ifp
, false);
1123 brcmf_err("failed: %d\n", ret
);
1125 brcmf_cfg80211_detach(drvr
->config
);
1127 brcmf_fws_del_interface(ifp
);
1128 brcmf_fws_deinit(drvr
);
1130 if (drvr
->iflist
[0]) {
1131 free_netdev(ifp
->ndev
);
1132 drvr
->iflist
[0] = NULL
;
1135 free_netdev(p2p_ifp
->ndev
);
1136 drvr
->iflist
[1] = NULL
;
1140 if ((brcmf_p2p_enable
) && (p2p_ifp
))
1141 if (brcmf_net_p2p_attach(p2p_ifp
) < 0)
1142 brcmf_p2p_enable
= 0;
1147 static void brcmf_bus_detach(struct brcmf_pub
*drvr
)
1149 brcmf_dbg(TRACE
, "Enter\n");
1152 /* Stop the protocol module */
1153 brcmf_proto_stop(drvr
);
1155 /* Stop the bus module */
1156 brcmf_bus_stop(drvr
->bus_if
);
1160 void brcmf_dev_reset(struct device
*dev
)
1162 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
1163 struct brcmf_pub
*drvr
= bus_if
->drvr
;
1168 if (drvr
->iflist
[0])
1169 brcmf_fil_cmd_int_set(drvr
->iflist
[0], BRCMF_C_TERMINATED
, 1);
1172 void brcmf_detach(struct device
*dev
)
1175 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
1176 struct brcmf_pub
*drvr
= bus_if
->drvr
;
1178 brcmf_dbg(TRACE
, "Enter\n");
1183 /* stop firmware event handling */
1184 brcmf_fweh_detach(drvr
);
1186 /* make sure primary interface removed last */
1187 for (i
= BRCMF_MAX_IFS
-1; i
> -1; i
--)
1188 if (drvr
->iflist
[i
]) {
1189 brcmf_fws_del_interface(drvr
->iflist
[i
]);
1190 brcmf_del_if(drvr
, i
);
1193 brcmf_bus_detach(drvr
);
1196 brcmf_proto_detach(drvr
);
1198 brcmf_fws_deinit(drvr
);
1200 brcmf_debugfs_detach(drvr
);
1201 bus_if
->drvr
= NULL
;
1205 static int brcmf_get_pend_8021x_cnt(struct brcmf_if
*ifp
)
1207 return atomic_read(&ifp
->pend_8021x_cnt
);
1210 int brcmf_netdev_wait_pend8021x(struct net_device
*ndev
)
1212 struct brcmf_if
*ifp
= netdev_priv(ndev
);
1215 err
= wait_event_timeout(ifp
->pend_8021x_wait
,
1216 !brcmf_get_pend_8021x_cnt(ifp
),
1217 msecs_to_jiffies(MAX_WAIT_FOR_8021X_TX
));
1225 * return chip id and rev of the device encoded in u32.
1227 u32
brcmf_get_chip_info(struct brcmf_if
*ifp
)
1229 struct brcmf_bus
*bus
= ifp
->drvr
->bus_if
;
1231 return bus
->chip
<< 4 | bus
->chiprev
;
1234 static void brcmf_driver_register(struct work_struct
*work
)
1236 #ifdef CONFIG_BRCMFMAC_SDIO
1237 brcmf_sdio_register();
1239 #ifdef CONFIG_BRCMFMAC_USB
1240 brcmf_usb_register();
1243 static DECLARE_WORK(brcmf_driver_work
, brcmf_driver_register
);
1245 static int __init
brcmfmac_module_init(void)
1247 brcmf_debugfs_init();
1248 #ifdef CONFIG_BRCMFMAC_SDIO
1251 if (!schedule_work(&brcmf_driver_work
))
1257 static void __exit
brcmfmac_module_exit(void)
1259 cancel_work_sync(&brcmf_driver_work
);
1261 #ifdef CONFIG_BRCMFMAC_SDIO
1264 #ifdef CONFIG_BRCMFMAC_USB
1267 brcmf_debugfs_exit();
1270 module_init(brcmfmac_module_init
);
1271 module_exit(brcmfmac_module_exit
);