treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / ti / wl1251 / rx.c
blobb4b0ba8542027581198d4ce02dbac302348d3800
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * This file is part of wl1251
5 * Copyright (c) 1998-2007 Texas Instruments Incorporated
6 * Copyright (C) 2008 Nokia Corporation
7 */
9 #include <linux/skbuff.h>
10 #include <linux/gfp.h>
11 #include <net/mac80211.h>
13 #include "wl1251.h"
14 #include "reg.h"
15 #include "io.h"
16 #include "rx.h"
17 #include "cmd.h"
18 #include "acx.h"
20 static void wl1251_rx_header(struct wl1251 *wl,
21 struct wl1251_rx_descriptor *desc)
23 u32 rx_packet_ring_addr;
25 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
26 if (wl->rx_current_buffer)
27 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
29 wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
32 static void wl1251_rx_status(struct wl1251 *wl,
33 struct wl1251_rx_descriptor *desc,
34 struct ieee80211_rx_status *status,
35 u8 beacon)
37 u64 mactime;
38 int ret;
40 memset(status, 0, sizeof(struct ieee80211_rx_status));
42 status->band = NL80211_BAND_2GHZ;
43 status->mactime = desc->timestamp;
46 * The rx status timestamp is a 32 bits value while the TSF is a
47 * 64 bits one.
48 * For IBSS merging, TSF is mandatory, so we have to get it
49 * somehow, so we ask for ACX_TSF_INFO.
50 * That could be moved to the get_tsf() hook, but unfortunately,
51 * this one must be atomic, while our SPI routines can sleep.
53 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
54 ret = wl1251_acx_tsf_info(wl, &mactime);
55 if (ret == 0)
56 status->mactime = mactime;
59 status->signal = desc->rssi;
62 * FIXME: guessing that snr needs to be divided by two, otherwise
63 * the values don't make any sense
65 wl->noise = desc->rssi - desc->snr / 2;
67 status->freq = ieee80211_channel_to_frequency(desc->channel,
68 status->band);
70 status->flag |= RX_FLAG_MACTIME_START;
72 if (!wl->monitor_present && (desc->flags & RX_DESC_ENCRYPTION_MASK)) {
73 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
75 if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
76 status->flag |= RX_FLAG_DECRYPTED;
78 if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
79 status->flag |= RX_FLAG_MMIC_ERROR;
82 if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
83 status->flag |= RX_FLAG_FAILED_FCS_CRC;
85 switch (desc->rate) {
86 /* skip 1 and 12 Mbps because they have same value 0x0a */
87 case RATE_2MBPS:
88 status->rate_idx = 1;
89 break;
90 case RATE_5_5MBPS:
91 status->rate_idx = 2;
92 break;
93 case RATE_11MBPS:
94 status->rate_idx = 3;
95 break;
96 case RATE_6MBPS:
97 status->rate_idx = 4;
98 break;
99 case RATE_9MBPS:
100 status->rate_idx = 5;
101 break;
102 case RATE_18MBPS:
103 status->rate_idx = 7;
104 break;
105 case RATE_24MBPS:
106 status->rate_idx = 8;
107 break;
108 case RATE_36MBPS:
109 status->rate_idx = 9;
110 break;
111 case RATE_48MBPS:
112 status->rate_idx = 10;
113 break;
114 case RATE_54MBPS:
115 status->rate_idx = 11;
116 break;
119 /* for 1 and 12 Mbps we have to check the modulation */
120 if (desc->rate == RATE_1MBPS) {
121 if (!(desc->mod_pre & OFDM_RATE_BIT))
122 /* CCK -> RATE_1MBPS */
123 status->rate_idx = 0;
124 else
125 /* OFDM -> RATE_12MBPS */
126 status->rate_idx = 6;
129 if (desc->mod_pre & SHORT_PREAMBLE_BIT)
130 status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
133 static void wl1251_rx_body(struct wl1251 *wl,
134 struct wl1251_rx_descriptor *desc)
136 struct sk_buff *skb;
137 struct ieee80211_rx_status status;
138 u8 *rx_buffer, beacon = 0;
139 u16 length, *fc;
140 u32 curr_id, last_id_inc, rx_packet_ring_addr;
142 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
143 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
144 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
146 if (last_id_inc != curr_id) {
147 wl1251_warning("curr ID:%d, last ID inc:%d",
148 curr_id, last_id_inc);
149 wl->rx_last_id = curr_id;
150 } else {
151 wl->rx_last_id = last_id_inc;
154 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
155 sizeof(struct wl1251_rx_descriptor) + 20;
156 if (wl->rx_current_buffer)
157 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
159 skb = __dev_alloc_skb(length, GFP_KERNEL);
160 if (!skb) {
161 wl1251_error("Couldn't allocate RX frame");
162 return;
165 rx_buffer = skb_put(skb, length);
166 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
168 /* The actual length doesn't include the target's alignment */
169 skb_trim(skb, desc->length - PLCP_HEADER_LENGTH);
171 fc = (u16 *)skb->data;
173 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
174 beacon = 1;
176 wl1251_rx_status(wl, desc, &status, beacon);
178 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
179 beacon ? "beacon" : "");
181 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
182 ieee80211_rx_ni(wl->hw, skb);
185 static void wl1251_rx_ack(struct wl1251 *wl)
187 u32 data, addr;
189 if (wl->rx_current_buffer) {
190 addr = ACX_REG_INTERRUPT_TRIG_H;
191 data = INTR_TRIG_RX_PROC1;
192 } else {
193 addr = ACX_REG_INTERRUPT_TRIG;
194 data = INTR_TRIG_RX_PROC0;
197 wl1251_reg_write32(wl, addr, data);
199 /* Toggle buffer ring */
200 wl->rx_current_buffer = !wl->rx_current_buffer;
204 void wl1251_rx(struct wl1251 *wl)
206 struct wl1251_rx_descriptor *rx_desc;
208 if (wl->state != WL1251_STATE_ON)
209 return;
211 rx_desc = wl->rx_descriptor;
213 /* We first read the frame's header */
214 wl1251_rx_header(wl, rx_desc);
216 /* Now we can read the body */
217 wl1251_rx_body(wl, rx_desc);
219 /* Finally, we need to ACK the RX */
220 wl1251_rx_ack(wl);