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