wl1271: Support firmware RX packet aggregation
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / wl12xx / wl1271_rx.c
blobbea133b6e4893e2d61cbeff1e4d1f31d1faa42c4
1 /*
2 * This file is part of wl1271
4 * Copyright (C) 2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
24 #include <linux/gfp.h>
26 #include "wl1271.h"
27 #include "wl1271_acx.h"
28 #include "wl1271_reg.h"
29 #include "wl1271_rx.h"
30 #include "wl1271_io.h"
32 static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status,
33 u32 drv_rx_counter)
35 return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
36 RX_MEM_BLOCK_MASK;
39 static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
40 u32 drv_rx_counter)
42 return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
43 RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
46 static void wl1271_rx_status(struct wl1271 *wl,
47 struct wl1271_rx_descriptor *desc,
48 struct ieee80211_rx_status *status,
49 u8 beacon)
51 memset(status, 0, sizeof(struct ieee80211_rx_status));
53 status->band = wl->band;
54 status->rate_idx = wl1271_rate_to_idx(wl, desc->rate);
56 status->signal = desc->rssi;
59 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
60 * need to divide by two for now, but TI has been discussing about
61 * changing it. This needs to be rechecked.
63 wl->noise = desc->rssi - (desc->snr >> 1);
65 status->freq = ieee80211_channel_to_frequency(desc->channel);
67 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
68 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
70 if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
71 status->flag |= RX_FLAG_DECRYPTED;
72 if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
73 status->flag |= RX_FLAG_MMIC_ERROR;
77 static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length)
79 struct wl1271_rx_descriptor *desc;
80 struct sk_buff *skb;
81 u16 *fc;
82 u8 *buf;
83 u8 beacon = 0;
86 * In PLT mode we seem to get frames and mac80211 warns about them,
87 * workaround this by not retrieving them at all.
89 if (unlikely(wl->state == WL1271_STATE_PLT))
90 return -EINVAL;
92 skb = __dev_alloc_skb(length, GFP_KERNEL);
93 if (!skb) {
94 wl1271_error("Couldn't allocate RX frame");
95 return -ENOMEM;
98 buf = skb_put(skb, length);
99 memcpy(buf, data, length);
101 /* the data read starts with the descriptor */
102 desc = (struct wl1271_rx_descriptor *) buf;
104 /* now we pull the descriptor out of the buffer */
105 skb_pull(skb, sizeof(*desc));
107 fc = (u16 *)skb->data;
108 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
109 beacon = 1;
111 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
113 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
114 beacon ? "beacon" : "");
116 skb_trim(skb, skb->len - desc->pad_len);
118 ieee80211_rx_ni(wl->hw, skb);
120 return 0;
123 void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
125 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
126 u32 buf_size;
127 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
128 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
129 u32 rx_counter;
130 u32 mem_block;
131 u32 pkt_length;
132 u32 pkt_offset;
134 while (drv_rx_counter != fw_rx_counter) {
135 buf_size = 0;
136 rx_counter = drv_rx_counter;
137 while (rx_counter != fw_rx_counter) {
138 pkt_length = wl1271_rx_get_buf_size(status, rx_counter);
139 if (buf_size + pkt_length > WL1271_AGGR_BUFFER_SIZE)
140 break;
141 buf_size += pkt_length;
142 rx_counter++;
143 rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
146 if (buf_size == 0) {
147 wl1271_warning("received empty data");
148 break;
152 * Choose the block we want to read
153 * For aggregated packets, only the first memory block should
154 * be retrieved. The FW takes care of the rest.
156 mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
157 wl->rx_mem_pool_addr.addr = (mem_block << 8) +
158 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
159 wl->rx_mem_pool_addr.addr_extra =
160 wl->rx_mem_pool_addr.addr + 4;
161 wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
162 sizeof(wl->rx_mem_pool_addr), false);
164 /* Read all available packets at once */
165 wl1271_read(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
166 buf_size, true);
168 /* Split data into separate packets */
169 pkt_offset = 0;
170 while (pkt_offset < buf_size) {
171 pkt_length = wl1271_rx_get_buf_size(status,
172 drv_rx_counter);
173 if (wl1271_rx_handle_data(wl,
174 wl->aggr_buf + pkt_offset,
175 pkt_length) < 0)
176 break;
177 wl->rx_counter++;
178 drv_rx_counter++;
179 drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
180 pkt_offset += pkt_length;
183 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS,
184 cpu_to_le32(wl->rx_counter));