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