Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / drivers / staging / wilc1000 / wilc_wfi_netdevice.h
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_WFI_NETDEVICE
8 #define WILC_WFI_NETDEVICE
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 "wilc_hif.h"
18 #include "wilc_wlan.h"
19 #include "wilc_wlan_cfg.h"
20
21 #define FLOW_CONTROL_LOWER_THRESHOLD            128
22 #define FLOW_CONTROL_UPPER_THRESHOLD            256
23
24 #define WILC_MAX_NUM_PMKIDS                     16
25 #define PMKID_FOUND                             1
26 #define NUM_STA_ASSOCIATED                      8
27
28 #define NUM_REG_FRAME                           2
29
30 #define TCP_ACK_FILTER_LINK_SPEED_THRESH        54
31 #define DEFAULT_LINK_SPEED                      72
32
33 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
34
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;
40         u64 rx_time;
41         u64 tx_time;
42
43 };
44
45 struct wilc_wfi_key {
46         u8 *key;
47         u8 *seq;
48         int key_len;
49         int seq_len;
50         u32 cipher;
51 };
52
53 struct wilc_wfi_wep_key {
54         u8 *key;
55         u8 key_len;
56         u8 key_idx;
57 };
58
59 struct sta_info {
60         u8 sta_associated_bss[WILC_MAX_NUM_STA][ETH_ALEN];
61 };
62
63 /*Parameters needed for host interface for  remaining on channel*/
64 struct wilc_wfi_p2p_listen_params {
65         struct ieee80211_channel *listen_ch;
66         u32 listen_duration;
67         u64 listen_cookie;
68 };
69
70 struct wilc_p2p_var {
71         u8 local_random;
72         u8 recv_random;
73         bool is_wilc_ie;
74 };
75
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
82 };
83
84 #define CHAN2G(_channel, _freq, _flags) {        \
85         .band             = NL80211_BAND_2GHZ, \
86         .center_freq      = (_freq),             \
87         .hw_value         = (_channel),          \
88         .flags            = (_flags),            \
89         .max_antenna_gain = 0,                   \
90         .max_power        = 30,                  \
91 }
92
93 static const struct ieee80211_channel wilc_2ghz_channels[] = {
94         CHAN2G(1,  2412, 0),
95         CHAN2G(2,  2417, 0),
96         CHAN2G(3,  2422, 0),
97         CHAN2G(4,  2427, 0),
98         CHAN2G(5,  2432, 0),
99         CHAN2G(6,  2437, 0),
100         CHAN2G(7,  2442, 0),
101         CHAN2G(8,  2447, 0),
102         CHAN2G(9,  2452, 0),
103         CHAN2G(10, 2457, 0),
104         CHAN2G(11, 2462, 0),
105         CHAN2G(12, 2467, 0),
106         CHAN2G(13, 2472, 0),
107         CHAN2G(14, 2484, 0)
108 };
109
110 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
111         .bitrate  = (_rate),                    \
112         .hw_value = (_hw_value),                \
113         .flags    = (_flags),                   \
114 }
115
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)
129 };
130
131 struct wilc_priv {
132         struct wireless_dev wdev;
133         struct cfg80211_scan_request *scan_req;
134
135         struct wilc_wfi_p2p_listen_params remain_on_ch_params;
136         u64 tx_cookie;
137
138         bool cfg_scanning;
139
140         u8 associated_bss[ETH_ALEN];
141         struct sta_info assoc_stainfo;
142         struct sk_buff *skb;
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];
147         u8 wep_key_len[4];
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];
152         u8 wilc_groupkey;
153         /* mutexes */
154         struct mutex scan_req_lock;
155         bool p2p_listen_state;
156         int scanned_cnt;
157         struct wilc_p2p_var p2p;
158
159         u64 inc_roc_cookie;
160 };
161
162 struct frame_reg {
163         u16 type;
164         bool reg;
165 };
166
167 #define MAX_TCP_SESSION                25
168 #define MAX_PENDING_ACKS               256
169
170 struct ack_session_info {
171         u32 seq_num;
172         u32 bigger_ack_num;
173         u16 src_port;
174         u16 dst_port;
175         u16 status;
176 };
177
178 struct pending_acks {
179         u32 ack_num;
180         u32 session_index;
181         struct txq_entry_t  *txqe;
182 };
183
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];
187         u32 pending_base;
188         u32 tcp_session;
189         u32 pending_acks_idx;
190         bool enabled;
191 };
192
193 struct wilc_vif {
194         u8 idx;
195         u8 iftype;
196         int monitor_flag;
197         int mac_opened;
198         struct frame_reg frame_reg[NUM_REG_FRAME];
199         struct net_device_stats netstats;
200         struct wilc *wilc;
201         u8 bssid[ETH_ALEN];
202         struct host_if_drv *hif_drv;
203         struct net_device *ndev;
204         u8 mode;
205         struct timer_list during_ip_timer;
206         bool obtaining_ip;
207         struct timer_list periodic_rssi;
208         struct rf_info periodic_stat;
209         struct tcp_ack_filter ack_filter;
210         bool connecting;
211         struct wilc_priv priv;
212 };
213
214 struct wilc {
215         struct wiphy *wiphy;
216         const struct wilc_hif_func *hif_func;
217         int io_type;
218         s8 mac_status;
219         struct gpio_desc *gpio_irq;
220         bool initialized;
221         int dev_irq_num;
222         int close;
223         u8 vif_num;
224         struct wilc_vif *vif[WILC_NUM_CONCURRENT_IFC];
225         /*protect vif list*/
226         struct mutex vif_mutex;
227         u8 open_ifcs;
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*/
233         struct mutex rxq_cs;
234         /* lock to protect hif access */
235         struct mutex hif_cs;
236
237         struct completion cfg_event;
238         struct completion sync_event;
239         struct completion txq_event;
240         struct completion txq_thread_started;
241
242         struct task_struct *txq_thread;
243
244         int quit;
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;
249         u8 cfg_seq_no;
250
251         u8 *rx_buffer;
252         u32 rx_buffer_offset;
253         u8 *tx_buffer;
254
255         struct txq_entry_t txq_head;
256         int txq_entries;
257
258         struct rxq_entry_t rxq_head;
259
260         const struct firmware *firmware;
261
262         struct device *dev;
263         bool suspend_event;
264
265         bool enable_ps;
266         int clients_count;
267         struct workqueue_struct *hif_workqueue;
268         enum chip_ps_states chip_ps_state;
269         struct wilc_cfg cfg;
270         void *bus_data;
271         struct net_device *monitor_dev;
272         /* deinit lock */
273         struct mutex deinit_lock;
274         u8 sta_ch;
275         u8 op_ch;
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)];
280 };
281
282 struct wilc_wfi_mon_priv {
283         struct net_device *real_ndev;
284 };
285
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,
293                                       bool rtnl_locked);
294 #endif