Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | *****************************************************************************/ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/dma-mapping.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/sched.h> |
| 34 | #include <linux/skbuff.h> |
| 35 | #include <linux/netdevice.h> |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 36 | #include <net/mac80211.h> |
| 37 | #include <linux/etherdevice.h> |
| 38 | #include <asm/unaligned.h> |
| 39 | |
| 40 | #include "iwl-eeprom.h" |
| 41 | #include "iwl-dev.h" |
| 42 | #include "iwl-core.h" |
| 43 | #include "iwl-io.h" |
| 44 | #include "iwl-helpers.h" |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 45 | #include "iwl-4965-calib.h" |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 46 | #include "iwl-sta.h" |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 47 | #include "iwl-4965.h" |
| 48 | #include "iwl-4965-debugfs.h" |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 49 | |
Stanislaw Gruszka | 56e7a8c | 2011-08-30 12:45:25 +0200 | [diff] [blame^] | 50 | /****************************************************************************** |
| 51 | * |
| 52 | * EEPROM related functions |
| 53 | * |
| 54 | ******************************************************************************/ |
| 55 | |
| 56 | /* |
| 57 | * The device's EEPROM semaphore prevents conflicts between driver and uCode |
| 58 | * when accessing the EEPROM; each access is a series of pulses to/from the |
| 59 | * EEPROM chip, not a single event, so even reads could conflict if they |
| 60 | * weren't arbitrated by the semaphore. |
| 61 | */ |
| 62 | int il4965_eeprom_acquire_semaphore(struct il_priv *il) |
| 63 | { |
| 64 | u16 count; |
| 65 | int ret; |
| 66 | |
| 67 | for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) { |
| 68 | /* Request semaphore */ |
| 69 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, |
| 70 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); |
| 71 | |
| 72 | /* See if we got it */ |
| 73 | ret = _il_poll_bit(il, CSR_HW_IF_CONFIG_REG, |
| 74 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, |
| 75 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, |
| 76 | EEPROM_SEM_TIMEOUT); |
| 77 | if (ret >= 0) |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | void il4965_eeprom_release_semaphore(struct il_priv *il) |
| 85 | { |
| 86 | il_clear_bit(il, CSR_HW_IF_CONFIG_REG, |
| 87 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); |
| 88 | |
| 89 | } |
| 90 | |
| 91 | int il4965_eeprom_check_version(struct il_priv *il) |
| 92 | { |
| 93 | u16 eeprom_ver; |
| 94 | u16 calib_ver; |
| 95 | |
| 96 | eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION); |
| 97 | calib_ver = il_eeprom_query16(il, |
| 98 | EEPROM_4965_CALIB_VERSION_OFFSET); |
| 99 | |
| 100 | if (eeprom_ver < il->cfg->eeprom_ver || |
| 101 | calib_ver < il->cfg->eeprom_calib_ver) |
| 102 | goto err; |
| 103 | |
| 104 | IL_INFO("device EEPROM VER=0x%x, CALIB=0x%x\n", |
| 105 | eeprom_ver, calib_ver); |
| 106 | |
| 107 | return 0; |
| 108 | err: |
| 109 | IL_ERR("Unsupported (too old) EEPROM VER=0x%x < 0x%x " |
| 110 | "CALIB=0x%x < 0x%x\n", |
| 111 | eeprom_ver, il->cfg->eeprom_ver, |
| 112 | calib_ver, il->cfg->eeprom_calib_ver); |
| 113 | return -EINVAL; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | void il4965_eeprom_get_mac(const struct il_priv *il, u8 *mac) |
| 118 | { |
| 119 | const u8 *addr = il_eeprom_query_addr(il, |
| 120 | EEPROM_MAC_ADDRESS); |
| 121 | memcpy(mac, addr, ETH_ALEN); |
| 122 | } |
| 123 | |
Stanislaw Gruszka | fc19cbd | 2011-08-29 16:59:15 +0200 | [diff] [blame] | 124 | /* Send led command */ |
| 125 | static int |
| 126 | il4965_send_led_cmd(struct il_priv *il, struct il_led_cmd *led_cmd) |
| 127 | { |
| 128 | struct il_host_cmd cmd = { |
| 129 | .id = REPLY_LEDS_CMD, |
| 130 | .len = sizeof(struct il_led_cmd), |
| 131 | .data = led_cmd, |
| 132 | .flags = CMD_ASYNC, |
| 133 | .callback = NULL, |
| 134 | }; |
| 135 | u32 reg; |
| 136 | |
| 137 | reg = _il_rd(il, CSR_LED_REG); |
| 138 | if (reg != (reg & CSR_LED_BSM_CTRL_MSK)) |
| 139 | _il_wr(il, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK); |
| 140 | |
| 141 | return il_send_cmd(il, &cmd); |
| 142 | } |
| 143 | |
| 144 | /* Set led register off */ |
| 145 | void il4965_led_enable(struct il_priv *il) |
| 146 | { |
| 147 | _il_wr(il, CSR_LED_REG, CSR_LED_REG_TRUN_ON); |
| 148 | } |
| 149 | |
| 150 | const struct il_led_ops il4965_led_ops = { |
| 151 | .cmd = il4965_send_led_cmd, |
| 152 | }; |
| 153 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 154 | static int il4965_send_tx_power(struct il_priv *il); |
| 155 | static int il4965_hw_get_temperature(struct il_priv *il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 156 | |
| 157 | /* Highest firmware API version supported */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 158 | #define IL4965_UCODE_API_MAX 2 |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 159 | |
| 160 | /* Lowest firmware API version supported */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 161 | #define IL4965_UCODE_API_MIN 2 |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 162 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 163 | #define IL4965_FW_PRE "iwlwifi-4965-" |
| 164 | #define _IL4965_MODULE_FIRMWARE(api) IL4965_FW_PRE #api ".ucode" |
| 165 | #define IL4965_MODULE_FIRMWARE(api) _IL4965_MODULE_FIRMWARE(api) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 166 | |
| 167 | /* check contents of special bootstrap uCode SRAM */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 168 | static int il4965_verify_bsm(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 169 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 170 | __le32 *image = il->ucode_boot.v_addr; |
| 171 | u32 len = il->ucode_boot.len; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 172 | u32 reg; |
| 173 | u32 val; |
| 174 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 175 | D_INFO("Begin verify bsm\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 176 | |
| 177 | /* verify BSM SRAM contents */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 178 | val = il_rd_prph(il, BSM_WR_DWCOUNT_REG); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 179 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 180 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 181 | reg += sizeof(u32), image++) { |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 182 | val = il_rd_prph(il, reg); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 183 | if (val != le32_to_cpu(*image)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 184 | IL_ERR("BSM uCode verification failed at " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 185 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 186 | BSM_SRAM_LOWER_BOUND, |
| 187 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 188 | val, le32_to_cpu(*image)); |
| 189 | return -EIO; |
| 190 | } |
| 191 | } |
| 192 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 193 | D_INFO("BSM bootstrap uCode image OK\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 199 | * il4965_load_bsm - Load bootstrap instructions |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 200 | * |
| 201 | * BSM operation: |
| 202 | * |
| 203 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 204 | * in special SRAM that does not power down during RFKILL. When powering back |
| 205 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 206 | * the bootstrap program into the on-board processor, and starts it. |
| 207 | * |
| 208 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 209 | * program from host DRAM locations indicated by the host driver in the |
| 210 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 211 | * automatically. |
| 212 | * |
| 213 | * When initializing the NIC, the host driver points the BSM to the |
| 214 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 215 | * notifies host via "initialize alive" that it is complete. |
| 216 | * |
| 217 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 218 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 219 | * (filled initially with starting data values for the on-board processor), |
| 220 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 221 | * which begins normal operation. |
| 222 | * |
| 223 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 224 | * the backup data cache in DRAM before SRAM is powered down. |
| 225 | * |
| 226 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 227 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 228 | * and re-launches the runtime uCode from where it left off. |
| 229 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 230 | static int il4965_load_bsm(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 231 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 232 | __le32 *image = il->ucode_boot.v_addr; |
| 233 | u32 len = il->ucode_boot.len; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 234 | dma_addr_t pinst; |
| 235 | dma_addr_t pdata; |
| 236 | u32 inst_len; |
| 237 | u32 data_len; |
| 238 | int i; |
| 239 | u32 done; |
| 240 | u32 reg_offset; |
| 241 | int ret; |
| 242 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 243 | D_INFO("Begin load bsm\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 244 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 245 | il->ucode_type = UCODE_RT; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 246 | |
| 247 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 248 | if (len > IL49_MAX_BSM_SIZE) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 249 | return -EINVAL; |
| 250 | |
| 251 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
| 252 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 253 | * NOTE: il_init_alive_start() will replace these values, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 254 | * after the "initialize" uCode has run, to point to |
| 255 | * runtime/protocol instructions and backup data cache. |
| 256 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 257 | pinst = il->ucode_init.p_addr >> 4; |
| 258 | pdata = il->ucode_init_data.p_addr >> 4; |
| 259 | inst_len = il->ucode_init.len; |
| 260 | data_len = il->ucode_init_data.len; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 261 | |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 262 | il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst); |
| 263 | il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata); |
| 264 | il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 265 | il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 266 | |
| 267 | /* Fill BSM memory with bootstrap instructions */ |
| 268 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 269 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 270 | reg_offset += sizeof(u32), image++) |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 271 | _il_wr_prph(il, reg_offset, le32_to_cpu(*image)); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 272 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 273 | ret = il4965_verify_bsm(il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 274 | if (ret) |
| 275 | return ret; |
| 276 | |
| 277 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 278 | il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0); |
| 279 | il_wr_prph(il, |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 280 | BSM_WR_MEM_DST_REG, IL49_RTC_INST_LOWER_BOUND); |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 281 | il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 282 | |
| 283 | /* Load bootstrap code into instruction SRAM now, |
| 284 | * to prepare to load "initialize" uCode */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 285 | il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 286 | |
| 287 | /* Wait for load of bootstrap uCode to finish */ |
| 288 | for (i = 0; i < 100; i++) { |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 289 | done = il_rd_prph(il, BSM_WR_CTRL_REG); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 290 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 291 | break; |
| 292 | udelay(10); |
| 293 | } |
| 294 | if (i < 100) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 295 | D_INFO("BSM write complete, poll %d iterations\n", i); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 296 | else { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 297 | IL_ERR("BSM write did not complete!\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 298 | return -EIO; |
| 299 | } |
| 300 | |
| 301 | /* Enable future boot loads whenever power management unit triggers it |
| 302 | * (e.g. when powering back up after power-save shutdown) */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 303 | il_wr_prph(il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 304 | BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 305 | |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 311 | * il4965_set_ucode_ptrs - Set uCode address location |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 312 | * |
| 313 | * Tell initialization uCode where to find runtime uCode. |
| 314 | * |
| 315 | * BSM registers initially contain pointers to initialization uCode. |
| 316 | * We need to replace them to load runtime uCode inst and data, |
| 317 | * and to save runtime data when powering down. |
| 318 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 319 | static int il4965_set_ucode_ptrs(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 320 | { |
| 321 | dma_addr_t pinst; |
| 322 | dma_addr_t pdata; |
| 323 | int ret = 0; |
| 324 | |
| 325 | /* bits 35:4 for 4965 */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 326 | pinst = il->ucode_code.p_addr >> 4; |
| 327 | pdata = il->ucode_data_backup.p_addr >> 4; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 328 | |
| 329 | /* Tell bootstrap uCode where to find image to load */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 330 | il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst); |
| 331 | il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata); |
| 332 | il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 333 | il->ucode_data.len); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 334 | |
| 335 | /* Inst byte count must be last to set up, bit 31 signals uCode |
| 336 | * that all new ptr/size info is in place */ |
Stanislaw Gruszka | db54eb5 | 2011-08-24 21:06:33 +0200 | [diff] [blame] | 337 | il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 338 | il->ucode_code.len | BSM_DRAM_INST_LOAD); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 339 | D_INFO("Runtime uCode pointers are set.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 340 | |
| 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 345 | * il4965_init_alive_start - Called after REPLY_ALIVE notification received |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 346 | * |
| 347 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 348 | * |
| 349 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 350 | * Voltage, temperature, and MIMO tx gain correction, now stored in il |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 351 | * (3945 does not contain this data). |
| 352 | * |
| 353 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 354 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 355 | static void il4965_init_alive_start(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 356 | { |
| 357 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 358 | * This is a paranoid check, because we would not have gotten the |
| 359 | * "initialize" alive if code weren't properly loaded. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 360 | if (il4965_verify_ucode(il)) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 361 | /* Runtime instruction load was bad; |
| 362 | * take it all the way back down so we can try again */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 363 | D_INFO("Bad \"initialize\" uCode load.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 364 | goto restart; |
| 365 | } |
| 366 | |
| 367 | /* Calculate temperature */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 368 | il->temperature = il4965_hw_get_temperature(il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 369 | |
| 370 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 371 | * load and launch runtime uCode, which will send us another "Alive" |
| 372 | * notification. */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 373 | D_INFO("Initialization Alive received.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 374 | if (il4965_set_ucode_ptrs(il)) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 375 | /* Runtime instruction load won't happen; |
| 376 | * take it all the way back down so we can try again */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 377 | D_INFO("Couldn't set up uCode pointers.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 378 | goto restart; |
| 379 | } |
| 380 | return; |
| 381 | |
| 382 | restart: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 383 | queue_work(il->workqueue, &il->restart); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 386 | static bool iw4965_is_ht40_channel(__le32 rxon_flags) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 387 | { |
| 388 | int chan_mod = le32_to_cpu(rxon_flags & RXON_FLG_CHANNEL_MODE_MSK) |
| 389 | >> RXON_FLG_CHANNEL_MODE_POS; |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 390 | return (chan_mod == CHANNEL_MODE_PURE_40 || |
| 391 | chan_mod == CHANNEL_MODE_MIXED); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 394 | static void il4965_nic_config(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 395 | { |
| 396 | unsigned long flags; |
| 397 | u16 radio_cfg; |
| 398 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 399 | spin_lock_irqsave(&il->lock, flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 400 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 401 | radio_cfg = il_eeprom_query16(il, EEPROM_RADIO_CONFIG); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 402 | |
| 403 | /* write radio config values to register */ |
| 404 | if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 405 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 406 | EEPROM_RF_CFG_TYPE_MSK(radio_cfg) | |
| 407 | EEPROM_RF_CFG_STEP_MSK(radio_cfg) | |
| 408 | EEPROM_RF_CFG_DASH_MSK(radio_cfg)); |
| 409 | |
| 410 | /* set CSR_HW_CONFIG_REG for uCode use */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 411 | il_set_bit(il, CSR_HW_IF_CONFIG_REG, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 412 | CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | |
| 413 | CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); |
| 414 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 415 | il->calib_info = (struct il_eeprom_calib_info *) |
| 416 | il_eeprom_query_addr(il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 417 | EEPROM_4965_CALIB_TXPOWER_OFFSET); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 418 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 419 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* Reset differential Rx gains in NIC to prepare for chain noise calibration. |
| 423 | * Called after every association, but this runs only once! |
| 424 | * ... once chain noise is calibrated the first time, it's good forever. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 425 | static void il4965_chain_noise_reset(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 426 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 427 | struct il_chain_noise_data *data = &(il->chain_noise_data); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 428 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 429 | if (data->state == IL_CHAIN_NOISE_ALIVE && |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 430 | il_is_any_associated(il)) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 431 | struct il_calib_diff_gain_cmd cmd; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 432 | |
| 433 | /* clear data for chain noise calibration algorithm */ |
| 434 | data->chain_noise_a = 0; |
| 435 | data->chain_noise_b = 0; |
| 436 | data->chain_noise_c = 0; |
| 437 | data->chain_signal_a = 0; |
| 438 | data->chain_signal_b = 0; |
| 439 | data->chain_signal_c = 0; |
| 440 | data->beacon_count = 0; |
| 441 | |
| 442 | memset(&cmd, 0, sizeof(cmd)); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 443 | cmd.hdr.op_code = IL_PHY_CALIBRATE_DIFF_GAIN_CMD; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 444 | cmd.diff_gain_a = 0; |
| 445 | cmd.diff_gain_b = 0; |
| 446 | cmd.diff_gain_c = 0; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 447 | if (il_send_cmd_pdu(il, REPLY_PHY_CALIBRATION_CMD, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 448 | sizeof(cmd), &cmd)) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 449 | IL_ERR( |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 450 | "Could not send REPLY_PHY_CALIBRATION_CMD\n"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 451 | data->state = IL_CHAIN_NOISE_ACCUMULATE; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 452 | D_CALIB("Run chain_noise_calibrate\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 456 | static struct il_sensitivity_ranges il4965_sensitivity = { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 457 | .min_nrg_cck = 97, |
| 458 | .max_nrg_cck = 0, /* not used, set to 0 */ |
| 459 | |
| 460 | .auto_corr_min_ofdm = 85, |
| 461 | .auto_corr_min_ofdm_mrc = 170, |
| 462 | .auto_corr_min_ofdm_x1 = 105, |
| 463 | .auto_corr_min_ofdm_mrc_x1 = 220, |
| 464 | |
| 465 | .auto_corr_max_ofdm = 120, |
| 466 | .auto_corr_max_ofdm_mrc = 210, |
| 467 | .auto_corr_max_ofdm_x1 = 140, |
| 468 | .auto_corr_max_ofdm_mrc_x1 = 270, |
| 469 | |
| 470 | .auto_corr_min_cck = 125, |
| 471 | .auto_corr_max_cck = 200, |
| 472 | .auto_corr_min_cck_mrc = 200, |
| 473 | .auto_corr_max_cck_mrc = 400, |
| 474 | |
| 475 | .nrg_th_cck = 100, |
| 476 | .nrg_th_ofdm = 100, |
| 477 | |
| 478 | .barker_corr_th_min = 190, |
| 479 | .barker_corr_th_min_mrc = 390, |
| 480 | .nrg_th_cca = 62, |
| 481 | }; |
| 482 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 483 | static void il4965_set_ct_threshold(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 484 | { |
| 485 | /* want Kelvin */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 486 | il->hw_params.ct_kill_threshold = |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 487 | CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY); |
| 488 | } |
| 489 | |
| 490 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 491 | * il4965_hw_set_hw_params |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 492 | * |
| 493 | * Called when initializing driver |
| 494 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 495 | static int il4965_hw_set_hw_params(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 496 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 497 | if (il->cfg->mod_params->num_of_queues >= IL_MIN_NUM_QUEUES && |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 498 | il->cfg->mod_params->num_of_queues <= IL49_NUM_QUEUES) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 499 | il->cfg->base_params->num_of_queues = |
| 500 | il->cfg->mod_params->num_of_queues; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 501 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 502 | il->hw_params.max_txq_num = il->cfg->base_params->num_of_queues; |
| 503 | il->hw_params.dma_chnl_num = FH49_TCSR_CHNL_NUM; |
| 504 | il->hw_params.scd_bc_tbls_size = |
| 505 | il->cfg->base_params->num_of_queues * |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 506 | sizeof(struct il4965_scd_bc_tbl); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 507 | il->hw_params.tfd_size = sizeof(struct il_tfd); |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 508 | il->hw_params.max_stations = IL4965_STATION_COUNT; |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 509 | il->ctx.bcast_sta_id = IL4965_BROADCAST_ID; |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 510 | il->hw_params.max_data_size = IL49_RTC_DATA_SIZE; |
| 511 | il->hw_params.max_inst_size = IL49_RTC_INST_SIZE; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 512 | il->hw_params.max_bsm_size = BSM_SRAM_SIZE; |
| 513 | il->hw_params.ht40_channel = BIT(IEEE80211_BAND_5GHZ); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 514 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 515 | il->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 516 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 517 | il->hw_params.tx_chains_num = il4965_num_of_ant(il->cfg->valid_tx_ant); |
| 518 | il->hw_params.rx_chains_num = il4965_num_of_ant(il->cfg->valid_rx_ant); |
| 519 | il->hw_params.valid_tx_ant = il->cfg->valid_tx_ant; |
| 520 | il->hw_params.valid_rx_ant = il->cfg->valid_rx_ant; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 521 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 522 | il4965_set_ct_threshold(il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 523 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 524 | il->hw_params.sens = &il4965_sensitivity; |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 525 | il->hw_params.beacon_time_tsf_bits = IL4965_EXT_BEACON_TIME_POS; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 526 | |
| 527 | return 0; |
| 528 | } |
| 529 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 530 | static s32 il4965_math_div_round(s32 num, s32 denom, s32 *res) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 531 | { |
| 532 | s32 sign = 1; |
| 533 | |
| 534 | if (num < 0) { |
| 535 | sign = -sign; |
| 536 | num = -num; |
| 537 | } |
| 538 | if (denom < 0) { |
| 539 | sign = -sign; |
| 540 | denom = -denom; |
| 541 | } |
| 542 | *res = 1; |
| 543 | *res = ((num * 2 + denom) / (denom * 2)) * sign; |
| 544 | |
| 545 | return 1; |
| 546 | } |
| 547 | |
| 548 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 549 | * il4965_get_voltage_compensation - Power supply voltage comp for txpower |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 550 | * |
| 551 | * Determines power supply voltage compensation for txpower calculations. |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 552 | * Returns number of 1/2-dB steps to subtract from gain table idx, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 553 | * to compensate for difference between power supply voltage during |
| 554 | * factory measurements, vs. current power supply voltage. |
| 555 | * |
| 556 | * Voltage indication is higher for lower voltage. |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 557 | * Lower voltage requires more gain (lower gain table idx). |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 558 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 559 | static s32 il4965_get_voltage_compensation(s32 eeprom_voltage, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 560 | s32 current_voltage) |
| 561 | { |
| 562 | s32 comp = 0; |
| 563 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 564 | if (TX_POWER_IL_ILLEGAL_VOLTAGE == eeprom_voltage || |
| 565 | TX_POWER_IL_ILLEGAL_VOLTAGE == current_voltage) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 566 | return 0; |
| 567 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 568 | il4965_math_div_round(current_voltage - eeprom_voltage, |
| 569 | TX_POWER_IL_VOLTAGE_CODES_PER_03V, &comp); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 570 | |
| 571 | if (current_voltage > eeprom_voltage) |
| 572 | comp *= 2; |
| 573 | if ((comp < -2) || (comp > 2)) |
| 574 | comp = 0; |
| 575 | |
| 576 | return comp; |
| 577 | } |
| 578 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 579 | static s32 il4965_get_tx_atten_grp(u16 channel) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 580 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 581 | if (channel >= CALIB_IL_TX_ATTEN_GR5_FCH && |
| 582 | channel <= CALIB_IL_TX_ATTEN_GR5_LCH) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 583 | return CALIB_CH_GROUP_5; |
| 584 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 585 | if (channel >= CALIB_IL_TX_ATTEN_GR1_FCH && |
| 586 | channel <= CALIB_IL_TX_ATTEN_GR1_LCH) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 587 | return CALIB_CH_GROUP_1; |
| 588 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 589 | if (channel >= CALIB_IL_TX_ATTEN_GR2_FCH && |
| 590 | channel <= CALIB_IL_TX_ATTEN_GR2_LCH) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 591 | return CALIB_CH_GROUP_2; |
| 592 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 593 | if (channel >= CALIB_IL_TX_ATTEN_GR3_FCH && |
| 594 | channel <= CALIB_IL_TX_ATTEN_GR3_LCH) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 595 | return CALIB_CH_GROUP_3; |
| 596 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 597 | if (channel >= CALIB_IL_TX_ATTEN_GR4_FCH && |
| 598 | channel <= CALIB_IL_TX_ATTEN_GR4_LCH) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 599 | return CALIB_CH_GROUP_4; |
| 600 | |
Greg Dietsche | 8e63818 | 2011-06-02 21:06:08 -0500 | [diff] [blame] | 601 | return -EINVAL; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 602 | } |
| 603 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 604 | static u32 il4965_get_sub_band(const struct il_priv *il, u32 channel) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 605 | { |
| 606 | s32 b = -1; |
| 607 | |
| 608 | for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 609 | if (il->calib_info->band_info[b].ch_from == 0) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 610 | continue; |
| 611 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 612 | if (channel >= il->calib_info->band_info[b].ch_from && |
| 613 | channel <= il->calib_info->band_info[b].ch_to) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 614 | break; |
| 615 | } |
| 616 | |
| 617 | return b; |
| 618 | } |
| 619 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 620 | static s32 il4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 621 | { |
| 622 | s32 val; |
| 623 | |
| 624 | if (x2 == x1) |
| 625 | return y1; |
| 626 | else { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 627 | il4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 628 | return val + y2; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 633 | * il4965_interpolate_chan - Interpolate factory measurements for one channel |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 634 | * |
| 635 | * Interpolates factory measurements from the two sample channels within a |
| 636 | * sub-band, to apply to channel of interest. Interpolation is proportional to |
| 637 | * differences in channel frequencies, which is proportional to differences |
| 638 | * in channel number. |
| 639 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 640 | static int il4965_interpolate_chan(struct il_priv *il, u32 channel, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 641 | struct il_eeprom_calib_ch_info *chan_info) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 642 | { |
| 643 | s32 s = -1; |
| 644 | u32 c; |
| 645 | u32 m; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 646 | const struct il_eeprom_calib_measure *m1; |
| 647 | const struct il_eeprom_calib_measure *m2; |
| 648 | struct il_eeprom_calib_measure *omeas; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 649 | u32 ch_i1; |
| 650 | u32 ch_i2; |
| 651 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 652 | s = il4965_get_sub_band(il, channel); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 653 | if (s >= EEPROM_TX_POWER_BANDS) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 654 | IL_ERR("Tx Power can not find channel %d\n", channel); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 655 | return -1; |
| 656 | } |
| 657 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 658 | ch_i1 = il->calib_info->band_info[s].ch1.ch_num; |
| 659 | ch_i2 = il->calib_info->band_info[s].ch2.ch_num; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 660 | chan_info->ch_num = (u8) channel; |
| 661 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 662 | D_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 663 | channel, s, ch_i1, ch_i2); |
| 664 | |
| 665 | for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) { |
| 666 | for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 667 | m1 = &(il->calib_info->band_info[s].ch1. |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 668 | measurements[c][m]); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 669 | m2 = &(il->calib_info->band_info[s].ch2. |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 670 | measurements[c][m]); |
| 671 | omeas = &(chan_info->measurements[c][m]); |
| 672 | |
| 673 | omeas->actual_pow = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 674 | (u8) il4965_interpolate_value(channel, ch_i1, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 675 | m1->actual_pow, |
| 676 | ch_i2, |
| 677 | m2->actual_pow); |
| 678 | omeas->gain_idx = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 679 | (u8) il4965_interpolate_value(channel, ch_i1, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 680 | m1->gain_idx, ch_i2, |
| 681 | m2->gain_idx); |
| 682 | omeas->temperature = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 683 | (u8) il4965_interpolate_value(channel, ch_i1, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 684 | m1->temperature, |
| 685 | ch_i2, |
| 686 | m2->temperature); |
| 687 | omeas->pa_det = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 688 | (s8) il4965_interpolate_value(channel, ch_i1, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 689 | m1->pa_det, ch_i2, |
| 690 | m2->pa_det); |
| 691 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 692 | D_TXPOWER( |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 693 | "chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m, |
| 694 | m1->actual_pow, m2->actual_pow, omeas->actual_pow); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 695 | D_TXPOWER( |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 696 | "chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m, |
| 697 | m1->gain_idx, m2->gain_idx, omeas->gain_idx); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 698 | D_TXPOWER( |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 699 | "chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m, |
| 700 | m1->pa_det, m2->pa_det, omeas->pa_det); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 701 | D_TXPOWER( |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 702 | "chain %d meas %d T1=%d T2=%d T=%d\n", c, m, |
| 703 | m1->temperature, m2->temperature, |
| 704 | omeas->temperature); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | /* bit-rate-dependent table to prevent Tx distortion, in half-dB units, |
| 712 | * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */ |
| 713 | static s32 back_off_table[] = { |
| 714 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */ |
| 715 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */ |
| 716 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */ |
| 717 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */ |
| 718 | 10 /* CCK */ |
| 719 | }; |
| 720 | |
| 721 | /* Thermal compensation values for txpower for various frequency ranges ... |
| 722 | * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 723 | static struct il4965_txpower_comp_entry { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 724 | s32 degrees_per_05db_a; |
| 725 | s32 degrees_per_05db_a_denom; |
| 726 | } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = { |
| 727 | {9, 2}, /* group 0 5.2, ch 34-43 */ |
| 728 | {4, 1}, /* group 1 5.2, ch 44-70 */ |
| 729 | {4, 1}, /* group 2 5.2, ch 71-124 */ |
| 730 | {4, 1}, /* group 3 5.2, ch 125-200 */ |
| 731 | {3, 1} /* group 4 2.4, ch all */ |
| 732 | }; |
| 733 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 734 | static s32 get_min_power_idx(s32 rate_power_idx, u32 band) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 735 | { |
| 736 | if (!band) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 737 | if ((rate_power_idx & 7) <= 4) |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 738 | return MIN_TX_GAIN_IDX_52GHZ_EXT; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 739 | } |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 740 | return MIN_TX_GAIN_IDX; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | struct gain_entry { |
| 744 | u8 dsp; |
| 745 | u8 radio; |
| 746 | }; |
| 747 | |
| 748 | static const struct gain_entry gain_table[2][108] = { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 749 | /* 5.2GHz power gain idx table */ |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 750 | { |
| 751 | {123, 0x3F}, /* highest txpower */ |
| 752 | {117, 0x3F}, |
| 753 | {110, 0x3F}, |
| 754 | {104, 0x3F}, |
| 755 | {98, 0x3F}, |
| 756 | {110, 0x3E}, |
| 757 | {104, 0x3E}, |
| 758 | {98, 0x3E}, |
| 759 | {110, 0x3D}, |
| 760 | {104, 0x3D}, |
| 761 | {98, 0x3D}, |
| 762 | {110, 0x3C}, |
| 763 | {104, 0x3C}, |
| 764 | {98, 0x3C}, |
| 765 | {110, 0x3B}, |
| 766 | {104, 0x3B}, |
| 767 | {98, 0x3B}, |
| 768 | {110, 0x3A}, |
| 769 | {104, 0x3A}, |
| 770 | {98, 0x3A}, |
| 771 | {110, 0x39}, |
| 772 | {104, 0x39}, |
| 773 | {98, 0x39}, |
| 774 | {110, 0x38}, |
| 775 | {104, 0x38}, |
| 776 | {98, 0x38}, |
| 777 | {110, 0x37}, |
| 778 | {104, 0x37}, |
| 779 | {98, 0x37}, |
| 780 | {110, 0x36}, |
| 781 | {104, 0x36}, |
| 782 | {98, 0x36}, |
| 783 | {110, 0x35}, |
| 784 | {104, 0x35}, |
| 785 | {98, 0x35}, |
| 786 | {110, 0x34}, |
| 787 | {104, 0x34}, |
| 788 | {98, 0x34}, |
| 789 | {110, 0x33}, |
| 790 | {104, 0x33}, |
| 791 | {98, 0x33}, |
| 792 | {110, 0x32}, |
| 793 | {104, 0x32}, |
| 794 | {98, 0x32}, |
| 795 | {110, 0x31}, |
| 796 | {104, 0x31}, |
| 797 | {98, 0x31}, |
| 798 | {110, 0x30}, |
| 799 | {104, 0x30}, |
| 800 | {98, 0x30}, |
| 801 | {110, 0x25}, |
| 802 | {104, 0x25}, |
| 803 | {98, 0x25}, |
| 804 | {110, 0x24}, |
| 805 | {104, 0x24}, |
| 806 | {98, 0x24}, |
| 807 | {110, 0x23}, |
| 808 | {104, 0x23}, |
| 809 | {98, 0x23}, |
| 810 | {110, 0x22}, |
| 811 | {104, 0x18}, |
| 812 | {98, 0x18}, |
| 813 | {110, 0x17}, |
| 814 | {104, 0x17}, |
| 815 | {98, 0x17}, |
| 816 | {110, 0x16}, |
| 817 | {104, 0x16}, |
| 818 | {98, 0x16}, |
| 819 | {110, 0x15}, |
| 820 | {104, 0x15}, |
| 821 | {98, 0x15}, |
| 822 | {110, 0x14}, |
| 823 | {104, 0x14}, |
| 824 | {98, 0x14}, |
| 825 | {110, 0x13}, |
| 826 | {104, 0x13}, |
| 827 | {98, 0x13}, |
| 828 | {110, 0x12}, |
| 829 | {104, 0x08}, |
| 830 | {98, 0x08}, |
| 831 | {110, 0x07}, |
| 832 | {104, 0x07}, |
| 833 | {98, 0x07}, |
| 834 | {110, 0x06}, |
| 835 | {104, 0x06}, |
| 836 | {98, 0x06}, |
| 837 | {110, 0x05}, |
| 838 | {104, 0x05}, |
| 839 | {98, 0x05}, |
| 840 | {110, 0x04}, |
| 841 | {104, 0x04}, |
| 842 | {98, 0x04}, |
| 843 | {110, 0x03}, |
| 844 | {104, 0x03}, |
| 845 | {98, 0x03}, |
| 846 | {110, 0x02}, |
| 847 | {104, 0x02}, |
| 848 | {98, 0x02}, |
| 849 | {110, 0x01}, |
| 850 | {104, 0x01}, |
| 851 | {98, 0x01}, |
| 852 | {110, 0x00}, |
| 853 | {104, 0x00}, |
| 854 | {98, 0x00}, |
| 855 | {93, 0x00}, |
| 856 | {88, 0x00}, |
| 857 | {83, 0x00}, |
| 858 | {78, 0x00}, |
| 859 | }, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 860 | /* 2.4GHz power gain idx table */ |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 861 | { |
| 862 | {110, 0x3f}, /* highest txpower */ |
| 863 | {104, 0x3f}, |
| 864 | {98, 0x3f}, |
| 865 | {110, 0x3e}, |
| 866 | {104, 0x3e}, |
| 867 | {98, 0x3e}, |
| 868 | {110, 0x3d}, |
| 869 | {104, 0x3d}, |
| 870 | {98, 0x3d}, |
| 871 | {110, 0x3c}, |
| 872 | {104, 0x3c}, |
| 873 | {98, 0x3c}, |
| 874 | {110, 0x3b}, |
| 875 | {104, 0x3b}, |
| 876 | {98, 0x3b}, |
| 877 | {110, 0x3a}, |
| 878 | {104, 0x3a}, |
| 879 | {98, 0x3a}, |
| 880 | {110, 0x39}, |
| 881 | {104, 0x39}, |
| 882 | {98, 0x39}, |
| 883 | {110, 0x38}, |
| 884 | {104, 0x38}, |
| 885 | {98, 0x38}, |
| 886 | {110, 0x37}, |
| 887 | {104, 0x37}, |
| 888 | {98, 0x37}, |
| 889 | {110, 0x36}, |
| 890 | {104, 0x36}, |
| 891 | {98, 0x36}, |
| 892 | {110, 0x35}, |
| 893 | {104, 0x35}, |
| 894 | {98, 0x35}, |
| 895 | {110, 0x34}, |
| 896 | {104, 0x34}, |
| 897 | {98, 0x34}, |
| 898 | {110, 0x33}, |
| 899 | {104, 0x33}, |
| 900 | {98, 0x33}, |
| 901 | {110, 0x32}, |
| 902 | {104, 0x32}, |
| 903 | {98, 0x32}, |
| 904 | {110, 0x31}, |
| 905 | {104, 0x31}, |
| 906 | {98, 0x31}, |
| 907 | {110, 0x30}, |
| 908 | {104, 0x30}, |
| 909 | {98, 0x30}, |
| 910 | {110, 0x6}, |
| 911 | {104, 0x6}, |
| 912 | {98, 0x6}, |
| 913 | {110, 0x5}, |
| 914 | {104, 0x5}, |
| 915 | {98, 0x5}, |
| 916 | {110, 0x4}, |
| 917 | {104, 0x4}, |
| 918 | {98, 0x4}, |
| 919 | {110, 0x3}, |
| 920 | {104, 0x3}, |
| 921 | {98, 0x3}, |
| 922 | {110, 0x2}, |
| 923 | {104, 0x2}, |
| 924 | {98, 0x2}, |
| 925 | {110, 0x1}, |
| 926 | {104, 0x1}, |
| 927 | {98, 0x1}, |
| 928 | {110, 0x0}, |
| 929 | {104, 0x0}, |
| 930 | {98, 0x0}, |
| 931 | {97, 0}, |
| 932 | {96, 0}, |
| 933 | {95, 0}, |
| 934 | {94, 0}, |
| 935 | {93, 0}, |
| 936 | {92, 0}, |
| 937 | {91, 0}, |
| 938 | {90, 0}, |
| 939 | {89, 0}, |
| 940 | {88, 0}, |
| 941 | {87, 0}, |
| 942 | {86, 0}, |
| 943 | {85, 0}, |
| 944 | {84, 0}, |
| 945 | {83, 0}, |
| 946 | {82, 0}, |
| 947 | {81, 0}, |
| 948 | {80, 0}, |
| 949 | {79, 0}, |
| 950 | {78, 0}, |
| 951 | {77, 0}, |
| 952 | {76, 0}, |
| 953 | {75, 0}, |
| 954 | {74, 0}, |
| 955 | {73, 0}, |
| 956 | {72, 0}, |
| 957 | {71, 0}, |
| 958 | {70, 0}, |
| 959 | {69, 0}, |
| 960 | {68, 0}, |
| 961 | {67, 0}, |
| 962 | {66, 0}, |
| 963 | {65, 0}, |
| 964 | {64, 0}, |
| 965 | {63, 0}, |
| 966 | {62, 0}, |
| 967 | {61, 0}, |
| 968 | {60, 0}, |
| 969 | {59, 0}, |
| 970 | } |
| 971 | }; |
| 972 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 973 | static int il4965_fill_txpower_tbl(struct il_priv *il, u8 band, u16 channel, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 974 | u8 is_ht40, u8 ctrl_chan_high, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 975 | struct il4965_tx_power_db *tx_power_tbl) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 976 | { |
| 977 | u8 saturation_power; |
| 978 | s32 target_power; |
| 979 | s32 user_target_power; |
| 980 | s32 power_limit; |
| 981 | s32 current_temp; |
| 982 | s32 reg_limit; |
| 983 | s32 current_regulatory; |
| 984 | s32 txatten_grp = CALIB_CH_GROUP_MAX; |
| 985 | int i; |
| 986 | int c; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 987 | const struct il_channel_info *ch_info = NULL; |
| 988 | struct il_eeprom_calib_ch_info ch_eeprom_info; |
| 989 | const struct il_eeprom_calib_measure *measurement; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 990 | s16 voltage; |
| 991 | s32 init_voltage; |
| 992 | s32 voltage_compensation; |
| 993 | s32 degrees_per_05db_num; |
| 994 | s32 degrees_per_05db_denom; |
| 995 | s32 factory_temp; |
| 996 | s32 temperature_comp[2]; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 997 | s32 factory_gain_idx[2]; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 998 | s32 factory_actual_pwr[2]; |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 999 | s32 power_idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1000 | |
| 1001 | /* tx_power_user_lmt is in dBm, convert to half-dBm (half-dB units |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1002 | * are used for idxing into txpower table) */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1003 | user_target_power = 2 * il->tx_power_user_lmt; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1004 | |
| 1005 | /* Get current (RXON) channel, band, width */ |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1006 | D_TXPOWER("chan %d band %d is_ht40 %d\n", channel, band, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1007 | is_ht40); |
| 1008 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1009 | ch_info = il_get_channel_info(il, il->band, channel); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1010 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1011 | if (!il_is_channel_valid(ch_info)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1012 | return -EINVAL; |
| 1013 | |
| 1014 | /* get txatten group, used to select 1) thermal txpower adjustment |
| 1015 | * and 2) mimo txpower balance between Tx chains. */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1016 | txatten_grp = il4965_get_tx_atten_grp(channel); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1017 | if (txatten_grp < 0) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1018 | IL_ERR("Can't find txatten group for channel %d.\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1019 | channel); |
Greg Dietsche | 5c30c76 | 2011-06-02 21:06:09 -0500 | [diff] [blame] | 1020 | return txatten_grp; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1023 | D_TXPOWER("channel %d belongs to txatten group %d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1024 | channel, txatten_grp); |
| 1025 | |
| 1026 | if (is_ht40) { |
| 1027 | if (ctrl_chan_high) |
| 1028 | channel -= 2; |
| 1029 | else |
| 1030 | channel += 2; |
| 1031 | } |
| 1032 | |
| 1033 | /* hardware txpower limits ... |
| 1034 | * saturation (clipping distortion) txpowers are in half-dBm */ |
| 1035 | if (band) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1036 | saturation_power = il->calib_info->saturation_power24; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1037 | else |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1038 | saturation_power = il->calib_info->saturation_power52; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1039 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1040 | if (saturation_power < IL_TX_POWER_SATURATION_MIN || |
| 1041 | saturation_power > IL_TX_POWER_SATURATION_MAX) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1042 | if (band) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1043 | saturation_power = IL_TX_POWER_DEFAULT_SATURATION_24; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1044 | else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1045 | saturation_power = IL_TX_POWER_DEFAULT_SATURATION_52; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | /* regulatory txpower limits ... reg_limit values are in half-dBm, |
| 1049 | * max_power_avg values are in dBm, convert * 2 */ |
| 1050 | if (is_ht40) |
| 1051 | reg_limit = ch_info->ht40_max_power_avg * 2; |
| 1052 | else |
| 1053 | reg_limit = ch_info->max_power_avg * 2; |
| 1054 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1055 | if ((reg_limit < IL_TX_POWER_REGULATORY_MIN) || |
| 1056 | (reg_limit > IL_TX_POWER_REGULATORY_MAX)) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1057 | if (band) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1058 | reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_24; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1059 | else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1060 | reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_52; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | /* Interpolate txpower calibration values for this channel, |
| 1064 | * based on factory calibration tests on spaced channels. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1065 | il4965_interpolate_chan(il, channel, &ch_eeprom_info); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1066 | |
| 1067 | /* calculate tx gain adjustment based on power supply voltage */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1068 | voltage = le16_to_cpu(il->calib_info->voltage); |
| 1069 | init_voltage = (s32)le32_to_cpu(il->card_alive_init.voltage); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1070 | voltage_compensation = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1071 | il4965_get_voltage_compensation(voltage, init_voltage); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1072 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1073 | D_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1074 | init_voltage, |
| 1075 | voltage, voltage_compensation); |
| 1076 | |
| 1077 | /* get current temperature (Celsius) */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1078 | current_temp = max(il->temperature, IL_TX_POWER_TEMPERATURE_MIN); |
| 1079 | current_temp = min(il->temperature, IL_TX_POWER_TEMPERATURE_MAX); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1080 | current_temp = KELVIN_TO_CELSIUS(current_temp); |
| 1081 | |
| 1082 | /* select thermal txpower adjustment params, based on channel group |
| 1083 | * (same frequency group used for mimo txatten adjustment) */ |
| 1084 | degrees_per_05db_num = |
| 1085 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a; |
| 1086 | degrees_per_05db_denom = |
| 1087 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom; |
| 1088 | |
| 1089 | /* get per-chain txpower values from factory measurements */ |
| 1090 | for (c = 0; c < 2; c++) { |
| 1091 | measurement = &ch_eeprom_info.measurements[c][1]; |
| 1092 | |
| 1093 | /* txgain adjustment (in half-dB steps) based on difference |
| 1094 | * between factory and current temperature */ |
| 1095 | factory_temp = measurement->temperature; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1096 | il4965_math_div_round((current_temp - factory_temp) * |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1097 | degrees_per_05db_denom, |
| 1098 | degrees_per_05db_num, |
| 1099 | &temperature_comp[c]); |
| 1100 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1101 | factory_gain_idx[c] = measurement->gain_idx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1102 | factory_actual_pwr[c] = measurement->actual_pow; |
| 1103 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1104 | D_TXPOWER("chain = %d\n", c); |
| 1105 | D_TXPOWER("fctry tmp %d, " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1106 | "curr tmp %d, comp %d steps\n", |
| 1107 | factory_temp, current_temp, |
| 1108 | temperature_comp[c]); |
| 1109 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1110 | D_TXPOWER("fctry idx %d, fctry pwr %d\n", |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1111 | factory_gain_idx[c], |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1112 | factory_actual_pwr[c]); |
| 1113 | } |
| 1114 | |
| 1115 | /* for each of 33 bit-rates (including 1 for CCK) */ |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 1116 | for (i = 0; i < POWER_TBL_NUM_ENTRIES; i++) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1117 | u8 is_mimo_rate; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1118 | union il4965_tx_power_dual_stream tx_power; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1119 | |
| 1120 | /* for mimo, reduce each chain's txpower by half |
| 1121 | * (3dB, 6 steps), so total output power is regulatory |
| 1122 | * compliant. */ |
| 1123 | if (i & 0x8) { |
| 1124 | current_regulatory = reg_limit - |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1125 | IL_TX_POWER_MIMO_REGULATORY_COMPENSATION; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1126 | is_mimo_rate = 1; |
| 1127 | } else { |
| 1128 | current_regulatory = reg_limit; |
| 1129 | is_mimo_rate = 0; |
| 1130 | } |
| 1131 | |
| 1132 | /* find txpower limit, either hardware or regulatory */ |
| 1133 | power_limit = saturation_power - back_off_table[i]; |
| 1134 | if (power_limit > current_regulatory) |
| 1135 | power_limit = current_regulatory; |
| 1136 | |
| 1137 | /* reduce user's txpower request if necessary |
| 1138 | * for this rate on this channel */ |
| 1139 | target_power = user_target_power; |
| 1140 | if (target_power > power_limit) |
| 1141 | target_power = power_limit; |
| 1142 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1143 | D_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1144 | i, saturation_power - back_off_table[i], |
| 1145 | current_regulatory, user_target_power, |
| 1146 | target_power); |
| 1147 | |
| 1148 | /* for each of 2 Tx chains (radio transmitters) */ |
| 1149 | for (c = 0; c < 2; c++) { |
| 1150 | s32 atten_value; |
| 1151 | |
| 1152 | if (is_mimo_rate) |
| 1153 | atten_value = |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1154 | (s32)le32_to_cpu(il->card_alive_init. |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1155 | tx_atten[txatten_grp][c]); |
| 1156 | else |
| 1157 | atten_value = 0; |
| 1158 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1159 | /* calculate idx; higher idx means lower txpower */ |
| 1160 | power_idx = (u8) (factory_gain_idx[c] - |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1161 | (target_power - |
| 1162 | factory_actual_pwr[c]) - |
| 1163 | temperature_comp[c] - |
| 1164 | voltage_compensation + |
| 1165 | atten_value); |
| 1166 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1167 | /* D_TXPOWER("calculated txpower idx %d\n", |
| 1168 | power_idx); */ |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1169 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1170 | if (power_idx < get_min_power_idx(i, band)) |
| 1171 | power_idx = get_min_power_idx(i, band); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1172 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1173 | /* adjust 5 GHz idx to support negative idxes */ |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1174 | if (!band) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1175 | power_idx += 9; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1176 | |
| 1177 | /* CCK, rate 32, reduce txpower for CCK */ |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 1178 | if (i == POWER_TBL_CCK_ENTRY) |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1179 | power_idx += |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1180 | IL_TX_POWER_CCK_COMPENSATION_C_STEP; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1181 | |
| 1182 | /* stay within the table! */ |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1183 | if (power_idx > 107) { |
| 1184 | IL_WARN("txpower idx %d > 107\n", |
| 1185 | power_idx); |
| 1186 | power_idx = 107; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1187 | } |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1188 | if (power_idx < 0) { |
| 1189 | IL_WARN("txpower idx %d < 0\n", |
| 1190 | power_idx); |
| 1191 | power_idx = 0; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /* fill txpower command for this rate/chain */ |
| 1195 | tx_power.s.radio_tx_gain[c] = |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1196 | gain_table[band][power_idx].radio; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1197 | tx_power.s.dsp_predis_atten[c] = |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1198 | gain_table[band][power_idx].dsp; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1199 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1200 | D_TXPOWER("chain %d mimo %d idx %d " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1201 | "gain 0x%02x dsp %d\n", |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1202 | c, atten_value, power_idx, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1203 | tx_power.s.radio_tx_gain[c], |
| 1204 | tx_power.s.dsp_predis_atten[c]); |
| 1205 | } /* for each chain */ |
| 1206 | |
| 1207 | tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw); |
| 1208 | |
| 1209 | } /* for each rate */ |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1215 | * il4965_send_tx_power - Configure the TXPOWER level user limit |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1216 | * |
| 1217 | * Uses the active RXON for channel, band, and characteristics (ht40, high) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1218 | * The power limit is taken from il->tx_power_user_lmt. |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1219 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1220 | static int il4965_send_tx_power(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1221 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1222 | struct il4965_txpowertable_cmd cmd = { 0 }; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1223 | int ret; |
| 1224 | u8 band = 0; |
| 1225 | bool is_ht40 = false; |
| 1226 | u8 ctrl_chan_high = 0; |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 1227 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1228 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1229 | if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &il->status), |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1230 | "TX Power requested while scanning!\n")) |
| 1231 | return -EAGAIN; |
| 1232 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1233 | band = il->band == IEEE80211_BAND_2GHZ; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1234 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1235 | is_ht40 = iw4965_is_ht40_channel(ctx->active.flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1236 | |
| 1237 | if (is_ht40 && (ctx->active.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) |
| 1238 | ctrl_chan_high = 1; |
| 1239 | |
| 1240 | cmd.band = band; |
| 1241 | cmd.channel = ctx->active.channel; |
| 1242 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1243 | ret = il4965_fill_txpower_tbl(il, band, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1244 | le16_to_cpu(ctx->active.channel), |
| 1245 | is_ht40, ctrl_chan_high, &cmd.tx_power); |
| 1246 | if (ret) |
| 1247 | goto out; |
| 1248 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1249 | ret = il_send_cmd_pdu(il, |
Stanislaw Gruszka | 3b98c7f | 2011-08-26 16:29:35 +0200 | [diff] [blame] | 1250 | REPLY_TX_PWR_TBL_CMD, sizeof(cmd), &cmd); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1251 | |
| 1252 | out: |
| 1253 | return ret; |
| 1254 | } |
| 1255 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1256 | static int il4965_send_rxon_assoc(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1257 | struct il_rxon_context *ctx) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1258 | { |
| 1259 | int ret = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1260 | struct il4965_rxon_assoc_cmd rxon_assoc; |
| 1261 | const struct il_rxon_cmd *rxon1 = &ctx->staging; |
| 1262 | const struct il_rxon_cmd *rxon2 = &ctx->active; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1263 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1264 | if (rxon1->flags == rxon2->flags && |
| 1265 | rxon1->filter_flags == rxon2->filter_flags && |
| 1266 | rxon1->cck_basic_rates == rxon2->cck_basic_rates && |
| 1267 | rxon1->ofdm_ht_single_stream_basic_rates == |
| 1268 | rxon2->ofdm_ht_single_stream_basic_rates && |
| 1269 | rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1270 | rxon2->ofdm_ht_dual_stream_basic_rates && |
| 1271 | rxon1->rx_chain == rxon2->rx_chain && |
| 1272 | rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1273 | D_INFO("Using current RXON_ASSOC. Not resending.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | rxon_assoc.flags = ctx->staging.flags; |
| 1278 | rxon_assoc.filter_flags = ctx->staging.filter_flags; |
| 1279 | rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates; |
| 1280 | rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates; |
| 1281 | rxon_assoc.reserved = 0; |
| 1282 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1283 | ctx->staging.ofdm_ht_single_stream_basic_rates; |
| 1284 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1285 | ctx->staging.ofdm_ht_dual_stream_basic_rates; |
| 1286 | rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain; |
| 1287 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1288 | ret = il_send_cmd_pdu_async(il, REPLY_RXON_ASSOC, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1289 | sizeof(rxon_assoc), &rxon_assoc, NULL); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1290 | |
| 1291 | return ret; |
| 1292 | } |
| 1293 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1294 | static int il4965_commit_rxon(struct il_priv *il, struct il_rxon_context *ctx) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1295 | { |
| 1296 | /* cast away the const for active_rxon in this function */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1297 | struct il_rxon_cmd *active_rxon = (void *)&ctx->active; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1298 | int ret; |
| 1299 | bool new_assoc = |
| 1300 | !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); |
| 1301 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1302 | if (!il_is_alive(il)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1303 | return -EBUSY; |
| 1304 | |
| 1305 | if (!ctx->is_active) |
| 1306 | return 0; |
| 1307 | |
| 1308 | /* always get timestamp with Rx frame */ |
| 1309 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1310 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1311 | ret = il_check_rxon_cmd(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1312 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1313 | IL_ERR("Invalid RXON configuration. Not committing.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1314 | return -EINVAL; |
| 1315 | } |
| 1316 | |
| 1317 | /* |
| 1318 | * receive commit_rxon request |
| 1319 | * abort any previous channel switch if still in process |
| 1320 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1321 | if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status) && |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1322 | il->switch_channel != ctx->staging.channel) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1323 | D_11H("abort channel switch on %d\n", |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1324 | le16_to_cpu(il->switch_channel)); |
| 1325 | il_chswitch_done(il, false); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | /* If we don't need to send a full RXON, we can use |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1329 | * il_rxon_assoc_cmd which is used to reconfigure filter |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1330 | * and other flags for the current radio configuration. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1331 | if (!il_full_rxon_required(il, ctx)) { |
| 1332 | ret = il_send_rxon_assoc(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1333 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1334 | IL_ERR("Error setting RXON_ASSOC (%d)\n", ret); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1335 | return ret; |
| 1336 | } |
| 1337 | |
| 1338 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1339 | il_print_rx_config_cmd(il, ctx); |
Stanislaw Gruszka | 17e859a | 2011-07-27 15:37:43 +0200 | [diff] [blame] | 1340 | /* |
| 1341 | * We do not commit tx power settings while channel changing, |
| 1342 | * do it now if tx power changed. |
| 1343 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1344 | il_set_tx_power(il, il->tx_power_next, false); |
Stanislaw Gruszka | 17e859a | 2011-07-27 15:37:43 +0200 | [diff] [blame] | 1345 | return 0; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /* If we are currently associated and the new config requires |
| 1349 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1350 | * we must clear the associated from the active configuration |
| 1351 | * before we apply the new config */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1352 | if (il_is_associated_ctx(ctx) && new_assoc) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1353 | D_INFO("Toggling associated bit on current RXON\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1354 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1355 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1356 | ret = il_send_cmd_pdu(il, ctx->rxon_cmd, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1357 | sizeof(struct il_rxon_cmd), |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1358 | active_rxon); |
| 1359 | |
| 1360 | /* If the mask clearing failed then we set |
| 1361 | * active_rxon back to what it was previously */ |
| 1362 | if (ret) { |
| 1363 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1364 | IL_ERR("Error clearing ASSOC_MSK (%d)\n", ret); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1365 | return ret; |
| 1366 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1367 | il_clear_ucode_stations(il, ctx); |
| 1368 | il_restore_stations(il, ctx); |
| 1369 | ret = il4965_restore_default_wep_keys(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1370 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1371 | IL_ERR("Failed to restore WEP keys (%d)\n", ret); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1372 | return ret; |
| 1373 | } |
| 1374 | } |
| 1375 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1376 | D_INFO("Sending RXON\n" |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1377 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1378 | "* channel = %d\n" |
| 1379 | "* bssid = %pM\n", |
| 1380 | (new_assoc ? "" : "out"), |
| 1381 | le16_to_cpu(ctx->staging.channel), |
| 1382 | ctx->staging.bssid_addr); |
| 1383 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1384 | il_set_rxon_hwcrypto(il, ctx, |
| 1385 | !il->cfg->mod_params->sw_crypto); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1386 | |
| 1387 | /* Apply the new configuration |
| 1388 | * RXON unassoc clears the station table in uCode so restoration of |
| 1389 | * stations is needed after it (the RXON command) completes |
| 1390 | */ |
| 1391 | if (!new_assoc) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1392 | ret = il_send_cmd_pdu(il, ctx->rxon_cmd, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1393 | sizeof(struct il_rxon_cmd), &ctx->staging); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1394 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1395 | IL_ERR("Error setting new RXON (%d)\n", ret); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1396 | return ret; |
| 1397 | } |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1398 | D_INFO("Return from !new_assoc RXON.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1399 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1400 | il_clear_ucode_stations(il, ctx); |
| 1401 | il_restore_stations(il, ctx); |
| 1402 | ret = il4965_restore_default_wep_keys(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1403 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1404 | IL_ERR("Failed to restore WEP keys (%d)\n", ret); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1405 | return ret; |
| 1406 | } |
| 1407 | } |
| 1408 | if (new_assoc) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1409 | il->start_calib = 0; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1410 | /* Apply the new configuration |
| 1411 | * RXON assoc doesn't clear the station table in uCode, |
| 1412 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1413 | ret = il_send_cmd_pdu(il, ctx->rxon_cmd, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1414 | sizeof(struct il_rxon_cmd), &ctx->staging); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1415 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1416 | IL_ERR("Error setting new RXON (%d)\n", ret); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1417 | return ret; |
| 1418 | } |
| 1419 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); |
| 1420 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1421 | il_print_rx_config_cmd(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1422 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1423 | il4965_init_sensitivity(il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1424 | |
| 1425 | /* If we issue a new RXON command which required a tune then we must |
| 1426 | * send a new TXPOWER command or we won't be able to Tx any frames */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1427 | ret = il_set_tx_power(il, il->tx_power_next, true); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1428 | if (ret) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1429 | IL_ERR("Error sending TX power (%d)\n", ret); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1430 | return ret; |
| 1431 | } |
| 1432 | |
| 1433 | return 0; |
| 1434 | } |
| 1435 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1436 | static int il4965_hw_channel_switch(struct il_priv *il, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1437 | struct ieee80211_channel_switch *ch_switch) |
| 1438 | { |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 1439 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1440 | int rc; |
| 1441 | u8 band = 0; |
| 1442 | bool is_ht40 = false; |
| 1443 | u8 ctrl_chan_high = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1444 | struct il4965_channel_switch_cmd cmd; |
| 1445 | const struct il_channel_info *ch_info; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1446 | u32 switch_time_in_usec, ucode_switch_time; |
| 1447 | u16 ch; |
| 1448 | u32 tsf_low; |
| 1449 | u8 switch_count; |
| 1450 | u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval); |
| 1451 | struct ieee80211_vif *vif = ctx->vif; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1452 | band = il->band == IEEE80211_BAND_2GHZ; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1453 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1454 | is_ht40 = iw4965_is_ht40_channel(ctx->staging.flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1455 | |
| 1456 | if (is_ht40 && |
| 1457 | (ctx->staging.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) |
| 1458 | ctrl_chan_high = 1; |
| 1459 | |
| 1460 | cmd.band = band; |
| 1461 | cmd.expect_beacon = 0; |
| 1462 | ch = ch_switch->channel->hw_value; |
| 1463 | cmd.channel = cpu_to_le16(ch); |
| 1464 | cmd.rxon_flags = ctx->staging.flags; |
| 1465 | cmd.rxon_filter_flags = ctx->staging.filter_flags; |
| 1466 | switch_count = ch_switch->count; |
| 1467 | tsf_low = ch_switch->timestamp & 0x0ffffffff; |
| 1468 | /* |
| 1469 | * calculate the ucode channel switch time |
| 1470 | * adding TSF as one of the factor for when to switch |
| 1471 | */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1472 | if (il->ucode_beacon_time > tsf_low && beacon_interval) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1473 | if (switch_count > ((il->ucode_beacon_time - tsf_low) / |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1474 | beacon_interval)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1475 | switch_count -= (il->ucode_beacon_time - |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1476 | tsf_low) / beacon_interval; |
| 1477 | } else |
| 1478 | switch_count = 0; |
| 1479 | } |
| 1480 | if (switch_count <= 1) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1481 | cmd.switch_time = cpu_to_le32(il->ucode_beacon_time); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1482 | else { |
| 1483 | switch_time_in_usec = |
| 1484 | vif->bss_conf.beacon_int * switch_count * TIME_UNIT; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1485 | ucode_switch_time = il_usecs_to_beacons(il, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1486 | switch_time_in_usec, |
| 1487 | beacon_interval); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1488 | cmd.switch_time = il_add_beacon_time(il, |
| 1489 | il->ucode_beacon_time, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1490 | ucode_switch_time, |
| 1491 | beacon_interval); |
| 1492 | } |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1493 | D_11H("uCode time for the switch is 0x%x\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1494 | cmd.switch_time); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1495 | ch_info = il_get_channel_info(il, il->band, ch); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1496 | if (ch_info) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1497 | cmd.expect_beacon = il_is_channel_radar(ch_info); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1498 | else { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1499 | IL_ERR("invalid channel switch from %u to %u\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1500 | ctx->active.channel, ch); |
| 1501 | return -EFAULT; |
| 1502 | } |
| 1503 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1504 | rc = il4965_fill_txpower_tbl(il, band, ch, is_ht40, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1505 | ctrl_chan_high, &cmd.tx_power); |
| 1506 | if (rc) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1507 | D_11H("error:%d fill txpower_tbl\n", rc); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1508 | return rc; |
| 1509 | } |
| 1510 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1511 | return il_send_cmd_pdu(il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1512 | REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1516 | * il4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1517 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1518 | static void il4965_txq_update_byte_cnt_tbl(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1519 | struct il_tx_queue *txq, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1520 | u16 byte_cnt) |
| 1521 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1522 | struct il4965_scd_bc_tbl *scd_bc_tbl = il->scd_bc_tbls.addr; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1523 | int txq_id = txq->q.id; |
| 1524 | int write_ptr = txq->q.write_ptr; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1525 | int len = byte_cnt + IL_TX_CRC_SIZE + IL_TX_DELIMITER_SIZE; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1526 | __le16 bc_ent; |
| 1527 | |
| 1528 | WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX); |
| 1529 | |
| 1530 | bc_ent = cpu_to_le16(len & 0xFFF); |
| 1531 | /* Set up byte count within first 256 entries */ |
| 1532 | scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent; |
| 1533 | |
| 1534 | /* If within first 64 entries, duplicate at end */ |
| 1535 | if (write_ptr < TFD_QUEUE_SIZE_BC_DUP) |
| 1536 | scd_bc_tbl[txq_id]. |
| 1537 | tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent; |
| 1538 | } |
| 1539 | |
| 1540 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1541 | * il4965_hw_get_temperature - return the calibrated temperature (in Kelvin) |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 1542 | * @stats: Provides the temperature reading from the uCode |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1543 | * |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 1544 | * A return of <0 indicates bogus data in the stats |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1545 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1546 | static int il4965_hw_get_temperature(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1547 | { |
| 1548 | s32 temperature; |
| 1549 | s32 vt; |
| 1550 | s32 R1, R2, R3; |
| 1551 | u32 R4; |
| 1552 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1553 | if (test_bit(STATUS_TEMPERATURE, &il->status) && |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 1554 | (il->_4965.stats.flag & |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1555 | STATISTICS_REPLY_FLG_HT40_MODE_MSK)) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1556 | D_TEMP("Running HT40 temperature calibration\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1557 | R1 = (s32)le32_to_cpu(il->card_alive_init.therm_r1[1]); |
| 1558 | R2 = (s32)le32_to_cpu(il->card_alive_init.therm_r2[1]); |
| 1559 | R3 = (s32)le32_to_cpu(il->card_alive_init.therm_r3[1]); |
| 1560 | R4 = le32_to_cpu(il->card_alive_init.therm_r4[1]); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1561 | } else { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1562 | D_TEMP("Running temperature calibration\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1563 | R1 = (s32)le32_to_cpu(il->card_alive_init.therm_r1[0]); |
| 1564 | R2 = (s32)le32_to_cpu(il->card_alive_init.therm_r2[0]); |
| 1565 | R3 = (s32)le32_to_cpu(il->card_alive_init.therm_r3[0]); |
| 1566 | R4 = le32_to_cpu(il->card_alive_init.therm_r4[0]); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | /* |
| 1570 | * Temperature is only 23 bits, so sign extend out to 32. |
| 1571 | * |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 1572 | * NOTE If we haven't received a stats notification yet |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1573 | * with an updated temperature, use R4 provided to us in the |
| 1574 | * "initialize" ALIVE response. |
| 1575 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1576 | if (!test_bit(STATUS_TEMPERATURE, &il->status)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1577 | vt = sign_extend32(R4, 23); |
| 1578 | else |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 1579 | vt = sign_extend32(le32_to_cpu(il->_4965.stats. |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1580 | general.common.temperature), 23); |
| 1581 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1582 | D_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1583 | |
| 1584 | if (R3 == R1) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1585 | IL_ERR("Calibration conflict R1 == R3\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1586 | return -1; |
| 1587 | } |
| 1588 | |
| 1589 | /* Calculate temperature in degrees Kelvin, adjust by 97%. |
| 1590 | * Add offset to center the adjustment around 0 degrees Centigrade. */ |
| 1591 | temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2); |
| 1592 | temperature /= (R3 - R1); |
| 1593 | temperature = (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET; |
| 1594 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1595 | D_TEMP("Calibrated temperature: %dK, %dC\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1596 | temperature, KELVIN_TO_CELSIUS(temperature)); |
| 1597 | |
| 1598 | return temperature; |
| 1599 | } |
| 1600 | |
| 1601 | /* Adjust Txpower only if temperature variance is greater than threshold. */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1602 | #define IL_TEMPERATURE_THRESHOLD 3 |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1603 | |
| 1604 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1605 | * il4965_is_temp_calib_needed - determines if new calibration is needed |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1606 | * |
| 1607 | * If the temperature changed has changed sufficiently, then a recalibration |
| 1608 | * is needed. |
| 1609 | * |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1610 | * Assumes caller will replace il->last_temperature once calibration |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1611 | * executed. |
| 1612 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1613 | static int il4965_is_temp_calib_needed(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1614 | { |
| 1615 | int temp_diff; |
| 1616 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1617 | if (!test_bit(STATUS_STATISTICS, &il->status)) { |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 1618 | D_TEMP("Temperature not updated -- no stats.\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1619 | return 0; |
| 1620 | } |
| 1621 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1622 | temp_diff = il->temperature - il->last_temperature; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1623 | |
| 1624 | /* get absolute value */ |
| 1625 | if (temp_diff < 0) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1626 | D_POWER("Getting cooler, delta %d\n", temp_diff); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1627 | temp_diff = -temp_diff; |
| 1628 | } else if (temp_diff == 0) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1629 | D_POWER("Temperature unchanged\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1630 | else |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1631 | D_POWER("Getting warmer, delta %d\n", temp_diff); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1632 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1633 | if (temp_diff < IL_TEMPERATURE_THRESHOLD) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1634 | D_POWER(" => thermal txpower calib not needed\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1635 | return 0; |
| 1636 | } |
| 1637 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1638 | D_POWER(" => thermal txpower calib needed\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1639 | |
| 1640 | return 1; |
| 1641 | } |
| 1642 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1643 | static void il4965_temperature_calib(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1644 | { |
| 1645 | s32 temp; |
| 1646 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1647 | temp = il4965_hw_get_temperature(il); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1648 | if (IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1649 | return; |
| 1650 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1651 | if (il->temperature != temp) { |
| 1652 | if (il->temperature) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1653 | D_TEMP("Temperature changed " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1654 | "from %dC to %dC\n", |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1655 | KELVIN_TO_CELSIUS(il->temperature), |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1656 | KELVIN_TO_CELSIUS(temp)); |
| 1657 | else |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1658 | D_TEMP("Temperature " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1659 | "initialized to %dC\n", |
| 1660 | KELVIN_TO_CELSIUS(temp)); |
| 1661 | } |
| 1662 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1663 | il->temperature = temp; |
| 1664 | set_bit(STATUS_TEMPERATURE, &il->status); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1665 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1666 | if (!il->disable_tx_power_cal && |
| 1667 | unlikely(!test_bit(STATUS_SCANNING, &il->status)) && |
| 1668 | il4965_is_temp_calib_needed(il)) |
| 1669 | queue_work(il->workqueue, &il->txpower_work); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1670 | } |
| 1671 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1672 | static u16 il4965_get_hcmd_size(u8 cmd_id, u16 len) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1673 | { |
| 1674 | switch (cmd_id) { |
| 1675 | case REPLY_RXON: |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1676 | return (u16) sizeof(struct il4965_rxon_cmd); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1677 | default: |
| 1678 | return len; |
| 1679 | } |
| 1680 | } |
| 1681 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1682 | static u16 il4965_build_addsta_hcmd(const struct il_addsta_cmd *cmd, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1683 | u8 *data) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1684 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1685 | struct il4965_addsta_cmd *addsta = (struct il4965_addsta_cmd *)data; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1686 | addsta->mode = cmd->mode; |
| 1687 | memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify)); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1688 | memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo)); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1689 | addsta->station_flags = cmd->station_flags; |
| 1690 | addsta->station_flags_msk = cmd->station_flags_msk; |
| 1691 | addsta->tid_disable_tx = cmd->tid_disable_tx; |
| 1692 | addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid; |
| 1693 | addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid; |
| 1694 | addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn; |
| 1695 | addsta->sleep_tx_count = cmd->sleep_tx_count; |
| 1696 | addsta->reserved1 = cpu_to_le16(0); |
| 1697 | addsta->reserved2 = cpu_to_le16(0); |
| 1698 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1699 | return (u16)sizeof(struct il4965_addsta_cmd); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1700 | } |
| 1701 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1702 | static inline u32 il4965_get_scd_ssn(struct il4965_tx_resp *tx_resp) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1703 | { |
| 1704 | return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN; |
| 1705 | } |
| 1706 | |
| 1707 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1708 | * il4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1709 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1710 | static int il4965_tx_status_reply_tx(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1711 | struct il_ht_agg *agg, |
| 1712 | struct il4965_tx_resp *tx_resp, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1713 | int txq_id, u16 start_idx) |
| 1714 | { |
| 1715 | u16 status; |
| 1716 | struct agg_tx_status *frame_status = tx_resp->u.agg_status; |
| 1717 | struct ieee80211_tx_info *info = NULL; |
| 1718 | struct ieee80211_hdr *hdr = NULL; |
| 1719 | u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 1720 | int i, sh, idx; |
| 1721 | u16 seq; |
| 1722 | if (agg->wait_for_ba) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1723 | D_TX_REPLY("got tx response w/o block-ack\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1724 | |
| 1725 | agg->frame_count = tx_resp->frame_count; |
| 1726 | agg->start_idx = start_idx; |
| 1727 | agg->rate_n_flags = rate_n_flags; |
| 1728 | agg->bitmap = 0; |
| 1729 | |
| 1730 | /* num frames attempted by Tx command */ |
| 1731 | if (agg->frame_count == 1) { |
| 1732 | /* Only one frame was attempted; no block-ack will arrive */ |
| 1733 | status = le16_to_cpu(frame_status[0].status); |
| 1734 | idx = start_idx; |
| 1735 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1736 | D_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1737 | agg->frame_count, agg->start_idx, idx); |
| 1738 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1739 | info = IEEE80211_SKB_CB(il->txq[txq_id].txb[idx].skb); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1740 | info->status.rates[0].count = tx_resp->failure_frame + 1; |
| 1741 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1742 | info->flags |= il4965_tx_status_to_mac80211(status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1743 | il4965_hwrate_to_tx_control(il, rate_n_flags, info); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1744 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1745 | D_TX_REPLY("1 Frame 0x%x failure :%d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1746 | status & 0xff, tx_resp->failure_frame); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1747 | D_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1748 | |
| 1749 | agg->wait_for_ba = 0; |
| 1750 | } else { |
| 1751 | /* Two or more frames were attempted; expect block-ack */ |
| 1752 | u64 bitmap = 0; |
| 1753 | int start = agg->start_idx; |
| 1754 | |
Stanislaw Gruszka | 6ce1dc4 | 2011-08-26 15:49:28 +0200 | [diff] [blame] | 1755 | /* Construct bit-map of pending frames within Tx win */ |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1756 | for (i = 0; i < agg->frame_count; i++) { |
| 1757 | u16 sc; |
| 1758 | status = le16_to_cpu(frame_status[i].status); |
| 1759 | seq = le16_to_cpu(frame_status[i].sequence); |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 1760 | idx = SEQ_TO_IDX(seq); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1761 | txq_id = SEQ_TO_QUEUE(seq); |
| 1762 | |
| 1763 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 1764 | AGG_TX_STATE_ABORT_MSK)) |
| 1765 | continue; |
| 1766 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1767 | D_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1768 | agg->frame_count, txq_id, idx); |
| 1769 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1770 | hdr = il_tx_queue_get_hdr(il, txq_id, idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1771 | if (!hdr) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1772 | IL_ERR( |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1773 | "BUG_ON idx doesn't point to valid skb" |
| 1774 | " idx=%d, txq_id=%d\n", idx, txq_id); |
| 1775 | return -1; |
| 1776 | } |
| 1777 | |
| 1778 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 1779 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1780 | IL_ERR( |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1781 | "BUG_ON idx doesn't match seq control" |
| 1782 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 1783 | idx, SEQ_TO_SN(sc), hdr->seq_ctrl); |
| 1784 | return -1; |
| 1785 | } |
| 1786 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1787 | D_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1788 | i, idx, SEQ_TO_SN(sc)); |
| 1789 | |
| 1790 | sh = idx - start; |
| 1791 | if (sh > 64) { |
| 1792 | sh = (start - idx) + 0xff; |
| 1793 | bitmap = bitmap << sh; |
| 1794 | sh = 0; |
| 1795 | start = idx; |
| 1796 | } else if (sh < -64) |
| 1797 | sh = 0xff - (start - idx); |
| 1798 | else if (sh < 0) { |
| 1799 | sh = start - idx; |
| 1800 | start = idx; |
| 1801 | bitmap = bitmap << sh; |
| 1802 | sh = 0; |
| 1803 | } |
| 1804 | bitmap |= 1ULL << sh; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1805 | D_TX_REPLY("start=%d bitmap=0x%llx\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1806 | start, (unsigned long long)bitmap); |
| 1807 | } |
| 1808 | |
| 1809 | agg->bitmap = bitmap; |
| 1810 | agg->start_idx = start; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1811 | D_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1812 | agg->frame_count, agg->start_idx, |
| 1813 | (unsigned long long)agg->bitmap); |
| 1814 | |
| 1815 | if (bitmap) |
| 1816 | agg->wait_for_ba = 1; |
| 1817 | } |
| 1818 | return 0; |
| 1819 | } |
| 1820 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1821 | static u8 il4965_find_station(struct il_priv *il, const u8 *addr) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1822 | { |
| 1823 | int i; |
| 1824 | int start = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1825 | int ret = IL_INVALID_STATION; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1826 | unsigned long flags; |
| 1827 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1828 | if ((il->iw_mode == NL80211_IFTYPE_ADHOC)) |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1829 | start = IL_STA_ID; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1830 | |
| 1831 | if (is_broadcast_ether_addr(addr)) |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 1832 | return il->ctx.bcast_sta_id; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1833 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1834 | spin_lock_irqsave(&il->sta_lock, flags); |
| 1835 | for (i = start; i < il->hw_params.max_stations; i++) |
| 1836 | if (il->stations[i].used && |
| 1837 | (!compare_ether_addr(il->stations[i].sta.sta.addr, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1838 | addr))) { |
| 1839 | ret = i; |
| 1840 | goto out; |
| 1841 | } |
| 1842 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1843 | D_ASSOC("can not find STA %pM total %d\n", |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1844 | addr, il->num_stations); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1845 | |
| 1846 | out: |
| 1847 | /* |
| 1848 | * It may be possible that more commands interacting with stations |
| 1849 | * arrive before we completed processing the adding of |
| 1850 | * station |
| 1851 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1852 | if (ret != IL_INVALID_STATION && |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1853 | (!(il->stations[ret].used & IL_STA_UCODE_ACTIVE) || |
| 1854 | ((il->stations[ret].used & IL_STA_UCODE_ACTIVE) && |
| 1855 | (il->stations[ret].used & IL_STA_UCODE_INPROGRESS)))) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1856 | IL_ERR("Requested station info for sta %d before ready.\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1857 | ret); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1858 | ret = IL_INVALID_STATION; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1859 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1860 | spin_unlock_irqrestore(&il->sta_lock, flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1861 | return ret; |
| 1862 | } |
| 1863 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1864 | static int il4965_get_ra_sta_id(struct il_priv *il, struct ieee80211_hdr *hdr) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1865 | { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1866 | if (il->iw_mode == NL80211_IFTYPE_STATION) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1867 | return IL_AP_ID; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1868 | } else { |
| 1869 | u8 *da = ieee80211_get_DA(hdr); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1870 | return il4965_find_station(il, da); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | /** |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1875 | * il4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1876 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1877 | static void il4965_rx_reply_tx(struct il_priv *il, |
Stanislaw Gruszka | b73bb5f | 2011-08-26 14:37:54 +0200 | [diff] [blame] | 1878 | struct il_rx_buf *rxb) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1879 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 1880 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1881 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 1882 | int txq_id = SEQ_TO_QUEUE(sequence); |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1883 | int idx = SEQ_TO_IDX(sequence); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1884 | struct il_tx_queue *txq = &il->txq[txq_id]; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1885 | struct ieee80211_hdr *hdr; |
| 1886 | struct ieee80211_tx_info *info; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1887 | struct il4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1888 | u32 status = le32_to_cpu(tx_resp->u.status); |
| 1889 | int uninitialized_var(tid); |
| 1890 | int sta_id; |
| 1891 | int freed; |
| 1892 | u8 *qc = NULL; |
| 1893 | unsigned long flags; |
| 1894 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1895 | if (idx >= txq->q.n_bd || il_queue_used(&txq->q, idx) == 0) { |
| 1896 | IL_ERR("Read idx for DMA queue txq_id (%d) idx %d " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1897 | "is out of range [0-%d] %d %d\n", txq_id, |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1898 | idx, txq->q.n_bd, txq->q.write_ptr, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1899 | txq->q.read_ptr); |
| 1900 | return; |
| 1901 | } |
| 1902 | |
| 1903 | txq->time_stamp = jiffies; |
| 1904 | info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb); |
| 1905 | memset(&info->status, 0, sizeof(info->status)); |
| 1906 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1907 | hdr = il_tx_queue_get_hdr(il, txq_id, idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1908 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 1909 | qc = ieee80211_get_qos_ctl(hdr); |
| 1910 | tid = qc[0] & 0xf; |
| 1911 | } |
| 1912 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1913 | sta_id = il4965_get_ra_sta_id(il, hdr); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1914 | if (txq->sched_retry && unlikely(sta_id == IL_INVALID_STATION)) { |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 1915 | IL_ERR("Station not known\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1916 | return; |
| 1917 | } |
| 1918 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1919 | spin_lock_irqsave(&il->sta_lock, flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1920 | if (txq->sched_retry) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1921 | const u32 scd_ssn = il4965_get_scd_ssn(tx_resp); |
| 1922 | struct il_ht_agg *agg = NULL; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1923 | WARN_ON(!qc); |
| 1924 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1925 | agg = &il->stations[sta_id].tid[tid].agg; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1926 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1927 | il4965_tx_status_reply_tx(il, agg, tx_resp, txq_id, idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1928 | |
| 1929 | /* check if BAR is needed */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1930 | if ((tx_resp->frame_count == 1) && !il4965_is_tx_success(status)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1931 | info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; |
| 1932 | |
| 1933 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1934 | idx = il_queue_dec_wrap(scd_ssn & 0xff, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1935 | txq->q.n_bd); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1936 | D_TX_REPLY("Retry scheduler reclaim scd_ssn " |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1937 | "%d idx %d\n", scd_ssn , idx); |
| 1938 | freed = il4965_tx_queue_reclaim(il, txq_id, idx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1939 | if (qc) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1940 | il4965_free_tfds_in_queue(il, sta_id, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1941 | tid, freed); |
| 1942 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1943 | if (il->mac80211_registered && |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1944 | il_queue_space(&txq->q) > txq->q.low_mark && |
| 1945 | agg->state != IL_EMPTYING_HW_QUEUE_DELBA) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1946 | il_wake_queue(il, txq); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1947 | } |
| 1948 | } else { |
| 1949 | info->status.rates[0].count = tx_resp->failure_frame + 1; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1950 | info->flags |= il4965_tx_status_to_mac80211(status); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1951 | il4965_hwrate_to_tx_control(il, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1952 | le32_to_cpu(tx_resp->rate_n_flags), |
| 1953 | info); |
| 1954 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1955 | D_TX_REPLY("TXQ %d status %s (0x%08x) " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1956 | "rate_n_flags 0x%x retries %d\n", |
| 1957 | txq_id, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1958 | il4965_get_tx_fail_reason(status), status, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1959 | le32_to_cpu(tx_resp->rate_n_flags), |
| 1960 | tx_resp->failure_frame); |
| 1961 | |
Stanislaw Gruszka | 0c2c885 | 2011-11-15 12:30:17 +0100 | [diff] [blame] | 1962 | freed = il4965_tx_queue_reclaim(il, txq_id, idx); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1963 | if (qc && likely(sta_id != IL_INVALID_STATION)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1964 | il4965_free_tfds_in_queue(il, sta_id, tid, freed); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1965 | else if (sta_id == IL_INVALID_STATION) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1966 | D_TX_REPLY("Station not known\n"); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1967 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1968 | if (il->mac80211_registered && |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 1969 | il_queue_space(&txq->q) > txq->q.low_mark) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1970 | il_wake_queue(il, txq); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1971 | } |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1972 | if (qc && likely(sta_id != IL_INVALID_STATION)) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1973 | il4965_txq_check_empty(il, sta_id, tid, txq_id); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1974 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1975 | il4965_check_abort_status(il, tx_resp->frame_count, status); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1976 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1977 | spin_unlock_irqrestore(&il->sta_lock, flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1980 | static void il4965_rx_beacon_notif(struct il_priv *il, |
Stanislaw Gruszka | b73bb5f | 2011-08-26 14:37:54 +0200 | [diff] [blame] | 1981 | struct il_rx_buf *rxb) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1982 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 1983 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1984 | struct il4965_beacon_notif *beacon = (void *)pkt->u.raw; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1985 | u8 rate __maybe_unused = |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 1986 | il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1987 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 1988 | D_RX("beacon status %#x, retries:%d ibssmgr:%d " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1989 | "tsf:0x%.8x%.8x rate:%d\n", |
| 1990 | le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK, |
| 1991 | beacon->beacon_notify_hdr.failure_frame, |
| 1992 | le32_to_cpu(beacon->ibss_mgr_status), |
| 1993 | le32_to_cpu(beacon->high_tsf), |
| 1994 | le32_to_cpu(beacon->low_tsf), rate); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1995 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 1996 | il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 1999 | /* Set up 4965-specific Rx frame reply handlers */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2000 | static void il4965_rx_handler_setup(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2001 | { |
| 2002 | /* Legacy Rx frames */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2003 | il->rx_handlers[REPLY_RX] = il4965_rx_reply_rx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2004 | /* Tx response */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2005 | il->rx_handlers[REPLY_TX] = il4965_rx_reply_tx; |
| 2006 | il->rx_handlers[BEACON_NOTIFICATION] = il4965_rx_beacon_notif; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2009 | static struct il_hcmd_ops il4965_hcmd = { |
| 2010 | .rxon_assoc = il4965_send_rxon_assoc, |
| 2011 | .commit_rxon = il4965_commit_rxon, |
| 2012 | .set_rxon_chain = il4965_set_rxon_chain, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2013 | }; |
| 2014 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2015 | static void il4965_post_scan(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2016 | { |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 2017 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2018 | |
| 2019 | /* |
| 2020 | * Since setting the RXON may have been deferred while |
| 2021 | * performing the scan, fire one off if needed |
| 2022 | */ |
| 2023 | if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2024 | il_commit_rxon(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2025 | } |
| 2026 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2027 | static void il4965_post_associate(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2028 | { |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 2029 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2030 | struct ieee80211_vif *vif = ctx->vif; |
| 2031 | struct ieee80211_conf *conf = NULL; |
| 2032 | int ret = 0; |
| 2033 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2034 | if (!vif || !il->is_open) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2035 | return; |
| 2036 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2037 | if (test_bit(STATUS_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2038 | return; |
| 2039 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2040 | il_scan_cancel_timeout(il, 200); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2041 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2042 | conf = il_ieee80211_get_hw_conf(il->hw); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2043 | |
| 2044 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2045 | il_commit_rxon(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2046 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2047 | ret = il_send_rxon_timing(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2048 | if (ret) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 2049 | IL_WARN("RXON timing - " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2050 | "Attempting to continue.\n"); |
| 2051 | |
| 2052 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 2053 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2054 | il_set_rxon_ht(il, &il->current_ht_config); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2055 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2056 | if (il->cfg->ops->hcmd->set_rxon_chain) |
| 2057 | il->cfg->ops->hcmd->set_rxon_chain(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2058 | |
| 2059 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); |
| 2060 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2061 | D_ASSOC("assoc id %d beacon interval %d\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2062 | vif->bss_conf.aid, vif->bss_conf.beacon_int); |
| 2063 | |
| 2064 | if (vif->bss_conf.use_short_preamble) |
| 2065 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2066 | else |
| 2067 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2068 | |
| 2069 | if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) { |
| 2070 | if (vif->bss_conf.use_short_slot) |
| 2071 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2072 | else |
| 2073 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2074 | } |
| 2075 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2076 | il_commit_rxon(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2077 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 2078 | D_ASSOC("Associated as %d to: %pM\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2079 | vif->bss_conf.aid, ctx->active.bssid_addr); |
| 2080 | |
| 2081 | switch (vif->type) { |
| 2082 | case NL80211_IFTYPE_STATION: |
| 2083 | break; |
| 2084 | case NL80211_IFTYPE_ADHOC: |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2085 | il4965_send_beacon_cmd(il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2086 | break; |
| 2087 | default: |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 2088 | IL_ERR("%s Should not be called in %d mode\n", |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2089 | __func__, vif->type); |
| 2090 | break; |
| 2091 | } |
| 2092 | |
| 2093 | /* the chain noise calibration will enabled PM upon completion |
| 2094 | * If chain noise has already been run, then we need to enable |
| 2095 | * power management here */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2096 | if (il->chain_noise_data.state == IL_CHAIN_NOISE_DONE) |
| 2097 | il_power_update_mode(il, false); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2098 | |
| 2099 | /* Enable Rx differential gain and sensitivity calibrations */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2100 | il4965_chain_noise_reset(il); |
| 2101 | il->start_calib = 1; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2102 | } |
| 2103 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2104 | static void il4965_config_ap(struct il_priv *il) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2105 | { |
Stanislaw Gruszka | 7c2cde2 | 2011-11-15 11:29:04 +0100 | [diff] [blame] | 2106 | struct il_rxon_context *ctx = &il->ctx; |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2107 | struct ieee80211_vif *vif = ctx->vif; |
| 2108 | int ret = 0; |
| 2109 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2110 | lockdep_assert_held(&il->mutex); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2111 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2112 | if (test_bit(STATUS_EXIT_PENDING, &il->status)) |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2113 | return; |
| 2114 | |
| 2115 | /* The following should be done only at AP bring up */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2116 | if (!il_is_associated_ctx(ctx)) { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2117 | |
| 2118 | /* RXON - unassoc (to set timing command) */ |
| 2119 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2120 | il_commit_rxon(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2121 | |
| 2122 | /* RXON Timing */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2123 | ret = il_send_rxon_timing(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2124 | if (ret) |
Stanislaw Gruszka | 9406f79 | 2011-08-18 22:07:57 +0200 | [diff] [blame] | 2125 | IL_WARN("RXON timing failed - " |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2126 | "Attempting to continue.\n"); |
| 2127 | |
| 2128 | /* AP has all antennas */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2129 | il->chain_noise_data.active_chains = |
| 2130 | il->hw_params.valid_rx_ant; |
| 2131 | il_set_rxon_ht(il, &il->current_ht_config); |
| 2132 | if (il->cfg->ops->hcmd->set_rxon_chain) |
| 2133 | il->cfg->ops->hcmd->set_rxon_chain(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2134 | |
| 2135 | ctx->staging.assoc_id = 0; |
| 2136 | |
| 2137 | if (vif->bss_conf.use_short_preamble) |
| 2138 | ctx->staging.flags |= |
| 2139 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2140 | else |
| 2141 | ctx->staging.flags &= |
| 2142 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2143 | |
| 2144 | if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) { |
| 2145 | if (vif->bss_conf.use_short_slot) |
| 2146 | ctx->staging.flags |= |
| 2147 | RXON_FLG_SHORT_SLOT_MSK; |
| 2148 | else |
| 2149 | ctx->staging.flags &= |
| 2150 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 2151 | } |
| 2152 | /* need to send beacon cmd before committing assoc RXON! */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2153 | il4965_send_beacon_cmd(il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2154 | /* restore RXON assoc */ |
| 2155 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2156 | il_commit_rxon(il, ctx); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2157 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 2158 | il4965_send_beacon_cmd(il); |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2159 | } |
| 2160 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2161 | static struct il_hcmd_utils_ops il4965_hcmd_utils = { |
| 2162 | .get_hcmd_size = il4965_get_hcmd_size, |
| 2163 | .build_addsta_hcmd = il4965_build_addsta_hcmd, |
| 2164 | .request_scan = il4965_request_scan, |
| 2165 | .post_scan = il4965_post_scan, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2166 | }; |
| 2167 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2168 | static struct il_lib_ops il4965_lib = { |
| 2169 | .set_hw_params = il4965_hw_set_hw_params, |
| 2170 | .txq_update_byte_cnt_tbl = il4965_txq_update_byte_cnt_tbl, |
| 2171 | .txq_attach_buf_to_tfd = il4965_hw_txq_attach_buf_to_tfd, |
| 2172 | .txq_free_tfd = il4965_hw_txq_free_tfd, |
| 2173 | .txq_init = il4965_hw_tx_queue_init, |
| 2174 | .rx_handler_setup = il4965_rx_handler_setup, |
| 2175 | .is_valid_rtc_data_addr = il4965_hw_valid_rtc_data_addr, |
| 2176 | .init_alive_start = il4965_init_alive_start, |
| 2177 | .load_ucode = il4965_load_bsm, |
| 2178 | .dump_nic_error_log = il4965_dump_nic_error_log, |
| 2179 | .dump_fh = il4965_dump_fh, |
| 2180 | .set_channel_switch = il4965_hw_channel_switch, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2181 | .apm_ops = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2182 | .init = il_apm_init, |
| 2183 | .config = il4965_nic_config, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2184 | }, |
| 2185 | .eeprom_ops = { |
| 2186 | .regulatory_bands = { |
| 2187 | EEPROM_REGULATORY_BAND_1_CHANNELS, |
| 2188 | EEPROM_REGULATORY_BAND_2_CHANNELS, |
| 2189 | EEPROM_REGULATORY_BAND_3_CHANNELS, |
| 2190 | EEPROM_REGULATORY_BAND_4_CHANNELS, |
| 2191 | EEPROM_REGULATORY_BAND_5_CHANNELS, |
| 2192 | EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS, |
| 2193 | EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS |
| 2194 | }, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2195 | .acquire_semaphore = il4965_eeprom_acquire_semaphore, |
| 2196 | .release_semaphore = il4965_eeprom_release_semaphore, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2197 | }, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2198 | .send_tx_power = il4965_send_tx_power, |
| 2199 | .update_chain_flags = il4965_update_chain_flags, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2200 | .temp_ops = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2201 | .temperature = il4965_temperature_calib, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2202 | }, |
| 2203 | .debugfs_ops = { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2204 | .rx_stats_read = il4965_ucode_rx_stats_read, |
| 2205 | .tx_stats_read = il4965_ucode_tx_stats_read, |
| 2206 | .general_stats_read = il4965_ucode_general_stats_read, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2207 | }, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2208 | }; |
| 2209 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2210 | static const struct il_legacy_ops il4965_legacy_ops = { |
| 2211 | .post_associate = il4965_post_associate, |
| 2212 | .config_ap = il4965_config_ap, |
| 2213 | .manage_ibss_station = il4965_manage_ibss_station, |
| 2214 | .update_bcast_stations = il4965_update_bcast_stations, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2215 | }; |
| 2216 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2217 | struct ieee80211_ops il4965_hw_ops = { |
| 2218 | .tx = il4965_mac_tx, |
| 2219 | .start = il4965_mac_start, |
| 2220 | .stop = il4965_mac_stop, |
| 2221 | .add_interface = il_mac_add_interface, |
| 2222 | .remove_interface = il_mac_remove_interface, |
| 2223 | .change_interface = il_mac_change_interface, |
| 2224 | .config = il_mac_config, |
| 2225 | .configure_filter = il4965_configure_filter, |
| 2226 | .set_key = il4965_mac_set_key, |
| 2227 | .update_tkip_key = il4965_mac_update_tkip_key, |
| 2228 | .conf_tx = il_mac_conf_tx, |
| 2229 | .reset_tsf = il_mac_reset_tsf, |
| 2230 | .bss_info_changed = il_mac_bss_info_changed, |
| 2231 | .ampdu_action = il4965_mac_ampdu_action, |
| 2232 | .hw_scan = il_mac_hw_scan, |
| 2233 | .sta_add = il4965_mac_sta_add, |
| 2234 | .sta_remove = il_mac_sta_remove, |
| 2235 | .channel_switch = il4965_mac_channel_switch, |
| 2236 | .tx_last_beacon = il_mac_tx_last_beacon, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2237 | }; |
| 2238 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2239 | static const struct il_ops il4965_ops = { |
| 2240 | .lib = &il4965_lib, |
| 2241 | .hcmd = &il4965_hcmd, |
| 2242 | .utils = &il4965_hcmd_utils, |
| 2243 | .led = &il4965_led_ops, |
| 2244 | .legacy = &il4965_legacy_ops, |
| 2245 | .ieee80211_ops = &il4965_hw_ops, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2246 | }; |
| 2247 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2248 | static struct il_base_params il4965_base_params = { |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 2249 | .eeprom_size = IL4965_EEPROM_IMG_SIZE, |
| 2250 | .num_of_queues = IL49_NUM_QUEUES, |
| 2251 | .num_of_ampdu_queues = IL49_NUM_AMPDU_QUEUES, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2252 | .pll_cfg_val = 0, |
| 2253 | .set_l0s = true, |
| 2254 | .use_bsm = true, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2255 | .led_compensation = 61, |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 2256 | .chain_noise_num_beacons = IL4965_CAL_NUM_BEACONS, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2257 | .wd_timeout = IL_DEF_WD_TIMEOUT, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2258 | .temperature_kelvin = true, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2259 | .ucode_tracing = true, |
| 2260 | .sensitivity_calib_by_driver = true, |
| 2261 | .chain_noise_calib_by_driver = true, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2262 | }; |
| 2263 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2264 | struct il_cfg il4965_cfg = { |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2265 | .name = "Intel(R) Wireless WiFi Link 4965AGN", |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 2266 | .fw_name_pre = IL4965_FW_PRE, |
| 2267 | .ucode_api_max = IL4965_UCODE_API_MAX, |
| 2268 | .ucode_api_min = IL4965_UCODE_API_MIN, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2269 | .sku = IL_SKU_A|IL_SKU_G|IL_SKU_N, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2270 | .valid_tx_ant = ANT_AB, |
| 2271 | .valid_rx_ant = ANT_ABC, |
| 2272 | .eeprom_ver = EEPROM_4965_EEPROM_VERSION, |
| 2273 | .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 2274 | .ops = &il4965_ops, |
| 2275 | .mod_params = &il4965_mod_params, |
| 2276 | .base_params = &il4965_base_params, |
| 2277 | .led_mode = IL_LED_BLINK, |
Wey-Yi Guy | 4bc85c1 | 2011-02-21 11:11:05 -0800 | [diff] [blame] | 2278 | /* |
| 2279 | * Force use of chains B and C for scan RX on 5 GHz band |
| 2280 | * because the device has off-channel reception on chain A. |
| 2281 | */ |
| 2282 | .scan_rx_antennas[IEEE80211_BAND_5GHZ] = ANT_BC, |
| 2283 | }; |
| 2284 | |
| 2285 | /* Module firmware */ |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 2286 | MODULE_FIRMWARE(IL4965_MODULE_FIRMWARE(IL4965_UCODE_API_MAX)); |