Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/gfp.h> |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 25 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 27 | #include "wl12xx.h" |
| 28 | #include "acx.h" |
| 29 | #include "reg.h" |
| 30 | #include "rx.h" |
| 31 | #include "io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 32 | |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 33 | static u8 wl1271_rx_get_mem_block(struct wl1271_fw_common_status *status, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 34 | u32 drv_rx_counter) |
| 35 | { |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 36 | return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) & |
| 37 | RX_MEM_BLOCK_MASK; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 38 | } |
| 39 | |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 40 | static u32 wl1271_rx_get_buf_size(struct wl1271_fw_common_status *status, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 41 | u32 drv_rx_counter) |
| 42 | { |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 43 | return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) & |
| 44 | RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 45 | } |
| 46 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 47 | static void wl1271_rx_status(struct wl1271 *wl, |
| 48 | struct wl1271_rx_descriptor *desc, |
| 49 | struct ieee80211_rx_status *status, |
| 50 | u8 beacon) |
| 51 | { |
| 52 | memset(status, 0, sizeof(struct ieee80211_rx_status)); |
| 53 | |
Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 54 | if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG) |
Juuso Oikarinen | 0af0467 | 2011-03-10 10:01:43 +0200 | [diff] [blame] | 55 | status->band = IEEE80211_BAND_2GHZ; |
Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 56 | else |
Juuso Oikarinen | 0af0467 | 2011-03-10 10:01:43 +0200 | [diff] [blame] | 57 | status->band = IEEE80211_BAND_5GHZ; |
Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 58 | |
Juuso Oikarinen | 0af0467 | 2011-03-10 10:01:43 +0200 | [diff] [blame] | 59 | status->rate_idx = wl1271_rate_to_idx(desc->rate, status->band); |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 60 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 61 | #ifdef CONFIG_WL12XX_HT |
Shahar Levi | 1835785 | 2010-10-13 16:09:41 +0200 | [diff] [blame] | 62 | /* 11n support */ |
| 63 | if (desc->rate <= CONF_HW_RXTX_RATE_MCS0) |
| 64 | status->flag |= RX_FLAG_HT; |
| 65 | #endif |
| 66 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 67 | status->signal = desc->rssi; |
| 68 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 69 | /* |
| 70 | * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we |
| 71 | * need to divide by two for now, but TI has been discussing about |
| 72 | * changing it. This needs to be rechecked. |
| 73 | */ |
| 74 | wl->noise = desc->rssi - (desc->snr >> 1); |
| 75 | |
Juuso Oikarinen | 0af0467 | 2011-03-10 10:01:43 +0200 | [diff] [blame] | 76 | status->freq = ieee80211_channel_to_frequency(desc->channel, |
| 77 | status->band); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 78 | |
| 79 | if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) { |
Arik Nemtsov | 34c8e3d | 2011-04-26 23:35:40 +0300 | [diff] [blame] | 80 | u8 desc_err_code = desc->status & WL1271_RX_DESC_STATUS_MASK; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 81 | |
Arik Nemtsov | 34c8e3d | 2011-04-26 23:35:40 +0300 | [diff] [blame] | 82 | status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED | |
| 83 | RX_FLAG_DECRYPTED; |
| 84 | |
| 85 | if (unlikely(desc_err_code == WL1271_RX_DESC_MIC_FAIL)) { |
Teemu Paasikivi | 5d07b66 | 2009-10-13 12:47:52 +0300 | [diff] [blame] | 86 | status->flag |= RX_FLAG_MMIC_ERROR; |
Arik Nemtsov | 34c8e3d | 2011-04-26 23:35:40 +0300 | [diff] [blame] | 87 | wl1271_warning("Michael MIC error"); |
| 88 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 89 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 90 | } |
| 91 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 92 | static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 93 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 94 | struct wl1271_rx_descriptor *desc; |
| 95 | struct sk_buff *skb; |
Eliad Peller | 92fe9b5 | 2011-02-09 12:25:14 +0200 | [diff] [blame] | 96 | struct ieee80211_hdr *hdr; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 97 | u8 *buf; |
| 98 | u8 beacon = 0; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 99 | u8 is_data = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 100 | |
Kalle Valo | 93c5bb6 | 2010-02-22 08:38:30 +0200 | [diff] [blame] | 101 | /* |
| 102 | * In PLT mode we seem to get frames and mac80211 warns about them, |
| 103 | * workaround this by not retrieving them at all. |
| 104 | */ |
| 105 | if (unlikely(wl->state == WL1271_STATE_PLT)) |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 106 | return -EINVAL; |
Kalle Valo | 93c5bb6 | 2010-02-22 08:38:30 +0200 | [diff] [blame] | 107 | |
Arik Nemtsov | 34c8e3d | 2011-04-26 23:35:40 +0300 | [diff] [blame] | 108 | /* the data read starts with the descriptor */ |
| 109 | desc = (struct wl1271_rx_descriptor *) data; |
| 110 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 111 | if (desc->packet_class == WL12XX_RX_CLASS_LOGGER) { |
| 112 | size_t len = length - sizeof(*desc); |
| 113 | wl12xx_copy_fwlog(wl, data + sizeof(*desc), len); |
| 114 | wake_up_interruptible(&wl->fwlog_waitq); |
| 115 | return 0; |
| 116 | } |
| 117 | |
Arik Nemtsov | 34c8e3d | 2011-04-26 23:35:40 +0300 | [diff] [blame] | 118 | switch (desc->status & WL1271_RX_DESC_STATUS_MASK) { |
| 119 | /* discard corrupted packets */ |
| 120 | case WL1271_RX_DESC_DRIVER_RX_Q_FAIL: |
| 121 | case WL1271_RX_DESC_DECRYPT_FAIL: |
| 122 | wl1271_warning("corrupted packet in RX with status: 0x%x", |
| 123 | desc->status & WL1271_RX_DESC_STATUS_MASK); |
| 124 | return -EINVAL; |
| 125 | case WL1271_RX_DESC_SUCCESS: |
| 126 | case WL1271_RX_DESC_MIC_FAIL: |
| 127 | break; |
| 128 | default: |
| 129 | wl1271_error("invalid RX descriptor status: 0x%x", |
| 130 | desc->status & WL1271_RX_DESC_STATUS_MASK); |
| 131 | return -EINVAL; |
| 132 | } |
| 133 | |
Luis R. Rodriguez | e9a6269 | 2009-11-02 12:15:15 -0500 | [diff] [blame] | 134 | skb = __dev_alloc_skb(length, GFP_KERNEL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 135 | if (!skb) { |
| 136 | wl1271_error("Couldn't allocate RX frame"); |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 137 | return -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | buf = skb_put(skb, length); |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 141 | memcpy(buf, data, length); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 142 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 143 | /* now we pull the descriptor out of the buffer */ |
| 144 | skb_pull(skb, sizeof(*desc)); |
| 145 | |
Eliad Peller | 92fe9b5 | 2011-02-09 12:25:14 +0200 | [diff] [blame] | 146 | hdr = (struct ieee80211_hdr *)skb->data; |
| 147 | if (ieee80211_is_beacon(hdr->frame_control)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 148 | beacon = 1; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 149 | if (ieee80211_is_data_present(hdr->frame_control)) |
| 150 | is_data = 1; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 151 | |
Eliad Peller | 58be460 | 2010-09-19 18:55:08 +0200 | [diff] [blame] | 152 | wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 153 | |
Eliad Peller | a20a5b7 | 2011-04-05 18:21:31 +0300 | [diff] [blame] | 154 | wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, |
| 155 | skb->len - desc->pad_len, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 156 | beacon ? "beacon" : ""); |
| 157 | |
Juuso Oikarinen | b9f2e39 | 2010-05-14 10:46:24 +0300 | [diff] [blame] | 158 | skb_trim(skb, skb->len - desc->pad_len); |
| 159 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 160 | skb_queue_tail(&wl->deferred_rx_queue, skb); |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 161 | queue_work(wl->freezable_wq, &wl->netstack_work); |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 162 | |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 163 | return is_data; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 164 | } |
| 165 | |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 166 | void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_common_status *status) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 167 | { |
| 168 | struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map; |
| 169 | u32 buf_size; |
| 170 | u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK; |
| 171 | u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 172 | u32 rx_counter; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 173 | u32 mem_block; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 174 | u32 pkt_length; |
| 175 | u32 pkt_offset; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 176 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); |
| 177 | bool had_data = false; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 178 | |
| 179 | while (drv_rx_counter != fw_rx_counter) { |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 180 | buf_size = 0; |
| 181 | rx_counter = drv_rx_counter; |
| 182 | while (rx_counter != fw_rx_counter) { |
| 183 | pkt_length = wl1271_rx_get_buf_size(status, rx_counter); |
| 184 | if (buf_size + pkt_length > WL1271_AGGR_BUFFER_SIZE) |
| 185 | break; |
| 186 | buf_size += pkt_length; |
| 187 | rx_counter++; |
| 188 | rx_counter &= NUM_RX_PKT_DESC_MOD_MASK; |
| 189 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 190 | |
| 191 | if (buf_size == 0) { |
| 192 | wl1271_warning("received empty data"); |
| 193 | break; |
| 194 | } |
| 195 | |
Shahar Levi | ae77ecc | 2011-03-06 16:32:13 +0200 | [diff] [blame] | 196 | if (wl->chip.id != CHIP_ID_1283_PG20) { |
| 197 | /* |
| 198 | * Choose the block we want to read |
| 199 | * For aggregated packets, only the first memory block |
| 200 | * should be retrieved. The FW takes care of the rest. |
| 201 | */ |
| 202 | mem_block = wl1271_rx_get_mem_block(status, |
| 203 | drv_rx_counter); |
| 204 | |
| 205 | wl->rx_mem_pool_addr.addr = (mem_block << 8) + |
| 206 | le32_to_cpu(wl_mem_map->packet_memory_pool_start); |
| 207 | |
| 208 | wl->rx_mem_pool_addr.addr_extra = |
| 209 | wl->rx_mem_pool_addr.addr + 4; |
| 210 | |
| 211 | wl1271_write(wl, WL1271_SLV_REG_DATA, |
| 212 | &wl->rx_mem_pool_addr, |
| 213 | sizeof(wl->rx_mem_pool_addr), false); |
| 214 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 215 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 216 | /* Read all available packets at once */ |
| 217 | wl1271_read(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, |
| 218 | buf_size, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 219 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 220 | /* Split data into separate packets */ |
| 221 | pkt_offset = 0; |
| 222 | while (pkt_offset < buf_size) { |
| 223 | pkt_length = wl1271_rx_get_buf_size(status, |
| 224 | drv_rx_counter); |
Juuso Oikarinen | fb2382c | 2010-10-25 11:24:29 +0200 | [diff] [blame] | 225 | /* |
| 226 | * the handle data call can only fail in memory-outage |
| 227 | * conditions, in that case the received frame will just |
| 228 | * be dropped. |
| 229 | */ |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 230 | if (wl1271_rx_handle_data(wl, |
| 231 | wl->aggr_buf + pkt_offset, |
| 232 | pkt_length) == 1) |
| 233 | had_data = true; |
| 234 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 235 | wl->rx_counter++; |
| 236 | drv_rx_counter++; |
| 237 | drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK; |
| 238 | pkt_offset += pkt_length; |
| 239 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 240 | } |
Ido Yariv | 606ea9f | 2011-03-01 15:14:39 +0200 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * Write the driver's packet counter to the FW. This is only required |
| 244 | * for older hardware revisions |
| 245 | */ |
| 246 | if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION) |
| 247 | wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 248 | |
| 249 | if (!is_ap && wl->conf.rx_streaming.interval && had_data && |
| 250 | (wl->conf.rx_streaming.always || |
| 251 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) { |
| 252 | u32 timeout = wl->conf.rx_streaming.duration; |
| 253 | |
| 254 | /* restart rx streaming */ |
| 255 | if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) |
| 256 | ieee80211_queue_work(wl->hw, |
| 257 | &wl->rx_streaming_enable_work); |
| 258 | |
| 259 | mod_timer(&wl->rx_streaming_timer, |
| 260 | jiffies + msecs_to_jiffies(timeout)); |
| 261 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 262 | } |
Arik Nemtsov | ae113b5 | 2010-10-16 18:45:07 +0200 | [diff] [blame] | 263 | |
| 264 | void wl1271_set_default_filters(struct wl1271 *wl) |
| 265 | { |
| 266 | if (wl->bss_type == BSS_TYPE_AP_BSS) { |
| 267 | wl->rx_config = WL1271_DEFAULT_AP_RX_CONFIG; |
| 268 | wl->rx_filter = WL1271_DEFAULT_AP_RX_FILTER; |
| 269 | } else { |
| 270 | wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG; |
| 271 | wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER; |
| 272 | } |
| 273 | } |