at commit c03c1a14
| 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 | /* Order the decrement before waitqueue_active() */ |
| 559 | smp_mb__after_atomic(); |
| 560 | if (waitqueue_active(&ifp->pend_8021x_wait)) |
| 561 | wake_up(&ifp->pend_8021x_wait); |
| 562 | } |
| 563 | |
| 564 | if (!success) |
| 565 | ifp->ndev->stats.tx_errors++; |
| 566 | |
| 567 | brcmu_pkt_buf_free_skb(txp); |
| 568 | } |
| 569 | |
| 570 | static void brcmf_ethtool_get_drvinfo(struct net_device *ndev, |
| 571 | struct ethtool_drvinfo *info) |
| 572 | { |
| 573 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 574 | struct brcmf_pub *drvr = ifp->drvr; |
| 575 | char drev[BRCMU_DOTREV_LEN] = "n/a"; |
| 576 | |
| 577 | if (drvr->revinfo.result == 0) |
| 578 | brcmu_dotrev_str(drvr->revinfo.driverrev, drev); |
| 579 | strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
| 580 | strscpy(info->version, drev, sizeof(info->version)); |
| 581 | strscpy(info->fw_version, drvr->fwver, sizeof(info->fw_version)); |
| 582 | strscpy(info->bus_info, dev_name(drvr->bus_if->dev), |
| 583 | sizeof(info->bus_info)); |
| 584 | } |
| 585 | |
| 586 | static const struct ethtool_ops brcmf_ethtool_ops = { |
| 587 | .get_drvinfo = brcmf_ethtool_get_drvinfo, |
| 588 | }; |
| 589 | |
| 590 | static int brcmf_netdev_stop(struct net_device *ndev) |
| 591 | { |
| 592 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 593 | |
| 594 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx); |
| 595 | |
| 596 | brcmf_cfg80211_down(ndev); |
| 597 | |
| 598 | brcmf_net_setcarrier(ifp, false); |
| 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | static int brcmf_netdev_open(struct net_device *ndev) |
| 604 | { |
| 605 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 606 | struct brcmf_pub *drvr = ifp->drvr; |
| 607 | struct brcmf_bus *bus_if = drvr->bus_if; |
| 608 | u32 toe_ol; |
| 609 | |
| 610 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d\n", ifp->bsscfgidx); |
| 611 | |
| 612 | /* If bus is not ready, can't continue */ |
| 613 | if (bus_if->state != BRCMF_BUS_UP) { |
| 614 | bphy_err(drvr, "failed bus is not ready\n"); |
| 615 | return -EAGAIN; |
| 616 | } |
| 617 | |
| 618 | atomic_set(&ifp->pend_8021x_cnt, 0); |
| 619 | |
| 620 | /* Get current TOE mode from dongle */ |
| 621 | if (brcmf_fil_iovar_int_get(ifp, "toe_ol", &toe_ol) >= 0 |
| 622 | && (toe_ol & TOE_TX_CSUM_OL) != 0) |
| 623 | ndev->features |= NETIF_F_IP_CSUM; |
| 624 | else |
| 625 | ndev->features &= ~NETIF_F_IP_CSUM; |
| 626 | |
| 627 | if (brcmf_cfg80211_up(ndev)) { |
| 628 | bphy_err(drvr, "failed to bring up cfg80211\n"); |
| 629 | return -EIO; |
| 630 | } |
| 631 | |
| 632 | /* Clear, carrier, set when connected or AP mode. */ |
| 633 | netif_carrier_off(ndev); |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | static const struct net_device_ops brcmf_netdev_ops_pri = { |
| 638 | .ndo_open = brcmf_netdev_open, |
| 639 | .ndo_stop = brcmf_netdev_stop, |
| 640 | .ndo_start_xmit = brcmf_netdev_start_xmit, |
| 641 | .ndo_set_mac_address = brcmf_netdev_set_mac_address, |
| 642 | .ndo_set_rx_mode = brcmf_netdev_set_multicast_list |
| 643 | }; |
| 644 | |
| 645 | int brcmf_net_attach(struct brcmf_if *ifp, bool locked) |
| 646 | { |
| 647 | struct brcmf_pub *drvr = ifp->drvr; |
| 648 | struct net_device *ndev; |
| 649 | s32 err; |
| 650 | |
| 651 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d mac=%pM\n", ifp->bsscfgidx, |
| 652 | ifp->mac_addr); |
| 653 | ndev = ifp->ndev; |
| 654 | |
| 655 | /* set appropriate operations */ |
| 656 | ndev->netdev_ops = &brcmf_netdev_ops_pri; |
| 657 | |
| 658 | ndev->needed_headroom += drvr->hdrlen; |
| 659 | ndev->ethtool_ops = &brcmf_ethtool_ops; |
| 660 | |
| 661 | /* set the mac address & netns */ |
| 662 | eth_hw_addr_set(ndev, ifp->mac_addr); |
| 663 | dev_net_set(ndev, wiphy_net(cfg_to_wiphy(drvr->config))); |
| 664 | |
| 665 | INIT_WORK(&ifp->multicast_work, _brcmf_set_multicast_list); |
| 666 | INIT_WORK(&ifp->ndoffload_work, _brcmf_update_ndtable); |
| 667 | |
| 668 | if (locked) |
| 669 | err = cfg80211_register_netdevice(ndev); |
| 670 | else |
| 671 | err = register_netdev(ndev); |
| 672 | if (err != 0) { |
| 673 | bphy_err(drvr, "couldn't register the net device\n"); |
| 674 | goto fail; |
| 675 | } |
| 676 | |
| 677 | netif_carrier_off(ndev); |
| 678 | |
| 679 | ndev->priv_destructor = brcmf_cfg80211_free_vif; |
| 680 | brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name); |
| 681 | return 0; |
| 682 | |
| 683 | fail: |
| 684 | drvr->iflist[ifp->bsscfgidx] = NULL; |
| 685 | ndev->netdev_ops = NULL; |
| 686 | return -EBADE; |
| 687 | } |
| 688 | |
| 689 | void brcmf_net_detach(struct net_device *ndev, bool locked) |
| 690 | { |
| 691 | if (ndev->reg_state == NETREG_REGISTERED) { |
| 692 | if (locked) |
| 693 | cfg80211_unregister_netdevice(ndev); |
| 694 | else |
| 695 | unregister_netdev(ndev); |
| 696 | } else { |
| 697 | brcmf_cfg80211_free_vif(ndev); |
| 698 | free_netdev(ndev); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | static int brcmf_net_mon_open(struct net_device *ndev) |
| 703 | { |
| 704 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 705 | struct brcmf_pub *drvr = ifp->drvr; |
| 706 | u32 monitor; |
| 707 | int err; |
| 708 | |
| 709 | brcmf_dbg(TRACE, "Enter\n"); |
| 710 | |
| 711 | err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_MONITOR, &monitor); |
| 712 | if (err) { |
| 713 | bphy_err(drvr, "BRCMF_C_GET_MONITOR error (%d)\n", err); |
| 714 | return err; |
| 715 | } else if (monitor) { |
| 716 | bphy_err(drvr, "Monitor mode is already enabled\n"); |
| 717 | return -EEXIST; |
| 718 | } |
| 719 | |
| 720 | monitor = 3; |
| 721 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_MONITOR, monitor); |
| 722 | if (err) |
| 723 | bphy_err(drvr, "BRCMF_C_SET_MONITOR error (%d)\n", err); |
| 724 | |
| 725 | return err; |
| 726 | } |
| 727 | |
| 728 | static int brcmf_net_mon_stop(struct net_device *ndev) |
| 729 | { |
| 730 | struct brcmf_if *ifp = netdev_priv(ndev); |
| 731 | struct brcmf_pub *drvr = ifp->drvr; |
| 732 | u32 monitor; |
| 733 | int err; |
| 734 | |
| 735 | brcmf_dbg(TRACE, "Enter\n"); |
| 736 | |
| 737 | monitor = 0; |
| 738 | err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_MONITOR, monitor); |
| 739 | if (err) |
| 740 | bphy_err(drvr, "BRCMF_C_SET_MONITOR error (%d)\n", err); |
| 741 | |
| 742 | return err; |
| 743 | } |
| 744 | |
| 745 | static netdev_tx_t brcmf_net_mon_start_xmit(struct sk_buff *skb, |
| 746 | struct net_device *ndev) |
| 747 | { |
| 748 | dev_kfree_skb_any(skb); |
| 749 | |
| 750 | return NETDEV_TX_OK; |
| 751 | } |
| 752 | |
| 753 | static const struct net_device_ops brcmf_netdev_ops_mon = { |
| 754 | .ndo_open = brcmf_net_mon_open, |
| 755 | .ndo_stop = brcmf_net_mon_stop, |
| 756 | .ndo_start_xmit = brcmf_net_mon_start_xmit, |
| 757 | }; |
| 758 | |
| 759 | int brcmf_net_mon_attach(struct brcmf_if *ifp) |
| 760 | { |
| 761 | struct brcmf_pub *drvr = ifp->drvr; |
| 762 | struct net_device *ndev; |
| 763 | int err; |
| 764 | |
| 765 | brcmf_dbg(TRACE, "Enter\n"); |
| 766 | |
| 767 | ndev = ifp->ndev; |
| 768 | ndev->netdev_ops = &brcmf_netdev_ops_mon; |
| 769 | |
| 770 | err = cfg80211_register_netdevice(ndev); |
| 771 | if (err) |
| 772 | bphy_err(drvr, "Failed to register %s device\n", ndev->name); |
| 773 | |
| 774 | return err; |
| 775 | } |
| 776 | |
| 777 | void brcmf_net_setcarrier(struct brcmf_if *ifp, bool on) |
| 778 | { |
| 779 | struct net_device *ndev; |
| 780 | |
| 781 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d carrier=%d\n", ifp->bsscfgidx, |
| 782 | on); |
| 783 | |
| 784 | ndev = ifp->ndev; |
| 785 | brcmf_txflowblock_if(ifp, BRCMF_NETIF_STOP_REASON_DISCONNECTED, !on); |
| 786 | if (on) { |
| 787 | if (!netif_carrier_ok(ndev)) |
| 788 | netif_carrier_on(ndev); |
| 789 | |
| 790 | } else { |
| 791 | if (netif_carrier_ok(ndev)) |
| 792 | netif_carrier_off(ndev); |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | static int brcmf_net_p2p_open(struct net_device *ndev) |
| 797 | { |
| 798 | brcmf_dbg(TRACE, "Enter\n"); |
| 799 | |
| 800 | return brcmf_cfg80211_up(ndev); |
| 801 | } |
| 802 | |
| 803 | static int brcmf_net_p2p_stop(struct net_device *ndev) |
| 804 | { |
| 805 | brcmf_dbg(TRACE, "Enter\n"); |
| 806 | |
| 807 | return brcmf_cfg80211_down(ndev); |
| 808 | } |
| 809 | |
| 810 | static netdev_tx_t brcmf_net_p2p_start_xmit(struct sk_buff *skb, |
| 811 | struct net_device *ndev) |
| 812 | { |
| 813 | if (skb) |
| 814 | dev_kfree_skb_any(skb); |
| 815 | |
| 816 | return NETDEV_TX_OK; |
| 817 | } |
| 818 | |
| 819 | static const struct net_device_ops brcmf_netdev_ops_p2p = { |
| 820 | .ndo_open = brcmf_net_p2p_open, |
| 821 | .ndo_stop = brcmf_net_p2p_stop, |
| 822 | .ndo_start_xmit = brcmf_net_p2p_start_xmit |
| 823 | }; |
| 824 | |
| 825 | static int brcmf_net_p2p_attach(struct brcmf_if *ifp) |
| 826 | { |
| 827 | struct brcmf_pub *drvr = ifp->drvr; |
| 828 | struct net_device *ndev; |
| 829 | |
| 830 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d mac=%pM\n", ifp->bsscfgidx, |
| 831 | ifp->mac_addr); |
| 832 | ndev = ifp->ndev; |
| 833 | |
| 834 | ndev->netdev_ops = &brcmf_netdev_ops_p2p; |
| 835 | |
| 836 | /* set the mac address */ |
| 837 | eth_hw_addr_set(ndev, ifp->mac_addr); |
| 838 | |
| 839 | if (register_netdev(ndev) != 0) { |
| 840 | bphy_err(drvr, "couldn't register the p2p net device\n"); |
| 841 | goto fail; |
| 842 | } |
| 843 | |
| 844 | brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name); |
| 845 | |
| 846 | return 0; |
| 847 | |
| 848 | fail: |
| 849 | ifp->drvr->iflist[ifp->bsscfgidx] = NULL; |
| 850 | ndev->netdev_ops = NULL; |
| 851 | return -EBADE; |
| 852 | } |
| 853 | |
| 854 | struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bsscfgidx, s32 ifidx, |
| 855 | bool is_p2pdev, const char *name, u8 *mac_addr) |
| 856 | { |
| 857 | struct brcmf_if *ifp; |
| 858 | struct net_device *ndev; |
| 859 | |
| 860 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", bsscfgidx, ifidx); |
| 861 | |
| 862 | ifp = drvr->iflist[bsscfgidx]; |
| 863 | /* |
| 864 | * Delete the existing interface before overwriting it |
| 865 | * in case we missed the BRCMF_E_IF_DEL event. |
| 866 | */ |
| 867 | if (ifp) { |
| 868 | if (ifidx) { |
| 869 | bphy_err(drvr, "ERROR: netdev:%s already exists\n", |
| 870 | ifp->ndev->name); |
| 871 | netif_stop_queue(ifp->ndev); |
| 872 | brcmf_net_detach(ifp->ndev, false); |
| 873 | drvr->iflist[bsscfgidx] = NULL; |
| 874 | } else { |
| 875 | brcmf_dbg(INFO, "netdev:%s ignore IF event\n", |
| 876 | ifp->ndev->name); |
| 877 | return ERR_PTR(-EINVAL); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | if (!drvr->settings->p2p_enable && is_p2pdev) { |
| 882 | /* this is P2P_DEVICE interface */ |
| 883 | brcmf_dbg(INFO, "allocate non-netdev interface\n"); |
| 884 | ifp = kzalloc_obj(*ifp); |
| 885 | if (!ifp) |
| 886 | return ERR_PTR(-ENOMEM); |
| 887 | } else { |
| 888 | brcmf_dbg(INFO, "allocate netdev interface\n"); |
| 889 | /* Allocate netdev, including space for private structure */ |
| 890 | ndev = alloc_netdev(sizeof(*ifp), is_p2pdev ? "p2p%d" : name, |
| 891 | NET_NAME_UNKNOWN, ether_setup); |
| 892 | if (!ndev) |
| 893 | return ERR_PTR(-ENOMEM); |
| 894 | |
| 895 | ndev->needs_free_netdev = true; |
| 896 | ifp = netdev_priv(ndev); |
| 897 | ifp->ndev = ndev; |
| 898 | /* store mapping ifidx to bsscfgidx */ |
| 899 | if (drvr->if2bss[ifidx] == BRCMF_BSSIDX_INVALID) |
| 900 | drvr->if2bss[ifidx] = bsscfgidx; |
| 901 | } |
| 902 | |
| 903 | ifp->drvr = drvr; |
| 904 | drvr->iflist[bsscfgidx] = ifp; |
| 905 | ifp->ifidx = ifidx; |
| 906 | ifp->bsscfgidx = bsscfgidx; |
| 907 | |
| 908 | init_waitqueue_head(&ifp->pend_8021x_wait); |
| 909 | spin_lock_init(&ifp->netif_stop_lock); |
| 910 | |
| 911 | if (mac_addr != NULL) |
| 912 | memcpy(ifp->mac_addr, mac_addr, ETH_ALEN); |
| 913 | |
| 914 | brcmf_dbg(TRACE, " ==== pid:%x, if:%s (%pM) created ===\n", |
| 915 | current->pid, name, ifp->mac_addr); |
| 916 | |
| 917 | return ifp; |
| 918 | } |
| 919 | |
| 920 | static void brcmf_del_if(struct brcmf_pub *drvr, s32 bsscfgidx, |
| 921 | bool locked) |
| 922 | { |
| 923 | struct brcmf_if *ifp; |
| 924 | int ifidx; |
| 925 | |
| 926 | ifp = drvr->iflist[bsscfgidx]; |
| 927 | if (!ifp) { |
| 928 | bphy_err(drvr, "Null interface, bsscfgidx=%d\n", bsscfgidx); |
| 929 | return; |
| 930 | } |
| 931 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", bsscfgidx, |
| 932 | ifp->ifidx); |
| 933 | ifidx = ifp->ifidx; |
| 934 | |
| 935 | if (ifp->ndev) { |
| 936 | if (bsscfgidx == 0) { |
| 937 | if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) { |
| 938 | rtnl_lock(); |
| 939 | brcmf_netdev_stop(ifp->ndev); |
| 940 | rtnl_unlock(); |
| 941 | } |
| 942 | } else { |
| 943 | netif_stop_queue(ifp->ndev); |
| 944 | } |
| 945 | |
| 946 | if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) { |
| 947 | cancel_work_sync(&ifp->multicast_work); |
| 948 | cancel_work_sync(&ifp->ndoffload_work); |
| 949 | } |
| 950 | brcmf_net_detach(ifp->ndev, locked); |
| 951 | } else { |
| 952 | /* Only p2p device interfaces which get dynamically created |
| 953 | * end up here. In this case the p2p module should be informed |
| 954 | * about the removal of the interface within the firmware. If |
| 955 | * not then p2p commands towards the firmware will cause some |
| 956 | * serious troublesome side effects. The p2p module will clean |
| 957 | * up the ifp if needed. |
| 958 | */ |
| 959 | brcmf_p2p_ifp_removed(ifp, locked); |
| 960 | kfree(ifp); |
| 961 | } |
| 962 | |
| 963 | drvr->iflist[bsscfgidx] = NULL; |
| 964 | if (drvr->if2bss[ifidx] == bsscfgidx) |
| 965 | drvr->if2bss[ifidx] = BRCMF_BSSIDX_INVALID; |
| 966 | } |
| 967 | |
| 968 | void brcmf_remove_interface(struct brcmf_if *ifp, bool locked) |
| 969 | { |
| 970 | if (!ifp || WARN_ON(ifp->drvr->iflist[ifp->bsscfgidx] != ifp)) |
| 971 | return; |
| 972 | brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", ifp->bsscfgidx, |
| 973 | ifp->ifidx); |
| 974 | brcmf_proto_del_if(ifp->drvr, ifp); |
| 975 | brcmf_del_if(ifp->drvr, ifp->bsscfgidx, locked); |
| 976 | } |
| 977 | |
| 978 | static int brcmf_psm_watchdog_notify(struct brcmf_if *ifp, |
| 979 | const struct brcmf_event_msg *evtmsg, |
| 980 | void *data) |
| 981 | { |
| 982 | struct brcmf_pub *drvr = ifp->drvr; |
| 983 | int err; |
| 984 | |
| 985 | brcmf_dbg(TRACE, "enter: bsscfgidx=%d\n", ifp->bsscfgidx); |
| 986 | |
| 987 | bphy_err(drvr, "PSM's watchdog has fired!\n"); |
| 988 | |
| 989 | err = brcmf_debug_create_memdump(ifp->drvr->bus_if, data, |
| 990 | evtmsg->datalen); |
| 991 | if (err) |
| 992 | bphy_err(drvr, "Failed to get memory dump, %d\n", err); |
| 993 | |
| 994 | return err; |
| 995 | } |
| 996 | |
| 997 | #ifdef CONFIG_INET |
| 998 | #define ARPOL_MAX_ENTRIES 8 |
| 999 | static int brcmf_inetaddr_changed(struct notifier_block *nb, |
| 1000 | unsigned long action, void *data) |
| 1001 | { |
| 1002 | struct brcmf_pub *drvr = container_of(nb, struct brcmf_pub, |
| 1003 | inetaddr_notifier); |
| 1004 | struct in_ifaddr *ifa = data; |
| 1005 | struct net_device *ndev = ifa->ifa_dev->dev; |
| 1006 | struct brcmf_if *ifp; |
| 1007 | int idx, i, ret; |
| 1008 | u32 val; |
| 1009 | __be32 addr_table[ARPOL_MAX_ENTRIES] = {0}; |
| 1010 | |
| 1011 | /* Find out if the notification is meant for us */ |
| 1012 | for (idx = 0; idx < BRCMF_MAX_IFS; idx++) { |
| 1013 | ifp = drvr->iflist[idx]; |
| 1014 | if (ifp && ifp->ndev == ndev) |
| 1015 | break; |
| 1016 | if (idx == BRCMF_MAX_IFS - 1) |
| 1017 | return NOTIFY_DONE; |
| 1018 | } |
| 1019 | |
| 1020 | /* check if arp offload is supported */ |
| 1021 | ret = brcmf_fil_iovar_int_get(ifp, "arpoe", &val); |
| 1022 | if (ret) |
| 1023 | return NOTIFY_OK; |
| 1024 | |
| 1025 | /* old version only support primary index */ |
| 1026 | ret = brcmf_fil_iovar_int_get(ifp, "arp_version", &val); |
| 1027 | if (ret) |
| 1028 | val = 1; |
| 1029 | if (val == 1) |
| 1030 | ifp = drvr->iflist[0]; |
| 1031 | |
| 1032 | /* retrieve the table from firmware */ |
| 1033 | ret = brcmf_fil_iovar_data_get(ifp, "arp_hostip", addr_table, |
| 1034 | sizeof(addr_table)); |
| 1035 | if (ret) { |
| 1036 | bphy_err(drvr, "fail to get arp ip table err:%d\n", ret); |
| 1037 | return NOTIFY_OK; |
| 1038 | } |
| 1039 | |
| 1040 | for (i = 0; i < ARPOL_MAX_ENTRIES; i++) |
| 1041 | if (ifa->ifa_address == addr_table[i]) |
| 1042 | break; |
| 1043 | |
| 1044 | switch (action) { |
| 1045 | case NETDEV_UP: |
| 1046 | if (i == ARPOL_MAX_ENTRIES) { |
| 1047 | brcmf_dbg(TRACE, "add %pI4 to arp table\n", |
| 1048 | &ifa->ifa_address); |
| 1049 | /* set it directly */ |
| 1050 | ret = brcmf_fil_iovar_data_set(ifp, "arp_hostip", |
| 1051 | &ifa->ifa_address, sizeof(ifa->ifa_address)); |
| 1052 | if (ret) |
| 1053 | bphy_err(drvr, "add arp ip err %d\n", ret); |
| 1054 | } |
| 1055 | break; |
| 1056 | case NETDEV_DOWN: |
| 1057 | if (i < ARPOL_MAX_ENTRIES) { |
| 1058 | addr_table[i] = 0; |
| 1059 | brcmf_dbg(TRACE, "remove %pI4 from arp table\n", |
| 1060 | &ifa->ifa_address); |
| 1061 | /* clear the table in firmware */ |
| 1062 | ret = brcmf_fil_iovar_data_set(ifp, "arp_hostip_clear", |
| 1063 | NULL, 0); |
| 1064 | if (ret) { |
| 1065 | bphy_err(drvr, "fail to clear arp ip table err:%d\n", |
| 1066 | ret); |
| 1067 | return NOTIFY_OK; |
| 1068 | } |
| 1069 | for (i = 0; i < ARPOL_MAX_ENTRIES; i++) { |
| 1070 | if (addr_table[i] == 0) |
| 1071 | continue; |
| 1072 | ret = brcmf_fil_iovar_data_set(ifp, "arp_hostip", |
| 1073 | &addr_table[i], |
| 1074 | sizeof(addr_table[i])); |
| 1075 | if (ret) |
| 1076 | bphy_err(drvr, "add arp ip err %d\n", |
| 1077 | ret); |
| 1078 | } |
| 1079 | } |
| 1080 | break; |
| 1081 | default: |
| 1082 | break; |
| 1083 | } |
| 1084 | |
| 1085 | return NOTIFY_OK; |
| 1086 | } |
| 1087 | #endif |
| 1088 | |
| 1089 | #if IS_ENABLED(CONFIG_IPV6) |
| 1090 | static int brcmf_inet6addr_changed(struct notifier_block *nb, |
| 1091 | unsigned long action, void *data) |
| 1092 | { |
| 1093 | struct brcmf_pub *drvr = container_of(nb, struct brcmf_pub, |
| 1094 | inet6addr_notifier); |
| 1095 | struct inet6_ifaddr *ifa = data; |
| 1096 | struct brcmf_if *ifp; |
| 1097 | int i; |
| 1098 | struct in6_addr *table; |
| 1099 | |
| 1100 | /* Only handle primary interface */ |
| 1101 | ifp = drvr->iflist[0]; |
| 1102 | if (!ifp) |
| 1103 | return NOTIFY_DONE; |
| 1104 | if (ifp->ndev != ifa->idev->dev) |
| 1105 | return NOTIFY_DONE; |
| 1106 | |
| 1107 | table = ifp->ipv6_addr_tbl; |
| 1108 | for (i = 0; i < NDOL_MAX_ENTRIES; i++) |
| 1109 | if (ipv6_addr_equal(&ifa->addr, &table[i])) |
| 1110 | break; |
| 1111 | |
| 1112 | switch (action) { |
| 1113 | case NETDEV_UP: |
| 1114 | if (i == NDOL_MAX_ENTRIES) { |
| 1115 | if (ifp->ipv6addr_idx < NDOL_MAX_ENTRIES) { |
| 1116 | table[ifp->ipv6addr_idx++] = ifa->addr; |
| 1117 | } else { |
| 1118 | for (i = 0; i < NDOL_MAX_ENTRIES - 1; i++) |
| 1119 | table[i] = table[i + 1]; |
| 1120 | table[NDOL_MAX_ENTRIES - 1] = ifa->addr; |
| 1121 | } |
| 1122 | } |
| 1123 | break; |
| 1124 | case NETDEV_DOWN: |
| 1125 | if (i < NDOL_MAX_ENTRIES) { |
| 1126 | for (; i < ifp->ipv6addr_idx - 1; i++) |
| 1127 | table[i] = table[i + 1]; |
| 1128 | memset(&table[i], 0, sizeof(table[i])); |
| 1129 | ifp->ipv6addr_idx--; |
| 1130 | } |
| 1131 | break; |
| 1132 | default: |
| 1133 | break; |
| 1134 | } |
| 1135 | |
| 1136 | schedule_work(&ifp->ndoffload_work); |
| 1137 | |
| 1138 | return NOTIFY_OK; |
| 1139 | } |
| 1140 | #endif |
| 1141 | |
| 1142 | static int brcmf_revinfo_read(struct seq_file *s, void *data) |
| 1143 | { |
| 1144 | struct brcmf_bus *bus_if = dev_get_drvdata(s->private); |
| 1145 | struct brcmf_rev_info *ri = &bus_if->drvr->revinfo; |
| 1146 | char drev[BRCMU_DOTREV_LEN]; |
| 1147 | char brev[BRCMU_BOARDREV_LEN]; |
| 1148 | |
| 1149 | seq_printf(s, "vendorid: 0x%04x\n", ri->vendorid); |
| 1150 | seq_printf(s, "deviceid: 0x%04x\n", ri->deviceid); |
| 1151 | seq_printf(s, "radiorev: %s\n", brcmu_dotrev_str(ri->radiorev, drev)); |
| 1152 | seq_printf(s, "chip: %s (%s)\n", ri->chipname, |
| 1153 | brcmf_fwvid_vendor_name(bus_if->drvr)); |
| 1154 | seq_printf(s, "chippkg: %u\n", ri->chippkg); |
| 1155 | seq_printf(s, "corerev: %u\n", ri->corerev); |
| 1156 | seq_printf(s, "boardid: 0x%04x\n", ri->boardid); |
| 1157 | seq_printf(s, "boardvendor: 0x%04x\n", ri->boardvendor); |
| 1158 | seq_printf(s, "boardrev: %s\n", brcmu_boardrev_str(ri->boardrev, brev)); |
| 1159 | seq_printf(s, "driverrev: %s\n", brcmu_dotrev_str(ri->driverrev, drev)); |
| 1160 | seq_printf(s, "ucoderev: %u\n", ri->ucoderev); |
| 1161 | seq_printf(s, "bus: %u\n", ri->bus); |
| 1162 | seq_printf(s, "phytype: %u\n", ri->phytype); |
| 1163 | seq_printf(s, "phyrev: %u\n", ri->phyrev); |
| 1164 | seq_printf(s, "anarev: %u\n", ri->anarev); |
| 1165 | seq_printf(s, "nvramrev: %08x\n", ri->nvramrev); |
| 1166 | |
| 1167 | seq_printf(s, "clmver: %s\n", bus_if->drvr->clmver); |
| 1168 | |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | /* |
| 1173 | * Serialize arming from debugfs reset and brcmf_fw_crashed() against |
| 1174 | * teardown. The remove path sets ->removing and drains the work while |
| 1175 | * holding bus_reset_lock, so a racing armer is either drained or skips it. |
| 1176 | */ |
| 1177 | static void brcmf_bus_schedule_reset(struct brcmf_bus *bus_if) |
| 1178 | { |
| 1179 | mutex_lock(&bus_if->bus_reset_lock); |
| 1180 | if (bus_if->drvr && bus_if->drvr->bus_reset.func && !bus_if->removing) |
| 1181 | schedule_work(&bus_if->drvr->bus_reset); |
| 1182 | mutex_unlock(&bus_if->bus_reset_lock); |
| 1183 | } |
| 1184 | |
| 1185 | void brcmf_bus_cancel_reset_work(struct brcmf_bus *bus_if) |
| 1186 | { |
| 1187 | mutex_lock(&bus_if->bus_reset_lock); |
| 1188 | bus_if->removing = true; |
| 1189 | if (bus_if->drvr) |
| 1190 | cancel_work_sync(&bus_if->drvr->bus_reset); |
| 1191 | mutex_unlock(&bus_if->bus_reset_lock); |
| 1192 | } |
| 1193 | |
| 1194 | void brcmf_bus_allow_reset_work(struct brcmf_bus *bus_if) |
| 1195 | { |
| 1196 | mutex_lock(&bus_if->bus_reset_lock); |
| 1197 | bus_if->removing = false; |
| 1198 | mutex_unlock(&bus_if->bus_reset_lock); |
| 1199 | } |
| 1200 | |
| 1201 | static void brcmf_core_bus_reset(struct work_struct *work) |
| 1202 | { |
| 1203 | struct brcmf_pub *drvr = container_of(work, struct brcmf_pub, |
| 1204 | bus_reset); |
| 1205 | |
| 1206 | brcmf_bus_reset(drvr->bus_if); |
| 1207 | } |
| 1208 | |
| 1209 | static ssize_t bus_reset_write(struct file *file, const char __user *user_buf, |
| 1210 | size_t count, loff_t *ppos) |
| 1211 | { |
| 1212 | struct brcmf_pub *drvr = file->private_data; |
| 1213 | u8 value; |
| 1214 | |
| 1215 | if (kstrtou8_from_user(user_buf, count, 0, &value)) |
| 1216 | return -EINVAL; |
| 1217 | |
| 1218 | if (value != 1) |
| 1219 | return -EINVAL; |
| 1220 | |
| 1221 | brcmf_bus_schedule_reset(drvr->bus_if); |
| 1222 | |
| 1223 | return count; |
| 1224 | } |
| 1225 | |
| 1226 | static const struct file_operations bus_reset_fops = { |
| 1227 | .open = simple_open, |
| 1228 | .write = bus_reset_write, |
| 1229 | }; |
| 1230 | |
| 1231 | static int brcmf_bus_started(struct brcmf_pub *drvr, struct cfg80211_ops *ops) |
| 1232 | { |
| 1233 | int ret = -1; |
| 1234 | struct brcmf_bus *bus_if = drvr->bus_if; |
| 1235 | struct brcmf_if *ifp; |
| 1236 | struct brcmf_if *p2p_ifp; |
| 1237 | |
| 1238 | brcmf_dbg(TRACE, "\n"); |
| 1239 | |
| 1240 | /* add primary networking interface */ |
| 1241 | ifp = brcmf_add_if(drvr, 0, 0, false, "wlan%d", |
| 1242 | is_valid_ether_addr(drvr->settings->mac) ? drvr->settings->mac : NULL); |
| 1243 | if (IS_ERR(ifp)) |
| 1244 | return PTR_ERR(ifp); |
| 1245 | |
| 1246 | p2p_ifp = NULL; |
| 1247 | |
| 1248 | /* signal bus ready */ |
| 1249 | brcmf_bus_change_state(bus_if, BRCMF_BUS_UP); |
| 1250 | |
| 1251 | /* do bus specific preinit here */ |
| 1252 | ret = brcmf_bus_preinit(bus_if); |
| 1253 | if (ret < 0) |
| 1254 | goto fail; |
| 1255 | |
| 1256 | /* Bus is ready, do any initialization */ |
| 1257 | ret = brcmf_c_preinit_dcmds(ifp); |
| 1258 | if (ret < 0) |
| 1259 | goto fail; |
| 1260 | |
| 1261 | brcmf_feat_attach(drvr); |
| 1262 | |
| 1263 | ret = brcmf_proto_init_done(drvr); |
| 1264 | if (ret < 0) |
| 1265 | goto fail; |
| 1266 | |
| 1267 | brcmf_proto_add_if(drvr, ifp); |
| 1268 | |
| 1269 | drvr->config = brcmf_cfg80211_attach(drvr, ops, |
| 1270 | drvr->settings->p2p_enable); |
| 1271 | if (drvr->config == NULL) { |
| 1272 | ret = -ENOMEM; |
| 1273 | goto fail; |
| 1274 | } |
| 1275 | |
| 1276 | ret = brcmf_net_attach(ifp, false); |
| 1277 | |
| 1278 | if ((!ret) && (drvr->settings->p2p_enable)) { |
| 1279 | p2p_ifp = drvr->iflist[1]; |
| 1280 | if (p2p_ifp) |
| 1281 | ret = brcmf_net_p2p_attach(p2p_ifp); |
| 1282 | } |
| 1283 | |
| 1284 | if (ret) |
| 1285 | goto fail; |
| 1286 | |
| 1287 | #ifdef CONFIG_INET |
| 1288 | drvr->inetaddr_notifier.notifier_call = brcmf_inetaddr_changed; |
| 1289 | ret = register_inetaddr_notifier(&drvr->inetaddr_notifier); |
| 1290 | if (ret) |
| 1291 | goto fail; |
| 1292 | |
| 1293 | #if IS_ENABLED(CONFIG_IPV6) |
| 1294 | drvr->inet6addr_notifier.notifier_call = brcmf_inet6addr_changed; |
| 1295 | ret = register_inet6addr_notifier(&drvr->inet6addr_notifier); |
| 1296 | if (ret) { |
| 1297 | unregister_inetaddr_notifier(&drvr->inetaddr_notifier); |
| 1298 | goto fail; |
| 1299 | } |
| 1300 | #endif |
| 1301 | #endif /* CONFIG_INET */ |
| 1302 | |
| 1303 | INIT_WORK(&drvr->bus_reset, brcmf_core_bus_reset); |
| 1304 | |
| 1305 | /* populate debugfs */ |
| 1306 | brcmf_debugfs_add_entry(drvr, "revinfo", brcmf_revinfo_read); |
| 1307 | debugfs_create_file("reset", 0600, brcmf_debugfs_get_devdir(drvr), drvr, |
| 1308 | &bus_reset_fops); |
| 1309 | brcmf_feat_debugfs_create(drvr); |
| 1310 | brcmf_proto_debugfs_create(drvr); |
| 1311 | brcmf_bus_debugfs_create(bus_if); |
| 1312 | |
| 1313 | return 0; |
| 1314 | |
| 1315 | fail: |
| 1316 | bphy_err(drvr, "failed: %d\n", ret); |
| 1317 | if (drvr->config) { |
| 1318 | brcmf_cfg80211_detach(drvr->config); |
| 1319 | drvr->config = NULL; |
| 1320 | } |
| 1321 | brcmf_net_detach(ifp->ndev, false); |
| 1322 | if (p2p_ifp) |
| 1323 | brcmf_net_detach(p2p_ifp->ndev, false); |
| 1324 | drvr->iflist[0] = NULL; |
| 1325 | drvr->iflist[1] = NULL; |
| 1326 | if (drvr->settings->ignore_probe_fail) |
| 1327 | ret = 0; |
| 1328 | |
| 1329 | return ret; |
| 1330 | } |
| 1331 | |
| 1332 | int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings) |
| 1333 | { |
| 1334 | struct wiphy *wiphy; |
| 1335 | struct cfg80211_ops *ops; |
| 1336 | struct brcmf_pub *drvr = NULL; |
| 1337 | |
| 1338 | brcmf_dbg(TRACE, "Enter\n"); |
| 1339 | |
| 1340 | ops = brcmf_cfg80211_get_ops(settings); |
| 1341 | if (!ops) |
| 1342 | return -ENOMEM; |
| 1343 | |
| 1344 | wiphy = wiphy_new(ops, sizeof(*drvr)); |
| 1345 | if (!wiphy) { |
| 1346 | kfree(ops); |
| 1347 | return -ENOMEM; |
| 1348 | } |
| 1349 | |
| 1350 | set_wiphy_dev(wiphy, dev); |
| 1351 | drvr = wiphy_priv(wiphy); |
| 1352 | drvr->wiphy = wiphy; |
| 1353 | drvr->ops = ops; |
| 1354 | drvr->bus_if = dev_get_drvdata(dev); |
| 1355 | drvr->bus_if->drvr = drvr; |
| 1356 | drvr->settings = settings; |
| 1357 | |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
| 1361 | int brcmf_attach(struct device *dev) |
| 1362 | { |
| 1363 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1364 | struct brcmf_pub *drvr = bus_if->drvr; |
| 1365 | int ret = 0; |
| 1366 | int i; |
| 1367 | |
| 1368 | brcmf_dbg(TRACE, "Enter\n"); |
| 1369 | |
| 1370 | for (i = 0; i < ARRAY_SIZE(drvr->if2bss); i++) |
| 1371 | drvr->if2bss[i] = BRCMF_BSSIDX_INVALID; |
| 1372 | |
| 1373 | mutex_init(&drvr->proto_block); |
| 1374 | |
| 1375 | /* Link to bus module */ |
| 1376 | drvr->hdrlen = 0; |
| 1377 | |
| 1378 | ret = brcmf_fwvid_attach(drvr); |
| 1379 | if (ret != 0) { |
| 1380 | bphy_err(drvr, "brcmf_fwvid_attach failed\n"); |
| 1381 | goto fail; |
| 1382 | } |
| 1383 | |
| 1384 | /* Attach and link in the protocol */ |
| 1385 | ret = brcmf_proto_attach(drvr); |
| 1386 | if (ret != 0) { |
| 1387 | bphy_err(drvr, "brcmf_prot_attach failed\n"); |
| 1388 | goto fail; |
| 1389 | } |
| 1390 | |
| 1391 | /* attach firmware event handler */ |
| 1392 | ret = brcmf_fweh_attach(drvr); |
| 1393 | if (ret != 0) { |
| 1394 | bphy_err(drvr, "brcmf_fweh_attach failed\n"); |
| 1395 | goto fail; |
| 1396 | } |
| 1397 | |
| 1398 | /* Attach to events important for core code */ |
| 1399 | brcmf_fweh_register(drvr, BRCMF_E_PSM_WATCHDOG, |
| 1400 | brcmf_psm_watchdog_notify); |
| 1401 | |
| 1402 | brcmf_fwvid_get_cfg80211_ops(drvr); |
| 1403 | |
| 1404 | ret = brcmf_bus_started(drvr, drvr->ops); |
| 1405 | if (ret != 0) { |
| 1406 | bphy_err(drvr, "dongle is not responding: err=%d\n", ret); |
| 1407 | goto fail; |
| 1408 | } |
| 1409 | |
| 1410 | return 0; |
| 1411 | |
| 1412 | fail: |
| 1413 | brcmf_detach(dev); |
| 1414 | |
| 1415 | return ret; |
| 1416 | } |
| 1417 | |
| 1418 | void brcmf_bus_add_txhdrlen(struct device *dev, uint len) |
| 1419 | { |
| 1420 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1421 | struct brcmf_pub *drvr = bus_if->drvr; |
| 1422 | |
| 1423 | if (drvr) { |
| 1424 | drvr->hdrlen += len; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | void brcmf_dev_reset(struct device *dev) |
| 1429 | { |
| 1430 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1431 | struct brcmf_pub *drvr = bus_if->drvr; |
| 1432 | |
| 1433 | if (drvr == NULL) |
| 1434 | return; |
| 1435 | |
| 1436 | if (drvr->iflist[0]) |
| 1437 | brcmf_fil_cmd_int_set(drvr->iflist[0], BRCMF_C_TERMINATED, 1); |
| 1438 | } |
| 1439 | |
| 1440 | void brcmf_dev_coredump(struct device *dev) |
| 1441 | { |
| 1442 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1443 | |
| 1444 | if (brcmf_debug_create_memdump(bus_if, NULL, 0) < 0) |
| 1445 | brcmf_dbg(TRACE, "failed to create coredump\n"); |
| 1446 | } |
| 1447 | |
| 1448 | void brcmf_fw_crashed(struct device *dev) |
| 1449 | { |
| 1450 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1451 | struct brcmf_pub *drvr; |
| 1452 | |
| 1453 | /* May fire before brcmf_attach() wires up drvr, or after removal |
| 1454 | * has cleared it; guard the derefs below (and the arming gate in |
| 1455 | * brcmf_bus_schedule_reset() already checks drvr/->removing). |
| 1456 | */ |
| 1457 | if (!bus_if) |
| 1458 | return; |
| 1459 | drvr = bus_if->drvr; |
| 1460 | if (!drvr) |
| 1461 | return; |
| 1462 | |
| 1463 | bphy_err(drvr, "Firmware has halted or crashed\n"); |
| 1464 | |
| 1465 | brcmf_dev_coredump(dev); |
| 1466 | |
| 1467 | brcmf_bus_schedule_reset(bus_if); |
| 1468 | } |
| 1469 | |
| 1470 | void brcmf_detach(struct device *dev) |
| 1471 | { |
| 1472 | s32 i; |
| 1473 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1474 | struct brcmf_pub *drvr = bus_if->drvr; |
| 1475 | |
| 1476 | brcmf_dbg(TRACE, "Enter\n"); |
| 1477 | |
| 1478 | if (drvr == NULL) |
| 1479 | return; |
| 1480 | |
| 1481 | #ifdef CONFIG_INET |
| 1482 | unregister_inetaddr_notifier(&drvr->inetaddr_notifier); |
| 1483 | #endif |
| 1484 | |
| 1485 | #if IS_ENABLED(CONFIG_IPV6) |
| 1486 | unregister_inet6addr_notifier(&drvr->inet6addr_notifier); |
| 1487 | #endif |
| 1488 | |
| 1489 | brcmf_bus_change_state(bus_if, BRCMF_BUS_DOWN); |
| 1490 | /* make sure primary interface removed last */ |
| 1491 | for (i = BRCMF_MAX_IFS - 1; i > -1; i--) { |
| 1492 | struct brcmf_if *ifp = drvr->iflist[i]; |
| 1493 | |
| 1494 | if (!ifp) |
| 1495 | continue; |
| 1496 | |
| 1497 | if (ifp->ndev) { |
| 1498 | brcmf_remove_interface(ifp, false); |
| 1499 | continue; |
| 1500 | } |
| 1501 | |
| 1502 | /* The P2P device interface has no netdev. Its removal can |
| 1503 | * race with NL80211_CMD_DEL_INTERFACE issued by a user space |
| 1504 | * process that is exiting (e.g. wpa_supplicant), which ends |
| 1505 | * in brcmf_p2p_del_vif() under RTNL and the wiphy mutex. If |
| 1506 | * both paths remove the interface, the wdev is unregistered |
| 1507 | * twice and the vif is used after being freed. Take the same |
| 1508 | * locks and re-read iflist, so only one path removes it. |
| 1509 | */ |
| 1510 | rtnl_lock(); |
| 1511 | wiphy_lock(drvr->wiphy); |
| 1512 | ifp = drvr->iflist[i]; |
| 1513 | if (ifp) |
| 1514 | brcmf_remove_interface(ifp, true); |
| 1515 | wiphy_unlock(drvr->wiphy); |
| 1516 | rtnl_unlock(); |
| 1517 | } |
| 1518 | brcmf_bus_stop(drvr->bus_if); |
| 1519 | |
| 1520 | brcmf_fweh_detach(drvr); |
| 1521 | brcmf_proto_detach(drvr); |
| 1522 | |
| 1523 | if (drvr->mon_if) { |
| 1524 | brcmf_net_detach(drvr->mon_if->ndev, false); |
| 1525 | drvr->mon_if = NULL; |
| 1526 | } |
| 1527 | |
| 1528 | if (drvr->config) { |
| 1529 | brcmf_p2p_detach(&drvr->config->p2p); |
| 1530 | brcmf_cfg80211_detach(drvr->config); |
| 1531 | drvr->config = NULL; |
| 1532 | } |
| 1533 | |
| 1534 | brcmf_fwvid_detach(drvr); |
| 1535 | } |
| 1536 | |
| 1537 | void brcmf_free(struct device *dev) |
| 1538 | { |
| 1539 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1540 | struct brcmf_pub *drvr = bus_if->drvr; |
| 1541 | |
| 1542 | if (!drvr) |
| 1543 | return; |
| 1544 | |
| 1545 | bus_if->drvr = NULL; |
| 1546 | |
| 1547 | kfree(drvr->ops); |
| 1548 | |
| 1549 | wiphy_free(drvr->wiphy); |
| 1550 | } |
| 1551 | |
| 1552 | s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len) |
| 1553 | { |
| 1554 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1555 | struct brcmf_if *ifp = bus_if->drvr->iflist[0]; |
| 1556 | |
| 1557 | return brcmf_fil_iovar_data_set(ifp, name, data, len); |
| 1558 | } |
| 1559 | |
| 1560 | static int brcmf_get_pend_8021x_cnt(struct brcmf_if *ifp) |
| 1561 | { |
| 1562 | return atomic_read(&ifp->pend_8021x_cnt); |
| 1563 | } |
| 1564 | |
| 1565 | int brcmf_netdev_wait_pend8021x(struct brcmf_if *ifp) |
| 1566 | { |
| 1567 | struct brcmf_pub *drvr = ifp->drvr; |
| 1568 | int err; |
| 1569 | |
| 1570 | err = wait_event_timeout(ifp->pend_8021x_wait, |
| 1571 | !brcmf_get_pend_8021x_cnt(ifp), |
| 1572 | MAX_WAIT_FOR_8021X_TX); |
| 1573 | |
| 1574 | if (!err) { |
| 1575 | bphy_err(drvr, "Timed out waiting for no pending 802.1x packets\n"); |
| 1576 | atomic_set(&ifp->pend_8021x_cnt, 0); |
| 1577 | } |
| 1578 | |
| 1579 | return !err; |
| 1580 | } |
| 1581 | |
| 1582 | void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state) |
| 1583 | { |
| 1584 | struct brcmf_pub *drvr = bus->drvr; |
| 1585 | struct net_device *ndev; |
| 1586 | int ifidx; |
| 1587 | |
| 1588 | brcmf_dbg(TRACE, "%d -> %d\n", bus->state, state); |
| 1589 | |
| 1590 | if (!drvr) { |
| 1591 | brcmf_dbg(INFO, "ignoring transition, bus not attached yet\n"); |
| 1592 | return; |
| 1593 | } |
| 1594 | |
| 1595 | bus->state = state; |
| 1596 | |
| 1597 | if (state == BRCMF_BUS_UP) { |
| 1598 | for (ifidx = 0; ifidx < BRCMF_MAX_IFS; ifidx++) { |
| 1599 | if ((drvr->iflist[ifidx]) && |
| 1600 | (drvr->iflist[ifidx]->ndev)) { |
| 1601 | ndev = drvr->iflist[ifidx]->ndev; |
| 1602 | if (netif_queue_stopped(ndev)) |
| 1603 | netif_wake_queue(ndev); |
| 1604 | } |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | int __init brcmf_core_init(void) |
| 1610 | { |
| 1611 | int err; |
| 1612 | |
| 1613 | err = brcmf_sdio_register(); |
| 1614 | if (err) |
| 1615 | return err; |
| 1616 | |
| 1617 | err = brcmf_usb_register(); |
| 1618 | if (err) |
| 1619 | goto error_usb_register; |
| 1620 | |
| 1621 | err = brcmf_pcie_register(); |
| 1622 | if (err) |
| 1623 | goto error_pcie_register; |
| 1624 | return 0; |
| 1625 | |
| 1626 | error_pcie_register: |
| 1627 | brcmf_usb_exit(); |
| 1628 | error_usb_register: |
| 1629 | brcmf_sdio_exit(); |
| 1630 | return err; |
| 1631 | } |
| 1632 | |
| 1633 | void __exit brcmf_core_exit(void) |
| 1634 | { |
| 1635 | brcmf_sdio_exit(); |
| 1636 | brcmf_usb_exit(); |
| 1637 | brcmf_pcie_exit(); |
| 1638 | } |