Linux-libre 5.7.3-gnu
[librecmc/linux-libre.git] / drivers / staging / wilc1000 / netdev.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_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 NUM_REG_FRAME                           2
28
29 #define TCP_ACK_FILTER_LINK_SPEED_THRESH        54
30 #define DEFAULT_LINK_SPEED                      72
31
32 struct 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
42 struct wilc_wfi_key {
43         u8 *key;
44         u8 *seq;
45         int key_len;
46         int seq_len;
47         u32 cipher;
48 };
49
50 struct wilc_wfi_wep_key {
51         u8 *key;
52         u8 key_len;
53         u8 key_idx;
54 };
55
56 struct 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 */
61 struct wilc_wfi_p2p_listen_params {
62         struct ieee80211_channel *listen_ch;
63         u32 listen_duration;
64         u64 listen_cookie;
65 };
66
67 static const u32 wilc_cipher_suites[] = {
68         WLAN_CIPHER_SUITE_WEP40,
69         WLAN_CIPHER_SUITE_WEP104,
70         WLAN_CIPHER_SUITE_TKIP,
71         WLAN_CIPHER_SUITE_CCMP,
72         WLAN_CIPHER_SUITE_AES_CMAC
73 };
74
75 #define CHAN2G(_channel, _freq, _flags) {        \
76         .band             = NL80211_BAND_2GHZ, \
77         .center_freq      = (_freq),             \
78         .hw_value         = (_channel),          \
79         .flags            = (_flags),            \
80         .max_antenna_gain = 0,                   \
81         .max_power        = 30,                  \
82 }
83
84 static const struct ieee80211_channel wilc_2ghz_channels[] = {
85         CHAN2G(1,  2412, 0),
86         CHAN2G(2,  2417, 0),
87         CHAN2G(3,  2422, 0),
88         CHAN2G(4,  2427, 0),
89         CHAN2G(5,  2432, 0),
90         CHAN2G(6,  2437, 0),
91         CHAN2G(7,  2442, 0),
92         CHAN2G(8,  2447, 0),
93         CHAN2G(9,  2452, 0),
94         CHAN2G(10, 2457, 0),
95         CHAN2G(11, 2462, 0),
96         CHAN2G(12, 2467, 0),
97         CHAN2G(13, 2472, 0),
98         CHAN2G(14, 2484, 0)
99 };
100
101 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
102         .bitrate  = (_rate),                    \
103         .hw_value = (_hw_value),                \
104         .flags    = (_flags),                   \
105 }
106
107 static struct ieee80211_rate wilc_bitrates[] = {
108         RATETAB_ENT(10,  0,  0),
109         RATETAB_ENT(20,  1,  0),
110         RATETAB_ENT(55,  2,  0),
111         RATETAB_ENT(110, 3,  0),
112         RATETAB_ENT(60,  9,  0),
113         RATETAB_ENT(90,  6,  0),
114         RATETAB_ENT(120, 7,  0),
115         RATETAB_ENT(180, 8,  0),
116         RATETAB_ENT(240, 9,  0),
117         RATETAB_ENT(360, 10, 0),
118         RATETAB_ENT(480, 11, 0),
119         RATETAB_ENT(540, 12, 0)
120 };
121
122 struct wilc_priv {
123         struct wireless_dev wdev;
124         struct cfg80211_scan_request *scan_req;
125
126         struct wilc_wfi_p2p_listen_params remain_on_ch_params;
127         u64 tx_cookie;
128
129         bool cfg_scanning;
130
131         u8 associated_bss[ETH_ALEN];
132         struct sta_info assoc_stainfo;
133         struct sk_buff *skb;
134         struct net_device *dev;
135         struct host_if_drv *hif_drv;
136         struct wilc_pmkid_attr pmkid_list;
137         u8 wep_key[4][WLAN_KEY_LEN_WEP104];
138         u8 wep_key_len[4];
139
140         /* The real interface that the monitor is on */
141         struct net_device *real_ndev;
142         struct wilc_wfi_key *wilc_gtk[WILC_MAX_NUM_STA];
143         struct wilc_wfi_key *wilc_ptk[WILC_MAX_NUM_STA];
144         u8 wilc_groupkey;
145
146         /* mutexes */
147         struct mutex scan_req_lock;
148         bool p2p_listen_state;
149         int scanned_cnt;
150
151         u64 inc_roc_cookie;
152 };
153
154 struct frame_reg {
155         u16 type;
156         bool reg;
157 };
158
159 #define MAX_TCP_SESSION                25
160 #define MAX_PENDING_ACKS               256
161
162 struct ack_session_info {
163         u32 seq_num;
164         u32 bigger_ack_num;
165         u16 src_port;
166         u16 dst_port;
167         u16 status;
168 };
169
170 struct pending_acks {
171         u32 ack_num;
172         u32 session_index;
173         struct txq_entry_t  *txqe;
174 };
175
176 struct tcp_ack_filter {
177         struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
178         struct pending_acks pending_acks[MAX_PENDING_ACKS];
179         u32 pending_base;
180         u32 tcp_session;
181         u32 pending_acks_idx;
182         bool enabled;
183 };
184
185 struct wilc_vif {
186         u8 idx;
187         u8 iftype;
188         int monitor_flag;
189         int mac_opened;
190         struct frame_reg frame_reg[NUM_REG_FRAME];
191         struct net_device_stats netstats;
192         struct wilc *wilc;
193         u8 bssid[ETH_ALEN];
194         struct host_if_drv *hif_drv;
195         struct net_device *ndev;
196         u8 mode;
197         struct timer_list during_ip_timer;
198         struct timer_list periodic_rssi;
199         struct rf_info periodic_stat;
200         struct tcp_ack_filter ack_filter;
201         bool connecting;
202         struct wilc_priv priv;
203         struct list_head list;
204         struct cfg80211_bss *bss;
205 };
206
207 struct 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         int dev_irq_num;
215         int close;
216         u8 vif_num;
217         struct list_head vif_list;
218
219         /* protect vif list */
220         struct mutex vif_mutex;
221         struct srcu_struct srcu;
222         u8 open_ifcs;
223
224         /* protect head of transmit queue */
225         struct mutex txq_add_to_head_cs;
226
227         /* protect txq_entry_t transmit queue */
228         spinlock_t txq_spinlock;
229
230         /* protect rxq_entry_t receiver queue */
231         struct mutex rxq_cs;
232
233         /* lock to protect hif access */
234         struct mutex hif_cs;
235
236         struct completion cfg_event;
237         struct completion sync_event;
238         struct completion txq_event;
239         struct completion txq_thread_started;
240
241         struct task_struct *txq_thread;
242
243         int quit;
244
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         int clients_count;
266         struct workqueue_struct *hif_workqueue;
267         enum chip_ps_states chip_ps_state;
268         struct wilc_cfg cfg;
269         void *bus_data;
270         struct net_device *monitor_dev;
271
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