2 * This file is part of wl1251
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 #include <linux/skbuff.h>
24 #include <linux/gfp.h>
25 #include <net/mac80211.h>
34 static void wl1251_rx_header(struct wl1251
*wl
,
35 struct wl1251_rx_descriptor
*desc
)
37 u32 rx_packet_ring_addr
;
39 rx_packet_ring_addr
= wl
->data_path
->rx_packet_ring_addr
;
40 if (wl
->rx_current_buffer
)
41 rx_packet_ring_addr
+= wl
->data_path
->rx_packet_ring_chunk_size
;
43 wl1251_mem_read(wl
, rx_packet_ring_addr
, desc
, sizeof(*desc
));
46 static void wl1251_rx_status(struct wl1251
*wl
,
47 struct wl1251_rx_descriptor
*desc
,
48 struct ieee80211_rx_status
*status
,
54 memset(status
, 0, sizeof(struct ieee80211_rx_status
));
56 status
->band
= IEEE80211_BAND_2GHZ
;
57 status
->mactime
= desc
->timestamp
;
60 * The rx status timestamp is a 32 bits value while the TSF is a
62 * For IBSS merging, TSF is mandatory, so we have to get it
63 * somehow, so we ask for ACX_TSF_INFO.
64 * That could be moved to the get_tsf() hook, but unfortunately,
65 * this one must be atomic, while our SPI routines can sleep.
67 if ((wl
->bss_type
== BSS_TYPE_IBSS
) && beacon
) {
68 ret
= wl1251_acx_tsf_info(wl
, &mactime
);
70 status
->mactime
= mactime
;
73 status
->signal
= desc
->rssi
;
76 * FIXME: guessing that snr needs to be divided by two, otherwise
77 * the values don't make any sense
79 wl
->noise
= desc
->rssi
- desc
->snr
/ 2;
81 status
->freq
= ieee80211_channel_to_frequency(desc
->channel
,
84 status
->flag
|= RX_FLAG_MACTIME_MPDU
;
86 if (desc
->flags
& RX_DESC_ENCRYPTION_MASK
) {
87 status
->flag
|= RX_FLAG_IV_STRIPPED
| RX_FLAG_MMIC_STRIPPED
;
89 if (likely(!(desc
->flags
& RX_DESC_DECRYPT_FAIL
)))
90 status
->flag
|= RX_FLAG_DECRYPTED
;
92 if (unlikely(desc
->flags
& RX_DESC_MIC_FAIL
))
93 status
->flag
|= RX_FLAG_MMIC_ERROR
;
96 if (unlikely(!(desc
->flags
& RX_DESC_VALID_FCS
)))
97 status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
100 /* skip 1 and 12 Mbps because they have same value 0x0a */
102 status
->rate_idx
= 1;
105 status
->rate_idx
= 2;
108 status
->rate_idx
= 3;
111 status
->rate_idx
= 4;
114 status
->rate_idx
= 5;
117 status
->rate_idx
= 7;
120 status
->rate_idx
= 8;
123 status
->rate_idx
= 9;
126 status
->rate_idx
= 10;
129 status
->rate_idx
= 11;
133 /* for 1 and 12 Mbps we have to check the modulation */
134 if (desc
->rate
== RATE_1MBPS
) {
135 if (!(desc
->mod_pre
& OFDM_RATE_BIT
))
136 /* CCK -> RATE_1MBPS */
137 status
->rate_idx
= 0;
139 /* OFDM -> RATE_12MBPS */
140 status
->rate_idx
= 6;
143 if (desc
->mod_pre
& SHORT_PREAMBLE_BIT
)
144 status
->flag
|= RX_FLAG_SHORTPRE
;
147 static void wl1251_rx_body(struct wl1251
*wl
,
148 struct wl1251_rx_descriptor
*desc
)
151 struct ieee80211_rx_status status
;
152 u8
*rx_buffer
, beacon
= 0;
154 u32 curr_id
, last_id_inc
, rx_packet_ring_addr
;
156 length
= WL1251_RX_ALIGN(desc
->length
- PLCP_HEADER_LENGTH
);
157 curr_id
= (desc
->flags
& RX_DESC_SEQNUM_MASK
) >> RX_DESC_PACKETID_SHIFT
;
158 last_id_inc
= (wl
->rx_last_id
+ 1) % (RX_MAX_PACKET_ID
+ 1);
160 if (last_id_inc
!= curr_id
) {
161 wl1251_warning("curr ID:%d, last ID inc:%d",
162 curr_id
, last_id_inc
);
163 wl
->rx_last_id
= curr_id
;
165 wl
->rx_last_id
= last_id_inc
;
168 rx_packet_ring_addr
= wl
->data_path
->rx_packet_ring_addr
+
169 sizeof(struct wl1251_rx_descriptor
) + 20;
170 if (wl
->rx_current_buffer
)
171 rx_packet_ring_addr
+= wl
->data_path
->rx_packet_ring_chunk_size
;
173 skb
= __dev_alloc_skb(length
, GFP_KERNEL
);
175 wl1251_error("Couldn't allocate RX frame");
179 rx_buffer
= skb_put(skb
, length
);
180 wl1251_mem_read(wl
, rx_packet_ring_addr
, rx_buffer
, length
);
182 /* The actual length doesn't include the target's alignment */
183 skb
->len
= desc
->length
- PLCP_HEADER_LENGTH
;
185 fc
= (u16
*)skb
->data
;
187 if ((*fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
)
190 wl1251_rx_status(wl
, desc
, &status
, beacon
);
192 wl1251_debug(DEBUG_RX
, "rx skb 0x%p: %d B %s", skb
, skb
->len
,
193 beacon
? "beacon" : "");
195 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
196 ieee80211_rx_ni(wl
->hw
, skb
);
199 static void wl1251_rx_ack(struct wl1251
*wl
)
203 if (wl
->rx_current_buffer
) {
204 addr
= ACX_REG_INTERRUPT_TRIG_H
;
205 data
= INTR_TRIG_RX_PROC1
;
207 addr
= ACX_REG_INTERRUPT_TRIG
;
208 data
= INTR_TRIG_RX_PROC0
;
211 wl1251_reg_write32(wl
, addr
, data
);
213 /* Toggle buffer ring */
214 wl
->rx_current_buffer
= !wl
->rx_current_buffer
;
218 void wl1251_rx(struct wl1251
*wl
)
220 struct wl1251_rx_descriptor
*rx_desc
;
222 if (wl
->state
!= WL1251_STATE_ON
)
225 rx_desc
= wl
->rx_descriptor
;
227 /* We first read the frame's header */
228 wl1251_rx_header(wl
, rx_desc
);
230 /* Now we can read the body */
231 wl1251_rx_body(wl
, rx_desc
);
233 /* Finally, we need to ACK the RX */