staging: r8188eu: fix include directory mess
[linux-2.6-microblaze.git] / drivers / staging / r8188eu / include / rtw_recv.h
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
3
4 #ifndef _RTW_RECV_H_
5 #define _RTW_RECV_H_
6
7 #include "osdep_service.h"
8 #include "drv_types.h"
9
10 #define NR_RECVFRAME 256
11
12 #define RXFRAME_ALIGN   8
13 #define RXFRAME_ALIGN_SZ        (1<<RXFRAME_ALIGN)
14
15 #define MAX_RXFRAME_CNT 512
16 #define MAX_RX_NUMBLKS          (32)
17 #define RECVFRAME_HDR_ALIGN 128
18
19 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
20
21 #define MAX_SUBFRAME_COUNT      64
22
23 /* for Rx reordering buffer control */
24 struct recv_reorder_ctrl {
25         struct adapter  *padapter;
26         u8 enable;
27         u16 indicate_seq;/* wstart_b, init_value=0xffff */
28         u16 wend_b;
29         u8 wsize_b;
30         struct __queue pending_recvframe_queue;
31         struct timer_list reordering_ctrl_timer;
32 };
33
34 struct  stainfo_rxcache {
35         u16     tid_rxseq[16];
36 /*
37         unsigned short  tid0_rxseq;
38         unsigned short  tid1_rxseq;
39         unsigned short  tid2_rxseq;
40         unsigned short  tid3_rxseq;
41         unsigned short  tid4_rxseq;
42         unsigned short  tid5_rxseq;
43         unsigned short  tid6_rxseq;
44         unsigned short  tid7_rxseq;
45         unsigned short  tid8_rxseq;
46         unsigned short  tid9_rxseq;
47         unsigned short  tid10_rxseq;
48         unsigned short  tid11_rxseq;
49         unsigned short  tid12_rxseq;
50         unsigned short  tid13_rxseq;
51         unsigned short  tid14_rxseq;
52         unsigned short  tid15_rxseq;
53 */
54 };
55
56 struct smooth_rssi_data {
57         u32     elements[100];  /* array to store values */
58         u32     index;                  /* index to current array to store */
59         u32     total_num;              /* num of valid elements */
60         u32     total_val;              /* sum of valid elements */
61 };
62
63 struct signal_stat {
64         u8      update_req;             /* used to indicate */
65         u8      avg_val;                /* avg of valid elements */
66         u32     total_num;              /* num of valid elements */
67         u32     total_val;              /* sum of valid elements */
68 };
69 #define MAX_PATH_NUM_92CS               3
70 struct phy_info {
71         u8      RxPWDBAll;
72         u8      SignalQuality;   /*  in 0-100 index. */
73         u8      RxMIMOSignalQuality[MAX_PATH_NUM_92CS]; /* EVM */
74         u8      RxMIMOSignalStrength[MAX_PATH_NUM_92CS];/*  in 0~100 index */
75         s8      RxPower; /*  in dBm Translate from PWdB */
76 /*  Real power in dBm for this packet, no beautification and aggregation.
77  * Keep this raw info to be used for the other procedures. */
78         s8      recvpower;
79         u8      BTRxRSSIPercentage;
80         u8      SignalStrength; /*  in 0-100 index. */
81         u8      RxPwr[MAX_PATH_NUM_92CS];/* per-path's pwdb */
82         u8      RxSNR[MAX_PATH_NUM_92CS];/* per-path's SNR */
83 };
84
85 struct rx_pkt_attrib {
86         u16     pkt_len;
87         u8      physt;
88         u8      drvinfo_sz;
89         u8      shift_sz;
90         u8      hdrlen; /* the WLAN Header Len */
91         u8      to_fr_ds;
92         u8      amsdu;
93         u8      qos;
94         u8      priority;
95         u8      pw_save;
96         u8      mdata;
97         u16     seq_num;
98         u8      frag_num;
99         u8      mfrag;
100         u8      order;
101         u8      privacy; /* in frame_ctrl field */
102         u8      bdecrypted;
103         u8      encrypt; /* when 0 indicate no encrypt. when non-zero,
104                           * indicate the encrypt algorith */
105         u8      iv_len;
106         u8      icv_len;
107         u8      crc_err;
108         u8      icv_err;
109
110         u16 eth_type;
111
112         u8      dst[ETH_ALEN];
113         u8      src[ETH_ALEN];
114         u8      ta[ETH_ALEN];
115         u8      ra[ETH_ALEN];
116         u8      bssid[ETH_ALEN];
117
118         u8 ack_policy;
119
120         u8      key_index;
121
122         u8      mcs_rate;
123         u8      rxht;
124         u8      sgi;
125         u8      pkt_rpt_type;
126         u32     MacIDValidEntry[2];     /*  64 bits present 64 entry. */
127
128         struct phy_info phy_info;
129 };
130
131 /* These definition is used for Rx packet reordering. */
132 #define SN_LESS(a, b)           (((a - b) & 0x800) != 0)
133 #define SN_EQUAL(a, b)  (a == b)
134 #define REORDER_WAIT_TIME       (50) /*  (ms) */
135
136 #define RECVBUFF_ALIGN_SZ 8
137
138 #define RXDESC_SIZE     24
139 #define RXDESC_OFFSET RXDESC_SIZE
140
141 struct recv_stat {
142         __le32 rxdw0;
143         __le32 rxdw1;
144         __le32 rxdw2;
145         __le32 rxdw3;
146         __le32 rxdw4;
147         __le32 rxdw5;
148 };
149
150 #define EOR BIT(30)
151
152 /*
153 accesser of recv_priv: rtw_recv_entry(dispatch / passive level);
154 recv_thread(passive) ; returnpkt(dispatch)
155 ; halt(passive) ;
156
157 using enter_critical section to protect
158 */
159 struct recv_priv {
160         spinlock_t lock;
161         struct __queue free_recv_queue;
162         struct __queue recv_pending_queue;
163         struct __queue uc_swdec_pending_queue;
164         u8 *pallocated_frame_buf;
165         u8 *precv_frame_buf;
166         uint free_recvframe_cnt;
167         struct adapter  *adapter;
168         u32     bIsAnyNonBEPkts;
169         u64     rx_bytes;
170         u64     rx_pkts;
171         u64     rx_drop;
172         u64     last_rx_bytes;
173
174         uint  rx_icv_err;
175         uint  rx_largepacket_crcerr;
176         uint  rx_smallpacket_crcerr;
177         uint  rx_middlepacket_crcerr;
178         struct semaphore allrxreturnevt;
179         uint    ff_hwaddr;
180         u8      rx_pending_cnt;
181
182         struct tasklet_struct irq_prepare_beacon_tasklet;
183         struct tasklet_struct recv_tasklet;
184         struct sk_buff_head free_recv_skb_queue;
185         struct sk_buff_head rx_skb_queue;
186         u8 *pallocated_recv_buf;
187         u8 *precv_buf;    /*  4 alignment */
188         struct __queue free_recv_buf_queue;
189         u32     free_recv_buf_queue_cnt;
190         /* For display the phy informatiom */
191         u8 is_signal_dbg;       /*  for debug */
192         u8 signal_strength_dbg; /*  for debug */
193         s8 rssi;
194         s8 rxpwdb;
195         u8 signal_strength;
196         u8 signal_qual;
197         u8 noise;
198         int RxSNRdB[2];
199         s8 RxRssi[2];
200         int FalseAlmCnt_all;
201
202         struct timer_list signal_stat_timer;
203         u32 signal_stat_sampling_interval;
204         struct signal_stat signal_qual_data;
205         struct signal_stat signal_strength_data;
206 };
207
208 #define rtw_set_signal_stat_timer(recvpriv)                     \
209         _set_timer(&(recvpriv)->signal_stat_timer,              \
210                    (recvpriv)->signal_stat_sampling_interval)
211
212 struct sta_recv_priv {
213         spinlock_t lock;
214         int     option;
215         struct __queue defrag_q; /* keeping the fragment frame until defrag */
216         struct  stainfo_rxcache rxcache;
217 };
218
219 struct recv_buf {
220         struct list_head list;
221         spinlock_t recvbuf_lock;
222         u32     ref_cnt;
223         struct adapter *adapter;
224         u8      *pbuf;
225         u8      *pallocated_buf;
226         u32     len;
227         u8      *phead;
228         u8      *pdata;
229         u8      *ptail;
230         u8      *pend;
231         struct urb *purb;
232         dma_addr_t dma_transfer_addr;   /* (in) dma addr for transfer_buffer */
233         u32 alloc_sz;
234         u8  irp_pending;
235         int  transfer_len;
236         struct sk_buff *pskb;
237         u8      reuse;
238 };
239
240 /*
241         head  ----->
242
243                 data  ----->
244
245                         payload
246
247                 tail  ----->
248
249         end   ----->
250
251         len = (unsigned int )(tail - data);
252
253 */
254 struct recv_frame {
255         struct list_head list;
256         struct sk_buff   *pkt;
257         struct sk_buff   *pkt_newalloc;
258         struct adapter  *adapter;
259         u8 fragcnt;
260         int frame_tag;
261         struct rx_pkt_attrib attrib;
262         uint  len;
263         u8 *rx_head;
264         u8 *rx_data;
265         u8 *rx_tail;
266         u8 *rx_end;
267         void *precvbuf;
268         struct sta_info *psta;
269         /* for A-MPDU Rx reordering buffer control */
270         struct recv_reorder_ctrl *preorder_ctrl;
271 };
272
273 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
274 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
275 void rtw_init_recvframe(struct recv_frame *precvframe,
276                         struct recv_priv *precvpriv);
277 int  rtw_free_recvframe(struct recv_frame *precvframe,
278                         struct __queue *pfree_recv_queue);
279 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
280 int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue);
281 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue);
282 void rtw_free_recvframe_queue(struct __queue *pframequeue,
283                               struct __queue *pfree_recv_queue);
284 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
285 int rtw_enqueue_recvbuf_to_head(struct recv_buf *buf, struct __queue *queue);
286 int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue);
287 struct recv_buf *rtw_dequeue_recvbuf(struct __queue *queue);
288
289 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
290
291 static inline u8 *get_rxmem(struct recv_frame *precvframe)
292 {
293         /* always return rx_head... */
294         if (precvframe == NULL)
295                 return NULL;
296         return precvframe->rx_head;
297 }
298
299 static inline u8 *get_rx_status(struct recv_frame *precvframe)
300 {
301         return get_rxmem(precvframe);
302 }
303
304 static inline u8 *get_recvframe_data(struct recv_frame *precvframe)
305 {
306         /* always return rx_data */
307         if (precvframe == NULL)
308                 return NULL;
309
310         return precvframe->rx_data;
311 }
312
313 static inline u8 *recvframe_push(struct recv_frame *precvframe, int sz)
314 {
315         /*  append data before rx_data */
316
317         /* add data to the start of recv_frame
318  *
319  *      This function extends the used data area of the recv_frame at the buffer
320  *      start. rx_data must be still larger than rx_head, after pushing.
321  */
322         if (precvframe == NULL)
323                 return NULL;
324         precvframe->rx_data -= sz ;
325         if (precvframe->rx_data < precvframe->rx_head) {
326                 precvframe->rx_data += sz;
327                 return NULL;
328         }
329         precvframe->len += sz;
330         return precvframe->rx_data;
331 }
332
333 static inline u8 *recvframe_pull(struct recv_frame *precvframe, int sz)
334 {
335         /*  rx_data += sz; move rx_data sz bytes  hereafter */
336
337         /* used for extract sz bytes from rx_data, update rx_data and return
338          * the updated rx_data to the caller */
339
340         if (precvframe == NULL)
341                 return NULL;
342         precvframe->rx_data += sz;
343         if (precvframe->rx_data > precvframe->rx_tail) {
344                 precvframe->rx_data -= sz;
345                 return NULL;
346         }
347         precvframe->len -= sz;
348         return precvframe->rx_data;
349 }
350
351 static inline u8 *recvframe_put(struct recv_frame *precvframe, int sz)
352 {
353         /* used for append sz bytes from ptr to rx_tail, update rx_tail
354          * and return the updated rx_tail to the caller */
355         /* after putting, rx_tail must be still larger than rx_end. */
356
357         if (precvframe == NULL)
358                 return NULL;
359
360         precvframe->rx_tail += sz;
361
362         if (precvframe->rx_tail > precvframe->rx_end) {
363                 precvframe->rx_tail -= sz;
364                 return NULL;
365         }
366         precvframe->len += sz;
367         return precvframe->rx_tail;
368 }
369
370 static inline u8 *recvframe_pull_tail(struct recv_frame *precvframe, int sz)
371 {
372         /*  rmv data from rx_tail (by yitsen) */
373
374         /* used for extract sz bytes from rx_end, update rx_end and return
375          * the updated rx_end to the caller */
376         /* after pulling, rx_end must be still larger than rx_data. */
377
378         if (precvframe == NULL)
379                 return NULL;
380         precvframe->rx_tail -= sz;
381         if (precvframe->rx_tail < precvframe->rx_data) {
382                 precvframe->rx_tail += sz;
383                 return NULL;
384         }
385         precvframe->len -= sz;
386         return precvframe->rx_tail;
387 }
388
389 static inline unsigned char *get_rxbuf_desc(struct recv_frame *precvframe)
390 {
391         unsigned char *buf_desc;
392
393         if (precvframe == NULL)
394                 return NULL;
395         return buf_desc;
396 }
397
398 static inline struct recv_frame *rxmem_to_recvframe(u8 *rxmem)
399 {
400         /* due to the design of 2048 bytes alignment of recv_frame,
401          * we can reference the struct recv_frame */
402         /* from any given member of recv_frame. */
403         /*  rxmem indicates the any member/address in recv_frame */
404
405         return (struct recv_frame *)(((size_t)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
406 }
407
408 static inline struct recv_frame *pkt_to_recvframe(struct sk_buff *pkt)
409 {
410         u8 *buf_star;
411         struct recv_frame *precv_frame;
412         precv_frame = rxmem_to_recvframe((unsigned char *)buf_star);
413
414         return precv_frame;
415 }
416
417 static inline u8 *pkt_to_recvmem(struct sk_buff *pkt)
418 {
419         /*  return the rx_head */
420
421         struct recv_frame *precv_frame = pkt_to_recvframe(pkt);
422
423         return  precv_frame->rx_head;
424 }
425
426 static inline u8 *pkt_to_recvdata(struct sk_buff *pkt)
427 {
428         /*  return the rx_data */
429
430         struct recv_frame *precv_frame = pkt_to_recvframe(pkt);
431
432         return  precv_frame->rx_data;
433 }
434
435 static inline int get_recvframe_len(struct recv_frame *precvframe)
436 {
437         return precvframe->len;
438 }
439
440 static inline s32 translate_percentage_to_dbm(u32 sig_stren_index)
441 {
442         s32     power; /*  in dBm. */
443
444         /*  Translate to dBm (x=0.5y-95). */
445         power = (s32)((sig_stren_index + 1) >> 1);
446         power -= 95;
447
448         return power;
449 }
450
451 struct sta_info;
452
453 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
454
455 void  mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame);
456
457 #endif