rtl8188eu: update driver to v4.3.0.8_13968.20150417
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / 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 #ifdef PLATFORM_OS_XP
24         #ifdef CONFIG_SDIO_HCI
25                 #define NR_RECVBUFF 1024//512//128
26         #else
27                 #define NR_RECVBUFF (16)
28         #endif
29 #elif defined(PLATFORM_OS_CE)
30         #ifdef CONFIG_SDIO_HCI
31                 #define NR_RECVBUFF (128)
32         #else
33                 #define NR_RECVBUFF (4)
34         #endif
35 #else //PLATFORM_LINUX /PLATFORM_BSD
36
37         #ifdef CONFIG_SINGLE_RECV_BUF
38                 #define NR_RECVBUFF (1)
39         #else
40                 #if defined(CONFIG_GSPI_HCI)
41                         #define NR_RECVBUFF (32)
42                 #elif defined(CONFIG_SDIO_HCI)
43                         #define NR_RECVBUFF (8) 
44                 #else
45                         #define NR_RECVBUFF (8)
46                 #endif  
47         #endif //CONFIG_SINGLE_RECV_BUF
48
49         #define NR_PREALLOC_RECV_SKB (8)        
50 #endif
51
52 #define NR_RECVFRAME 256
53
54 #define RXFRAME_ALIGN   8
55 #define RXFRAME_ALIGN_SZ        (1<<RXFRAME_ALIGN)
56
57 #define DRVINFO_SZ      4 // unit is 8bytes
58
59 #define MAX_RXFRAME_CNT 512
60 #define MAX_RX_NUMBLKS          (32)
61 #define RECVFRAME_HDR_ALIGN 128
62
63
64 #define PHY_RSSI_SLID_WIN_MAX                           100
65 #define PHY_LINKQUALITY_SLID_WIN_MAX            20
66
67
68 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
69
70 #define RX_MPDU_QUEUE                           0
71 #define RX_CMD_QUEUE                            1
72 #define RX_MAX_QUEUE                            2
73
74 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
75
76 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
77 static u8 SNAP_ETH_TYPE_APPLETALK_DDP[2] = {0x80, 0x9b};
78 static u8 SNAP_ETH_TYPE_TDLS[2] = {0x89, 0x0d};
79 static u8 SNAP_HDR_APPLETALK_DDP[3] = {0x08, 0x00, 0x07}; // Datagram Delivery Protocol
80
81 static u8 oui_8021h[] = {0x00, 0x00, 0xf8};
82 static u8 oui_rfc1042[]= {0x00,0x00,0x00};
83
84 #define MAX_SUBFRAME_COUNT      64
85 static u8 rtw_rfc1042_header[] =
86 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
87 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
88 static u8 rtw_bridge_tunnel_header[] =
89 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
90
91 //for Rx reordering buffer control
92 struct recv_reorder_ctrl
93 {
94         _adapter        *padapter;
95         u8 enable;
96         u16 indicate_seq;//=wstart_b, init_value=0xffff
97         u16 wend_b;
98         u8 wsize_b;
99         _queue pending_recvframe_queue;
100         _timer reordering_ctrl_timer;
101 };
102
103 struct  stainfo_rxcache {
104         u16     tid_rxseq[16];
105 /*
106         unsigned short  tid0_rxseq;
107         unsigned short  tid1_rxseq;
108         unsigned short  tid2_rxseq;
109         unsigned short  tid3_rxseq;
110         unsigned short  tid4_rxseq;
111         unsigned short  tid5_rxseq;
112         unsigned short  tid6_rxseq;
113         unsigned short  tid7_rxseq;
114         unsigned short  tid8_rxseq;
115         unsigned short  tid9_rxseq;
116         unsigned short  tid10_rxseq;
117         unsigned short  tid11_rxseq;
118         unsigned short  tid12_rxseq;
119         unsigned short  tid13_rxseq;
120         unsigned short  tid14_rxseq;
121         unsigned short  tid15_rxseq;
122 */
123 };
124
125
126 struct smooth_rssi_data {
127         u32     elements[100];  //array to store values
128         u32     index;                  //index to current array to store
129         u32     total_num;              //num of valid elements
130         u32     total_val;              //sum of valid elements
131 };
132
133 struct signal_stat {
134         u8      update_req;             //used to indicate 
135         u8      avg_val;                //avg of valid elements
136         u32     total_num;              //num of valid elements
137         u32     total_val;              //sum of valid elements 
138 };
139 /*
140 typedef struct _ODM_Phy_Status_Info_
141 {
142         //
143         // Be care, if you want to add any element please insert between 
144         // RxPWDBAll & SignalStrength.
145         //
146 #if (DM_ODM_SUPPORT_TYPE &  (ODM_WIN))
147         u4Byte          RxPWDBAll;      
148 #else
149         u1Byte          RxPWDBAll;      
150 #endif
151
152         u1Byte          SignalQuality;                  // in 0-100 index. 
153         s1Byte          RxMIMOSignalQuality[4]; //per-path's EVM
154         u1Byte          RxMIMOEVMdbm[4];                //per-path's EVM dbm
155
156         u1Byte          RxMIMOSignalStrength[4];// in 0~100 index
157
158         u2Byte          Cfo_short[4];                   // per-path's Cfo_short
159         u2Byte          Cfo_tail[4];                    // per-path's Cfo_tail
160         
161 #if (DM_ODM_SUPPORT_TYPE &  (ODM_WIN|ODM_CE))
162         s1Byte          RxPower;                                // in dBm Translate from PWdB
163         s1Byte          RecvSignalPower;                // Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures.
164         u1Byte          BTRxRSSIPercentage;     
165         u1Byte          SignalStrength;                 // in 0-100 index.
166  
167         u1Byte          RxPwr[4];                               //per-path's pwdb
168 #endif
169         u1Byte          RxSNR[4];                               //per-path's SNR        
170         u1Byte          BandWidth;
171         u1Byte          btCoexPwrAdjust;
172 }ODM_PHY_INFO_T,*PODM_PHY_INFO_T;
173 */
174
175 struct phy_info
176 {               
177         u8              RxPWDBAll;
178
179         u8              SignalQuality;   // in 0-100 index. 
180         s8              RxMIMOSignalQuality[4]; //per-path's EVM
181         u8              RxMIMOEVMdbm[4];                //per-path's EVM dbm
182
183         u8              RxMIMOSignalStrength[4];// in 0~100 index
184
185         u16             Cfo_short[4];                   // per-path's Cfo_short
186         u16             Cfo_tail[4];                    // per-path's Cfo_tail
187
188         s8              RxPower; // in dBm Translate from PWdB
189         s8              RecvSignalPower;// Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures.
190         u8              BTRxRSSIPercentage;     
191         u8              SignalStrength; // in 0-100 index.
192
193         s8              RxPwr[4];                               //per-path's pwdb
194         u8              RxSNR[4];                               //per-path's SNR        
195         u8              BandWidth;
196         u8              btCoexPwrAdjust;
197 };
198
199 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
200 struct rx_raw_rssi
201 {
202         u8 data_rate;
203         u8 pwdball;
204         s8 pwr_all;
205         
206         u8 mimo_singal_strength[4];// in 0~100 index
207         u8 mimo_singal_quality[4];
208         
209         s8 ofdm_pwr[4];
210         u8 ofdm_snr[4];
211
212 };
213 #endif
214
215 struct rx_pkt_attrib    {
216         u16     pkt_len;
217         u8      physt;
218         u8      drvinfo_sz;
219         u8      shift_sz;
220         u8      hdrlen; //the WLAN Header Len
221         u8      to_fr_ds;
222         u8      amsdu;
223         u8      qos;
224         u8      priority;
225         u8      pw_save;
226         u8      mdata;
227         u16     seq_num;
228         u8      frag_num;
229         u8      mfrag;
230         u8      order;
231         u8      privacy; //in frame_ctrl field
232         u8      bdecrypted;
233         u8      encrypt; //when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith
234         u8      iv_len;
235         u8      icv_len;
236         u8      crc_err;
237         u8      icv_err;
238
239         u16     eth_type;
240
241         u8      dst[ETH_ALEN];
242         u8      src[ETH_ALEN];
243         u8      ta[ETH_ALEN];
244         u8      ra[ETH_ALEN];
245         u8      bssid[ETH_ALEN];
246         
247         u8      ack_policy;
248         
249 //#ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
250         u8      tcpchk_valid; // 0: invalid, 1: valid
251         u8      ip_chkrpt; //0: incorrect, 1: correct
252         u8      tcp_chkrpt; //0: incorrect, 1: correct
253 //#endif
254         u8      key_index;
255
256         u8      data_rate;
257         u8      bw;
258         u8      stbc;
259         u8      ldpc;
260         u8      sgi;
261         u8      pkt_rpt_type;
262         u32 tsfl;
263         u32     MacIDValidEntry[2];     // 64 bits present 64 entry.
264
265 /*
266         u8      signal_qual;
267         s8      rx_mimo_signal_qual[2];
268         u8      signal_strength;
269         u32     RxPWDBAll;      
270         s32     RecvSignalPower;
271 */
272         struct phy_info phy_info;
273 };
274
275
276 //These definition is used for Rx packet reordering.
277 #define SN_LESS(a, b)           (((a-b)&0x800)!=0)
278 #define SN_EQUAL(a, b)  (a == b)
279 //#define REORDER_WIN_SIZE      128
280 //#define REORDER_ENTRY_NUM     128
281 #define REORDER_WAIT_TIME       (50) // (ms)
282
283 #define RECVBUFF_ALIGN_SZ 8
284
285 #define RXDESC_SIZE     24
286 #define RXDESC_OFFSET RXDESC_SIZE
287
288 struct recv_stat
289 {
290         unsigned int rxdw0;
291
292         unsigned int rxdw1;
293
294         unsigned int rxdw2;
295
296         unsigned int rxdw3;
297
298         unsigned int rxdw4;
299
300         unsigned int rxdw5;
301
302 #ifdef CONFIG_PCI_HCI
303         unsigned int rxdw6;
304
305         unsigned int rxdw7;
306 #endif
307 };
308
309 #define EOR BIT(30)
310
311 #ifdef CONFIG_PCI_HCI
312 #define PCI_MAX_RX_QUEUE                1// MSDU packet queue, Rx Command Queue
313 #define PCI_MAX_RX_COUNT                128
314
315 struct rtw_rx_ring {
316         struct recv_stat        *desc;
317         dma_addr_t              dma;
318         unsigned int            idx;
319         struct sk_buff  *rx_buf[PCI_MAX_RX_COUNT];
320 };
321 #endif
322
323
324
325 /*
326 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
327 ; halt(passive) ;
328
329 using enter_critical section to protect
330 */
331 struct recv_priv
332 {
333         _lock   lock;
334
335 #ifdef CONFIG_RECV_THREAD_MODE
336         _sema   recv_sema;
337         _sema   terminate_recvthread_sema;
338 #endif
339
340         //_queue        blk_strms[MAX_RX_NUMBLKS];    // keeping the block ack frame until return ack
341         _queue  free_recv_queue;
342         _queue  recv_pending_queue;
343         _queue  uc_swdec_pending_queue;
344
345
346         u8 *pallocated_frame_buf;
347         u8 *precv_frame_buf;
348
349         uint free_recvframe_cnt;
350
351         _adapter        *adapter;
352
353 #ifdef PLATFORM_WINDOWS
354         _nic_hdl  RxPktPoolHdl;
355         _nic_hdl  RxBufPoolHdl;
356
357 #ifdef PLATFORM_OS_XP
358         PMDL    pbytecnt_mdl;
359 #endif
360         uint    counter; //record the number that up-layer will return to drv; only when counter==0 can we  release recv_priv
361         NDIS_EVENT      recv_resource_evt ;
362 #endif
363
364         u32     bIsAnyNonBEPkts;
365         u64     rx_bytes;
366         u64     rx_pkts;
367         u64     rx_drop;
368
369         uint  rx_icv_err;
370         uint  rx_largepacket_crcerr;
371         uint  rx_smallpacket_crcerr;
372         uint  rx_middlepacket_crcerr;
373
374 #ifdef CONFIG_USB_HCI
375         //u8 *pallocated_urb_buf;
376         _sema allrxreturnevt;
377         uint    ff_hwaddr;
378         u8      rx_pending_cnt;
379
380 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
381 #ifdef PLATFORM_LINUX
382         PURB    int_in_urb;
383 #endif
384
385         u8      *int_in_buf;
386 #endif //CONFIG_USB_INTERRUPT_IN_PIPE
387
388 #endif
389 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
390 #ifdef PLATFORM_FREEBSD
391         struct task irq_prepare_beacon_tasklet;
392         struct task recv_tasklet;
393 #else //PLATFORM_FREEBSD
394         struct tasklet_struct irq_prepare_beacon_tasklet;
395         struct tasklet_struct recv_tasklet;
396 #endif //PLATFORM_FREEBSD
397         struct sk_buff_head free_recv_skb_queue;
398         struct sk_buff_head rx_skb_queue;
399 #ifdef CONFIG_RX_INDICATE_QUEUE
400         struct task rx_indicate_tasklet;
401         struct ifqueue rx_indicate_queue;
402 #endif  // CONFIG_RX_INDICATE_QUEUE
403
404 #endif //defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
405
406         u8 *pallocated_recv_buf;
407         u8 *precv_buf;    // 4 alignment
408         _queue  free_recv_buf_queue;
409         u32     free_recv_buf_queue_cnt;
410
411 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) || defined(CONFIG_USB_HCI) 
412         _queue  recv_buf_pending_queue;
413 #endif
414
415 #ifdef CONFIG_PCI_HCI
416         // Rx
417         struct rtw_rx_ring      rx_ring[PCI_MAX_RX_QUEUE];
418         int     rxringcount;
419         u16     rxbuffersize;
420 #endif
421
422         //For display the phy informatiom
423         u8 is_signal_dbg;       // for debug
424         u8 signal_strength_dbg; // for debug
425         
426         u8 signal_strength;
427         u8 signal_qual;
428         s8 rssi;        //translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength);
429         #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
430         struct rx_raw_rssi raw_rssi_info;
431         #endif
432         //s8 rxpwdb;    
433         u8 noise;       
434         //int RxSNRdB[2];
435         //s8 RxRssi[2];
436         //int FalseAlmCnt_all;
437         
438
439 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
440         _timer signal_stat_timer;
441         u32 signal_stat_sampling_interval;
442         //u32 signal_stat_converging_constant;
443         struct signal_stat signal_qual_data;
444         struct signal_stat signal_strength_data;
445 #else //CONFIG_NEW_SIGNAL_STAT_PROCESS
446         struct smooth_rssi_data signal_qual_data;
447         struct smooth_rssi_data signal_strength_data;
448 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
449
450 };
451
452 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
453 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
454 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
455
456 struct sta_recv_priv {
457
458         _lock   lock;
459         sint    option;
460
461         //_queue        blk_strms[MAX_RX_NUMBLKS];
462         _queue defrag_q;         //keeping the fragment frame until defrag
463
464         struct  stainfo_rxcache rxcache;
465
466         //uint  sta_rx_bytes;
467         //uint  sta_rx_pkts;
468         //uint  sta_rx_fail;
469
470 };
471
472
473 struct recv_buf
474 {
475         _list list;
476
477         _lock recvbuf_lock;
478
479         u32     ref_cnt;
480
481         PADAPTER adapter;
482
483         u8      *pbuf;
484         u8      *pallocated_buf;
485
486         u32     len;
487         u8      *phead;
488         u8      *pdata;
489         u8      *ptail;
490         u8      *pend;
491
492 #ifdef CONFIG_USB_HCI
493
494         #if defined(PLATFORM_OS_XP)||defined(PLATFORM_LINUX)||defined(PLATFORM_FREEBSD)
495         PURB    purb;
496         dma_addr_t dma_transfer_addr;   /* (in) dma addr for transfer_buffer */
497         u32 alloc_sz;
498         #endif
499
500         #ifdef PLATFORM_OS_XP
501         PIRP            pirp;
502         #endif
503
504         #ifdef PLATFORM_OS_CE
505         USB_TRANSFER    usb_transfer_read_port;
506         #endif
507
508         u8  irp_pending;
509         int  transfer_len;
510
511 #endif
512
513 #ifdef PLATFORM_LINUX
514         _pkt    *pskb;
515         u8      reuse;
516 #endif
517 #ifdef PLATFORM_FREEBSD //skb solution
518         struct sk_buff *pskb;
519         u8      reuse;
520 #endif //PLATFORM_FREEBSD //skb solution
521 };
522
523
524 /*
525         head  ----->
526
527                 data  ----->
528
529                         payload
530
531                 tail  ----->
532
533
534         end   ----->
535
536         len = (unsigned int )(tail - data);
537
538 */
539 struct recv_frame_hdr
540 {
541         _list   list;
542 #ifndef CONFIG_BSD_RX_USE_MBUF
543         struct sk_buff   *pkt;
544         struct sk_buff   *pkt_newalloc;
545 #else // CONFIG_BSD_RX_USE_MBUF
546         _pkt    *pkt;
547         _pkt *pkt_newalloc;
548 #endif // CONFIG_BSD_RX_USE_MBUF
549
550         _adapter  *adapter;
551
552         u8 fragcnt;
553
554         int frame_tag;
555
556         struct rx_pkt_attrib attrib;
557
558         uint  len;
559         u8 *rx_head;
560         u8 *rx_data;
561         u8 *rx_tail;
562         u8 *rx_end;
563
564         void *precvbuf;
565
566
567         //
568         struct sta_info *psta;
569
570         //for A-MPDU Rx reordering buffer control
571         struct recv_reorder_ctrl *preorder_ctrl;
572
573 #ifdef CONFIG_WAPI_SUPPORT
574         u8 UserPriority;
575         u8 WapiTempPN[16];
576         u8 WapiSrcAddr[6];
577         u8 bWapiCheckPNInDecrypt;
578         u8 bIsWaiPacket;
579 #endif
580
581 };
582
583
584 union recv_frame{
585
586         union{
587                 _list list;
588                 struct recv_frame_hdr hdr;
589                 uint mem[RECVFRAME_HDR_ALIGN>>2];
590         }u;
591
592         //uint mem[MAX_RXSZ>>2];
593
594 };
595
596 typedef enum _RX_PACKET_TYPE{
597         NORMAL_RX,//Normal rx packet
598         TX_REPORT1,//CCX
599         TX_REPORT2,//TX RPT
600         HIS_REPORT,// USB HISR RPT
601         C2H_PACKET
602 }RX_PACKET_TYPE, *PRX_PACKET_TYPE;
603
604 extern union recv_frame *_rtw_alloc_recvframe (_queue *pfree_recv_queue);  //get a free recv_frame from pfree_recv_queue
605 extern union recv_frame *rtw_alloc_recvframe (_queue *pfree_recv_queue);  //get a free recv_frame from pfree_recv_queue
606 extern void rtw_init_recvframe(union recv_frame *precvframe ,struct recv_priv *precvpriv);
607 extern int       rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue);
608
609 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
610 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
611 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
612
613 extern void rtw_free_recvframe_queue(_queue *pframequeue,  _queue *pfree_recv_queue);
614 u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
615
616 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue);
617 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue);
618 struct recv_buf *rtw_dequeue_recvbuf (_queue *queue);
619
620 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
621
622 __inline static u8 *get_rxmem(union recv_frame *precvframe)
623 {
624         //always return rx_head...
625         if(precvframe==NULL)
626                 return NULL;
627
628         return precvframe->u.hdr.rx_head;
629 }
630
631 __inline static u8 *get_rx_status(union recv_frame *precvframe)
632 {
633
634         return get_rxmem(precvframe);
635
636 }
637
638 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
639 {
640
641         //alwasy return rx_data
642         if(precvframe==NULL)
643                 return NULL;
644
645         return precvframe->u.hdr.rx_data;
646
647 }
648
649 __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz)
650 {
651         // append data before rx_data
652
653         /* add data to the start of recv_frame
654  *
655  *      This function extends the used data area of the recv_frame at the buffer
656  *      start. rx_data must be still larger than rx_head, after pushing.
657  */
658
659         if(precvframe==NULL)
660                 return NULL;
661
662
663         precvframe->u.hdr.rx_data -= sz ;
664         if( precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head )
665         {
666                 precvframe->u.hdr.rx_data += sz ;
667                 return NULL;
668         }
669
670         precvframe->u.hdr.len +=sz;
671
672         return precvframe->u.hdr.rx_data;
673
674 }
675
676
677 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
678 {
679         // rx_data += sz; move rx_data sz bytes  hereafter
680
681         //used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller
682
683
684         if(precvframe==NULL)
685                 return NULL;
686
687
688         precvframe->u.hdr.rx_data += sz;
689
690         if(precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail)
691         {
692                 precvframe->u.hdr.rx_data -= sz;
693                 return NULL;
694         }
695
696         precvframe->u.hdr.len -=sz;
697
698         return precvframe->u.hdr.rx_data;
699
700 }
701
702 __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
703 {
704         // rx_tai += sz; move rx_tail sz bytes  hereafter
705
706         //used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller
707         //after putting, rx_tail must be still larger than rx_end.
708         unsigned char * prev_rx_tail;
709
710         if(precvframe==NULL)
711                 return NULL;
712
713         prev_rx_tail = precvframe->u.hdr.rx_tail;
714
715         precvframe->u.hdr.rx_tail += sz;
716
717         if(precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end)
718         {
719                 precvframe->u.hdr.rx_tail -= sz;
720                 return NULL;
721         }
722
723         precvframe->u.hdr.len +=sz;
724
725         return precvframe->u.hdr.rx_tail;
726
727 }
728
729
730
731 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
732 {
733         // rmv data from rx_tail (by yitsen)
734
735         //used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller
736         //after pulling, rx_end must be still larger than rx_data.
737
738         if(precvframe==NULL)
739                 return NULL;
740
741         precvframe->u.hdr.rx_tail -= sz;
742
743         if(precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data)
744         {
745                 precvframe->u.hdr.rx_tail += sz;
746                 return NULL;
747         }
748
749         precvframe->u.hdr.len -=sz;
750
751         return precvframe->u.hdr.rx_tail;
752
753 }
754
755
756
757 __inline static _buffer * get_rxbuf_desc(union recv_frame *precvframe)
758 {
759         _buffer * buf_desc;
760
761         if(precvframe==NULL)
762                 return NULL;
763 #ifdef PLATFORM_WINDOWS
764         NdisQueryPacket(precvframe->u.hdr.pkt, NULL, NULL, &buf_desc, NULL);
765 #endif
766
767         return buf_desc;
768 }
769
770
771 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
772 {
773         //due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame
774         //from any given member of recv_frame.
775         // rxmem indicates the any member/address in recv_frame
776
777         return (union recv_frame*)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
778
779 }
780
781 __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
782 {
783
784         u8 * buf_star;
785         union recv_frame * precv_frame;
786 #ifdef PLATFORM_WINDOWS
787         _buffer * buf_desc;
788         uint len;
789
790         NdisQueryPacket(pkt, NULL, NULL, &buf_desc, &len);
791         NdisQueryBufferSafe(buf_desc, &buf_star, &len, HighPagePriority);
792 #endif
793         precv_frame = rxmem_to_recvframe((unsigned char*)buf_star);
794
795         return precv_frame;
796 }
797
798 __inline static u8 *pkt_to_recvmem(_pkt *pkt)
799 {
800         // return the rx_head
801
802         union recv_frame * precv_frame = pkt_to_recvframe(pkt);
803
804         return  precv_frame->u.hdr.rx_head;
805
806 }
807
808 __inline static u8 *pkt_to_recvdata(_pkt *pkt)
809 {
810         // return the rx_data
811
812         union recv_frame * precv_frame =pkt_to_recvframe(pkt);
813
814         return  precv_frame->u.hdr.rx_data;
815
816 }
817
818
819 __inline static sint get_recvframe_len(union recv_frame *precvframe)
820 {
821         return precvframe->u.hdr.len;
822 }
823
824
825 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
826 {
827         s32     SignalPower; // in dBm.
828
829 #ifdef CONFIG_SKIP_SIGNAL_SCALE_MAPPING
830         // Translate to dBm (x=y-100)
831         SignalPower = SignalStrengthIndex - 100;
832 #else
833         // Translate to dBm (x=0.5y-95).
834         SignalPower = (s32)((SignalStrengthIndex + 1) >> 1); 
835         SignalPower -= 95; 
836 #endif
837
838         return SignalPower;
839 }
840
841
842 struct sta_info;
843
844 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
845
846 extern void  mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
847
848 #endif
849