1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
7 #ifndef WILC_WFI_NETDEVICE
8 #define WILC_WFI_NETDEVICE
10 #include <linux/tcp.h>
11 #include <linux/ieee80211.h>
12 #include <net/cfg80211.h>
13 #include <net/ieee80211_radiotap.h>
14 #include <linux/if_arp.h>
15 #include <linux/gpio/consumer.h>
18 #include "wilc_wlan.h"
19 #include "wilc_wlan_cfg.h"
21 #define FLOW_CONTROL_LOWER_THRESHOLD 128
22 #define FLOW_CONTROL_UPPER_THRESHOLD 256
24 #define WILC_MAX_NUM_PMKIDS 16
26 #define NUM_STA_ASSOCIATED 8
28 #define NUM_REG_FRAME 2
30 #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
31 #define DEFAULT_LINK_SPEED 72
33 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
35 struct wilc_wfi_stats {
36 unsigned long rx_packets;
37 unsigned long tx_packets;
38 unsigned long rx_bytes;
39 unsigned long tx_bytes;
53 struct wilc_wfi_wep_key {
60 u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
63 /*Parameters needed for host interface for remaining on channel*/
64 struct wilc_wfi_p2p_listen_params {
65 struct ieee80211_channel *listen_ch;
76 static const u32 wilc_cipher_suites[] = {
77 WLAN_CIPHER_SUITE_WEP40,
78 WLAN_CIPHER_SUITE_WEP104,
79 WLAN_CIPHER_SUITE_TKIP,
80 WLAN_CIPHER_SUITE_CCMP,
81 WLAN_CIPHER_SUITE_AES_CMAC
84 #define CHAN2G(_channel, _freq, _flags) { \
85 .band = NL80211_BAND_2GHZ, \
86 .center_freq = (_freq), \
87 .hw_value = (_channel), \
89 .max_antenna_gain = 0, \
93 static const struct ieee80211_channel wilc_2ghz_channels[] = {
110 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
111 .bitrate = (_rate), \
112 .hw_value = (_hw_value), \
116 static struct ieee80211_rate wilc_bitrates[] = {
117 RATETAB_ENT(10, 0, 0),
118 RATETAB_ENT(20, 1, 0),
119 RATETAB_ENT(55, 2, 0),
120 RATETAB_ENT(110, 3, 0),
121 RATETAB_ENT(60, 9, 0),
122 RATETAB_ENT(90, 6, 0),
123 RATETAB_ENT(120, 7, 0),
124 RATETAB_ENT(180, 8, 0),
125 RATETAB_ENT(240, 9, 0),
126 RATETAB_ENT(360, 10, 0),
127 RATETAB_ENT(480, 11, 0),
128 RATETAB_ENT(540, 12, 0)
132 struct wireless_dev wdev;
133 struct cfg80211_scan_request *scan_req;
135 struct wilc_wfi_p2p_listen_params remain_on_ch_params;
140 u8 associated_bss[ETH_ALEN];
141 struct sta_info assoc_stainfo;
143 struct net_device *dev;
144 struct host_if_drv *hif_drv;
145 struct wilc_pmkid_attr pmkid_list;
146 u8 wep_key[4][WLAN_KEY_LEN_WEP104];
148 /* The real interface that the monitor is on */
149 struct net_device *real_ndev;
150 struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
151 struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
154 struct mutex scan_req_lock;
155 bool p2p_listen_state;
157 struct wilc_p2p_var p2p;
167 #define MAX_TCP_SESSION 25
168 #define MAX_PENDING_ACKS 256
170 struct ack_session_info {
178 struct pending_acks {
181 struct txq_entry_t *txqe;
184 struct tcp_ack_filter {
185 struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
186 struct pending_acks pending_acks[MAX_PENDING_ACKS];
189 u32 pending_acks_idx;
198 struct frame_reg frame_reg[NUM_REG_FRAME];
199 struct net_device_stats netstats;
202 struct host_if_drv *hif_drv;
203 struct net_device *ndev;
205 struct timer_list during_ip_timer;
207 struct timer_list periodic_rssi;
208 struct rf_info periodic_stat;
209 struct tcp_ack_filter ack_filter;
211 struct wilc_priv priv;
216 const struct wilc_hif_func *hif_func;
219 struct gpio_desc *gpio_irq;
224 struct wilc_vif *vif[WILC_NUM_CONCURRENT_IFC];
226 struct mutex vif_mutex;
228 /*protect head of transmit queue*/
229 struct mutex txq_add_to_head_cs;
230 /*protect txq_entry_t transmit queue*/
231 spinlock_t txq_spinlock;
232 /*protect rxq_entry_t receiver queue*/
234 /* lock to protect hif access */
237 struct completion cfg_event;
238 struct completion sync_event;
239 struct completion txq_event;
240 struct completion txq_thread_started;
242 struct task_struct *txq_thread;
245 /* lock to protect issue of wid command to firmware */
246 struct mutex cfg_cmd_lock;
247 struct wilc_cfg_frame cfg_frame;
248 u32 cfg_frame_offset;
252 u32 rx_buffer_offset;
255 struct txq_entry_t txq_head;
258 struct rxq_entry_t rxq_head;
260 const struct firmware *firmware;
267 struct workqueue_struct *hif_workqueue;
268 enum chip_ps_states chip_ps_state;
271 struct net_device *monitor_dev;
273 struct mutex deinit_lock;
276 struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
277 struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
278 struct ieee80211_supported_band band;
279 u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
282 struct wilc_wfi_mon_priv {
283 struct net_device *real_ndev;
286 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
287 void wilc_mac_indicate(struct wilc *wilc);
288 void wilc_netdev_cleanup(struct wilc *wilc);
289 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
290 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
291 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
292 int vif_type, enum nl80211_iftype type,