linux/drivers/staging/vt6655/dpc.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
   4 * All rights reserved.
   5 *
   6 * File: dpc.c
   7 *
   8 * Purpose: handle dpc rx functions
   9 *
  10 * Author: Lyndon Chen
  11 *
  12 * Date: May 20, 2003
  13 *
  14 * Functions:
  15 *
  16 * Revision History:
  17 *
  18 */
  19
  20#include "device.h"
  21#include "baseband.h"
  22#include "rf.h"
  23#include "dpc.h"
  24
  25static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb,
  26                        u16 bytes_received)
  27{
  28        struct ieee80211_hw *hw = priv->hw;
  29        struct ieee80211_supported_band *sband;
  30        struct ieee80211_rx_status rx_status = { 0 };
  31        struct ieee80211_hdr *hdr;
  32        __le16 fc;
  33        u8 *rsr, *new_rsr, *rssi;
  34        __le64 *tsf_time;
  35        u16 frame_size;
  36        int ii, r;
  37        u8 *rx_sts, *rx_rate, *sq;
  38        u8 *skb_data;
  39        u8 rate_idx = 0;
  40        u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
  41        long rx_dbm;
  42
  43        /* [31:16]RcvByteCount ( not include 4-byte Status ) */
  44        frame_size = le16_to_cpu(*((__le16 *)(skb->data + 2)));
  45        if (frame_size > 2346 || frame_size < 14) {
  46                dev_dbg(&priv->pcid->dev, "------- WRONG Length 1\n");
  47                return false;
  48        }
  49
  50        skb_data = (u8 *)skb->data;
  51
  52        rx_sts = skb_data;
  53        rx_rate = skb_data + 1;
  54
  55        sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
  56
  57        for (r = RATE_1M; r < MAX_RATE; r++) {
  58                if (*rx_rate == rate[r])
  59                        break;
  60        }
  61
  62        priv->rx_rate = r;
  63
  64        for (ii = 0; ii < sband->n_bitrates; ii++) {
  65                if (sband->bitrates[ii].hw_value == r) {
  66                        rate_idx = ii;
  67                                break;
  68                }
  69        }
  70
  71        if (ii == sband->n_bitrates) {
  72                dev_dbg(&priv->pcid->dev, "Wrong RxRate %x\n", *rx_rate);
  73                return false;
  74        }
  75
  76        tsf_time = (__le64 *)(skb_data + bytes_received - 12);
  77        sq = skb_data + bytes_received - 4;
  78        new_rsr = skb_data + bytes_received - 3;
  79        rssi = skb_data + bytes_received - 2;
  80        rsr = skb_data + bytes_received - 1;
  81        if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
  82                return false;
  83
  84        RFvRSSITodBm(priv, *rssi, &rx_dbm);
  85
  86        priv->byBBPreEDRSSI = (u8)rx_dbm + 1;
  87        priv->uCurrRSSI = *rssi;
  88
  89        skb_pull(skb, 4);
  90        skb_trim(skb, frame_size);
  91
  92        rx_status.mactime = le64_to_cpu(*tsf_time);
  93        rx_status.band = hw->conf.chandef.chan->band;
  94        rx_status.signal = rx_dbm;
  95        rx_status.flag = 0;
  96        rx_status.freq = hw->conf.chandef.chan->center_freq;
  97
  98        if (!(*rsr & RSR_CRCOK))
  99                rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
 100
 101        hdr = (struct ieee80211_hdr *)(skb->data);
 102        fc = hdr->frame_control;
 103
 104        rx_status.rate_idx = rate_idx;
 105
 106        if (ieee80211_has_protected(fc)) {
 107                if (priv->byLocalID > REV_ID_VT3253_A1)
 108                        rx_status.flag |= RX_FLAG_DECRYPTED;
 109
 110                /* Drop packet */
 111                if (!(*new_rsr & NEWRSR_DECRYPTOK))
 112                        return false;
 113        }
 114
 115        memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
 116
 117        ieee80211_rx_irqsafe(priv->hw, skb);
 118
 119        return true;
 120}
 121
 122bool vnt_receive_frame(struct vnt_private *priv, struct vnt_rx_desc *curr_rd)
 123{
 124        struct vnt_rd_info *rd_info = curr_rd->rd_info;
 125        struct sk_buff *skb;
 126        u16 frame_size;
 127
 128        skb = rd_info->skb;
 129
 130        dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
 131                         priv->rx_buf_sz, DMA_FROM_DEVICE);
 132
 133        frame_size = le16_to_cpu(curr_rd->rd1.req_count)
 134                        - le16_to_cpu(curr_rd->rd0.res_count);
 135
 136        if ((frame_size > 2364) || (frame_size < 33)) {
 137                /* Frame Size error drop this packet.*/
 138                dev_dbg(&priv->pcid->dev, "Wrong frame size %d\n", frame_size);
 139                dev_kfree_skb_irq(skb);
 140                return true;
 141        }
 142
 143        if (vnt_rx_data(priv, skb, frame_size))
 144                return true;
 145
 146        dev_kfree_skb_irq(skb);
 147
 148        return true;
 149}
 150