linux/drivers/staging/rtl8712/rtl8712_recv.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/******************************************************************************
   3 * rtl8712_recv.c
   4 *
   5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
   6 * Linux device driver for RTL8192SU
   7 *
   8 * Modifications for inclusion into the Linux staging tree are
   9 * Copyright(c) 2010 Larry Finger. All rights reserved.
  10 *
  11 * Contact information:
  12 * WLAN FAE <wlanfae@realtek.com>
  13 * Larry Finger <Larry.Finger@lwfinger.net>
  14 *
  15 ******************************************************************************/
  16
  17#define _RTL8712_RECV_C_
  18
  19#include <linux/if_ether.h>
  20#include <linux/ip.h>
  21
  22#include "osdep_service.h"
  23#include "drv_types.h"
  24#include "recv_osdep.h"
  25#include "mlme_osdep.h"
  26#include "ethernet.h"
  27#include "usb_ops.h"
  28#include "wifi.h"
  29
  30/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  31static u8 bridge_tunnel_header[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
  32
  33/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  34static u8 rfc1042_header[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  35
  36static void recv_tasklet(unsigned long priv);
  37
  38void r8712_init_recv_priv(struct recv_priv *precvpriv,
  39                          struct _adapter *padapter)
  40{
  41        int i;
  42        struct recv_buf *precvbuf;
  43        addr_t tmpaddr = 0;
  44        int alignment = 0;
  45        struct sk_buff *pskb = NULL;
  46
  47        /*init recv_buf*/
  48        _init_queue(&precvpriv->free_recv_buf_queue);
  49        precvpriv->pallocated_recv_buf =
  50                kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4, GFP_ATOMIC);
  51        if (!precvpriv->pallocated_recv_buf)
  52                return;
  53        precvpriv->precv_buf = precvpriv->pallocated_recv_buf + 4 -
  54                              ((addr_t)(precvpriv->pallocated_recv_buf) & 3);
  55        precvbuf = (struct recv_buf *)precvpriv->precv_buf;
  56        for (i = 0; i < NR_RECVBUFF; i++) {
  57                INIT_LIST_HEAD(&precvbuf->list);
  58                spin_lock_init(&precvbuf->recvbuf_lock);
  59                if (r8712_os_recvbuf_resource_alloc(padapter, precvbuf))
  60                        break;
  61                precvbuf->ref_cnt = 0;
  62                precvbuf->adapter = padapter;
  63                list_add_tail(&precvbuf->list,
  64                              &(precvpriv->free_recv_buf_queue.queue));
  65                precvbuf++;
  66        }
  67        precvpriv->free_recv_buf_queue_cnt = NR_RECVBUFF;
  68        tasklet_init(&precvpriv->recv_tasklet, recv_tasklet,
  69                     (unsigned long)padapter);
  70        skb_queue_head_init(&precvpriv->rx_skb_queue);
  71
  72        skb_queue_head_init(&precvpriv->free_recv_skb_queue);
  73        for (i = 0; i < NR_PREALLOC_RECV_SKB; i++) {
  74                pskb = netdev_alloc_skb(padapter->pnetdev, MAX_RECVBUF_SZ +
  75                       RECVBUFF_ALIGN_SZ);
  76                if (pskb) {
  77                        tmpaddr = (addr_t)pskb->data;
  78                        alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
  79                        skb_reserve(pskb, (RECVBUFF_ALIGN_SZ - alignment));
  80                        skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb);
  81                }
  82                pskb = NULL;
  83        }
  84}
  85
  86void r8712_free_recv_priv(struct recv_priv *precvpriv)
  87{
  88        int i;
  89        struct recv_buf *precvbuf;
  90        struct _adapter *padapter = precvpriv->adapter;
  91
  92        precvbuf = (struct recv_buf *)precvpriv->precv_buf;
  93        for (i = 0; i < NR_RECVBUFF; i++) {
  94                r8712_os_recvbuf_resource_free(padapter, precvbuf);
  95                precvbuf++;
  96        }
  97        kfree(precvpriv->pallocated_recv_buf);
  98        skb_queue_purge(&precvpriv->rx_skb_queue);
  99        if (skb_queue_len(&precvpriv->rx_skb_queue))
 100                netdev_warn(padapter->pnetdev, "r8712u: rx_skb_queue not empty\n");
 101        skb_queue_purge(&precvpriv->free_recv_skb_queue);
 102        if (skb_queue_len(&precvpriv->free_recv_skb_queue))
 103                netdev_warn(padapter->pnetdev, "r8712u: free_recv_skb_queue not empty %d\n",
 104                            skb_queue_len(&precvpriv->free_recv_skb_queue));
 105}
 106
 107void r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf)
 108{
 109        precvbuf->transfer_len = 0;
 110        precvbuf->len = 0;
 111        precvbuf->ref_cnt = 0;
 112        if (precvbuf->pbuf) {
 113                precvbuf->pdata = precvbuf->pbuf;
 114                precvbuf->phead = precvbuf->pbuf;
 115                precvbuf->ptail = precvbuf->pbuf;
 116                precvbuf->pend = precvbuf->pdata + MAX_RECVBUF_SZ;
 117        }
 118}
 119
 120void r8712_free_recvframe(union recv_frame *precvframe,
 121                          struct  __queue *pfree_recv_queue)
 122{
 123        unsigned long irqL;
 124        struct _adapter *padapter = precvframe->u.hdr.adapter;
 125        struct recv_priv *precvpriv = &padapter->recvpriv;
 126
 127        if (precvframe->u.hdr.pkt) {
 128                dev_kfree_skb_any(precvframe->u.hdr.pkt);/*free skb by driver*/
 129                precvframe->u.hdr.pkt = NULL;
 130        }
 131        spin_lock_irqsave(&pfree_recv_queue->lock, irqL);
 132        list_del_init(&(precvframe->u.hdr.list));
 133        list_add_tail(&(precvframe->u.hdr.list), &pfree_recv_queue->queue);
 134        if (padapter) {
 135                if (pfree_recv_queue == &precvpriv->free_recv_queue)
 136                        precvpriv->free_recvframe_cnt++;
 137        }
 138        spin_unlock_irqrestore(&pfree_recv_queue->lock, irqL);
 139}
 140
 141static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib,
 142                                                  struct recv_stat *prxstat)
 143{
 144        u16 drvinfo_sz;
 145
 146        drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16;
 147        drvinfo_sz <<= 3;
 148        /*TODO:
 149         * Offset 0
 150         */
 151        pattrib->bdecrypted = ((le32_to_cpu(prxstat->rxdw0) & BIT(27)) >> 27)
 152                                 ? 0 : 1;
 153        pattrib->crc_err = (le32_to_cpu(prxstat->rxdw0) & BIT(14)) >> 14;
 154        /*Offset 4*/
 155        /*Offset 8*/
 156        /*Offset 12*/
 157        if (le32_to_cpu(prxstat->rxdw3) & BIT(13)) {
 158                pattrib->tcpchk_valid = 1; /* valid */
 159                if (le32_to_cpu(prxstat->rxdw3) & BIT(11))
 160                        pattrib->tcp_chkrpt = 1; /* correct */
 161                else
 162                        pattrib->tcp_chkrpt = 0; /* incorrect */
 163                if (le32_to_cpu(prxstat->rxdw3) & BIT(12))
 164                        pattrib->ip_chkrpt = 1; /* correct */
 165                else
 166                        pattrib->ip_chkrpt = 0; /* incorrect */
 167        } else {
 168                pattrib->tcpchk_valid = 0; /* invalid */
 169        }
 170        pattrib->mcs_rate = (u8)((le32_to_cpu(prxstat->rxdw3)) & 0x3f);
 171        pattrib->htc = (u8)((le32_to_cpu(prxstat->rxdw3) >> 14) & 0x1);
 172        /*Offset 16*/
 173        /*Offset 20*/
 174        /*phy_info*/
 175}
 176
 177/*perform defrag*/
 178static union recv_frame *recvframe_defrag(struct _adapter *adapter,
 179                                          struct  __queue *defrag_q)
 180{
 181        struct list_head *plist, *phead;
 182        u8 wlanhdr_offset;
 183        u8      curfragnum;
 184        struct recv_frame_hdr *pfhdr, *pnfhdr;
 185        union recv_frame *prframe, *pnextrframe;
 186        struct  __queue *pfree_recv_queue;
 187
 188        pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
 189        phead = &defrag_q->queue;
 190        plist = phead->next;
 191        prframe = container_of(plist, union recv_frame, u.list);
 192        list_del_init(&prframe->u.list);
 193        pfhdr = &prframe->u.hdr;
 194        curfragnum = 0;
 195        if (curfragnum != pfhdr->attrib.frag_num) {
 196                /*the first fragment number must be 0
 197                 *free the whole queue
 198                 */
 199                r8712_free_recvframe(prframe, pfree_recv_queue);
 200                r8712_free_recvframe_queue(defrag_q, pfree_recv_queue);
 201                return NULL;
 202        }
 203        curfragnum++;
 204        plist = &defrag_q->queue;
 205        plist = plist->next;
 206        while (!end_of_queue_search(phead, plist)) {
 207                pnextrframe = container_of(plist, union recv_frame, u.list);
 208                pnfhdr = &pnextrframe->u.hdr;
 209                /*check the fragment sequence  (2nd ~n fragment frame) */
 210                if (curfragnum != pnfhdr->attrib.frag_num) {
 211                        /* the fragment number must increase  (after decache)
 212                         * release the defrag_q & prframe
 213                         */
 214                        r8712_free_recvframe(prframe, pfree_recv_queue);
 215                        r8712_free_recvframe_queue(defrag_q, pfree_recv_queue);
 216                        return NULL;
 217                }
 218                curfragnum++;
 219                /* copy the 2nd~n fragment frame's payload to the first fragment
 220                 * get the 2nd~last fragment frame's payload
 221                 */
 222                wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
 223                recvframe_pull(pnextrframe, wlanhdr_offset);
 224                /* append  to first fragment frame's tail (if privacy frame,
 225                 * pull the ICV)
 226                 */
 227                recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
 228                memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
 229                recvframe_put(prframe, pnfhdr->len);
 230                pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
 231                plist = plist->next;
 232        }
 233        /* free the defrag_q queue and return the prframe */
 234        r8712_free_recvframe_queue(defrag_q, pfree_recv_queue);
 235        return prframe;
 236}
 237
 238/* check if need to defrag, if needed queue the frame to defrag_q */
 239union recv_frame *r8712_recvframe_chk_defrag(struct _adapter *padapter,
 240                                             union recv_frame *precv_frame)
 241{
 242        u8      ismfrag;
 243        u8      fragnum;
 244        u8   *psta_addr;
 245        struct recv_frame_hdr *pfhdr;
 246        struct sta_info *psta;
 247        struct  sta_priv *pstapriv;
 248        struct list_head *phead;
 249        union recv_frame *prtnframe = NULL;
 250        struct  __queue *pfree_recv_queue, *pdefrag_q;
 251
 252        pstapriv = &padapter->stapriv;
 253        pfhdr = &precv_frame->u.hdr;
 254        pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
 255        /* need to define struct of wlan header frame ctrl */
 256        ismfrag = pfhdr->attrib.mfrag;
 257        fragnum = pfhdr->attrib.frag_num;
 258        psta_addr = pfhdr->attrib.ta;
 259        psta = r8712_get_stainfo(pstapriv, psta_addr);
 260        if (!psta)
 261                pdefrag_q = NULL;
 262        else
 263                pdefrag_q = &psta->sta_recvpriv.defrag_q;
 264
 265        if ((ismfrag == 0) && (fragnum == 0))
 266                prtnframe = precv_frame;/*isn't a fragment frame*/
 267        if (ismfrag == 1) {
 268                /* 0~(n-1) fragment frame
 269                 * enqueue to defraf_g
 270                 */
 271                if (pdefrag_q) {
 272                        if (fragnum == 0) {
 273                                /*the first fragment*/
 274                                if (!list_empty(&pdefrag_q->queue)) {
 275                                        /*free current defrag_q */
 276                                        r8712_free_recvframe_queue(pdefrag_q,
 277                                                             pfree_recv_queue);
 278                                }
 279                        }
 280                        /* Then enqueue the 0~(n-1) fragment to the defrag_q */
 281                        phead = &pdefrag_q->queue;
 282                        list_add_tail(&pfhdr->list, phead);
 283                        prtnframe = NULL;
 284                } else {
 285                        /* can't find this ta's defrag_queue, so free this
 286                         * recv_frame
 287                         */
 288                        r8712_free_recvframe(precv_frame, pfree_recv_queue);
 289                        prtnframe = NULL;
 290                }
 291        }
 292        if ((ismfrag == 0) && (fragnum != 0)) {
 293                /* the last fragment frame
 294                 * enqueue the last fragment
 295                 */
 296                if (pdefrag_q) {
 297                        phead = &pdefrag_q->queue;
 298                        list_add_tail(&pfhdr->list, phead);
 299                        /*call recvframe_defrag to defrag*/
 300                        precv_frame = recvframe_defrag(padapter, pdefrag_q);
 301                        prtnframe = precv_frame;
 302                } else {
 303                        /* can't find this ta's defrag_queue, so free this
 304                         *  recv_frame
 305                         */
 306                        r8712_free_recvframe(precv_frame, pfree_recv_queue);
 307                        prtnframe = NULL;
 308                }
 309        }
 310        if (prtnframe && (prtnframe->u.hdr.attrib.privacy)) {
 311                /* after defrag we must check tkip mic code */
 312                if (r8712_recvframe_chkmic(padapter, prtnframe) == _FAIL) {
 313                        r8712_free_recvframe(prtnframe, pfree_recv_queue);
 314                        prtnframe = NULL;
 315                }
 316        }
 317        return prtnframe;
 318}
 319
 320static void amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe)
 321{
 322        int     a_len, padding_len;
 323        u16     eth_type, nSubframe_Length;
 324        u8      nr_subframes, i;
 325        unsigned char *pdata;
 326        struct rx_pkt_attrib *pattrib;
 327        _pkt *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
 328        struct recv_priv *precvpriv = &padapter->recvpriv;
 329        struct  __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
 330
 331        nr_subframes = 0;
 332        pattrib = &prframe->u.hdr.attrib;
 333        recvframe_pull(prframe, prframe->u.hdr.attrib.hdrlen);
 334        if (prframe->u.hdr.attrib.iv_len > 0)
 335                recvframe_pull(prframe, prframe->u.hdr.attrib.iv_len);
 336        a_len = prframe->u.hdr.len;
 337        pdata = prframe->u.hdr.rx_data;
 338        while (a_len > ETH_HLEN) {
 339                /* Offset 12 denote 2 mac address */
 340                nSubframe_Length = *((u16 *)(pdata + 12));
 341                /*==m==>change the length order*/
 342                nSubframe_Length = (nSubframe_Length >> 8) +
 343                                   (nSubframe_Length << 8);
 344                if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
 345                        netdev_warn(padapter->pnetdev, "r8712u: nRemain_Length is %d and nSubframe_Length is: %d\n",
 346                                    a_len, nSubframe_Length);
 347                        goto exit;
 348                }
 349                /* move the data point to data content */
 350                pdata += ETH_HLEN;
 351                a_len -= ETH_HLEN;
 352                /* Allocate new skb for releasing to upper layer */
 353                sub_skb = dev_alloc_skb(nSubframe_Length + 12);
 354                if (!sub_skb)
 355                        break;
 356                skb_reserve(sub_skb, 12);
 357                skb_put_data(sub_skb, pdata, nSubframe_Length);
 358                subframes[nr_subframes++] = sub_skb;
 359                if (nr_subframes >= MAX_SUBFRAME_COUNT) {
 360                        netdev_warn(padapter->pnetdev, "r8712u: ParseSubframe(): Too many Subframes! Packets dropped!\n");
 361                        break;
 362                }
 363                pdata += nSubframe_Length;
 364                a_len -= nSubframe_Length;
 365                if (a_len != 0) {
 366                        padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & 3);
 367                        if (padding_len == 4)
 368                                padding_len = 0;
 369                        if (a_len < padding_len)
 370                                goto exit;
 371                        pdata += padding_len;
 372                        a_len -= padding_len;
 373                }
 374        }
 375        for (i = 0; i < nr_subframes; i++) {
 376                sub_skb = subframes[i];
 377                /* convert hdr + possible LLC headers into Ethernet header */
 378                eth_type = (sub_skb->data[6] << 8) | sub_skb->data[7];
 379                if (sub_skb->len >= 8 &&
 380                    ((!memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) &&
 381                      eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
 382                     !memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE))) {
 383                        /* remove RFC1042 or Bridge-Tunnel encapsulation and
 384                         * replace EtherType
 385                         */
 386                        skb_pull(sub_skb, SNAP_SIZE);
 387                        memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src,
 388                               ETH_ALEN);
 389                        memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst,
 390                               ETH_ALEN);
 391                } else {
 392                        __be16 len;
 393                        /* Leave Ethernet header part of hdr and full payload */
 394                        len = htons(sub_skb->len);
 395                        memcpy(skb_push(sub_skb, 2), &len, 2);
 396                        memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src,
 397                               ETH_ALEN);
 398                        memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst,
 399                               ETH_ALEN);
 400                }
 401                /* Indicate the packets to upper layer */
 402                if (sub_skb) {
 403                        sub_skb->protocol =
 404                                 eth_type_trans(sub_skb, padapter->pnetdev);
 405                        sub_skb->dev = padapter->pnetdev;
 406                        if ((pattrib->tcpchk_valid == 1) &&
 407                            (pattrib->tcp_chkrpt == 1)) {
 408                                sub_skb->ip_summed = CHECKSUM_UNNECESSARY;
 409                        } else {
 410                                sub_skb->ip_summed = CHECKSUM_NONE;
 411                        }
 412                        netif_rx(sub_skb);
 413                }
 414        }
 415exit:
 416        prframe->u.hdr.len = 0;
 417        r8712_free_recvframe(prframe, pfree_recv_queue);
 418}
 419
 420void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf)
 421{
 422        __le32 voffset;
 423        u8 *poffset;
 424        u16 cmd_len, drvinfo_sz;
 425        struct recv_stat *prxstat;
 426
 427        poffset = prxcmdbuf;
 428        voffset = *(__le32 *)poffset;
 429        prxstat = prxcmdbuf;
 430        drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16;
 431        drvinfo_sz <<= 3;
 432        poffset += RXDESC_SIZE + drvinfo_sz;
 433        do {
 434                voffset  = *(__le32 *)poffset;
 435                cmd_len = (u16)(le32_to_cpu(voffset) & 0xffff);
 436                r8712_event_handle(padapter, (__le32 *)poffset);
 437                poffset += (cmd_len + 8);/*8 bytes alignment*/
 438        } while (le32_to_cpu(voffset) & BIT(31));
 439}
 440
 441static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl,
 442                              u16 seq_num)
 443{
 444        u8 wsize = preorder_ctrl->wsize_b;
 445        u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) % 4096;
 446
 447        /* Rx Reorder initialize condition.*/
 448        if (preorder_ctrl->indicate_seq == 0xffff)
 449                preorder_ctrl->indicate_seq = seq_num;
 450        /* Drop out the packet which SeqNum is smaller than WinStart */
 451        if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
 452                return false;
 453        /*
 454         * Sliding window manipulation. Conditions includes:
 455         * 1. Incoming SeqNum is equal to WinStart =>Window shift 1
 456         * 2. Incoming SeqNum is larger than the WinEnd => Window shift N
 457         */
 458        if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq))
 459                preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq +
 460                                              1) % 4096;
 461        else if (SN_LESS(wend, seq_num)) {
 462                if (seq_num >= (wsize - 1))
 463                        preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
 464                else
 465                        preorder_ctrl->indicate_seq = 4095 - (wsize -
 466                                                      (seq_num + 1)) + 1;
 467        }
 468        return true;
 469}
 470
 471static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 472                                     union recv_frame *prframe)
 473{
 474        struct list_head *phead, *plist;
 475        union recv_frame *pnextrframe;
 476        struct rx_pkt_attrib *pnextattrib;
 477        struct  __queue *ppending_recvframe_queue =
 478                                        &preorder_ctrl->pending_recvframe_queue;
 479        struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
 480
 481        phead = &ppending_recvframe_queue->queue;
 482        plist = phead->next;
 483        while (!end_of_queue_search(phead, plist)) {
 484                pnextrframe = container_of(plist, union recv_frame, u.list);
 485                pnextattrib = &pnextrframe->u.hdr.attrib;
 486                if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
 487                        plist = plist->next;
 488                else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
 489                        return false;
 490                else
 491                        break;
 492        }
 493        list_del_init(&(prframe->u.hdr.list));
 494        list_add_tail(&(prframe->u.hdr.list), plist);
 495        return true;
 496}
 497
 498int r8712_recv_indicatepkts_in_order(struct _adapter *padapter,
 499                                     struct recv_reorder_ctrl *preorder_ctrl,
 500                                     int bforced)
 501{
 502        struct list_head *phead, *plist;
 503        union recv_frame *prframe;
 504        struct rx_pkt_attrib *pattrib;
 505        int bPktInBuf = false;
 506        struct  __queue *ppending_recvframe_queue =
 507                         &preorder_ctrl->pending_recvframe_queue;
 508
 509        phead = &ppending_recvframe_queue->queue;
 510        plist = phead->next;
 511        /* Handling some condition for forced indicate case.*/
 512        if (bforced) {
 513                if (list_empty(phead))
 514                        return true;
 515
 516                prframe = container_of(plist, union recv_frame, u.list);
 517                pattrib = &prframe->u.hdr.attrib;
 518                preorder_ctrl->indicate_seq = pattrib->seq_num;
 519        }
 520        /* Prepare indication list and indication.
 521         * Check if there is any packet need indicate.
 522         */
 523        while (!list_empty(phead)) {
 524                prframe = container_of(plist, union recv_frame, u.list);
 525                pattrib = &prframe->u.hdr.attrib;
 526                if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
 527                        plist = plist->next;
 528                        list_del_init(&(prframe->u.hdr.list));
 529                        if (SN_EQUAL(preorder_ctrl->indicate_seq,
 530                                     pattrib->seq_num))
 531                                preorder_ctrl->indicate_seq =
 532                                  (preorder_ctrl->indicate_seq + 1) % 4096;
 533                        /*indicate this recv_frame*/
 534                        if (!pattrib->amsdu) {
 535                                if (!padapter->driver_stopped &&
 536                                    !padapter->surprise_removed) {
 537                                        /* indicate this recv_frame */
 538                                        r8712_recv_indicatepkt(padapter,
 539                                                               prframe);
 540                                }
 541                        } else if (pattrib->amsdu == 1) {
 542                                amsdu_to_msdu(padapter, prframe);
 543                        }
 544                        /* Update local variables. */
 545                        bPktInBuf = false;
 546                } else {
 547                        bPktInBuf = true;
 548                        break;
 549                }
 550        }
 551        return bPktInBuf;
 552}
 553
 554static int recv_indicatepkt_reorder(struct _adapter *padapter,
 555                                    union recv_frame *prframe)
 556{
 557        unsigned long irql;
 558        struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
 559        struct recv_reorder_ctrl *preorder_ctrl = prframe->u.hdr.preorder_ctrl;
 560        struct  __queue *ppending_recvframe_queue =
 561                         &preorder_ctrl->pending_recvframe_queue;
 562
 563        if (!pattrib->amsdu) {
 564                /* s1. */
 565                r8712_wlanhdr_to_ethhdr(prframe);
 566                if (pattrib->qos != 1) {
 567                        if (!padapter->driver_stopped &&
 568                            !padapter->surprise_removed) {
 569                                r8712_recv_indicatepkt(padapter, prframe);
 570                                return 0;
 571                        } else {
 572                                return -EINVAL;
 573                        }
 574                }
 575        }
 576        spin_lock_irqsave(&ppending_recvframe_queue->lock, irql);
 577        /*s2. check if winstart_b(indicate_seq) needs to be updated*/
 578        if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num))
 579                goto _err_exit;
 580        /*s3. Insert all packet into Reorder Queue to maintain its ordering.*/
 581        if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
 582                goto _err_exit;
 583        /*s4.
 584         * Indication process.
 585         * After Packet dropping and Sliding Window shifting as above, we can
 586         * now just indicate the packets with the SeqNum smaller than latest
 587         * WinStart and buffer other packets.
 588         *
 589         * For Rx Reorder condition:
 590         * 1. All packets with SeqNum smaller than WinStart => Indicate
 591         * 2. All packets with SeqNum larger than or equal to
 592         * WinStart => Buffer it.
 593         */
 594        if (r8712_recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
 595                mod_timer(&preorder_ctrl->reordering_ctrl_timer,
 596                          jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
 597                spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
 598        } else {
 599                spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
 600                del_timer(&preorder_ctrl->reordering_ctrl_timer);
 601        }
 602        return 0;
 603_err_exit:
 604        spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
 605        return -ENOMEM;
 606}
 607
 608void r8712_reordering_ctrl_timeout_handler(void *pcontext)
 609{
 610        unsigned long irql;
 611        struct recv_reorder_ctrl *preorder_ctrl = pcontext;
 612        struct _adapter *padapter = preorder_ctrl->padapter;
 613        struct  __queue *ppending_recvframe_queue =
 614                                 &preorder_ctrl->pending_recvframe_queue;
 615
 616        if (padapter->driver_stopped || padapter->surprise_removed)
 617                return;
 618        spin_lock_irqsave(&ppending_recvframe_queue->lock, irql);
 619        r8712_recv_indicatepkts_in_order(padapter, preorder_ctrl, true);
 620        spin_unlock_irqrestore(&ppending_recvframe_queue->lock, irql);
 621}
 622
 623static int r8712_process_recv_indicatepkts(struct _adapter *padapter,
 624                                           union recv_frame *prframe)
 625{
 626        int retval = _SUCCESS;
 627        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 628        struct ht_priv  *phtpriv = &pmlmepriv->htpriv;
 629
 630        if (phtpriv->ht_option == 1) { /*B/G/N Mode*/
 631                if (recv_indicatepkt_reorder(padapter, prframe)) {
 632                        /* including perform A-MPDU Rx Ordering Buffer Control*/
 633                        if (!padapter->driver_stopped &&
 634                            !padapter->surprise_removed)
 635                                return _FAIL;
 636                }
 637        } else { /*B/G mode*/
 638                retval = r8712_wlanhdr_to_ethhdr(prframe);
 639                if (retval)
 640                        return _FAIL;
 641                if (!padapter->driver_stopped && !padapter->surprise_removed) {
 642                        /* indicate this recv_frame */
 643                        r8712_recv_indicatepkt(padapter, prframe);
 644                } else {
 645                        return _FAIL;
 646                }
 647        }
 648        return retval;
 649}
 650
 651static u8 query_rx_pwr_percentage(s8 antpower)
 652{
 653        if ((antpower <= -100) || (antpower >= 20))
 654                return  0;
 655        else if (antpower >= 0)
 656                return  100;
 657        else
 658                return 100 + antpower;
 659}
 660
 661static u8 evm_db2percentage(s8 value)
 662{
 663        /*
 664         * -33dB~0dB to 0%~99%
 665         */
 666        s8 ret_val = clamp(-value, 0, 33) * 3;
 667
 668        if (ret_val == 99)
 669                ret_val = 100;
 670
 671        return ret_val;
 672}
 673
 674s32 r8712_signal_scale_mapping(s32 cur_sig)
 675{
 676        s32 ret_sig;
 677
 678        if (cur_sig >= 51 && cur_sig <= 100)
 679                ret_sig = 100;
 680        else if (cur_sig >= 41 && cur_sig <= 50)
 681                ret_sig = 80 + ((cur_sig - 40) * 2);
 682        else if (cur_sig >= 31 && cur_sig <= 40)
 683                ret_sig = 66 + (cur_sig - 30);
 684        else if (cur_sig >= 21 && cur_sig <= 30)
 685                ret_sig = 54 + (cur_sig - 20);
 686        else if (cur_sig >= 10 && cur_sig <= 20)
 687                ret_sig = 42 + (((cur_sig - 10) * 2) / 3);
 688        else if (cur_sig >= 5 && cur_sig <= 9)
 689                ret_sig = 22 + (((cur_sig - 5) * 3) / 2);
 690        else if (cur_sig >= 1 && cur_sig <= 4)
 691                ret_sig = 6 + (((cur_sig - 1) * 3) / 2);
 692        else
 693                ret_sig = cur_sig;
 694        return ret_sig;
 695}
 696
 697static s32  translate2dbm(struct _adapter *padapter, u8 signal_strength_idx)
 698{
 699        s32 signal_power; /* in dBm.*/
 700        /* Translate to dBm (x=0.5y-95).*/
 701        signal_power = (s32)((signal_strength_idx + 1) >> 1);
 702        signal_power -= 95;
 703        return signal_power;
 704}
 705
 706static void query_rx_phy_status(struct _adapter *padapter,
 707                                union recv_frame *prframe)
 708{
 709        u8 i, max_spatial_stream, evm;
 710        struct recv_stat *prxstat = (struct recv_stat *)prframe->u.hdr.rx_head;
 711        struct phy_stat *pphy_stat = (struct phy_stat *)(prxstat + 1);
 712        u8 *pphy_head = (u8 *)(prxstat + 1);
 713        s8 rx_pwr[4], rx_pwr_all;
 714        u8 pwdb_all;
 715        u32 rssi, total_rssi = 0;
 716        u8 bcck_rate = 0, rf_rx_num = 0, cck_highpwr = 0;
 717        struct phy_cck_rx_status *pcck_buf;
 718        u8 sq;
 719
 720        /* Record it for next packet processing*/
 721        bcck_rate = (prframe->u.hdr.attrib.mcs_rate <= 3 ? 1 : 0);
 722        if (bcck_rate) {
 723                u8 report;
 724
 725                /* CCK Driver info Structure is not the same as OFDM packet.*/
 726                pcck_buf = (struct phy_cck_rx_status *)pphy_stat;
 727                /* (1)Hardware does not provide RSSI for CCK
 728                 * (2)PWDB, Average PWDB calculated by hardware
 729                 * (for rate adaptive)
 730                 */
 731                if (!cck_highpwr) {
 732                        report = pcck_buf->cck_agc_rpt & 0xc0;
 733                        report >>= 6;
 734                        switch (report) {
 735                        /* Modify the RF RNA gain value to -40, -20,
 736                         * -2, 14 by Jenyu's suggestion
 737                         * Note: different RF with the different
 738                         * RNA gain.
 739                         */
 740                        case 0x3:
 741                                rx_pwr_all = -40 - (pcck_buf->cck_agc_rpt &
 742                                             0x3e);
 743                                break;
 744                        case 0x2:
 745                                rx_pwr_all = -20 - (pcck_buf->cck_agc_rpt &
 746                                             0x3e);
 747                                break;
 748                        case 0x1:
 749                                rx_pwr_all = -2 - (pcck_buf->cck_agc_rpt &
 750                                             0x3e);
 751                                break;
 752                        case 0x0:
 753                                rx_pwr_all = 14 - (pcck_buf->cck_agc_rpt &
 754                                             0x3e);
 755                                break;
 756                        }
 757                } else {
 758                        report = ((u8)(le32_to_cpu(pphy_stat->phydw1) >> 8)) &
 759                                 0x60;
 760                        report >>= 5;
 761                        switch (report) {
 762                        case 0x3:
 763                                rx_pwr_all = -40 - ((pcck_buf->cck_agc_rpt &
 764                                             0x1f) << 1);
 765                                break;
 766                        case 0x2:
 767                                rx_pwr_all = -20 - ((pcck_buf->cck_agc_rpt &
 768                                             0x1f) << 1);
 769                                break;
 770                        case 0x1:
 771                                rx_pwr_all = -2 - ((pcck_buf->cck_agc_rpt &
 772                                             0x1f) << 1);
 773                                break;
 774                        case 0x0:
 775                                rx_pwr_all = 14 - ((pcck_buf->cck_agc_rpt &
 776                                             0x1f) << 1);
 777                                break;
 778                        }
 779                }
 780                pwdb_all = query_rx_pwr_percentage(rx_pwr_all);
 781                /* CCK gain is smaller than OFDM/MCS gain,*/
 782                /* so we add gain diff by experiences, the val is 6 */
 783                pwdb_all += 6;
 784                if (pwdb_all > 100)
 785                        pwdb_all = 100;
 786                /* modify the offset to make the same gain index with OFDM.*/
 787                if (pwdb_all > 34 && pwdb_all <= 42)
 788                        pwdb_all -= 2;
 789                else if (pwdb_all > 26 && pwdb_all <= 34)
 790                        pwdb_all -= 6;
 791                else if (pwdb_all > 14 && pwdb_all <= 26)
 792                        pwdb_all -= 8;
 793                else if (pwdb_all > 4 && pwdb_all <= 14)
 794                        pwdb_all -= 4;
 795                /*
 796                 * (3) Get Signal Quality (EVM)
 797                 */
 798                if (pwdb_all > 40) {
 799                        sq = 100;
 800                } else {
 801                        sq = pcck_buf->sq_rpt;
 802                        if (pcck_buf->sq_rpt > 64)
 803                                sq = 0;
 804                        else if (pcck_buf->sq_rpt < 20)
 805                                sq = 100;
 806                        else
 807                                sq = ((64 - sq) * 100) / 44;
 808                }
 809                prframe->u.hdr.attrib.signal_qual = sq;
 810                prframe->u.hdr.attrib.rx_mimo_signal_qual[0] = sq;
 811                prframe->u.hdr.attrib.rx_mimo_signal_qual[1] = -1;
 812        } else {
 813                /* (1)Get RSSI for HT rate */
 814                for (i = 0; i < ((padapter->registrypriv.rf_config) &
 815                            0x0f); i++) {
 816                        rf_rx_num++;
 817                        rx_pwr[i] = ((pphy_head[PHY_STAT_GAIN_TRSW_SHT + i]
 818                                    & 0x3F) * 2) - 110;
 819                        /* Translate DBM to percentage. */
 820                        rssi = query_rx_pwr_percentage(rx_pwr[i]);
 821                        total_rssi += rssi;
 822                }
 823                /* (2)PWDB, Average PWDB calculated by hardware (for
 824                 * rate adaptive)
 825                 */
 826                rx_pwr_all = (((pphy_head[PHY_STAT_PWDB_ALL_SHT]) >> 1) & 0x7f)
 827                             - 106;
 828                pwdb_all = query_rx_pwr_percentage(rx_pwr_all);
 829
 830                {
 831                        /* (3)EVM of HT rate */
 832                        if (prframe->u.hdr.attrib.htc &&
 833                            prframe->u.hdr.attrib.mcs_rate >= 20 &&
 834                            prframe->u.hdr.attrib.mcs_rate <= 27) {
 835                                /* both spatial stream make sense */
 836                                max_spatial_stream = 2;
 837                        } else {
 838                                /* only spatial stream 1 makes sense */
 839                                max_spatial_stream = 1;
 840                        }
 841                        for (i = 0; i < max_spatial_stream; i++) {
 842                                evm = evm_db2percentage((pphy_head
 843                                      [PHY_STAT_RXEVM_SHT + i]));/*dbm*/
 844                                prframe->u.hdr.attrib.signal_qual =
 845                                         (u8)(evm & 0xff);
 846                                prframe->u.hdr.attrib.rx_mimo_signal_qual[i] =
 847                                         (u8)(evm & 0xff);
 848                        }
 849                }
 850        }
 851        /* UI BSS List signal strength(in percentage), make it good looking,
 852         * from 0~100. It is assigned to the BSS List in
 853         * GetValueFromBeaconOrProbeRsp().
 854         */
 855        if (bcck_rate) {
 856                prframe->u.hdr.attrib.signal_strength =
 857                         (u8)r8712_signal_scale_mapping(pwdb_all);
 858        } else {
 859                if (rf_rx_num != 0)
 860                        prframe->u.hdr.attrib.signal_strength =
 861                                 (u8)(r8712_signal_scale_mapping(total_rssi /=
 862                                 rf_rx_num));
 863        }
 864}
 865
 866static void process_link_qual(struct _adapter *padapter,
 867                              union recv_frame *prframe)
 868{
 869        u32     last_evm = 0, tmpVal;
 870        struct rx_pkt_attrib *pattrib;
 871        struct smooth_rssi_data *sqd = &padapter->recvpriv.signal_qual_data;
 872
 873        if (!prframe || !padapter)
 874                return;
 875        pattrib = &prframe->u.hdr.attrib;
 876        if (pattrib->signal_qual != 0) {
 877                /*
 878                 * 1. Record the general EVM to the sliding window.
 879                 */
 880                if (sqd->total_num++ >= PHY_LINKQUALITY_SLID_WIN_MAX) {
 881                        sqd->total_num = PHY_LINKQUALITY_SLID_WIN_MAX;
 882                        last_evm = sqd->elements[sqd->index];
 883                        sqd->total_val -= last_evm;
 884                }
 885                sqd->total_val += pattrib->signal_qual;
 886                sqd->elements[sqd->index++] = pattrib->signal_qual;
 887                if (sqd->index >= PHY_LINKQUALITY_SLID_WIN_MAX)
 888                        sqd->index = 0;
 889
 890                /* <1> Showed on UI for user, in percentage. */
 891                tmpVal = sqd->total_val / sqd->total_num;
 892                padapter->recvpriv.signal = (u8)tmpVal;
 893        }
 894}
 895
 896static void process_rssi(struct _adapter *padapter, union recv_frame *prframe)
 897{
 898        u32 last_rssi, tmp_val;
 899        struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
 900        struct smooth_rssi_data *ssd = &padapter->recvpriv.signal_strength_data;
 901
 902        if (ssd->total_num++ >= PHY_RSSI_SLID_WIN_MAX) {
 903                ssd->total_num = PHY_RSSI_SLID_WIN_MAX;
 904                last_rssi = ssd->elements[ssd->index];
 905                ssd->total_val -= last_rssi;
 906        }
 907        ssd->total_val += pattrib->signal_strength;
 908        ssd->elements[ssd->index++] = pattrib->signal_strength;
 909        if (ssd->index >= PHY_RSSI_SLID_WIN_MAX)
 910                ssd->index = 0;
 911        tmp_val = ssd->total_val / ssd->total_num;
 912        padapter->recvpriv.rssi = (s8)translate2dbm(padapter, (u8)tmp_val);
 913}
 914
 915static void process_phy_info(struct _adapter *padapter,
 916                             union recv_frame *prframe)
 917{
 918        query_rx_phy_status(padapter, prframe);
 919        process_rssi(padapter, prframe);
 920        process_link_qual(padapter,  prframe);
 921}
 922
 923int recv_func(struct _adapter *padapter, void *pcontext)
 924{
 925        struct rx_pkt_attrib *pattrib;
 926        union recv_frame *prframe, *orig_prframe;
 927        int retval = _SUCCESS;
 928        struct  __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
 929        struct  mlme_priv       *pmlmepriv = &padapter->mlmepriv;
 930
 931        prframe = pcontext;
 932        orig_prframe = prframe;
 933        pattrib = &prframe->u.hdr.attrib;
 934        if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
 935                if (pattrib->crc_err == 1)
 936                        padapter->mppriv.rx_crcerrpktcount++;
 937                else
 938                        padapter->mppriv.rx_pktcount++;
 939                if (!check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE)) {
 940                        /* free this recv_frame */
 941                        r8712_free_recvframe(orig_prframe, pfree_recv_queue);
 942                        goto _exit_recv_func;
 943                }
 944        }
 945        /* check the frame crtl field and decache */
 946        retval = r8712_validate_recv_frame(padapter, prframe);
 947        if (retval != _SUCCESS) {
 948                /* free this recv_frame */
 949                r8712_free_recvframe(orig_prframe, pfree_recv_queue);
 950                goto _exit_recv_func;
 951        }
 952        process_phy_info(padapter, prframe);
 953        prframe = r8712_decryptor(padapter, prframe);
 954        if (!prframe) {
 955                retval = _FAIL;
 956                goto _exit_recv_func;
 957        }
 958        prframe = r8712_recvframe_chk_defrag(padapter, prframe);
 959        if (!prframe)
 960                goto _exit_recv_func;
 961        prframe = r8712_portctrl(padapter, prframe);
 962        if (!prframe) {
 963                retval = _FAIL;
 964                goto _exit_recv_func;
 965        }
 966        retval = r8712_process_recv_indicatepkts(padapter, prframe);
 967        if (retval != _SUCCESS) {
 968                r8712_free_recvframe(orig_prframe, pfree_recv_queue);
 969                goto _exit_recv_func;
 970        }
 971_exit_recv_func:
 972        return retval;
 973}
 974
 975static void recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
 976{
 977        u8 *pbuf, shift_sz = 0;
 978        u8      frag, mf;
 979        uint    pkt_len;
 980        u32 transfer_len;
 981        struct recv_stat *prxstat;
 982        u16     pkt_cnt, drvinfo_sz, pkt_offset, tmp_len, alloc_sz;
 983        struct  __queue *pfree_recv_queue;
 984        _pkt  *pkt_copy = NULL;
 985        union recv_frame *precvframe = NULL;
 986        struct recv_priv *precvpriv = &padapter->recvpriv;
 987
 988        pfree_recv_queue = &(precvpriv->free_recv_queue);
 989        pbuf = pskb->data;
 990        prxstat = (struct recv_stat *)pbuf;
 991        pkt_cnt = (le32_to_cpu(prxstat->rxdw2) >> 16) & 0xff;
 992        pkt_len =  le32_to_cpu(prxstat->rxdw0) & 0x00003fff;
 993        transfer_len = pskb->len;
 994        /* Test throughput with Netgear 3700 (No security) with Chariot 3T3R
 995         * pairs. The packet count will be a big number so that the containing
 996         * packet will effect the Rx reordering.
 997         */
 998        if (transfer_len < pkt_len) {
 999                /* In this case, it means the MAX_RECVBUF_SZ is too small to
1000                 * get the data from 8712u.
1001                 */
1002                return;
1003        }
1004        do {
1005                prxstat = (struct recv_stat *)pbuf;
1006                pkt_len =  le32_to_cpu(prxstat->rxdw0) & 0x00003fff;
1007                /* more fragment bit */
1008                mf = (le32_to_cpu(prxstat->rxdw1) >> 27) & 0x1;
1009                /* ragmentation number */
1010                frag = (le32_to_cpu(prxstat->rxdw2) >> 12) & 0xf;
1011                /* uint 2^3 = 8 bytes */
1012                drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16;
1013                drvinfo_sz <<= 3;
1014                if (pkt_len <= 0)
1015                        return;
1016                /* Qos data, wireless lan header length is 26 */
1017                if ((le32_to_cpu(prxstat->rxdw0) >> 23) & 0x01)
1018                        shift_sz = 2;
1019                precvframe = r8712_alloc_recvframe(pfree_recv_queue);
1020                if (!precvframe)
1021                        return;
1022                INIT_LIST_HEAD(&precvframe->u.hdr.list);
1023                precvframe->u.hdr.precvbuf = NULL; /*can't access the precvbuf*/
1024                precvframe->u.hdr.len = 0;
1025                tmp_len = pkt_len + drvinfo_sz + RXDESC_SIZE;
1026                pkt_offset = (u16)round_up(tmp_len, 128);
1027                /* for first fragment packet, driver need allocate 1536 +
1028                 * drvinfo_sz + RXDESC_SIZE to defrag packet.
1029                 */
1030                if ((mf == 1) && (frag == 0))
1031                        /*1658+6=1664, 1664 is 128 alignment.*/
1032                        alloc_sz = max_t(u16, tmp_len, 1658);
1033                else
1034                        alloc_sz = tmp_len;
1035                /* 2 is for IP header 4 bytes alignment in QoS packet case.
1036                 * 4 is for skb->data 4 bytes alignment.
1037                 */
1038                alloc_sz += 6;
1039                pkt_copy = netdev_alloc_skb(padapter->pnetdev, alloc_sz);
1040                if (pkt_copy) {
1041                        precvframe->u.hdr.pkt = pkt_copy;
1042                        skb_reserve(pkt_copy, 4 - ((addr_t)(pkt_copy->data)
1043                                    % 4));
1044                        skb_reserve(pkt_copy, shift_sz);
1045                        memcpy(pkt_copy->data, pbuf, tmp_len);
1046                        precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data =
1047                                 precvframe->u.hdr.rx_tail = pkt_copy->data;
1048                        precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz;
1049                } else {
1050                        precvframe->u.hdr.pkt = skb_clone(pskb, GFP_ATOMIC);
1051                        if (!precvframe->u.hdr.pkt)
1052                                return;
1053                        precvframe->u.hdr.rx_head = pbuf;
1054                        precvframe->u.hdr.rx_data = pbuf;
1055                        precvframe->u.hdr.rx_tail = pbuf;
1056                        precvframe->u.hdr.rx_end = pbuf + alloc_sz;
1057                }
1058                recvframe_put(precvframe, tmp_len);
1059                recvframe_pull(precvframe, drvinfo_sz + RXDESC_SIZE);
1060                /* because the endian issue, driver avoid reference to the
1061                 * rxstat after calling update_recvframe_attrib_from_recvstat();
1062                 */
1063                update_recvframe_attrib_from_recvstat(&precvframe->u.hdr.attrib,
1064                                                      prxstat);
1065                r8712_recv_entry(precvframe);
1066                transfer_len -= pkt_offset;
1067                pbuf += pkt_offset;
1068                pkt_cnt--;
1069                precvframe = NULL;
1070                pkt_copy = NULL;
1071        } while ((transfer_len > 0) && pkt_cnt > 0);
1072}
1073
1074static void recv_tasklet(unsigned long priv)
1075{
1076        struct sk_buff *pskb;
1077        struct _adapter *padapter = (struct _adapter *)priv;
1078        struct recv_priv *precvpriv = &padapter->recvpriv;
1079
1080        while (NULL != (pskb = skb_dequeue(&precvpriv->rx_skb_queue))) {
1081                recvbuf2recvframe(padapter, pskb);
1082                skb_reset_tail_pointer(pskb);
1083                pskb->len = 0;
1084                if (!skb_cloned(pskb))
1085                        skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb);
1086                else
1087                        consume_skb(pskb);
1088        }
1089}
1090