| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
| Wey-Yi Guy | 901069c | 2011-04-05 09:42:00 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 4 | * | 
|  | 5 | * Portions of this file are derived from the ipw3945 project, as well | 
|  | 6 | * as portions of the ieee80211 subsystem header files. | 
|  | 7 | * | 
|  | 8 | * This program is free software; you can redistribute it and/or modify it | 
|  | 9 | * under the terms of version 2 of the GNU General Public License as | 
|  | 10 | * published by the Free Software Foundation. | 
|  | 11 | * | 
|  | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT | 
|  | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|  | 14 | * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
|  | 15 | * more details. | 
|  | 16 | * | 
|  | 17 | * You should have received a copy of the GNU General Public License along with | 
|  | 18 | * this program; if not, write to the Free Software Foundation, Inc., | 
|  | 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | 
|  | 20 | * | 
|  | 21 | * The full GNU General Public License is included in this distribution in the | 
|  | 22 | * file called LICENSE. | 
|  | 23 | * | 
|  | 24 | * Contact Information: | 
| Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | *  Intel Linux Wireless <ilw@linux.intel.com> | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
|  | 27 | * | 
|  | 28 | *****************************************************************************/ | 
|  | 29 |  | 
| Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 30 | #include <linux/etherdevice.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> | 
| Stanislaw Gruszka | 118253c | 2011-03-07 09:22:24 +0100 | [diff] [blame] | 32 | #include <linux/sched.h> | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 33 | #include <net/mac80211.h> | 
| Tomas Winkler | a05ffd3 | 2008-07-10 14:28:42 +0300 | [diff] [blame] | 34 | #include <asm/unaligned.h> | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 35 | #include "iwl-eeprom.h" | 
|  | 36 | #include "iwl-dev.h" | 
|  | 37 | #include "iwl-core.h" | 
|  | 38 | #include "iwl-sta.h" | 
|  | 39 | #include "iwl-io.h" | 
|  | 40 | #include "iwl-helpers.h" | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 41 | #include "iwl-agn-calib.h" | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 42 | #include "iwl-agn.h" | 
|  | 43 |  | 
|  | 44 | /****************************************************************************** | 
|  | 45 | * | 
|  | 46 | * RX path functions | 
|  | 47 | * | 
|  | 48 | ******************************************************************************/ | 
|  | 49 |  | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 50 | /* | 
|  | 51 | * Rx theory of operation | 
|  | 52 | * | 
|  | 53 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), | 
|  | 54 | * each of which point to Receive Buffers to be filled by the NIC.  These get | 
|  | 55 | * used not only for Rx frames, but for any command response or notification | 
|  | 56 | * from the NIC.  The driver and NIC manage the Rx buffers by means | 
|  | 57 | * of indexes into the circular buffer. | 
|  | 58 | * | 
|  | 59 | * Rx Queue Indexes | 
|  | 60 | * The host/firmware share two index registers for managing the Rx buffers. | 
|  | 61 | * | 
|  | 62 | * The READ index maps to the first position that the firmware may be writing | 
|  | 63 | * to -- the driver can read up to (but not including) this position and get | 
|  | 64 | * good data. | 
|  | 65 | * The READ index is managed by the firmware once the card is enabled. | 
|  | 66 | * | 
|  | 67 | * The WRITE index maps to the last position the driver has read from -- the | 
|  | 68 | * position preceding WRITE is the last slot the firmware can place a packet. | 
|  | 69 | * | 
|  | 70 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if | 
|  | 71 | * WRITE = READ. | 
|  | 72 | * | 
|  | 73 | * During initialization, the host sets up the READ queue position to the first | 
|  | 74 | * INDEX position, and WRITE to the last (READ - 1 wrapped) | 
|  | 75 | * | 
|  | 76 | * When the firmware places a packet in a buffer, it will advance the READ index | 
|  | 77 | * and fire the RX interrupt.  The driver can then query the READ index and | 
|  | 78 | * process as many packets as possible, moving the WRITE index forward as it | 
|  | 79 | * resets the Rx queue buffers with new memory. | 
|  | 80 | * | 
|  | 81 | * The management in the driver is as follows: | 
|  | 82 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free.  When | 
|  | 83 | *   iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled | 
|  | 84 | *   to replenish the iwl->rxq->rx_free. | 
|  | 85 | * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the | 
|  | 86 | *   iwl->rxq is replenished and the READ INDEX is updated (updating the | 
|  | 87 | *   'processed' and 'read' driver indexes as well) | 
|  | 88 | * + A received packet is processed and handed to the kernel network stack, | 
|  | 89 | *   detached from the iwl->rxq.  The driver 'processed' index is updated. | 
|  | 90 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free | 
|  | 91 | *   list. If there are no allocated buffers in iwl->rxq->rx_free, the READ | 
|  | 92 | *   INDEX is not incremented and iwl->status(RX_STALLED) is set.  If there | 
|  | 93 | *   were enough free buffers and RX_STALLED is set it is cleared. | 
|  | 94 | * | 
|  | 95 | * | 
|  | 96 | * Driver sequence: | 
|  | 97 | * | 
|  | 98 | * iwl_rx_queue_alloc()   Allocates rx_free | 
|  | 99 | * iwl_rx_replenish()     Replenishes rx_free list from rx_used, and calls | 
|  | 100 | *                            iwl_rx_queue_restock | 
|  | 101 | * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx | 
|  | 102 | *                            queue, updates firmware pointers, and updates | 
|  | 103 | *                            the WRITE index.  If insufficient rx_free buffers | 
|  | 104 | *                            are available, schedules iwl_rx_replenish | 
|  | 105 | * | 
|  | 106 | * -- enable interrupts -- | 
|  | 107 | * ISR - iwl_rx()         Detach iwl_rx_mem_buffers from pool up to the | 
|  | 108 | *                            READ INDEX, detaching the SKB from the pool. | 
|  | 109 | *                            Moves the packet buffer from queue to rx_used. | 
|  | 110 | *                            Calls iwl_rx_queue_restock to refill any empty | 
|  | 111 | *                            slots. | 
|  | 112 | * ... | 
|  | 113 | * | 
|  | 114 | */ | 
|  | 115 |  | 
|  | 116 | /** | 
|  | 117 | * iwl_rx_queue_space - Return number of free slots available in queue. | 
|  | 118 | */ | 
|  | 119 | int iwl_rx_queue_space(const struct iwl_rx_queue *q) | 
|  | 120 | { | 
|  | 121 | int s = q->read - q->write; | 
|  | 122 | if (s <= 0) | 
|  | 123 | s += RX_QUEUE_SIZE; | 
|  | 124 | /* keep some buffer to not confuse full and empty queue */ | 
|  | 125 | s -= 2; | 
|  | 126 | if (s < 0) | 
|  | 127 | s = 0; | 
|  | 128 | return s; | 
|  | 129 | } | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 130 |  | 
|  | 131 | /** | 
|  | 132 | * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue | 
|  | 133 | */ | 
| Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 134 | void iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 135 | { | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 136 | unsigned long flags; | 
| Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 137 | u32 rx_wrt_ptr_reg = priv->hw_params.rx_wrt_ptr_reg; | 
|  | 138 | u32 reg; | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 139 |  | 
|  | 140 | spin_lock_irqsave(&q->lock, flags); | 
|  | 141 |  | 
|  | 142 | if (q->need_update == 0) | 
|  | 143 | goto exit_unlock; | 
|  | 144 |  | 
| Wey-Yi Guy | f81c1f4 | 2010-11-10 09:56:50 -0800 | [diff] [blame] | 145 | if (priv->cfg->base_params->shadow_reg_enable) { | 
|  | 146 | /* shadow register enabled */ | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 147 | /* Device expects a multiple of 8 */ | 
| Mohamed Abbas | 4752c93 | 2009-05-22 11:01:51 -0700 | [diff] [blame] | 148 | q->write_actual = (q->write & ~0x7); | 
| Winkler, Tomas | fd11743 | 2010-11-10 09:56:42 -0800 | [diff] [blame] | 149 | iwl_write32(priv, rx_wrt_ptr_reg, q->write_actual); | 
| Wey-Yi Guy | f81c1f4 | 2010-11-10 09:56:50 -0800 | [diff] [blame] | 150 | } else { | 
|  | 151 | /* If power-saving is in use, make sure device is awake */ | 
|  | 152 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { | 
|  | 153 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 154 |  | 
| Wey-Yi Guy | f81c1f4 | 2010-11-10 09:56:50 -0800 | [diff] [blame] | 155 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { | 
|  | 156 | IWL_DEBUG_INFO(priv, | 
|  | 157 | "Rx queue requesting wakeup," | 
|  | 158 | " GP1 = 0x%x\n", reg); | 
|  | 159 | iwl_set_bit(priv, CSR_GP_CNTRL, | 
|  | 160 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); | 
|  | 161 | goto exit_unlock; | 
|  | 162 | } | 
|  | 163 |  | 
|  | 164 | q->write_actual = (q->write & ~0x7); | 
|  | 165 | iwl_write_direct32(priv, rx_wrt_ptr_reg, | 
|  | 166 | q->write_actual); | 
|  | 167 |  | 
|  | 168 | /* Else device is assumed to be awake */ | 
|  | 169 | } else { | 
|  | 170 | /* Device expects a multiple of 8 */ | 
|  | 171 | q->write_actual = (q->write & ~0x7); | 
|  | 172 | iwl_write_direct32(priv, rx_wrt_ptr_reg, | 
|  | 173 | q->write_actual); | 
|  | 174 | } | 
|  | 175 | } | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 176 | q->need_update = 0; | 
|  | 177 |  | 
|  | 178 | exit_unlock: | 
|  | 179 | spin_unlock_irqrestore(&q->lock, flags); | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 180 | } | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 181 |  | 
|  | 182 | int iwl_rx_queue_alloc(struct iwl_priv *priv) | 
|  | 183 | { | 
|  | 184 | struct iwl_rx_queue *rxq = &priv->rxq; | 
| Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 185 | struct device *dev = &priv->pci_dev->dev; | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 186 | int i; | 
|  | 187 |  | 
|  | 188 | spin_lock_init(&rxq->lock); | 
|  | 189 | INIT_LIST_HEAD(&rxq->rx_free); | 
|  | 190 | INIT_LIST_HEAD(&rxq->rx_used); | 
|  | 191 |  | 
|  | 192 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ | 
| Emmanuel Grumbach | d5b25c9 | 2010-06-07 13:21:46 -0700 | [diff] [blame] | 193 | rxq->bd = dma_alloc_coherent(dev, 4 * RX_QUEUE_SIZE, &rxq->bd_dma, | 
| Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 194 | GFP_KERNEL); | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 195 | if (!rxq->bd) | 
| Winkler, Tomas | 8d86422 | 2008-11-07 09:58:39 -0800 | [diff] [blame] | 196 | goto err_bd; | 
|  | 197 |  | 
| Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 198 | rxq->rb_stts = dma_alloc_coherent(dev, sizeof(struct iwl_rb_status), | 
|  | 199 | &rxq->rb_stts_dma, GFP_KERNEL); | 
| Winkler, Tomas | 8d86422 | 2008-11-07 09:58:39 -0800 | [diff] [blame] | 200 | if (!rxq->rb_stts) | 
|  | 201 | goto err_rb; | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 202 |  | 
|  | 203 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | 
|  | 204 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) | 
|  | 205 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); | 
|  | 206 |  | 
|  | 207 | /* Set us so that we have processed and used all buffers, but have | 
|  | 208 | * not restocked the Rx queue with fresh buffers */ | 
|  | 209 | rxq->read = rxq->write = 0; | 
| Mohamed Abbas | 4752c93 | 2009-05-22 11:01:51 -0700 | [diff] [blame] | 210 | rxq->write_actual = 0; | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 211 | rxq->free_count = 0; | 
|  | 212 | rxq->need_update = 0; | 
|  | 213 | return 0; | 
| Winkler, Tomas | 8d86422 | 2008-11-07 09:58:39 -0800 | [diff] [blame] | 214 |  | 
|  | 215 | err_rb: | 
| Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 216 | dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd, | 
| Emmanuel Grumbach | d5b25c9 | 2010-06-07 13:21:46 -0700 | [diff] [blame] | 217 | rxq->bd_dma); | 
| Winkler, Tomas | 8d86422 | 2008-11-07 09:58:39 -0800 | [diff] [blame] | 218 | err_bd: | 
|  | 219 | return -ENOMEM; | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 220 | } | 
| Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 221 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 222 | /****************************************************************************** | 
|  | 223 | * | 
|  | 224 | * Generic RX handler implementations | 
|  | 225 | * | 
|  | 226 | ******************************************************************************/ | 
|  | 227 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 228 | static void iwl_rx_reply_error(struct iwl_priv *priv, | 
|  | 229 | struct iwl_rx_mem_buffer *rxb) | 
|  | 230 | { | 
|  | 231 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 232 |  | 
|  | 233 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " | 
|  | 234 | "seq 0x%04X ser 0x%08X\n", | 
|  | 235 | le32_to_cpu(pkt->u.err_resp.error_type), | 
|  | 236 | get_cmd_string(pkt->u.err_resp.cmd_id), | 
|  | 237 | pkt->u.err_resp.cmd_id, | 
|  | 238 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), | 
|  | 239 | le32_to_cpu(pkt->u.err_resp.error_info)); | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) | 
|  | 243 | { | 
|  | 244 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 245 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); | 
|  | 246 | /* | 
|  | 247 | * MULTI-FIXME | 
|  | 248 | * See iwl_mac_channel_switch. | 
|  | 249 | */ | 
|  | 250 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | 
|  | 251 | struct iwl_rxon_cmd *rxon = (void *)&ctx->active; | 
|  | 252 |  | 
| Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 253 | if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) | 
|  | 254 | return; | 
|  | 255 |  | 
|  | 256 | if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) { | 
|  | 257 | rxon->channel = csa->channel; | 
|  | 258 | ctx->staging.channel = csa->channel; | 
|  | 259 | IWL_DEBUG_11H(priv, "CSA notif: channel %d\n", | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 260 | le16_to_cpu(csa->channel)); | 
| Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 261 | iwl_chswitch_done(priv, true); | 
|  | 262 | } else { | 
|  | 263 | IWL_ERR(priv, "CSA notif (fail) : channel %d\n", | 
|  | 264 | le16_to_cpu(csa->channel)); | 
|  | 265 | iwl_chswitch_done(priv, false); | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 266 | } | 
|  | 267 | } | 
|  | 268 |  | 
|  | 269 |  | 
|  | 270 | static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, | 
| Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 271 | struct iwl_rx_mem_buffer *rxb) | 
|  | 272 | { | 
|  | 273 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 274 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); | 
|  | 275 |  | 
|  | 276 | if (!report->state) { | 
|  | 277 | IWL_DEBUG_11H(priv, | 
|  | 278 | "Spectrum Measure Notification: Start\n"); | 
|  | 279 | return; | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | memcpy(&priv->measure_report, report, sizeof(*report)); | 
|  | 283 | priv->measurement_status |= MEASUREMENT_READY; | 
|  | 284 | } | 
| Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 285 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 286 | static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, | 
|  | 287 | struct iwl_rx_mem_buffer *rxb) | 
|  | 288 | { | 
|  | 289 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 290 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 291 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); | 
|  | 292 | IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", | 
|  | 293 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); | 
|  | 294 | #endif | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv, | 
|  | 298 | struct iwl_rx_mem_buffer *rxb) | 
|  | 299 | { | 
|  | 300 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 301 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | 
|  | 302 | IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " | 
|  | 303 | "notification for %s:\n", len, | 
|  | 304 | get_cmd_string(pkt->hdr.cmd)); | 
|  | 305 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len); | 
|  | 306 | } | 
|  | 307 |  | 
|  | 308 | static void iwl_rx_beacon_notif(struct iwl_priv *priv, | 
|  | 309 | struct iwl_rx_mem_buffer *rxb) | 
|  | 310 | { | 
|  | 311 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 312 | struct iwlagn_beacon_notif *beacon = (void *)pkt->u.raw; | 
|  | 313 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 314 | u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status); | 
|  | 315 | u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); | 
|  | 316 |  | 
|  | 317 | IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d " | 
|  | 318 | "tsf:0x%.8x%.8x rate:%d\n", | 
|  | 319 | status & TX_STATUS_MSK, | 
|  | 320 | beacon->beacon_notify_hdr.failure_frame, | 
|  | 321 | le32_to_cpu(beacon->ibss_mgr_status), | 
|  | 322 | le32_to_cpu(beacon->high_tsf), | 
|  | 323 | le32_to_cpu(beacon->low_tsf), rate); | 
|  | 324 | #endif | 
|  | 325 |  | 
|  | 326 | priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); | 
|  | 327 |  | 
|  | 328 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) | 
|  | 329 | queue_work(priv->workqueue, &priv->beacon_update); | 
|  | 330 | } | 
|  | 331 |  | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 332 | /* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */ | 
|  | 333 | #define ACK_CNT_RATIO (50) | 
|  | 334 | #define BA_TIMEOUT_CNT (5) | 
|  | 335 | #define BA_TIMEOUT_MAX (16) | 
|  | 336 |  | 
|  | 337 | /** | 
|  | 338 | * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries. | 
|  | 339 | * | 
|  | 340 | * When the ACK count ratio is low and aggregated BA timeout retries exceeding | 
|  | 341 | * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal | 
|  | 342 | * operation state. | 
|  | 343 | */ | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 344 | static bool iwl_good_ack_health(struct iwl_priv *priv, | 
|  | 345 | struct statistics_tx *cur) | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 346 | { | 
|  | 347 | int actual_delta, expected_delta, ba_timeout_delta; | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 348 | struct statistics_tx *old; | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 349 |  | 
|  | 350 | if (priv->_agn.agg_tids_count) | 
|  | 351 | return true; | 
|  | 352 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 353 | old = &priv->statistics.tx; | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 354 |  | 
|  | 355 | actual_delta = le32_to_cpu(cur->actual_ack_cnt) - | 
|  | 356 | le32_to_cpu(old->actual_ack_cnt); | 
|  | 357 | expected_delta = le32_to_cpu(cur->expected_ack_cnt) - | 
|  | 358 | le32_to_cpu(old->expected_ack_cnt); | 
|  | 359 |  | 
|  | 360 | /* Values should not be negative, but we do not trust the firmware */ | 
|  | 361 | if (actual_delta <= 0 || expected_delta <= 0) | 
|  | 362 | return true; | 
|  | 363 |  | 
|  | 364 | ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) - | 
|  | 365 | le32_to_cpu(old->agg.ba_timeout); | 
|  | 366 |  | 
|  | 367 | if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO && | 
|  | 368 | ba_timeout_delta > BA_TIMEOUT_CNT) { | 
|  | 369 | IWL_DEBUG_RADIO(priv, "deltas: actual %d expected %d ba_timeout %d\n", | 
|  | 370 | actual_delta, expected_delta, ba_timeout_delta); | 
|  | 371 |  | 
|  | 372 | #ifdef CONFIG_IWLWIFI_DEBUGFS | 
|  | 373 | /* | 
|  | 374 | * This is ifdef'ed on DEBUGFS because otherwise the | 
|  | 375 | * statistics aren't available. If DEBUGFS is set but | 
|  | 376 | * DEBUG is not, these will just compile out. | 
|  | 377 | */ | 
|  | 378 | IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n", | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 379 | priv->delta_stats.tx.rx_detected_cnt); | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 380 | IWL_DEBUG_RADIO(priv, | 
|  | 381 | "ack_or_ba_timeout_collision delta %d\n", | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 382 | priv->delta_stats.tx.ack_or_ba_timeout_collision); | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 383 | #endif | 
|  | 384 |  | 
|  | 385 | if (ba_timeout_delta >= BA_TIMEOUT_MAX) | 
|  | 386 | return false; | 
|  | 387 | } | 
|  | 388 |  | 
|  | 389 | return true; | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 | /** | 
|  | 393 | * iwl_good_plcp_health - checks for plcp error. | 
|  | 394 | * | 
|  | 395 | * When the plcp error is exceeding the thresholds, reset the radio | 
|  | 396 | * to improve the throughput. | 
|  | 397 | */ | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 398 | static bool iwl_good_plcp_health(struct iwl_priv *priv, | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 399 | struct statistics_rx_phy *cur_ofdm, | 
|  | 400 | struct statistics_rx_ht_phy *cur_ofdm_ht, | 
|  | 401 | unsigned int msecs) | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 402 | { | 
| Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 403 | int delta; | 
|  | 404 | int threshold = priv->cfg->base_params->plcp_delta_threshold; | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 405 |  | 
| Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 406 | if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) { | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 407 | IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n"); | 
| Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 408 | return true; | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 409 | } | 
|  | 410 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 411 | delta = le32_to_cpu(cur_ofdm->plcp_err) - | 
|  | 412 | le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) + | 
|  | 413 | le32_to_cpu(cur_ofdm_ht->plcp_err) - | 
|  | 414 | le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err); | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 415 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 416 | /* Can be negative if firmware reset statistics */ | 
| Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 417 | if (delta <= 0) | 
|  | 418 | return true; | 
|  | 419 |  | 
|  | 420 | if ((delta * 100 / msecs) > threshold) { | 
|  | 421 | IWL_DEBUG_RADIO(priv, | 
|  | 422 | "plcp health threshold %u delta %d msecs %u\n", | 
|  | 423 | threshold, delta, msecs); | 
|  | 424 | return false; | 
|  | 425 | } | 
|  | 426 |  | 
|  | 427 | return true; | 
| Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 428 | } | 
|  | 429 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 430 | static void iwl_recover_from_statistics(struct iwl_priv *priv, | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 431 | struct statistics_rx_phy *cur_ofdm, | 
|  | 432 | struct statistics_rx_ht_phy *cur_ofdm_ht, | 
|  | 433 | struct statistics_tx *tx, | 
|  | 434 | unsigned long stamp) | 
| Wey-Yi Guy | fa8f130 | 2010-03-05 14:22:46 -0800 | [diff] [blame] | 435 | { | 
| Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 436 | unsigned int msecs; | 
| Stanislaw Gruszka | b7977ff | 2011-02-28 14:33:15 +0100 | [diff] [blame] | 437 |  | 
| Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 438 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | 
|  | 439 | return; | 
|  | 440 |  | 
| Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 441 | msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies); | 
|  | 442 |  | 
|  | 443 | /* Only gather statistics and update time stamp when not associated */ | 
|  | 444 | if (!iwl_is_any_associated(priv)) | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 445 | return; | 
| Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 446 |  | 
|  | 447 | /* Do not check/recover when do not have enough statistics data */ | 
|  | 448 | if (msecs < 99) | 
| Wey-Yi Guy | fa8f130 | 2010-03-05 14:22:46 -0800 | [diff] [blame] | 449 | return; | 
| Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 450 |  | 
| Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 451 | if (iwlagn_mod_params.ack_check && !iwl_good_ack_health(priv, tx)) { | 
| Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 452 | IWL_ERR(priv, "low ack count detected, restart firmware\n"); | 
|  | 453 | if (!iwl_force_reset(priv, IWL_FW_RESET, false)) | 
|  | 454 | return; | 
| Trieu 'Andrew' Nguyen | 3e4fb5f | 2010-01-22 14:22:46 -0800 | [diff] [blame] | 455 | } | 
| Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 456 |  | 
| Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 457 | if (iwlagn_mod_params.plcp_check && | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 458 | !iwl_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs)) | 
| Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 459 | iwl_force_reset(priv, IWL_RF_RESET, false); | 
| Wey-Yi Guy | beac549 | 2010-03-04 13:38:58 -0800 | [diff] [blame] | 460 | } | 
| Wey-Yi Guy | beac549 | 2010-03-04 13:38:58 -0800 | [diff] [blame] | 461 |  | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 462 | /* Calculate noise level, based on measurements during network silence just | 
|  | 463 | *   before arriving beacon.  This measurement can be done only if we know | 
|  | 464 | *   exactly when to expect beacons, therefore only when we're associated. */ | 
|  | 465 | static void iwl_rx_calc_noise(struct iwl_priv *priv) | 
|  | 466 | { | 
|  | 467 | struct statistics_rx_non_phy *rx_info; | 
|  | 468 | int num_active_rx = 0; | 
|  | 469 | int total_silence = 0; | 
|  | 470 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; | 
|  | 471 | int last_rx_noise; | 
|  | 472 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 473 | rx_info = &priv->statistics.rx_non_phy; | 
|  | 474 |  | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 475 | bcn_silence_a = | 
|  | 476 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; | 
|  | 477 | bcn_silence_b = | 
|  | 478 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; | 
|  | 479 | bcn_silence_c = | 
|  | 480 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; | 
|  | 481 |  | 
|  | 482 | if (bcn_silence_a) { | 
|  | 483 | total_silence += bcn_silence_a; | 
|  | 484 | num_active_rx++; | 
|  | 485 | } | 
|  | 486 | if (bcn_silence_b) { | 
|  | 487 | total_silence += bcn_silence_b; | 
|  | 488 | num_active_rx++; | 
|  | 489 | } | 
|  | 490 | if (bcn_silence_c) { | 
|  | 491 | total_silence += bcn_silence_c; | 
|  | 492 | num_active_rx++; | 
|  | 493 | } | 
|  | 494 |  | 
|  | 495 | /* Average among active antennas */ | 
|  | 496 | if (num_active_rx) | 
|  | 497 | last_rx_noise = (total_silence / num_active_rx) - 107; | 
|  | 498 | else | 
|  | 499 | last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; | 
|  | 500 |  | 
|  | 501 | IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n", | 
|  | 502 | bcn_silence_a, bcn_silence_b, bcn_silence_c, | 
|  | 503 | last_rx_noise); | 
|  | 504 | } | 
|  | 505 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 506 | #ifdef CONFIG_IWLWIFI_DEBUGFS | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 507 | /* | 
|  | 508 | *  based on the assumption of all statistics counter are in DWORD | 
|  | 509 | *  FIXME: This function is for debugging, do not deal with | 
|  | 510 | *  the case of counters roll-over. | 
|  | 511 | */ | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 512 | static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta, | 
|  | 513 | __le32 *max_delta, __le32 *accum, int size) | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 514 | { | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 515 | int i; | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 516 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 517 | for (i = 0; | 
|  | 518 | i < size / sizeof(__le32); | 
|  | 519 | i++, prev++, cur++, delta++, max_delta++, accum++) { | 
|  | 520 | if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) { | 
|  | 521 | *delta = cpu_to_le32( | 
|  | 522 | le32_to_cpu(*cur) - le32_to_cpu(*prev)); | 
|  | 523 | le32_add_cpu(accum, le32_to_cpu(*delta)); | 
|  | 524 | if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta)) | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 525 | *max_delta = *delta; | 
|  | 526 | } | 
|  | 527 | } | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 528 | } | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 529 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 530 | static void | 
|  | 531 | iwl_accumulative_statistics(struct iwl_priv *priv, | 
|  | 532 | struct statistics_general_common *common, | 
|  | 533 | struct statistics_rx_non_phy *rx_non_phy, | 
|  | 534 | struct statistics_rx_phy *rx_ofdm, | 
|  | 535 | struct statistics_rx_ht_phy *rx_ofdm_ht, | 
|  | 536 | struct statistics_rx_phy *rx_cck, | 
|  | 537 | struct statistics_tx *tx, | 
|  | 538 | struct statistics_bt_activity *bt_activity) | 
|  | 539 | { | 
|  | 540 | #define ACCUM(_name)	\ | 
|  | 541 | accum_stats((__le32 *)&priv->statistics._name,		\ | 
|  | 542 | (__le32 *)_name,				\ | 
|  | 543 | (__le32 *)&priv->delta_stats._name,		\ | 
|  | 544 | (__le32 *)&priv->max_delta_stats._name,	\ | 
|  | 545 | (__le32 *)&priv->accum_stats._name,		\ | 
|  | 546 | sizeof(*_name)); | 
|  | 547 |  | 
|  | 548 | ACCUM(common); | 
|  | 549 | ACCUM(rx_non_phy); | 
|  | 550 | ACCUM(rx_ofdm); | 
|  | 551 | ACCUM(rx_ofdm_ht); | 
|  | 552 | ACCUM(rx_cck); | 
|  | 553 | ACCUM(tx); | 
|  | 554 | if (bt_activity) | 
|  | 555 | ACCUM(bt_activity); | 
|  | 556 | #undef ACCUM | 
|  | 557 | } | 
|  | 558 | #else | 
|  | 559 | static inline void | 
|  | 560 | iwl_accumulative_statistics(struct iwl_priv *priv, | 
|  | 561 | struct statistics_general_common *common, | 
|  | 562 | struct statistics_rx_non_phy *rx_non_phy, | 
|  | 563 | struct statistics_rx_phy *rx_ofdm, | 
|  | 564 | struct statistics_rx_ht_phy *rx_ofdm_ht, | 
|  | 565 | struct statistics_rx_phy *rx_cck, | 
|  | 566 | struct statistics_tx *tx, | 
|  | 567 | struct statistics_bt_activity *bt_activity) | 
|  | 568 | { | 
|  | 569 | } | 
|  | 570 | #endif | 
|  | 571 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 572 | static void iwl_rx_statistics(struct iwl_priv *priv, | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 573 | struct iwl_rx_mem_buffer *rxb) | 
|  | 574 | { | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 575 | unsigned long stamp = jiffies; | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 576 | const int reg_recalib_period = 60; | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 577 | int change; | 
|  | 578 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 579 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | 
|  | 580 | __le32 *flag; | 
|  | 581 | struct statistics_general_common *common; | 
|  | 582 | struct statistics_rx_non_phy *rx_non_phy; | 
|  | 583 | struct statistics_rx_phy *rx_ofdm; | 
|  | 584 | struct statistics_rx_ht_phy *rx_ofdm_ht; | 
|  | 585 | struct statistics_rx_phy *rx_cck; | 
|  | 586 | struct statistics_tx *tx; | 
|  | 587 | struct statistics_bt_activity *bt_activity; | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 588 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 589 | len -= sizeof(struct iwl_cmd_header); /* skip header */ | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 590 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 591 | IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n", | 
|  | 592 | len); | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 593 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 594 | if (len == sizeof(struct iwl_bt_notif_statistics)) { | 
|  | 595 | struct iwl_bt_notif_statistics *stats; | 
|  | 596 | stats = &pkt->u.stats_bt; | 
|  | 597 | flag = &stats->flag; | 
|  | 598 | common = &stats->general.common; | 
|  | 599 | rx_non_phy = &stats->rx.general.common; | 
|  | 600 | rx_ofdm = &stats->rx.ofdm; | 
|  | 601 | rx_ofdm_ht = &stats->rx.ofdm_ht; | 
|  | 602 | rx_cck = &stats->rx.cck; | 
|  | 603 | tx = &stats->tx; | 
|  | 604 | bt_activity = &stats->general.activity; | 
|  | 605 |  | 
|  | 606 | #ifdef CONFIG_IWLWIFI_DEBUGFS | 
|  | 607 | /* handle this exception directly */ | 
|  | 608 | priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills; | 
|  | 609 | le32_add_cpu(&priv->statistics.accum_num_bt_kills, | 
|  | 610 | le32_to_cpu(stats->rx.general.num_bt_kills)); | 
|  | 611 | #endif | 
|  | 612 | } else if (len == sizeof(struct iwl_notif_statistics)) { | 
|  | 613 | struct iwl_notif_statistics *stats; | 
|  | 614 | stats = &pkt->u.stats; | 
|  | 615 | flag = &stats->flag; | 
|  | 616 | common = &stats->general.common; | 
|  | 617 | rx_non_phy = &stats->rx.general; | 
|  | 618 | rx_ofdm = &stats->rx.ofdm; | 
|  | 619 | rx_ofdm_ht = &stats->rx.ofdm_ht; | 
|  | 620 | rx_cck = &stats->rx.cck; | 
|  | 621 | tx = &stats->tx; | 
|  | 622 | bt_activity = NULL; | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 623 | } else { | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 624 | WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n", | 
|  | 625 | len, sizeof(struct iwl_bt_notif_statistics), | 
|  | 626 | sizeof(struct iwl_notif_statistics)); | 
|  | 627 | return; | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 628 | } | 
|  | 629 |  | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 630 | change = common->temperature != priv->statistics.common.temperature || | 
|  | 631 | (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) != | 
|  | 632 | (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK); | 
|  | 633 |  | 
|  | 634 | iwl_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm, | 
|  | 635 | rx_ofdm_ht, rx_cck, tx, bt_activity); | 
|  | 636 |  | 
|  | 637 | iwl_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp); | 
|  | 638 |  | 
|  | 639 | priv->statistics.flag = *flag; | 
|  | 640 | memcpy(&priv->statistics.common, common, sizeof(*common)); | 
|  | 641 | memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy)); | 
|  | 642 | memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm)); | 
|  | 643 | memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht)); | 
|  | 644 | memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck)); | 
|  | 645 | memcpy(&priv->statistics.tx, tx, sizeof(*tx)); | 
|  | 646 | #ifdef CONFIG_IWLWIFI_DEBUGFS | 
|  | 647 | if (bt_activity) | 
|  | 648 | memcpy(&priv->statistics.bt_activity, bt_activity, | 
|  | 649 | sizeof(*bt_activity)); | 
|  | 650 | #endif | 
|  | 651 |  | 
|  | 652 | priv->rx_statistics_jiffies = stamp; | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 653 |  | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 654 | set_bit(STATUS_STATISTICS, &priv->status); | 
|  | 655 |  | 
|  | 656 | /* Reschedule the statistics timer to occur in | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 657 | * reg_recalib_period seconds to ensure we get a | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 658 | * thermal update even if the uCode doesn't give | 
|  | 659 | * us one */ | 
|  | 660 | mod_timer(&priv->statistics_periodic, jiffies + | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 661 | msecs_to_jiffies(reg_recalib_period * 1000)); | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 662 |  | 
|  | 663 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && | 
|  | 664 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { | 
|  | 665 | iwl_rx_calc_noise(priv); | 
|  | 666 | queue_work(priv->workqueue, &priv->run_time_calib_work); | 
|  | 667 | } | 
|  | 668 | if (priv->cfg->ops->lib->temp_ops.temperature && change) | 
|  | 669 | priv->cfg->ops->lib->temp_ops.temperature(priv); | 
|  | 670 | } | 
|  | 671 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 672 | static void iwl_rx_reply_statistics(struct iwl_priv *priv, | 
|  | 673 | struct iwl_rx_mem_buffer *rxb) | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 674 | { | 
|  | 675 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 676 |  | 
|  | 677 | if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) { | 
|  | 678 | #ifdef CONFIG_IWLWIFI_DEBUGFS | 
| Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 679 | memset(&priv->accum_stats, 0, | 
|  | 680 | sizeof(priv->accum_stats)); | 
|  | 681 | memset(&priv->delta_stats, 0, | 
|  | 682 | sizeof(priv->delta_stats)); | 
|  | 683 | memset(&priv->max_delta_stats, 0, | 
|  | 684 | sizeof(priv->max_delta_stats)); | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 685 | #endif | 
|  | 686 | IWL_DEBUG_RX(priv, "Statistics have been cleared\n"); | 
|  | 687 | } | 
|  | 688 | iwl_rx_statistics(priv, rxb); | 
|  | 689 | } | 
|  | 690 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 691 | /* Handle notification from uCode that card's power state is changing | 
|  | 692 | * due to software, hardware, or critical temperature RFKILL */ | 
|  | 693 | static void iwl_rx_card_state_notif(struct iwl_priv *priv, | 
|  | 694 | struct iwl_rx_mem_buffer *rxb) | 
|  | 695 | { | 
|  | 696 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 697 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); | 
|  | 698 | unsigned long status = priv->status; | 
|  | 699 |  | 
|  | 700 | IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n", | 
|  | 701 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", | 
|  | 702 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", | 
|  | 703 | (flags & CT_CARD_DISABLED) ? | 
|  | 704 | "Reached" : "Not reached"); | 
|  | 705 |  | 
|  | 706 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | | 
|  | 707 | CT_CARD_DISABLED)) { | 
|  | 708 |  | 
|  | 709 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, | 
|  | 710 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); | 
|  | 711 |  | 
|  | 712 | iwl_write_direct32(priv, HBUS_TARG_MBX_C, | 
|  | 713 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); | 
|  | 714 |  | 
|  | 715 | if (!(flags & RXON_CARD_DISABLED)) { | 
|  | 716 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, | 
|  | 717 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); | 
|  | 718 | iwl_write_direct32(priv, HBUS_TARG_MBX_C, | 
|  | 719 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); | 
|  | 720 | } | 
|  | 721 | if (flags & CT_CARD_DISABLED) | 
|  | 722 | iwl_tt_enter_ct_kill(priv); | 
|  | 723 | } | 
|  | 724 | if (!(flags & CT_CARD_DISABLED)) | 
|  | 725 | iwl_tt_exit_ct_kill(priv); | 
|  | 726 |  | 
|  | 727 | if (flags & HW_CARD_DISABLED) | 
|  | 728 | set_bit(STATUS_RF_KILL_HW, &priv->status); | 
|  | 729 | else | 
|  | 730 | clear_bit(STATUS_RF_KILL_HW, &priv->status); | 
|  | 731 |  | 
|  | 732 |  | 
|  | 733 | if (!(flags & RXON_CARD_DISABLED)) | 
|  | 734 | iwl_scan_cancel(priv); | 
|  | 735 |  | 
|  | 736 | if ((test_bit(STATUS_RF_KILL_HW, &status) != | 
|  | 737 | test_bit(STATUS_RF_KILL_HW, &priv->status))) | 
|  | 738 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, | 
|  | 739 | test_bit(STATUS_RF_KILL_HW, &priv->status)); | 
|  | 740 | else | 
|  | 741 | wake_up_interruptible(&priv->wait_command_queue); | 
|  | 742 | } | 
|  | 743 |  | 
|  | 744 | static void iwl_rx_missed_beacon_notif(struct iwl_priv *priv, | 
|  | 745 | struct iwl_rx_mem_buffer *rxb) | 
| Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 746 |  | 
|  | 747 | { | 
|  | 748 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 749 | struct iwl_missed_beacon_notif *missed_beacon; | 
|  | 750 |  | 
|  | 751 | missed_beacon = &pkt->u.missed_beacon; | 
|  | 752 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > | 
|  | 753 | priv->missed_beacon_threshold) { | 
|  | 754 | IWL_DEBUG_CALIB(priv, | 
|  | 755 | "missed bcn cnsq %d totl %d rcd %d expctd %d\n", | 
|  | 756 | le32_to_cpu(missed_beacon->consecutive_missed_beacons), | 
|  | 757 | le32_to_cpu(missed_beacon->total_missed_becons), | 
|  | 758 | le32_to_cpu(missed_beacon->num_recvd_beacons), | 
|  | 759 | le32_to_cpu(missed_beacon->num_expected_beacons)); | 
|  | 760 | if (!test_bit(STATUS_SCANNING, &priv->status)) | 
|  | 761 | iwl_init_sensitivity(priv); | 
|  | 762 | } | 
|  | 763 | } | 
|  | 764 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 765 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). | 
|  | 766 | * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ | 
|  | 767 | static void iwl_rx_reply_rx_phy(struct iwl_priv *priv, | 
|  | 768 | struct iwl_rx_mem_buffer *rxb) | 
|  | 769 | { | 
|  | 770 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 771 |  | 
|  | 772 | priv->_agn.last_phy_res_valid = true; | 
|  | 773 | memcpy(&priv->_agn.last_phy_res, pkt->u.raw, | 
|  | 774 | sizeof(struct iwl_rx_phy_res)); | 
|  | 775 | } | 
|  | 776 |  | 
| Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 777 | /* | 
|  | 778 | * returns non-zero if packet should be dropped | 
|  | 779 | */ | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 780 | static int iwl_set_decrypted_flag(struct iwl_priv *priv, | 
|  | 781 | struct ieee80211_hdr *hdr, | 
|  | 782 | u32 decrypt_res, | 
|  | 783 | struct ieee80211_rx_status *stats) | 
| Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 784 | { | 
|  | 785 | u16 fc = le16_to_cpu(hdr->frame_control); | 
|  | 786 |  | 
| Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 787 | /* | 
|  | 788 | * All contexts have the same setting here due to it being | 
|  | 789 | * a module parameter, so OK to check any context. | 
|  | 790 | */ | 
|  | 791 | if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags & | 
|  | 792 | RXON_FILTER_DIS_DECRYPT_MSK) | 
| Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 793 | return 0; | 
|  | 794 |  | 
|  | 795 | if (!(fc & IEEE80211_FCTL_PROTECTED)) | 
|  | 796 | return 0; | 
|  | 797 |  | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 798 | IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res); | 
| Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 799 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { | 
|  | 800 | case RX_RES_STATUS_SEC_TYPE_TKIP: | 
|  | 801 | /* The uCode has got a bad phase 1 Key, pushes the packet. | 
|  | 802 | * Decryption will be done in SW. */ | 
|  | 803 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | 
|  | 804 | RX_RES_STATUS_BAD_KEY_TTAK) | 
|  | 805 | break; | 
|  | 806 |  | 
|  | 807 | case RX_RES_STATUS_SEC_TYPE_WEP: | 
|  | 808 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | 
|  | 809 | RX_RES_STATUS_BAD_ICV_MIC) { | 
|  | 810 | /* bad ICV, the packet is destroyed since the | 
|  | 811 | * decryption is inplace, drop it */ | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 812 | IWL_DEBUG_RX(priv, "Packet destroyed\n"); | 
| Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 813 | return -1; | 
|  | 814 | } | 
|  | 815 | case RX_RES_STATUS_SEC_TYPE_CCMP: | 
|  | 816 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | 
|  | 817 | RX_RES_STATUS_DECRYPT_OK) { | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 818 | IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n"); | 
| Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 819 | stats->flag |= RX_FLAG_DECRYPTED; | 
|  | 820 | } | 
|  | 821 | break; | 
|  | 822 |  | 
|  | 823 | default: | 
|  | 824 | break; | 
|  | 825 | } | 
|  | 826 | return 0; | 
|  | 827 | } | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 828 |  | 
|  | 829 | static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv, | 
|  | 830 | struct ieee80211_hdr *hdr, | 
|  | 831 | u16 len, | 
|  | 832 | u32 ampdu_status, | 
|  | 833 | struct iwl_rx_mem_buffer *rxb, | 
|  | 834 | struct ieee80211_rx_status *stats) | 
|  | 835 | { | 
|  | 836 | struct sk_buff *skb; | 
|  | 837 | __le16 fc = hdr->frame_control; | 
| Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 838 | struct iwl_rxon_context *ctx; | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 839 |  | 
|  | 840 | /* We only process data packets if the interface is open */ | 
|  | 841 | if (unlikely(!priv->is_open)) { | 
|  | 842 | IWL_DEBUG_DROP_LIMIT(priv, | 
|  | 843 | "Dropping packet while interface is not open.\n"); | 
|  | 844 | return; | 
|  | 845 | } | 
|  | 846 |  | 
|  | 847 | /* In case of HW accelerated crypto and bad decryption, drop */ | 
| Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 848 | if (!iwlagn_mod_params.sw_crypto && | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 849 | iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats)) | 
|  | 850 | return; | 
|  | 851 |  | 
|  | 852 | skb = dev_alloc_skb(128); | 
|  | 853 | if (!skb) { | 
|  | 854 | IWL_ERR(priv, "dev_alloc_skb failed\n"); | 
|  | 855 | return; | 
|  | 856 | } | 
|  | 857 |  | 
|  | 858 | skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len); | 
|  | 859 |  | 
|  | 860 | iwl_update_stats(priv, false, fc, len); | 
| Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 861 |  | 
|  | 862 | /* | 
|  | 863 | * Wake any queues that were stopped due to a passive channel tx | 
|  | 864 | * failure. This can happen because the regulatory enforcement in | 
|  | 865 | * the device waits for a beacon before allowing transmission, | 
|  | 866 | * sometimes even after already having transmitted frames for the | 
|  | 867 | * association because the new RXON may reset the information. | 
|  | 868 | */ | 
|  | 869 | if (unlikely(ieee80211_is_beacon(fc))) { | 
|  | 870 | for_each_context(priv, ctx) { | 
|  | 871 | if (!ctx->last_tx_rejected) | 
|  | 872 | continue; | 
|  | 873 | if (compare_ether_addr(hdr->addr3, | 
|  | 874 | ctx->active.bssid_addr)) | 
|  | 875 | continue; | 
|  | 876 | ctx->last_tx_rejected = false; | 
|  | 877 | iwl_wake_any_queue(priv, ctx); | 
|  | 878 | } | 
|  | 879 | } | 
|  | 880 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 881 | memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); | 
|  | 882 |  | 
|  | 883 | ieee80211_rx(priv->hw, skb); | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 884 | rxb->page = NULL; | 
|  | 885 | } | 
|  | 886 |  | 
|  | 887 | static u32 iwl_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in) | 
|  | 888 | { | 
|  | 889 | u32 decrypt_out = 0; | 
|  | 890 |  | 
|  | 891 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == | 
|  | 892 | RX_RES_STATUS_STATION_FOUND) | 
|  | 893 | decrypt_out |= (RX_RES_STATUS_STATION_FOUND | | 
|  | 894 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); | 
|  | 895 |  | 
|  | 896 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); | 
|  | 897 |  | 
|  | 898 | /* packet was not encrypted */ | 
|  | 899 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | 
|  | 900 | RX_RES_STATUS_SEC_TYPE_NONE) | 
|  | 901 | return decrypt_out; | 
|  | 902 |  | 
|  | 903 | /* packet was encrypted with unknown alg */ | 
|  | 904 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | 
|  | 905 | RX_RES_STATUS_SEC_TYPE_ERR) | 
|  | 906 | return decrypt_out; | 
|  | 907 |  | 
|  | 908 | /* decryption was not done in HW */ | 
|  | 909 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != | 
|  | 910 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) | 
|  | 911 | return decrypt_out; | 
|  | 912 |  | 
|  | 913 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { | 
|  | 914 |  | 
|  | 915 | case RX_RES_STATUS_SEC_TYPE_CCMP: | 
|  | 916 | /* alg is CCM: check MIC only */ | 
|  | 917 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) | 
|  | 918 | /* Bad MIC */ | 
|  | 919 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | 
|  | 920 | else | 
|  | 921 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | 
|  | 922 |  | 
|  | 923 | break; | 
|  | 924 |  | 
|  | 925 | case RX_RES_STATUS_SEC_TYPE_TKIP: | 
|  | 926 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { | 
|  | 927 | /* Bad TTAK */ | 
|  | 928 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; | 
|  | 929 | break; | 
|  | 930 | } | 
|  | 931 | /* fall through if TTAK OK */ | 
|  | 932 | default: | 
|  | 933 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) | 
|  | 934 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | 
|  | 935 | else | 
|  | 936 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | 
|  | 937 | break; | 
|  | 938 | } | 
|  | 939 |  | 
|  | 940 | IWL_DEBUG_RX(priv, "decrypt_in:0x%x  decrypt_out = 0x%x\n", | 
|  | 941 | decrypt_in, decrypt_out); | 
|  | 942 |  | 
|  | 943 | return decrypt_out; | 
|  | 944 | } | 
|  | 945 |  | 
|  | 946 | /* Called for REPLY_RX (legacy ABG frames), or | 
|  | 947 | * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ | 
|  | 948 | static void iwl_rx_reply_rx(struct iwl_priv *priv, | 
|  | 949 | struct iwl_rx_mem_buffer *rxb) | 
|  | 950 | { | 
|  | 951 | struct ieee80211_hdr *header; | 
|  | 952 | struct ieee80211_rx_status rx_status; | 
|  | 953 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | 
|  | 954 | struct iwl_rx_phy_res *phy_res; | 
|  | 955 | __le32 rx_pkt_status; | 
|  | 956 | struct iwl_rx_mpdu_res_start *amsdu; | 
|  | 957 | u32 len; | 
|  | 958 | u32 ampdu_status; | 
|  | 959 | u32 rate_n_flags; | 
|  | 960 |  | 
|  | 961 | /** | 
|  | 962 | * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently. | 
|  | 963 | *	REPLY_RX: physical layer info is in this buffer | 
|  | 964 | *	REPLY_RX_MPDU_CMD: physical layer info was sent in separate | 
|  | 965 | *		command and cached in priv->last_phy_res | 
|  | 966 | * | 
|  | 967 | * Here we set up local variables depending on which command is | 
|  | 968 | * received. | 
|  | 969 | */ | 
|  | 970 | if (pkt->hdr.cmd == REPLY_RX) { | 
|  | 971 | phy_res = (struct iwl_rx_phy_res *)pkt->u.raw; | 
|  | 972 | header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res) | 
|  | 973 | + phy_res->cfg_phy_cnt); | 
|  | 974 |  | 
|  | 975 | len = le16_to_cpu(phy_res->byte_count); | 
|  | 976 | rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) + | 
|  | 977 | phy_res->cfg_phy_cnt + len); | 
|  | 978 | ampdu_status = le32_to_cpu(rx_pkt_status); | 
|  | 979 | } else { | 
|  | 980 | if (!priv->_agn.last_phy_res_valid) { | 
|  | 981 | IWL_ERR(priv, "MPDU frame without cached PHY data\n"); | 
|  | 982 | return; | 
|  | 983 | } | 
|  | 984 | phy_res = &priv->_agn.last_phy_res; | 
|  | 985 | amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw; | 
|  | 986 | header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu)); | 
|  | 987 | len = le16_to_cpu(amsdu->byte_count); | 
|  | 988 | rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len); | 
|  | 989 | ampdu_status = iwl_translate_rx_status(priv, | 
|  | 990 | le32_to_cpu(rx_pkt_status)); | 
|  | 991 | } | 
|  | 992 |  | 
|  | 993 | if ((unlikely(phy_res->cfg_phy_cnt > 20))) { | 
|  | 994 | IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n", | 
|  | 995 | phy_res->cfg_phy_cnt); | 
|  | 996 | return; | 
|  | 997 | } | 
|  | 998 |  | 
|  | 999 | if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) || | 
|  | 1000 | !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) { | 
|  | 1001 | IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n", | 
|  | 1002 | le32_to_cpu(rx_pkt_status)); | 
|  | 1003 | return; | 
|  | 1004 | } | 
|  | 1005 |  | 
|  | 1006 | /* This will be used in several places later */ | 
|  | 1007 | rate_n_flags = le32_to_cpu(phy_res->rate_n_flags); | 
|  | 1008 |  | 
|  | 1009 | /* rx_status carries information about the packet to mac80211 */ | 
|  | 1010 | rx_status.mactime = le64_to_cpu(phy_res->timestamp); | 
|  | 1011 | rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? | 
|  | 1012 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; | 
|  | 1013 | rx_status.freq = | 
|  | 1014 | ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel), | 
|  | 1015 | rx_status.band); | 
|  | 1016 | rx_status.rate_idx = | 
|  | 1017 | iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band); | 
|  | 1018 | rx_status.flag = 0; | 
|  | 1019 |  | 
|  | 1020 | /* TSF isn't reliable. In order to allow smooth user experience, | 
|  | 1021 | * this W/A doesn't propagate it to the mac80211 */ | 
|  | 1022 | /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/ | 
|  | 1023 |  | 
|  | 1024 | priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp); | 
|  | 1025 |  | 
|  | 1026 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ | 
|  | 1027 | rx_status.signal = priv->cfg->ops->utils->calc_rssi(priv, phy_res); | 
|  | 1028 |  | 
|  | 1029 | iwl_dbg_log_rx_data_frame(priv, len, header); | 
|  | 1030 | IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n", | 
|  | 1031 | rx_status.signal, (unsigned long long)rx_status.mactime); | 
|  | 1032 |  | 
|  | 1033 | /* | 
|  | 1034 | * "antenna number" | 
|  | 1035 | * | 
|  | 1036 | * It seems that the antenna field in the phy flags value | 
|  | 1037 | * is actually a bit field. This is undefined by radiotap, | 
|  | 1038 | * it wants an actual antenna number but I always get "7" | 
|  | 1039 | * for most legacy frames I receive indicating that the | 
|  | 1040 | * same frame was received on all three RX chains. | 
|  | 1041 | * | 
|  | 1042 | * I think this field should be removed in favor of a | 
|  | 1043 | * new 802.11n radiotap field "RX chains" that is defined | 
|  | 1044 | * as a bitmask. | 
|  | 1045 | */ | 
|  | 1046 | rx_status.antenna = | 
|  | 1047 | (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) | 
|  | 1048 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; | 
|  | 1049 |  | 
|  | 1050 | /* set the preamble flag if appropriate */ | 
|  | 1051 | if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) | 
|  | 1052 | rx_status.flag |= RX_FLAG_SHORTPRE; | 
|  | 1053 |  | 
|  | 1054 | /* Set up the HT phy flags */ | 
|  | 1055 | if (rate_n_flags & RATE_MCS_HT_MSK) | 
|  | 1056 | rx_status.flag |= RX_FLAG_HT; | 
|  | 1057 | if (rate_n_flags & RATE_MCS_HT40_MSK) | 
|  | 1058 | rx_status.flag |= RX_FLAG_40MHZ; | 
|  | 1059 | if (rate_n_flags & RATE_MCS_SGI_MSK) | 
|  | 1060 | rx_status.flag |= RX_FLAG_SHORT_GI; | 
|  | 1061 |  | 
|  | 1062 | iwl_pass_packet_to_mac80211(priv, header, len, ampdu_status, | 
|  | 1063 | rxb, &rx_status); | 
|  | 1064 | } | 
|  | 1065 |  | 
|  | 1066 | /** | 
|  | 1067 | * iwl_setup_rx_handlers - Initialize Rx handler callbacks | 
|  | 1068 | * | 
|  | 1069 | * Setup the RX handlers for each of the reply types sent from the uCode | 
|  | 1070 | * to the host. | 
|  | 1071 | */ | 
|  | 1072 | void iwl_setup_rx_handlers(struct iwl_priv *priv) | 
|  | 1073 | { | 
|  | 1074 | void (**handlers)(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb); | 
|  | 1075 |  | 
|  | 1076 | handlers = priv->rx_handlers; | 
|  | 1077 |  | 
| Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1078 | handlers[REPLY_ERROR]			= iwl_rx_reply_error; | 
|  | 1079 | handlers[CHANNEL_SWITCH_NOTIFICATION]	= iwl_rx_csa; | 
|  | 1080 | handlers[SPECTRUM_MEASURE_NOTIFICATION]	= iwl_rx_spectrum_measure_notif; | 
|  | 1081 | handlers[PM_SLEEP_NOTIFICATION]		= iwl_rx_pm_sleep_notif; | 
|  | 1082 | handlers[PM_DEBUG_STATISTIC_NOTIFIC]	= iwl_rx_pm_debug_statistics_notif; | 
|  | 1083 | handlers[BEACON_NOTIFICATION]		= iwl_rx_beacon_notif; | 
|  | 1084 |  | 
|  | 1085 | /* | 
|  | 1086 | * The same handler is used for both the REPLY to a discrete | 
|  | 1087 | * statistics request from the host as well as for the periodic | 
|  | 1088 | * statistics notifications (after received beacons) from the uCode. | 
|  | 1089 | */ | 
|  | 1090 | handlers[REPLY_STATISTICS_CMD]		= iwl_rx_reply_statistics; | 
|  | 1091 | handlers[STATISTICS_NOTIFICATION]	= iwl_rx_statistics; | 
|  | 1092 |  | 
|  | 1093 | iwl_setup_rx_scan_handlers(priv); | 
|  | 1094 |  | 
|  | 1095 | handlers[CARD_STATE_NOTIFICATION]	= iwl_rx_card_state_notif; | 
|  | 1096 | handlers[MISSED_BEACONS_NOTIFICATION]	= iwl_rx_missed_beacon_notif; | 
|  | 1097 |  | 
|  | 1098 | /* Rx handlers */ | 
|  | 1099 | handlers[REPLY_RX_PHY_CMD]		= iwl_rx_reply_rx_phy; | 
|  | 1100 | handlers[REPLY_RX_MPDU_CMD]		= iwl_rx_reply_rx; | 
|  | 1101 |  | 
|  | 1102 | /* block ack */ | 
|  | 1103 | handlers[REPLY_COMPRESSED_BA]		= iwlagn_rx_reply_compressed_ba; | 
|  | 1104 |  | 
|  | 1105 | /* Set up hardware specific Rx handlers */ | 
|  | 1106 | priv->cfg->ops->lib->rx_handler_setup(priv); | 
|  | 1107 | } |