xref: /linux/drivers/net/wireless/quantenna/qtnfmac/core.c (revision 4f6b838c378a52ea3ae0b15f12ca8a20849072fa)
1ff233cb5SSergey Matyukevich // SPDX-License-Identifier: GPL-2.0+
2ff233cb5SSergey Matyukevich /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
398f44cb0SIgor Mitsyanko 
498f44cb0SIgor Mitsyanko #include <linux/kernel.h>
598f44cb0SIgor Mitsyanko #include <linux/module.h>
698f44cb0SIgor Mitsyanko #include <linux/if_ether.h>
7946d077aSSergey Matyukevich #include <linux/nospec.h>
898f44cb0SIgor Mitsyanko 
998f44cb0SIgor Mitsyanko #include "core.h"
1098f44cb0SIgor Mitsyanko #include "bus.h"
1198f44cb0SIgor Mitsyanko #include "trans.h"
1298f44cb0SIgor Mitsyanko #include "commands.h"
1398f44cb0SIgor Mitsyanko #include "cfg80211.h"
1498f44cb0SIgor Mitsyanko #include "event.h"
1598f44cb0SIgor Mitsyanko #include "util.h"
161db35994SIgor Mitsyanko #include "switchdev.h"
1798f44cb0SIgor Mitsyanko 
1898f44cb0SIgor Mitsyanko #define QTNF_PRIMARY_VIF_IDX	0
1998f44cb0SIgor Mitsyanko 
20888f1564SIgor Mitsyanko static bool slave_radar = true;
21888f1564SIgor Mitsyanko module_param(slave_radar, bool, 0644);
22888f1564SIgor Mitsyanko MODULE_PARM_DESC(slave_radar, "set 0 to disable radar detection in slave mode");
23888f1564SIgor Mitsyanko 
24155b424cSSergey Matyukevich static bool dfs_offload;
25155b424cSSergey Matyukevich module_param(dfs_offload, bool, 0644);
26155b424cSSergey Matyukevich MODULE_PARM_DESC(dfs_offload, "set 1 to enable DFS offload to firmware");
27155b424cSSergey Matyukevich 
280b68fe10SSergey Matyukevich static struct dentry *qtnf_debugfs_dir;
290b68fe10SSergey Matyukevich 
30e92b07a2SSergey Matyukevich bool qtnf_slave_radar_get(void)
31e92b07a2SSergey Matyukevich {
32e92b07a2SSergey Matyukevich 	return slave_radar;
33e92b07a2SSergey Matyukevich }
34e92b07a2SSergey Matyukevich 
35155b424cSSergey Matyukevich bool qtnf_dfs_offload_get(void)
36155b424cSSergey Matyukevich {
37155b424cSSergey Matyukevich 	return dfs_offload;
38155b424cSSergey Matyukevich }
39155b424cSSergey Matyukevich 
4098f44cb0SIgor Mitsyanko struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid)
4198f44cb0SIgor Mitsyanko {
4298f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac = NULL;
4398f44cb0SIgor Mitsyanko 
44946d077aSSergey Matyukevich 	if (macid >= QTNF_MAX_MAC) {
4598f44cb0SIgor Mitsyanko 		pr_err("invalid MAC index %u\n", macid);
4698f44cb0SIgor Mitsyanko 		return NULL;
4798f44cb0SIgor Mitsyanko 	}
4898f44cb0SIgor Mitsyanko 
49946d077aSSergey Matyukevich 	macid = array_index_nospec(macid, QTNF_MAX_MAC);
5098f44cb0SIgor Mitsyanko 	mac = bus->mac[macid];
5198f44cb0SIgor Mitsyanko 
5298f44cb0SIgor Mitsyanko 	if (unlikely(!mac)) {
5398f44cb0SIgor Mitsyanko 		pr_err("MAC%u: not initialized\n", macid);
5498f44cb0SIgor Mitsyanko 		return NULL;
5598f44cb0SIgor Mitsyanko 	}
5698f44cb0SIgor Mitsyanko 
5798f44cb0SIgor Mitsyanko 	return mac;
5898f44cb0SIgor Mitsyanko }
5998f44cb0SIgor Mitsyanko 
6098f44cb0SIgor Mitsyanko /* Netdev handler for open.
6198f44cb0SIgor Mitsyanko  */
6298f44cb0SIgor Mitsyanko static int qtnf_netdev_open(struct net_device *ndev)
6398f44cb0SIgor Mitsyanko {
6498f44cb0SIgor Mitsyanko 	netif_carrier_off(ndev);
6598f44cb0SIgor Mitsyanko 	qtnf_netdev_updown(ndev, 1);
6698f44cb0SIgor Mitsyanko 	return 0;
6798f44cb0SIgor Mitsyanko }
6898f44cb0SIgor Mitsyanko 
6998f44cb0SIgor Mitsyanko /* Netdev handler for close.
7098f44cb0SIgor Mitsyanko  */
7198f44cb0SIgor Mitsyanko static int qtnf_netdev_close(struct net_device *ndev)
7298f44cb0SIgor Mitsyanko {
7398f44cb0SIgor Mitsyanko 	netif_carrier_off(ndev);
7498f44cb0SIgor Mitsyanko 	qtnf_virtual_intf_cleanup(ndev);
7598f44cb0SIgor Mitsyanko 	qtnf_netdev_updown(ndev, 0);
7698f44cb0SIgor Mitsyanko 	return 0;
7798f44cb0SIgor Mitsyanko }
7898f44cb0SIgor Mitsyanko 
7946d55fceSSergey Matyukevich static void qtnf_packet_send_hi_pri(struct sk_buff *skb)
8046d55fceSSergey Matyukevich {
8146d55fceSSergey Matyukevich 	struct qtnf_vif *vif = qtnf_netdev_get_priv(skb->dev);
8246d55fceSSergey Matyukevich 
8346d55fceSSergey Matyukevich 	skb_queue_tail(&vif->high_pri_tx_queue, skb);
8446d55fceSSergey Matyukevich 	queue_work(vif->mac->bus->hprio_workqueue, &vif->high_pri_tx_work);
8546d55fceSSergey Matyukevich }
8646d55fceSSergey Matyukevich 
8798f44cb0SIgor Mitsyanko /* Netdev handler for data transmission.
8898f44cb0SIgor Mitsyanko  */
893ff6ee28SLuc Van Oostenryck static netdev_tx_t
9098f44cb0SIgor Mitsyanko qtnf_netdev_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
9198f44cb0SIgor Mitsyanko {
9298f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
9398f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac;
9498f44cb0SIgor Mitsyanko 
9598f44cb0SIgor Mitsyanko 	vif = qtnf_netdev_get_priv(ndev);
9698f44cb0SIgor Mitsyanko 
9798f44cb0SIgor Mitsyanko 	if (unlikely(skb->dev != ndev)) {
9898f44cb0SIgor Mitsyanko 		pr_err_ratelimited("invalid skb->dev");
9998f44cb0SIgor Mitsyanko 		dev_kfree_skb_any(skb);
10098f44cb0SIgor Mitsyanko 		return 0;
10198f44cb0SIgor Mitsyanko 	}
10298f44cb0SIgor Mitsyanko 
10398f44cb0SIgor Mitsyanko 	if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
10498f44cb0SIgor Mitsyanko 		pr_err_ratelimited("%s: VIF not initialized\n", ndev->name);
10598f44cb0SIgor Mitsyanko 		dev_kfree_skb_any(skb);
10698f44cb0SIgor Mitsyanko 		return 0;
10798f44cb0SIgor Mitsyanko 	}
10898f44cb0SIgor Mitsyanko 
10998f44cb0SIgor Mitsyanko 	mac = vif->mac;
11098f44cb0SIgor Mitsyanko 	if (unlikely(!mac)) {
11198f44cb0SIgor Mitsyanko 		pr_err_ratelimited("%s: NULL mac pointer", ndev->name);
11298f44cb0SIgor Mitsyanko 		dev_kfree_skb_any(skb);
11398f44cb0SIgor Mitsyanko 		return 0;
11498f44cb0SIgor Mitsyanko 	}
11598f44cb0SIgor Mitsyanko 
11698f44cb0SIgor Mitsyanko 	if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
11798f44cb0SIgor Mitsyanko 		pr_err_ratelimited("%s: invalid skb len %d\n", ndev->name,
11898f44cb0SIgor Mitsyanko 				   skb->len);
11998f44cb0SIgor Mitsyanko 		dev_kfree_skb_any(skb);
12098f44cb0SIgor Mitsyanko 		ndev->stats.tx_dropped++;
12198f44cb0SIgor Mitsyanko 		return 0;
12298f44cb0SIgor Mitsyanko 	}
12398f44cb0SIgor Mitsyanko 
12498f44cb0SIgor Mitsyanko 	/* tx path is enabled: reset vif timeout */
12598f44cb0SIgor Mitsyanko 	vif->cons_tx_timeout_cnt = 0;
12698f44cb0SIgor Mitsyanko 
12746d55fceSSergey Matyukevich 	if (unlikely(skb->protocol == htons(ETH_P_PAE))) {
12846d55fceSSergey Matyukevich 		qtnf_packet_send_hi_pri(skb);
12946d55fceSSergey Matyukevich 		qtnf_update_tx_stats(ndev, skb);
13046d55fceSSergey Matyukevich 		return NETDEV_TX_OK;
13146d55fceSSergey Matyukevich 	}
13246d55fceSSergey Matyukevich 
133904628d3SIgor Mitsyanko 	return qtnf_bus_data_tx(mac->bus, skb, mac->macid, vif->vifid);
13498f44cb0SIgor Mitsyanko }
13598f44cb0SIgor Mitsyanko 
13698f44cb0SIgor Mitsyanko /* Netdev handler for getting stats.
13798f44cb0SIgor Mitsyanko  */
13804b01affSVasily Ulyanov static void qtnf_netdev_get_stats64(struct net_device *ndev,
13904b01affSVasily Ulyanov 				    struct rtnl_link_stats64 *stats)
14098f44cb0SIgor Mitsyanko {
14104b01affSVasily Ulyanov 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
14204b01affSVasily Ulyanov 
14304b01affSVasily Ulyanov 	netdev_stats_to_stats64(stats, &ndev->stats);
14404b01affSVasily Ulyanov 
14504b01affSVasily Ulyanov 	if (!vif->stats64)
14604b01affSVasily Ulyanov 		return;
14704b01affSVasily Ulyanov 
148*1f68b209SHeiner Kallweit 	dev_fetch_sw_netstats(stats, vif->stats64);
14998f44cb0SIgor Mitsyanko }
15098f44cb0SIgor Mitsyanko 
15198f44cb0SIgor Mitsyanko /* Netdev handler for transmission timeout.
15298f44cb0SIgor Mitsyanko  */
1530290bd29SMichael S. Tsirkin static void qtnf_netdev_tx_timeout(struct net_device *ndev, unsigned int txqueue)
15498f44cb0SIgor Mitsyanko {
15598f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
15698f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac;
15798f44cb0SIgor Mitsyanko 	struct qtnf_bus *bus;
15898f44cb0SIgor Mitsyanko 
15998f44cb0SIgor Mitsyanko 	if (unlikely(!vif || !vif->mac || !vif->mac->bus))
16098f44cb0SIgor Mitsyanko 		return;
16198f44cb0SIgor Mitsyanko 
16298f44cb0SIgor Mitsyanko 	mac = vif->mac;
16398f44cb0SIgor Mitsyanko 	bus = mac->bus;
16498f44cb0SIgor Mitsyanko 
16598f44cb0SIgor Mitsyanko 	pr_warn("VIF%u.%u: Tx timeout- %lu\n", mac->macid, vif->vifid, jiffies);
16698f44cb0SIgor Mitsyanko 
16798f44cb0SIgor Mitsyanko 	qtnf_bus_data_tx_timeout(bus, ndev);
16898f44cb0SIgor Mitsyanko 	ndev->stats.tx_errors++;
16998f44cb0SIgor Mitsyanko 
17098f44cb0SIgor Mitsyanko 	if (++vif->cons_tx_timeout_cnt > QTNF_TX_TIMEOUT_TRSHLD) {
17198f44cb0SIgor Mitsyanko 		pr_err("Tx timeout threshold exceeded !\n");
17298f44cb0SIgor Mitsyanko 		pr_err("schedule interface %s reset !\n", netdev_name(ndev));
17398f44cb0SIgor Mitsyanko 		queue_work(bus->workqueue, &vif->reset_work);
17498f44cb0SIgor Mitsyanko 	}
17598f44cb0SIgor Mitsyanko }
17698f44cb0SIgor Mitsyanko 
177ed9f34bbSIgor Mitsyanko static int qtnf_netdev_set_mac_address(struct net_device *ndev, void *addr)
178ed9f34bbSIgor Mitsyanko {
179ed9f34bbSIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
180ed9f34bbSIgor Mitsyanko 	struct sockaddr *sa = addr;
181ed9f34bbSIgor Mitsyanko 	int ret;
182ed9f34bbSIgor Mitsyanko 	unsigned char old_addr[ETH_ALEN];
183ed9f34bbSIgor Mitsyanko 
184ed9f34bbSIgor Mitsyanko 	memcpy(old_addr, sa->sa_data, sizeof(old_addr));
185ed9f34bbSIgor Mitsyanko 
186ed9f34bbSIgor Mitsyanko 	ret = eth_mac_addr(ndev, sa);
187ed9f34bbSIgor Mitsyanko 	if (ret)
188ed9f34bbSIgor Mitsyanko 		return ret;
189ed9f34bbSIgor Mitsyanko 
190ed9f34bbSIgor Mitsyanko 	qtnf_scan_done(vif->mac, true);
191ed9f34bbSIgor Mitsyanko 
192ed9f34bbSIgor Mitsyanko 	ret = qtnf_cmd_send_change_intf_type(vif, vif->wdev.iftype,
193de624a35SSergey Matyukevich 					     vif->wdev.use_4addr,
194ed9f34bbSIgor Mitsyanko 					     sa->sa_data);
195ed9f34bbSIgor Mitsyanko 
196ed9f34bbSIgor Mitsyanko 	if (ret)
197ed9f34bbSIgor Mitsyanko 		memcpy(ndev->dev_addr, old_addr, ETH_ALEN);
198ed9f34bbSIgor Mitsyanko 
199ed9f34bbSIgor Mitsyanko 	return ret;
200ed9f34bbSIgor Mitsyanko }
201ed9f34bbSIgor Mitsyanko 
2024e14e76cSIgor Mitsyanko static int qtnf_netdev_port_parent_id(struct net_device *ndev,
2034e14e76cSIgor Mitsyanko 				      struct netdev_phys_item_id *ppid)
2044e14e76cSIgor Mitsyanko {
2054e14e76cSIgor Mitsyanko 	const struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
2064e14e76cSIgor Mitsyanko 	const struct qtnf_bus *bus = vif->mac->bus;
2074e14e76cSIgor Mitsyanko 
2084e14e76cSIgor Mitsyanko 	ppid->id_len = sizeof(bus->hw_id);
2094e14e76cSIgor Mitsyanko 	memcpy(&ppid->id, bus->hw_id, ppid->id_len);
2104e14e76cSIgor Mitsyanko 
2114e14e76cSIgor Mitsyanko 	return 0;
2124e14e76cSIgor Mitsyanko }
2134e14e76cSIgor Mitsyanko 
21498f44cb0SIgor Mitsyanko /* Network device ops handlers */
21598f44cb0SIgor Mitsyanko const struct net_device_ops qtnf_netdev_ops = {
21698f44cb0SIgor Mitsyanko 	.ndo_open = qtnf_netdev_open,
21798f44cb0SIgor Mitsyanko 	.ndo_stop = qtnf_netdev_close,
21898f44cb0SIgor Mitsyanko 	.ndo_start_xmit = qtnf_netdev_hard_start_xmit,
21998f44cb0SIgor Mitsyanko 	.ndo_tx_timeout = qtnf_netdev_tx_timeout,
22004b01affSVasily Ulyanov 	.ndo_get_stats64 = qtnf_netdev_get_stats64,
221ed9f34bbSIgor Mitsyanko 	.ndo_set_mac_address = qtnf_netdev_set_mac_address,
2224e14e76cSIgor Mitsyanko 	.ndo_get_port_parent_id = qtnf_netdev_port_parent_id,
22398f44cb0SIgor Mitsyanko };
22498f44cb0SIgor Mitsyanko 
22598f44cb0SIgor Mitsyanko static int qtnf_mac_init_single_band(struct wiphy *wiphy,
22698f44cb0SIgor Mitsyanko 				     struct qtnf_wmac *mac,
22798f44cb0SIgor Mitsyanko 				     enum nl80211_band band)
22898f44cb0SIgor Mitsyanko {
22998f44cb0SIgor Mitsyanko 	int ret;
23098f44cb0SIgor Mitsyanko 
23198f44cb0SIgor Mitsyanko 	wiphy->bands[band] = kzalloc(sizeof(*wiphy->bands[band]), GFP_KERNEL);
23298f44cb0SIgor Mitsyanko 	if (!wiphy->bands[band])
23398f44cb0SIgor Mitsyanko 		return -ENOMEM;
23498f44cb0SIgor Mitsyanko 
23598f44cb0SIgor Mitsyanko 	wiphy->bands[band]->band = band;
23698f44cb0SIgor Mitsyanko 
237e294cbfdSIgor Mitsyanko 	ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
23898f44cb0SIgor Mitsyanko 	if (ret) {
23998f44cb0SIgor Mitsyanko 		pr_err("MAC%u: band %u: failed to get chans info: %d\n",
24098f44cb0SIgor Mitsyanko 		       mac->macid, band, ret);
24198f44cb0SIgor Mitsyanko 		return ret;
24298f44cb0SIgor Mitsyanko 	}
24398f44cb0SIgor Mitsyanko 
24498f44cb0SIgor Mitsyanko 	qtnf_band_init_rates(wiphy->bands[band]);
24598f44cb0SIgor Mitsyanko 
24698f44cb0SIgor Mitsyanko 	return 0;
24798f44cb0SIgor Mitsyanko }
24898f44cb0SIgor Mitsyanko 
24998f44cb0SIgor Mitsyanko static int qtnf_mac_init_bands(struct qtnf_wmac *mac)
25098f44cb0SIgor Mitsyanko {
25198f44cb0SIgor Mitsyanko 	struct wiphy *wiphy = priv_to_wiphy(mac);
25298f44cb0SIgor Mitsyanko 	int ret = 0;
25398f44cb0SIgor Mitsyanko 
25498f44cb0SIgor Mitsyanko 	if (mac->macinfo.bands_cap & QLINK_BAND_2GHZ) {
25598f44cb0SIgor Mitsyanko 		ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_2GHZ);
25698f44cb0SIgor Mitsyanko 		if (ret)
25798f44cb0SIgor Mitsyanko 			goto out;
25898f44cb0SIgor Mitsyanko 	}
25998f44cb0SIgor Mitsyanko 
26098f44cb0SIgor Mitsyanko 	if (mac->macinfo.bands_cap & QLINK_BAND_5GHZ) {
26198f44cb0SIgor Mitsyanko 		ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_5GHZ);
26298f44cb0SIgor Mitsyanko 		if (ret)
26398f44cb0SIgor Mitsyanko 			goto out;
26498f44cb0SIgor Mitsyanko 	}
26598f44cb0SIgor Mitsyanko 
26698f44cb0SIgor Mitsyanko 	if (mac->macinfo.bands_cap & QLINK_BAND_60GHZ)
26798f44cb0SIgor Mitsyanko 		ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_60GHZ);
26898f44cb0SIgor Mitsyanko 
26998f44cb0SIgor Mitsyanko out:
27098f44cb0SIgor Mitsyanko 	return ret;
27198f44cb0SIgor Mitsyanko }
27298f44cb0SIgor Mitsyanko 
27398f44cb0SIgor Mitsyanko struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac)
27498f44cb0SIgor Mitsyanko {
27598f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
27698f44cb0SIgor Mitsyanko 	int i;
27798f44cb0SIgor Mitsyanko 
27898f44cb0SIgor Mitsyanko 	for (i = 0; i < QTNF_MAX_INTF; i++) {
27998f44cb0SIgor Mitsyanko 		vif = &mac->iflist[i];
28098f44cb0SIgor Mitsyanko 		if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
28198f44cb0SIgor Mitsyanko 			return vif;
28298f44cb0SIgor Mitsyanko 	}
28398f44cb0SIgor Mitsyanko 
28498f44cb0SIgor Mitsyanko 	return NULL;
28598f44cb0SIgor Mitsyanko }
28698f44cb0SIgor Mitsyanko 
28798f44cb0SIgor Mitsyanko struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac)
28898f44cb0SIgor Mitsyanko {
28998f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
29098f44cb0SIgor Mitsyanko 
29198f44cb0SIgor Mitsyanko 	vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
29298f44cb0SIgor Mitsyanko 
29398f44cb0SIgor Mitsyanko 	if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
29498f44cb0SIgor Mitsyanko 		return NULL;
29598f44cb0SIgor Mitsyanko 
29698f44cb0SIgor Mitsyanko 	return vif;
29798f44cb0SIgor Mitsyanko }
29898f44cb0SIgor Mitsyanko 
299537faf26SSergey Matyukevich void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac)
300537faf26SSergey Matyukevich {
301537faf26SSergey Matyukevich 	struct ieee80211_iface_combination *comb;
302537faf26SSergey Matyukevich 	int i;
303537faf26SSergey Matyukevich 
304537faf26SSergey Matyukevich 	if (mac->macinfo.if_comb) {
305537faf26SSergey Matyukevich 		for (i = 0; i < mac->macinfo.n_if_comb; i++) {
306537faf26SSergey Matyukevich 			comb = &mac->macinfo.if_comb[i];
307537faf26SSergey Matyukevich 			kfree(comb->limits);
308537faf26SSergey Matyukevich 			comb->limits = NULL;
309537faf26SSergey Matyukevich 		}
310537faf26SSergey Matyukevich 
311537faf26SSergey Matyukevich 		kfree(mac->macinfo.if_comb);
312537faf26SSergey Matyukevich 		mac->macinfo.if_comb = NULL;
313537faf26SSergey Matyukevich 	}
314537faf26SSergey Matyukevich }
315537faf26SSergey Matyukevich 
316ab1c64a1SSergey Matyukevich void qtnf_mac_ext_caps_free(struct qtnf_wmac *mac)
317ab1c64a1SSergey Matyukevich {
318ab1c64a1SSergey Matyukevich 	if (mac->macinfo.extended_capabilities_len) {
319ab1c64a1SSergey Matyukevich 		kfree(mac->macinfo.extended_capabilities);
320ab1c64a1SSergey Matyukevich 		mac->macinfo.extended_capabilities = NULL;
321ab1c64a1SSergey Matyukevich 
322ab1c64a1SSergey Matyukevich 		kfree(mac->macinfo.extended_capabilities_mask);
323ab1c64a1SSergey Matyukevich 		mac->macinfo.extended_capabilities_mask = NULL;
324ab1c64a1SSergey Matyukevich 
325ab1c64a1SSergey Matyukevich 		mac->macinfo.extended_capabilities_len = 0;
326ab1c64a1SSergey Matyukevich 	}
327ab1c64a1SSergey Matyukevich }
328ab1c64a1SSergey Matyukevich 
32998f44cb0SIgor Mitsyanko static void qtnf_vif_reset_handler(struct work_struct *work)
33098f44cb0SIgor Mitsyanko {
33198f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = container_of(work, struct qtnf_vif, reset_work);
33298f44cb0SIgor Mitsyanko 
33398f44cb0SIgor Mitsyanko 	rtnl_lock();
33498f44cb0SIgor Mitsyanko 
33598f44cb0SIgor Mitsyanko 	if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
33698f44cb0SIgor Mitsyanko 		rtnl_unlock();
33798f44cb0SIgor Mitsyanko 		return;
33898f44cb0SIgor Mitsyanko 	}
33998f44cb0SIgor Mitsyanko 
34098f44cb0SIgor Mitsyanko 	/* stop tx completely */
34198f44cb0SIgor Mitsyanko 	netif_tx_stop_all_queues(vif->netdev);
34298f44cb0SIgor Mitsyanko 	if (netif_carrier_ok(vif->netdev))
34398f44cb0SIgor Mitsyanko 		netif_carrier_off(vif->netdev);
34498f44cb0SIgor Mitsyanko 
34598f44cb0SIgor Mitsyanko 	qtnf_cfg80211_vif_reset(vif);
34698f44cb0SIgor Mitsyanko 
34798f44cb0SIgor Mitsyanko 	rtnl_unlock();
34898f44cb0SIgor Mitsyanko }
34998f44cb0SIgor Mitsyanko 
35098f44cb0SIgor Mitsyanko static void qtnf_mac_init_primary_intf(struct qtnf_wmac *mac)
35198f44cb0SIgor Mitsyanko {
35298f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
35398f44cb0SIgor Mitsyanko 
354e6ef8cd0SIgor Mitsyanko 	vif->wdev.iftype = NL80211_IFTYPE_STATION;
35598f44cb0SIgor Mitsyanko 	vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
35698f44cb0SIgor Mitsyanko 	vif->wdev.wiphy = priv_to_wiphy(mac);
35798f44cb0SIgor Mitsyanko 	INIT_WORK(&vif->reset_work, qtnf_vif_reset_handler);
35898f44cb0SIgor Mitsyanko 	vif->cons_tx_timeout_cnt = 0;
35998f44cb0SIgor Mitsyanko }
36098f44cb0SIgor Mitsyanko 
361f2cddd54SIgor Mitsyanko static void qtnf_mac_scan_finish(struct qtnf_wmac *mac, bool aborted)
362f2cddd54SIgor Mitsyanko {
363f2cddd54SIgor Mitsyanko 	struct cfg80211_scan_info info = {
364f2cddd54SIgor Mitsyanko 		.aborted = aborted,
365f2cddd54SIgor Mitsyanko 	};
366f2cddd54SIgor Mitsyanko 
367f2cddd54SIgor Mitsyanko 	mutex_lock(&mac->mac_lock);
368f2cddd54SIgor Mitsyanko 
369f2cddd54SIgor Mitsyanko 	if (mac->scan_req) {
370f2cddd54SIgor Mitsyanko 		cfg80211_scan_done(mac->scan_req, &info);
371f2cddd54SIgor Mitsyanko 		mac->scan_req = NULL;
372f2cddd54SIgor Mitsyanko 	}
373f2cddd54SIgor Mitsyanko 
374f2cddd54SIgor Mitsyanko 	mutex_unlock(&mac->mac_lock);
375f2cddd54SIgor Mitsyanko }
376f2cddd54SIgor Mitsyanko 
377f2cddd54SIgor Mitsyanko void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted)
378f2cddd54SIgor Mitsyanko {
379f2cddd54SIgor Mitsyanko 	cancel_delayed_work_sync(&mac->scan_timeout);
380f2cddd54SIgor Mitsyanko 	qtnf_mac_scan_finish(mac, aborted);
381f2cddd54SIgor Mitsyanko }
382f2cddd54SIgor Mitsyanko 
383f2cddd54SIgor Mitsyanko static void qtnf_mac_scan_timeout(struct work_struct *work)
384f2cddd54SIgor Mitsyanko {
385f2cddd54SIgor Mitsyanko 	struct qtnf_wmac *mac =
386f2cddd54SIgor Mitsyanko 		container_of(work, struct qtnf_wmac, scan_timeout.work);
387f2cddd54SIgor Mitsyanko 
388f2cddd54SIgor Mitsyanko 	pr_warn("MAC%d: scan timed out\n", mac->macid);
389f2cddd54SIgor Mitsyanko 	qtnf_mac_scan_finish(mac, true);
390f2cddd54SIgor Mitsyanko }
391f2cddd54SIgor Mitsyanko 
392bc70732fSIgor Mitsyanko static void qtnf_vif_send_data_high_pri(struct work_struct *work)
393bc70732fSIgor Mitsyanko {
394bc70732fSIgor Mitsyanko 	struct qtnf_vif *vif =
395bc70732fSIgor Mitsyanko 		container_of(work, struct qtnf_vif, high_pri_tx_work);
396bc70732fSIgor Mitsyanko 	struct sk_buff *skb;
397bc70732fSIgor Mitsyanko 
398bc70732fSIgor Mitsyanko 	if (!vif->netdev ||
399bc70732fSIgor Mitsyanko 	    vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
400bc70732fSIgor Mitsyanko 		return;
401bc70732fSIgor Mitsyanko 
402bc70732fSIgor Mitsyanko 	while ((skb = skb_dequeue(&vif->high_pri_tx_queue))) {
403bc70732fSIgor Mitsyanko 		qtnf_cmd_send_frame(vif, 0, QLINK_FRAME_TX_FLAG_8023,
404bc70732fSIgor Mitsyanko 				    0, skb->data, skb->len);
405bc70732fSIgor Mitsyanko 		dev_kfree_skb_any(skb);
406bc70732fSIgor Mitsyanko 	}
407bc70732fSIgor Mitsyanko }
408bc70732fSIgor Mitsyanko 
40998f44cb0SIgor Mitsyanko static struct qtnf_wmac *qtnf_core_mac_alloc(struct qtnf_bus *bus,
41098f44cb0SIgor Mitsyanko 					     unsigned int macid)
41198f44cb0SIgor Mitsyanko {
412616f5701SSergey Matyukevich 	struct platform_device *pdev = NULL;
413616f5701SSergey Matyukevich 	struct qtnf_wmac *mac;
41475001bbcSIgor Mitsyanko 	struct qtnf_vif *vif;
41598f44cb0SIgor Mitsyanko 	struct wiphy *wiphy;
41698f44cb0SIgor Mitsyanko 	unsigned int i;
41798f44cb0SIgor Mitsyanko 
418616f5701SSergey Matyukevich 	if (bus->hw_info.num_mac > 1) {
419616f5701SSergey Matyukevich 		pdev = platform_device_register_data(bus->dev,
420616f5701SSergey Matyukevich 						     dev_name(bus->dev),
421616f5701SSergey Matyukevich 						     macid, NULL, 0);
422616f5701SSergey Matyukevich 		if (IS_ERR(pdev))
423616f5701SSergey Matyukevich 			return ERR_PTR(-EINVAL);
424616f5701SSergey Matyukevich 	}
425616f5701SSergey Matyukevich 
426616f5701SSergey Matyukevich 	wiphy = qtnf_wiphy_allocate(bus, pdev);
427141bc9abSWang Hai 	if (!wiphy) {
428141bc9abSWang Hai 		if (pdev)
429141bc9abSWang Hai 			platform_device_unregister(pdev);
43098f44cb0SIgor Mitsyanko 		return ERR_PTR(-ENOMEM);
431141bc9abSWang Hai 	}
43298f44cb0SIgor Mitsyanko 
43398f44cb0SIgor Mitsyanko 	mac = wiphy_priv(wiphy);
43498f44cb0SIgor Mitsyanko 
43598f44cb0SIgor Mitsyanko 	mac->macid = macid;
436616f5701SSergey Matyukevich 	mac->pdev = pdev;
43798f44cb0SIgor Mitsyanko 	mac->bus = bus;
438c7ead2abSSergey Matyukevich 	mutex_init(&mac->mac_lock);
439f2cddd54SIgor Mitsyanko 	INIT_DELAYED_WORK(&mac->scan_timeout, qtnf_mac_scan_timeout);
44075001bbcSIgor Mitsyanko 
44175001bbcSIgor Mitsyanko 	for (i = 0; i < QTNF_MAX_INTF; i++) {
44275001bbcSIgor Mitsyanko 		vif = &mac->iflist[i];
44375001bbcSIgor Mitsyanko 
44475001bbcSIgor Mitsyanko 		memset(vif, 0, sizeof(*vif));
44575001bbcSIgor Mitsyanko 		vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
44675001bbcSIgor Mitsyanko 		vif->mac = mac;
44775001bbcSIgor Mitsyanko 		vif->vifid = i;
44875001bbcSIgor Mitsyanko 		qtnf_sta_list_init(&vif->sta_list);
449bc70732fSIgor Mitsyanko 		INIT_WORK(&vif->high_pri_tx_work, qtnf_vif_send_data_high_pri);
450bc70732fSIgor Mitsyanko 		skb_queue_head_init(&vif->high_pri_tx_queue);
45175001bbcSIgor Mitsyanko 		vif->stats64 = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
45275001bbcSIgor Mitsyanko 		if (!vif->stats64)
45304b01affSVasily Ulyanov 			pr_warn("VIF%u.%u: per cpu stats allocation failed\n",
45404b01affSVasily Ulyanov 				macid, i);
45598f44cb0SIgor Mitsyanko 	}
45698f44cb0SIgor Mitsyanko 
45798f44cb0SIgor Mitsyanko 	qtnf_mac_init_primary_intf(mac);
45898f44cb0SIgor Mitsyanko 	bus->mac[macid] = mac;
45998f44cb0SIgor Mitsyanko 
46098f44cb0SIgor Mitsyanko 	return mac;
46198f44cb0SIgor Mitsyanko }
46298f44cb0SIgor Mitsyanko 
4630b419d01SVasily Ulyanov static const struct ethtool_ops qtnf_ethtool_ops = {
4640b419d01SVasily Ulyanov 	.get_drvinfo = cfg80211_get_drvinfo,
4650b419d01SVasily Ulyanov };
4660b419d01SVasily Ulyanov 
46798f44cb0SIgor Mitsyanko int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *vif,
468e6ef8cd0SIgor Mitsyanko 			 const char *name, unsigned char name_assign_type)
46998f44cb0SIgor Mitsyanko {
47098f44cb0SIgor Mitsyanko 	struct wiphy *wiphy = priv_to_wiphy(mac);
47198f44cb0SIgor Mitsyanko 	struct net_device *dev;
47298f44cb0SIgor Mitsyanko 	void *qdev_vif;
47398f44cb0SIgor Mitsyanko 	int ret;
47498f44cb0SIgor Mitsyanko 
47598f44cb0SIgor Mitsyanko 	dev = alloc_netdev_mqs(sizeof(struct qtnf_vif *), name,
47698f44cb0SIgor Mitsyanko 			       name_assign_type, ether_setup, 1, 1);
47745028223SIgor Mitsyanko 	if (!dev)
47898f44cb0SIgor Mitsyanko 		return -ENOMEM;
47998f44cb0SIgor Mitsyanko 
48098f44cb0SIgor Mitsyanko 	vif->netdev = dev;
48198f44cb0SIgor Mitsyanko 
48298f44cb0SIgor Mitsyanko 	dev->netdev_ops = &qtnf_netdev_ops;
4830ddead90SDavid S. Miller 	dev->needs_free_netdev = true;
48498f44cb0SIgor Mitsyanko 	dev_net_set(dev, wiphy_net(wiphy));
48598f44cb0SIgor Mitsyanko 	dev->ieee80211_ptr = &vif->wdev;
48698f44cb0SIgor Mitsyanko 	ether_addr_copy(dev->dev_addr, vif->mac_addr);
48798f44cb0SIgor Mitsyanko 	dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
48898f44cb0SIgor Mitsyanko 	dev->watchdog_timeo = QTNF_DEF_WDOG_TIMEOUT;
48998f44cb0SIgor Mitsyanko 	dev->tx_queue_len = 100;
4900b419d01SVasily Ulyanov 	dev->ethtool_ops = &qtnf_ethtool_ops;
49198f44cb0SIgor Mitsyanko 
492310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(&mac->bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE))
493904628d3SIgor Mitsyanko 		dev->needed_tailroom = sizeof(struct qtnf_frame_meta_info);
494904628d3SIgor Mitsyanko 
49598f44cb0SIgor Mitsyanko 	qdev_vif = netdev_priv(dev);
49698f44cb0SIgor Mitsyanko 	*((void **)qdev_vif) = vif;
49798f44cb0SIgor Mitsyanko 
498616f5701SSergey Matyukevich 	SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
49998f44cb0SIgor Mitsyanko 
50098f44cb0SIgor Mitsyanko 	ret = register_netdevice(dev);
50198f44cb0SIgor Mitsyanko 	if (ret) {
50298f44cb0SIgor Mitsyanko 		free_netdev(dev);
50345028223SIgor Mitsyanko 		vif->netdev = NULL;
50498f44cb0SIgor Mitsyanko 	}
50598f44cb0SIgor Mitsyanko 
50698f44cb0SIgor Mitsyanko 	return ret;
50798f44cb0SIgor Mitsyanko }
50898f44cb0SIgor Mitsyanko 
50998f44cb0SIgor Mitsyanko static void qtnf_core_mac_detach(struct qtnf_bus *bus, unsigned int macid)
51098f44cb0SIgor Mitsyanko {
51198f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac;
51298f44cb0SIgor Mitsyanko 	struct wiphy *wiphy;
51398f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
51498f44cb0SIgor Mitsyanko 	unsigned int i;
51598f44cb0SIgor Mitsyanko 	enum nl80211_band band;
51698f44cb0SIgor Mitsyanko 
51798f44cb0SIgor Mitsyanko 	mac = bus->mac[macid];
51898f44cb0SIgor Mitsyanko 
51998f44cb0SIgor Mitsyanko 	if (!mac)
52098f44cb0SIgor Mitsyanko 		return;
52198f44cb0SIgor Mitsyanko 
52298f44cb0SIgor Mitsyanko 	wiphy = priv_to_wiphy(mac);
52398f44cb0SIgor Mitsyanko 
52498f44cb0SIgor Mitsyanko 	for (i = 0; i < QTNF_MAX_INTF; i++) {
52598f44cb0SIgor Mitsyanko 		vif = &mac->iflist[i];
52698f44cb0SIgor Mitsyanko 		rtnl_lock();
52798f44cb0SIgor Mitsyanko 		if (vif->netdev &&
52898f44cb0SIgor Mitsyanko 		    vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED) {
52998f44cb0SIgor Mitsyanko 			qtnf_virtual_intf_cleanup(vif->netdev);
53098f44cb0SIgor Mitsyanko 			qtnf_del_virtual_intf(wiphy, &vif->wdev);
53198f44cb0SIgor Mitsyanko 		}
53298f44cb0SIgor Mitsyanko 		rtnl_unlock();
53398f44cb0SIgor Mitsyanko 		qtnf_sta_list_free(&vif->sta_list);
53404b01affSVasily Ulyanov 		free_percpu(vif->stats64);
53598f44cb0SIgor Mitsyanko 	}
53698f44cb0SIgor Mitsyanko 
53798f44cb0SIgor Mitsyanko 	if (mac->wiphy_registered)
53898f44cb0SIgor Mitsyanko 		wiphy_unregister(wiphy);
53998f44cb0SIgor Mitsyanko 
54098f44cb0SIgor Mitsyanko 	for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; ++band) {
54198f44cb0SIgor Mitsyanko 		if (!wiphy->bands[band])
54298f44cb0SIgor Mitsyanko 			continue;
54398f44cb0SIgor Mitsyanko 
544df0af4c7SMikhail Karpenko 		kfree(wiphy->bands[band]->iftype_data);
545df0af4c7SMikhail Karpenko 		wiphy->bands[band]->n_iftype_data = 0;
546df0af4c7SMikhail Karpenko 
54798f44cb0SIgor Mitsyanko 		kfree(wiphy->bands[band]->channels);
54898f44cb0SIgor Mitsyanko 		wiphy->bands[band]->n_channels = 0;
54998f44cb0SIgor Mitsyanko 
55098f44cb0SIgor Mitsyanko 		kfree(wiphy->bands[band]);
55198f44cb0SIgor Mitsyanko 		wiphy->bands[band] = NULL;
55298f44cb0SIgor Mitsyanko 	}
55398f44cb0SIgor Mitsyanko 
554616f5701SSergey Matyukevich 	platform_device_unregister(mac->pdev);
555537faf26SSergey Matyukevich 	qtnf_mac_iface_comb_free(mac);
556ab1c64a1SSergey Matyukevich 	qtnf_mac_ext_caps_free(mac);
55728b91884SSergey Matyukevich 	kfree(mac->macinfo.wowlan);
558c698bce0SIgor Mitsyanko 	kfree(mac->rd);
559c698bce0SIgor Mitsyanko 	mac->rd = NULL;
56098f44cb0SIgor Mitsyanko 	wiphy_free(wiphy);
56198f44cb0SIgor Mitsyanko 	bus->mac[macid] = NULL;
56298f44cb0SIgor Mitsyanko }
56398f44cb0SIgor Mitsyanko 
56498f44cb0SIgor Mitsyanko static int qtnf_core_mac_attach(struct qtnf_bus *bus, unsigned int macid)
56598f44cb0SIgor Mitsyanko {
56698f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac;
56798f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
56898f44cb0SIgor Mitsyanko 	int ret;
56998f44cb0SIgor Mitsyanko 
57098f44cb0SIgor Mitsyanko 	if (!(bus->hw_info.mac_bitmap & BIT(macid))) {
57198f44cb0SIgor Mitsyanko 		pr_info("MAC%u is not active in FW\n", macid);
57298f44cb0SIgor Mitsyanko 		return 0;
57398f44cb0SIgor Mitsyanko 	}
57498f44cb0SIgor Mitsyanko 
57598f44cb0SIgor Mitsyanko 	mac = qtnf_core_mac_alloc(bus, macid);
57698f44cb0SIgor Mitsyanko 	if (IS_ERR(mac)) {
57798f44cb0SIgor Mitsyanko 		pr_err("MAC%u allocation failed\n", macid);
57898f44cb0SIgor Mitsyanko 		return PTR_ERR(mac);
57998f44cb0SIgor Mitsyanko 	}
58098f44cb0SIgor Mitsyanko 
58198f44cb0SIgor Mitsyanko 	vif = qtnf_mac_get_base_vif(mac);
58298f44cb0SIgor Mitsyanko 	if (!vif) {
58398f44cb0SIgor Mitsyanko 		pr_err("MAC%u: primary VIF is not ready\n", macid);
58498f44cb0SIgor Mitsyanko 		ret = -EFAULT;
58598f44cb0SIgor Mitsyanko 		goto error;
58698f44cb0SIgor Mitsyanko 	}
58798f44cb0SIgor Mitsyanko 
588de624a35SSergey Matyukevich 	ret = qtnf_cmd_send_add_intf(vif, vif->wdev.iftype,
589de624a35SSergey Matyukevich 				     vif->wdev.use_4addr, vif->mac_addr);
59098f44cb0SIgor Mitsyanko 	if (ret) {
59198f44cb0SIgor Mitsyanko 		pr_err("MAC%u: failed to add VIF\n", macid);
59298f44cb0SIgor Mitsyanko 		goto error;
59398f44cb0SIgor Mitsyanko 	}
59498f44cb0SIgor Mitsyanko 
595e70cf22bSIgor Mitsyanko 	ret = qtnf_cmd_get_mac_info(mac);
59698f44cb0SIgor Mitsyanko 	if (ret) {
597e70cf22bSIgor Mitsyanko 		pr_err("MAC%u: failed to get MAC info\n", macid);
59845028223SIgor Mitsyanko 		goto error_del_vif;
59998f44cb0SIgor Mitsyanko 	}
60098f44cb0SIgor Mitsyanko 
601e70cf22bSIgor Mitsyanko 	/* Use MAC address of the first active radio as a unique device ID */
602e70cf22bSIgor Mitsyanko 	if (is_zero_ether_addr(mac->bus->hw_id))
603e70cf22bSIgor Mitsyanko 		ether_addr_copy(mac->bus->hw_id, mac->macaddr);
604e70cf22bSIgor Mitsyanko 
60598f44cb0SIgor Mitsyanko 	ret = qtnf_mac_init_bands(mac);
60698f44cb0SIgor Mitsyanko 	if (ret) {
60798f44cb0SIgor Mitsyanko 		pr_err("MAC%u: failed to init bands\n", macid);
60845028223SIgor Mitsyanko 		goto error_del_vif;
60998f44cb0SIgor Mitsyanko 	}
61098f44cb0SIgor Mitsyanko 
61198f44cb0SIgor Mitsyanko 	ret = qtnf_wiphy_register(&bus->hw_info, mac);
61298f44cb0SIgor Mitsyanko 	if (ret) {
61398f44cb0SIgor Mitsyanko 		pr_err("MAC%u: wiphy registration failed\n", macid);
61445028223SIgor Mitsyanko 		goto error_del_vif;
61598f44cb0SIgor Mitsyanko 	}
61698f44cb0SIgor Mitsyanko 
61798f44cb0SIgor Mitsyanko 	mac->wiphy_registered = 1;
61898f44cb0SIgor Mitsyanko 
61998f44cb0SIgor Mitsyanko 	rtnl_lock();
62098f44cb0SIgor Mitsyanko 
621e6ef8cd0SIgor Mitsyanko 	ret = qtnf_core_net_attach(mac, vif, "wlan%d", NET_NAME_ENUM);
62298f44cb0SIgor Mitsyanko 	rtnl_unlock();
62398f44cb0SIgor Mitsyanko 
62498f44cb0SIgor Mitsyanko 	if (ret) {
62598f44cb0SIgor Mitsyanko 		pr_err("MAC%u: failed to attach netdev\n", macid);
62645028223SIgor Mitsyanko 		goto error_del_vif;
62798f44cb0SIgor Mitsyanko 	}
62898f44cb0SIgor Mitsyanko 
629310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE)) {
630decfc5c7SIgor Mitsyanko 		ret = qtnf_cmd_netdev_changeupper(vif, vif->netdev->ifindex);
631decfc5c7SIgor Mitsyanko 		if (ret)
632decfc5c7SIgor Mitsyanko 			goto error;
633decfc5c7SIgor Mitsyanko 	}
634decfc5c7SIgor Mitsyanko 
63598f44cb0SIgor Mitsyanko 	pr_debug("MAC%u initialized\n", macid);
63698f44cb0SIgor Mitsyanko 
63798f44cb0SIgor Mitsyanko 	return 0;
63898f44cb0SIgor Mitsyanko 
63945028223SIgor Mitsyanko error_del_vif:
64045028223SIgor Mitsyanko 	qtnf_cmd_send_del_intf(vif);
64145028223SIgor Mitsyanko 	vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
64298f44cb0SIgor Mitsyanko error:
64398f44cb0SIgor Mitsyanko 	qtnf_core_mac_detach(bus, macid);
64498f44cb0SIgor Mitsyanko 	return ret;
64598f44cb0SIgor Mitsyanko }
64698f44cb0SIgor Mitsyanko 
647decfc5c7SIgor Mitsyanko bool qtnf_netdev_is_qtn(const struct net_device *ndev)
648decfc5c7SIgor Mitsyanko {
649decfc5c7SIgor Mitsyanko 	return ndev->netdev_ops == &qtnf_netdev_ops;
650decfc5c7SIgor Mitsyanko }
651decfc5c7SIgor Mitsyanko 
652eff74233STaehee Yoo static int qtnf_check_br_ports(struct net_device *dev,
653eff74233STaehee Yoo 			       struct netdev_nested_priv *priv)
654e1429175SSergey Matyukevich {
655eff74233STaehee Yoo 	struct net_device *ndev = (struct net_device *)priv->data;
656e1429175SSergey Matyukevich 
657e1429175SSergey Matyukevich 	if (dev != ndev && netdev_port_same_parent_id(dev, ndev))
658e1429175SSergey Matyukevich 		return -ENOTSUPP;
659e1429175SSergey Matyukevich 
660e1429175SSergey Matyukevich 	return 0;
661e1429175SSergey Matyukevich }
662e1429175SSergey Matyukevich 
663decfc5c7SIgor Mitsyanko static int qtnf_core_netdevice_event(struct notifier_block *nb,
664decfc5c7SIgor Mitsyanko 				     unsigned long event, void *ptr)
665decfc5c7SIgor Mitsyanko {
666decfc5c7SIgor Mitsyanko 	struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
667decfc5c7SIgor Mitsyanko 	const struct netdev_notifier_changeupper_info *info;
668eff74233STaehee Yoo 	struct netdev_nested_priv priv = {
669eff74233STaehee Yoo 		.data = (void *)ndev,
670eff74233STaehee Yoo 	};
671e1429175SSergey Matyukevich 	struct net_device *brdev;
672decfc5c7SIgor Mitsyanko 	struct qtnf_vif *vif;
673e1429175SSergey Matyukevich 	struct qtnf_bus *bus;
674decfc5c7SIgor Mitsyanko 	int br_domain;
675decfc5c7SIgor Mitsyanko 	int ret = 0;
676decfc5c7SIgor Mitsyanko 
677decfc5c7SIgor Mitsyanko 	if (!qtnf_netdev_is_qtn(ndev))
678decfc5c7SIgor Mitsyanko 		return NOTIFY_DONE;
679decfc5c7SIgor Mitsyanko 
680decfc5c7SIgor Mitsyanko 	if (!net_eq(dev_net(ndev), &init_net))
681decfc5c7SIgor Mitsyanko 		return NOTIFY_OK;
682decfc5c7SIgor Mitsyanko 
683decfc5c7SIgor Mitsyanko 	vif = qtnf_netdev_get_priv(ndev);
684e1429175SSergey Matyukevich 	bus = vif->mac->bus;
685decfc5c7SIgor Mitsyanko 
686decfc5c7SIgor Mitsyanko 	switch (event) {
687decfc5c7SIgor Mitsyanko 	case NETDEV_CHANGEUPPER:
688decfc5c7SIgor Mitsyanko 		info = ptr;
689e1429175SSergey Matyukevich 		brdev = info->upper_dev;
690decfc5c7SIgor Mitsyanko 
691e1429175SSergey Matyukevich 		if (!netif_is_bridge_master(brdev))
692decfc5c7SIgor Mitsyanko 			break;
693decfc5c7SIgor Mitsyanko 
694decfc5c7SIgor Mitsyanko 		pr_debug("[VIF%u.%u] change bridge: %s %s\n",
695e1429175SSergey Matyukevich 			 vif->mac->macid, vif->vifid, netdev_name(brdev),
696decfc5c7SIgor Mitsyanko 			 info->linking ? "add" : "del");
697decfc5c7SIgor Mitsyanko 
698e1429175SSergey Matyukevich 		if (IS_ENABLED(CONFIG_NET_SWITCHDEV) &&
699310cd5ddSIgor Mitsyanko 		    qtnf_hwcap_is_set(&bus->hw_info,
700310cd5ddSIgor Mitsyanko 				      QLINK_HW_CAPAB_HW_BRIDGE)) {
701decfc5c7SIgor Mitsyanko 			if (info->linking)
702e1429175SSergey Matyukevich 				br_domain = brdev->ifindex;
703decfc5c7SIgor Mitsyanko 			else
704decfc5c7SIgor Mitsyanko 				br_domain = ndev->ifindex;
705decfc5c7SIgor Mitsyanko 
706decfc5c7SIgor Mitsyanko 			ret = qtnf_cmd_netdev_changeupper(vif, br_domain);
707e1429175SSergey Matyukevich 		} else {
708e1429175SSergey Matyukevich 			ret = netdev_walk_all_lower_dev(brdev,
709e1429175SSergey Matyukevich 							qtnf_check_br_ports,
710eff74233STaehee Yoo 							&priv);
711e1429175SSergey Matyukevich 		}
712e1429175SSergey Matyukevich 
713decfc5c7SIgor Mitsyanko 		break;
714decfc5c7SIgor Mitsyanko 	default:
715decfc5c7SIgor Mitsyanko 		break;
716decfc5c7SIgor Mitsyanko 	}
717decfc5c7SIgor Mitsyanko 
718decfc5c7SIgor Mitsyanko 	return notifier_from_errno(ret);
719decfc5c7SIgor Mitsyanko }
720decfc5c7SIgor Mitsyanko 
72198f44cb0SIgor Mitsyanko int qtnf_core_attach(struct qtnf_bus *bus)
72298f44cb0SIgor Mitsyanko {
72398f44cb0SIgor Mitsyanko 	unsigned int i;
72498f44cb0SIgor Mitsyanko 	int ret;
72598f44cb0SIgor Mitsyanko 
72698f44cb0SIgor Mitsyanko 	qtnf_trans_init(bus);
72798f44cb0SIgor Mitsyanko 	qtnf_bus_data_rx_start(bus);
72898f44cb0SIgor Mitsyanko 
72998f44cb0SIgor Mitsyanko 	bus->workqueue = alloc_ordered_workqueue("QTNF_BUS", 0);
73098f44cb0SIgor Mitsyanko 	if (!bus->workqueue) {
73198f44cb0SIgor Mitsyanko 		pr_err("failed to alloc main workqueue\n");
73298f44cb0SIgor Mitsyanko 		ret = -ENOMEM;
73398f44cb0SIgor Mitsyanko 		goto error;
73498f44cb0SIgor Mitsyanko 	}
73598f44cb0SIgor Mitsyanko 
736bc70732fSIgor Mitsyanko 	bus->hprio_workqueue = alloc_workqueue("QTNF_HPRI", WQ_HIGHPRI, 0);
737bc70732fSIgor Mitsyanko 	if (!bus->hprio_workqueue) {
738bc70732fSIgor Mitsyanko 		pr_err("failed to alloc high prio workqueue\n");
739bc70732fSIgor Mitsyanko 		ret = -ENOMEM;
740bc70732fSIgor Mitsyanko 		goto error;
741bc70732fSIgor Mitsyanko 	}
742bc70732fSIgor Mitsyanko 
74398f44cb0SIgor Mitsyanko 	INIT_WORK(&bus->event_work, qtnf_event_work_handler);
74498f44cb0SIgor Mitsyanko 
74598f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_init_fw(bus);
74698f44cb0SIgor Mitsyanko 	if (ret) {
74798f44cb0SIgor Mitsyanko 		pr_err("failed to init FW: %d\n", ret);
74898f44cb0SIgor Mitsyanko 		goto error;
74998f44cb0SIgor Mitsyanko 	}
75098f44cb0SIgor Mitsyanko 
751a3ebb033SIgor Mitsyanko 	if (QLINK_VER_MAJOR(bus->hw_info.ql_proto_ver) !=
752a3ebb033SIgor Mitsyanko 	    QLINK_PROTO_VER_MAJOR) {
753a3ebb033SIgor Mitsyanko 		pr_err("qlink driver vs FW version mismatch: %u vs %u\n",
754a3ebb033SIgor Mitsyanko 		       QLINK_PROTO_VER_MAJOR,
755a3ebb033SIgor Mitsyanko 		       QLINK_VER_MAJOR(bus->hw_info.ql_proto_ver));
756a3ebb033SIgor Mitsyanko 		ret = -EPROTONOSUPPORT;
757a3ebb033SIgor Mitsyanko 		goto error;
758a3ebb033SIgor Mitsyanko 	}
759a3ebb033SIgor Mitsyanko 
76098f44cb0SIgor Mitsyanko 	bus->fw_state = QTNF_FW_STATE_ACTIVE;
76198f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_get_hw_info(bus);
76298f44cb0SIgor Mitsyanko 	if (ret) {
76398f44cb0SIgor Mitsyanko 		pr_err("failed to get HW info: %d\n", ret);
76498f44cb0SIgor Mitsyanko 		goto error;
76598f44cb0SIgor Mitsyanko 	}
76698f44cb0SIgor Mitsyanko 
767310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE) &&
768904628d3SIgor Mitsyanko 	    bus->bus_ops->data_tx_use_meta_set)
769904628d3SIgor Mitsyanko 		bus->bus_ops->data_tx_use_meta_set(bus, true);
770904628d3SIgor Mitsyanko 
77198f44cb0SIgor Mitsyanko 	if (bus->hw_info.num_mac > QTNF_MAX_MAC) {
77298f44cb0SIgor Mitsyanko 		pr_err("no support for number of MACs=%u\n",
77398f44cb0SIgor Mitsyanko 		       bus->hw_info.num_mac);
77498f44cb0SIgor Mitsyanko 		ret = -ERANGE;
77598f44cb0SIgor Mitsyanko 		goto error;
77698f44cb0SIgor Mitsyanko 	}
77798f44cb0SIgor Mitsyanko 
77898f44cb0SIgor Mitsyanko 	for (i = 0; i < bus->hw_info.num_mac; i++) {
77998f44cb0SIgor Mitsyanko 		ret = qtnf_core_mac_attach(bus, i);
78098f44cb0SIgor Mitsyanko 
78198f44cb0SIgor Mitsyanko 		if (ret) {
78298f44cb0SIgor Mitsyanko 			pr_err("MAC%u: attach failed: %d\n", i, ret);
78398f44cb0SIgor Mitsyanko 			goto error;
78498f44cb0SIgor Mitsyanko 		}
78598f44cb0SIgor Mitsyanko 	}
78698f44cb0SIgor Mitsyanko 
787decfc5c7SIgor Mitsyanko 	bus->netdev_nb.notifier_call = qtnf_core_netdevice_event;
788decfc5c7SIgor Mitsyanko 	ret = register_netdevice_notifier(&bus->netdev_nb);
789decfc5c7SIgor Mitsyanko 	if (ret) {
790decfc5c7SIgor Mitsyanko 		pr_err("failed to register netdev notifier: %d\n", ret);
791decfc5c7SIgor Mitsyanko 		goto error;
792decfc5c7SIgor Mitsyanko 	}
793decfc5c7SIgor Mitsyanko 
79483b00f6eSSergey Matyukevich 	bus->fw_state = QTNF_FW_STATE_RUNNING;
79598f44cb0SIgor Mitsyanko 	return 0;
79698f44cb0SIgor Mitsyanko 
79798f44cb0SIgor Mitsyanko error:
79898f44cb0SIgor Mitsyanko 	qtnf_core_detach(bus);
79998f44cb0SIgor Mitsyanko 	return ret;
80098f44cb0SIgor Mitsyanko }
80198f44cb0SIgor Mitsyanko EXPORT_SYMBOL_GPL(qtnf_core_attach);
80298f44cb0SIgor Mitsyanko 
80398f44cb0SIgor Mitsyanko void qtnf_core_detach(struct qtnf_bus *bus)
80498f44cb0SIgor Mitsyanko {
80598f44cb0SIgor Mitsyanko 	unsigned int macid;
80698f44cb0SIgor Mitsyanko 
807decfc5c7SIgor Mitsyanko 	unregister_netdevice_notifier(&bus->netdev_nb);
80898f44cb0SIgor Mitsyanko 	qtnf_bus_data_rx_stop(bus);
80998f44cb0SIgor Mitsyanko 
81098f44cb0SIgor Mitsyanko 	for (macid = 0; macid < QTNF_MAX_MAC; macid++)
81198f44cb0SIgor Mitsyanko 		qtnf_core_mac_detach(bus, macid);
81298f44cb0SIgor Mitsyanko 
81383b00f6eSSergey Matyukevich 	if (qtnf_fw_is_up(bus))
81498f44cb0SIgor Mitsyanko 		qtnf_cmd_send_deinit_fw(bus);
81598f44cb0SIgor Mitsyanko 
8169e33e7fbSDmitry Lebed 	bus->fw_state = QTNF_FW_STATE_DETACHED;
81798f44cb0SIgor Mitsyanko 
81898f44cb0SIgor Mitsyanko 	if (bus->workqueue) {
81998f44cb0SIgor Mitsyanko 		flush_workqueue(bus->workqueue);
82098f44cb0SIgor Mitsyanko 		destroy_workqueue(bus->workqueue);
821bc70732fSIgor Mitsyanko 		bus->workqueue = NULL;
822bc70732fSIgor Mitsyanko 	}
823bc70732fSIgor Mitsyanko 
824bc70732fSIgor Mitsyanko 	if (bus->hprio_workqueue) {
825bc70732fSIgor Mitsyanko 		flush_workqueue(bus->hprio_workqueue);
826bc70732fSIgor Mitsyanko 		destroy_workqueue(bus->hprio_workqueue);
827bc70732fSIgor Mitsyanko 		bus->hprio_workqueue = NULL;
82898f44cb0SIgor Mitsyanko 	}
82998f44cb0SIgor Mitsyanko 
83098f44cb0SIgor Mitsyanko 	qtnf_trans_free(bus);
83198f44cb0SIgor Mitsyanko }
83298f44cb0SIgor Mitsyanko EXPORT_SYMBOL_GPL(qtnf_core_detach);
83398f44cb0SIgor Mitsyanko 
83498f44cb0SIgor Mitsyanko static inline int qtnf_is_frame_meta_magic_valid(struct qtnf_frame_meta_info *m)
83598f44cb0SIgor Mitsyanko {
836904628d3SIgor Mitsyanko 	return m->magic_s == HBM_FRAME_META_MAGIC_PATTERN_S &&
837904628d3SIgor Mitsyanko 		m->magic_e == HBM_FRAME_META_MAGIC_PATTERN_E;
83898f44cb0SIgor Mitsyanko }
83998f44cb0SIgor Mitsyanko 
84098f44cb0SIgor Mitsyanko struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb)
84198f44cb0SIgor Mitsyanko {
84298f44cb0SIgor Mitsyanko 	struct qtnf_frame_meta_info *meta;
84398f44cb0SIgor Mitsyanko 	struct net_device *ndev = NULL;
84498f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac;
84598f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
84698f44cb0SIgor Mitsyanko 
84783b00f6eSSergey Matyukevich 	if (unlikely(bus->fw_state != QTNF_FW_STATE_RUNNING))
84883b00f6eSSergey Matyukevich 		return NULL;
84983b00f6eSSergey Matyukevich 
85098f44cb0SIgor Mitsyanko 	meta = (struct qtnf_frame_meta_info *)
85198f44cb0SIgor Mitsyanko 		(skb_tail_pointer(skb) - sizeof(*meta));
85298f44cb0SIgor Mitsyanko 
85398f44cb0SIgor Mitsyanko 	if (unlikely(!qtnf_is_frame_meta_magic_valid(meta))) {
85498f44cb0SIgor Mitsyanko 		pr_err_ratelimited("invalid magic 0x%x:0x%x\n",
85598f44cb0SIgor Mitsyanko 				   meta->magic_s, meta->magic_e);
85698f44cb0SIgor Mitsyanko 		goto out;
85798f44cb0SIgor Mitsyanko 	}
85898f44cb0SIgor Mitsyanko 
85998f44cb0SIgor Mitsyanko 	if (unlikely(meta->macid >= QTNF_MAX_MAC)) {
86098f44cb0SIgor Mitsyanko 		pr_err_ratelimited("invalid mac(%u)\n", meta->macid);
86198f44cb0SIgor Mitsyanko 		goto out;
86298f44cb0SIgor Mitsyanko 	}
86398f44cb0SIgor Mitsyanko 
86498f44cb0SIgor Mitsyanko 	if (unlikely(meta->ifidx >= QTNF_MAX_INTF)) {
86598f44cb0SIgor Mitsyanko 		pr_err_ratelimited("invalid vif(%u)\n", meta->ifidx);
86698f44cb0SIgor Mitsyanko 		goto out;
86798f44cb0SIgor Mitsyanko 	}
86898f44cb0SIgor Mitsyanko 
86998f44cb0SIgor Mitsyanko 	mac = bus->mac[meta->macid];
87098f44cb0SIgor Mitsyanko 
87198f44cb0SIgor Mitsyanko 	if (unlikely(!mac)) {
87298f44cb0SIgor Mitsyanko 		pr_err_ratelimited("mac(%d) does not exist\n", meta->macid);
87398f44cb0SIgor Mitsyanko 		goto out;
87498f44cb0SIgor Mitsyanko 	}
87598f44cb0SIgor Mitsyanko 
87698f44cb0SIgor Mitsyanko 	vif = &mac->iflist[meta->ifidx];
87798f44cb0SIgor Mitsyanko 
87898f44cb0SIgor Mitsyanko 	if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
87998f44cb0SIgor Mitsyanko 		pr_err_ratelimited("vif(%u) does not exists\n", meta->ifidx);
88098f44cb0SIgor Mitsyanko 		goto out;
88198f44cb0SIgor Mitsyanko 	}
88298f44cb0SIgor Mitsyanko 
88398f44cb0SIgor Mitsyanko 	ndev = vif->netdev;
88498f44cb0SIgor Mitsyanko 
88598f44cb0SIgor Mitsyanko 	if (unlikely(!ndev)) {
88698f44cb0SIgor Mitsyanko 		pr_err_ratelimited("netdev for wlan%u.%u does not exists\n",
88798f44cb0SIgor Mitsyanko 				   meta->macid, meta->ifidx);
88898f44cb0SIgor Mitsyanko 		goto out;
88998f44cb0SIgor Mitsyanko 	}
89098f44cb0SIgor Mitsyanko 
89198f44cb0SIgor Mitsyanko 	__skb_trim(skb, skb->len - sizeof(*meta));
8921db35994SIgor Mitsyanko 	/* Firmware always handles packets that require flooding */
8931db35994SIgor Mitsyanko 	qtnfmac_switch_mark_skb_flooded(skb);
89498f44cb0SIgor Mitsyanko 
89598f44cb0SIgor Mitsyanko out:
89698f44cb0SIgor Mitsyanko 	return ndev;
89798f44cb0SIgor Mitsyanko }
89898f44cb0SIgor Mitsyanko EXPORT_SYMBOL_GPL(qtnf_classify_skb);
89998f44cb0SIgor Mitsyanko 
900c35c0d54SSergey Matyukevich void qtnf_wake_all_queues(struct net_device *ndev)
901c35c0d54SSergey Matyukevich {
902c35c0d54SSergey Matyukevich 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
903c35c0d54SSergey Matyukevich 	struct qtnf_wmac *mac;
904c35c0d54SSergey Matyukevich 	struct qtnf_bus *bus;
905c35c0d54SSergey Matyukevich 	int macid;
906c35c0d54SSergey Matyukevich 	int i;
907c35c0d54SSergey Matyukevich 
908c35c0d54SSergey Matyukevich 	if (unlikely(!vif || !vif->mac || !vif->mac->bus))
909c35c0d54SSergey Matyukevich 		return;
910c35c0d54SSergey Matyukevich 
911c35c0d54SSergey Matyukevich 	bus = vif->mac->bus;
912c35c0d54SSergey Matyukevich 
913c35c0d54SSergey Matyukevich 	for (macid = 0; macid < QTNF_MAX_MAC; macid++) {
914c35c0d54SSergey Matyukevich 		if (!(bus->hw_info.mac_bitmap & BIT(macid)))
915c35c0d54SSergey Matyukevich 			continue;
916c35c0d54SSergey Matyukevich 
917c35c0d54SSergey Matyukevich 		mac = bus->mac[macid];
918c35c0d54SSergey Matyukevich 		for (i = 0; i < QTNF_MAX_INTF; i++) {
919c35c0d54SSergey Matyukevich 			vif = &mac->iflist[i];
920c35c0d54SSergey Matyukevich 			if (vif->netdev && netif_queue_stopped(vif->netdev))
921c35c0d54SSergey Matyukevich 				netif_tx_wake_all_queues(vif->netdev);
922c35c0d54SSergey Matyukevich 		}
923c35c0d54SSergey Matyukevich 	}
924c35c0d54SSergey Matyukevich }
925c35c0d54SSergey Matyukevich EXPORT_SYMBOL_GPL(qtnf_wake_all_queues);
926c35c0d54SSergey Matyukevich 
92704b01affSVasily Ulyanov void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb)
92804b01affSVasily Ulyanov {
92904b01affSVasily Ulyanov 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
93004b01affSVasily Ulyanov 	struct pcpu_sw_netstats *stats64;
93104b01affSVasily Ulyanov 
93204b01affSVasily Ulyanov 	if (unlikely(!vif || !vif->stats64)) {
93304b01affSVasily Ulyanov 		ndev->stats.rx_packets++;
93404b01affSVasily Ulyanov 		ndev->stats.rx_bytes += skb->len;
93504b01affSVasily Ulyanov 		return;
93604b01affSVasily Ulyanov 	}
93704b01affSVasily Ulyanov 
93804b01affSVasily Ulyanov 	stats64 = this_cpu_ptr(vif->stats64);
93904b01affSVasily Ulyanov 
94004b01affSVasily Ulyanov 	u64_stats_update_begin(&stats64->syncp);
94104b01affSVasily Ulyanov 	stats64->rx_packets++;
94204b01affSVasily Ulyanov 	stats64->rx_bytes += skb->len;
94304b01affSVasily Ulyanov 	u64_stats_update_end(&stats64->syncp);
94404b01affSVasily Ulyanov }
94504b01affSVasily Ulyanov EXPORT_SYMBOL_GPL(qtnf_update_rx_stats);
94604b01affSVasily Ulyanov 
94704b01affSVasily Ulyanov void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb)
94804b01affSVasily Ulyanov {
94904b01affSVasily Ulyanov 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
95004b01affSVasily Ulyanov 	struct pcpu_sw_netstats *stats64;
95104b01affSVasily Ulyanov 
95204b01affSVasily Ulyanov 	if (unlikely(!vif || !vif->stats64)) {
95304b01affSVasily Ulyanov 		ndev->stats.tx_packets++;
95404b01affSVasily Ulyanov 		ndev->stats.tx_bytes += skb->len;
95504b01affSVasily Ulyanov 		return;
95604b01affSVasily Ulyanov 	}
95704b01affSVasily Ulyanov 
95804b01affSVasily Ulyanov 	stats64 = this_cpu_ptr(vif->stats64);
95904b01affSVasily Ulyanov 
96004b01affSVasily Ulyanov 	u64_stats_update_begin(&stats64->syncp);
96104b01affSVasily Ulyanov 	stats64->tx_packets++;
96204b01affSVasily Ulyanov 	stats64->tx_bytes += skb->len;
96304b01affSVasily Ulyanov 	u64_stats_update_end(&stats64->syncp);
96404b01affSVasily Ulyanov }
96504b01affSVasily Ulyanov EXPORT_SYMBOL_GPL(qtnf_update_tx_stats);
96604b01affSVasily Ulyanov 
9670b68fe10SSergey Matyukevich struct dentry *qtnf_get_debugfs_dir(void)
9680b68fe10SSergey Matyukevich {
9690b68fe10SSergey Matyukevich 	return qtnf_debugfs_dir;
9700b68fe10SSergey Matyukevich }
9710b68fe10SSergey Matyukevich EXPORT_SYMBOL_GPL(qtnf_get_debugfs_dir);
9720b68fe10SSergey Matyukevich 
9730b68fe10SSergey Matyukevich static int __init qtnf_core_register(void)
9740b68fe10SSergey Matyukevich {
9750b68fe10SSergey Matyukevich 	qtnf_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
9760b68fe10SSergey Matyukevich 
9770b68fe10SSergey Matyukevich 	if (IS_ERR(qtnf_debugfs_dir))
9780b68fe10SSergey Matyukevich 		qtnf_debugfs_dir = NULL;
9790b68fe10SSergey Matyukevich 
9800b68fe10SSergey Matyukevich 	return 0;
9810b68fe10SSergey Matyukevich }
9820b68fe10SSergey Matyukevich 
9830b68fe10SSergey Matyukevich static void __exit qtnf_core_exit(void)
9840b68fe10SSergey Matyukevich {
9850b68fe10SSergey Matyukevich 	debugfs_remove(qtnf_debugfs_dir);
9860b68fe10SSergey Matyukevich }
9870b68fe10SSergey Matyukevich 
9880b68fe10SSergey Matyukevich module_init(qtnf_core_register);
9890b68fe10SSergey Matyukevich module_exit(qtnf_core_exit);
9900b68fe10SSergey Matyukevich 
99198f44cb0SIgor Mitsyanko MODULE_AUTHOR("Quantenna Communications");
99298f44cb0SIgor Mitsyanko MODULE_DESCRIPTION("Quantenna 802.11 wireless LAN FullMAC driver.");
99398f44cb0SIgor Mitsyanko MODULE_LICENSE("GPL");
994