1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
10 #ifdef CONFIG_SINGLE_RECV_BUF
11 #define NR_RECVBUFF (1)
13 #define NR_RECVBUFF (8)
14 #endif /* CONFIG_SINGLE_RECV_BUF */
16 #define NR_PREALLOC_RECV_SKB (8)
18 #define NR_RECVFRAME 256
20 #define RXFRAME_ALIGN 8
21 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
23 #define DRVINFO_SZ 4 /* unit is 8bytes */
25 #define MAX_RXFRAME_CNT 512
26 #define MAX_RX_NUMBLKS (32)
27 #define RECVFRAME_HDR_ALIGN 128
30 #define PHY_RSSI_SLID_WIN_MAX 100
31 #define PHY_LINKQUALITY_SLID_WIN_MAX 20
34 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
36 #define RX_MPDU_QUEUE 0
37 #define RX_CMD_QUEUE 1
38 #define RX_MAX_QUEUE 2
40 #define MAX_SUBFRAME_COUNT 64
41 extern u8 rtw_rfc1042_header[];
42 extern u8 rtw_bridge_tunnel_header[];
44 /* for Rx reordering buffer control */
45 struct recv_reorder_ctrl
47 struct adapter *padapter;
49 u16 indicate_seq;/* wstart_b, init_value = 0xffff */
52 struct __queue pending_recvframe_queue;
53 _timer reordering_ctrl_timer;
56 struct stainfo_rxcache {
59 unsigned short tid0_rxseq;
60 unsigned short tid1_rxseq;
61 unsigned short tid2_rxseq;
62 unsigned short tid3_rxseq;
63 unsigned short tid4_rxseq;
64 unsigned short tid5_rxseq;
65 unsigned short tid6_rxseq;
66 unsigned short tid7_rxseq;
67 unsigned short tid8_rxseq;
68 unsigned short tid9_rxseq;
69 unsigned short tid10_rxseq;
70 unsigned short tid11_rxseq;
71 unsigned short tid12_rxseq;
72 unsigned short tid13_rxseq;
73 unsigned short tid14_rxseq;
74 unsigned short tid15_rxseq;
79 struct smooth_rssi_data {
80 u32 elements[100]; /* array to store values */
81 u32 index; /* index to current array to store */
82 u32 total_num; /* num of valid elements */
83 u32 total_val; /* sum of valid elements */
87 u8 update_req; /* used to indicate */
88 u8 avg_val; /* avg of valid elements */
89 u32 total_num; /* num of valid elements */
90 u32 total_val; /* sum of valid elements */
96 u8 SignalQuality; /* in 0-100 index. */
97 s8 rx_mimo_signal_quality[4]; /* per-path's EVM */
98 u8 RxMIMOEVMdbm[4]; /* per-path's EVM dbm */
100 u8 rx_mimo_signal_strength[4];/* in 0~100 index */
102 u16 Cfo_short[4]; /* per-path's Cfo_short */
103 u16 Cfo_tail[4]; /* per-path's Cfo_tail */
105 s8 RxPower; /* in dBm Translate from PWdB */
106 s8 RecvSignalPower;/* Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures. */
107 u8 bt_rx_rssi_percentage;
108 u8 SignalStrength; /* in 0-100 index. */
110 s8 RxPwr[4]; /* per-path's pwdb */
111 u8 RxSNR[4]; /* per-path's SNR */
116 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
123 u8 mimo_singal_strength[4];/* in 0~100 index */
124 u8 mimo_singal_quality[4];
132 struct rx_pkt_attrib {
137 u8 hdrlen; /* the WLAN Header Len */
148 u8 privacy; /* in frame_ctrl field */
150 u8 encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */
166 /* ifdef CONFIG_TCP_CSUM_OFFLOAD_RX */
167 u8 tcpchk_valid; /* 0: invalid, 1: valid */
168 u8 ip_chkrpt; /* 0: incorrect, 1: correct */
169 u8 tcp_chkrpt; /* 0: incorrect, 1: correct */
176 u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */
180 s8 rx_mimo_signal_qual[2];
185 struct phy_info phy_info;
189 /* These definition is used for Rx packet reordering. */
190 #define SN_LESS(a, b) (((a-b)&0x800)!= 0)
191 #define SN_EQUAL(a, b) (a == b)
192 /* define REORDER_WIN_SIZE 128 */
193 /* define REORDER_ENTRY_NUM 128 */
194 #define REORDER_WAIT_TIME (50) /* (ms) */
196 #define RECVBUFF_ALIGN_SZ 8
198 #define RXDESC_SIZE 24
199 #define RXDESC_OFFSET RXDESC_SIZE
206 #ifndef BUF_DESC_ARCH
209 #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */
215 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
218 using enter_critical section to protect
222 struct __queue free_recv_queue;
223 struct __queue recv_pending_queue;
224 struct __queue uc_swdec_pending_queue;
225 u8 *pallocated_frame_buf;
227 uint free_recvframe_cnt;
228 struct adapter *adapter;
234 uint rx_largepacket_crcerr;
235 uint rx_smallpacket_crcerr;
236 uint rx_middlepacket_crcerr;
238 struct tasklet_struct irq_prepare_beacon_tasklet;
239 struct tasklet_struct recv_tasklet;
240 struct sk_buff_head free_recv_skb_queue;
241 struct sk_buff_head rx_skb_queue;
242 #ifdef CONFIG_RX_INDICATE_QUEUE
243 struct task rx_indicate_tasklet;
244 struct ifqueue rx_indicate_queue;
245 #endif /* CONFIG_RX_INDICATE_QUEUE */
247 u8 *pallocated_recv_buf;
248 u8 *precv_buf; /* 4 alignment */
249 struct __queue free_recv_buf_queue;
250 u32 free_recv_buf_queue_cnt;
252 struct __queue recv_buf_pending_queue;
254 /* For display the phy informatiom */
255 u8 is_signal_dbg; /* for debug */
256 u8 signal_strength_dbg; /* for debug */
260 s8 rssi; /* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
261 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
262 struct rx_raw_rssi raw_rssi_info;
266 /* int RxSNRdB[2]; */
268 /* int FalseAlmCnt_all; */
271 _timer signal_stat_timer;
272 u32 signal_stat_sampling_interval;
273 /* u32 signal_stat_converging_constant; */
274 struct signal_stat signal_qual_data;
275 struct signal_stat signal_strength_data;
278 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
280 struct sta_recv_priv {
285 /* struct __queue blk_strms[MAX_RX_NUMBLKS]; */
286 struct __queue defrag_q; /* keeping the fragment frame until defrag */
288 struct stainfo_rxcache rxcache;
290 /* uint sta_rx_bytes; */
291 /* uint sta_rx_pkts; */
292 /* uint sta_rx_fail; */
299 struct list_head list;
305 struct adapter * adapter;
333 len = (unsigned int)(tail - data);
336 struct recv_frame_hdr
338 struct list_head list;
339 #ifndef CONFIG_BSD_RX_USE_MBUF
341 struct sk_buff *pkt_newalloc;
342 #else /* CONFIG_BSD_RX_USE_MBUF */
345 #endif /* CONFIG_BSD_RX_USE_MBUF */
347 struct adapter *adapter;
353 struct rx_pkt_attrib attrib;
365 struct sta_info *psta;
367 /* for A-MPDU Rx reordering buffer control */
368 struct recv_reorder_ctrl *preorder_ctrl;
374 struct list_head list;
375 struct recv_frame_hdr hdr;
376 uint mem[RECVFRAME_HDR_ALIGN>>2];
379 /* uint mem[MAX_RXSZ>>2]; */
383 enum RX_PACKET_TYPE {
384 NORMAL_RX,/* Normal rx packet */
386 TX_REPORT2,/* TX RPT */
387 HIS_REPORT,/* USB HISR RPT */
391 extern union recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
392 extern union recv_frame *rtw_alloc_recvframe (struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
393 extern int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue);
395 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
396 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue);
397 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue);
399 extern void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue);
400 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
402 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue);
403 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue);
404 struct recv_buf *rtw_dequeue_recvbuf (struct __queue *queue);
406 void rtw_reordering_ctrl_timeout_handler(struct timer_list *t);
408 __inline static u8 *get_rxmem(union recv_frame *precvframe)
410 /* always return rx_head... */
411 if (precvframe == NULL)
414 return precvframe->u.hdr.rx_head;
417 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
420 /* alwasy return rx_data */
421 if (precvframe == NULL)
424 return precvframe->u.hdr.rx_data;
428 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
430 /* rx_data += sz; move rx_data sz bytes hereafter */
432 /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
435 if (precvframe == NULL)
439 precvframe->u.hdr.rx_data += sz;
441 if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail)
443 precvframe->u.hdr.rx_data -= sz;
447 precvframe->u.hdr.len -=sz;
449 return precvframe->u.hdr.rx_data;
453 __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
455 /* rx_tai += sz; move rx_tail sz bytes hereafter */
457 /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
458 /* after putting, rx_tail must be still larger than rx_end. */
459 unsigned char * prev_rx_tail;
461 if (precvframe == NULL)
464 prev_rx_tail = precvframe->u.hdr.rx_tail;
466 precvframe->u.hdr.rx_tail += sz;
468 if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end)
470 precvframe->u.hdr.rx_tail = prev_rx_tail;
474 precvframe->u.hdr.len +=sz;
476 return precvframe->u.hdr.rx_tail;
482 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
484 /* rmv data from rx_tail (by yitsen) */
486 /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
487 /* after pulling, rx_end must be still larger than rx_data. */
489 if (precvframe == NULL)
492 precvframe->u.hdr.rx_tail -= sz;
494 if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data)
496 precvframe->u.hdr.rx_tail += sz;
500 precvframe->u.hdr.len -=sz;
502 return precvframe->u.hdr.rx_tail;
506 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
508 /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
509 /* from any given member of recv_frame. */
510 /* rxmem indicates the any member/address in recv_frame */
512 return (union recv_frame*)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
516 __inline static sint get_recvframe_len(union recv_frame *precvframe)
518 return precvframe->u.hdr.len;
522 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
524 s32 SignalPower; /* in dBm. */
526 #ifdef CONFIG_SKIP_SIGNAL_SCALE_MAPPING
527 /* Translate to dBm (x =y-100) */
528 SignalPower = SignalStrengthIndex - 100;
530 /* Translate to dBm (x = 0.5y-95). */
531 SignalPower = (s32)((SignalStrengthIndex + 1) >> 1);
541 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
543 extern void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame);