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