wl1271: Fix RX data path frame lengths
[deliverable/linux.git] / drivers / net / wireless / wl12xx / wl1271_rx.c
CommitLineData
f5fc0f86
LC
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
5a0e3ad6
TH
24#include <linux/gfp.h>
25
f5fc0f86
LC
26#include "wl1271.h"
27#include "wl1271_acx.h"
28#include "wl1271_reg.h"
29#include "wl1271_rx.h"
7b048c52 30#include "wl1271_io.h"
f5fc0f86
LC
31
32static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status,
33 u32 drv_rx_counter)
34{
d0f63b20
LC
35 return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
36 RX_MEM_BLOCK_MASK;
f5fc0f86
LC
37}
38
39static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
40 u32 drv_rx_counter)
41{
d0f63b20
LC
42 return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
43 RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
f5fc0f86
LC
44}
45
f5fc0f86
LC
46static void wl1271_rx_status(struct wl1271 *wl,
47 struct wl1271_rx_descriptor *desc,
48 struct ieee80211_rx_status *status,
49 u8 beacon)
50{
51 memset(status, 0, sizeof(struct ieee80211_rx_status));
52
f876bb9a
JO
53 status->band = wl->band;
54 status->rate_idx = wl1271_rate_to_idx(wl, desc->rate);
a4102645 55
f5fc0f86
LC
56 /*
57 * FIXME: Add mactime handling. For IBSS (ad-hoc) we need to get the
58 * timestamp from the beacon (acx_tsf_info). In BSS mode (infra) we
59 * only need the mactime for monitor mode. For now the mactime is
60 * not valid, so RX_FLAG_TSFT should not be set
61 */
62 status->signal = desc->rssi;
63
f5fc0f86
LC
64 status->freq = ieee80211_channel_to_frequency(desc->channel);
65
66 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
67 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
68
5d07b668 69 if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
f5fc0f86 70 status->flag |= RX_FLAG_DECRYPTED;
5d07b668
TP
71 if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
72 status->flag |= RX_FLAG_MMIC_ERROR;
f5fc0f86 73 }
f5fc0f86
LC
74}
75
76static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
77{
78 struct ieee80211_rx_status rx_status;
79 struct wl1271_rx_descriptor *desc;
80 struct sk_buff *skb;
81 u16 *fc;
82 u8 *buf;
83 u8 beacon = 0;
84
93c5bb68
KV
85 /*
86 * In PLT mode we seem to get frames and mac80211 warns about them,
87 * workaround this by not retrieving them at all.
88 */
89 if (unlikely(wl->state == WL1271_STATE_PLT))
90 return;
91
e9a6269d 92 skb = __dev_alloc_skb(length, GFP_KERNEL);
f5fc0f86
LC
93 if (!skb) {
94 wl1271_error("Couldn't allocate RX frame");
95 return;
96 }
97
98 buf = skb_put(skb, length);
7b048c52 99 wl1271_read(wl, WL1271_SLV_MEM_DATA, buf, length, true);
f5fc0f86
LC
100
101 /* the data read starts with the descriptor */
102 desc = (struct wl1271_rx_descriptor *) buf;
103
104 /* now we pull the descriptor out of the buffer */
105 skb_pull(skb, sizeof(*desc));
106
107 fc = (u16 *)skb->data;
108 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
109 beacon = 1;
110
111 wl1271_rx_status(wl, desc, &rx_status, beacon);
112
113 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
114 beacon ? "beacon" : "");
115
b9f2e39d
JO
116 skb_trim(skb, skb->len - desc->pad_len);
117
f5fc0f86 118 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
287d3741 119 ieee80211_rx_ni(wl->hw, skb);
f5fc0f86
LC
120}
121
122void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
123{
124 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
125 u32 buf_size;
126 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
127 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
128 u32 mem_block;
129
130 while (drv_rx_counter != fw_rx_counter) {
131 mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
132 buf_size = wl1271_rx_get_buf_size(status, drv_rx_counter);
133
134 if (buf_size == 0) {
135 wl1271_warning("received empty data");
136 break;
137 }
138
d0f63b20
LC
139 wl->rx_mem_pool_addr.addr = (mem_block << 8) +
140 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
f5fc0f86
LC
141 wl->rx_mem_pool_addr.addr_extra =
142 wl->rx_mem_pool_addr.addr + 4;
143
144 /* Choose the block we want to read */
7b048c52
TP
145 wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
146 sizeof(wl->rx_mem_pool_addr), false);
f5fc0f86
LC
147
148 wl1271_rx_handle_data(wl, buf_size);
149
150 wl->rx_counter++;
151 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
152 }
295cc0bf
JO
153
154 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
f5fc0f86 155}
This page took 0.144996 seconds and 5 git commands to generate.