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