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