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