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