treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / staging / vt6656 / dpc.c
blob821aae8ca402fa3cac7ed2bca2f93fc3cdd62961
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
6 * File: dpc.c
8 * Purpose: handle dpc rx functions
10 * Author: Lyndon Chen
12 * Date: May 20, 2003
14 * Functions:
16 * Revision History:
20 #include "dpc.h"
21 #include "device.h"
22 #include "mac.h"
23 #include "baseband.h"
24 #include "rf.h"
26 int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb,
27 unsigned long bytes_received)
29 struct ieee80211_hw *hw = priv->hw;
30 struct ieee80211_supported_band *sband;
31 struct sk_buff *skb;
32 struct ieee80211_rx_status *rx_status;
33 struct vnt_rx_header *head;
34 struct vnt_rx_tail *tail;
35 u32 frame_size;
36 int ii;
37 u16 rx_bitrate, pay_load_with_padding;
38 u8 rate_idx = 0;
39 long rx_dbm;
41 skb = ptr_rcb->skb;
42 rx_status = IEEE80211_SKB_RXCB(skb);
44 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
45 head = (struct vnt_rx_header *)skb->data;
46 frame_size = head->wbk_status >> 16;
47 frame_size += 4;
49 if (bytes_received != frame_size) {
50 dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n");
51 return false;
54 if ((bytes_received > 2372) || (bytes_received <= 40)) {
55 /* Frame Size error drop this packet.*/
56 dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n");
57 return false;
60 /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */
61 /* -8TSF - 4RSR - 4SQ3 - ?Padding */
63 /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */
65 /*Fix hardware bug => PLCP_Length error */
66 if (((bytes_received - head->pay_load_len) > 27) ||
67 ((bytes_received - head->pay_load_len) < 24) ||
68 (bytes_received < head->pay_load_len)) {
69 dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n",
70 head->pay_load_len);
71 return false;
74 sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
75 rx_bitrate = head->rx_rate * 5; /* rx_rate * 5 */
77 for (ii = 0; ii < sband->n_bitrates; ii++) {
78 if (sband->bitrates[ii].bitrate == rx_bitrate) {
79 rate_idx = ii;
80 break;
84 if (ii == sband->n_bitrates) {
85 dev_dbg(&priv->usb->dev, "Wrong Rx Bit Rate %d\n", rx_bitrate);
86 return false;
89 pay_load_with_padding = ((head->pay_load_len / 4) +
90 ((head->pay_load_len % 4) ? 1 : 0)) * 4;
92 tail = (struct vnt_rx_tail *)(skb->data +
93 sizeof(*head) + pay_load_with_padding);
94 priv->tsf_time = le64_to_cpu(tail->tsf_time);
96 if (tail->rsr & (RSR_IVLDTYP | RSR_IVLDLEN))
97 return false;
99 vnt_rf_rssi_to_dbm(priv, tail->rssi, &rx_dbm);
101 priv->bb_pre_ed_rssi = (u8)rx_dbm + 1;
102 priv->current_rssi = priv->bb_pre_ed_rssi;
104 skb_pull(skb, sizeof(*head));
105 skb_trim(skb, head->pay_load_len);
107 rx_status->mactime = priv->tsf_time;
108 rx_status->band = hw->conf.chandef.chan->band;
109 rx_status->signal = rx_dbm;
110 rx_status->flag = 0;
111 rx_status->freq = hw->conf.chandef.chan->center_freq;
113 if (!(tail->rsr & RSR_CRCOK))
114 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
116 rx_status->rate_idx = rate_idx;
118 if (tail->new_rsr & NEWRSR_DECRYPTOK)
119 rx_status->flag |= RX_FLAG_DECRYPTED;
121 ieee80211_rx_irqsafe(priv->hw, skb);
123 return true;