This source file includes following definitions.
- initrecvbuf
- update_recvframe_attrib
- update_recvframe_phyinfo
- rtl8723bs_c2h_packet_handler
- try_alloc_recvframe
- rx_crc_err
- pkt_exceeds_tail
- rtl8723bs_recv_tasklet
- rtl8723bs_init_recv_priv
- rtl8723bs_free_recv_priv
1
2
3
4
5
6
7 #define _RTL8723BS_RECV_C_
8
9 #include <drv_types.h>
10 #include <rtw_debug.h>
11 #include <rtl8723b_hal.h>
12
13 static void initrecvbuf(struct recv_buf *precvbuf, struct adapter *padapter)
14 {
15 INIT_LIST_HEAD(&precvbuf->list);
16 spin_lock_init(&precvbuf->recvbuf_lock);
17
18 precvbuf->adapter = padapter;
19 }
20
21 static void update_recvframe_attrib(struct adapter *padapter,
22 union recv_frame *precvframe,
23 struct recv_stat *prxstat)
24 {
25 struct rx_pkt_attrib *pattrib;
26 struct recv_stat report;
27 PRXREPORT prxreport = (PRXREPORT)&report;
28
29 report.rxdw0 = prxstat->rxdw0;
30 report.rxdw1 = prxstat->rxdw1;
31 report.rxdw2 = prxstat->rxdw2;
32 report.rxdw3 = prxstat->rxdw3;
33 report.rxdw4 = prxstat->rxdw4;
34 report.rxdw5 = prxstat->rxdw5;
35
36 pattrib = &precvframe->u.hdr.attrib;
37 memset(pattrib, 0, sizeof(struct rx_pkt_attrib));
38
39
40 pattrib->pkt_rpt_type = prxreport->c2h_ind ? C2H_PACKET : NORMAL_RX;
41
42
43 if (pattrib->pkt_rpt_type == NORMAL_RX) {
44
45
46 pattrib->pkt_len = (u16)prxreport->pktlen;
47 pattrib->drvinfo_sz = (u8)(prxreport->drvinfosize << 3);
48 pattrib->physt = (u8)prxreport->physt;
49
50 pattrib->crc_err = (u8)prxreport->crc32;
51 pattrib->icv_err = (u8)prxreport->icverr;
52
53 pattrib->bdecrypted = (u8)(prxreport->swdec ? 0 : 1);
54 pattrib->encrypt = (u8)prxreport->security;
55
56 pattrib->qos = (u8)prxreport->qos;
57 pattrib->priority = (u8)prxreport->tid;
58
59 pattrib->amsdu = (u8)prxreport->amsdu;
60
61 pattrib->seq_num = (u16)prxreport->seq;
62 pattrib->frag_num = (u8)prxreport->frag;
63 pattrib->mfrag = (u8)prxreport->mf;
64 pattrib->mdata = (u8)prxreport->md;
65
66 pattrib->data_rate = (u8)prxreport->rx_rate;
67 } else {
68 pattrib->pkt_len = (u16)prxreport->pktlen;
69 }
70 }
71
72
73
74
75
76
77 static void update_recvframe_phyinfo(union recv_frame *precvframe,
78 struct phy_stat *pphy_status)
79 {
80 struct adapter *padapter = precvframe->u.hdr.adapter;
81 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
82 struct hal_com_data *p_hal_data = GET_HAL_DATA(padapter);
83 struct odm_phy_info *p_phy_info =
84 (struct odm_phy_info *)(&pattrib->phy_info);
85
86 u8 *wlanhdr;
87 u8 *my_bssid;
88 u8 *rx_bssid;
89 u8 *rx_ra;
90 u8 *my_hwaddr;
91 u8 *sa = NULL;
92
93 struct odm_packet_info pkt_info = {
94 .data_rate = 0x00,
95 .station_id = 0x00,
96 .bssid_match = false,
97 .to_self = false,
98 .is_beacon = false,
99 };
100
101
102 struct sta_priv *pstapriv;
103 struct sta_info *psta;
104
105 wlanhdr = get_recvframe_data(precvframe);
106 my_bssid = get_bssid(&padapter->mlmepriv);
107 rx_bssid = get_hdr_bssid(wlanhdr);
108 pkt_info.bssid_match = ((!IsFrameTypeCtrl(wlanhdr)) &&
109 !pattrib->icv_err && !pattrib->crc_err &&
110 ether_addr_equal(rx_bssid, my_bssid));
111
112 rx_ra = get_ra(wlanhdr);
113 my_hwaddr = myid(&padapter->eeprompriv);
114 pkt_info.to_self = pkt_info.bssid_match &&
115 ether_addr_equal(rx_ra, my_hwaddr);
116
117
118 pkt_info.is_beacon = pkt_info.bssid_match &&
119 (GetFrameSubType(wlanhdr) == WIFI_BEACON);
120
121 sa = get_ta(wlanhdr);
122
123 pkt_info.station_id = 0xFF;
124
125 pstapriv = &padapter->stapriv;
126 psta = rtw_get_stainfo(pstapriv, sa);
127 if (psta) {
128 pkt_info.station_id = psta->mac_id;
129
130
131 }
132 pkt_info.data_rate = pattrib->data_rate;
133
134
135
136 ODM_PhyStatusQuery(&p_hal_data->odmpriv, p_phy_info,
137 (u8 *)pphy_status, &(pkt_info));
138 if (psta)
139 psta->rssi = pattrib->phy_info.RecvSignalPower;
140
141 precvframe->u.hdr.psta = NULL;
142 if (
143 pkt_info.bssid_match &&
144 (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == true)
145 ) {
146 if (psta) {
147 precvframe->u.hdr.psta = psta;
148 rtl8723b_process_phy_info(padapter, precvframe);
149 }
150 } else if (pkt_info.to_self || pkt_info.is_beacon) {
151 u32 adhoc_state = WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE;
152 if (check_fwstate(&padapter->mlmepriv, adhoc_state))
153 if (psta)
154 precvframe->u.hdr.psta = psta;
155 rtl8723b_process_phy_info(padapter, precvframe);
156 }
157 }
158
159 static void rtl8723bs_c2h_packet_handler(struct adapter *padapter,
160 u8 *pbuf, u16 length)
161 {
162 u8 *tmp = NULL;
163 u8 res = false;
164
165 if (length == 0)
166 return;
167
168
169
170 tmp = rtw_zmalloc(length);
171 if (!tmp)
172 return;
173
174 memcpy(tmp, pbuf, length);
175
176 res = rtw_c2h_packet_wk_cmd(padapter, tmp, length);
177
178 if (!res)
179 kfree(tmp);
180
181
182
183 return;
184 }
185
186 static inline union recv_frame *try_alloc_recvframe(struct recv_priv *precvpriv,
187 struct recv_buf *precvbuf)
188 {
189 union recv_frame *precvframe;
190
191 precvframe = rtw_alloc_recvframe(&precvpriv->free_recv_queue);
192 if (!precvframe) {
193 DBG_8192C("%s: no enough recv frame!\n", __func__);
194 rtw_enqueue_recvbuf_to_head(precvbuf,
195 &precvpriv->recv_buf_pending_queue);
196
197
198
199 tasklet_schedule(&precvpriv->recv_tasklet);
200 }
201
202 return precvframe;
203 }
204
205 static inline bool rx_crc_err(struct recv_priv *precvpriv,
206 struct hal_com_data *p_hal_data,
207 struct rx_pkt_attrib *pattrib,
208 union recv_frame *precvframe)
209 {
210
211 if ((!(p_hal_data->ReceiveConfig & RCR_ACRC32)) && pattrib->crc_err) {
212 DBG_8192C("%s()-%d: RX Warning! rx CRC ERROR !!\n",
213 __func__, __LINE__);
214 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
215 return true;
216 }
217
218 return false;
219 }
220
221 static inline bool pkt_exceeds_tail(struct recv_priv *precvpriv,
222 u8 *end, u8 *tail,
223 union recv_frame *precvframe)
224 {
225 if (end > tail) {
226 DBG_8192C("%s()-%d: : next pkt len(%p,%d) exceed ptail(%p)!\n",
227 __func__, __LINE__, ptr, pkt_offset, precvbuf->ptail);
228 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
229 return true;
230 }
231
232 return false;
233 }
234
235 static void rtl8723bs_recv_tasklet(void *priv)
236 {
237 struct adapter *padapter;
238 struct hal_com_data *p_hal_data;
239 struct recv_priv *precvpriv;
240 struct recv_buf *precvbuf;
241 union recv_frame *precvframe;
242 struct rx_pkt_attrib *pattrib;
243 struct __queue *recv_buf_queue;
244 u8 *ptr;
245 u32 pkt_offset, skb_len, alloc_sz;
246 _pkt *pkt_copy = NULL;
247 u8 shift_sz = 0, rx_report_sz = 0;
248
249 padapter = priv;
250 p_hal_data = GET_HAL_DATA(padapter);
251 precvpriv = &padapter->recvpriv;
252 recv_buf_queue = &precvpriv->recv_buf_pending_queue;
253
254 do {
255 precvbuf = rtw_dequeue_recvbuf(recv_buf_queue);
256 if (!precvbuf)
257 break;
258
259 ptr = precvbuf->pdata;
260
261 while (ptr < precvbuf->ptail) {
262 precvframe = try_alloc_recvframe(precvpriv, precvbuf);
263 if (!precvframe)
264 return;
265
266
267 update_recvframe_attrib(padapter, precvframe,
268 (struct recv_stat *)ptr);
269
270 pattrib = &precvframe->u.hdr.attrib;
271
272 if (rx_crc_err(precvpriv, p_hal_data,
273 pattrib, precvframe))
274 break;
275
276 rx_report_sz = RXDESC_SIZE + pattrib->drvinfo_sz;
277 pkt_offset = rx_report_sz +
278 pattrib->shift_sz +
279 pattrib->pkt_len;
280
281 if (pkt_exceeds_tail(precvpriv, ptr + pkt_offset,
282 precvbuf->ptail, precvframe))
283 break;
284
285 if ((pattrib->crc_err) || (pattrib->icv_err)) {
286 DBG_8192C("%s: crc_err =%d icv_err =%d, skip!\n",
287 __func__, pattrib->crc_err,
288 pattrib->icv_err);
289 rtw_free_recvframe(precvframe,
290 &precvpriv->free_recv_queue);
291 } else {
292
293
294 if (pattrib->qos)
295 shift_sz = 6;
296 else
297 shift_sz = 0;
298
299 skb_len = pattrib->pkt_len;
300
301
302
303 if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
304 if (skb_len <= 1650)
305 alloc_sz = 1664;
306 else
307 alloc_sz = skb_len + 14;
308 } else {
309 alloc_sz = skb_len;
310
311
312 alloc_sz += 14;
313 }
314
315 pkt_copy = rtw_skb_alloc(alloc_sz);
316
317 if (pkt_copy) {
318 pkt_copy->dev = padapter->pnetdev;
319 precvframe->u.hdr.pkt = pkt_copy;
320 skb_reserve(pkt_copy, 8 - ((SIZE_PTR)(pkt_copy->data) & 7));
321 skb_reserve(pkt_copy, shift_sz);
322 memcpy(pkt_copy->data, (ptr + rx_report_sz + pattrib->shift_sz), skb_len);
323 precvframe->u.hdr.rx_head = pkt_copy->head;
324 precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pkt_copy->data;
325 precvframe->u.hdr.rx_end = skb_end_pointer(pkt_copy);
326 } else {
327 if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
328 DBG_8192C("%s: alloc_skb fail, drop frag frame\n", __func__);
329 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
330 break;
331 }
332
333 precvframe->u.hdr.pkt = rtw_skb_clone(precvbuf->pskb);
334 if (precvframe->u.hdr.pkt) {
335 _pkt *pkt_clone = precvframe->u.hdr.pkt;
336
337 pkt_clone->data = ptr + rx_report_sz + pattrib->shift_sz;
338 skb_reset_tail_pointer(pkt_clone);
339 precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail
340 = pkt_clone->data;
341 precvframe->u.hdr.rx_end = pkt_clone->data + skb_len;
342 } else {
343 DBG_8192C("%s: rtw_skb_clone fail\n", __func__);
344 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
345 break;
346 }
347 }
348
349 recvframe_put(precvframe, skb_len);
350
351
352 if (p_hal_data->ReceiveConfig & RCR_APPFCS)
353 recvframe_pull_tail(precvframe, IEEE80211_FCS_LEN);
354
355
356 ptr += RXDESC_SIZE;
357
358
359 if (p_hal_data->ReceiveConfig & RCR_APP_BA_SSN) {
360
361 ptr += 4;
362 }
363
364 if (pattrib->pkt_rpt_type == NORMAL_RX) {
365 if (pattrib->physt)
366 update_recvframe_phyinfo(precvframe, (struct phy_stat *)ptr);
367
368 if (rtw_recv_entry(precvframe) != _SUCCESS) {
369 RT_TRACE(_module_rtl871x_recv_c_, _drv_dump_, ("%s: rtw_recv_entry(precvframe) != _SUCCESS\n", __func__));
370 }
371 } else if (pattrib->pkt_rpt_type == C2H_PACKET) {
372 C2H_EVT_HDR C2hEvent;
373
374 u16 len_c2h = pattrib->pkt_len;
375 u8 *pbuf_c2h = precvframe->u.hdr.rx_data;
376 u8 *pdata_c2h;
377
378 C2hEvent.CmdID = pbuf_c2h[0];
379 C2hEvent.CmdSeq = pbuf_c2h[1];
380 C2hEvent.CmdLen = (len_c2h-2);
381 pdata_c2h = pbuf_c2h+2;
382
383 if (C2hEvent.CmdID == C2H_CCX_TX_RPT)
384 CCX_FwC2HTxRpt_8723b(padapter, pdata_c2h, C2hEvent.CmdLen);
385 else
386 rtl8723bs_c2h_packet_handler(padapter, precvframe->u.hdr.rx_data, pattrib->pkt_len);
387
388 rtw_free_recvframe(precvframe, &precvpriv->free_recv_queue);
389 }
390 }
391
392 pkt_offset = _RND8(pkt_offset);
393 precvbuf->pdata += pkt_offset;
394 ptr = precvbuf->pdata;
395 precvframe = NULL;
396 pkt_copy = NULL;
397 }
398
399 rtw_enqueue_recvbuf(precvbuf, &precvpriv->free_recv_buf_queue);
400 } while (1);
401 }
402
403
404
405
406
407
408
409 s32 rtl8723bs_init_recv_priv(struct adapter *padapter)
410 {
411 s32 res;
412 u32 i, n;
413 struct recv_priv *precvpriv;
414 struct recv_buf *precvbuf;
415
416 res = _SUCCESS;
417 precvpriv = &padapter->recvpriv;
418
419
420 _rtw_init_queue(&precvpriv->free_recv_buf_queue);
421 _rtw_init_queue(&precvpriv->recv_buf_pending_queue);
422
423 n = NR_RECVBUFF * sizeof(struct recv_buf) + 4;
424 precvpriv->pallocated_recv_buf = rtw_zmalloc(n);
425 if (!precvpriv->pallocated_recv_buf) {
426 res = _FAIL;
427 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("alloc recv_buf fail!\n"));
428 goto exit;
429 }
430
431 precvpriv->precv_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(precvpriv->pallocated_recv_buf), 4);
432
433
434 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
435 for (i = 0; i < NR_RECVBUFF; i++) {
436 initrecvbuf(precvbuf, padapter);
437
438 if (!precvbuf->pskb) {
439 SIZE_PTR tmpaddr = 0;
440 SIZE_PTR alignment = 0;
441
442 precvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
443
444 if (precvbuf->pskb) {
445 precvbuf->pskb->dev = padapter->pnetdev;
446
447 tmpaddr = (SIZE_PTR)precvbuf->pskb->data;
448 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
449 skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
450 }
451
452 if (!precvbuf->pskb) {
453 DBG_871X("%s: alloc_skb fail!\n", __func__);
454 }
455 }
456
457 list_add_tail(&precvbuf->list, &precvpriv->free_recv_buf_queue.queue);
458
459 precvbuf++;
460 }
461 precvpriv->free_recv_buf_queue_cnt = i;
462
463 if (res == _FAIL)
464 goto initbuferror;
465
466
467 tasklet_init(
468 &precvpriv->recv_tasklet,
469 (void(*)(unsigned long))rtl8723bs_recv_tasklet,
470 (unsigned long)padapter
471 );
472
473 goto exit;
474
475 initbuferror:
476 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
477 if (precvbuf) {
478 n = precvpriv->free_recv_buf_queue_cnt;
479 precvpriv->free_recv_buf_queue_cnt = 0;
480 for (i = 0; i < n ; i++) {
481 list_del_init(&precvbuf->list);
482 rtw_os_recvbuf_resource_free(padapter, precvbuf);
483 precvbuf++;
484 }
485 precvpriv->precv_buf = NULL;
486 }
487
488 if (precvpriv->pallocated_recv_buf) {
489 kfree(precvpriv->pallocated_recv_buf);
490 precvpriv->pallocated_recv_buf = NULL;
491 }
492
493 exit:
494 return res;
495 }
496
497
498
499
500
501
502
503 void rtl8723bs_free_recv_priv(struct adapter *padapter)
504 {
505 u32 i;
506 struct recv_priv *precvpriv;
507 struct recv_buf *precvbuf;
508
509 precvpriv = &padapter->recvpriv;
510
511
512 tasklet_kill(&precvpriv->recv_tasklet);
513
514
515 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
516 if (precvbuf) {
517 precvpriv->free_recv_buf_queue_cnt = 0;
518 for (i = 0; i < NR_RECVBUFF; i++) {
519 list_del_init(&precvbuf->list);
520 rtw_os_recvbuf_resource_free(padapter, precvbuf);
521 precvbuf++;
522 }
523 precvpriv->precv_buf = NULL;
524 }
525
526 if (precvpriv->pallocated_recv_buf) {
527 kfree(precvpriv->pallocated_recv_buf);
528 precvpriv->pallocated_recv_buf = NULL;
529 }
530 }