xref: /openbmc/linux/drivers/staging/vt6655/dpc.c (revision c0e297dc)
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: dpc.c
20  *
21  * Purpose: handle dpc rx functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: May 20, 2003
26  *
27  * Functions:
28  *
29  * Revision History:
30  *
31  */
32 
33 #include "device.h"
34 #include "baseband.h"
35 #include "rf.h"
36 #include "dpc.h"
37 
38 static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb,
39 			u16 bytes_received)
40 {
41 	struct ieee80211_hw *hw = priv->hw;
42 	struct ieee80211_supported_band *sband;
43 	struct ieee80211_rx_status rx_status = { 0 };
44 	struct ieee80211_hdr *hdr;
45 	__le16 fc;
46 	u8 *rsr, *new_rsr, *rssi;
47 	__le64 *tsf_time;
48 	u16 frame_size;
49 	int ii, r;
50 	u8 *rx_sts, *rx_rate, *sq;
51 	u8 *skb_data;
52 	u8 rate_idx = 0;
53 	u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
54 	long rx_dbm;
55 
56 	/* [31:16]RcvByteCount ( not include 4-byte Status ) */
57 	frame_size = le16_to_cpu(*((__le16 *)(skb->data + 2)));
58 	if (frame_size > 2346 || frame_size < 14) {
59 		dev_dbg(&priv->pcid->dev, "------- WRONG Length 1\n");
60 		return false;
61 	}
62 
63 	skb_data = (u8 *)skb->data;
64 
65 	rx_sts = skb_data;
66 	rx_rate = skb_data + 1;
67 
68 	sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
69 
70 	for (r = RATE_1M; r < MAX_RATE; r++) {
71 		if (*rx_rate == rate[r])
72 			break;
73 	}
74 
75 	priv->rx_rate = r;
76 
77 	for (ii = 0; ii < sband->n_bitrates; ii++) {
78 		if (sband->bitrates[ii].hw_value == r) {
79 			rate_idx = ii;
80 				break;
81 		}
82 	}
83 
84 	if (ii == sband->n_bitrates) {
85 		dev_dbg(&priv->pcid->dev, "Wrong RxRate %x\n", *rx_rate);
86 		return false;
87 	}
88 
89 	tsf_time = (__le64 *)(skb_data + bytes_received - 12);
90 	sq = skb_data + bytes_received - 4;
91 	new_rsr = skb_data + bytes_received - 3;
92 	rssi = skb_data + bytes_received - 2;
93 	rsr = skb_data + bytes_received - 1;
94 	if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
95 		return false;
96 
97 	RFvRSSITodBm(priv, *rssi, &rx_dbm);
98 
99 	priv->byBBPreEDRSSI = (u8)rx_dbm + 1;
100 	priv->uCurrRSSI = *rssi;
101 
102 	skb_pull(skb, 4);
103 	skb_trim(skb, frame_size);
104 
105 	rx_status.mactime = le64_to_cpu(*tsf_time);
106 	rx_status.band = hw->conf.chandef.chan->band;
107 	rx_status.signal = rx_dbm;
108 	rx_status.flag = 0;
109 	rx_status.freq = hw->conf.chandef.chan->center_freq;
110 
111 	if (!(*rsr & RSR_CRCOK))
112 		rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
113 
114 	hdr = (struct ieee80211_hdr *)(skb->data);
115 	fc = hdr->frame_control;
116 
117 	rx_status.rate_idx = rate_idx;
118 
119 	if (ieee80211_has_protected(fc)) {
120 		if (priv->byLocalID > REV_ID_VT3253_A1)
121 			rx_status.flag |= RX_FLAG_DECRYPTED;
122 
123 		/* Drop packet */
124 		if (!(*new_rsr & NEWRSR_DECRYPTOK))
125 			return false;
126 	}
127 
128 	memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
129 
130 	ieee80211_rx_irqsafe(priv->hw, skb);
131 
132 	return true;
133 }
134 
135 bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd)
136 {
137 	PDEVICE_RD_INFO rd_info = curr_rd->pRDInfo;
138 	struct sk_buff *skb;
139 	u16 frame_size;
140 
141 	skb = rd_info->skb;
142 
143 	dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
144 			 priv->rx_buf_sz, DMA_FROM_DEVICE);
145 
146 	frame_size = le16_to_cpu(curr_rd->m_rd1RD1.wReqCount)
147 			- cpu_to_le16(curr_rd->m_rd0RD0.wResCount);
148 
149 	if ((frame_size > 2364) || (frame_size < 33)) {
150 		/* Frame Size error drop this packet.*/
151 		dev_dbg(&priv->pcid->dev, "Wrong frame size %d\n", frame_size);
152 		dev_kfree_skb_irq(skb);
153 		return true;
154 	}
155 
156 	if (vnt_rx_data(priv, skb, frame_size))
157 		return true;
158 
159 	dev_kfree_skb_irq(skb);
160 
161 	return true;
162 }
163