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