2 * This file is part of wl1251
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <linux/skbuff.h>
26 #include <net/mac80211.h>
30 #include "wl1251_spi.h"
31 #include "wl1251_rx.h"
32 #include "wl1251_acx.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_spi_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
;
74 status
->qual
= (desc
->rssi
- WL1251_RX_MIN_RSSI
) * 100 /
75 (WL1251_RX_MAX_RSSI
- WL1251_RX_MIN_RSSI
);
76 status
->qual
= min(status
->qual
, 100);
77 status
->qual
= max(status
->qual
, 0);
80 * FIXME: guessing that snr needs to be divided by two, otherwise
81 * the values don't make any sense
83 status
->noise
= desc
->rssi
- desc
->snr
/ 2;
85 status
->freq
= ieee80211_channel_to_frequency(desc
->channel
);
87 status
->flag
|= RX_FLAG_TSFT
;
89 if (desc
->flags
& RX_DESC_ENCRYPTION_MASK
) {
90 status
->flag
|= RX_FLAG_IV_STRIPPED
| RX_FLAG_MMIC_STRIPPED
;
92 if (likely(!(desc
->flags
& RX_DESC_DECRYPT_FAIL
)))
93 status
->flag
|= RX_FLAG_DECRYPTED
;
95 if (unlikely(desc
->flags
& RX_DESC_MIC_FAIL
))
96 status
->flag
|= RX_FLAG_MMIC_ERROR
;
99 if (unlikely(!(desc
->flags
& RX_DESC_VALID_FCS
)))
100 status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
103 /* FIXME: set status->rate_idx */
106 static void wl1251_rx_body(struct wl1251
*wl
,
107 struct wl1251_rx_descriptor
*desc
)
110 struct ieee80211_rx_status status
;
111 u8
*rx_buffer
, beacon
= 0;
113 u32 curr_id
, last_id_inc
, rx_packet_ring_addr
;
115 length
= WL1251_RX_ALIGN(desc
->length
- PLCP_HEADER_LENGTH
);
116 curr_id
= (desc
->flags
& RX_DESC_SEQNUM_MASK
) >> RX_DESC_PACKETID_SHIFT
;
117 last_id_inc
= (wl
->rx_last_id
+ 1) % (RX_MAX_PACKET_ID
+ 1);
119 if (last_id_inc
!= curr_id
) {
120 wl1251_warning("curr ID:%d, last ID inc:%d",
121 curr_id
, last_id_inc
);
122 wl
->rx_last_id
= curr_id
;
124 wl
->rx_last_id
= last_id_inc
;
127 rx_packet_ring_addr
= wl
->data_path
->rx_packet_ring_addr
+
128 sizeof(struct wl1251_rx_descriptor
) + 20;
129 if (wl
->rx_current_buffer
)
130 rx_packet_ring_addr
+= wl
->data_path
->rx_packet_ring_chunk_size
;
132 skb
= dev_alloc_skb(length
);
134 wl1251_error("Couldn't allocate RX frame");
138 rx_buffer
= skb_put(skb
, length
);
139 wl1251_spi_mem_read(wl
, rx_packet_ring_addr
, rx_buffer
, length
);
141 /* The actual lenght doesn't include the target's alignment */
142 skb
->len
= desc
->length
- PLCP_HEADER_LENGTH
;
144 fc
= (u16
*)skb
->data
;
146 if ((*fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
)
149 wl1251_rx_status(wl
, desc
, &status
, beacon
);
151 wl1251_debug(DEBUG_RX
, "rx skb 0x%p: %d B %s", skb
, skb
->len
,
152 beacon
? "beacon" : "");
154 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
155 ieee80211_rx(wl
->hw
, skb
);
158 static void wl1251_rx_ack(struct wl1251
*wl
)
162 if (wl
->rx_current_buffer
) {
163 addr
= ACX_REG_INTERRUPT_TRIG_H
;
164 data
= INTR_TRIG_RX_PROC1
;
166 addr
= ACX_REG_INTERRUPT_TRIG
;
167 data
= INTR_TRIG_RX_PROC0
;
170 wl1251_reg_write32(wl
, addr
, data
);
172 /* Toggle buffer ring */
173 wl
->rx_current_buffer
= !wl
->rx_current_buffer
;
177 void wl1251_rx(struct wl1251
*wl
)
179 struct wl1251_rx_descriptor
*rx_desc
;
181 if (wl
->state
!= WL1251_STATE_ON
)
184 rx_desc
= wl
->rx_descriptor
;
186 /* We first read the frame's header */
187 wl1251_rx_header(wl
, rx_desc
);
189 /* Now we can read the body */
190 wl1251_rx_body(wl
, rx_desc
);
192 /* Finally, we need to ACK the RX */