1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/if_ether.h>
7 #include <linux/nospec.h>
16 #include "switchdev.h"
18 #define QTNF_PRIMARY_VIF_IDX 0
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");
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");
28 static struct dentry *qtnf_debugfs_dir;
30 bool qtnf_slave_radar_get(void)
35 bool qtnf_dfs_offload_get(void)
40 struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid)
42 struct qtnf_wmac *mac = NULL;
44 if (macid >= QTNF_MAX_MAC) {
45 pr_err("invalid MAC index %u\n", macid);
49 macid = array_index_nospec(macid, QTNF_MAX_MAC);
50 mac = bus->mac[macid];
53 pr_err("MAC%u: not initialized\n", macid);
60 /* Netdev handler for open.
62 static int qtnf_netdev_open(struct net_device *ndev)
64 netif_carrier_off(ndev);
65 qtnf_netdev_updown(ndev, 1);
69 /* Netdev handler for close.
71 static int qtnf_netdev_close(struct net_device *ndev)
73 netif_carrier_off(ndev);
74 qtnf_virtual_intf_cleanup(ndev);
75 qtnf_netdev_updown(ndev, 0);
79 static void qtnf_packet_send_hi_pri(struct sk_buff *skb)
81 struct qtnf_vif *vif = qtnf_netdev_get_priv(skb->dev);
83 skb_queue_tail(&vif->high_pri_tx_queue, skb);
84 queue_work(vif->mac->bus->hprio_workqueue, &vif->high_pri_tx_work);
87 /* Netdev handler for data transmission.
90 qtnf_netdev_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
93 struct qtnf_wmac *mac;
95 vif = qtnf_netdev_get_priv(ndev);
97 if (unlikely(skb->dev != ndev)) {
98 pr_err_ratelimited("invalid skb->dev");
99 dev_kfree_skb_any(skb);
103 if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
104 pr_err_ratelimited("%s: VIF not initialized\n", ndev->name);
105 dev_kfree_skb_any(skb);
110 if (unlikely(!mac)) {
111 pr_err_ratelimited("%s: NULL mac pointer", ndev->name);
112 dev_kfree_skb_any(skb);
116 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
117 pr_err_ratelimited("%s: invalid skb len %d\n", ndev->name,
119 dev_kfree_skb_any(skb);
120 ndev->stats.tx_dropped++;
124 /* tx path is enabled: reset vif timeout */
125 vif->cons_tx_timeout_cnt = 0;
127 if (unlikely(skb->protocol == htons(ETH_P_PAE))) {
128 qtnf_packet_send_hi_pri(skb);
129 qtnf_update_tx_stats(ndev, skb);
133 return qtnf_bus_data_tx(mac->bus, skb, mac->macid, vif->vifid);
136 /* Netdev handler for getting stats.
138 static void qtnf_netdev_get_stats64(struct net_device *ndev,
139 struct rtnl_link_stats64 *stats)
141 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
145 netdev_stats_to_stats64(stats, &ndev->stats);
150 for_each_possible_cpu(cpu) {
151 struct pcpu_sw_netstats *stats64;
152 u64 rx_packets, rx_bytes;
153 u64 tx_packets, tx_bytes;
155 stats64 = per_cpu_ptr(vif->stats64, cpu);
158 start = u64_stats_fetch_begin_irq(&stats64->syncp);
159 rx_packets = stats64->rx_packets;
160 rx_bytes = stats64->rx_bytes;
161 tx_packets = stats64->tx_packets;
162 tx_bytes = stats64->tx_bytes;
163 } while (u64_stats_fetch_retry_irq(&stats64->syncp, start));
165 stats->rx_packets += rx_packets;
166 stats->rx_bytes += rx_bytes;
167 stats->tx_packets += tx_packets;
168 stats->tx_bytes += tx_bytes;
172 /* Netdev handler for transmission timeout.
174 static void qtnf_netdev_tx_timeout(struct net_device *ndev, unsigned int txqueue)
176 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
177 struct qtnf_wmac *mac;
178 struct qtnf_bus *bus;
180 if (unlikely(!vif || !vif->mac || !vif->mac->bus))
186 pr_warn("VIF%u.%u: Tx timeout- %lu\n", mac->macid, vif->vifid, jiffies);
188 qtnf_bus_data_tx_timeout(bus, ndev);
189 ndev->stats.tx_errors++;
191 if (++vif->cons_tx_timeout_cnt > QTNF_TX_TIMEOUT_TRSHLD) {
192 pr_err("Tx timeout threshold exceeded !\n");
193 pr_err("schedule interface %s reset !\n", netdev_name(ndev));
194 queue_work(bus->workqueue, &vif->reset_work);
198 static int qtnf_netdev_set_mac_address(struct net_device *ndev, void *addr)
200 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
201 struct sockaddr *sa = addr;
203 unsigned char old_addr[ETH_ALEN];
205 memcpy(old_addr, sa->sa_data, sizeof(old_addr));
207 ret = eth_mac_addr(ndev, sa);
211 qtnf_scan_done(vif->mac, true);
213 ret = qtnf_cmd_send_change_intf_type(vif, vif->wdev.iftype,
218 memcpy(ndev->dev_addr, old_addr, ETH_ALEN);
223 static int qtnf_netdev_port_parent_id(struct net_device *ndev,
224 struct netdev_phys_item_id *ppid)
226 const struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
227 const struct qtnf_bus *bus = vif->mac->bus;
229 ppid->id_len = sizeof(bus->hw_id);
230 memcpy(&ppid->id, bus->hw_id, ppid->id_len);
235 /* Network device ops handlers */
236 const struct net_device_ops qtnf_netdev_ops = {
237 .ndo_open = qtnf_netdev_open,
238 .ndo_stop = qtnf_netdev_close,
239 .ndo_start_xmit = qtnf_netdev_hard_start_xmit,
240 .ndo_tx_timeout = qtnf_netdev_tx_timeout,
241 .ndo_get_stats64 = qtnf_netdev_get_stats64,
242 .ndo_set_mac_address = qtnf_netdev_set_mac_address,
243 .ndo_get_port_parent_id = qtnf_netdev_port_parent_id,
246 static int qtnf_mac_init_single_band(struct wiphy *wiphy,
247 struct qtnf_wmac *mac,
248 enum nl80211_band band)
252 wiphy->bands[band] = kzalloc(sizeof(*wiphy->bands[band]), GFP_KERNEL);
253 if (!wiphy->bands[band])
256 wiphy->bands[band]->band = band;
258 ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
260 pr_err("MAC%u: band %u: failed to get chans info: %d\n",
261 mac->macid, band, ret);
265 qtnf_band_init_rates(wiphy->bands[band]);
270 static int qtnf_mac_init_bands(struct qtnf_wmac *mac)
272 struct wiphy *wiphy = priv_to_wiphy(mac);
275 if (mac->macinfo.bands_cap & QLINK_BAND_2GHZ) {
276 ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_2GHZ);
281 if (mac->macinfo.bands_cap & QLINK_BAND_5GHZ) {
282 ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_5GHZ);
287 if (mac->macinfo.bands_cap & QLINK_BAND_60GHZ)
288 ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_60GHZ);
294 struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac)
296 struct qtnf_vif *vif;
299 for (i = 0; i < QTNF_MAX_INTF; i++) {
300 vif = &mac->iflist[i];
301 if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
308 struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac)
310 struct qtnf_vif *vif;
312 vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
314 if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
320 void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac)
322 struct ieee80211_iface_combination *comb;
325 if (mac->macinfo.if_comb) {
326 for (i = 0; i < mac->macinfo.n_if_comb; i++) {
327 comb = &mac->macinfo.if_comb[i];
332 kfree(mac->macinfo.if_comb);
333 mac->macinfo.if_comb = NULL;
337 void qtnf_mac_ext_caps_free(struct qtnf_wmac *mac)
339 if (mac->macinfo.extended_capabilities_len) {
340 kfree(mac->macinfo.extended_capabilities);
341 mac->macinfo.extended_capabilities = NULL;
343 kfree(mac->macinfo.extended_capabilities_mask);
344 mac->macinfo.extended_capabilities_mask = NULL;
346 mac->macinfo.extended_capabilities_len = 0;
350 static void qtnf_vif_reset_handler(struct work_struct *work)
352 struct qtnf_vif *vif = container_of(work, struct qtnf_vif, reset_work);
356 if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
361 /* stop tx completely */
362 netif_tx_stop_all_queues(vif->netdev);
363 if (netif_carrier_ok(vif->netdev))
364 netif_carrier_off(vif->netdev);
366 qtnf_cfg80211_vif_reset(vif);
371 static void qtnf_mac_init_primary_intf(struct qtnf_wmac *mac)
373 struct qtnf_vif *vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
375 vif->wdev.iftype = NL80211_IFTYPE_STATION;
376 vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
377 vif->wdev.wiphy = priv_to_wiphy(mac);
378 INIT_WORK(&vif->reset_work, qtnf_vif_reset_handler);
379 vif->cons_tx_timeout_cnt = 0;
382 static void qtnf_mac_scan_finish(struct qtnf_wmac *mac, bool aborted)
384 struct cfg80211_scan_info info = {
388 mutex_lock(&mac->mac_lock);
391 cfg80211_scan_done(mac->scan_req, &info);
392 mac->scan_req = NULL;
395 mutex_unlock(&mac->mac_lock);
398 void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted)
400 cancel_delayed_work_sync(&mac->scan_timeout);
401 qtnf_mac_scan_finish(mac, aborted);
404 static void qtnf_mac_scan_timeout(struct work_struct *work)
406 struct qtnf_wmac *mac =
407 container_of(work, struct qtnf_wmac, scan_timeout.work);
409 pr_warn("MAC%d: scan timed out\n", mac->macid);
410 qtnf_mac_scan_finish(mac, true);
413 static void qtnf_vif_send_data_high_pri(struct work_struct *work)
415 struct qtnf_vif *vif =
416 container_of(work, struct qtnf_vif, high_pri_tx_work);
420 vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
423 while ((skb = skb_dequeue(&vif->high_pri_tx_queue))) {
424 qtnf_cmd_send_frame(vif, 0, QLINK_FRAME_TX_FLAG_8023,
425 0, skb->data, skb->len);
426 dev_kfree_skb_any(skb);
430 static struct qtnf_wmac *qtnf_core_mac_alloc(struct qtnf_bus *bus,
433 struct platform_device *pdev = NULL;
434 struct qtnf_wmac *mac;
435 struct qtnf_vif *vif;
439 if (bus->hw_info.num_mac > 1) {
440 pdev = platform_device_register_data(bus->dev,
444 return ERR_PTR(-EINVAL);
447 wiphy = qtnf_wiphy_allocate(bus, pdev);
450 platform_device_unregister(pdev);
451 return ERR_PTR(-ENOMEM);
454 mac = wiphy_priv(wiphy);
459 mutex_init(&mac->mac_lock);
460 INIT_DELAYED_WORK(&mac->scan_timeout, qtnf_mac_scan_timeout);
462 for (i = 0; i < QTNF_MAX_INTF; i++) {
463 vif = &mac->iflist[i];
465 memset(vif, 0, sizeof(*vif));
466 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
469 qtnf_sta_list_init(&vif->sta_list);
470 INIT_WORK(&vif->high_pri_tx_work, qtnf_vif_send_data_high_pri);
471 skb_queue_head_init(&vif->high_pri_tx_queue);
472 vif->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
474 pr_warn("VIF%u.%u: per cpu stats allocation failed\n",
478 qtnf_mac_init_primary_intf(mac);
479 bus->mac[macid] = mac;
484 static const struct ethtool_ops qtnf_ethtool_ops = {
485 .get_drvinfo = cfg80211_get_drvinfo,
488 int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *vif,
489 const char *name, unsigned char name_assign_type)
491 struct wiphy *wiphy = priv_to_wiphy(mac);
492 struct net_device *dev;
496 dev = alloc_netdev_mqs(sizeof(struct qtnf_vif *), name,
497 name_assign_type, ether_setup, 1, 1);
503 dev->netdev_ops = &qtnf_netdev_ops;
504 dev->needs_free_netdev = true;
505 dev_net_set(dev, wiphy_net(wiphy));
506 dev->ieee80211_ptr = &vif->wdev;
507 ether_addr_copy(dev->dev_addr, vif->mac_addr);
508 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
509 dev->watchdog_timeo = QTNF_DEF_WDOG_TIMEOUT;
510 dev->tx_queue_len = 100;
511 dev->ethtool_ops = &qtnf_ethtool_ops;
513 if (qtnf_hwcap_is_set(&mac->bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE))
514 dev->needed_tailroom = sizeof(struct qtnf_frame_meta_info);
516 qdev_vif = netdev_priv(dev);
517 *((void **)qdev_vif) = vif;
519 SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
521 ret = register_netdevice(dev);
530 static void qtnf_core_mac_detach(struct qtnf_bus *bus, unsigned int macid)
532 struct qtnf_wmac *mac;
534 struct qtnf_vif *vif;
536 enum nl80211_band band;
538 mac = bus->mac[macid];
543 wiphy = priv_to_wiphy(mac);
545 for (i = 0; i < QTNF_MAX_INTF; i++) {
546 vif = &mac->iflist[i];
549 vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED) {
550 qtnf_virtual_intf_cleanup(vif->netdev);
551 qtnf_del_virtual_intf(wiphy, &vif->wdev);
554 qtnf_sta_list_free(&vif->sta_list);
555 free_percpu(vif->stats64);
558 if (mac->wiphy_registered)
559 wiphy_unregister(wiphy);
561 for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; ++band) {
562 if (!wiphy->bands[band])
565 kfree(wiphy->bands[band]->iftype_data);
566 wiphy->bands[band]->n_iftype_data = 0;
568 kfree(wiphy->bands[band]->channels);
569 wiphy->bands[band]->n_channels = 0;
571 kfree(wiphy->bands[band]);
572 wiphy->bands[band] = NULL;
575 platform_device_unregister(mac->pdev);
576 qtnf_mac_iface_comb_free(mac);
577 qtnf_mac_ext_caps_free(mac);
578 kfree(mac->macinfo.wowlan);
582 bus->mac[macid] = NULL;
585 static int qtnf_core_mac_attach(struct qtnf_bus *bus, unsigned int macid)
587 struct qtnf_wmac *mac;
588 struct qtnf_vif *vif;
591 if (!(bus->hw_info.mac_bitmap & BIT(macid))) {
592 pr_info("MAC%u is not active in FW\n", macid);
596 mac = qtnf_core_mac_alloc(bus, macid);
598 pr_err("MAC%u allocation failed\n", macid);
602 vif = qtnf_mac_get_base_vif(mac);
604 pr_err("MAC%u: primary VIF is not ready\n", macid);
609 ret = qtnf_cmd_send_add_intf(vif, vif->wdev.iftype,
610 vif->wdev.use_4addr, vif->mac_addr);
612 pr_err("MAC%u: failed to add VIF\n", macid);
616 ret = qtnf_cmd_get_mac_info(mac);
618 pr_err("MAC%u: failed to get MAC info\n", macid);
622 /* Use MAC address of the first active radio as a unique device ID */
623 if (is_zero_ether_addr(mac->bus->hw_id))
624 ether_addr_copy(mac->bus->hw_id, mac->macaddr);
626 ret = qtnf_mac_init_bands(mac);
628 pr_err("MAC%u: failed to init bands\n", macid);
632 ret = qtnf_wiphy_register(&bus->hw_info, mac);
634 pr_err("MAC%u: wiphy registration failed\n", macid);
638 mac->wiphy_registered = 1;
642 ret = qtnf_core_net_attach(mac, vif, "wlan%d", NET_NAME_ENUM);
646 pr_err("MAC%u: failed to attach netdev\n", macid);
650 if (qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE)) {
651 ret = qtnf_cmd_netdev_changeupper(vif, vif->netdev->ifindex);
656 pr_debug("MAC%u initialized\n", macid);
661 qtnf_cmd_send_del_intf(vif);
662 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
664 qtnf_core_mac_detach(bus, macid);
668 bool qtnf_netdev_is_qtn(const struct net_device *ndev)
670 return ndev->netdev_ops == &qtnf_netdev_ops;
673 static int qtnf_check_br_ports(struct net_device *dev,
674 struct netdev_nested_priv *priv)
676 struct net_device *ndev = (struct net_device *)priv->data;
678 if (dev != ndev && netdev_port_same_parent_id(dev, ndev))
684 static int qtnf_core_netdevice_event(struct notifier_block *nb,
685 unsigned long event, void *ptr)
687 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
688 const struct netdev_notifier_changeupper_info *info;
689 struct netdev_nested_priv priv = {
690 .data = (void *)ndev,
692 struct net_device *brdev;
693 struct qtnf_vif *vif;
694 struct qtnf_bus *bus;
698 if (!qtnf_netdev_is_qtn(ndev))
701 if (!net_eq(dev_net(ndev), &init_net))
704 vif = qtnf_netdev_get_priv(ndev);
708 case NETDEV_CHANGEUPPER:
710 brdev = info->upper_dev;
712 if (!netif_is_bridge_master(brdev))
715 pr_debug("[VIF%u.%u] change bridge: %s %s\n",
716 vif->mac->macid, vif->vifid, netdev_name(brdev),
717 info->linking ? "add" : "del");
719 if (IS_ENABLED(CONFIG_NET_SWITCHDEV) &&
720 qtnf_hwcap_is_set(&bus->hw_info,
721 QLINK_HW_CAPAB_HW_BRIDGE)) {
723 br_domain = brdev->ifindex;
725 br_domain = ndev->ifindex;
727 ret = qtnf_cmd_netdev_changeupper(vif, br_domain);
729 ret = netdev_walk_all_lower_dev(brdev,
739 return notifier_from_errno(ret);
742 int qtnf_core_attach(struct qtnf_bus *bus)
747 qtnf_trans_init(bus);
748 qtnf_bus_data_rx_start(bus);
750 bus->workqueue = alloc_ordered_workqueue("QTNF_BUS", 0);
751 if (!bus->workqueue) {
752 pr_err("failed to alloc main workqueue\n");
757 bus->hprio_workqueue = alloc_workqueue("QTNF_HPRI", WQ_HIGHPRI, 0);
758 if (!bus->hprio_workqueue) {
759 pr_err("failed to alloc high prio workqueue\n");
764 INIT_WORK(&bus->event_work, qtnf_event_work_handler);
766 ret = qtnf_cmd_send_init_fw(bus);
768 pr_err("failed to init FW: %d\n", ret);
772 if (QLINK_VER_MAJOR(bus->hw_info.ql_proto_ver) !=
773 QLINK_PROTO_VER_MAJOR) {
774 pr_err("qlink driver vs FW version mismatch: %u vs %u\n",
775 QLINK_PROTO_VER_MAJOR,
776 QLINK_VER_MAJOR(bus->hw_info.ql_proto_ver));
777 ret = -EPROTONOSUPPORT;
781 bus->fw_state = QTNF_FW_STATE_ACTIVE;
782 ret = qtnf_cmd_get_hw_info(bus);
784 pr_err("failed to get HW info: %d\n", ret);
788 if (qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE) &&
789 bus->bus_ops->data_tx_use_meta_set)
790 bus->bus_ops->data_tx_use_meta_set(bus, true);
792 if (bus->hw_info.num_mac > QTNF_MAX_MAC) {
793 pr_err("no support for number of MACs=%u\n",
794 bus->hw_info.num_mac);
799 for (i = 0; i < bus->hw_info.num_mac; i++) {
800 ret = qtnf_core_mac_attach(bus, i);
803 pr_err("MAC%u: attach failed: %d\n", i, ret);
808 bus->netdev_nb.notifier_call = qtnf_core_netdevice_event;
809 ret = register_netdevice_notifier(&bus->netdev_nb);
811 pr_err("failed to register netdev notifier: %d\n", ret);
815 bus->fw_state = QTNF_FW_STATE_RUNNING;
819 qtnf_core_detach(bus);
822 EXPORT_SYMBOL_GPL(qtnf_core_attach);
824 void qtnf_core_detach(struct qtnf_bus *bus)
828 unregister_netdevice_notifier(&bus->netdev_nb);
829 qtnf_bus_data_rx_stop(bus);
831 for (macid = 0; macid < QTNF_MAX_MAC; macid++)
832 qtnf_core_mac_detach(bus, macid);
834 if (qtnf_fw_is_up(bus))
835 qtnf_cmd_send_deinit_fw(bus);
837 bus->fw_state = QTNF_FW_STATE_DETACHED;
839 if (bus->workqueue) {
840 flush_workqueue(bus->workqueue);
841 destroy_workqueue(bus->workqueue);
842 bus->workqueue = NULL;
845 if (bus->hprio_workqueue) {
846 flush_workqueue(bus->hprio_workqueue);
847 destroy_workqueue(bus->hprio_workqueue);
848 bus->hprio_workqueue = NULL;
851 qtnf_trans_free(bus);
853 EXPORT_SYMBOL_GPL(qtnf_core_detach);
855 static inline int qtnf_is_frame_meta_magic_valid(struct qtnf_frame_meta_info *m)
857 return m->magic_s == HBM_FRAME_META_MAGIC_PATTERN_S &&
858 m->magic_e == HBM_FRAME_META_MAGIC_PATTERN_E;
861 struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb)
863 struct qtnf_frame_meta_info *meta;
864 struct net_device *ndev = NULL;
865 struct qtnf_wmac *mac;
866 struct qtnf_vif *vif;
868 if (unlikely(bus->fw_state != QTNF_FW_STATE_RUNNING))
871 meta = (struct qtnf_frame_meta_info *)
872 (skb_tail_pointer(skb) - sizeof(*meta));
874 if (unlikely(!qtnf_is_frame_meta_magic_valid(meta))) {
875 pr_err_ratelimited("invalid magic 0x%x:0x%x\n",
876 meta->magic_s, meta->magic_e);
880 if (unlikely(meta->macid >= QTNF_MAX_MAC)) {
881 pr_err_ratelimited("invalid mac(%u)\n", meta->macid);
885 if (unlikely(meta->ifidx >= QTNF_MAX_INTF)) {
886 pr_err_ratelimited("invalid vif(%u)\n", meta->ifidx);
890 mac = bus->mac[meta->macid];
892 if (unlikely(!mac)) {
893 pr_err_ratelimited("mac(%d) does not exist\n", meta->macid);
897 vif = &mac->iflist[meta->ifidx];
899 if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
900 pr_err_ratelimited("vif(%u) does not exists\n", meta->ifidx);
906 if (unlikely(!ndev)) {
907 pr_err_ratelimited("netdev for wlan%u.%u does not exists\n",
908 meta->macid, meta->ifidx);
912 __skb_trim(skb, skb->len - sizeof(*meta));
913 /* Firmware always handles packets that require flooding */
914 qtnfmac_switch_mark_skb_flooded(skb);
919 EXPORT_SYMBOL_GPL(qtnf_classify_skb);
921 void qtnf_wake_all_queues(struct net_device *ndev)
923 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
924 struct qtnf_wmac *mac;
925 struct qtnf_bus *bus;
929 if (unlikely(!vif || !vif->mac || !vif->mac->bus))
934 for (macid = 0; macid < QTNF_MAX_MAC; macid++) {
935 if (!(bus->hw_info.mac_bitmap & BIT(macid)))
938 mac = bus->mac[macid];
939 for (i = 0; i < QTNF_MAX_INTF; i++) {
940 vif = &mac->iflist[i];
941 if (vif->netdev && netif_queue_stopped(vif->netdev))
942 netif_tx_wake_all_queues(vif->netdev);
946 EXPORT_SYMBOL_GPL(qtnf_wake_all_queues);
948 void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb)
950 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
951 struct pcpu_sw_netstats *stats64;
953 if (unlikely(!vif || !vif->stats64)) {
954 ndev->stats.rx_packets++;
955 ndev->stats.rx_bytes += skb->len;
959 stats64 = this_cpu_ptr(vif->stats64);
961 u64_stats_update_begin(&stats64->syncp);
962 stats64->rx_packets++;
963 stats64->rx_bytes += skb->len;
964 u64_stats_update_end(&stats64->syncp);
966 EXPORT_SYMBOL_GPL(qtnf_update_rx_stats);
968 void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb)
970 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
971 struct pcpu_sw_netstats *stats64;
973 if (unlikely(!vif || !vif->stats64)) {
974 ndev->stats.tx_packets++;
975 ndev->stats.tx_bytes += skb->len;
979 stats64 = this_cpu_ptr(vif->stats64);
981 u64_stats_update_begin(&stats64->syncp);
982 stats64->tx_packets++;
983 stats64->tx_bytes += skb->len;
984 u64_stats_update_end(&stats64->syncp);
986 EXPORT_SYMBOL_GPL(qtnf_update_tx_stats);
988 struct dentry *qtnf_get_debugfs_dir(void)
990 return qtnf_debugfs_dir;
992 EXPORT_SYMBOL_GPL(qtnf_get_debugfs_dir);
994 static int __init qtnf_core_register(void)
996 qtnf_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
998 if (IS_ERR(qtnf_debugfs_dir))
999 qtnf_debugfs_dir = NULL;
1004 static void __exit qtnf_core_exit(void)
1006 debugfs_remove(qtnf_debugfs_dir);
1009 module_init(qtnf_core_register);
1010 module_exit(qtnf_core_exit);
1012 MODULE_AUTHOR("Quantenna Communications");
1013 MODULE_DESCRIPTION("Quantenna 802.11 wireless LAN FullMAC driver.");
1014 MODULE_LICENSE("GPL");