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