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