blob: a4b42cc4c4c7509663e3c346fb9529569c0bda0f [file] [log] [blame]
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001/******************************************************************************
2 *
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08003 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08004 *
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 Guy4bc85c12011-02-21 11:11:05 -080036#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 Guybe663ab2011-02-21 11:27:26 -080045#include "iwl-4965-calib.h"
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -080046#include "iwl-sta.h"
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080047#include "iwl-4965.h"
48#include "iwl-4965-debugfs.h"
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -080049
Stanislaw Gruszka56e7a8c2011-08-30 12:45:25 +020050/******************************************************************************
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 */
62int 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
84void 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
91int 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;
108err:
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
117void 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 Gruszkafc19cbd2011-08-29 16:59:15 +0200124/* Send led command */
125static int
126il4965_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 */
145void il4965_led_enable(struct il_priv *il)
146{
147 _il_wr(il, CSR_LED_REG, CSR_LED_REG_TRUN_ON);
148}
149
150const struct il_led_ops il4965_led_ops = {
151 .cmd = il4965_send_led_cmd,
152};
153
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200154static int il4965_send_tx_power(struct il_priv *il);
155static int il4965_hw_get_temperature(struct il_priv *il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800156
157/* Highest firmware API version supported */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100158#define IL4965_UCODE_API_MAX 2
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800159
160/* Lowest firmware API version supported */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100161#define IL4965_UCODE_API_MIN 2
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800162
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100163#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 Guy4bc85c12011-02-21 11:11:05 -0800166
167/* check contents of special bootstrap uCode SRAM */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200168static int il4965_verify_bsm(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800169{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200170 __le32 *image = il->ucode_boot.v_addr;
171 u32 len = il->ucode_boot.len;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800172 u32 reg;
173 u32 val;
174
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100175 D_INFO("Begin verify bsm\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800176
177 /* verify BSM SRAM contents */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200178 val = il_rd_prph(il, BSM_WR_DWCOUNT_REG);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800179 for (reg = BSM_SRAM_LOWER_BOUND;
180 reg < BSM_SRAM_LOWER_BOUND + len;
181 reg += sizeof(u32), image++) {
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200182 val = il_rd_prph(il, reg);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800183 if (val != le32_to_cpu(*image)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200184 IL_ERR("BSM uCode verification failed at "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800185 "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 Gruszka58de00a2011-11-15 11:21:01 +0100193 D_INFO("BSM bootstrap uCode image OK\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800194
195 return 0;
196}
197
198/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200199 * il4965_load_bsm - Load bootstrap instructions
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800200 *
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 Gruszka46bc8d42011-10-24 16:49:25 +0200230static int il4965_load_bsm(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800231{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200232 __le32 *image = il->ucode_boot.v_addr;
233 u32 len = il->ucode_boot.len;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800234 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 Gruszka58de00a2011-11-15 11:21:01 +0100243 D_INFO("Begin load bsm\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800244
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200245 il->ucode_type = UCODE_RT;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800246
247 /* make sure bootstrap program is no larger than BSM's SRAM size */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100248 if (len > IL49_MAX_BSM_SIZE)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800249 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 Gruszkae2ebc832011-10-24 15:41:30 +0200253 * NOTE: il_init_alive_start() will replace these values,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800254 * after the "initialize" uCode has run, to point to
255 * runtime/protocol instructions and backup data cache.
256 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200257 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 Guy4bc85c12011-02-21 11:11:05 -0800261
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200262 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 Guy4bc85c12011-02-21 11:11:05 -0800266
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 Gruszkadb54eb52011-08-24 21:06:33 +0200271 _il_wr_prph(il, reg_offset, le32_to_cpu(*image));
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800272
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200273 ret = il4965_verify_bsm(il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800274 if (ret)
275 return ret;
276
277 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200278 il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0);
279 il_wr_prph(il,
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100280 BSM_WR_MEM_DST_REG, IL49_RTC_INST_LOWER_BOUND);
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200281 il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800282
283 /* Load bootstrap code into instruction SRAM now,
284 * to prepare to load "initialize" uCode */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200285 il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800286
287 /* Wait for load of bootstrap uCode to finish */
288 for (i = 0; i < 100; i++) {
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200289 done = il_rd_prph(il, BSM_WR_CTRL_REG);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800290 if (!(done & BSM_WR_CTRL_REG_BIT_START))
291 break;
292 udelay(10);
293 }
294 if (i < 100)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100295 D_INFO("BSM write complete, poll %d iterations\n", i);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800296 else {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200297 IL_ERR("BSM write did not complete!\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800298 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 Gruszkadb54eb52011-08-24 21:06:33 +0200303 il_wr_prph(il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800304 BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800305
306
307 return 0;
308}
309
310/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200311 * il4965_set_ucode_ptrs - Set uCode address location
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800312 *
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 Gruszka46bc8d42011-10-24 16:49:25 +0200319static int il4965_set_ucode_ptrs(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800320{
321 dma_addr_t pinst;
322 dma_addr_t pdata;
323 int ret = 0;
324
325 /* bits 35:4 for 4965 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200326 pinst = il->ucode_code.p_addr >> 4;
327 pdata = il->ucode_data_backup.p_addr >> 4;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800328
329 /* Tell bootstrap uCode where to find image to load */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200330 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 Gruszka46bc8d42011-10-24 16:49:25 +0200333 il->ucode_data.len);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800334
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 Gruszkadb54eb52011-08-24 21:06:33 +0200337 il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200338 il->ucode_code.len | BSM_DRAM_INST_LOAD);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100339 D_INFO("Runtime uCode pointers are set.\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800340
341 return ret;
342}
343
344/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200345 * il4965_init_alive_start - Called after REPLY_ALIVE notification received
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800346 *
347 * Called after REPLY_ALIVE notification received from "initialize" uCode.
348 *
349 * The 4965 "initialize" ALIVE reply contains calibration data for:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200350 * Voltage, temperature, and MIMO tx gain correction, now stored in il
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800351 * (3945 does not contain this data).
352 *
353 * Tell "initialize" uCode to go ahead and load the runtime uCode.
354*/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200355static void il4965_init_alive_start(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800356{
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 Gruszka46bc8d42011-10-24 16:49:25 +0200360 if (il4965_verify_ucode(il)) {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800361 /* Runtime instruction load was bad;
362 * take it all the way back down so we can try again */
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100363 D_INFO("Bad \"initialize\" uCode load.\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800364 goto restart;
365 }
366
367 /* Calculate temperature */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200368 il->temperature = il4965_hw_get_temperature(il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800369
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 Gruszka58de00a2011-11-15 11:21:01 +0100373 D_INFO("Initialization Alive received.\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200374 if (il4965_set_ucode_ptrs(il)) {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800375 /* Runtime instruction load won't happen;
376 * take it all the way back down so we can try again */
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100377 D_INFO("Couldn't set up uCode pointers.\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800378 goto restart;
379 }
380 return;
381
382restart:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200383 queue_work(il->workqueue, &il->restart);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800384}
385
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800386static bool iw4965_is_ht40_channel(__le32 rxon_flags)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800387{
388 int chan_mod = le32_to_cpu(rxon_flags & RXON_FLG_CHANNEL_MODE_MSK)
389 >> RXON_FLG_CHANNEL_MODE_POS;
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200390 return (chan_mod == CHANNEL_MODE_PURE_40 ||
391 chan_mod == CHANNEL_MODE_MIXED);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800392}
393
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200394static void il4965_nic_config(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800395{
396 unsigned long flags;
397 u16 radio_cfg;
398
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200399 spin_lock_irqsave(&il->lock, flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800400
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200401 radio_cfg = il_eeprom_query16(il, EEPROM_RADIO_CONFIG);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800402
403 /* write radio config values to register */
404 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200405 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800406 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 Gruszka46bc8d42011-10-24 16:49:25 +0200411 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800412 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
413 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
414
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200415 il->calib_info = (struct il_eeprom_calib_info *)
416 il_eeprom_query_addr(il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800417 EEPROM_4965_CALIB_TXPOWER_OFFSET);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800418
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200419 spin_unlock_irqrestore(&il->lock, flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800420}
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 Gruszka46bc8d42011-10-24 16:49:25 +0200425static void il4965_chain_noise_reset(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800426{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200427 struct il_chain_noise_data *data = &(il->chain_noise_data);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800428
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200429 if (data->state == IL_CHAIN_NOISE_ALIVE &&
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200430 il_is_any_associated(il)) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200431 struct il_calib_diff_gain_cmd cmd;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800432
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 Gruszkae2ebc832011-10-24 15:41:30 +0200443 cmd.hdr.op_code = IL_PHY_CALIBRATE_DIFF_GAIN_CMD;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800444 cmd.diff_gain_a = 0;
445 cmd.diff_gain_b = 0;
446 cmd.diff_gain_c = 0;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200447 if (il_send_cmd_pdu(il, REPLY_PHY_CALIBRATION_CMD,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800448 sizeof(cmd), &cmd))
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200449 IL_ERR(
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800450 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200451 data->state = IL_CHAIN_NOISE_ACCUMULATE;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100452 D_CALIB("Run chain_noise_calibrate\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800453 }
454}
455
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200456static struct il_sensitivity_ranges il4965_sensitivity = {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800457 .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 Gruszka46bc8d42011-10-24 16:49:25 +0200483static void il4965_set_ct_threshold(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800484{
485 /* want Kelvin */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200486 il->hw_params.ct_kill_threshold =
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800487 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY);
488}
489
490/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200491 * il4965_hw_set_hw_params
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800492 *
493 * Called when initializing driver
494 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200495static int il4965_hw_set_hw_params(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800496{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200497 if (il->cfg->mod_params->num_of_queues >= IL_MIN_NUM_QUEUES &&
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100498 il->cfg->mod_params->num_of_queues <= IL49_NUM_QUEUES)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200499 il->cfg->base_params->num_of_queues =
500 il->cfg->mod_params->num_of_queues;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800501
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200502 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 Gruszkae2ebc832011-10-24 15:41:30 +0200506 sizeof(struct il4965_scd_bc_tbl);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200507 il->hw_params.tfd_size = sizeof(struct il_tfd);
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100508 il->hw_params.max_stations = IL4965_STATION_COUNT;
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +0100509 il->ctx.bcast_sta_id = IL4965_BROADCAST_ID;
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100510 il->hw_params.max_data_size = IL49_RTC_DATA_SIZE;
511 il->hw_params.max_inst_size = IL49_RTC_INST_SIZE;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200512 il->hw_params.max_bsm_size = BSM_SRAM_SIZE;
513 il->hw_params.ht40_channel = BIT(IEEE80211_BAND_5GHZ);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800514
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200515 il->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800516
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200517 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 Guy4bc85c12011-02-21 11:11:05 -0800521
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200522 il4965_set_ct_threshold(il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800523
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200524 il->hw_params.sens = &il4965_sensitivity;
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100525 il->hw_params.beacon_time_tsf_bits = IL4965_EXT_BEACON_TIME_POS;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800526
527 return 0;
528}
529
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200530static s32 il4965_math_div_round(s32 num, s32 denom, s32 *res)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800531{
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 Gruszkae2ebc832011-10-24 15:41:30 +0200549 * il4965_get_voltage_compensation - Power supply voltage comp for txpower
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800550 *
551 * Determines power supply voltage compensation for txpower calculations.
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100552 * Returns number of 1/2-dB steps to subtract from gain table idx,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800553 * 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 Gruszka0c2c8852011-11-15 12:30:17 +0100557 * Lower voltage requires more gain (lower gain table idx).
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800558 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200559static s32 il4965_get_voltage_compensation(s32 eeprom_voltage,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800560 s32 current_voltage)
561{
562 s32 comp = 0;
563
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200564 if (TX_POWER_IL_ILLEGAL_VOLTAGE == eeprom_voltage ||
565 TX_POWER_IL_ILLEGAL_VOLTAGE == current_voltage)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800566 return 0;
567
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200568 il4965_math_div_round(current_voltage - eeprom_voltage,
569 TX_POWER_IL_VOLTAGE_CODES_PER_03V, &comp);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800570
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 Gruszkae2ebc832011-10-24 15:41:30 +0200579static s32 il4965_get_tx_atten_grp(u16 channel)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800580{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200581 if (channel >= CALIB_IL_TX_ATTEN_GR5_FCH &&
582 channel <= CALIB_IL_TX_ATTEN_GR5_LCH)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800583 return CALIB_CH_GROUP_5;
584
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200585 if (channel >= CALIB_IL_TX_ATTEN_GR1_FCH &&
586 channel <= CALIB_IL_TX_ATTEN_GR1_LCH)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800587 return CALIB_CH_GROUP_1;
588
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200589 if (channel >= CALIB_IL_TX_ATTEN_GR2_FCH &&
590 channel <= CALIB_IL_TX_ATTEN_GR2_LCH)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800591 return CALIB_CH_GROUP_2;
592
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200593 if (channel >= CALIB_IL_TX_ATTEN_GR3_FCH &&
594 channel <= CALIB_IL_TX_ATTEN_GR3_LCH)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800595 return CALIB_CH_GROUP_3;
596
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200597 if (channel >= CALIB_IL_TX_ATTEN_GR4_FCH &&
598 channel <= CALIB_IL_TX_ATTEN_GR4_LCH)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800599 return CALIB_CH_GROUP_4;
600
Greg Dietsche8e638182011-06-02 21:06:08 -0500601 return -EINVAL;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800602}
603
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200604static u32 il4965_get_sub_band(const struct il_priv *il, u32 channel)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800605{
606 s32 b = -1;
607
608 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200609 if (il->calib_info->band_info[b].ch_from == 0)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800610 continue;
611
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200612 if (channel >= il->calib_info->band_info[b].ch_from &&
613 channel <= il->calib_info->band_info[b].ch_to)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800614 break;
615 }
616
617 return b;
618}
619
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200620static s32 il4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800621{
622 s32 val;
623
624 if (x2 == x1)
625 return y1;
626 else {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200627 il4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800628 return val + y2;
629 }
630}
631
632/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200633 * il4965_interpolate_chan - Interpolate factory measurements for one channel
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800634 *
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 Gruszka46bc8d42011-10-24 16:49:25 +0200640static int il4965_interpolate_chan(struct il_priv *il, u32 channel,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200641 struct il_eeprom_calib_ch_info *chan_info)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800642{
643 s32 s = -1;
644 u32 c;
645 u32 m;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200646 const struct il_eeprom_calib_measure *m1;
647 const struct il_eeprom_calib_measure *m2;
648 struct il_eeprom_calib_measure *omeas;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800649 u32 ch_i1;
650 u32 ch_i2;
651
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200652 s = il4965_get_sub_band(il, channel);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800653 if (s >= EEPROM_TX_POWER_BANDS) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200654 IL_ERR("Tx Power can not find channel %d\n", channel);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800655 return -1;
656 }
657
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200658 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 Guy4bc85c12011-02-21 11:11:05 -0800660 chan_info->ch_num = (u8) channel;
661
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100662 D_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800663 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 Gruszka46bc8d42011-10-24 16:49:25 +0200667 m1 = &(il->calib_info->band_info[s].ch1.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800668 measurements[c][m]);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200669 m2 = &(il->calib_info->band_info[s].ch2.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800670 measurements[c][m]);
671 omeas = &(chan_info->measurements[c][m]);
672
673 omeas->actual_pow =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200674 (u8) il4965_interpolate_value(channel, ch_i1,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800675 m1->actual_pow,
676 ch_i2,
677 m2->actual_pow);
678 omeas->gain_idx =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200679 (u8) il4965_interpolate_value(channel, ch_i1,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800680 m1->gain_idx, ch_i2,
681 m2->gain_idx);
682 omeas->temperature =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200683 (u8) il4965_interpolate_value(channel, ch_i1,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800684 m1->temperature,
685 ch_i2,
686 m2->temperature);
687 omeas->pa_det =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200688 (s8) il4965_interpolate_value(channel, ch_i1,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800689 m1->pa_det, ch_i2,
690 m2->pa_det);
691
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100692 D_TXPOWER(
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800693 "chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
694 m1->actual_pow, m2->actual_pow, omeas->actual_pow);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100695 D_TXPOWER(
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800696 "chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
697 m1->gain_idx, m2->gain_idx, omeas->gain_idx);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100698 D_TXPOWER(
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800699 "chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
700 m1->pa_det, m2->pa_det, omeas->pa_det);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100701 D_TXPOWER(
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800702 "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. */
713static 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 Gruszkae2ebc832011-10-24 15:41:30 +0200723static struct il4965_txpower_comp_entry {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800724 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 Gruszka0c2c8852011-11-15 12:30:17 +0100734static s32 get_min_power_idx(s32 rate_power_idx, u32 band)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800735{
736 if (!band) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100737 if ((rate_power_idx & 7) <= 4)
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +0200738 return MIN_TX_GAIN_IDX_52GHZ_EXT;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800739 }
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +0200740 return MIN_TX_GAIN_IDX;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800741}
742
743struct gain_entry {
744 u8 dsp;
745 u8 radio;
746};
747
748static const struct gain_entry gain_table[2][108] = {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100749 /* 5.2GHz power gain idx table */
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800750 {
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 Gruszka0c2c8852011-11-15 12:30:17 +0100860 /* 2.4GHz power gain idx table */
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800861 {
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 Gruszka46bc8d42011-10-24 16:49:25 +0200973static int il4965_fill_txpower_tbl(struct il_priv *il, u8 band, u16 channel,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800974 u8 is_ht40, u8 ctrl_chan_high,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200975 struct il4965_tx_power_db *tx_power_tbl)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800976{
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 Gruszkae2ebc832011-10-24 15:41:30 +0200987 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 Guy4bc85c12011-02-21 11:11:05 -0800990 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 Gruszka0c2c8852011-11-15 12:30:17 +0100997 s32 factory_gain_idx[2];
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800998 s32 factory_actual_pwr[2];
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100999 s32 power_idx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001000
1001 /* tx_power_user_lmt is in dBm, convert to half-dBm (half-dB units
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001002 * are used for idxing into txpower table) */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001003 user_target_power = 2 * il->tx_power_user_lmt;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001004
1005 /* Get current (RXON) channel, band, width */
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001006 D_TXPOWER("chan %d band %d is_ht40 %d\n", channel, band,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001007 is_ht40);
1008
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001009 ch_info = il_get_channel_info(il, il->band, channel);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001010
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001011 if (!il_is_channel_valid(ch_info))
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001012 return -EINVAL;
1013
1014 /* get txatten group, used to select 1) thermal txpower adjustment
1015 * and 2) mimo txpower balance between Tx chains. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001016 txatten_grp = il4965_get_tx_atten_grp(channel);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001017 if (txatten_grp < 0) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001018 IL_ERR("Can't find txatten group for channel %d.\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001019 channel);
Greg Dietsche5c30c762011-06-02 21:06:09 -05001020 return txatten_grp;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001021 }
1022
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001023 D_TXPOWER("channel %d belongs to txatten group %d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001024 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 Gruszka46bc8d42011-10-24 16:49:25 +02001036 saturation_power = il->calib_info->saturation_power24;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001037 else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001038 saturation_power = il->calib_info->saturation_power52;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001039
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001040 if (saturation_power < IL_TX_POWER_SATURATION_MIN ||
1041 saturation_power > IL_TX_POWER_SATURATION_MAX) {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001042 if (band)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001043 saturation_power = IL_TX_POWER_DEFAULT_SATURATION_24;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001044 else
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001045 saturation_power = IL_TX_POWER_DEFAULT_SATURATION_52;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001046 }
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 Gruszkae2ebc832011-10-24 15:41:30 +02001055 if ((reg_limit < IL_TX_POWER_REGULATORY_MIN) ||
1056 (reg_limit > IL_TX_POWER_REGULATORY_MAX)) {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001057 if (band)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001058 reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_24;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001059 else
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001060 reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_52;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001061 }
1062
1063 /* Interpolate txpower calibration values for this channel,
1064 * based on factory calibration tests on spaced channels. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001065 il4965_interpolate_chan(il, channel, &ch_eeprom_info);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001066
1067 /* calculate tx gain adjustment based on power supply voltage */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001068 voltage = le16_to_cpu(il->calib_info->voltage);
1069 init_voltage = (s32)le32_to_cpu(il->card_alive_init.voltage);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001070 voltage_compensation =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001071 il4965_get_voltage_compensation(voltage, init_voltage);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001072
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001073 D_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001074 init_voltage,
1075 voltage, voltage_compensation);
1076
1077 /* get current temperature (Celsius) */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001078 current_temp = max(il->temperature, IL_TX_POWER_TEMPERATURE_MIN);
1079 current_temp = min(il->temperature, IL_TX_POWER_TEMPERATURE_MAX);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001080 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 Gruszkae2ebc832011-10-24 15:41:30 +02001096 il4965_math_div_round((current_temp - factory_temp) *
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001097 degrees_per_05db_denom,
1098 degrees_per_05db_num,
1099 &temperature_comp[c]);
1100
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001101 factory_gain_idx[c] = measurement->gain_idx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001102 factory_actual_pwr[c] = measurement->actual_pow;
1103
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001104 D_TXPOWER("chain = %d\n", c);
1105 D_TXPOWER("fctry tmp %d, "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001106 "curr tmp %d, comp %d steps\n",
1107 factory_temp, current_temp,
1108 temperature_comp[c]);
1109
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001110 D_TXPOWER("fctry idx %d, fctry pwr %d\n",
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001111 factory_gain_idx[c],
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001112 factory_actual_pwr[c]);
1113 }
1114
1115 /* for each of 33 bit-rates (including 1 for CCK) */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001116 for (i = 0; i < POWER_TBL_NUM_ENTRIES; i++) {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001117 u8 is_mimo_rate;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001118 union il4965_tx_power_dual_stream tx_power;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001119
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 Gruszkae2ebc832011-10-24 15:41:30 +02001125 IL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001126 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 Gruszka58de00a2011-11-15 11:21:01 +01001143 D_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001144 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 Gruszka46bc8d42011-10-24 16:49:25 +02001154 (s32)le32_to_cpu(il->card_alive_init.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001155 tx_atten[txatten_grp][c]);
1156 else
1157 atten_value = 0;
1158
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001159 /* calculate idx; higher idx means lower txpower */
1160 power_idx = (u8) (factory_gain_idx[c] -
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001161 (target_power -
1162 factory_actual_pwr[c]) -
1163 temperature_comp[c] -
1164 voltage_compensation +
1165 atten_value);
1166
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001167/* D_TXPOWER("calculated txpower idx %d\n",
1168 power_idx); */
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001169
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001170 if (power_idx < get_min_power_idx(i, band))
1171 power_idx = get_min_power_idx(i, band);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001172
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001173 /* adjust 5 GHz idx to support negative idxes */
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001174 if (!band)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001175 power_idx += 9;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001176
1177 /* CCK, rate 32, reduce txpower for CCK */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001178 if (i == POWER_TBL_CCK_ENTRY)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001179 power_idx +=
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001180 IL_TX_POWER_CCK_COMPENSATION_C_STEP;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001181
1182 /* stay within the table! */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001183 if (power_idx > 107) {
1184 IL_WARN("txpower idx %d > 107\n",
1185 power_idx);
1186 power_idx = 107;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001187 }
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001188 if (power_idx < 0) {
1189 IL_WARN("txpower idx %d < 0\n",
1190 power_idx);
1191 power_idx = 0;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001192 }
1193
1194 /* fill txpower command for this rate/chain */
1195 tx_power.s.radio_tx_gain[c] =
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001196 gain_table[band][power_idx].radio;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001197 tx_power.s.dsp_predis_atten[c] =
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001198 gain_table[band][power_idx].dsp;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001199
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001200 D_TXPOWER("chain %d mimo %d idx %d "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001201 "gain 0x%02x dsp %d\n",
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001202 c, atten_value, power_idx,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001203 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 Gruszkae2ebc832011-10-24 15:41:30 +02001215 * il4965_send_tx_power - Configure the TXPOWER level user limit
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001216 *
1217 * Uses the active RXON for channel, band, and characteristics (ht40, high)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001218 * The power limit is taken from il->tx_power_user_lmt.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001219 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001220static int il4965_send_tx_power(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001221{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001222 struct il4965_txpowertable_cmd cmd = { 0 };
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001223 int ret;
1224 u8 band = 0;
1225 bool is_ht40 = false;
1226 u8 ctrl_chan_high = 0;
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001227 struct il_rxon_context *ctx = &il->ctx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001228
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001229 if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &il->status),
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001230 "TX Power requested while scanning!\n"))
1231 return -EAGAIN;
1232
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001233 band = il->band == IEEE80211_BAND_2GHZ;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001234
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001235 is_ht40 = iw4965_is_ht40_channel(ctx->active.flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001236
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 Gruszka46bc8d42011-10-24 16:49:25 +02001243 ret = il4965_fill_txpower_tbl(il, band,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001244 le16_to_cpu(ctx->active.channel),
1245 is_ht40, ctrl_chan_high, &cmd.tx_power);
1246 if (ret)
1247 goto out;
1248
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001249 ret = il_send_cmd_pdu(il,
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001250 REPLY_TX_PWR_TBL_CMD, sizeof(cmd), &cmd);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001251
1252out:
1253 return ret;
1254}
1255
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001256static int il4965_send_rxon_assoc(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001257 struct il_rxon_context *ctx)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001258{
1259 int ret = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001260 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 Guy4bc85c12011-02-21 11:11:05 -08001263
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001264 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 Gruszka58de00a2011-11-15 11:21:01 +01001273 D_INFO("Using current RXON_ASSOC. Not resending.\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001274 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 Gruszka46bc8d42011-10-24 16:49:25 +02001288 ret = il_send_cmd_pdu_async(il, REPLY_RXON_ASSOC,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001289 sizeof(rxon_assoc), &rxon_assoc, NULL);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001290
1291 return ret;
1292}
1293
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001294static int il4965_commit_rxon(struct il_priv *il, struct il_rxon_context *ctx)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001295{
1296 /* cast away the const for active_rxon in this function */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001297 struct il_rxon_cmd *active_rxon = (void *)&ctx->active;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001298 int ret;
1299 bool new_assoc =
1300 !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
1301
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001302 if (!il_is_alive(il))
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001303 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 Gruszka46bc8d42011-10-24 16:49:25 +02001311 ret = il_check_rxon_cmd(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001312 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001313 IL_ERR("Invalid RXON configuration. Not committing.\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001314 return -EINVAL;
1315 }
1316
1317 /*
1318 * receive commit_rxon request
1319 * abort any previous channel switch if still in process
1320 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001321 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status) &&
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001322 il->switch_channel != ctx->staging.channel) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001323 D_11H("abort channel switch on %d\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001324 le16_to_cpu(il->switch_channel));
1325 il_chswitch_done(il, false);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001326 }
1327
1328 /* If we don't need to send a full RXON, we can use
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001329 * il_rxon_assoc_cmd which is used to reconfigure filter
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001330 * and other flags for the current radio configuration. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001331 if (!il_full_rxon_required(il, ctx)) {
1332 ret = il_send_rxon_assoc(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001333 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001334 IL_ERR("Error setting RXON_ASSOC (%d)\n", ret);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001335 return ret;
1336 }
1337
1338 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001339 il_print_rx_config_cmd(il, ctx);
Stanislaw Gruszka17e859a2011-07-27 15:37:43 +02001340 /*
1341 * We do not commit tx power settings while channel changing,
1342 * do it now if tx power changed.
1343 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001344 il_set_tx_power(il, il->tx_power_next, false);
Stanislaw Gruszka17e859a2011-07-27 15:37:43 +02001345 return 0;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001346 }
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 Gruszkae2ebc832011-10-24 15:41:30 +02001352 if (il_is_associated_ctx(ctx) && new_assoc) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001353 D_INFO("Toggling associated bit on current RXON\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001354 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1355
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001356 ret = il_send_cmd_pdu(il, ctx->rxon_cmd,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001357 sizeof(struct il_rxon_cmd),
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001358 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 Gruszka9406f792011-08-18 22:07:57 +02001364 IL_ERR("Error clearing ASSOC_MSK (%d)\n", ret);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001365 return ret;
1366 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001367 il_clear_ucode_stations(il, ctx);
1368 il_restore_stations(il, ctx);
1369 ret = il4965_restore_default_wep_keys(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001370 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001371 IL_ERR("Failed to restore WEP keys (%d)\n", ret);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001372 return ret;
1373 }
1374 }
1375
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001376 D_INFO("Sending RXON\n"
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001377 "* 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 Gruszka46bc8d42011-10-24 16:49:25 +02001384 il_set_rxon_hwcrypto(il, ctx,
1385 !il->cfg->mod_params->sw_crypto);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001386
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 Gruszka46bc8d42011-10-24 16:49:25 +02001392 ret = il_send_cmd_pdu(il, ctx->rxon_cmd,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001393 sizeof(struct il_rxon_cmd), &ctx->staging);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001394 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001395 IL_ERR("Error setting new RXON (%d)\n", ret);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001396 return ret;
1397 }
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001398 D_INFO("Return from !new_assoc RXON.\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001399 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001400 il_clear_ucode_stations(il, ctx);
1401 il_restore_stations(il, ctx);
1402 ret = il4965_restore_default_wep_keys(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001403 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001404 IL_ERR("Failed to restore WEP keys (%d)\n", ret);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001405 return ret;
1406 }
1407 }
1408 if (new_assoc) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001409 il->start_calib = 0;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001410 /* Apply the new configuration
1411 * RXON assoc doesn't clear the station table in uCode,
1412 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001413 ret = il_send_cmd_pdu(il, ctx->rxon_cmd,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001414 sizeof(struct il_rxon_cmd), &ctx->staging);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001415 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001416 IL_ERR("Error setting new RXON (%d)\n", ret);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001417 return ret;
1418 }
1419 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
1420 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001421 il_print_rx_config_cmd(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001422
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001423 il4965_init_sensitivity(il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001424
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 Gruszka46bc8d42011-10-24 16:49:25 +02001427 ret = il_set_tx_power(il, il->tx_power_next, true);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001428 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001429 IL_ERR("Error sending TX power (%d)\n", ret);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001430 return ret;
1431 }
1432
1433 return 0;
1434}
1435
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001436static int il4965_hw_channel_switch(struct il_priv *il,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001437 struct ieee80211_channel_switch *ch_switch)
1438{
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001439 struct il_rxon_context *ctx = &il->ctx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001440 int rc;
1441 u8 band = 0;
1442 bool is_ht40 = false;
1443 u8 ctrl_chan_high = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001444 struct il4965_channel_switch_cmd cmd;
1445 const struct il_channel_info *ch_info;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001446 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 Gruszka46bc8d42011-10-24 16:49:25 +02001452 band = il->band == IEEE80211_BAND_2GHZ;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001453
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001454 is_ht40 = iw4965_is_ht40_channel(ctx->staging.flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001455
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 Gruszka232913b2011-08-26 10:45:16 +02001472 if (il->ucode_beacon_time > tsf_low && beacon_interval) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001473 if (switch_count > ((il->ucode_beacon_time - tsf_low) /
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001474 beacon_interval)) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001475 switch_count -= (il->ucode_beacon_time -
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001476 tsf_low) / beacon_interval;
1477 } else
1478 switch_count = 0;
1479 }
1480 if (switch_count <= 1)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001481 cmd.switch_time = cpu_to_le32(il->ucode_beacon_time);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001482 else {
1483 switch_time_in_usec =
1484 vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001485 ucode_switch_time = il_usecs_to_beacons(il,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001486 switch_time_in_usec,
1487 beacon_interval);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001488 cmd.switch_time = il_add_beacon_time(il,
1489 il->ucode_beacon_time,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001490 ucode_switch_time,
1491 beacon_interval);
1492 }
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001493 D_11H("uCode time for the switch is 0x%x\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001494 cmd.switch_time);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001495 ch_info = il_get_channel_info(il, il->band, ch);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001496 if (ch_info)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001497 cmd.expect_beacon = il_is_channel_radar(ch_info);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001498 else {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001499 IL_ERR("invalid channel switch from %u to %u\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001500 ctx->active.channel, ch);
1501 return -EFAULT;
1502 }
1503
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001504 rc = il4965_fill_txpower_tbl(il, band, ch, is_ht40,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001505 ctrl_chan_high, &cmd.tx_power);
1506 if (rc) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001507 D_11H("error:%d fill txpower_tbl\n", rc);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001508 return rc;
1509 }
1510
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001511 return il_send_cmd_pdu(il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001512 REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001513}
1514
1515/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001516 * il4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001517 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001518static void il4965_txq_update_byte_cnt_tbl(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001519 struct il_tx_queue *txq,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001520 u16 byte_cnt)
1521{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001522 struct il4965_scd_bc_tbl *scd_bc_tbl = il->scd_bc_tbls.addr;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001523 int txq_id = txq->q.id;
1524 int write_ptr = txq->q.write_ptr;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001525 int len = byte_cnt + IL_TX_CRC_SIZE + IL_TX_DELIMITER_SIZE;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001526 __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 Gruszkae2ebc832011-10-24 15:41:30 +02001541 * il4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001542 * @stats: Provides the temperature reading from the uCode
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001543 *
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001544 * A return of <0 indicates bogus data in the stats
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001545 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001546static int il4965_hw_get_temperature(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001547{
1548 s32 temperature;
1549 s32 vt;
1550 s32 R1, R2, R3;
1551 u32 R4;
1552
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001553 if (test_bit(STATUS_TEMPERATURE, &il->status) &&
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001554 (il->_4965.stats.flag &
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001555 STATISTICS_REPLY_FLG_HT40_MODE_MSK)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001556 D_TEMP("Running HT40 temperature calibration\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001557 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 Guy4bc85c12011-02-21 11:11:05 -08001561 } else {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001562 D_TEMP("Running temperature calibration\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001563 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 Guy4bc85c12011-02-21 11:11:05 -08001567 }
1568
1569 /*
1570 * Temperature is only 23 bits, so sign extend out to 32.
1571 *
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001572 * NOTE If we haven't received a stats notification yet
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001573 * with an updated temperature, use R4 provided to us in the
1574 * "initialize" ALIVE response.
1575 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001576 if (!test_bit(STATUS_TEMPERATURE, &il->status))
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001577 vt = sign_extend32(R4, 23);
1578 else
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001579 vt = sign_extend32(le32_to_cpu(il->_4965.stats.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001580 general.common.temperature), 23);
1581
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001582 D_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001583
1584 if (R3 == R1) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001585 IL_ERR("Calibration conflict R1 == R3\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001586 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 Gruszka58de00a2011-11-15 11:21:01 +01001595 D_TEMP("Calibrated temperature: %dK, %dC\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001596 temperature, KELVIN_TO_CELSIUS(temperature));
1597
1598 return temperature;
1599}
1600
1601/* Adjust Txpower only if temperature variance is greater than threshold. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001602#define IL_TEMPERATURE_THRESHOLD 3
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001603
1604/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001605 * il4965_is_temp_calib_needed - determines if new calibration is needed
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001606 *
1607 * If the temperature changed has changed sufficiently, then a recalibration
1608 * is needed.
1609 *
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001610 * Assumes caller will replace il->last_temperature once calibration
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001611 * executed.
1612 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001613static int il4965_is_temp_calib_needed(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001614{
1615 int temp_diff;
1616
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001617 if (!test_bit(STATUS_STATISTICS, &il->status)) {
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001618 D_TEMP("Temperature not updated -- no stats.\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001619 return 0;
1620 }
1621
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001622 temp_diff = il->temperature - il->last_temperature;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001623
1624 /* get absolute value */
1625 if (temp_diff < 0) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001626 D_POWER("Getting cooler, delta %d\n", temp_diff);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001627 temp_diff = -temp_diff;
1628 } else if (temp_diff == 0)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001629 D_POWER("Temperature unchanged\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001630 else
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001631 D_POWER("Getting warmer, delta %d\n", temp_diff);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001632
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001633 if (temp_diff < IL_TEMPERATURE_THRESHOLD) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001634 D_POWER(" => thermal txpower calib not needed\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001635 return 0;
1636 }
1637
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001638 D_POWER(" => thermal txpower calib needed\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001639
1640 return 1;
1641}
1642
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001643static void il4965_temperature_calib(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001644{
1645 s32 temp;
1646
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001647 temp = il4965_hw_get_temperature(il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001648 if (IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp))
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001649 return;
1650
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001651 if (il->temperature != temp) {
1652 if (il->temperature)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001653 D_TEMP("Temperature changed "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001654 "from %dC to %dC\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001655 KELVIN_TO_CELSIUS(il->temperature),
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001656 KELVIN_TO_CELSIUS(temp));
1657 else
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001658 D_TEMP("Temperature "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001659 "initialized to %dC\n",
1660 KELVIN_TO_CELSIUS(temp));
1661 }
1662
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001663 il->temperature = temp;
1664 set_bit(STATUS_TEMPERATURE, &il->status);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001665
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001666 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 Guy4bc85c12011-02-21 11:11:05 -08001670}
1671
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001672static u16 il4965_get_hcmd_size(u8 cmd_id, u16 len)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001673{
1674 switch (cmd_id) {
1675 case REPLY_RXON:
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001676 return (u16) sizeof(struct il4965_rxon_cmd);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001677 default:
1678 return len;
1679 }
1680}
1681
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001682static u16 il4965_build_addsta_hcmd(const struct il_addsta_cmd *cmd,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001683 u8 *data)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001684{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001685 struct il4965_addsta_cmd *addsta = (struct il4965_addsta_cmd *)data;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001686 addsta->mode = cmd->mode;
1687 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001688 memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo));
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001689 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 Gruszkae2ebc832011-10-24 15:41:30 +02001699 return (u16)sizeof(struct il4965_addsta_cmd);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001700}
1701
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001702static inline u32 il4965_get_scd_ssn(struct il4965_tx_resp *tx_resp)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001703{
1704 return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
1705}
1706
1707/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001708 * il4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001709 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001710static int il4965_tx_status_reply_tx(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001711 struct il_ht_agg *agg,
1712 struct il4965_tx_resp *tx_resp,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001713 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 Gruszka58de00a2011-11-15 11:21:01 +01001723 D_TX_REPLY("got tx response w/o block-ack\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001724
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 Gruszka58de00a2011-11-15 11:21:01 +01001736 D_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001737 agg->frame_count, agg->start_idx, idx);
1738
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001739 info = IEEE80211_SKB_CB(il->txq[txq_id].txb[idx].skb);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001740 info->status.rates[0].count = tx_resp->failure_frame + 1;
1741 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001742 info->flags |= il4965_tx_status_to_mac80211(status);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001743 il4965_hwrate_to_tx_control(il, rate_n_flags, info);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001744
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001745 D_TX_REPLY("1 Frame 0x%x failure :%d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001746 status & 0xff, tx_resp->failure_frame);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001747 D_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001748
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 Gruszka6ce1dc42011-08-26 15:49:28 +02001755 /* Construct bit-map of pending frames within Tx win */
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001756 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 Gruszka2d09b062011-08-26 16:10:40 +02001760 idx = SEQ_TO_IDX(seq);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001761 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 Gruszka58de00a2011-11-15 11:21:01 +01001767 D_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001768 agg->frame_count, txq_id, idx);
1769
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001770 hdr = il_tx_queue_get_hdr(il, txq_id, idx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001771 if (!hdr) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001772 IL_ERR(
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001773 "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 Gruszka9406f792011-08-18 22:07:57 +02001780 IL_ERR(
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001781 "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 Gruszka58de00a2011-11-15 11:21:01 +01001787 D_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001788 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 Gruszka58de00a2011-11-15 11:21:01 +01001805 D_TX_REPLY("start=%d bitmap=0x%llx\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001806 start, (unsigned long long)bitmap);
1807 }
1808
1809 agg->bitmap = bitmap;
1810 agg->start_idx = start;
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001811 D_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001812 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 Gruszka46bc8d42011-10-24 16:49:25 +02001821static u8 il4965_find_station(struct il_priv *il, const u8 *addr)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001822{
1823 int i;
1824 int start = 0;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001825 int ret = IL_INVALID_STATION;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001826 unsigned long flags;
1827
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001828 if ((il->iw_mode == NL80211_IFTYPE_ADHOC))
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001829 start = IL_STA_ID;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001830
1831 if (is_broadcast_ether_addr(addr))
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001832 return il->ctx.bcast_sta_id;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001833
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001834 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 Guy4bc85c12011-02-21 11:11:05 -08001838 addr))) {
1839 ret = i;
1840 goto out;
1841 }
1842
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001843 D_ASSOC("can not find STA %pM total %d\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001844 addr, il->num_stations);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001845
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 Gruszkae2ebc832011-10-24 15:41:30 +02001852 if (ret != IL_INVALID_STATION &&
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001853 (!(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 Gruszka9406f792011-08-18 22:07:57 +02001856 IL_ERR("Requested station info for sta %d before ready.\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001857 ret);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001858 ret = IL_INVALID_STATION;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001859 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001860 spin_unlock_irqrestore(&il->sta_lock, flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001861 return ret;
1862}
1863
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001864static int il4965_get_ra_sta_id(struct il_priv *il, struct ieee80211_hdr *hdr)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001865{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001866 if (il->iw_mode == NL80211_IFTYPE_STATION) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001867 return IL_AP_ID;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001868 } else {
1869 u8 *da = ieee80211_get_DA(hdr);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001870 return il4965_find_station(il, da);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001871 }
1872}
1873
1874/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001875 * il4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001876 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001877static void il4965_rx_reply_tx(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001878 struct il_rx_buf *rxb)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001879{
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001880 struct il_rx_pkt *pkt = rxb_addr(rxb);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001881 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1882 int txq_id = SEQ_TO_QUEUE(sequence);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001883 int idx = SEQ_TO_IDX(sequence);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001884 struct il_tx_queue *txq = &il->txq[txq_id];
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001885 struct ieee80211_hdr *hdr;
1886 struct ieee80211_tx_info *info;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001887 struct il4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001888 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 Gruszka0c2c8852011-11-15 12:30:17 +01001895 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 Guy4bc85c12011-02-21 11:11:05 -08001897 "is out of range [0-%d] %d %d\n", txq_id,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001898 idx, txq->q.n_bd, txq->q.write_ptr,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001899 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 Gruszka0c2c8852011-11-15 12:30:17 +01001907 hdr = il_tx_queue_get_hdr(il, txq_id, idx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001908 if (ieee80211_is_data_qos(hdr->frame_control)) {
1909 qc = ieee80211_get_qos_ctl(hdr);
1910 tid = qc[0] & 0xf;
1911 }
1912
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001913 sta_id = il4965_get_ra_sta_id(il, hdr);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001914 if (txq->sched_retry && unlikely(sta_id == IL_INVALID_STATION)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001915 IL_ERR("Station not known\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001916 return;
1917 }
1918
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001919 spin_lock_irqsave(&il->sta_lock, flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001920 if (txq->sched_retry) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001921 const u32 scd_ssn = il4965_get_scd_ssn(tx_resp);
1922 struct il_ht_agg *agg = NULL;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001923 WARN_ON(!qc);
1924
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001925 agg = &il->stations[sta_id].tid[tid].agg;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001926
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001927 il4965_tx_status_reply_tx(il, agg, tx_resp, txq_id, idx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001928
1929 /* check if BAR is needed */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001930 if ((tx_resp->frame_count == 1) && !il4965_is_tx_success(status))
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001931 info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1932
1933 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001934 idx = il_queue_dec_wrap(scd_ssn & 0xff,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001935 txq->q.n_bd);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001936 D_TX_REPLY("Retry scheduler reclaim scd_ssn "
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001937 "%d idx %d\n", scd_ssn , idx);
1938 freed = il4965_tx_queue_reclaim(il, txq_id, idx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001939 if (qc)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001940 il4965_free_tfds_in_queue(il, sta_id,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001941 tid, freed);
1942
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001943 if (il->mac80211_registered &&
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001944 il_queue_space(&txq->q) > txq->q.low_mark &&
1945 agg->state != IL_EMPTYING_HW_QUEUE_DELBA)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001946 il_wake_queue(il, txq);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001947 }
1948 } else {
1949 info->status.rates[0].count = tx_resp->failure_frame + 1;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001950 info->flags |= il4965_tx_status_to_mac80211(status);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001951 il4965_hwrate_to_tx_control(il,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001952 le32_to_cpu(tx_resp->rate_n_flags),
1953 info);
1954
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001955 D_TX_REPLY("TXQ %d status %s (0x%08x) "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001956 "rate_n_flags 0x%x retries %d\n",
1957 txq_id,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001958 il4965_get_tx_fail_reason(status), status,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001959 le32_to_cpu(tx_resp->rate_n_flags),
1960 tx_resp->failure_frame);
1961
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001962 freed = il4965_tx_queue_reclaim(il, txq_id, idx);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001963 if (qc && likely(sta_id != IL_INVALID_STATION))
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001964 il4965_free_tfds_in_queue(il, sta_id, tid, freed);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001965 else if (sta_id == IL_INVALID_STATION)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001966 D_TX_REPLY("Station not known\n");
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001967
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001968 if (il->mac80211_registered &&
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001969 il_queue_space(&txq->q) > txq->q.low_mark)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001970 il_wake_queue(il, txq);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001971 }
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001972 if (qc && likely(sta_id != IL_INVALID_STATION))
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001973 il4965_txq_check_empty(il, sta_id, tid, txq_id);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001974
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001975 il4965_check_abort_status(il, tx_resp->frame_count, status);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001976
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001977 spin_unlock_irqrestore(&il->sta_lock, flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001978}
1979
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001980static void il4965_rx_beacon_notif(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001981 struct il_rx_buf *rxb)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001982{
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001983 struct il_rx_pkt *pkt = rxb_addr(rxb);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001984 struct il4965_beacon_notif *beacon = (void *)pkt->u.raw;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001985 u8 rate __maybe_unused =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001986 il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001987
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001988 D_RX("beacon status %#x, retries:%d ibssmgr:%d "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001989 "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 Guy4bc85c12011-02-21 11:11:05 -08001995
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001996 il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001997}
1998
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001999/* Set up 4965-specific Rx frame reply handlers */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002000static void il4965_rx_handler_setup(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002001{
2002 /* Legacy Rx frames */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002003 il->rx_handlers[REPLY_RX] = il4965_rx_reply_rx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002004 /* Tx response */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002005 il->rx_handlers[REPLY_TX] = il4965_rx_reply_tx;
2006 il->rx_handlers[BEACON_NOTIFICATION] = il4965_rx_beacon_notif;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002007}
2008
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002009static 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 Guy4bc85c12011-02-21 11:11:05 -08002013};
2014
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002015static void il4965_post_scan(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002016{
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01002017 struct il_rxon_context *ctx = &il->ctx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002018
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 Gruszka46bc8d42011-10-24 16:49:25 +02002024 il_commit_rxon(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002025}
2026
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002027static void il4965_post_associate(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002028{
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01002029 struct il_rxon_context *ctx = &il->ctx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002030 struct ieee80211_vif *vif = ctx->vif;
2031 struct ieee80211_conf *conf = NULL;
2032 int ret = 0;
2033
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002034 if (!vif || !il->is_open)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002035 return;
2036
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002037 if (test_bit(STATUS_EXIT_PENDING, &il->status))
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002038 return;
2039
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002040 il_scan_cancel_timeout(il, 200);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002041
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002042 conf = il_ieee80211_get_hw_conf(il->hw);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002043
2044 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002045 il_commit_rxon(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002046
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002047 ret = il_send_rxon_timing(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002048 if (ret)
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002049 IL_WARN("RXON timing - "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002050 "Attempting to continue.\n");
2051
2052 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
2053
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002054 il_set_rxon_ht(il, &il->current_ht_config);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002055
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002056 if (il->cfg->ops->hcmd->set_rxon_chain)
2057 il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002058
2059 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
2060
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002061 D_ASSOC("assoc id %d beacon interval %d\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002062 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 Gruszka46bc8d42011-10-24 16:49:25 +02002076 il_commit_rxon(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002077
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002078 D_ASSOC("Associated as %d to: %pM\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002079 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 Gruszka46bc8d42011-10-24 16:49:25 +02002085 il4965_send_beacon_cmd(il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002086 break;
2087 default:
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002088 IL_ERR("%s Should not be called in %d mode\n",
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002089 __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 Gruszka46bc8d42011-10-24 16:49:25 +02002096 if (il->chain_noise_data.state == IL_CHAIN_NOISE_DONE)
2097 il_power_update_mode(il, false);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002098
2099 /* Enable Rx differential gain and sensitivity calibrations */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002100 il4965_chain_noise_reset(il);
2101 il->start_calib = 1;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002102}
2103
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002104static void il4965_config_ap(struct il_priv *il)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002105{
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01002106 struct il_rxon_context *ctx = &il->ctx;
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002107 struct ieee80211_vif *vif = ctx->vif;
2108 int ret = 0;
2109
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002110 lockdep_assert_held(&il->mutex);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002111
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002112 if (test_bit(STATUS_EXIT_PENDING, &il->status))
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002113 return;
2114
2115 /* The following should be done only at AP bring up */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002116 if (!il_is_associated_ctx(ctx)) {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002117
2118 /* RXON - unassoc (to set timing command) */
2119 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002120 il_commit_rxon(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002121
2122 /* RXON Timing */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002123 ret = il_send_rxon_timing(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002124 if (ret)
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002125 IL_WARN("RXON timing failed - "
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002126 "Attempting to continue.\n");
2127
2128 /* AP has all antennas */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002129 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 Guy4bc85c12011-02-21 11:11:05 -08002134
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 Gruszka46bc8d42011-10-24 16:49:25 +02002153 il4965_send_beacon_cmd(il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002154 /* restore RXON assoc */
2155 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002156 il_commit_rxon(il, ctx);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002157 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002158 il4965_send_beacon_cmd(il);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002159}
2160
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002161static 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 Guy4bc85c12011-02-21 11:11:05 -08002166};
2167
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002168static 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 Guy4bc85c12011-02-21 11:11:05 -08002181 .apm_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002182 .init = il_apm_init,
2183 .config = il4965_nic_config,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002184 },
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 Gruszkae2ebc832011-10-24 15:41:30 +02002195 .acquire_semaphore = il4965_eeprom_acquire_semaphore,
2196 .release_semaphore = il4965_eeprom_release_semaphore,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002197 },
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002198 .send_tx_power = il4965_send_tx_power,
2199 .update_chain_flags = il4965_update_chain_flags,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002200 .temp_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002201 .temperature = il4965_temperature_calib,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002202 },
2203 .debugfs_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002204 .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 Guy4bc85c12011-02-21 11:11:05 -08002207 },
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002208};
2209
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002210static 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 Guy4bc85c12011-02-21 11:11:05 -08002215};
2216
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002217struct 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 Guy4bc85c12011-02-21 11:11:05 -08002237};
2238
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002239static 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 Guy4bc85c12011-02-21 11:11:05 -08002246};
2247
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002248static struct il_base_params il4965_base_params = {
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002249 .eeprom_size = IL4965_EEPROM_IMG_SIZE,
2250 .num_of_queues = IL49_NUM_QUEUES,
2251 .num_of_ampdu_queues = IL49_NUM_AMPDU_QUEUES,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002252 .pll_cfg_val = 0,
2253 .set_l0s = true,
2254 .use_bsm = true,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002255 .led_compensation = 61,
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002256 .chain_noise_num_beacons = IL4965_CAL_NUM_BEACONS,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002257 .wd_timeout = IL_DEF_WD_TIMEOUT,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002258 .temperature_kelvin = true,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002259 .ucode_tracing = true,
2260 .sensitivity_calib_by_driver = true,
2261 .chain_noise_calib_by_driver = true,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002262};
2263
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002264struct il_cfg il4965_cfg = {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002265 .name = "Intel(R) Wireless WiFi Link 4965AGN",
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002266 .fw_name_pre = IL4965_FW_PRE,
2267 .ucode_api_max = IL4965_UCODE_API_MAX,
2268 .ucode_api_min = IL4965_UCODE_API_MIN,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002269 .sku = IL_SKU_A|IL_SKU_G|IL_SKU_N,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002270 .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 Gruszkae2ebc832011-10-24 15:41:30 +02002274 .ops = &il4965_ops,
2275 .mod_params = &il4965_mod_params,
2276 .base_params = &il4965_base_params,
2277 .led_mode = IL_LED_BLINK,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08002278 /*
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 Gruszkad3175162011-11-15 11:25:42 +01002286MODULE_FIRMWARE(IL4965_MODULE_FIRMWARE(IL4965_UCODE_API_MAX));