1 /* 2 * Copyright (c) 2015-2016 Quantenna Communications, Inc. 3 * All rights reserved. 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 */ 16 17 #ifndef _QTN_FMAC_CORE_H_ 18 #define _QTN_FMAC_CORE_H_ 19 20 #include <linux/kernel.h> 21 #include <linux/module.h> 22 #include <linux/sched.h> 23 #include <linux/semaphore.h> 24 #include <linux/ip.h> 25 #include <linux/skbuff.h> 26 #include <linux/if_arp.h> 27 #include <linux/etherdevice.h> 28 #include <net/sock.h> 29 #include <net/lib80211.h> 30 #include <net/cfg80211.h> 31 #include <linux/vmalloc.h> 32 #include <linux/firmware.h> 33 #include <linux/ctype.h> 34 #include <linux/workqueue.h> 35 #include <linux/slab.h> 36 37 #include "qlink.h" 38 #include "trans.h" 39 40 #undef pr_fmt 41 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__ 42 43 #define QTNF_MAX_SSID_LIST_LENGTH 2 44 #define QTNF_MAX_VSIE_LEN 255 45 #define QTNF_MAX_INTF 8 46 #define QTNF_MAX_EVENT_QUEUE_LEN 255 47 #define QTNF_DEFAULT_BG_SCAN_PERIOD 300 48 #define QTNF_MAX_BG_SCAN_PERIOD 0xffff 49 #define QTNF_SCAN_TIMEOUT_SEC 15 50 51 #define QTNF_DEF_BSS_PRIORITY 0 52 #define QTNF_DEF_WDOG_TIMEOUT 5 53 #define QTNF_TX_TIMEOUT_TRSHLD 100 54 55 #define QTNF_STATE_AP_CONFIG BIT(2) 56 #define QTNF_STATE_AP_START BIT(1) 57 58 extern const struct net_device_ops qtnf_netdev_ops; 59 struct qtnf_bus; 60 struct qtnf_vif; 61 62 struct qtnf_bss_config { 63 u8 ssid[IEEE80211_MAX_SSID_LEN]; 64 u8 bssid[ETH_ALEN]; 65 size_t ssid_len; 66 u8 dtim; 67 u16 bcn_period; 68 u16 auth_type; 69 bool privacy; 70 enum nl80211_mfp mfp; 71 struct cfg80211_crypto_settings crypto; 72 u16 bg_scan_period; 73 u32 connect_flags; 74 }; 75 76 struct qtnf_sta_node { 77 struct list_head list; 78 u8 mac_addr[ETH_ALEN]; 79 }; 80 81 struct qtnf_sta_list { 82 struct list_head head; 83 atomic_t size; 84 }; 85 86 enum qtnf_sta_state { 87 QTNF_STA_DISCONNECTED, 88 QTNF_STA_CONNECTING, 89 QTNF_STA_CONNECTED 90 }; 91 92 enum qtnf_mac_status { 93 QTNF_MAC_CSA_ACTIVE = BIT(0) 94 }; 95 96 struct qtnf_vif { 97 struct wireless_dev wdev; 98 u8 vifid; 99 u8 bss_priority; 100 u8 bss_status; 101 enum qtnf_sta_state sta_state; 102 u16 mgmt_frames_bitmask; 103 struct net_device *netdev; 104 struct qtnf_wmac *mac; 105 u8 mac_addr[ETH_ALEN]; 106 struct work_struct reset_work; 107 struct qtnf_bss_config bss_cfg; 108 struct qtnf_sta_list sta_list; 109 unsigned long cons_tx_timeout_cnt; 110 }; 111 112 struct qtnf_mac_info { 113 u8 bands_cap; 114 u8 phymode_cap; 115 u8 dev_mac[ETH_ALEN]; 116 u8 num_tx_chain; 117 u8 num_rx_chain; 118 u16 max_ap_assoc_sta; 119 u32 frag_thr; 120 u32 rts_thr; 121 u8 lretry_limit; 122 u8 sretry_limit; 123 u8 coverage_class; 124 u8 radar_detect_widths; 125 struct ieee80211_ht_cap ht_cap; 126 struct ieee80211_vht_cap vht_cap; 127 struct ieee80211_iface_limit *limits; 128 size_t n_limits; 129 }; 130 131 struct qtnf_chan_stats { 132 u32 chan_num; 133 u32 cca_tx; 134 u32 cca_rx; 135 u32 cca_busy; 136 u32 cca_try; 137 s8 chan_noise; 138 }; 139 140 struct qtnf_wmac { 141 u8 macid; 142 u8 wiphy_registered; 143 u8 macaddr[ETH_ALEN]; 144 u32 status; 145 struct qtnf_bus *bus; 146 struct qtnf_mac_info macinfo; 147 struct qtnf_vif iflist[QTNF_MAX_INTF]; 148 struct cfg80211_scan_request *scan_req; 149 struct cfg80211_chan_def chandef; 150 struct cfg80211_chan_def csa_chandef; 151 struct mutex mac_lock; /* lock during wmac speicific ops */ 152 struct timer_list scan_timeout; 153 }; 154 155 struct qtnf_hw_info { 156 u16 ql_proto_ver; 157 u8 num_mac; 158 u8 mac_bitmap; 159 u32 fw_ver; 160 u32 hw_capab; 161 struct ieee80211_regdomain *rd; 162 u8 total_tx_chain; 163 u8 total_rx_chain; 164 }; 165 166 struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac); 167 struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac); 168 struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus); 169 int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *priv, 170 const char *name, unsigned char name_assign_type, 171 enum nl80211_iftype iftype); 172 void qtnf_main_work_queue(struct work_struct *work); 173 int qtnf_cmd_send_update_phy_params(struct qtnf_wmac *mac, u32 changed); 174 int qtnf_cmd_send_get_phy_params(struct qtnf_wmac *mac); 175 176 struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid); 177 struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb); 178 struct net_device *qtnf_classify_skb_no_mbss(struct qtnf_bus *bus, 179 struct sk_buff *skb); 180 181 void qtnf_virtual_intf_cleanup(struct net_device *ndev); 182 183 void qtnf_netdev_updown(struct net_device *ndev, bool up); 184 185 static inline struct qtnf_vif *qtnf_netdev_get_priv(struct net_device *dev) 186 { 187 return *((void **)netdev_priv(dev)); 188 } 189 190 #endif /* _QTN_FMAC_CORE_H_ */ 191