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