]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/wireless/wl12xx/wl1251_rx.c
Merge branch 'master' of /repos/git/net-next-2.6
[net-next-2.6.git] / drivers / net / wireless / wl12xx / wl1251_rx.c
CommitLineData
2f01a1f5 1/*
80301cdc 2 * This file is part of wl1251
2f01a1f5
KV
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
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.
12 *
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.
17 *
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
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/skbuff.h>
5a0e3ad6 26#include <linux/gfp.h>
2f01a1f5
KV
27#include <net/mac80211.h>
28
13674118 29#include "wl1251.h"
29d904c4 30#include "wl1251_reg.h"
0764de64 31#include "wl1251_io.h"
ef2f8d45 32#include "wl1251_rx.h"
0764de64 33#include "wl1251_cmd.h"
ef2f8d45 34#include "wl1251_acx.h"
2f01a1f5 35
80301cdc
KV
36static void wl1251_rx_header(struct wl1251 *wl,
37 struct wl1251_rx_descriptor *desc)
2f01a1f5
KV
38{
39 u32 rx_packet_ring_addr;
40
41 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
42 if (wl->rx_current_buffer)
43 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
44
0764de64 45 wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
2f01a1f5
KV
46}
47
80301cdc
KV
48static void wl1251_rx_status(struct wl1251 *wl,
49 struct wl1251_rx_descriptor *desc,
2f01a1f5
KV
50 struct ieee80211_rx_status *status,
51 u8 beacon)
52{
ff25839b
KV
53 u64 mactime;
54 int ret;
55
2f01a1f5
KV
56 memset(status, 0, sizeof(struct ieee80211_rx_status));
57
58 status->band = IEEE80211_BAND_2GHZ;
59 status->mactime = desc->timestamp;
60
61 /*
62 * The rx status timestamp is a 32 bits value while the TSF is a
63 * 64 bits one.
64 * For IBSS merging, TSF is mandatory, so we have to get it
65 * somehow, so we ask for ACX_TSF_INFO.
66 * That could be moved to the get_tsf() hook, but unfortunately,
67 * this one must be atomic, while our SPI routines can sleep.
68 */
69 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
80301cdc 70 ret = wl1251_acx_tsf_info(wl, &mactime);
ff25839b
KV
71 if (ret == 0)
72 status->mactime = mactime;
2f01a1f5
KV
73 }
74
75 status->signal = desc->rssi;
2f01a1f5 76
2f01a1f5
KV
77 status->freq = ieee80211_channel_to_frequency(desc->channel);
78
79 status->flag |= RX_FLAG_TSFT;
80
81 if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
82 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
83
84 if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
85 status->flag |= RX_FLAG_DECRYPTED;
86
87 if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
88 status->flag |= RX_FLAG_MMIC_ERROR;
89 }
90
91 if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
92 status->flag |= RX_FLAG_FAILED_FCS_CRC;
93
94
95 /* FIXME: set status->rate_idx */
96}
97
80301cdc
KV
98static void wl1251_rx_body(struct wl1251 *wl,
99 struct wl1251_rx_descriptor *desc)
2f01a1f5
KV
100{
101 struct sk_buff *skb;
102 struct ieee80211_rx_status status;
103 u8 *rx_buffer, beacon = 0;
104 u16 length, *fc;
105 u32 curr_id, last_id_inc, rx_packet_ring_addr;
106
80301cdc 107 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
2f01a1f5
KV
108 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
109 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
110
111 if (last_id_inc != curr_id) {
80301cdc 112 wl1251_warning("curr ID:%d, last ID inc:%d",
2f01a1f5
KV
113 curr_id, last_id_inc);
114 wl->rx_last_id = curr_id;
115 } else {
116 wl->rx_last_id = last_id_inc;
117 }
118
119 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
80301cdc 120 sizeof(struct wl1251_rx_descriptor) + 20;
2f01a1f5
KV
121 if (wl->rx_current_buffer)
122 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
123
cdd1e9a9 124 skb = __dev_alloc_skb(length, GFP_KERNEL);
2f01a1f5 125 if (!skb) {
80301cdc 126 wl1251_error("Couldn't allocate RX frame");
2f01a1f5
KV
127 return;
128 }
129
130 rx_buffer = skb_put(skb, length);
0764de64 131 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
2f01a1f5
KV
132
133 /* The actual lenght doesn't include the target's alignment */
134 skb->len = desc->length - PLCP_HEADER_LENGTH;
135
136 fc = (u16 *)skb->data;
137
138 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
139 beacon = 1;
140
80301cdc 141 wl1251_rx_status(wl, desc, &status, beacon);
2f01a1f5 142
80301cdc 143 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
2f01a1f5
KV
144 beacon ? "beacon" : "");
145
f1d58c25 146 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
878283f1 147 ieee80211_rx_ni(wl->hw, skb);
2f01a1f5
KV
148}
149
80301cdc 150static void wl1251_rx_ack(struct wl1251 *wl)
2f01a1f5
KV
151{
152 u32 data, addr;
153
154 if (wl->rx_current_buffer) {
155 addr = ACX_REG_INTERRUPT_TRIG_H;
156 data = INTR_TRIG_RX_PROC1;
157 } else {
158 addr = ACX_REG_INTERRUPT_TRIG;
159 data = INTR_TRIG_RX_PROC0;
160 }
161
80301cdc 162 wl1251_reg_write32(wl, addr, data);
2f01a1f5
KV
163
164 /* Toggle buffer ring */
165 wl->rx_current_buffer = !wl->rx_current_buffer;
166}
167
168
80301cdc 169void wl1251_rx(struct wl1251 *wl)
2f01a1f5 170{
80301cdc 171 struct wl1251_rx_descriptor *rx_desc;
2f01a1f5 172
80301cdc 173 if (wl->state != WL1251_STATE_ON)
2f01a1f5
KV
174 return;
175
4721213f
KV
176 rx_desc = wl->rx_descriptor;
177
2f01a1f5 178 /* We first read the frame's header */
80301cdc 179 wl1251_rx_header(wl, rx_desc);
2f01a1f5
KV
180
181 /* Now we can read the body */
80301cdc 182 wl1251_rx_body(wl, rx_desc);
2f01a1f5
KV
183
184 /* Finally, we need to ACK the RX */
80301cdc 185 wl1251_rx_ack(wl);
2f01a1f5
KV
186
187 return;
188}