OSDN Git Service

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