1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wl1251
5 * Copyright (c) 1998-2007 Texas Instruments Incorporated
6 * Copyright (C) 2008 Nokia Corporation
9 #include <linux/skbuff.h>
10 #include <linux/gfp.h>
11 #include <net/mac80211.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
,
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
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
);
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
,
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
;
86 /* skip 1 and 12 Mbps because they have same value 0x0a */
100 status
->rate_idx
= 5;
103 status
->rate_idx
= 7;
106 status
->rate_idx
= 8;
109 status
->rate_idx
= 9;
112 status
->rate_idx
= 10;
115 status
->rate_idx
= 11;
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;
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
)
137 struct ieee80211_rx_status status
;
138 u8
*rx_buffer
, beacon
= 0;
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
;
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
);
161 wl1251_error("Couldn't allocate RX frame");
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
)
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
)
189 if (wl
->rx_current_buffer
) {
190 addr
= ACX_REG_INTERRUPT_TRIG_H
;
191 data
= INTR_TRIG_RX_PROC1
;
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
)
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 */