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 | * |
| 7 | * Contact: Kalle Valo <kalle.valo@nokia.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * version 2 as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/skbuff.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/gfp.h> |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 27 | #include <net/mac80211.h> |
| 28 | |
Kalle Valo | 1367411 | 2009-06-12 14:17:25 +0300 | [diff] [blame] | 29 | #include "wl1251.h" |
Kalle Valo | 29d904c | 2009-08-07 13:35:11 +0300 | [diff] [blame] | 30 | #include "wl1251_reg.h" |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 31 | #include "wl1251_io.h" |
Kalle Valo | ef2f8d4 | 2009-06-12 14:17:19 +0300 | [diff] [blame] | 32 | #include "wl1251_rx.h" |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 33 | #include "wl1251_cmd.h" |
Kalle Valo | ef2f8d4 | 2009-06-12 14:17:19 +0300 | [diff] [blame] | 34 | #include "wl1251_acx.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 35 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 36 | static void wl1251_rx_header(struct wl1251 *wl, |
| 37 | struct wl1251_rx_descriptor *desc) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 38 | { |
| 39 | u32 rx_packet_ring_addr; |
| 40 | |
| 41 | rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr; |
| 42 | if (wl->rx_current_buffer) |
| 43 | rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size; |
| 44 | |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 45 | wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 46 | } |
| 47 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 48 | static void wl1251_rx_status(struct wl1251 *wl, |
| 49 | struct wl1251_rx_descriptor *desc, |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 50 | struct ieee80211_rx_status *status, |
| 51 | u8 beacon) |
| 52 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 53 | u64 mactime; |
| 54 | int ret; |
| 55 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 56 | memset(status, 0, sizeof(struct ieee80211_rx_status)); |
| 57 | |
| 58 | status->band = IEEE80211_BAND_2GHZ; |
| 59 | status->mactime = desc->timestamp; |
| 60 | |
| 61 | /* |
| 62 | * The rx status timestamp is a 32 bits value while the TSF is a |
| 63 | * 64 bits one. |
| 64 | * For IBSS merging, TSF is mandatory, so we have to get it |
| 65 | * somehow, so we ask for ACX_TSF_INFO. |
| 66 | * That could be moved to the get_tsf() hook, but unfortunately, |
| 67 | * this one must be atomic, while our SPI routines can sleep. |
| 68 | */ |
| 69 | if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 70 | ret = wl1251_acx_tsf_info(wl, &mactime); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 71 | if (ret == 0) |
| 72 | status->mactime = mactime; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | status->signal = desc->rssi; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 76 | |
John W. Linville | 1943414 | 2010-07-28 15:23:30 -0400 | [diff] [blame^] | 77 | /* |
| 78 | * FIXME: guessing that snr needs to be divided by two, otherwise |
| 79 | * the values don't make any sense |
| 80 | */ |
| 81 | wl->noise = desc->rssi - desc->snr / 2; |
| 82 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 83 | status->freq = ieee80211_channel_to_frequency(desc->channel); |
| 84 | |
| 85 | status->flag |= RX_FLAG_TSFT; |
| 86 | |
| 87 | if (desc->flags & RX_DESC_ENCRYPTION_MASK) { |
| 88 | status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED; |
| 89 | |
| 90 | if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL))) |
| 91 | status->flag |= RX_FLAG_DECRYPTED; |
| 92 | |
| 93 | if (unlikely(desc->flags & RX_DESC_MIC_FAIL)) |
| 94 | status->flag |= RX_FLAG_MMIC_ERROR; |
| 95 | } |
| 96 | |
| 97 | if (unlikely(!(desc->flags & RX_DESC_VALID_FCS))) |
| 98 | status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 99 | |
| 100 | |
| 101 | /* FIXME: set status->rate_idx */ |
| 102 | } |
| 103 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 104 | static void wl1251_rx_body(struct wl1251 *wl, |
| 105 | struct wl1251_rx_descriptor *desc) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 106 | { |
| 107 | struct sk_buff *skb; |
| 108 | struct ieee80211_rx_status status; |
| 109 | u8 *rx_buffer, beacon = 0; |
| 110 | u16 length, *fc; |
| 111 | u32 curr_id, last_id_inc, rx_packet_ring_addr; |
| 112 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 113 | length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 114 | curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT; |
| 115 | last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1); |
| 116 | |
| 117 | if (last_id_inc != curr_id) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 118 | wl1251_warning("curr ID:%d, last ID inc:%d", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 119 | curr_id, last_id_inc); |
| 120 | wl->rx_last_id = curr_id; |
| 121 | } else { |
| 122 | wl->rx_last_id = last_id_inc; |
| 123 | } |
| 124 | |
| 125 | rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr + |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 126 | sizeof(struct wl1251_rx_descriptor) + 20; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 127 | if (wl->rx_current_buffer) |
| 128 | rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size; |
| 129 | |
Kalle Valo | cdd1e9a | 2009-11-30 10:18:12 +0200 | [diff] [blame] | 130 | skb = __dev_alloc_skb(length, GFP_KERNEL); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 131 | if (!skb) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 132 | wl1251_error("Couldn't allocate RX frame"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | |
| 136 | rx_buffer = skb_put(skb, length); |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 137 | wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 138 | |
| 139 | /* The actual lenght doesn't include the target's alignment */ |
| 140 | skb->len = desc->length - PLCP_HEADER_LENGTH; |
| 141 | |
| 142 | fc = (u16 *)skb->data; |
| 143 | |
| 144 | if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) |
| 145 | beacon = 1; |
| 146 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 147 | wl1251_rx_status(wl, desc, &status, beacon); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 148 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 149 | 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] | 150 | beacon ? "beacon" : ""); |
| 151 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 152 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
Kalle Valo | 878283f | 2009-10-13 20:33:21 +0300 | [diff] [blame] | 153 | ieee80211_rx_ni(wl->hw, skb); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 154 | } |
| 155 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 156 | static void wl1251_rx_ack(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 157 | { |
| 158 | u32 data, addr; |
| 159 | |
| 160 | if (wl->rx_current_buffer) { |
| 161 | addr = ACX_REG_INTERRUPT_TRIG_H; |
| 162 | data = INTR_TRIG_RX_PROC1; |
| 163 | } else { |
| 164 | addr = ACX_REG_INTERRUPT_TRIG; |
| 165 | data = INTR_TRIG_RX_PROC0; |
| 166 | } |
| 167 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 168 | wl1251_reg_write32(wl, addr, data); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 169 | |
| 170 | /* Toggle buffer ring */ |
| 171 | wl->rx_current_buffer = !wl->rx_current_buffer; |
| 172 | } |
| 173 | |
| 174 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 175 | void wl1251_rx(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 176 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 177 | struct wl1251_rx_descriptor *rx_desc; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 178 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 179 | if (wl->state != WL1251_STATE_ON) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 180 | return; |
| 181 | |
Kalle Valo | 4721213 | 2009-06-12 14:15:08 +0300 | [diff] [blame] | 182 | rx_desc = wl->rx_descriptor; |
| 183 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 184 | /* We first read the frame's header */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 185 | wl1251_rx_header(wl, rx_desc); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 186 | |
| 187 | /* Now we can read the body */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 188 | wl1251_rx_body(wl, rx_desc); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 189 | |
| 190 | /* Finally, we need to ACK the RX */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 191 | wl1251_rx_ack(wl); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 192 | } |