Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 1 | /* |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 2 | * This file is part of wl1251 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 1998-2007 Texas Instruments Incorporated |
| 5 | * Copyright (C) 2008 Nokia Corporation |
| 6 | * |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <linux/skbuff.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/gfp.h> |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 25 | #include <net/mac80211.h> |
| 26 | |
Kalle Valo | 1367411 | 2009-06-12 14:17:25 +0300 | [diff] [blame] | 27 | #include "wl1251.h" |
Kalle Valo | 9bc6772 | 2010-10-10 11:28:32 +0300 | [diff] [blame] | 28 | #include "reg.h" |
| 29 | #include "io.h" |
| 30 | #include "rx.h" |
| 31 | #include "cmd.h" |
| 32 | #include "acx.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 33 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 34 | static void wl1251_rx_header(struct wl1251 *wl, |
| 35 | struct wl1251_rx_descriptor *desc) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 36 | { |
| 37 | u32 rx_packet_ring_addr; |
| 38 | |
| 39 | rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr; |
| 40 | if (wl->rx_current_buffer) |
| 41 | rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size; |
| 42 | |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 43 | wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 44 | } |
| 45 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 46 | static void wl1251_rx_status(struct wl1251 *wl, |
| 47 | struct wl1251_rx_descriptor *desc, |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 48 | struct ieee80211_rx_status *status, |
| 49 | u8 beacon) |
| 50 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 51 | u64 mactime; |
| 52 | int ret; |
| 53 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 54 | memset(status, 0, sizeof(struct ieee80211_rx_status)); |
| 55 | |
| 56 | status->band = IEEE80211_BAND_2GHZ; |
| 57 | status->mactime = desc->timestamp; |
| 58 | |
| 59 | /* |
| 60 | * The rx status timestamp is a 32 bits value while the TSF is a |
| 61 | * 64 bits one. |
| 62 | * For IBSS merging, TSF is mandatory, so we have to get it |
| 63 | * somehow, so we ask for ACX_TSF_INFO. |
| 64 | * That could be moved to the get_tsf() hook, but unfortunately, |
| 65 | * this one must be atomic, while our SPI routines can sleep. |
| 66 | */ |
| 67 | if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 68 | ret = wl1251_acx_tsf_info(wl, &mactime); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 69 | if (ret == 0) |
| 70 | status->mactime = mactime; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | status->signal = desc->rssi; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 74 | |
John W. Linville | 1943414 | 2010-07-28 15:23:30 -0400 | [diff] [blame] | 75 | /* |
| 76 | * FIXME: guessing that snr needs to be divided by two, otherwise |
| 77 | * the values don't make any sense |
| 78 | */ |
| 79 | wl->noise = desc->rssi - desc->snr / 2; |
| 80 | |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 81 | status->freq = ieee80211_channel_to_frequency(desc->channel, |
| 82 | status->band); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 83 | |
Johannes Berg | 6ebacbb | 2011-02-23 15:06:08 +0100 | [diff] [blame] | 84 | status->flag |= RX_FLAG_MACTIME_MPDU; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 85 | |
| 86 | if (desc->flags & RX_DESC_ENCRYPTION_MASK) { |
| 87 | status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED; |
| 88 | |
| 89 | if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL))) |
| 90 | status->flag |= RX_FLAG_DECRYPTED; |
| 91 | |
| 92 | if (unlikely(desc->flags & RX_DESC_MIC_FAIL)) |
| 93 | status->flag |= RX_FLAG_MMIC_ERROR; |
| 94 | } |
| 95 | |
| 96 | if (unlikely(!(desc->flags & RX_DESC_VALID_FCS))) |
| 97 | status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 98 | |
David Gnedt | 73b30df | 2011-01-30 20:11:10 +0100 | [diff] [blame] | 99 | switch (desc->rate) { |
| 100 | /* skip 1 and 12 Mbps because they have same value 0x0a */ |
| 101 | case RATE_2MBPS: |
| 102 | status->rate_idx = 1; |
| 103 | break; |
| 104 | case RATE_5_5MBPS: |
| 105 | status->rate_idx = 2; |
| 106 | break; |
| 107 | case RATE_11MBPS: |
| 108 | status->rate_idx = 3; |
| 109 | break; |
| 110 | case RATE_6MBPS: |
| 111 | status->rate_idx = 4; |
| 112 | break; |
| 113 | case RATE_9MBPS: |
| 114 | status->rate_idx = 5; |
| 115 | break; |
| 116 | case RATE_18MBPS: |
| 117 | status->rate_idx = 7; |
| 118 | break; |
| 119 | case RATE_24MBPS: |
| 120 | status->rate_idx = 8; |
| 121 | break; |
| 122 | case RATE_36MBPS: |
| 123 | status->rate_idx = 9; |
| 124 | break; |
| 125 | case RATE_48MBPS: |
| 126 | status->rate_idx = 10; |
| 127 | break; |
| 128 | case RATE_54MBPS: |
| 129 | status->rate_idx = 11; |
| 130 | break; |
| 131 | } |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 132 | |
David Gnedt | 73b30df | 2011-01-30 20:11:10 +0100 | [diff] [blame] | 133 | /* for 1 and 12 Mbps we have to check the modulation */ |
| 134 | if (desc->rate == RATE_1MBPS) { |
| 135 | if (!(desc->mod_pre & OFDM_RATE_BIT)) |
| 136 | /* CCK -> RATE_1MBPS */ |
| 137 | status->rate_idx = 0; |
| 138 | else |
| 139 | /* OFDM -> RATE_12MBPS */ |
| 140 | status->rate_idx = 6; |
| 141 | } |
| 142 | |
| 143 | if (desc->mod_pre & SHORT_PREAMBLE_BIT) |
| 144 | status->flag |= RX_FLAG_SHORTPRE; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 145 | } |
| 146 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 147 | static void wl1251_rx_body(struct wl1251 *wl, |
| 148 | struct wl1251_rx_descriptor *desc) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 149 | { |
| 150 | struct sk_buff *skb; |
| 151 | struct ieee80211_rx_status status; |
| 152 | u8 *rx_buffer, beacon = 0; |
| 153 | u16 length, *fc; |
| 154 | u32 curr_id, last_id_inc, rx_packet_ring_addr; |
| 155 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 156 | length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 157 | curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT; |
| 158 | last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1); |
| 159 | |
| 160 | if (last_id_inc != curr_id) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 161 | wl1251_warning("curr ID:%d, last ID inc:%d", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 162 | curr_id, last_id_inc); |
| 163 | wl->rx_last_id = curr_id; |
| 164 | } else { |
| 165 | wl->rx_last_id = last_id_inc; |
| 166 | } |
| 167 | |
| 168 | rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr + |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 169 | sizeof(struct wl1251_rx_descriptor) + 20; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 170 | if (wl->rx_current_buffer) |
| 171 | rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size; |
| 172 | |
Kalle Valo | cdd1e9a | 2009-11-30 10:18:12 +0200 | [diff] [blame] | 173 | skb = __dev_alloc_skb(length, GFP_KERNEL); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 174 | if (!skb) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 175 | wl1251_error("Couldn't allocate RX frame"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 176 | return; |
| 177 | } |
| 178 | |
| 179 | rx_buffer = skb_put(skb, length); |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 180 | wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 181 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 182 | /* The actual length doesn't include the target's alignment */ |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 183 | skb->len = desc->length - PLCP_HEADER_LENGTH; |
| 184 | |
| 185 | fc = (u16 *)skb->data; |
| 186 | |
| 187 | if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) |
| 188 | beacon = 1; |
| 189 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 190 | wl1251_rx_status(wl, desc, &status, beacon); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 191 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 192 | wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len, |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 193 | beacon ? "beacon" : ""); |
| 194 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 195 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
Kalle Valo | 878283f | 2009-10-13 20:33:21 +0300 | [diff] [blame] | 196 | ieee80211_rx_ni(wl->hw, skb); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 197 | } |
| 198 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 199 | static void wl1251_rx_ack(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 200 | { |
| 201 | u32 data, addr; |
| 202 | |
| 203 | if (wl->rx_current_buffer) { |
| 204 | addr = ACX_REG_INTERRUPT_TRIG_H; |
| 205 | data = INTR_TRIG_RX_PROC1; |
| 206 | } else { |
| 207 | addr = ACX_REG_INTERRUPT_TRIG; |
| 208 | data = INTR_TRIG_RX_PROC0; |
| 209 | } |
| 210 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 211 | wl1251_reg_write32(wl, addr, data); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 212 | |
| 213 | /* Toggle buffer ring */ |
| 214 | wl->rx_current_buffer = !wl->rx_current_buffer; |
| 215 | } |
| 216 | |
| 217 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 218 | void wl1251_rx(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 219 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 220 | struct wl1251_rx_descriptor *rx_desc; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 221 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 222 | if (wl->state != WL1251_STATE_ON) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 223 | return; |
| 224 | |
Kalle Valo | 4721213 | 2009-06-12 14:15:08 +0300 | [diff] [blame] | 225 | rx_desc = wl->rx_descriptor; |
| 226 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 227 | /* We first read the frame's header */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 228 | wl1251_rx_header(wl, rx_desc); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 229 | |
| 230 | /* Now we can read the body */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 231 | wl1251_rx_body(wl, rx_desc); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 232 | |
| 233 | /* Finally, we need to ACK the RX */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 234 | wl1251_rx_ack(wl); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 235 | } |