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