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>
21 #define FLOW_CONTROL_LOWER_THRESHOLD 128
22 #define FLOW_CONTROL_UPPER_THRESHOLD 256
25 #define NUM_STA_ASSOCIATED 8
27 #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
28 #define DEFAULT_LINK_SPEED 72
30 struct wilc_wfi_stats {
31 unsigned long rx_packets;
32 unsigned long tx_packets;
33 unsigned long rx_bytes;
34 unsigned long tx_bytes;
48 struct wilc_wfi_wep_key {
55 u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
58 /* Parameters needed for host interface for remaining on channel */
59 struct wilc_wfi_p2p_listen_params {
60 struct ieee80211_channel *listen_ch;
65 static const u32 wilc_cipher_suites[] = {
66 WLAN_CIPHER_SUITE_WEP40,
67 WLAN_CIPHER_SUITE_WEP104,
68 WLAN_CIPHER_SUITE_TKIP,
69 WLAN_CIPHER_SUITE_CCMP,
70 WLAN_CIPHER_SUITE_AES_CMAC
73 #define CHAN2G(_channel, _freq, _flags) { \
74 .band = NL80211_BAND_2GHZ, \
75 .center_freq = (_freq), \
76 .hw_value = (_channel), \
78 .max_antenna_gain = 0, \
82 static const struct ieee80211_channel wilc_2ghz_channels[] = {
99 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
100 .bitrate = (_rate), \
101 .hw_value = (_hw_value), \
105 static struct ieee80211_rate wilc_bitrates[] = {
106 RATETAB_ENT(10, 0, 0),
107 RATETAB_ENT(20, 1, 0),
108 RATETAB_ENT(55, 2, 0),
109 RATETAB_ENT(110, 3, 0),
110 RATETAB_ENT(60, 9, 0),
111 RATETAB_ENT(90, 6, 0),
112 RATETAB_ENT(120, 7, 0),
113 RATETAB_ENT(180, 8, 0),
114 RATETAB_ENT(240, 9, 0),
115 RATETAB_ENT(360, 10, 0),
116 RATETAB_ENT(480, 11, 0),
117 RATETAB_ENT(540, 12, 0)
121 struct wireless_dev wdev;
122 struct cfg80211_scan_request *scan_req;
124 struct wilc_wfi_p2p_listen_params remain_on_ch_params;
129 u8 associated_bss[ETH_ALEN];
130 struct sta_info assoc_stainfo;
132 struct net_device *dev;
133 struct host_if_drv *hif_drv;
134 struct wilc_pmkid_attr pmkid_list;
135 u8 wep_key[4][WLAN_KEY_LEN_WEP104];
138 /* The real interface that the monitor is on */
139 struct net_device *real_ndev;
140 struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
141 struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
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;
190 struct timer_list during_ip_timer;
191 struct timer_list periodic_rssi;
192 struct rf_info periodic_stat;
193 struct tcp_ack_filter ack_filter;
195 struct wilc_priv priv;
196 struct list_head list;
197 struct cfg80211_bss *bss;
200 struct wilc_tx_queue_status {
201 u8 buffer[AC_BUFFER_SIZE];
210 const struct wilc_hif_func *hif_func;
218 struct list_head vif_list;
220 /* protect vif list */
221 struct mutex vif_mutex;
222 struct srcu_struct srcu;
225 /* protect head of transmit queue */
226 struct mutex txq_add_to_head_cs;
228 /* protect txq_entry_t transmit queue */
229 spinlock_t txq_spinlock;
231 /* 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;
246 /* lock to protect issue of wid command to firmware */
247 struct mutex cfg_cmd_lock;
248 struct wilc_cfg_frame cfg_frame;
249 u32 cfg_frame_offset;
253 u32 rx_buffer_offset;
256 struct txq_handle txq[NQUEUES];
259 struct wilc_tx_queue_status tx_q_limit;
260 struct rxq_entry_t rxq_head;
262 const struct firmware *firmware;
268 struct workqueue_struct *hif_workqueue;
269 enum chip_ps_states chip_ps_state;
272 struct net_device *monitor_dev;
275 struct mutex deinit_lock;
278 struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
279 struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
280 struct ieee80211_supported_band band;
281 u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
284 struct wilc_wfi_mon_priv {
285 struct net_device *real_ndev;
288 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
289 void wilc_mac_indicate(struct wilc *wilc);
290 void wilc_netdev_cleanup(struct wilc *wilc);
291 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
292 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
293 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
294 int vif_type, enum nl80211_iftype type,