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