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
24 #include <linux/gfp.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,
35 return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
39 static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
42 return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
43 RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
46 /* The values of this table must match the wl1271_rates[] array */
47 static u8 wl1271_rx_rate_to_idx[] = {
48 /* MCS rates are used only with 11n */
49 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS7 */
50 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS6 */
51 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS5 */
52 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS4 */
53 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS3 */
54 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS2 */
55 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS1 */
56 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS0 */
58 11, /* WL1271_RATE_54 */
59 10, /* WL1271_RATE_48 */
60 9, /* WL1271_RATE_36 */
61 8, /* WL1271_RATE_24 */
63 /* TI-specific rate */
64 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_22 */
66 7, /* WL1271_RATE_18 */
67 6, /* WL1271_RATE_12 */
68 3, /* WL1271_RATE_11 */
69 5, /* WL1271_RATE_9 */
70 4, /* WL1271_RATE_6 */
71 2, /* WL1271_RATE_5_5 */
72 1, /* WL1271_RATE_2 */
76 /* The values of this table must match the wl1271_rates[] array */
77 static u8 wl1271_5_ghz_rx_rate_to_idx[] = {
78 /* MCS rates are used only with 11n */
79 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS7 */
80 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS6 */
81 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS5 */
82 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS4 */
83 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS3 */
84 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS2 */
85 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS1 */
86 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS0 */
88 7, /* WL1271_RATE_54 */
89 6, /* WL1271_RATE_48 */
90 5, /* WL1271_RATE_36 */
91 4, /* WL1271_RATE_24 */
93 /* TI-specific rate */
94 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_22 */
96 3, /* WL1271_RATE_18 */
97 2, /* WL1271_RATE_12 */
98 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_11 */
99 1, /* WL1271_RATE_9 */
100 0, /* WL1271_RATE_6 */
101 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_5_5 */
102 WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_2 */
103 WL1271_RX_RATE_UNSUPPORTED /* WL1271_RATE_1 */
106 static void wl1271_rx_status(struct wl1271 *wl,
107 struct wl1271_rx_descriptor *desc,
108 struct ieee80211_rx_status *status,
111 memset(status, 0, sizeof(struct ieee80211_rx_status));
113 if ((desc->flags & WL1271_RX_DESC_BAND_MASK) ==
114 WL1271_RX_DESC_BAND_BG) {
115 status->band = IEEE80211_BAND_2GHZ;
116 status->rate_idx = wl1271_rx_rate_to_idx[desc->rate];
117 } else if ((desc->flags & WL1271_RX_DESC_BAND_MASK) ==
118 WL1271_RX_DESC_BAND_A) {
119 status->band = IEEE80211_BAND_5GHZ;
120 status->rate_idx = wl1271_5_ghz_rx_rate_to_idx[desc->rate];
122 wl1271_warning("unsupported band 0x%x",
123 desc->flags & WL1271_RX_DESC_BAND_MASK);
125 if (unlikely(status->rate_idx == WL1271_RX_RATE_UNSUPPORTED))
126 wl1271_warning("unsupported rate");
129 * FIXME: Add mactime handling. For IBSS (ad-hoc) we need to get the
130 * timestamp from the beacon (acx_tsf_info). In BSS mode (infra) we
131 * only need the mactime for monitor mode. For now the mactime is
132 * not valid, so RX_FLAG_TSFT should not be set
134 status->signal = desc->rssi;
137 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
138 * need to divide by two for now, but TI has been discussing about
139 * changing it. This needs to be rechecked.
141 status->noise = desc->rssi - (desc->snr >> 1);
143 status->freq = ieee80211_channel_to_frequency(desc->channel);
145 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
146 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
148 if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
149 status->flag |= RX_FLAG_DECRYPTED;
150 if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
151 status->flag |= RX_FLAG_MMIC_ERROR;
155 static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
157 struct ieee80211_rx_status rx_status;
158 struct wl1271_rx_descriptor *desc;
165 * In PLT mode we seem to get frames and mac80211 warns about them,
166 * workaround this by not retrieving them at all.
168 if (unlikely(wl->state == WL1271_STATE_PLT))
171 skb = __dev_alloc_skb(length, GFP_KERNEL);
173 wl1271_error("Couldn't allocate RX frame");
177 buf = skb_put(skb, length);
178 wl1271_read(wl, WL1271_SLV_MEM_DATA, buf, length, true);
180 /* the data read starts with the descriptor */
181 desc = (struct wl1271_rx_descriptor *) buf;
183 /* now we pull the descriptor out of the buffer */
184 skb_pull(skb, sizeof(*desc));
186 fc = (u16 *)skb->data;
187 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
190 wl1271_rx_status(wl, desc, &rx_status, beacon);
192 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
193 beacon ? "beacon" : "");
195 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
196 ieee80211_rx_ni(wl->hw, skb);
199 void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
201 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
203 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
204 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
207 while (drv_rx_counter != fw_rx_counter) {
208 mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
209 buf_size = wl1271_rx_get_buf_size(status, drv_rx_counter);
212 wl1271_warning("received empty data");
216 wl->rx_mem_pool_addr.addr = (mem_block << 8) +
217 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
218 wl->rx_mem_pool_addr.addr_extra =
219 wl->rx_mem_pool_addr.addr + 4;
221 /* Choose the block we want to read */
222 wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
223 sizeof(wl->rx_mem_pool_addr), false);
225 wl1271_rx_handle_data(wl, buf_size);
228 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
231 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);