]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/net/wireless/wl12xx/wl1251_rx.c
iwlwifi: don't include iwl-dev.h from iwl-devtrace.h
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / wireless / wl12xx / wl1251_rx.c
1 /*
2 * This file is part of wl1251
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>
26 #include <net/mac80211.h>
27
28 #include "wl1251.h"
29 #include "wl1251_reg.h"
30 #include "wl1251_io.h"
31 #include "wl1251_rx.h"
32 #include "wl1251_cmd.h"
33 #include "wl1251_acx.h"
34
35 static void wl1251_rx_header(struct wl1251 *wl,
36 struct wl1251_rx_descriptor *desc)
37 {
38 u32 rx_packet_ring_addr;
39
40 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
41 if (wl->rx_current_buffer)
42 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
43
44 wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
45 }
46
47 static void wl1251_rx_status(struct wl1251 *wl,
48 struct wl1251_rx_descriptor *desc,
49 struct ieee80211_rx_status *status,
50 u8 beacon)
51 {
52 u64 mactime;
53 int ret;
54
55 memset(status, 0, sizeof(struct ieee80211_rx_status));
56
57 status->band = IEEE80211_BAND_2GHZ;
58 status->mactime = desc->timestamp;
59
60 /*
61 * The rx status timestamp is a 32 bits value while the TSF is a
62 * 64 bits one.
63 * For IBSS merging, TSF is mandatory, so we have to get it
64 * somehow, so we ask for ACX_TSF_INFO.
65 * That could be moved to the get_tsf() hook, but unfortunately,
66 * this one must be atomic, while our SPI routines can sleep.
67 */
68 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
69 ret = wl1251_acx_tsf_info(wl, &mactime);
70 if (ret == 0)
71 status->mactime = mactime;
72 }
73
74 status->signal = desc->rssi;
75
76 /*
77 * FIXME: guessing that snr needs to be divided by two, otherwise
78 * the values don't make any sense
79 */
80 status->noise = desc->rssi - desc->snr / 2;
81
82 status->freq = ieee80211_channel_to_frequency(desc->channel);
83
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
103 static void wl1251_rx_body(struct wl1251 *wl,
104 struct wl1251_rx_descriptor *desc)
105 {
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
112 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
113 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) {
117 wl1251_warning("curr ID:%d, last ID inc:%d",
118 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 +
125 sizeof(struct wl1251_rx_descriptor) + 20;
126 if (wl->rx_current_buffer)
127 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
128
129 skb = __dev_alloc_skb(length, GFP_KERNEL);
130 if (!skb) {
131 wl1251_error("Couldn't allocate RX frame");
132 return;
133 }
134
135 rx_buffer = skb_put(skb, length);
136 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
137
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
146 wl1251_rx_status(wl, desc, &status, beacon);
147
148 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
149 beacon ? "beacon" : "");
150
151 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
152 ieee80211_rx_ni(wl->hw, skb);
153 }
154
155 static void wl1251_rx_ack(struct wl1251 *wl)
156 {
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
167 wl1251_reg_write32(wl, addr, data);
168
169 /* Toggle buffer ring */
170 wl->rx_current_buffer = !wl->rx_current_buffer;
171 }
172
173
174 void wl1251_rx(struct wl1251 *wl)
175 {
176 struct wl1251_rx_descriptor *rx_desc;
177
178 if (wl->state != WL1251_STATE_ON)
179 return;
180
181 rx_desc = wl->rx_descriptor;
182
183 /* We first read the frame's header */
184 wl1251_rx_header(wl, rx_desc);
185
186 /* Now we can read the body */
187 wl1251_rx_body(wl, rx_desc);
188
189 /* Finally, we need to ACK the RX */
190 wl1251_rx_ack(wl);
191
192 return;
193 }