blob: a1a7953e475ac915c912a06e2ed993e60846ef8e [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
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
24#include "wl1271.h"
25#include "wl1271_acx.h"
26#include "wl1271_reg.h"
27#include "wl1271_rx.h"
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020028#include "wl1271_io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030029
30static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status,
31 u32 drv_rx_counter)
32{
Luciano Coelhod0f63b22009-10-15 10:33:29 +030033 return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
34 RX_MEM_BLOCK_MASK;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030035}
36
37static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
38 u32 drv_rx_counter)
39{
Luciano Coelhod0f63b22009-10-15 10:33:29 +030040 return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
41 RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030042}
43
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030044static void wl1271_rx_status(struct wl1271 *wl,
45 struct wl1271_rx_descriptor *desc,
46 struct ieee80211_rx_status *status,
47 u8 beacon)
48{
49 memset(status, 0, sizeof(struct ieee80211_rx_status));
50
Juuso Oikarinenf876bb92010-03-26 12:53:11 +020051 status->band = wl->band;
52 status->rate_idx = wl1271_rate_to_idx(wl, desc->rate);
Teemu Paasikivia4102642009-10-13 12:47:51 +030053
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030054 /*
55 * FIXME: Add mactime handling. For IBSS (ad-hoc) we need to get the
56 * timestamp from the beacon (acx_tsf_info). In BSS mode (infra) we
57 * only need the mactime for monitor mode. For now the mactime is
58 * not valid, so RX_FLAG_TSFT should not be set
59 */
60 status->signal = desc->rssi;
61
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030062 /*
63 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
64 * need to divide by two for now, but TI has been discussing about
65 * changing it. This needs to be rechecked.
66 */
67 status->noise = desc->rssi - (desc->snr >> 1);
68
69 status->freq = ieee80211_channel_to_frequency(desc->channel);
70
71 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
72 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
73
Teemu Paasikivi5d07b662009-10-13 12:47:52 +030074 if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030075 status->flag |= RX_FLAG_DECRYPTED;
Teemu Paasikivi5d07b662009-10-13 12:47:52 +030076 if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
77 status->flag |= RX_FLAG_MMIC_ERROR;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030078 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030079}
80
81static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
82{
83 struct ieee80211_rx_status rx_status;
84 struct wl1271_rx_descriptor *desc;
85 struct sk_buff *skb;
86 u16 *fc;
87 u8 *buf;
88 u8 beacon = 0;
89
Kalle Valo93c5bb62010-02-22 08:38:30 +020090 /*
91 * In PLT mode we seem to get frames and mac80211 warns about them,
92 * workaround this by not retrieving them at all.
93 */
94 if (unlikely(wl->state == WL1271_STATE_PLT))
95 return;
96
Luis R. Rodrigueze9a62692009-11-02 12:15:15 -050097 skb = __dev_alloc_skb(length, GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030098 if (!skb) {
99 wl1271_error("Couldn't allocate RX frame");
100 return;
101 }
102
103 buf = skb_put(skb, length);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200104 wl1271_read(wl, WL1271_SLV_MEM_DATA, buf, length, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300105
106 /* the data read starts with the descriptor */
107 desc = (struct wl1271_rx_descriptor *) buf;
108
109 /* now we pull the descriptor out of the buffer */
110 skb_pull(skb, sizeof(*desc));
111
112 fc = (u16 *)skb->data;
113 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
114 beacon = 1;
115
116 wl1271_rx_status(wl, desc, &rx_status, beacon);
117
118 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
119 beacon ? "beacon" : "");
120
121 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
Luciano Coelho287d3742009-10-21 14:03:46 +0300122 ieee80211_rx_ni(wl->hw, skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300123}
124
125void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
126{
127 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
128 u32 buf_size;
129 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
130 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
131 u32 mem_block;
132
133 while (drv_rx_counter != fw_rx_counter) {
134 mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
135 buf_size = wl1271_rx_get_buf_size(status, drv_rx_counter);
136
137 if (buf_size == 0) {
138 wl1271_warning("received empty data");
139 break;
140 }
141
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300142 wl->rx_mem_pool_addr.addr = (mem_block << 8) +
143 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300144 wl->rx_mem_pool_addr.addr_extra =
145 wl->rx_mem_pool_addr.addr + 4;
146
147 /* Choose the block we want to read */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200148 wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
149 sizeof(wl->rx_mem_pool_addr), false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300150
151 wl1271_rx_handle_data(wl, buf_size);
152
153 wl->rx_counter++;
154 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
155 }
Juuso Oikarinen295cc0b2010-02-22 08:38:35 +0200156
157 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300158}