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 dev_sw_netstats_tx_add(ndev
, 1, skb
->len
);
133 return qtnf_bus_data_tx(mac
->bus
, skb
, mac
->macid
, vif
->vifid
);
136 /* Netdev handler for transmission timeout.
138 static void qtnf_netdev_tx_timeout(struct net_device
*ndev
, unsigned int txqueue
)
140 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(ndev
);
141 struct qtnf_wmac
*mac
;
142 struct qtnf_bus
*bus
;
144 if (unlikely(!vif
|| !vif
->mac
|| !vif
->mac
->bus
))
150 pr_warn("VIF%u.%u: Tx timeout- %lu\n", mac
->macid
, vif
->vifid
, jiffies
);
152 qtnf_bus_data_tx_timeout(bus
, ndev
);
153 ndev
->stats
.tx_errors
++;
155 if (++vif
->cons_tx_timeout_cnt
> QTNF_TX_TIMEOUT_TRSHLD
) {
156 pr_err("Tx timeout threshold exceeded !\n");
157 pr_err("schedule interface %s reset !\n", netdev_name(ndev
));
158 queue_work(bus
->workqueue
, &vif
->reset_work
);
162 static int qtnf_netdev_set_mac_address(struct net_device
*ndev
, void *addr
)
164 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(ndev
);
165 struct sockaddr
*sa
= addr
;
167 unsigned char old_addr
[ETH_ALEN
];
169 memcpy(old_addr
, sa
->sa_data
, sizeof(old_addr
));
171 ret
= eth_mac_addr(ndev
, sa
);
175 qtnf_scan_done(vif
->mac
, true);
177 ret
= qtnf_cmd_send_change_intf_type(vif
, vif
->wdev
.iftype
,
182 eth_hw_addr_set(ndev
, old_addr
);
187 static int qtnf_netdev_port_parent_id(struct net_device
*ndev
,
188 struct netdev_phys_item_id
*ppid
)
190 const struct qtnf_vif
*vif
= qtnf_netdev_get_priv(ndev
);
191 const struct qtnf_bus
*bus
= vif
->mac
->bus
;
193 ppid
->id_len
= sizeof(bus
->hw_id
);
194 memcpy(&ppid
->id
, bus
->hw_id
, ppid
->id_len
);
199 /* Network device ops handlers */
200 const struct net_device_ops qtnf_netdev_ops
= {
201 .ndo_open
= qtnf_netdev_open
,
202 .ndo_stop
= qtnf_netdev_close
,
203 .ndo_start_xmit
= qtnf_netdev_hard_start_xmit
,
204 .ndo_tx_timeout
= qtnf_netdev_tx_timeout
,
205 .ndo_set_mac_address
= qtnf_netdev_set_mac_address
,
206 .ndo_get_port_parent_id
= qtnf_netdev_port_parent_id
,
209 static int qtnf_mac_init_single_band(struct wiphy
*wiphy
,
210 struct qtnf_wmac
*mac
,
211 enum nl80211_band band
)
215 wiphy
->bands
[band
] = kzalloc(sizeof(*wiphy
->bands
[band
]), GFP_KERNEL
);
216 if (!wiphy
->bands
[band
])
219 wiphy
->bands
[band
]->band
= band
;
221 ret
= qtnf_cmd_band_info_get(mac
, wiphy
->bands
[band
]);
223 pr_err("MAC%u: band %u: failed to get chans info: %d\n",
224 mac
->macid
, band
, ret
);
228 qtnf_band_init_rates(wiphy
->bands
[band
]);
233 static int qtnf_mac_init_bands(struct qtnf_wmac
*mac
)
235 struct wiphy
*wiphy
= priv_to_wiphy(mac
);
238 if (mac
->macinfo
.bands_cap
& QLINK_BAND_2GHZ
) {
239 ret
= qtnf_mac_init_single_band(wiphy
, mac
, NL80211_BAND_2GHZ
);
244 if (mac
->macinfo
.bands_cap
& QLINK_BAND_5GHZ
) {
245 ret
= qtnf_mac_init_single_band(wiphy
, mac
, NL80211_BAND_5GHZ
);
250 if (mac
->macinfo
.bands_cap
& QLINK_BAND_60GHZ
)
251 ret
= qtnf_mac_init_single_band(wiphy
, mac
, NL80211_BAND_60GHZ
);
257 struct qtnf_vif
*qtnf_mac_get_free_vif(struct qtnf_wmac
*mac
)
259 struct qtnf_vif
*vif
;
262 for (i
= 0; i
< QTNF_MAX_INTF
; i
++) {
263 vif
= &mac
->iflist
[i
];
264 if (vif
->wdev
.iftype
== NL80211_IFTYPE_UNSPECIFIED
)
271 struct qtnf_vif
*qtnf_mac_get_base_vif(struct qtnf_wmac
*mac
)
273 struct qtnf_vif
*vif
;
275 vif
= &mac
->iflist
[QTNF_PRIMARY_VIF_IDX
];
277 if (vif
->wdev
.iftype
== NL80211_IFTYPE_UNSPECIFIED
)
283 void qtnf_mac_iface_comb_free(struct qtnf_wmac
*mac
)
285 struct ieee80211_iface_combination
*comb
;
288 if (mac
->macinfo
.if_comb
) {
289 for (i
= 0; i
< mac
->macinfo
.n_if_comb
; i
++) {
290 comb
= &mac
->macinfo
.if_comb
[i
];
295 kfree(mac
->macinfo
.if_comb
);
296 mac
->macinfo
.if_comb
= NULL
;
300 void qtnf_mac_ext_caps_free(struct qtnf_wmac
*mac
)
302 if (mac
->macinfo
.extended_capabilities_len
) {
303 kfree(mac
->macinfo
.extended_capabilities
);
304 mac
->macinfo
.extended_capabilities
= NULL
;
306 kfree(mac
->macinfo
.extended_capabilities_mask
);
307 mac
->macinfo
.extended_capabilities_mask
= NULL
;
309 mac
->macinfo
.extended_capabilities_len
= 0;
313 static void qtnf_vif_reset_handler(struct work_struct
*work
)
315 struct qtnf_vif
*vif
= container_of(work
, struct qtnf_vif
, reset_work
);
319 if (vif
->wdev
.iftype
== NL80211_IFTYPE_UNSPECIFIED
) {
324 /* stop tx completely */
325 netif_tx_stop_all_queues(vif
->netdev
);
326 if (netif_carrier_ok(vif
->netdev
))
327 netif_carrier_off(vif
->netdev
);
329 qtnf_cfg80211_vif_reset(vif
);
334 static void qtnf_mac_init_primary_intf(struct qtnf_wmac
*mac
)
336 struct qtnf_vif
*vif
= &mac
->iflist
[QTNF_PRIMARY_VIF_IDX
];
338 vif
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
339 vif
->bss_priority
= QTNF_DEF_BSS_PRIORITY
;
340 vif
->wdev
.wiphy
= priv_to_wiphy(mac
);
341 INIT_WORK(&vif
->reset_work
, qtnf_vif_reset_handler
);
342 vif
->cons_tx_timeout_cnt
= 0;
345 static void qtnf_mac_scan_finish(struct qtnf_wmac
*mac
, bool aborted
)
347 struct cfg80211_scan_info info
= {
351 mutex_lock(&mac
->mac_lock
);
354 cfg80211_scan_done(mac
->scan_req
, &info
);
355 mac
->scan_req
= NULL
;
358 mutex_unlock(&mac
->mac_lock
);
361 void qtnf_scan_done(struct qtnf_wmac
*mac
, bool aborted
)
363 cancel_delayed_work_sync(&mac
->scan_timeout
);
364 qtnf_mac_scan_finish(mac
, aborted
);
367 static void qtnf_mac_scan_timeout(struct work_struct
*work
)
369 struct qtnf_wmac
*mac
=
370 container_of(work
, struct qtnf_wmac
, scan_timeout
.work
);
372 pr_warn("MAC%d: scan timed out\n", mac
->macid
);
373 qtnf_mac_scan_finish(mac
, true);
376 static void qtnf_vif_send_data_high_pri(struct work_struct
*work
)
378 struct qtnf_vif
*vif
=
379 container_of(work
, struct qtnf_vif
, high_pri_tx_work
);
383 vif
->wdev
.iftype
== NL80211_IFTYPE_UNSPECIFIED
)
386 while ((skb
= skb_dequeue(&vif
->high_pri_tx_queue
))) {
387 qtnf_cmd_send_frame(vif
, 0, QLINK_FRAME_TX_FLAG_8023
,
388 0, skb
->data
, skb
->len
);
389 dev_kfree_skb_any(skb
);
393 static struct qtnf_wmac
*qtnf_core_mac_alloc(struct qtnf_bus
*bus
,
396 struct platform_device
*pdev
= NULL
;
397 struct qtnf_wmac
*mac
;
398 struct qtnf_vif
*vif
;
402 if (bus
->hw_info
.num_mac
> 1) {
403 pdev
= platform_device_register_data(bus
->dev
,
407 return ERR_PTR(-EINVAL
);
410 wiphy
= qtnf_wiphy_allocate(bus
, pdev
);
413 platform_device_unregister(pdev
);
414 return ERR_PTR(-ENOMEM
);
417 mac
= wiphy_priv(wiphy
);
422 mutex_init(&mac
->mac_lock
);
423 INIT_DELAYED_WORK(&mac
->scan_timeout
, qtnf_mac_scan_timeout
);
425 for (i
= 0; i
< QTNF_MAX_INTF
; i
++) {
426 vif
= &mac
->iflist
[i
];
428 memset(vif
, 0, sizeof(*vif
));
429 vif
->wdev
.iftype
= NL80211_IFTYPE_UNSPECIFIED
;
432 qtnf_sta_list_init(&vif
->sta_list
);
433 INIT_WORK(&vif
->high_pri_tx_work
, qtnf_vif_send_data_high_pri
);
434 skb_queue_head_init(&vif
->high_pri_tx_queue
);
437 qtnf_mac_init_primary_intf(mac
);
438 bus
->mac
[macid
] = mac
;
443 static const struct ethtool_ops qtnf_ethtool_ops
= {
444 .get_drvinfo
= cfg80211_get_drvinfo
,
447 int qtnf_core_net_attach(struct qtnf_wmac
*mac
, struct qtnf_vif
*vif
,
448 const char *name
, unsigned char name_assign_type
)
450 struct wiphy
*wiphy
= priv_to_wiphy(mac
);
451 struct net_device
*dev
;
455 dev
= alloc_netdev_mqs(sizeof(struct qtnf_vif
*), name
,
456 name_assign_type
, ether_setup
, 1, 1);
462 dev
->netdev_ops
= &qtnf_netdev_ops
;
463 dev
->needs_free_netdev
= true;
464 dev_net_set(dev
, wiphy_net(wiphy
));
465 dev
->ieee80211_ptr
= &vif
->wdev
;
466 eth_hw_addr_set(dev
, vif
->mac_addr
);
467 dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
468 dev
->watchdog_timeo
= QTNF_DEF_WDOG_TIMEOUT
;
469 dev
->tx_queue_len
= 100;
470 dev
->ethtool_ops
= &qtnf_ethtool_ops
;
471 dev
->pcpu_stat_type
= NETDEV_PCPU_STAT_TSTATS
;
473 if (qtnf_hwcap_is_set(&mac
->bus
->hw_info
, QLINK_HW_CAPAB_HW_BRIDGE
))
474 dev
->needed_tailroom
= sizeof(struct qtnf_frame_meta_info
);
476 qdev_vif
= netdev_priv(dev
);
477 *((void **)qdev_vif
) = vif
;
479 SET_NETDEV_DEV(dev
, wiphy_dev(wiphy
));
481 ret
= cfg80211_register_netdevice(dev
);
490 static void qtnf_core_mac_detach(struct qtnf_bus
*bus
, unsigned int macid
)
492 struct qtnf_wmac
*mac
;
494 struct qtnf_vif
*vif
;
496 enum nl80211_band band
;
498 mac
= bus
->mac
[macid
];
503 wiphy
= priv_to_wiphy(mac
);
505 for (i
= 0; i
< QTNF_MAX_INTF
; i
++) {
506 vif
= &mac
->iflist
[i
];
509 vif
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
) {
510 qtnf_virtual_intf_cleanup(vif
->netdev
);
511 qtnf_del_virtual_intf(wiphy
, &vif
->wdev
);
514 qtnf_sta_list_free(&vif
->sta_list
);
517 if (mac
->wiphy_registered
)
518 wiphy_unregister(wiphy
);
520 for (band
= NL80211_BAND_2GHZ
; band
< NUM_NL80211_BANDS
; ++band
) {
521 if (!wiphy
->bands
[band
])
524 kfree((__force
void *)wiphy
->bands
[band
]->iftype_data
);
525 wiphy
->bands
[band
]->n_iftype_data
= 0;
527 kfree(wiphy
->bands
[band
]->channels
);
528 wiphy
->bands
[band
]->n_channels
= 0;
530 kfree(wiphy
->bands
[band
]);
531 wiphy
->bands
[band
] = NULL
;
534 platform_device_unregister(mac
->pdev
);
535 qtnf_mac_iface_comb_free(mac
);
536 qtnf_mac_ext_caps_free(mac
);
537 kfree(mac
->macinfo
.wowlan
);
541 bus
->mac
[macid
] = NULL
;
544 static int qtnf_core_mac_attach(struct qtnf_bus
*bus
, unsigned int macid
)
546 struct qtnf_wmac
*mac
;
547 struct qtnf_vif
*vif
;
550 if (!(bus
->hw_info
.mac_bitmap
& BIT(macid
))) {
551 pr_info("MAC%u is not active in FW\n", macid
);
555 mac
= qtnf_core_mac_alloc(bus
, macid
);
557 pr_err("MAC%u allocation failed\n", macid
);
561 vif
= qtnf_mac_get_base_vif(mac
);
563 pr_err("MAC%u: primary VIF is not ready\n", macid
);
568 ret
= qtnf_cmd_send_add_intf(vif
, vif
->wdev
.iftype
,
569 vif
->wdev
.use_4addr
, vif
->mac_addr
);
571 pr_err("MAC%u: failed to add VIF\n", macid
);
575 ret
= qtnf_cmd_get_mac_info(mac
);
577 pr_err("MAC%u: failed to get MAC info\n", macid
);
581 /* Use MAC address of the first active radio as a unique device ID */
582 if (is_zero_ether_addr(mac
->bus
->hw_id
))
583 ether_addr_copy(mac
->bus
->hw_id
, mac
->macaddr
);
585 ret
= qtnf_mac_init_bands(mac
);
587 pr_err("MAC%u: failed to init bands\n", macid
);
591 ret
= qtnf_wiphy_register(&bus
->hw_info
, mac
);
593 pr_err("MAC%u: wiphy registration failed\n", macid
);
597 mac
->wiphy_registered
= 1;
600 wiphy_lock(priv_to_wiphy(mac
));
601 ret
= qtnf_core_net_attach(mac
, vif
, "wlan%d", NET_NAME_ENUM
);
602 wiphy_unlock(priv_to_wiphy(mac
));
606 pr_err("MAC%u: failed to attach netdev\n", macid
);
610 if (qtnf_hwcap_is_set(&bus
->hw_info
, QLINK_HW_CAPAB_HW_BRIDGE
)) {
611 ret
= qtnf_cmd_netdev_changeupper(vif
, vif
->netdev
->ifindex
);
616 pr_debug("MAC%u initialized\n", macid
);
621 qtnf_cmd_send_del_intf(vif
);
622 vif
->wdev
.iftype
= NL80211_IFTYPE_UNSPECIFIED
;
624 qtnf_core_mac_detach(bus
, macid
);
628 bool qtnf_netdev_is_qtn(const struct net_device
*ndev
)
630 return ndev
->netdev_ops
== &qtnf_netdev_ops
;
633 static int qtnf_check_br_ports(struct net_device
*dev
,
634 struct netdev_nested_priv
*priv
)
636 struct net_device
*ndev
= (struct net_device
*)priv
->data
;
638 if (dev
!= ndev
&& netdev_port_same_parent_id(dev
, ndev
))
644 static int qtnf_core_netdevice_event(struct notifier_block
*nb
,
645 unsigned long event
, void *ptr
)
647 struct net_device
*ndev
= netdev_notifier_info_to_dev(ptr
);
648 const struct netdev_notifier_changeupper_info
*info
;
649 struct netdev_nested_priv priv
= {
650 .data
= (void *)ndev
,
652 struct net_device
*brdev
;
653 struct qtnf_vif
*vif
;
654 struct qtnf_bus
*bus
;
658 if (!qtnf_netdev_is_qtn(ndev
))
661 if (!net_eq(dev_net(ndev
), &init_net
))
664 vif
= qtnf_netdev_get_priv(ndev
);
668 case NETDEV_CHANGEUPPER
:
670 brdev
= info
->upper_dev
;
672 if (!netif_is_bridge_master(brdev
))
675 pr_debug("[VIF%u.%u] change bridge: %s %s\n",
676 vif
->mac
->macid
, vif
->vifid
, netdev_name(brdev
),
677 info
->linking
? "add" : "del");
679 if (IS_ENABLED(CONFIG_NET_SWITCHDEV
) &&
680 qtnf_hwcap_is_set(&bus
->hw_info
,
681 QLINK_HW_CAPAB_HW_BRIDGE
)) {
683 br_domain
= brdev
->ifindex
;
685 br_domain
= ndev
->ifindex
;
687 ret
= qtnf_cmd_netdev_changeupper(vif
, br_domain
);
689 ret
= netdev_walk_all_lower_dev(brdev
,
699 return notifier_from_errno(ret
);
702 int qtnf_core_attach(struct qtnf_bus
*bus
)
707 qtnf_trans_init(bus
);
708 qtnf_bus_data_rx_start(bus
);
710 bus
->workqueue
= alloc_ordered_workqueue("QTNF_BUS", 0);
711 if (!bus
->workqueue
) {
712 pr_err("failed to alloc main workqueue\n");
717 bus
->hprio_workqueue
= alloc_workqueue("QTNF_HPRI", WQ_HIGHPRI
, 0);
718 if (!bus
->hprio_workqueue
) {
719 pr_err("failed to alloc high prio workqueue\n");
724 INIT_WORK(&bus
->event_work
, qtnf_event_work_handler
);
726 ret
= qtnf_cmd_send_init_fw(bus
);
728 pr_err("failed to init FW: %d\n", ret
);
732 if (QLINK_VER_MAJOR(bus
->hw_info
.ql_proto_ver
) !=
733 QLINK_PROTO_VER_MAJOR
) {
734 pr_err("qlink driver vs FW version mismatch: %u vs %u\n",
735 QLINK_PROTO_VER_MAJOR
,
736 QLINK_VER_MAJOR(bus
->hw_info
.ql_proto_ver
));
737 ret
= -EPROTONOSUPPORT
;
741 bus
->fw_state
= QTNF_FW_STATE_ACTIVE
;
742 ret
= qtnf_cmd_get_hw_info(bus
);
744 pr_err("failed to get HW info: %d\n", ret
);
748 if (qtnf_hwcap_is_set(&bus
->hw_info
, QLINK_HW_CAPAB_HW_BRIDGE
) &&
749 bus
->bus_ops
->data_tx_use_meta_set
)
750 bus
->bus_ops
->data_tx_use_meta_set(bus
, true);
752 if (bus
->hw_info
.num_mac
> QTNF_MAX_MAC
) {
753 pr_err("no support for number of MACs=%u\n",
754 bus
->hw_info
.num_mac
);
759 for (i
= 0; i
< bus
->hw_info
.num_mac
; i
++) {
760 ret
= qtnf_core_mac_attach(bus
, i
);
763 pr_err("MAC%u: attach failed: %d\n", i
, ret
);
768 bus
->netdev_nb
.notifier_call
= qtnf_core_netdevice_event
;
769 ret
= register_netdevice_notifier(&bus
->netdev_nb
);
771 pr_err("failed to register netdev notifier: %d\n", ret
);
775 bus
->fw_state
= QTNF_FW_STATE_RUNNING
;
779 qtnf_core_detach(bus
);
782 EXPORT_SYMBOL_GPL(qtnf_core_attach
);
784 void qtnf_core_detach(struct qtnf_bus
*bus
)
788 unregister_netdevice_notifier(&bus
->netdev_nb
);
789 qtnf_bus_data_rx_stop(bus
);
791 for (macid
= 0; macid
< QTNF_MAX_MAC
; macid
++)
792 qtnf_core_mac_detach(bus
, macid
);
794 if (qtnf_fw_is_up(bus
))
795 qtnf_cmd_send_deinit_fw(bus
);
797 bus
->fw_state
= QTNF_FW_STATE_DETACHED
;
799 if (bus
->workqueue
) {
800 destroy_workqueue(bus
->workqueue
);
801 bus
->workqueue
= NULL
;
804 if (bus
->hprio_workqueue
) {
805 destroy_workqueue(bus
->hprio_workqueue
);
806 bus
->hprio_workqueue
= NULL
;
809 qtnf_trans_free(bus
);
811 EXPORT_SYMBOL_GPL(qtnf_core_detach
);
813 static inline int qtnf_is_frame_meta_magic_valid(struct qtnf_frame_meta_info
*m
)
815 return m
->magic_s
== HBM_FRAME_META_MAGIC_PATTERN_S
&&
816 m
->magic_e
== HBM_FRAME_META_MAGIC_PATTERN_E
;
819 struct net_device
*qtnf_classify_skb(struct qtnf_bus
*bus
, struct sk_buff
*skb
)
821 struct qtnf_frame_meta_info
*meta
;
822 struct net_device
*ndev
= NULL
;
823 struct qtnf_wmac
*mac
;
824 struct qtnf_vif
*vif
;
826 if (unlikely(bus
->fw_state
!= QTNF_FW_STATE_RUNNING
))
829 meta
= (struct qtnf_frame_meta_info
*)
830 (skb_tail_pointer(skb
) - sizeof(*meta
));
832 if (unlikely(!qtnf_is_frame_meta_magic_valid(meta
))) {
833 pr_err_ratelimited("invalid magic 0x%x:0x%x\n",
834 meta
->magic_s
, meta
->magic_e
);
838 if (unlikely(meta
->macid
>= QTNF_MAX_MAC
)) {
839 pr_err_ratelimited("invalid mac(%u)\n", meta
->macid
);
843 if (unlikely(meta
->ifidx
>= QTNF_MAX_INTF
)) {
844 pr_err_ratelimited("invalid vif(%u)\n", meta
->ifidx
);
848 mac
= bus
->mac
[meta
->macid
];
850 if (unlikely(!mac
)) {
851 pr_err_ratelimited("mac(%d) does not exist\n", meta
->macid
);
855 vif
= &mac
->iflist
[meta
->ifidx
];
857 if (unlikely(vif
->wdev
.iftype
== NL80211_IFTYPE_UNSPECIFIED
)) {
858 pr_err_ratelimited("vif(%u) does not exists\n", meta
->ifidx
);
864 if (unlikely(!ndev
)) {
865 pr_err_ratelimited("netdev for wlan%u.%u does not exists\n",
866 meta
->macid
, meta
->ifidx
);
870 __skb_trim(skb
, skb
->len
- sizeof(*meta
));
871 /* Firmware always handles packets that require flooding */
872 qtnfmac_switch_mark_skb_flooded(skb
);
877 EXPORT_SYMBOL_GPL(qtnf_classify_skb
);
879 void qtnf_wake_all_queues(struct net_device
*ndev
)
881 struct qtnf_vif
*vif
= qtnf_netdev_get_priv(ndev
);
882 struct qtnf_wmac
*mac
;
883 struct qtnf_bus
*bus
;
887 if (unlikely(!vif
|| !vif
->mac
|| !vif
->mac
->bus
))
892 for (macid
= 0; macid
< QTNF_MAX_MAC
; macid
++) {
893 if (!(bus
->hw_info
.mac_bitmap
& BIT(macid
)))
896 mac
= bus
->mac
[macid
];
897 for (i
= 0; i
< QTNF_MAX_INTF
; i
++) {
898 vif
= &mac
->iflist
[i
];
899 if (vif
->netdev
&& netif_queue_stopped(vif
->netdev
))
900 netif_tx_wake_all_queues(vif
->netdev
);
904 EXPORT_SYMBOL_GPL(qtnf_wake_all_queues
);
906 struct dentry
*qtnf_get_debugfs_dir(void)
908 return qtnf_debugfs_dir
;
910 EXPORT_SYMBOL_GPL(qtnf_get_debugfs_dir
);
912 static int __init
qtnf_core_register(void)
914 qtnf_debugfs_dir
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
916 if (IS_ERR(qtnf_debugfs_dir
))
917 qtnf_debugfs_dir
= NULL
;
922 static void __exit
qtnf_core_exit(void)
924 debugfs_remove(qtnf_debugfs_dir
);
927 module_init(qtnf_core_register
);
928 module_exit(qtnf_core_exit
);
930 MODULE_AUTHOR("Quantenna Communications");
931 MODULE_DESCRIPTION("Quantenna 802.11 wireless LAN FullMAC driver.");
932 MODULE_LICENSE("GPL");