Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / staging / vt6656 / dpc.c
blob6019aac8bdd59705e812500990a89167e172c625
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
16 * File: dpc.c
18 * Purpose: handle dpc rx functions
20 * Author: Lyndon Chen
22 * Date: May 20, 2003
24 * Functions:
26 * Revision History:
30 #include "dpc.h"
31 #include "device.h"
32 #include "mac.h"
33 #include "baseband.h"
34 #include "rf.h"
36 int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb,
37 unsigned long bytes_received)
39 struct ieee80211_hw *hw = priv->hw;
40 struct ieee80211_supported_band *sband;
41 struct sk_buff *skb;
42 struct ieee80211_rx_status rx_status = { 0 };
43 struct ieee80211_hdr *hdr;
44 __le16 fc;
45 u8 *rsr, *new_rsr, *rssi, *frame;
46 __le64 *tsf_time;
47 u32 frame_size;
48 int ii, r;
49 u8 *rx_sts, *rx_rate, *sq, *sq_3;
50 u32 wbk_status;
51 u8 *skb_data;
52 u16 *pay_load_len;
53 u16 pay_load_with_padding;
54 u8 rate_idx = 0;
55 u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
56 long rx_dbm;
58 skb = ptr_rcb->skb;
60 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
61 wbk_status = *((u32 *)(skb->data));
62 frame_size = wbk_status >> 16;
63 frame_size += 4;
65 if (bytes_received != frame_size) {
66 dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n");
67 return false;
70 if ((bytes_received > 2372) || (bytes_received <= 40)) {
71 /* Frame Size error drop this packet.*/
72 dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n");
73 return false;
76 skb_data = (u8 *)skb->data;
78 rx_sts = skb_data+4;
79 rx_rate = skb_data+5;
81 /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */
82 /* -8TSF - 4RSR - 4SQ3 - ?Padding */
84 /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */
86 pay_load_len = (u16 *) (skb_data + 6);
88 /*Fix hardware bug => PLCP_Length error */
89 if (((bytes_received - (*pay_load_len)) > 27) ||
90 ((bytes_received - (*pay_load_len)) < 24) ||
91 (bytes_received < (*pay_load_len))) {
92 dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n",
93 *pay_load_len);
94 return false;
97 sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
99 for (r = RATE_1M; r < MAX_RATE; r++) {
100 if (*rx_rate == rate[r])
101 break;
104 priv->rx_rate = r;
106 for (ii = 0; ii < sband->n_bitrates; ii++) {
107 if (sband->bitrates[ii].hw_value == r) {
108 rate_idx = ii;
109 break;
113 if (ii == sband->n_bitrates) {
114 dev_dbg(&priv->usb->dev, "Wrong RxRate %x\n", *rx_rate);
115 return false;
118 pay_load_with_padding = ((*pay_load_len / 4) +
119 ((*pay_load_len % 4) ? 1 : 0)) * 4;
121 tsf_time = (__le64 *)(skb_data + 8 + pay_load_with_padding);
123 priv->tsf_time = le64_to_cpu(*tsf_time);
125 if (priv->bb_type == BB_TYPE_11G) {
126 sq_3 = skb_data + 8 + pay_load_with_padding + 12;
127 sq = sq_3;
128 } else {
129 sq = skb_data + 8 + pay_load_with_padding + 8;
130 sq_3 = sq;
133 new_rsr = skb_data + 8 + pay_load_with_padding + 9;
134 rssi = skb_data + 8 + pay_load_with_padding + 10;
136 rsr = skb_data + 8 + pay_load_with_padding + 11;
137 if (*rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
138 return false;
140 frame_size = *pay_load_len;
142 vnt_rf_rssi_to_dbm(priv, *rssi, &rx_dbm);
144 priv->bb_pre_ed_rssi = (u8)rx_dbm + 1;
145 priv->current_rssi = priv->bb_pre_ed_rssi;
147 frame = skb_data + 8;
149 skb_pull(skb, 8);
150 skb_trim(skb, frame_size);
152 rx_status.mactime = priv->tsf_time;
153 rx_status.band = hw->conf.chandef.chan->band;
154 rx_status.signal = rx_dbm;
155 rx_status.flag = 0;
156 rx_status.freq = hw->conf.chandef.chan->center_freq;
158 if (!(*rsr & RSR_CRCOK))
159 rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
161 hdr = (struct ieee80211_hdr *)(skb->data);
162 fc = hdr->frame_control;
164 rx_status.rate_idx = rate_idx;
166 if (ieee80211_has_protected(fc)) {
167 if (priv->local_id > REV_ID_VT3253_A1) {
168 rx_status.flag |= RX_FLAG_DECRYPTED;
170 /* Drop packet */
171 if (!(*new_rsr & NEWRSR_DECRYPTOK)) {
172 dev_kfree_skb(skb);
173 return true;
178 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
180 ieee80211_rx_irqsafe(priv->hw, skb);
182 return true;