1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
10 #define NR_RECVBUFF (8)
12 #define NR_PREALLOC_RECV_SKB (8)
14 #define NR_RECVFRAME 256
16 #define RXFRAME_ALIGN 8
17 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
19 #define DRVINFO_SZ 4 /* unit is 8bytes */
21 #define MAX_RXFRAME_CNT 512
22 #define MAX_RX_NUMBLKS (32)
23 #define RECVFRAME_HDR_ALIGN 128
26 #define PHY_RSSI_SLID_WIN_MAX 100
27 #define PHY_LINKQUALITY_SLID_WIN_MAX 20
30 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
32 #define RX_MPDU_QUEUE 0
33 #define RX_CMD_QUEUE 1
34 #define RX_MAX_QUEUE 2
36 #define MAX_SUBFRAME_COUNT 64
38 #define LLC_HEADER_LENGTH 6
40 /* for Rx reordering buffer control */
41 struct recv_reorder_ctrl {
42 struct adapter *padapter;
44 u16 indicate_seq;/* wstart_b, init_value = 0xffff */
47 struct __queue pending_recvframe_queue;
48 struct timer_list reordering_ctrl_timer;
51 struct stainfo_rxcache {
54 unsigned short tid0_rxseq;
55 unsigned short tid1_rxseq;
56 unsigned short tid2_rxseq;
57 unsigned short tid3_rxseq;
58 unsigned short tid4_rxseq;
59 unsigned short tid5_rxseq;
60 unsigned short tid6_rxseq;
61 unsigned short tid7_rxseq;
62 unsigned short tid8_rxseq;
63 unsigned short tid9_rxseq;
64 unsigned short tid10_rxseq;
65 unsigned short tid11_rxseq;
66 unsigned short tid12_rxseq;
67 unsigned short tid13_rxseq;
68 unsigned short tid14_rxseq;
69 unsigned short tid15_rxseq;
75 u8 update_req; /* used to indicate */
76 u8 avg_val; /* avg of valid elements */
77 u32 total_num; /* num of valid elements */
78 u32 total_val; /* sum of valid elements */
84 u8 SignalQuality; /* in 0-100 index. */
85 s8 rx_mimo_signal_quality[4]; /* per-path's EVM */
86 u8 RxMIMOEVMdbm[4]; /* per-path's EVM dbm */
88 u8 rx_mimo_signal_strength[4];/* in 0~100 index */
90 u16 Cfo_short[4]; /* per-path's Cfo_short */
91 u16 Cfo_tail[4]; /* per-path's Cfo_tail */
93 s8 RxPower; /* in dBm Translate from PWdB */
94 s8 RecvSignalPower;/* Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures. */
95 u8 bt_rx_rssi_percentage;
96 u8 SignalStrength; /* in 0-100 index. */
98 s8 RxPwr[4]; /* per-path's pwdb */
99 u8 RxSNR[4]; /* per-path's SNR */
104 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
110 u8 mimo_signal_strength[4];/* in 0~100 index */
111 u8 mimo_signal_quality[4];
119 struct rx_pkt_attrib {
124 u8 hdrlen; /* the WLAN Header Len */
135 u8 privacy; /* in frame_ctrl field */
137 u8 encrypt; /* when 0 indicates no encryption; when non-zero, indicates the encryption algorithm */
158 u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */
162 s8 rx_mimo_signal_qual[2];
167 struct phy_info phy_info;
171 /* These definition is used for Rx packet reordering. */
172 #define SN_LESS(a, b) (((a - b) & 0x800) != 0)
173 #define SN_EQUAL(a, b) (a == b)
174 /* define REORDER_WIN_SIZE 128 */
175 /* define REORDER_ENTRY_NUM 128 */
176 #define REORDER_WAIT_TIME (50) /* (ms) */
178 #define RECVBUFF_ALIGN_SZ 8
180 #define RXDESC_SIZE 24
181 #define RXDESC_OFFSET RXDESC_SIZE
188 #ifndef BUF_DESC_ARCH
191 #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */
197 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
200 using enter_critical section to protect
204 struct __queue free_recv_queue;
205 struct __queue recv_pending_queue;
206 struct __queue uc_swdec_pending_queue;
207 u8 *pallocated_frame_buf;
209 uint free_recvframe_cnt;
210 struct adapter *adapter;
216 uint rx_largepacket_crcerr;
217 uint rx_smallpacket_crcerr;
218 uint rx_middlepacket_crcerr;
220 struct tasklet_struct irq_prepare_beacon_tasklet;
221 struct tasklet_struct recv_tasklet;
222 struct sk_buff_head free_recv_skb_queue;
223 struct sk_buff_head rx_skb_queue;
225 u8 *pallocated_recv_buf;
226 u8 *precv_buf; /* 4 alignment */
227 struct __queue free_recv_buf_queue;
228 u32 free_recv_buf_queue_cnt;
230 struct __queue recv_buf_pending_queue;
232 /* For display the phy information */
233 u8 is_signal_dbg; /* for debug */
234 u8 signal_strength_dbg; /* for debug */
238 s8 rssi; /* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
239 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA
240 struct rx_raw_rssi raw_rssi_info;
244 /* int RxSNRdB[2]; */
246 /* int FalseAlmCnt_all; */
249 struct timer_list signal_stat_timer;
250 u32 signal_stat_sampling_interval;
251 /* u32 signal_stat_converging_constant; */
252 struct signal_stat signal_qual_data;
253 struct signal_stat signal_strength_data;
256 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
258 struct sta_recv_priv {
263 /* struct __queue blk_strms[MAX_RX_NUMBLKS]; */
264 struct __queue defrag_q; /* keeping the fragment frame until defrag */
266 struct stainfo_rxcache rxcache;
268 /* uint sta_rx_bytes; */
269 /* uint sta_rx_pkts; */
270 /* uint sta_rx_fail; */
276 struct list_head list;
278 spinlock_t recvbuf_lock;
282 struct adapter *adapter;
293 struct sk_buff *pskb;
310 len = (unsigned int)(tail - data);
313 struct recv_frame_hdr {
314 struct list_head list;
316 struct sk_buff *pkt_newalloc;
318 struct adapter *adapter;
324 struct rx_pkt_attrib attrib;
336 struct sta_info *psta;
338 /* for A-MPDU Rx reordering buffer control */
339 struct recv_reorder_ctrl *preorder_ctrl;
345 struct list_head list;
346 struct recv_frame_hdr hdr;
347 uint mem[RECVFRAME_HDR_ALIGN>>2];
350 /* uint mem[MAX_RXSZ>>2]; */
355 NORMAL_RX,/* Normal rx packet */
357 TX_REPORT2,/* TX RPT */
358 HIS_REPORT,/* USB HISR RPT */
362 extern union recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
363 extern union recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
364 extern int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue);
366 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
367 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue);
368 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue);
370 extern void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue);
371 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
373 signed int rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue);
374 signed int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue);
375 struct recv_buf *rtw_dequeue_recvbuf(struct __queue *queue);
377 void rtw_reordering_ctrl_timeout_handler(struct timer_list *t);
379 static inline u8 *get_rxmem(union recv_frame *precvframe)
381 /* always return rx_head... */
382 if (precvframe == NULL)
385 return precvframe->u.hdr.rx_head;
388 static inline u8 *recvframe_pull(union recv_frame *precvframe, signed int sz)
390 /* rx_data += sz; move rx_data sz bytes hereafter */
392 /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
395 if (precvframe == NULL)
399 precvframe->u.hdr.rx_data += sz;
401 if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail)
403 precvframe->u.hdr.rx_data -= sz;
407 precvframe->u.hdr.len -= sz;
409 return precvframe->u.hdr.rx_data;
413 static inline u8 *recvframe_put(union recv_frame *precvframe, signed int sz)
415 /* rx_tai += sz; move rx_tail sz bytes hereafter */
417 /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
418 /* after putting, rx_tail must be still larger than rx_end. */
419 unsigned char *prev_rx_tail;
421 if (precvframe == NULL)
424 prev_rx_tail = precvframe->u.hdr.rx_tail;
426 precvframe->u.hdr.rx_tail += sz;
428 if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end)
430 precvframe->u.hdr.rx_tail = prev_rx_tail;
434 precvframe->u.hdr.len += sz;
436 return precvframe->u.hdr.rx_tail;
442 static inline u8 *recvframe_pull_tail(union recv_frame *precvframe, signed int sz)
444 /* rmv data from rx_tail (by yitsen) */
446 /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
447 /* after pulling, rx_end must be still larger than rx_data. */
449 if (precvframe == NULL)
452 precvframe->u.hdr.rx_tail -= sz;
454 if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data)
456 precvframe->u.hdr.rx_tail += sz;
460 precvframe->u.hdr.len -= sz;
462 return precvframe->u.hdr.rx_tail;
466 static inline union recv_frame *rxmem_to_recvframe(u8 *rxmem)
468 /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
469 /* from any given member of recv_frame. */
470 /* rxmem indicates the any member/address in recv_frame */
472 return (union recv_frame *)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
476 static inline signed int get_recvframe_len(union recv_frame *precvframe)
478 return precvframe->u.hdr.len;
482 static inline s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
484 s32 SignalPower; /* in dBm. */
486 /* Translate to dBm (x = 0.5y-95). */
487 SignalPower = (s32)((SignalStrengthIndex + 1) >> 1);
496 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
498 extern void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame);