1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2017 Realtek Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 *****************************************************************************/
16 #ifndef _RTW_RECV_H_
17 #define _RTW_RECV_H_
18
19 #define RTW_RX_MSDU_ACT_NONE 0
20 #define RTW_RX_MSDU_ACT_INDICATE BIT0
21 #define RTW_RX_MSDU_ACT_FORWARD BIT1
22
23 #ifdef CONFIG_SINGLE_RECV_BUF
24 #define NR_RECVBUFF (1)
25 #else
26 #if defined(CONFIG_GSPI_HCI)
27 #define NR_RECVBUFF (32)
28 #elif defined(CONFIG_SDIO_HCI)
29 #define NR_RECVBUFF (8)
30 #else
31 #define NR_RECVBUFF (8)
32 #endif
33 #endif /* CONFIG_SINGLE_RECV_BUF */
34 #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
35 #define NR_PREALLOC_RECV_SKB (rtw_rtkm_get_nr_recv_skb()>>1)
36 #else /*!CONFIG_PREALLOC_RX_SKB_BUFFER */
37 #define NR_PREALLOC_RECV_SKB 8
38 #endif /* CONFIG_PREALLOC_RX_SKB_BUFFER */
39
40 #ifdef CONFIG_RTW_NAPI
41 #define RTL_NAPI_WEIGHT (32)
42 #endif
43
44
45 #if defined(CONFIG_RTL8821C) && defined(CONFIG_SDIO_HCI) && defined(CONFIG_RECV_THREAD_MODE)
46 #ifdef NR_RECVBUFF
47 #undef NR_RECVBUFF
48 #define NR_RECVBUFF (32)
49 #endif
50 #endif
51
52 #define NR_RECVFRAME 256
53
54 #define RXFRAME_ALIGN 8
55 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
56
57 #define DRVINFO_SZ 4 /* unit is 8bytes */
58
59 #define MAX_RXFRAME_CNT 512
60 #define MAX_RX_NUMBLKS (32)
61 #define RECVFRAME_HDR_ALIGN 128
62 #define MAX_CONTINUAL_NORXPACKET_COUNT 4 /* In MAX_CONTINUAL_NORXPACKET_COUNT*2 sec , no rx traffict would issue DELBA*/
63
64 #define PHY_RSSI_SLID_WIN_MAX 100
65 #define PHY_LINKQUALITY_SLID_WIN_MAX 20
66
67
68 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
69
70 #define RX_MPDU_QUEUE 0
71 #define RX_CMD_QUEUE 1
72 #define RX_MAX_QUEUE 2
73
74 #define MAX_SUBFRAME_COUNT 64
75 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
76 extern u8 rtw_bridge_tunnel_header[];
77 extern u8 rtw_rfc1042_header[];
78
79 /* for Rx reordering buffer control */
80 struct recv_reorder_ctrl {
81 _adapter *padapter;
82 u8 tid;
83 u8 enable;
84 u16 indicate_seq;/* =wstart_b, init_value=0xffff */
85 u16 wend_b;
86 u8 wsize_b;
87 u8 ampdu_size;
88 _queue pending_recvframe_queue;
89 _timer reordering_ctrl_timer;
90 u8 bReorderWaiting;
91 };
92
93 struct stainfo_rxcache {
94 u16 tid_rxseq[16];
95 u8 iv[16][8];
96 u8 last_tid;
97 #if 0
98 unsigned short tid0_rxseq;
99 unsigned short tid1_rxseq;
100 unsigned short tid2_rxseq;
101 unsigned short tid3_rxseq;
102 unsigned short tid4_rxseq;
103 unsigned short tid5_rxseq;
104 unsigned short tid6_rxseq;
105 unsigned short tid7_rxseq;
106 unsigned short tid8_rxseq;
107 unsigned short tid9_rxseq;
108 unsigned short tid10_rxseq;
109 unsigned short tid11_rxseq;
110 unsigned short tid12_rxseq;
111 unsigned short tid13_rxseq;
112 unsigned short tid14_rxseq;
113 unsigned short tid15_rxseq;
114 #endif
115 };
116
117
118 struct smooth_rssi_data {
119 u32 elements[100]; /* array to store values */
120 u32 index; /* index to current array to store */
121 u32 total_num; /* num of valid elements */
122 u32 total_val; /* sum of valid elements */
123 };
124
125 struct signal_stat {
126 u8 update_req; /* used to indicate */
127 u8 avg_val; /* avg of valid elements */
128 u32 total_num; /* num of valid elements */
129 u32 total_val; /* sum of valid elements */
130 };
131
132 struct rx_raw_rssi {
133 u8 data_rate;
134 u8 pwdball;
135 s8 pwr_all;
136
137 u8 mimo_signal_strength[4];/* in 0~100 index */
138 u8 mimo_signal_quality[4];
139
140 s8 ofdm_pwr[4];
141 u8 ofdm_snr[4];
142 };
143
144
145 #include "cmn_info/rtw_sta_info.h"
146
147 struct rx_pkt_attrib {
148 u16 pkt_len;
149 u8 physt;
150 u8 drvinfo_sz;
151 u8 shift_sz;
152 u8 hdrlen; /* the WLAN Header Len */
153 u8 to_fr_ds;
154 u8 amsdu;
155 u8 qos;
156 u8 priority;
157 u8 pw_save;
158 u8 mdata;
159 u16 seq_num;
160 u8 frag_num;
161 u8 mfrag;
162 u8 order;
163 u8 privacy; /* in frame_ctrl field */
164 u8 bdecrypted;
165 u8 encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */
166 u8 iv_len;
167 u8 icv_len;
168 u8 crc_err;
169 u8 icv_err;
170
171 u16 eth_type;
172
173 u8 dst[ETH_ALEN];
174 u8 src[ETH_ALEN];
175 u8 ta[ETH_ALEN];
176 u8 ra[ETH_ALEN];
177 u8 bssid[ETH_ALEN];
178 #ifdef CONFIG_RTW_MESH
179 u8 msa[ETH_ALEN]; /* mesh sa */
180 u8 mda[ETH_ALEN]; /* mesh da */
181 u8 mesh_ctrl_present;
182 u8 mesh_ctrl_len; /* length of mesh control field */
183 #endif
184
185 u8 ack_policy;
186
187 u8 key_index;
188
189 u8 data_rate;
190 u8 ch; /* RX channel */
191 u8 bw;
192 u8 stbc;
193 u8 ldpc;
194 u8 sgi;
195 u8 pkt_rpt_type;
196 u32 tsfl;
197 u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */
198 u8 ppdu_cnt;
199 u32 free_cnt; /* free run counter */
200 struct phydm_phyinfo_struct phy_info;
201
202 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
203 /* checksum offload realted varaiables */
204 u8 csum_valid; /* Checksum valid, 0: not check, 1: checked */
205 u8 csum_err; /* Checksum Error occurs */
206 #endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
207 };
208
209 #ifdef CONFIG_RTW_MESH
210 #define RATTRIB_GET_MCTRL_LEN(rattrib) ((rattrib)->mesh_ctrl_len)
211 #else
212 #define RATTRIB_GET_MCTRL_LEN(rattrib) 0
213 #endif
214
215 /* These definition is used for Rx packet reordering. */
216 #define SN_LESS(a, b) (((a-b) & 0x800) != 0)
217 #define SN_EQUAL(a, b) (a == b)
218 /* #define REORDER_WIN_SIZE 128 */
219 /* #define REORDER_ENTRY_NUM 128 */
220 #define REORDER_WAIT_TIME (50) /* (ms) */
221
222 #if defined(CONFIG_PLATFORM_RTK390X) && defined(CONFIG_USB_HCI)
223 #define RECVBUFF_ALIGN_SZ 32
224 #else
225 #define RECVBUFF_ALIGN_SZ 8
226 #endif
227
228 #ifdef CONFIG_TRX_BD_ARCH
229 #define RX_WIFI_INFO_SIZE 24
230 #elif (defined(CONFIG_RTL8192E) || defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B)) && defined(CONFIG_PCI_HCI)
231 #define RXBD_SIZE sizeof(struct recv_stat)
232 #endif
233
234 #define RXDESC_SIZE 24
235 #define RXDESC_OFFSET RXDESC_SIZE
236
237 #ifdef CONFIG_TRX_BD_ARCH
238 struct rx_buf_desc {
239 /* RX has exactly one segment */
240 #ifdef CONFIG_64BIT_DMA
241 unsigned int dword[4];
242 #else
243 unsigned int dword[2];
244 #endif
245 };
246
247 struct recv_stat {
248 unsigned int rxdw[8];
249 };
250 #else
251 struct recv_stat {
252 unsigned int rxdw0;
253
254 unsigned int rxdw1;
255
256 #if !((defined(CONFIG_RTL8192E) || defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C) || defined(CONFIG_RTL8822C)) && defined(CONFIG_PCI_HCI)) /* exclude 8192ee, 8814ae, 8822be, 8821ce */
257 unsigned int rxdw2;
258
259 unsigned int rxdw3;
260 #endif
261
262 #ifndef BUF_DESC_ARCH
263 unsigned int rxdw4;
264
265 unsigned int rxdw5;
266
267 #ifdef CONFIG_PCI_HCI
268 unsigned int rxdw6;
269
270 unsigned int rxdw7;
271 #endif
272 #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */
273 };
274 #endif
275
276 #define EOR BIT(30)
277
278 #ifdef CONFIG_PCI_HCI
279 #define PCI_MAX_RX_QUEUE 1/* MSDU packet queue, Rx Command Queue */
280 #define PCI_MAX_RX_COUNT 128
281 #ifdef CONFIG_TRX_BD_ARCH
282 #define RX_BD_NUM PCI_MAX_RX_COUNT /* alias */
283 #endif
284
285 struct rtw_rx_ring {
286 #ifdef CONFIG_TRX_BD_ARCH
287 struct rx_buf_desc *buf_desc;
288 #else
289 struct recv_stat *desc;
290 #endif
291 dma_addr_t dma;
292 unsigned int idx;
293 struct sk_buff *rx_buf[PCI_MAX_RX_COUNT];
294 };
295 #endif
296
297
298
299 /*
300 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
301 ; halt(passive) ;
302
303 using enter_critical section to protect
304 */
305
306 #ifndef DBG_RX_BH_TRACKING
307 #define DBG_RX_BH_TRACKING 0
308 #endif
309
310 struct recv_priv {
311 _lock lock;
312
313 #ifdef CONFIG_RECV_THREAD_MODE
314 _sema recv_sema;
315
316 #endif
317
318 /* _queue blk_strms[MAX_RX_NUMBLKS]; */ /* keeping the block ack frame until return ack */
319 _queue free_recv_queue;
320 _queue recv_pending_queue;
321 _queue uc_swdec_pending_queue;
322
323
324 u8 *pallocated_frame_buf;
325 u8 *precv_frame_buf;
326
327 uint free_recvframe_cnt;
328
329 #if DBG_RX_BH_TRACKING
330 u32 rx_bh_stage;
331 u32 rx_bh_buf_dq_cnt;
332 void *rx_bh_lbuf;
333 void *rx_bh_cbuf;
334 void *rx_bh_cbuf_data;
335 u32 rx_bh_cbuf_dlen;
336 u32 rx_bh_cbuf_pos;
337 void *rx_bh_cframe;
338 #endif
339
340 _adapter *adapter;
341
342 u32 is_any_non_be_pkts;
343
344 u64 rx_bytes;
345 u64 rx_pkts;
346 u64 rx_drop;
347
348 u64 dbg_rx_drop_count;
349 u64 dbg_rx_ampdu_drop_count;
350 u64 dbg_rx_ampdu_forced_indicate_count;
351 u64 dbg_rx_ampdu_loss_count;
352 u64 dbg_rx_dup_mgt_frame_drop_count;
353 u64 dbg_rx_ampdu_window_shift_cnt;
354 u64 dbg_rx_conflic_mac_addr_cnt;
355
356 uint rx_icv_err;
357 uint rx_largepacket_crcerr;
358 uint rx_smallpacket_crcerr;
359 uint rx_middlepacket_crcerr;
360
361 #ifdef CONFIG_USB_HCI
362 /* u8 *pallocated_urb_buf; */
363 _sema allrxreturnevt;
364 uint ff_hwaddr;
365 ATOMIC_T rx_pending_cnt;
366
367 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
368 #ifdef PLATFORM_LINUX
369 PURB int_in_urb;
370 #endif
371
372 u8 *int_in_buf;
373 #endif /* CONFIG_USB_INTERRUPT_IN_PIPE */
374
375 #endif
376 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
377 _tasklet irq_prepare_beacon_tasklet;
378 _tasklet recv_tasklet;
379
380 struct sk_buff_head free_recv_skb_queue;
381 struct sk_buff_head rx_skb_queue;
382 #ifdef CONFIG_RTW_NAPI
383 struct sk_buff_head rx_napi_skb_queue;
384 #endif
385 #ifdef CONFIG_RX_INDICATE_QUEUE
386 _tasklet rx_indicate_tasklet;
387 struct ifqueue rx_indicate_queue;
388 #endif /* CONFIG_RX_INDICATE_QUEUE */
389
390 #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) */
391
392 u8 *pallocated_recv_buf;
393 u8 *precv_buf; /* 4 alignment */
394 _queue free_recv_buf_queue;
395 u32 free_recv_buf_queue_cnt;
396
397 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) || defined(CONFIG_USB_HCI)
398 _queue recv_buf_pending_queue;
399 #endif
400
401 #ifdef CONFIG_PCI_HCI
402 /* Rx */
403 struct rtw_rx_ring rx_ring[PCI_MAX_RX_QUEUE];
404 int rxringcount; /* size should be PCI_MAX_RX_QUEUE */
405 u32 rxbuffersize;
406 #endif
407
408 /* For display the phy informatiom */
409 u8 is_signal_dbg; /* for debug */
410 u8 signal_strength_dbg; /* for debug */
411
412 u8 signal_strength;
413 u8 signal_qual;
414 s8 rssi; /* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
415 struct rx_raw_rssi raw_rssi_info;
416 /* s8 rxpwdb; */
417 /* int RxSNRdB[2]; */
418 /* s8 RxRssi[2]; */
419 /* int FalseAlmCnt_all; */
420
421
422 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
423 _timer signal_stat_timer;
424 u32 signal_stat_sampling_interval;
425 /* u32 signal_stat_converging_constant; */
426 struct signal_stat signal_qual_data;
427 struct signal_stat signal_strength_data;
428 #else /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
429 struct smooth_rssi_data signal_qual_data;
430 struct smooth_rssi_data signal_strength_data;
431 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
432 u16 sink_udpport, pre_rtp_rxseq, cur_rtp_rxseq;
433
434 BOOLEAN store_law_data_flag;
435 };
436
437 #define RX_BH_STG_UNKNOWN 0
438 #define RX_BH_STG_HDL_ENTER 1
439 #define RX_BH_STG_HDL_EXIT 2
440 #define RX_BH_STG_NEW_BUF 3
441 #define RX_BH_STG_NEW_FRAME 4
442 #define RX_BH_STG_NORMAL_RX 5
443 #define RX_BH_STG_NORMAL_RX_END 6
444 #define RX_BH_STG_C2H 7
445 #define RX_BH_STG_C2H_END 8
446
447 #if DBG_RX_BH_TRACKING
448 void rx_bh_tk_set_stage(struct recv_priv *recv, u32 s);
449 void rx_bh_tk_set_buf(struct recv_priv *recv, void *buf, void *data, u32 dlen);
450 void rx_bh_tk_set_buf_pos(struct recv_priv *recv, void *pos);
451 void rx_bh_tk_set_frame(struct recv_priv *recv, void *frame);
452 void dump_rx_bh_tk(void *sel, struct recv_priv *recv);
453 #else
454 #define rx_bh_tk_set_stage(recv, s) do {} while (0)
455 #define rx_bh_tk_set_buf(recv, buf, data, dlen) do {} while (0)
456 #define rx_bh_tk_set_buf_pos(recv, pos) do {} while (0)
457 #define rx_bh_tk_set_frame(recv, frame) do {} while (0)
458 #define dump_rx_bh_tk(sel, recv) do {} while (0)
459 #endif
460
461 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
462 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
463 #endif /* CONFIG_NEW_SIGNAL_STAT_PROCESS */
464
465 struct sta_recv_priv {
466
467 _lock lock;
468 sint option;
469
470 /* _queue blk_strms[MAX_RX_NUMBLKS]; */
471 _queue defrag_q; /* keeping the fragment frame until defrag */
472
473 struct stainfo_rxcache rxcache;
474 u16 bmc_tid_rxseq[16];
475 u16 nonqos_rxseq;
476 u16 nonqos_bmc_rxseq;
477
478 /* uint sta_rx_bytes; */
479 /* uint sta_rx_pkts; */
480 /* uint sta_rx_fail; */
481
482 };
483
484
485 struct recv_buf {
486 _list list;
487
488 _lock recvbuf_lock;
489
490 u32 ref_cnt;
491
492 PADAPTER adapter;
493
494 u8 *pbuf;
495 u8 *pallocated_buf;
496
497 u32 len;
498 u8 *phead;
499 u8 *pdata;
500 u8 *ptail;
501 u8 *pend;
502
503 #ifdef CONFIG_USB_HCI
504 PURB purb;
505 dma_addr_t dma_transfer_addr; /* (in) dma addr for transfer_buffer */
506 u32 alloc_sz;
507
508 u8 irp_pending;
509 int transfer_len;
510 #endif
511
512 #if defined(PLATFORM_LINUX)
513 _pkt *pskb;
514 #elif defined(PLATFORM_FREEBSD) /* skb solution */
515 struct sk_buff *pskb;
516 #endif
517 };
518
519
520 /*
521 head ----->
522
523 data ----->
524
525 payload
526
527 tail ----->
528
529
530 end ----->
531
532 len = (unsigned int )(tail - data);
533
534 */
535 struct recv_frame_hdr {
536 _list list;
537 _pkt *pkt;
538
539 _adapter *adapter;
540
541 u8 fragcnt;
542
543 int frame_tag;
544
545 struct rx_pkt_attrib attrib;
546
547 uint len;
548 u8 *rx_head;
549 u8 *rx_data;
550 u8 *rx_tail;
551 u8 *rx_end;
552
553 void *precvbuf;
554
555
556 /* */
557 struct sta_info *psta;
558
559 /* for A-MPDU Rx reordering buffer control */
560 struct recv_reorder_ctrl *preorder_ctrl;
561
562 #ifdef CONFIG_WAPI_SUPPORT
563 u8 UserPriority;
564 u8 WapiTempPN[16];
565 u8 WapiSrcAddr[6];
566 u8 bWapiCheckPNInDecrypt;
567 u8 bIsWaiPacket;
568 #endif
569
570 };
571
572
573 union recv_frame {
574
575 union {
576 _list list;
577 struct recv_frame_hdr hdr;
578 uint mem[RECVFRAME_HDR_ALIGN >> 2];
579 } u;
580
581 /* uint mem[MAX_RXSZ>>2]; */
582
583 };
584
585 bool rtw_rframe_del_wfd_ie(union recv_frame *rframe, u8 ies_offset);
586
587 typedef enum _RX_PACKET_TYPE {
588 NORMAL_RX,/* Normal rx packet */
589 TX_REPORT1,/* CCX */
590 TX_REPORT2,/* TX RPT */
591 HIS_REPORT,/* USB HISR RPT */
592 C2H_PACKET
593 } RX_PACKET_TYPE, *PRX_PACKET_TYPE;
594
595 extern union recv_frame *_rtw_alloc_recvframe(_queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
596 extern union recv_frame *rtw_alloc_recvframe(_queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */
597 extern void rtw_init_recvframe(union recv_frame *precvframe , struct recv_priv *precvpriv);
598 extern int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue);
599
600 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
601 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
602 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
603
604 extern void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue);
605 u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
606
607 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue);
608 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue);
609 struct recv_buf *rtw_dequeue_recvbuf(_queue *queue);
610
611 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
612 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
613 #endif
614
615 void rx_query_phy_status(union recv_frame *rframe, u8 *phy_stat);
616 int rtw_inc_and_chk_continual_no_rx_packet(struct sta_info *sta, int tid_index);
617 void rtw_reset_continual_no_rx_packet(struct sta_info *sta, int tid_index);
618
619 #ifdef CONFIG_RECV_THREAD_MODE
620 thread_return rtw_recv_thread(thread_context context);
621 #endif
622
get_rxmem(union recv_frame * precvframe)623 __inline static u8 *get_rxmem(union recv_frame *precvframe)
624 {
625 /* always return rx_head... */
626 if (precvframe == NULL)
627 return NULL;
628
629 return precvframe->u.hdr.rx_head;
630 }
631
get_rx_status(union recv_frame * precvframe)632 __inline static u8 *get_rx_status(union recv_frame *precvframe)
633 {
634
635 return get_rxmem(precvframe);
636
637 }
638
get_recvframe_data(union recv_frame * precvframe)639 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
640 {
641
642 /* alwasy return rx_data */
643 if (precvframe == NULL)
644 return NULL;
645
646 return precvframe->u.hdr.rx_data;
647
648 }
649
recvframe_push(union recv_frame * precvframe,sint sz)650 __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz)
651 {
652 /* append data before rx_data */
653
654 /* add data to the start of recv_frame
655 *
656 * This function extends the used data area of the recv_frame at the buffer
657 * start. rx_data must be still larger than rx_head, after pushing.
658 */
659
660 if (precvframe == NULL)
661 return NULL;
662
663
664 precvframe->u.hdr.rx_data -= sz ;
665 if (precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head) {
666 precvframe->u.hdr.rx_data += sz ;
667 return NULL;
668 }
669
670 precvframe->u.hdr.len += sz;
671
672 return precvframe->u.hdr.rx_data;
673
674 }
675
676
recvframe_pull(union recv_frame * precvframe,sint sz)677 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
678 {
679 /* rx_data += sz; move rx_data sz bytes hereafter */
680
681 /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
682
683
684 if (precvframe == NULL)
685 return NULL;
686
687
688 precvframe->u.hdr.rx_data += sz;
689
690 if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) {
691 precvframe->u.hdr.rx_data -= sz;
692 return NULL;
693 }
694
695 precvframe->u.hdr.len -= sz;
696
697 return precvframe->u.hdr.rx_data;
698
699 }
700
recvframe_put(union recv_frame * precvframe,sint sz)701 __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
702 {
703 /* rx_tai += sz; move rx_tail sz bytes hereafter */
704
705 /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
706 /* after putting, rx_tail must be still larger than rx_end. */
707 unsigned char *prev_rx_tail;
708
709 /* RTW_INFO("recvframe_put: len=%d\n", sz); */
710
711 if (precvframe == NULL)
712 return NULL;
713
714 prev_rx_tail = precvframe->u.hdr.rx_tail;
715
716 precvframe->u.hdr.rx_tail += sz;
717
718 if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) {
719 precvframe->u.hdr.rx_tail -= sz;
720 return NULL;
721 }
722
723 precvframe->u.hdr.len += sz;
724
725 return precvframe->u.hdr.rx_tail;
726
727 }
728
729
730
recvframe_pull_tail(union recv_frame * precvframe,sint sz)731 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
732 {
733 /* rmv data from rx_tail (by yitsen) */
734
735 /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
736 /* after pulling, rx_end must be still larger than rx_data. */
737
738 if (precvframe == NULL)
739 return NULL;
740
741 precvframe->u.hdr.rx_tail -= sz;
742
743 if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) {
744 precvframe->u.hdr.rx_tail += sz;
745 return NULL;
746 }
747
748 precvframe->u.hdr.len -= sz;
749
750 return precvframe->u.hdr.rx_tail;
751
752 }
753
rxmem_to_recvframe(u8 * rxmem)754 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
755 {
756 /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */
757 /* from any given member of recv_frame. */
758 /* rxmem indicates the any member/address in recv_frame */
759
760 return (union recv_frame *)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
761
762 }
763
pkt_to_recvframe(_pkt * pkt)764 __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
765 {
766
767 u8 *buf_star;
768 union recv_frame *precv_frame;
769 precv_frame = rxmem_to_recvframe((unsigned char *)buf_star);
770
771 return precv_frame;
772 }
773
pkt_to_recvmem(_pkt * pkt)774 __inline static u8 *pkt_to_recvmem(_pkt *pkt)
775 {
776 /* return the rx_head */
777
778 union recv_frame *precv_frame = pkt_to_recvframe(pkt);
779
780 return precv_frame->u.hdr.rx_head;
781
782 }
783
pkt_to_recvdata(_pkt * pkt)784 __inline static u8 *pkt_to_recvdata(_pkt *pkt)
785 {
786 /* return the rx_data */
787
788 union recv_frame *precv_frame = pkt_to_recvframe(pkt);
789
790 return precv_frame->u.hdr.rx_data;
791
792 }
793
794
get_recvframe_len(union recv_frame * precvframe)795 __inline static sint get_recvframe_len(union recv_frame *precvframe)
796 {
797 return precvframe->u.hdr.len;
798 }
799
800
translate_percentage_to_dbm(u32 SignalStrengthIndex)801 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
802 {
803 s32 SignalPower; /* in dBm. */
804
805 /* Translate to dBm (x=y-100) */
806 SignalPower = SignalStrengthIndex - 100;
807 return SignalPower;
808 }
809
810 struct sta_info;
811
812 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
813
814 extern void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
815
816 u8 adapter_allow_bmc_data_rx(_adapter *adapter);
817 s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status);
818 void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info *sta);
819
820 #endif
821