1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */ 3 4 #ifndef _QTN_FMAC_CORE_H_ 5 #define _QTN_FMAC_CORE_H_ 6 7 #include <linux/kernel.h> 8 #include <linux/module.h> 9 #include <linux/sched.h> 10 #include <linux/semaphore.h> 11 #include <linux/ip.h> 12 #include <linux/skbuff.h> 13 #include <linux/if_arp.h> 14 #include <linux/etherdevice.h> 15 #include <net/sock.h> 16 #include <net/lib80211.h> 17 #include <net/cfg80211.h> 18 #include <linux/vmalloc.h> 19 #include <linux/firmware.h> 20 #include <linux/ctype.h> 21 #include <linux/workqueue.h> 22 #include <linux/slab.h> 23 24 #include "qlink.h" 25 #include "trans.h" 26 27 #undef pr_fmt 28 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__ 29 30 #define QTNF_MAX_VSIE_LEN 255 31 #define QTNF_MAX_INTF 8 32 #define QTNF_MAX_EVENT_QUEUE_LEN 255 33 #define QTNF_SCAN_TIMEOUT_SEC 15 34 35 #define QTNF_DEF_BSS_PRIORITY 0 36 #define QTNF_DEF_WDOG_TIMEOUT 5 37 #define QTNF_TX_TIMEOUT_TRSHLD 100 38 39 extern const struct net_device_ops qtnf_netdev_ops; 40 41 struct qtnf_bus; 42 struct qtnf_vif; 43 44 struct qtnf_sta_node { 45 struct list_head list; 46 u8 mac_addr[ETH_ALEN]; 47 }; 48 49 struct qtnf_sta_list { 50 struct list_head head; 51 atomic_t size; 52 }; 53 54 struct qtnf_vif { 55 struct wireless_dev wdev; 56 u8 bssid[ETH_ALEN]; 57 u8 mac_addr[ETH_ALEN]; 58 u8 vifid; 59 u8 bss_priority; 60 u8 bss_status; 61 u16 mgmt_frames_bitmask; 62 struct net_device *netdev; 63 struct qtnf_wmac *mac; 64 65 struct work_struct reset_work; 66 struct qtnf_sta_list sta_list; 67 unsigned long cons_tx_timeout_cnt; 68 int generation; 69 70 struct pcpu_sw_netstats __percpu *stats64; 71 }; 72 73 struct qtnf_mac_info { 74 u8 bands_cap; 75 u8 dev_mac[ETH_ALEN]; 76 u8 num_tx_chain; 77 u8 num_rx_chain; 78 u16 max_ap_assoc_sta; 79 u32 frag_thr; 80 u32 rts_thr; 81 u8 lretry_limit; 82 u8 sretry_limit; 83 u8 coverage_class; 84 u8 radar_detect_widths; 85 u32 max_acl_mac_addrs; 86 struct ieee80211_ht_cap ht_cap_mod_mask; 87 struct ieee80211_vht_cap vht_cap_mod_mask; 88 struct ieee80211_iface_combination *if_comb; 89 size_t n_if_comb; 90 u8 *extended_capabilities; 91 u8 *extended_capabilities_mask; 92 u8 extended_capabilities_len; 93 struct wiphy_wowlan_support *wowlan; 94 }; 95 96 struct qtnf_chan_stats { 97 u32 chan_num; 98 u32 cca_tx; 99 u32 cca_rx; 100 u32 cca_busy; 101 u32 cca_try; 102 s8 chan_noise; 103 }; 104 105 struct qtnf_wmac { 106 u8 macid; 107 u8 wiphy_registered; 108 u8 macaddr[ETH_ALEN]; 109 struct qtnf_bus *bus; 110 struct qtnf_mac_info macinfo; 111 struct qtnf_vif iflist[QTNF_MAX_INTF]; 112 struct cfg80211_scan_request *scan_req; 113 struct mutex mac_lock; /* lock during wmac speicific ops */ 114 struct delayed_work scan_timeout; 115 }; 116 117 struct qtnf_hw_info { 118 u16 ql_proto_ver; 119 u8 num_mac; 120 u8 mac_bitmap; 121 u32 fw_ver; 122 u32 hw_capab; 123 struct ieee80211_regdomain *rd; 124 u8 total_tx_chain; 125 u8 total_rx_chain; 126 char fw_version[ETHTOOL_FWVERS_LEN]; 127 u32 hw_version; 128 u8 max_scan_ssids; 129 }; 130 131 struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac); 132 struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac); 133 void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac); 134 void qtnf_mac_ext_caps_free(struct qtnf_wmac *mac); 135 struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus); 136 int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *priv, 137 const char *name, unsigned char name_assign_type); 138 void qtnf_main_work_queue(struct work_struct *work); 139 int qtnf_cmd_send_update_phy_params(struct qtnf_wmac *mac, u32 changed); 140 int qtnf_cmd_send_get_phy_params(struct qtnf_wmac *mac); 141 142 struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid); 143 struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb); 144 void qtnf_wake_all_queues(struct net_device *ndev); 145 void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb); 146 void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb); 147 148 void qtnf_virtual_intf_cleanup(struct net_device *ndev); 149 150 void qtnf_netdev_updown(struct net_device *ndev, bool up); 151 void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted); 152 153 static inline struct qtnf_vif *qtnf_netdev_get_priv(struct net_device *dev) 154 { 155 return *((void **)netdev_priv(dev)); 156 } 157 158 #endif /* _QTN_FMAC_CORE_H_ */ 159