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 | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 822 | static inline u32 |
| 823 | il4965_ant_idx_to_flags(u8 ant_idx) |
Stanislaw Gruszka | af038f4 | 2011-08-30 13:58:27 +0200 | [diff] [blame] | 824 | { |
| 825 | return BIT(ant_idx) << RATE_MCS_ANT_POS; |
| 826 | } |
| 827 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 828 | int |
| 829 | il4965_request_scan(struct il_priv *il, struct ieee80211_vif *vif) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 830 | { |
| 831 | struct il_host_cmd cmd = { |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 832 | .id = C_SCAN, |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 833 | .len = sizeof(struct il_scan_cmd), |
| 834 | .flags = CMD_SIZE_HUGE, |
| 835 | }; |
| 836 | struct il_scan_cmd *scan; |
| 837 | struct il_rxon_context *ctx = &il->ctx; |
| 838 | u32 rate_flags = 0; |
| 839 | u16 cmd_len; |
| 840 | u16 rx_chain = 0; |
| 841 | enum ieee80211_band band; |
| 842 | u8 n_probes = 0; |
| 843 | u8 rx_ant = il->hw_params.valid_rx_ant; |
| 844 | u8 rate; |
| 845 | bool is_active = false; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 846 | int chan_mod; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 847 | u8 active_chains; |
| 848 | u8 scan_tx_antennas = il->hw_params.valid_tx_ant; |
| 849 | int ret; |
| 850 | |
| 851 | lockdep_assert_held(&il->mutex); |
| 852 | |
Greg Dietsche | 730b4c2 | 2011-09-06 17:33:51 -0500 | [diff] [blame^] | 853 | ctx = il_rxon_ctx_from_vif(vif); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 854 | |
| 855 | if (!il->scan_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 856 | il->scan_cmd = |
| 857 | kmalloc(sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE, |
| 858 | GFP_KERNEL); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 859 | if (!il->scan_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 860 | D_SCAN("fail to allocate memory for scan\n"); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 861 | return -ENOMEM; |
| 862 | } |
| 863 | } |
| 864 | scan = il->scan_cmd; |
| 865 | memset(scan, 0, sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE); |
| 866 | |
| 867 | scan->quiet_plcp_th = IL_PLCP_QUIET_THRESH; |
| 868 | scan->quiet_time = IL_ACTIVE_QUIET_TIME; |
| 869 | |
| 870 | if (il_is_any_associated(il)) { |
| 871 | u16 interval; |
| 872 | u32 extra; |
| 873 | u32 suspend_time = 100; |
| 874 | u32 scan_suspend_time = 100; |
| 875 | |
| 876 | D_INFO("Scanning while associated...\n"); |
| 877 | interval = vif->bss_conf.beacon_int; |
| 878 | |
| 879 | scan->suspend_time = 0; |
| 880 | scan->max_out_time = cpu_to_le32(200 * 1024); |
| 881 | if (!interval) |
| 882 | interval = suspend_time; |
| 883 | |
| 884 | extra = (suspend_time / interval) << 22; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 885 | scan_suspend_time = |
| 886 | (extra | ((suspend_time % interval) * 1024)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 887 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 888 | D_SCAN("suspend_time 0x%X beacon interval %d\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 889 | scan_suspend_time, interval); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | if (il->scan_request->n_ssids) { |
| 893 | int i, p = 0; |
| 894 | D_SCAN("Kicking off active scan\n"); |
| 895 | for (i = 0; i < il->scan_request->n_ssids; i++) { |
| 896 | /* always does wildcard anyway */ |
| 897 | if (!il->scan_request->ssids[i].ssid_len) |
| 898 | continue; |
| 899 | scan->direct_scan[p].id = WLAN_EID_SSID; |
| 900 | scan->direct_scan[p].len = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 901 | il->scan_request->ssids[i].ssid_len; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 902 | memcpy(scan->direct_scan[p].ssid, |
| 903 | il->scan_request->ssids[i].ssid, |
| 904 | il->scan_request->ssids[i].ssid_len); |
| 905 | n_probes++; |
| 906 | p++; |
| 907 | } |
| 908 | is_active = true; |
| 909 | } else |
| 910 | D_SCAN("Start passive scan.\n"); |
| 911 | |
| 912 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 913 | scan->tx_cmd.sta_id = ctx->bcast_sta_id; |
| 914 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 915 | |
| 916 | switch (il->scan_band) { |
| 917 | case IEEE80211_BAND_2GHZ: |
| 918 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 919 | chan_mod = |
| 920 | le32_to_cpu(il->ctx.active. |
| 921 | flags & RXON_FLG_CHANNEL_MODE_MSK) >> |
| 922 | RXON_FLG_CHANNEL_MODE_POS; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 923 | if (chan_mod == CHANNEL_MODE_PURE_40) { |
| 924 | rate = RATE_6M_PLCP; |
| 925 | } else { |
| 926 | rate = RATE_1M_PLCP; |
| 927 | rate_flags = RATE_MCS_CCK_MSK; |
| 928 | } |
| 929 | break; |
| 930 | case IEEE80211_BAND_5GHZ: |
| 931 | rate = RATE_6M_PLCP; |
| 932 | break; |
| 933 | default: |
| 934 | IL_WARN("Invalid scan band\n"); |
| 935 | return -EIO; |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * If active scanning is requested but a certain channel is |
| 940 | * marked passive, we can do active scanning if we detect |
| 941 | * transmissions. |
| 942 | * |
| 943 | * There is an issue with some firmware versions that triggers |
| 944 | * a sysassert on a "good CRC threshold" of zero (== disabled), |
| 945 | * on a radar channel even though this means that we should NOT |
| 946 | * send probes. |
| 947 | * |
| 948 | * The "good CRC threshold" is the number of frames that we |
| 949 | * need to receive during our dwell time on a channel before |
| 950 | * sending out probes -- setting this to a huge value will |
| 951 | * mean we never reach it, but at the same time work around |
| 952 | * the aforementioned issue. Thus use IL_GOOD_CRC_TH_NEVER |
| 953 | * here instead of IL_GOOD_CRC_TH_DISABLED. |
| 954 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 955 | scan->good_CRC_th = |
| 956 | is_active ? IL_GOOD_CRC_TH_DEFAULT : IL_GOOD_CRC_TH_NEVER; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 957 | |
| 958 | band = il->scan_band; |
| 959 | |
| 960 | if (il->cfg->scan_rx_antennas[band]) |
| 961 | rx_ant = il->cfg->scan_rx_antennas[band]; |
| 962 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 963 | il->scan_tx_ant[band] = |
| 964 | il4965_toggle_tx_ant(il, il->scan_tx_ant[band], scan_tx_antennas); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 965 | rate_flags |= il4965_ant_idx_to_flags(il->scan_tx_ant[band]); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 966 | scan->tx_cmd.rate_n_flags = |
| 967 | il4965_hw_set_rate_n_flags(rate, rate_flags); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 968 | |
| 969 | /* In power save mode use one chain, otherwise use all chains */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 970 | if (test_bit(S_POWER_PMI, &il->status)) { |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 971 | /* rx_ant has been set to all valid chains previously */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 972 | active_chains = |
| 973 | rx_ant & ((u8) (il->chain_noise_data.active_chains)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 974 | if (!active_chains) |
| 975 | active_chains = rx_ant; |
| 976 | |
| 977 | D_SCAN("chain_noise_data.active_chains: %u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 978 | il->chain_noise_data.active_chains); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 979 | |
| 980 | rx_ant = il4965_first_antenna(active_chains); |
| 981 | } |
| 982 | |
| 983 | /* MIMO is not used here, but value is required */ |
| 984 | rx_chain |= il->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS; |
| 985 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS; |
| 986 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS; |
| 987 | rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS; |
| 988 | scan->rx_chain = cpu_to_le16(rx_chain); |
| 989 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 990 | cmd_len = |
| 991 | il_fill_probe_req(il, (struct ieee80211_mgmt *)scan->data, |
| 992 | vif->addr, il->scan_request->ie, |
| 993 | il->scan_request->ie_len, |
| 994 | IL_MAX_SCAN_SIZE - sizeof(*scan)); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 995 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
| 996 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 997 | scan->filter_flags |= |
| 998 | (RXON_FILTER_ACCEPT_GRP_MSK | RXON_FILTER_BCON_AWARE_MSK); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 999 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1000 | scan->channel_count = |
| 1001 | il4965_get_channels_for_scan(il, vif, band, is_active, n_probes, |
| 1002 | (void *)&scan->data[cmd_len]); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1003 | if (scan->channel_count == 0) { |
| 1004 | D_SCAN("channel count %d\n", scan->channel_count); |
| 1005 | return -EIO; |
| 1006 | } |
| 1007 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1008 | cmd.len += |
| 1009 | le16_to_cpu(scan->tx_cmd.len) + |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1010 | scan->channel_count * sizeof(struct il_scan_channel); |
| 1011 | cmd.data = scan; |
| 1012 | scan->len = cpu_to_le16(cmd.len); |
| 1013 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1014 | set_bit(S_SCAN_HW, &il->status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1015 | |
| 1016 | ret = il_send_cmd_sync(il, &cmd); |
| 1017 | if (ret) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1018 | clear_bit(S_SCAN_HW, &il->status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1019 | |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1023 | int |
| 1024 | il4965_manage_ibss_station(struct il_priv *il, struct ieee80211_vif *vif, |
| 1025 | bool add) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1026 | { |
| 1027 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 1028 | |
| 1029 | if (add) |
| 1030 | return il4965_add_bssid_station(il, vif_priv->ctx, |
| 1031 | vif->bss_conf.bssid, |
| 1032 | &vif_priv->ibss_bssid_sta_id); |
| 1033 | return il_remove_station(il, vif_priv->ibss_bssid_sta_id, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1034 | vif->bss_conf.bssid); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1035 | } |
| 1036 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1037 | void |
| 1038 | 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] | 1039 | { |
| 1040 | lockdep_assert_held(&il->sta_lock); |
| 1041 | |
| 1042 | if (il->stations[sta_id].tid[tid].tfds_in_queue >= freed) |
| 1043 | il->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 1044 | else { |
| 1045 | D_TX("free more than tfds_in_queue (%u:%d)\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1046 | il->stations[sta_id].tid[tid].tfds_in_queue, freed); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1047 | il->stations[sta_id].tid[tid].tfds_in_queue = 0; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | #define IL_TX_QUEUE_MSK 0xfffff |
| 1052 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1053 | static bool |
| 1054 | il4965_is_single_rx_stream(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1055 | { |
| 1056 | return il->current_ht_config.smps == IEEE80211_SMPS_STATIC || |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1057 | il->current_ht_config.single_chain_sufficient; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | #define IL_NUM_RX_CHAINS_MULTIPLE 3 |
| 1061 | #define IL_NUM_RX_CHAINS_SINGLE 2 |
| 1062 | #define IL_NUM_IDLE_CHAINS_DUAL 2 |
| 1063 | #define IL_NUM_IDLE_CHAINS_SINGLE 1 |
| 1064 | |
| 1065 | /* |
| 1066 | * Determine how many receiver/antenna chains to use. |
| 1067 | * |
| 1068 | * More provides better reception via diversity. Fewer saves power |
| 1069 | * at the expense of throughput, but only when not in powersave to |
| 1070 | * start with. |
| 1071 | * |
| 1072 | * MIMO (dual stream) requires at least 2, but works better with 3. |
| 1073 | * This does not determine *which* chains to use, just how many. |
| 1074 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1075 | static int |
| 1076 | il4965_get_active_rx_chain_count(struct il_priv *il) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1077 | { |
| 1078 | /* # of Rx chains to use when expecting MIMO. */ |
| 1079 | if (il4965_is_single_rx_stream(il)) |
| 1080 | return IL_NUM_RX_CHAINS_SINGLE; |
| 1081 | else |
| 1082 | return IL_NUM_RX_CHAINS_MULTIPLE; |
| 1083 | } |
| 1084 | |
| 1085 | /* |
| 1086 | * When we are in power saving mode, unless device support spatial |
| 1087 | * multiplexing power save, use the active count for rx chain count. |
| 1088 | */ |
| 1089 | static int |
| 1090 | il4965_get_idle_rx_chain_count(struct il_priv *il, int active_cnt) |
| 1091 | { |
| 1092 | /* # Rx chains when idling, depending on SMPS mode */ |
| 1093 | switch (il->current_ht_config.smps) { |
| 1094 | case IEEE80211_SMPS_STATIC: |
| 1095 | case IEEE80211_SMPS_DYNAMIC: |
| 1096 | return IL_NUM_IDLE_CHAINS_SINGLE; |
| 1097 | case IEEE80211_SMPS_OFF: |
| 1098 | return active_cnt; |
| 1099 | default: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1100 | WARN(1, "invalid SMPS mode %d", il->current_ht_config.smps); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1101 | return active_cnt; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | /* up to 4 chains */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1106 | static u8 |
| 1107 | il4965_count_chain_bitmap(u32 chain_bitmap) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1108 | { |
| 1109 | u8 res; |
| 1110 | res = (chain_bitmap & BIT(0)) >> 0; |
| 1111 | res += (chain_bitmap & BIT(1)) >> 1; |
| 1112 | res += (chain_bitmap & BIT(2)) >> 2; |
| 1113 | res += (chain_bitmap & BIT(3)) >> 3; |
| 1114 | return res; |
| 1115 | } |
| 1116 | |
| 1117 | /** |
| 1118 | * il4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image |
| 1119 | * |
| 1120 | * Selects how many and which Rx receivers/antennas/chains to use. |
| 1121 | * This should not be used for scan command ... it puts data in wrong place. |
| 1122 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1123 | void |
| 1124 | 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] | 1125 | { |
| 1126 | bool is_single = il4965_is_single_rx_stream(il); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1127 | bool is_cam = !test_bit(S_POWER_PMI, &il->status); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1128 | u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt; |
| 1129 | u32 active_chains; |
| 1130 | u16 rx_chain; |
| 1131 | |
| 1132 | /* Tell uCode which antennas are actually connected. |
| 1133 | * Before first association, we assume all antennas are connected. |
| 1134 | * Just after first association, il4965_chain_noise_calibration() |
| 1135 | * checks which antennas actually *are* connected. */ |
| 1136 | if (il->chain_noise_data.active_chains) |
| 1137 | active_chains = il->chain_noise_data.active_chains; |
| 1138 | else |
| 1139 | active_chains = il->hw_params.valid_rx_ant; |
| 1140 | |
| 1141 | rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS; |
| 1142 | |
| 1143 | /* How many receivers should we use? */ |
| 1144 | active_rx_cnt = il4965_get_active_rx_chain_count(il); |
| 1145 | idle_rx_cnt = il4965_get_idle_rx_chain_count(il, active_rx_cnt); |
| 1146 | |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1147 | /* correct rx chain count according hw settings |
| 1148 | * and chain noise calibration |
| 1149 | */ |
| 1150 | valid_rx_cnt = il4965_count_chain_bitmap(active_chains); |
| 1151 | if (valid_rx_cnt < active_rx_cnt) |
| 1152 | active_rx_cnt = valid_rx_cnt; |
| 1153 | |
| 1154 | if (valid_rx_cnt < idle_rx_cnt) |
| 1155 | idle_rx_cnt = valid_rx_cnt; |
| 1156 | |
| 1157 | rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1158 | rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1159 | |
| 1160 | ctx->staging.rx_chain = cpu_to_le16(rx_chain); |
| 1161 | |
| 1162 | if (!is_single && active_rx_cnt >= IL_NUM_RX_CHAINS_SINGLE && is_cam) |
| 1163 | ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK; |
| 1164 | else |
| 1165 | ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK; |
| 1166 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1167 | D_ASSOC("rx_chain=0x%X active=%d idle=%d\n", ctx->staging.rx_chain, |
| 1168 | active_rx_cnt, idle_rx_cnt); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1169 | |
| 1170 | WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 || |
| 1171 | active_rx_cnt < idle_rx_cnt); |
| 1172 | } |
| 1173 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1174 | u8 |
| 1175 | il4965_toggle_tx_ant(struct il_priv *il, u8 ant, u8 valid) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1176 | { |
| 1177 | int i; |
| 1178 | u8 ind = ant; |
| 1179 | |
| 1180 | for (i = 0; i < RATE_ANT_NUM - 1; i++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1181 | ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0; |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1182 | if (valid & BIT(ind)) |
| 1183 | return ind; |
| 1184 | } |
| 1185 | return ant; |
| 1186 | } |
| 1187 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1188 | static const char * |
| 1189 | il4965_get_fh_string(int cmd) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1190 | { |
| 1191 | switch (cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1192 | IL_CMD(FH49_RSCSR_CHNL0_STTS_WPTR_REG); |
| 1193 | IL_CMD(FH49_RSCSR_CHNL0_RBDCB_BASE_REG); |
| 1194 | IL_CMD(FH49_RSCSR_CHNL0_WPTR); |
| 1195 | IL_CMD(FH49_MEM_RCSR_CHNL0_CONFIG_REG); |
| 1196 | IL_CMD(FH49_MEM_RSSR_SHARED_CTRL_REG); |
| 1197 | IL_CMD(FH49_MEM_RSSR_RX_STATUS_REG); |
| 1198 | IL_CMD(FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV); |
| 1199 | IL_CMD(FH49_TSSR_TX_STATUS_REG); |
| 1200 | IL_CMD(FH49_TSSR_TX_ERROR_REG); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1201 | default: |
| 1202 | return "UNKNOWN"; |
| 1203 | } |
| 1204 | } |
| 1205 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1206 | int |
| 1207 | il4965_dump_fh(struct il_priv *il, char **buf, bool display) |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1208 | { |
| 1209 | int i; |
| 1210 | #ifdef CONFIG_IWLEGACY_DEBUG |
| 1211 | int pos = 0; |
| 1212 | size_t bufsz = 0; |
| 1213 | #endif |
| 1214 | static const u32 fh_tbl[] = { |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 1215 | FH49_RSCSR_CHNL0_STTS_WPTR_REG, |
| 1216 | FH49_RSCSR_CHNL0_RBDCB_BASE_REG, |
| 1217 | FH49_RSCSR_CHNL0_WPTR, |
| 1218 | FH49_MEM_RCSR_CHNL0_CONFIG_REG, |
| 1219 | FH49_MEM_RSSR_SHARED_CTRL_REG, |
| 1220 | FH49_MEM_RSSR_RX_STATUS_REG, |
| 1221 | FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV, |
| 1222 | FH49_TSSR_TX_STATUS_REG, |
| 1223 | FH49_TSSR_TX_ERROR_REG |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1224 | }; |
| 1225 | #ifdef CONFIG_IWLEGACY_DEBUG |
| 1226 | if (display) { |
| 1227 | bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40; |
| 1228 | *buf = kmalloc(bufsz, GFP_KERNEL); |
| 1229 | if (!*buf) |
| 1230 | return -ENOMEM; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1231 | pos += |
| 1232 | scnprintf(*buf + pos, bufsz - pos, "FH register values:\n"); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1233 | for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1234 | pos += |
| 1235 | scnprintf(*buf + pos, bufsz - pos, |
| 1236 | " %34s: 0X%08x\n", |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1237 | 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 pos; |
| 1241 | } |
| 1242 | #endif |
| 1243 | IL_ERR("FH register values:\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1244 | for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) { |
| 1245 | IL_ERR(" %34s: 0X%08x\n", il4965_get_fh_string(fh_tbl[i]), |
| 1246 | il_rd(il, fh_tbl[i])); |
Stanislaw Gruszka | fcb7458 | 2011-08-30 13:06:03 +0200 | [diff] [blame] | 1247 | } |
| 1248 | return 0; |
| 1249 | } |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1250 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1251 | void |
| 1252 | 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] | 1253 | { |
| 1254 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 1255 | struct il_missed_beacon_notif *missed_beacon; |
| 1256 | |
| 1257 | missed_beacon = &pkt->u.missed_beacon; |
| 1258 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > |
| 1259 | il->missed_beacon_threshold) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1260 | D_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n", |
| 1261 | le32_to_cpu(missed_beacon->consecutive_missed_beacons), |
| 1262 | le32_to_cpu(missed_beacon->total_missed_becons), |
| 1263 | le32_to_cpu(missed_beacon->num_recvd_beacons), |
| 1264 | le32_to_cpu(missed_beacon->num_expected_beacons)); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1265 | if (!test_bit(S_SCANNING, &il->status)) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1266 | il4965_init_sensitivity(il); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | /* Calculate noise level, based on measurements during network silence just |
| 1271 | * before arriving beacon. This measurement can be done only if we know |
| 1272 | * exactly when to expect beacons, therefore only when we're associated. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1273 | static void |
| 1274 | il4965_rx_calc_noise(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1275 | { |
| 1276 | struct stats_rx_non_phy *rx_info; |
| 1277 | int num_active_rx = 0; |
| 1278 | int total_silence = 0; |
| 1279 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; |
| 1280 | int last_rx_noise; |
| 1281 | |
| 1282 | rx_info = &(il->_4965.stats.rx.general); |
| 1283 | bcn_silence_a = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1284 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1285 | bcn_silence_b = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1286 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1287 | bcn_silence_c = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1288 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1289 | |
| 1290 | if (bcn_silence_a) { |
| 1291 | total_silence += bcn_silence_a; |
| 1292 | num_active_rx++; |
| 1293 | } |
| 1294 | if (bcn_silence_b) { |
| 1295 | total_silence += bcn_silence_b; |
| 1296 | num_active_rx++; |
| 1297 | } |
| 1298 | if (bcn_silence_c) { |
| 1299 | total_silence += bcn_silence_c; |
| 1300 | num_active_rx++; |
| 1301 | } |
| 1302 | |
| 1303 | /* Average among active antennas */ |
| 1304 | if (num_active_rx) |
| 1305 | last_rx_noise = (total_silence / num_active_rx) - 107; |
| 1306 | else |
| 1307 | last_rx_noise = IL_NOISE_MEAS_NOT_AVAILABLE; |
| 1308 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1309 | D_CALIB("inband silence a %u, b %u, c %u, dBm %d\n", bcn_silence_a, |
| 1310 | bcn_silence_b, bcn_silence_c, last_rx_noise); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
| 1314 | /* |
| 1315 | * based on the assumption of all stats counter are in DWORD |
| 1316 | * FIXME: This function is for debugging, do not deal with |
| 1317 | * the case of counters roll-over. |
| 1318 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1319 | static void |
| 1320 | il4965_accumulative_stats(struct il_priv *il, __le32 * stats) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1321 | { |
| 1322 | int i, size; |
| 1323 | __le32 *prev_stats; |
| 1324 | u32 *accum_stats; |
| 1325 | u32 *delta, *max_delta; |
| 1326 | struct stats_general_common *general, *accum_general; |
| 1327 | struct stats_tx *tx, *accum_tx; |
| 1328 | |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1329 | prev_stats = (__le32 *) &il->_4965.stats; |
| 1330 | accum_stats = (u32 *) &il->_4965.accum_stats; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1331 | size = sizeof(struct il_notif_stats); |
| 1332 | general = &il->_4965.stats.general.common; |
| 1333 | accum_general = &il->_4965.accum_stats.general.common; |
| 1334 | tx = &il->_4965.stats.tx; |
| 1335 | accum_tx = &il->_4965.accum_stats.tx; |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1336 | delta = (u32 *) &il->_4965.delta_stats; |
| 1337 | max_delta = (u32 *) &il->_4965.max_delta; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1338 | |
| 1339 | for (i = sizeof(__le32); i < size; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1340 | i += |
| 1341 | sizeof(__le32), stats++, prev_stats++, delta++, max_delta++, |
| 1342 | accum_stats++) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1343 | if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1344 | *delta = |
| 1345 | (le32_to_cpu(*stats) - le32_to_cpu(*prev_stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1346 | *accum_stats += *delta; |
| 1347 | if (*delta > *max_delta) |
| 1348 | *max_delta = *delta; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | /* reset accumulative stats for "no-counter" type stats */ |
| 1353 | accum_general->temperature = general->temperature; |
| 1354 | accum_general->ttl_timestamp = general->ttl_timestamp; |
| 1355 | } |
| 1356 | #endif |
| 1357 | |
| 1358 | #define REG_RECALIB_PERIOD (60) |
| 1359 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1360 | void |
| 1361 | il4965_hdl_stats(struct il_priv *il, struct il_rx_buf *rxb) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1362 | { |
| 1363 | int change; |
| 1364 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 1365 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1366 | D_RX("Statistics notification received (%d vs %d).\n", |
| 1367 | (int)sizeof(struct il_notif_stats), |
| 1368 | le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1369 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1370 | change = |
| 1371 | ((il->_4965.stats.general.common.temperature != |
| 1372 | pkt->u.stats.general.common.temperature) || |
| 1373 | ((il->_4965.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK) != |
| 1374 | (pkt->u.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK))); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1375 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 1376 | il4965_accumulative_stats(il, (__le32 *) &pkt->u.stats); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1377 | #endif |
| 1378 | |
| 1379 | /* TODO: reading some of stats is unneeded */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1380 | memcpy(&il->_4965.stats, &pkt->u.stats, sizeof(il->_4965.stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1381 | |
Stanislaw Gruszka | db7746f | 2011-11-15 13:11:50 +0100 | [diff] [blame] | 1382 | set_bit(S_STATS, &il->status); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1383 | |
| 1384 | /* Reschedule the stats timer to occur in |
| 1385 | * REG_RECALIB_PERIOD seconds to ensure we get a |
| 1386 | * thermal update even if the uCode doesn't give |
| 1387 | * us one */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1388 | mod_timer(&il->stats_periodic, |
| 1389 | jiffies + msecs_to_jiffies(REG_RECALIB_PERIOD * 1000)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1390 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 1391 | if (unlikely(!test_bit(S_SCANNING, &il->status)) && |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1392 | (pkt->hdr.cmd == N_STATS)) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1393 | il4965_rx_calc_noise(il); |
| 1394 | queue_work(il->workqueue, &il->run_time_calib_work); |
| 1395 | } |
| 1396 | if (il->cfg->ops->lib->temp_ops.temperature && change) |
| 1397 | il->cfg->ops->lib->temp_ops.temperature(il); |
| 1398 | } |
| 1399 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1400 | void |
| 1401 | 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] | 1402 | { |
| 1403 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 1404 | |
Stanislaw Gruszka | db7746f | 2011-11-15 13:11:50 +0100 | [diff] [blame] | 1405 | if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATS_CLEAR_MSK) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1406 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
| 1407 | memset(&il->_4965.accum_stats, 0, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1408 | sizeof(struct il_notif_stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1409 | memset(&il->_4965.delta_stats, 0, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1410 | sizeof(struct il_notif_stats)); |
| 1411 | memset(&il->_4965.max_delta, 0, sizeof(struct il_notif_stats)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1412 | #endif |
| 1413 | D_RX("Statistics have been cleared\n"); |
| 1414 | } |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 1415 | il4965_hdl_stats(il, rxb); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
Stanislaw Gruszka | 8f29b45 | 2011-11-15 12:57:25 +0100 | [diff] [blame] | 1418 | |
| 1419 | /* |
| 1420 | * mac80211 queues, ACs, hardware queues, FIFOs. |
| 1421 | * |
| 1422 | * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues |
| 1423 | * |
| 1424 | * Mac80211 uses the following numbers, which we get as from it |
| 1425 | * by way of skb_get_queue_mapping(skb): |
| 1426 | * |
| 1427 | * VO 0 |
| 1428 | * VI 1 |
| 1429 | * BE 2 |
| 1430 | * BK 3 |
| 1431 | * |
| 1432 | * |
| 1433 | * Regular (not A-MPDU) frames are put into hardware queues corresponding |
| 1434 | * to the FIFOs, see comments in iwl-prph.h. Aggregated frames get their |
| 1435 | * own queue per aggregation session (RA/TID combination), such queues are |
| 1436 | * set up to map into FIFOs too, for which we need an AC->FIFO mapping. In |
| 1437 | * order to map frames to the right queue, we also need an AC->hw queue |
| 1438 | * mapping. This is implemented here. |
| 1439 | * |
| 1440 | * 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] | 1441 | * 4965.c), the AC->hw queue mapping is the identity |
Stanislaw Gruszka | 8f29b45 | 2011-11-15 12:57:25 +0100 | [diff] [blame] | 1442 | * mapping. |
| 1443 | */ |
| 1444 | |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1445 | static const u8 tid_to_ac[] = { |
| 1446 | IEEE80211_AC_BE, |
| 1447 | IEEE80211_AC_BK, |
| 1448 | IEEE80211_AC_BK, |
| 1449 | IEEE80211_AC_BE, |
| 1450 | IEEE80211_AC_VI, |
| 1451 | IEEE80211_AC_VI, |
| 1452 | IEEE80211_AC_VO, |
| 1453 | IEEE80211_AC_VO |
| 1454 | }; |
| 1455 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1456 | static inline int |
| 1457 | il4965_get_ac_from_tid(u16 tid) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1458 | { |
| 1459 | if (likely(tid < ARRAY_SIZE(tid_to_ac))) |
| 1460 | return tid_to_ac[tid]; |
| 1461 | |
| 1462 | /* no support for TIDs 8-15 yet */ |
| 1463 | return -EINVAL; |
| 1464 | } |
| 1465 | |
| 1466 | static inline int |
| 1467 | il4965_get_fifo_from_tid(struct il_rxon_context *ctx, u16 tid) |
| 1468 | { |
| 1469 | if (likely(tid < ARRAY_SIZE(tid_to_ac))) |
| 1470 | return ctx->ac_to_fifo[tid_to_ac[tid]]; |
| 1471 | |
| 1472 | /* no support for TIDs 8-15 yet */ |
| 1473 | return -EINVAL; |
| 1474 | } |
| 1475 | |
| 1476 | /* |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1477 | * handle build C_TX command notification. |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1478 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1479 | static void |
| 1480 | il4965_tx_cmd_build_basic(struct il_priv *il, struct sk_buff *skb, |
| 1481 | struct il_tx_cmd *tx_cmd, |
| 1482 | struct ieee80211_tx_info *info, |
| 1483 | struct ieee80211_hdr *hdr, u8 std_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1484 | { |
| 1485 | __le16 fc = hdr->frame_control; |
| 1486 | __le32 tx_flags = tx_cmd->tx_flags; |
| 1487 | |
| 1488 | tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 1489 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
| 1490 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 1491 | if (ieee80211_is_mgmt(fc)) |
| 1492 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1493 | if (ieee80211_is_probe_resp(fc) && |
| 1494 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 1495 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 1496 | } else { |
| 1497 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 1498 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1499 | } |
| 1500 | |
| 1501 | if (ieee80211_is_back_req(fc)) |
| 1502 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 1503 | |
| 1504 | tx_cmd->sta_id = std_id; |
| 1505 | if (ieee80211_has_morefrags(fc)) |
| 1506 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 1507 | |
| 1508 | if (ieee80211_is_data_qos(fc)) { |
| 1509 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 1510 | tx_cmd->tid_tspec = qc[0] & 0xf; |
| 1511 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 1512 | } else { |
| 1513 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1514 | } |
| 1515 | |
| 1516 | il_tx_cmd_protection(il, info, fc, &tx_flags); |
| 1517 | |
| 1518 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 1519 | if (ieee80211_is_mgmt(fc)) { |
| 1520 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
| 1521 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3); |
| 1522 | else |
| 1523 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2); |
| 1524 | } else { |
| 1525 | tx_cmd->timeout.pm_frame_timeout = 0; |
| 1526 | } |
| 1527 | |
| 1528 | tx_cmd->driver_txop = 0; |
| 1529 | tx_cmd->tx_flags = tx_flags; |
| 1530 | tx_cmd->next_frame_len = 0; |
| 1531 | } |
| 1532 | |
| 1533 | #define RTS_DFAULT_RETRY_LIMIT 60 |
| 1534 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1535 | static void |
| 1536 | il4965_tx_cmd_build_rate(struct il_priv *il, struct il_tx_cmd *tx_cmd, |
| 1537 | struct ieee80211_tx_info *info, __le16 fc) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1538 | { |
| 1539 | u32 rate_flags; |
| 1540 | int rate_idx; |
| 1541 | u8 rts_retry_limit; |
| 1542 | u8 data_retry_limit; |
| 1543 | u8 rate_plcp; |
| 1544 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1545 | /* Set retry limit on DATA packets and Probe Responses */ |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1546 | if (ieee80211_is_probe_resp(fc)) |
| 1547 | data_retry_limit = 3; |
| 1548 | else |
| 1549 | data_retry_limit = IL4965_DEFAULT_TX_RETRY; |
| 1550 | tx_cmd->data_retry_limit = data_retry_limit; |
| 1551 | |
| 1552 | /* Set retry limit on RTS packets */ |
| 1553 | rts_retry_limit = RTS_DFAULT_RETRY_LIMIT; |
| 1554 | if (data_retry_limit < rts_retry_limit) |
| 1555 | rts_retry_limit = data_retry_limit; |
| 1556 | tx_cmd->rts_retry_limit = rts_retry_limit; |
| 1557 | |
| 1558 | /* DATA packets will use the uCode station table for rate/antenna |
| 1559 | * selection */ |
| 1560 | if (ieee80211_is_data(fc)) { |
| 1561 | tx_cmd->initial_rate_idx = 0; |
| 1562 | tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; |
| 1563 | return; |
| 1564 | } |
| 1565 | |
| 1566 | /** |
| 1567 | * If the current TX rate stored in mac80211 has the MCS bit set, it's |
| 1568 | * not really a TX rate. Thus, we use the lowest supported rate for |
| 1569 | * this band. Also use the lowest supported rate if the stored rate |
| 1570 | * idx is invalid. |
| 1571 | */ |
| 1572 | rate_idx = info->control.rates[0].idx; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1573 | if ((info->control.rates[0].flags & IEEE80211_TX_RC_MCS) || rate_idx < 0 |
| 1574 | || rate_idx > RATE_COUNT_LEGACY) |
| 1575 | rate_idx = |
| 1576 | rate_lowest_index(&il->bands[info->band], |
| 1577 | info->control.sta); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1578 | /* For 5 GHZ band, remap mac80211 rate indices into driver indices */ |
| 1579 | if (info->band == IEEE80211_BAND_5GHZ) |
| 1580 | rate_idx += IL_FIRST_OFDM_RATE; |
| 1581 | /* Get PLCP rate for tx_cmd->rate_n_flags */ |
| 1582 | rate_plcp = il_rates[rate_idx].plcp; |
| 1583 | /* Zero out flags for this packet */ |
| 1584 | rate_flags = 0; |
| 1585 | |
| 1586 | /* Set CCK flag as needed */ |
| 1587 | if (rate_idx >= IL_FIRST_CCK_RATE && rate_idx <= IL_LAST_CCK_RATE) |
| 1588 | rate_flags |= RATE_MCS_CCK_MSK; |
| 1589 | |
| 1590 | /* Set up antennas */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1591 | il->mgmt_tx_ant = |
| 1592 | il4965_toggle_tx_ant(il, il->mgmt_tx_ant, |
| 1593 | il->hw_params.valid_tx_ant); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1594 | |
| 1595 | rate_flags |= il4965_ant_idx_to_flags(il->mgmt_tx_ant); |
| 1596 | |
| 1597 | /* Set the rate in the TX cmd */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1598 | tx_cmd->rate_n_flags = |
| 1599 | il4965_hw_set_rate_n_flags(rate_plcp, rate_flags); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1600 | } |
| 1601 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1602 | static void |
| 1603 | il4965_tx_cmd_build_hwcrypto(struct il_priv *il, struct ieee80211_tx_info *info, |
| 1604 | struct il_tx_cmd *tx_cmd, struct sk_buff *skb_frag, |
| 1605 | int sta_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1606 | { |
| 1607 | struct ieee80211_key_conf *keyconf = info->control.hw_key; |
| 1608 | |
| 1609 | switch (keyconf->cipher) { |
| 1610 | case WLAN_CIPHER_SUITE_CCMP: |
| 1611 | tx_cmd->sec_ctl = TX_CMD_SEC_CCM; |
| 1612 | memcpy(tx_cmd->key, keyconf->key, keyconf->keylen); |
| 1613 | if (info->flags & IEEE80211_TX_CTL_AMPDU) |
| 1614 | tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; |
| 1615 | D_TX("tx_cmd with AES hwcrypto\n"); |
| 1616 | break; |
| 1617 | |
| 1618 | case WLAN_CIPHER_SUITE_TKIP: |
| 1619 | tx_cmd->sec_ctl = TX_CMD_SEC_TKIP; |
| 1620 | ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key); |
| 1621 | D_TX("tx_cmd with tkip hwcrypto\n"); |
| 1622 | break; |
| 1623 | |
| 1624 | case WLAN_CIPHER_SUITE_WEP104: |
| 1625 | tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128; |
| 1626 | /* fall through */ |
| 1627 | case WLAN_CIPHER_SUITE_WEP40: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1628 | tx_cmd->sec_ctl |= |
| 1629 | (TX_CMD_SEC_WEP | (keyconf->keyidx & TX_CMD_SEC_MSK) << |
| 1630 | TX_CMD_SEC_SHIFT); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1631 | |
| 1632 | memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen); |
| 1633 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1634 | D_TX("Configuring packet for WEP encryption " "with key %d\n", |
| 1635 | keyconf->keyidx); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1636 | break; |
| 1637 | |
| 1638 | default: |
| 1639 | IL_ERR("Unknown encode cipher %x\n", keyconf->cipher); |
| 1640 | break; |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | /* |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1645 | * start C_TX command process |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1646 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1647 | int |
| 1648 | il4965_tx_skb(struct il_priv *il, struct sk_buff *skb) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1649 | { |
| 1650 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1651 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1652 | struct ieee80211_sta *sta = info->control.sta; |
| 1653 | struct il_station_priv *sta_priv = NULL; |
| 1654 | struct il_tx_queue *txq; |
| 1655 | struct il_queue *q; |
| 1656 | struct il_device_cmd *out_cmd; |
| 1657 | struct il_cmd_meta *out_meta; |
| 1658 | struct il_tx_cmd *tx_cmd; |
| 1659 | struct il_rxon_context *ctx = &il->ctx; |
| 1660 | int txq_id; |
| 1661 | dma_addr_t phys_addr; |
| 1662 | dma_addr_t txcmd_phys; |
| 1663 | dma_addr_t scratch_phys; |
| 1664 | u16 len, firstlen, secondlen; |
| 1665 | u16 seq_number = 0; |
| 1666 | __le16 fc; |
| 1667 | u8 hdr_len; |
| 1668 | u8 sta_id; |
| 1669 | u8 wait_write_ptr = 0; |
| 1670 | u8 tid = 0; |
| 1671 | u8 *qc = NULL; |
| 1672 | unsigned long flags; |
| 1673 | bool is_agg = false; |
| 1674 | |
| 1675 | if (info->control.vif) |
| 1676 | ctx = il_rxon_ctx_from_vif(info->control.vif); |
| 1677 | |
| 1678 | spin_lock_irqsave(&il->lock, flags); |
| 1679 | if (il_is_rfkill(il)) { |
| 1680 | D_DROP("Dropping - RF KILL\n"); |
| 1681 | goto drop_unlock; |
| 1682 | } |
| 1683 | |
| 1684 | fc = hdr->frame_control; |
| 1685 | |
| 1686 | #ifdef CONFIG_IWLEGACY_DEBUG |
| 1687 | if (ieee80211_is_auth(fc)) |
| 1688 | D_TX("Sending AUTH frame\n"); |
| 1689 | else if (ieee80211_is_assoc_req(fc)) |
| 1690 | D_TX("Sending ASSOC frame\n"); |
| 1691 | else if (ieee80211_is_reassoc_req(fc)) |
| 1692 | D_TX("Sending REASSOC frame\n"); |
| 1693 | #endif |
| 1694 | |
| 1695 | hdr_len = ieee80211_hdrlen(fc); |
| 1696 | |
| 1697 | /* For management frames use broadcast id to do not break aggregation */ |
| 1698 | if (!ieee80211_is_data(fc)) |
| 1699 | sta_id = ctx->bcast_sta_id; |
| 1700 | else { |
| 1701 | /* Find idx into station table for destination station */ |
| 1702 | sta_id = il_sta_id_or_broadcast(il, ctx, info->control.sta); |
| 1703 | |
| 1704 | if (sta_id == IL_INVALID_STATION) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1705 | D_DROP("Dropping - INVALID STATION: %pM\n", hdr->addr1); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1706 | goto drop_unlock; |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | D_TX("station Id %d\n", sta_id); |
| 1711 | |
| 1712 | if (sta) |
| 1713 | sta_priv = (void *)sta->drv_priv; |
| 1714 | |
| 1715 | if (sta_priv && sta_priv->asleep && |
| 1716 | (info->flags & IEEE80211_TX_CTL_POLL_RESPONSE)) { |
| 1717 | /* |
| 1718 | * This sends an asynchronous command to the device, |
| 1719 | * but we can rely on it being processed before the |
| 1720 | * next frame is processed -- and the next frame to |
| 1721 | * this station is the one that will consume this |
| 1722 | * counter. |
| 1723 | * For now set the counter to just 1 since we do not |
| 1724 | * support uAPSD yet. |
| 1725 | */ |
| 1726 | il4965_sta_modify_sleep_tx_count(il, sta_id, 1); |
| 1727 | } |
| 1728 | |
| 1729 | /* |
| 1730 | * Send this frame after DTIM -- there's a special queue |
| 1731 | * reserved for this for contexts that support AP mode. |
| 1732 | */ |
| 1733 | if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) { |
| 1734 | txq_id = ctx->mcast_queue; |
| 1735 | /* |
| 1736 | * The microcode will clear the more data |
| 1737 | * bit in the last frame it transmits. |
| 1738 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1739 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1740 | } else |
| 1741 | txq_id = ctx->ac_to_queue[skb_get_queue_mapping(skb)]; |
| 1742 | |
| 1743 | /* irqs already disabled/saved above when locking il->lock */ |
| 1744 | spin_lock(&il->sta_lock); |
| 1745 | |
| 1746 | if (ieee80211_is_data_qos(fc)) { |
| 1747 | qc = ieee80211_get_qos_ctl(hdr); |
| 1748 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 1749 | if (WARN_ON_ONCE(tid >= MAX_TID_COUNT)) { |
| 1750 | spin_unlock(&il->sta_lock); |
| 1751 | goto drop_unlock; |
| 1752 | } |
| 1753 | seq_number = il->stations[sta_id].tid[tid].seq_number; |
| 1754 | seq_number &= IEEE80211_SCTL_SEQ; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1755 | hdr->seq_ctrl = |
| 1756 | hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1757 | hdr->seq_ctrl |= cpu_to_le16(seq_number); |
| 1758 | seq_number += 0x10; |
| 1759 | /* aggregation is on for this <sta,tid> */ |
| 1760 | if (info->flags & IEEE80211_TX_CTL_AMPDU && |
| 1761 | il->stations[sta_id].tid[tid].agg.state == IL_AGG_ON) { |
| 1762 | txq_id = il->stations[sta_id].tid[tid].agg.txq_id; |
| 1763 | is_agg = true; |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | txq = &il->txq[txq_id]; |
| 1768 | q = &txq->q; |
| 1769 | |
| 1770 | if (unlikely(il_queue_space(q) < q->high_mark)) { |
| 1771 | spin_unlock(&il->sta_lock); |
| 1772 | goto drop_unlock; |
| 1773 | } |
| 1774 | |
| 1775 | if (ieee80211_is_data_qos(fc)) { |
| 1776 | il->stations[sta_id].tid[tid].tfds_in_queue++; |
| 1777 | if (!ieee80211_has_morefrags(fc)) |
| 1778 | il->stations[sta_id].tid[tid].seq_number = seq_number; |
| 1779 | } |
| 1780 | |
| 1781 | spin_unlock(&il->sta_lock); |
| 1782 | |
| 1783 | /* Set up driver data for this TFD */ |
| 1784 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct il_tx_info)); |
| 1785 | txq->txb[q->write_ptr].skb = skb; |
| 1786 | txq->txb[q->write_ptr].ctx = ctx; |
| 1787 | |
| 1788 | /* Set up first empty entry in queue's array of Tx/cmd buffers */ |
| 1789 | out_cmd = txq->cmd[q->write_ptr]; |
| 1790 | out_meta = &txq->meta[q->write_ptr]; |
| 1791 | tx_cmd = &out_cmd->cmd.tx; |
| 1792 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 1793 | memset(tx_cmd, 0, sizeof(struct il_tx_cmd)); |
| 1794 | |
| 1795 | /* |
| 1796 | * Set up the Tx-command (not MAC!) header. |
| 1797 | * Store the chosen Tx queue and TFD idx within the sequence field; |
| 1798 | * after Tx, uCode's Tx response will return this value so driver can |
| 1799 | * locate the frame within the tx queue and do post-tx processing. |
| 1800 | */ |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 1801 | out_cmd->hdr.cmd = C_TX; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1802 | out_cmd->hdr.sequence = |
| 1803 | cpu_to_le16((u16) |
| 1804 | (QUEUE_TO_SEQ(txq_id) | IDX_TO_SEQ(q->write_ptr))); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1805 | |
| 1806 | /* Copy MAC header from skb into command buffer */ |
| 1807 | memcpy(tx_cmd->hdr, hdr, hdr_len); |
| 1808 | |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1809 | /* Total # bytes to be transmitted */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1810 | len = (u16) skb->len; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1811 | tx_cmd->len = cpu_to_le16(len); |
| 1812 | |
| 1813 | if (info->control.hw_key) |
| 1814 | il4965_tx_cmd_build_hwcrypto(il, info, tx_cmd, skb, sta_id); |
| 1815 | |
| 1816 | /* TODO need this for burst mode later on */ |
| 1817 | il4965_tx_cmd_build_basic(il, skb, tx_cmd, info, hdr, sta_id); |
| 1818 | il_dbg_log_tx_data_frame(il, len, hdr); |
| 1819 | |
| 1820 | il4965_tx_cmd_build_rate(il, tx_cmd, info, fc); |
| 1821 | |
| 1822 | il_update_stats(il, true, fc, len); |
| 1823 | /* |
| 1824 | * Use the first empty entry in this queue's command buffer array |
| 1825 | * to contain the Tx command and MAC header concatenated together |
| 1826 | * (payload data will be in another buffer). |
| 1827 | * Size of this varies, due to varying MAC header length. |
| 1828 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 1829 | * of the MAC header (device reads on dword boundaries). |
| 1830 | * We'll tell device about this padding later. |
| 1831 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1832 | 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] | 1833 | firstlen = (len + 3) & ~3; |
| 1834 | |
| 1835 | /* Tell NIC about any 2-byte padding after MAC header */ |
| 1836 | if (firstlen != len) |
| 1837 | tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 1838 | |
| 1839 | /* Physical address of this Tx command's header (not MAC header!), |
| 1840 | * within command buffer array. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1841 | txcmd_phys = |
| 1842 | pci_map_single(il->pci_dev, &out_cmd->hdr, firstlen, |
| 1843 | PCI_DMA_BIDIRECTIONAL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1844 | dma_unmap_addr_set(out_meta, mapping, txcmd_phys); |
| 1845 | dma_unmap_len_set(out_meta, len, firstlen); |
| 1846 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 1847 | * first entry */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1848 | il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq, txcmd_phys, firstlen, |
| 1849 | 1, 0); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1850 | |
| 1851 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
| 1852 | txq->need_update = 1; |
| 1853 | } else { |
| 1854 | wait_write_ptr = 1; |
| 1855 | txq->need_update = 0; |
| 1856 | } |
| 1857 | |
| 1858 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 1859 | * if any (802.11 null frames have no payload). */ |
| 1860 | secondlen = skb->len - hdr_len; |
| 1861 | if (secondlen > 0) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1862 | phys_addr = |
| 1863 | pci_map_single(il->pci_dev, skb->data + hdr_len, secondlen, |
| 1864 | PCI_DMA_TODEVICE); |
| 1865 | il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq, phys_addr, |
| 1866 | secondlen, 0, 0); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1867 | } |
| 1868 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1869 | scratch_phys = |
| 1870 | txcmd_phys + sizeof(struct il_cmd_header) + |
| 1871 | offsetof(struct il_tx_cmd, scratch); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1872 | |
| 1873 | /* take back ownership of DMA buffer to enable update */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1874 | pci_dma_sync_single_for_cpu(il->pci_dev, txcmd_phys, firstlen, |
| 1875 | PCI_DMA_BIDIRECTIONAL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1876 | tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 1877 | tx_cmd->dram_msb_ptr = il_get_dma_hi_addr(scratch_phys); |
| 1878 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1879 | 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] | 1880 | 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] | 1881 | il_print_hex_dump(il, IL_DL_TX, (u8 *) tx_cmd, sizeof(*tx_cmd)); |
| 1882 | 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] | 1883 | |
| 1884 | /* Set up entry for this TFD in Tx byte-count array */ |
| 1885 | if (info->flags & IEEE80211_TX_CTL_AMPDU) |
| 1886 | il->cfg->ops->lib->txq_update_byte_cnt_tbl(il, txq, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1887 | le16_to_cpu(tx_cmd-> |
| 1888 | len)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1889 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1890 | pci_dma_sync_single_for_device(il->pci_dev, txcmd_phys, firstlen, |
| 1891 | PCI_DMA_BIDIRECTIONAL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1892 | |
| 1893 | /* Tell device the write idx *just past* this latest filled TFD */ |
| 1894 | q->write_ptr = il_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 1895 | il_txq_update_write_ptr(il, txq); |
| 1896 | spin_unlock_irqrestore(&il->lock, flags); |
| 1897 | |
| 1898 | /* |
| 1899 | * At this point the frame is "transmitted" successfully |
| 1900 | * and we will get a TX status notification eventually, |
| 1901 | * regardless of the value of ret. "ret" only indicates |
| 1902 | * whether or not we should update the write pointer. |
| 1903 | */ |
| 1904 | |
| 1905 | /* |
| 1906 | * Avoid atomic ops if it isn't an associated client. |
| 1907 | * Also, if this is a packet for aggregation, don't |
| 1908 | * increase the counter because the ucode will stop |
| 1909 | * aggregation queues when their respective station |
| 1910 | * goes to sleep. |
| 1911 | */ |
| 1912 | if (sta_priv && sta_priv->client && !is_agg) |
| 1913 | atomic_inc(&sta_priv->pending_frames); |
| 1914 | |
| 1915 | if (il_queue_space(q) < q->high_mark && il->mac80211_registered) { |
| 1916 | if (wait_write_ptr) { |
| 1917 | spin_lock_irqsave(&il->lock, flags); |
| 1918 | txq->need_update = 1; |
| 1919 | il_txq_update_write_ptr(il, txq); |
| 1920 | spin_unlock_irqrestore(&il->lock, flags); |
| 1921 | } else { |
| 1922 | il_stop_queue(il, txq); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | return 0; |
| 1927 | |
| 1928 | drop_unlock: |
| 1929 | spin_unlock_irqrestore(&il->lock, flags); |
| 1930 | return -1; |
| 1931 | } |
| 1932 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1933 | static inline int |
| 1934 | 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] | 1935 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1936 | ptr->addr = |
| 1937 | dma_alloc_coherent(&il->pci_dev->dev, size, &ptr->dma, GFP_KERNEL); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1938 | if (!ptr->addr) |
| 1939 | return -ENOMEM; |
| 1940 | ptr->size = size; |
| 1941 | return 0; |
| 1942 | } |
| 1943 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1944 | static inline void |
| 1945 | 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] | 1946 | { |
| 1947 | if (unlikely(!ptr->addr)) |
| 1948 | return; |
| 1949 | |
| 1950 | dma_free_coherent(&il->pci_dev->dev, ptr->size, ptr->addr, ptr->dma); |
| 1951 | memset(ptr, 0, sizeof(*ptr)); |
| 1952 | } |
| 1953 | |
| 1954 | /** |
| 1955 | * il4965_hw_txq_ctx_free - Free TXQ Context |
| 1956 | * |
| 1957 | * Destroy all TX DMA queues and structures |
| 1958 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1959 | void |
| 1960 | il4965_hw_txq_ctx_free(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1961 | { |
| 1962 | int txq_id; |
| 1963 | |
| 1964 | /* Tx queues */ |
| 1965 | if (il->txq) { |
| 1966 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) |
| 1967 | if (txq_id == il->cmd_queue) |
| 1968 | il_cmd_queue_free(il); |
| 1969 | else |
| 1970 | il_tx_queue_free(il, txq_id); |
| 1971 | } |
| 1972 | il4965_free_dma_ptr(il, &il->kw); |
| 1973 | |
| 1974 | il4965_free_dma_ptr(il, &il->scd_bc_tbls); |
| 1975 | |
| 1976 | /* free tx queue structure */ |
| 1977 | il_txq_mem(il); |
| 1978 | } |
| 1979 | |
| 1980 | /** |
| 1981 | * il4965_txq_ctx_alloc - allocate TX queue context |
| 1982 | * Allocate all Tx DMA structures and initialize them |
| 1983 | * |
| 1984 | * @param il |
| 1985 | * @return error code |
| 1986 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1987 | int |
| 1988 | il4965_txq_ctx_alloc(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 1989 | { |
| 1990 | int ret; |
| 1991 | int txq_id, slots_num; |
| 1992 | unsigned long flags; |
| 1993 | |
| 1994 | /* Free all tx/cmd queues and keep-warm buffer */ |
| 1995 | il4965_hw_txq_ctx_free(il); |
| 1996 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 1997 | ret = |
| 1998 | il4965_alloc_dma_ptr(il, &il->scd_bc_tbls, |
| 1999 | il->hw_params.scd_bc_tbls_size); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2000 | if (ret) { |
| 2001 | IL_ERR("Scheduler BC Table allocation failed\n"); |
| 2002 | goto error_bc_tbls; |
| 2003 | } |
| 2004 | /* Alloc keep-warm buffer */ |
| 2005 | ret = il4965_alloc_dma_ptr(il, &il->kw, IL_KW_SIZE); |
| 2006 | if (ret) { |
| 2007 | IL_ERR("Keep Warm allocation failed\n"); |
| 2008 | goto error_kw; |
| 2009 | } |
| 2010 | |
| 2011 | /* allocate tx queue structure */ |
| 2012 | ret = il_alloc_txq_mem(il); |
| 2013 | if (ret) |
| 2014 | goto error; |
| 2015 | |
| 2016 | spin_lock_irqsave(&il->lock, flags); |
| 2017 | |
| 2018 | /* Turn off all Tx DMA fifos */ |
| 2019 | il4965_txq_set_sched(il, 0); |
| 2020 | |
| 2021 | /* Tell NIC where to find the "keep warm" buffer */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 2022 | il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2023 | |
| 2024 | spin_unlock_irqrestore(&il->lock, flags); |
| 2025 | |
| 2026 | /* Alloc and init all Tx queues, including the command queue (#4/#9) */ |
| 2027 | 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] | 2028 | slots_num = |
| 2029 | (txq_id == |
| 2030 | il->cmd_queue) ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; |
| 2031 | 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] | 2032 | if (ret) { |
| 2033 | IL_ERR("Tx %d queue init failed\n", txq_id); |
| 2034 | goto error; |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | return ret; |
| 2039 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2040 | error: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2041 | il4965_hw_txq_ctx_free(il); |
| 2042 | il4965_free_dma_ptr(il, &il->kw); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2043 | error_kw: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2044 | il4965_free_dma_ptr(il, &il->scd_bc_tbls); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2045 | error_bc_tbls: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2046 | return ret; |
| 2047 | } |
| 2048 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2049 | void |
| 2050 | il4965_txq_ctx_reset(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2051 | { |
| 2052 | int txq_id, slots_num; |
| 2053 | unsigned long flags; |
| 2054 | |
| 2055 | spin_lock_irqsave(&il->lock, flags); |
| 2056 | |
| 2057 | /* Turn off all Tx DMA fifos */ |
| 2058 | il4965_txq_set_sched(il, 0); |
| 2059 | |
| 2060 | /* Tell NIC where to find the "keep warm" buffer */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 2061 | il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2062 | |
| 2063 | spin_unlock_irqrestore(&il->lock, flags); |
| 2064 | |
| 2065 | /* Alloc and init all Tx queues, including the command queue (#4) */ |
| 2066 | 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] | 2067 | slots_num = |
| 2068 | txq_id == il->cmd_queue ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; |
| 2069 | 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] | 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | /** |
| 2074 | * il4965_txq_ctx_stop - Stop all Tx DMA channels |
| 2075 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2076 | void |
| 2077 | il4965_txq_ctx_stop(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2078 | { |
| 2079 | int ch, txq_id; |
| 2080 | unsigned long flags; |
| 2081 | |
| 2082 | /* Turn off all Tx DMA fifos */ |
| 2083 | spin_lock_irqsave(&il->lock, flags); |
| 2084 | |
| 2085 | il4965_txq_set_sched(il, 0); |
| 2086 | |
| 2087 | /* Stop each Tx DMA channel, and wait for it to be idle */ |
| 2088 | for (ch = 0; ch < il->hw_params.dma_chnl_num; ch++) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2089 | il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0); |
| 2090 | if (il_poll_bit |
| 2091 | (il, FH49_TSSR_TX_STATUS_REG, |
| 2092 | FH49_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch), 1000)) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2093 | IL_ERR("Failing on timeout while stopping" |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 2094 | " DMA channel %d [0x%08x]", ch, |
| 2095 | il_rd(il, FH49_TSSR_TX_STATUS_REG)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2096 | } |
| 2097 | spin_unlock_irqrestore(&il->lock, flags); |
| 2098 | |
| 2099 | if (!il->txq) |
| 2100 | return; |
| 2101 | |
| 2102 | /* Unmap DMA from host system and free skb's */ |
| 2103 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) |
| 2104 | if (txq_id == il->cmd_queue) |
| 2105 | il_cmd_queue_unmap(il); |
| 2106 | else |
| 2107 | il_tx_queue_unmap(il, txq_id); |
| 2108 | } |
| 2109 | |
| 2110 | /* |
| 2111 | * Find first available (lowest unused) Tx Queue, mark it "active". |
| 2112 | * Called only when finding queue for aggregation. |
| 2113 | * Should never return anything < 7, because they should already |
| 2114 | * be in use as EDCA AC (0-3), Command (4), reserved (5, 6) |
| 2115 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2116 | static int |
| 2117 | il4965_txq_ctx_activate_free(struct il_priv *il) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2118 | { |
| 2119 | int txq_id; |
| 2120 | |
| 2121 | for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) |
| 2122 | if (!test_and_set_bit(txq_id, &il->txq_ctx_active_msk)) |
| 2123 | return txq_id; |
| 2124 | return -1; |
| 2125 | } |
| 2126 | |
| 2127 | /** |
| 2128 | * il4965_tx_queue_stop_scheduler - Stop queue, but keep configuration |
| 2129 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2130 | static void |
| 2131 | il4965_tx_queue_stop_scheduler(struct il_priv *il, u16 txq_id) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2132 | { |
| 2133 | /* Simply stop the queue, but don't change any configuration; |
| 2134 | * 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] | 2135 | il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 2136 | (0 << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) | |
| 2137 | (1 << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * il4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue |
| 2142 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2143 | static int |
| 2144 | 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] | 2145 | { |
| 2146 | u32 tbl_dw_addr; |
| 2147 | u32 tbl_dw; |
| 2148 | u16 scd_q2ratid; |
| 2149 | |
| 2150 | scd_q2ratid = ra_tid & IL_SCD_QUEUE_RA_TID_MAP_RATID_MSK; |
| 2151 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2152 | tbl_dw_addr = |
| 2153 | il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2154 | |
| 2155 | tbl_dw = il_read_targ_mem(il, tbl_dw_addr); |
| 2156 | |
| 2157 | if (txq_id & 0x1) |
| 2158 | tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF); |
| 2159 | else |
| 2160 | tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000); |
| 2161 | |
| 2162 | il_write_targ_mem(il, tbl_dw_addr, tbl_dw); |
| 2163 | |
| 2164 | return 0; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * il4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue |
| 2169 | * |
| 2170 | * NOTE: txq_id must be greater than IL49_FIRST_AMPDU_QUEUE, |
| 2171 | * i.e. it must be one of the higher queues used for aggregation |
| 2172 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2173 | static int |
| 2174 | il4965_txq_agg_enable(struct il_priv *il, int txq_id, int tx_fifo, int sta_id, |
| 2175 | int tid, u16 ssn_idx) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2176 | { |
| 2177 | unsigned long flags; |
| 2178 | u16 ra_tid; |
| 2179 | int ret; |
| 2180 | |
| 2181 | if ((IL49_FIRST_AMPDU_QUEUE > txq_id) || |
| 2182 | (IL49_FIRST_AMPDU_QUEUE + |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2183 | il->cfg->base_params->num_of_ampdu_queues <= txq_id)) { |
| 2184 | 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] | 2185 | txq_id, IL49_FIRST_AMPDU_QUEUE, |
| 2186 | IL49_FIRST_AMPDU_QUEUE + |
| 2187 | il->cfg->base_params->num_of_ampdu_queues - 1); |
| 2188 | return -EINVAL; |
| 2189 | } |
| 2190 | |
| 2191 | ra_tid = BUILD_RAxTID(sta_id, tid); |
| 2192 | |
| 2193 | /* Modify device's station table to Tx this TID */ |
| 2194 | ret = il4965_sta_tx_modify_enable_tid(il, sta_id, tid); |
| 2195 | if (ret) |
| 2196 | return ret; |
| 2197 | |
| 2198 | spin_lock_irqsave(&il->lock, flags); |
| 2199 | |
| 2200 | /* Stop this Tx queue before configuring it */ |
| 2201 | il4965_tx_queue_stop_scheduler(il, txq_id); |
| 2202 | |
| 2203 | /* Map receiver-address / traffic-ID to this queue */ |
| 2204 | il4965_tx_queue_set_q2ratid(il, ra_tid, txq_id); |
| 2205 | |
| 2206 | /* Set this queue as a chain-building queue */ |
| 2207 | il_set_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
| 2208 | |
| 2209 | /* Place first TFD at idx corresponding to start sequence number. |
| 2210 | * Assumes that ssn_idx is valid (!= 0xFFF) */ |
| 2211 | il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 2212 | il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
| 2213 | il4965_set_wr_ptrs(il, txq_id, ssn_idx); |
| 2214 | |
| 2215 | /* Set up Tx win size and frame limit for this queue */ |
| 2216 | il_write_targ_mem(il, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2217 | il->scd_base_addr + |
| 2218 | IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id), |
| 2219 | (SCD_WIN_SIZE << IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) |
| 2220 | & IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2221 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2222 | il_write_targ_mem(il, |
| 2223 | il->scd_base_addr + |
| 2224 | IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), |
| 2225 | (SCD_FRAME_LIMIT << |
| 2226 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & |
| 2227 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2228 | |
| 2229 | il_set_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
| 2230 | |
| 2231 | /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */ |
| 2232 | il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 1); |
| 2233 | |
| 2234 | spin_unlock_irqrestore(&il->lock, flags); |
| 2235 | |
| 2236 | return 0; |
| 2237 | } |
| 2238 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2239 | int |
| 2240 | il4965_tx_agg_start(struct il_priv *il, struct ieee80211_vif *vif, |
| 2241 | struct ieee80211_sta *sta, u16 tid, u16 * ssn) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2242 | { |
| 2243 | int sta_id; |
| 2244 | int tx_fifo; |
| 2245 | int txq_id; |
| 2246 | int ret; |
| 2247 | unsigned long flags; |
| 2248 | struct il_tid_data *tid_data; |
| 2249 | |
| 2250 | tx_fifo = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid); |
| 2251 | if (unlikely(tx_fifo < 0)) |
| 2252 | return tx_fifo; |
| 2253 | |
Greg Dietsche | 53611e0 | 2011-08-28 08:26:16 -0500 | [diff] [blame] | 2254 | 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] | 2255 | |
| 2256 | sta_id = il_sta_id(sta); |
| 2257 | if (sta_id == IL_INVALID_STATION) { |
| 2258 | IL_ERR("Start AGG on invalid station\n"); |
| 2259 | return -ENXIO; |
| 2260 | } |
| 2261 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 2262 | return -EINVAL; |
| 2263 | |
| 2264 | if (il->stations[sta_id].tid[tid].agg.state != IL_AGG_OFF) { |
| 2265 | IL_ERR("Start AGG when state is not IL_AGG_OFF !\n"); |
| 2266 | return -ENXIO; |
| 2267 | } |
| 2268 | |
| 2269 | txq_id = il4965_txq_ctx_activate_free(il); |
| 2270 | if (txq_id == -1) { |
| 2271 | IL_ERR("No free aggregation queue available\n"); |
| 2272 | return -ENXIO; |
| 2273 | } |
| 2274 | |
| 2275 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2276 | tid_data = &il->stations[sta_id].tid[tid]; |
| 2277 | *ssn = SEQ_TO_SN(tid_data->seq_number); |
| 2278 | tid_data->agg.txq_id = txq_id; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2279 | 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] | 2280 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2281 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2282 | 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] | 2283 | if (ret) |
| 2284 | return ret; |
| 2285 | |
| 2286 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2287 | tid_data = &il->stations[sta_id].tid[tid]; |
| 2288 | if (tid_data->tfds_in_queue == 0) { |
| 2289 | D_HT("HW queue is empty\n"); |
| 2290 | tid_data->agg.state = IL_AGG_ON; |
| 2291 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2292 | } else { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2293 | D_HT("HW queue is NOT empty: %d packets in HW queue\n", |
| 2294 | tid_data->tfds_in_queue); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2295 | tid_data->agg.state = IL_EMPTYING_HW_QUEUE_ADDBA; |
| 2296 | } |
| 2297 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2298 | return ret; |
| 2299 | } |
| 2300 | |
| 2301 | /** |
| 2302 | * txq_id must be greater than IL49_FIRST_AMPDU_QUEUE |
| 2303 | * il->lock must be held by the caller |
| 2304 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2305 | static int |
| 2306 | 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] | 2307 | { |
| 2308 | if ((IL49_FIRST_AMPDU_QUEUE > txq_id) || |
| 2309 | (IL49_FIRST_AMPDU_QUEUE + |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2310 | il->cfg->base_params->num_of_ampdu_queues <= txq_id)) { |
| 2311 | 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] | 2312 | txq_id, IL49_FIRST_AMPDU_QUEUE, |
| 2313 | IL49_FIRST_AMPDU_QUEUE + |
| 2314 | il->cfg->base_params->num_of_ampdu_queues - 1); |
| 2315 | return -EINVAL; |
| 2316 | } |
| 2317 | |
| 2318 | il4965_tx_queue_stop_scheduler(il, txq_id); |
| 2319 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2320 | il_clear_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2321 | |
| 2322 | il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 2323 | il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
| 2324 | /* supposes that ssn_idx is valid (!= 0xFFF) */ |
| 2325 | il4965_set_wr_ptrs(il, txq_id, ssn_idx); |
| 2326 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2327 | il_clear_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2328 | il_txq_ctx_deactivate(il, txq_id); |
| 2329 | il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 0); |
| 2330 | |
| 2331 | return 0; |
| 2332 | } |
| 2333 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2334 | int |
| 2335 | il4965_tx_agg_stop(struct il_priv *il, struct ieee80211_vif *vif, |
| 2336 | struct ieee80211_sta *sta, u16 tid) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2337 | { |
| 2338 | int tx_fifo_id, txq_id, sta_id, ssn; |
| 2339 | struct il_tid_data *tid_data; |
| 2340 | int write_ptr, read_ptr; |
| 2341 | unsigned long flags; |
| 2342 | |
| 2343 | tx_fifo_id = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid); |
| 2344 | if (unlikely(tx_fifo_id < 0)) |
| 2345 | return tx_fifo_id; |
| 2346 | |
| 2347 | sta_id = il_sta_id(sta); |
| 2348 | |
| 2349 | if (sta_id == IL_INVALID_STATION) { |
| 2350 | IL_ERR("Invalid station for AGG tid %d\n", tid); |
| 2351 | return -ENXIO; |
| 2352 | } |
| 2353 | |
| 2354 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2355 | |
| 2356 | tid_data = &il->stations[sta_id].tid[tid]; |
| 2357 | ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4; |
| 2358 | txq_id = tid_data->agg.txq_id; |
| 2359 | |
| 2360 | switch (il->stations[sta_id].tid[tid].agg.state) { |
| 2361 | case IL_EMPTYING_HW_QUEUE_ADDBA: |
| 2362 | /* |
| 2363 | * This can happen if the peer stops aggregation |
| 2364 | * again before we've had a chance to drain the |
| 2365 | * queue we selected previously, i.e. before the |
| 2366 | * session was really started completely. |
| 2367 | */ |
| 2368 | D_HT("AGG stop before setup done\n"); |
| 2369 | goto turn_off; |
| 2370 | case IL_AGG_ON: |
| 2371 | break; |
| 2372 | default: |
| 2373 | IL_WARN("Stopping AGG while state not ON or starting\n"); |
| 2374 | } |
| 2375 | |
| 2376 | write_ptr = il->txq[txq_id].q.write_ptr; |
| 2377 | read_ptr = il->txq[txq_id].q.read_ptr; |
| 2378 | |
| 2379 | /* The queue is not empty */ |
| 2380 | if (write_ptr != read_ptr) { |
| 2381 | D_HT("Stopping a non empty AGG HW QUEUE\n"); |
| 2382 | il->stations[sta_id].tid[tid].agg.state = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2383 | IL_EMPTYING_HW_QUEUE_DELBA; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2384 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2385 | return 0; |
| 2386 | } |
| 2387 | |
| 2388 | D_HT("HW queue is empty\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2389 | turn_off: |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2390 | il->stations[sta_id].tid[tid].agg.state = IL_AGG_OFF; |
| 2391 | |
| 2392 | /* do not restore/save irqs */ |
| 2393 | spin_unlock(&il->sta_lock); |
| 2394 | spin_lock(&il->lock); |
| 2395 | |
| 2396 | /* |
| 2397 | * the only reason this call can fail is queue number out of range, |
| 2398 | * which can happen if uCode is reloaded and all the station |
| 2399 | * information are lost. if it is outside the range, there is no need |
| 2400 | * to deactivate the uCode queue, just return "success" to allow |
| 2401 | * mac80211 to clean up it own data. |
| 2402 | */ |
| 2403 | il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo_id); |
| 2404 | spin_unlock_irqrestore(&il->lock, flags); |
| 2405 | |
| 2406 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2407 | |
| 2408 | return 0; |
| 2409 | } |
| 2410 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2411 | int |
| 2412 | 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] | 2413 | { |
| 2414 | struct il_queue *q = &il->txq[txq_id].q; |
| 2415 | u8 *addr = il->stations[sta_id].sta.sta.addr; |
| 2416 | struct il_tid_data *tid_data = &il->stations[sta_id].tid[tid]; |
| 2417 | struct il_rxon_context *ctx; |
| 2418 | |
| 2419 | ctx = &il->ctx; |
| 2420 | |
| 2421 | lockdep_assert_held(&il->sta_lock); |
| 2422 | |
| 2423 | switch (il->stations[sta_id].tid[tid].agg.state) { |
| 2424 | case IL_EMPTYING_HW_QUEUE_DELBA: |
| 2425 | /* We are reclaiming the last packet of the */ |
| 2426 | /* aggregated HW queue */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2427 | if (txq_id == tid_data->agg.txq_id && |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2428 | q->read_ptr == q->write_ptr) { |
| 2429 | u16 ssn = SEQ_TO_SN(tid_data->seq_number); |
| 2430 | int tx_fifo = il4965_get_fifo_from_tid(ctx, tid); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2431 | D_HT("HW queue empty: continue DELBA flow\n"); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2432 | il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo); |
| 2433 | tid_data->agg.state = IL_AGG_OFF; |
| 2434 | ieee80211_stop_tx_ba_cb_irqsafe(ctx->vif, addr, tid); |
| 2435 | } |
| 2436 | break; |
| 2437 | case IL_EMPTYING_HW_QUEUE_ADDBA: |
| 2438 | /* We are reclaiming the last packet of the queue */ |
| 2439 | if (tid_data->tfds_in_queue == 0) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2440 | D_HT("HW queue empty: continue ADDBA flow\n"); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2441 | tid_data->agg.state = IL_AGG_ON; |
| 2442 | ieee80211_start_tx_ba_cb_irqsafe(ctx->vif, addr, tid); |
| 2443 | } |
| 2444 | break; |
| 2445 | } |
| 2446 | |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2450 | static void |
| 2451 | 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] | 2452 | const u8 *addr1) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2453 | { |
| 2454 | struct ieee80211_sta *sta; |
| 2455 | struct il_station_priv *sta_priv; |
| 2456 | |
| 2457 | rcu_read_lock(); |
| 2458 | sta = ieee80211_find_sta(ctx->vif, addr1); |
| 2459 | if (sta) { |
| 2460 | sta_priv = (void *)sta->drv_priv; |
| 2461 | /* avoid atomic ops if this isn't a client */ |
| 2462 | if (sta_priv->client && |
| 2463 | atomic_dec_return(&sta_priv->pending_frames) == 0) |
| 2464 | ieee80211_sta_block_awake(il->hw, sta, false); |
| 2465 | } |
| 2466 | rcu_read_unlock(); |
| 2467 | } |
| 2468 | |
| 2469 | static void |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2470 | 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] | 2471 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2472 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx_info->skb->data; |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2473 | |
| 2474 | if (!is_agg) |
| 2475 | il4965_non_agg_tx_status(il, tx_info->ctx, hdr->addr1); |
| 2476 | |
| 2477 | ieee80211_tx_status_irqsafe(il->hw, tx_info->skb); |
| 2478 | } |
| 2479 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2480 | int |
| 2481 | 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] | 2482 | { |
| 2483 | struct il_tx_queue *txq = &il->txq[txq_id]; |
| 2484 | struct il_queue *q = &txq->q; |
| 2485 | struct il_tx_info *tx_info; |
| 2486 | int nfreed = 0; |
| 2487 | struct ieee80211_hdr *hdr; |
| 2488 | |
| 2489 | if (idx >= q->n_bd || il_queue_used(q, idx) == 0) { |
| 2490 | IL_ERR("Read idx for DMA queue txq id (%d), idx %d, " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2491 | "is out of range [0-%d] %d %d.\n", txq_id, idx, q->n_bd, |
| 2492 | q->write_ptr, q->read_ptr); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2493 | return 0; |
| 2494 | } |
| 2495 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2496 | 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] | 2497 | q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 2498 | |
| 2499 | tx_info = &txq->txb[txq->q.read_ptr]; |
| 2500 | |
| 2501 | if (WARN_ON_ONCE(tx_info->skb == NULL)) |
| 2502 | continue; |
| 2503 | |
| 2504 | hdr = (struct ieee80211_hdr *)tx_info->skb->data; |
| 2505 | if (ieee80211_is_data_qos(hdr->frame_control)) |
| 2506 | nfreed++; |
| 2507 | |
| 2508 | il4965_tx_status(il, tx_info, |
| 2509 | txq_id >= IL4965_FIRST_AMPDU_QUEUE); |
| 2510 | tx_info->skb = NULL; |
| 2511 | |
| 2512 | il->cfg->ops->lib->txq_free_tfd(il, txq); |
| 2513 | } |
| 2514 | return nfreed; |
| 2515 | } |
| 2516 | |
| 2517 | /** |
| 2518 | * il4965_tx_status_reply_compressed_ba - Update tx status from block-ack |
| 2519 | * |
| 2520 | * Go through block-ack's bitmap of ACK'd frames, update driver's record of |
| 2521 | * ACK vs. not. This gets sent to mac80211, then to rate scaling algo. |
| 2522 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2523 | static int |
| 2524 | il4965_tx_status_reply_compressed_ba(struct il_priv *il, struct il_ht_agg *agg, |
| 2525 | struct il_compressed_ba_resp *ba_resp) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2526 | { |
| 2527 | int i, sh, ack; |
| 2528 | u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl); |
| 2529 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
| 2530 | int successes = 0; |
| 2531 | struct ieee80211_tx_info *info; |
| 2532 | u64 bitmap, sent_bitmap; |
| 2533 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2534 | if (unlikely(!agg->wait_for_ba)) { |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2535 | if (unlikely(ba_resp->bitmap)) |
| 2536 | IL_ERR("Received BA when not expected\n"); |
| 2537 | return -EINVAL; |
| 2538 | } |
| 2539 | |
| 2540 | /* Mark that the expected block-ack response arrived */ |
| 2541 | agg->wait_for_ba = 0; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2542 | 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] | 2543 | |
| 2544 | /* Calculate shift to align block-ack bits with our Tx win bits */ |
| 2545 | sh = agg->start_idx - SEQ_TO_IDX(seq_ctl >> 4); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2546 | if (sh < 0) /* tbw something is wrong with indices */ |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2547 | sh += 0x100; |
| 2548 | |
| 2549 | if (agg->frame_count > (64 - sh)) { |
| 2550 | D_TX_REPLY("more frames than bitmap size"); |
| 2551 | return -1; |
| 2552 | } |
| 2553 | |
| 2554 | /* don't use 64-bit values for now */ |
| 2555 | bitmap = le64_to_cpu(ba_resp->bitmap) >> sh; |
| 2556 | |
| 2557 | /* check for success or failure according to the |
| 2558 | * transmitted bitmap and block-ack bitmap */ |
| 2559 | sent_bitmap = bitmap & agg->bitmap; |
| 2560 | |
| 2561 | /* For each frame attempted in aggregation, |
| 2562 | * update driver's record of tx frame's status. */ |
| 2563 | i = 0; |
| 2564 | while (sent_bitmap) { |
| 2565 | ack = sent_bitmap & 1ULL; |
| 2566 | successes += ack; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2567 | D_TX_REPLY("%s ON i=%d idx=%d raw=%d\n", ack ? "ACK" : "NACK", |
| 2568 | i, (agg->start_idx + i) & 0xff, agg->start_idx + i); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2569 | sent_bitmap >>= 1; |
| 2570 | ++i; |
| 2571 | } |
| 2572 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2573 | D_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2574 | |
| 2575 | info = IEEE80211_SKB_CB(il->txq[scd_flow].txb[agg->start_idx].skb); |
| 2576 | memset(&info->status, 0, sizeof(info->status)); |
| 2577 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 2578 | info->flags |= IEEE80211_TX_STAT_AMPDU; |
| 2579 | info->status.ampdu_ack_len = successes; |
| 2580 | info->status.ampdu_len = agg->frame_count; |
| 2581 | il4965_hwrate_to_tx_control(il, agg->rate_n_flags, info); |
| 2582 | |
| 2583 | return 0; |
| 2584 | } |
| 2585 | |
| 2586 | /** |
| 2587 | * translate ucode response to mac80211 tx status control values |
| 2588 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2589 | void |
| 2590 | il4965_hwrate_to_tx_control(struct il_priv *il, u32 rate_n_flags, |
| 2591 | struct ieee80211_tx_info *info) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2592 | { |
| 2593 | struct ieee80211_tx_rate *r = &info->control.rates[0]; |
| 2594 | |
| 2595 | info->antenna_sel_tx = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2596 | ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2597 | if (rate_n_flags & RATE_MCS_HT_MSK) |
| 2598 | r->flags |= IEEE80211_TX_RC_MCS; |
| 2599 | if (rate_n_flags & RATE_MCS_GF_MSK) |
| 2600 | r->flags |= IEEE80211_TX_RC_GREEN_FIELD; |
| 2601 | if (rate_n_flags & RATE_MCS_HT40_MSK) |
| 2602 | r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
| 2603 | if (rate_n_flags & RATE_MCS_DUP_MSK) |
| 2604 | r->flags |= IEEE80211_TX_RC_DUP_DATA; |
| 2605 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
| 2606 | r->flags |= IEEE80211_TX_RC_SHORT_GI; |
| 2607 | r->idx = il4965_hwrate_to_mac80211_idx(rate_n_flags, info->band); |
| 2608 | } |
| 2609 | |
| 2610 | /** |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 2611 | * il4965_hdl_compressed_ba - Handler for N_COMPRESSED_BA |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2612 | * |
| 2613 | * Handles block-acknowledge notification from device, which reports success |
| 2614 | * of frames sent via aggregation. |
| 2615 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2616 | void |
| 2617 | 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] | 2618 | { |
| 2619 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
| 2620 | struct il_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba; |
| 2621 | struct il_tx_queue *txq = NULL; |
| 2622 | struct il_ht_agg *agg; |
| 2623 | int idx; |
| 2624 | int sta_id; |
| 2625 | int tid; |
| 2626 | unsigned long flags; |
| 2627 | |
| 2628 | /* "flow" corresponds to Tx queue */ |
| 2629 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
| 2630 | |
| 2631 | /* "ssn" is start of block-ack Tx win, corresponds to idx |
| 2632 | * (in Tx queue's circular buffer) of first TFD/frame in win */ |
| 2633 | u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn); |
| 2634 | |
| 2635 | if (scd_flow >= il->hw_params.max_txq_num) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2636 | 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] | 2637 | return; |
| 2638 | } |
| 2639 | |
| 2640 | txq = &il->txq[scd_flow]; |
| 2641 | sta_id = ba_resp->sta_id; |
| 2642 | tid = ba_resp->tid; |
| 2643 | agg = &il->stations[sta_id].tid[tid].agg; |
| 2644 | if (unlikely(agg->txq_id != scd_flow)) { |
| 2645 | /* |
| 2646 | * FIXME: this is a uCode bug which need to be addressed, |
| 2647 | * log the information and return for now! |
| 2648 | * since it is possible happen very often and in order |
| 2649 | * not to fill the syslog, don't enable the logging by default |
| 2650 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2651 | D_TX_REPLY("BA scd_flow %d does not match txq_id %d\n", |
| 2652 | scd_flow, agg->txq_id); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2653 | return; |
| 2654 | } |
| 2655 | |
| 2656 | /* Find idx just before block-ack win */ |
| 2657 | idx = il_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd); |
| 2658 | |
| 2659 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2660 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2661 | 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] | 2662 | agg->wait_for_ba, (u8 *) &ba_resp->sta_addr_lo32, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2663 | ba_resp->sta_id); |
| 2664 | D_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx," "scd_flow = " |
| 2665 | "%d, scd_ssn = %d\n", ba_resp->tid, ba_resp->seq_ctl, |
| 2666 | (unsigned long long)le64_to_cpu(ba_resp->bitmap), |
| 2667 | ba_resp->scd_flow, ba_resp->scd_ssn); |
| 2668 | D_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx\n", agg->start_idx, |
| 2669 | (unsigned long long)agg->bitmap); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2670 | |
| 2671 | /* Update driver's record of ACK vs. not for each frame in win */ |
| 2672 | il4965_tx_status_reply_compressed_ba(il, agg, ba_resp); |
| 2673 | |
| 2674 | /* Release all TFDs before the SSN, i.e. all TFDs in front of |
| 2675 | * block-ack win (we assume that they've been successfully |
| 2676 | * transmitted ... if not, it's too late anyway). */ |
| 2677 | if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) { |
| 2678 | /* calculate mac80211 ampdu sw queue to wake */ |
| 2679 | int freed = il4965_tx_queue_reclaim(il, scd_flow, idx); |
| 2680 | il4965_free_tfds_in_queue(il, sta_id, tid, freed); |
| 2681 | |
| 2682 | if (il_queue_space(&txq->q) > txq->q.low_mark && |
| 2683 | il->mac80211_registered && |
| 2684 | agg->state != IL_EMPTYING_HW_QUEUE_DELBA) |
| 2685 | il_wake_queue(il, txq); |
| 2686 | |
| 2687 | il4965_txq_check_empty(il, sta_id, tid, scd_flow); |
| 2688 | } |
| 2689 | |
| 2690 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2691 | } |
| 2692 | |
| 2693 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2694 | const char * |
| 2695 | il4965_get_tx_fail_reason(u32 status) |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2696 | { |
| 2697 | #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2698 | #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x |
| 2699 | |
| 2700 | switch (status & TX_STATUS_MSK) { |
| 2701 | case TX_STATUS_SUCCESS: |
| 2702 | return "SUCCESS"; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2703 | TX_STATUS_POSTPONE(DELAY); |
| 2704 | TX_STATUS_POSTPONE(FEW_BYTES); |
| 2705 | TX_STATUS_POSTPONE(QUIET_PERIOD); |
| 2706 | TX_STATUS_POSTPONE(CALC_TTAK); |
| 2707 | TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY); |
| 2708 | TX_STATUS_FAIL(SHORT_LIMIT); |
| 2709 | TX_STATUS_FAIL(LONG_LIMIT); |
| 2710 | TX_STATUS_FAIL(FIFO_UNDERRUN); |
| 2711 | TX_STATUS_FAIL(DRAIN_FLOW); |
| 2712 | TX_STATUS_FAIL(RFKILL_FLUSH); |
| 2713 | TX_STATUS_FAIL(LIFE_EXPIRE); |
| 2714 | TX_STATUS_FAIL(DEST_PS); |
| 2715 | TX_STATUS_FAIL(HOST_ABORTED); |
| 2716 | TX_STATUS_FAIL(BT_RETRY); |
| 2717 | TX_STATUS_FAIL(STA_INVALID); |
| 2718 | TX_STATUS_FAIL(FRAG_DROPPED); |
| 2719 | TX_STATUS_FAIL(TID_DISABLE); |
| 2720 | TX_STATUS_FAIL(FIFO_FLUSHED); |
| 2721 | TX_STATUS_FAIL(INSUFFICIENT_CF_POLL); |
| 2722 | TX_STATUS_FAIL(PASSIVE_NO_RX); |
| 2723 | TX_STATUS_FAIL(NO_BEACON_ON_RADAR); |
Stanislaw Gruszka | a1751b2 | 2011-11-15 12:50:37 +0100 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | return "UNKNOWN"; |
| 2727 | |
| 2728 | #undef TX_STATUS_FAIL |
| 2729 | #undef TX_STATUS_POSTPONE |
| 2730 | } |
| 2731 | #endif /* CONFIG_IWLEGACY_DEBUG */ |
| 2732 | |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2733 | static struct il_link_quality_cmd * |
| 2734 | il4965_sta_alloc_lq(struct il_priv *il, u8 sta_id) |
| 2735 | { |
| 2736 | int i, r; |
| 2737 | struct il_link_quality_cmd *link_cmd; |
| 2738 | u32 rate_flags = 0; |
| 2739 | __le32 rate_n_flags; |
| 2740 | |
| 2741 | link_cmd = kzalloc(sizeof(struct il_link_quality_cmd), GFP_KERNEL); |
| 2742 | if (!link_cmd) { |
| 2743 | IL_ERR("Unable to allocate memory for LQ cmd.\n"); |
| 2744 | return NULL; |
| 2745 | } |
| 2746 | /* Set up the rate scaling to start at selected rate, fall back |
| 2747 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
| 2748 | if (il->band == IEEE80211_BAND_5GHZ) |
| 2749 | r = RATE_6M_IDX; |
| 2750 | else |
| 2751 | r = RATE_1M_IDX; |
| 2752 | |
| 2753 | if (r >= IL_FIRST_CCK_RATE && r <= IL_LAST_CCK_RATE) |
| 2754 | rate_flags |= RATE_MCS_CCK_MSK; |
| 2755 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2756 | rate_flags |= |
| 2757 | il4965_first_antenna(il->hw_params. |
| 2758 | valid_tx_ant) << RATE_MCS_ANT_POS; |
| 2759 | rate_n_flags = il4965_hw_set_rate_n_flags(il_rates[r].plcp, rate_flags); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2760 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
| 2761 | link_cmd->rs_table[i].rate_n_flags = rate_n_flags; |
| 2762 | |
| 2763 | link_cmd->general_params.single_stream_ant_msk = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2764 | il4965_first_antenna(il->hw_params.valid_tx_ant); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2765 | |
| 2766 | link_cmd->general_params.dual_stream_ant_msk = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2767 | il->hw_params.valid_tx_ant & ~il4965_first_antenna(il->hw_params. |
| 2768 | valid_tx_ant); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2769 | if (!link_cmd->general_params.dual_stream_ant_msk) { |
| 2770 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; |
| 2771 | } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) { |
| 2772 | link_cmd->general_params.dual_stream_ant_msk = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2773 | il->hw_params.valid_tx_ant; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
| 2777 | link_cmd->agg_params.agg_time_limit = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2778 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2779 | |
| 2780 | link_cmd->sta_id = sta_id; |
| 2781 | |
| 2782 | return link_cmd; |
| 2783 | } |
| 2784 | |
| 2785 | /* |
| 2786 | * il4965_add_bssid_station - Add the special IBSS BSSID station |
| 2787 | * |
| 2788 | * Function sleeps. |
| 2789 | */ |
| 2790 | int |
| 2791 | 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] | 2792 | const u8 *addr, u8 *sta_id_r) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2793 | { |
| 2794 | int ret; |
| 2795 | u8 sta_id; |
| 2796 | struct il_link_quality_cmd *link_cmd; |
| 2797 | unsigned long flags; |
| 2798 | |
| 2799 | if (sta_id_r) |
| 2800 | *sta_id_r = IL_INVALID_STATION; |
| 2801 | |
| 2802 | ret = il_add_station_common(il, ctx, addr, 0, NULL, &sta_id); |
| 2803 | if (ret) { |
| 2804 | IL_ERR("Unable to add station %pM\n", addr); |
| 2805 | return ret; |
| 2806 | } |
| 2807 | |
| 2808 | if (sta_id_r) |
| 2809 | *sta_id_r = sta_id; |
| 2810 | |
| 2811 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2812 | il->stations[sta_id].used |= IL_STA_LOCAL; |
| 2813 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2814 | |
| 2815 | /* Set up default rate scaling table in device's station table */ |
| 2816 | link_cmd = il4965_sta_alloc_lq(il, sta_id); |
| 2817 | if (!link_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2818 | IL_ERR("Unable to initialize rate scaling for station %pM.\n", |
| 2819 | addr); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2820 | return -ENOMEM; |
| 2821 | } |
| 2822 | |
| 2823 | ret = il_send_lq_cmd(il, ctx, link_cmd, CMD_SYNC, true); |
| 2824 | if (ret) |
| 2825 | IL_ERR("Link quality command failed (%d)\n", ret); |
| 2826 | |
| 2827 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2828 | il->stations[sta_id].lq = link_cmd; |
| 2829 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2830 | |
| 2831 | return 0; |
| 2832 | } |
| 2833 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2834 | static int |
| 2835 | il4965_static_wepkey_cmd(struct il_priv *il, struct il_rxon_context *ctx, |
| 2836 | bool send_if_empty) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2837 | { |
| 2838 | int i, not_empty = 0; |
| 2839 | u8 buff[sizeof(struct il_wep_cmd) + |
| 2840 | sizeof(struct il_wep_key) * WEP_KEYS_MAX]; |
| 2841 | struct il_wep_cmd *wep_cmd = (struct il_wep_cmd *)buff; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2842 | size_t cmd_size = sizeof(struct il_wep_cmd); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2843 | struct il_host_cmd cmd = { |
| 2844 | .id = ctx->wep_key_cmd, |
| 2845 | .data = wep_cmd, |
| 2846 | .flags = CMD_SYNC, |
| 2847 | }; |
| 2848 | |
| 2849 | might_sleep(); |
| 2850 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2851 | memset(wep_cmd, 0, |
| 2852 | cmd_size + (sizeof(struct il_wep_key) * WEP_KEYS_MAX)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2853 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2854 | for (i = 0; i < WEP_KEYS_MAX; i++) { |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2855 | wep_cmd->key[i].key_idx = i; |
| 2856 | if (ctx->wep_keys[i].key_size) { |
| 2857 | wep_cmd->key[i].key_offset = i; |
| 2858 | not_empty = 1; |
| 2859 | } else { |
| 2860 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 2861 | } |
| 2862 | |
| 2863 | wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size; |
| 2864 | memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2865 | ctx->wep_keys[i].key_size); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 2869 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 2870 | |
| 2871 | cmd_size += sizeof(struct il_wep_key) * WEP_KEYS_MAX; |
| 2872 | |
| 2873 | cmd.len = cmd_size; |
| 2874 | |
| 2875 | if (not_empty || send_if_empty) |
| 2876 | return il_send_cmd(il, &cmd); |
| 2877 | else |
| 2878 | return 0; |
| 2879 | } |
| 2880 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2881 | int |
| 2882 | 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] | 2883 | { |
| 2884 | lockdep_assert_held(&il->mutex); |
| 2885 | |
| 2886 | return il4965_static_wepkey_cmd(il, ctx, false); |
| 2887 | } |
| 2888 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2889 | int |
| 2890 | il4965_remove_default_wep_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 2891 | struct ieee80211_key_conf *keyconf) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2892 | { |
| 2893 | int ret; |
| 2894 | |
| 2895 | lockdep_assert_held(&il->mutex); |
| 2896 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2897 | D_WEP("Removing default WEP key: idx=%d\n", keyconf->keyidx); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2898 | |
| 2899 | memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0])); |
| 2900 | if (il_is_rfkill(il)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2901 | D_WEP("Not sending C_WEPKEY command due to RFKILL.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2902 | /* but keys in device are clear anyway so return success */ |
| 2903 | return 0; |
| 2904 | } |
| 2905 | ret = il4965_static_wepkey_cmd(il, ctx, 1); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2906 | D_WEP("Remove default WEP key: idx=%d ret=%d\n", keyconf->keyidx, ret); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2907 | |
| 2908 | return ret; |
| 2909 | } |
| 2910 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2911 | int |
| 2912 | il4965_set_default_wep_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 2913 | struct ieee80211_key_conf *keyconf) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2914 | { |
| 2915 | int ret; |
| 2916 | |
| 2917 | lockdep_assert_held(&il->mutex); |
| 2918 | |
| 2919 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
| 2920 | keyconf->keylen != WEP_KEY_LEN_64) { |
| 2921 | D_WEP("Bad WEP key length %d\n", keyconf->keylen); |
| 2922 | return -EINVAL; |
| 2923 | } |
| 2924 | |
| 2925 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
| 2926 | keyconf->hw_key_idx = HW_KEY_DEFAULT; |
| 2927 | il->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher; |
| 2928 | |
| 2929 | ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
| 2930 | memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2931 | keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2932 | |
| 2933 | ret = il4965_static_wepkey_cmd(il, ctx, false); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2934 | D_WEP("Set default WEP key: len=%d idx=%d ret=%d\n", keyconf->keylen, |
| 2935 | keyconf->keyidx, ret); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2936 | |
| 2937 | return ret; |
| 2938 | } |
| 2939 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2940 | static int |
| 2941 | il4965_set_wep_dynamic_key_info(struct il_priv *il, struct il_rxon_context *ctx, |
| 2942 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2943 | { |
| 2944 | unsigned long flags; |
| 2945 | __le16 key_flags = 0; |
| 2946 | struct il_addsta_cmd sta_cmd; |
| 2947 | |
| 2948 | lockdep_assert_held(&il->mutex); |
| 2949 | |
| 2950 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
| 2951 | |
| 2952 | key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); |
| 2953 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 2954 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 2955 | |
| 2956 | if (keyconf->keylen == WEP_KEY_LEN_128) |
| 2957 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
| 2958 | |
| 2959 | if (sta_id == ctx->bcast_sta_id) |
| 2960 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 2961 | |
| 2962 | spin_lock_irqsave(&il->sta_lock, flags); |
| 2963 | |
| 2964 | il->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
| 2965 | il->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 2966 | il->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; |
| 2967 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2968 | memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2969 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2970 | memcpy(&il->stations[sta_id].sta.key.key[3], keyconf->key, |
| 2971 | keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2972 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2973 | if ((il->stations[sta_id].sta.key. |
| 2974 | key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2975 | il->stations[sta_id].sta.key.key_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2976 | il_get_free_ucode_key_idx(il); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2977 | /* else, we are overriding an existing key => no need to allocated room |
| 2978 | * in uCode. */ |
| 2979 | |
| 2980 | WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2981 | "no space for a new key"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2982 | |
| 2983 | il->stations[sta_id].sta.key.key_flags = key_flags; |
| 2984 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 2985 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 2986 | |
| 2987 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2988 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2989 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 2990 | |
| 2991 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 2992 | } |
| 2993 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 2994 | static int |
| 2995 | il4965_set_ccmp_dynamic_key_info(struct il_priv *il, |
| 2996 | struct il_rxon_context *ctx, |
| 2997 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 2998 | { |
| 2999 | unsigned long flags; |
| 3000 | __le16 key_flags = 0; |
| 3001 | struct il_addsta_cmd sta_cmd; |
| 3002 | |
| 3003 | lockdep_assert_held(&il->mutex); |
| 3004 | |
| 3005 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); |
| 3006 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 3007 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 3008 | |
| 3009 | if (sta_id == ctx->bcast_sta_id) |
| 3010 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 3011 | |
| 3012 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 3013 | |
| 3014 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3015 | il->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
| 3016 | il->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 3017 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3018 | memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3019 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3020 | memcpy(il->stations[sta_id].sta.key.key, keyconf->key, keyconf->keylen); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3021 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3022 | if ((il->stations[sta_id].sta.key. |
| 3023 | key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3024 | il->stations[sta_id].sta.key.key_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3025 | il_get_free_ucode_key_idx(il); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3026 | /* else, we are overriding an existing key => no need to allocated room |
| 3027 | * in uCode. */ |
| 3028 | |
| 3029 | WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3030 | "no space for a new key"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3031 | |
| 3032 | il->stations[sta_id].sta.key.key_flags = key_flags; |
| 3033 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 3034 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3035 | |
| 3036 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3037 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3038 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3039 | |
| 3040 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3041 | } |
| 3042 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3043 | static int |
| 3044 | il4965_set_tkip_dynamic_key_info(struct il_priv *il, |
| 3045 | struct il_rxon_context *ctx, |
| 3046 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3047 | { |
| 3048 | unsigned long flags; |
| 3049 | int ret = 0; |
| 3050 | __le16 key_flags = 0; |
| 3051 | |
| 3052 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 3053 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 3054 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 3055 | |
| 3056 | if (sta_id == ctx->bcast_sta_id) |
| 3057 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 3058 | |
| 3059 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 3060 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 3061 | |
| 3062 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3063 | |
| 3064 | il->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
| 3065 | il->stations[sta_id].keyinfo.keylen = 16; |
| 3066 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3067 | if ((il->stations[sta_id].sta.key. |
| 3068 | key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3069 | il->stations[sta_id].sta.key.key_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3070 | il_get_free_ucode_key_idx(il); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3071 | /* else, we are overriding an existing key => no need to allocated room |
| 3072 | * in uCode. */ |
| 3073 | |
| 3074 | WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3075 | "no space for a new key"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3076 | |
| 3077 | il->stations[sta_id].sta.key.key_flags = key_flags; |
| 3078 | |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3079 | /* This copy is acutally not needed: we get the key with each TX */ |
| 3080 | memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, 16); |
| 3081 | |
| 3082 | memcpy(il->stations[sta_id].sta.key.key, keyconf->key, 16); |
| 3083 | |
| 3084 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3085 | |
| 3086 | return ret; |
| 3087 | } |
| 3088 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3089 | void |
| 3090 | il4965_update_tkip_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 3091 | struct ieee80211_key_conf *keyconf, |
| 3092 | struct ieee80211_sta *sta, u32 iv32, u16 * phase1key) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3093 | { |
| 3094 | u8 sta_id; |
| 3095 | unsigned long flags; |
| 3096 | int i; |
| 3097 | |
| 3098 | if (il_scan_cancel(il)) { |
| 3099 | /* cancel scan failed, just live w/ bad key and rely |
| 3100 | briefly on SW decryption */ |
| 3101 | return; |
| 3102 | } |
| 3103 | |
| 3104 | sta_id = il_sta_id_or_broadcast(il, ctx, sta); |
| 3105 | if (sta_id == IL_INVALID_STATION) |
| 3106 | return; |
| 3107 | |
| 3108 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3109 | |
| 3110 | il->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 3111 | |
| 3112 | for (i = 0; i < 5; i++) |
| 3113 | il->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3114 | cpu_to_le16(phase1key[i]); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3115 | |
| 3116 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 3117 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3118 | |
| 3119 | il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC); |
| 3120 | |
| 3121 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3122 | |
| 3123 | } |
| 3124 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3125 | int |
| 3126 | il4965_remove_dynamic_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 3127 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3128 | { |
| 3129 | unsigned long flags; |
| 3130 | u16 key_flags; |
| 3131 | u8 keyidx; |
| 3132 | struct il_addsta_cmd sta_cmd; |
| 3133 | |
| 3134 | lockdep_assert_held(&il->mutex); |
| 3135 | |
| 3136 | ctx->key_mapping_keys--; |
| 3137 | |
| 3138 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3139 | key_flags = le16_to_cpu(il->stations[sta_id].sta.key.key_flags); |
| 3140 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; |
| 3141 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3142 | 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] | 3143 | |
| 3144 | if (keyconf->keyidx != keyidx) { |
| 3145 | /* We need to remove a key with idx different that the one |
| 3146 | * in the uCode. This means that the key we need to remove has |
| 3147 | * been replaced by another one with different idx. |
| 3148 | * Don't do anything and return ok |
| 3149 | */ |
| 3150 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3151 | return 0; |
| 3152 | } |
| 3153 | |
| 3154 | if (il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3155 | IL_WARN("Removing wrong key %d 0x%x\n", keyconf->keyidx, |
| 3156 | key_flags); |
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 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3161 | if (!test_and_clear_bit |
| 3162 | (il->stations[sta_id].sta.key.key_offset, &il->ucode_key_table)) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3163 | IL_ERR("idx %d not used in uCode key table.\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3164 | il->stations[sta_id].sta.key.key_offset); |
| 3165 | memset(&il->stations[sta_id].keyinfo, 0, sizeof(struct il_hw_key)); |
| 3166 | memset(&il->stations[sta_id].sta.key, 0, sizeof(struct il4965_keyinfo)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3167 | il->stations[sta_id].sta.key.key_flags = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3168 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3169 | il->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; |
| 3170 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 3171 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3172 | |
| 3173 | if (il_is_rfkill(il)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3174 | D_WEP |
| 3175 | ("Not sending C_ADD_STA command because RFKILL enabled.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3176 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3177 | return 0; |
| 3178 | } |
| 3179 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3180 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3181 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3182 | |
| 3183 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3184 | } |
| 3185 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3186 | int |
| 3187 | il4965_set_dynamic_key(struct il_priv *il, struct il_rxon_context *ctx, |
| 3188 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3189 | { |
| 3190 | int ret; |
| 3191 | |
| 3192 | lockdep_assert_held(&il->mutex); |
| 3193 | |
| 3194 | ctx->key_mapping_keys++; |
| 3195 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
| 3196 | |
| 3197 | switch (keyconf->cipher) { |
| 3198 | case WLAN_CIPHER_SUITE_CCMP: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3199 | ret = |
| 3200 | il4965_set_ccmp_dynamic_key_info(il, ctx, keyconf, sta_id); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3201 | break; |
| 3202 | case WLAN_CIPHER_SUITE_TKIP: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3203 | ret = |
| 3204 | il4965_set_tkip_dynamic_key_info(il, ctx, keyconf, sta_id); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3205 | break; |
| 3206 | case WLAN_CIPHER_SUITE_WEP40: |
| 3207 | case WLAN_CIPHER_SUITE_WEP104: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3208 | ret = il4965_set_wep_dynamic_key_info(il, ctx, keyconf, sta_id); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3209 | break; |
| 3210 | default: |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3211 | IL_ERR("Unknown alg: %s cipher = %x\n", __func__, |
| 3212 | keyconf->cipher); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3213 | ret = -EINVAL; |
| 3214 | } |
| 3215 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3216 | D_WEP("Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n", |
| 3217 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, sta_id, ret); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3218 | |
| 3219 | return ret; |
| 3220 | } |
| 3221 | |
| 3222 | /** |
| 3223 | * il4965_alloc_bcast_station - add broadcast station into driver's station table. |
| 3224 | * |
| 3225 | * This adds the broadcast station into the driver's station table |
| 3226 | * and marks it driver active, so that it will be restored to the |
| 3227 | * device at the next best time. |
| 3228 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3229 | int |
| 3230 | 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] | 3231 | { |
| 3232 | struct il_link_quality_cmd *link_cmd; |
| 3233 | unsigned long flags; |
| 3234 | u8 sta_id; |
| 3235 | |
| 3236 | spin_lock_irqsave(&il->sta_lock, flags); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3237 | sta_id = il_prep_station(il, ctx, il_bcast_addr, false, NULL); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3238 | if (sta_id == IL_INVALID_STATION) { |
| 3239 | IL_ERR("Unable to prepare broadcast station\n"); |
| 3240 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3241 | |
| 3242 | return -EINVAL; |
| 3243 | } |
| 3244 | |
| 3245 | il->stations[sta_id].used |= IL_STA_DRIVER_ACTIVE; |
| 3246 | il->stations[sta_id].used |= IL_STA_BCAST; |
| 3247 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3248 | |
| 3249 | link_cmd = il4965_sta_alloc_lq(il, sta_id); |
| 3250 | if (!link_cmd) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3251 | IL_ERR |
| 3252 | ("Unable to initialize rate scaling for bcast station.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3253 | return -ENOMEM; |
| 3254 | } |
| 3255 | |
| 3256 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3257 | il->stations[sta_id].lq = link_cmd; |
| 3258 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3259 | |
| 3260 | return 0; |
| 3261 | } |
| 3262 | |
| 3263 | /** |
| 3264 | * il4965_update_bcast_station - update broadcast station's LQ command |
| 3265 | * |
| 3266 | * Only used by iwl4965. Placed here to have all bcast station management |
| 3267 | * code together. |
| 3268 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3269 | static int |
| 3270 | 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] | 3271 | { |
| 3272 | unsigned long flags; |
| 3273 | struct il_link_quality_cmd *link_cmd; |
| 3274 | u8 sta_id = ctx->bcast_sta_id; |
| 3275 | |
| 3276 | link_cmd = il4965_sta_alloc_lq(il, sta_id); |
| 3277 | if (!link_cmd) { |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 3278 | IL_ERR("Unable to initialize rate scaling for bcast sta.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3279 | return -ENOMEM; |
| 3280 | } |
| 3281 | |
| 3282 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3283 | if (il->stations[sta_id].lq) |
| 3284 | kfree(il->stations[sta_id].lq); |
| 3285 | else |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 3286 | D_INFO("Bcast sta rate scaling has not been initialized.\n"); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3287 | il->stations[sta_id].lq = link_cmd; |
| 3288 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3289 | |
| 3290 | return 0; |
| 3291 | } |
| 3292 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3293 | int |
| 3294 | il4965_update_bcast_stations(struct il_priv *il) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3295 | { |
| 3296 | return il4965_update_bcast_station(il, &il->ctx); |
| 3297 | } |
| 3298 | |
| 3299 | /** |
| 3300 | * il4965_sta_tx_modify_enable_tid - Enable Tx for this TID in station table |
| 3301 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3302 | int |
| 3303 | 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] | 3304 | { |
| 3305 | unsigned long flags; |
| 3306 | struct il_addsta_cmd sta_cmd; |
| 3307 | |
| 3308 | lockdep_assert_held(&il->mutex); |
| 3309 | |
| 3310 | /* Remove "disable" flag, to enable Tx for this TID */ |
| 3311 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3312 | il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 3313 | il->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 3314 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3315 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3316 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3317 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3318 | |
| 3319 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3320 | } |
| 3321 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3322 | int |
| 3323 | il4965_sta_rx_agg_start(struct il_priv *il, struct ieee80211_sta *sta, int tid, |
| 3324 | u16 ssn) |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3325 | { |
| 3326 | unsigned long flags; |
| 3327 | int sta_id; |
| 3328 | struct il_addsta_cmd sta_cmd; |
| 3329 | |
| 3330 | lockdep_assert_held(&il->mutex); |
| 3331 | |
| 3332 | sta_id = il_sta_id(sta); |
| 3333 | if (sta_id == IL_INVALID_STATION) |
| 3334 | return -ENXIO; |
| 3335 | |
| 3336 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3337 | il->stations[sta_id].sta.station_flags_msk = 0; |
| 3338 | 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] | 3339 | il->stations[sta_id].sta.add_immediate_ba_tid = (u8) tid; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3340 | il->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 3341 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3342 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3343 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3344 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3345 | |
| 3346 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3347 | } |
| 3348 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3349 | int |
| 3350 | 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] | 3351 | { |
| 3352 | unsigned long flags; |
| 3353 | int sta_id; |
| 3354 | struct il_addsta_cmd sta_cmd; |
| 3355 | |
| 3356 | lockdep_assert_held(&il->mutex); |
| 3357 | |
| 3358 | sta_id = il_sta_id(sta); |
| 3359 | if (sta_id == IL_INVALID_STATION) { |
| 3360 | IL_ERR("Invalid station for AGG tid %d\n", tid); |
| 3361 | return -ENXIO; |
| 3362 | } |
| 3363 | |
| 3364 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3365 | il->stations[sta_id].sta.station_flags_msk = 0; |
| 3366 | 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] | 3367 | il->stations[sta_id].sta.remove_immediate_ba_tid = (u8) tid; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3368 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3369 | memcpy(&sta_cmd, &il->stations[sta_id].sta, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3370 | sizeof(struct il_addsta_cmd)); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3371 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3372 | |
| 3373 | return il_send_add_sta(il, &sta_cmd, CMD_SYNC); |
| 3374 | } |
| 3375 | |
| 3376 | void |
| 3377 | il4965_sta_modify_sleep_tx_count(struct il_priv *il, int sta_id, int cnt) |
| 3378 | { |
| 3379 | unsigned long flags; |
| 3380 | |
| 3381 | spin_lock_irqsave(&il->sta_lock, flags); |
| 3382 | il->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK; |
| 3383 | il->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 3384 | il->stations[sta_id].sta.sta.modify_mask = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3385 | STA_MODIFY_SLEEP_TX_COUNT_MSK; |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3386 | il->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt); |
| 3387 | il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3388 | il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC); |
Stanislaw Gruszka | eb3cdfb | 2011-08-30 12:58:35 +0200 | [diff] [blame] | 3389 | spin_unlock_irqrestore(&il->sta_lock, flags); |
| 3390 | |
| 3391 | } |
| 3392 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3393 | void |
| 3394 | il4965_update_chain_flags(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3395 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3396 | if (il->cfg->ops->hcmd->set_rxon_chain) { |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 3397 | il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx); |
| 3398 | if (il->ctx.active.rx_chain != il->ctx.staging.rx_chain) |
| 3399 | il_commit_rxon(il, &il->ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3400 | } |
| 3401 | } |
| 3402 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3403 | static void |
| 3404 | il4965_clear_free_frames(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3405 | { |
| 3406 | struct list_head *element; |
| 3407 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3408 | 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] | 3409 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3410 | while (!list_empty(&il->free_frames)) { |
| 3411 | element = il->free_frames.next; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3412 | list_del(element); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3413 | kfree(list_entry(element, struct il_frame, list)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3414 | il->frames_count--; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3415 | } |
| 3416 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3417 | if (il->frames_count) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3418 | IL_WARN("%d frames still in use. Did we lose one?\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3419 | il->frames_count); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3420 | il->frames_count = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3421 | } |
| 3422 | } |
| 3423 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3424 | static struct il_frame * |
| 3425 | il4965_get_free_frame(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3426 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3427 | struct il_frame *frame; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3428 | struct list_head *element; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3429 | if (list_empty(&il->free_frames)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3430 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 3431 | if (!frame) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3432 | IL_ERR("Could not allocate frame!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3433 | return NULL; |
| 3434 | } |
| 3435 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3436 | il->frames_count++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3437 | return frame; |
| 3438 | } |
| 3439 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3440 | element = il->free_frames.next; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3441 | list_del(element); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3442 | return list_entry(element, struct il_frame, list); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3443 | } |
| 3444 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3445 | static void |
| 3446 | il4965_free_frame(struct il_priv *il, struct il_frame *frame) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3447 | { |
| 3448 | memset(frame, 0, sizeof(*frame)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3449 | list_add(&frame->list, &il->free_frames); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3450 | } |
| 3451 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3452 | static u32 |
| 3453 | il4965_fill_beacon_frame(struct il_priv *il, struct ieee80211_hdr *hdr, |
| 3454 | int left) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3455 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3456 | lockdep_assert_held(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3457 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3458 | if (!il->beacon_skb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3459 | return 0; |
| 3460 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3461 | if (il->beacon_skb->len > left) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3462 | return 0; |
| 3463 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3464 | memcpy(hdr, il->beacon_skb->data, il->beacon_skb->len); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3465 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3466 | return il->beacon_skb->len; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | /* 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] | 3470 | static void |
| 3471 | il4965_set_beacon_tim(struct il_priv *il, |
| 3472 | struct il_tx_beacon_cmd *tx_beacon_cmd, u8 * beacon, |
| 3473 | u32 frame_size) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3474 | { |
| 3475 | u16 tim_idx; |
| 3476 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon; |
| 3477 | |
| 3478 | /* |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3479 | * 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] | 3480 | * variable-length part of the beacon. |
| 3481 | */ |
| 3482 | tim_idx = mgmt->u.beacon.variable - beacon; |
| 3483 | |
| 3484 | /* Parse variable-length elements of beacon to find WLAN_EID_TIM */ |
| 3485 | while ((tim_idx < (frame_size - 2)) && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3486 | (beacon[tim_idx] != WLAN_EID_TIM)) |
| 3487 | tim_idx += beacon[tim_idx + 1] + 2; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3488 | |
| 3489 | /* If TIM field was found, set variables */ |
| 3490 | if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) { |
| 3491 | tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3492 | tx_beacon_cmd->tim_size = beacon[tim_idx + 1]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3493 | } else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3494 | IL_WARN("Unable to find TIM Element in beacon\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3495 | } |
| 3496 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3497 | static unsigned int |
| 3498 | 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] | 3499 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3500 | struct il_tx_beacon_cmd *tx_beacon_cmd; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3501 | u32 frame_size; |
| 3502 | u32 rate_flags; |
| 3503 | u32 rate; |
| 3504 | /* |
| 3505 | * We have to set up the TX command, the TX Beacon command, and the |
| 3506 | * beacon contents. |
| 3507 | */ |
| 3508 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3509 | lockdep_assert_held(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3510 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3511 | if (!il->beacon_ctx) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3512 | IL_ERR("trying to build beacon w/o beacon context!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3513 | return 0; |
| 3514 | } |
| 3515 | |
| 3516 | /* Initialize memory */ |
| 3517 | tx_beacon_cmd = &frame->u.beacon; |
| 3518 | memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); |
| 3519 | |
| 3520 | /* Set up TX beacon contents */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3521 | frame_size = |
| 3522 | il4965_fill_beacon_frame(il, tx_beacon_cmd->frame, |
| 3523 | sizeof(frame->u) - sizeof(*tx_beacon_cmd)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3524 | if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE)) |
| 3525 | return 0; |
| 3526 | if (!frame_size) |
| 3527 | return 0; |
| 3528 | |
| 3529 | /* Set up TX command fields */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3530 | tx_beacon_cmd->tx.len = cpu_to_le16((u16) frame_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3531 | tx_beacon_cmd->tx.sta_id = il->beacon_ctx->bcast_sta_id; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3532 | 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] | 3533 | tx_beacon_cmd->tx.tx_flags = |
| 3534 | TX_CMD_FLG_SEQ_CTL_MSK | TX_CMD_FLG_TSF_MSK | |
| 3535 | TX_CMD_FLG_STA_RATE_MSK; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3536 | |
| 3537 | /* Set up TX beacon command fields */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3538 | il4965_set_beacon_tim(il, tx_beacon_cmd, (u8 *) tx_beacon_cmd->frame, |
| 3539 | frame_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3540 | |
| 3541 | /* Set up packet rate and flags */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3542 | rate = il_get_lowest_plcp(il, il->beacon_ctx); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3543 | il->mgmt_tx_ant = |
| 3544 | il4965_toggle_tx_ant(il, il->mgmt_tx_ant, |
| 3545 | il->hw_params.valid_tx_ant); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3546 | rate_flags = il4965_ant_idx_to_flags(il->mgmt_tx_ant); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3547 | if ((rate >= IL_FIRST_CCK_RATE) && (rate <= IL_LAST_CCK_RATE)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3548 | rate_flags |= RATE_MCS_CCK_MSK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3549 | tx_beacon_cmd->tx.rate_n_flags = |
| 3550 | il4965_hw_set_rate_n_flags(rate, rate_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3551 | |
| 3552 | return sizeof(*tx_beacon_cmd) + frame_size; |
| 3553 | } |
| 3554 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3555 | int |
| 3556 | il4965_send_beacon_cmd(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3557 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3558 | struct il_frame *frame; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3559 | unsigned int frame_size; |
| 3560 | int rc; |
| 3561 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3562 | frame = il4965_get_free_frame(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3563 | if (!frame) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3564 | IL_ERR("Could not obtain free frame buffer for beacon " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3565 | "command.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3566 | return -ENOMEM; |
| 3567 | } |
| 3568 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3569 | frame_size = il4965_hw_get_beacon_cmd(il, frame); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3570 | if (!frame_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3571 | IL_ERR("Error configuring the beacon command\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3572 | il4965_free_frame(il, frame); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3573 | return -EINVAL; |
| 3574 | } |
| 3575 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3576 | 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] | 3577 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3578 | il4965_free_frame(il, frame); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3579 | |
| 3580 | return rc; |
| 3581 | } |
| 3582 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3583 | static inline dma_addr_t |
| 3584 | il4965_tfd_tb_get_addr(struct il_tfd *tfd, u8 idx) |
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 | |
| 3588 | dma_addr_t addr = get_unaligned_le32(&tb->lo); |
| 3589 | if (sizeof(dma_addr_t) > sizeof(u32)) |
| 3590 | addr |= |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3591 | ((dma_addr_t) (le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << |
| 3592 | 16; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3593 | |
| 3594 | return addr; |
| 3595 | } |
| 3596 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3597 | static inline u16 |
| 3598 | il4965_tfd_tb_get_len(struct il_tfd *tfd, u8 idx) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3599 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3600 | struct il_tfd_tb *tb = &tfd->tbs[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3601 | |
| 3602 | return le16_to_cpu(tb->hi_n_len) >> 4; |
| 3603 | } |
| 3604 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3605 | static inline void |
| 3606 | 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] | 3607 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3608 | struct il_tfd_tb *tb = &tfd->tbs[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3609 | u16 hi_n_len = len << 4; |
| 3610 | |
| 3611 | put_unaligned_le32(addr, &tb->lo); |
| 3612 | if (sizeof(dma_addr_t) > sizeof(u32)) |
| 3613 | hi_n_len |= ((addr >> 16) >> 16) & 0xF; |
| 3614 | |
| 3615 | tb->hi_n_len = cpu_to_le16(hi_n_len); |
| 3616 | |
| 3617 | tfd->num_tbs = idx + 1; |
| 3618 | } |
| 3619 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3620 | static inline u8 |
| 3621 | il4965_tfd_get_num_tbs(struct il_tfd *tfd) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3622 | { |
| 3623 | return tfd->num_tbs & 0x1f; |
| 3624 | } |
| 3625 | |
| 3626 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3627 | * 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] | 3628 | * @il - driver ilate data |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3629 | * @txq - tx queue |
| 3630 | * |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3631 | * Does NOT advance any TFD circular buffer read/write idxes |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3632 | * Does NOT free the TFD itself (which is within circular buffer) |
| 3633 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3634 | void |
| 3635 | 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] | 3636 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3637 | struct il_tfd *tfd_tmp = (struct il_tfd *)txq->tfds; |
| 3638 | struct il_tfd *tfd; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3639 | struct pci_dev *dev = il->pci_dev; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3640 | int idx = txq->q.read_ptr; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3641 | int i; |
| 3642 | int num_tbs; |
| 3643 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3644 | tfd = &tfd_tmp[idx]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3645 | |
| 3646 | /* Sanity check on number of chunks */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3647 | num_tbs = il4965_tfd_get_num_tbs(tfd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3648 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3649 | if (num_tbs >= IL_NUM_OF_TBS) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3650 | IL_ERR("Too many chunks: %i\n", num_tbs); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3651 | /* @todo issue fatal error, it is quite serious situation */ |
| 3652 | return; |
| 3653 | } |
| 3654 | |
| 3655 | /* Unmap tx_cmd */ |
| 3656 | if (num_tbs) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3657 | pci_unmap_single(dev, dma_unmap_addr(&txq->meta[idx], mapping), |
| 3658 | dma_unmap_len(&txq->meta[idx], len), |
| 3659 | PCI_DMA_BIDIRECTIONAL); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3660 | |
| 3661 | /* Unmap chunks, if any. */ |
| 3662 | for (i = 1; i < num_tbs; i++) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3663 | pci_unmap_single(dev, il4965_tfd_tb_get_addr(tfd, i), |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3664 | il4965_tfd_tb_get_len(tfd, i), |
| 3665 | PCI_DMA_TODEVICE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3666 | |
| 3667 | /* free SKB */ |
| 3668 | if (txq->txb) { |
| 3669 | struct sk_buff *skb; |
| 3670 | |
| 3671 | skb = txq->txb[txq->q.read_ptr].skb; |
| 3672 | |
| 3673 | /* can be called from irqs-disabled context */ |
| 3674 | if (skb) { |
| 3675 | dev_kfree_skb_any(skb); |
| 3676 | txq->txb[txq->q.read_ptr].skb = NULL; |
| 3677 | } |
| 3678 | } |
| 3679 | } |
| 3680 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3681 | int |
| 3682 | il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il, struct il_tx_queue *txq, |
| 3683 | dma_addr_t addr, u16 len, u8 reset, u8 pad) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3684 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3685 | struct il_queue *q; |
| 3686 | struct il_tfd *tfd, *tfd_tmp; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3687 | u32 num_tbs; |
| 3688 | |
| 3689 | q = &txq->q; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3690 | tfd_tmp = (struct il_tfd *)txq->tfds; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3691 | tfd = &tfd_tmp[q->write_ptr]; |
| 3692 | |
| 3693 | if (reset) |
| 3694 | memset(tfd, 0, sizeof(*tfd)); |
| 3695 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3696 | num_tbs = il4965_tfd_get_num_tbs(tfd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3697 | |
| 3698 | /* Each TFD can point to a maximum 20 Tx buffers */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3699 | if (num_tbs >= IL_NUM_OF_TBS) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3700 | IL_ERR("Error can not send more than %d chunks\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3701 | IL_NUM_OF_TBS); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3702 | return -EINVAL; |
| 3703 | } |
| 3704 | |
| 3705 | BUG_ON(addr & ~DMA_BIT_MASK(36)); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3706 | if (unlikely(addr & ~IL_TX_DMA_MASK)) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3707 | IL_ERR("Unaligned address = %llx\n", (unsigned long long)addr); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3708 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3709 | il4965_tfd_set_tb(tfd, num_tbs, addr, len); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3710 | |
| 3711 | return 0; |
| 3712 | } |
| 3713 | |
| 3714 | /* |
| 3715 | * Tell nic where to find circular buffer of Tx Frame Descriptors for |
| 3716 | * given Tx queue, and enable the DMA channel used for that queue. |
| 3717 | * |
| 3718 | * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA |
| 3719 | * channels supported in hardware. |
| 3720 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3721 | int |
| 3722 | 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] | 3723 | { |
| 3724 | int txq_id = txq->q.id; |
| 3725 | |
| 3726 | /* Circular buffer (TFD queue in DRAM) physical base address */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3727 | 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] | 3728 | |
| 3729 | return 0; |
| 3730 | } |
| 3731 | |
| 3732 | /****************************************************************************** |
| 3733 | * |
| 3734 | * Generic RX handler implementations |
| 3735 | * |
| 3736 | ******************************************************************************/ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3737 | static void |
| 3738 | 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] | 3739 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3740 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3741 | struct il_alive_resp *palive; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3742 | struct delayed_work *pwork; |
| 3743 | |
| 3744 | palive = &pkt->u.alive_frame; |
| 3745 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3746 | D_INFO("Alive ucode status 0x%08X revision " "0x%01X 0x%01X\n", |
| 3747 | palive->is_valid, palive->ver_type, palive->ver_subtype); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3748 | |
| 3749 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3750 | D_INFO("Initialization Alive received.\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3751 | memcpy(&il->card_alive_init, &pkt->u.alive_frame, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3752 | sizeof(struct il_init_alive_resp)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3753 | pwork = &il->init_alive_start; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3754 | } else { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3755 | D_INFO("Runtime Alive received.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3756 | memcpy(&il->card_alive, &pkt->u.alive_frame, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3757 | sizeof(struct il_alive_resp)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3758 | pwork = &il->alive_start; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | /* We delay the ALIVE response by 5ms to |
| 3762 | * give the HW RF Kill time to activate... */ |
| 3763 | if (palive->is_valid == UCODE_VALID_OK) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3764 | queue_delayed_work(il->workqueue, pwork, msecs_to_jiffies(5)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3765 | else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 3766 | IL_WARN("uCode did not respond OK.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /** |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3770 | * il4965_bg_stats_periodic - Timer callback to queue stats |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3771 | * |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3772 | * This callback is provided in order to send a stats request. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3773 | * |
| 3774 | * This timer function is continually reset to execute within |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 3775 | * REG_RECALIB_PERIOD seconds since the last N_STATS |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3776 | * 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] | 3777 | * to update the temperature used for calibrating the TXPOWER. |
| 3778 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3779 | static void |
| 3780 | il4965_bg_stats_periodic(unsigned long data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3781 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3782 | struct il_priv *il = (struct il_priv *)data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3783 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3784 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3785 | return; |
| 3786 | |
| 3787 | /* dont send host command if rf-kill is on */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3788 | if (!il_is_ready_rf(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3789 | return; |
| 3790 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3791 | il_send_stats_request(il, CMD_ASYNC, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3794 | static void |
| 3795 | 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] | 3796 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3797 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3798 | struct il4965_beacon_notif *beacon = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3799 | (struct il4965_beacon_notif *)pkt->u.raw; |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 3800 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3801 | 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] | 3802 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3803 | D_RX("beacon status %x retries %d iss %d " "tsf %d %d rate %d\n", |
| 3804 | le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK, |
| 3805 | beacon->beacon_notify_hdr.failure_frame, |
| 3806 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3807 | 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] | 3808 | #endif |
| 3809 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3810 | il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3811 | } |
| 3812 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3813 | static void |
| 3814 | il4965_perform_ct_kill_task(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3815 | { |
| 3816 | unsigned long flags; |
| 3817 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3818 | D_POWER("Stop all queues\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3819 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3820 | if (il->mac80211_registered) |
| 3821 | ieee80211_stop_queues(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3822 | |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3823 | _il_wr(il, CSR_UCODE_DRV_GP1_SET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3824 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3825 | _il_rd(il, CSR_UCODE_DRV_GP1); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3826 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3827 | spin_lock_irqsave(&il->reg_lock, flags); |
Stanislaw Gruszka | 1388226 | 2011-08-24 15:39:23 +0200 | [diff] [blame] | 3828 | if (!_il_grab_nic_access(il)) |
| 3829 | _il_release_nic_access(il); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3830 | spin_unlock_irqrestore(&il->reg_lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | /* Handle notification from uCode that card's power state is changing |
| 3834 | * due to software, hardware, or critical temperature RFKILL */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3835 | static void |
| 3836 | 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] | 3837 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3838 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3839 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3840 | unsigned long status = il->status; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3841 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3842 | 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] | 3843 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3844 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", |
| 3845 | (flags & CT_CARD_DISABLED) ? "Reached" : "Not reached"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3846 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3847 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | CT_CARD_DISABLED)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3848 | |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3849 | _il_wr(il, CSR_UCODE_DRV_GP1_SET, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3850 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3851 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3852 | 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] | 3853 | |
| 3854 | if (!(flags & RXON_CARD_DISABLED)) { |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 3855 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3856 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Stanislaw Gruszka | 0c1a94e | 2011-08-24 17:37:16 +0200 | [diff] [blame] | 3857 | il_wr(il, HBUS_TARG_MBX_C, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3858 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | if (flags & CT_CARD_DISABLED) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3863 | il4965_perform_ct_kill_task(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3864 | |
| 3865 | if (flags & HW_CARD_DISABLED) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3866 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3867 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3868 | clear_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3869 | |
| 3870 | if (!(flags & RXON_CARD_DISABLED)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3871 | il_scan_cancel(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3872 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 3873 | if ((test_bit(S_RF_KILL_HW, &status) != |
| 3874 | test_bit(S_RF_KILL_HW, &il->status))) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3875 | wiphy_rfkill_set_hw_state(il->hw->wiphy, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3876 | test_bit(S_RF_KILL_HW, &il->status)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3877 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3878 | wake_up(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | /** |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3882 | * il4965_setup_handlers - Initialize Rx handler callbacks |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3883 | * |
| 3884 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3885 | * to the host. |
| 3886 | * |
| 3887 | * This function chains into the hardware specific files for them to setup |
| 3888 | * any hardware specific handlers as well. |
| 3889 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3890 | static void |
| 3891 | il4965_setup_handlers(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3892 | { |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 3893 | il->handlers[N_ALIVE] = il4965_hdl_alive; |
| 3894 | il->handlers[N_ERROR] = il_hdl_error; |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3895 | il->handlers[N_CHANNEL_SWITCH] = il_hdl_csa; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3896 | il->handlers[N_SPECTRUM_MEASUREMENT] = il_hdl_spectrum_measurement; |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3897 | il->handlers[N_PM_SLEEP] = il_hdl_pm_sleep; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3898 | il->handlers[N_PM_DEBUG_STATS] = il_hdl_pm_debug_stats; |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3899 | il->handlers[N_BEACON] = il4965_hdl_beacon; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3900 | |
| 3901 | /* |
| 3902 | * The same handler is used for both the REPLY to a discrete |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 3903 | * stats request from the host as well as for the periodic |
| 3904 | * stats notifications (after received beacons) from the uCode. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3905 | */ |
Stanislaw Gruszka | d2dfb33 | 2011-11-15 13:16:38 +0100 | [diff] [blame] | 3906 | il->handlers[C_STATS] = il4965_hdl_c_stats; |
| 3907 | il->handlers[N_STATS] = il4965_hdl_stats; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3908 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3909 | il_setup_rx_scan_handlers(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3910 | |
| 3911 | /* status change handler */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3912 | il->handlers[N_CARD_STATE] = il4965_hdl_card_state; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3913 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3914 | il->handlers[N_MISSED_BEACONS] = il4965_hdl_missed_beacon; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3915 | /* Rx handlers */ |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 3916 | il->handlers[N_RX_PHY] = il4965_hdl_rx_phy; |
| 3917 | il->handlers[N_RX_MPDU] = il4965_hdl_rx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3918 | /* block ack */ |
Stanislaw Gruszka | 6e9848b4 | 2011-08-30 15:45:31 +0200 | [diff] [blame] | 3919 | il->handlers[N_COMPRESSED_BA] = il4965_hdl_compressed_ba; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3920 | /* Set up hardware specific Rx handlers */ |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3921 | il->cfg->ops->lib->handler_setup(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 3925 | * il4965_rx_handle - Main entry function for receiving responses from uCode |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3926 | * |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3927 | * Uses the il->handlers callback function array to invoke |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3928 | * the appropriate handlers, including command responses, |
| 3929 | * frame-received notifications, and other notifications. |
| 3930 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3931 | void |
| 3932 | il4965_rx_handle(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3933 | { |
Stanislaw Gruszka | b73bb5f | 2011-08-26 14:37:54 +0200 | [diff] [blame] | 3934 | struct il_rx_buf *rxb; |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 3935 | struct il_rx_pkt *pkt; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3936 | struct il_rx_queue *rxq = &il->rxq; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3937 | u32 r, i; |
| 3938 | int reclaim; |
| 3939 | unsigned long flags; |
| 3940 | u8 fill_rx = 0; |
| 3941 | u32 count = 8; |
| 3942 | int total_empty; |
| 3943 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 3944 | /* 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] | 3945 | * buffer that the driver may process (last buffer filled by ucode). */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3946 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3947 | i = rxq->read; |
| 3948 | |
| 3949 | /* Rx interrupt, but nothing sent from uCode */ |
| 3950 | if (i == r) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 3951 | D_RX("r = %d, i = %d\n", r, i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3952 | |
| 3953 | /* calculate total frames need to be restock after handling RX */ |
| 3954 | total_empty = r - rxq->write_actual; |
| 3955 | if (total_empty < 0) |
| 3956 | total_empty += RX_QUEUE_SIZE; |
| 3957 | |
| 3958 | if (total_empty > (RX_QUEUE_SIZE / 2)) |
| 3959 | fill_rx = 1; |
| 3960 | |
| 3961 | while (i != r) { |
| 3962 | int len; |
| 3963 | |
| 3964 | rxb = rxq->queue[i]; |
| 3965 | |
| 3966 | /* If an RXB doesn't have a Rx queue slot associated with it, |
| 3967 | * then a bug has been introduced in the queue refilling |
| 3968 | * routines -- catch it here */ |
| 3969 | BUG_ON(rxb == NULL); |
| 3970 | |
| 3971 | rxq->queue[i] = NULL; |
| 3972 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 3973 | pci_unmap_page(il->pci_dev, rxb->page_dma, |
| 3974 | PAGE_SIZE << il->hw_params.rx_page_order, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3975 | PCI_DMA_FROMDEVICE); |
| 3976 | pkt = rxb_addr(rxb); |
| 3977 | |
Stanislaw Gruszka | e94a409 | 2011-08-31 13:23:20 +0200 | [diff] [blame] | 3978 | 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] | 3979 | len += sizeof(u32); /* account for status word */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3980 | |
| 3981 | /* Reclaim a command buffer only if this packet is a response |
| 3982 | * to a (driver-originated) command. |
| 3983 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3984 | * there is no command buffer to reclaim. |
| 3985 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3986 | * but apparently a few don't get set; catch them here. */ |
| 3987 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3988 | (pkt->hdr.cmd != N_RX_PHY) && (pkt->hdr.cmd != N_RX) && |
| 3989 | (pkt->hdr.cmd != N_RX_MPDU) && |
| 3990 | (pkt->hdr.cmd != N_COMPRESSED_BA) && |
| 3991 | (pkt->hdr.cmd != N_STATS) && (pkt->hdr.cmd != C_TX); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3992 | |
| 3993 | /* Based on type of command response or notification, |
| 3994 | * handle those that need handling via function in |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3995 | * handlers table. See il4965_setup_handlers() */ |
| 3996 | if (il->handlers[pkt->hdr.cmd]) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 3997 | D_RX("r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3998 | il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 3999 | il->isr_stats.handlers[pkt->hdr.cmd]++; |
| 4000 | il->handlers[pkt->hdr.cmd] (il, rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4001 | } else { |
| 4002 | /* No handling needed */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4003 | D_RX("r %d i %d No handler needed for %s, 0x%02x\n", r, |
| 4004 | i, il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | /* |
| 4008 | * XXX: After here, we should always check rxb->page |
| 4009 | * against NULL before touching it or its virtual |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 4010 | * memory (pkt). Because some handler might have |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4011 | * already taken or freed the pages. |
| 4012 | */ |
| 4013 | |
| 4014 | if (reclaim) { |
| 4015 | /* Invoke any callbacks, transfer the buffer to caller, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4016 | * and fire off the (possibly) blocking il_send_cmd() |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4017 | * as we reclaim the driver command queue */ |
| 4018 | if (rxb->page) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4019 | il_tx_cmd_complete(il, rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4020 | else |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4021 | IL_WARN("Claim null rxb?\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | /* Reuse the page if possible. For notification packets and |
| 4025 | * SKBs that fail to Rx correctly, add them back into the |
| 4026 | * rx_free list for reuse later. */ |
| 4027 | spin_lock_irqsave(&rxq->lock, flags); |
| 4028 | if (rxb->page != NULL) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4029 | rxb->page_dma = |
| 4030 | pci_map_page(il->pci_dev, rxb->page, 0, |
| 4031 | PAGE_SIZE << il->hw_params. |
| 4032 | rx_page_order, PCI_DMA_FROMDEVICE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4033 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4034 | rxq->free_count++; |
| 4035 | } else |
| 4036 | list_add_tail(&rxb->list, &rxq->rx_used); |
| 4037 | |
| 4038 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4039 | |
| 4040 | i = (i + 1) & RX_QUEUE_MASK; |
| 4041 | /* If there are a lot of unused frames, |
| 4042 | * restock the Rx queue so ucode wont assert. */ |
| 4043 | if (fill_rx) { |
| 4044 | count++; |
| 4045 | if (count >= 8) { |
| 4046 | rxq->read = i; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4047 | il4965_rx_replenish_now(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4048 | count = 0; |
| 4049 | } |
| 4050 | } |
| 4051 | } |
| 4052 | |
| 4053 | /* Backtrack one entry */ |
| 4054 | rxq->read = i; |
| 4055 | if (fill_rx) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4056 | il4965_rx_replenish_now(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4057 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4058 | il4965_rx_queue_restock(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /* call this function to flush any scheduled tasklet */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4062 | static inline void |
| 4063 | il4965_synchronize_irq(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4064 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4065 | /* wait to make sure we flush pending tasklet */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4066 | synchronize_irq(il->pci_dev->irq); |
| 4067 | tasklet_kill(&il->irq_tasklet); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4068 | } |
| 4069 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4070 | static void |
| 4071 | il4965_irq_tasklet(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4072 | { |
| 4073 | u32 inta, handled = 0; |
| 4074 | u32 inta_fh; |
| 4075 | unsigned long flags; |
| 4076 | u32 i; |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4077 | #ifdef CONFIG_IWLEGACY_DEBUG |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4078 | u32 inta_mask; |
| 4079 | #endif |
| 4080 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4081 | spin_lock_irqsave(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4082 | |
| 4083 | /* Ack/clear/reset pending uCode interrupts. |
| 4084 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4085 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4086 | inta = _il_rd(il, CSR_INT); |
| 4087 | _il_wr(il, CSR_INT, inta); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4088 | |
| 4089 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4090 | * Any new interrupts that happen after this, either while we're |
| 4091 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4092 | inta_fh = _il_rd(il, CSR_FH_INT_STATUS); |
| 4093 | _il_wr(il, CSR_FH_INT_STATUS, inta_fh); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4094 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4095 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4096 | if (il_get_debug_level(il) & IL_DL_ISR) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4097 | /* just for debug */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4098 | inta_mask = _il_rd(il, CSR_INT_MASK); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4099 | D_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta, |
| 4100 | inta_mask, inta_fh); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4101 | } |
| 4102 | #endif |
| 4103 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4104 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4105 | |
| 4106 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4107 | * atomic, make sure that inta covers all the interrupts that |
| 4108 | * we've discovered, even if FH interrupt came in just after |
| 4109 | * reading CSR_INT. */ |
| 4110 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
| 4111 | inta |= CSR_INT_BIT_FH_RX; |
| 4112 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
| 4113 | inta |= CSR_INT_BIT_FH_TX; |
| 4114 | |
| 4115 | /* Now service all interrupt bits discovered above. */ |
| 4116 | if (inta & CSR_INT_BIT_HW_ERR) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4117 | IL_ERR("Hardware error detected. Restarting.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4118 | |
| 4119 | /* Tell the device to stop sending interrupts */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4120 | il_disable_interrupts(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4121 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4122 | il->isr_stats.hw++; |
| 4123 | il_irq_handle_error(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4124 | |
| 4125 | handled |= CSR_INT_BIT_HW_ERR; |
| 4126 | |
| 4127 | return; |
| 4128 | } |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4129 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4130 | if (il_get_debug_level(il) & (IL_DL_ISR)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4131 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 4132 | if (inta & CSR_INT_BIT_SCD) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4133 | D_ISR("Scheduler finished to transmit " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4134 | "the frame/frames.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4135 | il->isr_stats.sch++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | /* Alive notification via Rx interrupt will do the real work */ |
| 4139 | if (inta & CSR_INT_BIT_ALIVE) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4140 | D_ISR("Alive interrupt\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4141 | il->isr_stats.alive++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | #endif |
| 4145 | /* Safely ignore these bits for debug checks below */ |
| 4146 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
| 4147 | |
| 4148 | /* HW RF KILL switch toggled */ |
| 4149 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 4150 | int hw_rf_kill = 0; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4151 | if (! |
| 4152 | (_il_rd(il, CSR_GP_CNTRL) & |
| 4153 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4154 | hw_rf_kill = 1; |
| 4155 | |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4156 | IL_WARN("RF_KILL bit toggled to %s.\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4157 | hw_rf_kill ? "disable radio" : "enable radio"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4158 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4159 | il->isr_stats.rfkill++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4160 | |
| 4161 | /* driver only loads ucode once setting the interface up. |
| 4162 | * the driver allows loading the ucode even if the radio |
| 4163 | * is killed. Hence update the killswitch state here. The |
| 4164 | * rfkill handler will care about restarting if needed. |
| 4165 | */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4166 | if (!test_bit(S_ALIVE, &il->status)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4167 | if (hw_rf_kill) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4168 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4169 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4170 | clear_bit(S_RF_KILL_HW, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4171 | wiphy_rfkill_set_hw_state(il->hw->wiphy, hw_rf_kill); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | handled |= CSR_INT_BIT_RF_KILL; |
| 4175 | } |
| 4176 | |
| 4177 | /* Chip got too hot and stopped itself */ |
| 4178 | if (inta & CSR_INT_BIT_CT_KILL) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4179 | IL_ERR("Microcode CT kill error detected.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4180 | il->isr_stats.ctkill++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4181 | handled |= CSR_INT_BIT_CT_KILL; |
| 4182 | } |
| 4183 | |
| 4184 | /* Error detected by uCode */ |
| 4185 | if (inta & CSR_INT_BIT_SW_ERR) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4186 | IL_ERR("Microcode SW error detected. " " Restarting 0x%X.\n", |
| 4187 | inta); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4188 | il->isr_stats.sw++; |
| 4189 | il_irq_handle_error(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4190 | handled |= CSR_INT_BIT_SW_ERR; |
| 4191 | } |
| 4192 | |
| 4193 | /* |
| 4194 | * uCode wakes up after power-down sleep. |
| 4195 | * Tell device about any new tx or host commands enqueued, |
| 4196 | * and about any Rx buffers made available while asleep. |
| 4197 | */ |
| 4198 | if (inta & CSR_INT_BIT_WAKEUP) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4199 | D_ISR("Wakeup interrupt\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4200 | il_rx_queue_update_write_ptr(il, &il->rxq); |
| 4201 | for (i = 0; i < il->hw_params.max_txq_num; i++) |
| 4202 | il_txq_update_write_ptr(il, &il->txq[i]); |
| 4203 | il->isr_stats.wakeup++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4204 | handled |= CSR_INT_BIT_WAKEUP; |
| 4205 | } |
| 4206 | |
| 4207 | /* All uCode command responses, including Tx command responses, |
| 4208 | * Rx "responses" (frame-received notification), and other |
| 4209 | * notifications from uCode come through here*/ |
| 4210 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4211 | il4965_rx_handle(il); |
| 4212 | il->isr_stats.rx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4213 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 4214 | } |
| 4215 | |
| 4216 | /* This "Tx" DMA channel is used only for loading uCode */ |
| 4217 | if (inta & CSR_INT_BIT_FH_TX) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4218 | D_ISR("uCode load interrupt\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4219 | il->isr_stats.tx++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4220 | handled |= CSR_INT_BIT_FH_TX; |
| 4221 | /* Wake up uCode load routine, now that load is complete */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4222 | il->ucode_write_complete = 1; |
| 4223 | wake_up(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | if (inta & ~handled) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4227 | IL_ERR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4228 | il->isr_stats.unhandled++; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4231 | if (inta & ~(il->inta_mask)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4232 | IL_WARN("Disabled INTA bits 0x%08x were pending\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4233 | inta & ~il->inta_mask); |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 4234 | IL_WARN(" with FH49_INT = 0x%08x\n", inta_fh); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | /* Re-enable all interrupts */ |
Stanislaw Gruszka | 93fd74e | 2011-04-28 11:51:30 +0200 | [diff] [blame] | 4238 | /* only Re-enable if disabled by irq */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 4239 | if (test_bit(S_INT_ENABLED, &il->status)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4240 | il_enable_interrupts(il); |
Stanislaw Gruszka | a078a1f | 2011-04-28 11:51:25 +0200 | [diff] [blame] | 4241 | /* Re-enable RF_KILL if it occurred */ |
| 4242 | else if (handled & CSR_INT_BIT_RF_KILL) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4243 | il_enable_rfkill_int(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4244 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4245 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4246 | if (il_get_debug_level(il) & (IL_DL_ISR)) { |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4247 | inta = _il_rd(il, CSR_INT); |
| 4248 | inta_mask = _il_rd(il, CSR_INT_MASK); |
| 4249 | inta_fh = _il_rd(il, CSR_FH_INT_STATUS); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4250 | D_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4251 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4252 | } |
| 4253 | #endif |
| 4254 | } |
| 4255 | |
| 4256 | /***************************************************************************** |
| 4257 | * |
| 4258 | * sysfs attributes |
| 4259 | * |
| 4260 | *****************************************************************************/ |
| 4261 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4262 | #ifdef CONFIG_IWLEGACY_DEBUG |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4263 | |
| 4264 | /* |
| 4265 | * The following adds a new attribute to the sysfs representation |
| 4266 | * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/) |
| 4267 | * used for controlling the debug level. |
| 4268 | * |
| 4269 | * See the level definitions in iwl for details. |
| 4270 | * |
| 4271 | * The debug_level being managed using sysfs below is a per device debug |
| 4272 | * level that is used instead of the global debug level if it (the per |
| 4273 | * device debug level) is set. |
| 4274 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4275 | static ssize_t |
| 4276 | il4965_show_debug_level(struct device *d, struct device_attribute *attr, |
| 4277 | char *buf) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4278 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4279 | struct il_priv *il = dev_get_drvdata(d); |
| 4280 | return sprintf(buf, "0x%08X\n", il_get_debug_level(il)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4281 | } |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4282 | |
| 4283 | static ssize_t |
| 4284 | il4965_store_debug_level(struct device *d, struct device_attribute *attr, |
| 4285 | const char *buf, size_t count) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4286 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4287 | struct il_priv *il = dev_get_drvdata(d); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4288 | unsigned long val; |
| 4289 | int ret; |
| 4290 | |
| 4291 | ret = strict_strtoul(buf, 0, &val); |
| 4292 | if (ret) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4293 | 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] | 4294 | else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4295 | il->debug_level = val; |
| 4296 | if (il_alloc_traffic_mem(il)) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4297 | IL_ERR("Not enough memory to generate traffic log\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4298 | } |
| 4299 | return strnlen(buf, count); |
| 4300 | } |
| 4301 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4302 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, il4965_show_debug_level, |
| 4303 | il4965_store_debug_level); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4304 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4305 | #endif /* CONFIG_IWLEGACY_DEBUG */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4306 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4307 | static ssize_t |
| 4308 | il4965_show_temperature(struct device *d, struct device_attribute *attr, |
| 4309 | char *buf) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4310 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4311 | struct il_priv *il = dev_get_drvdata(d); |
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 | if (!il_is_alive(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4314 | return -EAGAIN; |
| 4315 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4316 | return sprintf(buf, "%d\n", il->temperature); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4317 | } |
| 4318 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4319 | static DEVICE_ATTR(temperature, S_IRUGO, il4965_show_temperature, NULL); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4320 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4321 | static ssize_t |
| 4322 | 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] | 4323 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4324 | struct il_priv *il = dev_get_drvdata(d); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4325 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4326 | if (!il_is_ready_rf(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4327 | return sprintf(buf, "off\n"); |
| 4328 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4329 | return sprintf(buf, "%d\n", il->tx_power_user_lmt); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4330 | } |
| 4331 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4332 | static ssize_t |
| 4333 | il4965_store_tx_power(struct device *d, struct device_attribute *attr, |
| 4334 | const char *buf, size_t count) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4335 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4336 | struct il_priv *il = dev_get_drvdata(d); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4337 | unsigned long val; |
| 4338 | int ret; |
| 4339 | |
| 4340 | ret = strict_strtoul(buf, 10, &val); |
| 4341 | if (ret) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4342 | IL_INFO("%s is not in decimal form.\n", buf); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4343 | else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4344 | ret = il_set_tx_power(il, val, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4345 | if (ret) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4346 | IL_ERR("failed setting tx power (0x%d).\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4347 | else |
| 4348 | ret = count; |
| 4349 | } |
| 4350 | return ret; |
| 4351 | } |
| 4352 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4353 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, il4965_show_tx_power, |
| 4354 | il4965_store_tx_power); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4355 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4356 | static struct attribute *il_sysfs_entries[] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4357 | &dev_attr_temperature.attr, |
| 4358 | &dev_attr_tx_power.attr, |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4359 | #ifdef CONFIG_IWLEGACY_DEBUG |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4360 | &dev_attr_debug_level.attr, |
| 4361 | #endif |
| 4362 | NULL |
| 4363 | }; |
| 4364 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4365 | static struct attribute_group il_attribute_group = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4366 | .name = NULL, /* put in device directory */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4367 | .attrs = il_sysfs_entries, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4368 | }; |
| 4369 | |
| 4370 | /****************************************************************************** |
| 4371 | * |
| 4372 | * uCode download functions |
| 4373 | * |
| 4374 | ******************************************************************************/ |
| 4375 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4376 | static void |
| 4377 | il4965_dealloc_ucode_pci(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4378 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4379 | il_free_fw_desc(il->pci_dev, &il->ucode_code); |
| 4380 | il_free_fw_desc(il->pci_dev, &il->ucode_data); |
| 4381 | il_free_fw_desc(il->pci_dev, &il->ucode_data_backup); |
| 4382 | il_free_fw_desc(il->pci_dev, &il->ucode_init); |
| 4383 | il_free_fw_desc(il->pci_dev, &il->ucode_init_data); |
| 4384 | il_free_fw_desc(il->pci_dev, &il->ucode_boot); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4385 | } |
| 4386 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4387 | static void |
| 4388 | il4965_nic_start(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4389 | { |
| 4390 | /* Remove all resets to allow NIC to operate */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4391 | _il_wr(il, CSR_RESET, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4392 | } |
| 4393 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4394 | static void il4965_ucode_callback(const struct firmware *ucode_raw, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4395 | void *context); |
| 4396 | 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] | 4397 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4398 | static int __must_check |
| 4399 | il4965_request_firmware(struct il_priv *il, bool first) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4400 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4401 | const char *name_pre = il->cfg->fw_name_pre; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4402 | char tag[8]; |
| 4403 | |
| 4404 | if (first) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4405 | il->fw_idx = il->cfg->ucode_api_max; |
| 4406 | sprintf(tag, "%d", il->fw_idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4407 | } else { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4408 | il->fw_idx--; |
| 4409 | sprintf(tag, "%d", il->fw_idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4410 | } |
| 4411 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4412 | if (il->fw_idx < il->cfg->ucode_api_min) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4413 | IL_ERR("no suitable firmware found!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4414 | return -ENOENT; |
| 4415 | } |
| 4416 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4417 | sprintf(il->firmware_name, "%s%s%s", name_pre, tag, ".ucode"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4418 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4419 | D_INFO("attempting to load firmware '%s'\n", il->firmware_name); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4420 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4421 | return request_firmware_nowait(THIS_MODULE, 1, il->firmware_name, |
| 4422 | &il->pci_dev->dev, GFP_KERNEL, il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4423 | il4965_ucode_callback); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4424 | } |
| 4425 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4426 | struct il4965_firmware_pieces { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4427 | const void *inst, *data, *init, *init_data, *boot; |
| 4428 | size_t inst_size, data_size, init_size, init_data_size, boot_size; |
| 4429 | }; |
| 4430 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4431 | static int |
| 4432 | il4965_load_firmware(struct il_priv *il, const struct firmware *ucode_raw, |
| 4433 | struct il4965_firmware_pieces *pieces) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4434 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4435 | struct il_ucode_header *ucode = (void *)ucode_raw->data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4436 | u32 api_ver, hdr_size; |
| 4437 | const u8 *src; |
| 4438 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4439 | il->ucode_ver = le32_to_cpu(ucode->ver); |
| 4440 | api_ver = IL_UCODE_API(il->ucode_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4441 | |
| 4442 | switch (api_ver) { |
| 4443 | default: |
| 4444 | case 0: |
| 4445 | case 1: |
| 4446 | case 2: |
| 4447 | hdr_size = 24; |
| 4448 | if (ucode_raw->size < hdr_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4449 | IL_ERR("File size too small!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4450 | return -EINVAL; |
| 4451 | } |
| 4452 | pieces->inst_size = le32_to_cpu(ucode->v1.inst_size); |
| 4453 | pieces->data_size = le32_to_cpu(ucode->v1.data_size); |
| 4454 | pieces->init_size = le32_to_cpu(ucode->v1.init_size); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4455 | 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] | 4456 | pieces->boot_size = le32_to_cpu(ucode->v1.boot_size); |
| 4457 | src = ucode->v1.data; |
| 4458 | break; |
| 4459 | } |
| 4460 | |
| 4461 | /* Verify size of file vs. image size info in file's header */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4462 | if (ucode_raw->size != |
| 4463 | hdr_size + pieces->inst_size + pieces->data_size + |
| 4464 | pieces->init_size + pieces->init_data_size + pieces->boot_size) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4465 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4466 | IL_ERR("uCode file size %d does not match expected size\n", |
| 4467 | (int)ucode_raw->size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4468 | return -EINVAL; |
| 4469 | } |
| 4470 | |
| 4471 | pieces->inst = src; |
| 4472 | src += pieces->inst_size; |
| 4473 | pieces->data = src; |
| 4474 | src += pieces->data_size; |
| 4475 | pieces->init = src; |
| 4476 | src += pieces->init_size; |
| 4477 | pieces->init_data = src; |
| 4478 | src += pieces->init_data_size; |
| 4479 | pieces->boot = src; |
| 4480 | src += pieces->boot_size; |
| 4481 | |
| 4482 | return 0; |
| 4483 | } |
| 4484 | |
| 4485 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4486 | * il4965_ucode_callback - callback when firmware was loaded |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4487 | * |
| 4488 | * If loaded successfully, copies the firmware into buffers |
| 4489 | * for the card to fetch (via DMA). |
| 4490 | */ |
| 4491 | static void |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4492 | il4965_ucode_callback(const struct firmware *ucode_raw, void *context) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4493 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4494 | struct il_priv *il = context; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4495 | struct il_ucode_header *ucode; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4496 | int err; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4497 | struct il4965_firmware_pieces pieces; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4498 | const unsigned int api_max = il->cfg->ucode_api_max; |
| 4499 | const unsigned int api_min = il->cfg->ucode_api_min; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4500 | u32 api_ver; |
| 4501 | |
| 4502 | u32 max_probe_length = 200; |
| 4503 | u32 standard_phy_calibration_size = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4504 | IL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4505 | |
| 4506 | memset(&pieces, 0, sizeof(pieces)); |
| 4507 | |
| 4508 | if (!ucode_raw) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4509 | if (il->fw_idx <= il->cfg->ucode_api_max) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4510 | IL_ERR("request for firmware file '%s' failed.\n", |
| 4511 | il->firmware_name); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4512 | goto try_again; |
| 4513 | } |
| 4514 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4515 | D_INFO("Loaded firmware file '%s' (%zd bytes).\n", il->firmware_name, |
| 4516 | ucode_raw->size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4517 | |
| 4518 | /* Make sure that we got at least the API version number */ |
| 4519 | if (ucode_raw->size < 4) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4520 | IL_ERR("File size way too small!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4521 | goto try_again; |
| 4522 | } |
| 4523 | |
| 4524 | /* Data from ucode file: header followed by uCode images */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4525 | ucode = (struct il_ucode_header *)ucode_raw->data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4526 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4527 | err = il4965_load_firmware(il, ucode_raw, &pieces); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4528 | |
| 4529 | if (err) |
| 4530 | goto try_again; |
| 4531 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4532 | api_ver = IL_UCODE_API(il->ucode_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4533 | |
| 4534 | /* |
| 4535 | * api_ver should match the api version forming part of the |
| 4536 | * firmware filename ... but we don't check for that and only rely |
| 4537 | * on the API version read from firmware header from here on forward |
| 4538 | */ |
| 4539 | if (api_ver < api_min || api_ver > api_max) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4540 | IL_ERR("Driver unable to support your firmware API. " |
| 4541 | "Driver supports v%u, firmware is v%u.\n", api_max, |
| 4542 | api_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4543 | goto try_again; |
| 4544 | } |
| 4545 | |
| 4546 | if (api_ver != api_max) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4547 | IL_ERR("Firmware has old API version. Expected v%u, " |
| 4548 | "got v%u. New firmware can be obtained " |
| 4549 | "from http://www.intellinuxwireless.org.\n", api_max, |
| 4550 | api_ver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4551 | |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4552 | IL_INFO("loaded firmware version %u.%u.%u.%u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4553 | IL_UCODE_MAJOR(il->ucode_ver), IL_UCODE_MINOR(il->ucode_ver), |
| 4554 | 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] | 4555 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4556 | snprintf(il->hw->wiphy->fw_version, sizeof(il->hw->wiphy->fw_version), |
| 4557 | "%u.%u.%u.%u", IL_UCODE_MAJOR(il->ucode_ver), |
| 4558 | IL_UCODE_MINOR(il->ucode_ver), IL_UCODE_API(il->ucode_ver), |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4559 | IL_UCODE_SERIAL(il->ucode_ver)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4560 | |
| 4561 | /* |
| 4562 | * For any of the failures below (before allocating pci memory) |
| 4563 | * we will try to load a version with a smaller API -- maybe the |
| 4564 | * user just got a corrupted version of the latest API. |
| 4565 | */ |
| 4566 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4567 | D_INFO("f/w package hdr ucode version raw = 0x%x\n", il->ucode_ver); |
| 4568 | D_INFO("f/w package hdr runtime inst size = %Zd\n", pieces.inst_size); |
| 4569 | D_INFO("f/w package hdr runtime data size = %Zd\n", pieces.data_size); |
| 4570 | D_INFO("f/w package hdr init inst size = %Zd\n", pieces.init_size); |
| 4571 | D_INFO("f/w package hdr init data size = %Zd\n", pieces.init_data_size); |
| 4572 | 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] | 4573 | |
| 4574 | /* Verify that uCode images will fit in card's SRAM */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4575 | if (pieces.inst_size > il->hw_params.max_inst_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4576 | IL_ERR("uCode instr len %Zd too large to fit in\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4577 | pieces.inst_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4578 | goto try_again; |
| 4579 | } |
| 4580 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4581 | if (pieces.data_size > il->hw_params.max_data_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4582 | IL_ERR("uCode data len %Zd too large to fit in\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4583 | pieces.data_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4584 | goto try_again; |
| 4585 | } |
| 4586 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4587 | if (pieces.init_size > il->hw_params.max_inst_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4588 | 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] | 4589 | pieces.init_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4590 | goto try_again; |
| 4591 | } |
| 4592 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4593 | if (pieces.init_data_size > il->hw_params.max_data_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4594 | 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] | 4595 | pieces.init_data_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4596 | goto try_again; |
| 4597 | } |
| 4598 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4599 | if (pieces.boot_size > il->hw_params.max_bsm_size) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4600 | 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] | 4601 | pieces.boot_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4602 | goto try_again; |
| 4603 | } |
| 4604 | |
| 4605 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4606 | |
| 4607 | /* Runtime instructions and 2 copies of data: |
| 4608 | * 1) unmodified from disk |
| 4609 | * 2) backup cache for save/restore during power-downs */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4610 | il->ucode_code.len = pieces.inst_size; |
| 4611 | il_alloc_fw_desc(il->pci_dev, &il->ucode_code); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4612 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4613 | il->ucode_data.len = pieces.data_size; |
| 4614 | il_alloc_fw_desc(il->pci_dev, &il->ucode_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4615 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4616 | il->ucode_data_backup.len = pieces.data_size; |
| 4617 | il_alloc_fw_desc(il->pci_dev, &il->ucode_data_backup); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4618 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4619 | if (!il->ucode_code.v_addr || !il->ucode_data.v_addr || |
| 4620 | !il->ucode_data_backup.v_addr) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4621 | goto err_pci_alloc; |
| 4622 | |
| 4623 | /* Initialization instructions and data */ |
| 4624 | if (pieces.init_size && pieces.init_data_size) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4625 | il->ucode_init.len = pieces.init_size; |
| 4626 | il_alloc_fw_desc(il->pci_dev, &il->ucode_init); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4627 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4628 | il->ucode_init_data.len = pieces.init_data_size; |
| 4629 | il_alloc_fw_desc(il->pci_dev, &il->ucode_init_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4630 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4631 | 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] | 4632 | goto err_pci_alloc; |
| 4633 | } |
| 4634 | |
| 4635 | /* Bootstrap (instructions only, no data) */ |
| 4636 | if (pieces.boot_size) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4637 | il->ucode_boot.len = pieces.boot_size; |
| 4638 | il_alloc_fw_desc(il->pci_dev, &il->ucode_boot); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4639 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4640 | if (!il->ucode_boot.v_addr) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4641 | goto err_pci_alloc; |
| 4642 | } |
| 4643 | |
| 4644 | /* Now that we can no longer fail, copy information */ |
| 4645 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4646 | il->sta_key_max_num = STA_KEY_MAX_NUM; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4647 | |
| 4648 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4649 | |
| 4650 | /* Runtime instructions (first block of data in file) */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4651 | D_INFO("Copying (but not loading) uCode instr len %Zd\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4652 | pieces.inst_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4653 | memcpy(il->ucode_code.v_addr, pieces.inst, pieces.inst_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4654 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4655 | D_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4656 | il->ucode_code.v_addr, (u32) il->ucode_code.p_addr); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4657 | |
| 4658 | /* |
| 4659 | * Runtime data |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4660 | * NOTE: Copy into backup buffer will be done in il_up() |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4661 | */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4662 | D_INFO("Copying (but not loading) uCode data len %Zd\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4663 | pieces.data_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4664 | memcpy(il->ucode_data.v_addr, pieces.data, pieces.data_size); |
| 4665 | 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] | 4666 | |
| 4667 | /* Initialization instructions */ |
| 4668 | if (pieces.init_size) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4669 | D_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4670 | pieces.init_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4671 | memcpy(il->ucode_init.v_addr, pieces.init, pieces.init_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | /* Initialization data */ |
| 4675 | if (pieces.init_data_size) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4676 | D_INFO("Copying (but not loading) init data len %Zd\n", |
| 4677 | pieces.init_data_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4678 | memcpy(il->ucode_init_data.v_addr, pieces.init_data, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4679 | pieces.init_data_size); |
| 4680 | } |
| 4681 | |
| 4682 | /* Bootstrap instructions */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 4683 | D_INFO("Copying (but not loading) boot instr len %Zd\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4684 | pieces.boot_size); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4685 | memcpy(il->ucode_boot.v_addr, pieces.boot, pieces.boot_size); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4686 | |
| 4687 | /* |
| 4688 | * figure out the offset of chain noise reset and gain commands |
| 4689 | * base on the size of standard phy calibration commands table size |
| 4690 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4691 | il->_4965.phy_calib_chain_noise_reset_cmd = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4692 | standard_phy_calibration_size; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4693 | il->_4965.phy_calib_chain_noise_gain_cmd = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4694 | standard_phy_calibration_size + 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4695 | |
| 4696 | /************************************************** |
| 4697 | * This is still part of probe() in a sense... |
| 4698 | * |
| 4699 | * 9. Setup and register with mac80211 and debugfs |
| 4700 | **************************************************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4701 | err = il4965_mac_setup_register(il, max_probe_length); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4702 | if (err) |
| 4703 | goto out_unbind; |
| 4704 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4705 | err = il_dbgfs_register(il, DRV_NAME); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4706 | if (err) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4707 | IL_ERR("failed to create debugfs files. Ignoring error: %d\n", |
| 4708 | err); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4709 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4710 | 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] | 4711 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4712 | IL_ERR("failed to create sysfs device attributes\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4713 | goto out_unbind; |
| 4714 | } |
| 4715 | |
| 4716 | /* We have our copies now, allow OS release its copies */ |
| 4717 | release_firmware(ucode_raw); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4718 | complete(&il->_4965.firmware_loading_complete); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4719 | return; |
| 4720 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4721 | try_again: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4722 | /* try next, if any */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4723 | if (il4965_request_firmware(il, false)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4724 | goto out_unbind; |
| 4725 | release_firmware(ucode_raw); |
| 4726 | return; |
| 4727 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4728 | err_pci_alloc: |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4729 | IL_ERR("failed to allocate pci memory\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4730 | il4965_dealloc_ucode_pci(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4731 | out_unbind: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4732 | complete(&il->_4965.firmware_loading_complete); |
| 4733 | device_release_driver(&il->pci_dev->dev); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4734 | release_firmware(ucode_raw); |
| 4735 | } |
| 4736 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4737 | static const char *const desc_lookup_text[] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4738 | "OK", |
| 4739 | "FAIL", |
| 4740 | "BAD_PARAM", |
| 4741 | "BAD_CHECKSUM", |
| 4742 | "NMI_INTERRUPT_WDG", |
| 4743 | "SYSASSERT", |
| 4744 | "FATAL_ERROR", |
| 4745 | "BAD_COMMAND", |
| 4746 | "HW_ERROR_TUNE_LOCK", |
| 4747 | "HW_ERROR_TEMPERATURE", |
| 4748 | "ILLEGAL_CHAN_FREQ", |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 4749 | "VCC_NOT_STBL", |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 4750 | "FH49_ERROR", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4751 | "NMI_INTERRUPT_HOST", |
| 4752 | "NMI_INTERRUPT_ACTION_PT", |
| 4753 | "NMI_INTERRUPT_UNKNOWN", |
| 4754 | "UCODE_VERSION_MISMATCH", |
| 4755 | "HW_ERROR_ABS_LOCK", |
| 4756 | "HW_ERROR_CAL_LOCK_FAIL", |
| 4757 | "NMI_INTERRUPT_INST_ACTION_PT", |
| 4758 | "NMI_INTERRUPT_DATA_ACTION_PT", |
| 4759 | "NMI_TRM_HW_ER", |
| 4760 | "NMI_INTERRUPT_TRM", |
Joe Perches | 861d9c3 | 2011-07-08 23:20:24 -0700 | [diff] [blame] | 4761 | "NMI_INTERRUPT_BREAK_POINT", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4762 | "DEBUG_0", |
| 4763 | "DEBUG_1", |
| 4764 | "DEBUG_2", |
| 4765 | "DEBUG_3", |
| 4766 | }; |
| 4767 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4768 | static struct { |
| 4769 | char *name; |
| 4770 | u8 num; |
| 4771 | } advanced_lookup[] = { |
| 4772 | { |
| 4773 | "NMI_INTERRUPT_WDG", 0x34}, { |
| 4774 | "SYSASSERT", 0x35}, { |
| 4775 | "UCODE_VERSION_MISMATCH", 0x37}, { |
| 4776 | "BAD_COMMAND", 0x38}, { |
| 4777 | "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C}, { |
| 4778 | "FATAL_ERROR", 0x3D}, { |
| 4779 | "NMI_TRM_HW_ERR", 0x46}, { |
| 4780 | "NMI_INTERRUPT_TRM", 0x4C}, { |
| 4781 | "NMI_INTERRUPT_BREAK_POINT", 0x54}, { |
| 4782 | "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C}, { |
| 4783 | "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64}, { |
| 4784 | "NMI_INTERRUPT_HOST", 0x66}, { |
| 4785 | "NMI_INTERRUPT_ACTION_PT", 0x7C}, { |
| 4786 | "NMI_INTERRUPT_UNKNOWN", 0x84}, { |
| 4787 | "NMI_INTERRUPT_INST_ACTION_PT", 0x86}, { |
| 4788 | "ADVANCED_SYSASSERT", 0},}; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4789 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4790 | static const char * |
| 4791 | il4965_desc_lookup(u32 num) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4792 | { |
| 4793 | int i; |
| 4794 | int max = ARRAY_SIZE(desc_lookup_text); |
| 4795 | |
| 4796 | if (num < max) |
| 4797 | return desc_lookup_text[num]; |
| 4798 | |
| 4799 | max = ARRAY_SIZE(advanced_lookup) - 1; |
| 4800 | for (i = 0; i < max; i++) { |
| 4801 | if (advanced_lookup[i].num == num) |
| 4802 | break; |
| 4803 | } |
| 4804 | return advanced_lookup[i].name; |
| 4805 | } |
| 4806 | |
| 4807 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4808 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4809 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4810 | void |
| 4811 | il4965_dump_nic_error_log(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4812 | { |
| 4813 | u32 data2, line; |
| 4814 | u32 desc, time, count, base, data1; |
| 4815 | u32 blink1, blink2, ilink1, ilink2; |
| 4816 | u32 pc, hcmd; |
| 4817 | |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 4818 | if (il->ucode_type == UCODE_INIT) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4819 | base = le32_to_cpu(il->card_alive_init.error_event_table_ptr); |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 4820 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4821 | base = le32_to_cpu(il->card_alive.error_event_table_ptr); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4822 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4823 | if (!il->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4824 | IL_ERR("Not valid error log pointer 0x%08X for %s uCode\n", |
| 4825 | base, (il->ucode_type == UCODE_INIT) ? "Init" : "RT"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4826 | return; |
| 4827 | } |
| 4828 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4829 | count = il_read_targ_mem(il, base); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4830 | |
| 4831 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4832 | IL_ERR("Start IWL Error Log Dump:\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4833 | IL_ERR("Status: 0x%08lX, count: %d\n", il->status, count); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4834 | } |
| 4835 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4836 | desc = il_read_targ_mem(il, base + 1 * sizeof(u32)); |
| 4837 | il->isr_stats.err_code = desc; |
| 4838 | pc = il_read_targ_mem(il, base + 2 * sizeof(u32)); |
| 4839 | blink1 = il_read_targ_mem(il, base + 3 * sizeof(u32)); |
| 4840 | blink2 = il_read_targ_mem(il, base + 4 * sizeof(u32)); |
| 4841 | ilink1 = il_read_targ_mem(il, base + 5 * sizeof(u32)); |
| 4842 | ilink2 = il_read_targ_mem(il, base + 6 * sizeof(u32)); |
| 4843 | data1 = il_read_targ_mem(il, base + 7 * sizeof(u32)); |
| 4844 | data2 = il_read_targ_mem(il, base + 8 * sizeof(u32)); |
| 4845 | line = il_read_targ_mem(il, base + 9 * sizeof(u32)); |
| 4846 | time = il_read_targ_mem(il, base + 11 * sizeof(u32)); |
| 4847 | hcmd = il_read_targ_mem(il, base + 22 * sizeof(u32)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4848 | |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4849 | IL_ERR("Desc Time " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4850 | "data1 data2 line\n"); |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4851 | IL_ERR("%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4852 | il4965_desc_lookup(desc), desc, time, data1, data2, line); |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 4853 | IL_ERR("pc blink1 blink2 ilink1 ilink2 hcmd\n"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4854 | IL_ERR("0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n", pc, blink1, |
| 4855 | blink2, ilink1, ilink2, hcmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4856 | } |
| 4857 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4858 | static void |
| 4859 | il4965_rf_kill_ct_config(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4860 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4861 | struct il_ct_kill_config cmd; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4862 | unsigned long flags; |
| 4863 | int ret = 0; |
| 4864 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4865 | spin_lock_irqsave(&il->lock, flags); |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 4866 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4867 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4868 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4869 | |
| 4870 | cmd.critical_temperature_R = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4871 | cpu_to_le32(il->hw_params.ct_kill_threshold); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4872 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4873 | 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] | 4874 | if (ret) |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 4875 | IL_ERR("C_CT_KILL_CONFIG failed\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4876 | else |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4877 | D_INFO("C_CT_KILL_CONFIG " "succeeded, " |
| 4878 | "critical temperature is %d\n", |
| 4879 | il->hw_params.ct_kill_threshold); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | static const s8 default_queue_to_tx_fifo[] = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4883 | IL_TX_FIFO_VO, |
| 4884 | IL_TX_FIFO_VI, |
| 4885 | IL_TX_FIFO_BE, |
| 4886 | IL_TX_FIFO_BK, |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4887 | IL49_CMD_FIFO_NUM, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4888 | IL_TX_FIFO_UNUSED, |
| 4889 | IL_TX_FIFO_UNUSED, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4890 | }; |
| 4891 | |
Stanislaw Gruszka | e53aac4 | 2011-08-31 11:18:16 +0200 | [diff] [blame] | 4892 | #define IL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo)))) |
| 4893 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4894 | static int |
| 4895 | il4965_alive_notify(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4896 | { |
| 4897 | u32 a; |
| 4898 | unsigned long flags; |
| 4899 | int i, chan; |
| 4900 | u32 reg_val; |
| 4901 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4902 | spin_lock_irqsave(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4903 | |
| 4904 | /* Clear 4965's internal Tx Scheduler data base */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4905 | 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] | 4906 | a = il->scd_base_addr + IL49_SCD_CONTEXT_DATA_OFFSET; |
| 4907 | 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] | 4908 | il_write_targ_mem(il, a, 0); |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4909 | 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] | 4910 | il_write_targ_mem(il, a, 0); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4911 | for (; |
| 4912 | a < |
| 4913 | il->scd_base_addr + |
| 4914 | IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(il->hw_params.max_txq_num); |
| 4915 | a += 4) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4916 | il_write_targ_mem(il, a, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4917 | |
| 4918 | /* Tel 4965 where to find Tx byte count tables */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4919 | 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] | 4920 | |
| 4921 | /* Enable DMA channel */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4922 | for (chan = 0; chan < FH49_TCSR_CHNL_NUM; chan++) |
| 4923 | il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(chan), |
| 4924 | FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | |
| 4925 | FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4926 | |
| 4927 | /* Update FH chicken bits */ |
Stanislaw Gruszka | 9a95b37 | 2011-08-31 14:20:23 +0200 | [diff] [blame] | 4928 | reg_val = il_rd(il, FH49_TX_CHICKEN_BITS_REG); |
| 4929 | il_wr(il, FH49_TX_CHICKEN_BITS_REG, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4930 | reg_val | FH49_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4931 | |
| 4932 | /* Disable chain mode for all queues */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4933 | il_wr_prph(il, IL49_SCD_QUEUECHAIN_SEL, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4934 | |
| 4935 | /* Initialize each Tx queue (including the command queue) */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4936 | for (i = 0; i < il->hw_params.max_txq_num; i++) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4937 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 4938 | /* TFD circular buffer read/write idxes */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4939 | il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(i), 0); |
Stanislaw Gruszka | 0c1a94e | 2011-08-24 17:37:16 +0200 | [diff] [blame] | 4940 | il_wr(il, HBUS_TARG_WRPTR, 0 | (i << 8)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4941 | |
| 4942 | /* Max Tx Window size for Scheduler-ACK mode */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4943 | il_write_targ_mem(il, |
| 4944 | il->scd_base_addr + |
| 4945 | IL49_SCD_CONTEXT_QUEUE_OFFSET(i), |
| 4946 | (SCD_WIN_SIZE << |
| 4947 | IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & |
| 4948 | IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4949 | |
| 4950 | /* Frame limit */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4951 | il_write_targ_mem(il, |
| 4952 | il->scd_base_addr + |
| 4953 | IL49_SCD_CONTEXT_QUEUE_OFFSET(i) + |
| 4954 | sizeof(u32), |
| 4955 | (SCD_FRAME_LIMIT << |
| 4956 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & |
| 4957 | IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4958 | |
| 4959 | } |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 4960 | il_wr_prph(il, IL49_SCD_INTERRUPT_MASK, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4961 | (1 << il->hw_params.max_txq_num) - 1); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4962 | |
| 4963 | /* Activate all Tx DMA/FIFO channels */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4964 | il4965_txq_set_sched(il, IL_MASK(0, 6)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4965 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4966 | il4965_set_wr_ptrs(il, IL_DEFAULT_CMD_QUEUE_NUM, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4967 | |
| 4968 | /* make sure all queue are not stopped */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4969 | memset(&il->queue_stopped[0], 0, sizeof(il->queue_stopped)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4970 | for (i = 0; i < 4; i++) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4971 | atomic_set(&il->queue_stop_count[i], 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4972 | |
| 4973 | /* reset to 0 to enable all the queue first */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4974 | il->txq_ctx_active_msk = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4975 | /* Map each Tx/cmd queue to its corresponding fifo */ |
| 4976 | BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7); |
| 4977 | |
| 4978 | for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { |
| 4979 | int ac = default_queue_to_tx_fifo[i]; |
| 4980 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4981 | il_txq_ctx_activate(il, i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4982 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4983 | if (ac == IL_TX_FIFO_UNUSED) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4984 | continue; |
| 4985 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4986 | il4965_tx_queue_set_status(il, &il->txq[i], ac, 0); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4987 | } |
| 4988 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 4989 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4990 | |
| 4991 | return 0; |
| 4992 | } |
| 4993 | |
| 4994 | /** |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 4995 | * il4965_alive_start - called after N_ALIVE notification received |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4996 | * from protocol/runtime uCode (initialization uCode's |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 4997 | * Alive gets handled by il_init_alive_start()). |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 4998 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 4999 | static void |
| 5000 | il4965_alive_start(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5001 | { |
| 5002 | int ret = 0; |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 5003 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5004 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5005 | D_INFO("Runtime Alive received.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5006 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5007 | if (il->card_alive.is_valid != UCODE_VALID_OK) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5008 | /* We had an error bringing up the hardware, so take it |
| 5009 | * all the way back down so we can try again */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5010 | D_INFO("Alive failed.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5011 | goto restart; |
| 5012 | } |
| 5013 | |
| 5014 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 5015 | * This is a paranoid check, because we would not have gotten the |
| 5016 | * "runtime" alive if code weren't properly loaded. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5017 | if (il4965_verify_ucode(il)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5018 | /* Runtime instruction load was bad; |
| 5019 | * take it all the way back down so we can try again */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5020 | D_INFO("Bad runtime uCode load.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5021 | goto restart; |
| 5022 | } |
| 5023 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5024 | ret = il4965_alive_notify(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5025 | if (ret) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5026 | IL_WARN("Could not complete ALIVE transition [ntf]: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5027 | goto restart; |
| 5028 | } |
| 5029 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5030 | /* After the ALIVE response, we can send host commands to the uCode */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5031 | set_bit(S_ALIVE, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5032 | |
| 5033 | /* Enable watchdog to monitor the driver tx queues */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5034 | il_setup_watchdog(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5035 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5036 | if (il_is_rfkill(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5037 | return; |
| 5038 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5039 | ieee80211_wake_queues(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5040 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 5041 | il->active_rate = RATES_MASK; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5042 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5043 | if (il_is_associated_ctx(ctx)) { |
| 5044 | struct il_rxon_cmd *active_rxon = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5045 | (struct il_rxon_cmd *)&ctx->active; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5046 | /* apply any changes in staging */ |
| 5047 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 5048 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5049 | } else { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5050 | /* Initialize our rx_config data */ |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5051 | il_connection_init_rx_config(il, &il->ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5052 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5053 | if (il->cfg->ops->hcmd->set_rxon_chain) |
| 5054 | il->cfg->ops->hcmd->set_rxon_chain(il, ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | /* Configure bluetooth coexistence if enabled */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5058 | il_send_bt_config(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5059 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5060 | il4965_reset_run_time_calib(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5061 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5062 | set_bit(S_READY, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5063 | |
| 5064 | /* Configure the adapter for unassociated operation */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5065 | il_commit_rxon(il, ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5066 | |
| 5067 | /* At this point, the NIC is initialized and operational */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5068 | il4965_rf_kill_ct_config(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5069 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5070 | D_INFO("ALIVE processing complete.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5071 | wake_up(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5072 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5073 | il_power_update_mode(il, true); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5074 | D_INFO("Updated power mode\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5075 | |
| 5076 | return; |
| 5077 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5078 | restart: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5079 | queue_work(il->workqueue, &il->restart); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5080 | } |
| 5081 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5082 | static void il4965_cancel_deferred_work(struct il_priv *il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5083 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5084 | static void |
| 5085 | __il4965_down(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5086 | { |
| 5087 | unsigned long flags; |
Stanislaw Gruszka | ab42b40 | 2011-04-28 11:51:24 +0200 | [diff] [blame] | 5088 | int exit_pending; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5089 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5090 | D_INFO(DRV_NAME " is going down\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5091 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5092 | il_scan_cancel_timeout(il, 200); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5093 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5094 | exit_pending = test_and_set_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5095 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5096 | /* 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] | 5097 | * to prevent rearm timer */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5098 | del_timer_sync(&il->watchdog); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5099 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5100 | il_clear_ucode_stations(il, NULL); |
| 5101 | il_dealloc_bcast_stations(il); |
| 5102 | il_clear_driver_stations(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5103 | |
| 5104 | /* Unblock any waiting calls */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5105 | wake_up_all(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5106 | |
| 5107 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5108 | * exiting the module */ |
| 5109 | if (!exit_pending) |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5110 | clear_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5111 | |
| 5112 | /* stop and reset the on-board processor */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5113 | _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5114 | |
| 5115 | /* tell the device to stop sending interrupts */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5116 | spin_lock_irqsave(&il->lock, flags); |
| 5117 | il_disable_interrupts(il); |
| 5118 | spin_unlock_irqrestore(&il->lock, flags); |
| 5119 | il4965_synchronize_irq(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5120 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5121 | if (il->mac80211_registered) |
| 5122 | ieee80211_stop_queues(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5123 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5124 | /* If we have not previously called il_init() then |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5125 | * clear all bits but the RF Kill bit and return */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5126 | if (!il_is_init(il)) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5127 | il->status = |
| 5128 | test_bit(S_RF_KILL_HW, |
| 5129 | &il-> |
| 5130 | status) << S_RF_KILL_HW | |
| 5131 | test_bit(S_GEO_CONFIGURED, |
| 5132 | &il-> |
| 5133 | status) << S_GEO_CONFIGURED | |
| 5134 | test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5135 | goto exit; |
| 5136 | } |
| 5137 | |
| 5138 | /* ...otherwise clear out all the status bits but the RF Kill |
| 5139 | * bit and continue taking the NIC down. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5140 | il->status &= |
| 5141 | test_bit(S_RF_KILL_HW, |
| 5142 | &il->status) << S_RF_KILL_HW | test_bit(S_GEO_CONFIGURED, |
| 5143 | &il-> |
| 5144 | status) << |
| 5145 | S_GEO_CONFIGURED | test_bit(S_FW_ERROR, |
| 5146 | &il-> |
| 5147 | status) << S_FW_ERROR | |
| 5148 | test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5149 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5150 | il4965_txq_ctx_stop(il); |
| 5151 | il4965_rxq_stop(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5152 | |
| 5153 | /* Power-down device's busmaster DMA clocks */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 5154 | 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] | 5155 | udelay(5); |
| 5156 | |
| 5157 | /* Make sure (redundant) we've released our request to stay awake */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5158 | 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] | 5159 | |
| 5160 | /* Stop the device, and put it in low power state */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5161 | il_apm_stop(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5162 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5163 | exit: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5164 | memset(&il->card_alive, 0, sizeof(struct il_alive_resp)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5165 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5166 | dev_kfree_skb(il->beacon_skb); |
| 5167 | il->beacon_skb = NULL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5168 | |
| 5169 | /* clear out any free frames */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5170 | il4965_clear_free_frames(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5173 | static void |
| 5174 | il4965_down(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5175 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5176 | mutex_lock(&il->mutex); |
| 5177 | __il4965_down(il); |
| 5178 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5179 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5180 | il4965_cancel_deferred_work(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | #define HW_READY_TIMEOUT (50) |
| 5184 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5185 | static int |
| 5186 | il4965_set_hw_ready(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5187 | { |
| 5188 | int ret = 0; |
| 5189 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5190 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5191 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5192 | |
| 5193 | /* See if we got it */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5194 | ret = |
| 5195 | _il_poll_bit(il, CSR_HW_IF_CONFIG_REG, |
| 5196 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, |
| 5197 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, HW_READY_TIMEOUT); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5198 | if (ret != -ETIMEDOUT) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5199 | il->hw_ready = true; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5200 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5201 | il->hw_ready = false; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5202 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5203 | 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] | 5204 | return ret; |
| 5205 | } |
| 5206 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5207 | static int |
| 5208 | il4965_prepare_card_hw(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5209 | { |
| 5210 | int ret = 0; |
| 5211 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5212 | D_INFO("il4965_prepare_card_hw enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5213 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5214 | ret = il4965_set_hw_ready(il); |
| 5215 | if (il->hw_ready) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5216 | return ret; |
| 5217 | |
| 5218 | /* If HW is not ready, prepare the conditions to check again */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5219 | 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] | 5220 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5221 | ret = |
| 5222 | _il_poll_bit(il, CSR_HW_IF_CONFIG_REG, |
| 5223 | ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, |
| 5224 | CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5225 | |
| 5226 | /* HW should be ready by now, check again. */ |
| 5227 | if (ret != -ETIMEDOUT) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5228 | il4965_set_hw_ready(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5229 | |
| 5230 | return ret; |
| 5231 | } |
| 5232 | |
| 5233 | #define MAX_HW_RESTARTS 5 |
| 5234 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5235 | static int |
| 5236 | __il4965_up(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5237 | { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5238 | int i; |
| 5239 | int ret; |
| 5240 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5241 | if (test_bit(S_EXIT_PENDING, &il->status)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5242 | IL_WARN("Exit pending; will not bring the NIC up\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5243 | return -EIO; |
| 5244 | } |
| 5245 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5246 | if (!il->ucode_data_backup.v_addr || !il->ucode_data.v_addr) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5247 | IL_ERR("ucode not available for device bringup\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5248 | return -EIO; |
| 5249 | } |
| 5250 | |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5251 | ret = il4965_alloc_bcast_station(il, &il->ctx); |
| 5252 | if (ret) { |
| 5253 | il_dealloc_bcast_stations(il); |
| 5254 | return ret; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5255 | } |
| 5256 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5257 | il4965_prepare_card_hw(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5258 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5259 | if (!il->hw_ready) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5260 | IL_WARN("Exit HW not ready\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5261 | return -EIO; |
| 5262 | } |
| 5263 | |
| 5264 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5265 | 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] | 5266 | clear_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5267 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5268 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5269 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5270 | if (il_is_rfkill(il)) { |
| 5271 | wiphy_rfkill_set_hw_state(il->hw->wiphy, true); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5272 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5273 | il_enable_interrupts(il); |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5274 | IL_WARN("Radio disabled by HW RF Kill switch\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5275 | return 0; |
| 5276 | } |
| 5277 | |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5278 | _il_wr(il, CSR_INT, 0xFFFFFFFF); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5279 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5280 | /* must be initialised before il_hw_nic_init */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5281 | il->cmd_queue = IL_DEFAULT_CMD_QUEUE_NUM; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5282 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5283 | ret = il4965_hw_nic_init(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5284 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5285 | IL_ERR("Unable to init nic\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5286 | return ret; |
| 5287 | } |
| 5288 | |
| 5289 | /* make sure rfkill handshake bits are cleared */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5290 | _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] | 5291 | _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] | 5292 | |
| 5293 | /* clear (again), then enable host interrupts */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5294 | _il_wr(il, CSR_INT, 0xFFFFFFFF); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5295 | il_enable_interrupts(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5296 | |
| 5297 | /* really make sure rfkill handshake bits are cleared */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5298 | _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5299 | _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] | 5300 | |
| 5301 | /* Copy original ucode data image from disk into backup cache. |
| 5302 | * This will be used to initialize the on-board processor's |
| 5303 | * data SRAM for a clean start when the runtime program first loads. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5304 | memcpy(il->ucode_data_backup.v_addr, il->ucode_data.v_addr, |
| 5305 | il->ucode_data.len); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5306 | |
| 5307 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5308 | |
| 5309 | /* load bootstrap state machine, |
| 5310 | * load bootstrap program into processor's memory, |
| 5311 | * prepare to load the "initialize" uCode */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5312 | ret = il->cfg->ops->lib->load_ucode(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5313 | |
| 5314 | if (ret) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5315 | IL_ERR("Unable to set up bootstrap uCode: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5316 | continue; |
| 5317 | } |
| 5318 | |
| 5319 | /* start card; "initialize" will load runtime ucode */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5320 | il4965_nic_start(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5321 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5322 | D_INFO(DRV_NAME " is coming up\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5323 | |
| 5324 | return 0; |
| 5325 | } |
| 5326 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5327 | set_bit(S_EXIT_PENDING, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5328 | __il4965_down(il); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5329 | clear_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5330 | |
| 5331 | /* tried to restart and config the device for as long as our |
| 5332 | * patience could withstand */ |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5333 | IL_ERR("Unable to initialize device after %d attempts.\n", i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5334 | return -EIO; |
| 5335 | } |
| 5336 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5337 | /***************************************************************************** |
| 5338 | * |
| 5339 | * Workqueue callbacks |
| 5340 | * |
| 5341 | *****************************************************************************/ |
| 5342 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5343 | static void |
| 5344 | il4965_bg_init_alive_start(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5345 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5346 | struct il_priv *il = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5347 | container_of(data, struct il_priv, init_alive_start.work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5348 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5349 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5350 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5351 | goto out; |
| 5352 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5353 | il->cfg->ops->lib->init_alive_start(il); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5354 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5355 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5356 | } |
| 5357 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5358 | static void |
| 5359 | il4965_bg_alive_start(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5360 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5361 | struct il_priv *il = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5362 | container_of(data, struct il_priv, alive_start.work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5363 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5364 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5365 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5366 | goto out; |
| 5367 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5368 | il4965_alive_start(il); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5369 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5370 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5371 | } |
| 5372 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5373 | static void |
| 5374 | il4965_bg_run_time_calib_work(struct work_struct *work) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5375 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5376 | struct il_priv *il = container_of(work, struct il_priv, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5377 | run_time_calib_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5378 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5379 | mutex_lock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5380 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5381 | if (test_bit(S_EXIT_PENDING, &il->status) || |
| 5382 | test_bit(S_SCANNING, &il->status)) { |
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 | return; |
| 5385 | } |
| 5386 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5387 | if (il->start_calib) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5388 | il4965_chain_noise_calibration(il, (void *)&il->_4965.stats); |
| 5389 | il4965_sensitivity_calibration(il, (void *)&il->_4965.stats); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5390 | } |
| 5391 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5392 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5393 | } |
| 5394 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5395 | static void |
| 5396 | il4965_bg_restart(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5397 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5398 | struct il_priv *il = container_of(data, struct il_priv, restart); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5399 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5400 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5401 | return; |
| 5402 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5403 | if (test_and_clear_bit(S_FW_ERROR, &il->status)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5404 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5405 | il->ctx.vif = NULL; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5406 | il->is_open = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5407 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5408 | __il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5409 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5410 | mutex_unlock(&il->mutex); |
| 5411 | il4965_cancel_deferred_work(il); |
| 5412 | ieee80211_restart_hw(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5413 | } else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5414 | il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5415 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5416 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5417 | if (test_bit(S_EXIT_PENDING, &il->status)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5418 | mutex_unlock(&il->mutex); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5419 | return; |
| 5420 | } |
| 5421 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5422 | __il4965_up(il); |
| 5423 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5424 | } |
| 5425 | } |
| 5426 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5427 | static void |
| 5428 | il4965_bg_rx_replenish(struct work_struct *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5429 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5430 | 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] | 5431 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5432 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5433 | return; |
| 5434 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5435 | mutex_lock(&il->mutex); |
| 5436 | il4965_rx_replenish(il); |
| 5437 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | /***************************************************************************** |
| 5441 | * |
| 5442 | * mac80211 entry point functions |
| 5443 | * |
| 5444 | *****************************************************************************/ |
| 5445 | |
| 5446 | #define UCODE_READY_TIMEOUT (4 * HZ) |
| 5447 | |
| 5448 | /* |
| 5449 | * Not a mac80211 entry point function, but it fits in with all the |
| 5450 | * other mac80211 functions grouped here. |
| 5451 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5452 | static int |
| 5453 | 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] | 5454 | { |
| 5455 | int ret; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5456 | struct ieee80211_hw *hw = il->hw; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5457 | |
| 5458 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 5459 | |
| 5460 | /* Tell mac80211 our characteristics */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5461 | hw->flags = |
| 5462 | IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_AMPDU_AGGREGATION | |
| 5463 | IEEE80211_HW_NEED_DTIM_PERIOD | IEEE80211_HW_SPECTRUM_MGMT | |
| 5464 | IEEE80211_HW_REPORTS_TX_ACK_STATUS; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5465 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5466 | if (il->cfg->sku & IL_SKU_N) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5467 | hw->flags |= |
| 5468 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | |
| 5469 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5470 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5471 | hw->sta_data_size = sizeof(struct il_station_priv); |
| 5472 | hw->vif_data_size = sizeof(struct il_vif_priv); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5473 | |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5474 | hw->wiphy->interface_modes |= il->ctx.interface_modes; |
| 5475 | hw->wiphy->interface_modes |= il->ctx.exclusive_interface_modes; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5476 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5477 | hw->wiphy->flags |= |
| 5478 | WIPHY_FLAG_CUSTOM_REGULATORY | WIPHY_FLAG_DISABLE_BEACON_HINTS; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5479 | |
| 5480 | /* |
| 5481 | * For now, disable PS by default because it affects |
| 5482 | * RX performance significantly. |
| 5483 | */ |
| 5484 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
| 5485 | |
| 5486 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
| 5487 | /* we create the 802.11 header and a zero-length SSID element */ |
| 5488 | hw->wiphy->max_scan_ie_len = max_probe_length - 24 - 2; |
| 5489 | |
| 5490 | /* Default value; 4 EDCA QOS priorities */ |
| 5491 | hw->queues = 4; |
| 5492 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5493 | hw->max_listen_interval = IL_CONN_MAX_LISTEN_INTERVAL; |
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 | if (il->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 5496 | il->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5497 | &il->bands[IEEE80211_BAND_2GHZ]; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5498 | if (il->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 5499 | il->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5500 | &il->bands[IEEE80211_BAND_5GHZ]; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5501 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5502 | il_leds_init(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5503 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5504 | ret = ieee80211_register_hw(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5505 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5506 | IL_ERR("Failed to register hw (error %d)\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5507 | return ret; |
| 5508 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5509 | il->mac80211_registered = 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5510 | |
| 5511 | return 0; |
| 5512 | } |
| 5513 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5514 | int |
| 5515 | il4965_mac_start(struct ieee80211_hw *hw) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5516 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5517 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5518 | int ret; |
| 5519 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5520 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5521 | |
| 5522 | /* we should be verifying the device is ready to be opened */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5523 | mutex_lock(&il->mutex); |
| 5524 | ret = __il4965_up(il); |
| 5525 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5526 | |
| 5527 | if (ret) |
| 5528 | return ret; |
| 5529 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5530 | if (il_is_rfkill(il)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5531 | goto out; |
| 5532 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5533 | D_INFO("Start UP work done.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5534 | |
| 5535 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
| 5536 | * mac80211 will not be run successfully. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5537 | ret = wait_event_timeout(il->wait_command_queue, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5538 | test_bit(S_READY, &il->status), |
| 5539 | UCODE_READY_TIMEOUT); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5540 | if (!ret) { |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5541 | if (!test_bit(S_READY, &il->status)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 5542 | IL_ERR("START_ALIVE timeout after %dms.\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5543 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 5544 | return -ETIMEDOUT; |
| 5545 | } |
| 5546 | } |
| 5547 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5548 | il4965_led_enable(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5549 | |
| 5550 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5551 | il->is_open = 1; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5552 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5553 | return 0; |
| 5554 | } |
| 5555 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5556 | void |
| 5557 | il4965_mac_stop(struct ieee80211_hw *hw) |
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 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5560 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5561 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5562 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5563 | if (!il->is_open) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5564 | return; |
| 5565 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5566 | il->is_open = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5567 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5568 | il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5569 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5570 | flush_workqueue(il->workqueue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5571 | |
Stanislaw Gruszka | a078a1f | 2011-04-28 11:51:25 +0200 | [diff] [blame] | 5572 | /* User space software may expect getting rfkill changes |
| 5573 | * even if interface is down */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 5574 | _il_wr(il, CSR_INT, 0xFFFFFFFF); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5575 | il_enable_rfkill_int(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5576 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5577 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5578 | } |
| 5579 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5580 | void |
| 5581 | il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5582 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5583 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5584 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5585 | D_MACDUMP("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5586 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5587 | 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] | 5588 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5589 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5590 | if (il4965_tx_skb(il, skb)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5591 | dev_kfree_skb_any(skb); |
| 5592 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5593 | D_MACDUMP("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5596 | void |
| 5597 | il4965_mac_update_tkip_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5598 | struct ieee80211_key_conf *keyconf, |
| 5599 | struct ieee80211_sta *sta, u32 iv32, u16 * phase1key) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5600 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5601 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5602 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5603 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5604 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5605 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5606 | il4965_update_tkip_key(il, vif_priv->ctx, keyconf, sta, iv32, |
| 5607 | phase1key); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5608 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5609 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5610 | } |
| 5611 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5612 | int |
| 5613 | il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 5614 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 5615 | struct ieee80211_key_conf *key) |
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 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5618 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 5619 | struct il_rxon_context *ctx = vif_priv->ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5620 | int ret; |
| 5621 | u8 sta_id; |
| 5622 | bool is_default_wep_key = false; |
| 5623 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5624 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5625 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5626 | if (il->cfg->mod_params->sw_crypto) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5627 | D_MAC80211("leave - hwcrypto disabled\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5628 | return -EOPNOTSUPP; |
| 5629 | } |
| 5630 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5631 | sta_id = il_sta_id_or_broadcast(il, vif_priv->ctx, sta); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5632 | if (sta_id == IL_INVALID_STATION) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5633 | return -EINVAL; |
| 5634 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5635 | mutex_lock(&il->mutex); |
| 5636 | il_scan_cancel_timeout(il, 100); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5637 | |
| 5638 | /* |
| 5639 | * If we are getting WEP group key and we didn't receive any key mapping |
| 5640 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 5641 | * in 1X mode. |
| 5642 | * In legacy wep mode, we use another host command to the uCode. |
| 5643 | */ |
| 5644 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5645 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5646 | if (cmd == SET_KEY) |
| 5647 | is_default_wep_key = !ctx->key_mapping_keys; |
| 5648 | else |
| 5649 | is_default_wep_key = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5650 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | switch (cmd) { |
| 5654 | case SET_KEY: |
| 5655 | if (is_default_wep_key) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5656 | ret = |
| 5657 | il4965_set_default_wep_key(il, vif_priv->ctx, key); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5658 | else |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5659 | ret = |
| 5660 | il4965_set_dynamic_key(il, vif_priv->ctx, key, |
| 5661 | sta_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5662 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5663 | D_MAC80211("enable hwcrypto key\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5664 | break; |
| 5665 | case DISABLE_KEY: |
| 5666 | if (is_default_wep_key) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5667 | ret = il4965_remove_default_wep_key(il, ctx, key); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5668 | else |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5669 | ret = il4965_remove_dynamic_key(il, ctx, key, sta_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5670 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5671 | D_MAC80211("disable hwcrypto key\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5672 | break; |
| 5673 | default: |
| 5674 | ret = -EINVAL; |
| 5675 | } |
| 5676 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5677 | mutex_unlock(&il->mutex); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5678 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5679 | |
| 5680 | return ret; |
| 5681 | } |
| 5682 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5683 | int |
| 5684 | il4965_mac_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5685 | enum ieee80211_ampdu_mlme_action action, |
| 5686 | struct ieee80211_sta *sta, u16 tid, u16 * ssn, |
| 5687 | u8 buf_size) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5688 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5689 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5690 | int ret = -EINVAL; |
| 5691 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5692 | 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] | 5693 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5694 | if (!(il->cfg->sku & IL_SKU_N)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5695 | return -EACCES; |
| 5696 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5697 | mutex_lock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5698 | |
| 5699 | switch (action) { |
| 5700 | case IEEE80211_AMPDU_RX_START: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5701 | D_HT("start Rx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5702 | ret = il4965_sta_rx_agg_start(il, sta, tid, *ssn); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5703 | break; |
| 5704 | case IEEE80211_AMPDU_RX_STOP: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5705 | D_HT("stop Rx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5706 | ret = il4965_sta_rx_agg_stop(il, sta, tid); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5707 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5708 | ret = 0; |
| 5709 | break; |
| 5710 | case IEEE80211_AMPDU_TX_START: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5711 | D_HT("start Tx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5712 | ret = il4965_tx_agg_start(il, vif, sta, tid, ssn); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5713 | break; |
| 5714 | case IEEE80211_AMPDU_TX_STOP: |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5715 | D_HT("stop Tx\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5716 | ret = il4965_tx_agg_stop(il, vif, sta, tid); |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5717 | if (test_bit(S_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5718 | ret = 0; |
| 5719 | break; |
| 5720 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 5721 | ret = 0; |
| 5722 | break; |
| 5723 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5724 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5725 | |
| 5726 | return ret; |
| 5727 | } |
| 5728 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5729 | int |
| 5730 | il4965_mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5731 | struct ieee80211_sta *sta) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5732 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5733 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5734 | struct il_station_priv *sta_priv = (void *)sta->drv_priv; |
| 5735 | struct il_vif_priv *vif_priv = (void *)vif->drv_priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5736 | bool is_ap = vif->type == NL80211_IFTYPE_STATION; |
| 5737 | int ret; |
| 5738 | u8 sta_id; |
| 5739 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5740 | D_INFO("received request to add station %pM\n", sta->addr); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5741 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5742 | D_INFO("proceeding to add station %pM\n", sta->addr); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5743 | sta_priv->common.sta_id = IL_INVALID_STATION; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5744 | |
| 5745 | atomic_set(&sta_priv->pending_frames, 0); |
| 5746 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5747 | ret = |
| 5748 | il_add_station_common(il, vif_priv->ctx, sta->addr, is_ap, sta, |
| 5749 | &sta_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5750 | if (ret) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5751 | 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] | 5752 | /* Should we return success if return code is EEXIST ? */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5753 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5754 | return ret; |
| 5755 | } |
| 5756 | |
| 5757 | sta_priv->common.sta_id = sta_id; |
| 5758 | |
| 5759 | /* Initialize rate scaling */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5760 | D_INFO("Initializing rate scaling for station %pM\n", sta->addr); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5761 | il4965_rs_rate_init(il, sta, sta_id); |
| 5762 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5763 | |
| 5764 | return 0; |
| 5765 | } |
| 5766 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5767 | void |
| 5768 | il4965_mac_channel_switch(struct ieee80211_hw *hw, |
| 5769 | struct ieee80211_channel_switch *ch_switch) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5770 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5771 | struct il_priv *il = hw->priv; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5772 | const struct il_channel_info *ch_info; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5773 | struct ieee80211_conf *conf = &hw->conf; |
| 5774 | struct ieee80211_channel *channel = ch_switch->channel; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5775 | struct il_ht_config *ht_conf = &il->current_ht_config; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5776 | |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 5777 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5778 | u16 ch; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5779 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5780 | D_MAC80211("enter\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5781 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5782 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5783 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5784 | if (il_is_rfkill(il)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5785 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5786 | |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5787 | if (test_bit(S_EXIT_PENDING, &il->status) || |
| 5788 | test_bit(S_SCANNING, &il->status) || |
| 5789 | test_bit(S_CHANNEL_SWITCH_PENDING, &il->status)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5790 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5791 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5792 | if (!il_is_associated_ctx(ctx)) |
Stanislaw Gruszka | 28a6e57 | 2011-04-28 11:51:32 +0200 | [diff] [blame] | 5793 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5794 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5795 | if (!il->cfg->ops->lib->set_channel_switch) |
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 | ch = channel->hw_value; |
| 5799 | if (le16_to_cpu(ctx->active.channel) == ch) |
| 5800 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5801 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5802 | ch_info = il_get_channel_info(il, channel->band, ch); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5803 | if (!il_is_channel_valid(ch_info)) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5804 | D_MAC80211("invalid channel\n"); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5805 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5806 | } |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5807 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5808 | spin_lock_irq(&il->lock); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5809 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5810 | il->current_ht_config.smps = conf->smps_mode; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5811 | |
| 5812 | /* Configure HT40 channels */ |
| 5813 | ctx->ht.enabled = conf_is_ht(conf); |
| 5814 | if (ctx->ht.enabled) { |
| 5815 | if (conf_is_ht40_minus(conf)) { |
| 5816 | ctx->ht.extension_chan_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5817 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5818 | ctx->ht.is_40mhz = true; |
| 5819 | } else if (conf_is_ht40_plus(conf)) { |
| 5820 | ctx->ht.extension_chan_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5821 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5822 | ctx->ht.is_40mhz = true; |
| 5823 | } else { |
| 5824 | ctx->ht.extension_chan_offset = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5825 | IEEE80211_HT_PARAM_CHA_SEC_NONE; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5826 | ctx->ht.is_40mhz = false; |
| 5827 | } |
| 5828 | } else |
| 5829 | ctx->ht.is_40mhz = false; |
| 5830 | |
| 5831 | if ((le16_to_cpu(ctx->staging.channel) != ch)) |
| 5832 | ctx->staging.flags = 0; |
| 5833 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5834 | il_set_rxon_channel(il, channel, ctx); |
| 5835 | il_set_rxon_ht(il, ht_conf); |
| 5836 | il_set_flags_for_band(il, ctx, channel->band, ctx->vif); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5837 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5838 | spin_unlock_irq(&il->lock); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5839 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5840 | il_set_rate(il); |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5841 | /* |
| 5842 | * at this point, staging_rxon has the |
| 5843 | * configuration for channel switch |
| 5844 | */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5845 | set_bit(S_CHANNEL_SWITCH_PENDING, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5846 | il->switch_channel = cpu_to_le16(ch); |
| 5847 | if (il->cfg->ops->lib->set_channel_switch(il, ch_switch)) { |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5848 | clear_bit(S_CHANNEL_SWITCH_PENDING, &il->status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5849 | il->switch_channel = 0; |
Stanislaw Gruszka | 7f1f974 | 2011-06-08 15:28:29 +0200 | [diff] [blame] | 5850 | ieee80211_chswitch_done(ctx->vif, false); |
| 5851 | } |
| 5852 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5853 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5854 | mutex_unlock(&il->mutex); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 5855 | D_MAC80211("leave\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5856 | } |
| 5857 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5858 | void |
| 5859 | il4965_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, |
| 5860 | unsigned int *total_flags, u64 multicast) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5861 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5862 | struct il_priv *il = hw->priv; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5863 | __le32 filter_or = 0, filter_nand = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5864 | |
| 5865 | #define CHK(test, flag) do { \ |
| 5866 | if (*total_flags & (test)) \ |
| 5867 | filter_or |= (flag); \ |
| 5868 | else \ |
| 5869 | filter_nand |= (flag); \ |
| 5870 | } while (0) |
| 5871 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5872 | D_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", changed_flags, |
| 5873 | *total_flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5874 | |
| 5875 | CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK); |
| 5876 | /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */ |
| 5877 | CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK); |
| 5878 | CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK); |
| 5879 | |
| 5880 | #undef CHK |
| 5881 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5882 | mutex_lock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5883 | |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5884 | il->ctx.staging.filter_flags &= ~filter_nand; |
| 5885 | il->ctx.staging.filter_flags |= filter_or; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5886 | |
Stanislaw Gruszka | 17d6e55 | 2011-08-29 12:52:20 +0200 | [diff] [blame] | 5887 | /* |
| 5888 | * Not committing directly because hardware can perform a scan, |
| 5889 | * but we'll eventually commit the filter flags change anyway. |
| 5890 | */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5891 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5892 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5893 | |
| 5894 | /* |
| 5895 | * Receiving all multicast frames is always enabled by the |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5896 | * default flags setup in il_connection_init_rx_config() |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5897 | * since we currently do not support programming multicast |
| 5898 | * filters into the device. |
| 5899 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5900 | *total_flags &= |
| 5901 | FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
| 5902 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | /***************************************************************************** |
| 5906 | * |
| 5907 | * driver setup and teardown |
| 5908 | * |
| 5909 | *****************************************************************************/ |
| 5910 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5911 | static void |
| 5912 | il4965_bg_txpower_work(struct work_struct *work) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5913 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5914 | struct il_priv *il = container_of(work, struct il_priv, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5915 | txpower_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5916 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5917 | mutex_lock(&il->mutex); |
Stanislaw Gruszka | f325757 | 2011-04-28 11:36:54 +0200 | [diff] [blame] | 5918 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5919 | /* If a scan happened to start before we got here |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 5920 | * then just return; the stats notification will |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5921 | * kick off another scheduled work to compensate for |
| 5922 | * any temperature delta we missed here. */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 5923 | if (test_bit(S_EXIT_PENDING, &il->status) || |
| 5924 | test_bit(S_SCANNING, &il->status)) |
Stanislaw Gruszka | f325757 | 2011-04-28 11:36:54 +0200 | [diff] [blame] | 5925 | goto out; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5926 | |
| 5927 | /* Regardless of if we are associated, we must reconfigure the |
| 5928 | * TX power since frames can be sent on non-radar channels while |
| 5929 | * not associated */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5930 | il->cfg->ops->lib->send_tx_power(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5931 | |
| 5932 | /* Update last_temperature to keep is_calib_needed from running |
| 5933 | * when it isn't needed... */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5934 | il->last_temperature = il->temperature; |
Stanislaw Gruszka | f325757 | 2011-04-28 11:36:54 +0200 | [diff] [blame] | 5935 | out: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5936 | mutex_unlock(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5937 | } |
| 5938 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5939 | static void |
| 5940 | il4965_setup_deferred_work(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5941 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5942 | il->workqueue = create_singlethread_workqueue(DRV_NAME); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5943 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5944 | init_waitqueue_head(&il->wait_command_queue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5945 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5946 | INIT_WORK(&il->restart, il4965_bg_restart); |
| 5947 | INIT_WORK(&il->rx_replenish, il4965_bg_rx_replenish); |
| 5948 | INIT_WORK(&il->run_time_calib_work, il4965_bg_run_time_calib_work); |
| 5949 | INIT_DELAYED_WORK(&il->init_alive_start, il4965_bg_init_alive_start); |
| 5950 | INIT_DELAYED_WORK(&il->alive_start, il4965_bg_alive_start); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5951 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5952 | il_setup_scan_deferred_work(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5953 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5954 | INIT_WORK(&il->txpower_work, il4965_bg_txpower_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5955 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 5956 | init_timer(&il->stats_periodic); |
| 5957 | il->stats_periodic.data = (unsigned long)il; |
| 5958 | il->stats_periodic.function = il4965_bg_stats_periodic; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5959 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5960 | init_timer(&il->watchdog); |
| 5961 | il->watchdog.data = (unsigned long)il; |
| 5962 | il->watchdog.function = il_bg_watchdog; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5963 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5964 | tasklet_init(&il->irq_tasklet, |
| 5965 | (void (*)(unsigned long))il4965_irq_tasklet, |
| 5966 | (unsigned long)il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5967 | } |
| 5968 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5969 | static void |
| 5970 | il4965_cancel_deferred_work(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5971 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5972 | cancel_work_sync(&il->txpower_work); |
| 5973 | cancel_delayed_work_sync(&il->init_alive_start); |
| 5974 | cancel_delayed_work(&il->alive_start); |
| 5975 | cancel_work_sync(&il->run_time_calib_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5976 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 5977 | il_cancel_scan_deferred_work(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5978 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 5979 | del_timer_sync(&il->stats_periodic); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5980 | } |
| 5981 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5982 | static void |
| 5983 | 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] | 5984 | { |
| 5985 | int i; |
| 5986 | |
Stanislaw Gruszka | 2eb0581 | 2011-08-26 16:07:43 +0200 | [diff] [blame] | 5987 | for (i = 0; i < RATE_COUNT_LEGACY; i++) { |
Stanislaw Gruszka | d2ddf62 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 5988 | rates[i].bitrate = il_rates[i].ieee * 5; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5989 | rates[i].hw_value = i; /* Rate scaling will work on idxes */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5990 | rates[i].hw_value_short = i; |
| 5991 | rates[i].flags = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 5992 | if ((i >= IL_FIRST_CCK_RATE) && (i <= IL_LAST_CCK_RATE)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5993 | /* |
| 5994 | * If CCK != 1M then set short preamble rate flag. |
| 5995 | */ |
| 5996 | rates[i].flags |= |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 5997 | (il_rates[i].plcp == |
| 5998 | RATE_1M_PLCP) ? 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 5999 | } |
| 6000 | } |
| 6001 | } |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6002 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6003 | /* |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6004 | * Acquire il->lock before calling this function ! |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6005 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6006 | void |
| 6007 | 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] | 6008 | { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6009 | il_wr(il, HBUS_TARG_WRPTR, (idx & 0xff) | (txq_id << 8)); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 6010 | il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(txq_id), idx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6011 | } |
| 6012 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6013 | void |
| 6014 | il4965_tx_queue_set_status(struct il_priv *il, struct il_tx_queue *txq, |
| 6015 | int tx_fifo_id, int scd_retry) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6016 | { |
| 6017 | int txq_id = txq->q.id; |
| 6018 | |
| 6019 | /* Find out whether to activate Tx queue */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6020 | 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] | 6021 | |
| 6022 | /* Set up and activate */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 6023 | il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 6024 | (active << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) | |
| 6025 | (tx_fifo_id << IL49_SCD_QUEUE_STTS_REG_POS_TXF) | |
| 6026 | (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_WSL) | |
| 6027 | (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) | |
| 6028 | IL49_SCD_QUEUE_STTS_REG_MSK); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6029 | |
| 6030 | txq->sched_retry = scd_retry; |
| 6031 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6032 | D_INFO("%s %s Queue %d on AC %d\n", active ? "Activate" : "Deactivate", |
| 6033 | scd_retry ? "BA" : "AC", txq_id, tx_fifo_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6034 | } |
| 6035 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6036 | static int |
| 6037 | il4965_init_drv(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6038 | { |
| 6039 | int ret; |
| 6040 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6041 | spin_lock_init(&il->sta_lock); |
| 6042 | spin_lock_init(&il->hcmd_lock); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6043 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6044 | INIT_LIST_HEAD(&il->free_frames); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6045 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6046 | mutex_init(&il->mutex); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6047 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6048 | il->ieee_channels = NULL; |
| 6049 | il->ieee_rates = NULL; |
| 6050 | il->band = IEEE80211_BAND_2GHZ; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6051 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6052 | il->iw_mode = NL80211_IFTYPE_STATION; |
| 6053 | il->current_ht_config.smps = IEEE80211_SMPS_STATIC; |
| 6054 | il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6055 | |
| 6056 | /* initialize force reset */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6057 | il->force_reset.reset_duration = IL_DELAY_NEXT_FORCE_FW_RELOAD; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6058 | |
| 6059 | /* Choose which receivers/antennas to use */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6060 | if (il->cfg->ops->hcmd->set_rxon_chain) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6061 | il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6062 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6063 | il_init_scan_params(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6064 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6065 | ret = il_init_channel_map(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6066 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6067 | IL_ERR("initializing regulatory failed: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6068 | goto err; |
| 6069 | } |
| 6070 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6071 | ret = il_init_geos(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6072 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6073 | IL_ERR("initializing geos failed: %d\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6074 | goto err_free_channel_map; |
| 6075 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6076 | il4965_init_hw_rates(il, il->ieee_rates); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6077 | |
| 6078 | return 0; |
| 6079 | |
| 6080 | err_free_channel_map: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6081 | il_free_channel_map(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6082 | err: |
| 6083 | return ret; |
| 6084 | } |
| 6085 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6086 | static void |
| 6087 | il4965_uninit_drv(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6088 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6089 | il4965_calib_free_results(il); |
| 6090 | il_free_geos(il); |
| 6091 | il_free_channel_map(il); |
| 6092 | kfree(il->scan_cmd); |
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 void |
| 6096 | il4965_hw_detect(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6097 | { |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 6098 | il->hw_rev = _il_rd(il, CSR_HW_REV); |
| 6099 | il->hw_wa_rev = _il_rd(il, CSR_HW_REV_WA_REG); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6100 | il->rev_id = il->pci_dev->revision; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6101 | D_INFO("HW Revision ID = 0x%X\n", il->rev_id); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6102 | } |
| 6103 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6104 | static int |
| 6105 | il4965_set_hw_params(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6106 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6107 | il->hw_params.max_rxq_size = RX_QUEUE_SIZE; |
| 6108 | il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; |
| 6109 | if (il->cfg->mod_params->amsdu_size_8K) |
| 6110 | 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] | 6111 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6112 | 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] | 6113 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6114 | il->hw_params.max_beacon_itrvl = IL_MAX_UCODE_BEACON_INTERVAL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6115 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6116 | if (il->cfg->mod_params->disable_11n) |
| 6117 | il->cfg->sku &= ~IL_SKU_N; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6118 | |
| 6119 | /* Device-specific setup */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6120 | return il->cfg->ops->lib->set_hw_params(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6121 | } |
| 6122 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6123 | static const u8 il4965_bss_ac_to_fifo[] = { |
| 6124 | IL_TX_FIFO_VO, |
| 6125 | IL_TX_FIFO_VI, |
| 6126 | IL_TX_FIFO_BE, |
| 6127 | IL_TX_FIFO_BK, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6128 | }; |
| 6129 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6130 | static const u8 il4965_bss_ac_to_queue[] = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6131 | 0, 1, 2, 3, |
| 6132 | }; |
| 6133 | |
| 6134 | static int |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6135 | 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] | 6136 | { |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6137 | int err = 0; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6138 | struct il_priv *il; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6139 | struct ieee80211_hw *hw; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6140 | struct il_cfg *cfg = (struct il_cfg *)(ent->driver_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6141 | unsigned long flags; |
| 6142 | u16 pci_cmd; |
| 6143 | |
| 6144 | /************************ |
| 6145 | * 1. Allocating HW data |
| 6146 | ************************/ |
| 6147 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6148 | hw = il_alloc_all(cfg); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6149 | if (!hw) { |
| 6150 | err = -ENOMEM; |
| 6151 | goto out; |
| 6152 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6153 | il = hw->priv; |
| 6154 | /* At this point both hw and il are allocated. */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6155 | |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6156 | il->ctx.ctxid = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6157 | |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6158 | il->ctx.always_active = true; |
| 6159 | il->ctx.is_active = true; |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 6160 | il->ctx.rxon_cmd = C_RXON; |
| 6161 | il->ctx.rxon_timing_cmd = C_RXON_TIMING; |
| 6162 | il->ctx.rxon_assoc_cmd = C_RXON_ASSOC; |
| 6163 | il->ctx.qos_cmd = C_QOS_PARAM; |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6164 | il->ctx.ap_sta_id = IL_AP_ID; |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 6165 | il->ctx.wep_key_cmd = C_WEPKEY; |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6166 | il->ctx.ac_to_fifo = il4965_bss_ac_to_fifo; |
| 6167 | il->ctx.ac_to_queue = il4965_bss_ac_to_queue; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6168 | il->ctx.exclusive_interface_modes = BIT(NL80211_IFTYPE_ADHOC); |
| 6169 | il->ctx.interface_modes = BIT(NL80211_IFTYPE_STATION); |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 6170 | il->ctx.ap_devtype = RXON_DEV_TYPE_AP; |
| 6171 | il->ctx.ibss_devtype = RXON_DEV_TYPE_IBSS; |
| 6172 | il->ctx.station_devtype = RXON_DEV_TYPE_ESS; |
| 6173 | il->ctx.unused_devtype = RXON_DEV_TYPE_ESS; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6174 | |
| 6175 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 6176 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6177 | D_INFO("*** LOAD DRIVER ***\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6178 | il->cfg = cfg; |
| 6179 | il->pci_dev = pdev; |
| 6180 | il->inta_mask = CSR_INI_SET_MASK; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6181 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6182 | if (il_alloc_traffic_mem(il)) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6183 | IL_ERR("Not enough memory to generate traffic log\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6184 | |
| 6185 | /************************** |
| 6186 | * 2. Initializing PCI bus |
| 6187 | **************************/ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6188 | pci_disable_link_state(pdev, |
| 6189 | PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 6190 | PCIE_LINK_STATE_CLKPM); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6191 | |
| 6192 | if (pci_enable_device(pdev)) { |
| 6193 | err = -ENODEV; |
| 6194 | goto out_ieee80211_free_hw; |
| 6195 | } |
| 6196 | |
| 6197 | pci_set_master(pdev); |
| 6198 | |
| 6199 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36)); |
| 6200 | if (!err) |
| 6201 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36)); |
| 6202 | if (err) { |
| 6203 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 6204 | if (!err) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6205 | err = |
| 6206 | pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6207 | /* both attempts failed: */ |
| 6208 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6209 | IL_WARN("No suitable DMA available.\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6210 | goto out_pci_disable_device; |
| 6211 | } |
| 6212 | } |
| 6213 | |
| 6214 | err = pci_request_regions(pdev, DRV_NAME); |
| 6215 | if (err) |
| 6216 | goto out_pci_disable_device; |
| 6217 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6218 | pci_set_drvdata(pdev, il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6219 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6220 | /*********************** |
| 6221 | * 3. Read REV register |
| 6222 | ***********************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6223 | il->hw_base = pci_iomap(pdev, 0, 0); |
| 6224 | if (!il->hw_base) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6225 | err = -ENODEV; |
| 6226 | goto out_pci_release_regions; |
| 6227 | } |
| 6228 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6229 | D_INFO("pci_resource_len = 0x%08llx\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6230 | (unsigned long long)pci_resource_len(pdev, 0)); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6231 | D_INFO("pci_resource_base = %p\n", il->hw_base); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6232 | |
| 6233 | /* these spin locks will be used in apm_ops.init and EEPROM access |
| 6234 | * we should init now |
| 6235 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6236 | spin_lock_init(&il->reg_lock); |
| 6237 | spin_lock_init(&il->lock); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6238 | |
| 6239 | /* |
| 6240 | * stop and reset the on-board processor just in case it is in a |
| 6241 | * strange state ... like being left stranded by a primary kernel |
| 6242 | * and this is now the kdump kernel trying to start up |
| 6243 | */ |
Stanislaw Gruszka | 841b2cc | 2011-08-24 15:14:03 +0200 | [diff] [blame] | 6244 | _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6245 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6246 | il4965_hw_detect(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6247 | 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] | 6248 | |
| 6249 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 6250 | * PCI Tx retries from interfering with C3 CPU state */ |
| 6251 | pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00); |
| 6252 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6253 | il4965_prepare_card_hw(il); |
| 6254 | if (!il->hw_ready) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6255 | IL_WARN("Failed, HW not ready\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6256 | goto out_iounmap; |
| 6257 | } |
| 6258 | |
| 6259 | /***************** |
| 6260 | * 4. Read EEPROM |
| 6261 | *****************/ |
| 6262 | /* Read the EEPROM */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6263 | err = il_eeprom_init(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6264 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6265 | IL_ERR("Unable to init EEPROM\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6266 | goto out_iounmap; |
| 6267 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6268 | err = il4965_eeprom_check_version(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6269 | if (err) |
| 6270 | goto out_free_eeprom; |
| 6271 | |
| 6272 | if (err) |
| 6273 | goto out_free_eeprom; |
| 6274 | |
| 6275 | /* extract MAC Address */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6276 | il4965_eeprom_get_mac(il, il->addresses[0].addr); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6277 | D_INFO("MAC address: %pM\n", il->addresses[0].addr); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6278 | il->hw->wiphy->addresses = il->addresses; |
| 6279 | il->hw->wiphy->n_addresses = 1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6280 | |
| 6281 | /************************ |
| 6282 | * 5. Setup HW constants |
| 6283 | ************************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6284 | if (il4965_set_hw_params(il)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6285 | IL_ERR("failed to set hw parameters\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6286 | goto out_free_eeprom; |
| 6287 | } |
| 6288 | |
| 6289 | /******************* |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6290 | * 6. Setup il |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6291 | *******************/ |
| 6292 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6293 | err = il4965_init_drv(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6294 | if (err) |
| 6295 | goto out_free_eeprom; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6296 | /* At this point both hw and il are initialized. */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6297 | |
| 6298 | /******************** |
| 6299 | * 7. Setup services |
| 6300 | ********************/ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6301 | spin_lock_irqsave(&il->lock, flags); |
| 6302 | il_disable_interrupts(il); |
| 6303 | spin_unlock_irqrestore(&il->lock, flags); |
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 | pci_enable_msi(il->pci_dev); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6306 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6307 | 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] | 6308 | if (err) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 6309 | IL_ERR("Error allocating IRQ %d\n", il->pci_dev->irq); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6310 | goto out_disable_msi; |
| 6311 | } |
| 6312 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6313 | il4965_setup_deferred_work(il); |
Stanislaw Gruszka | d0c7234 | 2011-08-30 15:39:42 +0200 | [diff] [blame] | 6314 | il4965_setup_handlers(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6315 | |
| 6316 | /********************************************* |
| 6317 | * 8. Enable interrupts and read RFKILL state |
| 6318 | *********************************************/ |
| 6319 | |
Stanislaw Gruszka | a078a1f | 2011-04-28 11:51:25 +0200 | [diff] [blame] | 6320 | /* enable rfkill interrupt: hw bug w/a */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6321 | pci_read_config_word(il->pci_dev, PCI_COMMAND, &pci_cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6322 | if (pci_cmd & PCI_COMMAND_INTX_DISABLE) { |
| 6323 | pci_cmd &= ~PCI_COMMAND_INTX_DISABLE; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6324 | pci_write_config_word(il->pci_dev, PCI_COMMAND, pci_cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6325 | } |
| 6326 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6327 | il_enable_rfkill_int(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6328 | |
| 6329 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6330 | 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] | 6331 | clear_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6332 | else |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 6333 | set_bit(S_RF_KILL_HW, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6334 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6335 | wiphy_rfkill_set_hw_state(il->hw->wiphy, |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6336 | test_bit(S_RF_KILL_HW, &il->status)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6337 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6338 | il_power_initialize(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6339 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6340 | init_completion(&il->_4965.firmware_loading_complete); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6341 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6342 | err = il4965_request_firmware(il, true); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6343 | if (err) |
| 6344 | goto out_destroy_workqueue; |
| 6345 | |
| 6346 | return 0; |
| 6347 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6348 | out_destroy_workqueue: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6349 | destroy_workqueue(il->workqueue); |
| 6350 | il->workqueue = NULL; |
| 6351 | free_irq(il->pci_dev->irq, il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6352 | out_disable_msi: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6353 | pci_disable_msi(il->pci_dev); |
| 6354 | il4965_uninit_drv(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6355 | out_free_eeprom: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6356 | il_eeprom_free(il); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6357 | out_iounmap: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6358 | pci_iounmap(pdev, il->hw_base); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6359 | out_pci_release_regions: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6360 | pci_set_drvdata(pdev, NULL); |
| 6361 | pci_release_regions(pdev); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6362 | out_pci_disable_device: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6363 | pci_disable_device(pdev); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6364 | out_ieee80211_free_hw: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6365 | il_free_traffic_mem(il); |
| 6366 | ieee80211_free_hw(il->hw); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6367 | out: |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6368 | return err; |
| 6369 | } |
| 6370 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6371 | static void __devexit |
| 6372 | il4965_pci_remove(struct pci_dev *pdev) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6373 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6374 | struct il_priv *il = pci_get_drvdata(pdev); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6375 | unsigned long flags; |
| 6376 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6377 | if (!il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6378 | return; |
| 6379 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6380 | wait_for_completion(&il->_4965.firmware_loading_complete); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6381 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 6382 | D_INFO("*** UNLOAD DRIVER ***\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6383 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6384 | il_dbgfs_unregister(il); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6385 | sysfs_remove_group(&pdev->dev.kobj, &il_attribute_group); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6386 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6387 | /* ieee80211_unregister_hw call wil cause il_mac_stop to |
| 6388 | * to be called and il4965_down since we are removing the device |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 6389 | * we need to set S_EXIT_PENDING bit. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6390 | */ |
Stanislaw Gruszka | a6766cc | 2011-11-15 13:09:01 +0100 | [diff] [blame] | 6391 | set_bit(S_EXIT_PENDING, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6392 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6393 | il_leds_exit(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6394 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6395 | if (il->mac80211_registered) { |
| 6396 | ieee80211_unregister_hw(il->hw); |
| 6397 | il->mac80211_registered = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6398 | } else { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6399 | il4965_down(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | /* |
| 6403 | * Make sure device is reset to low power before unloading driver. |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6404 | * This may be redundant with il4965_down(), but there are paths to |
| 6405 | * run il4965_down() without calling apm_ops.stop(), and there are |
| 6406 | * paths to avoid running il4965_down() at all before leaving driver. |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6407 | * This (inexpensive) call *makes sure* device is reset. |
| 6408 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6409 | il_apm_stop(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6410 | |
| 6411 | /* make sure we flush any pending irq or |
| 6412 | * tasklet for the driver |
| 6413 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6414 | spin_lock_irqsave(&il->lock, flags); |
| 6415 | il_disable_interrupts(il); |
| 6416 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6417 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6418 | il4965_synchronize_irq(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6419 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6420 | il4965_dealloc_ucode_pci(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6421 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6422 | if (il->rxq.bd) |
| 6423 | il4965_rx_queue_free(il, &il->rxq); |
| 6424 | il4965_hw_txq_ctx_free(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6425 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6426 | il_eeprom_free(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6427 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6428 | /*netif_stop_queue(dev); */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6429 | flush_workqueue(il->workqueue); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6430 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6431 | /* ieee80211_unregister_hw calls il_mac_stop, which flushes |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6432 | * il->workqueue... so we can't take down the workqueue |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6433 | * until now... */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6434 | destroy_workqueue(il->workqueue); |
| 6435 | il->workqueue = NULL; |
| 6436 | il_free_traffic_mem(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6437 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6438 | free_irq(il->pci_dev->irq, il); |
| 6439 | pci_disable_msi(il->pci_dev); |
| 6440 | pci_iounmap(pdev, il->hw_base); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6441 | pci_release_regions(pdev); |
| 6442 | pci_disable_device(pdev); |
| 6443 | pci_set_drvdata(pdev, NULL); |
| 6444 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6445 | il4965_uninit_drv(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6446 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6447 | dev_kfree_skb(il->beacon_skb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6448 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6449 | ieee80211_free_hw(il->hw); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6450 | } |
| 6451 | |
| 6452 | /* |
| 6453 | * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 6454 | * must be called under il->lock and mac access |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6455 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6456 | void |
| 6457 | il4965_txq_set_sched(struct il_priv *il, u32 mask) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6458 | { |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 6459 | il_wr_prph(il, IL49_SCD_TXFACT, mask); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6460 | } |
| 6461 | |
| 6462 | /***************************************************************************** |
| 6463 | * |
| 6464 | * driver and module entry point |
| 6465 | * |
| 6466 | *****************************************************************************/ |
| 6467 | |
| 6468 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6469 | static DEFINE_PCI_DEVICE_TABLE(il4965_hw_card_ids) = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6470 | {IL_PCI_DEVICE(0x4229, PCI_ANY_ID, il4965_cfg)}, |
| 6471 | {IL_PCI_DEVICE(0x4230, PCI_ANY_ID, il4965_cfg)}, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6472 | {0} |
| 6473 | }; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6474 | MODULE_DEVICE_TABLE(pci, il4965_hw_card_ids); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6475 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6476 | static struct pci_driver il4965_driver = { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6477 | .name = DRV_NAME, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6478 | .id_table = il4965_hw_card_ids, |
| 6479 | .probe = il4965_pci_probe, |
| 6480 | .remove = __devexit_p(il4965_pci_remove), |
| 6481 | .driver.pm = IL_LEGACY_PM_OPS, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6482 | }; |
| 6483 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6484 | static int __init |
| 6485 | il4965_init(void) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6486 | { |
| 6487 | |
| 6488 | int ret; |
| 6489 | pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 6490 | pr_info(DRV_COPYRIGHT "\n"); |
| 6491 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6492 | ret = il4965_rate_control_register(); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6493 | if (ret) { |
| 6494 | pr_err("Unable to register rate control algorithm: %d\n", ret); |
| 6495 | return ret; |
| 6496 | } |
| 6497 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6498 | ret = pci_register_driver(&il4965_driver); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6499 | if (ret) { |
| 6500 | pr_err("Unable to initialize PCI module\n"); |
| 6501 | goto error_register; |
| 6502 | } |
| 6503 | |
| 6504 | return ret; |
| 6505 | |
| 6506 | error_register: |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6507 | il4965_rate_control_unregister(); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6508 | return ret; |
| 6509 | } |
| 6510 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6511 | static void __exit |
| 6512 | il4965_exit(void) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6513 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6514 | pci_unregister_driver(&il4965_driver); |
| 6515 | il4965_rate_control_unregister(); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6516 | } |
| 6517 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6518 | module_exit(il4965_exit); |
| 6519 | module_init(il4965_init); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6520 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 6521 | #ifdef CONFIG_IWLEGACY_DEBUG |
Stanislaw Gruszka | d2ddf62 | 2011-08-16 14:17:04 +0200 | [diff] [blame] | 6522 | 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] | 6523 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 6524 | #endif |
| 6525 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6526 | 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] | 6527 | MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6528 | 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] | 6529 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6530 | 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] | 6531 | MODULE_PARM_DESC(11n_disable, "disable 11n functionality"); |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 6532 | module_param_named(amsdu_size_8K, il4965_mod_params.amsdu_size_8K, int, |
| 6533 | S_IRUGO); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 6534 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 6535 | 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] | 6536 | MODULE_PARM_DESC(fw_restart, "restart firmware in case of error"); |