1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /****************************************************************************** 3 * 4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. 5 * 6 ******************************************************************************/ 7 #ifndef _RTW_RECV_H_ 8 #define _RTW_RECV_H_ 9 10 #ifdef CONFIG_SINGLE_RECV_BUF 11 #define NR_RECVBUFF (1) 12 #else 13 #define NR_RECVBUFF (8) 14 #endif /* CONFIG_SINGLE_RECV_BUF */ 15 16 #define NR_PREALLOC_RECV_SKB (8) 17 18 #define NR_RECVFRAME 256 19 20 #define RXFRAME_ALIGN 8 21 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN) 22 23 #define DRVINFO_SZ 4 /* unit is 8bytes */ 24 25 #define MAX_RXFRAME_CNT 512 26 #define MAX_RX_NUMBLKS (32) 27 #define RECVFRAME_HDR_ALIGN 128 28 29 30 #define PHY_RSSI_SLID_WIN_MAX 100 31 #define PHY_LINKQUALITY_SLID_WIN_MAX 20 32 33 34 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr) 35 36 #define RX_MPDU_QUEUE 0 37 #define RX_CMD_QUEUE 1 38 #define RX_MAX_QUEUE 2 39 40 #define MAX_SUBFRAME_COUNT 64 41 42 /* for Rx reordering buffer control */ 43 struct recv_reorder_ctrl { 44 struct adapter *padapter; 45 u8 enable; 46 u16 indicate_seq;/* wstart_b, init_value = 0xffff */ 47 u16 wend_b; 48 u8 wsize_b; 49 struct __queue pending_recvframe_queue; 50 _timer reordering_ctrl_timer; 51 }; 52 53 struct stainfo_rxcache { 54 u16 tid_rxseq[16]; 55 /* 56 unsigned short tid0_rxseq; 57 unsigned short tid1_rxseq; 58 unsigned short tid2_rxseq; 59 unsigned short tid3_rxseq; 60 unsigned short tid4_rxseq; 61 unsigned short tid5_rxseq; 62 unsigned short tid6_rxseq; 63 unsigned short tid7_rxseq; 64 unsigned short tid8_rxseq; 65 unsigned short tid9_rxseq; 66 unsigned short tid10_rxseq; 67 unsigned short tid11_rxseq; 68 unsigned short tid12_rxseq; 69 unsigned short tid13_rxseq; 70 unsigned short tid14_rxseq; 71 unsigned short tid15_rxseq; 72 */ 73 }; 74 75 76 struct smooth_rssi_data { 77 u32 elements[100]; /* array to store values */ 78 u32 index; /* index to current array to store */ 79 u32 total_num; /* num of valid elements */ 80 u32 total_val; /* sum of valid elements */ 81 }; 82 83 struct signal_stat { 84 u8 update_req; /* used to indicate */ 85 u8 avg_val; /* avg of valid elements */ 86 u32 total_num; /* num of valid elements */ 87 u32 total_val; /* sum of valid elements */ 88 }; 89 90 struct phy_info { 91 u8 rx_pwd_ba11; 92 93 u8 SignalQuality; /* in 0-100 index. */ 94 s8 rx_mimo_signal_quality[4]; /* per-path's EVM */ 95 u8 RxMIMOEVMdbm[4]; /* per-path's EVM dbm */ 96 97 u8 rx_mimo_signal_strength[4];/* in 0~100 index */ 98 99 u16 Cfo_short[4]; /* per-path's Cfo_short */ 100 u16 Cfo_tail[4]; /* per-path's Cfo_tail */ 101 102 s8 RxPower; /* in dBm Translate from PWdB */ 103 s8 RecvSignalPower;/* Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures. */ 104 u8 bt_rx_rssi_percentage; 105 u8 SignalStrength; /* in 0-100 index. */ 106 107 s8 RxPwr[4]; /* per-path's pwdb */ 108 u8 RxSNR[4]; /* per-path's SNR */ 109 u8 BandWidth; 110 u8 btCoexPwrAdjust; 111 }; 112 113 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA 114 struct rx_raw_rssi { 115 u8 data_rate; 116 u8 pwdball; 117 s8 pwr_all; 118 119 u8 mimo_signal_strength[4];/* in 0~100 index */ 120 u8 mimo_signal_quality[4]; 121 122 s8 ofdm_pwr[4]; 123 u8 ofdm_snr[4]; 124 125 }; 126 #endif 127 128 struct rx_pkt_attrib { 129 u16 pkt_len; 130 u8 physt; 131 u8 drvinfo_sz; 132 u8 shift_sz; 133 u8 hdrlen; /* the WLAN Header Len */ 134 u8 to_fr_ds; 135 u8 amsdu; 136 u8 qos; 137 u8 priority; 138 u8 pw_save; 139 u8 mdata; 140 u16 seq_num; 141 u8 frag_num; 142 u8 mfrag; 143 u8 order; 144 u8 privacy; /* in frame_ctrl field */ 145 u8 bdecrypted; 146 u8 encrypt; /* when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith */ 147 u8 iv_len; 148 u8 icv_len; 149 u8 crc_err; 150 u8 icv_err; 151 152 u16 eth_type; 153 154 u8 dst[ETH_ALEN]; 155 u8 src[ETH_ALEN]; 156 u8 ta[ETH_ALEN]; 157 u8 ra[ETH_ALEN]; 158 u8 bssid[ETH_ALEN]; 159 160 u8 ack_policy; 161 162 /* ifdef CONFIG_TCP_CSUM_OFFLOAD_RX */ 163 u8 tcpchk_valid; /* 0: invalid, 1: valid */ 164 u8 ip_chkrpt; /* 0: incorrect, 1: correct */ 165 u8 tcp_chkrpt; /* 0: incorrect, 1: correct */ 166 /* endif */ 167 u8 key_index; 168 169 u8 data_rate; 170 u8 sgi; 171 u8 pkt_rpt_type; 172 u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */ 173 174 /* 175 u8 signal_qual; 176 s8 rx_mimo_signal_qual[2]; 177 u8 signal_strength; 178 u32 rx_pwd_ba11; 179 s32 RecvSignalPower; 180 */ 181 struct phy_info phy_info; 182 }; 183 184 185 /* These definition is used for Rx packet reordering. */ 186 #define SN_LESS(a, b) (((a - b) & 0x800) != 0) 187 #define SN_EQUAL(a, b) (a == b) 188 /* define REORDER_WIN_SIZE 128 */ 189 /* define REORDER_ENTRY_NUM 128 */ 190 #define REORDER_WAIT_TIME (50) /* (ms) */ 191 192 #define RECVBUFF_ALIGN_SZ 8 193 194 #define RXDESC_SIZE 24 195 #define RXDESC_OFFSET RXDESC_SIZE 196 197 struct recv_stat { 198 __le32 rxdw0; 199 __le32 rxdw1; 200 __le32 rxdw2; 201 __le32 rxdw3; 202 #ifndef BUF_DESC_ARCH 203 __le32 rxdw4; 204 __le32 rxdw5; 205 #endif /* if BUF_DESC_ARCH is defined, rx_buf_desc occupy 4 double words */ 206 }; 207 208 #define EOR BIT(30) 209 210 /* 211 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch) 212 ; halt(passive) ; 213 214 using enter_critical section to protect 215 */ 216 struct recv_priv { 217 _lock lock; 218 struct __queue free_recv_queue; 219 struct __queue recv_pending_queue; 220 struct __queue uc_swdec_pending_queue; 221 u8 *pallocated_frame_buf; 222 u8 *precv_frame_buf; 223 uint free_recvframe_cnt; 224 struct adapter *adapter; 225 u32 bIsAnyNonBEPkts; 226 u64 rx_bytes; 227 u64 rx_pkts; 228 u64 rx_drop; 229 uint rx_icv_err; 230 uint rx_largepacket_crcerr; 231 uint rx_smallpacket_crcerr; 232 uint rx_middlepacket_crcerr; 233 234 struct tasklet_struct irq_prepare_beacon_tasklet; 235 struct tasklet_struct recv_tasklet; 236 struct sk_buff_head free_recv_skb_queue; 237 struct sk_buff_head rx_skb_queue; 238 #ifdef CONFIG_RX_INDICATE_QUEUE 239 struct task rx_indicate_tasklet; 240 struct ifqueue rx_indicate_queue; 241 #endif /* CONFIG_RX_INDICATE_QUEUE */ 242 243 u8 *pallocated_recv_buf; 244 u8 *precv_buf; /* 4 alignment */ 245 struct __queue free_recv_buf_queue; 246 u32 free_recv_buf_queue_cnt; 247 248 struct __queue recv_buf_pending_queue; 249 250 /* For display the phy informatiom */ 251 u8 is_signal_dbg; /* for debug */ 252 u8 signal_strength_dbg; /* for debug */ 253 254 u8 signal_strength; 255 u8 signal_qual; 256 s8 rssi; /* translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength); */ 257 #ifdef DBG_RX_SIGNAL_DISPLAY_RAW_DATA 258 struct rx_raw_rssi raw_rssi_info; 259 #endif 260 /* s8 rxpwdb; */ 261 s16 noise; 262 /* int RxSNRdB[2]; */ 263 /* s8 RxRssi[2]; */ 264 /* int FalseAlmCnt_all; */ 265 266 267 _timer signal_stat_timer; 268 u32 signal_stat_sampling_interval; 269 /* u32 signal_stat_converging_constant; */ 270 struct signal_stat signal_qual_data; 271 struct signal_stat signal_strength_data; 272 }; 273 274 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval) 275 276 struct sta_recv_priv { 277 278 _lock lock; 279 sint option; 280 281 /* struct __queue blk_strms[MAX_RX_NUMBLKS]; */ 282 struct __queue defrag_q; /* keeping the fragment frame until defrag */ 283 284 struct stainfo_rxcache rxcache; 285 286 /* uint sta_rx_bytes; */ 287 /* uint sta_rx_pkts; */ 288 /* uint sta_rx_fail; */ 289 290 }; 291 292 293 struct recv_buf { 294 struct list_head list; 295 296 _lock recvbuf_lock; 297 298 u32 ref_cnt; 299 300 struct adapter *adapter; 301 302 u8 *pbuf; 303 u8 *pallocated_buf; 304 305 u32 len; 306 u8 *phead; 307 u8 *pdata; 308 u8 *ptail; 309 u8 *pend; 310 311 _pkt *pskb; 312 u8 reuse; 313 }; 314 315 316 /* 317 head -----> 318 319 data -----> 320 321 payload 322 323 tail -----> 324 325 326 end -----> 327 328 len = (unsigned int)(tail - data); 329 330 */ 331 struct recv_frame_hdr { 332 struct list_head list; 333 #ifndef CONFIG_BSD_RX_USE_MBUF 334 struct sk_buff *pkt; 335 struct sk_buff *pkt_newalloc; 336 #else /* CONFIG_BSD_RX_USE_MBUF */ 337 _pkt *pkt; 338 _pkt *pkt_newalloc; 339 #endif /* CONFIG_BSD_RX_USE_MBUF */ 340 341 struct adapter *adapter; 342 343 u8 fragcnt; 344 345 int frame_tag; 346 347 struct rx_pkt_attrib attrib; 348 349 uint len; 350 u8 *rx_head; 351 u8 *rx_data; 352 u8 *rx_tail; 353 u8 *rx_end; 354 355 void *precvbuf; 356 357 358 /* */ 359 struct sta_info *psta; 360 361 /* for A-MPDU Rx reordering buffer control */ 362 struct recv_reorder_ctrl *preorder_ctrl; 363 }; 364 365 366 union recv_frame { 367 union{ 368 struct list_head list; 369 struct recv_frame_hdr hdr; 370 uint mem[RECVFRAME_HDR_ALIGN>>2]; 371 } u; 372 373 /* uint mem[MAX_RXSZ>>2]; */ 374 375 }; 376 377 enum RX_PACKET_TYPE { 378 NORMAL_RX,/* Normal rx packet */ 379 TX_REPORT1,/* CCX */ 380 TX_REPORT2,/* TX RPT */ 381 HIS_REPORT,/* USB HISR RPT */ 382 C2H_PACKET 383 }; 384 385 extern union recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ 386 extern union recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ 387 extern int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue); 388 389 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue) 390 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue); 391 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue); 392 393 extern void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue); 394 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter); 395 396 sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue); 397 sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue); 398 struct recv_buf *rtw_dequeue_recvbuf(struct __queue *queue); 399 400 void rtw_reordering_ctrl_timeout_handler(struct timer_list *t); 401 402 static inline u8 *get_rxmem(union recv_frame *precvframe) 403 { 404 /* always return rx_head... */ 405 if (precvframe == NULL) 406 return NULL; 407 408 return precvframe->u.hdr.rx_head; 409 } 410 411 static inline u8 *get_recvframe_data(union recv_frame *precvframe) 412 { 413 414 /* alwasy return rx_data */ 415 if (precvframe == NULL) 416 return NULL; 417 418 return precvframe->u.hdr.rx_data; 419 420 } 421 422 static inline u8 *recvframe_pull(union recv_frame *precvframe, sint sz) 423 { 424 /* rx_data += sz; move rx_data sz bytes hereafter */ 425 426 /* used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller */ 427 428 429 if (precvframe == NULL) 430 return NULL; 431 432 433 precvframe->u.hdr.rx_data += sz; 434 435 if (precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail) 436 { 437 precvframe->u.hdr.rx_data -= sz; 438 return NULL; 439 } 440 441 precvframe->u.hdr.len -= sz; 442 443 return precvframe->u.hdr.rx_data; 444 445 } 446 447 static inline u8 *recvframe_put(union recv_frame *precvframe, sint sz) 448 { 449 /* rx_tai += sz; move rx_tail sz bytes hereafter */ 450 451 /* used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller */ 452 /* after putting, rx_tail must be still larger than rx_end. */ 453 unsigned char *prev_rx_tail; 454 455 if (precvframe == NULL) 456 return NULL; 457 458 prev_rx_tail = precvframe->u.hdr.rx_tail; 459 460 precvframe->u.hdr.rx_tail += sz; 461 462 if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) 463 { 464 precvframe->u.hdr.rx_tail = prev_rx_tail; 465 return NULL; 466 } 467 468 precvframe->u.hdr.len += sz; 469 470 return precvframe->u.hdr.rx_tail; 471 472 } 473 474 475 476 static inline u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz) 477 { 478 /* rmv data from rx_tail (by yitsen) */ 479 480 /* used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller */ 481 /* after pulling, rx_end must be still larger than rx_data. */ 482 483 if (precvframe == NULL) 484 return NULL; 485 486 precvframe->u.hdr.rx_tail -= sz; 487 488 if (precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data) 489 { 490 precvframe->u.hdr.rx_tail += sz; 491 return NULL; 492 } 493 494 precvframe->u.hdr.len -= sz; 495 496 return precvframe->u.hdr.rx_tail; 497 498 } 499 500 static inline union recv_frame *rxmem_to_recvframe(u8 *rxmem) 501 { 502 /* due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame */ 503 /* from any given member of recv_frame. */ 504 /* rxmem indicates the any member/address in recv_frame */ 505 506 return (union recv_frame *)(((SIZE_PTR)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN); 507 508 } 509 510 static inline sint get_recvframe_len(union recv_frame *precvframe) 511 { 512 return precvframe->u.hdr.len; 513 } 514 515 516 static inline s32 translate_percentage_to_dbm(u32 SignalStrengthIndex) 517 { 518 s32 SignalPower; /* in dBm. */ 519 520 #ifdef CONFIG_SKIP_SIGNAL_SCALE_MAPPING 521 /* Translate to dBm (x =y-100) */ 522 SignalPower = SignalStrengthIndex - 100; 523 #else 524 /* Translate to dBm (x = 0.5y-95). */ 525 SignalPower = (s32)((SignalStrengthIndex + 1) >> 1); 526 SignalPower -= 95; 527 #endif 528 529 return SignalPower; 530 } 531 532 533 struct sta_info; 534 535 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv); 536 537 extern void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame); 538 539 #endif 540