1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
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>
16 #include <linux/rculist.h>
17 #include <uapi/linux/if_ether.h>
23 #define FLOW_CONTROL_LOWER_THRESHOLD 128
24 #define FLOW_CONTROL_UPPER_THRESHOLD 256
27 #define NUM_STA_ASSOCIATED 8
29 #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
30 #define DEFAULT_LINK_SPEED 72
32 #define TX_BACKOFF_WEIGHT_MS 1
34 #define wilc_for_each_vif(w, v) \
35 struct wilc *_w = w; \
36 list_for_each_entry_srcu(v, &_w->vif_list, list, \
37 srcu_read_lock_held(&_w->srcu))
39 struct wilc_wfi_stats {
40 unsigned long rx_packets;
41 unsigned long tx_packets;
42 unsigned long rx_bytes;
43 unsigned long tx_bytes;
58 u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
61 /* Parameters needed for host interface for remaining on channel */
62 struct wilc_wfi_p2p_listen_params {
63 struct ieee80211_channel *listen_ch;
68 static const u32 wilc_cipher_suites[] = {
69 WLAN_CIPHER_SUITE_TKIP,
70 WLAN_CIPHER_SUITE_CCMP,
71 WLAN_CIPHER_SUITE_AES_CMAC
74 #define CHAN2G(_channel, _freq, _flags) { \
75 .band = NL80211_BAND_2GHZ, \
76 .center_freq = (_freq), \
77 .hw_value = (_channel), \
79 .max_antenna_gain = 0, \
83 static const struct ieee80211_channel wilc_2ghz_channels[] = {
100 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
101 .bitrate = (_rate), \
102 .hw_value = (_hw_value), \
106 static struct ieee80211_rate wilc_bitrates[] = {
107 RATETAB_ENT(10, 0, 0),
108 RATETAB_ENT(20, 1, 0),
109 RATETAB_ENT(55, 2, 0),
110 RATETAB_ENT(110, 3, 0),
111 RATETAB_ENT(60, 9, 0),
112 RATETAB_ENT(90, 6, 0),
113 RATETAB_ENT(120, 7, 0),
114 RATETAB_ENT(180, 8, 0),
115 RATETAB_ENT(240, 9, 0),
116 RATETAB_ENT(360, 10, 0),
117 RATETAB_ENT(480, 11, 0),
118 RATETAB_ENT(540, 12, 0)
122 struct wireless_dev wdev;
123 struct cfg80211_scan_request *scan_req;
125 struct wilc_wfi_p2p_listen_params remain_on_ch_params;
130 u8 associated_bss[ETH_ALEN];
131 struct sta_info assoc_stainfo;
133 struct net_device *dev;
134 struct host_if_drv *hif_drv;
135 struct wilc_pmkid_attr pmkid_list;
137 /* The real interface that the monitor is on */
138 struct net_device *real_ndev;
139 struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
140 struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
141 struct wilc_wfi_key *wilc_igtk[2];
145 struct mutex scan_req_lock;
146 bool p2p_listen_state;
152 #define MAX_TCP_SESSION 25
153 #define MAX_PENDING_ACKS 256
155 struct ack_session_info {
163 struct pending_acks {
166 struct txq_entry_t *txqe;
169 struct tcp_ack_filter {
170 struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
171 struct pending_acks pending_acks[MAX_PENDING_ACKS];
174 u32 pending_acks_idx;
184 struct net_device_stats netstats;
187 struct host_if_drv *hif_drv;
188 struct net_device *ndev;
189 struct timer_list during_ip_timer;
190 struct timer_list periodic_rssi;
191 struct rf_info periodic_stat;
192 struct tcp_ack_filter ack_filter;
194 struct wilc_priv priv;
195 struct list_head list;
196 struct cfg80211_bss *bss;
197 struct cfg80211_external_auth_params auth;
200 struct wilc_tx_queue_status {
201 u8 buffer[AC_BUFFER_SIZE];
210 const struct wilc_hif_func *hif_func;
216 bool power_save_mode;
220 struct list_head vif_list;
222 /* protect vif list */
223 struct mutex vif_mutex;
224 /* Sleepable RCU struct to manipulate vif list. Sleepable version is
225 * needed over the classic RCU version because the driver's current
226 * design involves some sleeping code while manipulating a vif
227 * retrieved from vif list (so in a SRCU critical section), like:
228 * - sending commands to the chip, using info from retrieved vif
229 * - registering a new monitoring net device
231 struct srcu_struct srcu;
234 /* protect head of transmit queue */
235 struct mutex txq_add_to_head_cs;
237 /* protect txq_entry_t transmit queue */
238 spinlock_t txq_spinlock;
240 /* protect rxq_entry_t receiver queue */
243 /* lock to protect hif access */
246 struct completion cfg_event;
247 struct completion sync_event;
248 struct completion txq_event;
249 struct completion txq_thread_started;
251 struct task_struct *txq_thread;
255 /* lock to protect issue of wid command to firmware */
256 struct mutex cfg_cmd_lock;
257 struct wilc_cfg_frame cfg_frame;
258 u32 cfg_frame_offset;
262 u32 rx_buffer_offset;
266 struct txq_handle txq[NQUEUES];
269 struct wilc_tx_queue_status tx_q_limit;
270 struct rxq_entry_t rxq_head;
272 const struct firmware *firmware;
276 struct workqueue_struct *hif_workqueue;
279 struct net_device *monitor_dev;
282 struct mutex deinit_lock;
285 struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
286 struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
287 struct ieee80211_supported_band band;
288 u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
289 u8 nv_mac_address[ETH_ALEN];
292 struct wilc_wfi_mon_priv {
293 struct net_device *real_ndev;
296 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
297 void wilc_mac_indicate(struct wilc *wilc);
298 void wilc_netdev_cleanup(struct wilc *wilc);
299 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth);
300 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, const u8 *bssid,
302 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
303 int vif_type, enum nl80211_iftype type,