blob: 86eef456d7b2b5299265312cbe4364051a9488b4 [file] [log] [blame]
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001/*
Kalle Valo80301cd2009-06-12 14:17:39 +03002 * This file is part of wl1251
Kalle Valo2f01a1f2009-04-29 23:33:31 +03003 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
Kalle Valo2f01a1f2009-04-29 23:33:31 +03007 * 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.
10 *
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.
15 *
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
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/skbuff.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/gfp.h>
Kalle Valo2f01a1f2009-04-29 23:33:31 +030025#include <net/mac80211.h>
26
Kalle Valo13674112009-06-12 14:17:25 +030027#include "wl1251.h"
Kalle Valo9bc67722010-10-10 11:28:32 +030028#include "reg.h"
29#include "io.h"
30#include "rx.h"
31#include "cmd.h"
32#include "acx.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030033
Kalle Valo80301cd2009-06-12 14:17:39 +030034static void wl1251_rx_header(struct wl1251 *wl,
35 struct wl1251_rx_descriptor *desc)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030036{
37 u32 rx_packet_ring_addr;
38
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;
42
Bob Copeland0764de62009-08-07 13:32:56 +030043 wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
Kalle Valo2f01a1f2009-04-29 23:33:31 +030044}
45
Kalle Valo80301cd2009-06-12 14:17:39 +030046static void wl1251_rx_status(struct wl1251 *wl,
47 struct wl1251_rx_descriptor *desc,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030048 struct ieee80211_rx_status *status,
49 u8 beacon)
50{
Kalle Valoff258392009-06-12 14:14:19 +030051 u64 mactime;
52 int ret;
53
Kalle Valo2f01a1f2009-04-29 23:33:31 +030054 memset(status, 0, sizeof(struct ieee80211_rx_status));
55
56 status->band = IEEE80211_BAND_2GHZ;
57 status->mactime = desc->timestamp;
58
59 /*
60 * The rx status timestamp is a 32 bits value while the TSF is a
61 * 64 bits one.
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.
66 */
67 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
Kalle Valo80301cd2009-06-12 14:17:39 +030068 ret = wl1251_acx_tsf_info(wl, &mactime);
Kalle Valoff258392009-06-12 14:14:19 +030069 if (ret == 0)
70 status->mactime = mactime;
Kalle Valo2f01a1f2009-04-29 23:33:31 +030071 }
72
73 status->signal = desc->rssi;
Kalle Valo2f01a1f2009-04-29 23:33:31 +030074
John W. Linville19434142010-07-28 15:23:30 -040075 /*
76 * FIXME: guessing that snr needs to be divided by two, otherwise
77 * the values don't make any sense
78 */
79 wl->noise = desc->rssi - desc->snr / 2;
80
Bruno Randolf59eb21a2011-01-17 13:37:28 +090081 status->freq = ieee80211_channel_to_frequency(desc->channel,
82 status->band);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030083
84 status->flag |= RX_FLAG_TSFT;
85
86 if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
87 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
88
89 if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
90 status->flag |= RX_FLAG_DECRYPTED;
91
92 if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
93 status->flag |= RX_FLAG_MMIC_ERROR;
94 }
95
96 if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
97 status->flag |= RX_FLAG_FAILED_FCS_CRC;
98
99
100 /* FIXME: set status->rate_idx */
101}
102
Kalle Valo80301cd2009-06-12 14:17:39 +0300103static void wl1251_rx_body(struct wl1251 *wl,
104 struct wl1251_rx_descriptor *desc)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300105{
106 struct sk_buff *skb;
107 struct ieee80211_rx_status status;
108 u8 *rx_buffer, beacon = 0;
109 u16 length, *fc;
110 u32 curr_id, last_id_inc, rx_packet_ring_addr;
111
Kalle Valo80301cd2009-06-12 14:17:39 +0300112 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300113 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
114 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
115
116 if (last_id_inc != curr_id) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300117 wl1251_warning("curr ID:%d, last ID inc:%d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300118 curr_id, last_id_inc);
119 wl->rx_last_id = curr_id;
120 } else {
121 wl->rx_last_id = last_id_inc;
122 }
123
124 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
Kalle Valo80301cd2009-06-12 14:17:39 +0300125 sizeof(struct wl1251_rx_descriptor) + 20;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300126 if (wl->rx_current_buffer)
127 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
128
Kalle Valocdd1e9a2009-11-30 10:18:12 +0200129 skb = __dev_alloc_skb(length, GFP_KERNEL);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300130 if (!skb) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300131 wl1251_error("Couldn't allocate RX frame");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300132 return;
133 }
134
135 rx_buffer = skb_put(skb, length);
Bob Copeland0764de62009-08-07 13:32:56 +0300136 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300137
138 /* The actual lenght doesn't include the target's alignment */
139 skb->len = desc->length - PLCP_HEADER_LENGTH;
140
141 fc = (u16 *)skb->data;
142
143 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
144 beacon = 1;
145
Kalle Valo80301cd2009-06-12 14:17:39 +0300146 wl1251_rx_status(wl, desc, &status, beacon);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300147
Kalle Valo80301cd2009-06-12 14:17:39 +0300148 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300149 beacon ? "beacon" : "");
150
Johannes Bergf1d58c22009-06-17 13:13:00 +0200151 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
Kalle Valo878283f2009-10-13 20:33:21 +0300152 ieee80211_rx_ni(wl->hw, skb);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300153}
154
Kalle Valo80301cd2009-06-12 14:17:39 +0300155static void wl1251_rx_ack(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300156{
157 u32 data, addr;
158
159 if (wl->rx_current_buffer) {
160 addr = ACX_REG_INTERRUPT_TRIG_H;
161 data = INTR_TRIG_RX_PROC1;
162 } else {
163 addr = ACX_REG_INTERRUPT_TRIG;
164 data = INTR_TRIG_RX_PROC0;
165 }
166
Kalle Valo80301cd2009-06-12 14:17:39 +0300167 wl1251_reg_write32(wl, addr, data);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300168
169 /* Toggle buffer ring */
170 wl->rx_current_buffer = !wl->rx_current_buffer;
171}
172
173
Kalle Valo80301cd2009-06-12 14:17:39 +0300174void wl1251_rx(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300175{
Kalle Valo80301cd2009-06-12 14:17:39 +0300176 struct wl1251_rx_descriptor *rx_desc;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300177
Kalle Valo80301cd2009-06-12 14:17:39 +0300178 if (wl->state != WL1251_STATE_ON)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300179 return;
180
Kalle Valo47212132009-06-12 14:15:08 +0300181 rx_desc = wl->rx_descriptor;
182
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300183 /* We first read the frame's header */
Kalle Valo80301cd2009-06-12 14:17:39 +0300184 wl1251_rx_header(wl, rx_desc);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300185
186 /* Now we can read the body */
Kalle Valo80301cd2009-06-12 14:17:39 +0300187 wl1251_rx_body(wl, rx_desc);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300188
189 /* Finally, we need to ACK the RX */
Kalle Valo80301cd2009-06-12 14:17:39 +0300190 wl1251_rx_ack(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300191}