root/drivers/staging/rtl8723bs/include/rtw_recv.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. get_rxmem
  2. get_recvframe_data
  3. recvframe_pull
  4. recvframe_put
  5. recvframe_pull_tail
  6. rxmem_to_recvframe
  7. get_recvframe_len
  8. translate_percentage_to_dbm

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

/* [<][>][^][v][top][bottom][index][help] */