9828f507b643eb1574373f53c6664eea75714286
[openwrt/openwrt.git] /
1 From bbb6f9be7f99464d5ab7e2f321fa728d33eeec9a Mon Sep 17 00:00:00 2001
2 From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
3 Date: Fri, 20 Sep 2024 22:27:30 +0300
4 Subject: [PATCH] wifi: rtw88: Parse the RX descriptor with a single function
5
6 rtw8703b_query_rx_desc(), rtw8723d_query_rx_desc(),
7 rtw8821c_query_rx_desc(), rtw8822b_query_rx_desc(), and
8 rtw8822c_query_rx_desc() are almost identical, so replace them all with
9 a single function, rtw_rx_query_rx_desc().
10
11 Also, access the RX descriptor using a struct with __le32 members and
12 le32_get_bits().
13
14 Tested with RTL8811CU, RTL8811AU, and RTL8812AU.
15
16 Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
17 Tested-by: Ping-Ke Shih <pkshih@realtek.com> # RTL8723DE and RTL8822CE
18 Acked-by: Ping-Ke Shih <pkshih@realtek.com>
19 Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
20 Link: https://patch.msgid.link/913f1747-38fc-4409-85a4-57bb9cee506b@gmail.com
21 ---
22 drivers/net/wireless/realtek/rtw88/main.h | 5 +-
23 drivers/net/wireless/realtek/rtw88/pci.c | 2 +-
24 drivers/net/wireless/realtek/rtw88/rtw8703b.c | 56 +--------------
25 drivers/net/wireless/realtek/rtw88/rtw8723d.c | 43 +-----------
26 drivers/net/wireless/realtek/rtw88/rtw8821c.c | 43 +-----------
27 drivers/net/wireless/realtek/rtw88/rtw8822b.c | 43 +-----------
28 drivers/net/wireless/realtek/rtw88/rtw8822c.c | 44 +-----------
29 drivers/net/wireless/realtek/rtw88/rx.c | 70 +++++++++++++++++--
30 drivers/net/wireless/realtek/rtw88/rx.h | 64 ++++++++---------
31 drivers/net/wireless/realtek/rtw88/sdio.c | 3 +-
32 drivers/net/wireless/realtek/rtw88/usb.c | 4 +-
33 11 files changed, 106 insertions(+), 271 deletions(-)
34
35 --- a/drivers/net/wireless/realtek/rtw88/main.h
36 +++ b/drivers/net/wireless/realtek/rtw88/main.h
37 @@ -848,9 +848,8 @@ struct rtw_chip_ops {
38 void (*phy_set_param)(struct rtw_dev *rtwdev);
39 void (*set_channel)(struct rtw_dev *rtwdev, u8 channel,
40 u8 bandwidth, u8 primary_chan_idx);
41 - void (*query_rx_desc)(struct rtw_dev *rtwdev, u8 *rx_desc,
42 - struct rtw_rx_pkt_stat *pkt_stat,
43 - struct ieee80211_rx_status *rx_status);
44 + void (*query_phy_status)(struct rtw_dev *rtwdev, u8 *phy_status,
45 + struct rtw_rx_pkt_stat *pkt_stat);
46 u32 (*read_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
47 u32 addr, u32 mask);
48 bool (*write_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
49 --- a/drivers/net/wireless/realtek/rtw88/pci.c
50 +++ b/drivers/net/wireless/realtek/rtw88/pci.c
51 @@ -1065,7 +1065,7 @@ static u32 rtw_pci_rx_napi(struct rtw_de
52 dma_sync_single_for_cpu(rtwdev->dev, dma, RTK_PCI_RX_BUF_SIZE,
53 DMA_FROM_DEVICE);
54 rx_desc = skb->data;
55 - chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat, &rx_status);
56 + rtw_rx_query_rx_desc(rtwdev, rx_desc, &pkt_stat, &rx_status);
57
58 /* offset from rx_desc to payload */
59 pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz +
60 --- a/drivers/net/wireless/realtek/rtw88/rtw8703b.c
61 +++ b/drivers/net/wireless/realtek/rtw88/rtw8703b.c
62 @@ -29,9 +29,6 @@
63 #define TBTT_PROHIBIT_HOLD_TIME 0x80
64 #define TBTT_PROHIBIT_HOLD_TIME_STOP_BCN 0x64
65
66 -/* raw pkt_stat->drv_info_sz is in unit of 8-bytes */
67 -#define RX_DRV_INFO_SZ_UNIT_8703B 8
68 -
69 #define TRANS_SEQ_END \
70 0xFFFF, \
71 RTW_PWR_CUT_ALL_MSK, \
72 @@ -1032,57 +1029,6 @@ static void query_phy_status(struct rtw_
73 query_phy_status_ofdm(rtwdev, phy_status, pkt_stat);
74 }
75
76 -static void rtw8703b_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc,
77 - struct rtw_rx_pkt_stat *pkt_stat,
78 - struct ieee80211_rx_status *rx_status)
79 -{
80 - struct ieee80211_hdr *hdr;
81 - u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz;
82 - u8 *phy_status = NULL;
83 -
84 - memset(pkt_stat, 0, sizeof(*pkt_stat));
85 -
86 - pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc);
87 - pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc);
88 - pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc);
89 - pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc) &&
90 - GET_RX_DESC_ENC_TYPE(rx_desc) != RX_DESC_ENC_NONE;
91 - pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc);
92 - pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc);
93 - pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc);
94 - pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc);
95 - pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc);
96 - pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc);
97 - pkt_stat->ppdu_cnt = 0;
98 - pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc);
99 -
100 - pkt_stat->drv_info_sz *= RX_DRV_INFO_SZ_UNIT_8703B;
101 -
102 - if (pkt_stat->is_c2h)
103 - return;
104 -
105 - hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift +
106 - pkt_stat->drv_info_sz);
107 -
108 - pkt_stat->bw = GET_RX_DESC_BW(rx_desc);
109 -
110 - if (pkt_stat->phy_status) {
111 - phy_status = rx_desc + desc_sz + pkt_stat->shift;
112 - query_phy_status(rtwdev, phy_status, pkt_stat);
113 - }
114 -
115 - rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status);
116 -
117 - /* Rtl8723cs driver checks for size < 14 or size > 8192 and
118 - * simply drops the packet. Maybe this should go into
119 - * rtw_rx_fill_rx_status()?
120 - */
121 - if (pkt_stat->pkt_len == 0) {
122 - rx_status->flag |= RX_FLAG_NO_PSDU;
123 - rtw_dbg(rtwdev, RTW_DBG_RX, "zero length packet");
124 - }
125 -}
126 -
127 #define ADDA_ON_VAL_8703B 0x03c00014
128
129 static
130 @@ -1948,7 +1894,7 @@ static const struct rtw_chip_ops rtw8703
131 .read_efuse = rtw8703b_read_efuse,
132 .phy_set_param = rtw8703b_phy_set_param,
133 .set_channel = rtw8703b_set_channel,
134 - .query_rx_desc = rtw8703b_query_rx_desc,
135 + .query_phy_status = query_phy_status,
136 .read_rf = rtw_phy_read_rf_sipi,
137 .write_rf = rtw_phy_write_rf_reg_sipi,
138 .set_tx_power_index = rtw8723x_set_tx_power_index,
139 --- a/drivers/net/wireless/realtek/rtw88/rtw8723d.c
140 +++ b/drivers/net/wireless/realtek/rtw88/rtw8723d.c
141 @@ -227,47 +227,6 @@ static void query_phy_status(struct rtw_
142 }
143 }
144
145 -static void rtw8723d_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc,
146 - struct rtw_rx_pkt_stat *pkt_stat,
147 - struct ieee80211_rx_status *rx_status)
148 -{
149 - struct ieee80211_hdr *hdr;
150 - u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz;
151 - u8 *phy_status = NULL;
152 -
153 - memset(pkt_stat, 0, sizeof(*pkt_stat));
154 -
155 - pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc);
156 - pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc);
157 - pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc);
158 - pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc) &&
159 - GET_RX_DESC_ENC_TYPE(rx_desc) != RX_DESC_ENC_NONE;
160 - pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc);
161 - pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc);
162 - pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc);
163 - pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc);
164 - pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc);
165 - pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc);
166 - pkt_stat->ppdu_cnt = 0;
167 - pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc);
168 -
169 - /* drv_info_sz is in unit of 8-bytes */
170 - pkt_stat->drv_info_sz *= 8;
171 -
172 - /* c2h cmd pkt's rx/phy status is not interested */
173 - if (pkt_stat->is_c2h)
174 - return;
175 -
176 - hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift +
177 - pkt_stat->drv_info_sz);
178 - if (pkt_stat->phy_status) {
179 - phy_status = rx_desc + desc_sz + pkt_stat->shift;
180 - query_phy_status(rtwdev, phy_status, pkt_stat);
181 - }
182 -
183 - rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status);
184 -}
185 -
186 static bool rtw8723d_check_spur_ov_thres(struct rtw_dev *rtwdev,
187 u8 channel, u32 thres)
188 {
189 @@ -1433,7 +1392,7 @@ static void rtw8723d_pwr_track(struct rt
190 static const struct rtw_chip_ops rtw8723d_ops = {
191 .phy_set_param = rtw8723d_phy_set_param,
192 .read_efuse = rtw8723x_read_efuse,
193 - .query_rx_desc = rtw8723d_query_rx_desc,
194 + .query_phy_status = query_phy_status,
195 .set_channel = rtw8723d_set_channel,
196 .mac_init = rtw8723x_mac_init,
197 .shutdown = rtw8723d_shutdown,
198 --- a/drivers/net/wireless/realtek/rtw88/rtw8821c.c
199 +++ b/drivers/net/wireless/realtek/rtw88/rtw8821c.c
200 @@ -679,47 +679,6 @@ static void query_phy_status(struct rtw_
201 }
202 }
203
204 -static void rtw8821c_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc,
205 - struct rtw_rx_pkt_stat *pkt_stat,
206 - struct ieee80211_rx_status *rx_status)
207 -{
208 - struct ieee80211_hdr *hdr;
209 - u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz;
210 - u8 *phy_status = NULL;
211 -
212 - memset(pkt_stat, 0, sizeof(*pkt_stat));
213 -
214 - pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc);
215 - pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc);
216 - pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc);
217 - pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc) &&
218 - GET_RX_DESC_ENC_TYPE(rx_desc) != RX_DESC_ENC_NONE;
219 - pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc);
220 - pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc);
221 - pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc);
222 - pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc);
223 - pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc);
224 - pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc);
225 - pkt_stat->ppdu_cnt = GET_RX_DESC_PPDU_CNT(rx_desc);
226 - pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc);
227 -
228 - /* drv_info_sz is in unit of 8-bytes */
229 - pkt_stat->drv_info_sz *= 8;
230 -
231 - /* c2h cmd pkt's rx/phy status is not interested */
232 - if (pkt_stat->is_c2h)
233 - return;
234 -
235 - hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift +
236 - pkt_stat->drv_info_sz);
237 - if (pkt_stat->phy_status) {
238 - phy_status = rx_desc + desc_sz + pkt_stat->shift;
239 - query_phy_status(rtwdev, phy_status, pkt_stat);
240 - }
241 -
242 - rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status);
243 -}
244 -
245 static void
246 rtw8821c_set_tx_power_index_by_rate(struct rtw_dev *rtwdev, u8 path, u8 rs)
247 {
248 @@ -1686,7 +1645,7 @@ static const struct rtw_prioq_addrs prio
249 static const struct rtw_chip_ops rtw8821c_ops = {
250 .phy_set_param = rtw8821c_phy_set_param,
251 .read_efuse = rtw8821c_read_efuse,
252 - .query_rx_desc = rtw8821c_query_rx_desc,
253 + .query_phy_status = query_phy_status,
254 .set_channel = rtw8821c_set_channel,
255 .mac_init = rtw8821c_mac_init,
256 .read_rf = rtw_phy_read_rf,
257 --- a/drivers/net/wireless/realtek/rtw88/rtw8822b.c
258 +++ b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
259 @@ -934,47 +934,6 @@ static void query_phy_status(struct rtw_
260 }
261 }
262
263 -static void rtw8822b_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc,
264 - struct rtw_rx_pkt_stat *pkt_stat,
265 - struct ieee80211_rx_status *rx_status)
266 -{
267 - struct ieee80211_hdr *hdr;
268 - u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz;
269 - u8 *phy_status = NULL;
270 -
271 - memset(pkt_stat, 0, sizeof(*pkt_stat));
272 -
273 - pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc);
274 - pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc);
275 - pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc);
276 - pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc) &&
277 - GET_RX_DESC_ENC_TYPE(rx_desc) != RX_DESC_ENC_NONE;
278 - pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc);
279 - pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc);
280 - pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc);
281 - pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc);
282 - pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc);
283 - pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc);
284 - pkt_stat->ppdu_cnt = GET_RX_DESC_PPDU_CNT(rx_desc);
285 - pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc);
286 -
287 - /* drv_info_sz is in unit of 8-bytes */
288 - pkt_stat->drv_info_sz *= 8;
289 -
290 - /* c2h cmd pkt's rx/phy status is not interested */
291 - if (pkt_stat->is_c2h)
292 - return;
293 -
294 - hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift +
295 - pkt_stat->drv_info_sz);
296 - if (pkt_stat->phy_status) {
297 - phy_status = rx_desc + desc_sz + pkt_stat->shift;
298 - query_phy_status(rtwdev, phy_status, pkt_stat);
299 - }
300 -
301 - rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status);
302 -}
303 -
304 static void
305 rtw8822b_set_tx_power_index_by_rate(struct rtw_dev *rtwdev, u8 path, u8 rs)
306 {
307 @@ -2175,7 +2134,7 @@ static const struct rtw_prioq_addrs prio
308 static const struct rtw_chip_ops rtw8822b_ops = {
309 .phy_set_param = rtw8822b_phy_set_param,
310 .read_efuse = rtw8822b_read_efuse,
311 - .query_rx_desc = rtw8822b_query_rx_desc,
312 + .query_phy_status = query_phy_status,
313 .set_channel = rtw8822b_set_channel,
314 .mac_init = rtw8822b_mac_init,
315 .read_rf = rtw_phy_read_rf,
316 --- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
317 +++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
318 @@ -2690,48 +2690,6 @@ static void query_phy_status(struct rtw_
319 }
320 }
321
322 -static void rtw8822c_query_rx_desc(struct rtw_dev *rtwdev, u8 *rx_desc,
323 - struct rtw_rx_pkt_stat *pkt_stat,
324 - struct ieee80211_rx_status *rx_status)
325 -{
326 - struct ieee80211_hdr *hdr;
327 - u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz;
328 - u8 *phy_status = NULL;
329 -
330 - memset(pkt_stat, 0, sizeof(*pkt_stat));
331 -
332 - pkt_stat->phy_status = GET_RX_DESC_PHYST(rx_desc);
333 - pkt_stat->icv_err = GET_RX_DESC_ICV_ERR(rx_desc);
334 - pkt_stat->crc_err = GET_RX_DESC_CRC32(rx_desc);
335 - pkt_stat->decrypted = !GET_RX_DESC_SWDEC(rx_desc) &&
336 - GET_RX_DESC_ENC_TYPE(rx_desc) != RX_DESC_ENC_NONE;
337 - pkt_stat->is_c2h = GET_RX_DESC_C2H(rx_desc);
338 - pkt_stat->pkt_len = GET_RX_DESC_PKT_LEN(rx_desc);
339 - pkt_stat->drv_info_sz = GET_RX_DESC_DRV_INFO_SIZE(rx_desc);
340 - pkt_stat->shift = GET_RX_DESC_SHIFT(rx_desc);
341 - pkt_stat->rate = GET_RX_DESC_RX_RATE(rx_desc);
342 - pkt_stat->cam_id = GET_RX_DESC_MACID(rx_desc);
343 - pkt_stat->ppdu_cnt = GET_RX_DESC_PPDU_CNT(rx_desc);
344 - pkt_stat->tsf_low = GET_RX_DESC_TSFL(rx_desc);
345 -
346 - /* drv_info_sz is in unit of 8-bytes */
347 - pkt_stat->drv_info_sz *= 8;
348 -
349 - /* c2h cmd pkt's rx/phy status is not interested */
350 - if (pkt_stat->is_c2h)
351 - return;
352 -
353 - hdr = (struct ieee80211_hdr *)(rx_desc + desc_sz + pkt_stat->shift +
354 - pkt_stat->drv_info_sz);
355 - pkt_stat->hdr = hdr;
356 - if (pkt_stat->phy_status) {
357 - phy_status = rx_desc + desc_sz + pkt_stat->shift;
358 - query_phy_status(rtwdev, phy_status, pkt_stat);
359 - }
360 -
361 - rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status, phy_status);
362 -}
363 -
364 static void
365 rtw8822c_set_write_tx_power_ref(struct rtw_dev *rtwdev, u8 *tx_pwr_ref_cck,
366 u8 *tx_pwr_ref_ofdm)
367 @@ -4991,7 +4949,7 @@ static const struct rtw_prioq_addrs prio
368 static const struct rtw_chip_ops rtw8822c_ops = {
369 .phy_set_param = rtw8822c_phy_set_param,
370 .read_efuse = rtw8822c_read_efuse,
371 - .query_rx_desc = rtw8822c_query_rx_desc,
372 + .query_phy_status = query_phy_status,
373 .set_channel = rtw8822c_set_channel,
374 .mac_init = rtw8822c_mac_init,
375 .dump_fw_crash = rtw8822c_dump_fw_crash,
376 --- a/drivers/net/wireless/realtek/rtw88/rx.c
377 +++ b/drivers/net/wireless/realtek/rtw88/rx.c
378 @@ -187,11 +187,10 @@ fill_rx_status:
379 }
380 EXPORT_SYMBOL(rtw_update_rx_freq_from_ie);
381
382 -void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
383 - struct rtw_rx_pkt_stat *pkt_stat,
384 - struct ieee80211_hdr *hdr,
385 - struct ieee80211_rx_status *rx_status,
386 - u8 *phy_status)
387 +static void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
388 + struct rtw_rx_pkt_stat *pkt_stat,
389 + struct ieee80211_hdr *hdr,
390 + struct ieee80211_rx_status *rx_status)
391 {
392 struct ieee80211_hw *hw = rtwdev->hw;
393 u8 path;
394 @@ -242,5 +241,64 @@ void rtw_rx_fill_rx_status(struct rtw_de
395 }
396
397 rtw_rx_addr_match(rtwdev, pkt_stat, hdr);
398 +
399 + /* Rtl8723cs driver checks for size < 14 or size > 8192 and
400 + * simply drops the packet.
401 + */
402 + if (rtwdev->chip->id == RTW_CHIP_TYPE_8703B && pkt_stat->pkt_len == 0) {
403 + rx_status->flag |= RX_FLAG_NO_PSDU;
404 + rtw_dbg(rtwdev, RTW_DBG_RX, "zero length packet");
405 + }
406 +}
407 +
408 +void rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
409 + struct rtw_rx_pkt_stat *pkt_stat,
410 + struct ieee80211_rx_status *rx_status)
411 +{
412 + u32 desc_sz = rtwdev->chip->rx_pkt_desc_sz;
413 + struct rtw_rx_desc *rx_desc = rx_desc8;
414 + struct ieee80211_hdr *hdr;
415 + u32 enc_type, swdec;
416 + void *phy_status;
417 +
418 + memset(pkt_stat, 0, sizeof(*pkt_stat));
419 +
420 + pkt_stat->pkt_len = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_PKT_LEN);
421 + pkt_stat->crc_err = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_CRC32);
422 + pkt_stat->icv_err = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_ICV_ERR);
423 + pkt_stat->drv_info_sz = le32_get_bits(rx_desc->w0,
424 + RTW_RX_DESC_W0_DRV_INFO_SIZE);
425 + enc_type = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_ENC_TYPE);
426 + pkt_stat->shift = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_SHIFT);
427 + pkt_stat->phy_status = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_PHYST);
428 + swdec = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_SWDEC);
429 + pkt_stat->decrypted = !swdec && enc_type != RX_DESC_ENC_NONE;
430 +
431 + pkt_stat->cam_id = le32_get_bits(rx_desc->w1, RTW_RX_DESC_W1_MACID);
432 +
433 + pkt_stat->is_c2h = le32_get_bits(rx_desc->w2, RTW_RX_DESC_W2_C2H);
434 + pkt_stat->ppdu_cnt = le32_get_bits(rx_desc->w2, RTW_RX_DESC_W2_PPDU_CNT);
435 +
436 + pkt_stat->rate = le32_get_bits(rx_desc->w3, RTW_RX_DESC_W3_RX_RATE);
437 +
438 + pkt_stat->bw = le32_get_bits(rx_desc->w4, RTW_RX_DESC_W4_BW);
439 +
440 + pkt_stat->tsf_low = le32_get_bits(rx_desc->w5, RTW_RX_DESC_W5_TSFL);
441 +
442 + /* drv_info_sz is in unit of 8-bytes */
443 + pkt_stat->drv_info_sz *= 8;
444 +
445 + /* c2h cmd pkt's rx/phy status is not interested */
446 + if (pkt_stat->is_c2h)
447 + return;
448 +
449 + phy_status = rx_desc8 + desc_sz + pkt_stat->shift;
450 + hdr = phy_status + pkt_stat->drv_info_sz;
451 + pkt_stat->hdr = hdr;
452 +
453 + if (pkt_stat->phy_status)
454 + rtwdev->chip->ops->query_phy_status(rtwdev, phy_status, pkt_stat);
455 +
456 + rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status);
457 }
458 -EXPORT_SYMBOL(rtw_rx_fill_rx_status);
459 +EXPORT_SYMBOL(rtw_rx_query_rx_desc);
460 --- a/drivers/net/wireless/realtek/rtw88/rx.h
461 +++ b/drivers/net/wireless/realtek/rtw88/rx.h
462 @@ -14,42 +14,40 @@ enum rtw_rx_desc_enc {
463 RX_DESC_ENC_WEP104 = 5,
464 };
465
466 -#define GET_RX_DESC_PHYST(rxdesc) \
467 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), BIT(26))
468 -#define GET_RX_DESC_ICV_ERR(rxdesc) \
469 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), BIT(15))
470 -#define GET_RX_DESC_CRC32(rxdesc) \
471 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), BIT(14))
472 -#define GET_RX_DESC_SWDEC(rxdesc) \
473 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), BIT(27))
474 -#define GET_RX_DESC_C2H(rxdesc) \
475 - le32_get_bits(*((__le32 *)(rxdesc) + 0x02), BIT(28))
476 -#define GET_RX_DESC_PKT_LEN(rxdesc) \
477 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), GENMASK(13, 0))
478 -#define GET_RX_DESC_DRV_INFO_SIZE(rxdesc) \
479 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), GENMASK(19, 16))
480 -#define GET_RX_DESC_SHIFT(rxdesc) \
481 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), GENMASK(25, 24))
482 -#define GET_RX_DESC_ENC_TYPE(rxdesc) \
483 - le32_get_bits(*((__le32 *)(rxdesc) + 0x00), GENMASK(22, 20))
484 -#define GET_RX_DESC_RX_RATE(rxdesc) \
485 - le32_get_bits(*((__le32 *)(rxdesc) + 0x03), GENMASK(6, 0))
486 -#define GET_RX_DESC_MACID(rxdesc) \
487 - le32_get_bits(*((__le32 *)(rxdesc) + 0x01), GENMASK(6, 0))
488 -#define GET_RX_DESC_PPDU_CNT(rxdesc) \
489 - le32_get_bits(*((__le32 *)(rxdesc) + 0x02), GENMASK(30, 29))
490 -#define GET_RX_DESC_TSFL(rxdesc) \
491 - le32_get_bits(*((__le32 *)(rxdesc) + 0x05), GENMASK(31, 0))
492 -#define GET_RX_DESC_BW(rxdesc) \
493 - (le32_get_bits(*((__le32 *)(rxdesc) + 0x04), GENMASK(5, 4)))
494 +struct rtw_rx_desc {
495 + __le32 w0;
496 + __le32 w1;
497 + __le32 w2;
498 + __le32 w3;
499 + __le32 w4;
500 + __le32 w5;
501 +} __packed;
502 +
503 +#define RTW_RX_DESC_W0_PKT_LEN GENMASK(13, 0)
504 +#define RTW_RX_DESC_W0_CRC32 BIT(14)
505 +#define RTW_RX_DESC_W0_ICV_ERR BIT(15)
506 +#define RTW_RX_DESC_W0_DRV_INFO_SIZE GENMASK(19, 16)
507 +#define RTW_RX_DESC_W0_ENC_TYPE GENMASK(22, 20)
508 +#define RTW_RX_DESC_W0_SHIFT GENMASK(25, 24)
509 +#define RTW_RX_DESC_W0_PHYST BIT(26)
510 +#define RTW_RX_DESC_W0_SWDEC BIT(27)
511 +
512 +#define RTW_RX_DESC_W1_MACID GENMASK(6, 0)
513 +
514 +#define RTW_RX_DESC_W2_C2H BIT(28)
515 +#define RTW_RX_DESC_W2_PPDU_CNT GENMASK(30, 29)
516 +
517 +#define RTW_RX_DESC_W3_RX_RATE GENMASK(6, 0)
518 +
519 +#define RTW_RX_DESC_W4_BW GENMASK(5, 4)
520 +
521 +#define RTW_RX_DESC_W5_TSFL GENMASK(31, 0)
522
523 void rtw_rx_stats(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
524 struct sk_buff *skb);
525 -void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
526 - struct rtw_rx_pkt_stat *pkt_stat,
527 - struct ieee80211_hdr *hdr,
528 - struct ieee80211_rx_status *rx_status,
529 - u8 *phy_status);
530 +void rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
531 + struct rtw_rx_pkt_stat *pkt_stat,
532 + struct ieee80211_rx_status *rx_status);
533 void rtw_update_rx_freq_from_ie(struct rtw_dev *rtwdev, struct sk_buff *skb,
534 struct ieee80211_rx_status *rx_status,
535 struct rtw_rx_pkt_stat *pkt_stat);
536 --- a/drivers/net/wireless/realtek/rtw88/sdio.c
537 +++ b/drivers/net/wireless/realtek/rtw88/sdio.c
538 @@ -981,8 +981,7 @@ static void rtw_sdio_rxfifo_recv(struct
539
540 while (true) {
541 rx_desc = skb->data;
542 - chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat,
543 - &rx_status);
544 + rtw_rx_query_rx_desc(rtwdev, rx_desc, &pkt_stat, &rx_status);
545 pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz +
546 pkt_stat.shift;
547
548 --- a/drivers/net/wireless/realtek/rtw88/usb.c
549 +++ b/drivers/net/wireless/realtek/rtw88/usb.c
550 @@ -570,8 +570,8 @@ static void rtw_usb_rx_handler(struct wo
551
552 do {
553 rx_desc = skb->data;
554 - chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat,
555 - &rx_status);
556 + rtw_rx_query_rx_desc(rtwdev, rx_desc, &pkt_stat,
557 + &rx_status);
558 pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz +
559 pkt_stat.shift;
560