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