]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/rtl8723bs/include/rtw_recv.h
staging: Add rtl8723bs sdio wifi driver
[karo-tx-linux.git] / drivers / staging / rtl8723bs / 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  ******************************************************************************/
15 #ifndef _RTW_RECV_H_
16 #define _RTW_RECV_H_
17
18         #ifdef CONFIG_SINGLE_RECV_BUF
19                 #define NR_RECVBUFF (1)
20         #else
21                 #define NR_RECVBUFF (8)
22         #endif /* CONFIG_SINGLE_RECV_BUF */
23
24         #define NR_PREALLOC_RECV_SKB (8)
25
26 #define NR_RECVFRAME 256
27
28 #define RXFRAME_ALIGN   8
29 #define RXFRAME_ALIGN_SZ        (1<<RXFRAME_ALIGN)
30
31 #define DRVINFO_SZ      4 /*  unit is 8bytes */
32
33 #define MAX_RXFRAME_CNT 512
34 #define MAX_RX_NUMBLKS          (32)
35 #define RECVFRAME_HDR_ALIGN 128
36
37
38 #define PHY_RSSI_SLID_WIN_MAX                           100
39 #define PHY_LINKQUALITY_SLID_WIN_MAX            20
40
41
42 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
43
44 #define RX_MPDU_QUEUE                           0
45 #define RX_CMD_QUEUE                            1
46 #define RX_MAX_QUEUE                            2
47
48 #define MAX_SUBFRAME_COUNT      64
49 extern u8 rtw_rfc1042_header[];
50 extern u8 rtw_bridge_tunnel_header[];
51
52 /* for Rx reordering buffer control */
53 struct recv_reorder_ctrl
54 {
55         struct adapter  *padapter;
56         u8 enable;
57         u16 indicate_seq;/* wstart_b, init_value = 0xffff */
58         u16 wend_b;
59         u8 wsize_b;
60         struct __queue pending_recvframe_queue;
61         _timer reordering_ctrl_timer;
62 };
63
64 struct  stainfo_rxcache {
65         u16 tid_rxseq[16];
66 /*
67         unsigned short  tid0_rxseq;
68         unsigned short  tid1_rxseq;
69         unsigned short  tid2_rxseq;
70         unsigned short  tid3_rxseq;
71         unsigned short  tid4_rxseq;
72         unsigned short  tid5_rxseq;
73         unsigned short  tid6_rxseq;
74         unsigned short  tid7_rxseq;
75         unsigned short  tid8_rxseq;
76         unsigned short  tid9_rxseq;
77         unsigned short  tid10_rxseq;
78         unsigned short  tid11_rxseq;
79         unsigned short  tid12_rxseq;
80         unsigned short  tid13_rxseq;
81         unsigned short  tid14_rxseq;
82         unsigned short  tid15_rxseq;
83 */
84 };
85
86
87 struct smooth_rssi_data {
88         u32 elements[100];      /* array to store values */
89         u32 index;                      /* index to current array to store */
90         u32 total_num;          /* num of valid elements */
91         u32 total_val;          /* sum of valid elements */
92 };
93
94 struct signal_stat {
95         u8 update_req;          /* used to indicate */
96         u8 avg_val;             /* avg of valid elements */
97         u32 total_num;          /* num of valid elements */
98         u32 total_val;          /* sum of valid elements */
99 };
100
101 struct phy_info {
102         u8 RxPWDBAll;
103
104         u8 SignalQuality;        /*  in 0-100 index. */
105         s8              RxMIMOSignalQuality[4]; /* per-path's EVM */
106         u8 RxMIMOEVMdbm[4];             /* per-path's EVM dbm */
107
108         u8 RxMIMOSignalStrength[4];/*  in 0~100 index */
109
110         u16     Cfo_short[4];                   /*  per-path's Cfo_short */
111         u16     Cfo_tail[4];                    /*  per-path's Cfo_tail */
112
113         s8              RxPower; /*  in dBm Translate from PWdB */
114         s8              RecvSignalPower;/*  Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures. */
115         u8 BTRxRSSIPercentage;
116         u8 SignalStrength; /*  in 0-100 index. */
117
118         s8              RxPwr[4];                               /* per-path's pwdb */
119         u8 RxSNR[4];                            /* per-path's SNR */
120         u8 BandWidth;
121         u8 btCoexPwrAdjust;
122 };
123
124 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
125 struct rx_raw_rssi
126 {
127         u8 data_rate;
128         u8 pwdball;
129         s8 pwr_all;
130
131         u8 mimo_singal_strength[4];/*  in 0~100 index */
132         u8 mimo_singal_quality[4];
133
134         s8 ofdm_pwr[4];
135         u8 ofdm_snr[4];
136
137 };
138 #endif
139
140 struct rx_pkt_attrib    {
141         u16 pkt_len;
142         u8 physt;
143         u8 drvinfo_sz;
144         u8 shift_sz;
145         u8 hdrlen; /* the WLAN Header Len */
146         u8 to_fr_ds;
147         u8 amsdu;
148         u8 qos;
149         u8 priority;
150         u8 pw_save;
151         u8 mdata;
152         u16 seq_num;
153         u8 frag_num;
154         u8 mfrag;
155         u8 order;
156         u8 privacy; /* in frame_ctrl field */
157         u8 bdecrypted;
158         u8 encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */
159         u8 iv_len;
160         u8 icv_len;
161         u8 crc_err;
162         u8 icv_err;
163
164         u16 eth_type;
165
166         u8 dst[ETH_ALEN];
167         u8 src[ETH_ALEN];
168         u8 ta[ETH_ALEN];
169         u8 ra[ETH_ALEN];
170         u8 bssid[ETH_ALEN];
171
172         u8 ack_policy;
173
174 /* ifdef CONFIG_TCP_CSUM_OFFLOAD_RX */
175         u8 tcpchk_valid; /*  0: invalid, 1: valid */
176         u8 ip_chkrpt; /* 0: incorrect, 1: correct */
177         u8 tcp_chkrpt; /* 0: incorrect, 1: correct */
178 /* endif */
179         u8 key_index;
180
181         u8 data_rate;
182         u8 sgi;
183         u8 pkt_rpt_type;
184         u32 MacIDValidEntry[2]; /*  64 bits present 64 entry. */
185
186 /*
187         u8 signal_qual;
188         s8      rx_mimo_signal_qual[2];
189         u8 signal_strength;
190         u32 RxPWDBAll;
191         s32     RecvSignalPower;
192 */
193         struct phy_info phy_info;
194 };
195
196
197 /* These definition is used for Rx packet reordering. */
198 #define SN_LESS(a, b)           (((a-b)&0x800)!= 0)
199 #define SN_EQUAL(a, b)  (a == b)
200 /* define REORDER_WIN_SIZE      128 */
201 /* define REORDER_ENTRY_NUM     128 */
202 #define REORDER_WAIT_TIME       (50) /*  (ms) */
203
204 #define RECVBUFF_ALIGN_SZ 8
205
206 #define RXDESC_SIZE     24
207 #define RXDESC_OFFSET RXDESC_SIZE
208
209 struct recv_stat {
210         __le32 rxdw0;
211         __le32 rxdw1;
212         __le32 rxdw2;
213         __le32 rxdw3;
214 #ifndef BUF_DESC_ARCH
215         __le32 rxdw4;
216         __le32 rxdw5;
217 #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */
218 };
219
220 #define EOR BIT(30)
221
222 /*
223 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
224 ; halt(passive) ;
225
226 using enter_critical section to protect
227 */
228 struct recv_priv {
229         _lock   lock;
230         struct __queue  free_recv_queue;
231         struct __queue  recv_pending_queue;
232         struct __queue  uc_swdec_pending_queue;
233         u8 *pallocated_frame_buf;
234         u8 *precv_frame_buf;
235         uint free_recvframe_cnt;
236         struct adapter  *adapter;
237         u32 bIsAnyNonBEPkts;
238         u64     rx_bytes;
239         u64     rx_pkts;
240         u64     rx_drop;
241         uint  rx_icv_err;
242         uint  rx_largepacket_crcerr;
243         uint  rx_smallpacket_crcerr;
244         uint  rx_middlepacket_crcerr;
245
246         struct tasklet_struct irq_prepare_beacon_tasklet;
247         struct tasklet_struct recv_tasklet;
248         struct sk_buff_head free_recv_skb_queue;
249         struct sk_buff_head rx_skb_queue;
250 #ifdef CONFIG_RX_INDICATE_QUEUE
251         struct task rx_indicate_tasklet;
252         struct ifqueue rx_indicate_queue;
253 #endif  /*  CONFIG_RX_INDICATE_QUEUE */
254
255         u8 *pallocated_recv_buf;
256         u8 *precv_buf;    /*  4 alignment */
257         struct __queue  free_recv_buf_queue;
258         u32 free_recv_buf_queue_cnt;
259
260         struct __queue  recv_buf_pending_queue;
261
262         /* For display the phy informatiom */
263         u8 is_signal_dbg;       /*  for debug */
264         u8 signal_strength_dbg; /*  for debug */
265
266         u8 signal_strength;
267         u8 signal_qual;
268         s8 rssi;        /* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
269         #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
270         struct rx_raw_rssi raw_rssi_info;
271         #endif
272         /* s8 rxpwdb; */
273         s16 noise;
274         /* int RxSNRdB[2]; */
275         /* s8 RxRssi[2]; */
276         /* int FalseAlmCnt_all; */
277
278
279         _timer signal_stat_timer;
280         u32 signal_stat_sampling_interval;
281         /* u32 signal_stat_converging_constant; */
282         struct signal_stat signal_qual_data;
283         struct signal_stat signal_strength_data;
284 };
285
286 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
287
288 struct sta_recv_priv {
289
290         _lock   lock;
291         sint    option;
292
293         /* struct __queue       blk_strms[MAX_RX_NUMBLKS]; */
294         struct __queue defrag_q;         /* keeping the fragment frame until defrag */
295
296         struct  stainfo_rxcache rxcache;
297
298         /* uint sta_rx_bytes; */
299         /* uint sta_rx_pkts; */
300         /* uint sta_rx_fail; */
301
302 };
303
304
305 struct recv_buf
306 {
307         struct list_head list;
308
309         _lock recvbuf_lock;
310
311         u32 ref_cnt;
312
313         struct adapter * adapter;
314
315         u8 *pbuf;
316         u8 *pallocated_buf;
317
318         u32 len;
319         u8 *phead;
320         u8 *pdata;
321         u8 *ptail;
322         u8 *pend;
323
324         _pkt    *pskb;
325         u8 reuse;
326 };
327
328
329 /*
330         head  ----->
331
332                 data  ----->
333
334                         payload
335
336                 tail  ----->
337
338
339         end   ----->
340
341         len = (unsigned int)(tail - data);
342
343 */
344 struct recv_frame_hdr
345 {
346         struct list_head        list;
347 #ifndef CONFIG_BSD_RX_USE_MBUF
348         struct sk_buff   *pkt;
349         struct sk_buff   *pkt_newalloc;
350 #else /*  CONFIG_BSD_RX_USE_MBUF */
351         _pkt    *pkt;
352         _pkt *pkt_newalloc;
353 #endif /*  CONFIG_BSD_RX_USE_MBUF */
354
355         struct adapter  *adapter;
356
357         u8 fragcnt;
358
359         int frame_tag;
360
361         struct rx_pkt_attrib attrib;
362
363         uint  len;
364         u8 *rx_head;
365         u8 *rx_data;
366         u8 *rx_tail;
367         u8 *rx_end;
368
369         void *precvbuf;
370
371
372         /*  */
373         struct sta_info *psta;
374
375         /* for A-MPDU Rx reordering buffer control */
376         struct recv_reorder_ctrl *preorder_ctrl;
377 };
378
379
380 union recv_frame{
381         union{
382                 struct list_head list;
383                 struct recv_frame_hdr hdr;
384                 uint mem[RECVFRAME_HDR_ALIGN>>2];
385         }u;
386
387         /* uint mem[MAX_RXSZ>>2]; */
388
389 };
390
391 enum RX_PACKET_TYPE {
392         NORMAL_RX,/* Normal rx packet */
393         TX_REPORT1,/* CCX */
394         TX_REPORT2,/* TX RPT */
395         HIS_REPORT,/*  USB HISR RPT */
396         C2H_PACKET
397 };
398
399 extern union recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue);  /* get a free recv_frame from pfree_recv_queue */
400 extern union recv_frame *rtw_alloc_recvframe (struct __queue *pfree_recv_queue);  /* get a free recv_frame from pfree_recv_queue */
401 extern int       rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue);
402
403 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
404 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue);
405 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue);
406
407 extern void rtw_free_recvframe_queue(struct __queue *pframequeue,  struct __queue *pfree_recv_queue);
408 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
409
410 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue);
411 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue);
412 struct recv_buf *rtw_dequeue_recvbuf (struct __queue *queue);
413
414 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
415
416 __inline static u8 *get_rxmem(union recv_frame *precvframe)
417 {
418         /* always return rx_head... */
419         if (precvframe == NULL)
420                 return NULL;
421
422         return precvframe->u.hdr.rx_head;
423 }
424
425 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
426 {
427
428         /* alwasy return rx_data */
429         if (precvframe == NULL)
430                 return NULL;
431
432         return precvframe->u.hdr.rx_data;
433
434 }
435
436 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
437 {
438         /*  rx_data += sz; move rx_data sz bytes  hereafter */
439
440         /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
441
442
443         if (precvframe == NULL)
444                 return NULL;
445
446
447         precvframe->u.hdr.rx_data += sz;
448
449         if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail)
450         {
451                 precvframe->u.hdr.rx_data -= sz;
452                 return NULL;
453         }
454
455         precvframe->u.hdr.len -=sz;
456
457         return precvframe->u.hdr.rx_data;
458
459 }
460
461 __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
462 {
463         /*  rx_tai += sz; move rx_tail sz bytes  hereafter */
464
465         /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
466         /* after putting, rx_tail must be still larger than rx_end. */
467         unsigned char * prev_rx_tail;
468
469         if (precvframe == NULL)
470                 return NULL;
471
472         prev_rx_tail = precvframe->u.hdr.rx_tail;
473
474         precvframe->u.hdr.rx_tail += sz;
475
476         if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end)
477         {
478                 precvframe->u.hdr.rx_tail = prev_rx_tail;
479                 return NULL;
480         }
481
482         precvframe->u.hdr.len +=sz;
483
484         return precvframe->u.hdr.rx_tail;
485
486 }
487
488
489
490 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
491 {
492         /*  rmv data from rx_tail (by yitsen) */
493
494         /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
495         /* after pulling, rx_end must be still larger than rx_data. */
496
497         if (precvframe == NULL)
498                 return NULL;
499
500         precvframe->u.hdr.rx_tail -= sz;
501
502         if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data)
503         {
504                 precvframe->u.hdr.rx_tail += sz;
505                 return NULL;
506         }
507
508         precvframe->u.hdr.len -=sz;
509
510         return precvframe->u.hdr.rx_tail;
511
512 }
513
514 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
515 {
516         /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
517         /* from any given member of recv_frame. */
518         /*  rxmem indicates the any member/address in recv_frame */
519
520         return (union recv_frame*)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
521
522 }
523
524 __inline static sint get_recvframe_len(union recv_frame *precvframe)
525 {
526         return precvframe->u.hdr.len;
527 }
528
529
530 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
531 {
532         s32     SignalPower; /*  in dBm. */
533
534 #ifdef CONFIG_SKIP_SIGNAL_SCALE_MAPPING
535         /*  Translate to dBm (x =y-100) */
536         SignalPower = SignalStrengthIndex - 100;
537 #else
538         /*  Translate to dBm (x = 0.5y-95). */
539         SignalPower = (s32)((SignalStrengthIndex + 1) >> 1);
540         SignalPower -= 95;
541 #endif
542
543         return SignalPower;
544 }
545
546
547 struct sta_info;
548
549 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
550
551 extern void  mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame);
552
553 #endif