xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8821cs/include/rtw_recv.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
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  *****************************************************************************/
15 #ifndef _RTW_RECV_H_
16 #define _RTW_RECV_H_
17 
18 #define RTW_RX_MSDU_ACT_NONE		0
19 #define RTW_RX_MSDU_ACT_INDICATE	BIT0
20 #define RTW_RX_MSDU_ACT_FORWARD		BIT1
21 
22 #ifdef CONFIG_SINGLE_RECV_BUF
23 	#define NR_RECVBUFF (1)
24 #else
25 	#if defined(CONFIG_GSPI_HCI)
26 		#define NR_RECVBUFF (32)
27 	#elif defined(CONFIG_SDIO_HCI)
28 		#define NR_RECVBUFF (8)
29 	#else
30 		#define NR_RECVBUFF (8)
31 	#endif
32 #endif /* CONFIG_SINGLE_RECV_BUF */
33 #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
34 	#define NR_PREALLOC_RECV_SKB (rtw_rtkm_get_nr_recv_skb()>>1)
35 #else /*!CONFIG_PREALLOC_RX_SKB_BUFFER */
36 	#define NR_PREALLOC_RECV_SKB 8
37 #endif /* CONFIG_PREALLOC_RX_SKB_BUFFER */
38 
39 #ifdef CONFIG_RTW_NAPI
40 	#define RTL_NAPI_WEIGHT (32)
41 #endif
42 
43 
44 #if defined(CONFIG_RTL8821C) && defined(CONFIG_SDIO_HCI) && defined(CONFIG_RECV_THREAD_MODE)
45 	#ifdef NR_RECVBUFF
46 	#undef NR_RECVBUFF
47 	#define NR_RECVBUFF (32)
48 	#endif
49 #endif
50 
51 #define NR_RECVFRAME 256
52 
53 #define RXFRAME_ALIGN	8
54 #define RXFRAME_ALIGN_SZ	(1<<RXFRAME_ALIGN)
55 
56 #define DRVINFO_SZ	4 /* unit is 8bytes */
57 
58 #define MAX_RXFRAME_CNT	512
59 #define MAX_RX_NUMBLKS		(32)
60 #define RECVFRAME_HDR_ALIGN 128
61 #define MAX_CONTINUAL_NORXPACKET_COUNT 4    /*  In MAX_CONTINUAL_NORXPACKET_COUNT*2 sec  , no rx traffict would issue DELBA*/
62 
63 #define PHY_RSSI_SLID_WIN_MAX				100
64 #define PHY_LINKQUALITY_SLID_WIN_MAX		20
65 
66 
67 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
68 
69 #define RX_MPDU_QUEUE				0
70 #define RX_CMD_QUEUE				1
71 #define RX_MAX_QUEUE				2
72 
73 #define MAX_SUBFRAME_COUNT	64
74 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
75 extern u8 rtw_bridge_tunnel_header[];
76 extern u8 rtw_rfc1042_header[];
77 
78 enum addba_rsp_ack_state {
79 	RTW_RECV_ACK_OR_TIMEOUT,
80 	RTW_RECV_REORDER_WOW
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 struct rtw_ip_dbg_cnt_statistic {
305 	u8 enabled;
306 	u8 ip[4];
307 	u16 dst_port;
308 	u32 ip_cnt;
309 	u32 tcp_cnt;
310 	u32 udp_cnt;
311 	u32 frag_cnt;
312 	u8 iperf_ver;	/* bit7 for debug enable */
313 	u32 iperf_seq;
314 	u32 iperf_err_cnt;
315 	u32 iperf_out_of_order_cnt;
316 
317 	u32 ip_seq_chk;
318 	u16 frag_offset_chk, max_frag_offset_chk;
319 	u8 defrag_done;
320 
321 #define need_to_chk_iudp_cnt(p, s) \
322 	((GET_IPV4_PROTOCOL((p)) == 0x11) && \
323 	((((struct rtw_ip_dbg_cnt_statistic *)(s))->iperf_ver & 0x7f) > 0))
324 #define ip_cnt_inc(s)	\
325 	((struct rtw_ip_dbg_cnt_statistic *)(s))->ip_cnt++
326 #define frag_cnt_inc(s)	\
327 	((struct rtw_ip_dbg_cnt_statistic *)(s))->frag_cnt++
328 #define tcp_udp_cnt_inc(p, s)	\
329 	do {	\
330 		if (GET_IPV4_PROTOCOL(p) == 0x06)	\
331 			((struct rtw_ip_dbg_cnt_statistic *)(s))->tcp_cnt++;	\
332 		else if (GET_IPV4_PROTOCOL(p) == 0x11)	\
333 			((struct rtw_ip_dbg_cnt_statistic *)(s))->udp_cnt++;	\
334 	} while(0)
335 #define iudp_err_cnt_inc(s, str)	\
336 	do {	\
337 		struct rtw_ip_dbg_cnt_statistic *ps = \
338 			(struct rtw_ip_dbg_cnt_statistic *)(s);	\
339 			ps->iperf_err_cnt++;	\
340 		if (((ps->iperf_ver & 0xf0) >> 7) > 0)	\
341 			RTW_INFO("%s : %s-err iperf_err_cnt(%u), iperf_seq(%u)\n"\
342 			,__func__, (const u8 *)(str), ps->iperf_err_cnt, ps->iperf_seq);	\
343 	} while(0)
344 #define iudp_err_cnt_update(s, c)	\
345 	do {	\
346 		struct rtw_ip_dbg_cnt_statistic *ps = \
347 			(struct rtw_ip_dbg_cnt_statistic *)(s);	\
348 		ps->iperf_err_cnt += ((c - 1) - ps->iperf_seq);	\
349 		if (((ps->iperf_ver & 0xf0) >> 7) > 0)	\
350 			RTW_INFO("%s : iperf_err_cnt(%u), cur_iperf_seq(%u), last_iperf_seq(%u)\n"\
351 			,__func__, ps->iperf_err_cnt, (c), ps->iperf_seq);	\
352 	} while(0)
353 #define iperf_out_of_order_cnt_inc(s, c)	\
354 	do {	\
355 		struct rtw_ip_dbg_cnt_statistic *ps = \
356 			(struct rtw_ip_dbg_cnt_statistic *)(s);	\
357 		ps->iperf_out_of_order_cnt++;	\
358 		if (((ps->iperf_ver & 0xf0) >> 7) > 0)	\
359 			RTW_INFO("%s : iperf_out_of_order_cnt(%u), cur_iperf_seq(%u), last_iperf_seq(%u)\n"\
360 			,__func__, ps->iperf_out_of_order_cnt, (c), ps->iperf_seq);	\
361 	} while(0)
362 
363 #define iudp_ip_seq_set(s, v)	\
364 	(((struct rtw_ip_dbg_cnt_statistic *)(s))->iperf_seq = (v))
365 #define iudp_ip_seq_get(s)	\
366 	((struct rtw_ip_dbg_cnt_statistic *)(s))->iperf_seq
367 #define iudp_defrag_done_set(s, v)	\
368 	(((struct rtw_ip_dbg_cnt_statistic *)(s))->defrag_done = (v))
369 #define iudp_defrag_done_get(s)	\
370 	((struct rtw_ip_dbg_cnt_statistic *)(s))->defrag_done
371 #define iudp_ip_seq_chk_set(s, v)	\
372 	(((struct rtw_ip_dbg_cnt_statistic *)(s))->ip_seq_chk = (v))
373 #define iudp_ip_seq_chk_get(s)	\
374 	((struct rtw_ip_dbg_cnt_statistic *)(s))->ip_seq_chk
375 #define iudp_frag_offset_chk_set(s, v)	\
376 	(((struct rtw_ip_dbg_cnt_statistic *)(s))->frag_offset_chk = (v))
377 #define iudp_frag_offset_chk_get(s)	\
378 	((struct rtw_ip_dbg_cnt_statistic *)(s))->frag_offset_chk
379 #define iudp_max_frag_offset_chk_set(s, v)	\
380 	(((struct rtw_ip_dbg_cnt_statistic *)(s))->max_frag_offset_chk = (v))
381 #define iudp_max_frag_offset_chk_get(s)	\
382 	((struct rtw_ip_dbg_cnt_statistic *)(s))->max_frag_offset_chk
383 };	/* end of struct rtw_ip_dbg_cnt_statistic */
384 
385 /*
386 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
387 ; halt(passive) ;
388 
389 using enter_critical section to protect
390 */
391 
392 #ifndef DBG_RX_BH_TRACKING
393 #define DBG_RX_BH_TRACKING 0
394 #endif
395 
396 struct recv_priv {
397 	_lock	lock;
398 
399 #ifdef CONFIG_RECV_THREAD_MODE
400 	_sema	recv_sema;
401 
402 #endif
403 
404 	/* _queue	blk_strms[MAX_RX_NUMBLKS];    */ /* keeping the block ack frame until return ack */
405 	_queue	free_recv_queue;
406 	_queue	recv_pending_queue;
407 	_queue	uc_swdec_pending_queue;
408 
409 
410 	u8 *pallocated_frame_buf;
411 	u8 *precv_frame_buf;
412 
413 	uint free_recvframe_cnt;
414 
415 	#if DBG_RX_BH_TRACKING
416 	u32 rx_bh_stage;
417 	u32 rx_bh_buf_dq_cnt;
418 	void *rx_bh_lbuf;
419 	void *rx_bh_cbuf;
420 	void *rx_bh_cbuf_data;
421 	u32 rx_bh_cbuf_dlen;
422 	u32 rx_bh_cbuf_pos;
423 	void *rx_bh_cframe;
424 	#endif
425 
426 	_adapter	*adapter;
427 
428 	u32 is_any_non_be_pkts;
429 
430 	u64	rx_bytes;
431 	u64	rx_pkts;
432 	u64	rx_drop;
433 
434 	u64 dbg_rx_drop_count;
435 	u64 dbg_rx_ampdu_drop_count;
436 	u64 dbg_rx_ampdu_forced_indicate_count;
437 	u64 dbg_rx_ampdu_loss_count;
438 	u64 dbg_rx_dup_mgt_frame_drop_count;
439 	u64 dbg_rx_ampdu_window_shift_cnt;
440 	u64 dbg_rx_conflic_mac_addr_cnt;
441 
442 	uint  rx_icv_err;
443 	uint  rx_largepacket_crcerr;
444 	uint  rx_smallpacket_crcerr;
445 	uint  rx_middlepacket_crcerr;
446 
447 	struct rtw_ip_dbg_cnt_statistic ip_statistic;
448 
449 #ifdef CONFIG_USB_HCI
450 	/* u8 *pallocated_urb_buf; */
451 	_sema allrxreturnevt;
452 	uint	ff_hwaddr;
453 	ATOMIC_T	rx_pending_cnt;
454 #ifdef CONFIG_USB_PROTECT_RX_CLONED_SKB
455 	struct sk_buff_head rx_cloned_skb_queue;
456 #endif
457 
458 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
459 #ifdef PLATFORM_LINUX
460 	PURB	int_in_urb;
461 #endif
462 
463 	u8	*int_in_buf;
464 #endif /* CONFIG_USB_INTERRUPT_IN_PIPE */
465 
466 #endif
467 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
468 	_tasklet irq_prepare_beacon_tasklet;
469 	_tasklet recv_tasklet;
470 
471 	struct sk_buff_head free_recv_skb_queue;
472 	struct sk_buff_head rx_skb_queue;
473 #ifdef CONFIG_RTW_NAPI
474 		struct sk_buff_head rx_napi_skb_queue;
475 #endif
476 #ifdef CONFIG_RX_INDICATE_QUEUE
477 	_tasklet rx_indicate_tasklet;
478 	struct ifqueue rx_indicate_queue;
479 #endif /* CONFIG_RX_INDICATE_QUEUE */
480 
481 #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) */
482 
483 	u8 *pallocated_recv_buf;
484 	u8 *precv_buf;    /* 4 alignment */
485 	_queue	free_recv_buf_queue;
486 	u32	free_recv_buf_queue_cnt;
487 
488 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) || defined(CONFIG_USB_HCI)
489 	_queue	recv_buf_pending_queue;
490 #endif
491 
492 #if defined(CONFIG_SDIO_HCI)
493 #ifdef CONFIG_SDIO_RECVBUF_PWAIT
494 	struct rtw_pwait_ctx recvbuf_pwait;
495 #endif
496 #ifdef CONFIG_SDIO_RECVBUF_AGGREGATION
497 	bool recvbuf_agg;
498 #endif
499 #endif /* CONFIG_SDIO_HCI */
500 
501 #ifdef CONFIG_PCI_HCI
502 	/* Rx */
503 	struct rtw_rx_ring	rx_ring[PCI_MAX_RX_QUEUE];
504 	int rxringcount;	/* size should be PCI_MAX_RX_QUEUE */
505 	u32	rxbuffersize;
506 #endif
507 
508 	/* For display the phy informatiom */
509 	u8 is_signal_dbg;	/* for debug */
510 	u8 signal_strength_dbg;	/* for debug */
511 
512 	u8 signal_strength;
513 	u8 signal_qual;
514 	s8 rssi;	/* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
515 	struct rx_raw_rssi raw_rssi_info;
516 	/* s8 rxpwdb;	 */
517 	/* int RxSNRdB[2]; */
518 	/* s8 RxRssi[2]; */
519 	/* int FalseAlmCnt_all; */
520 
521 
522 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
523 	_timer signal_stat_timer;
524 	u32 signal_stat_sampling_interval;
525 	/* u32 signal_stat_converging_constant; */
526 	struct signal_stat signal_qual_data;
527 	struct signal_stat signal_strength_data;
528 #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
529 	struct smooth_rssi_data signal_qual_data;
530 	struct smooth_rssi_data signal_strength_data;
531 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
532 	u16 sink_udpport, pre_rtp_rxseq, cur_rtp_rxseq;
533 
534 	BOOLEAN store_law_data_flag;
535 };
536 
537 #ifdef CONFIG_SDIO_RECVBUF_AGGREGATION
538 #define recv_buf_agg(recvpriv) recvpriv->recvbuf_agg
539 #ifndef CONFIG_SDIO_RECVBUF_AGGREGATION_EN
540 #define CONFIG_SDIO_RECVBUF_AGGREGATION_EN 1
541 #endif
542 #else
543 #define recv_buf_agg(recvpriv) 0
544 #endif
545 
546 #define RX_BH_STG_UNKNOWN		0
547 #define RX_BH_STG_HDL_ENTER		1
548 #define RX_BH_STG_HDL_EXIT		2
549 #define RX_BH_STG_NEW_BUF		3
550 #define RX_BH_STG_NEW_FRAME		4
551 #define RX_BH_STG_NORMAL_RX		5
552 #define RX_BH_STG_NORMAL_RX_END	6
553 #define RX_BH_STG_C2H			7
554 #define RX_BH_STG_C2H_END		8
555 
556 #if DBG_RX_BH_TRACKING
557 void rx_bh_tk_set_stage(struct recv_priv *recv, u32 s);
558 void rx_bh_tk_set_buf(struct recv_priv *recv, void *buf, void *data, u32 dlen);
559 void rx_bh_tk_set_buf_pos(struct recv_priv *recv, void *pos);
560 void rx_bh_tk_set_frame(struct recv_priv *recv, void *frame);
561 void dump_rx_bh_tk(void *sel, struct recv_priv *recv);
562 #else
563 #define rx_bh_tk_set_stage(recv, s) do {} while (0)
564 #define rx_bh_tk_set_buf(recv, buf, data, dlen) do {} while (0)
565 #define rx_bh_tk_set_buf_pos(recv, pos) do {} while (0)
566 #define rx_bh_tk_set_frame(recv, frame) do {} while (0)
567 #define dump_rx_bh_tk(sel, recv) do {} while (0)
568 #endif
569 
570 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
571 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
572 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
573 
574 struct sta_recv_priv {
575 
576 	_lock	lock;
577 	sint	option;
578 
579 	/* _queue	blk_strms[MAX_RX_NUMBLKS]; */
580 	_queue defrag_q;	 /* keeping the fragment frame until defrag */
581 
582 	struct	stainfo_rxcache rxcache;
583 	u16	bmc_tid_rxseq[16];
584 	u16	nonqos_rxseq;
585 	u16	nonqos_bmc_rxseq;
586 
587 	/* uint	sta_rx_bytes; */
588 	/* uint	sta_rx_pkts; */
589 	/* uint	sta_rx_fail; */
590 
591 };
592 
593 
594 #define RBUF_TYPE_PREALLOC	0
595 #define RBUF_TYPE_TMP		1
596 #define RBUF_TYPE_PWAIT_ADJ	2
597 
598 struct recv_buf {
599 	_list list;
600 
601 #ifdef PLATFORM_WINDOWS
602 	_lock recvbuf_lock;
603 #endif
604 
605 #ifdef CONFIG_SDIO_RECVBUF_PWAIT_RUNTIME_ADJUST
606 	u8 type;
607 #endif
608 
609 	u32	ref_cnt;
610 
611 	PADAPTER adapter;
612 
613 	u8	*pbuf;
614 	u8	*pallocated_buf;
615 
616 	u32	len;
617 	u8	*phead;
618 	u8	*pdata;
619 	u8	*ptail;
620 	u8	*pend;
621 
622 #ifdef CONFIG_USB_HCI
623 	PURB	purb;
624 	dma_addr_t dma_transfer_addr;	/* (in) dma addr for transfer_buffer */
625 	u32 alloc_sz;
626 
627 	u8  irp_pending;
628 	int  transfer_len;
629 #endif
630 
631 #if defined(PLATFORM_LINUX)
632 	_pkt *pskb;
633 #elif defined(PLATFORM_FREEBSD) /* skb solution */
634 	struct sk_buff *pskb;
635 #endif
636 };
637 
638 #ifdef CONFIG_SDIO_RECVBUF_PWAIT_RUNTIME_ADJUST
639 #define RBUF_IS_PREALLOC(rbuf) ((rbuf)->type == RBUF_TYPE_PREALLOC)
640 #else
641 #define RBUF_IS_PREALLOC(rbuf) 1
642 #endif
643 
644 /*
645 	head  ----->
646 
647 		data  ----->
648 
649 			payload
650 
651 		tail  ----->
652 
653 
654 	end   ----->
655 
656 	len = (unsigned int )(tail - data);
657 
658 */
659 struct recv_frame_hdr {
660 	_list	list;
661 	_pkt *pkt;
662 
663 	_adapter  *adapter;
664 
665 	u8 fragcnt;
666 
667 	int frame_tag;
668 	int keytrack;
669 	struct rx_pkt_attrib attrib;
670 
671 	uint  len;
672 	u8 *rx_head;
673 	u8 *rx_data;
674 	u8 *rx_tail;
675 	u8 *rx_end;
676 
677 	void *precvbuf;
678 
679 
680 	/*  */
681 	struct sta_info *psta;
682 
683 	/* for A-MPDU Rx reordering buffer control */
684 	struct recv_reorder_ctrl *preorder_ctrl;
685 
686 #ifdef CONFIG_WAPI_SUPPORT
687 	u8 UserPriority;
688 	u8 WapiTempPN[16];
689 	u8 WapiSrcAddr[6];
690 	u8 bWapiCheckPNInDecrypt;
691 	u8 bIsWaiPacket;
692 #endif
693 
694 };
695 
696 
697 union recv_frame {
698 
699 	union {
700 		_list list;
701 		struct recv_frame_hdr hdr;
702 		uint mem[RECVFRAME_HDR_ALIGN >> 2];
703 	} u;
704 
705 	/* uint mem[MAX_RXSZ>>2]; */
706 
707 };
708 
709 enum rtw_rx_llc_hdl {
710 	RTW_RX_LLC_KEEP		= 0,
711 	RTW_RX_LLC_REMOVE	= 1,
712 	RTW_RX_LLC_VLAN		= 2,
713 };
714 
715 bool rtw_rframe_del_wfd_ie(union recv_frame *rframe, u8 ies_offset);
716 
717 typedef enum _RX_PACKET_TYPE {
718 	NORMAL_RX,/* Normal rx packet */
719 	TX_REPORT1,/* CCX */
720 	TX_REPORT2,/* TX RPT */
721 	HIS_REPORT,/* USB HISR RPT */
722 	C2H_PACKET
723 } RX_PACKET_TYPE, *PRX_PACKET_TYPE;
724 
725 extern union recv_frame *_rtw_alloc_recvframe(_queue *pfree_recv_queue);   /* get a free recv_frame from pfree_recv_queue */
726 extern union recv_frame *rtw_alloc_recvframe(_queue *pfree_recv_queue);   /* get a free recv_frame from pfree_recv_queue */
727 extern void rtw_init_recvframe(union recv_frame *precvframe , struct recv_priv *precvpriv);
728 extern int	 rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue);
729 
730 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
731 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
732 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
733 
734 extern void rtw_free_recvframe_queue(_queue *pframequeue,  _queue *pfree_recv_queue);
735 u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
736 
737 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue);
738 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue);
739 struct recv_buf *rtw_dequeue_recvbuf(_queue *queue);
740 
741 void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta);
742 void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta);
743 
744 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
745 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
746 #endif
747 
748 void rx_query_phy_status(union recv_frame *rframe, u8 *phy_stat);
749 int rtw_inc_and_chk_continual_no_rx_packet(struct sta_info *sta, int tid_index);
750 void rtw_reset_continual_no_rx_packet(struct sta_info *sta, int tid_index);
751 
752 #ifdef CONFIG_RECV_THREAD_MODE
753 thread_return rtw_recv_thread(thread_context context);
754 #endif
755 
get_rxmem(union recv_frame * precvframe)756 __inline static u8 *get_rxmem(union recv_frame *precvframe)
757 {
758 	/* always return rx_head... */
759 	if (precvframe == NULL)
760 		return NULL;
761 
762 	return precvframe->u.hdr.rx_head;
763 }
764 
get_rx_status(union recv_frame * precvframe)765 __inline static u8 *get_rx_status(union recv_frame *precvframe)
766 {
767 
768 	return get_rxmem(precvframe);
769 
770 }
771 
get_recvframe_data(union recv_frame * precvframe)772 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
773 {
774 
775 	/* alwasy return rx_data */
776 	if (precvframe == NULL)
777 		return NULL;
778 
779 	return precvframe->u.hdr.rx_data;
780 
781 }
782 
recvframe_push(union recv_frame * precvframe,sint sz)783 __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz)
784 {
785 	/* append data before rx_data */
786 
787 	/* add data to the start of recv_frame
788 	*
789 	*      This function extends the used data area of the recv_frame at the buffer
790 	*      start. rx_data must be still larger than rx_head, after pushing.
791 	*/
792 
793 	if (precvframe == NULL)
794 		return NULL;
795 
796 
797 	precvframe->u.hdr.rx_data -= sz ;
798 	if (precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head) {
799 		precvframe->u.hdr.rx_data += sz ;
800 		return NULL;
801 	}
802 
803 	precvframe->u.hdr.len += sz;
804 
805 	return precvframe->u.hdr.rx_data;
806 
807 }
808 
809 
recvframe_pull(union recv_frame * precvframe,sint sz)810 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
811 {
812 	/* rx_data += sz; move rx_data sz bytes  hereafter */
813 
814 	/* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
815 
816 
817 	if (precvframe == NULL)
818 		return NULL;
819 
820 
821 	precvframe->u.hdr.rx_data += sz;
822 
823 	if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) {
824 		precvframe->u.hdr.rx_data -= sz;
825 		return NULL;
826 	}
827 
828 	precvframe->u.hdr.len -= sz;
829 
830 	return precvframe->u.hdr.rx_data;
831 
832 }
833 
recvframe_put(union recv_frame * precvframe,sint sz)834 __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
835 {
836 	/* rx_tai += sz; move rx_tail sz bytes  hereafter */
837 
838 	/* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
839 	/* after putting, rx_tail must be still larger than rx_end. */
840 	unsigned char *prev_rx_tail;
841 
842 	/* RTW_INFO("recvframe_put: len=%d\n", sz); */
843 
844 	if (precvframe == NULL)
845 		return NULL;
846 
847 	prev_rx_tail = precvframe->u.hdr.rx_tail;
848 
849 	precvframe->u.hdr.rx_tail += sz;
850 
851 	if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) {
852 		precvframe->u.hdr.rx_tail -= sz;
853 		return NULL;
854 	}
855 
856 	precvframe->u.hdr.len += sz;
857 
858 	return precvframe->u.hdr.rx_tail;
859 
860 }
861 
862 
863 
recvframe_pull_tail(union recv_frame * precvframe,sint sz)864 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
865 {
866 	/* rmv data from rx_tail (by yitsen) */
867 
868 	/* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
869 	/* after pulling, rx_end must be still larger than rx_data. */
870 
871 	if (precvframe == NULL)
872 		return NULL;
873 
874 	precvframe->u.hdr.rx_tail -= sz;
875 
876 	if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) {
877 		precvframe->u.hdr.rx_tail += sz;
878 		return NULL;
879 	}
880 
881 	precvframe->u.hdr.len -= sz;
882 
883 	return precvframe->u.hdr.rx_tail;
884 
885 }
886 
887 #if 0
888 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
889 {
890 	/* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
891 	/* from any given member of recv_frame. */
892 	/* rxmem indicates the any member/address in recv_frame */
893 
894 	return (union recv_frame *)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
895 
896 }
897 
898 __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
899 {
900 
901 	u8 *buf_star;
902 	union recv_frame *precv_frame;
903 	precv_frame = rxmem_to_recvframe((unsigned char *)buf_star);
904 
905 	return precv_frame;
906 }
907 
908 __inline static u8 *pkt_to_recvmem(_pkt *pkt)
909 {
910 	/* return the rx_head */
911 
912 	union recv_frame *precv_frame = pkt_to_recvframe(pkt);
913 
914 	return	precv_frame->u.hdr.rx_head;
915 
916 }
917 
918 __inline static u8 *pkt_to_recvdata(_pkt *pkt)
919 {
920 	/* return the rx_data */
921 
922 	union recv_frame *precv_frame = pkt_to_recvframe(pkt);
923 
924 	return	precv_frame->u.hdr.rx_data;
925 
926 }
927 #endif
928 
929 
get_recvframe_len(union recv_frame * precvframe)930 __inline static sint get_recvframe_len(union recv_frame *precvframe)
931 {
932 	return precvframe->u.hdr.len;
933 }
934 
935 
translate_percentage_to_dbm(u32 SignalStrengthIndex)936 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
937 {
938 	s32	SignalPower; /* in dBm. */
939 
940 	/* Translate to dBm (x=y-100) */
941 	SignalPower = SignalStrengthIndex - 100;
942 	return SignalPower;
943 }
944 
945 struct sta_info;
946 
947 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
948 
949 extern void  mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
950 
951 u8 adapter_allow_bmc_data_rx(_adapter *adapter);
952 s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status);
953 void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info *sta);
954 
955 #endif
956