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