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