Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
4 * All rights reserved.
5 */
6
7#ifndef WILC_NETDEV_H
8#define WILC_NETDEV_H
9
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>
18
19#include "hif.h"
20#include "wlan.h"
21#include "wlan_cfg.h"
22
23#define FLOW_CONTROL_LOWER_THRESHOLD 128
24#define FLOW_CONTROL_UPPER_THRESHOLD 256
25
26#define PMKID_FOUND 1
27#define NUM_STA_ASSOCIATED 8
28
29#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
30#define DEFAULT_LINK_SPEED 72
31
32#define TX_BACKOFF_WEIGHT_MS 1
33
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))
38
39struct wilc_wfi_stats {
40 unsigned long rx_packets;
41 unsigned long tx_packets;
42 unsigned long rx_bytes;
43 unsigned long tx_bytes;
44 u64 rx_time;
45 u64 tx_time;
46
47};
48
49struct wilc_wfi_key {
50 u8 *key;
51 u8 *seq;
52 int key_len;
53 int seq_len;
54 u32 cipher;
55};
56
57struct sta_info {
58 u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
59};
60
61/* Parameters needed for host interface for remaining on channel */
62struct wilc_wfi_p2p_listen_params {
63 struct ieee80211_channel *listen_ch;
64 u32 listen_duration;
65 u64 listen_cookie;
66};
67
68static const u32 wilc_cipher_suites[] = {
69 WLAN_CIPHER_SUITE_TKIP,
70 WLAN_CIPHER_SUITE_CCMP,
71 WLAN_CIPHER_SUITE_AES_CMAC
72};
73
74#define CHAN2G(_channel, _freq, _flags) { \
75 .band = NL80211_BAND_2GHZ, \
76 .center_freq = (_freq), \
77 .hw_value = (_channel), \
78 .flags = (_flags), \
79 .max_antenna_gain = 0, \
80 .max_power = 30, \
81}
82
83static const struct ieee80211_channel wilc_2ghz_channels[] = {
84 CHAN2G(1, 2412, 0),
85 CHAN2G(2, 2417, 0),
86 CHAN2G(3, 2422, 0),
87 CHAN2G(4, 2427, 0),
88 CHAN2G(5, 2432, 0),
89 CHAN2G(6, 2437, 0),
90 CHAN2G(7, 2442, 0),
91 CHAN2G(8, 2447, 0),
92 CHAN2G(9, 2452, 0),
93 CHAN2G(10, 2457, 0),
94 CHAN2G(11, 2462, 0),
95 CHAN2G(12, 2467, 0),
96 CHAN2G(13, 2472, 0),
97 CHAN2G(14, 2484, 0)
98};
99
100#define RATETAB_ENT(_rate, _hw_value, _flags) { \
101 .bitrate = (_rate), \
102 .hw_value = (_hw_value), \
103 .flags = (_flags), \
104}
105
106static 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)
119};
120
121struct wilc_priv {
122 struct wireless_dev wdev;
123 struct cfg80211_scan_request *scan_req;
124
125 struct wilc_wfi_p2p_listen_params remain_on_ch_params;
126 u64 tx_cookie;
127
128 bool cfg_scanning;
129
130 u8 associated_bss[ETH_ALEN];
131 struct sta_info assoc_stainfo;
132 struct sk_buff *skb;
133 struct net_device *dev;
134 struct host_if_drv *hif_drv;
135 struct wilc_pmkid_attr pmkid_list;
136
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];
142 u8 wilc_groupkey;
143
144 /* mutexes */
145 struct mutex scan_req_lock;
146 bool p2p_listen_state;
147 int scanned_cnt;
148
149 u64 inc_roc_cookie;
150};
151
152#define MAX_TCP_SESSION 25
153#define MAX_PENDING_ACKS 256
154
155struct ack_session_info {
156 u32 seq_num;
157 u32 bigger_ack_num;
158 u16 src_port;
159 u16 dst_port;
160 u16 status;
161};
162
163struct pending_acks {
164 u32 ack_num;
165 u32 session_index;
166 struct txq_entry_t *txqe;
167};
168
169struct tcp_ack_filter {
170 struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
171 struct pending_acks pending_acks[MAX_PENDING_ACKS];
172 u32 pending_base;
173 u32 tcp_session;
174 u32 pending_acks_idx;
175 bool enabled;
176};
177
178struct wilc_vif {
179 u8 idx;
180 u8 iftype;
181 int monitor_flag;
182 int mac_opened;
183 u32 mgmt_reg_stypes;
184 struct net_device_stats netstats;
185 struct wilc *wilc;
186 u8 bssid[ETH_ALEN];
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;
193 bool connecting;
194 struct wilc_priv priv;
195 struct list_head list;
196 struct cfg80211_bss *bss;
197 struct cfg80211_external_auth_params auth;
198};
199
200struct wilc_tx_queue_status {
201 u8 buffer[AC_BUFFER_SIZE];
202 u16 end_index;
203 u16 cnt[NQUEUES];
204 u16 sum;
205 bool initialized;
206};
207
208struct wilc {
209 struct wiphy *wiphy;
210 const struct wilc_hif_func *hif_func;
211 int io_type;
212 s8 mac_status;
213 struct clk *rtc_clk;
214 bool initialized;
215 u32 chipid;
216 bool power_save_mode;
217 int dev_irq_num;
218 int close;
219 u8 vif_num;
220 struct list_head vif_list;
221
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
230 */
231 struct srcu_struct srcu;
232 u8 open_ifcs;
233
234 /* protect head of transmit queue */
235 struct mutex txq_add_to_head_cs;
236
237 /* protect txq_entry_t transmit queue */
238 spinlock_t txq_spinlock;
239
240 /* protect rxq_entry_t receiver queue */
241 struct mutex rxq_cs;
242
243 /* lock to protect hif access */
244 struct mutex hif_cs;
245
246 struct completion cfg_event;
247 struct completion sync_event;
248 struct completion txq_event;
249 struct completion txq_thread_started;
250
251 struct task_struct *txq_thread;
252
253 int quit;
254
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;
259 u8 cfg_seq_no;
260
261 u8 *rx_buffer;
262 u32 rx_buffer_offset;
263 u8 *tx_buffer;
264 u32 *vmm_table;
265
266 struct txq_handle txq[NQUEUES];
267 int txq_entries;
268
269 struct wilc_tx_queue_status tx_q_limit;
270 struct rxq_entry_t rxq_head;
271
272 const struct firmware *firmware;
273
274 struct device *dev;
275
276 struct workqueue_struct *hif_workqueue;
277 struct wilc_cfg cfg;
278 void *bus_data;
279 struct net_device *monitor_dev;
280
281 /* deinit lock */
282 struct mutex deinit_lock;
283 u8 sta_ch;
284 u8 op_ch;
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];
290};
291
292struct wilc_wfi_mon_priv {
293 struct net_device *real_ndev;
294};
295
296void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
297void wilc_mac_indicate(struct wilc *wilc);
298void wilc_netdev_cleanup(struct wilc *wilc);
299void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth);
300void wilc_wlan_set_bssid(struct net_device *wilc_netdev, const u8 *bssid,
301 u8 mode);
302struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
303 int vif_type, enum nl80211_iftype type,
304 bool rtnl_locked);
305#endif
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
4 * All rights reserved.
5 */
6
7#ifndef WILC_NETDEV_H
8#define WILC_NETDEV_H
9
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
17#include "hif.h"
18#include "wlan.h"
19#include "wlan_cfg.h"
20
21#define FLOW_CONTROL_LOWER_THRESHOLD 128
22#define FLOW_CONTROL_UPPER_THRESHOLD 256
23
24#define PMKID_FOUND 1
25#define NUM_STA_ASSOCIATED 8
26
27#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
28#define DEFAULT_LINK_SPEED 72
29
30struct wilc_wfi_stats {
31 unsigned long rx_packets;
32 unsigned long tx_packets;
33 unsigned long rx_bytes;
34 unsigned long tx_bytes;
35 u64 rx_time;
36 u64 tx_time;
37
38};
39
40struct wilc_wfi_key {
41 u8 *key;
42 u8 *seq;
43 int key_len;
44 int seq_len;
45 u32 cipher;
46};
47
48struct sta_info {
49 u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
50};
51
52/* Parameters needed for host interface for remaining on channel */
53struct wilc_wfi_p2p_listen_params {
54 struct ieee80211_channel *listen_ch;
55 u32 listen_duration;
56 u64 listen_cookie;
57};
58
59static const u32 wilc_cipher_suites[] = {
60 WLAN_CIPHER_SUITE_TKIP,
61 WLAN_CIPHER_SUITE_CCMP,
62 WLAN_CIPHER_SUITE_AES_CMAC
63};
64
65#define CHAN2G(_channel, _freq, _flags) { \
66 .band = NL80211_BAND_2GHZ, \
67 .center_freq = (_freq), \
68 .hw_value = (_channel), \
69 .flags = (_flags), \
70 .max_antenna_gain = 0, \
71 .max_power = 30, \
72}
73
74static const struct ieee80211_channel wilc_2ghz_channels[] = {
75 CHAN2G(1, 2412, 0),
76 CHAN2G(2, 2417, 0),
77 CHAN2G(3, 2422, 0),
78 CHAN2G(4, 2427, 0),
79 CHAN2G(5, 2432, 0),
80 CHAN2G(6, 2437, 0),
81 CHAN2G(7, 2442, 0),
82 CHAN2G(8, 2447, 0),
83 CHAN2G(9, 2452, 0),
84 CHAN2G(10, 2457, 0),
85 CHAN2G(11, 2462, 0),
86 CHAN2G(12, 2467, 0),
87 CHAN2G(13, 2472, 0),
88 CHAN2G(14, 2484, 0)
89};
90
91#define RATETAB_ENT(_rate, _hw_value, _flags) { \
92 .bitrate = (_rate), \
93 .hw_value = (_hw_value), \
94 .flags = (_flags), \
95}
96
97static struct ieee80211_rate wilc_bitrates[] = {
98 RATETAB_ENT(10, 0, 0),
99 RATETAB_ENT(20, 1, 0),
100 RATETAB_ENT(55, 2, 0),
101 RATETAB_ENT(110, 3, 0),
102 RATETAB_ENT(60, 9, 0),
103 RATETAB_ENT(90, 6, 0),
104 RATETAB_ENT(120, 7, 0),
105 RATETAB_ENT(180, 8, 0),
106 RATETAB_ENT(240, 9, 0),
107 RATETAB_ENT(360, 10, 0),
108 RATETAB_ENT(480, 11, 0),
109 RATETAB_ENT(540, 12, 0)
110};
111
112struct wilc_priv {
113 struct wireless_dev wdev;
114 struct cfg80211_scan_request *scan_req;
115
116 struct wilc_wfi_p2p_listen_params remain_on_ch_params;
117 u64 tx_cookie;
118
119 bool cfg_scanning;
120
121 u8 associated_bss[ETH_ALEN];
122 struct sta_info assoc_stainfo;
123 struct sk_buff *skb;
124 struct net_device *dev;
125 struct host_if_drv *hif_drv;
126 struct wilc_pmkid_attr pmkid_list;
127
128 /* The real interface that the monitor is on */
129 struct net_device *real_ndev;
130 struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
131 struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
132 struct wilc_wfi_key *wilc_igtk[2];
133 u8 wilc_groupkey;
134
135 /* mutexes */
136 struct mutex scan_req_lock;
137 bool p2p_listen_state;
138 int scanned_cnt;
139
140 u64 inc_roc_cookie;
141};
142
143#define MAX_TCP_SESSION 25
144#define MAX_PENDING_ACKS 256
145
146struct ack_session_info {
147 u32 seq_num;
148 u32 bigger_ack_num;
149 u16 src_port;
150 u16 dst_port;
151 u16 status;
152};
153
154struct pending_acks {
155 u32 ack_num;
156 u32 session_index;
157 struct txq_entry_t *txqe;
158};
159
160struct tcp_ack_filter {
161 struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
162 struct pending_acks pending_acks[MAX_PENDING_ACKS];
163 u32 pending_base;
164 u32 tcp_session;
165 u32 pending_acks_idx;
166 bool enabled;
167};
168
169struct wilc_vif {
170 u8 idx;
171 u8 iftype;
172 int monitor_flag;
173 int mac_opened;
174 u32 mgmt_reg_stypes;
175 struct net_device_stats netstats;
176 struct wilc *wilc;
177 u8 bssid[ETH_ALEN];
178 struct host_if_drv *hif_drv;
179 struct net_device *ndev;
180 struct timer_list during_ip_timer;
181 struct timer_list periodic_rssi;
182 struct rf_info periodic_stat;
183 struct tcp_ack_filter ack_filter;
184 bool connecting;
185 struct wilc_priv priv;
186 struct list_head list;
187 struct cfg80211_bss *bss;
188 struct cfg80211_external_auth_params auth;
189};
190
191struct wilc_tx_queue_status {
192 u8 buffer[AC_BUFFER_SIZE];
193 u16 end_index;
194 u16 cnt[NQUEUES];
195 u16 sum;
196 bool initialized;
197};
198
199struct wilc {
200 struct wiphy *wiphy;
201 const struct wilc_hif_func *hif_func;
202 int io_type;
203 s8 mac_status;
204 struct clk *rtc_clk;
205 bool initialized;
206 u32 chipid;
207 bool power_save_mode;
208 int dev_irq_num;
209 int close;
210 u8 vif_num;
211 struct list_head vif_list;
212
213 /* protect vif list */
214 struct mutex vif_mutex;
215 struct srcu_struct srcu;
216 u8 open_ifcs;
217
218 /* protect head of transmit queue */
219 struct mutex txq_add_to_head_cs;
220
221 /* protect txq_entry_t transmit queue */
222 spinlock_t txq_spinlock;
223
224 /* protect rxq_entry_t receiver queue */
225 struct mutex rxq_cs;
226
227 /* lock to protect hif access */
228 struct mutex hif_cs;
229
230 struct completion cfg_event;
231 struct completion sync_event;
232 struct completion txq_event;
233 struct completion txq_thread_started;
234
235 struct task_struct *txq_thread;
236
237 int quit;
238
239 /* lock to protect issue of wid command to firmware */
240 struct mutex cfg_cmd_lock;
241 struct wilc_cfg_frame cfg_frame;
242 u32 cfg_frame_offset;
243 u8 cfg_seq_no;
244
245 u8 *rx_buffer;
246 u32 rx_buffer_offset;
247 u8 *tx_buffer;
248 u32 *vmm_table;
249
250 struct txq_handle txq[NQUEUES];
251 int txq_entries;
252
253 struct wilc_tx_queue_status tx_q_limit;
254 struct rxq_entry_t rxq_head;
255
256 const struct firmware *firmware;
257
258 struct device *dev;
259 bool suspend_event;
260
261 struct workqueue_struct *hif_workqueue;
262 struct wilc_cfg cfg;
263 void *bus_data;
264 struct net_device *monitor_dev;
265
266 /* deinit lock */
267 struct mutex deinit_lock;
268 u8 sta_ch;
269 u8 op_ch;
270 struct ieee80211_channel channels[ARRAY_SIZE(wilc_2ghz_channels)];
271 struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)];
272 struct ieee80211_supported_band band;
273 u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)];
274};
275
276struct wilc_wfi_mon_priv {
277 struct net_device *real_ndev;
278};
279
280void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
281void wilc_mac_indicate(struct wilc *wilc);
282void wilc_netdev_cleanup(struct wilc *wilc);
283void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth);
284void wilc_wlan_set_bssid(struct net_device *wilc_netdev, const u8 *bssid,
285 u8 mode);
286struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
287 int vif_type, enum nl80211_iftype type,
288 bool rtnl_locked);
289#endif