1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #ifndef _RTW_RECV_H_
8 #define _RTW_RECV_H_
9
10 #include <osdep_service.h>
11 #include <drv_types.h>
12
13
14 #define NR_RECVFRAME 256
15
16 #define RXFRAME_ALIGN 8
17 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
18
19 #define MAX_RXFRAME_CNT 512
20 #define MAX_RX_NUMBLKS (32)
21 #define RECVFRAME_HDR_ALIGN 128
22
23 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
24
25 #define MAX_SUBFRAME_COUNT 64
26
27 /* for Rx reordering buffer control */
28 struct recv_reorder_ctrl {
29 struct adapter *padapter;
30 u8 enable;
31 u16 indicate_seq;/* wstart_b, init_value=0xffff */
32 u16 wend_b;
33 u8 wsize_b;
34 struct __queue pending_recvframe_queue;
35 struct timer_list reordering_ctrl_timer;
36 };
37
38 struct stainfo_rxcache {
39 u16 tid_rxseq[16];
40 /*
41 * unsigned short tid0_rxseq;
42 * unsigned short tid1_rxseq;
43 * unsigned short tid2_rxseq;
44 * unsigned short tid3_rxseq;
45 * unsigned short tid4_rxseq;
46 * unsigned short tid5_rxseq;
47 * unsigned short tid6_rxseq;
48 * unsigned short tid7_rxseq;
49 * unsigned short tid8_rxseq;
50 * unsigned short tid9_rxseq;
51 * unsigned short tid10_rxseq;
52 * unsigned short tid11_rxseq;
53 * unsigned short tid12_rxseq;
54 * unsigned short tid13_rxseq;
55 * unsigned short tid14_rxseq;
56 * unsigned short tid15_rxseq;
57 */
58 };
59
60 struct signal_stat {
61 u8 update_req; /* used to indicate */
62 u8 avg_val; /* avg of valid elements */
63 u32 total_num; /* num of valid elements */
64 u32 total_val; /* sum of valid elements */
65 };
66 #define MAX_PATH_NUM_92CS 3
67 struct phy_info {
68 u8 RxPWDBAll;
69 u8 SignalQuality; /* in 0-100 index. */
70 u8 RxMIMOSignalQuality[MAX_PATH_NUM_92CS]; /* EVM */
71 u8 RxMIMOSignalStrength[MAX_PATH_NUM_92CS];/* in 0~100 index */
72 s8 RxPower; /* in dBm Translate from PWdB */
73 /* Real power in dBm for this packet, no beautification and aggregation.
74 * Keep this raw info to be used for the other procedures.
75 */
76 s8 recvpower;
77 u8 BTRxRSSIPercentage;
78 u8 SignalStrength; /* in 0-100 index. */
79 u8 RxPwr[MAX_PATH_NUM_92CS];/* per-path's pwdb */
80 u8 RxSNR[MAX_PATH_NUM_92CS];/* per-path's SNR */
81 };
82
83 struct rx_pkt_attrib {
84 u16 pkt_len;
85 u8 physt;
86 u8 drvinfo_sz;
87 u8 shift_sz;
88 u8 hdrlen; /* the WLAN Header Len */
89 u8 to_fr_ds;
90 u8 amsdu;
91 u8 qos;
92 u8 priority;
93 u8 pw_save;
94 u8 mdata;
95 u16 seq_num;
96 u8 frag_num;
97 u8 mfrag;
98 u8 order;
99 u8 privacy; /* in frame_ctrl field */
100 u8 bdecrypted;
101 u8 encrypt; /* when 0 indicate no encrypt. when non-zero,
102 * indicate the encrypt algorithm
103 */
104 u8 iv_len;
105 u8 icv_len;
106 u8 crc_err;
107 u8 icv_err;
108
109 u16 eth_type;
110
111 u8 dst[ETH_ALEN];
112 u8 src[ETH_ALEN];
113 u8 ta[ETH_ALEN];
114 u8 ra[ETH_ALEN];
115 u8 bssid[ETH_ALEN];
116
117 u8 ack_policy;
118
119 u8 key_index;
120
121 u8 mcs_rate;
122 u8 rxht;
123 u8 sgi;
124 u8 pkt_rpt_type;
125 u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */
126
127 struct phy_info phy_info;
128 };
129
130
131 /* These definition is used for Rx packet reordering. */
132 #define SN_LESS(a, b) (((a - b) & 0x800) != 0)
133 #define SN_EQUAL(a, b) (a == b)
134 #define REORDER_WAIT_TIME (50) /* (ms) */
135
136 #define RXDESC_SIZE 24
137 #define RXDESC_OFFSET RXDESC_SIZE
138
139 struct recv_stat {
140 __le32 rxdw0;
141 __le32 rxdw1;
142 __le32 rxdw2;
143 __le32 rxdw3;
144 __le32 rxdw4;
145 __le32 rxdw5;
146 };
147
148 /*
149 * accesser of recv_priv: rtw_recv_entry(dispatch / passive level);
150 * recv_thread(passive) ; returnpkt(dispatch)
151 * ; halt(passive) ;
152 *
153 * using enter_critical section to protect
154 */
155 struct recv_priv {
156 struct __queue free_recv_queue;
157 struct __queue recv_pending_queue;
158 struct __queue uc_swdec_pending_queue;
159 void *pallocated_frame_buf;
160 struct adapter *adapter;
161 u32 bIsAnyNonBEPkts;
162 u64 rx_bytes;
163 u64 rx_pkts;
164 u64 rx_drop;
165 u64 last_rx_bytes;
166
167 struct tasklet_struct irq_prepare_beacon_tasklet;
168 struct tasklet_struct recv_tasklet;
169 struct sk_buff_head free_recv_skb_queue;
170 struct sk_buff_head rx_skb_queue;
171 struct recv_buf *precv_buf; /* 4 alignment */
172 struct __queue free_recv_buf_queue;
173 /* For display the phy information */
174 s8 rssi;
175 s8 rxpwdb;
176 u8 signal_strength;
177 u8 signal_qual;
178 u8 noise;
179 s8 RxRssi[2];
180
181 struct timer_list signal_stat_timer;
182 u32 signal_stat_sampling_interval;
183 struct signal_stat signal_qual_data;
184 struct signal_stat signal_strength_data;
185 };
186
187 #define rtw_set_signal_stat_timer(recvpriv) \
188 mod_timer(&(recvpriv)->signal_stat_timer, jiffies + \
189 msecs_to_jiffies((recvpriv)->signal_stat_sampling_interval))
190
191 struct sta_recv_priv {
192 spinlock_t lock;
193 int option;
194 struct __queue defrag_q; /* keeping the fragment frame until defrag */
195 struct stainfo_rxcache rxcache;
196 };
197
198 struct recv_buf {
199 struct adapter *adapter;
200 struct urb *purb;
201 struct sk_buff *pskb;
202 u8 reuse;
203 };
204
205 /*
206 * head ----->
207 *
208 * data ----->
209 *
210 * payload
211 *
212 * tail ----->
213 *
214 *
215 * end ----->
216 *
217 * len = (unsigned int )(tail - data);
218 *
219 */
220 struct recv_frame {
221 struct list_head list;
222 struct sk_buff *pkt;
223 struct adapter *adapter;
224 struct rx_pkt_attrib attrib;
225 struct sta_info *psta;
226 /* for A-MPDU Rx reordering buffer control */
227 struct recv_reorder_ctrl *preorder_ctrl;
228 };
229
230 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
231 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
232 void rtw_init_recvframe(struct recv_frame *precvframe,
233 struct recv_priv *precvpriv);
234 int rtw_free_recvframe(struct recv_frame *precvframe,
235 struct __queue *pfree_recv_queue);
236 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
237 int _rtw_enqueue_recvframe(struct recv_frame *precvframe,
238 struct __queue *queue);
239 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue);
240 void rtw_free_recvframe_queue(struct __queue *pframequeue,
241 struct __queue *pfree_recv_queue);
242 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
243
244 void rtw_reordering_ctrl_timeout_handler(struct timer_list *t);
245
translate_percentage_to_dbm(u32 sig_stren_index)246 static inline s32 translate_percentage_to_dbm(u32 sig_stren_index)
247 {
248 s32 power; /* in dBm. */
249
250 /* Translate to dBm (x=0.5y-95). */
251 power = (s32)((sig_stren_index + 1) >> 1);
252 power -= 95;
253
254 return power;
255 }
256
257
258 struct sta_info;
259
260 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
261
262 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame);
263
264 #endif
265