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 | |
| 24 | #include "wl1271.h" |
| 25 | #include "wl1271_acx.h" |
| 26 | #include "wl1271_reg.h" |
| 27 | #include "wl1271_rx.h" |
| 28 | #include "wl1271_spi.h" |
| 29 | |
| 30 | static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status, |
| 31 | u32 drv_rx_counter) |
| 32 | { |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 33 | return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) & |
| 34 | RX_MEM_BLOCK_MASK; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status, |
| 38 | u32 drv_rx_counter) |
| 39 | { |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 40 | return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) & |
| 41 | RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* The values of this table must match the wl1271_rates[] array */ |
| 45 | static u8 wl1271_rx_rate_to_idx[] = { |
| 46 | /* MCS rates are used only with 11n */ |
| 47 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS7 */ |
| 48 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS6 */ |
| 49 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS5 */ |
| 50 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS4 */ |
| 51 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS3 */ |
| 52 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS2 */ |
| 53 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS1 */ |
| 54 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS0 */ |
| 55 | |
| 56 | 11, /* WL1271_RATE_54 */ |
| 57 | 10, /* WL1271_RATE_48 */ |
| 58 | 9, /* WL1271_RATE_36 */ |
| 59 | 8, /* WL1271_RATE_24 */ |
| 60 | |
| 61 | /* TI-specific rate */ |
| 62 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_22 */ |
| 63 | |
| 64 | 7, /* WL1271_RATE_18 */ |
| 65 | 6, /* WL1271_RATE_12 */ |
| 66 | 3, /* WL1271_RATE_11 */ |
| 67 | 5, /* WL1271_RATE_9 */ |
| 68 | 4, /* WL1271_RATE_6 */ |
| 69 | 2, /* WL1271_RATE_5_5 */ |
| 70 | 1, /* WL1271_RATE_2 */ |
| 71 | 0 /* WL1271_RATE_1 */ |
| 72 | }; |
| 73 | |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 74 | /* The values of this table must match the wl1271_rates[] array */ |
| 75 | static u8 wl1271_5_ghz_rx_rate_to_idx[] = { |
| 76 | /* MCS rates are used only with 11n */ |
| 77 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS7 */ |
| 78 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS6 */ |
| 79 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS5 */ |
| 80 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS4 */ |
| 81 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS3 */ |
| 82 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS2 */ |
| 83 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS1 */ |
| 84 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS0 */ |
| 85 | |
| 86 | 7, /* WL1271_RATE_54 */ |
| 87 | 6, /* WL1271_RATE_48 */ |
| 88 | 5, /* WL1271_RATE_36 */ |
| 89 | 4, /* WL1271_RATE_24 */ |
| 90 | |
| 91 | /* TI-specific rate */ |
| 92 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_22 */ |
| 93 | |
| 94 | 3, /* WL1271_RATE_18 */ |
| 95 | 2, /* WL1271_RATE_12 */ |
| 96 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_11 */ |
| 97 | 1, /* WL1271_RATE_9 */ |
| 98 | 0, /* WL1271_RATE_6 */ |
| 99 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_5_5 */ |
| 100 | WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_2 */ |
| 101 | WL1271_RX_RATE_UNSUPPORTED /* WL1271_RATE_1 */ |
| 102 | }; |
| 103 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 104 | static void wl1271_rx_status(struct wl1271 *wl, |
| 105 | struct wl1271_rx_descriptor *desc, |
| 106 | struct ieee80211_rx_status *status, |
| 107 | u8 beacon) |
| 108 | { |
| 109 | memset(status, 0, sizeof(struct ieee80211_rx_status)); |
| 110 | |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 111 | if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == |
| 112 | WL1271_RX_DESC_BAND_BG) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 113 | status->band = IEEE80211_BAND_2GHZ; |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 114 | status->rate_idx = wl1271_rx_rate_to_idx[desc->rate]; |
| 115 | } else if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == |
| 116 | WL1271_RX_DESC_BAND_A) { |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 117 | status->band = IEEE80211_BAND_5GHZ; |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 118 | status->rate_idx = wl1271_5_ghz_rx_rate_to_idx[desc->rate]; |
| 119 | } else |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 120 | wl1271_warning("unsupported band 0x%x", |
| 121 | desc->flags & WL1271_RX_DESC_BAND_MASK); |
| 122 | |
Teemu Paasikivi | a410264 | 2009-10-13 12:47:51 +0300 | [diff] [blame] | 123 | if (unlikely(status->rate_idx == WL1271_RX_RATE_UNSUPPORTED)) |
| 124 | wl1271_warning("unsupported rate"); |
| 125 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 126 | /* |
| 127 | * FIXME: Add mactime handling. For IBSS (ad-hoc) we need to get the |
| 128 | * timestamp from the beacon (acx_tsf_info). In BSS mode (infra) we |
| 129 | * only need the mactime for monitor mode. For now the mactime is |
| 130 | * not valid, so RX_FLAG_TSFT should not be set |
| 131 | */ |
| 132 | status->signal = desc->rssi; |
| 133 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 134 | /* |
| 135 | * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we |
| 136 | * need to divide by two for now, but TI has been discussing about |
| 137 | * changing it. This needs to be rechecked. |
| 138 | */ |
| 139 | status->noise = desc->rssi - (desc->snr >> 1); |
| 140 | |
| 141 | status->freq = ieee80211_channel_to_frequency(desc->channel); |
| 142 | |
| 143 | if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) { |
| 144 | status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED; |
| 145 | |
Teemu Paasikivi | 5d07b66 | 2009-10-13 12:47:52 +0300 | [diff] [blame] | 146 | if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL))) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 147 | status->flag |= RX_FLAG_DECRYPTED; |
Teemu Paasikivi | 5d07b66 | 2009-10-13 12:47:52 +0300 | [diff] [blame] | 148 | if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL)) |
| 149 | status->flag |= RX_FLAG_MMIC_ERROR; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 150 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length) |
| 154 | { |
| 155 | struct ieee80211_rx_status rx_status; |
| 156 | struct wl1271_rx_descriptor *desc; |
| 157 | struct sk_buff *skb; |
| 158 | u16 *fc; |
| 159 | u8 *buf; |
| 160 | u8 beacon = 0; |
| 161 | |
| 162 | skb = dev_alloc_skb(length); |
| 163 | if (!skb) { |
| 164 | wl1271_error("Couldn't allocate RX frame"); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | buf = skb_put(skb, length); |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 169 | wl1271_spi_read(wl, WL1271_SLV_MEM_DATA, buf, length, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 170 | |
| 171 | /* the data read starts with the descriptor */ |
| 172 | desc = (struct wl1271_rx_descriptor *) buf; |
| 173 | |
| 174 | /* now we pull the descriptor out of the buffer */ |
| 175 | skb_pull(skb, sizeof(*desc)); |
| 176 | |
| 177 | fc = (u16 *)skb->data; |
| 178 | if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) |
| 179 | beacon = 1; |
| 180 | |
| 181 | wl1271_rx_status(wl, desc, &rx_status, beacon); |
| 182 | |
| 183 | wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len, |
| 184 | beacon ? "beacon" : ""); |
| 185 | |
| 186 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); |
Luciano Coelho | 287d374 | 2009-10-21 14:03:46 +0300 | [diff] [blame^] | 187 | ieee80211_rx_ni(wl->hw, skb); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status) |
| 191 | { |
| 192 | struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map; |
| 193 | u32 buf_size; |
| 194 | u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK; |
| 195 | u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; |
| 196 | u32 mem_block; |
| 197 | |
| 198 | while (drv_rx_counter != fw_rx_counter) { |
| 199 | mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter); |
| 200 | buf_size = wl1271_rx_get_buf_size(status, drv_rx_counter); |
| 201 | |
| 202 | if (buf_size == 0) { |
| 203 | wl1271_warning("received empty data"); |
| 204 | break; |
| 205 | } |
| 206 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 207 | wl->rx_mem_pool_addr.addr = (mem_block << 8) + |
| 208 | le32_to_cpu(wl_mem_map->packet_memory_pool_start); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 209 | wl->rx_mem_pool_addr.addr_extra = |
| 210 | wl->rx_mem_pool_addr.addr + 4; |
| 211 | |
| 212 | /* Choose the block we want to read */ |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 213 | wl1271_spi_write(wl, WL1271_SLV_REG_DATA, |
| 214 | &wl->rx_mem_pool_addr, |
| 215 | sizeof(wl->rx_mem_pool_addr), false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 216 | |
| 217 | wl1271_rx_handle_data(wl, buf_size); |
| 218 | |
| 219 | wl->rx_counter++; |
| 220 | drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; |
| 221 | } |
| 222 | |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 223 | wl1271_spi_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 224 | } |