xref: /linux/drivers/net/wireless/quantenna/qtnfmac/core.h (revision ead5d1f4d877e92c051e1a1ade623d0d30e71619)
1ff233cb5SSergey Matyukevich /* SPDX-License-Identifier: GPL-2.0+ */
2ff233cb5SSergey Matyukevich /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
398f44cb0SIgor Mitsyanko 
498f44cb0SIgor Mitsyanko #ifndef _QTN_FMAC_CORE_H_
598f44cb0SIgor Mitsyanko #define _QTN_FMAC_CORE_H_
698f44cb0SIgor Mitsyanko 
798f44cb0SIgor Mitsyanko #include <linux/kernel.h>
898f44cb0SIgor Mitsyanko #include <linux/module.h>
998f44cb0SIgor Mitsyanko #include <linux/sched.h>
1098f44cb0SIgor Mitsyanko #include <linux/semaphore.h>
1198f44cb0SIgor Mitsyanko #include <linux/ip.h>
1298f44cb0SIgor Mitsyanko #include <linux/skbuff.h>
1398f44cb0SIgor Mitsyanko #include <linux/if_arp.h>
1498f44cb0SIgor Mitsyanko #include <linux/etherdevice.h>
1598f44cb0SIgor Mitsyanko #include <net/sock.h>
1698f44cb0SIgor Mitsyanko #include <net/lib80211.h>
1798f44cb0SIgor Mitsyanko #include <net/cfg80211.h>
1898f44cb0SIgor Mitsyanko #include <linux/vmalloc.h>
1998f44cb0SIgor Mitsyanko #include <linux/firmware.h>
2098f44cb0SIgor Mitsyanko #include <linux/ctype.h>
2198f44cb0SIgor Mitsyanko #include <linux/workqueue.h>
2298f44cb0SIgor Mitsyanko #include <linux/slab.h>
23*616f5701SSergey Matyukevich #include <linux/platform_device.h>
2498f44cb0SIgor Mitsyanko 
2598f44cb0SIgor Mitsyanko #include "qlink.h"
2698f44cb0SIgor Mitsyanko #include "trans.h"
27310cd5ddSIgor Mitsyanko #include "qlink_util.h"
2898f44cb0SIgor Mitsyanko 
2998f44cb0SIgor Mitsyanko #undef pr_fmt
3098f44cb0SIgor Mitsyanko #define pr_fmt(fmt)	KBUILD_MODNAME ": %s: " fmt, __func__
3198f44cb0SIgor Mitsyanko 
3298f44cb0SIgor Mitsyanko #define QTNF_MAX_VSIE_LEN		255
3398f44cb0SIgor Mitsyanko #define QTNF_MAX_INTF			8
3498f44cb0SIgor Mitsyanko #define QTNF_MAX_EVENT_QUEUE_LEN	255
35c7ead2abSSergey Matyukevich #define QTNF_SCAN_TIMEOUT_SEC		15
3698f44cb0SIgor Mitsyanko 
3798f44cb0SIgor Mitsyanko #define QTNF_DEF_BSS_PRIORITY		0
3898f44cb0SIgor Mitsyanko #define QTNF_DEF_WDOG_TIMEOUT		5
3998f44cb0SIgor Mitsyanko #define QTNF_TX_TIMEOUT_TRSHLD		100
4098f44cb0SIgor Mitsyanko 
4198f44cb0SIgor Mitsyanko extern const struct net_device_ops qtnf_netdev_ops;
42d7b80052SIgor Mitsyanko 
4398f44cb0SIgor Mitsyanko struct qtnf_bus;
4498f44cb0SIgor Mitsyanko struct qtnf_vif;
4598f44cb0SIgor Mitsyanko 
4698f44cb0SIgor Mitsyanko struct qtnf_sta_node {
4798f44cb0SIgor Mitsyanko 	struct list_head list;
4898f44cb0SIgor Mitsyanko 	u8 mac_addr[ETH_ALEN];
4998f44cb0SIgor Mitsyanko };
5098f44cb0SIgor Mitsyanko 
5198f44cb0SIgor Mitsyanko struct qtnf_sta_list {
5298f44cb0SIgor Mitsyanko 	struct list_head head;
5398f44cb0SIgor Mitsyanko 	atomic_t size;
5498f44cb0SIgor Mitsyanko };
5598f44cb0SIgor Mitsyanko 
5698f44cb0SIgor Mitsyanko struct qtnf_vif {
5798f44cb0SIgor Mitsyanko 	struct wireless_dev wdev;
589766d1ddSIgor Mitsyanko 	u8 bssid[ETH_ALEN];
599766d1ddSIgor Mitsyanko 	u8 mac_addr[ETH_ALEN];
6098f44cb0SIgor Mitsyanko 	u8 vifid;
6198f44cb0SIgor Mitsyanko 	u8 bss_priority;
6298f44cb0SIgor Mitsyanko 	u8 bss_status;
6398f44cb0SIgor Mitsyanko 	u16 mgmt_frames_bitmask;
6498f44cb0SIgor Mitsyanko 	struct net_device *netdev;
6598f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac;
669766d1ddSIgor Mitsyanko 
6798f44cb0SIgor Mitsyanko 	struct work_struct reset_work;
68bc70732fSIgor Mitsyanko 	struct work_struct high_pri_tx_work;
69bc70732fSIgor Mitsyanko 	struct sk_buff_head high_pri_tx_queue;
7098f44cb0SIgor Mitsyanko 	struct qtnf_sta_list sta_list;
7198f44cb0SIgor Mitsyanko 	unsigned long cons_tx_timeout_cnt;
727a4d3a3bSIgor Mitsyanko 	int generation;
7304b01affSVasily Ulyanov 
7404b01affSVasily Ulyanov 	struct pcpu_sw_netstats __percpu *stats64;
7598f44cb0SIgor Mitsyanko };
7698f44cb0SIgor Mitsyanko 
7798f44cb0SIgor Mitsyanko struct qtnf_mac_info {
7898f44cb0SIgor Mitsyanko 	u8 bands_cap;
7998f44cb0SIgor Mitsyanko 	u8 num_tx_chain;
8098f44cb0SIgor Mitsyanko 	u8 num_rx_chain;
8198f44cb0SIgor Mitsyanko 	u16 max_ap_assoc_sta;
8298f44cb0SIgor Mitsyanko 	u32 frag_thr;
8398f44cb0SIgor Mitsyanko 	u32 rts_thr;
8498f44cb0SIgor Mitsyanko 	u8 lretry_limit;
8598f44cb0SIgor Mitsyanko 	u8 sretry_limit;
8698f44cb0SIgor Mitsyanko 	u8 coverage_class;
8798f44cb0SIgor Mitsyanko 	u8 radar_detect_widths;
880d18a9c0SIgor Mitsyanko 	u8 max_scan_ssids;
89e70cf22bSIgor Mitsyanko 	u16 max_acl_mac_addrs;
90d42df85fSIgor Mitsyanko 	struct ieee80211_ht_cap ht_cap_mod_mask;
91d42df85fSIgor Mitsyanko 	struct ieee80211_vht_cap vht_cap_mod_mask;
92537faf26SSergey Matyukevich 	struct ieee80211_iface_combination *if_comb;
93537faf26SSergey Matyukevich 	size_t n_if_comb;
949cbd5999SVasily Ulyanov 	u8 *extended_capabilities;
959cbd5999SVasily Ulyanov 	u8 *extended_capabilities_mask;
969cbd5999SVasily Ulyanov 	u8 extended_capabilities_len;
9728b91884SSergey Matyukevich 	struct wiphy_wowlan_support *wowlan;
9898f44cb0SIgor Mitsyanko };
9998f44cb0SIgor Mitsyanko 
10098f44cb0SIgor Mitsyanko struct qtnf_wmac {
10198f44cb0SIgor Mitsyanko 	u8 macid;
10298f44cb0SIgor Mitsyanko 	u8 wiphy_registered;
10398f44cb0SIgor Mitsyanko 	u8 macaddr[ETH_ALEN];
10498f44cb0SIgor Mitsyanko 	struct qtnf_bus *bus;
10598f44cb0SIgor Mitsyanko 	struct qtnf_mac_info macinfo;
10698f44cb0SIgor Mitsyanko 	struct qtnf_vif iflist[QTNF_MAX_INTF];
10798f44cb0SIgor Mitsyanko 	struct cfg80211_scan_request *scan_req;
108c7ead2abSSergey Matyukevich 	struct mutex mac_lock;	/* lock during wmac speicific ops */
109f2cddd54SIgor Mitsyanko 	struct delayed_work scan_timeout;
110c698bce0SIgor Mitsyanko 	struct ieee80211_regdomain *rd;
111*616f5701SSergey Matyukevich 	struct platform_device *pdev;
11298f44cb0SIgor Mitsyanko };
11398f44cb0SIgor Mitsyanko 
11498f44cb0SIgor Mitsyanko struct qtnf_hw_info {
115a3ebb033SIgor Mitsyanko 	u32 ql_proto_ver;
11698f44cb0SIgor Mitsyanko 	u8 num_mac;
11798f44cb0SIgor Mitsyanko 	u8 mac_bitmap;
11898f44cb0SIgor Mitsyanko 	u32 fw_ver;
11998f44cb0SIgor Mitsyanko 	u8 total_tx_chain;
12098f44cb0SIgor Mitsyanko 	u8 total_rx_chain;
1210b419d01SVasily Ulyanov 	char fw_version[ETHTOOL_FWVERS_LEN];
1220b419d01SVasily Ulyanov 	u32 hw_version;
123310cd5ddSIgor Mitsyanko 	u8 hw_capab[QLINK_HW_CAPAB_NUM / BITS_PER_BYTE + 1];
12498f44cb0SIgor Mitsyanko };
12598f44cb0SIgor Mitsyanko 
12698f44cb0SIgor Mitsyanko struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac);
12798f44cb0SIgor Mitsyanko struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac);
128537faf26SSergey Matyukevich void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac);
129ab1c64a1SSergey Matyukevich void qtnf_mac_ext_caps_free(struct qtnf_wmac *mac);
130e92b07a2SSergey Matyukevich bool qtnf_slave_radar_get(void);
131155b424cSSergey Matyukevich bool qtnf_dfs_offload_get(void);
132*616f5701SSergey Matyukevich struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus,
133*616f5701SSergey Matyukevich 				  struct platform_device *pdev);
13498f44cb0SIgor Mitsyanko int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *priv,
135e6ef8cd0SIgor Mitsyanko 			 const char *name, unsigned char name_assign_type);
13698f44cb0SIgor Mitsyanko void qtnf_main_work_queue(struct work_struct *work);
13798f44cb0SIgor Mitsyanko int qtnf_cmd_send_update_phy_params(struct qtnf_wmac *mac, u32 changed);
13898f44cb0SIgor Mitsyanko 
13998f44cb0SIgor Mitsyanko struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid);
14098f44cb0SIgor Mitsyanko struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb);
141c35c0d54SSergey Matyukevich void qtnf_wake_all_queues(struct net_device *ndev);
14204b01affSVasily Ulyanov void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb);
14304b01affSVasily Ulyanov void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb);
14404b01affSVasily Ulyanov 
14598f44cb0SIgor Mitsyanko void qtnf_virtual_intf_cleanup(struct net_device *ndev);
14698f44cb0SIgor Mitsyanko 
14798f44cb0SIgor Mitsyanko void qtnf_netdev_updown(struct net_device *ndev, bool up);
148f2cddd54SIgor Mitsyanko void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted);
1490b68fe10SSergey Matyukevich struct dentry *qtnf_get_debugfs_dir(void);
150decfc5c7SIgor Mitsyanko bool qtnf_netdev_is_qtn(const struct net_device *ndev);
15198f44cb0SIgor Mitsyanko 
15298f44cb0SIgor Mitsyanko static inline struct qtnf_vif *qtnf_netdev_get_priv(struct net_device *dev)
15398f44cb0SIgor Mitsyanko {
15498f44cb0SIgor Mitsyanko 	return *((void **)netdev_priv(dev));
15598f44cb0SIgor Mitsyanko }
15698f44cb0SIgor Mitsyanko 
157310cd5ddSIgor Mitsyanko static inline bool qtnf_hwcap_is_set(const struct qtnf_hw_info *info,
158310cd5ddSIgor Mitsyanko 				     unsigned int bit)
159310cd5ddSIgor Mitsyanko {
160310cd5ddSIgor Mitsyanko 	return qtnf_utils_is_bit_set(info->hw_capab, bit,
161310cd5ddSIgor Mitsyanko 				     sizeof(info->hw_capab));
162310cd5ddSIgor Mitsyanko }
163310cd5ddSIgor Mitsyanko 
16498f44cb0SIgor Mitsyanko #endif /* _QTN_FMAC_CORE_H_ */
165