OSDN Git Service

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