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_VSIE_LEN 255 44 #define QTNF_MAX_INTF 8 45 #define QTNF_MAX_EVENT_QUEUE_LEN 255 46 #define QTNF_SCAN_TIMEOUT_SEC 15 47 48 #define QTNF_DEF_BSS_PRIORITY 0 49 #define QTNF_DEF_WDOG_TIMEOUT 5 50 #define QTNF_TX_TIMEOUT_TRSHLD 100 51 52 extern const struct net_device_ops qtnf_netdev_ops; 53 54 struct qtnf_bus; 55 struct qtnf_vif; 56 57 struct qtnf_sta_node { 58 struct list_head list; 59 u8 mac_addr[ETH_ALEN]; 60 }; 61 62 struct qtnf_sta_list { 63 struct list_head head; 64 atomic_t size; 65 }; 66 67 struct qtnf_vif { 68 struct wireless_dev wdev; 69 u8 bssid[ETH_ALEN]; 70 u8 mac_addr[ETH_ALEN]; 71 u8 vifid; 72 u8 bss_priority; 73 u8 bss_status; 74 u16 mgmt_frames_bitmask; 75 struct net_device *netdev; 76 struct qtnf_wmac *mac; 77 78 struct work_struct reset_work; 79 struct qtnf_sta_list sta_list; 80 unsigned long cons_tx_timeout_cnt; 81 int generation; 82 83 struct pcpu_sw_netstats __percpu *stats64; 84 }; 85 86 struct qtnf_mac_info { 87 u8 bands_cap; 88 u8 dev_mac[ETH_ALEN]; 89 u8 num_tx_chain; 90 u8 num_rx_chain; 91 u16 max_ap_assoc_sta; 92 u32 frag_thr; 93 u32 rts_thr; 94 u8 lretry_limit; 95 u8 sretry_limit; 96 u8 coverage_class; 97 u8 radar_detect_widths; 98 u32 max_acl_mac_addrs; 99 struct ieee80211_ht_cap ht_cap_mod_mask; 100 struct ieee80211_vht_cap vht_cap_mod_mask; 101 struct ieee80211_iface_combination *if_comb; 102 size_t n_if_comb; 103 u8 *extended_capabilities; 104 u8 *extended_capabilities_mask; 105 u8 extended_capabilities_len; 106 struct wiphy_wowlan_support *wowlan; 107 }; 108 109 struct qtnf_chan_stats { 110 u32 chan_num; 111 u32 cca_tx; 112 u32 cca_rx; 113 u32 cca_busy; 114 u32 cca_try; 115 s8 chan_noise; 116 }; 117 118 struct qtnf_wmac { 119 u8 macid; 120 u8 wiphy_registered; 121 u8 macaddr[ETH_ALEN]; 122 struct qtnf_bus *bus; 123 struct qtnf_mac_info macinfo; 124 struct qtnf_vif iflist[QTNF_MAX_INTF]; 125 struct cfg80211_scan_request *scan_req; 126 struct mutex mac_lock; /* lock during wmac speicific ops */ 127 struct delayed_work scan_timeout; 128 }; 129 130 struct qtnf_hw_info { 131 u16 ql_proto_ver; 132 u8 num_mac; 133 u8 mac_bitmap; 134 u32 fw_ver; 135 u32 hw_capab; 136 struct ieee80211_regdomain *rd; 137 u8 total_tx_chain; 138 u8 total_rx_chain; 139 char fw_version[ETHTOOL_FWVERS_LEN]; 140 u32 hw_version; 141 u8 max_scan_ssids; 142 }; 143 144 struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac); 145 struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac); 146 void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac); 147 void qtnf_mac_ext_caps_free(struct qtnf_wmac *mac); 148 struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus); 149 int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *priv, 150 const char *name, unsigned char name_assign_type); 151 void qtnf_main_work_queue(struct work_struct *work); 152 int qtnf_cmd_send_update_phy_params(struct qtnf_wmac *mac, u32 changed); 153 int qtnf_cmd_send_get_phy_params(struct qtnf_wmac *mac); 154 155 struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid); 156 struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb); 157 void qtnf_wake_all_queues(struct net_device *ndev); 158 void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb); 159 void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb); 160 161 void qtnf_virtual_intf_cleanup(struct net_device *ndev); 162 163 void qtnf_netdev_updown(struct net_device *ndev, bool up); 164 void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted); 165 166 static inline struct qtnf_vif *qtnf_netdev_get_priv(struct net_device *dev) 167 { 168 return *((void **)netdev_priv(dev)); 169 } 170 171 #endif /* _QTN_FMAC_CORE_H_ */ 172