| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * Copyright (c) 2015-2016 Quantenna Communications, Inc. |
|---|
| 3 | | - * All rights reserved. |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or |
|---|
| 6 | | - * modify it under the terms of the GNU General Public License |
|---|
| 7 | | - * as published by the Free Software Foundation; either version 2 |
|---|
| 8 | | - * of the License, or (at your option) any later version. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 2 | +/* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */ |
|---|
| 16 | 3 | |
|---|
| 17 | 4 | #include <linux/kernel.h> |
|---|
| 18 | 5 | #include <linux/module.h> |
|---|
| 19 | 6 | #include <linux/if_ether.h> |
|---|
| 7 | +#include <linux/nospec.h> |
|---|
| 20 | 8 | |
|---|
| 21 | 9 | #include "core.h" |
|---|
| 22 | 10 | #include "bus.h" |
|---|
| .. | .. |
|---|
| 25 | 13 | #include "cfg80211.h" |
|---|
| 26 | 14 | #include "event.h" |
|---|
| 27 | 15 | #include "util.h" |
|---|
| 16 | +#include "switchdev.h" |
|---|
| 28 | 17 | |
|---|
| 29 | | -#define QTNF_DMP_MAX_LEN 48 |
|---|
| 30 | 18 | #define QTNF_PRIMARY_VIF_IDX 0 |
|---|
| 31 | 19 | |
|---|
| 32 | | -struct qtnf_frame_meta_info { |
|---|
| 33 | | - u8 magic_s; |
|---|
| 34 | | - u8 ifidx; |
|---|
| 35 | | - u8 macid; |
|---|
| 36 | | - u8 magic_e; |
|---|
| 37 | | -} __packed; |
|---|
| 20 | +static bool slave_radar = true; |
|---|
| 21 | +module_param(slave_radar, bool, 0644); |
|---|
| 22 | +MODULE_PARM_DESC(slave_radar, "set 0 to disable radar detection in slave mode"); |
|---|
| 23 | + |
|---|
| 24 | +static bool dfs_offload; |
|---|
| 25 | +module_param(dfs_offload, bool, 0644); |
|---|
| 26 | +MODULE_PARM_DESC(dfs_offload, "set 1 to enable DFS offload to firmware"); |
|---|
| 27 | + |
|---|
| 28 | +static struct dentry *qtnf_debugfs_dir; |
|---|
| 29 | + |
|---|
| 30 | +bool qtnf_slave_radar_get(void) |
|---|
| 31 | +{ |
|---|
| 32 | + return slave_radar; |
|---|
| 33 | +} |
|---|
| 34 | + |
|---|
| 35 | +bool qtnf_dfs_offload_get(void) |
|---|
| 36 | +{ |
|---|
| 37 | + return dfs_offload; |
|---|
| 38 | +} |
|---|
| 38 | 39 | |
|---|
| 39 | 40 | struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid) |
|---|
| 40 | 41 | { |
|---|
| 41 | 42 | struct qtnf_wmac *mac = NULL; |
|---|
| 42 | 43 | |
|---|
| 43 | | - if (unlikely(macid >= QTNF_MAX_MAC)) { |
|---|
| 44 | + if (macid >= QTNF_MAX_MAC) { |
|---|
| 44 | 45 | pr_err("invalid MAC index %u\n", macid); |
|---|
| 45 | 46 | return NULL; |
|---|
| 46 | 47 | } |
|---|
| 47 | 48 | |
|---|
| 49 | + macid = array_index_nospec(macid, QTNF_MAX_MAC); |
|---|
| 48 | 50 | mac = bus->mac[macid]; |
|---|
| 49 | 51 | |
|---|
| 50 | 52 | if (unlikely(!mac)) { |
|---|
| .. | .. |
|---|
| 72 | 74 | qtnf_virtual_intf_cleanup(ndev); |
|---|
| 73 | 75 | qtnf_netdev_updown(ndev, 0); |
|---|
| 74 | 76 | return 0; |
|---|
| 77 | +} |
|---|
| 78 | + |
|---|
| 79 | +static void qtnf_packet_send_hi_pri(struct sk_buff *skb) |
|---|
| 80 | +{ |
|---|
| 81 | + struct qtnf_vif *vif = qtnf_netdev_get_priv(skb->dev); |
|---|
| 82 | + |
|---|
| 83 | + skb_queue_tail(&vif->high_pri_tx_queue, skb); |
|---|
| 84 | + queue_work(vif->mac->bus->hprio_workqueue, &vif->high_pri_tx_work); |
|---|
| 75 | 85 | } |
|---|
| 76 | 86 | |
|---|
| 77 | 87 | /* Netdev handler for data transmission. |
|---|
| .. | .. |
|---|
| 114 | 124 | /* tx path is enabled: reset vif timeout */ |
|---|
| 115 | 125 | vif->cons_tx_timeout_cnt = 0; |
|---|
| 116 | 126 | |
|---|
| 117 | | - return qtnf_bus_data_tx(mac->bus, skb); |
|---|
| 127 | + if (unlikely(skb->protocol == htons(ETH_P_PAE))) { |
|---|
| 128 | + qtnf_packet_send_hi_pri(skb); |
|---|
| 129 | + qtnf_update_tx_stats(ndev, skb); |
|---|
| 130 | + return NETDEV_TX_OK; |
|---|
| 131 | + } |
|---|
| 132 | + |
|---|
| 133 | + return qtnf_bus_data_tx(mac->bus, skb, mac->macid, vif->vifid); |
|---|
| 118 | 134 | } |
|---|
| 119 | 135 | |
|---|
| 120 | 136 | /* Netdev handler for getting stats. |
|---|
| .. | .. |
|---|
| 123 | 139 | struct rtnl_link_stats64 *stats) |
|---|
| 124 | 140 | { |
|---|
| 125 | 141 | struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev); |
|---|
| 126 | | - unsigned int start; |
|---|
| 127 | | - int cpu; |
|---|
| 128 | 142 | |
|---|
| 129 | 143 | netdev_stats_to_stats64(stats, &ndev->stats); |
|---|
| 130 | 144 | |
|---|
| 131 | 145 | if (!vif->stats64) |
|---|
| 132 | 146 | return; |
|---|
| 133 | 147 | |
|---|
| 134 | | - for_each_possible_cpu(cpu) { |
|---|
| 135 | | - struct pcpu_sw_netstats *stats64; |
|---|
| 136 | | - u64 rx_packets, rx_bytes; |
|---|
| 137 | | - u64 tx_packets, tx_bytes; |
|---|
| 138 | | - |
|---|
| 139 | | - stats64 = per_cpu_ptr(vif->stats64, cpu); |
|---|
| 140 | | - |
|---|
| 141 | | - do { |
|---|
| 142 | | - start = u64_stats_fetch_begin_irq(&stats64->syncp); |
|---|
| 143 | | - rx_packets = stats64->rx_packets; |
|---|
| 144 | | - rx_bytes = stats64->rx_bytes; |
|---|
| 145 | | - tx_packets = stats64->tx_packets; |
|---|
| 146 | | - tx_bytes = stats64->tx_bytes; |
|---|
| 147 | | - } while (u64_stats_fetch_retry_irq(&stats64->syncp, start)); |
|---|
| 148 | | - |
|---|
| 149 | | - stats->rx_packets += rx_packets; |
|---|
| 150 | | - stats->rx_bytes += rx_bytes; |
|---|
| 151 | | - stats->tx_packets += tx_packets; |
|---|
| 152 | | - stats->tx_bytes += tx_bytes; |
|---|
| 153 | | - } |
|---|
| 148 | + dev_fetch_sw_netstats(stats, vif->stats64); |
|---|
| 154 | 149 | } |
|---|
| 155 | 150 | |
|---|
| 156 | 151 | /* Netdev handler for transmission timeout. |
|---|
| 157 | 152 | */ |
|---|
| 158 | | -static void qtnf_netdev_tx_timeout(struct net_device *ndev) |
|---|
| 153 | +static void qtnf_netdev_tx_timeout(struct net_device *ndev, unsigned int txqueue) |
|---|
| 159 | 154 | { |
|---|
| 160 | 155 | struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev); |
|---|
| 161 | 156 | struct qtnf_wmac *mac; |
|---|
| .. | .. |
|---|
| 195 | 190 | qtnf_scan_done(vif->mac, true); |
|---|
| 196 | 191 | |
|---|
| 197 | 192 | ret = qtnf_cmd_send_change_intf_type(vif, vif->wdev.iftype, |
|---|
| 193 | + vif->wdev.use_4addr, |
|---|
| 198 | 194 | sa->sa_data); |
|---|
| 199 | 195 | |
|---|
| 200 | 196 | if (ret) |
|---|
| 201 | 197 | memcpy(ndev->dev_addr, old_addr, ETH_ALEN); |
|---|
| 202 | 198 | |
|---|
| 203 | 199 | return ret; |
|---|
| 200 | +} |
|---|
| 201 | + |
|---|
| 202 | +static int qtnf_netdev_port_parent_id(struct net_device *ndev, |
|---|
| 203 | + struct netdev_phys_item_id *ppid) |
|---|
| 204 | +{ |
|---|
| 205 | + const struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev); |
|---|
| 206 | + const struct qtnf_bus *bus = vif->mac->bus; |
|---|
| 207 | + |
|---|
| 208 | + ppid->id_len = sizeof(bus->hw_id); |
|---|
| 209 | + memcpy(&ppid->id, bus->hw_id, ppid->id_len); |
|---|
| 210 | + |
|---|
| 211 | + return 0; |
|---|
| 204 | 212 | } |
|---|
| 205 | 213 | |
|---|
| 206 | 214 | /* Network device ops handlers */ |
|---|
| .. | .. |
|---|
| 211 | 219 | .ndo_tx_timeout = qtnf_netdev_tx_timeout, |
|---|
| 212 | 220 | .ndo_get_stats64 = qtnf_netdev_get_stats64, |
|---|
| 213 | 221 | .ndo_set_mac_address = qtnf_netdev_set_mac_address, |
|---|
| 222 | + .ndo_get_port_parent_id = qtnf_netdev_port_parent_id, |
|---|
| 214 | 223 | }; |
|---|
| 215 | 224 | |
|---|
| 216 | 225 | static int qtnf_mac_init_single_band(struct wiphy *wiphy, |
|---|
| .. | .. |
|---|
| 380 | 389 | qtnf_mac_scan_finish(mac, true); |
|---|
| 381 | 390 | } |
|---|
| 382 | 391 | |
|---|
| 392 | +static void qtnf_vif_send_data_high_pri(struct work_struct *work) |
|---|
| 393 | +{ |
|---|
| 394 | + struct qtnf_vif *vif = |
|---|
| 395 | + container_of(work, struct qtnf_vif, high_pri_tx_work); |
|---|
| 396 | + struct sk_buff *skb; |
|---|
| 397 | + |
|---|
| 398 | + if (!vif->netdev || |
|---|
| 399 | + vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) |
|---|
| 400 | + return; |
|---|
| 401 | + |
|---|
| 402 | + while ((skb = skb_dequeue(&vif->high_pri_tx_queue))) { |
|---|
| 403 | + qtnf_cmd_send_frame(vif, 0, QLINK_FRAME_TX_FLAG_8023, |
|---|
| 404 | + 0, skb->data, skb->len); |
|---|
| 405 | + dev_kfree_skb_any(skb); |
|---|
| 406 | + } |
|---|
| 407 | +} |
|---|
| 408 | + |
|---|
| 383 | 409 | static struct qtnf_wmac *qtnf_core_mac_alloc(struct qtnf_bus *bus, |
|---|
| 384 | 410 | unsigned int macid) |
|---|
| 385 | 411 | { |
|---|
| 386 | | - struct wiphy *wiphy; |
|---|
| 412 | + struct platform_device *pdev = NULL; |
|---|
| 387 | 413 | struct qtnf_wmac *mac; |
|---|
| 414 | + struct qtnf_vif *vif; |
|---|
| 415 | + struct wiphy *wiphy; |
|---|
| 388 | 416 | unsigned int i; |
|---|
| 389 | 417 | |
|---|
| 390 | | - wiphy = qtnf_wiphy_allocate(bus); |
|---|
| 391 | | - if (!wiphy) |
|---|
| 418 | + if (bus->hw_info.num_mac > 1) { |
|---|
| 419 | + pdev = platform_device_register_data(bus->dev, |
|---|
| 420 | + dev_name(bus->dev), |
|---|
| 421 | + macid, NULL, 0); |
|---|
| 422 | + if (IS_ERR(pdev)) |
|---|
| 423 | + return ERR_PTR(-EINVAL); |
|---|
| 424 | + } |
|---|
| 425 | + |
|---|
| 426 | + wiphy = qtnf_wiphy_allocate(bus, pdev); |
|---|
| 427 | + if (!wiphy) { |
|---|
| 428 | + if (pdev) |
|---|
| 429 | + platform_device_unregister(pdev); |
|---|
| 392 | 430 | return ERR_PTR(-ENOMEM); |
|---|
| 431 | + } |
|---|
| 393 | 432 | |
|---|
| 394 | 433 | mac = wiphy_priv(wiphy); |
|---|
| 395 | 434 | |
|---|
| 396 | 435 | mac->macid = macid; |
|---|
| 436 | + mac->pdev = pdev; |
|---|
| 397 | 437 | mac->bus = bus; |
|---|
| 438 | + mutex_init(&mac->mac_lock); |
|---|
| 439 | + INIT_DELAYED_WORK(&mac->scan_timeout, qtnf_mac_scan_timeout); |
|---|
| 398 | 440 | |
|---|
| 399 | 441 | for (i = 0; i < QTNF_MAX_INTF; i++) { |
|---|
| 400 | | - memset(&mac->iflist[i], 0, sizeof(struct qtnf_vif)); |
|---|
| 401 | | - mac->iflist[i].wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; |
|---|
| 402 | | - mac->iflist[i].mac = mac; |
|---|
| 403 | | - mac->iflist[i].vifid = i; |
|---|
| 404 | | - qtnf_sta_list_init(&mac->iflist[i].sta_list); |
|---|
| 405 | | - mutex_init(&mac->mac_lock); |
|---|
| 406 | | - INIT_DELAYED_WORK(&mac->scan_timeout, qtnf_mac_scan_timeout); |
|---|
| 407 | | - mac->iflist[i].stats64 = |
|---|
| 408 | | - netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
|---|
| 409 | | - if (!mac->iflist[i].stats64) |
|---|
| 442 | + vif = &mac->iflist[i]; |
|---|
| 443 | + |
|---|
| 444 | + memset(vif, 0, sizeof(*vif)); |
|---|
| 445 | + vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; |
|---|
| 446 | + vif->mac = mac; |
|---|
| 447 | + vif->vifid = i; |
|---|
| 448 | + qtnf_sta_list_init(&vif->sta_list); |
|---|
| 449 | + INIT_WORK(&vif->high_pri_tx_work, qtnf_vif_send_data_high_pri); |
|---|
| 450 | + skb_queue_head_init(&vif->high_pri_tx_queue); |
|---|
| 451 | + vif->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
|---|
| 452 | + if (!vif->stats64) |
|---|
| 410 | 453 | pr_warn("VIF%u.%u: per cpu stats allocation failed\n", |
|---|
| 411 | 454 | macid, i); |
|---|
| 412 | 455 | } |
|---|
| .. | .. |
|---|
| 431 | 474 | |
|---|
| 432 | 475 | dev = alloc_netdev_mqs(sizeof(struct qtnf_vif *), name, |
|---|
| 433 | 476 | name_assign_type, ether_setup, 1, 1); |
|---|
| 434 | | - if (!dev) { |
|---|
| 435 | | - vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; |
|---|
| 477 | + if (!dev) |
|---|
| 436 | 478 | return -ENOMEM; |
|---|
| 437 | | - } |
|---|
| 438 | 479 | |
|---|
| 439 | 480 | vif->netdev = dev; |
|---|
| 440 | 481 | |
|---|
| .. | .. |
|---|
| 443 | 484 | dev_net_set(dev, wiphy_net(wiphy)); |
|---|
| 444 | 485 | dev->ieee80211_ptr = &vif->wdev; |
|---|
| 445 | 486 | ether_addr_copy(dev->dev_addr, vif->mac_addr); |
|---|
| 446 | | - SET_NETDEV_DEV(dev, wiphy_dev(wiphy)); |
|---|
| 447 | 487 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
|---|
| 448 | 488 | dev->watchdog_timeo = QTNF_DEF_WDOG_TIMEOUT; |
|---|
| 449 | 489 | dev->tx_queue_len = 100; |
|---|
| 450 | 490 | dev->ethtool_ops = &qtnf_ethtool_ops; |
|---|
| 451 | 491 | |
|---|
| 492 | + if (qtnf_hwcap_is_set(&mac->bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE)) |
|---|
| 493 | + dev->needed_tailroom = sizeof(struct qtnf_frame_meta_info); |
|---|
| 494 | + |
|---|
| 452 | 495 | qdev_vif = netdev_priv(dev); |
|---|
| 453 | 496 | *((void **)qdev_vif) = vif; |
|---|
| 454 | 497 | |
|---|
| 455 | | - SET_NETDEV_DEV(dev, mac->bus->dev); |
|---|
| 498 | + SET_NETDEV_DEV(dev, wiphy_dev(wiphy)); |
|---|
| 456 | 499 | |
|---|
| 457 | 500 | ret = register_netdevice(dev); |
|---|
| 458 | 501 | if (ret) { |
|---|
| 459 | 502 | free_netdev(dev); |
|---|
| 460 | | - vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; |
|---|
| 503 | + vif->netdev = NULL; |
|---|
| 461 | 504 | } |
|---|
| 462 | 505 | |
|---|
| 463 | 506 | return ret; |
|---|
| .. | .. |
|---|
| 498 | 541 | if (!wiphy->bands[band]) |
|---|
| 499 | 542 | continue; |
|---|
| 500 | 543 | |
|---|
| 544 | + kfree(wiphy->bands[band]->iftype_data); |
|---|
| 545 | + wiphy->bands[band]->n_iftype_data = 0; |
|---|
| 546 | + |
|---|
| 501 | 547 | kfree(wiphy->bands[band]->channels); |
|---|
| 502 | 548 | wiphy->bands[band]->n_channels = 0; |
|---|
| 503 | 549 | |
|---|
| .. | .. |
|---|
| 505 | 551 | wiphy->bands[band] = NULL; |
|---|
| 506 | 552 | } |
|---|
| 507 | 553 | |
|---|
| 554 | + platform_device_unregister(mac->pdev); |
|---|
| 508 | 555 | qtnf_mac_iface_comb_free(mac); |
|---|
| 509 | 556 | qtnf_mac_ext_caps_free(mac); |
|---|
| 510 | 557 | kfree(mac->macinfo.wowlan); |
|---|
| 558 | + kfree(mac->rd); |
|---|
| 559 | + mac->rd = NULL; |
|---|
| 511 | 560 | wiphy_free(wiphy); |
|---|
| 512 | 561 | bus->mac[macid] = NULL; |
|---|
| 513 | 562 | } |
|---|
| .. | .. |
|---|
| 529 | 578 | return PTR_ERR(mac); |
|---|
| 530 | 579 | } |
|---|
| 531 | 580 | |
|---|
| 532 | | - ret = qtnf_cmd_get_mac_info(mac); |
|---|
| 533 | | - if (ret) { |
|---|
| 534 | | - pr_err("MAC%u: failed to get info\n", macid); |
|---|
| 535 | | - goto error; |
|---|
| 536 | | - } |
|---|
| 537 | | - |
|---|
| 538 | 581 | vif = qtnf_mac_get_base_vif(mac); |
|---|
| 539 | 582 | if (!vif) { |
|---|
| 540 | 583 | pr_err("MAC%u: primary VIF is not ready\n", macid); |
|---|
| .. | .. |
|---|
| 542 | 585 | goto error; |
|---|
| 543 | 586 | } |
|---|
| 544 | 587 | |
|---|
| 545 | | - ret = qtnf_cmd_send_add_intf(vif, vif->wdev.iftype, vif->mac_addr); |
|---|
| 588 | + ret = qtnf_cmd_send_add_intf(vif, vif->wdev.iftype, |
|---|
| 589 | + vif->wdev.use_4addr, vif->mac_addr); |
|---|
| 546 | 590 | if (ret) { |
|---|
| 547 | 591 | pr_err("MAC%u: failed to add VIF\n", macid); |
|---|
| 548 | 592 | goto error; |
|---|
| 549 | 593 | } |
|---|
| 550 | 594 | |
|---|
| 551 | | - ret = qtnf_cmd_send_get_phy_params(mac); |
|---|
| 595 | + ret = qtnf_cmd_get_mac_info(mac); |
|---|
| 552 | 596 | if (ret) { |
|---|
| 553 | | - pr_err("MAC%u: failed to get PHY settings\n", macid); |
|---|
| 554 | | - goto error; |
|---|
| 597 | + pr_err("MAC%u: failed to get MAC info\n", macid); |
|---|
| 598 | + goto error_del_vif; |
|---|
| 555 | 599 | } |
|---|
| 600 | + |
|---|
| 601 | + /* Use MAC address of the first active radio as a unique device ID */ |
|---|
| 602 | + if (is_zero_ether_addr(mac->bus->hw_id)) |
|---|
| 603 | + ether_addr_copy(mac->bus->hw_id, mac->macaddr); |
|---|
| 556 | 604 | |
|---|
| 557 | 605 | ret = qtnf_mac_init_bands(mac); |
|---|
| 558 | 606 | if (ret) { |
|---|
| 559 | 607 | pr_err("MAC%u: failed to init bands\n", macid); |
|---|
| 560 | | - goto error; |
|---|
| 608 | + goto error_del_vif; |
|---|
| 561 | 609 | } |
|---|
| 562 | 610 | |
|---|
| 563 | 611 | ret = qtnf_wiphy_register(&bus->hw_info, mac); |
|---|
| 564 | 612 | if (ret) { |
|---|
| 565 | 613 | pr_err("MAC%u: wiphy registration failed\n", macid); |
|---|
| 566 | | - goto error; |
|---|
| 614 | + goto error_del_vif; |
|---|
| 567 | 615 | } |
|---|
| 568 | 616 | |
|---|
| 569 | 617 | mac->wiphy_registered = 1; |
|---|
| .. | .. |
|---|
| 575 | 623 | |
|---|
| 576 | 624 | if (ret) { |
|---|
| 577 | 625 | pr_err("MAC%u: failed to attach netdev\n", macid); |
|---|
| 578 | | - vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; |
|---|
| 579 | | - vif->netdev = NULL; |
|---|
| 580 | | - goto error; |
|---|
| 626 | + goto error_del_vif; |
|---|
| 627 | + } |
|---|
| 628 | + |
|---|
| 629 | + if (qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE)) { |
|---|
| 630 | + ret = qtnf_cmd_netdev_changeupper(vif, vif->netdev->ifindex); |
|---|
| 631 | + if (ret) |
|---|
| 632 | + goto error; |
|---|
| 581 | 633 | } |
|---|
| 582 | 634 | |
|---|
| 583 | 635 | pr_debug("MAC%u initialized\n", macid); |
|---|
| 584 | 636 | |
|---|
| 585 | 637 | return 0; |
|---|
| 586 | 638 | |
|---|
| 639 | +error_del_vif: |
|---|
| 640 | + qtnf_cmd_send_del_intf(vif); |
|---|
| 641 | + vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; |
|---|
| 587 | 642 | error: |
|---|
| 588 | 643 | qtnf_core_mac_detach(bus, macid); |
|---|
| 589 | 644 | return ret; |
|---|
| 645 | +} |
|---|
| 646 | + |
|---|
| 647 | +bool qtnf_netdev_is_qtn(const struct net_device *ndev) |
|---|
| 648 | +{ |
|---|
| 649 | + return ndev->netdev_ops == &qtnf_netdev_ops; |
|---|
| 650 | +} |
|---|
| 651 | + |
|---|
| 652 | +static int qtnf_check_br_ports(struct net_device *dev, |
|---|
| 653 | + struct netdev_nested_priv *priv) |
|---|
| 654 | +{ |
|---|
| 655 | + struct net_device *ndev = (struct net_device *)priv->data; |
|---|
| 656 | + |
|---|
| 657 | + if (dev != ndev && netdev_port_same_parent_id(dev, ndev)) |
|---|
| 658 | + return -ENOTSUPP; |
|---|
| 659 | + |
|---|
| 660 | + return 0; |
|---|
| 661 | +} |
|---|
| 662 | + |
|---|
| 663 | +static int qtnf_core_netdevice_event(struct notifier_block *nb, |
|---|
| 664 | + unsigned long event, void *ptr) |
|---|
| 665 | +{ |
|---|
| 666 | + struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
|---|
| 667 | + const struct netdev_notifier_changeupper_info *info; |
|---|
| 668 | + struct netdev_nested_priv priv = { |
|---|
| 669 | + .data = (void *)ndev, |
|---|
| 670 | + }; |
|---|
| 671 | + struct net_device *brdev; |
|---|
| 672 | + struct qtnf_vif *vif; |
|---|
| 673 | + struct qtnf_bus *bus; |
|---|
| 674 | + int br_domain; |
|---|
| 675 | + int ret = 0; |
|---|
| 676 | + |
|---|
| 677 | + if (!qtnf_netdev_is_qtn(ndev)) |
|---|
| 678 | + return NOTIFY_DONE; |
|---|
| 679 | + |
|---|
| 680 | + if (!net_eq(dev_net(ndev), &init_net)) |
|---|
| 681 | + return NOTIFY_OK; |
|---|
| 682 | + |
|---|
| 683 | + vif = qtnf_netdev_get_priv(ndev); |
|---|
| 684 | + bus = vif->mac->bus; |
|---|
| 685 | + |
|---|
| 686 | + switch (event) { |
|---|
| 687 | + case NETDEV_CHANGEUPPER: |
|---|
| 688 | + info = ptr; |
|---|
| 689 | + brdev = info->upper_dev; |
|---|
| 690 | + |
|---|
| 691 | + if (!netif_is_bridge_master(brdev)) |
|---|
| 692 | + break; |
|---|
| 693 | + |
|---|
| 694 | + pr_debug("[VIF%u.%u] change bridge: %s %s\n", |
|---|
| 695 | + vif->mac->macid, vif->vifid, netdev_name(brdev), |
|---|
| 696 | + info->linking ? "add" : "del"); |
|---|
| 697 | + |
|---|
| 698 | + if (IS_ENABLED(CONFIG_NET_SWITCHDEV) && |
|---|
| 699 | + qtnf_hwcap_is_set(&bus->hw_info, |
|---|
| 700 | + QLINK_HW_CAPAB_HW_BRIDGE)) { |
|---|
| 701 | + if (info->linking) |
|---|
| 702 | + br_domain = brdev->ifindex; |
|---|
| 703 | + else |
|---|
| 704 | + br_domain = ndev->ifindex; |
|---|
| 705 | + |
|---|
| 706 | + ret = qtnf_cmd_netdev_changeupper(vif, br_domain); |
|---|
| 707 | + } else { |
|---|
| 708 | + ret = netdev_walk_all_lower_dev(brdev, |
|---|
| 709 | + qtnf_check_br_ports, |
|---|
| 710 | + &priv); |
|---|
| 711 | + } |
|---|
| 712 | + |
|---|
| 713 | + break; |
|---|
| 714 | + default: |
|---|
| 715 | + break; |
|---|
| 716 | + } |
|---|
| 717 | + |
|---|
| 718 | + return notifier_from_errno(ret); |
|---|
| 590 | 719 | } |
|---|
| 591 | 720 | |
|---|
| 592 | 721 | int qtnf_core_attach(struct qtnf_bus *bus) |
|---|
| .. | .. |
|---|
| 595 | 724 | int ret; |
|---|
| 596 | 725 | |
|---|
| 597 | 726 | qtnf_trans_init(bus); |
|---|
| 598 | | - |
|---|
| 599 | | - bus->fw_state = QTNF_FW_STATE_BOOT_DONE; |
|---|
| 600 | 727 | qtnf_bus_data_rx_start(bus); |
|---|
| 601 | 728 | |
|---|
| 602 | 729 | bus->workqueue = alloc_ordered_workqueue("QTNF_BUS", 0); |
|---|
| 603 | 730 | if (!bus->workqueue) { |
|---|
| 604 | 731 | pr_err("failed to alloc main workqueue\n"); |
|---|
| 732 | + ret = -ENOMEM; |
|---|
| 733 | + goto error; |
|---|
| 734 | + } |
|---|
| 735 | + |
|---|
| 736 | + bus->hprio_workqueue = alloc_workqueue("QTNF_HPRI", WQ_HIGHPRI, 0); |
|---|
| 737 | + if (!bus->hprio_workqueue) { |
|---|
| 738 | + pr_err("failed to alloc high prio workqueue\n"); |
|---|
| 605 | 739 | ret = -ENOMEM; |
|---|
| 606 | 740 | goto error; |
|---|
| 607 | 741 | } |
|---|
| .. | .. |
|---|
| 614 | 748 | goto error; |
|---|
| 615 | 749 | } |
|---|
| 616 | 750 | |
|---|
| 617 | | - bus->fw_state = QTNF_FW_STATE_ACTIVE; |
|---|
| 751 | + if (QLINK_VER_MAJOR(bus->hw_info.ql_proto_ver) != |
|---|
| 752 | + QLINK_PROTO_VER_MAJOR) { |
|---|
| 753 | + pr_err("qlink driver vs FW version mismatch: %u vs %u\n", |
|---|
| 754 | + QLINK_PROTO_VER_MAJOR, |
|---|
| 755 | + QLINK_VER_MAJOR(bus->hw_info.ql_proto_ver)); |
|---|
| 756 | + ret = -EPROTONOSUPPORT; |
|---|
| 757 | + goto error; |
|---|
| 758 | + } |
|---|
| 618 | 759 | |
|---|
| 760 | + bus->fw_state = QTNF_FW_STATE_ACTIVE; |
|---|
| 619 | 761 | ret = qtnf_cmd_get_hw_info(bus); |
|---|
| 620 | 762 | if (ret) { |
|---|
| 621 | 763 | pr_err("failed to get HW info: %d\n", ret); |
|---|
| 622 | 764 | goto error; |
|---|
| 623 | 765 | } |
|---|
| 624 | 766 | |
|---|
| 625 | | - if (bus->hw_info.ql_proto_ver != QLINK_PROTO_VER) { |
|---|
| 626 | | - pr_err("qlink version mismatch %u != %u\n", |
|---|
| 627 | | - QLINK_PROTO_VER, bus->hw_info.ql_proto_ver); |
|---|
| 628 | | - ret = -EPROTONOSUPPORT; |
|---|
| 629 | | - goto error; |
|---|
| 630 | | - } |
|---|
| 767 | + if (qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE) && |
|---|
| 768 | + bus->bus_ops->data_tx_use_meta_set) |
|---|
| 769 | + bus->bus_ops->data_tx_use_meta_set(bus, true); |
|---|
| 631 | 770 | |
|---|
| 632 | 771 | if (bus->hw_info.num_mac > QTNF_MAX_MAC) { |
|---|
| 633 | 772 | pr_err("no support for number of MACs=%u\n", |
|---|
| .. | .. |
|---|
| 645 | 784 | } |
|---|
| 646 | 785 | } |
|---|
| 647 | 786 | |
|---|
| 787 | + bus->netdev_nb.notifier_call = qtnf_core_netdevice_event; |
|---|
| 788 | + ret = register_netdevice_notifier(&bus->netdev_nb); |
|---|
| 789 | + if (ret) { |
|---|
| 790 | + pr_err("failed to register netdev notifier: %d\n", ret); |
|---|
| 791 | + goto error; |
|---|
| 792 | + } |
|---|
| 793 | + |
|---|
| 794 | + bus->fw_state = QTNF_FW_STATE_RUNNING; |
|---|
| 648 | 795 | return 0; |
|---|
| 649 | 796 | |
|---|
| 650 | 797 | error: |
|---|
| 651 | 798 | qtnf_core_detach(bus); |
|---|
| 652 | | - |
|---|
| 653 | 799 | return ret; |
|---|
| 654 | 800 | } |
|---|
| 655 | 801 | EXPORT_SYMBOL_GPL(qtnf_core_attach); |
|---|
| .. | .. |
|---|
| 658 | 804 | { |
|---|
| 659 | 805 | unsigned int macid; |
|---|
| 660 | 806 | |
|---|
| 807 | + unregister_netdevice_notifier(&bus->netdev_nb); |
|---|
| 661 | 808 | qtnf_bus_data_rx_stop(bus); |
|---|
| 662 | 809 | |
|---|
| 663 | 810 | for (macid = 0; macid < QTNF_MAX_MAC; macid++) |
|---|
| 664 | 811 | qtnf_core_mac_detach(bus, macid); |
|---|
| 665 | 812 | |
|---|
| 666 | | - if (bus->fw_state == QTNF_FW_STATE_ACTIVE) |
|---|
| 813 | + if (qtnf_fw_is_up(bus)) |
|---|
| 667 | 814 | qtnf_cmd_send_deinit_fw(bus); |
|---|
| 668 | 815 | |
|---|
| 669 | 816 | bus->fw_state = QTNF_FW_STATE_DETACHED; |
|---|
| .. | .. |
|---|
| 671 | 818 | if (bus->workqueue) { |
|---|
| 672 | 819 | flush_workqueue(bus->workqueue); |
|---|
| 673 | 820 | destroy_workqueue(bus->workqueue); |
|---|
| 821 | + bus->workqueue = NULL; |
|---|
| 674 | 822 | } |
|---|
| 675 | 823 | |
|---|
| 676 | | - kfree(bus->hw_info.rd); |
|---|
| 677 | | - bus->hw_info.rd = NULL; |
|---|
| 824 | + if (bus->hprio_workqueue) { |
|---|
| 825 | + flush_workqueue(bus->hprio_workqueue); |
|---|
| 826 | + destroy_workqueue(bus->hprio_workqueue); |
|---|
| 827 | + bus->hprio_workqueue = NULL; |
|---|
| 828 | + } |
|---|
| 678 | 829 | |
|---|
| 679 | 830 | qtnf_trans_free(bus); |
|---|
| 680 | 831 | } |
|---|
| .. | .. |
|---|
| 682 | 833 | |
|---|
| 683 | 834 | static inline int qtnf_is_frame_meta_magic_valid(struct qtnf_frame_meta_info *m) |
|---|
| 684 | 835 | { |
|---|
| 685 | | - return m->magic_s == 0xAB && m->magic_e == 0xBA; |
|---|
| 836 | + return m->magic_s == HBM_FRAME_META_MAGIC_PATTERN_S && |
|---|
| 837 | + m->magic_e == HBM_FRAME_META_MAGIC_PATTERN_E; |
|---|
| 686 | 838 | } |
|---|
| 687 | 839 | |
|---|
| 688 | 840 | struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb) |
|---|
| .. | .. |
|---|
| 691 | 843 | struct net_device *ndev = NULL; |
|---|
| 692 | 844 | struct qtnf_wmac *mac; |
|---|
| 693 | 845 | struct qtnf_vif *vif; |
|---|
| 846 | + |
|---|
| 847 | + if (unlikely(bus->fw_state != QTNF_FW_STATE_RUNNING)) |
|---|
| 848 | + return NULL; |
|---|
| 694 | 849 | |
|---|
| 695 | 850 | meta = (struct qtnf_frame_meta_info *) |
|---|
| 696 | 851 | (skb_tail_pointer(skb) - sizeof(*meta)); |
|---|
| .. | .. |
|---|
| 734 | 889 | } |
|---|
| 735 | 890 | |
|---|
| 736 | 891 | __skb_trim(skb, skb->len - sizeof(*meta)); |
|---|
| 892 | + /* Firmware always handles packets that require flooding */ |
|---|
| 893 | + qtnfmac_switch_mark_skb_flooded(skb); |
|---|
| 737 | 894 | |
|---|
| 738 | 895 | out: |
|---|
| 739 | 896 | return ndev; |
|---|
| .. | .. |
|---|
| 807 | 964 | } |
|---|
| 808 | 965 | EXPORT_SYMBOL_GPL(qtnf_update_tx_stats); |
|---|
| 809 | 966 | |
|---|
| 967 | +struct dentry *qtnf_get_debugfs_dir(void) |
|---|
| 968 | +{ |
|---|
| 969 | + return qtnf_debugfs_dir; |
|---|
| 970 | +} |
|---|
| 971 | +EXPORT_SYMBOL_GPL(qtnf_get_debugfs_dir); |
|---|
| 972 | + |
|---|
| 973 | +static int __init qtnf_core_register(void) |
|---|
| 974 | +{ |
|---|
| 975 | + qtnf_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); |
|---|
| 976 | + |
|---|
| 977 | + if (IS_ERR(qtnf_debugfs_dir)) |
|---|
| 978 | + qtnf_debugfs_dir = NULL; |
|---|
| 979 | + |
|---|
| 980 | + return 0; |
|---|
| 981 | +} |
|---|
| 982 | + |
|---|
| 983 | +static void __exit qtnf_core_exit(void) |
|---|
| 984 | +{ |
|---|
| 985 | + debugfs_remove(qtnf_debugfs_dir); |
|---|
| 986 | +} |
|---|
| 987 | + |
|---|
| 988 | +module_init(qtnf_core_register); |
|---|
| 989 | +module_exit(qtnf_core_exit); |
|---|
| 990 | + |
|---|
| 810 | 991 | MODULE_AUTHOR("Quantenna Communications"); |
|---|
| 811 | 992 | MODULE_DESCRIPTION("Quantenna 802.11 wireless LAN FullMAC driver."); |
|---|
| 812 | 993 | MODULE_LICENSE("GPL"); |
|---|