xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723ds/include/rtw_recv.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2017 Realtek Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  *****************************************************************************/
16 #ifndef _RTW_RECV_H_
17 #define _RTW_RECV_H_
18 
19 #define RTW_RX_MSDU_ACT_NONE		0
20 #define RTW_RX_MSDU_ACT_INDICATE	BIT0
21 #define RTW_RX_MSDU_ACT_FORWARD		BIT1
22 
23 #ifdef CONFIG_SINGLE_RECV_BUF
24 	#define NR_RECVBUFF (1)
25 #else
26 	#if defined(CONFIG_GSPI_HCI)
27 		#define NR_RECVBUFF (32)
28 	#elif defined(CONFIG_SDIO_HCI)
29 		#define NR_RECVBUFF (8)
30 	#else
31 		#define NR_RECVBUFF (8)
32 	#endif
33 #endif /* CONFIG_SINGLE_RECV_BUF */
34 #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
35 	#define NR_PREALLOC_RECV_SKB (rtw_rtkm_get_nr_recv_skb()>>1)
36 #else /*!CONFIG_PREALLOC_RX_SKB_BUFFER */
37 	#define NR_PREALLOC_RECV_SKB 8
38 #endif /* CONFIG_PREALLOC_RX_SKB_BUFFER */
39 
40 #ifdef CONFIG_RTW_NAPI
41 	#define RTL_NAPI_WEIGHT (32)
42 #endif
43 
44 
45 #if defined(CONFIG_RTL8821C) && defined(CONFIG_SDIO_HCI) && defined(CONFIG_RECV_THREAD_MODE)
46 	#ifdef NR_RECVBUFF
47 	#undef NR_RECVBUFF
48 	#define NR_RECVBUFF (32)
49 	#endif
50 #endif
51 
52 #define NR_RECVFRAME 256
53 
54 #define RXFRAME_ALIGN	8
55 #define RXFRAME_ALIGN_SZ	(1<<RXFRAME_ALIGN)
56 
57 #define DRVINFO_SZ	4 /* unit is 8bytes */
58 
59 #define MAX_RXFRAME_CNT	512
60 #define MAX_RX_NUMBLKS		(32)
61 #define RECVFRAME_HDR_ALIGN 128
62 #define MAX_CONTINUAL_NORXPACKET_COUNT 4    /*  In MAX_CONTINUAL_NORXPACKET_COUNT*2 sec  , no rx traffict would issue DELBA*/
63 
64 #define PHY_RSSI_SLID_WIN_MAX				100
65 #define PHY_LINKQUALITY_SLID_WIN_MAX		20
66 
67 
68 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
69 
70 #define RX_MPDU_QUEUE				0
71 #define RX_CMD_QUEUE				1
72 #define RX_MAX_QUEUE				2
73 
74 #define MAX_SUBFRAME_COUNT	64
75 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
76 extern u8 rtw_bridge_tunnel_header[];
77 extern u8 rtw_rfc1042_header[];
78 
79 enum addba_rsp_ack_state {
80 	RTW_RECV_ACK_OR_TIMEOUT,
81 };
82 
83 /* for Rx reordering buffer control */
84 struct recv_reorder_ctrl {
85 	_adapter	*padapter;
86 	u8 tid;
87 	u8 enable;
88 	u16 indicate_seq;/* =wstart_b, init_value=0xffff */
89 	u16 wend_b;
90 	u8 wsize_b;
91 	u8 ampdu_size;
92 	_queue pending_recvframe_queue;
93 	_timer reordering_ctrl_timer;
94 	u8 bReorderWaiting;
95 	unsigned long rec_abba_rsp_ack;
96 };
97 
98 struct	stainfo_rxcache	{
99 	u16	tid_rxseq[16];
100 	u8 iv[16][8];
101 	u8 last_tid;
102 #if 0
103 	unsigned short	tid0_rxseq;
104 	unsigned short	tid1_rxseq;
105 	unsigned short	tid2_rxseq;
106 	unsigned short	tid3_rxseq;
107 	unsigned short	tid4_rxseq;
108 	unsigned short	tid5_rxseq;
109 	unsigned short	tid6_rxseq;
110 	unsigned short	tid7_rxseq;
111 	unsigned short	tid8_rxseq;
112 	unsigned short	tid9_rxseq;
113 	unsigned short	tid10_rxseq;
114 	unsigned short	tid11_rxseq;
115 	unsigned short	tid12_rxseq;
116 	unsigned short	tid13_rxseq;
117 	unsigned short	tid14_rxseq;
118 	unsigned short	tid15_rxseq;
119 #endif
120 };
121 
122 
123 struct smooth_rssi_data {
124 	u32	elements[100];	/* array to store values */
125 	u32	index;			/* index to current array to store */
126 	u32	total_num;		/* num of valid elements */
127 	u32	total_val;		/* sum of valid elements */
128 };
129 
130 struct signal_stat {
131 	u8	update_req;		/* used to indicate */
132 	u8	avg_val;		/* avg of valid elements */
133 	u32	total_num;		/* num of valid elements */
134 	u32	total_val;		/* sum of valid elements	 */
135 };
136 
137 struct rx_raw_rssi {
138 	u8 data_rate;
139 	u8 pwdball;
140 	s8 pwr_all;
141 
142 	u8 mimo_signal_strength[4];/* in 0~100 index */
143 	u8 mimo_signal_quality[4];
144 
145 	s8 ofdm_pwr[4];
146 	u8 ofdm_snr[4];
147 };
148 
149 
150 #include "cmn_info/rtw_sta_info.h"
151 
152 struct rx_pkt_attrib	{
153 	u16	pkt_len;
154 	u8	physt;
155 	u8	drvinfo_sz;
156 	u8	shift_sz;
157 	u8	hdrlen; /* the WLAN Header Len */
158 	u8	to_fr_ds;
159 	u8	amsdu;
160 	u8	qos;
161 	u8	priority;
162 	u8	pw_save;
163 	u8	mdata;
164 	u16	seq_num;
165 	u8	frag_num;
166 	u8	mfrag;
167 	u8	order;
168 	u8	privacy; /* in frame_ctrl field */
169 	u8	bdecrypted;
170 	u8	encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */
171 	u8	iv_len;
172 	u8	icv_len;
173 	u8	crc_err;
174 	u8	icv_err;
175 
176 	u8	dst[ETH_ALEN];
177 	u8	src[ETH_ALEN];
178 	u8	ta[ETH_ALEN];
179 	u8	ra[ETH_ALEN];
180 	u8	bssid[ETH_ALEN];
181 #ifdef CONFIG_RTW_MESH
182 	u8	msa[ETH_ALEN]; /* mesh sa */
183 	u8	mda[ETH_ALEN]; /* mesh da */
184 	u8 mesh_ctrl_present;
185 	u8	mesh_ctrl_len; /* length of mesh control field */
186 #endif
187 
188 	u8	ack_policy;
189 
190 	u8	key_index;
191 
192 	u8	data_rate;
193 	u8 ch; /* RX channel */
194 	u8	bw;
195 	u8	stbc;
196 	u8	ldpc;
197 	u8	sgi;
198 	u8	pkt_rpt_type;
199 	u32	MacIDValidEntry[2];	/* 64 bits present 64 entry. */
200 	u8	ampdu;
201 	u8	ppdu_cnt;
202 	u8	ampdu_eof;
203 	u32 	free_cnt;		/* free run counter */
204 	struct phydm_phyinfo_struct phy_info;
205 #ifdef CONFIG_WIFI_MONITOR
206 	u8 moif[16];
207 #endif
208 
209 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
210 	/* checksum offload realted varaiables */
211 	u8 csum_valid;		/* Checksum valid, 0: not check, 1: checked */
212 	u8 csum_err;		/* Checksum Error occurs */
213 #endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
214 };
215 
216 #ifdef CONFIG_RTW_MESH
217 #define RATTRIB_GET_MCTRL_LEN(rattrib) ((rattrib)->mesh_ctrl_len)
218 #else
219 #define RATTRIB_GET_MCTRL_LEN(rattrib) 0
220 #endif
221 
222 /* These definition is used for Rx packet reordering. */
223 #define SN_LESS(a, b)		(((a-b) & 0x800) != 0)
224 #define SN_EQUAL(a, b)	(a == b)
225 /* #define REORDER_WIN_SIZE	128 */
226 /* #define REORDER_ENTRY_NUM	128 */
227 #define REORDER_WAIT_TIME	(50) /* (ms) */
228 
229 #if defined(CONFIG_PLATFORM_RTK390X) && defined(CONFIG_USB_HCI)
230 	#define RECVBUFF_ALIGN_SZ 32
231 #else
232 	#define RECVBUFF_ALIGN_SZ 8
233 #endif
234 
235 #ifdef CONFIG_TRX_BD_ARCH
236 	#define RX_WIFI_INFO_SIZE	24
237 #elif (defined(CONFIG_RTL8192E) || defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B)) && defined(CONFIG_PCI_HCI)
238 	#define RXBD_SIZE	sizeof(struct recv_stat)
239 #endif
240 
241 #define RXDESC_SIZE	24
242 #define RXDESC_OFFSET RXDESC_SIZE
243 
244 #ifdef CONFIG_TRX_BD_ARCH
245 struct rx_buf_desc {
246 	/* RX has exactly one segment */
247 #ifdef CONFIG_64BIT_DMA
248 	unsigned int dword[4];
249 #else
250 	unsigned int dword[2];
251 #endif
252 };
253 
254 struct recv_stat {
255 	unsigned int rxdw[8];
256 };
257 #else
258 struct recv_stat {
259 	unsigned int rxdw0;
260 
261 	unsigned int rxdw1;
262 
263 #if !((defined(CONFIG_RTL8192E) || defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C) || defined(CONFIG_RTL8822C)) && defined(CONFIG_PCI_HCI))  /* exclude 8192ee, 8814ae, 8822be, 8821ce */
264 	unsigned int rxdw2;
265 
266 	unsigned int rxdw3;
267 #endif
268 
269 #ifndef BUF_DESC_ARCH
270 	unsigned int rxdw4;
271 
272 	unsigned int rxdw5;
273 
274 #ifdef CONFIG_PCI_HCI
275 	unsigned int rxdw6;
276 
277 	unsigned int rxdw7;
278 #endif
279 #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */
280 };
281 #endif
282 
283 #define EOR BIT(30)
284 
285 #ifdef CONFIG_PCI_HCI
286 #define PCI_MAX_RX_QUEUE		1/* MSDU packet queue, Rx Command Queue */
287 #define PCI_MAX_RX_COUNT		128
288 #ifdef CONFIG_TRX_BD_ARCH
289 #define RX_BD_NUM				PCI_MAX_RX_COUNT	/* alias */
290 #endif
291 
292 struct rtw_rx_ring {
293 #ifdef CONFIG_TRX_BD_ARCH
294 	struct rx_buf_desc	*buf_desc;
295 #else
296 	struct recv_stat	*desc;
297 #endif
298 	dma_addr_t		dma;
299 	unsigned int		idx;
300 	struct sk_buff	*rx_buf[PCI_MAX_RX_COUNT];
301 };
302 #endif
303 
304 
305 
306 /*
307 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
308 ; halt(passive) ;
309 
310 using enter_critical section to protect
311 */
312 
313 #ifndef DBG_RX_BH_TRACKING
314 #define DBG_RX_BH_TRACKING 0
315 #endif
316 
317 struct recv_priv {
318 	_lock	lock;
319 
320 #ifdef CONFIG_RECV_THREAD_MODE
321 	_sema	recv_sema;
322 
323 #endif
324 
325 	/* _queue	blk_strms[MAX_RX_NUMBLKS];    */ /* keeping the block ack frame until return ack */
326 	_queue	free_recv_queue;
327 	_queue	recv_pending_queue;
328 	_queue	uc_swdec_pending_queue;
329 
330 
331 	u8 *pallocated_frame_buf;
332 	u8 *precv_frame_buf;
333 
334 	uint free_recvframe_cnt;
335 
336 	#if DBG_RX_BH_TRACKING
337 	u32 rx_bh_stage;
338 	u32 rx_bh_buf_dq_cnt;
339 	void *rx_bh_lbuf;
340 	void *rx_bh_cbuf;
341 	void *rx_bh_cbuf_data;
342 	u32 rx_bh_cbuf_dlen;
343 	u32 rx_bh_cbuf_pos;
344 	void *rx_bh_cframe;
345 	#endif
346 
347 	_adapter	*adapter;
348 
349 	u32 is_any_non_be_pkts;
350 
351 	u64	rx_bytes;
352 	u64	rx_pkts;
353 	u64	rx_drop;
354 
355 	u64 dbg_rx_drop_count;
356 	u64 dbg_rx_ampdu_drop_count;
357 	u64 dbg_rx_ampdu_forced_indicate_count;
358 	u64 dbg_rx_ampdu_loss_count;
359 	u64 dbg_rx_dup_mgt_frame_drop_count;
360 	u64 dbg_rx_ampdu_window_shift_cnt;
361 	u64 dbg_rx_conflic_mac_addr_cnt;
362 
363 	uint  rx_icv_err;
364 	uint  rx_largepacket_crcerr;
365 	uint  rx_smallpacket_crcerr;
366 	uint  rx_middlepacket_crcerr;
367 
368 #ifdef CONFIG_USB_HCI
369 	/* u8 *pallocated_urb_buf; */
370 	_sema allrxreturnevt;
371 	uint	ff_hwaddr;
372 	ATOMIC_T	rx_pending_cnt;
373 
374 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
375 #ifdef PLATFORM_LINUX
376 	PURB	int_in_urb;
377 #endif
378 
379 	u8	*int_in_buf;
380 #endif /* CONFIG_USB_INTERRUPT_IN_PIPE */
381 
382 #endif
383 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
384 	_tasklet irq_prepare_beacon_tasklet;
385 	_tasklet recv_tasklet;
386 
387 	struct sk_buff_head free_recv_skb_queue;
388 	struct sk_buff_head rx_skb_queue;
389 #ifdef CONFIG_RTW_NAPI
390 		struct sk_buff_head rx_napi_skb_queue;
391 #endif
392 #ifdef CONFIG_RX_INDICATE_QUEUE
393 	_tasklet rx_indicate_tasklet;
394 	struct ifqueue rx_indicate_queue;
395 #endif /* CONFIG_RX_INDICATE_QUEUE */
396 
397 #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) */
398 
399 	u8 *pallocated_recv_buf;
400 	u8 *precv_buf;    /* 4 alignment */
401 	_queue	free_recv_buf_queue;
402 	u32	free_recv_buf_queue_cnt;
403 
404 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) || defined(CONFIG_USB_HCI)
405 	_queue	recv_buf_pending_queue;
406 #endif
407 
408 #ifdef CONFIG_PCI_HCI
409 	/* Rx */
410 	struct rtw_rx_ring	rx_ring[PCI_MAX_RX_QUEUE];
411 	int rxringcount;	/* size should be PCI_MAX_RX_QUEUE */
412 	u32	rxbuffersize;
413 #endif
414 
415 	/* For display the phy informatiom */
416 	u8 is_signal_dbg;	/* for debug */
417 	u8 signal_strength_dbg;	/* for debug */
418 
419 	u8 signal_strength;
420 	u8 signal_qual;
421 	s8 rssi;	/* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
422 	struct rx_raw_rssi raw_rssi_info;
423 	/* s8 rxpwdb;	 */
424 	/* int RxSNRdB[2]; */
425 	/* s8 RxRssi[2]; */
426 	/* int FalseAlmCnt_all; */
427 
428 
429 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
430 	_timer signal_stat_timer;
431 	u32 signal_stat_sampling_interval;
432 	/* u32 signal_stat_converging_constant; */
433 	struct signal_stat signal_qual_data;
434 	struct signal_stat signal_strength_data;
435 #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
436 	struct smooth_rssi_data signal_qual_data;
437 	struct smooth_rssi_data signal_strength_data;
438 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
439 	u16 sink_udpport, pre_rtp_rxseq, cur_rtp_rxseq;
440 
441 	BOOLEAN store_law_data_flag;
442 };
443 
444 #define RX_BH_STG_UNKNOWN		0
445 #define RX_BH_STG_HDL_ENTER		1
446 #define RX_BH_STG_HDL_EXIT		2
447 #define RX_BH_STG_NEW_BUF		3
448 #define RX_BH_STG_NEW_FRAME		4
449 #define RX_BH_STG_NORMAL_RX		5
450 #define RX_BH_STG_NORMAL_RX_END	6
451 #define RX_BH_STG_C2H			7
452 #define RX_BH_STG_C2H_END		8
453 
454 #if DBG_RX_BH_TRACKING
455 void rx_bh_tk_set_stage(struct recv_priv *recv, u32 s);
456 void rx_bh_tk_set_buf(struct recv_priv *recv, void *buf, void *data, u32 dlen);
457 void rx_bh_tk_set_buf_pos(struct recv_priv *recv, void *pos);
458 void rx_bh_tk_set_frame(struct recv_priv *recv, void *frame);
459 void dump_rx_bh_tk(void *sel, struct recv_priv *recv);
460 #else
461 #define rx_bh_tk_set_stage(recv, s) do {} while (0)
462 #define rx_bh_tk_set_buf(recv, buf, data, dlen) do {} while (0)
463 #define rx_bh_tk_set_buf_pos(recv, pos) do {} while (0)
464 #define rx_bh_tk_set_frame(recv, frame) do {} while (0)
465 #define dump_rx_bh_tk(sel, recv) do {} while (0)
466 #endif
467 
468 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
469 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
470 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
471 
472 struct sta_recv_priv {
473 
474 	_lock	lock;
475 	sint	option;
476 
477 	/* _queue	blk_strms[MAX_RX_NUMBLKS]; */
478 	_queue defrag_q;	 /* keeping the fragment frame until defrag */
479 
480 	struct	stainfo_rxcache rxcache;
481 	u16	bmc_tid_rxseq[16];
482 	u16	nonqos_rxseq;
483 	u16	nonqos_bmc_rxseq;
484 
485 	/* uint	sta_rx_bytes; */
486 	/* uint	sta_rx_pkts; */
487 	/* uint	sta_rx_fail; */
488 
489 };
490 
491 
492 struct recv_buf {
493 	_list list;
494 
495 	_lock recvbuf_lock;
496 
497 	u32	ref_cnt;
498 
499 	PADAPTER adapter;
500 
501 	u8	*pbuf;
502 	u8	*pallocated_buf;
503 
504 	u32	len;
505 	u8	*phead;
506 	u8	*pdata;
507 	u8	*ptail;
508 	u8	*pend;
509 
510 #ifdef CONFIG_USB_HCI
511 	PURB	purb;
512 	dma_addr_t dma_transfer_addr;	/* (in) dma addr for transfer_buffer */
513 	u32 alloc_sz;
514 
515 	u8  irp_pending;
516 	int  transfer_len;
517 #endif
518 
519 #if defined(PLATFORM_LINUX)
520 	_pkt *pskb;
521 #elif defined(PLATFORM_FREEBSD) /* skb solution */
522 	struct sk_buff *pskb;
523 #endif
524 };
525 
526 
527 /*
528 	head  ----->
529 
530 		data  ----->
531 
532 			payload
533 
534 		tail  ----->
535 
536 
537 	end   ----->
538 
539 	len = (unsigned int )(tail - data);
540 
541 */
542 struct recv_frame_hdr {
543 	_list	list;
544 	_pkt *pkt;
545 
546 	_adapter  *adapter;
547 
548 	u8 fragcnt;
549 
550 	int frame_tag;
551 
552 	struct rx_pkt_attrib attrib;
553 
554 	uint  len;
555 	u8 *rx_head;
556 	u8 *rx_data;
557 	u8 *rx_tail;
558 	u8 *rx_end;
559 
560 	void *precvbuf;
561 
562 
563 	/*  */
564 	struct sta_info *psta;
565 
566 	/* for A-MPDU Rx reordering buffer control */
567 	struct recv_reorder_ctrl *preorder_ctrl;
568 
569 #ifdef CONFIG_WAPI_SUPPORT
570 	u8 UserPriority;
571 	u8 WapiTempPN[16];
572 	u8 WapiSrcAddr[6];
573 	u8 bWapiCheckPNInDecrypt;
574 	u8 bIsWaiPacket;
575 #endif
576 
577 };
578 
579 
580 union recv_frame {
581 
582 	union {
583 		_list list;
584 		struct recv_frame_hdr hdr;
585 		uint mem[RECVFRAME_HDR_ALIGN >> 2];
586 	} u;
587 
588 	/* uint mem[MAX_RXSZ>>2]; */
589 
590 };
591 
592 enum rtw_rx_llc_hdl {
593 	RTW_RX_LLC_KEEP		= 0,
594 	RTW_RX_LLC_REMOVE	= 1,
595 	RTW_RX_LLC_VLAN		= 2,
596 };
597 
598 bool rtw_rframe_del_wfd_ie(union recv_frame *rframe, u8 ies_offset);
599 
600 typedef enum _RX_PACKET_TYPE {
601 	NORMAL_RX,/* Normal rx packet */
602 	TX_REPORT1,/* CCX */
603 	TX_REPORT2,/* TX RPT */
604 	HIS_REPORT,/* USB HISR RPT */
605 	C2H_PACKET
606 } RX_PACKET_TYPE, *PRX_PACKET_TYPE;
607 
608 extern union recv_frame *_rtw_alloc_recvframe(_queue *pfree_recv_queue);   /* get a free recv_frame from pfree_recv_queue */
609 extern union recv_frame *rtw_alloc_recvframe(_queue *pfree_recv_queue);   /* get a free recv_frame from pfree_recv_queue */
610 extern void rtw_init_recvframe(union recv_frame *precvframe , struct recv_priv *precvpriv);
611 extern int	 rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue);
612 
613 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
614 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
615 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
616 
617 extern void rtw_free_recvframe_queue(_queue *pframequeue,  _queue *pfree_recv_queue);
618 u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
619 
620 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue);
621 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue);
622 struct recv_buf *rtw_dequeue_recvbuf(_queue *queue);
623 
624 void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta);
625 void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta);
626 
627 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
628 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
629 #endif
630 
631 void rx_query_phy_status(union recv_frame *rframe, u8 *phy_stat);
632 int rtw_inc_and_chk_continual_no_rx_packet(struct sta_info *sta, int tid_index);
633 void rtw_reset_continual_no_rx_packet(struct sta_info *sta, int tid_index);
634 
635 #ifdef CONFIG_RECV_THREAD_MODE
636 thread_return rtw_recv_thread(thread_context context);
637 #endif
638 
get_rxmem(union recv_frame * precvframe)639 __inline static u8 *get_rxmem(union recv_frame *precvframe)
640 {
641 	/* always return rx_head... */
642 	if (precvframe == NULL)
643 		return NULL;
644 
645 	return precvframe->u.hdr.rx_head;
646 }
647 
get_rx_status(union recv_frame * precvframe)648 __inline static u8 *get_rx_status(union recv_frame *precvframe)
649 {
650 
651 	return get_rxmem(precvframe);
652 
653 }
654 
get_recvframe_data(union recv_frame * precvframe)655 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
656 {
657 
658 	/* alwasy return rx_data */
659 	if (precvframe == NULL)
660 		return NULL;
661 
662 	return precvframe->u.hdr.rx_data;
663 
664 }
665 
recvframe_push(union recv_frame * precvframe,sint sz)666 __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz)
667 {
668 	/* append data before rx_data */
669 
670 	/* add data to the start of recv_frame
671 	*
672 	*      This function extends the used data area of the recv_frame at the buffer
673 	*      start. rx_data must be still larger than rx_head, after pushing.
674 	*/
675 
676 	if (precvframe == NULL)
677 		return NULL;
678 
679 
680 	precvframe->u.hdr.rx_data -= sz ;
681 	if (precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head) {
682 		precvframe->u.hdr.rx_data += sz ;
683 		return NULL;
684 	}
685 
686 	precvframe->u.hdr.len += sz;
687 
688 	return precvframe->u.hdr.rx_data;
689 
690 }
691 
692 
recvframe_pull(union recv_frame * precvframe,sint sz)693 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
694 {
695 	/* rx_data += sz; move rx_data sz bytes  hereafter */
696 
697 	/* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
698 
699 
700 	if (precvframe == NULL)
701 		return NULL;
702 
703 
704 	precvframe->u.hdr.rx_data += sz;
705 
706 	if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) {
707 		precvframe->u.hdr.rx_data -= sz;
708 		return NULL;
709 	}
710 
711 	precvframe->u.hdr.len -= sz;
712 
713 	return precvframe->u.hdr.rx_data;
714 
715 }
716 
recvframe_put(union recv_frame * precvframe,sint sz)717 __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
718 {
719 	/* rx_tai += sz; move rx_tail sz bytes  hereafter */
720 
721 	/* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
722 	/* after putting, rx_tail must be still larger than rx_end. */
723 	unsigned char *prev_rx_tail;
724 
725 	/* RTW_INFO("recvframe_put: len=%d\n", sz); */
726 
727 	if (precvframe == NULL)
728 		return NULL;
729 
730 	prev_rx_tail = precvframe->u.hdr.rx_tail;
731 
732 	precvframe->u.hdr.rx_tail += sz;
733 
734 	if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) {
735 		precvframe->u.hdr.rx_tail -= sz;
736 		return NULL;
737 	}
738 
739 	precvframe->u.hdr.len += sz;
740 
741 	return precvframe->u.hdr.rx_tail;
742 
743 }
744 
745 
746 
recvframe_pull_tail(union recv_frame * precvframe,sint sz)747 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
748 {
749 	/* rmv data from rx_tail (by yitsen) */
750 
751 	/* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
752 	/* after pulling, rx_end must be still larger than rx_data. */
753 
754 	if (precvframe == NULL)
755 		return NULL;
756 
757 	precvframe->u.hdr.rx_tail -= sz;
758 
759 	if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) {
760 		precvframe->u.hdr.rx_tail += sz;
761 		return NULL;
762 	}
763 
764 	precvframe->u.hdr.len -= sz;
765 
766 	return precvframe->u.hdr.rx_tail;
767 
768 }
769 
rxmem_to_recvframe(u8 * rxmem)770 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
771 {
772 	/* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
773 	/* from any given member of recv_frame. */
774 	/* rxmem indicates the any member/address in recv_frame */
775 
776 	return (union recv_frame *)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
777 
778 }
779 
pkt_to_recvframe(_pkt * pkt)780 __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
781 {
782 
783 	u8 *buf_star;
784 	union recv_frame *precv_frame;
785 	precv_frame = rxmem_to_recvframe((unsigned char *)buf_star);
786 
787 	return precv_frame;
788 }
789 
pkt_to_recvmem(_pkt * pkt)790 __inline static u8 *pkt_to_recvmem(_pkt *pkt)
791 {
792 	/* return the rx_head */
793 
794 	union recv_frame *precv_frame = pkt_to_recvframe(pkt);
795 
796 	return	precv_frame->u.hdr.rx_head;
797 
798 }
799 
pkt_to_recvdata(_pkt * pkt)800 __inline static u8 *pkt_to_recvdata(_pkt *pkt)
801 {
802 	/* return the rx_data */
803 
804 	union recv_frame *precv_frame = pkt_to_recvframe(pkt);
805 
806 	return	precv_frame->u.hdr.rx_data;
807 
808 }
809 
810 
get_recvframe_len(union recv_frame * precvframe)811 __inline static sint get_recvframe_len(union recv_frame *precvframe)
812 {
813 	return precvframe->u.hdr.len;
814 }
815 
816 
translate_percentage_to_dbm(u32 SignalStrengthIndex)817 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
818 {
819 	s32	SignalPower; /* in dBm. */
820 
821 	/* Translate to dBm (x=y-100) */
822 	SignalPower = SignalStrengthIndex - 100;
823 	return SignalPower;
824 }
825 
826 struct sta_info;
827 
828 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
829 
830 extern void  mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
831 
832 u8 adapter_allow_bmc_data_rx(_adapter *adapter);
833 s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status);
834 void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info *sta);
835 
836 #endif
837