Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. |
| 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: |
| 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 31 | |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/pci.h> |
| 36 | #include <linux/pci-aspm.h> |
| 37 | #include <linux/slab.h> |
| 38 | #include <linux/dma-mapping.h> |
| 39 | #include <linux/delay.h> |
| 40 | #include <linux/sched.h> |
| 41 | #include <linux/skbuff.h> |
| 42 | #include <linux/netdevice.h> |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 43 | #include <linux/firmware.h> |
| 44 | #include <linux/etherdevice.h> |
| 45 | #include <linux/if_arp.h> |
| 46 | |
| 47 | #include <net/mac80211.h> |
| 48 | |
| 49 | #include <asm/div64.h> |
| 50 | |
| 51 | #define DRV_NAME "iwl4965" |
| 52 | |
Stanislaw Gruszka | 98613be | 2011-11-15 14:19:34 +0100 | [diff] [blame] | 53 | #include "common.h" |
Stanislaw Gruszka | af038f4 | 2011-08-30 13:58:27 +0200 | [diff] [blame] | 54 | #include "4965.h" |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 55 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 56 | /****************************************************************************** |
| 57 | * |
| 58 | * module boiler plate |
| 59 | * |
| 60 | ******************************************************************************/ |
| 61 | |
| 62 | /* |
| 63 | * module name, copyright, version, etc. |
| 64 | */ |
| 65 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi 4965 driver for Linux" |
| 66 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 67 | #ifdef CONFIG_IWLEGACY_DEBUG |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 68 | #define VD "d" |
| 69 | #else |
| 70 | #define VD |
| 71 | #endif |
| 72 | |
| 73 | #define DRV_VERSION IWLWIFI_VERSION VD |
| 74 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 75 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 76 | MODULE_VERSION(DRV_VERSION); |
| 77 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
| 78 | MODULE_LICENSE("GPL"); |
| 79 | MODULE_ALIAS("iwl4965"); |
| 80 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 81 | void |
| 82 | il4965_check_abort_status(struct il_priv *il, u8 frame_count, u32 status) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 83 | { |
| 84 | if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) { |
| 85 | IL_ERR("Tx flush command to flush out all frames\n"); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 86 | if (!test_bit(S_EXIT_PENDING, &il->status)) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 87 | queue_work(il->workqueue, &il->tx_flush); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * EEPROM |
| 93 | */ |
| 94 | struct il_mod_params il4965_mod_params = { |
| 95 | .amsdu_size_8K = 1, |
| 96 | .restart_fw = 1, |
| 97 | /* the rest are 0 by default */ |
| 98 | }; |
| 99 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 100 | void |
| 101 | il4965_rx_queue_reset(struct il_priv *il, struct il_rx_queue *rxq) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 102 | { |
| 103 | unsigned long flags; |
| 104 | int i; |
| 105 | spin_lock_irqsave(&rxq->lock, flags); |
| 106 | INIT_LIST_HEAD(&rxq->rx_free); |
| 107 | INIT_LIST_HEAD(&rxq->rx_used); |
| 108 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 109 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 110 | /* In the reset function, these buffers may have been allocated |
| 111 | * to an SKB, so we need to unmap and free potential storage */ |
| 112 | if (rxq->pool[i].page != NULL) { |
| 113 | pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 114 | PAGE_SIZE << il->hw_params.rx_page_order, |
| 115 | PCI_DMA_FROMDEVICE); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 116 | __il_free_pages(il, rxq->pool[i].page); |
| 117 | rxq->pool[i].page = NULL; |
| 118 | } |
| 119 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 120 | } |
| 121 | |
| 122 | for (i = 0; i < RX_QUEUE_SIZE; i++) |
| 123 | rxq->queue[i] = NULL; |
| 124 | |
| 125 | /* Set us so that we have processed and used all buffers, but have |
| 126 | * not restocked the Rx queue with fresh buffers */ |
| 127 | rxq->read = rxq->write = 0; |
| 128 | rxq->write_actual = 0; |
| 129 | rxq->free_count = 0; |
| 130 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 131 | } |
| 132 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 133 | int |
| 134 | il4965_rx_init(struct il_priv *il, struct il_rx_queue *rxq) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 135 | { |
| 136 | u32 rb_size; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 137 | const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */ |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 138 | u32 rb_timeout = 0; |
| 139 | |
| 140 | if (il->cfg->mod_params->amsdu_size_8K) |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 141 | rb_size = FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 142 | else |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 143 | rb_size = FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 144 | |
| 145 | /* Stop Rx DMA */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 146 | il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG, 0); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 147 | |
| 148 | /* Reset driver's Rx queue write idx */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 149 | il_wr(il, FH49_RSCSR_CHNL0_RBDCB_WPTR_REG, 0); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 150 | |
| 151 | /* Tell device where to find RBD circular buffer in DRAM */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 152 | il_wr(il, FH49_RSCSR_CHNL0_RBDCB_BASE_REG, (u32) (rxq->bd_dma >> 8)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 153 | |
| 154 | /* Tell device where in DRAM to update its Rx status */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 155 | il_wr(il, FH49_RSCSR_CHNL0_STTS_WPTR_REG, rxq->rb_stts_dma >> 4); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 156 | |
| 157 | /* Enable Rx DMA |
| 158 | * Direct rx interrupts to hosts |
| 159 | * Rx buffer size 4 or 8k |
| 160 | * RB timeout 0x10 |
| 161 | * 256 RBDs |
| 162 | */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 163 | il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 164 | FH49_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL | |
| 165 | FH49_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL | |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 166 | FH49_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK | |
| 167 | rb_size | |
| 168 | (rb_timeout << FH49_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS) | |
| 169 | (rfdnlog << FH49_RCSR_RX_CONFIG_RBDCB_SIZE_POS)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 170 | |
| 171 | /* Set interrupt coalescing timer to default (2048 usecs) */ |
| 172 | il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_TIMEOUT_DEF); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 177 | static void |
| 178 | il4965_set_pwr_vmain(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 179 | { |
| 180 | /* |
| 181 | * (for documentation purposes) |
| 182 | * to set power to V_AUX, do: |
| 183 | |
| 184 | if (pci_pme_capable(il->pci_dev, PCI_D3cold)) |
| 185 | il_set_bits_mask_prph(il, APMG_PS_CTRL_REG, |
| 186 | APMG_PS_CTRL_VAL_PWR_SRC_VAUX, |
| 187 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
| 188 | */ |
| 189 | |
| 190 | il_set_bits_mask_prph(il, APMG_PS_CTRL_REG, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 191 | APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, |
| 192 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 195 | int |
| 196 | il4965_hw_nic_init(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 197 | { |
| 198 | unsigned long flags; |
| 199 | struct il_rx_queue *rxq = &il->rxq; |
| 200 | int ret; |
| 201 | |
| 202 | /* nic_init */ |
| 203 | spin_lock_irqsave(&il->lock, flags); |
| 204 | il->cfg->ops->lib->apm_ops.init(il); |
| 205 | |
| 206 | /* Set interrupt coalescing calibration timer to default (512 usecs) */ |
| 207 | il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_CALIB_TIMEOUT_DEF); |
| 208 | |
| 209 | spin_unlock_irqrestore(&il->lock, flags); |
| 210 | |
| 211 | il4965_set_pwr_vmain(il); |
| 212 | |
| 213 | il->cfg->ops->lib->apm_ops.config(il); |
| 214 | |
| 215 | /* Allocate the RX queue, or reset if it is already allocated */ |
| 216 | if (!rxq->bd) { |
| 217 | ret = il_rx_queue_alloc(il); |
| 218 | if (ret) { |
| 219 | IL_ERR("Unable to initialize Rx queue\n"); |
| 220 | return -ENOMEM; |
| 221 | } |
| 222 | } else |
| 223 | il4965_rx_queue_reset(il, rxq); |
| 224 | |
| 225 | il4965_rx_replenish(il); |
| 226 | |
| 227 | il4965_rx_init(il, rxq); |
| 228 | |
| 229 | spin_lock_irqsave(&il->lock, flags); |
| 230 | |
| 231 | rxq->need_update = 1; |
| 232 | il_rx_queue_update_write_ptr(il, rxq); |
| 233 | |
| 234 | spin_unlock_irqrestore(&il->lock, flags); |
| 235 | |
| 236 | /* Allocate or reset and init all Tx and Command queues */ |
| 237 | if (!il->txq) { |
| 238 | ret = il4965_txq_ctx_alloc(il); |
| 239 | if (ret) |
| 240 | return ret; |
| 241 | } else |
| 242 | il4965_txq_ctx_reset(il); |
| 243 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 244 | set_bit(S_INIT, &il->status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * il4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr |
| 251 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 252 | static inline __le32 |
| 253 | il4965_dma_addr2rbd_ptr(struct il_priv *il, dma_addr_t dma_addr) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 254 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 255 | return cpu_to_le32((u32) (dma_addr >> 8)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /** |
| 259 | * il4965_rx_queue_restock - refill RX queue from pre-allocated pool |
| 260 | * |
| 261 | * If there are slots in the RX queue that need to be restocked, |
| 262 | * and we have free pre-allocated buffers, fill the ranks as much |
| 263 | * as we can, pulling from rx_free. |
| 264 | * |
| 265 | * This moves the 'write' idx forward to catch up with 'processed', and |
| 266 | * also updates the memory address in the firmware to reference the new |
| 267 | * target buffer. |
| 268 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 269 | void |
| 270 | il4965_rx_queue_restock(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 271 | { |
| 272 | struct il_rx_queue *rxq = &il->rxq; |
| 273 | struct list_head *element; |
| 274 | struct il_rx_buf *rxb; |
| 275 | unsigned long flags; |
| 276 | |
| 277 | spin_lock_irqsave(&rxq->lock, flags); |
| 278 | while (il_rx_queue_space(rxq) > 0 && rxq->free_count) { |
| 279 | /* The overwritten rxb must be a used one */ |
| 280 | rxb = rxq->queue[rxq->write]; |
| 281 | BUG_ON(rxb && rxb->page); |
| 282 | |
| 283 | /* Get next free Rx buffer, remove from free list */ |
| 284 | element = rxq->rx_free.next; |
| 285 | rxb = list_entry(element, struct il_rx_buf, list); |
| 286 | list_del(element); |
| 287 | |
| 288 | /* Point to Rx buffer via next RBD in circular buffer */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 289 | rxq->bd[rxq->write] = |
| 290 | il4965_dma_addr2rbd_ptr(il, rxb->page_dma); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 291 | rxq->queue[rxq->write] = rxb; |
| 292 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 293 | rxq->free_count--; |
| 294 | } |
| 295 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 296 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 297 | * refill it */ |
| 298 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 299 | queue_work(il->workqueue, &il->rx_replenish); |
| 300 | |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 301 | /* If we've added more space for the firmware to place data, tell it. |
| 302 | * Increment device's write pointer in multiples of 8. */ |
| 303 | if (rxq->write_actual != (rxq->write & ~0x7)) { |
| 304 | spin_lock_irqsave(&rxq->lock, flags); |
| 305 | rxq->need_update = 1; |
| 306 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 307 | il_rx_queue_update_write_ptr(il, rxq); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * il4965_rx_replenish - Move all used packet from rx_used to rx_free |
| 313 | * |
| 314 | * When moving to rx_free an SKB is allocated for the slot. |
| 315 | * |
| 316 | * Also restock the Rx queue via il_rx_queue_restock. |
| 317 | * This is called as a scheduled work item (except for during initialization) |
| 318 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 319 | static void |
| 320 | il4965_rx_allocate(struct il_priv *il, gfp_t priority) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 321 | { |
| 322 | struct il_rx_queue *rxq = &il->rxq; |
| 323 | struct list_head *element; |
| 324 | struct il_rx_buf *rxb; |
| 325 | struct page *page; |
| 326 | unsigned long flags; |
| 327 | gfp_t gfp_mask = priority; |
| 328 | |
| 329 | while (1) { |
| 330 | spin_lock_irqsave(&rxq->lock, flags); |
| 331 | if (list_empty(&rxq->rx_used)) { |
| 332 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 333 | return; |
| 334 | } |
| 335 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 336 | |
| 337 | if (rxq->free_count > RX_LOW_WATERMARK) |
| 338 | gfp_mask |= __GFP_NOWARN; |
| 339 | |
| 340 | if (il->hw_params.rx_page_order > 0) |
| 341 | gfp_mask |= __GFP_COMP; |
| 342 | |
| 343 | /* Alloc a new receive buffer */ |
| 344 | page = alloc_pages(gfp_mask, il->hw_params.rx_page_order); |
| 345 | if (!page) { |
| 346 | if (net_ratelimit()) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 347 | D_INFO("alloc_pages failed, " "order: %d\n", |
| 348 | il->hw_params.rx_page_order); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 349 | |
| 350 | if (rxq->free_count <= RX_LOW_WATERMARK && |
| 351 | net_ratelimit()) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 352 | IL_ERR("Failed to alloc_pages with %s. " |
| 353 | "Only %u free buffers remaining.\n", |
| 354 | priority == |
| 355 | GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL", |
| 356 | rxq->free_count); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 357 | /* We don't reschedule replenish work here -- we will |
| 358 | * call the restock method and if it still needs |
| 359 | * more buffers it will schedule replenish */ |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | spin_lock_irqsave(&rxq->lock, flags); |
| 364 | |
| 365 | if (list_empty(&rxq->rx_used)) { |
| 366 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 367 | __free_pages(page, il->hw_params.rx_page_order); |
| 368 | return; |
| 369 | } |
| 370 | element = rxq->rx_used.next; |
| 371 | rxb = list_entry(element, struct il_rx_buf, list); |
| 372 | list_del(element); |
| 373 | |
| 374 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 375 | |
| 376 | BUG_ON(rxb->page); |
| 377 | rxb->page = page; |
| 378 | /* Get physical address of the RB */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 379 | rxb->page_dma = |
| 380 | pci_map_page(il->pci_dev, page, 0, |
| 381 | PAGE_SIZE << il->hw_params.rx_page_order, |
| 382 | PCI_DMA_FROMDEVICE); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 383 | /* dma address must be no more than 36 bits */ |
| 384 | BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36)); |
| 385 | /* and also 256 byte aligned! */ |
| 386 | BUG_ON(rxb->page_dma & DMA_BIT_MASK(8)); |
| 387 | |
| 388 | spin_lock_irqsave(&rxq->lock, flags); |
| 389 | |
| 390 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 391 | rxq->free_count++; |
| 392 | il->alloc_rxb_page++; |
| 393 | |
| 394 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 395 | } |
| 396 | } |
| 397 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 398 | void |
| 399 | il4965_rx_replenish(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 400 | { |
| 401 | unsigned long flags; |
| 402 | |
| 403 | il4965_rx_allocate(il, GFP_KERNEL); |
| 404 | |
| 405 | spin_lock_irqsave(&il->lock, flags); |
| 406 | il4965_rx_queue_restock(il); |
| 407 | spin_unlock_irqrestore(&il->lock, flags); |
| 408 | } |
| 409 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 410 | void |
| 411 | il4965_rx_replenish_now(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 412 | { |
| 413 | il4965_rx_allocate(il, GFP_ATOMIC); |
| 414 | |
| 415 | il4965_rx_queue_restock(il); |
| 416 | } |
| 417 | |
| 418 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
| 419 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
| 420 | * This free routine walks the list of POOL entries and if SKB is set to |
| 421 | * non NULL it is unmapped and freed |
| 422 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 423 | void |
| 424 | il4965_rx_queue_free(struct il_priv *il, struct il_rx_queue *rxq) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 425 | { |
| 426 | int i; |
| 427 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 428 | if (rxq->pool[i].page != NULL) { |
| 429 | pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 430 | PAGE_SIZE << il->hw_params.rx_page_order, |
| 431 | PCI_DMA_FROMDEVICE); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 432 | __il_free_pages(il, rxq->pool[i].page); |
| 433 | rxq->pool[i].page = NULL; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | dma_free_coherent(&il->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 438 | rxq->bd_dma); |
| 439 | dma_free_coherent(&il->pci_dev->dev, sizeof(struct il_rb_status), |
| 440 | rxq->rb_stts, rxq->rb_stts_dma); |
| 441 | rxq->bd = NULL; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 442 | rxq->rb_stts = NULL; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 445 | int |
| 446 | il4965_rxq_stop(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 447 | { |
| 448 | |
| 449 | /* stop Rx DMA */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 450 | il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG, 0); |
| 451 | il_poll_bit(il, FH49_MEM_RSSR_RX_STATUS_REG, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 452 | FH49_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 457 | int |
| 458 | il4965_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 459 | { |
| 460 | int idx = 0; |
| 461 | int band_offset = 0; |
| 462 | |
| 463 | /* HT rate format: mac80211 wants an MCS number, which is just LSB */ |
| 464 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 465 | idx = (rate_n_flags & 0xff); |
| 466 | return idx; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 467 | /* Legacy rate format, search for match in table */ |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 468 | } else { |
| 469 | if (band == IEEE80211_BAND_5GHZ) |
| 470 | band_offset = IL_FIRST_OFDM_RATE; |
| 471 | for (idx = band_offset; idx < RATE_COUNT_LEGACY; idx++) |
| 472 | if (il_rates[idx].plcp == (rate_n_flags & 0xFF)) |
| 473 | return idx - band_offset; |
| 474 | } |
| 475 | |
| 476 | return -1; |
| 477 | } |
| 478 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 479 | static int |
| 480 | il4965_calc_rssi(struct il_priv *il, struct il_rx_phy_res *rx_resp) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 481 | { |
| 482 | /* data from PHY/DSP regarding signal strength, etc., |
| 483 | * contents are always there, not configurable by host. */ |
| 484 | struct il4965_rx_non_cfg_phy *ncphy = |
| 485 | (struct il4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy_buf; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 486 | u32 agc = |
| 487 | (le16_to_cpu(ncphy->agc_info) & IL49_AGC_DB_MASK) >> |
| 488 | IL49_AGC_DB_POS; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 489 | |
| 490 | u32 valid_antennae = |
| 491 | (le16_to_cpu(rx_resp->phy_flags) & IL49_RX_PHY_FLAGS_ANTENNAE_MASK) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 492 | >> IL49_RX_PHY_FLAGS_ANTENNAE_OFFSET; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 493 | u8 max_rssi = 0; |
| 494 | u32 i; |
| 495 | |
| 496 | /* Find max rssi among 3 possible receivers. |
| 497 | * These values are measured by the digital signal processor (DSP). |
| 498 | * They should stay fairly constant even as the signal strength varies, |
| 499 | * if the radio's automatic gain control (AGC) is working right. |
| 500 | * AGC value (see below) will provide the "interesting" info. */ |
| 501 | for (i = 0; i < 3; i++) |
| 502 | if (valid_antennae & (1 << i)) |
| 503 | max_rssi = max(ncphy->rssi_info[i << 1], max_rssi); |
| 504 | |
| 505 | D_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n", |
| 506 | ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4], |
| 507 | max_rssi, agc); |
| 508 | |
| 509 | /* dBm = max_rssi dB - agc dB - constant. |
| 510 | * Higher AGC (higher radio gain) means lower signal. */ |
| 511 | return max_rssi - agc - IL4965_RSSI_OFFSET; |
| 512 | } |
| 513 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 514 | static u32 |
| 515 | il4965_translate_rx_status(struct il_priv *il, u32 decrypt_in) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 516 | { |
| 517 | u32 decrypt_out = 0; |
| 518 | |
| 519 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 520 | RX_RES_STATUS_STATION_FOUND) |
| 521 | decrypt_out |= |
| 522 | (RX_RES_STATUS_STATION_FOUND | |
| 523 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 524 | |
| 525 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); |
| 526 | |
| 527 | /* packet was not encrypted */ |
| 528 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 529 | RX_RES_STATUS_SEC_TYPE_NONE) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 530 | return decrypt_out; |
| 531 | |
| 532 | /* packet was encrypted with unknown alg */ |
| 533 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 534 | RX_RES_STATUS_SEC_TYPE_ERR) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 535 | return decrypt_out; |
| 536 | |
| 537 | /* decryption was not done in HW */ |
| 538 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 539 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 540 | return decrypt_out; |
| 541 | |
| 542 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 543 | |
| 544 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 545 | /* alg is CCM: check MIC only */ |
| 546 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) |
| 547 | /* Bad MIC */ |
| 548 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 549 | else |
| 550 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 551 | |
| 552 | break; |
| 553 | |
| 554 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 555 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { |
| 556 | /* Bad TTAK */ |
| 557 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; |
| 558 | break; |
| 559 | } |
| 560 | /* fall through if TTAK OK */ |
| 561 | default: |
| 562 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) |
| 563 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 564 | else |
| 565 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 566 | break; |
| 567 | } |
| 568 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 569 | D_RX("decrypt_in:0x%x decrypt_out = 0x%x\n", decrypt_in, decrypt_out); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 570 | |
| 571 | return decrypt_out; |
| 572 | } |
| 573 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 574 | static void |
| 575 | il4965_pass_packet_to_mac80211(struct il_priv *il, struct ieee80211_hdr *hdr, |
| 576 | u16 len, u32 ampdu_status, struct il_rx_buf *rxb, |
| 577 | struct ieee80211_rx_status *stats) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 578 | { |
| 579 | struct sk_buff *skb; |
| 580 | __le16 fc = hdr->frame_control; |
| 581 | |
| 582 | /* We only process data packets if the interface is open */ |
| 583 | if (unlikely(!il->is_open)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 584 | D_DROP("Dropping packet while interface is not open.\n"); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 585 | return; |
| 586 | } |
| 587 | |
| 588 | /* In case of HW accelerated crypto and bad decryption, drop */ |
| 589 | if (!il->cfg->mod_params->sw_crypto && |
| 590 | il_set_decrypted_flag(il, hdr, ampdu_status, stats)) |
| 591 | return; |
| 592 | |
| 593 | skb = dev_alloc_skb(128); |
| 594 | if (!skb) { |
| 595 | IL_ERR("dev_alloc_skb failed\n"); |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len); |
| 600 | |
| 601 | il_update_stats(il, false, fc, len); |
| 602 | memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); |
| 603 | |
| 604 | ieee80211_rx(il->hw, skb); |
| 605 | il->alloc_rxb_page--; |
| 606 | rxb->page = NULL; |
| 607 | } |
| 608 | |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 609 | /* Called for N_RX (legacy ABG frames), or |
| 610 | * N_RX_MPDU (HT high-throughput N frames). */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 611 | void |
| 612 | il4965_hdl_rx(struct il_priv *il, struct il_rx_buf *rxb) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 613 | { |
| 614 | struct ieee80211_hdr *header; |
| 615 | struct ieee80211_rx_status rx_status; |
| 616 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 617 | struct il_rx_phy_res *phy_res; |
| 618 | __le32 rx_pkt_status; |
| 619 | struct il_rx_mpdu_res_start *amsdu; |
| 620 | u32 len; |
| 621 | u32 ampdu_status; |
| 622 | u32 rate_n_flags; |
| 623 | |
| 624 | /** |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 625 | * N_RX and N_RX_MPDU are handled differently. |
| 626 | * N_RX: physical layer info is in this buffer |
| 627 | * N_RX_MPDU: physical layer info was sent in separate |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 628 | * command and cached in il->last_phy_res |
| 629 | * |
| 630 | * Here we set up local variables depending on which command is |
| 631 | * received. |
| 632 | */ |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 633 | if (pkt->hdr.cmd == N_RX) { |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 634 | phy_res = (struct il_rx_phy_res *)pkt->u.raw; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 635 | header = |
| 636 | (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res) + |
| 637 | phy_res->cfg_phy_cnt); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 638 | |
| 639 | len = le16_to_cpu(phy_res->byte_count); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 640 | rx_pkt_status = |
| 641 | *(__le32 *) (pkt->u.raw + sizeof(*phy_res) + |
| 642 | phy_res->cfg_phy_cnt + len); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 643 | ampdu_status = le32_to_cpu(rx_pkt_status); |
| 644 | } else { |
| 645 | if (!il->_4965.last_phy_res_valid) { |
| 646 | IL_ERR("MPDU frame without cached PHY data\n"); |
| 647 | return; |
| 648 | } |
| 649 | phy_res = &il->_4965.last_phy_res; |
| 650 | amsdu = (struct il_rx_mpdu_res_start *)pkt->u.raw; |
| 651 | header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu)); |
| 652 | len = le16_to_cpu(amsdu->byte_count); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 653 | rx_pkt_status = *(__le32 *) (pkt->u.raw + sizeof(*amsdu) + len); |
| 654 | ampdu_status = |
| 655 | il4965_translate_rx_status(il, le32_to_cpu(rx_pkt_status)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | if ((unlikely(phy_res->cfg_phy_cnt > 20))) { |
| 659 | D_DROP("dsp size out of range [0,20]: %d/n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 660 | phy_res->cfg_phy_cnt); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 661 | return; |
| 662 | } |
| 663 | |
| 664 | if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) || |
| 665 | !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 666 | D_RX("Bad CRC or FIFO: 0x%08X.\n", le32_to_cpu(rx_pkt_status)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 667 | return; |
| 668 | } |
| 669 | |
| 670 | /* This will be used in several places later */ |
| 671 | rate_n_flags = le32_to_cpu(phy_res->rate_n_flags); |
| 672 | |
| 673 | /* rx_status carries information about the packet to mac80211 */ |
| 674 | rx_status.mactime = le64_to_cpu(phy_res->timestamp); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 675 | rx_status.band = |
| 676 | (phy_res-> |
| 677 | phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? IEEE80211_BAND_2GHZ : |
| 678 | IEEE80211_BAND_5GHZ; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 679 | rx_status.freq = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 680 | ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel), |
| 681 | rx_status.band); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 682 | rx_status.rate_idx = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 683 | il4965_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 684 | rx_status.flag = 0; |
| 685 | |
| 686 | /* TSF isn't reliable. In order to allow smooth user experience, |
| 687 | * this W/A doesn't propagate it to the mac80211 */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 688 | /*rx_status.flag |= RX_FLAG_MACTIME_MPDU; */ |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 689 | |
| 690 | il->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp); |
| 691 | |
| 692 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ |
| 693 | rx_status.signal = il4965_calc_rssi(il, phy_res); |
| 694 | |
| 695 | il_dbg_log_rx_data_frame(il, len, header); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 696 | D_STATS("Rssi %d, TSF %llu\n", rx_status.signal, |
| 697 | (unsigned long long)rx_status.mactime); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 698 | |
| 699 | /* |
| 700 | * "antenna number" |
| 701 | * |
| 702 | * It seems that the antenna field in the phy flags value |
| 703 | * is actually a bit field. This is undefined by radiotap, |
| 704 | * it wants an actual antenna number but I always get "7" |
| 705 | * for most legacy frames I receive indicating that the |
| 706 | * same frame was received on all three RX chains. |
| 707 | * |
| 708 | * I think this field should be removed in favor of a |
| 709 | * new 802.11n radiotap field "RX chains" that is defined |
| 710 | * as a bitmask. |
| 711 | */ |
| 712 | rx_status.antenna = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 713 | (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> |
| 714 | RX_RES_PHY_FLAGS_ANTENNA_POS; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 715 | |
| 716 | /* set the preamble flag if appropriate */ |
| 717 | if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) |
| 718 | rx_status.flag |= RX_FLAG_SHORTPRE; |
| 719 | |
| 720 | /* Set up the HT phy flags */ |
| 721 | if (rate_n_flags & RATE_MCS_HT_MSK) |
| 722 | rx_status.flag |= RX_FLAG_HT; |
| 723 | if (rate_n_flags & RATE_MCS_HT40_MSK) |
| 724 | rx_status.flag |= RX_FLAG_40MHZ; |
| 725 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
| 726 | rx_status.flag |= RX_FLAG_SHORT_GI; |
| 727 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 728 | il4965_pass_packet_to_mac80211(il, header, len, ampdu_status, rxb, |
| 729 | &rx_status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 730 | } |
| 731 | |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 732 | /* Cache phy data (Rx signal strength, etc) for HT frame (N_RX_PHY). |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 733 | * This will be used later in il_hdl_rx() for N_RX_MPDU. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 734 | void |
| 735 | il4965_hdl_rx_phy(struct il_priv *il, struct il_rx_buf *rxb) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 736 | { |
| 737 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 738 | il->_4965.last_phy_res_valid = true; |
| 739 | memcpy(&il->_4965.last_phy_res, pkt->u.raw, |
| 740 | sizeof(struct il_rx_phy_res)); |
| 741 | } |
| 742 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 743 | static int |
| 744 | il4965_get_channels_for_scan(struct il_priv *il, struct ieee80211_vif *vif, |
| 745 | enum ieee80211_band band, u8 is_active, |
| 746 | u8 n_probes, struct il_scan_channel *scan_ch) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 747 | { |
| 748 | struct ieee80211_channel *chan; |
| 749 | const struct ieee80211_supported_band *sband; |
| 750 | const struct il_channel_info *ch_info; |
| 751 | u16 passive_dwell = 0; |
| 752 | u16 active_dwell = 0; |
| 753 | int added, i; |
| 754 | u16 channel; |
| 755 | |
| 756 | sband = il_get_hw_mode(il, band); |
| 757 | if (!sband) |
| 758 | return 0; |
| 759 | |
| 760 | active_dwell = il_get_active_dwell_time(il, band, n_probes); |
| 761 | passive_dwell = il_get_passive_dwell_time(il, band, vif); |
| 762 | |
| 763 | if (passive_dwell <= active_dwell) |
| 764 | passive_dwell = active_dwell + 1; |
| 765 | |
| 766 | for (i = 0, added = 0; i < il->scan_request->n_channels; i++) { |
| 767 | chan = il->scan_request->channels[i]; |
| 768 | |
| 769 | if (chan->band != band) |
| 770 | continue; |
| 771 | |
| 772 | channel = chan->hw_value; |
| 773 | scan_ch->channel = cpu_to_le16(channel); |
| 774 | |
| 775 | ch_info = il_get_channel_info(il, band, channel); |
| 776 | if (!il_is_channel_valid(ch_info)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 777 | D_SCAN("Channel %d is INVALID for this band.\n", |
| 778 | channel); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 779 | continue; |
| 780 | } |
| 781 | |
| 782 | if (!is_active || il_is_channel_passive(ch_info) || |
| 783 | (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
| 784 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; |
| 785 | else |
| 786 | scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE; |
| 787 | |
| 788 | if (n_probes) |
| 789 | scan_ch->type |= IL_SCAN_PROBE_MASK(n_probes); |
| 790 | |
| 791 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 792 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 793 | |
| 794 | /* Set txpower levels to defaults */ |
| 795 | scan_ch->dsp_atten = 110; |
| 796 | |
| 797 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
| 798 | * power level: |
| 799 | * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3; |
| 800 | */ |
| 801 | if (band == IEEE80211_BAND_5GHZ) |
| 802 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 803 | else |
| 804 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); |
| 805 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 806 | D_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n", channel, |
| 807 | le32_to_cpu(scan_ch->type), |
| 808 | (scan_ch-> |
| 809 | type & SCAN_CHANNEL_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE", |
| 810 | (scan_ch-> |
| 811 | type & SCAN_CHANNEL_TYPE_ACTIVE) ? active_dwell : |
| 812 | passive_dwell); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 813 | |
| 814 | scan_ch++; |
| 815 | added++; |
| 816 | } |
| 817 | |
| 818 | D_SCAN("total channels to scan %d\n", added); |
| 819 | return added; |
| 820 | } |
| 821 | |
Stanislaw Gruszka | a0c1ef3 | 2011-12-23 08:13:44 +0100 | [diff] [blame] | 822 | static void |
| 823 | il4965_toggle_tx_ant(struct il_priv *il, u8 *ant, u8 valid) |
| 824 | { |
| 825 | int i; |
| 826 | u8 ind = *ant; |
| 827 | |
| 828 | for (i = 0; i < RATE_ANT_NUM - 1; i++) { |
| 829 | ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0; |
| 830 | if (valid & BIT(ind)) { |
| 831 | *ant = ind; |
| 832 | return; |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 837 | int |
| 838 | il4965_request_scan(struct il_priv *il, struct ieee80211_vif *vif) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 839 | { |
| 840 | struct il_host_cmd cmd = { |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 841 | .id = C_SCAN, |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 842 | .len = sizeof(struct il_scan_cmd), |
| 843 | .flags = CMD_SIZE_HUGE, |
| 844 | }; |
| 845 | struct il_scan_cmd *scan; |
| 846 | struct il_rxon_context *ctx = &il->ctx; |
| 847 | u32 rate_flags = 0; |
| 848 | u16 cmd_len; |
| 849 | u16 rx_chain = 0; |
| 850 | enum ieee80211_band band; |
| 851 | u8 n_probes = 0; |
| 852 | u8 rx_ant = il->hw_params.valid_rx_ant; |
| 853 | u8 rate; |
| 854 | bool is_active = false; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 855 | int chan_mod; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 856 | u8 active_chains; |
| 857 | u8 scan_tx_antennas = il->hw_params.valid_tx_ant; |
| 858 | int ret; |
| 859 | |
| 860 | lockdep_assert_held(&il->mutex); |
| 861 | |
Greg Dietsche | 730b4c2 | 2011-09-06 17:33:51 -0500 | [diff] [blame] | 862 | ctx = il_rxon_ctx_from_vif(vif); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 863 | |
| 864 | if (!il->scan_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 865 | il->scan_cmd = |
| 866 | kmalloc(sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE, |
| 867 | GFP_KERNEL); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 868 | if (!il->scan_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 869 | D_SCAN("fail to allocate memory for scan\n"); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 870 | return -ENOMEM; |
| 871 | } |
| 872 | } |
| 873 | scan = il->scan_cmd; |
| 874 | memset(scan, 0, sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE); |
| 875 | |
| 876 | scan->quiet_plcp_th = IL_PLCP_QUIET_THRESH; |
| 877 | scan->quiet_time = IL_ACTIVE_QUIET_TIME; |
| 878 | |
| 879 | if (il_is_any_associated(il)) { |
| 880 | u16 interval; |
| 881 | u32 extra; |
| 882 | u32 suspend_time = 100; |
| 883 | u32 scan_suspend_time = 100; |
| 884 | |
| 885 | D_INFO("Scanning while associated...\n"); |
| 886 | interval = vif->bss_conf.beacon_int; |
| 887 | |
| 888 | scan->suspend_time = 0; |
| 889 | scan->max_out_time = cpu_to_le32(200 * 1024); |
| 890 | if (!interval) |
| 891 | interval = suspend_time; |
| 892 | |
| 893 | extra = (suspend_time / interval) << 22; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 894 | scan_suspend_time = |
| 895 | (extra | ((suspend_time % interval) * 1024)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 896 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 897 | D_SCAN("suspend_time 0x%X beacon interval %d\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 898 | scan_suspend_time, interval); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | if (il->scan_request->n_ssids) { |
| 902 | int i, p = 0; |
| 903 | D_SCAN("Kicking off active scan\n"); |
| 904 | for (i = 0; i < il->scan_request->n_ssids; i++) { |
| 905 | /* always does wildcard anyway */ |
| 906 | if (!il->scan_request->ssids[i].ssid_len) |
| 907 | continue; |
| 908 | scan->direct_scan[p].id = WLAN_EID_SSID; |
| 909 | scan->direct_scan[p].len = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 910 | il->scan_request->ssids[i].ssid_len; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 911 | memcpy(scan->direct_scan[p].ssid, |
| 912 | il->scan_request->ssids[i].ssid, |
| 913 | il->scan_request->ssids[i].ssid_len); |
| 914 | n_probes++; |
| 915 | p++; |
| 916 | } |
| 917 | is_active = true; |
| 918 | } else |
| 919 | D_SCAN("Start passive scan.\n"); |
| 920 | |
| 921 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 922 | scan->tx_cmd.sta_id = il->hw_params.bcast_id; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 923 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 924 | |
| 925 | switch (il->scan_band) { |
| 926 | case IEEE80211_BAND_2GHZ: |
| 927 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 928 | chan_mod = |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 929 | le32_to_cpu(il->active.flags & RXON_FLG_CHANNEL_MODE_MSK) >> |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 930 | RXON_FLG_CHANNEL_MODE_POS; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 931 | if (chan_mod == CHANNEL_MODE_PURE_40) { |
| 932 | rate = RATE_6M_PLCP; |
| 933 | } else { |
| 934 | rate = RATE_1M_PLCP; |
| 935 | rate_flags = RATE_MCS_CCK_MSK; |
| 936 | } |
| 937 | break; |
| 938 | case IEEE80211_BAND_5GHZ: |
| 939 | rate = RATE_6M_PLCP; |
| 940 | break; |
| 941 | default: |
| 942 | IL_WARN("Invalid scan band\n"); |
| 943 | return -EIO; |
| 944 | } |
| 945 | |
| 946 | /* |
| 947 | * If active scanning is requested but a certain channel is |
| 948 | * marked passive, we can do active scanning if we detect |
| 949 | * transmissions. |
| 950 | * |
| 951 | * There is an issue with some firmware versions that triggers |
| 952 | * a sysassert on a "good CRC threshold" of zero (== disabled), |
| 953 | * on a radar channel even though this means that we should NOT |
| 954 | * send probes. |
| 955 | * |
| 956 | * The "good CRC threshold" is the number of frames that we |
| 957 | * need to receive during our dwell time on a channel before |
| 958 | * sending out probes -- setting this to a huge value will |
| 959 | * mean we never reach it, but at the same time work around |
| 960 | * the aforementioned issue. Thus use IL_GOOD_CRC_TH_NEVER |
| 961 | * here instead of IL_GOOD_CRC_TH_DISABLED. |
| 962 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 963 | scan->good_CRC_th = |
| 964 | is_active ? IL_GOOD_CRC_TH_DEFAULT : IL_GOOD_CRC_TH_NEVER; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 965 | |
| 966 | band = il->scan_band; |
| 967 | |
| 968 | if (il->cfg->scan_rx_antennas[band]) |
| 969 | rx_ant = il->cfg->scan_rx_antennas[band]; |
| 970 | |
Stanislaw Gruszka | a0c1ef3 | 2011-12-23 08:13:44 +0100 | [diff] [blame] | 971 | il4965_toggle_tx_ant(il, &il->scan_tx_ant[band], scan_tx_antennas); |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 972 | rate_flags |= BIT(il->scan_tx_ant[band]) << RATE_MCS_ANT_POS; |
| 973 | scan->tx_cmd.rate_n_flags = cpu_to_le32(rate | rate_flags); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 974 | |
| 975 | /* In power save mode use one chain, otherwise use all chains */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 976 | if (test_bit(S_POWER_PMI, &il->status)) { |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 977 | /* rx_ant has been set to all valid chains previously */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 978 | active_chains = |
| 979 | rx_ant & ((u8) (il->chain_noise_data.active_chains)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 980 | if (!active_chains) |
| 981 | active_chains = rx_ant; |
| 982 | |
| 983 | D_SCAN("chain_noise_data.active_chains: %u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 984 | il->chain_noise_data.active_chains); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 985 | |
| 986 | rx_ant = il4965_first_antenna(active_chains); |
| 987 | } |
| 988 | |
| 989 | /* MIMO is not used here, but value is required */ |
| 990 | rx_chain |= il->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS; |
| 991 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS; |
| 992 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS; |
| 993 | rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS; |
| 994 | scan->rx_chain = cpu_to_le16(rx_chain); |
| 995 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 996 | cmd_len = |
| 997 | il_fill_probe_req(il, (struct ieee80211_mgmt *)scan->data, |
| 998 | vif->addr, il->scan_request->ie, |
| 999 | il->scan_request->ie_len, |
| 1000 | IL_MAX_SCAN_SIZE - sizeof(*scan)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1001 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
| 1002 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1003 | scan->filter_flags |= |
| 1004 | (RXON_FILTER_ACCEPT_GRP_MSK | RXON_FILTER_BCON_AWARE_MSK); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1005 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1006 | scan->channel_count = |
| 1007 | il4965_get_channels_for_scan(il, vif, band, is_active, n_probes, |
| 1008 | (void *)&scan->data[cmd_len]); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1009 | if (scan->channel_count == 0) { |
| 1010 | D_SCAN("channel count %d\n", scan->channel_count); |
| 1011 | return -EIO; |
| 1012 | } |
| 1013 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1014 | cmd.len += |
| 1015 | le16_to_cpu(scan->tx_cmd.len) + |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1016 | scan->channel_count * sizeof(struct il_scan_channel); |
| 1017 | cmd.data = scan; |
| 1018 | scan->len = cpu_to_le16(cmd.len); |
| 1019 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1020 | set_bit(S_SCAN_HW, &il->status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1021 | |
| 1022 | ret = il_send_cmd_sync(il, &cmd); |
| 1023 | if (ret) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1024 | clear_bit(S_SCAN_HW, &il->status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1025 | |
| 1026 | return ret; |
| 1027 | } |
| 1028 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1029 | int |
| 1030 | il4965_manage_ibss_station(struct il_priv *il, struct ieee80211_vif *vif, |
| 1031 | bool add) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1032 | { |
| 1033 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 1034 | |
| 1035 | if (add) |
| 1036 | return il4965_add_bssid_station(il, vif_priv->ctx, |
| 1037 | vif->bss_conf.bssid, |
| 1038 | &vif_priv->ibss_bssid_sta_id); |
| 1039 | return il_remove_station(il, vif_priv->ibss_bssid_sta_id, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1040 | vif->bss_conf.bssid); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1043 | void |
| 1044 | il4965_free_tfds_in_queue(struct il_priv *il, int sta_id, int tid, int freed) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1045 | { |
| 1046 | lockdep_assert_held(&il->sta_lock); |
| 1047 | |
| 1048 | if (il->stations[sta_id].tid[tid].tfds_in_queue >= freed) |
| 1049 | il->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 1050 | else { |
| 1051 | D_TX("free more than tfds_in_queue (%u:%d)\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1052 | il->stations[sta_id].tid[tid].tfds_in_queue, freed); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1053 | il->stations[sta_id].tid[tid].tfds_in_queue = 0; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | #define IL_TX_QUEUE_MSK 0xfffff |
| 1058 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1059 | static bool |
| 1060 | il4965_is_single_rx_stream(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1061 | { |
| 1062 | return il->current_ht_config.smps == IEEE80211_SMPS_STATIC || |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1063 | il->current_ht_config.single_chain_sufficient; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | #define IL_NUM_RX_CHAINS_MULTIPLE 3 |
| 1067 | #define IL_NUM_RX_CHAINS_SINGLE 2 |
| 1068 | #define IL_NUM_IDLE_CHAINS_DUAL 2 |
| 1069 | #define IL_NUM_IDLE_CHAINS_SINGLE 1 |
| 1070 | |
| 1071 | /* |
| 1072 | * Determine how many receiver/antenna chains to use. |
| 1073 | * |
| 1074 | * More provides better reception via diversity. Fewer saves power |
| 1075 | * at the expense of throughput, but only when not in powersave to |
| 1076 | * start with. |
| 1077 | * |
| 1078 | * MIMO (dual stream) requires at least 2, but works better with 3. |
| 1079 | * This does not determine *which* chains to use, just how many. |
| 1080 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1081 | static int |
| 1082 | il4965_get_active_rx_chain_count(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1083 | { |
| 1084 | /* # of Rx chains to use when expecting MIMO. */ |
| 1085 | if (il4965_is_single_rx_stream(il)) |
| 1086 | return IL_NUM_RX_CHAINS_SINGLE; |
| 1087 | else |
| 1088 | return IL_NUM_RX_CHAINS_MULTIPLE; |
| 1089 | } |
| 1090 | |
| 1091 | /* |
| 1092 | * When we are in power saving mode, unless device support spatial |
| 1093 | * multiplexing power save, use the active count for rx chain count. |
| 1094 | */ |
| 1095 | static int |
| 1096 | il4965_get_idle_rx_chain_count(struct il_priv *il, int active_cnt) |
| 1097 | { |
| 1098 | /* # Rx chains when idling, depending on SMPS mode */ |
| 1099 | switch (il->current_ht_config.smps) { |
| 1100 | case IEEE80211_SMPS_STATIC: |
| 1101 | case IEEE80211_SMPS_DYNAMIC: |
| 1102 | return IL_NUM_IDLE_CHAINS_SINGLE; |
| 1103 | case IEEE80211_SMPS_OFF: |
| 1104 | return active_cnt; |
| 1105 | default: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1106 | WARN(1, "invalid SMPS mode %d", il->current_ht_config.smps); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1107 | return active_cnt; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | /* up to 4 chains */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1112 | static u8 |
| 1113 | il4965_count_chain_bitmap(u32 chain_bitmap) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1114 | { |
| 1115 | u8 res; |
| 1116 | res = (chain_bitmap & BIT(0)) >> 0; |
| 1117 | res += (chain_bitmap & BIT(1)) >> 1; |
| 1118 | res += (chain_bitmap & BIT(2)) >> 2; |
| 1119 | res += (chain_bitmap & BIT(3)) >> 3; |
| 1120 | return res; |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * il4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image |
| 1125 | * |
| 1126 | * Selects how many and which Rx receivers/antennas/chains to use. |
| 1127 | * This should not be used for scan command ... it puts data in wrong place. |
| 1128 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1129 | void |
| 1130 | il4965_set_rxon_chain(struct il_priv *il, struct il_rxon_context *ctx) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1131 | { |
| 1132 | bool is_single = il4965_is_single_rx_stream(il); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1133 | bool is_cam = !test_bit(S_POWER_PMI, &il->status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1134 | u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt; |
| 1135 | u32 active_chains; |
| 1136 | u16 rx_chain; |
| 1137 | |
| 1138 | /* Tell uCode which antennas are actually connected. |
| 1139 | * Before first association, we assume all antennas are connected. |
| 1140 | * Just after first association, il4965_chain_noise_calibration() |
| 1141 | * checks which antennas actually *are* connected. */ |
| 1142 | if (il->chain_noise_data.active_chains) |
| 1143 | active_chains = il->chain_noise_data.active_chains; |
| 1144 | else |
| 1145 | active_chains = il->hw_params.valid_rx_ant; |
| 1146 | |
| 1147 | rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS; |
| 1148 | |
| 1149 | /* How many receivers should we use? */ |
| 1150 | active_rx_cnt = il4965_get_active_rx_chain_count(il); |
| 1151 | idle_rx_cnt = il4965_get_idle_rx_chain_count(il, active_rx_cnt); |
| 1152 | |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1153 | /* correct rx chain count according hw settings |
| 1154 | * and chain noise calibration |
| 1155 | */ |
| 1156 | valid_rx_cnt = il4965_count_chain_bitmap(active_chains); |
| 1157 | if (valid_rx_cnt < active_rx_cnt) |
| 1158 | active_rx_cnt = valid_rx_cnt; |
| 1159 | |
| 1160 | if (valid_rx_cnt < idle_rx_cnt) |
| 1161 | idle_rx_cnt = valid_rx_cnt; |
| 1162 | |
| 1163 | rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1164 | rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1165 | |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 1166 | il->staging.rx_chain = cpu_to_le16(rx_chain); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1167 | |
| 1168 | if (!is_single && active_rx_cnt >= IL_NUM_RX_CHAINS_SINGLE && is_cam) |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 1169 | il->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1170 | else |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 1171 | il->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1172 | |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 1173 | D_ASSOC("rx_chain=0x%X active=%d idle=%d\n", il->staging.rx_chain, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1174 | active_rx_cnt, idle_rx_cnt); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1175 | |
| 1176 | WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 || |
| 1177 | active_rx_cnt < idle_rx_cnt); |
| 1178 | } |
| 1179 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1180 | static const char * |
| 1181 | il4965_get_fh_string(int cmd) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1182 | { |
| 1183 | switch (cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1184 | IL_CMD(FH49_RSCSR_CHNL0_STTS_WPTR_REG); |
| 1185 | IL_CMD(FH49_RSCSR_CHNL0_RBDCB_BASE_REG); |
| 1186 | IL_CMD(FH49_RSCSR_CHNL0_WPTR); |
| 1187 | IL_CMD(FH49_MEM_RCSR_CHNL0_CONFIG_REG); |
| 1188 | IL_CMD(FH49_MEM_RSSR_SHARED_CTRL_REG); |
| 1189 | IL_CMD(FH49_MEM_RSSR_RX_STATUS_REG); |
| 1190 | IL_CMD(FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV); |
| 1191 | IL_CMD(FH49_TSSR_TX_STATUS_REG); |
| 1192 | IL_CMD(FH49_TSSR_TX_ERROR_REG); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1193 | default: |
| 1194 | return "UNKNOWN"; |
| 1195 | } |
| 1196 | } |
| 1197 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1198 | int |
| 1199 | il4965_dump_fh(struct il_priv *il, char **buf, bool display) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1200 | { |
| 1201 | int i; |
| 1202 | #ifdef CONFIG_IWLEGACY_DEBUG |
| 1203 | int pos = 0; |
| 1204 | size_t bufsz = 0; |
| 1205 | #endif |
| 1206 | static const u32 fh_tbl[] = { |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 1207 | FH49_RSCSR_CHNL0_STTS_WPTR_REG, |
| 1208 | FH49_RSCSR_CHNL0_RBDCB_BASE_REG, |
| 1209 | FH49_RSCSR_CHNL0_WPTR, |
| 1210 | FH49_MEM_RCSR_CHNL0_CONFIG_REG, |
| 1211 | FH49_MEM_RSSR_SHARED_CTRL_REG, |
| 1212 | FH49_MEM_RSSR_RX_STATUS_REG, |
| 1213 | FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV, |
| 1214 | FH49_TSSR_TX_STATUS_REG, |
| 1215 | FH49_TSSR_TX_ERROR_REG |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1216 | }; |
| 1217 | #ifdef CONFIG_IWLEGACY_DEBUG |
| 1218 | if (display) { |
| 1219 | bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40; |
| 1220 | *buf = kmalloc(bufsz, GFP_KERNEL); |
| 1221 | if (!*buf) |
| 1222 | return -ENOMEM; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1223 | pos += |
| 1224 | scnprintf(*buf + pos, bufsz - pos, "FH register values:\n"); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1225 | for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1226 | pos += |
| 1227 | scnprintf(*buf + pos, bufsz - pos, |
| 1228 | " %34s: 0X%08x\n", |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1229 | il4965_get_fh_string(fh_tbl[i]), |
| 1230 | il_rd(il, fh_tbl[i])); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1231 | } |
| 1232 | return pos; |
| 1233 | } |
| 1234 | #endif |
| 1235 | IL_ERR("FH register values:\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1236 | for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) { |
| 1237 | IL_ERR(" %34s: 0X%08x\n", il4965_get_fh_string(fh_tbl[i]), |
| 1238 | il_rd(il, fh_tbl[i])); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1239 | } |
| 1240 | return 0; |
| 1241 | } |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1242 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1243 | void |
| 1244 | il4965_hdl_missed_beacon(struct il_priv *il, struct il_rx_buf *rxb) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1245 | { |
| 1246 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 1247 | struct il_missed_beacon_notif *missed_beacon; |
| 1248 | |
| 1249 | missed_beacon = &pkt->u.missed_beacon; |
| 1250 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > |
| 1251 | il->missed_beacon_threshold) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1252 | D_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n", |
| 1253 | le32_to_cpu(missed_beacon->consecutive_missed_beacons), |
| 1254 | le32_to_cpu(missed_beacon->total_missed_becons), |
| 1255 | le32_to_cpu(missed_beacon->num_recvd_beacons), |
| 1256 | le32_to_cpu(missed_beacon->num_expected_beacons)); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1257 | if (!test_bit(S_SCANNING, &il->status)) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1258 | il4965_init_sensitivity(il); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | /* Calculate noise level, based on measurements during network silence just |
| 1263 | * before arriving beacon. This measurement can be done only if we know |
| 1264 | * exactly when to expect beacons, therefore only when we're associated. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1265 | static void |
| 1266 | il4965_rx_calc_noise(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1267 | { |
| 1268 | struct stats_rx_non_phy *rx_info; |
| 1269 | int num_active_rx = 0; |
| 1270 | int total_silence = 0; |
| 1271 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; |
| 1272 | int last_rx_noise; |
| 1273 | |
| 1274 | rx_info = &(il->_4965.stats.rx.general); |
| 1275 | bcn_silence_a = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1276 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1277 | bcn_silence_b = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1278 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1279 | bcn_silence_c = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1280 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1281 | |
| 1282 | if (bcn_silence_a) { |
| 1283 | total_silence += bcn_silence_a; |
| 1284 | num_active_rx++; |
| 1285 | } |
| 1286 | if (bcn_silence_b) { |
| 1287 | total_silence += bcn_silence_b; |
| 1288 | num_active_rx++; |
| 1289 | } |
| 1290 | if (bcn_silence_c) { |
| 1291 | total_silence += bcn_silence_c; |
| 1292 | num_active_rx++; |
| 1293 | } |
| 1294 | |
| 1295 | /* Average among active antennas */ |
| 1296 | if (num_active_rx) |
| 1297 | last_rx_noise = (total_silence / num_active_rx) - 107; |
| 1298 | else |
| 1299 | last_rx_noise = IL_NOISE_MEAS_NOT_AVAILABLE; |
| 1300 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1301 | D_CALIB("inband silence a %u, b %u, c %u, dBm %d\n", bcn_silence_a, |
| 1302 | bcn_silence_b, bcn_silence_c, last_rx_noise); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
| 1306 | /* |
| 1307 | * based on the assumption of all stats counter are in DWORD |
| 1308 | * FIXME: This function is for debugging, do not deal with |
| 1309 | * the case of counters roll-over. |
| 1310 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1311 | static void |
| 1312 | il4965_accumulative_stats(struct il_priv *il, __le32 * stats) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1313 | { |
| 1314 | int i, size; |
| 1315 | __le32 *prev_stats; |
| 1316 | u32 *accum_stats; |
| 1317 | u32 *delta, *max_delta; |
| 1318 | struct stats_general_common *general, *accum_general; |
| 1319 | struct stats_tx *tx, *accum_tx; |
| 1320 | |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1321 | prev_stats = (__le32 *) &il->_4965.stats; |
| 1322 | accum_stats = (u32 *) &il->_4965.accum_stats; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1323 | size = sizeof(struct il_notif_stats); |
| 1324 | general = &il->_4965.stats.general.common; |
| 1325 | accum_general = &il->_4965.accum_stats.general.common; |
| 1326 | tx = &il->_4965.stats.tx; |
| 1327 | accum_tx = &il->_4965.accum_stats.tx; |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1328 | delta = (u32 *) &il->_4965.delta_stats; |
| 1329 | max_delta = (u32 *) &il->_4965.max_delta; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1330 | |
| 1331 | for (i = sizeof(__le32); i < size; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1332 | i += |
| 1333 | sizeof(__le32), stats++, prev_stats++, delta++, max_delta++, |
| 1334 | accum_stats++) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1335 | if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1336 | *delta = |
| 1337 | (le32_to_cpu(*stats) - le32_to_cpu(*prev_stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1338 | *accum_stats += *delta; |
| 1339 | if (*delta > *max_delta) |
| 1340 | *max_delta = *delta; |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | /* reset accumulative stats for "no-counter" type stats */ |
| 1345 | accum_general->temperature = general->temperature; |
| 1346 | accum_general->ttl_timestamp = general->ttl_timestamp; |
| 1347 | } |
| 1348 | #endif |
| 1349 | |
| 1350 | #define REG_RECALIB_PERIOD (60) |
| 1351 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1352 | void |
| 1353 | il4965_hdl_stats(struct il_priv *il, struct il_rx_buf *rxb) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1354 | { |
| 1355 | int change; |
| 1356 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 1357 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1358 | D_RX("Statistics notification received (%d vs %d).\n", |
| 1359 | (int)sizeof(struct il_notif_stats), |
| 1360 | le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1361 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1362 | change = |
| 1363 | ((il->_4965.stats.general.common.temperature != |
| 1364 | pkt->u.stats.general.common.temperature) || |
| 1365 | ((il->_4965.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK) != |
| 1366 | (pkt->u.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK))); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1367 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1368 | il4965_accumulative_stats(il, (__le32 *) &pkt->u.stats); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1369 | #endif |
| 1370 | |
| 1371 | /* TODO: reading some of stats is unneeded */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1372 | memcpy(&il->_4965.stats, &pkt->u.stats, sizeof(il->_4965.stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1373 | |
Stanislaw Gruszka | db7746f | 2011-11-15 13:11:50 +0100 | [diff] [blame] | 1374 | set_bit(S_STATS, &il->status); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1375 | |
| 1376 | /* Reschedule the stats timer to occur in |
| 1377 | * REG_RECALIB_PERIOD seconds to ensure we get a |
| 1378 | * thermal update even if the uCode doesn't give |
| 1379 | * us one */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1380 | mod_timer(&il->stats_periodic, |
| 1381 | jiffies + msecs_to_jiffies(REG_RECALIB_PERIOD * 1000)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1382 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1383 | if (unlikely(!test_bit(S_SCANNING, &il->status)) && |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1384 | (pkt->hdr.cmd == N_STATS)) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1385 | il4965_rx_calc_noise(il); |
| 1386 | queue_work(il->workqueue, &il->run_time_calib_work); |
| 1387 | } |
| 1388 | if (il->cfg->ops->lib->temp_ops.temperature && change) |
| 1389 | il->cfg->ops->lib->temp_ops.temperature(il); |
| 1390 | } |
| 1391 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1392 | void |
| 1393 | il4965_hdl_c_stats(struct il_priv *il, struct il_rx_buf *rxb) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1394 | { |
| 1395 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 1396 | |
Stanislaw Gruszka | db7746f | 2011-11-15 13:11:50 +0100 | [diff] [blame] | 1397 | if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATS_CLEAR_MSK) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1398 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
| 1399 | memset(&il->_4965.accum_stats, 0, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1400 | sizeof(struct il_notif_stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1401 | memset(&il->_4965.delta_stats, 0, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1402 | sizeof(struct il_notif_stats)); |
| 1403 | memset(&il->_4965.max_delta, 0, sizeof(struct il_notif_stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1404 | #endif |
| 1405 | D_RX("Statistics have been cleared\n"); |
| 1406 | } |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 1407 | il4965_hdl_stats(il, rxb); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
Stanislaw Gruszka | 8f29b45 | 2011-11-15 12:57:25 +0100 | [diff] [blame] | 1410 | |
| 1411 | /* |
| 1412 | * mac80211 queues, ACs, hardware queues, FIFOs. |
| 1413 | * |
| 1414 | * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues |
| 1415 | * |
| 1416 | * Mac80211 uses the following numbers, which we get as from it |
| 1417 | * by way of skb_get_queue_mapping(skb): |
| 1418 | * |
| 1419 | * VO 0 |
| 1420 | * VI 1 |
| 1421 | * BE 2 |
| 1422 | * BK 3 |
| 1423 | * |
| 1424 | * |
| 1425 | * Regular (not A-MPDU) frames are put into hardware queues corresponding |
| 1426 | * to the FIFOs, see comments in iwl-prph.h. Aggregated frames get their |
| 1427 | * own queue per aggregation session (RA/TID combination), such queues are |
| 1428 | * set up to map into FIFOs too, for which we need an AC->FIFO mapping. In |
| 1429 | * order to map frames to the right queue, we also need an AC->hw queue |
| 1430 | * mapping. This is implemented here. |
| 1431 | * |
| 1432 | * Due to the way hw queues are set up (by the hw specific modules like |
Stanislaw Gruszka | af038f4 | 2011-08-30 13:58:27 +0200 | [diff] [blame] | 1433 | * 4965.c), the AC->hw queue mapping is the identity |
Stanislaw Gruszka | 8f29b45 | 2011-11-15 12:57:25 +0100 | [diff] [blame] | 1434 | * mapping. |
| 1435 | */ |
| 1436 | |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1437 | static const u8 tid_to_ac[] = { |
| 1438 | IEEE80211_AC_BE, |
| 1439 | IEEE80211_AC_BK, |
| 1440 | IEEE80211_AC_BK, |
| 1441 | IEEE80211_AC_BE, |
| 1442 | IEEE80211_AC_VI, |
| 1443 | IEEE80211_AC_VI, |
| 1444 | IEEE80211_AC_VO, |
| 1445 | IEEE80211_AC_VO |
| 1446 | }; |
| 1447 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1448 | static inline int |
| 1449 | il4965_get_ac_from_tid(u16 tid) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1450 | { |
| 1451 | if (likely(tid < ARRAY_SIZE(tid_to_ac))) |
| 1452 | return tid_to_ac[tid]; |
| 1453 | |
| 1454 | /* no support for TIDs 8-15 yet */ |
| 1455 | return -EINVAL; |
| 1456 | } |
| 1457 | |
| 1458 | static inline int |
| 1459 | il4965_get_fifo_from_tid(struct il_rxon_context *ctx, u16 tid) |
| 1460 | { |
Stanislaw Gruszka | b75b3a7 | 2012-02-03 17:31:53 +0100 | [diff] [blame] | 1461 | const u8 ac_to_fifo[] = { |
| 1462 | IL_TX_FIFO_VO, |
| 1463 | IL_TX_FIFO_VI, |
| 1464 | IL_TX_FIFO_BE, |
| 1465 | IL_TX_FIFO_BK, |
| 1466 | }; |
| 1467 | |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1468 | if (likely(tid < ARRAY_SIZE(tid_to_ac))) |
Stanislaw Gruszka | b75b3a7 | 2012-02-03 17:31:53 +0100 | [diff] [blame] | 1469 | return ac_to_fifo[tid_to_ac[tid]]; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1470 | |
| 1471 | /* no support for TIDs 8-15 yet */ |
| 1472 | return -EINVAL; |
| 1473 | } |
| 1474 | |
| 1475 | /* |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1476 | * handle build C_TX command notification. |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1477 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1478 | static void |
| 1479 | il4965_tx_cmd_build_basic(struct il_priv *il, struct sk_buff *skb, |
| 1480 | struct il_tx_cmd *tx_cmd, |
| 1481 | struct ieee80211_tx_info *info, |
| 1482 | struct ieee80211_hdr *hdr, u8 std_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1483 | { |
| 1484 | __le16 fc = hdr->frame_control; |
| 1485 | __le32 tx_flags = tx_cmd->tx_flags; |
| 1486 | |
| 1487 | tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 1488 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
| 1489 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 1490 | if (ieee80211_is_mgmt(fc)) |
| 1491 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1492 | if (ieee80211_is_probe_resp(fc) && |
| 1493 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 1494 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 1495 | } else { |
| 1496 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 1497 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1498 | } |
| 1499 | |
| 1500 | if (ieee80211_is_back_req(fc)) |
| 1501 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 1502 | |
| 1503 | tx_cmd->sta_id = std_id; |
| 1504 | if (ieee80211_has_morefrags(fc)) |
| 1505 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 1506 | |
| 1507 | if (ieee80211_is_data_qos(fc)) { |
| 1508 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 1509 | tx_cmd->tid_tspec = qc[0] & 0xf; |
| 1510 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 1511 | } else { |
| 1512 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1513 | } |
| 1514 | |
| 1515 | il_tx_cmd_protection(il, info, fc, &tx_flags); |
| 1516 | |
| 1517 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 1518 | if (ieee80211_is_mgmt(fc)) { |
| 1519 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
| 1520 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3); |
| 1521 | else |
| 1522 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2); |
| 1523 | } else { |
| 1524 | tx_cmd->timeout.pm_frame_timeout = 0; |
| 1525 | } |
| 1526 | |
| 1527 | tx_cmd->driver_txop = 0; |
| 1528 | tx_cmd->tx_flags = tx_flags; |
| 1529 | tx_cmd->next_frame_len = 0; |
| 1530 | } |
| 1531 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1532 | static void |
| 1533 | il4965_tx_cmd_build_rate(struct il_priv *il, struct il_tx_cmd *tx_cmd, |
| 1534 | struct ieee80211_tx_info *info, __le16 fc) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1535 | { |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 1536 | const u8 rts_retry_limit = 60; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1537 | u32 rate_flags; |
| 1538 | int rate_idx; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1539 | u8 data_retry_limit; |
| 1540 | u8 rate_plcp; |
| 1541 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1542 | /* Set retry limit on DATA packets and Probe Responses */ |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1543 | if (ieee80211_is_probe_resp(fc)) |
| 1544 | data_retry_limit = 3; |
| 1545 | else |
| 1546 | data_retry_limit = IL4965_DEFAULT_TX_RETRY; |
| 1547 | tx_cmd->data_retry_limit = data_retry_limit; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1548 | /* Set retry limit on RTS packets */ |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 1549 | tx_cmd->rts_retry_limit = min(data_retry_limit, rts_retry_limit); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1550 | |
| 1551 | /* DATA packets will use the uCode station table for rate/antenna |
| 1552 | * selection */ |
| 1553 | if (ieee80211_is_data(fc)) { |
| 1554 | tx_cmd->initial_rate_idx = 0; |
| 1555 | tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; |
| 1556 | return; |
| 1557 | } |
| 1558 | |
| 1559 | /** |
| 1560 | * If the current TX rate stored in mac80211 has the MCS bit set, it's |
| 1561 | * not really a TX rate. Thus, we use the lowest supported rate for |
| 1562 | * this band. Also use the lowest supported rate if the stored rate |
| 1563 | * idx is invalid. |
| 1564 | */ |
| 1565 | rate_idx = info->control.rates[0].idx; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1566 | if ((info->control.rates[0].flags & IEEE80211_TX_RC_MCS) || rate_idx < 0 |
| 1567 | || rate_idx > RATE_COUNT_LEGACY) |
| 1568 | rate_idx = |
| 1569 | rate_lowest_index(&il->bands[info->band], |
| 1570 | info->control.sta); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1571 | /* For 5 GHZ band, remap mac80211 rate indices into driver indices */ |
| 1572 | if (info->band == IEEE80211_BAND_5GHZ) |
| 1573 | rate_idx += IL_FIRST_OFDM_RATE; |
| 1574 | /* Get PLCP rate for tx_cmd->rate_n_flags */ |
| 1575 | rate_plcp = il_rates[rate_idx].plcp; |
| 1576 | /* Zero out flags for this packet */ |
| 1577 | rate_flags = 0; |
| 1578 | |
| 1579 | /* Set CCK flag as needed */ |
| 1580 | if (rate_idx >= IL_FIRST_CCK_RATE && rate_idx <= IL_LAST_CCK_RATE) |
| 1581 | rate_flags |= RATE_MCS_CCK_MSK; |
| 1582 | |
| 1583 | /* Set up antennas */ |
Stanislaw Gruszka | a0c1ef3 | 2011-12-23 08:13:44 +0100 | [diff] [blame] | 1584 | il4965_toggle_tx_ant(il, &il->mgmt_tx_ant, il->hw_params.valid_tx_ant); |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 1585 | rate_flags |= BIT(il->mgmt_tx_ant) << RATE_MCS_ANT_POS; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1586 | |
| 1587 | /* Set the rate in the TX cmd */ |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 1588 | tx_cmd->rate_n_flags = cpu_to_le32(rate_plcp | rate_flags); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1589 | } |
| 1590 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1591 | static void |
| 1592 | il4965_tx_cmd_build_hwcrypto(struct il_priv *il, struct ieee80211_tx_info *info, |
| 1593 | struct il_tx_cmd *tx_cmd, struct sk_buff *skb_frag, |
| 1594 | int sta_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1595 | { |
| 1596 | struct ieee80211_key_conf *keyconf = info->control.hw_key; |
| 1597 | |
| 1598 | switch (keyconf->cipher) { |
| 1599 | case WLAN_CIPHER_SUITE_CCMP: |
| 1600 | tx_cmd->sec_ctl = TX_CMD_SEC_CCM; |
| 1601 | memcpy(tx_cmd->key, keyconf->key, keyconf->keylen); |
| 1602 | if (info->flags & IEEE80211_TX_CTL_AMPDU) |
| 1603 | tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; |
| 1604 | D_TX("tx_cmd with AES hwcrypto\n"); |
| 1605 | break; |
| 1606 | |
| 1607 | case WLAN_CIPHER_SUITE_TKIP: |
| 1608 | tx_cmd->sec_ctl = TX_CMD_SEC_TKIP; |
| 1609 | ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key); |
| 1610 | D_TX("tx_cmd with tkip hwcrypto\n"); |
| 1611 | break; |
| 1612 | |
| 1613 | case WLAN_CIPHER_SUITE_WEP104: |
| 1614 | tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128; |
| 1615 | /* fall through */ |
| 1616 | case WLAN_CIPHER_SUITE_WEP40: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1617 | tx_cmd->sec_ctl |= |
| 1618 | (TX_CMD_SEC_WEP | (keyconf->keyidx & TX_CMD_SEC_MSK) << |
| 1619 | TX_CMD_SEC_SHIFT); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1620 | |
| 1621 | memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen); |
| 1622 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1623 | D_TX("Configuring packet for WEP encryption " "with key %d\n", |
| 1624 | keyconf->keyidx); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1625 | break; |
| 1626 | |
| 1627 | default: |
| 1628 | IL_ERR("Unknown encode cipher %x\n", keyconf->cipher); |
| 1629 | break; |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | /* |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1634 | * start C_TX command process |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1635 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1636 | int |
| 1637 | il4965_tx_skb(struct il_priv *il, struct sk_buff *skb) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1638 | { |
| 1639 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1640 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1641 | struct ieee80211_sta *sta = info->control.sta; |
| 1642 | struct il_station_priv *sta_priv = NULL; |
| 1643 | struct il_tx_queue *txq; |
| 1644 | struct il_queue *q; |
| 1645 | struct il_device_cmd *out_cmd; |
| 1646 | struct il_cmd_meta *out_meta; |
| 1647 | struct il_tx_cmd *tx_cmd; |
| 1648 | struct il_rxon_context *ctx = &il->ctx; |
| 1649 | int txq_id; |
| 1650 | dma_addr_t phys_addr; |
| 1651 | dma_addr_t txcmd_phys; |
| 1652 | dma_addr_t scratch_phys; |
| 1653 | u16 len, firstlen, secondlen; |
| 1654 | u16 seq_number = 0; |
| 1655 | __le16 fc; |
| 1656 | u8 hdr_len; |
| 1657 | u8 sta_id; |
| 1658 | u8 wait_write_ptr = 0; |
| 1659 | u8 tid = 0; |
| 1660 | u8 *qc = NULL; |
| 1661 | unsigned long flags; |
| 1662 | bool is_agg = false; |
| 1663 | |
| 1664 | if (info->control.vif) |
| 1665 | ctx = il_rxon_ctx_from_vif(info->control.vif); |
| 1666 | |
| 1667 | spin_lock_irqsave(&il->lock, flags); |
| 1668 | if (il_is_rfkill(il)) { |
| 1669 | D_DROP("Dropping - RF KILL\n"); |
| 1670 | goto drop_unlock; |
| 1671 | } |
| 1672 | |
| 1673 | fc = hdr->frame_control; |
| 1674 | |
| 1675 | #ifdef CONFIG_IWLEGACY_DEBUG |
| 1676 | if (ieee80211_is_auth(fc)) |
| 1677 | D_TX("Sending AUTH frame\n"); |
| 1678 | else if (ieee80211_is_assoc_req(fc)) |
| 1679 | D_TX("Sending ASSOC frame\n"); |
| 1680 | else if (ieee80211_is_reassoc_req(fc)) |
| 1681 | D_TX("Sending REASSOC frame\n"); |
| 1682 | #endif |
| 1683 | |
| 1684 | hdr_len = ieee80211_hdrlen(fc); |
| 1685 | |
| 1686 | /* For management frames use broadcast id to do not break aggregation */ |
| 1687 | if (!ieee80211_is_data(fc)) |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 1688 | sta_id = il->hw_params.bcast_id; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1689 | else { |
| 1690 | /* Find idx into station table for destination station */ |
| 1691 | sta_id = il_sta_id_or_broadcast(il, ctx, info->control.sta); |
| 1692 | |
| 1693 | if (sta_id == IL_INVALID_STATION) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1694 | D_DROP("Dropping - INVALID STATION: %pM\n", hdr->addr1); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1695 | goto drop_unlock; |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | D_TX("station Id %d\n", sta_id); |
| 1700 | |
| 1701 | if (sta) |
| 1702 | sta_priv = (void *)sta->drv_priv; |
| 1703 | |
| 1704 | if (sta_priv && sta_priv->asleep && |
| 1705 | (info->flags & IEEE80211_TX_CTL_POLL_RESPONSE)) { |
| 1706 | /* |
| 1707 | * This sends an asynchronous command to the device, |
| 1708 | * but we can rely on it being processed before the |
| 1709 | * next frame is processed -- and the next frame to |
| 1710 | * this station is the one that will consume this |
| 1711 | * counter. |
| 1712 | * For now set the counter to just 1 since we do not |
| 1713 | * support uAPSD yet. |
| 1714 | */ |
| 1715 | il4965_sta_modify_sleep_tx_count(il, sta_id, 1); |
| 1716 | } |
| 1717 | |
Stanislaw Gruszka | d1e14e9 | 2012-02-03 17:31:47 +0100 | [diff] [blame] | 1718 | /* FIXME: remove me ? */ |
| 1719 | WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM); |
| 1720 | |
Stanislaw Gruszka | eb123af | 2012-02-03 17:31:54 +0100 | [diff] [blame^] | 1721 | /* Access category (AC) is also the queue number */ |
| 1722 | txq_id = skb_get_queue_mapping(skb); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1723 | |
| 1724 | /* irqs already disabled/saved above when locking il->lock */ |
| 1725 | spin_lock(&il->sta_lock); |
| 1726 | |
| 1727 | if (ieee80211_is_data_qos(fc)) { |
| 1728 | qc = ieee80211_get_qos_ctl(hdr); |
| 1729 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 1730 | if (WARN_ON_ONCE(tid >= MAX_TID_COUNT)) { |
| 1731 | spin_unlock(&il->sta_lock); |
| 1732 | goto drop_unlock; |
| 1733 | } |
| 1734 | seq_number = il->stations[sta_id].tid[tid].seq_number; |
| 1735 | seq_number &= IEEE80211_SCTL_SEQ; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1736 | hdr->seq_ctrl = |
| 1737 | hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1738 | hdr->seq_ctrl |= cpu_to_le16(seq_number); |
| 1739 | seq_number += 0x10; |
| 1740 | /* aggregation is on for this <sta,tid> */ |
| 1741 | if (info->flags & IEEE80211_TX_CTL_AMPDU && |
| 1742 | il->stations[sta_id].tid[tid].agg.state == IL_AGG_ON) { |
| 1743 | txq_id = il->stations[sta_id].tid[tid].agg.txq_id; |
| 1744 | is_agg = true; |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | txq = &il->txq[txq_id]; |
| 1749 | q = &txq->q; |
| 1750 | |
| 1751 | if (unlikely(il_queue_space(q) < q->high_mark)) { |
| 1752 | spin_unlock(&il->sta_lock); |
| 1753 | goto drop_unlock; |
| 1754 | } |
| 1755 | |
| 1756 | if (ieee80211_is_data_qos(fc)) { |
| 1757 | il->stations[sta_id].tid[tid].tfds_in_queue++; |
| 1758 | if (!ieee80211_has_morefrags(fc)) |
| 1759 | il->stations[sta_id].tid[tid].seq_number = seq_number; |
| 1760 | } |
| 1761 | |
| 1762 | spin_unlock(&il->sta_lock); |
| 1763 | |
| 1764 | /* Set up driver data for this TFD */ |
| 1765 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct il_tx_info)); |
| 1766 | txq->txb[q->write_ptr].skb = skb; |
| 1767 | txq->txb[q->write_ptr].ctx = ctx; |
| 1768 | |
| 1769 | /* Set up first empty entry in queue's array of Tx/cmd buffers */ |
| 1770 | out_cmd = txq->cmd[q->write_ptr]; |
| 1771 | out_meta = &txq->meta[q->write_ptr]; |
| 1772 | tx_cmd = &out_cmd->cmd.tx; |
| 1773 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 1774 | memset(tx_cmd, 0, sizeof(struct il_tx_cmd)); |
| 1775 | |
| 1776 | /* |
| 1777 | * Set up the Tx-command (not MAC!) header. |
| 1778 | * Store the chosen Tx queue and TFD idx within the sequence field; |
| 1779 | * after Tx, uCode's Tx response will return this value so driver can |
| 1780 | * locate the frame within the tx queue and do post-tx processing. |
| 1781 | */ |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1782 | out_cmd->hdr.cmd = C_TX; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1783 | out_cmd->hdr.sequence = |
| 1784 | cpu_to_le16((u16) |
| 1785 | (QUEUE_TO_SEQ(txq_id) | IDX_TO_SEQ(q->write_ptr))); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1786 | |
| 1787 | /* Copy MAC header from skb into command buffer */ |
| 1788 | memcpy(tx_cmd->hdr, hdr, hdr_len); |
| 1789 | |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1790 | /* Total # bytes to be transmitted */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1791 | len = (u16) skb->len; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1792 | tx_cmd->len = cpu_to_le16(len); |
| 1793 | |
| 1794 | if (info->control.hw_key) |
| 1795 | il4965_tx_cmd_build_hwcrypto(il, info, tx_cmd, skb, sta_id); |
| 1796 | |
| 1797 | /* TODO need this for burst mode later on */ |
| 1798 | il4965_tx_cmd_build_basic(il, skb, tx_cmd, info, hdr, sta_id); |
| 1799 | il_dbg_log_tx_data_frame(il, len, hdr); |
| 1800 | |
| 1801 | il4965_tx_cmd_build_rate(il, tx_cmd, info, fc); |
| 1802 | |
| 1803 | il_update_stats(il, true, fc, len); |
| 1804 | /* |
| 1805 | * Use the first empty entry in this queue's command buffer array |
| 1806 | * to contain the Tx command and MAC header concatenated together |
| 1807 | * (payload data will be in another buffer). |
| 1808 | * Size of this varies, due to varying MAC header length. |
| 1809 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 1810 | * of the MAC header (device reads on dword boundaries). |
| 1811 | * We'll tell device about this padding later. |
| 1812 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1813 | len = sizeof(struct il_tx_cmd) + sizeof(struct il_cmd_header) + hdr_len; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1814 | firstlen = (len + 3) & ~3; |
| 1815 | |
| 1816 | /* Tell NIC about any 2-byte padding after MAC header */ |
| 1817 | if (firstlen != len) |
| 1818 | tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 1819 | |
| 1820 | /* Physical address of this Tx command's header (not MAC header!), |
| 1821 | * within command buffer array. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1822 | txcmd_phys = |
| 1823 | pci_map_single(il->pci_dev, &out_cmd->hdr, firstlen, |
| 1824 | PCI_DMA_BIDIRECTIONAL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1825 | dma_unmap_addr_set(out_meta, mapping, txcmd_phys); |
| 1826 | dma_unmap_len_set(out_meta, len, firstlen); |
| 1827 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 1828 | * first entry */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1829 | il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq, txcmd_phys, firstlen, |
| 1830 | 1, 0); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1831 | |
| 1832 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
| 1833 | txq->need_update = 1; |
| 1834 | } else { |
| 1835 | wait_write_ptr = 1; |
| 1836 | txq->need_update = 0; |
| 1837 | } |
| 1838 | |
| 1839 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 1840 | * if any (802.11 null frames have no payload). */ |
| 1841 | secondlen = skb->len - hdr_len; |
| 1842 | if (secondlen > 0) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1843 | phys_addr = |
| 1844 | pci_map_single(il->pci_dev, skb->data + hdr_len, secondlen, |
| 1845 | PCI_DMA_TODEVICE); |
| 1846 | il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq, phys_addr, |
| 1847 | secondlen, 0, 0); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1850 | scratch_phys = |
| 1851 | txcmd_phys + sizeof(struct il_cmd_header) + |
| 1852 | offsetof(struct il_tx_cmd, scratch); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1853 | |
| 1854 | /* take back ownership of DMA buffer to enable update */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1855 | pci_dma_sync_single_for_cpu(il->pci_dev, txcmd_phys, firstlen, |
| 1856 | PCI_DMA_BIDIRECTIONAL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1857 | tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 1858 | tx_cmd->dram_msb_ptr = il_get_dma_hi_addr(scratch_phys); |
| 1859 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1860 | D_TX("sequence nr = 0X%x\n", le16_to_cpu(out_cmd->hdr.sequence)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1861 | D_TX("tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags)); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1862 | il_print_hex_dump(il, IL_DL_TX, (u8 *) tx_cmd, sizeof(*tx_cmd)); |
| 1863 | il_print_hex_dump(il, IL_DL_TX, (u8 *) tx_cmd->hdr, hdr_len); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1864 | |
| 1865 | /* Set up entry for this TFD in Tx byte-count array */ |
| 1866 | if (info->flags & IEEE80211_TX_CTL_AMPDU) |
| 1867 | il->cfg->ops->lib->txq_update_byte_cnt_tbl(il, txq, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1868 | le16_to_cpu(tx_cmd-> |
| 1869 | len)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1870 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1871 | pci_dma_sync_single_for_device(il->pci_dev, txcmd_phys, firstlen, |
| 1872 | PCI_DMA_BIDIRECTIONAL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1873 | |
| 1874 | /* Tell device the write idx *just past* this latest filled TFD */ |
| 1875 | q->write_ptr = il_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 1876 | il_txq_update_write_ptr(il, txq); |
| 1877 | spin_unlock_irqrestore(&il->lock, flags); |
| 1878 | |
| 1879 | /* |
| 1880 | * At this point the frame is "transmitted" successfully |
| 1881 | * and we will get a TX status notification eventually, |
| 1882 | * regardless of the value of ret. "ret" only indicates |
| 1883 | * whether or not we should update the write pointer. |
| 1884 | */ |
| 1885 | |
| 1886 | /* |
| 1887 | * Avoid atomic ops if it isn't an associated client. |
| 1888 | * Also, if this is a packet for aggregation, don't |
| 1889 | * increase the counter because the ucode will stop |
| 1890 | * aggregation queues when their respective station |
| 1891 | * goes to sleep. |
| 1892 | */ |
| 1893 | if (sta_priv && sta_priv->client && !is_agg) |
| 1894 | atomic_inc(&sta_priv->pending_frames); |
| 1895 | |
| 1896 | if (il_queue_space(q) < q->high_mark && il->mac80211_registered) { |
| 1897 | if (wait_write_ptr) { |
| 1898 | spin_lock_irqsave(&il->lock, flags); |
| 1899 | txq->need_update = 1; |
| 1900 | il_txq_update_write_ptr(il, txq); |
| 1901 | spin_unlock_irqrestore(&il->lock, flags); |
| 1902 | } else { |
| 1903 | il_stop_queue(il, txq); |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | return 0; |
| 1908 | |
| 1909 | drop_unlock: |
| 1910 | spin_unlock_irqrestore(&il->lock, flags); |
| 1911 | return -1; |
| 1912 | } |
| 1913 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1914 | static inline int |
| 1915 | il4965_alloc_dma_ptr(struct il_priv *il, struct il_dma_ptr *ptr, size_t size) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1916 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1917 | ptr->addr = |
| 1918 | dma_alloc_coherent(&il->pci_dev->dev, size, &ptr->dma, GFP_KERNEL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1919 | if (!ptr->addr) |
| 1920 | return -ENOMEM; |
| 1921 | ptr->size = size; |
| 1922 | return 0; |
| 1923 | } |
| 1924 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1925 | static inline void |
| 1926 | il4965_free_dma_ptr(struct il_priv *il, struct il_dma_ptr *ptr) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1927 | { |
| 1928 | if (unlikely(!ptr->addr)) |
| 1929 | return; |
| 1930 | |
| 1931 | dma_free_coherent(&il->pci_dev->dev, ptr->size, ptr->addr, ptr->dma); |
| 1932 | memset(ptr, 0, sizeof(*ptr)); |
| 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * il4965_hw_txq_ctx_free - Free TXQ Context |
| 1937 | * |
| 1938 | * Destroy all TX DMA queues and structures |
| 1939 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1940 | void |
| 1941 | il4965_hw_txq_ctx_free(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1942 | { |
| 1943 | int txq_id; |
| 1944 | |
| 1945 | /* Tx queues */ |
| 1946 | if (il->txq) { |
| 1947 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) |
| 1948 | if (txq_id == il->cmd_queue) |
| 1949 | il_cmd_queue_free(il); |
| 1950 | else |
| 1951 | il_tx_queue_free(il, txq_id); |
| 1952 | } |
| 1953 | il4965_free_dma_ptr(il, &il->kw); |
| 1954 | |
| 1955 | il4965_free_dma_ptr(il, &il->scd_bc_tbls); |
| 1956 | |
| 1957 | /* free tx queue structure */ |
| 1958 | il_txq_mem(il); |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * il4965_txq_ctx_alloc - allocate TX queue context |
| 1963 | * Allocate all Tx DMA structures and initialize them |
| 1964 | * |
| 1965 | * @param il |
| 1966 | * @return error code |
| 1967 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1968 | int |
| 1969 | il4965_txq_ctx_alloc(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1970 | { |
| 1971 | int ret; |
| 1972 | int txq_id, slots_num; |
| 1973 | unsigned long flags; |
| 1974 | |
| 1975 | /* Free all tx/cmd queues and keep-warm buffer */ |
| 1976 | il4965_hw_txq_ctx_free(il); |
| 1977 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1978 | ret = |
| 1979 | il4965_alloc_dma_ptr(il, &il->scd_bc_tbls, |
| 1980 | il->hw_params.scd_bc_tbls_size); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1981 | if (ret) { |
| 1982 | IL_ERR("Scheduler BC Table allocation failed\n"); |
| 1983 | goto error_bc_tbls; |
| 1984 | } |
| 1985 | /* Alloc keep-warm buffer */ |
| 1986 | ret = il4965_alloc_dma_ptr(il, &il->kw, IL_KW_SIZE); |
| 1987 | if (ret) { |
| 1988 | IL_ERR("Keep Warm allocation failed\n"); |
| 1989 | goto error_kw; |
| 1990 | } |
| 1991 | |
| 1992 | /* allocate tx queue structure */ |
| 1993 | ret = il_alloc_txq_mem(il); |
| 1994 | if (ret) |
| 1995 | goto error; |
| 1996 | |
| 1997 | spin_lock_irqsave(&il->lock, flags); |
| 1998 | |
| 1999 | /* Turn off all Tx DMA fifos */ |
| 2000 | il4965_txq_set_sched(il, 0); |
| 2001 | |
| 2002 | /* Tell NIC where to find the "keep warm" buffer */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 2003 | il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2004 | |
| 2005 | spin_unlock_irqrestore(&il->lock, flags); |
| 2006 | |
| 2007 | /* Alloc and init all Tx queues, including the command queue (#4/#9) */ |
| 2008 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2009 | slots_num = |
| 2010 | (txq_id == |
| 2011 | il->cmd_queue) ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; |
| 2012 | ret = il_tx_queue_init(il, &il->txq[txq_id], slots_num, txq_id); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2013 | if (ret) { |
| 2014 | IL_ERR("Tx %d queue init failed\n", txq_id); |
| 2015 | goto error; |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | return ret; |
| 2020 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2021 | error: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2022 | il4965_hw_txq_ctx_free(il); |
| 2023 | il4965_free_dma_ptr(il, &il->kw); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2024 | error_kw: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2025 | il4965_free_dma_ptr(il, &il->scd_bc_tbls); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2026 | error_bc_tbls: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2027 | return ret; |
| 2028 | } |
| 2029 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2030 | void |
| 2031 | il4965_txq_ctx_reset(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2032 | { |
| 2033 | int txq_id, slots_num; |
| 2034 | unsigned long flags; |
| 2035 | |
| 2036 | spin_lock_irqsave(&il->lock, flags); |
| 2037 | |
| 2038 | /* Turn off all Tx DMA fifos */ |
| 2039 | il4965_txq_set_sched(il, 0); |
| 2040 | |
| 2041 | /* Tell NIC where to find the "keep warm" buffer */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 2042 | il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2043 | |
| 2044 | spin_unlock_irqrestore(&il->lock, flags); |
| 2045 | |
| 2046 | /* Alloc and init all Tx queues, including the command queue (#4) */ |
| 2047 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2048 | slots_num = |
| 2049 | txq_id == il->cmd_queue ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; |
| 2050 | il_tx_queue_reset(il, &il->txq[txq_id], slots_num, txq_id); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * il4965_txq_ctx_stop - Stop all Tx DMA channels |
| 2056 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2057 | void |
| 2058 | il4965_txq_ctx_stop(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2059 | { |
| 2060 | int ch, txq_id; |
| 2061 | unsigned long flags; |
| 2062 | |
| 2063 | /* Turn off all Tx DMA fifos */ |
| 2064 | spin_lock_irqsave(&il->lock, flags); |
| 2065 | |
| 2066 | il4965_txq_set_sched(il, 0); |
| 2067 | |
| 2068 | /* Stop each Tx DMA channel, and wait for it to be idle */ |
| 2069 | for (ch = 0; ch < il->hw_params.dma_chnl_num; ch++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2070 | il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0); |
| 2071 | if (il_poll_bit |
| 2072 | (il, FH49_TSSR_TX_STATUS_REG, |
| 2073 | FH49_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch), 1000)) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2074 | IL_ERR("Failing on timeout while stopping" |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 2075 | " DMA channel %d [0x%08x]", ch, |
| 2076 | il_rd(il, FH49_TSSR_TX_STATUS_REG)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2077 | } |
| 2078 | spin_unlock_irqrestore(&il->lock, flags); |
| 2079 | |
| 2080 | if (!il->txq) |
| 2081 | return; |
| 2082 | |
| 2083 | /* Unmap DMA from host system and free skb's */ |
| 2084 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) |
| 2085 | if (txq_id == il->cmd_queue) |
| 2086 | il_cmd_queue_unmap(il); |
| 2087 | else |
| 2088 | il_tx_queue_unmap(il, txq_id); |
| 2089 | } |
| 2090 | |
| 2091 | /* |
| 2092 | * Find first available (lowest unused) Tx Queue, mark it "active". |
| 2093 | * Called only when finding queue for aggregation. |
| 2094 | * Should never return anything < 7, because they should already |
| 2095 | * be in use as EDCA AC (0-3), Command (4), reserved (5, 6) |
| 2096 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2097 | static int |
| 2098 | il4965_txq_ctx_activate_free(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2099 | { |
| 2100 | int txq_id; |
| 2101 | |
| 2102 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) |
| 2103 | if (!test_and_set_bit(txq_id, &il->txq_ctx_active_msk)) |
| 2104 | return txq_id; |
| 2105 | return -1; |
| 2106 | } |
| 2107 | |
| 2108 | /** |
| 2109 | * il4965_tx_queue_stop_scheduler - Stop queue, but keep configuration |
| 2110 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2111 | static void |
| 2112 | il4965_tx_queue_stop_scheduler(struct il_priv *il, u16 txq_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2113 | { |
| 2114 | /* Simply stop the queue, but don't change any configuration; |
| 2115 | * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2116 | il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 2117 | (0 << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) | |
| 2118 | (1 << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | /** |
| 2122 | * il4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue |
| 2123 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2124 | static int |
| 2125 | il4965_tx_queue_set_q2ratid(struct il_priv *il, u16 ra_tid, u16 txq_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2126 | { |
| 2127 | u32 tbl_dw_addr; |
| 2128 | u32 tbl_dw; |
| 2129 | u16 scd_q2ratid; |
| 2130 | |
| 2131 | scd_q2ratid = ra_tid & IL_SCD_QUEUE_RA_TID_MAP_RATID_MSK; |
| 2132 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2133 | tbl_dw_addr = |
| 2134 | il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2135 | |
| 2136 | tbl_dw = il_read_targ_mem(il, tbl_dw_addr); |
| 2137 | |
| 2138 | if (txq_id & 0x1) |
| 2139 | tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF); |
| 2140 | else |
| 2141 | tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000); |
| 2142 | |
| 2143 | il_write_targ_mem(il, tbl_dw_addr, tbl_dw); |
| 2144 | |
| 2145 | return 0; |
| 2146 | } |
| 2147 | |
| 2148 | /** |
| 2149 | * il4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue |
| 2150 | * |
| 2151 | * NOTE: txq_id must be greater than IL49_FIRST_AMPDU_QUEUE, |
| 2152 | * i.e. it must be one of the higher queues used for aggregation |
| 2153 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2154 | static int |
| 2155 | il4965_txq_agg_enable(struct il_priv *il, int txq_id, int tx_fifo, int sta_id, |
| 2156 | int tid, u16 ssn_idx) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2157 | { |
| 2158 | unsigned long flags; |
| 2159 | u16 ra_tid; |
| 2160 | int ret; |
| 2161 | |
| 2162 | if ((IL49_FIRST_AMPDU_QUEUE > txq_id) || |
| 2163 | (IL49_FIRST_AMPDU_QUEUE + |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2164 | il->cfg->base_params->num_of_ampdu_queues <= txq_id)) { |
| 2165 | IL_WARN("queue number out of range: %d, must be %d to %d\n", |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2166 | txq_id, IL49_FIRST_AMPDU_QUEUE, |
| 2167 | IL49_FIRST_AMPDU_QUEUE + |
| 2168 | il->cfg->base_params->num_of_ampdu_queues - 1); |
| 2169 | return -EINVAL; |
| 2170 | } |
| 2171 | |
| 2172 | ra_tid = BUILD_RAxTID(sta_id, tid); |
| 2173 | |
| 2174 | /* Modify device's station table to Tx this TID */ |
| 2175 | ret = il4965_sta_tx_modify_enable_tid(il, sta_id, tid); |
| 2176 | if (ret) |
| 2177 | return ret; |
| 2178 | |
| 2179 | spin_lock_irqsave(&il->lock, flags); |
| 2180 | |
| 2181 | /* Stop this Tx queue before configuring it */ |
| 2182 | il4965_tx_queue_stop_scheduler(il, txq_id); |
| 2183 | |
| 2184 | /* Map receiver-address / traffic-ID to this queue */ |
| 2185 | il4965_tx_queue_set_q2ratid(il, ra_tid, txq_id); |
| 2186 | |
| 2187 | /* Set this queue as a chain-building queue */ |
| 2188 | il_set_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
| 2189 | |
| 2190 | /* Place first TFD at idx corresponding to start sequence number. |
| 2191 | * Assumes that ssn_idx is valid (!= 0xFFF) */ |
| 2192 | il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 2193 | il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
| 2194 | il4965_set_wr_ptrs(il, txq_id, ssn_idx); |
| 2195 | |
| 2196 | /* Set up Tx win size and frame limit for this queue */ |
| 2197 | il_write_targ_mem(il, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2198 | il->scd_base_addr + |
| 2199 | IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id), |
| 2200 | (SCD_WIN_SIZE << IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) |
| 2201 | & IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2202 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2203 | il_write_targ_mem(il, |
| 2204 | il->scd_base_addr + |
| 2205 | IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), |
| 2206 | (SCD_FRAME_LIMIT << |
| 2207 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & |
| 2208 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2209 | |
| 2210 | il_set_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
| 2211 | |
| 2212 | /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */ |
| 2213 | il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 1); |
| 2214 | |
| 2215 | spin_unlock_irqrestore(&il->lock, flags); |
| 2216 | |
| 2217 | return 0; |
| 2218 | } |
| 2219 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2220 | int |
| 2221 | il4965_tx_agg_start(struct il_priv *il, struct ieee80211_vif *vif, |
| 2222 | struct ieee80211_sta *sta, u16 tid, u16 * ssn) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2223 | { |
| 2224 | int sta_id; |
| 2225 | int tx_fifo; |
| 2226 | int txq_id; |
| 2227 | int ret; |
| 2228 | unsigned long flags; |
| 2229 | struct il_tid_data *tid_data; |
| 2230 | |
| 2231 | tx_fifo = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid); |
| 2232 | if (unlikely(tx_fifo < 0)) |
| 2233 | return tx_fifo; |
| 2234 | |
Greg Dietsche | 53611e0 | 2011-08-28 08:26:16 -0500 | [diff] [blame] | 2235 | D_HT("%s on ra = %pM tid = %d\n", __func__, sta->addr, tid); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2236 | |
| 2237 | sta_id = il_sta_id(sta); |
| 2238 | if (sta_id == IL_INVALID_STATION) { |
| 2239 | IL_ERR("Start AGG on invalid station\n"); |
| 2240 | return -ENXIO; |
| 2241 | } |
| 2242 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 2243 | return -EINVAL; |
| 2244 | |
| 2245 | if (il->stations[sta_id].tid[tid].agg.state != IL_AGG_OFF) { |
| 2246 | IL_ERR("Start AGG when state is not IL_AGG_OFF !\n"); |
| 2247 | return -ENXIO; |
| 2248 | } |
| 2249 | |
| 2250 | txq_id = il4965_txq_ctx_activate_free(il); |
| 2251 | if (txq_id == -1) { |
| 2252 | IL_ERR("No free aggregation queue available\n"); |
| 2253 | return -ENXIO; |
| 2254 | } |
| 2255 | |
| 2256 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2257 | tid_data = &il->stations[sta_id].tid[tid]; |
| 2258 | *ssn = SEQ_TO_SN(tid_data->seq_number); |
| 2259 | tid_data->agg.txq_id = txq_id; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2260 | il_set_swq_id(&il->txq[txq_id], il4965_get_ac_from_tid(tid), txq_id); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2261 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2262 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2263 | ret = il4965_txq_agg_enable(il, txq_id, tx_fifo, sta_id, tid, *ssn); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2264 | if (ret) |
| 2265 | return ret; |
| 2266 | |
| 2267 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2268 | tid_data = &il->stations[sta_id].tid[tid]; |
| 2269 | if (tid_data->tfds_in_queue == 0) { |
| 2270 | D_HT("HW queue is empty\n"); |
| 2271 | tid_data->agg.state = IL_AGG_ON; |
| 2272 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2273 | } else { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2274 | D_HT("HW queue is NOT empty: %d packets in HW queue\n", |
| 2275 | tid_data->tfds_in_queue); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2276 | tid_data->agg.state = IL_EMPTYING_HW_QUEUE_ADDBA; |
| 2277 | } |
| 2278 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2279 | return ret; |
| 2280 | } |
| 2281 | |
| 2282 | /** |
| 2283 | * txq_id must be greater than IL49_FIRST_AMPDU_QUEUE |
| 2284 | * il->lock must be held by the caller |
| 2285 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2286 | static int |
| 2287 | il4965_txq_agg_disable(struct il_priv *il, u16 txq_id, u16 ssn_idx, u8 tx_fifo) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2288 | { |
| 2289 | if ((IL49_FIRST_AMPDU_QUEUE > txq_id) || |
| 2290 | (IL49_FIRST_AMPDU_QUEUE + |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2291 | il->cfg->base_params->num_of_ampdu_queues <= txq_id)) { |
| 2292 | IL_WARN("queue number out of range: %d, must be %d to %d\n", |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2293 | txq_id, IL49_FIRST_AMPDU_QUEUE, |
| 2294 | IL49_FIRST_AMPDU_QUEUE + |
| 2295 | il->cfg->base_params->num_of_ampdu_queues - 1); |
| 2296 | return -EINVAL; |
| 2297 | } |
| 2298 | |
| 2299 | il4965_tx_queue_stop_scheduler(il, txq_id); |
| 2300 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2301 | il_clear_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2302 | |
| 2303 | il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 2304 | il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
| 2305 | /* supposes that ssn_idx is valid (!= 0xFFF) */ |
| 2306 | il4965_set_wr_ptrs(il, txq_id, ssn_idx); |
| 2307 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2308 | il_clear_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2309 | il_txq_ctx_deactivate(il, txq_id); |
| 2310 | il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 0); |
| 2311 | |
| 2312 | return 0; |
| 2313 | } |
| 2314 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2315 | int |
| 2316 | il4965_tx_agg_stop(struct il_priv *il, struct ieee80211_vif *vif, |
| 2317 | struct ieee80211_sta *sta, u16 tid) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2318 | { |
| 2319 | int tx_fifo_id, txq_id, sta_id, ssn; |
| 2320 | struct il_tid_data *tid_data; |
| 2321 | int write_ptr, read_ptr; |
| 2322 | unsigned long flags; |
| 2323 | |
| 2324 | tx_fifo_id = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid); |
| 2325 | if (unlikely(tx_fifo_id < 0)) |
| 2326 | return tx_fifo_id; |
| 2327 | |
| 2328 | sta_id = il_sta_id(sta); |
| 2329 | |
| 2330 | if (sta_id == IL_INVALID_STATION) { |
| 2331 | IL_ERR("Invalid station for AGG tid %d\n", tid); |
| 2332 | return -ENXIO; |
| 2333 | } |
| 2334 | |
| 2335 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2336 | |
| 2337 | tid_data = &il->stations[sta_id].tid[tid]; |
| 2338 | ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4; |
| 2339 | txq_id = tid_data->agg.txq_id; |
| 2340 | |
| 2341 | switch (il->stations[sta_id].tid[tid].agg.state) { |
| 2342 | case IL_EMPTYING_HW_QUEUE_ADDBA: |
| 2343 | /* |
| 2344 | * This can happen if the peer stops aggregation |
| 2345 | * again before we've had a chance to drain the |
| 2346 | * queue we selected previously, i.e. before the |
| 2347 | * session was really started completely. |
| 2348 | */ |
| 2349 | D_HT("AGG stop before setup done\n"); |
| 2350 | goto turn_off; |
| 2351 | case IL_AGG_ON: |
| 2352 | break; |
| 2353 | default: |
| 2354 | IL_WARN("Stopping AGG while state not ON or starting\n"); |
| 2355 | } |
| 2356 | |
| 2357 | write_ptr = il->txq[txq_id].q.write_ptr; |
| 2358 | read_ptr = il->txq[txq_id].q.read_ptr; |
| 2359 | |
| 2360 | /* The queue is not empty */ |
| 2361 | if (write_ptr != read_ptr) { |
| 2362 | D_HT("Stopping a non empty AGG HW QUEUE\n"); |
| 2363 | il->stations[sta_id].tid[tid].agg.state = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2364 | IL_EMPTYING_HW_QUEUE_DELBA; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2365 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2366 | return 0; |
| 2367 | } |
| 2368 | |
| 2369 | D_HT("HW queue is empty\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2370 | turn_off: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2371 | il->stations[sta_id].tid[tid].agg.state = IL_AGG_OFF; |
| 2372 | |
| 2373 | /* do not restore/save irqs */ |
| 2374 | spin_unlock(&il->sta_lock); |
| 2375 | spin_lock(&il->lock); |
| 2376 | |
| 2377 | /* |
| 2378 | * the only reason this call can fail is queue number out of range, |
| 2379 | * which can happen if uCode is reloaded and all the station |
| 2380 | * information are lost. if it is outside the range, there is no need |
| 2381 | * to deactivate the uCode queue, just return "success" to allow |
| 2382 | * mac80211 to clean up it own data. |
| 2383 | */ |
| 2384 | il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo_id); |
| 2385 | spin_unlock_irqrestore(&il->lock, flags); |
| 2386 | |
| 2387 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2388 | |
| 2389 | return 0; |
| 2390 | } |
| 2391 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2392 | int |
| 2393 | il4965_txq_check_empty(struct il_priv *il, int sta_id, u8 tid, int txq_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2394 | { |
| 2395 | struct il_queue *q = &il->txq[txq_id].q; |
| 2396 | u8 *addr = il->stations[sta_id].sta.sta.addr; |
| 2397 | struct il_tid_data *tid_data = &il->stations[sta_id].tid[tid]; |
| 2398 | struct il_rxon_context *ctx; |
| 2399 | |
| 2400 | ctx = &il->ctx; |
| 2401 | |
| 2402 | lockdep_assert_held(&il->sta_lock); |
| 2403 | |
| 2404 | switch (il->stations[sta_id].tid[tid].agg.state) { |
| 2405 | case IL_EMPTYING_HW_QUEUE_DELBA: |
| 2406 | /* We are reclaiming the last packet of the */ |
| 2407 | /* aggregated HW queue */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2408 | if (txq_id == tid_data->agg.txq_id && |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2409 | q->read_ptr == q->write_ptr) { |
| 2410 | u16 ssn = SEQ_TO_SN(tid_data->seq_number); |
| 2411 | int tx_fifo = il4965_get_fifo_from_tid(ctx, tid); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2412 | D_HT("HW queue empty: continue DELBA flow\n"); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2413 | il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo); |
| 2414 | tid_data->agg.state = IL_AGG_OFF; |
| 2415 | ieee80211_stop_tx_ba_cb_irqsafe(ctx->vif, addr, tid); |
| 2416 | } |
| 2417 | break; |
| 2418 | case IL_EMPTYING_HW_QUEUE_ADDBA: |
| 2419 | /* We are reclaiming the last packet of the queue */ |
| 2420 | if (tid_data->tfds_in_queue == 0) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2421 | D_HT("HW queue empty: continue ADDBA flow\n"); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2422 | tid_data->agg.state = IL_AGG_ON; |
| 2423 | ieee80211_start_tx_ba_cb_irqsafe(ctx->vif, addr, tid); |
| 2424 | } |
| 2425 | break; |
| 2426 | } |
| 2427 | |
| 2428 | return 0; |
| 2429 | } |
| 2430 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2431 | static void |
| 2432 | il4965_non_agg_tx_status(struct il_priv *il, struct il_rxon_context *ctx, |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 2433 | const u8 *addr1) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2434 | { |
| 2435 | struct ieee80211_sta *sta; |
| 2436 | struct il_station_priv *sta_priv; |
| 2437 | |
| 2438 | rcu_read_lock(); |
| 2439 | sta = ieee80211_find_sta(ctx->vif, addr1); |
| 2440 | if (sta) { |
| 2441 | sta_priv = (void *)sta->drv_priv; |
| 2442 | /* avoid atomic ops if this isn't a client */ |
| 2443 | if (sta_priv->client && |
| 2444 | atomic_dec_return(&sta_priv->pending_frames) == 0) |
| 2445 | ieee80211_sta_block_awake(il->hw, sta, false); |
| 2446 | } |
| 2447 | rcu_read_unlock(); |
| 2448 | } |
| 2449 | |
| 2450 | static void |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2451 | il4965_tx_status(struct il_priv *il, struct il_tx_info *tx_info, bool is_agg) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2452 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2453 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx_info->skb->data; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2454 | |
| 2455 | if (!is_agg) |
| 2456 | il4965_non_agg_tx_status(il, tx_info->ctx, hdr->addr1); |
| 2457 | |
| 2458 | ieee80211_tx_status_irqsafe(il->hw, tx_info->skb); |
| 2459 | } |
| 2460 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2461 | int |
| 2462 | il4965_tx_queue_reclaim(struct il_priv *il, int txq_id, int idx) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2463 | { |
| 2464 | struct il_tx_queue *txq = &il->txq[txq_id]; |
| 2465 | struct il_queue *q = &txq->q; |
| 2466 | struct il_tx_info *tx_info; |
| 2467 | int nfreed = 0; |
| 2468 | struct ieee80211_hdr *hdr; |
| 2469 | |
| 2470 | if (idx >= q->n_bd || il_queue_used(q, idx) == 0) { |
| 2471 | IL_ERR("Read idx for DMA queue txq id (%d), idx %d, " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2472 | "is out of range [0-%d] %d %d.\n", txq_id, idx, q->n_bd, |
| 2473 | q->write_ptr, q->read_ptr); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2474 | return 0; |
| 2475 | } |
| 2476 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2477 | for (idx = il_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2478 | q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 2479 | |
| 2480 | tx_info = &txq->txb[txq->q.read_ptr]; |
| 2481 | |
| 2482 | if (WARN_ON_ONCE(tx_info->skb == NULL)) |
| 2483 | continue; |
| 2484 | |
| 2485 | hdr = (struct ieee80211_hdr *)tx_info->skb->data; |
| 2486 | if (ieee80211_is_data_qos(hdr->frame_control)) |
| 2487 | nfreed++; |
| 2488 | |
| 2489 | il4965_tx_status(il, tx_info, |
| 2490 | txq_id >= IL4965_FIRST_AMPDU_QUEUE); |
| 2491 | tx_info->skb = NULL; |
| 2492 | |
| 2493 | il->cfg->ops->lib->txq_free_tfd(il, txq); |
| 2494 | } |
| 2495 | return nfreed; |
| 2496 | } |
| 2497 | |
| 2498 | /** |
| 2499 | * il4965_tx_status_reply_compressed_ba - Update tx status from block-ack |
| 2500 | * |
| 2501 | * Go through block-ack's bitmap of ACK'd frames, update driver's record of |
| 2502 | * ACK vs. not. This gets sent to mac80211, then to rate scaling algo. |
| 2503 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2504 | static int |
| 2505 | il4965_tx_status_reply_compressed_ba(struct il_priv *il, struct il_ht_agg *agg, |
| 2506 | struct il_compressed_ba_resp *ba_resp) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2507 | { |
| 2508 | int i, sh, ack; |
| 2509 | u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl); |
| 2510 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
| 2511 | int successes = 0; |
| 2512 | struct ieee80211_tx_info *info; |
| 2513 | u64 bitmap, sent_bitmap; |
| 2514 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2515 | if (unlikely(!agg->wait_for_ba)) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2516 | if (unlikely(ba_resp->bitmap)) |
| 2517 | IL_ERR("Received BA when not expected\n"); |
| 2518 | return -EINVAL; |
| 2519 | } |
| 2520 | |
| 2521 | /* Mark that the expected block-ack response arrived */ |
| 2522 | agg->wait_for_ba = 0; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2523 | D_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2524 | |
| 2525 | /* Calculate shift to align block-ack bits with our Tx win bits */ |
| 2526 | sh = agg->start_idx - SEQ_TO_IDX(seq_ctl >> 4); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2527 | if (sh < 0) /* tbw something is wrong with indices */ |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2528 | sh += 0x100; |
| 2529 | |
| 2530 | if (agg->frame_count > (64 - sh)) { |
| 2531 | D_TX_REPLY("more frames than bitmap size"); |
| 2532 | return -1; |
| 2533 | } |
| 2534 | |
| 2535 | /* don't use 64-bit values for now */ |
| 2536 | bitmap = le64_to_cpu(ba_resp->bitmap) >> sh; |
| 2537 | |
| 2538 | /* check for success or failure according to the |
| 2539 | * transmitted bitmap and block-ack bitmap */ |
| 2540 | sent_bitmap = bitmap & agg->bitmap; |
| 2541 | |
| 2542 | /* For each frame attempted in aggregation, |
| 2543 | * update driver's record of tx frame's status. */ |
| 2544 | i = 0; |
| 2545 | while (sent_bitmap) { |
| 2546 | ack = sent_bitmap & 1ULL; |
| 2547 | successes += ack; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2548 | D_TX_REPLY("%s ON i=%d idx=%d raw=%d\n", ack ? "ACK" : "NACK", |
| 2549 | i, (agg->start_idx + i) & 0xff, agg->start_idx + i); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2550 | sent_bitmap >>= 1; |
| 2551 | ++i; |
| 2552 | } |
| 2553 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2554 | D_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2555 | |
| 2556 | info = IEEE80211_SKB_CB(il->txq[scd_flow].txb[agg->start_idx].skb); |
| 2557 | memset(&info->status, 0, sizeof(info->status)); |
| 2558 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 2559 | info->flags |= IEEE80211_TX_STAT_AMPDU; |
| 2560 | info->status.ampdu_ack_len = successes; |
| 2561 | info->status.ampdu_len = agg->frame_count; |
| 2562 | il4965_hwrate_to_tx_control(il, agg->rate_n_flags, info); |
| 2563 | |
| 2564 | return 0; |
| 2565 | } |
| 2566 | |
| 2567 | /** |
| 2568 | * translate ucode response to mac80211 tx status control values |
| 2569 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2570 | void |
| 2571 | il4965_hwrate_to_tx_control(struct il_priv *il, u32 rate_n_flags, |
| 2572 | struct ieee80211_tx_info *info) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2573 | { |
| 2574 | struct ieee80211_tx_rate *r = &info->control.rates[0]; |
| 2575 | |
| 2576 | info->antenna_sel_tx = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2577 | ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2578 | if (rate_n_flags & RATE_MCS_HT_MSK) |
| 2579 | r->flags |= IEEE80211_TX_RC_MCS; |
| 2580 | if (rate_n_flags & RATE_MCS_GF_MSK) |
| 2581 | r->flags |= IEEE80211_TX_RC_GREEN_FIELD; |
| 2582 | if (rate_n_flags & RATE_MCS_HT40_MSK) |
| 2583 | r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
| 2584 | if (rate_n_flags & RATE_MCS_DUP_MSK) |
| 2585 | r->flags |= IEEE80211_TX_RC_DUP_DATA; |
| 2586 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
| 2587 | r->flags |= IEEE80211_TX_RC_SHORT_GI; |
| 2588 | r->idx = il4965_hwrate_to_mac80211_idx(rate_n_flags, info->band); |
| 2589 | } |
| 2590 | |
| 2591 | /** |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 2592 | * il4965_hdl_compressed_ba - Handler for N_COMPRESSED_BA |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2593 | * |
| 2594 | * Handles block-acknowledge notification from device, which reports success |
| 2595 | * of frames sent via aggregation. |
| 2596 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2597 | void |
| 2598 | il4965_hdl_compressed_ba(struct il_priv *il, struct il_rx_buf *rxb) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2599 | { |
| 2600 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 2601 | struct il_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba; |
| 2602 | struct il_tx_queue *txq = NULL; |
| 2603 | struct il_ht_agg *agg; |
| 2604 | int idx; |
| 2605 | int sta_id; |
| 2606 | int tid; |
| 2607 | unsigned long flags; |
| 2608 | |
| 2609 | /* "flow" corresponds to Tx queue */ |
| 2610 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
| 2611 | |
| 2612 | /* "ssn" is start of block-ack Tx win, corresponds to idx |
| 2613 | * (in Tx queue's circular buffer) of first TFD/frame in win */ |
| 2614 | u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn); |
| 2615 | |
| 2616 | if (scd_flow >= il->hw_params.max_txq_num) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2617 | IL_ERR("BUG_ON scd_flow is bigger than number of queues\n"); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2618 | return; |
| 2619 | } |
| 2620 | |
| 2621 | txq = &il->txq[scd_flow]; |
| 2622 | sta_id = ba_resp->sta_id; |
| 2623 | tid = ba_resp->tid; |
| 2624 | agg = &il->stations[sta_id].tid[tid].agg; |
| 2625 | if (unlikely(agg->txq_id != scd_flow)) { |
| 2626 | /* |
| 2627 | * FIXME: this is a uCode bug which need to be addressed, |
| 2628 | * log the information and return for now! |
| 2629 | * since it is possible happen very often and in order |
| 2630 | * not to fill the syslog, don't enable the logging by default |
| 2631 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2632 | D_TX_REPLY("BA scd_flow %d does not match txq_id %d\n", |
| 2633 | scd_flow, agg->txq_id); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2634 | return; |
| 2635 | } |
| 2636 | |
| 2637 | /* Find idx just before block-ack win */ |
| 2638 | idx = il_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd); |
| 2639 | |
| 2640 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2641 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2642 | D_TX_REPLY("N_COMPRESSED_BA [%d] Received from %pM, " "sta_id = %d\n", |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 2643 | agg->wait_for_ba, (u8 *) &ba_resp->sta_addr_lo32, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2644 | ba_resp->sta_id); |
| 2645 | D_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx," "scd_flow = " |
| 2646 | "%d, scd_ssn = %d\n", ba_resp->tid, ba_resp->seq_ctl, |
| 2647 | (unsigned long long)le64_to_cpu(ba_resp->bitmap), |
| 2648 | ba_resp->scd_flow, ba_resp->scd_ssn); |
| 2649 | D_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx\n", agg->start_idx, |
| 2650 | (unsigned long long)agg->bitmap); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2651 | |
| 2652 | /* Update driver's record of ACK vs. not for each frame in win */ |
| 2653 | il4965_tx_status_reply_compressed_ba(il, agg, ba_resp); |
| 2654 | |
| 2655 | /* Release all TFDs before the SSN, i.e. all TFDs in front of |
| 2656 | * block-ack win (we assume that they've been successfully |
| 2657 | * transmitted ... if not, it's too late anyway). */ |
| 2658 | if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) { |
| 2659 | /* calculate mac80211 ampdu sw queue to wake */ |
| 2660 | int freed = il4965_tx_queue_reclaim(il, scd_flow, idx); |
| 2661 | il4965_free_tfds_in_queue(il, sta_id, tid, freed); |
| 2662 | |
| 2663 | if (il_queue_space(&txq->q) > txq->q.low_mark && |
| 2664 | il->mac80211_registered && |
| 2665 | agg->state != IL_EMPTYING_HW_QUEUE_DELBA) |
| 2666 | il_wake_queue(il, txq); |
| 2667 | |
| 2668 | il4965_txq_check_empty(il, sta_id, tid, scd_flow); |
| 2669 | } |
| 2670 | |
| 2671 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2672 | } |
| 2673 | |
| 2674 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2675 | const char * |
| 2676 | il4965_get_tx_fail_reason(u32 status) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2677 | { |
| 2678 | #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2679 | #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x |
| 2680 | |
| 2681 | switch (status & TX_STATUS_MSK) { |
| 2682 | case TX_STATUS_SUCCESS: |
| 2683 | return "SUCCESS"; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2684 | TX_STATUS_POSTPONE(DELAY); |
| 2685 | TX_STATUS_POSTPONE(FEW_BYTES); |
| 2686 | TX_STATUS_POSTPONE(QUIET_PERIOD); |
| 2687 | TX_STATUS_POSTPONE(CALC_TTAK); |
| 2688 | TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY); |
| 2689 | TX_STATUS_FAIL(SHORT_LIMIT); |
| 2690 | TX_STATUS_FAIL(LONG_LIMIT); |
| 2691 | TX_STATUS_FAIL(FIFO_UNDERRUN); |
| 2692 | TX_STATUS_FAIL(DRAIN_FLOW); |
| 2693 | TX_STATUS_FAIL(RFKILL_FLUSH); |
| 2694 | TX_STATUS_FAIL(LIFE_EXPIRE); |
| 2695 | TX_STATUS_FAIL(DEST_PS); |
| 2696 | TX_STATUS_FAIL(HOST_ABORTED); |
| 2697 | TX_STATUS_FAIL(BT_RETRY); |
| 2698 | TX_STATUS_FAIL(STA_INVALID); |
| 2699 | TX_STATUS_FAIL(FRAG_DROPPED); |
| 2700 | TX_STATUS_FAIL(TID_DISABLE); |
| 2701 | TX_STATUS_FAIL(FIFO_FLUSHED); |
| 2702 | TX_STATUS_FAIL(INSUFFICIENT_CF_POLL); |
| 2703 | TX_STATUS_FAIL(PASSIVE_NO_RX); |
| 2704 | TX_STATUS_FAIL(NO_BEACON_ON_RADAR); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | return "UNKNOWN"; |
| 2708 | |
| 2709 | #undef TX_STATUS_FAIL |
| 2710 | #undef TX_STATUS_POSTPONE |
| 2711 | } |
| 2712 | #endif /* CONFIG_IWLEGACY_DEBUG */ |
| 2713 | |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2714 | static struct il_link_quality_cmd * |
| 2715 | il4965_sta_alloc_lq(struct il_priv *il, u8 sta_id) |
| 2716 | { |
| 2717 | int i, r; |
| 2718 | struct il_link_quality_cmd *link_cmd; |
| 2719 | u32 rate_flags = 0; |
| 2720 | __le32 rate_n_flags; |
| 2721 | |
| 2722 | link_cmd = kzalloc(sizeof(struct il_link_quality_cmd), GFP_KERNEL); |
| 2723 | if (!link_cmd) { |
| 2724 | IL_ERR("Unable to allocate memory for LQ cmd.\n"); |
| 2725 | return NULL; |
| 2726 | } |
| 2727 | /* Set up the rate scaling to start at selected rate, fall back |
| 2728 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
| 2729 | if (il->band == IEEE80211_BAND_5GHZ) |
| 2730 | r = RATE_6M_IDX; |
| 2731 | else |
| 2732 | r = RATE_1M_IDX; |
| 2733 | |
| 2734 | if (r >= IL_FIRST_CCK_RATE && r <= IL_LAST_CCK_RATE) |
| 2735 | rate_flags |= RATE_MCS_CCK_MSK; |
| 2736 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2737 | rate_flags |= |
| 2738 | il4965_first_antenna(il->hw_params. |
| 2739 | valid_tx_ant) << RATE_MCS_ANT_POS; |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 2740 | rate_n_flags = cpu_to_le32(il_rates[r].plcp | rate_flags); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2741 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
| 2742 | link_cmd->rs_table[i].rate_n_flags = rate_n_flags; |
| 2743 | |
| 2744 | link_cmd->general_params.single_stream_ant_msk = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2745 | il4965_first_antenna(il->hw_params.valid_tx_ant); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2746 | |
| 2747 | link_cmd->general_params.dual_stream_ant_msk = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2748 | il->hw_params.valid_tx_ant & ~il4965_first_antenna(il->hw_params. |
| 2749 | valid_tx_ant); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2750 | if (!link_cmd->general_params.dual_stream_ant_msk) { |
| 2751 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; |
| 2752 | } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) { |
| 2753 | link_cmd->general_params.dual_stream_ant_msk = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2754 | il->hw_params.valid_tx_ant; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
| 2758 | link_cmd->agg_params.agg_time_limit = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2759 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2760 | |
| 2761 | link_cmd->sta_id = sta_id; |
| 2762 | |
| 2763 | return link_cmd; |
| 2764 | } |
| 2765 | |
| 2766 | /* |
| 2767 | * il4965_add_bssid_station - Add the special IBSS BSSID station |
| 2768 | * |
| 2769 | * Function sleeps. |
| 2770 | */ |
| 2771 | int |
| 2772 | il4965_add_bssid_station(struct il_priv *il, struct il_rxon_context *ctx, |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 2773 | const u8 *addr, u8 *sta_id_r) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2774 | { |
| 2775 | int ret; |
| 2776 | u8 sta_id; |
| 2777 | struct il_link_quality_cmd *link_cmd; |
| 2778 | unsigned long flags; |
| 2779 | |
| 2780 | if (sta_id_r) |
| 2781 | *sta_id_r = IL_INVALID_STATION; |
| 2782 | |
| 2783 | ret = il_add_station_common(il, ctx, addr, 0, NULL, &sta_id); |
| 2784 | if (ret) { |
| 2785 | IL_ERR("Unable to add station %pM\n", addr); |
| 2786 | return ret; |
| 2787 | } |
| 2788 | |
| 2789 | if (sta_id_r) |
| 2790 | *sta_id_r = sta_id; |
| 2791 | |
| 2792 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2793 | il->stations[sta_id].used |= IL_STA_LOCAL; |
| 2794 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2795 | |
| 2796 | /* Set up default rate scaling table in device's station table */ |
| 2797 | link_cmd = il4965_sta_alloc_lq(il, sta_id); |
| 2798 | if (!link_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2799 | IL_ERR("Unable to initialize rate scaling for station %pM.\n", |
| 2800 | addr); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2801 | return -ENOMEM; |
| 2802 | } |
| 2803 | |
| 2804 | ret = il_send_lq_cmd(il, ctx, link_cmd, CMD_SYNC, true); |
| 2805 | if (ret) |
| 2806 | IL_ERR("Link quality command failed (%d)\n", ret); |
| 2807 | |
| 2808 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2809 | il->stations[sta_id].lq = link_cmd; |
| 2810 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2811 | |
| 2812 | return 0; |
| 2813 | } |
| 2814 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2815 | static int |
| 2816 | il4965_static_wepkey_cmd(struct il_priv *il, struct il_rxon_context *ctx, |
| 2817 | bool send_if_empty) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2818 | { |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2819 | int i; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2820 | u8 buff[sizeof(struct il_wep_cmd) + |
| 2821 | sizeof(struct il_wep_key) * WEP_KEYS_MAX]; |
| 2822 | struct il_wep_cmd *wep_cmd = (struct il_wep_cmd *)buff; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2823 | size_t cmd_size = sizeof(struct il_wep_cmd); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2824 | struct il_host_cmd cmd = { |
Stanislaw Gruszka | d98e294 | 2012-02-03 17:31:42 +0100 | [diff] [blame] | 2825 | .id = C_WEPKEY, |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2826 | .data = wep_cmd, |
| 2827 | .flags = CMD_SYNC, |
| 2828 | }; |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2829 | bool not_empty = false; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2830 | |
| 2831 | might_sleep(); |
| 2832 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2833 | memset(wep_cmd, 0, |
| 2834 | cmd_size + (sizeof(struct il_wep_key) * WEP_KEYS_MAX)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2835 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2836 | for (i = 0; i < WEP_KEYS_MAX; i++) { |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2837 | u8 key_size = il->_4965.wep_keys[i].key_size; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2838 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2839 | wep_cmd->key[i].key_idx = i; |
| 2840 | if (key_size) { |
| 2841 | wep_cmd->key[i].key_offset = i; |
| 2842 | not_empty = true; |
| 2843 | } else |
| 2844 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 2845 | |
| 2846 | wep_cmd->key[i].key_size = key_size; |
| 2847 | memcpy(&wep_cmd->key[i].key[3], il->_4965.wep_keys[i].key, key_size); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 2851 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 2852 | |
| 2853 | cmd_size += sizeof(struct il_wep_key) * WEP_KEYS_MAX; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2854 | cmd.len = cmd_size; |
| 2855 | |
| 2856 | if (not_empty || send_if_empty) |
| 2857 | return il_send_cmd(il, &cmd); |
| 2858 | else |
| 2859 | return 0; |
| 2860 | } |
| 2861 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2862 | int |
| 2863 | il4965_restore_default_wep_keys(struct il_priv *il, struct il_rxon_context *ctx) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2864 | { |
| 2865 | lockdep_assert_held(&il->mutex); |
| 2866 | |
| 2867 | return il4965_static_wepkey_cmd(il, ctx, false); |
| 2868 | } |
| 2869 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2870 | int |
| 2871 | il4965_remove_default_wep_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 2872 | struct ieee80211_key_conf *keyconf) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2873 | { |
| 2874 | int ret; |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2875 | int idx = keyconf->keyidx; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2876 | |
| 2877 | lockdep_assert_held(&il->mutex); |
| 2878 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2879 | D_WEP("Removing default WEP key: idx=%d\n", idx); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2880 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2881 | memset(&il->_4965.wep_keys[idx], 0, sizeof(struct il_wep_key)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2882 | if (il_is_rfkill(il)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2883 | D_WEP("Not sending C_WEPKEY command due to RFKILL.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2884 | /* but keys in device are clear anyway so return success */ |
| 2885 | return 0; |
| 2886 | } |
| 2887 | ret = il4965_static_wepkey_cmd(il, ctx, 1); |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2888 | D_WEP("Remove default WEP key: idx=%d ret=%d\n", idx, ret); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2889 | |
| 2890 | return ret; |
| 2891 | } |
| 2892 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2893 | int |
| 2894 | il4965_set_default_wep_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 2895 | struct ieee80211_key_conf *keyconf) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2896 | { |
| 2897 | int ret; |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2898 | int len = keyconf->keylen; |
| 2899 | int idx = keyconf->keyidx; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2900 | |
| 2901 | lockdep_assert_held(&il->mutex); |
| 2902 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2903 | if (len != WEP_KEY_LEN_128 && len != WEP_KEY_LEN_64) { |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2904 | D_WEP("Bad WEP key length %d\n", keyconf->keylen); |
| 2905 | return -EINVAL; |
| 2906 | } |
| 2907 | |
| 2908 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
| 2909 | keyconf->hw_key_idx = HW_KEY_DEFAULT; |
Stanislaw Gruszka | 8f9e564 | 2012-02-03 17:31:43 +0100 | [diff] [blame] | 2910 | il->stations[IL_AP_ID].keyinfo.cipher = keyconf->cipher; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2911 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2912 | il->_4965.wep_keys[idx].key_size = len; |
| 2913 | memcpy(&il->_4965.wep_keys[idx].key, &keyconf->key, len); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2914 | |
| 2915 | ret = il4965_static_wepkey_cmd(il, ctx, false); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2916 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 2917 | D_WEP("Set default WEP key: len=%d idx=%d ret=%d\n", len, idx, ret); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2918 | return ret; |
| 2919 | } |
| 2920 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2921 | static int |
| 2922 | il4965_set_wep_dynamic_key_info(struct il_priv *il, struct il_rxon_context *ctx, |
| 2923 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2924 | { |
| 2925 | unsigned long flags; |
| 2926 | __le16 key_flags = 0; |
| 2927 | struct il_addsta_cmd sta_cmd; |
| 2928 | |
| 2929 | lockdep_assert_held(&il->mutex); |
| 2930 | |
| 2931 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
| 2932 | |
| 2933 | key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); |
| 2934 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 2935 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 2936 | |
| 2937 | if (keyconf->keylen == WEP_KEY_LEN_128) |
| 2938 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
| 2939 | |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 2940 | if (sta_id == il->hw_params.bcast_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2941 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 2942 | |
| 2943 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2944 | |
| 2945 | il->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
| 2946 | il->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 2947 | il->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; |
| 2948 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2949 | memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2950 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2951 | memcpy(&il->stations[sta_id].sta.key.key[3], keyconf->key, |
| 2952 | keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2953 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2954 | if ((il->stations[sta_id].sta.key. |
| 2955 | key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2956 | il->stations[sta_id].sta.key.key_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2957 | il_get_free_ucode_key_idx(il); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2958 | /* else, we are overriding an existing key => no need to allocated room |
| 2959 | * in uCode. */ |
| 2960 | |
| 2961 | WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2962 | "no space for a new key"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2963 | |
| 2964 | il->stations[sta_id].sta.key.key_flags = key_flags; |
| 2965 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 2966 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 2967 | |
| 2968 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2969 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2970 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2971 | |
| 2972 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 2973 | } |
| 2974 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2975 | static int |
| 2976 | il4965_set_ccmp_dynamic_key_info(struct il_priv *il, |
| 2977 | struct il_rxon_context *ctx, |
| 2978 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2979 | { |
| 2980 | unsigned long flags; |
| 2981 | __le16 key_flags = 0; |
| 2982 | struct il_addsta_cmd sta_cmd; |
| 2983 | |
| 2984 | lockdep_assert_held(&il->mutex); |
| 2985 | |
| 2986 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); |
| 2987 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 2988 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 2989 | |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 2990 | if (sta_id == il->hw_params.bcast_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2991 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 2992 | |
| 2993 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 2994 | |
| 2995 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2996 | il->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
| 2997 | il->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 2998 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2999 | memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3000 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3001 | memcpy(il->stations[sta_id].sta.key.key, keyconf->key, keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3002 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3003 | if ((il->stations[sta_id].sta.key. |
| 3004 | key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3005 | il->stations[sta_id].sta.key.key_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3006 | il_get_free_ucode_key_idx(il); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3007 | /* else, we are overriding an existing key => no need to allocated room |
| 3008 | * in uCode. */ |
| 3009 | |
| 3010 | WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3011 | "no space for a new key"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3012 | |
| 3013 | il->stations[sta_id].sta.key.key_flags = key_flags; |
| 3014 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 3015 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3016 | |
| 3017 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3018 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3019 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3020 | |
| 3021 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3022 | } |
| 3023 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3024 | static int |
| 3025 | il4965_set_tkip_dynamic_key_info(struct il_priv *il, |
| 3026 | struct il_rxon_context *ctx, |
| 3027 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3028 | { |
| 3029 | unsigned long flags; |
| 3030 | int ret = 0; |
| 3031 | __le16 key_flags = 0; |
| 3032 | |
| 3033 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 3034 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 3035 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 3036 | |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 3037 | if (sta_id == il->hw_params.bcast_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3038 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 3039 | |
| 3040 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 3041 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 3042 | |
| 3043 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3044 | |
| 3045 | il->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
| 3046 | il->stations[sta_id].keyinfo.keylen = 16; |
| 3047 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3048 | if ((il->stations[sta_id].sta.key. |
| 3049 | key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3050 | il->stations[sta_id].sta.key.key_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3051 | il_get_free_ucode_key_idx(il); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3052 | /* else, we are overriding an existing key => no need to allocated room |
| 3053 | * in uCode. */ |
| 3054 | |
| 3055 | WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3056 | "no space for a new key"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3057 | |
| 3058 | il->stations[sta_id].sta.key.key_flags = key_flags; |
| 3059 | |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3060 | /* This copy is acutally not needed: we get the key with each TX */ |
| 3061 | memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, 16); |
| 3062 | |
| 3063 | memcpy(il->stations[sta_id].sta.key.key, keyconf->key, 16); |
| 3064 | |
| 3065 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3066 | |
| 3067 | return ret; |
| 3068 | } |
| 3069 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3070 | void |
| 3071 | il4965_update_tkip_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 3072 | struct ieee80211_key_conf *keyconf, |
| 3073 | struct ieee80211_sta *sta, u32 iv32, u16 * phase1key) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3074 | { |
| 3075 | u8 sta_id; |
| 3076 | unsigned long flags; |
| 3077 | int i; |
| 3078 | |
| 3079 | if (il_scan_cancel(il)) { |
| 3080 | /* cancel scan failed, just live w/ bad key and rely |
| 3081 | briefly on SW decryption */ |
| 3082 | return; |
| 3083 | } |
| 3084 | |
| 3085 | sta_id = il_sta_id_or_broadcast(il, ctx, sta); |
| 3086 | if (sta_id == IL_INVALID_STATION) |
| 3087 | return; |
| 3088 | |
| 3089 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3090 | |
| 3091 | il->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 3092 | |
| 3093 | for (i = 0; i < 5; i++) |
| 3094 | il->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3095 | cpu_to_le16(phase1key[i]); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3096 | |
| 3097 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 3098 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3099 | |
| 3100 | il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC); |
| 3101 | |
| 3102 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3103 | |
| 3104 | } |
| 3105 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3106 | int |
| 3107 | il4965_remove_dynamic_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 3108 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3109 | { |
| 3110 | unsigned long flags; |
| 3111 | u16 key_flags; |
| 3112 | u8 keyidx; |
| 3113 | struct il_addsta_cmd sta_cmd; |
| 3114 | |
| 3115 | lockdep_assert_held(&il->mutex); |
| 3116 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 3117 | il->_4965.key_mapping_keys--; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3118 | |
| 3119 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3120 | key_flags = le16_to_cpu(il->stations[sta_id].sta.key.key_flags); |
| 3121 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; |
| 3122 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3123 | D_WEP("Remove dynamic key: idx=%d sta=%d\n", keyconf->keyidx, sta_id); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3124 | |
| 3125 | if (keyconf->keyidx != keyidx) { |
| 3126 | /* We need to remove a key with idx different that the one |
| 3127 | * in the uCode. This means that the key we need to remove has |
| 3128 | * been replaced by another one with different idx. |
| 3129 | * Don't do anything and return ok |
| 3130 | */ |
| 3131 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3132 | return 0; |
| 3133 | } |
| 3134 | |
| 3135 | if (il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3136 | IL_WARN("Removing wrong key %d 0x%x\n", keyconf->keyidx, |
| 3137 | key_flags); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3138 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3139 | return 0; |
| 3140 | } |
| 3141 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3142 | if (!test_and_clear_bit |
| 3143 | (il->stations[sta_id].sta.key.key_offset, &il->ucode_key_table)) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3144 | IL_ERR("idx %d not used in uCode key table.\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3145 | il->stations[sta_id].sta.key.key_offset); |
| 3146 | memset(&il->stations[sta_id].keyinfo, 0, sizeof(struct il_hw_key)); |
| 3147 | memset(&il->stations[sta_id].sta.key, 0, sizeof(struct il4965_keyinfo)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3148 | il->stations[sta_id].sta.key.key_flags = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3149 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3150 | il->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; |
| 3151 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 3152 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3153 | |
| 3154 | if (il_is_rfkill(il)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3155 | D_WEP |
| 3156 | ("Not sending C_ADD_STA command because RFKILL enabled.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3157 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3158 | return 0; |
| 3159 | } |
| 3160 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3161 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3162 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3163 | |
| 3164 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3165 | } |
| 3166 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3167 | int |
| 3168 | il4965_set_dynamic_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 3169 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3170 | { |
| 3171 | int ret; |
| 3172 | |
| 3173 | lockdep_assert_held(&il->mutex); |
| 3174 | |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 3175 | il->_4965.key_mapping_keys++; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3176 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
| 3177 | |
| 3178 | switch (keyconf->cipher) { |
| 3179 | case WLAN_CIPHER_SUITE_CCMP: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3180 | ret = |
| 3181 | il4965_set_ccmp_dynamic_key_info(il, ctx, keyconf, sta_id); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3182 | break; |
| 3183 | case WLAN_CIPHER_SUITE_TKIP: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3184 | ret = |
| 3185 | il4965_set_tkip_dynamic_key_info(il, ctx, keyconf, sta_id); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3186 | break; |
| 3187 | case WLAN_CIPHER_SUITE_WEP40: |
| 3188 | case WLAN_CIPHER_SUITE_WEP104: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3189 | ret = il4965_set_wep_dynamic_key_info(il, ctx, keyconf, sta_id); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3190 | break; |
| 3191 | default: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3192 | IL_ERR("Unknown alg: %s cipher = %x\n", __func__, |
| 3193 | keyconf->cipher); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3194 | ret = -EINVAL; |
| 3195 | } |
| 3196 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3197 | D_WEP("Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n", |
| 3198 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, sta_id, ret); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3199 | |
| 3200 | return ret; |
| 3201 | } |
| 3202 | |
| 3203 | /** |
| 3204 | * il4965_alloc_bcast_station - add broadcast station into driver's station table. |
| 3205 | * |
| 3206 | * This adds the broadcast station into the driver's station table |
| 3207 | * and marks it driver active, so that it will be restored to the |
| 3208 | * device at the next best time. |
| 3209 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3210 | int |
| 3211 | il4965_alloc_bcast_station(struct il_priv *il, struct il_rxon_context *ctx) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3212 | { |
| 3213 | struct il_link_quality_cmd *link_cmd; |
| 3214 | unsigned long flags; |
| 3215 | u8 sta_id; |
| 3216 | |
| 3217 | spin_lock_irqsave(&il->sta_lock, flags); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3218 | sta_id = il_prep_station(il, ctx, il_bcast_addr, false, NULL); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3219 | if (sta_id == IL_INVALID_STATION) { |
| 3220 | IL_ERR("Unable to prepare broadcast station\n"); |
| 3221 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3222 | |
| 3223 | return -EINVAL; |
| 3224 | } |
| 3225 | |
| 3226 | il->stations[sta_id].used |= IL_STA_DRIVER_ACTIVE; |
| 3227 | il->stations[sta_id].used |= IL_STA_BCAST; |
| 3228 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3229 | |
| 3230 | link_cmd = il4965_sta_alloc_lq(il, sta_id); |
| 3231 | if (!link_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3232 | IL_ERR |
| 3233 | ("Unable to initialize rate scaling for bcast station.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3234 | return -ENOMEM; |
| 3235 | } |
| 3236 | |
| 3237 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3238 | il->stations[sta_id].lq = link_cmd; |
| 3239 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3240 | |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
| 3244 | /** |
| 3245 | * il4965_update_bcast_station - update broadcast station's LQ command |
| 3246 | * |
| 3247 | * Only used by iwl4965. Placed here to have all bcast station management |
| 3248 | * code together. |
| 3249 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3250 | static int |
| 3251 | il4965_update_bcast_station(struct il_priv *il, struct il_rxon_context *ctx) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3252 | { |
| 3253 | unsigned long flags; |
| 3254 | struct il_link_quality_cmd *link_cmd; |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 3255 | u8 sta_id = il->hw_params.bcast_id; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3256 | |
| 3257 | link_cmd = il4965_sta_alloc_lq(il, sta_id); |
| 3258 | if (!link_cmd) { |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 3259 | IL_ERR("Unable to initialize rate scaling for bcast sta.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3260 | return -ENOMEM; |
| 3261 | } |
| 3262 | |
| 3263 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3264 | if (il->stations[sta_id].lq) |
| 3265 | kfree(il->stations[sta_id].lq); |
| 3266 | else |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 3267 | D_INFO("Bcast sta rate scaling has not been initialized.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3268 | il->stations[sta_id].lq = link_cmd; |
| 3269 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3270 | |
| 3271 | return 0; |
| 3272 | } |
| 3273 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3274 | int |
| 3275 | il4965_update_bcast_stations(struct il_priv *il) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3276 | { |
| 3277 | return il4965_update_bcast_station(il, &il->ctx); |
| 3278 | } |
| 3279 | |
| 3280 | /** |
| 3281 | * il4965_sta_tx_modify_enable_tid - Enable Tx for this TID in station table |
| 3282 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3283 | int |
| 3284 | il4965_sta_tx_modify_enable_tid(struct il_priv *il, int sta_id, int tid) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3285 | { |
| 3286 | unsigned long flags; |
| 3287 | struct il_addsta_cmd sta_cmd; |
| 3288 | |
| 3289 | lockdep_assert_held(&il->mutex); |
| 3290 | |
| 3291 | /* Remove "disable" flag, to enable Tx for this TID */ |
| 3292 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3293 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 3294 | il->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 3295 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3296 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3297 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3298 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3299 | |
| 3300 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3301 | } |
| 3302 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3303 | int |
| 3304 | il4965_sta_rx_agg_start(struct il_priv *il, struct ieee80211_sta *sta, int tid, |
| 3305 | u16 ssn) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3306 | { |
| 3307 | unsigned long flags; |
| 3308 | int sta_id; |
| 3309 | struct il_addsta_cmd sta_cmd; |
| 3310 | |
| 3311 | lockdep_assert_held(&il->mutex); |
| 3312 | |
| 3313 | sta_id = il_sta_id(sta); |
| 3314 | if (sta_id == IL_INVALID_STATION) |
| 3315 | return -ENXIO; |
| 3316 | |
| 3317 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3318 | il->stations[sta_id].sta.station_flags_msk = 0; |
| 3319 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3320 | il->stations[sta_id].sta.add_immediate_ba_tid = (u8) tid; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3321 | il->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 3322 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3323 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3324 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3325 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3326 | |
| 3327 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3328 | } |
| 3329 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3330 | int |
| 3331 | il4965_sta_rx_agg_stop(struct il_priv *il, struct ieee80211_sta *sta, int tid) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3332 | { |
| 3333 | unsigned long flags; |
| 3334 | int sta_id; |
| 3335 | struct il_addsta_cmd sta_cmd; |
| 3336 | |
| 3337 | lockdep_assert_held(&il->mutex); |
| 3338 | |
| 3339 | sta_id = il_sta_id(sta); |
| 3340 | if (sta_id == IL_INVALID_STATION) { |
| 3341 | IL_ERR("Invalid station for AGG tid %d\n", tid); |
| 3342 | return -ENXIO; |
| 3343 | } |
| 3344 | |
| 3345 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3346 | il->stations[sta_id].sta.station_flags_msk = 0; |
| 3347 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3348 | il->stations[sta_id].sta.remove_immediate_ba_tid = (u8) tid; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3349 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3350 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3351 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3352 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3353 | |
| 3354 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3355 | } |
| 3356 | |
| 3357 | void |
| 3358 | il4965_sta_modify_sleep_tx_count(struct il_priv *il, int sta_id, int cnt) |
| 3359 | { |
| 3360 | unsigned long flags; |
| 3361 | |
| 3362 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3363 | il->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK; |
| 3364 | il->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 3365 | il->stations[sta_id].sta.sta.modify_mask = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3366 | STA_MODIFY_SLEEP_TX_COUNT_MSK; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3367 | il->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt); |
| 3368 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3369 | il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3370 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3371 | |
| 3372 | } |
| 3373 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3374 | void |
| 3375 | il4965_update_chain_flags(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3376 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3377 | if (il->cfg->ops->hcmd->set_rxon_chain) { |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 3378 | il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx); |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 3379 | if (il->active.rx_chain != il->staging.rx_chain) |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 3380 | il_commit_rxon(il, &il->ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3381 | } |
| 3382 | } |
| 3383 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3384 | static void |
| 3385 | il4965_clear_free_frames(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3386 | { |
| 3387 | struct list_head *element; |
| 3388 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3389 | D_INFO("%d frames on pre-allocated heap on clear.\n", il->frames_count); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3390 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3391 | while (!list_empty(&il->free_frames)) { |
| 3392 | element = il->free_frames.next; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3393 | list_del(element); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3394 | kfree(list_entry(element, struct il_frame, list)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3395 | il->frames_count--; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3396 | } |
| 3397 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3398 | if (il->frames_count) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3399 | IL_WARN("%d frames still in use. Did we lose one?\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3400 | il->frames_count); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3401 | il->frames_count = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3402 | } |
| 3403 | } |
| 3404 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3405 | static struct il_frame * |
| 3406 | il4965_get_free_frame(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3407 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3408 | struct il_frame *frame; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3409 | struct list_head *element; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3410 | if (list_empty(&il->free_frames)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3411 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 3412 | if (!frame) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3413 | IL_ERR("Could not allocate frame!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3414 | return NULL; |
| 3415 | } |
| 3416 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3417 | il->frames_count++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3418 | return frame; |
| 3419 | } |
| 3420 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3421 | element = il->free_frames.next; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3422 | list_del(element); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3423 | return list_entry(element, struct il_frame, list); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3424 | } |
| 3425 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3426 | static void |
| 3427 | il4965_free_frame(struct il_priv *il, struct il_frame *frame) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3428 | { |
| 3429 | memset(frame, 0, sizeof(*frame)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3430 | list_add(&frame->list, &il->free_frames); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3431 | } |
| 3432 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3433 | static u32 |
| 3434 | il4965_fill_beacon_frame(struct il_priv *il, struct ieee80211_hdr *hdr, |
| 3435 | int left) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3436 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3437 | lockdep_assert_held(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3438 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3439 | if (!il->beacon_skb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3440 | return 0; |
| 3441 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3442 | if (il->beacon_skb->len > left) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3443 | return 0; |
| 3444 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3445 | memcpy(hdr, il->beacon_skb->data, il->beacon_skb->len); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3446 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3447 | return il->beacon_skb->len; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3451 | static void |
| 3452 | il4965_set_beacon_tim(struct il_priv *il, |
| 3453 | struct il_tx_beacon_cmd *tx_beacon_cmd, u8 * beacon, |
| 3454 | u32 frame_size) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3455 | { |
| 3456 | u16 tim_idx; |
| 3457 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon; |
| 3458 | |
| 3459 | /* |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3460 | * The idx is relative to frame start but we start looking at the |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3461 | * variable-length part of the beacon. |
| 3462 | */ |
| 3463 | tim_idx = mgmt->u.beacon.variable - beacon; |
| 3464 | |
| 3465 | /* Parse variable-length elements of beacon to find WLAN_EID_TIM */ |
| 3466 | while ((tim_idx < (frame_size - 2)) && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3467 | (beacon[tim_idx] != WLAN_EID_TIM)) |
| 3468 | tim_idx += beacon[tim_idx + 1] + 2; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3469 | |
| 3470 | /* If TIM field was found, set variables */ |
| 3471 | if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) { |
| 3472 | tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3473 | tx_beacon_cmd->tim_size = beacon[tim_idx + 1]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3474 | } else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3475 | IL_WARN("Unable to find TIM Element in beacon\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3476 | } |
| 3477 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3478 | static unsigned int |
| 3479 | il4965_hw_get_beacon_cmd(struct il_priv *il, struct il_frame *frame) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3480 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3481 | struct il_tx_beacon_cmd *tx_beacon_cmd; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3482 | u32 frame_size; |
| 3483 | u32 rate_flags; |
| 3484 | u32 rate; |
| 3485 | /* |
| 3486 | * We have to set up the TX command, the TX Beacon command, and the |
| 3487 | * beacon contents. |
| 3488 | */ |
| 3489 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3490 | lockdep_assert_held(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3491 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3492 | if (!il->beacon_ctx) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3493 | IL_ERR("trying to build beacon w/o beacon context!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3494 | return 0; |
| 3495 | } |
| 3496 | |
| 3497 | /* Initialize memory */ |
| 3498 | tx_beacon_cmd = &frame->u.beacon; |
| 3499 | memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); |
| 3500 | |
| 3501 | /* Set up TX beacon contents */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3502 | frame_size = |
| 3503 | il4965_fill_beacon_frame(il, tx_beacon_cmd->frame, |
| 3504 | sizeof(frame->u) - sizeof(*tx_beacon_cmd)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3505 | if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE)) |
| 3506 | return 0; |
| 3507 | if (!frame_size) |
| 3508 | return 0; |
| 3509 | |
| 3510 | /* Set up TX command fields */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3511 | tx_beacon_cmd->tx.len = cpu_to_le16((u16) frame_size); |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 3512 | tx_beacon_cmd->tx.sta_id = il->hw_params.bcast_id; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3513 | tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3514 | tx_beacon_cmd->tx.tx_flags = |
| 3515 | TX_CMD_FLG_SEQ_CTL_MSK | TX_CMD_FLG_TSF_MSK | |
| 3516 | TX_CMD_FLG_STA_RATE_MSK; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3517 | |
| 3518 | /* Set up TX beacon command fields */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3519 | il4965_set_beacon_tim(il, tx_beacon_cmd, (u8 *) tx_beacon_cmd->frame, |
| 3520 | frame_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3521 | |
| 3522 | /* Set up packet rate and flags */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3523 | rate = il_get_lowest_plcp(il, il->beacon_ctx); |
Stanislaw Gruszka | a0c1ef3 | 2011-12-23 08:13:44 +0100 | [diff] [blame] | 3524 | il4965_toggle_tx_ant(il, &il->mgmt_tx_ant, il->hw_params.valid_tx_ant); |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 3525 | rate_flags = BIT(il->mgmt_tx_ant) << RATE_MCS_ANT_POS; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3526 | if ((rate >= IL_FIRST_CCK_RATE) && (rate <= IL_LAST_CCK_RATE)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3527 | rate_flags |= RATE_MCS_CCK_MSK; |
Stanislaw Gruszka | 616107e | 2011-12-23 08:13:45 +0100 | [diff] [blame] | 3528 | tx_beacon_cmd->tx.rate_n_flags = cpu_to_le32(rate | rate_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3529 | |
| 3530 | return sizeof(*tx_beacon_cmd) + frame_size; |
| 3531 | } |
| 3532 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3533 | int |
| 3534 | il4965_send_beacon_cmd(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3535 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3536 | struct il_frame *frame; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3537 | unsigned int frame_size; |
| 3538 | int rc; |
| 3539 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3540 | frame = il4965_get_free_frame(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3541 | if (!frame) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3542 | IL_ERR("Could not obtain free frame buffer for beacon " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3543 | "command.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3544 | return -ENOMEM; |
| 3545 | } |
| 3546 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3547 | frame_size = il4965_hw_get_beacon_cmd(il, frame); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3548 | if (!frame_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3549 | IL_ERR("Error configuring the beacon command\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3550 | il4965_free_frame(il, frame); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3551 | return -EINVAL; |
| 3552 | } |
| 3553 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3554 | rc = il_send_cmd_pdu(il, C_TX_BEACON, frame_size, &frame->u.cmd[0]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3555 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3556 | il4965_free_frame(il, frame); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3557 | |
| 3558 | return rc; |
| 3559 | } |
| 3560 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3561 | static inline dma_addr_t |
| 3562 | il4965_tfd_tb_get_addr(struct il_tfd *tfd, u8 idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3563 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3564 | struct il_tfd_tb *tb = &tfd->tbs[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3565 | |
| 3566 | dma_addr_t addr = get_unaligned_le32(&tb->lo); |
| 3567 | if (sizeof(dma_addr_t) > sizeof(u32)) |
| 3568 | addr |= |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3569 | ((dma_addr_t) (le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << |
| 3570 | 16; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3571 | |
| 3572 | return addr; |
| 3573 | } |
| 3574 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3575 | static inline u16 |
| 3576 | il4965_tfd_tb_get_len(struct il_tfd *tfd, u8 idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3577 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3578 | struct il_tfd_tb *tb = &tfd->tbs[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3579 | |
| 3580 | return le16_to_cpu(tb->hi_n_len) >> 4; |
| 3581 | } |
| 3582 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3583 | static inline void |
| 3584 | il4965_tfd_set_tb(struct il_tfd *tfd, u8 idx, dma_addr_t addr, u16 len) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3585 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3586 | struct il_tfd_tb *tb = &tfd->tbs[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3587 | u16 hi_n_len = len << 4; |
| 3588 | |
| 3589 | put_unaligned_le32(addr, &tb->lo); |
| 3590 | if (sizeof(dma_addr_t) > sizeof(u32)) |
| 3591 | hi_n_len |= ((addr >> 16) >> 16) & 0xF; |
| 3592 | |
| 3593 | tb->hi_n_len = cpu_to_le16(hi_n_len); |
| 3594 | |
| 3595 | tfd->num_tbs = idx + 1; |
| 3596 | } |
| 3597 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3598 | static inline u8 |
| 3599 | il4965_tfd_get_num_tbs(struct il_tfd *tfd) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3600 | { |
| 3601 | return tfd->num_tbs & 0x1f; |
| 3602 | } |
| 3603 | |
| 3604 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3605 | * il4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr] |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3606 | * @il - driver ilate data |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3607 | * @txq - tx queue |
| 3608 | * |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3609 | * Does NOT advance any TFD circular buffer read/write idxes |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3610 | * Does NOT free the TFD itself (which is within circular buffer) |
| 3611 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3612 | void |
| 3613 | il4965_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3614 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3615 | struct il_tfd *tfd_tmp = (struct il_tfd *)txq->tfds; |
| 3616 | struct il_tfd *tfd; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3617 | struct pci_dev *dev = il->pci_dev; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3618 | int idx = txq->q.read_ptr; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3619 | int i; |
| 3620 | int num_tbs; |
| 3621 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3622 | tfd = &tfd_tmp[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3623 | |
| 3624 | /* Sanity check on number of chunks */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3625 | num_tbs = il4965_tfd_get_num_tbs(tfd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3626 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3627 | if (num_tbs >= IL_NUM_OF_TBS) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3628 | IL_ERR("Too many chunks: %i\n", num_tbs); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3629 | /* @todo issue fatal error, it is quite serious situation */ |
| 3630 | return; |
| 3631 | } |
| 3632 | |
| 3633 | /* Unmap tx_cmd */ |
| 3634 | if (num_tbs) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3635 | pci_unmap_single(dev, dma_unmap_addr(&txq->meta[idx], mapping), |
| 3636 | dma_unmap_len(&txq->meta[idx], len), |
| 3637 | PCI_DMA_BIDIRECTIONAL); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3638 | |
| 3639 | /* Unmap chunks, if any. */ |
| 3640 | for (i = 1; i < num_tbs; i++) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3641 | pci_unmap_single(dev, il4965_tfd_tb_get_addr(tfd, i), |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3642 | il4965_tfd_tb_get_len(tfd, i), |
| 3643 | PCI_DMA_TODEVICE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3644 | |
| 3645 | /* free SKB */ |
| 3646 | if (txq->txb) { |
| 3647 | struct sk_buff *skb; |
| 3648 | |
| 3649 | skb = txq->txb[txq->q.read_ptr].skb; |
| 3650 | |
| 3651 | /* can be called from irqs-disabled context */ |
| 3652 | if (skb) { |
| 3653 | dev_kfree_skb_any(skb); |
| 3654 | txq->txb[txq->q.read_ptr].skb = NULL; |
| 3655 | } |
| 3656 | } |
| 3657 | } |
| 3658 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3659 | int |
| 3660 | il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il, struct il_tx_queue *txq, |
| 3661 | dma_addr_t addr, u16 len, u8 reset, u8 pad) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3662 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3663 | struct il_queue *q; |
| 3664 | struct il_tfd *tfd, *tfd_tmp; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3665 | u32 num_tbs; |
| 3666 | |
| 3667 | q = &txq->q; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3668 | tfd_tmp = (struct il_tfd *)txq->tfds; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3669 | tfd = &tfd_tmp[q->write_ptr]; |
| 3670 | |
| 3671 | if (reset) |
| 3672 | memset(tfd, 0, sizeof(*tfd)); |
| 3673 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3674 | num_tbs = il4965_tfd_get_num_tbs(tfd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3675 | |
| 3676 | /* Each TFD can point to a maximum 20 Tx buffers */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3677 | if (num_tbs >= IL_NUM_OF_TBS) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3678 | IL_ERR("Error can not send more than %d chunks\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3679 | IL_NUM_OF_TBS); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3680 | return -EINVAL; |
| 3681 | } |
| 3682 | |
| 3683 | BUG_ON(addr & ~DMA_BIT_MASK(36)); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3684 | if (unlikely(addr & ~IL_TX_DMA_MASK)) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3685 | IL_ERR("Unaligned address = %llx\n", (unsigned long long)addr); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3686 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3687 | il4965_tfd_set_tb(tfd, num_tbs, addr, len); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3688 | |
| 3689 | return 0; |
| 3690 | } |
| 3691 | |
| 3692 | /* |
| 3693 | * Tell nic where to find circular buffer of Tx Frame Descriptors for |
| 3694 | * given Tx queue, and enable the DMA channel used for that queue. |
| 3695 | * |
| 3696 | * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA |
| 3697 | * channels supported in hardware. |
| 3698 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3699 | int |
| 3700 | il4965_hw_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3701 | { |
| 3702 | int txq_id = txq->q.id; |
| 3703 | |
| 3704 | /* Circular buffer (TFD queue in DRAM) physical base address */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3705 | il_wr(il, FH49_MEM_CBBC_QUEUE(txq_id), txq->q.dma_addr >> 8); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3706 | |
| 3707 | return 0; |
| 3708 | } |
| 3709 | |
| 3710 | /****************************************************************************** |
| 3711 | * |
| 3712 | * Generic RX handler implementations |
| 3713 | * |
| 3714 | ******************************************************************************/ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3715 | static void |
| 3716 | il4965_hdl_alive(struct il_priv *il, struct il_rx_buf *rxb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3717 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3718 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3719 | struct il_alive_resp *palive; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3720 | struct delayed_work *pwork; |
| 3721 | |
| 3722 | palive = &pkt->u.alive_frame; |
| 3723 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3724 | D_INFO("Alive ucode status 0x%08X revision " "0x%01X 0x%01X\n", |
| 3725 | palive->is_valid, palive->ver_type, palive->ver_subtype); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3726 | |
| 3727 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3728 | D_INFO("Initialization Alive received.\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3729 | memcpy(&il->card_alive_init, &pkt->u.alive_frame, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3730 | sizeof(struct il_init_alive_resp)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3731 | pwork = &il->init_alive_start; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3732 | } else { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3733 | D_INFO("Runtime Alive received.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3734 | memcpy(&il->card_alive, &pkt->u.alive_frame, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3735 | sizeof(struct il_alive_resp)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3736 | pwork = &il->alive_start; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | /* We delay the ALIVE response by 5ms to |
| 3740 | * give the HW RF Kill time to activate... */ |
| 3741 | if (palive->is_valid == UCODE_VALID_OK) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3742 | queue_delayed_work(il->workqueue, pwork, msecs_to_jiffies(5)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3743 | else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3744 | IL_WARN("uCode did not respond OK.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | /** |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3748 | * il4965_bg_stats_periodic - Timer callback to queue stats |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3749 | * |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3750 | * This callback is provided in order to send a stats request. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3751 | * |
| 3752 | * This timer function is continually reset to execute within |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 3753 | * REG_RECALIB_PERIOD seconds since the last N_STATS |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3754 | * was received. We need to ensure we receive the stats in order |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3755 | * to update the temperature used for calibrating the TXPOWER. |
| 3756 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3757 | static void |
| 3758 | il4965_bg_stats_periodic(unsigned long data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3759 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3760 | struct il_priv *il = (struct il_priv *)data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3761 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3762 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3763 | return; |
| 3764 | |
| 3765 | /* dont send host command if rf-kill is on */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3766 | if (!il_is_ready_rf(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3767 | return; |
| 3768 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3769 | il_send_stats_request(il, CMD_ASYNC, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3770 | } |
| 3771 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3772 | static void |
| 3773 | il4965_hdl_beacon(struct il_priv *il, struct il_rx_buf *rxb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3774 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3775 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3776 | struct il4965_beacon_notif *beacon = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3777 | (struct il4965_beacon_notif *)pkt->u.raw; |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 3778 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3779 | u8 rate = il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3780 | |
Stanislaw Gruszka | 5bf0dac | 2011-12-23 08:13:47 +0100 | [diff] [blame] | 3781 | D_RX("beacon status %x retries %d iss %d tsf:0x%.8x%.8x rate %d\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3782 | le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK, |
| 3783 | beacon->beacon_notify_hdr.failure_frame, |
| 3784 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3785 | le32_to_cpu(beacon->high_tsf), le32_to_cpu(beacon->low_tsf), rate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3786 | #endif |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3787 | il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3788 | } |
| 3789 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3790 | static void |
| 3791 | il4965_perform_ct_kill_task(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3792 | { |
| 3793 | unsigned long flags; |
| 3794 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3795 | D_POWER("Stop all queues\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3796 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3797 | if (il->mac80211_registered) |
| 3798 | ieee80211_stop_queues(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3799 | |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3800 | _il_wr(il, CSR_UCODE_DRV_GP1_SET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3801 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3802 | _il_rd(il, CSR_UCODE_DRV_GP1); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3803 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3804 | spin_lock_irqsave(&il->reg_lock, flags); |
Stanislaw Gruszka | 1388226 | 2011-08-24 15:39:23 +0200 | [diff] [blame] | 3805 | if (!_il_grab_nic_access(il)) |
| 3806 | _il_release_nic_access(il); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3807 | spin_unlock_irqrestore(&il->reg_lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | /* Handle notification from uCode that card's power state is changing |
| 3811 | * due to software, hardware, or critical temperature RFKILL */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3812 | static void |
| 3813 | il4965_hdl_card_state(struct il_priv *il, struct il_rx_buf *rxb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3814 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3815 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3816 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3817 | unsigned long status = il->status; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3818 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3819 | D_RF_KILL("Card state received: HW:%s SW:%s CT:%s\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3820 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3821 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", |
| 3822 | (flags & CT_CARD_DISABLED) ? "Reached" : "Not reached"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3823 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3824 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | CT_CARD_DISABLED)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3825 | |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3826 | _il_wr(il, CSR_UCODE_DRV_GP1_SET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3827 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3828 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3829 | il_wr(il, HBUS_TARG_MBX_C, HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3830 | |
| 3831 | if (!(flags & RXON_CARD_DISABLED)) { |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3832 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3833 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Stanislaw Gruszka | 0c1a94e | 2011-08-24 17:37:16 +0200 | [diff] [blame] | 3834 | il_wr(il, HBUS_TARG_MBX_C, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3835 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | if (flags & CT_CARD_DISABLED) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3840 | il4965_perform_ct_kill_task(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3841 | |
| 3842 | if (flags & HW_CARD_DISABLED) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3843 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3844 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3845 | clear_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3846 | |
| 3847 | if (!(flags & RXON_CARD_DISABLED)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3848 | il_scan_cancel(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3849 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3850 | if ((test_bit(S_RF_KILL_HW, &status) != |
| 3851 | test_bit(S_RF_KILL_HW, &il->status))) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3852 | wiphy_rfkill_set_hw_state(il->hw->wiphy, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3853 | test_bit(S_RF_KILL_HW, &il->status)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3854 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3855 | wake_up(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | /** |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3859 | * il4965_setup_handlers - Initialize Rx handler callbacks |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3860 | * |
| 3861 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3862 | * to the host. |
| 3863 | * |
| 3864 | * This function chains into the hardware specific files for them to setup |
| 3865 | * any hardware specific handlers as well. |
| 3866 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3867 | static void |
| 3868 | il4965_setup_handlers(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3869 | { |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 3870 | il->handlers[N_ALIVE] = il4965_hdl_alive; |
| 3871 | il->handlers[N_ERROR] = il_hdl_error; |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3872 | il->handlers[N_CHANNEL_SWITCH] = il_hdl_csa; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3873 | il->handlers[N_SPECTRUM_MEASUREMENT] = il_hdl_spectrum_measurement; |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3874 | il->handlers[N_PM_SLEEP] = il_hdl_pm_sleep; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3875 | il->handlers[N_PM_DEBUG_STATS] = il_hdl_pm_debug_stats; |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3876 | il->handlers[N_BEACON] = il4965_hdl_beacon; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3877 | |
| 3878 | /* |
| 3879 | * The same handler is used for both the REPLY to a discrete |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3880 | * stats request from the host as well as for the periodic |
| 3881 | * stats notifications (after received beacons) from the uCode. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3882 | */ |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3883 | il->handlers[C_STATS] = il4965_hdl_c_stats; |
| 3884 | il->handlers[N_STATS] = il4965_hdl_stats; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3885 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3886 | il_setup_rx_scan_handlers(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3887 | |
| 3888 | /* status change handler */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3889 | il->handlers[N_CARD_STATE] = il4965_hdl_card_state; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3890 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3891 | il->handlers[N_MISSED_BEACONS] = il4965_hdl_missed_beacon; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3892 | /* Rx handlers */ |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 3893 | il->handlers[N_RX_PHY] = il4965_hdl_rx_phy; |
| 3894 | il->handlers[N_RX_MPDU] = il4965_hdl_rx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3895 | /* block ack */ |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 3896 | il->handlers[N_COMPRESSED_BA] = il4965_hdl_compressed_ba; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3897 | /* Set up hardware specific Rx handlers */ |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3898 | il->cfg->ops->lib->handler_setup(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3902 | * il4965_rx_handle - Main entry function for receiving responses from uCode |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3903 | * |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3904 | * Uses the il->handlers callback function array to invoke |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3905 | * the appropriate handlers, including command responses, |
| 3906 | * frame-received notifications, and other notifications. |
| 3907 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3908 | void |
| 3909 | il4965_rx_handle(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3910 | { |
Stanislaw Gruszka | b73bb5f | 2011-08-26 14:37:54 +0200 | [diff] [blame] | 3911 | struct il_rx_buf *rxb; |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3912 | struct il_rx_pkt *pkt; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3913 | struct il_rx_queue *rxq = &il->rxq; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3914 | u32 r, i; |
| 3915 | int reclaim; |
| 3916 | unsigned long flags; |
| 3917 | u8 fill_rx = 0; |
| 3918 | u32 count = 8; |
| 3919 | int total_empty; |
| 3920 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3921 | /* uCode's read idx (stored in shared DRAM) indicates the last Rx |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3922 | * buffer that the driver may process (last buffer filled by ucode). */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3923 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3924 | i = rxq->read; |
| 3925 | |
| 3926 | /* Rx interrupt, but nothing sent from uCode */ |
| 3927 | if (i == r) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3928 | D_RX("r = %d, i = %d\n", r, i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3929 | |
| 3930 | /* calculate total frames need to be restock after handling RX */ |
| 3931 | total_empty = r - rxq->write_actual; |
| 3932 | if (total_empty < 0) |
| 3933 | total_empty += RX_QUEUE_SIZE; |
| 3934 | |
| 3935 | if (total_empty > (RX_QUEUE_SIZE / 2)) |
| 3936 | fill_rx = 1; |
| 3937 | |
| 3938 | while (i != r) { |
| 3939 | int len; |
| 3940 | |
| 3941 | rxb = rxq->queue[i]; |
| 3942 | |
| 3943 | /* If an RXB doesn't have a Rx queue slot associated with it, |
| 3944 | * then a bug has been introduced in the queue refilling |
| 3945 | * routines -- catch it here */ |
| 3946 | BUG_ON(rxb == NULL); |
| 3947 | |
| 3948 | rxq->queue[i] = NULL; |
| 3949 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3950 | pci_unmap_page(il->pci_dev, rxb->page_dma, |
| 3951 | PAGE_SIZE << il->hw_params.rx_page_order, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3952 | PCI_DMA_FROMDEVICE); |
| 3953 | pkt = rxb_addr(rxb); |
| 3954 | |
Stanislaw Gruszka | e94a409 | 2011-08-31 13:23:20 +0200 | [diff] [blame] | 3955 | len = le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3956 | len += sizeof(u32); /* account for status word */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3957 | |
| 3958 | /* Reclaim a command buffer only if this packet is a response |
| 3959 | * to a (driver-originated) command. |
| 3960 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3961 | * there is no command buffer to reclaim. |
| 3962 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3963 | * but apparently a few don't get set; catch them here. */ |
| 3964 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3965 | (pkt->hdr.cmd != N_RX_PHY) && (pkt->hdr.cmd != N_RX) && |
| 3966 | (pkt->hdr.cmd != N_RX_MPDU) && |
| 3967 | (pkt->hdr.cmd != N_COMPRESSED_BA) && |
| 3968 | (pkt->hdr.cmd != N_STATS) && (pkt->hdr.cmd != C_TX); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3969 | |
| 3970 | /* Based on type of command response or notification, |
| 3971 | * handle those that need handling via function in |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3972 | * handlers table. See il4965_setup_handlers() */ |
| 3973 | if (il->handlers[pkt->hdr.cmd]) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3974 | D_RX("r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3975 | il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3976 | il->isr_stats.handlers[pkt->hdr.cmd]++; |
| 3977 | il->handlers[pkt->hdr.cmd] (il, rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3978 | } else { |
| 3979 | /* No handling needed */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3980 | D_RX("r %d i %d No handler needed for %s, 0x%02x\n", r, |
| 3981 | i, il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | /* |
| 3985 | * XXX: After here, we should always check rxb->page |
| 3986 | * against NULL before touching it or its virtual |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3987 | * memory (pkt). Because some handler might have |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3988 | * already taken or freed the pages. |
| 3989 | */ |
| 3990 | |
| 3991 | if (reclaim) { |
| 3992 | /* Invoke any callbacks, transfer the buffer to caller, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3993 | * and fire off the (possibly) blocking il_send_cmd() |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3994 | * as we reclaim the driver command queue */ |
| 3995 | if (rxb->page) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3996 | il_tx_cmd_complete(il, rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3997 | else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3998 | IL_WARN("Claim null rxb?\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | /* Reuse the page if possible. For notification packets and |
| 4002 | * SKBs that fail to Rx correctly, add them back into the |
| 4003 | * rx_free list for reuse later. */ |
| 4004 | spin_lock_irqsave(&rxq->lock, flags); |
| 4005 | if (rxb->page != NULL) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4006 | rxb->page_dma = |
| 4007 | pci_map_page(il->pci_dev, rxb->page, 0, |
| 4008 | PAGE_SIZE << il->hw_params. |
| 4009 | rx_page_order, PCI_DMA_FROMDEVICE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4010 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4011 | rxq->free_count++; |
| 4012 | } else |
| 4013 | list_add_tail(&rxb->list, &rxq->rx_used); |
| 4014 | |
| 4015 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4016 | |
| 4017 | i = (i + 1) & RX_QUEUE_MASK; |
| 4018 | /* If there are a lot of unused frames, |
| 4019 | * restock the Rx queue so ucode wont assert. */ |
| 4020 | if (fill_rx) { |
| 4021 | count++; |
| 4022 | if (count >= 8) { |
| 4023 | rxq->read = i; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4024 | il4965_rx_replenish_now(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4025 | count = 0; |
| 4026 | } |
| 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | /* Backtrack one entry */ |
| 4031 | rxq->read = i; |
| 4032 | if (fill_rx) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4033 | il4965_rx_replenish_now(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4034 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4035 | il4965_rx_queue_restock(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | /* call this function to flush any scheduled tasklet */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4039 | static inline void |
| 4040 | il4965_synchronize_irq(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4041 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4042 | /* wait to make sure we flush pending tasklet */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4043 | synchronize_irq(il->pci_dev->irq); |
| 4044 | tasklet_kill(&il->irq_tasklet); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4045 | } |
| 4046 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4047 | static void |
| 4048 | il4965_irq_tasklet(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4049 | { |
| 4050 | u32 inta, handled = 0; |
| 4051 | u32 inta_fh; |
| 4052 | unsigned long flags; |
| 4053 | u32 i; |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4054 | #ifdef CONFIG_IWLEGACY_DEBUG |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4055 | u32 inta_mask; |
| 4056 | #endif |
| 4057 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4058 | spin_lock_irqsave(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4059 | |
| 4060 | /* Ack/clear/reset pending uCode interrupts. |
| 4061 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4062 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4063 | inta = _il_rd(il, CSR_INT); |
| 4064 | _il_wr(il, CSR_INT, inta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4065 | |
| 4066 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4067 | * Any new interrupts that happen after this, either while we're |
| 4068 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4069 | inta_fh = _il_rd(il, CSR_FH_INT_STATUS); |
| 4070 | _il_wr(il, CSR_FH_INT_STATUS, inta_fh); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4071 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4072 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4073 | if (il_get_debug_level(il) & IL_DL_ISR) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4074 | /* just for debug */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4075 | inta_mask = _il_rd(il, CSR_INT_MASK); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4076 | D_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta, |
| 4077 | inta_mask, inta_fh); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4078 | } |
| 4079 | #endif |
| 4080 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4081 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4082 | |
| 4083 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4084 | * atomic, make sure that inta covers all the interrupts that |
| 4085 | * we've discovered, even if FH interrupt came in just after |
| 4086 | * reading CSR_INT. */ |
| 4087 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
| 4088 | inta |= CSR_INT_BIT_FH_RX; |
| 4089 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
| 4090 | inta |= CSR_INT_BIT_FH_TX; |
| 4091 | |
| 4092 | /* Now service all interrupt bits discovered above. */ |
| 4093 | if (inta & CSR_INT_BIT_HW_ERR) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4094 | IL_ERR("Hardware error detected. Restarting.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4095 | |
| 4096 | /* Tell the device to stop sending interrupts */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4097 | il_disable_interrupts(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4098 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4099 | il->isr_stats.hw++; |
| 4100 | il_irq_handle_error(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4101 | |
| 4102 | handled |= CSR_INT_BIT_HW_ERR; |
| 4103 | |
| 4104 | return; |
| 4105 | } |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4106 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4107 | if (il_get_debug_level(il) & (IL_DL_ISR)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4108 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 4109 | if (inta & CSR_INT_BIT_SCD) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4110 | D_ISR("Scheduler finished to transmit " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4111 | "the frame/frames.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4112 | il->isr_stats.sch++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | /* Alive notification via Rx interrupt will do the real work */ |
| 4116 | if (inta & CSR_INT_BIT_ALIVE) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4117 | D_ISR("Alive interrupt\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4118 | il->isr_stats.alive++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4119 | } |
| 4120 | } |
| 4121 | #endif |
| 4122 | /* Safely ignore these bits for debug checks below */ |
| 4123 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
| 4124 | |
| 4125 | /* HW RF KILL switch toggled */ |
| 4126 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 4127 | int hw_rf_kill = 0; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4128 | if (! |
| 4129 | (_il_rd(il, CSR_GP_CNTRL) & |
| 4130 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4131 | hw_rf_kill = 1; |
| 4132 | |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4133 | IL_WARN("RF_KILL bit toggled to %s.\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4134 | hw_rf_kill ? "disable radio" : "enable radio"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4135 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4136 | il->isr_stats.rfkill++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4137 | |
| 4138 | /* driver only loads ucode once setting the interface up. |
| 4139 | * the driver allows loading the ucode even if the radio |
| 4140 | * is killed. Hence update the killswitch state here. The |
| 4141 | * rfkill handler will care about restarting if needed. |
| 4142 | */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4143 | if (!test_bit(S_ALIVE, &il->status)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4144 | if (hw_rf_kill) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4145 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4146 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4147 | clear_bit(S_RF_KILL_HW, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4148 | wiphy_rfkill_set_hw_state(il->hw->wiphy, hw_rf_kill); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | handled |= CSR_INT_BIT_RF_KILL; |
| 4152 | } |
| 4153 | |
| 4154 | /* Chip got too hot and stopped itself */ |
| 4155 | if (inta & CSR_INT_BIT_CT_KILL) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4156 | IL_ERR("Microcode CT kill error detected.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4157 | il->isr_stats.ctkill++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4158 | handled |= CSR_INT_BIT_CT_KILL; |
| 4159 | } |
| 4160 | |
| 4161 | /* Error detected by uCode */ |
| 4162 | if (inta & CSR_INT_BIT_SW_ERR) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4163 | IL_ERR("Microcode SW error detected. " " Restarting 0x%X.\n", |
| 4164 | inta); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4165 | il->isr_stats.sw++; |
| 4166 | il_irq_handle_error(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4167 | handled |= CSR_INT_BIT_SW_ERR; |
| 4168 | } |
| 4169 | |
| 4170 | /* |
| 4171 | * uCode wakes up after power-down sleep. |
| 4172 | * Tell device about any new tx or host commands enqueued, |
| 4173 | * and about any Rx buffers made available while asleep. |
| 4174 | */ |
| 4175 | if (inta & CSR_INT_BIT_WAKEUP) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4176 | D_ISR("Wakeup interrupt\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4177 | il_rx_queue_update_write_ptr(il, &il->rxq); |
| 4178 | for (i = 0; i < il->hw_params.max_txq_num; i++) |
| 4179 | il_txq_update_write_ptr(il, &il->txq[i]); |
| 4180 | il->isr_stats.wakeup++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4181 | handled |= CSR_INT_BIT_WAKEUP; |
| 4182 | } |
| 4183 | |
| 4184 | /* All uCode command responses, including Tx command responses, |
| 4185 | * Rx "responses" (frame-received notification), and other |
| 4186 | * notifications from uCode come through here*/ |
| 4187 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4188 | il4965_rx_handle(il); |
| 4189 | il->isr_stats.rx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4190 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 4191 | } |
| 4192 | |
| 4193 | /* This "Tx" DMA channel is used only for loading uCode */ |
| 4194 | if (inta & CSR_INT_BIT_FH_TX) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4195 | D_ISR("uCode load interrupt\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4196 | il->isr_stats.tx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4197 | handled |= CSR_INT_BIT_FH_TX; |
| 4198 | /* Wake up uCode load routine, now that load is complete */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4199 | il->ucode_write_complete = 1; |
| 4200 | wake_up(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | if (inta & ~handled) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4204 | IL_ERR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4205 | il->isr_stats.unhandled++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4206 | } |
| 4207 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4208 | if (inta & ~(il->inta_mask)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4209 | IL_WARN("Disabled INTA bits 0x%08x were pending\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4210 | inta & ~il->inta_mask); |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 4211 | IL_WARN(" with FH49_INT = 0x%08x\n", inta_fh); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | /* Re-enable all interrupts */ |
Stanislaw Gruszka | 93fd74e | 2011-04-28 11:51:30 +0200 | [diff] [blame] | 4215 | /* only Re-enable if disabled by irq */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4216 | if (test_bit(S_INT_ENABLED, &il->status)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4217 | il_enable_interrupts(il); |
Stanislaw Gruszka | a078a1f | 2011-04-28 11:51:25 +0200 | [diff] [blame] | 4218 | /* Re-enable RF_KILL if it occurred */ |
| 4219 | else if (handled & CSR_INT_BIT_RF_KILL) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4220 | il_enable_rfkill_int(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4221 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4222 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4223 | if (il_get_debug_level(il) & (IL_DL_ISR)) { |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4224 | inta = _il_rd(il, CSR_INT); |
| 4225 | inta_mask = _il_rd(il, CSR_INT_MASK); |
| 4226 | inta_fh = _il_rd(il, CSR_FH_INT_STATUS); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4227 | D_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4228 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4229 | } |
| 4230 | #endif |
| 4231 | } |
| 4232 | |
| 4233 | /***************************************************************************** |
| 4234 | * |
| 4235 | * sysfs attributes |
| 4236 | * |
| 4237 | *****************************************************************************/ |
| 4238 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4239 | #ifdef CONFIG_IWLEGACY_DEBUG |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4240 | |
| 4241 | /* |
| 4242 | * The following adds a new attribute to the sysfs representation |
| 4243 | * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/) |
| 4244 | * used for controlling the debug level. |
| 4245 | * |
| 4246 | * See the level definitions in iwl for details. |
| 4247 | * |
| 4248 | * The debug_level being managed using sysfs below is a per device debug |
| 4249 | * level that is used instead of the global debug level if it (the per |
| 4250 | * device debug level) is set. |
| 4251 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4252 | static ssize_t |
| 4253 | il4965_show_debug_level(struct device *d, struct device_attribute *attr, |
| 4254 | char *buf) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4255 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4256 | struct il_priv *il = dev_get_drvdata(d); |
| 4257 | return sprintf(buf, "0x%08X\n", il_get_debug_level(il)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4258 | } |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4259 | |
| 4260 | static ssize_t |
| 4261 | il4965_store_debug_level(struct device *d, struct device_attribute *attr, |
| 4262 | const char *buf, size_t count) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4263 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4264 | struct il_priv *il = dev_get_drvdata(d); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4265 | unsigned long val; |
| 4266 | int ret; |
| 4267 | |
| 4268 | ret = strict_strtoul(buf, 0, &val); |
| 4269 | if (ret) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4270 | IL_ERR("%s is not in hex or decimal form.\n", buf); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4271 | else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4272 | il->debug_level = val; |
| 4273 | if (il_alloc_traffic_mem(il)) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4274 | IL_ERR("Not enough memory to generate traffic log\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4275 | } |
| 4276 | return strnlen(buf, count); |
| 4277 | } |
| 4278 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4279 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, il4965_show_debug_level, |
| 4280 | il4965_store_debug_level); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4281 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4282 | #endif /* CONFIG_IWLEGACY_DEBUG */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4283 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4284 | static ssize_t |
| 4285 | il4965_show_temperature(struct device *d, struct device_attribute *attr, |
| 4286 | char *buf) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4287 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4288 | struct il_priv *il = dev_get_drvdata(d); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4289 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4290 | if (!il_is_alive(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4291 | return -EAGAIN; |
| 4292 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4293 | return sprintf(buf, "%d\n", il->temperature); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4294 | } |
| 4295 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4296 | static DEVICE_ATTR(temperature, S_IRUGO, il4965_show_temperature, NULL); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4297 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4298 | static ssize_t |
| 4299 | il4965_show_tx_power(struct device *d, struct device_attribute *attr, char *buf) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4300 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4301 | struct il_priv *il = dev_get_drvdata(d); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4302 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4303 | if (!il_is_ready_rf(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4304 | return sprintf(buf, "off\n"); |
| 4305 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4306 | return sprintf(buf, "%d\n", il->tx_power_user_lmt); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4307 | } |
| 4308 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4309 | static ssize_t |
| 4310 | il4965_store_tx_power(struct device *d, struct device_attribute *attr, |
| 4311 | const char *buf, size_t count) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4312 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4313 | struct il_priv *il = dev_get_drvdata(d); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4314 | unsigned long val; |
| 4315 | int ret; |
| 4316 | |
| 4317 | ret = strict_strtoul(buf, 10, &val); |
| 4318 | if (ret) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4319 | IL_INFO("%s is not in decimal form.\n", buf); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4320 | else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4321 | ret = il_set_tx_power(il, val, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4322 | if (ret) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4323 | IL_ERR("failed setting tx power (0x%d).\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4324 | else |
| 4325 | ret = count; |
| 4326 | } |
| 4327 | return ret; |
| 4328 | } |
| 4329 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4330 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, il4965_show_tx_power, |
| 4331 | il4965_store_tx_power); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4332 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4333 | static struct attribute *il_sysfs_entries[] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4334 | &dev_attr_temperature.attr, |
| 4335 | &dev_attr_tx_power.attr, |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4336 | #ifdef CONFIG_IWLEGACY_DEBUG |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4337 | &dev_attr_debug_level.attr, |
| 4338 | #endif |
| 4339 | NULL |
| 4340 | }; |
| 4341 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4342 | static struct attribute_group il_attribute_group = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4343 | .name = NULL, /* put in device directory */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4344 | .attrs = il_sysfs_entries, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4345 | }; |
| 4346 | |
| 4347 | /****************************************************************************** |
| 4348 | * |
| 4349 | * uCode download functions |
| 4350 | * |
| 4351 | ******************************************************************************/ |
| 4352 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4353 | static void |
| 4354 | il4965_dealloc_ucode_pci(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4355 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4356 | il_free_fw_desc(il->pci_dev, &il->ucode_code); |
| 4357 | il_free_fw_desc(il->pci_dev, &il->ucode_data); |
| 4358 | il_free_fw_desc(il->pci_dev, &il->ucode_data_backup); |
| 4359 | il_free_fw_desc(il->pci_dev, &il->ucode_init); |
| 4360 | il_free_fw_desc(il->pci_dev, &il->ucode_init_data); |
| 4361 | il_free_fw_desc(il->pci_dev, &il->ucode_boot); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4362 | } |
| 4363 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4364 | static void |
| 4365 | il4965_nic_start(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4366 | { |
| 4367 | /* Remove all resets to allow NIC to operate */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4368 | _il_wr(il, CSR_RESET, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4369 | } |
| 4370 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4371 | static void il4965_ucode_callback(const struct firmware *ucode_raw, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4372 | void *context); |
| 4373 | static int il4965_mac_setup_register(struct il_priv *il, u32 max_probe_length); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4374 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4375 | static int __must_check |
| 4376 | il4965_request_firmware(struct il_priv *il, bool first) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4377 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4378 | const char *name_pre = il->cfg->fw_name_pre; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4379 | char tag[8]; |
| 4380 | |
| 4381 | if (first) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4382 | il->fw_idx = il->cfg->ucode_api_max; |
| 4383 | sprintf(tag, "%d", il->fw_idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4384 | } else { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4385 | il->fw_idx--; |
| 4386 | sprintf(tag, "%d", il->fw_idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4387 | } |
| 4388 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4389 | if (il->fw_idx < il->cfg->ucode_api_min) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4390 | IL_ERR("no suitable firmware found!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4391 | return -ENOENT; |
| 4392 | } |
| 4393 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4394 | sprintf(il->firmware_name, "%s%s%s", name_pre, tag, ".ucode"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4395 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4396 | D_INFO("attempting to load firmware '%s'\n", il->firmware_name); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4397 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4398 | return request_firmware_nowait(THIS_MODULE, 1, il->firmware_name, |
| 4399 | &il->pci_dev->dev, GFP_KERNEL, il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4400 | il4965_ucode_callback); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4401 | } |
| 4402 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4403 | struct il4965_firmware_pieces { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4404 | const void *inst, *data, *init, *init_data, *boot; |
| 4405 | size_t inst_size, data_size, init_size, init_data_size, boot_size; |
| 4406 | }; |
| 4407 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4408 | static int |
| 4409 | il4965_load_firmware(struct il_priv *il, const struct firmware *ucode_raw, |
| 4410 | struct il4965_firmware_pieces *pieces) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4411 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4412 | struct il_ucode_header *ucode = (void *)ucode_raw->data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4413 | u32 api_ver, hdr_size; |
| 4414 | const u8 *src; |
| 4415 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4416 | il->ucode_ver = le32_to_cpu(ucode->ver); |
| 4417 | api_ver = IL_UCODE_API(il->ucode_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4418 | |
| 4419 | switch (api_ver) { |
| 4420 | default: |
| 4421 | case 0: |
| 4422 | case 1: |
| 4423 | case 2: |
| 4424 | hdr_size = 24; |
| 4425 | if (ucode_raw->size < hdr_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4426 | IL_ERR("File size too small!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4427 | return -EINVAL; |
| 4428 | } |
| 4429 | pieces->inst_size = le32_to_cpu(ucode->v1.inst_size); |
| 4430 | pieces->data_size = le32_to_cpu(ucode->v1.data_size); |
| 4431 | pieces->init_size = le32_to_cpu(ucode->v1.init_size); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4432 | pieces->init_data_size = le32_to_cpu(ucode->v1.init_data_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4433 | pieces->boot_size = le32_to_cpu(ucode->v1.boot_size); |
| 4434 | src = ucode->v1.data; |
| 4435 | break; |
| 4436 | } |
| 4437 | |
| 4438 | /* Verify size of file vs. image size info in file's header */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4439 | if (ucode_raw->size != |
| 4440 | hdr_size + pieces->inst_size + pieces->data_size + |
| 4441 | pieces->init_size + pieces->init_data_size + pieces->boot_size) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4442 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4443 | IL_ERR("uCode file size %d does not match expected size\n", |
| 4444 | (int)ucode_raw->size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4445 | return -EINVAL; |
| 4446 | } |
| 4447 | |
| 4448 | pieces->inst = src; |
| 4449 | src += pieces->inst_size; |
| 4450 | pieces->data = src; |
| 4451 | src += pieces->data_size; |
| 4452 | pieces->init = src; |
| 4453 | src += pieces->init_size; |
| 4454 | pieces->init_data = src; |
| 4455 | src += pieces->init_data_size; |
| 4456 | pieces->boot = src; |
| 4457 | src += pieces->boot_size; |
| 4458 | |
| 4459 | return 0; |
| 4460 | } |
| 4461 | |
| 4462 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4463 | * il4965_ucode_callback - callback when firmware was loaded |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4464 | * |
| 4465 | * If loaded successfully, copies the firmware into buffers |
| 4466 | * for the card to fetch (via DMA). |
| 4467 | */ |
| 4468 | static void |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4469 | il4965_ucode_callback(const struct firmware *ucode_raw, void *context) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4470 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4471 | struct il_priv *il = context; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4472 | struct il_ucode_header *ucode; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4473 | int err; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4474 | struct il4965_firmware_pieces pieces; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4475 | const unsigned int api_max = il->cfg->ucode_api_max; |
| 4476 | const unsigned int api_min = il->cfg->ucode_api_min; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4477 | u32 api_ver; |
| 4478 | |
| 4479 | u32 max_probe_length = 200; |
| 4480 | u32 standard_phy_calibration_size = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4481 | IL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4482 | |
| 4483 | memset(&pieces, 0, sizeof(pieces)); |
| 4484 | |
| 4485 | if (!ucode_raw) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4486 | if (il->fw_idx <= il->cfg->ucode_api_max) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4487 | IL_ERR("request for firmware file '%s' failed.\n", |
| 4488 | il->firmware_name); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4489 | goto try_again; |
| 4490 | } |
| 4491 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4492 | D_INFO("Loaded firmware file '%s' (%zd bytes).\n", il->firmware_name, |
| 4493 | ucode_raw->size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4494 | |
| 4495 | /* Make sure that we got at least the API version number */ |
| 4496 | if (ucode_raw->size < 4) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4497 | IL_ERR("File size way too small!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4498 | goto try_again; |
| 4499 | } |
| 4500 | |
| 4501 | /* Data from ucode file: header followed by uCode images */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4502 | ucode = (struct il_ucode_header *)ucode_raw->data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4503 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4504 | err = il4965_load_firmware(il, ucode_raw, &pieces); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4505 | |
| 4506 | if (err) |
| 4507 | goto try_again; |
| 4508 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4509 | api_ver = IL_UCODE_API(il->ucode_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4510 | |
| 4511 | /* |
| 4512 | * api_ver should match the api version forming part of the |
| 4513 | * firmware filename ... but we don't check for that and only rely |
| 4514 | * on the API version read from firmware header from here on forward |
| 4515 | */ |
| 4516 | if (api_ver < api_min || api_ver > api_max) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4517 | IL_ERR("Driver unable to support your firmware API. " |
| 4518 | "Driver supports v%u, firmware is v%u.\n", api_max, |
| 4519 | api_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4520 | goto try_again; |
| 4521 | } |
| 4522 | |
| 4523 | if (api_ver != api_max) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4524 | IL_ERR("Firmware has old API version. Expected v%u, " |
| 4525 | "got v%u. New firmware can be obtained " |
| 4526 | "from http://www.intellinuxwireless.org.\n", api_max, |
| 4527 | api_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4528 | |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4529 | IL_INFO("loaded firmware version %u.%u.%u.%u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4530 | IL_UCODE_MAJOR(il->ucode_ver), IL_UCODE_MINOR(il->ucode_ver), |
| 4531 | IL_UCODE_API(il->ucode_ver), IL_UCODE_SERIAL(il->ucode_ver)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4532 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4533 | snprintf(il->hw->wiphy->fw_version, sizeof(il->hw->wiphy->fw_version), |
| 4534 | "%u.%u.%u.%u", IL_UCODE_MAJOR(il->ucode_ver), |
| 4535 | IL_UCODE_MINOR(il->ucode_ver), IL_UCODE_API(il->ucode_ver), |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4536 | IL_UCODE_SERIAL(il->ucode_ver)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4537 | |
| 4538 | /* |
| 4539 | * For any of the failures below (before allocating pci memory) |
| 4540 | * we will try to load a version with a smaller API -- maybe the |
| 4541 | * user just got a corrupted version of the latest API. |
| 4542 | */ |
| 4543 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4544 | D_INFO("f/w package hdr ucode version raw = 0x%x\n", il->ucode_ver); |
| 4545 | D_INFO("f/w package hdr runtime inst size = %Zd\n", pieces.inst_size); |
| 4546 | D_INFO("f/w package hdr runtime data size = %Zd\n", pieces.data_size); |
| 4547 | D_INFO("f/w package hdr init inst size = %Zd\n", pieces.init_size); |
| 4548 | D_INFO("f/w package hdr init data size = %Zd\n", pieces.init_data_size); |
| 4549 | D_INFO("f/w package hdr boot inst size = %Zd\n", pieces.boot_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4550 | |
| 4551 | /* Verify that uCode images will fit in card's SRAM */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4552 | if (pieces.inst_size > il->hw_params.max_inst_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4553 | IL_ERR("uCode instr len %Zd too large to fit in\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4554 | pieces.inst_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4555 | goto try_again; |
| 4556 | } |
| 4557 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4558 | if (pieces.data_size > il->hw_params.max_data_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4559 | IL_ERR("uCode data len %Zd too large to fit in\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4560 | pieces.data_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4561 | goto try_again; |
| 4562 | } |
| 4563 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4564 | if (pieces.init_size > il->hw_params.max_inst_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4565 | IL_ERR("uCode init instr len %Zd too large to fit in\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4566 | pieces.init_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4567 | goto try_again; |
| 4568 | } |
| 4569 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4570 | if (pieces.init_data_size > il->hw_params.max_data_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4571 | IL_ERR("uCode init data len %Zd too large to fit in\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4572 | pieces.init_data_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4573 | goto try_again; |
| 4574 | } |
| 4575 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4576 | if (pieces.boot_size > il->hw_params.max_bsm_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4577 | IL_ERR("uCode boot instr len %Zd too large to fit in\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4578 | pieces.boot_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4579 | goto try_again; |
| 4580 | } |
| 4581 | |
| 4582 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4583 | |
| 4584 | /* Runtime instructions and 2 copies of data: |
| 4585 | * 1) unmodified from disk |
| 4586 | * 2) backup cache for save/restore during power-downs */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4587 | il->ucode_code.len = pieces.inst_size; |
| 4588 | il_alloc_fw_desc(il->pci_dev, &il->ucode_code); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4589 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4590 | il->ucode_data.len = pieces.data_size; |
| 4591 | il_alloc_fw_desc(il->pci_dev, &il->ucode_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4592 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4593 | il->ucode_data_backup.len = pieces.data_size; |
| 4594 | il_alloc_fw_desc(il->pci_dev, &il->ucode_data_backup); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4595 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4596 | if (!il->ucode_code.v_addr || !il->ucode_data.v_addr || |
| 4597 | !il->ucode_data_backup.v_addr) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4598 | goto err_pci_alloc; |
| 4599 | |
| 4600 | /* Initialization instructions and data */ |
| 4601 | if (pieces.init_size && pieces.init_data_size) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4602 | il->ucode_init.len = pieces.init_size; |
| 4603 | il_alloc_fw_desc(il->pci_dev, &il->ucode_init); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4604 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4605 | il->ucode_init_data.len = pieces.init_data_size; |
| 4606 | il_alloc_fw_desc(il->pci_dev, &il->ucode_init_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4607 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4608 | if (!il->ucode_init.v_addr || !il->ucode_init_data.v_addr) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4609 | goto err_pci_alloc; |
| 4610 | } |
| 4611 | |
| 4612 | /* Bootstrap (instructions only, no data) */ |
| 4613 | if (pieces.boot_size) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4614 | il->ucode_boot.len = pieces.boot_size; |
| 4615 | il_alloc_fw_desc(il->pci_dev, &il->ucode_boot); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4616 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4617 | if (!il->ucode_boot.v_addr) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4618 | goto err_pci_alloc; |
| 4619 | } |
| 4620 | |
| 4621 | /* Now that we can no longer fail, copy information */ |
| 4622 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4623 | il->sta_key_max_num = STA_KEY_MAX_NUM; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4624 | |
| 4625 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4626 | |
| 4627 | /* Runtime instructions (first block of data in file) */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4628 | D_INFO("Copying (but not loading) uCode instr len %Zd\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4629 | pieces.inst_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4630 | memcpy(il->ucode_code.v_addr, pieces.inst, pieces.inst_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4631 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4632 | D_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4633 | il->ucode_code.v_addr, (u32) il->ucode_code.p_addr); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4634 | |
| 4635 | /* |
| 4636 | * Runtime data |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4637 | * NOTE: Copy into backup buffer will be done in il_up() |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4638 | */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4639 | D_INFO("Copying (but not loading) uCode data len %Zd\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4640 | pieces.data_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4641 | memcpy(il->ucode_data.v_addr, pieces.data, pieces.data_size); |
| 4642 | memcpy(il->ucode_data_backup.v_addr, pieces.data, pieces.data_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4643 | |
| 4644 | /* Initialization instructions */ |
| 4645 | if (pieces.init_size) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4646 | D_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4647 | pieces.init_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4648 | memcpy(il->ucode_init.v_addr, pieces.init, pieces.init_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | /* Initialization data */ |
| 4652 | if (pieces.init_data_size) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4653 | D_INFO("Copying (but not loading) init data len %Zd\n", |
| 4654 | pieces.init_data_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4655 | memcpy(il->ucode_init_data.v_addr, pieces.init_data, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4656 | pieces.init_data_size); |
| 4657 | } |
| 4658 | |
| 4659 | /* Bootstrap instructions */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4660 | D_INFO("Copying (but not loading) boot instr len %Zd\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4661 | pieces.boot_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4662 | memcpy(il->ucode_boot.v_addr, pieces.boot, pieces.boot_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4663 | |
| 4664 | /* |
| 4665 | * figure out the offset of chain noise reset and gain commands |
| 4666 | * base on the size of standard phy calibration commands table size |
| 4667 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4668 | il->_4965.phy_calib_chain_noise_reset_cmd = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4669 | standard_phy_calibration_size; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4670 | il->_4965.phy_calib_chain_noise_gain_cmd = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4671 | standard_phy_calibration_size + 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4672 | |
| 4673 | /************************************************** |
| 4674 | * This is still part of probe() in a sense... |
| 4675 | * |
| 4676 | * 9. Setup and register with mac80211 and debugfs |
| 4677 | **************************************************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4678 | err = il4965_mac_setup_register(il, max_probe_length); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4679 | if (err) |
| 4680 | goto out_unbind; |
| 4681 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4682 | err = il_dbgfs_register(il, DRV_NAME); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4683 | if (err) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4684 | IL_ERR("failed to create debugfs files. Ignoring error: %d\n", |
| 4685 | err); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4686 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4687 | err = sysfs_create_group(&il->pci_dev->dev.kobj, &il_attribute_group); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4688 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4689 | IL_ERR("failed to create sysfs device attributes\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4690 | goto out_unbind; |
| 4691 | } |
| 4692 | |
| 4693 | /* We have our copies now, allow OS release its copies */ |
| 4694 | release_firmware(ucode_raw); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4695 | complete(&il->_4965.firmware_loading_complete); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4696 | return; |
| 4697 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4698 | try_again: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4699 | /* try next, if any */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4700 | if (il4965_request_firmware(il, false)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4701 | goto out_unbind; |
| 4702 | release_firmware(ucode_raw); |
| 4703 | return; |
| 4704 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4705 | err_pci_alloc: |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4706 | IL_ERR("failed to allocate pci memory\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4707 | il4965_dealloc_ucode_pci(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4708 | out_unbind: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4709 | complete(&il->_4965.firmware_loading_complete); |
| 4710 | device_release_driver(&il->pci_dev->dev); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4711 | release_firmware(ucode_raw); |
| 4712 | } |
| 4713 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4714 | static const char *const desc_lookup_text[] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4715 | "OK", |
| 4716 | "FAIL", |
| 4717 | "BAD_PARAM", |
| 4718 | "BAD_CHECKSUM", |
| 4719 | "NMI_INTERRUPT_WDG", |
| 4720 | "SYSASSERT", |
| 4721 | "FATAL_ERROR", |
| 4722 | "BAD_COMMAND", |
| 4723 | "HW_ERROR_TUNE_LOCK", |
| 4724 | "HW_ERROR_TEMPERATURE", |
| 4725 | "ILLEGAL_CHAN_FREQ", |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 4726 | "VCC_NOT_STBL", |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 4727 | "FH49_ERROR", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4728 | "NMI_INTERRUPT_HOST", |
| 4729 | "NMI_INTERRUPT_ACTION_PT", |
| 4730 | "NMI_INTERRUPT_UNKNOWN", |
| 4731 | "UCODE_VERSION_MISMATCH", |
| 4732 | "HW_ERROR_ABS_LOCK", |
| 4733 | "HW_ERROR_CAL_LOCK_FAIL", |
| 4734 | "NMI_INTERRUPT_INST_ACTION_PT", |
| 4735 | "NMI_INTERRUPT_DATA_ACTION_PT", |
| 4736 | "NMI_TRM_HW_ER", |
| 4737 | "NMI_INTERRUPT_TRM", |
Joe Perches | 861d9c3 | 2011-07-08 23:20:24 -0700 | [diff] [blame] | 4738 | "NMI_INTERRUPT_BREAK_POINT", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4739 | "DEBUG_0", |
| 4740 | "DEBUG_1", |
| 4741 | "DEBUG_2", |
| 4742 | "DEBUG_3", |
| 4743 | }; |
| 4744 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4745 | static struct { |
| 4746 | char *name; |
| 4747 | u8 num; |
| 4748 | } advanced_lookup[] = { |
| 4749 | { |
| 4750 | "NMI_INTERRUPT_WDG", 0x34}, { |
| 4751 | "SYSASSERT", 0x35}, { |
| 4752 | "UCODE_VERSION_MISMATCH", 0x37}, { |
| 4753 | "BAD_COMMAND", 0x38}, { |
| 4754 | "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C}, { |
| 4755 | "FATAL_ERROR", 0x3D}, { |
| 4756 | "NMI_TRM_HW_ERR", 0x46}, { |
| 4757 | "NMI_INTERRUPT_TRM", 0x4C}, { |
| 4758 | "NMI_INTERRUPT_BREAK_POINT", 0x54}, { |
| 4759 | "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C}, { |
| 4760 | "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64}, { |
| 4761 | "NMI_INTERRUPT_HOST", 0x66}, { |
| 4762 | "NMI_INTERRUPT_ACTION_PT", 0x7C}, { |
| 4763 | "NMI_INTERRUPT_UNKNOWN", 0x84}, { |
| 4764 | "NMI_INTERRUPT_INST_ACTION_PT", 0x86}, { |
| 4765 | "ADVANCED_SYSASSERT", 0},}; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4766 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4767 | static const char * |
| 4768 | il4965_desc_lookup(u32 num) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4769 | { |
| 4770 | int i; |
| 4771 | int max = ARRAY_SIZE(desc_lookup_text); |
| 4772 | |
| 4773 | if (num < max) |
| 4774 | return desc_lookup_text[num]; |
| 4775 | |
| 4776 | max = ARRAY_SIZE(advanced_lookup) - 1; |
| 4777 | for (i = 0; i < max; i++) { |
| 4778 | if (advanced_lookup[i].num == num) |
| 4779 | break; |
| 4780 | } |
| 4781 | return advanced_lookup[i].name; |
| 4782 | } |
| 4783 | |
| 4784 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4785 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4786 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4787 | void |
| 4788 | il4965_dump_nic_error_log(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4789 | { |
| 4790 | u32 data2, line; |
| 4791 | u32 desc, time, count, base, data1; |
| 4792 | u32 blink1, blink2, ilink1, ilink2; |
| 4793 | u32 pc, hcmd; |
| 4794 | |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 4795 | if (il->ucode_type == UCODE_INIT) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4796 | base = le32_to_cpu(il->card_alive_init.error_event_table_ptr); |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 4797 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4798 | base = le32_to_cpu(il->card_alive.error_event_table_ptr); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4799 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4800 | if (!il->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4801 | IL_ERR("Not valid error log pointer 0x%08X for %s uCode\n", |
| 4802 | base, (il->ucode_type == UCODE_INIT) ? "Init" : "RT"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4803 | return; |
| 4804 | } |
| 4805 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4806 | count = il_read_targ_mem(il, base); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4807 | |
| 4808 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4809 | IL_ERR("Start IWL Error Log Dump:\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4810 | IL_ERR("Status: 0x%08lX, count: %d\n", il->status, count); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4811 | } |
| 4812 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4813 | desc = il_read_targ_mem(il, base + 1 * sizeof(u32)); |
| 4814 | il->isr_stats.err_code = desc; |
| 4815 | pc = il_read_targ_mem(il, base + 2 * sizeof(u32)); |
| 4816 | blink1 = il_read_targ_mem(il, base + 3 * sizeof(u32)); |
| 4817 | blink2 = il_read_targ_mem(il, base + 4 * sizeof(u32)); |
| 4818 | ilink1 = il_read_targ_mem(il, base + 5 * sizeof(u32)); |
| 4819 | ilink2 = il_read_targ_mem(il, base + 6 * sizeof(u32)); |
| 4820 | data1 = il_read_targ_mem(il, base + 7 * sizeof(u32)); |
| 4821 | data2 = il_read_targ_mem(il, base + 8 * sizeof(u32)); |
| 4822 | line = il_read_targ_mem(il, base + 9 * sizeof(u32)); |
| 4823 | time = il_read_targ_mem(il, base + 11 * sizeof(u32)); |
| 4824 | hcmd = il_read_targ_mem(il, base + 22 * sizeof(u32)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4825 | |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4826 | IL_ERR("Desc Time " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4827 | "data1 data2 line\n"); |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4828 | IL_ERR("%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4829 | il4965_desc_lookup(desc), desc, time, data1, data2, line); |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4830 | IL_ERR("pc blink1 blink2 ilink1 ilink2 hcmd\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4831 | IL_ERR("0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n", pc, blink1, |
| 4832 | blink2, ilink1, ilink2, hcmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4833 | } |
| 4834 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4835 | static void |
| 4836 | il4965_rf_kill_ct_config(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4837 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4838 | struct il_ct_kill_config cmd; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4839 | unsigned long flags; |
| 4840 | int ret = 0; |
| 4841 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4842 | spin_lock_irqsave(&il->lock, flags); |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4843 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4844 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4845 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4846 | |
| 4847 | cmd.critical_temperature_R = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4848 | cpu_to_le32(il->hw_params.ct_kill_threshold); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4849 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4850 | ret = il_send_cmd_pdu(il, C_CT_KILL_CONFIG, sizeof(cmd), &cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4851 | if (ret) |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 4852 | IL_ERR("C_CT_KILL_CONFIG failed\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4853 | else |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4854 | D_INFO("C_CT_KILL_CONFIG " "succeeded, " |
| 4855 | "critical temperature is %d\n", |
| 4856 | il->hw_params.ct_kill_threshold); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | static const s8 default_queue_to_tx_fifo[] = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4860 | IL_TX_FIFO_VO, |
| 4861 | IL_TX_FIFO_VI, |
| 4862 | IL_TX_FIFO_BE, |
| 4863 | IL_TX_FIFO_BK, |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4864 | IL49_CMD_FIFO_NUM, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4865 | IL_TX_FIFO_UNUSED, |
| 4866 | IL_TX_FIFO_UNUSED, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4867 | }; |
| 4868 | |
Stanislaw Gruszka | e53aac4 | 2011-08-31 11:18:16 +0200 | [diff] [blame] | 4869 | #define IL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo)))) |
| 4870 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4871 | static int |
| 4872 | il4965_alive_notify(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4873 | { |
| 4874 | u32 a; |
| 4875 | unsigned long flags; |
| 4876 | int i, chan; |
| 4877 | u32 reg_val; |
| 4878 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4879 | spin_lock_irqsave(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4880 | |
| 4881 | /* Clear 4965's internal Tx Scheduler data base */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4882 | il->scd_base_addr = il_rd_prph(il, IL49_SCD_SRAM_BASE_ADDR); |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4883 | a = il->scd_base_addr + IL49_SCD_CONTEXT_DATA_OFFSET; |
| 4884 | for (; a < il->scd_base_addr + IL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4885 | il_write_targ_mem(il, a, 0); |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4886 | for (; a < il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET; a += 4) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4887 | il_write_targ_mem(il, a, 0); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4888 | for (; |
| 4889 | a < |
| 4890 | il->scd_base_addr + |
| 4891 | IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(il->hw_params.max_txq_num); |
| 4892 | a += 4) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4893 | il_write_targ_mem(il, a, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4894 | |
| 4895 | /* Tel 4965 where to find Tx byte count tables */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4896 | il_wr_prph(il, IL49_SCD_DRAM_BASE_ADDR, il->scd_bc_tbls.dma >> 10); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4897 | |
| 4898 | /* Enable DMA channel */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4899 | for (chan = 0; chan < FH49_TCSR_CHNL_NUM; chan++) |
| 4900 | il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(chan), |
| 4901 | FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | |
| 4902 | FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4903 | |
| 4904 | /* Update FH chicken bits */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 4905 | reg_val = il_rd(il, FH49_TX_CHICKEN_BITS_REG); |
| 4906 | il_wr(il, FH49_TX_CHICKEN_BITS_REG, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4907 | reg_val | FH49_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4908 | |
| 4909 | /* Disable chain mode for all queues */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4910 | il_wr_prph(il, IL49_SCD_QUEUECHAIN_SEL, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4911 | |
| 4912 | /* Initialize each Tx queue (including the command queue) */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4913 | for (i = 0; i < il->hw_params.max_txq_num; i++) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4914 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4915 | /* TFD circular buffer read/write idxes */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4916 | il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(i), 0); |
Stanislaw Gruszka | 0c1a94e | 2011-08-24 17:37:16 +0200 | [diff] [blame] | 4917 | il_wr(il, HBUS_TARG_WRPTR, 0 | (i << 8)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4918 | |
| 4919 | /* Max Tx Window size for Scheduler-ACK mode */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4920 | il_write_targ_mem(il, |
| 4921 | il->scd_base_addr + |
| 4922 | IL49_SCD_CONTEXT_QUEUE_OFFSET(i), |
| 4923 | (SCD_WIN_SIZE << |
| 4924 | IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & |
| 4925 | IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4926 | |
| 4927 | /* Frame limit */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4928 | il_write_targ_mem(il, |
| 4929 | il->scd_base_addr + |
| 4930 | IL49_SCD_CONTEXT_QUEUE_OFFSET(i) + |
| 4931 | sizeof(u32), |
| 4932 | (SCD_FRAME_LIMIT << |
| 4933 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & |
| 4934 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4935 | |
| 4936 | } |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4937 | il_wr_prph(il, IL49_SCD_INTERRUPT_MASK, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4938 | (1 << il->hw_params.max_txq_num) - 1); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4939 | |
| 4940 | /* Activate all Tx DMA/FIFO channels */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4941 | il4965_txq_set_sched(il, IL_MASK(0, 6)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4942 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4943 | il4965_set_wr_ptrs(il, IL_DEFAULT_CMD_QUEUE_NUM, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4944 | |
| 4945 | /* make sure all queue are not stopped */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4946 | memset(&il->queue_stopped[0], 0, sizeof(il->queue_stopped)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4947 | for (i = 0; i < 4; i++) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4948 | atomic_set(&il->queue_stop_count[i], 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4949 | |
| 4950 | /* reset to 0 to enable all the queue first */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4951 | il->txq_ctx_active_msk = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4952 | /* Map each Tx/cmd queue to its corresponding fifo */ |
| 4953 | BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7); |
| 4954 | |
| 4955 | for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { |
| 4956 | int ac = default_queue_to_tx_fifo[i]; |
| 4957 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4958 | il_txq_ctx_activate(il, i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4959 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4960 | if (ac == IL_TX_FIFO_UNUSED) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4961 | continue; |
| 4962 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4963 | il4965_tx_queue_set_status(il, &il->txq[i], ac, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4964 | } |
| 4965 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4966 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4967 | |
| 4968 | return 0; |
| 4969 | } |
| 4970 | |
| 4971 | /** |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 4972 | * il4965_alive_start - called after N_ALIVE notification received |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4973 | * from protocol/runtime uCode (initialization uCode's |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4974 | * Alive gets handled by il_init_alive_start()). |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4975 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4976 | static void |
| 4977 | il4965_alive_start(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4978 | { |
| 4979 | int ret = 0; |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 4980 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4981 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4982 | D_INFO("Runtime Alive received.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4983 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4984 | if (il->card_alive.is_valid != UCODE_VALID_OK) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4985 | /* We had an error bringing up the hardware, so take it |
| 4986 | * all the way back down so we can try again */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4987 | D_INFO("Alive failed.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4988 | goto restart; |
| 4989 | } |
| 4990 | |
| 4991 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 4992 | * This is a paranoid check, because we would not have gotten the |
| 4993 | * "runtime" alive if code weren't properly loaded. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4994 | if (il4965_verify_ucode(il)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4995 | /* Runtime instruction load was bad; |
| 4996 | * take it all the way back down so we can try again */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4997 | D_INFO("Bad runtime uCode load.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4998 | goto restart; |
| 4999 | } |
| 5000 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5001 | ret = il4965_alive_notify(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5002 | if (ret) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5003 | IL_WARN("Could not complete ALIVE transition [ntf]: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5004 | goto restart; |
| 5005 | } |
| 5006 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5007 | /* After the ALIVE response, we can send host commands to the uCode */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5008 | set_bit(S_ALIVE, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5009 | |
| 5010 | /* Enable watchdog to monitor the driver tx queues */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5011 | il_setup_watchdog(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5012 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5013 | if (il_is_rfkill(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5014 | return; |
| 5015 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5016 | ieee80211_wake_queues(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5017 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 5018 | il->active_rate = RATES_MASK; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5019 | |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 5020 | if (il_is_associated(il)) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5021 | struct il_rxon_cmd *active_rxon = |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 5022 | (struct il_rxon_cmd *)&il->active; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5023 | /* apply any changes in staging */ |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 5024 | il->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5025 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5026 | } else { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5027 | /* Initialize our rx_config data */ |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5028 | il_connection_init_rx_config(il, &il->ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5029 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5030 | if (il->cfg->ops->hcmd->set_rxon_chain) |
| 5031 | il->cfg->ops->hcmd->set_rxon_chain(il, ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | /* Configure bluetooth coexistence if enabled */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5035 | il_send_bt_config(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5036 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5037 | il4965_reset_run_time_calib(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5038 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5039 | set_bit(S_READY, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5040 | |
| 5041 | /* Configure the adapter for unassociated operation */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5042 | il_commit_rxon(il, ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5043 | |
| 5044 | /* At this point, the NIC is initialized and operational */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5045 | il4965_rf_kill_ct_config(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5046 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5047 | D_INFO("ALIVE processing complete.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5048 | wake_up(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5049 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5050 | il_power_update_mode(il, true); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5051 | D_INFO("Updated power mode\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5052 | |
| 5053 | return; |
| 5054 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5055 | restart: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5056 | queue_work(il->workqueue, &il->restart); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5057 | } |
| 5058 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5059 | static void il4965_cancel_deferred_work(struct il_priv *il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5060 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5061 | static void |
| 5062 | __il4965_down(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5063 | { |
| 5064 | unsigned long flags; |
Stanislaw Gruszka | ab42b40 | 2011-04-28 11:51:24 +0200 | [diff] [blame] | 5065 | int exit_pending; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5066 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5067 | D_INFO(DRV_NAME " is going down\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5068 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5069 | il_scan_cancel_timeout(il, 200); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5070 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5071 | exit_pending = test_and_set_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5072 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5073 | /* Stop TX queues watchdog. We need to have S_EXIT_PENDING bit set |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5074 | * to prevent rearm timer */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5075 | del_timer_sync(&il->watchdog); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5076 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5077 | il_clear_ucode_stations(il, NULL); |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 5078 | |
| 5079 | /* FIXME: race conditions ? */ |
| 5080 | spin_lock_irq(&il->sta_lock); |
| 5081 | /* |
| 5082 | * Remove all key information that is not stored as part |
| 5083 | * of station information since mac80211 may not have had |
| 5084 | * a chance to remove all the keys. When device is |
| 5085 | * reconfigured by mac80211 after an error all keys will |
| 5086 | * be reconfigured. |
| 5087 | */ |
| 5088 | memset(il->_4965.wep_keys, 0, sizeof(il->_4965.wep_keys)); |
| 5089 | il->_4965.key_mapping_keys = 0; |
| 5090 | spin_unlock_irq(&il->sta_lock); |
| 5091 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5092 | il_dealloc_bcast_stations(il); |
| 5093 | il_clear_driver_stations(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5094 | |
| 5095 | /* Unblock any waiting calls */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5096 | wake_up_all(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5097 | |
| 5098 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5099 | * exiting the module */ |
| 5100 | if (!exit_pending) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5101 | clear_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5102 | |
| 5103 | /* stop and reset the on-board processor */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5104 | _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5105 | |
| 5106 | /* tell the device to stop sending interrupts */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5107 | spin_lock_irqsave(&il->lock, flags); |
| 5108 | il_disable_interrupts(il); |
| 5109 | spin_unlock_irqrestore(&il->lock, flags); |
| 5110 | il4965_synchronize_irq(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5111 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5112 | if (il->mac80211_registered) |
| 5113 | ieee80211_stop_queues(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5114 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5115 | /* If we have not previously called il_init() then |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5116 | * clear all bits but the RF Kill bit and return */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5117 | if (!il_is_init(il)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5118 | il->status = |
| 5119 | test_bit(S_RF_KILL_HW, |
| 5120 | &il-> |
| 5121 | status) << S_RF_KILL_HW | |
| 5122 | test_bit(S_GEO_CONFIGURED, |
| 5123 | &il-> |
| 5124 | status) << S_GEO_CONFIGURED | |
| 5125 | test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5126 | goto exit; |
| 5127 | } |
| 5128 | |
| 5129 | /* ...otherwise clear out all the status bits but the RF Kill |
| 5130 | * bit and continue taking the NIC down. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5131 | il->status &= |
| 5132 | test_bit(S_RF_KILL_HW, |
| 5133 | &il->status) << S_RF_KILL_HW | test_bit(S_GEO_CONFIGURED, |
| 5134 | &il-> |
| 5135 | status) << |
| 5136 | S_GEO_CONFIGURED | test_bit(S_FW_ERROR, |
| 5137 | &il-> |
| 5138 | status) << S_FW_ERROR | |
| 5139 | test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5140 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5141 | il4965_txq_ctx_stop(il); |
| 5142 | il4965_rxq_stop(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5143 | |
| 5144 | /* Power-down device's busmaster DMA clocks */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 5145 | il_wr_prph(il, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5146 | udelay(5); |
| 5147 | |
| 5148 | /* Make sure (redundant) we've released our request to stay awake */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5149 | il_clear_bit(il, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5150 | |
| 5151 | /* Stop the device, and put it in low power state */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5152 | il_apm_stop(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5153 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5154 | exit: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5155 | memset(&il->card_alive, 0, sizeof(struct il_alive_resp)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5156 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5157 | dev_kfree_skb(il->beacon_skb); |
| 5158 | il->beacon_skb = NULL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5159 | |
| 5160 | /* clear out any free frames */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5161 | il4965_clear_free_frames(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5164 | static void |
| 5165 | il4965_down(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5166 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5167 | mutex_lock(&il->mutex); |
| 5168 | __il4965_down(il); |
| 5169 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5170 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5171 | il4965_cancel_deferred_work(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5172 | } |
| 5173 | |
| 5174 | #define HW_READY_TIMEOUT (50) |
| 5175 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5176 | static int |
| 5177 | il4965_set_hw_ready(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5178 | { |
| 5179 | int ret = 0; |
| 5180 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5181 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5182 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5183 | |
| 5184 | /* See if we got it */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5185 | ret = |
| 5186 | _il_poll_bit(il, CSR_HW_IF_CONFIG_REG, |
| 5187 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, |
| 5188 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, HW_READY_TIMEOUT); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5189 | if (ret != -ETIMEDOUT) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5190 | il->hw_ready = true; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5191 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5192 | il->hw_ready = false; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5193 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5194 | D_INFO("hardware %s\n", (il->hw_ready == 1) ? "ready" : "not ready"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5195 | return ret; |
| 5196 | } |
| 5197 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5198 | static int |
| 5199 | il4965_prepare_card_hw(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5200 | { |
| 5201 | int ret = 0; |
| 5202 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5203 | D_INFO("il4965_prepare_card_hw enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5204 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5205 | ret = il4965_set_hw_ready(il); |
| 5206 | if (il->hw_ready) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5207 | return ret; |
| 5208 | |
| 5209 | /* If HW is not ready, prepare the conditions to check again */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5210 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_PREPARE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5211 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5212 | ret = |
| 5213 | _il_poll_bit(il, CSR_HW_IF_CONFIG_REG, |
| 5214 | ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, |
| 5215 | CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5216 | |
| 5217 | /* HW should be ready by now, check again. */ |
| 5218 | if (ret != -ETIMEDOUT) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5219 | il4965_set_hw_ready(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5220 | |
| 5221 | return ret; |
| 5222 | } |
| 5223 | |
| 5224 | #define MAX_HW_RESTARTS 5 |
| 5225 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5226 | static int |
| 5227 | __il4965_up(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5228 | { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5229 | int i; |
| 5230 | int ret; |
| 5231 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5232 | if (test_bit(S_EXIT_PENDING, &il->status)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5233 | IL_WARN("Exit pending; will not bring the NIC up\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5234 | return -EIO; |
| 5235 | } |
| 5236 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5237 | if (!il->ucode_data_backup.v_addr || !il->ucode_data.v_addr) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5238 | IL_ERR("ucode not available for device bringup\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5239 | return -EIO; |
| 5240 | } |
| 5241 | |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5242 | ret = il4965_alloc_bcast_station(il, &il->ctx); |
| 5243 | if (ret) { |
| 5244 | il_dealloc_bcast_stations(il); |
| 5245 | return ret; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5246 | } |
| 5247 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5248 | il4965_prepare_card_hw(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5249 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5250 | if (!il->hw_ready) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5251 | IL_WARN("Exit HW not ready\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5252 | return -EIO; |
| 5253 | } |
| 5254 | |
| 5255 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5256 | if (_il_rd(il, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5257 | clear_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5258 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5259 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5260 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5261 | if (il_is_rfkill(il)) { |
| 5262 | wiphy_rfkill_set_hw_state(il->hw->wiphy, true); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5263 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5264 | il_enable_interrupts(il); |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5265 | IL_WARN("Radio disabled by HW RF Kill switch\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5266 | return 0; |
| 5267 | } |
| 5268 | |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5269 | _il_wr(il, CSR_INT, 0xFFFFFFFF); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5270 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5271 | /* must be initialised before il_hw_nic_init */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5272 | il->cmd_queue = IL_DEFAULT_CMD_QUEUE_NUM; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5273 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5274 | ret = il4965_hw_nic_init(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5275 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5276 | IL_ERR("Unable to init nic\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5277 | return ret; |
| 5278 | } |
| 5279 | |
| 5280 | /* make sure rfkill handshake bits are cleared */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5281 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5282 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5283 | |
| 5284 | /* clear (again), then enable host interrupts */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5285 | _il_wr(il, CSR_INT, 0xFFFFFFFF); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5286 | il_enable_interrupts(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5287 | |
| 5288 | /* really make sure rfkill handshake bits are cleared */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5289 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5290 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5291 | |
| 5292 | /* Copy original ucode data image from disk into backup cache. |
| 5293 | * This will be used to initialize the on-board processor's |
| 5294 | * data SRAM for a clean start when the runtime program first loads. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5295 | memcpy(il->ucode_data_backup.v_addr, il->ucode_data.v_addr, |
| 5296 | il->ucode_data.len); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5297 | |
| 5298 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5299 | |
| 5300 | /* load bootstrap state machine, |
| 5301 | * load bootstrap program into processor's memory, |
| 5302 | * prepare to load the "initialize" uCode */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5303 | ret = il->cfg->ops->lib->load_ucode(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5304 | |
| 5305 | if (ret) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5306 | IL_ERR("Unable to set up bootstrap uCode: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5307 | continue; |
| 5308 | } |
| 5309 | |
| 5310 | /* start card; "initialize" will load runtime ucode */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5311 | il4965_nic_start(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5312 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5313 | D_INFO(DRV_NAME " is coming up\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5314 | |
| 5315 | return 0; |
| 5316 | } |
| 5317 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5318 | set_bit(S_EXIT_PENDING, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5319 | __il4965_down(il); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5320 | clear_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5321 | |
| 5322 | /* tried to restart and config the device for as long as our |
| 5323 | * patience could withstand */ |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5324 | IL_ERR("Unable to initialize device after %d attempts.\n", i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5325 | return -EIO; |
| 5326 | } |
| 5327 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5328 | /***************************************************************************** |
| 5329 | * |
| 5330 | * Workqueue callbacks |
| 5331 | * |
| 5332 | *****************************************************************************/ |
| 5333 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5334 | static void |
| 5335 | il4965_bg_init_alive_start(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5336 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5337 | struct il_priv *il = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5338 | container_of(data, struct il_priv, init_alive_start.work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5339 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5340 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5341 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5342 | goto out; |
| 5343 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5344 | il->cfg->ops->lib->init_alive_start(il); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5345 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5346 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5347 | } |
| 5348 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5349 | static void |
| 5350 | il4965_bg_alive_start(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5351 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5352 | struct il_priv *il = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5353 | container_of(data, struct il_priv, alive_start.work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5354 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5355 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5356 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5357 | goto out; |
| 5358 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5359 | il4965_alive_start(il); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5360 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5361 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5362 | } |
| 5363 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5364 | static void |
| 5365 | il4965_bg_run_time_calib_work(struct work_struct *work) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5366 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5367 | struct il_priv *il = container_of(work, struct il_priv, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5368 | run_time_calib_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5369 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5370 | mutex_lock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5371 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5372 | if (test_bit(S_EXIT_PENDING, &il->status) || |
| 5373 | test_bit(S_SCANNING, &il->status)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5374 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5375 | return; |
| 5376 | } |
| 5377 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5378 | if (il->start_calib) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5379 | il4965_chain_noise_calibration(il, (void *)&il->_4965.stats); |
| 5380 | il4965_sensitivity_calibration(il, (void *)&il->_4965.stats); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5381 | } |
| 5382 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5383 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5384 | } |
| 5385 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5386 | static void |
| 5387 | il4965_bg_restart(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5388 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5389 | struct il_priv *il = container_of(data, struct il_priv, restart); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5390 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5391 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5392 | return; |
| 5393 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5394 | if (test_and_clear_bit(S_FW_ERROR, &il->status)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5395 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5396 | il->ctx.vif = NULL; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5397 | il->is_open = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5398 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5399 | __il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5400 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5401 | mutex_unlock(&il->mutex); |
| 5402 | il4965_cancel_deferred_work(il); |
| 5403 | ieee80211_restart_hw(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5404 | } else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5405 | il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5406 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5407 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5408 | if (test_bit(S_EXIT_PENDING, &il->status)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5409 | mutex_unlock(&il->mutex); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5410 | return; |
| 5411 | } |
| 5412 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5413 | __il4965_up(il); |
| 5414 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5415 | } |
| 5416 | } |
| 5417 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5418 | static void |
| 5419 | il4965_bg_rx_replenish(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5420 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5421 | struct il_priv *il = container_of(data, struct il_priv, rx_replenish); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5422 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5423 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5424 | return; |
| 5425 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5426 | mutex_lock(&il->mutex); |
| 5427 | il4965_rx_replenish(il); |
| 5428 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | /***************************************************************************** |
| 5432 | * |
| 5433 | * mac80211 entry point functions |
| 5434 | * |
| 5435 | *****************************************************************************/ |
| 5436 | |
| 5437 | #define UCODE_READY_TIMEOUT (4 * HZ) |
| 5438 | |
| 5439 | /* |
| 5440 | * Not a mac80211 entry point function, but it fits in with all the |
| 5441 | * other mac80211 functions grouped here. |
| 5442 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5443 | static int |
| 5444 | il4965_mac_setup_register(struct il_priv *il, u32 max_probe_length) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5445 | { |
| 5446 | int ret; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5447 | struct ieee80211_hw *hw = il->hw; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5448 | |
| 5449 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 5450 | |
| 5451 | /* Tell mac80211 our characteristics */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5452 | hw->flags = |
| 5453 | IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_AMPDU_AGGREGATION | |
| 5454 | IEEE80211_HW_NEED_DTIM_PERIOD | IEEE80211_HW_SPECTRUM_MGMT | |
| 5455 | IEEE80211_HW_REPORTS_TX_ACK_STATUS; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5456 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5457 | if (il->cfg->sku & IL_SKU_N) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5458 | hw->flags |= |
| 5459 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | |
| 5460 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5461 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5462 | hw->sta_data_size = sizeof(struct il_station_priv); |
| 5463 | hw->vif_data_size = sizeof(struct il_vif_priv); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5464 | |
Stanislaw Gruszka | 8c9c48d | 2012-02-03 17:31:50 +0100 | [diff] [blame] | 5465 | hw->wiphy->interface_modes = |
| 5466 | BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5467 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5468 | hw->wiphy->flags |= |
| 5469 | WIPHY_FLAG_CUSTOM_REGULATORY | WIPHY_FLAG_DISABLE_BEACON_HINTS; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5470 | |
| 5471 | /* |
| 5472 | * For now, disable PS by default because it affects |
| 5473 | * RX performance significantly. |
| 5474 | */ |
| 5475 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 5476 | |
| 5477 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
| 5478 | /* we create the 802.11 header and a zero-length SSID element */ |
| 5479 | hw->wiphy->max_scan_ie_len = max_probe_length - 24 - 2; |
| 5480 | |
| 5481 | /* Default value; 4 EDCA QOS priorities */ |
| 5482 | hw->queues = 4; |
| 5483 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5484 | hw->max_listen_interval = IL_CONN_MAX_LISTEN_INTERVAL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5485 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5486 | if (il->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 5487 | il->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5488 | &il->bands[IEEE80211_BAND_2GHZ]; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5489 | if (il->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 5490 | il->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5491 | &il->bands[IEEE80211_BAND_5GHZ]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5492 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5493 | il_leds_init(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5494 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5495 | ret = ieee80211_register_hw(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5496 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5497 | IL_ERR("Failed to register hw (error %d)\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5498 | return ret; |
| 5499 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5500 | il->mac80211_registered = 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5501 | |
| 5502 | return 0; |
| 5503 | } |
| 5504 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5505 | int |
| 5506 | il4965_mac_start(struct ieee80211_hw *hw) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5507 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5508 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5509 | int ret; |
| 5510 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5511 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5512 | |
| 5513 | /* we should be verifying the device is ready to be opened */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5514 | mutex_lock(&il->mutex); |
| 5515 | ret = __il4965_up(il); |
| 5516 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5517 | |
| 5518 | if (ret) |
| 5519 | return ret; |
| 5520 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5521 | if (il_is_rfkill(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5522 | goto out; |
| 5523 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5524 | D_INFO("Start UP work done.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5525 | |
| 5526 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
| 5527 | * mac80211 will not be run successfully. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5528 | ret = wait_event_timeout(il->wait_command_queue, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5529 | test_bit(S_READY, &il->status), |
| 5530 | UCODE_READY_TIMEOUT); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5531 | if (!ret) { |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5532 | if (!test_bit(S_READY, &il->status)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5533 | IL_ERR("START_ALIVE timeout after %dms.\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5534 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 5535 | return -ETIMEDOUT; |
| 5536 | } |
| 5537 | } |
| 5538 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5539 | il4965_led_enable(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5540 | |
| 5541 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5542 | il->is_open = 1; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5543 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5544 | return 0; |
| 5545 | } |
| 5546 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5547 | void |
| 5548 | il4965_mac_stop(struct ieee80211_hw *hw) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5549 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5550 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5551 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5552 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5553 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5554 | if (!il->is_open) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5555 | return; |
| 5556 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5557 | il->is_open = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5558 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5559 | il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5560 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5561 | flush_workqueue(il->workqueue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5562 | |
Stanislaw Gruszka | a078a1f | 2011-04-28 11:51:25 +0200 | [diff] [blame] | 5563 | /* User space software may expect getting rfkill changes |
| 5564 | * even if interface is down */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5565 | _il_wr(il, CSR_INT, 0xFFFFFFFF); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5566 | il_enable_rfkill_int(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5567 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5568 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5569 | } |
| 5570 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5571 | void |
| 5572 | il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5573 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5574 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5575 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5576 | D_MACDUMP("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5577 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5578 | D_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5579 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5580 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5581 | if (il4965_tx_skb(il, skb)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5582 | dev_kfree_skb_any(skb); |
| 5583 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5584 | D_MACDUMP("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5585 | } |
| 5586 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5587 | void |
| 5588 | il4965_mac_update_tkip_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5589 | struct ieee80211_key_conf *keyconf, |
| 5590 | struct ieee80211_sta *sta, u32 iv32, u16 * phase1key) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5591 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5592 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5593 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5594 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5595 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5596 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5597 | il4965_update_tkip_key(il, vif_priv->ctx, keyconf, sta, iv32, |
| 5598 | phase1key); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5599 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5600 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5601 | } |
| 5602 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5603 | int |
| 5604 | il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 5605 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 5606 | struct ieee80211_key_conf *key) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5607 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5608 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5609 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 5610 | struct il_rxon_context *ctx = vif_priv->ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5611 | int ret; |
| 5612 | u8 sta_id; |
| 5613 | bool is_default_wep_key = false; |
| 5614 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5615 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5616 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5617 | if (il->cfg->mod_params->sw_crypto) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5618 | D_MAC80211("leave - hwcrypto disabled\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5619 | return -EOPNOTSUPP; |
| 5620 | } |
| 5621 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5622 | sta_id = il_sta_id_or_broadcast(il, vif_priv->ctx, sta); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5623 | if (sta_id == IL_INVALID_STATION) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5624 | return -EINVAL; |
| 5625 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5626 | mutex_lock(&il->mutex); |
| 5627 | il_scan_cancel_timeout(il, 100); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5628 | |
| 5629 | /* |
| 5630 | * If we are getting WEP group key and we didn't receive any key mapping |
| 5631 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 5632 | * in 1X mode. |
| 5633 | * In legacy wep mode, we use another host command to the uCode. |
| 5634 | */ |
| 5635 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5636 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5637 | if (cmd == SET_KEY) |
Stanislaw Gruszka | d735f92 | 2012-02-03 17:31:48 +0100 | [diff] [blame] | 5638 | is_default_wep_key = !il->_4965.key_mapping_keys; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5639 | else |
| 5640 | is_default_wep_key = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5641 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | switch (cmd) { |
| 5645 | case SET_KEY: |
| 5646 | if (is_default_wep_key) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5647 | ret = |
| 5648 | il4965_set_default_wep_key(il, vif_priv->ctx, key); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5649 | else |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5650 | ret = |
| 5651 | il4965_set_dynamic_key(il, vif_priv->ctx, key, |
| 5652 | sta_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5653 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5654 | D_MAC80211("enable hwcrypto key\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5655 | break; |
| 5656 | case DISABLE_KEY: |
| 5657 | if (is_default_wep_key) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5658 | ret = il4965_remove_default_wep_key(il, ctx, key); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5659 | else |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5660 | ret = il4965_remove_dynamic_key(il, ctx, key, sta_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5661 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5662 | D_MAC80211("disable hwcrypto key\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5663 | break; |
| 5664 | default: |
| 5665 | ret = -EINVAL; |
| 5666 | } |
| 5667 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5668 | mutex_unlock(&il->mutex); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5669 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5670 | |
| 5671 | return ret; |
| 5672 | } |
| 5673 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5674 | int |
| 5675 | il4965_mac_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5676 | enum ieee80211_ampdu_mlme_action action, |
| 5677 | struct ieee80211_sta *sta, u16 tid, u16 * ssn, |
| 5678 | u8 buf_size) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5679 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5680 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5681 | int ret = -EINVAL; |
| 5682 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5683 | D_HT("A-MPDU action on addr %pM tid %d\n", sta->addr, tid); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5684 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5685 | if (!(il->cfg->sku & IL_SKU_N)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5686 | return -EACCES; |
| 5687 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5688 | mutex_lock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5689 | |
| 5690 | switch (action) { |
| 5691 | case IEEE80211_AMPDU_RX_START: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5692 | D_HT("start Rx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5693 | ret = il4965_sta_rx_agg_start(il, sta, tid, *ssn); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5694 | break; |
| 5695 | case IEEE80211_AMPDU_RX_STOP: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5696 | D_HT("stop Rx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5697 | ret = il4965_sta_rx_agg_stop(il, sta, tid); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5698 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5699 | ret = 0; |
| 5700 | break; |
| 5701 | case IEEE80211_AMPDU_TX_START: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5702 | D_HT("start Tx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5703 | ret = il4965_tx_agg_start(il, vif, sta, tid, ssn); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5704 | break; |
| 5705 | case IEEE80211_AMPDU_TX_STOP: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5706 | D_HT("stop Tx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5707 | ret = il4965_tx_agg_stop(il, vif, sta, tid); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5708 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5709 | ret = 0; |
| 5710 | break; |
| 5711 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 5712 | ret = 0; |
| 5713 | break; |
| 5714 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5715 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5716 | |
| 5717 | return ret; |
| 5718 | } |
| 5719 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5720 | int |
| 5721 | il4965_mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5722 | struct ieee80211_sta *sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5723 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5724 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5725 | struct il_station_priv *sta_priv = (void *)sta->drv_priv; |
| 5726 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5727 | bool is_ap = vif->type == NL80211_IFTYPE_STATION; |
| 5728 | int ret; |
| 5729 | u8 sta_id; |
| 5730 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5731 | D_INFO("received request to add station %pM\n", sta->addr); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5732 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5733 | D_INFO("proceeding to add station %pM\n", sta->addr); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5734 | sta_priv->common.sta_id = IL_INVALID_STATION; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5735 | |
| 5736 | atomic_set(&sta_priv->pending_frames, 0); |
| 5737 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5738 | ret = |
| 5739 | il_add_station_common(il, vif_priv->ctx, sta->addr, is_ap, sta, |
| 5740 | &sta_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5741 | if (ret) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5742 | IL_ERR("Unable to add station %pM (%d)\n", sta->addr, ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5743 | /* Should we return success if return code is EEXIST ? */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5744 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5745 | return ret; |
| 5746 | } |
| 5747 | |
| 5748 | sta_priv->common.sta_id = sta_id; |
| 5749 | |
| 5750 | /* Initialize rate scaling */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5751 | D_INFO("Initializing rate scaling for station %pM\n", sta->addr); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5752 | il4965_rs_rate_init(il, sta, sta_id); |
| 5753 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5754 | |
| 5755 | return 0; |
| 5756 | } |
| 5757 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5758 | void |
| 5759 | il4965_mac_channel_switch(struct ieee80211_hw *hw, |
| 5760 | struct ieee80211_channel_switch *ch_switch) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5761 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5762 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5763 | const struct il_channel_info *ch_info; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5764 | struct ieee80211_conf *conf = &hw->conf; |
| 5765 | struct ieee80211_channel *channel = ch_switch->channel; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5766 | struct il_ht_config *ht_conf = &il->current_ht_config; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5767 | |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 5768 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5769 | u16 ch; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5770 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5771 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5772 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5773 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5774 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5775 | if (il_is_rfkill(il)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5776 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5777 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5778 | if (test_bit(S_EXIT_PENDING, &il->status) || |
| 5779 | test_bit(S_SCANNING, &il->status) || |
| 5780 | test_bit(S_CHANNEL_SWITCH_PENDING, &il->status)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5781 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5782 | |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 5783 | if (!il_is_associated(il)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5784 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5785 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5786 | if (!il->cfg->ops->lib->set_channel_switch) |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5787 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5788 | |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5789 | ch = channel->hw_value; |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 5790 | if (le16_to_cpu(il->active.channel) == ch) |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5791 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5792 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5793 | ch_info = il_get_channel_info(il, channel->band, ch); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5794 | if (!il_is_channel_valid(ch_info)) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5795 | D_MAC80211("invalid channel\n"); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5796 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5797 | } |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5798 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5799 | spin_lock_irq(&il->lock); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5800 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5801 | il->current_ht_config.smps = conf->smps_mode; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5802 | |
| 5803 | /* Configure HT40 channels */ |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5804 | il->ht.enabled = conf_is_ht(conf); |
| 5805 | if (il->ht.enabled) { |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5806 | if (conf_is_ht40_minus(conf)) { |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5807 | il->ht.extension_chan_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5808 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5809 | il->ht.is_40mhz = true; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5810 | } else if (conf_is_ht40_plus(conf)) { |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5811 | il->ht.extension_chan_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5812 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5813 | il->ht.is_40mhz = true; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5814 | } else { |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5815 | il->ht.extension_chan_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5816 | IEEE80211_HT_PARAM_CHA_SEC_NONE; |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5817 | il->ht.is_40mhz = false; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5818 | } |
| 5819 | } else |
Stanislaw Gruszka | 1c03c46 | 2012-02-03 17:31:52 +0100 | [diff] [blame] | 5820 | il->ht.is_40mhz = false; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5821 | |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 5822 | if ((le16_to_cpu(il->staging.channel) != ch)) |
| 5823 | il->staging.flags = 0; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5824 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5825 | il_set_rxon_channel(il, channel, ctx); |
| 5826 | il_set_rxon_ht(il, ht_conf); |
| 5827 | il_set_flags_for_band(il, ctx, channel->band, ctx->vif); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5828 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5829 | spin_unlock_irq(&il->lock); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5830 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5831 | il_set_rate(il); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5832 | /* |
| 5833 | * at this point, staging_rxon has the |
| 5834 | * configuration for channel switch |
| 5835 | */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5836 | set_bit(S_CHANNEL_SWITCH_PENDING, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5837 | il->switch_channel = cpu_to_le16(ch); |
| 5838 | if (il->cfg->ops->lib->set_channel_switch(il, ch_switch)) { |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5839 | clear_bit(S_CHANNEL_SWITCH_PENDING, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5840 | il->switch_channel = 0; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5841 | ieee80211_chswitch_done(ctx->vif, false); |
| 5842 | } |
| 5843 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5844 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5845 | mutex_unlock(&il->mutex); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5846 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5847 | } |
| 5848 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5849 | void |
| 5850 | il4965_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, |
| 5851 | unsigned int *total_flags, u64 multicast) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5852 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5853 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5854 | __le32 filter_or = 0, filter_nand = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5855 | |
| 5856 | #define CHK(test, flag) do { \ |
| 5857 | if (*total_flags & (test)) \ |
| 5858 | filter_or |= (flag); \ |
| 5859 | else \ |
| 5860 | filter_nand |= (flag); \ |
| 5861 | } while (0) |
| 5862 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5863 | D_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", changed_flags, |
| 5864 | *total_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5865 | |
| 5866 | CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK); |
| 5867 | /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */ |
| 5868 | CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK); |
| 5869 | CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK); |
| 5870 | |
| 5871 | #undef CHK |
| 5872 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5873 | mutex_lock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5874 | |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 5875 | il->staging.filter_flags &= ~filter_nand; |
| 5876 | il->staging.filter_flags |= filter_or; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5877 | |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5878 | /* |
| 5879 | * Not committing directly because hardware can perform a scan, |
| 5880 | * but we'll eventually commit the filter flags change anyway. |
| 5881 | */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5882 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5883 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5884 | |
| 5885 | /* |
| 5886 | * Receiving all multicast frames is always enabled by the |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5887 | * default flags setup in il_connection_init_rx_config() |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5888 | * since we currently do not support programming multicast |
| 5889 | * filters into the device. |
| 5890 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5891 | *total_flags &= |
| 5892 | FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
| 5893 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | /***************************************************************************** |
| 5897 | * |
| 5898 | * driver setup and teardown |
| 5899 | * |
| 5900 | *****************************************************************************/ |
| 5901 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5902 | static void |
| 5903 | il4965_bg_txpower_work(struct work_struct *work) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5904 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5905 | struct il_priv *il = container_of(work, struct il_priv, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5906 | txpower_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5907 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5908 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | f325757 | 2011-04-28 11:36:54 +0200 | [diff] [blame] | 5909 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5910 | /* If a scan happened to start before we got here |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 5911 | * then just return; the stats notification will |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5912 | * kick off another scheduled work to compensate for |
| 5913 | * any temperature delta we missed here. */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5914 | if (test_bit(S_EXIT_PENDING, &il->status) || |
| 5915 | test_bit(S_SCANNING, &il->status)) |
Stanislaw Gruszka | f325757 | 2011-04-28 11:36:54 +0200 | [diff] [blame] | 5916 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5917 | |
| 5918 | /* Regardless of if we are associated, we must reconfigure the |
| 5919 | * TX power since frames can be sent on non-radar channels while |
| 5920 | * not associated */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5921 | il->cfg->ops->lib->send_tx_power(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5922 | |
| 5923 | /* Update last_temperature to keep is_calib_needed from running |
| 5924 | * when it isn't needed... */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5925 | il->last_temperature = il->temperature; |
Stanislaw Gruszka | f325757 | 2011-04-28 11:36:54 +0200 | [diff] [blame] | 5926 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5927 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5928 | } |
| 5929 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5930 | static void |
| 5931 | il4965_setup_deferred_work(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5932 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5933 | il->workqueue = create_singlethread_workqueue(DRV_NAME); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5934 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5935 | init_waitqueue_head(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5936 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5937 | INIT_WORK(&il->restart, il4965_bg_restart); |
| 5938 | INIT_WORK(&il->rx_replenish, il4965_bg_rx_replenish); |
| 5939 | INIT_WORK(&il->run_time_calib_work, il4965_bg_run_time_calib_work); |
| 5940 | INIT_DELAYED_WORK(&il->init_alive_start, il4965_bg_init_alive_start); |
| 5941 | INIT_DELAYED_WORK(&il->alive_start, il4965_bg_alive_start); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5942 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5943 | il_setup_scan_deferred_work(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5944 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5945 | INIT_WORK(&il->txpower_work, il4965_bg_txpower_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5946 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 5947 | init_timer(&il->stats_periodic); |
| 5948 | il->stats_periodic.data = (unsigned long)il; |
| 5949 | il->stats_periodic.function = il4965_bg_stats_periodic; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5950 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5951 | init_timer(&il->watchdog); |
| 5952 | il->watchdog.data = (unsigned long)il; |
| 5953 | il->watchdog.function = il_bg_watchdog; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5954 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5955 | tasklet_init(&il->irq_tasklet, |
| 5956 | (void (*)(unsigned long))il4965_irq_tasklet, |
| 5957 | (unsigned long)il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5958 | } |
| 5959 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5960 | static void |
| 5961 | il4965_cancel_deferred_work(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5962 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5963 | cancel_work_sync(&il->txpower_work); |
| 5964 | cancel_delayed_work_sync(&il->init_alive_start); |
| 5965 | cancel_delayed_work(&il->alive_start); |
| 5966 | cancel_work_sync(&il->run_time_calib_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5967 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5968 | il_cancel_scan_deferred_work(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5969 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 5970 | del_timer_sync(&il->stats_periodic); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5971 | } |
| 5972 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5973 | static void |
| 5974 | il4965_init_hw_rates(struct il_priv *il, struct ieee80211_rate *rates) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5975 | { |
| 5976 | int i; |
| 5977 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 5978 | for (i = 0; i < RATE_COUNT_LEGACY; i++) { |
Stanislaw Gruszka | d2ddf62 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 5979 | rates[i].bitrate = il_rates[i].ieee * 5; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5980 | rates[i].hw_value = i; /* Rate scaling will work on idxes */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5981 | rates[i].hw_value_short = i; |
| 5982 | rates[i].flags = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5983 | if ((i >= IL_FIRST_CCK_RATE) && (i <= IL_LAST_CCK_RATE)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5984 | /* |
| 5985 | * If CCK != 1M then set short preamble rate flag. |
| 5986 | */ |
| 5987 | rates[i].flags |= |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5988 | (il_rates[i].plcp == |
| 5989 | RATE_1M_PLCP) ? 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5990 | } |
| 5991 | } |
| 5992 | } |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5993 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5994 | /* |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5995 | * Acquire il->lock before calling this function ! |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5996 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5997 | void |
| 5998 | il4965_set_wr_ptrs(struct il_priv *il, int txq_id, u32 idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5999 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6000 | il_wr(il, HBUS_TARG_WRPTR, (idx & 0xff) | (txq_id << 8)); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 6001 | il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(txq_id), idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6002 | } |
| 6003 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6004 | void |
| 6005 | il4965_tx_queue_set_status(struct il_priv *il, struct il_tx_queue *txq, |
| 6006 | int tx_fifo_id, int scd_retry) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6007 | { |
| 6008 | int txq_id = txq->q.id; |
| 6009 | |
| 6010 | /* Find out whether to activate Tx queue */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6011 | int active = test_bit(txq_id, &il->txq_ctx_active_msk) ? 1 : 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6012 | |
| 6013 | /* Set up and activate */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 6014 | il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 6015 | (active << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) | |
| 6016 | (tx_fifo_id << IL49_SCD_QUEUE_STTS_REG_POS_TXF) | |
| 6017 | (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_WSL) | |
| 6018 | (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) | |
| 6019 | IL49_SCD_QUEUE_STTS_REG_MSK); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6020 | |
| 6021 | txq->sched_retry = scd_retry; |
| 6022 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6023 | D_INFO("%s %s Queue %d on AC %d\n", active ? "Activate" : "Deactivate", |
| 6024 | scd_retry ? "BA" : "AC", txq_id, tx_fifo_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6025 | } |
| 6026 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6027 | static int |
| 6028 | il4965_init_drv(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6029 | { |
| 6030 | int ret; |
| 6031 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6032 | spin_lock_init(&il->sta_lock); |
| 6033 | spin_lock_init(&il->hcmd_lock); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6034 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6035 | INIT_LIST_HEAD(&il->free_frames); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6036 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6037 | mutex_init(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6038 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6039 | il->ieee_channels = NULL; |
| 6040 | il->ieee_rates = NULL; |
| 6041 | il->band = IEEE80211_BAND_2GHZ; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6042 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6043 | il->iw_mode = NL80211_IFTYPE_STATION; |
| 6044 | il->current_ht_config.smps = IEEE80211_SMPS_STATIC; |
| 6045 | il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6046 | |
| 6047 | /* initialize force reset */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6048 | il->force_reset.reset_duration = IL_DELAY_NEXT_FORCE_FW_RELOAD; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6049 | |
| 6050 | /* Choose which receivers/antennas to use */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6051 | if (il->cfg->ops->hcmd->set_rxon_chain) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6052 | il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6053 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6054 | il_init_scan_params(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6055 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6056 | ret = il_init_channel_map(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6057 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6058 | IL_ERR("initializing regulatory failed: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6059 | goto err; |
| 6060 | } |
| 6061 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6062 | ret = il_init_geos(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6063 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6064 | IL_ERR("initializing geos failed: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6065 | goto err_free_channel_map; |
| 6066 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6067 | il4965_init_hw_rates(il, il->ieee_rates); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6068 | |
| 6069 | return 0; |
| 6070 | |
| 6071 | err_free_channel_map: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6072 | il_free_channel_map(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6073 | err: |
| 6074 | return ret; |
| 6075 | } |
| 6076 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6077 | static void |
| 6078 | il4965_uninit_drv(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6079 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6080 | il4965_calib_free_results(il); |
| 6081 | il_free_geos(il); |
| 6082 | il_free_channel_map(il); |
| 6083 | kfree(il->scan_cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6084 | } |
| 6085 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6086 | static void |
| 6087 | il4965_hw_detect(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6088 | { |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 6089 | il->hw_rev = _il_rd(il, CSR_HW_REV); |
| 6090 | il->hw_wa_rev = _il_rd(il, CSR_HW_REV_WA_REG); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6091 | il->rev_id = il->pci_dev->revision; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6092 | D_INFO("HW Revision ID = 0x%X\n", il->rev_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6093 | } |
| 6094 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6095 | static int |
| 6096 | il4965_set_hw_params(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6097 | { |
Stanislaw Gruszka | b16db50 | 2012-02-03 17:31:44 +0100 | [diff] [blame] | 6098 | il->hw_params.bcast_id = IL4965_BROADCAST_ID; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6099 | il->hw_params.max_rxq_size = RX_QUEUE_SIZE; |
| 6100 | il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; |
| 6101 | if (il->cfg->mod_params->amsdu_size_8K) |
| 6102 | il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_8K); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6103 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6104 | il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_4K); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6105 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6106 | il->hw_params.max_beacon_itrvl = IL_MAX_UCODE_BEACON_INTERVAL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6107 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6108 | if (il->cfg->mod_params->disable_11n) |
| 6109 | il->cfg->sku &= ~IL_SKU_N; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6110 | |
| 6111 | /* Device-specific setup */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6112 | return il->cfg->ops->lib->set_hw_params(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6113 | } |
| 6114 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6115 | static int |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6116 | il4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6117 | { |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6118 | int err = 0; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6119 | struct il_priv *il; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6120 | struct ieee80211_hw *hw; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6121 | struct il_cfg *cfg = (struct il_cfg *)(ent->driver_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6122 | unsigned long flags; |
| 6123 | u16 pci_cmd; |
| 6124 | |
| 6125 | /************************ |
| 6126 | * 1. Allocating HW data |
| 6127 | ************************/ |
| 6128 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6129 | hw = il_alloc_all(cfg); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6130 | if (!hw) { |
| 6131 | err = -ENOMEM; |
| 6132 | goto out; |
| 6133 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6134 | il = hw->priv; |
| 6135 | /* At this point both hw and il are allocated. */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6136 | |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6137 | il->ctx.always_active = true; |
| 6138 | il->ctx.is_active = true; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6139 | |
| 6140 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 6141 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6142 | D_INFO("*** LOAD DRIVER ***\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6143 | il->cfg = cfg; |
| 6144 | il->pci_dev = pdev; |
| 6145 | il->inta_mask = CSR_INI_SET_MASK; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6146 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6147 | if (il_alloc_traffic_mem(il)) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6148 | IL_ERR("Not enough memory to generate traffic log\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6149 | |
| 6150 | /************************** |
| 6151 | * 2. Initializing PCI bus |
| 6152 | **************************/ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6153 | pci_disable_link_state(pdev, |
| 6154 | PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 6155 | PCIE_LINK_STATE_CLKPM); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6156 | |
| 6157 | if (pci_enable_device(pdev)) { |
| 6158 | err = -ENODEV; |
| 6159 | goto out_ieee80211_free_hw; |
| 6160 | } |
| 6161 | |
| 6162 | pci_set_master(pdev); |
| 6163 | |
| 6164 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36)); |
| 6165 | if (!err) |
| 6166 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36)); |
| 6167 | if (err) { |
| 6168 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 6169 | if (!err) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6170 | err = |
| 6171 | pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6172 | /* both attempts failed: */ |
| 6173 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6174 | IL_WARN("No suitable DMA available.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6175 | goto out_pci_disable_device; |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | err = pci_request_regions(pdev, DRV_NAME); |
| 6180 | if (err) |
| 6181 | goto out_pci_disable_device; |
| 6182 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6183 | pci_set_drvdata(pdev, il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6184 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6185 | /*********************** |
| 6186 | * 3. Read REV register |
| 6187 | ***********************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6188 | il->hw_base = pci_iomap(pdev, 0, 0); |
| 6189 | if (!il->hw_base) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6190 | err = -ENODEV; |
| 6191 | goto out_pci_release_regions; |
| 6192 | } |
| 6193 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6194 | D_INFO("pci_resource_len = 0x%08llx\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6195 | (unsigned long long)pci_resource_len(pdev, 0)); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6196 | D_INFO("pci_resource_base = %p\n", il->hw_base); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6197 | |
| 6198 | /* these spin locks will be used in apm_ops.init and EEPROM access |
| 6199 | * we should init now |
| 6200 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6201 | spin_lock_init(&il->reg_lock); |
| 6202 | spin_lock_init(&il->lock); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6203 | |
| 6204 | /* |
| 6205 | * stop and reset the on-board processor just in case it is in a |
| 6206 | * strange state ... like being left stranded by a primary kernel |
| 6207 | * and this is now the kdump kernel trying to start up |
| 6208 | */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 6209 | _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6210 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6211 | il4965_hw_detect(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6212 | IL_INFO("Detected %s, REV=0x%X\n", il->cfg->name, il->hw_rev); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6213 | |
| 6214 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 6215 | * PCI Tx retries from interfering with C3 CPU state */ |
| 6216 | pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00); |
| 6217 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6218 | il4965_prepare_card_hw(il); |
| 6219 | if (!il->hw_ready) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6220 | IL_WARN("Failed, HW not ready\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6221 | goto out_iounmap; |
| 6222 | } |
| 6223 | |
| 6224 | /***************** |
| 6225 | * 4. Read EEPROM |
| 6226 | *****************/ |
| 6227 | /* Read the EEPROM */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6228 | err = il_eeprom_init(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6229 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6230 | IL_ERR("Unable to init EEPROM\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6231 | goto out_iounmap; |
| 6232 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6233 | err = il4965_eeprom_check_version(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6234 | if (err) |
| 6235 | goto out_free_eeprom; |
| 6236 | |
| 6237 | if (err) |
| 6238 | goto out_free_eeprom; |
| 6239 | |
| 6240 | /* extract MAC Address */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6241 | il4965_eeprom_get_mac(il, il->addresses[0].addr); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6242 | D_INFO("MAC address: %pM\n", il->addresses[0].addr); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6243 | il->hw->wiphy->addresses = il->addresses; |
| 6244 | il->hw->wiphy->n_addresses = 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6245 | |
| 6246 | /************************ |
| 6247 | * 5. Setup HW constants |
| 6248 | ************************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6249 | if (il4965_set_hw_params(il)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6250 | IL_ERR("failed to set hw parameters\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6251 | goto out_free_eeprom; |
| 6252 | } |
| 6253 | |
| 6254 | /******************* |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6255 | * 6. Setup il |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6256 | *******************/ |
| 6257 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6258 | err = il4965_init_drv(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6259 | if (err) |
| 6260 | goto out_free_eeprom; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6261 | /* At this point both hw and il are initialized. */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6262 | |
| 6263 | /******************** |
| 6264 | * 7. Setup services |
| 6265 | ********************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6266 | spin_lock_irqsave(&il->lock, flags); |
| 6267 | il_disable_interrupts(il); |
| 6268 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6269 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6270 | pci_enable_msi(il->pci_dev); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6271 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6272 | err = request_irq(il->pci_dev->irq, il_isr, IRQF_SHARED, DRV_NAME, il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6273 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6274 | IL_ERR("Error allocating IRQ %d\n", il->pci_dev->irq); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6275 | goto out_disable_msi; |
| 6276 | } |
| 6277 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6278 | il4965_setup_deferred_work(il); |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 6279 | il4965_setup_handlers(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6280 | |
| 6281 | /********************************************* |
| 6282 | * 8. Enable interrupts and read RFKILL state |
| 6283 | *********************************************/ |
| 6284 | |
Stanislaw Gruszka | a078a1f | 2011-04-28 11:51:25 +0200 | [diff] [blame] | 6285 | /* enable rfkill interrupt: hw bug w/a */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6286 | pci_read_config_word(il->pci_dev, PCI_COMMAND, &pci_cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6287 | if (pci_cmd & PCI_COMMAND_INTX_DISABLE) { |
| 6288 | pci_cmd &= ~PCI_COMMAND_INTX_DISABLE; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6289 | pci_write_config_word(il->pci_dev, PCI_COMMAND, pci_cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6290 | } |
| 6291 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6292 | il_enable_rfkill_int(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6293 | |
| 6294 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6295 | if (_il_rd(il, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 6296 | clear_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6297 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 6298 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6299 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6300 | wiphy_rfkill_set_hw_state(il->hw->wiphy, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6301 | test_bit(S_RF_KILL_HW, &il->status)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6302 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6303 | il_power_initialize(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6304 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6305 | init_completion(&il->_4965.firmware_loading_complete); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6306 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6307 | err = il4965_request_firmware(il, true); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6308 | if (err) |
| 6309 | goto out_destroy_workqueue; |
| 6310 | |
| 6311 | return 0; |
| 6312 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6313 | out_destroy_workqueue: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6314 | destroy_workqueue(il->workqueue); |
| 6315 | il->workqueue = NULL; |
| 6316 | free_irq(il->pci_dev->irq, il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6317 | out_disable_msi: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6318 | pci_disable_msi(il->pci_dev); |
| 6319 | il4965_uninit_drv(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6320 | out_free_eeprom: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6321 | il_eeprom_free(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6322 | out_iounmap: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6323 | pci_iounmap(pdev, il->hw_base); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6324 | out_pci_release_regions: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6325 | pci_set_drvdata(pdev, NULL); |
| 6326 | pci_release_regions(pdev); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6327 | out_pci_disable_device: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6328 | pci_disable_device(pdev); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6329 | out_ieee80211_free_hw: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6330 | il_free_traffic_mem(il); |
| 6331 | ieee80211_free_hw(il->hw); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6332 | out: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6333 | return err; |
| 6334 | } |
| 6335 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6336 | static void __devexit |
| 6337 | il4965_pci_remove(struct pci_dev *pdev) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6338 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6339 | struct il_priv *il = pci_get_drvdata(pdev); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6340 | unsigned long flags; |
| 6341 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6342 | if (!il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6343 | return; |
| 6344 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6345 | wait_for_completion(&il->_4965.firmware_loading_complete); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6346 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6347 | D_INFO("*** UNLOAD DRIVER ***\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6348 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6349 | il_dbgfs_unregister(il); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6350 | sysfs_remove_group(&pdev->dev.kobj, &il_attribute_group); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6351 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6352 | /* ieee80211_unregister_hw call wil cause il_mac_stop to |
| 6353 | * to be called and il4965_down since we are removing the device |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 6354 | * we need to set S_EXIT_PENDING bit. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6355 | */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 6356 | set_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6357 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6358 | il_leds_exit(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6359 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6360 | if (il->mac80211_registered) { |
| 6361 | ieee80211_unregister_hw(il->hw); |
| 6362 | il->mac80211_registered = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6363 | } else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6364 | il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6365 | } |
| 6366 | |
| 6367 | /* |
| 6368 | * Make sure device is reset to low power before unloading driver. |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6369 | * This may be redundant with il4965_down(), but there are paths to |
| 6370 | * run il4965_down() without calling apm_ops.stop(), and there are |
| 6371 | * paths to avoid running il4965_down() at all before leaving driver. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6372 | * This (inexpensive) call *makes sure* device is reset. |
| 6373 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6374 | il_apm_stop(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6375 | |
| 6376 | /* make sure we flush any pending irq or |
| 6377 | * tasklet for the driver |
| 6378 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6379 | spin_lock_irqsave(&il->lock, flags); |
| 6380 | il_disable_interrupts(il); |
| 6381 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6382 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6383 | il4965_synchronize_irq(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6384 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6385 | il4965_dealloc_ucode_pci(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6386 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6387 | if (il->rxq.bd) |
| 6388 | il4965_rx_queue_free(il, &il->rxq); |
| 6389 | il4965_hw_txq_ctx_free(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6390 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6391 | il_eeprom_free(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6392 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6393 | /*netif_stop_queue(dev); */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6394 | flush_workqueue(il->workqueue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6395 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6396 | /* ieee80211_unregister_hw calls il_mac_stop, which flushes |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6397 | * il->workqueue... so we can't take down the workqueue |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6398 | * until now... */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6399 | destroy_workqueue(il->workqueue); |
| 6400 | il->workqueue = NULL; |
| 6401 | il_free_traffic_mem(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6402 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6403 | free_irq(il->pci_dev->irq, il); |
| 6404 | pci_disable_msi(il->pci_dev); |
| 6405 | pci_iounmap(pdev, il->hw_base); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6406 | pci_release_regions(pdev); |
| 6407 | pci_disable_device(pdev); |
| 6408 | pci_set_drvdata(pdev, NULL); |
| 6409 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6410 | il4965_uninit_drv(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6411 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6412 | dev_kfree_skb(il->beacon_skb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6413 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6414 | ieee80211_free_hw(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6415 | } |
| 6416 | |
| 6417 | /* |
| 6418 | * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6419 | * must be called under il->lock and mac access |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6420 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6421 | void |
| 6422 | il4965_txq_set_sched(struct il_priv *il, u32 mask) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6423 | { |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 6424 | il_wr_prph(il, IL49_SCD_TXFACT, mask); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6425 | } |
| 6426 | |
| 6427 | /***************************************************************************** |
| 6428 | * |
| 6429 | * driver and module entry point |
| 6430 | * |
| 6431 | *****************************************************************************/ |
| 6432 | |
| 6433 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6434 | static DEFINE_PCI_DEVICE_TABLE(il4965_hw_card_ids) = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6435 | {IL_PCI_DEVICE(0x4229, PCI_ANY_ID, il4965_cfg)}, |
| 6436 | {IL_PCI_DEVICE(0x4230, PCI_ANY_ID, il4965_cfg)}, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6437 | {0} |
| 6438 | }; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6439 | MODULE_DEVICE_TABLE(pci, il4965_hw_card_ids); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6440 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6441 | static struct pci_driver il4965_driver = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6442 | .name = DRV_NAME, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6443 | .id_table = il4965_hw_card_ids, |
| 6444 | .probe = il4965_pci_probe, |
| 6445 | .remove = __devexit_p(il4965_pci_remove), |
| 6446 | .driver.pm = IL_LEGACY_PM_OPS, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6447 | }; |
| 6448 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6449 | static int __init |
| 6450 | il4965_init(void) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6451 | { |
| 6452 | |
| 6453 | int ret; |
| 6454 | pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 6455 | pr_info(DRV_COPYRIGHT "\n"); |
| 6456 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6457 | ret = il4965_rate_control_register(); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6458 | if (ret) { |
| 6459 | pr_err("Unable to register rate control algorithm: %d\n", ret); |
| 6460 | return ret; |
| 6461 | } |
| 6462 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6463 | ret = pci_register_driver(&il4965_driver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6464 | if (ret) { |
| 6465 | pr_err("Unable to initialize PCI module\n"); |
| 6466 | goto error_register; |
| 6467 | } |
| 6468 | |
| 6469 | return ret; |
| 6470 | |
| 6471 | error_register: |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6472 | il4965_rate_control_unregister(); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6473 | return ret; |
| 6474 | } |
| 6475 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6476 | static void __exit |
| 6477 | il4965_exit(void) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6478 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6479 | pci_unregister_driver(&il4965_driver); |
| 6480 | il4965_rate_control_unregister(); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6481 | } |
| 6482 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6483 | module_exit(il4965_exit); |
| 6484 | module_init(il4965_init); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6485 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 6486 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | d2ddf62 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 6487 | module_param_named(debug, il_debug_level, uint, S_IRUGO | S_IWUSR); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6488 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 6489 | #endif |
| 6490 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6491 | module_param_named(swcrypto, il4965_mod_params.sw_crypto, int, S_IRUGO); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6492 | MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6493 | module_param_named(queues_num, il4965_mod_params.num_of_queues, int, S_IRUGO); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6494 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6495 | module_param_named(11n_disable, il4965_mod_params.disable_11n, int, S_IRUGO); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6496 | MODULE_PARM_DESC(11n_disable, "disable 11n functionality"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6497 | module_param_named(amsdu_size_8K, il4965_mod_params.amsdu_size_8K, int, |
| 6498 | S_IRUGO); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6499 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6500 | module_param_named(fw_restart, il4965_mod_params.restart_fw, int, S_IRUGO); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6501 | MODULE_PARM_DESC(fw_restart, "restart firmware in case of error"); |