| 1 |
// SPDX-License-Identifier: ISC |
| 2 |
/* |
| 3 |
* Copyright (c) 2010 Broadcom Corporation |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <linux/kernel.h> |
| 7 |
#include <linux/etherdevice.h> |
| 8 |
#include <linux/module.h> |
| 9 |
#include <linux/inetdevice.h> |
| 10 |
#include <linux/property.h> |
| 11 |
#include <net/cfg80211.h> |
| 12 |
#include <net/rtnetlink.h> |
| 13 |
#include <net/addrconf.h> |
| 14 |
#include <net/ieee80211_radiotap.h> |
| 15 |
#include <net/ipv6.h> |
| 16 |
#include <brcmu_utils.h> |
| 17 |
#include <brcmu_wifi.h> |
| 18 |
|
| 19 |
#include "core.h" |
| 20 |
#include "bus.h" |
| 21 |
#include "fwvid.h" |
| 22 |
#include "debug.h" |
| 23 |
#include "fwil_types.h" |
| 24 |
#include "p2p.h" |
| 25 |
#include "pno.h" |
| 26 |
#include "cfg80211.h" |
| 27 |
#include "fwil.h" |
| 28 |
#include "feature.h" |
| 29 |
#include "proto.h" |
| 30 |
#include "pcie.h" |
| 31 |
#include "common.h" |
| 32 |
|
| 33 |
#define MAX_WAIT_FOR_8021X_TX msecs_to_jiffies(950) |
| 34 |
|
| 35 |
#define BRCMF_BSSIDX_INVALID -1 |
| 36 |
|
| 37 |
#define RXS_PBPRES BIT(2) |
| 38 |
|
| 39 |
#define D11_PHY_HDR_LEN 6 |
| 40 |
|
| 41 |
struct d11rxhdr_le { |
| 42 |
__le16 RxFrameSize; |
| 43 |
u16 PAD; |
| 44 |
__le16 PhyRxStatus_0; |
| 45 |
__le16 PhyRxStatus_1; |
| 46 |
__le16 PhyRxStatus_2; |
| 47 |
__le16 PhyRxStatus_3; |
| 48 |
__le16 PhyRxStatus_4; |
| 49 |
__le16 PhyRxStatus_5; |
| 50 |
__le16 RxStatus1; |
| 51 |
__le16 RxStatus2; |
| 52 |
__le16 RxTSFTime; |
| 53 |
__le16 RxChan; |
| 54 |
u8 unknown[12]; |
| 55 |
} __packed; |
| 56 |
|
| 57 |
struct wlc_d11rxhdr { |
| 58 |
struct d11rxhdr_le rxhdr; |
| 59 |
__le32 tsf_l; |
| 60 |
s8 rssi; |
| 61 |
s8 rxpwr0; |
| 62 |
s8 rxpwr1; |
| 63 |
s8 do_rssi_ma; |
| 64 |
s8 rxpwr[4]; |
| 65 |
} __packed; |
| 66 |
|
| 67 |
char *brcmf_ifname(struct brcmf_if *ifp) |
| 68 |
{ |
| 69 |
if (!ifp) |
| 70 |
return "<if_null>"; |
| 71 |
|
| 72 |
if (ifp->ndev) |
| 73 |
return ifp->ndev->name; |
| 74 |
|
| 75 |
return "<if_none>"; |
| 76 |
} |
| 77 |
|
| 78 |
struct brcmf_if *brcmf_get_ifp(struct brcmf_pub *drvr, int ifidx) |
| 79 |
{ |
| 80 |
struct brcmf_if *ifp; |
| 81 |
s32 bsscfgidx; |
| 82 |
|
| 83 |
if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) { |
| 84 |
bphy_err(drvr, "ifidx %d out of range\n", ifidx); |
| 85 |
return NULL; |
| 86 |
} |
| 87 |
|
| 88 |
ifp = NULL; |
| 89 |
bsscfgidx = drvr->if2bss[ifidx]; |
| 90 |
if (bsscfgidx >= 0) |
| 91 |
ifp = drvr->iflist[bsscfgidx]; |
| 92 |
|
| 93 |
return ifp; |
| 94 |
} |
| 95 |
|
| 96 |
void brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable) |
| 97 |
{ |
| 98 |
s32 err; |
| 99 |
u32 mode; |
| 100 |
|
| 101 |
if (enable && brcmf_is_apmode_operating(ifp->drvr->wiphy)) { |
| 102 |
brcmf_dbg(TRACE, "Skip ARP/ND offload enable when soft AP is running\n"); |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
if (enable) |
| 107 |
mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY; |
| 108 |
else |
| 109 |
mode = 0; |
| 110 |
|
| 111 |
/* Try to set and enable ARP offload feature, this may fail, then it */ |
| 112 |
/* is simply not supported and err 0 will be returned */ |
| 113 |
err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode); |
| 114 |
if (err) { |
| 115 |
brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n", |
| 116 |
mode, err); |
| 117 |
} else { |
| 118 |
err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable); |
| 119 |
if (err) { |
| 120 |
brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n", |
| 121 |
enable, err); |
| 122 |
} else { |
| 123 |
brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n", |
| 124 |
enable, mode); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
err = brcmf_fil_iovar_int_set(ifp, "ndoe", enable); |
| 129 |
if (err) { |
| 130 |
brcmf_dbg(TRACE, "failed to configure (%d) ND offload err = %d\n", |
| 131 |
enable, err); |
| 132 |
} else { |
| 133 |
brcmf_dbg(TRACE, "successfully configured (%d) ND offload to 0x%x\n", |
| 134 |
enable, mode); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
static void _brcmf_set_multicast_list(struct work_struct *work) |
| 139 |
{ |
| 140 |
struct brcmf_if *ifp = container_of(work, struct brcmf_if, |
| 141 |
multicast_work); |
| 142 |
struct brcmf_pub *drvr = ifp->drvr; |
| 143 |
struct net_device *ndev; |
| 144 |
struct netdev_hw_addr *ha; |
| 145 |
u32 cmd_value, cnt; |
| 146 |
__le32 cnt_le; |
| 147 |
char *buf, *bufp; |
| 148 |
u32 buflen; |
| 149 |
s32 err; |
| 150 |
|
| 151 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx); |
| 152 |
|
| 153 |
ndev = ifp->ndev; |
| 154 |
|
| 155 |
/* Determine initial value of allmulti flag */ |
| 156 |
cmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false; |
| 157 |
|
| 158 |
/* Send down the multicast list first. */ |
| 159 |
cnt = netdev_mc_count(ndev); |
| 160 |
buflen = sizeof(cnt) + (cnt * ETH_ALEN); |
| 161 |
buf = kmalloc(buflen, GFP_KERNEL); |
| 162 |
if (!buf) |
| 163 |
return; |
| 164 |
bufp = buf; |
| 165 |
|
| 166 |
cnt_le = cpu_to_le32(cnt); |
| 167 |
memcpy(bufp, &cnt_le, sizeof(cnt_le)); |
| 168 |
bufp += sizeof(cnt_le); |
| 169 |
|
| 170 |
netdev_for_each_mc_addr(ha, ndev) { |
| 171 |
if (!cnt) |
| 172 |
break; |
| 173 |
memcpy(bufp, ha->addr, ETH_ALEN); |
| 174 |
bufp += ETH_ALEN; |
| 175 |
cnt--; |
| 176 |
} |
| 177 |
|
| 178 |
err = brcmf_fil_iovar_data_set(ifp, "mcast_list", buf, buflen); |
| 179 |
if (err < 0) { |
| 180 |
bphy_err(drvr, "Setting mcast_list failed, %d\n", err); |
| 181 |
cmd_value = cnt ? true : cmd_value; |
| 182 |
} |
| 183 |
|
| 184 |
kfree(buf); |
| 185 |
|
| 186 |
/* |
| 187 |
* Now send the allmulti setting. This is based on the setting in the |
| 188 |
* net_device flags, but might be modified above to be turned on if we |
| 189 |
* were trying to set some addresses and dongle rejected it... |
| 190 |
*/ |
| 191 |
err = brcmf_fil_iovar_int_set(ifp, "allmulti", cmd_value); |
| 192 |
if (err < 0) |
| 193 |
bphy_err(drvr, "Setting allmulti failed, %d\n", err); |
| 194 |
|
| 195 |
/*Finally, pick up the PROMISC flag */ |
| 196 |
cmd_value = (ndev->flags & IFF_PROMISC) ? true : false; |
| 197 |
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PROMISC, cmd_value); |
| 198 |
if (err < 0) { |
| 199 |
/* PROMISC unsupported by firmware of older chips */ |
| 200 |
if (err == -EBADE) |
| 201 |
bphy_info_once(drvr, "BRCMF_C_SET_PROMISC unsupported\n"); |
| 202 |
else |
| 203 |
bphy_err(drvr, "Setting BRCMF_C_SET_PROMISC failed, err=%d\n", |
| 204 |
err); |
| 205 |
} |
| 206 |
brcmf_configure_arp_nd_offload(ifp, !cmd_value); |
| 207 |
} |
| 208 |
|
| 209 |
#if IS_ENABLED(CONFIG_IPV6) |
| 210 |
static void _brcmf_update_ndtable(struct work_struct *work) |
| 211 |
{ |
| 212 |
struct brcmf_if *ifp = container_of(work, struct brcmf_if, |
| 213 |
ndoffload_work); |
| 214 |
struct brcmf_pub *drvr = ifp->drvr; |
| 215 |
int i, ret; |
| 216 |
|
| 217 |
/* clear the table in firmware */ |
| 218 |
ret = brcmf_fil_iovar_data_set(ifp, "nd_hostip_clear", NULL, 0); |
| 219 |
if (ret) { |
| 220 |
brcmf_dbg(TRACE, "fail to clear nd ip table err:%d\n", ret); |
| 221 |
return; |
| 222 |
} |
| 223 |
|
| 224 |
for (i = 0; i < ifp->ipv6addr_idx; i++) { |
| 225 |
ret = brcmf_fil_iovar_data_set(ifp, "nd_hostip", |
| 226 |
&ifp->ipv6_addr_tbl[i], |
| 227 |
sizeof(struct in6_addr)); |
| 228 |
if (ret) |
| 229 |
bphy_err(drvr, "add nd ip err %d\n", ret); |
| 230 |
} |
| 231 |
} |
| 232 |
#else |
| 233 |
static void _brcmf_update_ndtable(struct work_struct *work) |
| 234 |
{ |
| 235 |
} |
| 236 |
#endif |
| 237 |
|
| 238 |
static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr) |
| 239 |
{ |
| 240 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 241 |
struct sockaddr *sa = (struct sockaddr *)addr; |
| 242 |
int err; |
| 243 |
|
| 244 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx); |
| 245 |
|
| 246 |
err = brcmf_c_set_cur_etheraddr(ifp, sa->sa_data); |
| 247 |
if (err >= 0) { |
| 248 |
brcmf_dbg(TRACE, "updated to %pM\n", sa->sa_data); |
| 249 |
memcpy(ifp->mac_addr, sa->sa_data, ETH_ALEN); |
| 250 |
eth_hw_addr_set(ifp->ndev, ifp->mac_addr); |
| 251 |
} |
| 252 |
return err; |
| 253 |
} |
| 254 |
|
| 255 |
static void brcmf_netdev_set_multicast_list(struct net_device *ndev) |
| 256 |
{ |
| 257 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 258 |
|
| 259 |
schedule_work(&ifp->multicast_work); |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* brcmf_skb_is_iapp - checks if skb is an IAPP packet |
| 264 |
* |
| 265 |
* @skb: skb to check |
| 266 |
*/ |
| 267 |
static bool brcmf_skb_is_iapp(struct sk_buff *skb) |
| 268 |
{ |
| 269 |
static const u8 iapp_l2_update_packet[6] __aligned(2) = { |
| 270 |
0x00, 0x01, 0xaf, 0x81, 0x01, 0x00, |
| 271 |
}; |
| 272 |
unsigned char *eth_data; |
| 273 |
#if !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 274 |
const u16 *a, *b; |
| 275 |
#endif |
| 276 |
|
| 277 |
if (skb->len - skb->mac_len != 6 || |
| 278 |
!is_multicast_ether_addr(eth_hdr(skb)->h_dest)) |
| 279 |
return false; |
| 280 |
|
| 281 |
eth_data = skb_mac_header(skb) + ETH_HLEN; |
| 282 |
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 283 |
return !(((*(const u32 *)eth_data) ^ (*(const u32 *)iapp_l2_update_packet)) | |
| 284 |
((*(const u16 *)(eth_data + 4)) ^ (*(const u16 *)(iapp_l2_update_packet + 4)))); |
| 285 |
#else |
| 286 |
a = (const u16 *)eth_data; |
| 287 |
b = (const u16 *)iapp_l2_update_packet; |
| 288 |
|
| 289 |
return !((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])); |
| 290 |
#endif |
| 291 |
} |
| 292 |
|
| 293 |
static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *skb, |
| 294 |
struct net_device *ndev) |
| 295 |
{ |
| 296 |
int ret; |
| 297 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 298 |
struct brcmf_pub *drvr = ifp->drvr; |
| 299 |
struct ethhdr *eh; |
| 300 |
int head_delta; |
| 301 |
unsigned int tx_bytes = skb->len; |
| 302 |
|
| 303 |
brcmf_dbg(DATA, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx); |
| 304 |
|
| 305 |
/* Can the device send data? */ |
| 306 |
if (drvr->bus_if->state != BRCMF_BUS_UP) { |
| 307 |
bphy_err(drvr, "xmit rejected state=%d\n", drvr->bus_if->state); |
| 308 |
netif_stop_queue(ndev); |
| 309 |
dev_kfree_skb(skb); |
| 310 |
ret = -ENODEV; |
| 311 |
goto done; |
| 312 |
} |
| 313 |
|
| 314 |
/* Some recent Broadcom's firmwares disassociate STA when they receive |
| 315 |
* an 802.11f ADD frame. This behavior can lead to a local DoS security |
| 316 |
* issue. Attacker may trigger disassociation of any STA by sending a |
| 317 |
* proper Ethernet frame to the wireless interface. |
| 318 |
* |
| 319 |
* Moreover this feature may break AP interfaces in some specific |
| 320 |
* setups. This applies e.g. to the bridge with hairpin mode enabled and |
| 321 |
* IFLA_BRPORT_MCAST_TO_UCAST set. IAPP packet generated by a firmware |
| 322 |
* will get passed back to the wireless interface and cause immediate |
| 323 |
* disassociation of a just-connected STA. |
| 324 |
*/ |
| 325 |
if (!drvr->settings->iapp && brcmf_skb_is_iapp(skb)) { |
| 326 |
dev_kfree_skb(skb); |
| 327 |
ret = -EINVAL; |
| 328 |
goto done; |
| 329 |
} |
| 330 |
|
| 331 |
/* Make sure there's enough writeable headroom */ |
| 332 |
if (skb_headroom(skb) < drvr->hdrlen || skb_header_cloned(skb)) { |
| 333 |
head_delta = max_t(int, drvr->hdrlen - skb_headroom(skb), 0); |
| 334 |
|
| 335 |
brcmf_dbg(INFO, "%s: %s headroom\n", brcmf_ifname(ifp), |
| 336 |
head_delta ? "insufficient" : "unmodifiable"); |
| 337 |
atomic_inc(&drvr->bus_if->stats.pktcowed); |
| 338 |
ret = pskb_expand_head(skb, ALIGN(head_delta, NET_SKB_PAD), 0, |
| 339 |
GFP_ATOMIC); |
| 340 |
if (ret < 0) { |
| 341 |
bphy_err(drvr, "%s: failed to expand headroom\n", |
| 342 |
brcmf_ifname(ifp)); |
| 343 |
atomic_inc(&drvr->bus_if->stats.pktcow_failed); |
| 344 |
dev_kfree_skb(skb); |
| 345 |
goto done; |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
/* validate length for ether packet */ |
| 350 |
if (skb->len < sizeof(*eh)) { |
| 351 |
ret = -EINVAL; |
| 352 |
dev_kfree_skb(skb); |
| 353 |
goto done; |
| 354 |
} |
| 355 |
|
| 356 |
eh = (struct ethhdr *)(skb->data); |
| 357 |
|
| 358 |
if (eh->h_proto == htons(ETH_P_PAE)) |
| 359 |
atomic_inc(&ifp->pend_8021x_cnt); |
| 360 |
|
| 361 |
/* determine the priority */ |
| 362 |
if ((skb->priority == 0) || (skb->priority > 7)) |
| 363 |
skb->priority = cfg80211_classify8021d(skb, NULL); |
| 364 |
|
| 365 |
/* set pacing shift for packet aggregation */ |
| 366 |
sk_pacing_shift_update(skb->sk, 8); |
| 367 |
|
| 368 |
ret = brcmf_proto_tx_queue_data(drvr, ifp->ifidx, skb); |
| 369 |
if (ret < 0) |
| 370 |
brcmf_txfinalize(ifp, skb, false); |
| 371 |
|
| 372 |
done: |
| 373 |
if (ret) { |
| 374 |
ndev->stats.tx_dropped++; |
| 375 |
} else { |
| 376 |
ndev->stats.tx_packets++; |
| 377 |
ndev->stats.tx_bytes += tx_bytes; |
| 378 |
} |
| 379 |
|
| 380 |
/* Return ok: we always eat the packet */ |
| 381 |
return NETDEV_TX_OK; |
| 382 |
} |
| 383 |
|
| 384 |
void brcmf_txflowblock_if(struct brcmf_if *ifp, |
| 385 |
enum brcmf_netif_stop_reason reason, bool state) |
| 386 |
{ |
| 387 |
unsigned long flags; |
| 388 |
|
| 389 |
if (!ifp || !ifp->ndev) |
| 390 |
return; |
| 391 |
|
| 392 |
brcmf_dbg(TRACE, "enter: bsscfgidx=%d stop=0x%X reason=%d state=%d\n", |
| 393 |
ifp->bsscfgidx, ifp->netif_stop, reason, state); |
| 394 |
|
| 395 |
spin_lock_irqsave(&ifp->netif_stop_lock, flags); |
| 396 |
if (state) { |
| 397 |
if (!ifp->netif_stop) |
| 398 |
netif_stop_queue(ifp->ndev); |
| 399 |
ifp->netif_stop |= reason; |
| 400 |
} else { |
| 401 |
ifp->netif_stop &= ~reason; |
| 402 |
if (!ifp->netif_stop) |
| 403 |
netif_wake_queue(ifp->ndev); |
| 404 |
} |
| 405 |
spin_unlock_irqrestore(&ifp->netif_stop_lock, flags); |
| 406 |
} |
| 407 |
|
| 408 |
void brcmf_netif_rx(struct brcmf_if *ifp, struct sk_buff *skb) |
| 409 |
{ |
| 410 |
/* Most of Broadcom's firmwares send 802.11f ADD frame every time a new |
| 411 |
* STA connects to the AP interface. This is an obsoleted standard most |
| 412 |
* users don't use, so don't pass these frames up unless requested. |
| 413 |
*/ |
| 414 |
if (!ifp->drvr->settings->iapp && brcmf_skb_is_iapp(skb)) { |
| 415 |
brcmu_pkt_buf_free_skb(skb); |
| 416 |
return; |
| 417 |
} |
| 418 |
|
| 419 |
if (skb->pkt_type == PACKET_MULTICAST) |
| 420 |
ifp->ndev->stats.multicast++; |
| 421 |
|
| 422 |
if (!(ifp->ndev->flags & IFF_UP)) { |
| 423 |
brcmu_pkt_buf_free_skb(skb); |
| 424 |
return; |
| 425 |
} |
| 426 |
|
| 427 |
ifp->ndev->stats.rx_bytes += skb->len; |
| 428 |
ifp->ndev->stats.rx_packets++; |
| 429 |
|
| 430 |
brcmf_dbg(DATA, "rx proto=0x%X\n", ntohs(skb->protocol)); |
| 431 |
netif_rx(skb); |
| 432 |
} |
| 433 |
|
| 434 |
void brcmf_netif_mon_rx(struct brcmf_if *ifp, struct sk_buff *skb) |
| 435 |
{ |
| 436 |
if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MONITOR_FMT_RADIOTAP)) { |
| 437 |
/* Do nothing */ |
| 438 |
} else if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR)) { |
| 439 |
struct wlc_d11rxhdr *wlc_rxhdr = (struct wlc_d11rxhdr *)skb->data; |
| 440 |
struct ieee80211_radiotap_header *radiotap; |
| 441 |
unsigned int offset; |
| 442 |
u16 RxStatus1; |
| 443 |
|
| 444 |
RxStatus1 = le16_to_cpu(wlc_rxhdr->rxhdr.RxStatus1); |
| 445 |
|
| 446 |
offset = sizeof(struct wlc_d11rxhdr); |
| 447 |
/* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU |
| 448 |
* subframes |
| 449 |
*/ |
| 450 |
if (RxStatus1 & RXS_PBPRES) |
| 451 |
offset += 2; |
| 452 |
offset += D11_PHY_HDR_LEN; |
| 453 |
|
| 454 |
skb_pull(skb, offset); |
| 455 |
|
| 456 |
/* TODO: use RX header to fill some radiotap data */ |
| 457 |
radiotap = skb_push(skb, sizeof(*radiotap)); |
| 458 |
memset(radiotap, 0, sizeof(*radiotap)); |
| 459 |
radiotap->it_len = cpu_to_le16(sizeof(*radiotap)); |
| 460 |
|
| 461 |
/* TODO: 4 bytes with receive status? */ |
| 462 |
skb->len -= 4; |
| 463 |
} else { |
| 464 |
struct ieee80211_radiotap_header *radiotap; |
| 465 |
|
| 466 |
/* TODO: use RX status to fill some radiotap data */ |
| 467 |
radiotap = skb_push(skb, sizeof(*radiotap)); |
| 468 |
memset(radiotap, 0, sizeof(*radiotap)); |
| 469 |
radiotap->it_len = cpu_to_le16(sizeof(*radiotap)); |
| 470 |
|
| 471 |
/* TODO: 4 bytes with receive status? */ |
| 472 |
skb->len -= 4; |
| 473 |
} |
| 474 |
|
| 475 |
skb->dev = ifp->ndev; |
| 476 |
skb_reset_mac_header(skb); |
| 477 |
skb->pkt_type = PACKET_OTHERHOST; |
| 478 |
skb->protocol = htons(ETH_P_802_2); |
| 479 |
|
| 480 |
brcmf_netif_rx(ifp, skb); |
| 481 |
} |
| 482 |
|
| 483 |
static int brcmf_rx_hdrpull(struct brcmf_pub *drvr, struct sk_buff *skb, |
| 484 |
struct brcmf_if **ifp) |
| 485 |
{ |
| 486 |
int ret; |
| 487 |
|
| 488 |
/* process and remove protocol-specific header */ |
| 489 |
ret = brcmf_proto_hdrpull(drvr, true, skb, ifp); |
| 490 |
|
| 491 |
if (ret || !(*ifp) || !(*ifp)->ndev) { |
| 492 |
if (ret != -ENODATA && *ifp && (*ifp)->ndev) |
| 493 |
(*ifp)->ndev->stats.rx_errors++; |
| 494 |
brcmu_pkt_buf_free_skb(skb); |
| 495 |
return -ENODATA; |
| 496 |
} |
| 497 |
|
| 498 |
skb->protocol = eth_type_trans(skb, (*ifp)->ndev); |
| 499 |
return 0; |
| 500 |
} |
| 501 |
|
| 502 |
void brcmf_rx_frame(struct device *dev, struct sk_buff *skb, bool handle_event, |
| 503 |
bool inirq) |
| 504 |
{ |
| 505 |
struct brcmf_if *ifp; |
| 506 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 507 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 508 |
|
| 509 |
brcmf_dbg(DATA, "Enter: %s: rxp=%p\n", dev_name(dev), skb); |
| 510 |
|
| 511 |
if (brcmf_rx_hdrpull(drvr, skb, &ifp)) |
| 512 |
return; |
| 513 |
|
| 514 |
if (brcmf_proto_is_reorder_skb(skb)) { |
| 515 |
brcmf_proto_rxreorder(ifp, skb); |
| 516 |
} else { |
| 517 |
/* Process special event packets */ |
| 518 |
if (handle_event) { |
| 519 |
gfp_t gfp = inirq ? GFP_ATOMIC : GFP_KERNEL; |
| 520 |
|
| 521 |
brcmf_fweh_process_skb(ifp->drvr, skb, |
| 522 |
BCMILCP_SUBTYPE_VENDOR_LONG, gfp); |
| 523 |
} |
| 524 |
brcmf_netif_rx(ifp, skb); |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
void brcmf_rx_event(struct device *dev, struct sk_buff *skb) |
| 529 |
{ |
| 530 |
struct brcmf_if *ifp; |
| 531 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 532 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 533 |
|
| 534 |
brcmf_dbg(EVENT, "Enter: %s: rxp=%p\n", dev_name(dev), skb); |
| 535 |
|
| 536 |
if (brcmf_rx_hdrpull(drvr, skb, &ifp)) |
| 537 |
return; |
| 538 |
|
| 539 |
brcmf_fweh_process_skb(ifp->drvr, skb, 0, GFP_KERNEL); |
| 540 |
brcmu_pkt_buf_free_skb(skb); |
| 541 |
} |
| 542 |
|
| 543 |
void brcmf_txfinalize(struct brcmf_if *ifp, struct sk_buff *txp, bool success) |
| 544 |
{ |
| 545 |
struct ethhdr *eh; |
| 546 |
u16 type; |
| 547 |
|
| 548 |
if (!ifp) { |
| 549 |
brcmu_pkt_buf_free_skb(txp); |
| 550 |
return; |
| 551 |
} |
| 552 |
|
| 553 |
eh = (struct ethhdr *)(txp->data); |
| 554 |
type = ntohs(eh->h_proto); |
| 555 |
|
| 556 |
if (type == ETH_P_PAE) { |
| 557 |
atomic_dec(&ifp->pend_8021x_cnt); |
| 558 |
if (waitqueue_active(&ifp->pend_8021x_wait)) |
| 559 |
wake_up(&ifp->pend_8021x_wait); |
| 560 |
} |
| 561 |
|
| 562 |
if (!success) |
| 563 |
ifp->ndev->stats.tx_errors++; |
| 564 |
|
| 565 |
brcmu_pkt_buf_free_skb(txp); |
| 566 |
} |
| 567 |
|
| 568 |
static void brcmf_ethtool_get_drvinfo(struct net_device *ndev, |
| 569 |
struct ethtool_drvinfo *info) |
| 570 |
{ |
| 571 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 572 |
struct brcmf_pub *drvr = ifp->drvr; |
| 573 |
char drev[BRCMU_DOTREV_LEN] = "n/a"; |
| 574 |
|
| 575 |
if (drvr->revinfo.result == 0) |
| 576 |
brcmu_dotrev_str(drvr->revinfo.driverrev, drev); |
| 577 |
strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
| 578 |
strscpy(info->version, drev, sizeof(info->version)); |
| 579 |
strscpy(info->fw_version, drvr->fwver, sizeof(info->fw_version)); |
| 580 |
strscpy(info->bus_info, dev_name(drvr->bus_if->dev), |
| 581 |
sizeof(info->bus_info)); |
| 582 |
} |
| 583 |
|
| 584 |
static const struct ethtool_ops brcmf_ethtool_ops = { |
| 585 |
.get_drvinfo = brcmf_ethtool_get_drvinfo, |
| 586 |
}; |
| 587 |
|
| 588 |
static int brcmf_netdev_stop(struct net_device *ndev) |
| 589 |
{ |
| 590 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 591 |
|
| 592 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx); |
| 593 |
|
| 594 |
brcmf_cfg80211_down(ndev); |
| 595 |
|
| 596 |
brcmf_net_setcarrier(ifp, false); |
| 597 |
|
| 598 |
return 0; |
| 599 |
} |
| 600 |
|
| 601 |
static int brcmf_netdev_open(struct net_device *ndev) |
| 602 |
{ |
| 603 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 604 |
struct brcmf_pub *drvr = ifp->drvr; |
| 605 |
struct brcmf_bus *bus_if = drvr->bus_if; |
| 606 |
u32 toe_ol; |
| 607 |
|
| 608 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx); |
| 609 |
|
| 610 |
/* If bus is not ready, can't continue */ |
| 611 |
if (bus_if->state != BRCMF_BUS_UP) { |
| 612 |
bphy_err(drvr, "failed bus is not ready\n"); |
| 613 |
return -EAGAIN; |
| 614 |
} |
| 615 |
|
| 616 |
atomic_set(&ifp->pend_8021x_cnt, 0); |
| 617 |
|
| 618 |
/* Get current TOE mode from dongle */ |
| 619 |
if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0 |
| 620 |
&& (toe_ol & TOE_TX_CSUM_OL) != 0) |
| 621 |
ndev->features |= NETIF_F_IP_CSUM; |
| 622 |
else |
| 623 |
ndev->features &= ~NETIF_F_IP_CSUM; |
| 624 |
|
| 625 |
if (brcmf_cfg80211_up(ndev)) { |
| 626 |
bphy_err(drvr, "failed to bring up cfg80211\n"); |
| 627 |
return -EIO; |
| 628 |
} |
| 629 |
|
| 630 |
/* Clear, carrier, set when connected or AP mode. */ |
| 631 |
netif_carrier_off(ndev); |
| 632 |
return 0; |
| 633 |
} |
| 634 |
|
| 635 |
static const struct net_device_ops brcmf_netdev_ops_pri = { |
| 636 |
.ndo_open = brcmf_netdev_open, |
| 637 |
.ndo_stop = brcmf_netdev_stop, |
| 638 |
.ndo_start_xmit = brcmf_netdev_start_xmit, |
| 639 |
.ndo_set_mac_address = brcmf_netdev_set_mac_address, |
| 640 |
.ndo_set_rx_mode = brcmf_netdev_set_multicast_list |
| 641 |
}; |
| 642 |
|
| 643 |
int brcmf_net_attach(struct brcmf_if *ifp, bool locked) |
| 644 |
{ |
| 645 |
struct brcmf_pub *drvr = ifp->drvr; |
| 646 |
struct net_device *ndev; |
| 647 |
s32 err; |
| 648 |
|
| 649 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d mac=%pM\n", ifp->bsscfgidx, |
| 650 |
ifp->mac_addr); |
| 651 |
ndev = ifp->ndev; |
| 652 |
|
| 653 |
/* set appropriate operations */ |
| 654 |
ndev->netdev_ops = &brcmf_netdev_ops_pri; |
| 655 |
|
| 656 |
ndev->needed_headroom += drvr->hdrlen; |
| 657 |
ndev->ethtool_ops = &brcmf_ethtool_ops; |
| 658 |
|
| 659 |
/* set the mac address & netns */ |
| 660 |
eth_hw_addr_set(ndev, ifp->mac_addr); |
| 661 |
dev_net_set(ndev, wiphy_net(cfg_to_wiphy(drvr->config))); |
| 662 |
|
| 663 |
INIT_WORK(&ifp->multicast_work, _brcmf_set_multicast_list); |
| 664 |
INIT_WORK(&ifp->ndoffload_work, _brcmf_update_ndtable); |
| 665 |
|
| 666 |
if (locked) |
| 667 |
err = cfg80211_register_netdevice(ndev); |
| 668 |
else |
| 669 |
err = register_netdev(ndev); |
| 670 |
if (err != 0) { |
| 671 |
bphy_err(drvr, "couldn't register the net device\n"); |
| 672 |
goto fail; |
| 673 |
} |
| 674 |
|
| 675 |
netif_carrier_off(ndev); |
| 676 |
|
| 677 |
ndev->priv_destructor = brcmf_cfg80211_free_vif; |
| 678 |
brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name); |
| 679 |
return 0; |
| 680 |
|
| 681 |
fail: |
| 682 |
drvr->iflist[ifp->bsscfgidx] = NULL; |
| 683 |
ndev->netdev_ops = NULL; |
| 684 |
return -EBADE; |
| 685 |
} |
| 686 |
|
| 687 |
void brcmf_net_detach(struct net_device *ndev, bool locked) |
| 688 |
{ |
| 689 |
if (ndev->reg_state == NETREG_REGISTERED) { |
| 690 |
if (locked) |
| 691 |
cfg80211_unregister_netdevice(ndev); |
| 692 |
else |
| 693 |
unregister_netdev(ndev); |
| 694 |
} else { |
| 695 |
brcmf_cfg80211_free_vif(ndev); |
| 696 |
free_netdev(ndev); |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
static int brcmf_net_mon_open(struct net_device *ndev) |
| 701 |
{ |
| 702 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 703 |
struct brcmf_pub *drvr = ifp->drvr; |
| 704 |
u32 monitor; |
| 705 |
int err; |
| 706 |
|
| 707 |
brcmf_dbg(TRACE, "Enter\n"); |
| 708 |
|
| 709 |
err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_MONITOR, &monitor); |
| 710 |
if (err) { |
| 711 |
bphy_err(drvr, "BRCMF_C_GET_MONITOR error (%d)\n", err); |
| 712 |
return err; |
| 713 |
} else if (monitor) { |
| 714 |
bphy_err(drvr, "Monitor mode is already enabled\n"); |
| 715 |
return -EEXIST; |
| 716 |
} |
| 717 |
|
| 718 |
monitor = 3; |
| 719 |
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_MONITOR, monitor); |
| 720 |
if (err) |
| 721 |
bphy_err(drvr, "BRCMF_C_SET_MONITOR error (%d)\n", err); |
| 722 |
|
| 723 |
return err; |
| 724 |
} |
| 725 |
|
| 726 |
static int brcmf_net_mon_stop(struct net_device *ndev) |
| 727 |
{ |
| 728 |
struct brcmf_if *ifp = netdev_priv(ndev); |
| 729 |
struct brcmf_pub *drvr = ifp->drvr; |
| 730 |
u32 monitor; |
| 731 |
int err; |
| 732 |
|
| 733 |
brcmf_dbg(TRACE, "Enter\n"); |
| 734 |
|
| 735 |
monitor = 0; |
| 736 |
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_MONITOR, monitor); |
| 737 |
if (err) |
| 738 |
bphy_err(drvr, "BRCMF_C_SET_MONITOR error (%d)\n", err); |
| 739 |
|
| 740 |
return err; |
| 741 |
} |
| 742 |
|
| 743 |
static netdev_tx_t brcmf_net_mon_start_xmit(struct sk_buff *skb, |
| 744 |
struct net_device *ndev) |
| 745 |
{ |
| 746 |
dev_kfree_skb_any(skb); |
| 747 |
|
| 748 |
return NETDEV_TX_OK; |
| 749 |
} |
| 750 |
|
| 751 |
static const struct net_device_ops brcmf_netdev_ops_mon = { |
| 752 |
.ndo_open = brcmf_net_mon_open, |
| 753 |
.ndo_stop = brcmf_net_mon_stop, |
| 754 |
.ndo_start_xmit = brcmf_net_mon_start_xmit, |
| 755 |
}; |
| 756 |
|
| 757 |
int brcmf_net_mon_attach(struct brcmf_if *ifp) |
| 758 |
{ |
| 759 |
struct brcmf_pub *drvr = ifp->drvr; |
| 760 |
struct net_device *ndev; |
| 761 |
int err; |
| 762 |
|
| 763 |
brcmf_dbg(TRACE, "Enter\n"); |
| 764 |
|
| 765 |
ndev = ifp->ndev; |
| 766 |
ndev->netdev_ops = &brcmf_netdev_ops_mon; |
| 767 |
|
| 768 |
err = cfg80211_register_netdevice(ndev); |
| 769 |
if (err) |
| 770 |
bphy_err(drvr, "Failed to register %s device\n", ndev->name); |
| 771 |
|
| 772 |
return err; |
| 773 |
} |
| 774 |
|
| 775 |
void brcmf_net_setcarrier(struct brcmf_if *ifp, bool on) |
| 776 |
{ |
| 777 |
struct net_device *ndev; |
| 778 |
|
| 779 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d carrier=%d\n", ifp->bsscfgidx, |
| 780 |
on); |
| 781 |
|
| 782 |
ndev = ifp->ndev; |
| 783 |
brcmf_txflowblock_if(ifp, BRCMF_NETIF_STOP_REASON_DISCONNECTED, !on); |
| 784 |
if (on) { |
| 785 |
if (!netif_carrier_ok(ndev)) |
| 786 |
netif_carrier_on(ndev); |
| 787 |
|
| 788 |
} else { |
| 789 |
if (netif_carrier_ok(ndev)) |
| 790 |
netif_carrier_off(ndev); |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
static int brcmf_net_p2p_open(struct net_device *ndev) |
| 795 |
{ |
| 796 |
brcmf_dbg(TRACE, "Enter\n"); |
| 797 |
|
| 798 |
return brcmf_cfg80211_up(ndev); |
| 799 |
} |
| 800 |
|
| 801 |
static int brcmf_net_p2p_stop(struct net_device *ndev) |
| 802 |
{ |
| 803 |
brcmf_dbg(TRACE, "Enter\n"); |
| 804 |
|
| 805 |
return brcmf_cfg80211_down(ndev); |
| 806 |
} |
| 807 |
|
| 808 |
static netdev_tx_t brcmf_net_p2p_start_xmit(struct sk_buff *skb, |
| 809 |
struct net_device *ndev) |
| 810 |
{ |
| 811 |
if (skb) |
| 812 |
dev_kfree_skb_any(skb); |
| 813 |
|
| 814 |
return NETDEV_TX_OK; |
| 815 |
} |
| 816 |
|
| 817 |
static const struct net_device_ops brcmf_netdev_ops_p2p = { |
| 818 |
.ndo_open = brcmf_net_p2p_open, |
| 819 |
.ndo_stop = brcmf_net_p2p_stop, |
| 820 |
.ndo_start_xmit = brcmf_net_p2p_start_xmit |
| 821 |
}; |
| 822 |
|
| 823 |
static int brcmf_net_p2p_attach(struct brcmf_if *ifp) |
| 824 |
{ |
| 825 |
struct brcmf_pub *drvr = ifp->drvr; |
| 826 |
struct net_device *ndev; |
| 827 |
|
| 828 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d mac=%pM\n", ifp->bsscfgidx, |
| 829 |
ifp->mac_addr); |
| 830 |
ndev = ifp->ndev; |
| 831 |
|
| 832 |
ndev->netdev_ops = &brcmf_netdev_ops_p2p; |
| 833 |
|
| 834 |
/* set the mac address */ |
| 835 |
eth_hw_addr_set(ndev, ifp->mac_addr); |
| 836 |
|
| 837 |
if (register_netdev(ndev) != 0) { |
| 838 |
bphy_err(drvr, "couldn't register the p2p net device\n"); |
| 839 |
goto fail; |
| 840 |
} |
| 841 |
|
| 842 |
brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name); |
| 843 |
|
| 844 |
return 0; |
| 845 |
|
| 846 |
fail: |
| 847 |
ifp->drvr->iflist[ifp->bsscfgidx] = NULL; |
| 848 |
ndev->netdev_ops = NULL; |
| 849 |
return -EBADE; |
| 850 |
} |
| 851 |
|
| 852 |
struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bsscfgidx, s32 ifidx, |
| 853 |
bool is_p2pdev, const char *name, u8 *mac_addr) |
| 854 |
{ |
| 855 |
struct brcmf_if *ifp; |
| 856 |
struct net_device *ndev; |
| 857 |
|
| 858 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", bsscfgidx, ifidx); |
| 859 |
|
| 860 |
ifp = drvr->iflist[bsscfgidx]; |
| 861 |
/* |
| 862 |
* Delete the existing interface before overwriting it |
| 863 |
* in case we missed the BRCMF_E_IF_DEL event. |
| 864 |
*/ |
| 865 |
if (ifp) { |
| 866 |
if (ifidx) { |
| 867 |
bphy_err(drvr, "ERROR: netdev:%s already exists\n", |
| 868 |
ifp->ndev->name); |
| 869 |
netif_stop_queue(ifp->ndev); |
| 870 |
brcmf_net_detach(ifp->ndev, false); |
| 871 |
drvr->iflist[bsscfgidx] = NULL; |
| 872 |
} else { |
| 873 |
brcmf_dbg(INFO, "netdev:%s ignore IF event\n", |
| 874 |
ifp->ndev->name); |
| 875 |
return ERR_PTR(-EINVAL); |
| 876 |
} |
| 877 |
} |
| 878 |
|
| 879 |
if (!drvr->settings->p2p_enable && is_p2pdev) { |
| 880 |
/* this is P2P_DEVICE interface */ |
| 881 |
brcmf_dbg(INFO, "allocate non-netdev interface\n"); |
| 882 |
ifp = kzalloc_obj(*ifp); |
| 883 |
if (!ifp) |
| 884 |
return ERR_PTR(-ENOMEM); |
| 885 |
} else { |
| 886 |
brcmf_dbg(INFO, "allocate netdev interface\n"); |
| 887 |
/* Allocate netdev, including space for private structure */ |
| 888 |
ndev = alloc_netdev(sizeof(*ifp), is_p2pdev ? "p2p%d" : name, |
| 889 |
NET_NAME_UNKNOWN, ether_setup); |
| 890 |
if (!ndev) |
| 891 |
return ERR_PTR(-ENOMEM); |
| 892 |
|
| 893 |
ndev->needs_free_netdev = true; |
| 894 |
ifp = netdev_priv(ndev); |
| 895 |
ifp->ndev = ndev; |
| 896 |
/* store mapping ifidx to bsscfgidx */ |
| 897 |
if (drvr->if2bss[ifidx] == BRCMF_BSSIDX_INVALID) |
| 898 |
drvr->if2bss[ifidx] = bsscfgidx; |
| 899 |
} |
| 900 |
|
| 901 |
ifp->drvr = drvr; |
| 902 |
drvr->iflist[bsscfgidx] = ifp; |
| 903 |
ifp->ifidx = ifidx; |
| 904 |
ifp->bsscfgidx = bsscfgidx; |
| 905 |
|
| 906 |
init_waitqueue_head(&ifp->pend_8021x_wait); |
| 907 |
spin_lock_init(&ifp->netif_stop_lock); |
| 908 |
|
| 909 |
if (mac_addr != NULL) |
| 910 |
memcpy(ifp->mac_addr, mac_addr, ETH_ALEN); |
| 911 |
|
| 912 |
brcmf_dbg(TRACE, " ==== pid:%x, if:%s (%pM) created ===\n", |
| 913 |
current->pid, name, ifp->mac_addr); |
| 914 |
|
| 915 |
return ifp; |
| 916 |
} |
| 917 |
|
| 918 |
static void brcmf_del_if(struct brcmf_pub *drvr, s32 bsscfgidx, |
| 919 |
bool locked) |
| 920 |
{ |
| 921 |
struct brcmf_if *ifp; |
| 922 |
int ifidx; |
| 923 |
|
| 924 |
ifp = drvr->iflist[bsscfgidx]; |
| 925 |
if (!ifp) { |
| 926 |
bphy_err(drvr, "Null interface, bsscfgidx=%d\n", bsscfgidx); |
| 927 |
return; |
| 928 |
} |
| 929 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", bsscfgidx, |
| 930 |
ifp->ifidx); |
| 931 |
ifidx = ifp->ifidx; |
| 932 |
|
| 933 |
if (ifp->ndev) { |
| 934 |
if (bsscfgidx == 0) { |
| 935 |
if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) { |
| 936 |
rtnl_lock(); |
| 937 |
brcmf_netdev_stop(ifp->ndev); |
| 938 |
rtnl_unlock(); |
| 939 |
} |
| 940 |
} else { |
| 941 |
netif_stop_queue(ifp->ndev); |
| 942 |
} |
| 943 |
|
| 944 |
if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) { |
| 945 |
cancel_work_sync(&ifp->multicast_work); |
| 946 |
cancel_work_sync(&ifp->ndoffload_work); |
| 947 |
} |
| 948 |
brcmf_net_detach(ifp->ndev, locked); |
| 949 |
} else { |
| 950 |
/* Only p2p device interfaces which get dynamically created |
| 951 |
* end up here. In this case the p2p module should be informed |
| 952 |
* about the removal of the interface within the firmware. If |
| 953 |
* not then p2p commands towards the firmware will cause some |
| 954 |
* serious troublesome side effects. The p2p module will clean |
| 955 |
* up the ifp if needed. |
| 956 |
*/ |
| 957 |
brcmf_p2p_ifp_removed(ifp, locked); |
| 958 |
kfree(ifp); |
| 959 |
} |
| 960 |
|
| 961 |
drvr->iflist[bsscfgidx] = NULL; |
| 962 |
if (drvr->if2bss[ifidx] == bsscfgidx) |
| 963 |
drvr->if2bss[ifidx] = BRCMF_BSSIDX_INVALID; |
| 964 |
} |
| 965 |
|
| 966 |
void brcmf_remove_interface(struct brcmf_if *ifp, bool locked) |
| 967 |
{ |
| 968 |
if (!ifp || WARN_ON(ifp->drvr->iflist[ifp->bsscfgidx] != ifp)) |
| 969 |
return; |
| 970 |
brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", ifp->bsscfgidx, |
| 971 |
ifp->ifidx); |
| 972 |
brcmf_proto_del_if(ifp->drvr, ifp); |
| 973 |
brcmf_del_if(ifp->drvr, ifp->bsscfgidx, locked); |
| 974 |
} |
| 975 |
|
| 976 |
static int brcmf_psm_watchdog_notify(struct brcmf_if *ifp, |
| 977 |
const struct brcmf_event_msg *evtmsg, |
| 978 |
void *data) |
| 979 |
{ |
| 980 |
struct brcmf_pub *drvr = ifp->drvr; |
| 981 |
int err; |
| 982 |
|
| 983 |
brcmf_dbg(TRACE, "enter: bsscfgidx=%d\n", ifp->bsscfgidx); |
| 984 |
|
| 985 |
bphy_err(drvr, "PSM's watchdog has fired!\n"); |
| 986 |
|
| 987 |
err = brcmf_debug_create_memdump(ifp->drvr->bus_if, data, |
| 988 |
evtmsg->datalen); |
| 989 |
if (err) |
| 990 |
bphy_err(drvr, "Failed to get memory dump, %d\n", err); |
| 991 |
|
| 992 |
return err; |
| 993 |
} |
| 994 |
|
| 995 |
#ifdef CONFIG_INET |
| 996 |
#define ARPOL_MAX_ENTRIES 8 |
| 997 |
static int brcmf_inetaddr_changed(struct notifier_block *nb, |
| 998 |
unsigned long action, void *data) |
| 999 |
{ |
| 1000 |
struct brcmf_pub *drvr = container_of(nb, struct brcmf_pub, |
| 1001 |
inetaddr_notifier); |
| 1002 |
struct in_ifaddr *ifa = data; |
| 1003 |
struct net_device *ndev = ifa->ifa_dev->dev; |
| 1004 |
struct brcmf_if *ifp; |
| 1005 |
int idx, i, ret; |
| 1006 |
u32 val; |
| 1007 |
__be32 addr_table[ARPOL_MAX_ENTRIES] = {0}; |
| 1008 |
|
| 1009 |
/* Find out if the notification is meant for us */ |
| 1010 |
for (idx = 0; idx < BRCMF_MAX_IFS; idx++) { |
| 1011 |
ifp = drvr->iflist[idx]; |
| 1012 |
if (ifp && ifp->ndev == ndev) |
| 1013 |
break; |
| 1014 |
if (idx == BRCMF_MAX_IFS - 1) |
| 1015 |
return NOTIFY_DONE; |
| 1016 |
} |
| 1017 |
|
| 1018 |
/* check if arp offload is supported */ |
| 1019 |
ret = brcmf_fil_iovar_int_get(ifp, "arpoe", &val); |
| 1020 |
if (ret) |
| 1021 |
return NOTIFY_OK; |
| 1022 |
|
| 1023 |
/* old version only support primary index */ |
| 1024 |
ret = brcmf_fil_iovar_int_get(ifp, "arp_version", &val); |
| 1025 |
if (ret) |
| 1026 |
val = 1; |
| 1027 |
if (val == 1) |
| 1028 |
ifp = drvr->iflist[0]; |
| 1029 |
|
| 1030 |
/* retrieve the table from firmware */ |
| 1031 |
ret = brcmf_fil_iovar_data_get(ifp, "arp_hostip", addr_table, |
| 1032 |
sizeof(addr_table)); |
| 1033 |
if (ret) { |
| 1034 |
bphy_err(drvr, "fail to get arp ip table err:%d\n", ret); |
| 1035 |
return NOTIFY_OK; |
| 1036 |
} |
| 1037 |
|
| 1038 |
for (i = 0; i < ARPOL_MAX_ENTRIES; i++) |
| 1039 |
if (ifa->ifa_address == addr_table[i]) |
| 1040 |
break; |
| 1041 |
|
| 1042 |
switch (action) { |
| 1043 |
case NETDEV_UP: |
| 1044 |
if (i == ARPOL_MAX_ENTRIES) { |
| 1045 |
brcmf_dbg(TRACE, "add %pI4 to arp table\n", |
| 1046 |
&ifa->ifa_address); |
| 1047 |
/* set it directly */ |
| 1048 |
ret = brcmf_fil_iovar_data_set(ifp, "arp_hostip", |
| 1049 |
&ifa->ifa_address, sizeof(ifa->ifa_address)); |
| 1050 |
if (ret) |
| 1051 |
bphy_err(drvr, "add arp ip err %d\n", ret); |
| 1052 |
} |
| 1053 |
break; |
| 1054 |
case NETDEV_DOWN: |
| 1055 |
if (i < ARPOL_MAX_ENTRIES) { |
| 1056 |
addr_table[i] = 0; |
| 1057 |
brcmf_dbg(TRACE, "remove %pI4 from arp table\n", |
| 1058 |
&ifa->ifa_address); |
| 1059 |
/* clear the table in firmware */ |
| 1060 |
ret = brcmf_fil_iovar_data_set(ifp, "arp_hostip_clear", |
| 1061 |
NULL, 0); |
| 1062 |
if (ret) { |
| 1063 |
bphy_err(drvr, "fail to clear arp ip table err:%d\n", |
| 1064 |
ret); |
| 1065 |
return NOTIFY_OK; |
| 1066 |
} |
| 1067 |
for (i = 0; i < ARPOL_MAX_ENTRIES; i++) { |
| 1068 |
if (addr_table[i] == 0) |
| 1069 |
continue; |
| 1070 |
ret = brcmf_fil_iovar_data_set(ifp, "arp_hostip", |
| 1071 |
&addr_table[i], |
| 1072 |
sizeof(addr_table[i])); |
| 1073 |
if (ret) |
| 1074 |
bphy_err(drvr, "add arp ip err %d\n", |
| 1075 |
ret); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
break; |
| 1079 |
default: |
| 1080 |
break; |
| 1081 |
} |
| 1082 |
|
| 1083 |
return NOTIFY_OK; |
| 1084 |
} |
| 1085 |
#endif |
| 1086 |
|
| 1087 |
#if IS_ENABLED(CONFIG_IPV6) |
| 1088 |
static int brcmf_inet6addr_changed(struct notifier_block *nb, |
| 1089 |
unsigned long action, void *data) |
| 1090 |
{ |
| 1091 |
struct brcmf_pub *drvr = container_of(nb, struct brcmf_pub, |
| 1092 |
inet6addr_notifier); |
| 1093 |
struct inet6_ifaddr *ifa = data; |
| 1094 |
struct brcmf_if *ifp; |
| 1095 |
int i; |
| 1096 |
struct in6_addr *table; |
| 1097 |
|
| 1098 |
/* Only handle primary interface */ |
| 1099 |
ifp = drvr->iflist[0]; |
| 1100 |
if (!ifp) |
| 1101 |
return NOTIFY_DONE; |
| 1102 |
if (ifp->ndev != ifa->idev->dev) |
| 1103 |
return NOTIFY_DONE; |
| 1104 |
|
| 1105 |
table = ifp->ipv6_addr_tbl; |
| 1106 |
for (i = 0; i < NDOL_MAX_ENTRIES; i++) |
| 1107 |
if (ipv6_addr_equal(&ifa->addr, &table[i])) |
| 1108 |
break; |
| 1109 |
|
| 1110 |
switch (action) { |
| 1111 |
case NETDEV_UP: |
| 1112 |
if (i == NDOL_MAX_ENTRIES) { |
| 1113 |
if (ifp->ipv6addr_idx < NDOL_MAX_ENTRIES) { |
| 1114 |
table[ifp->ipv6addr_idx++] = ifa->addr; |
| 1115 |
} else { |
| 1116 |
for (i = 0; i < NDOL_MAX_ENTRIES - 1; i++) |
| 1117 |
table[i] = table[i + 1]; |
| 1118 |
table[NDOL_MAX_ENTRIES - 1] = ifa->addr; |
| 1119 |
} |
| 1120 |
} |
| 1121 |
break; |
| 1122 |
case NETDEV_DOWN: |
| 1123 |
if (i < NDOL_MAX_ENTRIES) { |
| 1124 |
for (; i < ifp->ipv6addr_idx - 1; i++) |
| 1125 |
table[i] = table[i + 1]; |
| 1126 |
memset(&table[i], 0, sizeof(table[i])); |
| 1127 |
ifp->ipv6addr_idx--; |
| 1128 |
} |
| 1129 |
break; |
| 1130 |
default: |
| 1131 |
break; |
| 1132 |
} |
| 1133 |
|
| 1134 |
schedule_work(&ifp->ndoffload_work); |
| 1135 |
|
| 1136 |
return NOTIFY_OK; |
| 1137 |
} |
| 1138 |
#endif |
| 1139 |
|
| 1140 |
static int brcmf_revinfo_read(struct seq_file *s, void *data) |
| 1141 |
{ |
| 1142 |
struct brcmf_bus *bus_if = dev_get_drvdata(s->private); |
| 1143 |
struct brcmf_rev_info *ri = &bus_if->drvr->revinfo; |
| 1144 |
char drev[BRCMU_DOTREV_LEN]; |
| 1145 |
char brev[BRCMU_BOARDREV_LEN]; |
| 1146 |
|
| 1147 |
seq_printf(s, "vendorid: 0x%04x\n", ri->vendorid); |
| 1148 |
seq_printf(s, "deviceid: 0x%04x\n", ri->deviceid); |
| 1149 |
seq_printf(s, "radiorev: %s\n", brcmu_dotrev_str(ri->radiorev, drev)); |
| 1150 |
seq_printf(s, "chip: %s (%s)\n", ri->chipname, |
| 1151 |
brcmf_fwvid_vendor_name(bus_if->drvr)); |
| 1152 |
seq_printf(s, "chippkg: %u\n", ri->chippkg); |
| 1153 |
seq_printf(s, "corerev: %u\n", ri->corerev); |
| 1154 |
seq_printf(s, "boardid: 0x%04x\n", ri->boardid); |
| 1155 |
seq_printf(s, "boardvendor: 0x%04x\n", ri->boardvendor); |
| 1156 |
seq_printf(s, "boardrev: %s\n", brcmu_boardrev_str(ri->boardrev, brev)); |
| 1157 |
seq_printf(s, "driverrev: %s\n", brcmu_dotrev_str(ri->driverrev, drev)); |
| 1158 |
seq_printf(s, "ucoderev: %u\n", ri->ucoderev); |
| 1159 |
seq_printf(s, "bus: %u\n", ri->bus); |
| 1160 |
seq_printf(s, "phytype: %u\n", ri->phytype); |
| 1161 |
seq_printf(s, "phyrev: %u\n", ri->phyrev); |
| 1162 |
seq_printf(s, "anarev: %u\n", ri->anarev); |
| 1163 |
seq_printf(s, "nvramrev: %08x\n", ri->nvramrev); |
| 1164 |
|
| 1165 |
seq_printf(s, "clmver: %s\n", bus_if->drvr->clmver); |
| 1166 |
|
| 1167 |
return 0; |
| 1168 |
} |
| 1169 |
|
| 1170 |
static void brcmf_core_bus_reset(struct work_struct *work) |
| 1171 |
{ |
| 1172 |
struct brcmf_pub *drvr = container_of(work, struct brcmf_pub, |
| 1173 |
bus_reset); |
| 1174 |
|
| 1175 |
brcmf_bus_reset(drvr->bus_if); |
| 1176 |
} |
| 1177 |
|
| 1178 |
static ssize_t bus_reset_write(struct file *file, const char __user *user_buf, |
| 1179 |
size_t count, loff_t *ppos) |
| 1180 |
{ |
| 1181 |
struct brcmf_pub *drvr = file->private_data; |
| 1182 |
u8 value; |
| 1183 |
|
| 1184 |
if (kstrtou8_from_user(user_buf, count, 0, &value)) |
| 1185 |
return -EINVAL; |
| 1186 |
|
| 1187 |
if (value != 1) |
| 1188 |
return -EINVAL; |
| 1189 |
|
| 1190 |
schedule_work(&drvr->bus_reset); |
| 1191 |
|
| 1192 |
return count; |
| 1193 |
} |
| 1194 |
|
| 1195 |
static const struct file_operations bus_reset_fops = { |
| 1196 |
.open = simple_open, |
| 1197 |
.write = bus_reset_write, |
| 1198 |
}; |
| 1199 |
|
| 1200 |
static int brcmf_bus_started(struct brcmf_pub *drvr, struct cfg80211_ops *ops) |
| 1201 |
{ |
| 1202 |
int ret = -1; |
| 1203 |
struct brcmf_bus *bus_if = drvr->bus_if; |
| 1204 |
struct brcmf_if *ifp; |
| 1205 |
struct brcmf_if *p2p_ifp; |
| 1206 |
|
| 1207 |
brcmf_dbg(TRACE, "\n"); |
| 1208 |
|
| 1209 |
/* add primary networking interface */ |
| 1210 |
ifp = brcmf_add_if(drvr, 0, 0, false, "wlan%d", |
| 1211 |
is_valid_ether_addr(drvr->settings->mac) ? drvr->settings->mac : NULL); |
| 1212 |
if (IS_ERR(ifp)) |
| 1213 |
return PTR_ERR(ifp); |
| 1214 |
|
| 1215 |
p2p_ifp = NULL; |
| 1216 |
|
| 1217 |
/* signal bus ready */ |
| 1218 |
brcmf_bus_change_state(bus_if, BRCMF_BUS_UP); |
| 1219 |
|
| 1220 |
/* do bus specific preinit here */ |
| 1221 |
ret = brcmf_bus_preinit(bus_if); |
| 1222 |
if (ret < 0) |
| 1223 |
goto fail; |
| 1224 |
|
| 1225 |
/* Bus is ready, do any initialization */ |
| 1226 |
ret = brcmf_c_preinit_dcmds(ifp); |
| 1227 |
if (ret < 0) |
| 1228 |
goto fail; |
| 1229 |
|
| 1230 |
brcmf_feat_attach(drvr); |
| 1231 |
|
| 1232 |
ret = brcmf_proto_init_done(drvr); |
| 1233 |
if (ret < 0) |
| 1234 |
goto fail; |
| 1235 |
|
| 1236 |
brcmf_proto_add_if(drvr, ifp); |
| 1237 |
|
| 1238 |
drvr->config = brcmf_cfg80211_attach(drvr, ops, |
| 1239 |
drvr->settings->p2p_enable); |
| 1240 |
if (drvr->config == NULL) { |
| 1241 |
ret = -ENOMEM; |
| 1242 |
goto fail; |
| 1243 |
} |
| 1244 |
|
| 1245 |
ret = brcmf_net_attach(ifp, false); |
| 1246 |
|
| 1247 |
if ((!ret) && (drvr->settings->p2p_enable)) { |
| 1248 |
p2p_ifp = drvr->iflist[1]; |
| 1249 |
if (p2p_ifp) |
| 1250 |
ret = brcmf_net_p2p_attach(p2p_ifp); |
| 1251 |
} |
| 1252 |
|
| 1253 |
if (ret) |
| 1254 |
goto fail; |
| 1255 |
|
| 1256 |
#ifdef CONFIG_INET |
| 1257 |
drvr->inetaddr_notifier.notifier_call = brcmf_inetaddr_changed; |
| 1258 |
ret = register_inetaddr_notifier(&drvr->inetaddr_notifier); |
| 1259 |
if (ret) |
| 1260 |
goto fail; |
| 1261 |
|
| 1262 |
#if IS_ENABLED(CONFIG_IPV6) |
| 1263 |
drvr->inet6addr_notifier.notifier_call = brcmf_inet6addr_changed; |
| 1264 |
ret = register_inet6addr_notifier(&drvr->inet6addr_notifier); |
| 1265 |
if (ret) { |
| 1266 |
unregister_inetaddr_notifier(&drvr->inetaddr_notifier); |
| 1267 |
goto fail; |
| 1268 |
} |
| 1269 |
#endif |
| 1270 |
#endif /* CONFIG_INET */ |
| 1271 |
|
| 1272 |
INIT_WORK(&drvr->bus_reset, brcmf_core_bus_reset); |
| 1273 |
|
| 1274 |
/* populate debugfs */ |
| 1275 |
brcmf_debugfs_add_entry(drvr, "revinfo", brcmf_revinfo_read); |
| 1276 |
debugfs_create_file("reset", 0600, brcmf_debugfs_get_devdir(drvr), drvr, |
| 1277 |
&bus_reset_fops); |
| 1278 |
brcmf_feat_debugfs_create(drvr); |
| 1279 |
brcmf_proto_debugfs_create(drvr); |
| 1280 |
brcmf_bus_debugfs_create(bus_if); |
| 1281 |
|
| 1282 |
return 0; |
| 1283 |
|
| 1284 |
fail: |
| 1285 |
bphy_err(drvr, "failed: %d\n", ret); |
| 1286 |
if (drvr->config) { |
| 1287 |
brcmf_cfg80211_detach(drvr->config); |
| 1288 |
drvr->config = NULL; |
| 1289 |
} |
| 1290 |
brcmf_net_detach(ifp->ndev, false); |
| 1291 |
if (p2p_ifp) |
| 1292 |
brcmf_net_detach(p2p_ifp->ndev, false); |
| 1293 |
drvr->iflist[0] = NULL; |
| 1294 |
drvr->iflist[1] = NULL; |
| 1295 |
if (drvr->settings->ignore_probe_fail) |
| 1296 |
ret = 0; |
| 1297 |
|
| 1298 |
return ret; |
| 1299 |
} |
| 1300 |
|
| 1301 |
int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings) |
| 1302 |
{ |
| 1303 |
struct wiphy *wiphy; |
| 1304 |
struct cfg80211_ops *ops; |
| 1305 |
struct brcmf_pub *drvr = NULL; |
| 1306 |
|
| 1307 |
brcmf_dbg(TRACE, "Enter\n"); |
| 1308 |
|
| 1309 |
ops = brcmf_cfg80211_get_ops(settings); |
| 1310 |
if (!ops) |
| 1311 |
return -ENOMEM; |
| 1312 |
|
| 1313 |
wiphy = wiphy_new(ops, sizeof(*drvr)); |
| 1314 |
if (!wiphy) { |
| 1315 |
kfree(ops); |
| 1316 |
return -ENOMEM; |
| 1317 |
} |
| 1318 |
|
| 1319 |
set_wiphy_dev(wiphy, dev); |
| 1320 |
drvr = wiphy_priv(wiphy); |
| 1321 |
drvr->wiphy = wiphy; |
| 1322 |
drvr->ops = ops; |
| 1323 |
drvr->bus_if = dev_get_drvdata(dev); |
| 1324 |
drvr->bus_if->drvr = drvr; |
| 1325 |
drvr->settings = settings; |
| 1326 |
|
| 1327 |
return 0; |
| 1328 |
} |
| 1329 |
|
| 1330 |
int brcmf_attach(struct device *dev) |
| 1331 |
{ |
| 1332 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1333 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 1334 |
int ret = 0; |
| 1335 |
int i; |
| 1336 |
|
| 1337 |
brcmf_dbg(TRACE, "Enter\n"); |
| 1338 |
|
| 1339 |
for (i = 0; i < ARRAY_SIZE(drvr->if2bss); i++) |
| 1340 |
drvr->if2bss[i] = BRCMF_BSSIDX_INVALID; |
| 1341 |
|
| 1342 |
mutex_init(&drvr->proto_block); |
| 1343 |
|
| 1344 |
/* Link to bus module */ |
| 1345 |
drvr->hdrlen = 0; |
| 1346 |
|
| 1347 |
ret = brcmf_fwvid_attach(drvr); |
| 1348 |
if (ret != 0) { |
| 1349 |
bphy_err(drvr, "brcmf_fwvid_attach failed\n"); |
| 1350 |
goto fail; |
| 1351 |
} |
| 1352 |
|
| 1353 |
/* Attach and link in the protocol */ |
| 1354 |
ret = brcmf_proto_attach(drvr); |
| 1355 |
if (ret != 0) { |
| 1356 |
bphy_err(drvr, "brcmf_prot_attach failed\n"); |
| 1357 |
goto fail; |
| 1358 |
} |
| 1359 |
|
| 1360 |
/* attach firmware event handler */ |
| 1361 |
ret = brcmf_fweh_attach(drvr); |
| 1362 |
if (ret != 0) { |
| 1363 |
bphy_err(drvr, "brcmf_fweh_attach failed\n"); |
| 1364 |
goto fail; |
| 1365 |
} |
| 1366 |
|
| 1367 |
/* Attach to events important for core code */ |
| 1368 |
brcmf_fweh_register(drvr, BRCMF_E_PSM_WATCHDOG, |
| 1369 |
brcmf_psm_watchdog_notify); |
| 1370 |
|
| 1371 |
brcmf_fwvid_get_cfg80211_ops(drvr); |
| 1372 |
|
| 1373 |
ret = brcmf_bus_started(drvr, drvr->ops); |
| 1374 |
if (ret != 0) { |
| 1375 |
bphy_err(drvr, "dongle is not responding: err=%d\n", ret); |
| 1376 |
goto fail; |
| 1377 |
} |
| 1378 |
|
| 1379 |
return 0; |
| 1380 |
|
| 1381 |
fail: |
| 1382 |
brcmf_detach(dev); |
| 1383 |
|
| 1384 |
return ret; |
| 1385 |
} |
| 1386 |
|
| 1387 |
void brcmf_bus_add_txhdrlen(struct device *dev, uint len) |
| 1388 |
{ |
| 1389 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1390 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 1391 |
|
| 1392 |
if (drvr) { |
| 1393 |
drvr->hdrlen += len; |
| 1394 |
} |
| 1395 |
} |
| 1396 |
|
| 1397 |
void brcmf_dev_reset(struct device *dev) |
| 1398 |
{ |
| 1399 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1400 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 1401 |
|
| 1402 |
if (drvr == NULL) |
| 1403 |
return; |
| 1404 |
|
| 1405 |
if (drvr->iflist[0]) |
| 1406 |
brcmf_fil_cmd_int_set(drvr->iflist[0], BRCMF_C_TERMINATED, 1); |
| 1407 |
} |
| 1408 |
|
| 1409 |
void brcmf_dev_coredump(struct device *dev) |
| 1410 |
{ |
| 1411 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1412 |
|
| 1413 |
if (brcmf_debug_create_memdump(bus_if, NULL, 0) < 0) |
| 1414 |
brcmf_dbg(TRACE, "failed to create coredump\n"); |
| 1415 |
} |
| 1416 |
|
| 1417 |
void brcmf_fw_crashed(struct device *dev) |
| 1418 |
{ |
| 1419 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1420 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 1421 |
|
| 1422 |
bphy_err(drvr, "Firmware has halted or crashed\n"); |
| 1423 |
|
| 1424 |
brcmf_dev_coredump(dev); |
| 1425 |
|
| 1426 |
if (drvr->bus_reset.func) |
| 1427 |
schedule_work(&drvr->bus_reset); |
| 1428 |
} |
| 1429 |
|
| 1430 |
void brcmf_detach(struct device *dev) |
| 1431 |
{ |
| 1432 |
s32 i; |
| 1433 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1434 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 1435 |
|
| 1436 |
brcmf_dbg(TRACE, "Enter\n"); |
| 1437 |
|
| 1438 |
if (drvr == NULL) |
| 1439 |
return; |
| 1440 |
|
| 1441 |
#ifdef CONFIG_INET |
| 1442 |
unregister_inetaddr_notifier(&drvr->inetaddr_notifier); |
| 1443 |
#endif |
| 1444 |
|
| 1445 |
#if IS_ENABLED(CONFIG_IPV6) |
| 1446 |
unregister_inet6addr_notifier(&drvr->inet6addr_notifier); |
| 1447 |
#endif |
| 1448 |
|
| 1449 |
brcmf_bus_change_state(bus_if, BRCMF_BUS_DOWN); |
| 1450 |
/* make sure primary interface removed last */ |
| 1451 |
for (i = BRCMF_MAX_IFS - 1; i > -1; i--) { |
| 1452 |
if (drvr->iflist[i]) |
| 1453 |
brcmf_remove_interface(drvr->iflist[i], false); |
| 1454 |
} |
| 1455 |
brcmf_bus_stop(drvr->bus_if); |
| 1456 |
|
| 1457 |
brcmf_fweh_detach(drvr); |
| 1458 |
brcmf_proto_detach(drvr); |
| 1459 |
|
| 1460 |
if (drvr->mon_if) { |
| 1461 |
brcmf_net_detach(drvr->mon_if->ndev, false); |
| 1462 |
drvr->mon_if = NULL; |
| 1463 |
} |
| 1464 |
|
| 1465 |
if (drvr->config) { |
| 1466 |
brcmf_p2p_detach(&drvr->config->p2p); |
| 1467 |
brcmf_cfg80211_detach(drvr->config); |
| 1468 |
drvr->config = NULL; |
| 1469 |
} |
| 1470 |
|
| 1471 |
brcmf_fwvid_detach(drvr); |
| 1472 |
} |
| 1473 |
|
| 1474 |
void brcmf_free(struct device *dev) |
| 1475 |
{ |
| 1476 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1477 |
struct brcmf_pub *drvr = bus_if->drvr; |
| 1478 |
|
| 1479 |
if (!drvr) |
| 1480 |
return; |
| 1481 |
|
| 1482 |
bus_if->drvr = NULL; |
| 1483 |
|
| 1484 |
kfree(drvr->ops); |
| 1485 |
|
| 1486 |
wiphy_free(drvr->wiphy); |
| 1487 |
} |
| 1488 |
|
| 1489 |
s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len) |
| 1490 |
{ |
| 1491 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1492 |
struct brcmf_if *ifp = bus_if->drvr->iflist[0]; |
| 1493 |
|
| 1494 |
return brcmf_fil_iovar_data_set(ifp, name, data, len); |
| 1495 |
} |
| 1496 |
|
| 1497 |
static int brcmf_get_pend_8021x_cnt(struct brcmf_if *ifp) |
| 1498 |
{ |
| 1499 |
return atomic_read(&ifp->pend_8021x_cnt); |
| 1500 |
} |
| 1501 |
|
| 1502 |
int brcmf_netdev_wait_pend8021x(struct brcmf_if *ifp) |
| 1503 |
{ |
| 1504 |
struct brcmf_pub *drvr = ifp->drvr; |
| 1505 |
int err; |
| 1506 |
|
| 1507 |
err = wait_event_timeout(ifp->pend_8021x_wait, |
| 1508 |
!brcmf_get_pend_8021x_cnt(ifp), |
| 1509 |
MAX_WAIT_FOR_8021X_TX); |
| 1510 |
|
| 1511 |
if (!err) { |
| 1512 |
bphy_err(drvr, "Timed out waiting for no pending 802.1x packets\n"); |
| 1513 |
atomic_set(&ifp->pend_8021x_cnt, 0); |
| 1514 |
} |
| 1515 |
|
| 1516 |
return !err; |
| 1517 |
} |
| 1518 |
|
| 1519 |
void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state) |
| 1520 |
{ |
| 1521 |
struct brcmf_pub *drvr = bus->drvr; |
| 1522 |
struct net_device *ndev; |
| 1523 |
int ifidx; |
| 1524 |
|
| 1525 |
brcmf_dbg(TRACE, "%d -> %d\n", bus->state, state); |
| 1526 |
|
| 1527 |
if (!drvr) { |
| 1528 |
brcmf_dbg(INFO, "ignoring transition, bus not attached yet\n"); |
| 1529 |
return; |
| 1530 |
} |
| 1531 |
|
| 1532 |
bus->state = state; |
| 1533 |
|
| 1534 |
if (state == BRCMF_BUS_UP) { |
| 1535 |
for (ifidx = 0; ifidx < BRCMF_MAX_IFS; ifidx++) { |
| 1536 |
if ((drvr->iflist[ifidx]) && |
| 1537 |
(drvr->iflist[ifidx]->ndev)) { |
| 1538 |
ndev = drvr->iflist[ifidx]->ndev; |
| 1539 |
if (netif_queue_stopped(ndev)) |
| 1540 |
netif_wake_queue(ndev); |
| 1541 |
} |
| 1542 |
} |
| 1543 |
} |
| 1544 |
} |
| 1545 |
|
| 1546 |
int __init brcmf_core_init(void) |
| 1547 |
{ |
| 1548 |
int err; |
| 1549 |
|
| 1550 |
err = brcmf_sdio_register(); |
| 1551 |
if (err) |
| 1552 |
return err; |
| 1553 |
|
| 1554 |
err = brcmf_usb_register(); |
| 1555 |
if (err) |
| 1556 |
goto error_usb_register; |
| 1557 |
|
| 1558 |
err = brcmf_pcie_register(); |
| 1559 |
if (err) |
| 1560 |
goto error_pcie_register; |
| 1561 |
return 0; |
| 1562 |
|
| 1563 |
error_pcie_register: |
| 1564 |
brcmf_usb_exit(); |
| 1565 |
error_usb_register: |
| 1566 |
brcmf_sdio_exit(); |
| 1567 |
return err; |
| 1568 |
} |
| 1569 |
|
| 1570 |
void __exit brcmf_core_exit(void) |
| 1571 |
{ |
| 1572 |
brcmf_sdio_exit(); |
| 1573 |
brcmf_usb_exit(); |
| 1574 |
brcmf_pcie_exit(); |
| 1575 |
} |
| 1576 |
|