1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2019 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_RTW_NAPI
23 #define RTL_NAPI_WEIGHT (32)
24 #endif
25
26
27 #define NR_RECVFRAME 256
28
29 #define RXFRAME_ALIGN 8
30 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
31
32 #define DRVINFO_SZ 4 /* unit is 8bytes */
33
34 #define MAX_RXFRAME_CNT 512
35 #define MAX_RX_NUMBLKS (32)
36 #define RECVFRAME_HDR_ALIGN 128
37 #define MAX_CONTINUAL_NORXPACKET_COUNT 4 /* In MAX_CONTINUAL_NORXPACKET_COUNT*2 sec , no rx traffict would issue DELBA*/
38
39 #define PHY_RSSI_SLID_WIN_MAX 100
40 #define PHY_LINKQUALITY_SLID_WIN_MAX 20
41
42
43 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
44
45 #define MAX_SUBFRAME_COUNT 64
46 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
47 extern u8 rtw_bridge_tunnel_header[];
48 extern u8 rtw_rfc1042_header[];
49
50 enum addba_rsp_ack_state {
51 RTW_RECV_ACK_OR_TIMEOUT,
52 };
53
54 #ifdef RTW_PHL_RX
55 enum rtw_core_rx_state {
56 CORE_RX_CONTINUE = _SUCCESS,
57 CORE_RX_DONE,
58 CORE_RX_DROP,
59 CORE_RX_FAIL,
60 #ifdef CONFIG_RTW_CORE_RXSC
61 CORE_RX_GO_SHORTCUT,
62 #endif
63 CORE_RX_DEFRAG,
64 };
65 #endif
66
67 /* for Rx reordering buffer control */
68 struct recv_reorder_ctrl {
69 _adapter *padapter;
70 u8 tid;
71 u8 enable;
72 u16 indicate_seq;/* =wstart_b, init_value=0xffff */
73 u8 ampdu_size;
74 unsigned long rec_abba_rsp_ack;
75
76 #ifdef CONFIG_RECV_REORDERING_CTRL
77 _queue pending_recvframe_queue;
78 u8 wsize_b;
79 _timer reordering_ctrl_timer;
80 u8 bReorderWaiting;
81 #endif
82 };
83
84 struct stainfo_rxcache {
85 u16 tid_rxseq[16];
86 u8 iv[16][8];
87 u8 last_tid;
88 };
89
90
91 struct smooth_rssi_data {
92 u32 elements[100]; /* array to store values */
93 u32 index; /* index to current array to store */
94 u32 total_num; /* num of valid elements */
95 u32 total_val; /* sum of valid elements */
96 };
97
98 struct signal_stat {
99 u8 update_req; /* used to indicate */
100 u8 avg_val; /* avg of valid elements */
101 u32 total_num; /* num of valid elements */
102 u32 total_val; /* sum of valid elements */
103 };
104
105 /*TODO get phyinfo from PHL PPDU status - RTW_WKARD_CORE_RSSI_V1*/
106 struct phydm_phyinfo_struct {
107 bool is_valid;
108 u8 rx_pwdb_all;
109 u8 signal_quality; /* OFDM: signal_quality=rx_mimo_signal_quality[0], CCK: signal qualityin 0-100 index. */
110
111 s8 rx_power; /* in dBm Translate from PWdB */
112 s8 recv_signal_power; /* Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures. */
113 u8 signal_strength; /* in 0-100 index. */
114 s8 rx_pwr[4]; /* per-path's pwdb */
115 s8 rx_snr[4]; /* per-path's SNR */
116 u8 rx_count:2; /* RX path counter---*/
117 };
118
119
120 struct rx_pkt_attrib {
121 u16 pkt_len;
122 u8 physt;
123 u8 drvinfo_sz;
124 u8 shift_sz;
125 u8 hdrlen; /* the WLAN Header Len */
126 u8 to_fr_ds;
127 u8 amsdu;
128 u8 qos;
129 u8 priority;
130 u8 pw_save;
131 u8 mdata;
132 u16 seq_num;
133 u8 frag_num;
134 u8 mfrag;
135 u8 order;
136 u8 privacy; /* in frame_ctrl field */
137 u8 bdecrypted;
138 u8 encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */
139 u8 iv_len;
140 u8 icv_len;
141 u8 crc_err;
142 u8 icv_err;
143
144 #ifdef CONFIG_RTW_CORE_RXSC
145 u16 eth_type;
146 #endif
147
148 u8 dst[ETH_ALEN];
149 u8 src[ETH_ALEN];
150 u8 ta[ETH_ALEN];
151 u8 ra[ETH_ALEN];
152 u8 bssid[ETH_ALEN];
153 #ifdef CONFIG_RTW_MESH
154 u8 msa[ETH_ALEN]; /* mesh sa */
155 u8 mda[ETH_ALEN]; /* mesh da */
156 u8 mesh_ctrl_present;
157 u8 mesh_ctrl_len; /* length of mesh control field */
158 #endif
159
160 u8 ack_policy;
161
162 u8 key_index;
163
164 u8 data_rate;
165 u8 ch; /* RX channel */
166 u8 bw;
167 u8 stbc;
168 u8 ldpc;
169 u8 sgi;
170 u8 pkt_rpt_type;
171 u8 ampdu;
172 u8 ppdu_cnt;
173 u8 ampdu_eof;
174 u32 free_cnt; /* free run counter */
175 struct phydm_phyinfo_struct phy_info;
176 #ifdef CONFIG_WIFI_MONITOR
177 u8 moif[16];
178 #endif
179
180 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
181 /* checksum offload realted varaiables */
182 u8 csum_valid; /* Checksum valid, 0: not check, 1: checked */
183 u8 csum_err; /* Checksum Error occurs */
184 #endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
185
186 #ifdef RTW_PHL_DBG_CMD
187 u8 wl_type;
188 u8 wl_subtype;
189 #endif
190 #ifdef CONFIG_RTW_CORE_RXSC
191 u8 bsnaphdr;
192 #endif
193
194 };
195
196 #ifdef CONFIG_RTW_MESH
197 #define RATTRIB_GET_MCTRL_LEN(rattrib) ((rattrib)->mesh_ctrl_len)
198 #else
199 #define RATTRIB_GET_MCTRL_LEN(rattrib) 0
200 #endif
201
202 /* These definition is used for Rx packet reordering. */
203 #define SN_LESS(a, b) (((a-b) & 0x800) != 0)
204 #define SN_EQUAL(a, b) (a == b)
205 /* #define REORDER_WIN_SIZE 128 */
206 /* #define REORDER_ENTRY_NUM 128 */
207 #define REORDER_WAIT_TIME (50) /* (ms) */
208
209 #if defined(CONFIG_PLATFORM_RTK390X) && defined(CONFIG_USB_HCI)
210 #define RECVBUFF_ALIGN_SZ 32
211 #else
212 #define RECVBUFF_ALIGN_SZ 8
213 #endif
214
215 /*GEORGIA_TODO_FIXIT_IC_DEPENDENCE*/
216 #define RXDESC_SIZE 24
217 #define RXDESC_OFFSET RXDESC_SIZE
218
219 #ifdef CONFIG_TRX_BD_ARCH
220 struct rx_buf_desc {
221 /* RX has exactly one segment */
222 #ifdef CONFIG_64BIT_DMA
223 unsigned int dword[4];
224 #else
225 unsigned int dword[2];
226 #endif
227 };
228
229 struct recv_stat {
230 unsigned int rxdw[8];
231 };
232 #else
233 struct recv_stat {
234 unsigned int rxdw0;
235
236 unsigned int rxdw1;
237
238 #if !(defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C) || defined(CONFIG_RTL8822C)) && defined(CONFIG_PCI_HCI) /* exclude 8822be, 8821ce ,8822ce*/
239 unsigned int rxdw2;
240
241 unsigned int rxdw3;
242 #endif
243
244 #ifndef BUF_DESC_ARCH
245 unsigned int rxdw4;
246
247 unsigned int rxdw5;
248
249 #ifdef CONFIG_PCI_HCI
250 unsigned int rxdw6;
251
252 unsigned int rxdw7;
253 #endif
254 #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */
255 };
256 #endif
257
258 #define EOR BIT(30)
259
260
261 /*
262 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
263 ; halt(passive) ;
264
265 using enter_critical section to protect
266 */
267
268 struct recv_info {
269 u64 rx_bytes;
270 u64 rx_pkts;
271 u64 rx_drop;
272
273 u64 dbg_rx_drop_count;
274 u64 dbg_rx_ampdu_drop_count;
275 u64 dbg_rx_ampdu_forced_indicate_count;
276 u64 dbg_rx_ampdu_loss_count;
277 u64 dbg_rx_dup_mgt_frame_drop_count;
278 u64 dbg_rx_ampdu_window_shift_cnt;
279 u64 dbg_rx_conflic_mac_addr_cnt;
280
281 /* For display the phy informatiom */
282 u8 is_signal_dbg; /* for debug */
283 u8 signal_strength_dbg; /* for debug */
284
285 /*RTW_WKARD_CORE_RSSI_V1 - GEORGIA MUST REFINE*/
286 u8 signal_strength;
287 u8 signal_qual;
288 s8 rssi; /* rtw_phl_rssi_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */
289
290
291 #ifdef CONFIG_SIGNAL_STAT_PROCESS
292 _timer signal_stat_timer;
293 u32 signal_stat_sampling_interval;
294 #endif
295
296 /* u32 signal_stat_converging_constant; */
297 struct signal_stat signal_qual_data;
298 struct signal_stat signal_strength_data;
299
300
301 u16 sink_udpport, pre_rtp_rxseq, cur_rtp_rxseq;
302 };
303 #ifdef CONFIG_SIGNAL_STAT_PROCESS
304 #define rtw_set_signal_stat_timer(recvinfo) _set_timer(&(recvinfo)->signal_stat_timer, (recvinfo)->signal_stat_sampling_interval)
305 #endif
306
307 struct sta_recv_priv {
308
309 _lock lock;
310 sint option;
311
312 /* _queue blk_strms[MAX_RX_NUMBLKS]; */
313 _queue defrag_q; /* keeping the fragment frame until defrag */
314
315 struct stainfo_rxcache rxcache;
316 u16 bmc_tid_rxseq[16];
317 u16 nonqos_rxseq;
318 u16 nonqos_bmc_rxseq;
319
320 /* uint sta_rx_bytes; */
321 /* uint sta_rx_pkts; */
322 /* uint sta_rx_fail; */
323
324 };
325
326 #if 0
327 struct recv_buf {
328 _list list;
329
330 _lock recvbuf_lock;
331
332 u32 ref_cnt;
333
334 _adapter *adapter;
335
336 u8 *pbuf;
337 u8 *pallocated_buf;
338
339 u32 len;
340 u8 *phead;
341 u8 *pdata;
342 u8 *ptail;
343 u8 *pend;
344
345 #ifdef CONFIG_USB_HCI
346 PURB purb;
347 dma_addr_t dma_transfer_addr; /* (in) dma addr for transfer_buffer */
348 u32 alloc_sz;
349
350 u8 irp_pending;
351 int transfer_len;
352 #endif
353 struct sk_buff *pskb;
354 };
355 #endif
356
357 struct recv_frame_hdr {
358 _list list;
359 struct sk_buff *pkt;
360
361 _adapter *adapter;
362 struct dvobj_priv *dvobj;
363
364 u8 fragcnt;
365
366 int frame_tag;
367 int keytrack;
368 struct rx_pkt_attrib attrib;
369
370 uint len;
371 u8 *rx_head;
372 u8 *rx_data;
373 u8 *rx_tail;
374 u8 *rx_end;
375
376 void *precvbuf;
377
378
379 /* */
380 struct sta_info *psta;
381 #ifdef CONFIG_RECV_REORDERING_CTRL
382 /* for A-MPDU Rx reordering buffer control */
383 struct recv_reorder_ctrl *preorder_ctrl;
384 #endif
385 #ifdef RTW_PHL_RX
386 void *rx_req;
387 #endif
388 #ifdef CONFIG_RTW_CORE_RXSC
389 struct core_rxsc_entry *rxsc_entry;
390 #endif
391
392 #ifdef CONFIG_WAPI_SUPPORT
393 u8 UserPriority;
394 u8 WapiTempPN[16];
395 u8 WapiSrcAddr[6];
396 u8 bWapiCheckPNInDecrypt;
397 u8 bIsWaiPacket;
398 #endif
399
400 };
401
402
403 union recv_frame {
404 union {
405 _list list;
406 struct recv_frame_hdr hdr;
407 uint mem[RECVFRAME_HDR_ALIGN >> 2];
408 } u;
409 /* uint mem[MAX_RXSZ>>2]; */
410 };
411
412 enum rtw_rx_llc_hdl {
413 RTW_RX_LLC_KEEP = 0,
414 RTW_RX_LLC_REMOVE = 1,
415 RTW_RX_LLC_VLAN = 2,
416 };
417
418 struct recv_priv {
419 struct dvobj_priv *dvobj;
420
421 #ifdef CONFIG_RECV_THREAD_MODE
422 _sema recv_sema;
423 #endif
424 _queue free_recv_queue; /*recv_frame*/
425 #if 0
426 _queue uc_swdec_pending_queue;
427 #endif
428
429 u8 *pallocated_frame_buf;
430 u8 *precv_frame_buf;
431
432 uint free_recvframe_cnt;
433
434 #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
435 #ifdef CONFIG_RTW_NAPI
436 struct sk_buff_head rx_napi_skb_queue;
437 #endif
438 #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) */
439
440 };
441
442 bool rtw_rframe_del_wfd_ie(union recv_frame *rframe, u8 ies_offset);
443 #ifdef RTW_PHL_RX
444 extern void dump_recv_frame(_adapter *adapter, union recv_frame *prframe);
445 extern sint validate_recv_frame(_adapter *adapter, union recv_frame *precv_frame);
446 extern s32 rtw_core_rx_data_pre_process(_adapter *adapter, union recv_frame **prframe);
447 extern s32 rtw_core_rx_data_post_process(_adapter *adapter, union recv_frame *prframe);
448
449 enum rtw_phl_status rtw_core_rx_process(void *drv_priv);
450 void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta);
451 void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *psta);
452 #ifdef CONFIG_RTW_CORE_RXSC
453 sint recv_ucast_pn_decache(union recv_frame *precv_frame);
454 sint recv_bcast_pn_decache(union recv_frame *precv_frame);
455 #endif /* CONFIG_RTW_CORE_RXSC */
456 #endif
457
458 extern void rtw_init_recvframe(union recv_frame *precvframe);
459 extern int rtw_free_recvframe(union recv_frame *precvframe);
460 union recv_frame *rtw_alloc_recvframe(_queue *pfree_recv_queue);
461
462 #if 0
463 u32 rtw_free_uc_swdec_pending_queue(struct dvobj_priv *dvobj);
464 #endif
465
466 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
467 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
468 #endif
469
470 #if 0
471 void rx_query_phy_status(union recv_frame *rframe, u8 *phy_stat);
472 #endif
473
474 int rtw_inc_and_chk_continual_no_rx_packet(struct sta_info *sta, int tid_index);
475 void rtw_reset_continual_no_rx_packet(struct sta_info *sta, int tid_index);
476
477 #ifdef CONFIG_RECV_THREAD_MODE
478 thread_return rtw_recv_thread(thread_context context);
479 #endif
480 #ifdef RTW_WKARD_CORE_RSSI_V1
481 void rx_process_phy_info(union recv_frame *precvframe);
482 #endif
get_rxmem(union recv_frame * precvframe)483 __inline static u8 *get_rxmem(union recv_frame *precvframe)
484 {
485 /* always return rx_head... */
486 if (precvframe == NULL)
487 return NULL;
488
489 return precvframe->u.hdr.rx_head;
490 }
491
get_rx_status(union recv_frame * precvframe)492 __inline static u8 *get_rx_status(union recv_frame *precvframe)
493 {
494
495 return get_rxmem(precvframe);
496
497 }
498
get_recvframe_data(union recv_frame * precvframe)499 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
500 {
501
502 /* alwasy return rx_data */
503 if (precvframe == NULL)
504 return NULL;
505
506 return precvframe->u.hdr.rx_data;
507
508 }
509
recvframe_push(union recv_frame * precvframe,sint sz)510 __inline static u8 *recvframe_push(union recv_frame *precvframe, sint sz)
511 {
512 /* append data before rx_data */
513
514 /* add data to the start of recv_frame
515 *
516 * This function extends the used data area of the recv_frame at the buffer
517 * start. rx_data must be still larger than rx_head, after pushing.
518 */
519
520 if (precvframe == NULL)
521 return NULL;
522
523
524 precvframe->u.hdr.rx_data -= sz ;
525 if (precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head) {
526 precvframe->u.hdr.rx_data += sz ;
527 return NULL;
528 }
529
530 precvframe->u.hdr.len += sz;
531
532 return precvframe->u.hdr.rx_data;
533
534 }
535
536
recvframe_pull(union recv_frame * precvframe,sint sz)537 __inline static u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
538 {
539 /* rx_data += sz; move rx_data sz bytes hereafter */
540
541 /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */
542
543
544 if (precvframe == NULL)
545 return NULL;
546
547
548 precvframe->u.hdr.rx_data += sz;
549
550 if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) {
551 precvframe->u.hdr.rx_data -= sz;
552 return NULL;
553 }
554
555 precvframe->u.hdr.len -= sz;
556
557 return precvframe->u.hdr.rx_data;
558
559 }
560
recvframe_put(union recv_frame * precvframe,sint sz)561 __inline static u8 *recvframe_put(union recv_frame *precvframe, sint sz)
562 {
563 /* rx_tai += sz; move rx_tail sz bytes hereafter */
564
565 /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */
566 /* after putting, rx_tail must be still larger than rx_end. */
567 unsigned char *prev_rx_tail;
568
569 /* RTW_INFO("recvframe_put: len=%d\n", sz); */
570
571 if (precvframe == NULL)
572 return NULL;
573
574 prev_rx_tail = precvframe->u.hdr.rx_tail;
575
576 precvframe->u.hdr.rx_tail += sz;
577
578 if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) {
579 precvframe->u.hdr.rx_tail -= sz;
580 return NULL;
581 }
582
583 precvframe->u.hdr.len += sz;
584
585 return precvframe->u.hdr.rx_tail;
586
587 }
588
589
590
recvframe_pull_tail(union recv_frame * precvframe,sint sz)591 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
592 {
593 /* rmv data from rx_tail (by yitsen) */
594
595 /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */
596 /* after pulling, rx_end must be still larger than rx_data. */
597
598 if (precvframe == NULL)
599 return NULL;
600
601 precvframe->u.hdr.rx_tail -= sz;
602
603 if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) {
604 precvframe->u.hdr.rx_tail += sz;
605 return NULL;
606 }
607
608 precvframe->u.hdr.len -= sz;
609
610 return precvframe->u.hdr.rx_tail;
611
612 }
613
get_recvframe_len(union recv_frame * precvframe)614 __inline static sint get_recvframe_len(union recv_frame *precvframe)
615 {
616 return precvframe->u.hdr.len;
617 }
618
619
620 struct sta_info;
621 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
622
623 extern void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
624
625 u8 adapter_allow_bmc_data_rx(_adapter *adapter);
626 #if 0
627 s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status);
628 #endif
629 void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info *sta);
630 u8 rtw_init_lite_recv_resource(struct dvobj_priv *dvobj);
631 void rtw_free_lite_recv_resource(struct dvobj_priv *dvobj);
632 #endif
633