Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / rtl8188eu / include / rtw_recv.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef _RTW_RECV_H_
21 #define _RTW_RECV_H_
22
23 #include <osdep_service.h>
24 #include <drv_types.h>
25
26
27 #define NR_RECVFRAME 256
28
29 #define RXFRAME_ALIGN   8
30 #define RXFRAME_ALIGN_SZ        (1<<RXFRAME_ALIGN)
31
32 #define MAX_RXFRAME_CNT 512
33 #define MAX_RX_NUMBLKS          (32)
34 #define RECVFRAME_HDR_ALIGN 128
35
36 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
37
38 #define MAX_SUBFRAME_COUNT      64
39
40 /* for Rx reordering buffer control */
41 struct recv_reorder_ctrl {
42         struct adapter  *padapter;
43         u8 enable;
44         u16 indicate_seq;/* wstart_b, init_value=0xffff */
45         u16 wend_b;
46         u8 wsize_b;
47         struct __queue pending_recvframe_queue;
48         struct timer_list reordering_ctrl_timer;
49 };
50
51 struct  stainfo_rxcache {
52         u16     tid_rxseq[16];
53 /*
54         unsigned short  tid0_rxseq;
55         unsigned short  tid1_rxseq;
56         unsigned short  tid2_rxseq;
57         unsigned short  tid3_rxseq;
58         unsigned short  tid4_rxseq;
59         unsigned short  tid5_rxseq;
60         unsigned short  tid6_rxseq;
61         unsigned short  tid7_rxseq;
62         unsigned short  tid8_rxseq;
63         unsigned short  tid9_rxseq;
64         unsigned short  tid10_rxseq;
65         unsigned short  tid11_rxseq;
66         unsigned short  tid12_rxseq;
67         unsigned short  tid13_rxseq;
68         unsigned short  tid14_rxseq;
69         unsigned short  tid15_rxseq;
70 */
71 };
72
73 struct smooth_rssi_data {
74         u32     elements[100];  /* array to store values */
75         u32     index;                  /* index to current array to store */
76         u32     total_num;              /* num of valid elements */
77         u32     total_val;              /* sum of valid elements */
78 };
79
80 struct signal_stat {
81         u8      update_req;             /* used to indicate */
82         u8      avg_val;                /* avg of valid elements */
83         u32     total_num;              /* num of valid elements */
84         u32     total_val;              /* sum of valid elements */
85 };
86 #define MAX_PATH_NUM_92CS               3
87 struct phy_info {
88         u8      RxPWDBAll;
89         u8      SignalQuality;   /*  in 0-100 index. */
90         u8      RxMIMOSignalQuality[MAX_PATH_NUM_92CS]; /* EVM */
91         u8      RxMIMOSignalStrength[MAX_PATH_NUM_92CS];/*  in 0~100 index */
92         s8      RxPower; /*  in dBm Translate from PWdB */
93 /*  Real power in dBm for this packet, no beautification and aggregation.
94  * Keep this raw info to be used for the other procedures. */
95         s8      recvpower;
96         u8      BTRxRSSIPercentage;
97         u8      SignalStrength; /*  in 0-100 index. */
98         u8      RxPwr[MAX_PATH_NUM_92CS];/* per-path's pwdb */
99         u8      RxSNR[MAX_PATH_NUM_92CS];/* per-path's SNR */
100 };
101
102 struct rx_pkt_attrib {
103         u16     pkt_len;
104         u8      physt;
105         u8      drvinfo_sz;
106         u8      shift_sz;
107         u8      hdrlen; /* the WLAN Header Len */
108         u8      to_fr_ds;
109         u8      amsdu;
110         u8      qos;
111         u8      priority;
112         u8      pw_save;
113         u8      mdata;
114         u16     seq_num;
115         u8      frag_num;
116         u8      mfrag;
117         u8      order;
118         u8      privacy; /* in frame_ctrl field */
119         u8      bdecrypted;
120         u8      encrypt; /* when 0 indicate no encrypt. when non-zero,
121                           * indicate the encrypt algorith */
122         u8      iv_len;
123         u8      icv_len;
124         u8      crc_err;
125         u8      icv_err;
126
127         u16 eth_type;
128
129         u8      dst[ETH_ALEN];
130         u8      src[ETH_ALEN];
131         u8      ta[ETH_ALEN];
132         u8      ra[ETH_ALEN];
133         u8      bssid[ETH_ALEN];
134
135         u8 ack_policy;
136
137         u8      key_index;
138
139         u8      mcs_rate;
140         u8      rxht;
141         u8      sgi;
142         u8      pkt_rpt_type;
143         u32     MacIDValidEntry[2];     /*  64 bits present 64 entry. */
144
145         struct phy_info phy_info;
146 };
147
148
149 /* These definition is used for Rx packet reordering. */
150 #define SN_LESS(a, b)           (((a - b) & 0x800) != 0)
151 #define SN_EQUAL(a, b)  (a == b)
152 #define REORDER_WAIT_TIME       (50) /*  (ms) */
153
154 #define RECVBUFF_ALIGN_SZ 8
155
156 #define RXDESC_SIZE     24
157 #define RXDESC_OFFSET RXDESC_SIZE
158
159 struct recv_stat {
160         __le32 rxdw0;
161         __le32 rxdw1;
162         __le32 rxdw2;
163         __le32 rxdw3;
164         __le32 rxdw4;
165         __le32 rxdw5;
166 };
167
168 #define EOR BIT(30)
169
170 /*
171 accesser of recv_priv: rtw_recv_entry(dispatch / passive level);
172 recv_thread(passive) ; returnpkt(dispatch)
173 ; halt(passive) ;
174
175 using enter_critical section to protect
176 */
177 struct recv_priv {
178         struct __queue free_recv_queue;
179         struct __queue recv_pending_queue;
180         struct __queue uc_swdec_pending_queue;
181         u8 *pallocated_frame_buf;
182         u8 *precv_frame_buf;
183         uint free_recvframe_cnt;
184         struct adapter  *adapter;
185         u32     bIsAnyNonBEPkts;
186         u64     rx_bytes;
187         u64     rx_pkts;
188         u64     rx_drop;
189         u64     last_rx_bytes;
190
191         uint    ff_hwaddr;
192         u8      rx_pending_cnt;
193
194         struct tasklet_struct irq_prepare_beacon_tasklet;
195         struct tasklet_struct recv_tasklet;
196         struct sk_buff_head free_recv_skb_queue;
197         struct sk_buff_head rx_skb_queue;
198         u8 *pallocated_recv_buf;
199         u8 *precv_buf;    /*  4 alignment */
200         struct __queue free_recv_buf_queue;
201         u32     free_recv_buf_queue_cnt;
202         /* For display the phy informatiom */
203         u8 is_signal_dbg;       /*  for debug */
204         u8 signal_strength_dbg; /*  for debug */
205         s8 rssi;
206         s8 rxpwdb;
207         u8 signal_strength;
208         u8 signal_qual;
209         u8 noise;
210         s8 RxRssi[2];
211
212         struct timer_list signal_stat_timer;
213         u32 signal_stat_sampling_interval;
214         struct signal_stat signal_qual_data;
215         struct signal_stat signal_strength_data;
216 };
217
218 #define rtw_set_signal_stat_timer(recvpriv)                     \
219         mod_timer(&(recvpriv)->signal_stat_timer, jiffies +     \
220                   msecs_to_jiffies((recvpriv)->signal_stat_sampling_interval))
221
222 struct sta_recv_priv {
223         spinlock_t lock;
224         int     option;
225         struct __queue defrag_q; /* keeping the fragment frame until defrag */
226         struct  stainfo_rxcache rxcache;
227 };
228
229 struct recv_buf {
230         struct adapter *adapter;
231         struct urb *purb;
232         struct sk_buff *pskb;
233         u8      reuse;
234 };
235
236 /*
237         head  ----->
238
239                 data  ----->
240
241                         payload
242
243                 tail  ----->
244
245
246         end   ----->
247
248         len = (unsigned int )(tail - data);
249
250 */
251 struct recv_frame {
252         struct list_head list;
253         struct sk_buff   *pkt;
254         struct sk_buff   *pkt_newalloc;
255         struct adapter  *adapter;
256         struct rx_pkt_attrib attrib;
257         uint  len;
258         u8 *rx_head;
259         u8 *rx_data;
260         u8 *rx_tail;
261         u8 *rx_end;
262         struct sta_info *psta;
263         /* for A-MPDU Rx reordering buffer control */
264         struct recv_reorder_ctrl *preorder_ctrl;
265 };
266
267 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
268 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
269 void rtw_init_recvframe(struct recv_frame *precvframe,
270                         struct recv_priv *precvpriv);
271 int  rtw_free_recvframe(struct recv_frame *precvframe,
272                         struct __queue *pfree_recv_queue);
273 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
274 int _rtw_enqueue_recvframe(struct recv_frame *precvframe,
275                            struct __queue *queue);
276 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue);
277 void rtw_free_recvframe_queue(struct __queue *pframequeue,
278                               struct __queue *pfree_recv_queue);
279 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
280
281 void rtw_reordering_ctrl_timeout_handler(unsigned long data);
282
283 static inline u8 *get_rxmem(struct recv_frame *precvframe)
284 {
285         /* always return rx_head... */
286         if (precvframe == NULL)
287                 return NULL;
288         return precvframe->rx_head;
289 }
290
291 static inline u8 *recvframe_pull(struct recv_frame *precvframe, int sz)
292 {
293         /*  rx_data += sz; move rx_data sz bytes  hereafter */
294
295         /* used for extract sz bytes from rx_data, update rx_data and return
296          * the updated rx_data to the caller */
297
298         if (precvframe == NULL)
299                 return NULL;
300         precvframe->rx_data += sz;
301         if (precvframe->rx_data > precvframe->rx_tail) {
302                 precvframe->rx_data -= sz;
303                 return NULL;
304         }
305         precvframe->len -= sz;
306         return precvframe->rx_data;
307 }
308
309 static inline u8 *recvframe_put(struct recv_frame *precvframe, int sz)
310 {
311         /* used for append sz bytes from ptr to rx_tail, update rx_tail
312          * and return the updated rx_tail to the caller */
313         /* after putting, rx_tail must be still larger than rx_end. */
314
315         if (precvframe == NULL)
316                 return NULL;
317
318         precvframe->rx_tail += sz;
319
320         if (precvframe->rx_tail > precvframe->rx_end) {
321                 precvframe->rx_tail -= sz;
322                 return NULL;
323         }
324         precvframe->len += sz;
325         return precvframe->rx_tail;
326 }
327
328 static inline u8 *recvframe_pull_tail(struct recv_frame *precvframe, int sz)
329 {
330         /*  rmv data from rx_tail (by yitsen) */
331
332         /* used for extract sz bytes from rx_end, update rx_end and return
333          * the updated rx_end to the caller */
334         /* after pulling, rx_end must be still larger than rx_data. */
335
336         if (precvframe == NULL)
337                 return NULL;
338         precvframe->rx_tail -= sz;
339         if (precvframe->rx_tail < precvframe->rx_data) {
340                 precvframe->rx_tail += sz;
341                 return NULL;
342         }
343         precvframe->len -= sz;
344         return precvframe->rx_tail;
345 }
346
347 static inline s32 translate_percentage_to_dbm(u32 sig_stren_index)
348 {
349         s32     power; /*  in dBm. */
350
351         /*  Translate to dBm (x=0.5y-95). */
352         power = (s32)((sig_stren_index + 1) >> 1);
353         power -= 95;
354
355         return power;
356 }
357
358
359 struct sta_info;
360
361 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
362
363 void  mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame);
364
365 #endif