net:wireless:Support eswin usb wifi ECR6600U
[platform/kernel/linux-starfive.git] / drivers / net / wireless / eswin / sdio / core.h
1 /**
2  ******************************************************************************
3  *
4  * @file core.h
5  *
6  * @brief sdio core definitions
7  *
8  * Copyright (C) ESWIN 2015-2020
9  *
10  ******************************************************************************
11  */
12
13 #ifndef _CORE_H_
14 #define _CORE_H_
15
16
17 #include <linux/completion.h>
18 #include <linux/if_ether.h>
19
20 #include <net/mac80211.h>
21 #include "ecrnx_compat.h"
22
23
24 #define ESWIN_FLAG_CORE_REGISTERED      1
25
26 #define ESWIN_NR_VIF            2
27 #define ESWIN_NR_VIF_HW_QUEUE   4
28
29
30 #define ESWIN_STATE_BOOT                1
31 #define ESWIN_STATE_INIT                2
32 #define ESWIN_STATE_STOP                3
33 #define ESWIN_STATE_CLOSING     4
34 #define ESWIN_STATE_CLOSEED     5
35 #define ESWIN_STATE_START       6
36 #define ESWIN_STATE_RUNNING     7
37
38 #define SDIO_PKG_MAX_BIT        9
39 #define SDIO_PKG_MAX_CNT        4//4/3
40 #define SDIO_PKG_BIT_SHIFT      (SDIO_PKG_MAX_BIT/SDIO_PKG_MAX_CNT)
41 #define SDIO_PKG_PAD_GRN        (512)//512/256
42 #define SDIO_PKG_DIV_MSZ        (1024)//1024/1536
43 #define SDIO_DATA_MTU       (1500)
44 #define SDIO_PKG_MAX_DATA   (SDIO_DATA_MTU + ECRNX_TX_TXDESC_API_ALIGN)
45
46
47 #define WIM_RESP_TIMEOUT    (msecs_to_jiffies(100))
48
49 enum ESWIN_SCAN_MODE {
50         ESWIN_SCAN_MODE_IDLE = 0,
51         ESWIN_SCAN_MODE_SCANNING,
52         ESWIN_SCAN_MODE_ABORTING,
53 };
54
55
56
57 struct fwinfo_t {
58         uint32_t ready;
59         uint32_t version;
60         uint32_t tx_head_size;
61         uint32_t rx_head_size;
62         uint32_t payload_align;
63         uint32_t buffer_size;
64 };
65
66 struct eswin_capabilities {
67         uint64_t cap_mask;
68         uint16_t listen_interval;
69         uint16_t bss_max_idle;
70         uint8_t bss_max_idle_options;
71 };
72
73 struct eswin_max_idle {
74         bool enable;
75         u16 period;
76         u16 scale_factor;
77         u8 options;
78         struct timer_list keep_alive_timer;
79
80         unsigned long idle_period; /* jiffies */
81         struct timer_list timer;
82 };
83
84
85 /* Private txq driver data structure */
86 struct eswin_txq {
87         u16 hw_queue; /* 0: AC_BK, 1: AC_BE, 2: AC_VI, 3: AC_VO */
88         struct list_head list;
89         struct sk_buff_head queue; /* own queue */
90         unsigned long nr_fw_queueud;
91         unsigned long nr_push_allowed;
92         struct ieee80211_vif vif;
93         struct ieee80211_sta sta;
94 };
95
96 struct tx_buff_node {
97         struct tx_buff_node * next;
98         void * buff;
99         int    len;
100         int    flag;
101 };
102
103 struct tx_buff_queue {
104         struct tx_buff_node * head;
105         struct tx_buff_node * tail;
106         int    count;
107         spinlock_t lock;
108 };
109
110 struct tx_buff_pkg_node {
111         struct tx_buff_pkg_node * next;
112         void * buff;
113         int    len;
114         int    flag;
115         struct tx_buff_node * tx_node[SDIO_PKG_MAX_CNT];
116         int    node_cnt;
117 };
118
119 struct tx_buff_pkg_queue {
120         struct tx_buff_pkg_node * head;
121         struct tx_buff_pkg_node * tail;
122         int    count;
123         spinlock_t lock;
124 };
125
126 struct tx_buff_pkg_head {
127         unsigned int len[SDIO_PKG_MAX_CNT];
128 };
129
130 #define ESWIN_QUEUE_MAX  (ESWIN_NR_VIF_HW_QUEUE*ESWIN_NR_VIF + 3)
131 #define ESWIN_TX_NODE_CNT        64
132
133 typedef int (*sdio_rx_cb_t)(void *priv, struct sk_buff *skb);
134 typedef int (*sdio_data_cfm_cb_t)(void *priv, void *host_id);
135 struct eswin {
136
137     void *umac_priv; //mac drv data.
138         struct ieee80211_hw *hw;
139         struct ieee80211_vif *vif[ESWIN_NR_VIF];
140         struct device *dev;
141         int nr_active_vif;
142         int state;
143         bool promisc;
144
145         bool loopback;
146         bool ampdu_supported;
147         int lb_count;
148         bool amsdu_supported;
149         bool block_frame;
150         bool ampdu_reject;
151         
152         char alpha2[2];
153         u64 tsf_offset;
154
155         const struct sdio_ops *ops;
156         sdio_rx_cb_t rx_callback;
157         sdio_data_cfm_cb_t data_cfm_callback;
158         sdio_data_cfm_cb_t msg_cfm_callback;
159
160         //struct sx_buff_queue queue[ESWIN_NR_VIF]; /* 0: frame, 1: wim */
161         struct tx_buff_queue tx_queue;
162         struct tx_buff_pkg_queue tx_c_queue;
163         struct tx_buff_pkg_queue tx_pkg_queue;
164         struct tx_buff_node tx_node[ESWIN_TX_NODE_CNT];
165         struct tx_buff_node * tx_node_head;
166         spinlock_t tx_lock;
167         int tx_node_num;
168
169         struct tx_buff_pkg_node tx_pkg_node[ESWIN_TX_NODE_CNT];
170         struct tx_buff_pkg_node * tx_pkg_node_head;
171         spinlock_t tx_pkg_lock;
172         int tx_pkg_node_num;
173
174         struct work_struct work;
175         struct work_struct work_c;
176         struct work_struct work_pkg;
177
178         //struct task_struct *kthread_pkg;
179         //wait_queue_head_t wait_pkg; /* wait queue */
180
181         struct eswin_txq ntxq[ESWIN_QUEUE_MAX];
182
183         struct mutex state_mtx;
184         enum ESWIN_SCAN_MODE scan_mode;
185         
186         struct task_struct *kthread_pkg;
187         struct task_struct *kthread_tx;
188         struct task_struct *kthread_cb;
189
190         wait_queue_head_t wait_pkg;
191         wait_queue_head_t wait_tx;
192         wait_queue_head_t wait_cb;
193
194         struct delayed_work scan_timeout;
195
196         //struct work_struct register_work;
197         struct delayed_work register_work;
198
199
200         unsigned long dev_flags;
201         struct mac_address mac_addr[ESWIN_NR_VIF];
202         struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
203
204
205
206         /* Move to vif or sta driver data */
207         u8 frame_seqno;
208         u8 wim_seqno;
209         u8 band;
210         u16 center_freq;
211         u16 aid;
212         u32 cipher_pairwise;
213         u32 cipher_group;
214         
215         struct fwinfo_t fwinfo;
216         struct eswin_capabilities cap;
217
218         /* power management */
219         enum ps_mode {
220                 PS_DISABLED,
221                 PS_ENABLED,
222                 PS_AUTO_POLL,
223                 PS_MANUAL_POLL
224         } ps;
225         bool ps_poll_pending;
226         bool ps_enabled;
227
228
229
230         /* tx */
231         spinlock_t txq_lock;
232         struct list_head txq;
233         /* 0: AC_BK, 1: AC_BE, 2: AC_VI, 3: AC_VO */
234         atomic_t tx_credit[IEEE80211_NUM_ACS*3];
235         atomic_t tx_pend[IEEE80211_NUM_ACS*3];
236
237 //      struct completion wim_responded;
238 //      struct sk_buff *last_wim_responded;
239
240
241         struct delayed_work roc_finish;
242
243         struct firmware *fw;
244
245         struct dentry *debugfs;
246
247         /* must be last */
248         u8 drv_priv[0] __aligned(sizeof(void *));
249 };
250
251
252 /* vif driver data structure */
253 struct eswin_vif {
254         struct eswin *tr;
255         int index;
256         struct net_device *dev;
257
258         /* scan */
259         struct delayed_work scan_timeout;
260
261         /* power save */
262         bool ps_polling;
263
264         /* MLME */
265         spinlock_t preassoc_sta_lock;
266         struct list_head preassoc_sta_list;
267
268         /* inactivity */
269         u16 max_idle_period;
270 };
271
272 #define to_ieee80211_vif(v) \
273         container_of((void *)v, struct ieee80211_vif, drv_priv)
274
275 #define to_i_vif(v) ((struct eswin_vif *) (v)->drv_priv)
276
277 static inline int hw_vifindex(struct ieee80211_vif *vif)
278 {
279         struct eswin_vif *i_vif;
280
281         if (vif == NULL)
282                 return 0;
283
284         i_vif = to_i_vif(vif);
285         return i_vif->index;
286 }
287
288 /* sta driver data structure */
289 struct eswin_sta {
290         struct eswin *tr;
291         struct ieee80211_vif *vif;
292         /*struct ieee80211_sta *sta;*/
293
294         enum ieee80211_sta_state state;
295         struct list_head list;
296
297         /* keys */
298         struct ieee80211_key_conf *ptk;
299         struct ieee80211_key_conf *gtk;
300
301         /* BSS max idle period */
302         struct eswin_capabilities cap;
303         struct eswin_max_idle max_idle;
304 };
305
306 #define to_ieee80211_sta(s) \
307         container_of((void *)s, struct ieee80211_sta, drv_priv)
308
309 #define to_i_sta(s) ((struct eswin_sta *) (s)->drv_priv)
310
311
312
313 struct eswin_sta_handler {
314         int (*sta_state)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
315                          struct ieee80211_sta *sta,
316                          enum ieee80211_sta_state old_state,
317                          enum ieee80211_sta_state new_state);
318
319 };
320
321 #if 0
322 #define STAH(fn)                                        \
323         static struct eswin_sta_handler __stah_ ## fn   \
324         __attribute((__used__))                         \
325         __attribute((__section__("nrc.sta"))) = {       \
326                 .sta_state = fn,                        \
327         }
328
329 extern struct eswin_sta_handler __sta_h_start, __sta_h_end;
330 #endif
331
332
333 /* trx */
334
335 struct eswin_trx_data {
336         struct eswin *tr;
337         struct ieee80211_vif *vif;
338         struct ieee80211_sta *sta;
339         struct sk_buff *skb;
340         int result;
341 };
342
343
344 #define NL80211_IFTYPE_ALL (BIT(NUM_NL80211_IFTYPES)-1)
345
346
347
348 int eswin_core_register(struct eswin *tr);
349 void eswin_core_unregister(struct eswin *tr);
350
351 struct eswin * eswin_core_create(size_t priv_size, struct device *dev,
352                                 const struct sdio_ops * ops);
353
354 void eswin_core_destroy(struct eswin *tr);
355
356
357 extern int power_save;
358 extern int disable_cqm;
359 #ifdef CONFIG_ECRNX_WIFO_CAIL
360 extern bool amt_mode;
361 #endif
362 extern bool set_gain;
363
364 #endif