blob: 646c589b8282f91938493dab870ea9966acbc1dd [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatreeb7ae892008-03-11 16:17:17 -07003 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
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 * James P. Ketrenos <ipw2100-admin@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/version.h>
30#include <linux/init.h>
31#include <linux/pci.h>
32#include <linux/dma-mapping.h>
33#include <linux/delay.h>
34#include <linux/skbuff.h>
35#include <linux/netdevice.h>
36#include <linux/wireless.h>
37#include <net/mac80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070038#include <linux/etherdevice.h>
Zhu Yi12342c42007-12-20 11:27:32 +080039#include <asm/unaligned.h>
Zhu Yib481de92007-09-25 17:54:57 -070040
Assaf Krauss6bc913b2008-03-11 16:17:18 -070041#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070042#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070043#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070044#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070045#include "iwl-helpers.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070046#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070047
Assaf Krauss1ea87392008-03-18 14:57:50 -070048/* module parameters */
49static struct iwl_mod_params iwl4965_mod_params = {
Emmanuel Grumbach038669e2008-04-23 17:15:04 -070050 .num_of_queues = IWL49_NUM_QUEUES,
Assaf Krauss1ea87392008-03-18 14:57:50 -070051 .enable_qos = 1,
52 .amsdu_size_8K = 1,
Ester Kummer3a1081e2008-05-06 11:05:14 +080053 .restart_fw = 1,
Assaf Krauss1ea87392008-03-18 14:57:50 -070054 /* the rest are 0 by default */
55};
56
Ron Rindjunskyfe01b472008-01-28 14:07:24 +020057#ifdef CONFIG_IWL4965_HT
58
59static const u16 default_tid_to_tx_fifo[] = {
60 IWL_TX_FIFO_AC1,
61 IWL_TX_FIFO_AC0,
62 IWL_TX_FIFO_AC0,
63 IWL_TX_FIFO_AC1,
64 IWL_TX_FIFO_AC2,
65 IWL_TX_FIFO_AC2,
66 IWL_TX_FIFO_AC3,
67 IWL_TX_FIFO_AC3,
68 IWL_TX_FIFO_NONE,
69 IWL_TX_FIFO_NONE,
70 IWL_TX_FIFO_NONE,
71 IWL_TX_FIFO_NONE,
72 IWL_TX_FIFO_NONE,
73 IWL_TX_FIFO_NONE,
74 IWL_TX_FIFO_NONE,
75 IWL_TX_FIFO_NONE,
76 IWL_TX_FIFO_AC3
77};
78
79#endif /*CONFIG_IWL4965_HT */
80
Tomas Winkler57aab752008-04-14 21:16:03 -070081/* check contents of special bootstrap uCode SRAM */
82static int iwl4965_verify_bsm(struct iwl_priv *priv)
83{
84 __le32 *image = priv->ucode_boot.v_addr;
85 u32 len = priv->ucode_boot.len;
86 u32 reg;
87 u32 val;
88
89 IWL_DEBUG_INFO("Begin verify bsm\n");
90
91 /* verify BSM SRAM contents */
92 val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
93 for (reg = BSM_SRAM_LOWER_BOUND;
94 reg < BSM_SRAM_LOWER_BOUND + len;
95 reg += sizeof(u32), image++) {
96 val = iwl_read_prph(priv, reg);
97 if (val != le32_to_cpu(*image)) {
98 IWL_ERROR("BSM uCode verification failed at "
99 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
100 BSM_SRAM_LOWER_BOUND,
101 reg - BSM_SRAM_LOWER_BOUND, len,
102 val, le32_to_cpu(*image));
103 return -EIO;
104 }
105 }
106
107 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
108
109 return 0;
110}
111
112/**
113 * iwl4965_load_bsm - Load bootstrap instructions
114 *
115 * BSM operation:
116 *
117 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
118 * in special SRAM that does not power down during RFKILL. When powering back
119 * up after power-saving sleeps (or during initial uCode load), the BSM loads
120 * the bootstrap program into the on-board processor, and starts it.
121 *
122 * The bootstrap program loads (via DMA) instructions and data for a new
123 * program from host DRAM locations indicated by the host driver in the
124 * BSM_DRAM_* registers. Once the new program is loaded, it starts
125 * automatically.
126 *
127 * When initializing the NIC, the host driver points the BSM to the
128 * "initialize" uCode image. This uCode sets up some internal data, then
129 * notifies host via "initialize alive" that it is complete.
130 *
131 * The host then replaces the BSM_DRAM_* pointer values to point to the
132 * normal runtime uCode instructions and a backup uCode data cache buffer
133 * (filled initially with starting data values for the on-board processor),
134 * then triggers the "initialize" uCode to load and launch the runtime uCode,
135 * which begins normal operation.
136 *
137 * When doing a power-save shutdown, runtime uCode saves data SRAM into
138 * the backup data cache in DRAM before SRAM is powered down.
139 *
140 * When powering back up, the BSM loads the bootstrap program. This reloads
141 * the runtime uCode instructions and the backup data cache into SRAM,
142 * and re-launches the runtime uCode from where it left off.
143 */
144static int iwl4965_load_bsm(struct iwl_priv *priv)
145{
146 __le32 *image = priv->ucode_boot.v_addr;
147 u32 len = priv->ucode_boot.len;
148 dma_addr_t pinst;
149 dma_addr_t pdata;
150 u32 inst_len;
151 u32 data_len;
152 int i;
153 u32 done;
154 u32 reg_offset;
155 int ret;
156
157 IWL_DEBUG_INFO("Begin load bsm\n");
158
159 /* make sure bootstrap program is no larger than BSM's SRAM size */
160 if (len > IWL_MAX_BSM_SIZE)
161 return -EINVAL;
162
163 /* Tell bootstrap uCode where to find the "Initialize" uCode
164 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
Tomas Winkler2d878892008-05-29 16:34:51 +0800165 * NOTE: iwl_init_alive_start() will replace these values,
Tomas Winkler57aab752008-04-14 21:16:03 -0700166 * after the "initialize" uCode has run, to point to
Tomas Winkler2d878892008-05-29 16:34:51 +0800167 * runtime/protocol instructions and backup data cache.
168 */
Tomas Winkler57aab752008-04-14 21:16:03 -0700169 pinst = priv->ucode_init.p_addr >> 4;
170 pdata = priv->ucode_init_data.p_addr >> 4;
171 inst_len = priv->ucode_init.len;
172 data_len = priv->ucode_init_data.len;
173
174 ret = iwl_grab_nic_access(priv);
175 if (ret)
176 return ret;
177
178 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
179 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
180 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
181 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
182
183 /* Fill BSM memory with bootstrap instructions */
184 for (reg_offset = BSM_SRAM_LOWER_BOUND;
185 reg_offset < BSM_SRAM_LOWER_BOUND + len;
186 reg_offset += sizeof(u32), image++)
187 _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
188
189 ret = iwl4965_verify_bsm(priv);
190 if (ret) {
191 iwl_release_nic_access(priv);
192 return ret;
193 }
194
195 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
196 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
197 iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND);
198 iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
199
200 /* Load bootstrap code into instruction SRAM now,
201 * to prepare to load "initialize" uCode */
202 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
203
204 /* Wait for load of bootstrap uCode to finish */
205 for (i = 0; i < 100; i++) {
206 done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
207 if (!(done & BSM_WR_CTRL_REG_BIT_START))
208 break;
209 udelay(10);
210 }
211 if (i < 100)
212 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
213 else {
214 IWL_ERROR("BSM write did not complete!\n");
215 return -EIO;
216 }
217
218 /* Enable future boot loads whenever power management unit triggers it
219 * (e.g. when powering back up after power-save shutdown) */
220 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
221
222 iwl_release_nic_access(priv);
223
Tomas Winkler2d878892008-05-29 16:34:51 +0800224 priv->ucode_type = UCODE_INIT;
225
Tomas Winkler57aab752008-04-14 21:16:03 -0700226 return 0;
227}
228
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +0800229/**
230 * iwl4965_set_ucode_ptrs - Set uCode address location
231 *
232 * Tell initialization uCode where to find runtime uCode.
233 *
234 * BSM registers initially contain pointers to initialization uCode.
235 * We need to replace them to load runtime uCode inst and data,
236 * and to save runtime data when powering down.
237 */
238static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
239{
240 dma_addr_t pinst;
241 dma_addr_t pdata;
242 unsigned long flags;
243 int ret = 0;
244
245 /* bits 35:4 for 4965 */
246 pinst = priv->ucode_code.p_addr >> 4;
247 pdata = priv->ucode_data_backup.p_addr >> 4;
248
249 spin_lock_irqsave(&priv->lock, flags);
250 ret = iwl_grab_nic_access(priv);
251 if (ret) {
252 spin_unlock_irqrestore(&priv->lock, flags);
253 return ret;
254 }
255
256 /* Tell bootstrap uCode where to find image to load */
257 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
258 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
259 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
260 priv->ucode_data.len);
261
262 /* Inst bytecount must be last to set up, bit 31 signals uCode
263 * that all new ptr/size info is in place */
264 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
265 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
266 iwl_release_nic_access(priv);
267
268 spin_unlock_irqrestore(&priv->lock, flags);
269
270 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
271
Tomas Winkler2d878892008-05-29 16:34:51 +0800272 priv->ucode_type = UCODE_RT;
273
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +0800274 return ret;
275}
276
277/**
278 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
279 *
280 * Called after REPLY_ALIVE notification received from "initialize" uCode.
281 *
282 * The 4965 "initialize" ALIVE reply contains calibration data for:
283 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
284 * (3945 does not contain this data).
285 *
286 * Tell "initialize" uCode to go ahead and load the runtime uCode.
287*/
288static void iwl4965_init_alive_start(struct iwl_priv *priv)
289{
290 /* Check alive response for "valid" sign from uCode */
291 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
292 /* We had an error bringing up the hardware, so take it
293 * all the way back down so we can try again */
294 IWL_DEBUG_INFO("Initialize Alive failed.\n");
295 goto restart;
296 }
297
298 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
299 * This is a paranoid check, because we would not have gotten the
300 * "initialize" alive if code weren't properly loaded. */
301 if (iwl_verify_ucode(priv)) {
302 /* Runtime instruction load was bad;
303 * take it all the way back down so we can try again */
304 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
305 goto restart;
306 }
307
308 /* Calculate temperature */
309 priv->temperature = iwl4965_get_temperature(priv);
310
311 /* Send pointers to protocol/runtime uCode image ... init code will
312 * load and launch runtime uCode, which will send us another "Alive"
313 * notification. */
314 IWL_DEBUG_INFO("Initialization Alive received.\n");
315 if (iwl4965_set_ucode_ptrs(priv)) {
316 /* Runtime instruction load won't happen;
317 * take it all the way back down so we can try again */
318 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
319 goto restart;
320 }
321 return;
322
323restart:
324 queue_work(priv->workqueue, &priv->restart);
325}
326
Zhu Yib481de92007-09-25 17:54:57 -0700327static int is_fat_channel(__le32 rxon_flags)
328{
329 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
330 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
331}
332
Tomas Winkler17744ff2008-03-02 01:52:00 +0200333int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
334{
335 int idx = 0;
336
337 /* 4965 HT rate format */
338 if (rate_n_flags & RATE_MCS_HT_MSK) {
339 idx = (rate_n_flags & 0xff);
340
Guy Cohenfde0db32008-04-21 15:42:01 -0700341 if (idx >= IWL_RATE_MIMO2_6M_PLCP)
342 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
Tomas Winkler17744ff2008-03-02 01:52:00 +0200343
344 idx += IWL_FIRST_OFDM_RATE;
345 /* skip 9M not supported in ht*/
346 if (idx >= IWL_RATE_9M_INDEX)
347 idx += 1;
348 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
349 return idx;
350
351 /* 4965 legacy rate format, search for match in table */
352 } else {
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800353 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
354 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
Tomas Winkler17744ff2008-03-02 01:52:00 +0200355 return idx;
356 }
357
358 return -1;
359}
360
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800361/**
362 * translate ucode response to mac80211 tx status control values
363 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700364void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
Johannes Berge039fa42008-05-15 12:55:29 +0200365 struct ieee80211_tx_info *control)
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800366{
367 int rate_index;
368
369 control->antenna_sel_tx =
Guy Cohenfde0db32008-04-21 15:42:01 -0700370 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800371 if (rate_n_flags & RATE_MCS_HT_MSK)
Johannes Berge039fa42008-05-15 12:55:29 +0200372 control->flags |= IEEE80211_TX_CTL_OFDM_HT;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800373 if (rate_n_flags & RATE_MCS_GF_MSK)
Johannes Berge039fa42008-05-15 12:55:29 +0200374 control->flags |= IEEE80211_TX_CTL_GREEN_FIELD;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800375 if (rate_n_flags & RATE_MCS_FAT_MSK)
Johannes Berge039fa42008-05-15 12:55:29 +0200376 control->flags |= IEEE80211_TX_CTL_40_MHZ_WIDTH;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800377 if (rate_n_flags & RATE_MCS_DUP_MSK)
Johannes Berge039fa42008-05-15 12:55:29 +0200378 control->flags |= IEEE80211_TX_CTL_DUP_DATA;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800379 if (rate_n_flags & RATE_MCS_SGI_MSK)
Johannes Berge039fa42008-05-15 12:55:29 +0200380 control->flags |= IEEE80211_TX_CTL_SHORT_GI;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800381 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200382 if (control->band == IEEE80211_BAND_5GHZ)
383 rate_index -= IWL_FIRST_OFDM_RATE;
384 control->tx_rate_idx = rate_index;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -0800385}
Tomas Winkler17744ff2008-03-02 01:52:00 +0200386
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700387int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700388{
389 int rc;
390 unsigned long flags;
391
392 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700393 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700394 if (rc) {
395 spin_unlock_irqrestore(&priv->lock, flags);
396 return rc;
397 }
398
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800399 /* stop Rx DMA */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700400 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
401 rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
Zhu Yib481de92007-09-25 17:54:57 -0700402 (1 << 24), 1000);
403 if (rc < 0)
404 IWL_ERROR("Can't stop Rx DMA.\n");
405
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700406 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700407 spin_unlock_irqrestore(&priv->lock, flags);
408
409 return 0;
410}
411
Tomas Winkler8614f362008-04-23 17:14:55 -0700412/*
413 * EEPROM handlers
414 */
415
416static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
417{
418 u16 eeprom_ver;
419 u16 calib_ver;
420
421 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
422
423 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
424
425 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
426 calib_ver < EEPROM_4965_TX_POWER_VERSION)
427 goto err;
428
429 return 0;
430err:
431 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
432 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
433 calib_ver, EEPROM_4965_TX_POWER_VERSION);
434 return -EINVAL;
435
436}
Tomas Winkler079a2532008-04-17 16:03:39 -0700437int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Zhu Yib481de92007-09-25 17:54:57 -0700438{
Tomas Winklerd8609652007-10-25 17:15:35 +0800439 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700440 unsigned long flags;
441
442 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700443 ret = iwl_grab_nic_access(priv);
Tomas Winklerd8609652007-10-25 17:15:35 +0800444 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700445 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winklerd8609652007-10-25 17:15:35 +0800446 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700447 }
448
Tomas Winkler6f4083a2008-04-16 16:34:49 -0700449 if (src == IWL_PWR_SRC_VAUX) {
Zhu Yib481de92007-09-25 17:54:57 -0700450 u32 val;
Tomas Winklerd8609652007-10-25 17:15:35 +0800451 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
Tomas Winkler6f4083a2008-04-16 16:34:49 -0700452 &val);
Zhu Yib481de92007-09-25 17:54:57 -0700453
Tomas Winkler6f4083a2008-04-16 16:34:49 -0700454 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700455 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
Tomas Winkler6f4083a2008-04-16 16:34:49 -0700456 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
457 ~APMG_PS_CTRL_MSK_PWR_SRC);
458 }
459 } else {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700460 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
Tomas Winkler6f4083a2008-04-16 16:34:49 -0700461 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
462 ~APMG_PS_CTRL_MSK_PWR_SRC);
463 }
Zhu Yib481de92007-09-25 17:54:57 -0700464
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700465 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700466 spin_unlock_irqrestore(&priv->lock, flags);
467
Tomas Winklerd8609652007-10-25 17:15:35 +0800468 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700469}
470
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +0800471static int iwl4965_disable_tx_fifo(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700472{
Zhu Yib481de92007-09-25 17:54:57 -0700473 unsigned long flags;
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +0800474 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700475
476 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +0800477
Tomas Winkler059ff822008-04-14 21:16:14 -0700478 ret = iwl_grab_nic_access(priv);
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +0800479 if (unlikely(ret)) {
480 IWL_ERROR("Tx fifo reset failed");
Zhu Yib481de92007-09-25 17:54:57 -0700481 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler059ff822008-04-14 21:16:14 -0700482 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700483 }
484
Tomas Winkler12a81f62008-04-03 16:05:20 -0700485 iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700486 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700487 spin_unlock_irqrestore(&priv->lock, flags);
488
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +0800489 return 0;
Zhu Yib481de92007-09-25 17:54:57 -0700490}
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +0800491
Tomas Winkler91238712008-04-23 17:14:53 -0700492static int iwl4965_apm_init(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700493{
Tomas Winkler91238712008-04-23 17:14:53 -0700494 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700495
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700496 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
Tomas Winkler91238712008-04-23 17:14:53 -0700497 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
Zhu Yib481de92007-09-25 17:54:57 -0700498
Tomas Winkler8f061892008-05-29 16:34:56 +0800499 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
500 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
501 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
502
Tomas Winkler91238712008-04-23 17:14:53 -0700503 /* set "initialization complete" bit to move adapter
504 * D0U* --> D0A* state */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700505 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
Tomas Winkler91238712008-04-23 17:14:53 -0700506
507 /* wait for clock stabilization */
508 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
509 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
510 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
511 if (ret < 0) {
Zhu Yib481de92007-09-25 17:54:57 -0700512 IWL_DEBUG_INFO("Failed to init the card\n");
Tomas Winkler91238712008-04-23 17:14:53 -0700513 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700514 }
515
Tomas Winkler91238712008-04-23 17:14:53 -0700516 ret = iwl_grab_nic_access(priv);
517 if (ret)
518 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700519
Tomas Winkler91238712008-04-23 17:14:53 -0700520 /* enable DMA */
Tomas Winkler8f061892008-05-29 16:34:56 +0800521 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
522 APMG_CLK_VAL_BSM_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -0700523
524 udelay(20);
525
Tomas Winkler8f061892008-05-29 16:34:56 +0800526 /* disable L1-Active */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700527 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
Tomas Winkler91238712008-04-23 17:14:53 -0700528 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
Zhu Yib481de92007-09-25 17:54:57 -0700529
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700530 iwl_release_nic_access(priv);
Tomas Winkler91238712008-04-23 17:14:53 -0700531out:
Tomas Winkler91238712008-04-23 17:14:53 -0700532 return ret;
533}
534
Tomas Winkler694cc562008-04-24 11:55:22 -0700535
536static void iwl4965_nic_config(struct iwl_priv *priv)
537{
538 unsigned long flags;
539 u32 val;
540 u16 radio_cfg;
541 u8 val_link;
542
543 spin_lock_irqsave(&priv->lock, flags);
544
545 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
546 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
547 /* Enable No Snoop field */
548 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
549 val & ~(1 << 11));
550 }
551
552 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
553
Tomas Winkler8f061892008-05-29 16:34:56 +0800554 /* L1 is enabled by BIOS */
555 if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
556 /* diable L0S disabled L1A enabled */
557 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
558 else
559 /* L0S enabled L1A disabled */
560 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
Tomas Winkler694cc562008-04-24 11:55:22 -0700561
562 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
563
564 /* write radio config values to register */
565 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
566 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
567 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
568 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
569 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
570
571 /* set CSR_HW_CONFIG_REG for uCode use */
572 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
573 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
574 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
575
576 priv->calib_info = (struct iwl_eeprom_calib_info *)
577 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
578
579 spin_unlock_irqrestore(&priv->lock, flags);
580}
581
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700582int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700583{
584 int rc = 0;
585 u32 reg_val;
586 unsigned long flags;
587
588 spin_lock_irqsave(&priv->lock, flags);
589
590 /* set stop master bit */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700591 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
Zhu Yib481de92007-09-25 17:54:57 -0700592
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700593 reg_val = iwl_read32(priv, CSR_GP_CNTRL);
Zhu Yib481de92007-09-25 17:54:57 -0700594
595 if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
596 (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
597 IWL_DEBUG_INFO("Card in power save, master is already "
598 "stopped\n");
599 else {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700600 rc = iwl_poll_bit(priv, CSR_RESET,
Zhu Yib481de92007-09-25 17:54:57 -0700601 CSR_RESET_REG_FLAG_MASTER_DISABLED,
602 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
603 if (rc < 0) {
604 spin_unlock_irqrestore(&priv->lock, flags);
605 return rc;
606 }
607 }
608
609 spin_unlock_irqrestore(&priv->lock, flags);
610 IWL_DEBUG_INFO("stop master\n");
611
612 return rc;
613}
614
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800615/**
616 * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
617 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700618void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700619{
620
621 int txq_id;
622 unsigned long flags;
623
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800624 /* Stop each Tx DMA channel, and wait for it to be idle */
Tomas Winkler5425e492008-04-15 16:01:38 -0700625 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
Zhu Yib481de92007-09-25 17:54:57 -0700626 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700627 if (iwl_grab_nic_access(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -0700628 spin_unlock_irqrestore(&priv->lock, flags);
629 continue;
630 }
631
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700632 iwl_write_direct32(priv,
Emmanuel Grumbach4b52c392008-04-23 17:15:07 -0700633 FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
634 iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG,
635 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700636 (txq_id), 200);
637 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700638 spin_unlock_irqrestore(&priv->lock, flags);
639 }
640
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800641 /* Deallocate memory for all Tx queues */
Ron Rindjunsky1053d352008-05-05 10:22:43 +0800642 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700643}
644
Tomas Winkler7f066102008-05-29 16:34:57 +0800645static int iwl4965_apm_reset(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700646{
Tomas Winkler7f066102008-05-29 16:34:57 +0800647 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700648 unsigned long flags;
649
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800650 iwl4965_hw_nic_stop_master(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700651
652 spin_lock_irqsave(&priv->lock, flags);
653
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700654 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
Zhu Yib481de92007-09-25 17:54:57 -0700655
656 udelay(10);
657
Tomas Winkler7f066102008-05-29 16:34:57 +0800658 /* FIXME: put here L1A -L0S w/a */
659
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700660 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
Tomas Winkler7f066102008-05-29 16:34:57 +0800661 ret = iwl_poll_bit(priv, CSR_RESET,
Zhu Yib481de92007-09-25 17:54:57 -0700662 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
663 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
664
Tomas Winkler7f066102008-05-29 16:34:57 +0800665 if (ret)
666 goto out;
667
Zhu Yib481de92007-09-25 17:54:57 -0700668 udelay(10);
669
Tomas Winkler7f066102008-05-29 16:34:57 +0800670 ret = iwl_grab_nic_access(priv);
671 if (ret)
672 goto out;
673 /* Enable DMA and BSM Clock */
674 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
675 APMG_CLK_VAL_BSM_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -0700676
Tomas Winkler7f066102008-05-29 16:34:57 +0800677 udelay(10);
Zhu Yib481de92007-09-25 17:54:57 -0700678
Tomas Winkler7f066102008-05-29 16:34:57 +0800679 /* disable L1A */
680 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
681 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
Zhu Yib481de92007-09-25 17:54:57 -0700682
Tomas Winkler7f066102008-05-29 16:34:57 +0800683 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700684
685 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
686 wake_up_interruptible(&priv->wait_command_queue);
687
Tomas Winkler7f066102008-05-29 16:34:57 +0800688out:
Zhu Yib481de92007-09-25 17:54:57 -0700689 spin_unlock_irqrestore(&priv->lock, flags);
690
Tomas Winkler7f066102008-05-29 16:34:57 +0800691 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700692
693}
694
695#define REG_RECALIB_PERIOD (60)
696
697/**
698 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
699 *
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -0700700 * This callback is provided in order to send a statistics request.
Zhu Yib481de92007-09-25 17:54:57 -0700701 *
702 * This timer function is continually reset to execute within
703 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
704 * was received. We need to ensure we receive the statistics in order
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -0700705 * to update the temperature used for calibrating the TXPOWER.
Zhu Yib481de92007-09-25 17:54:57 -0700706 */
707static void iwl4965_bg_statistics_periodic(unsigned long data)
708{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700709 struct iwl_priv *priv = (struct iwl_priv *)data;
Zhu Yib481de92007-09-25 17:54:57 -0700710
Zhu Yib481de92007-09-25 17:54:57 -0700711 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
712 return;
713
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -0700714 iwl_send_statistics_request(priv, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700715}
716
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700717void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700718{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800719 struct iwl4965_ct_kill_config cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700720 unsigned long flags;
Tomas Winkler857485c2008-03-21 13:53:44 -0700721 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700722
723 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700724 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -0700725 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
726 spin_unlock_irqrestore(&priv->lock, flags);
727
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700728 cmd.critical_temperature_R =
Emmanuel Grumbachb73cdf22008-04-21 15:41:58 -0700729 cpu_to_le32(priv->hw_params.ct_kill_threshold);
730
Tomas Winkler857485c2008-03-21 13:53:44 -0700731 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
732 sizeof(cmd), &cmd);
733 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -0700734 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
735 else
Emmanuel Grumbachb73cdf22008-04-21 15:41:58 -0700736 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
737 "critical temperature is %d\n",
738 cmd.critical_temperature_R);
Zhu Yib481de92007-09-25 17:54:57 -0700739}
740
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700741#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
Zhu Yib481de92007-09-25 17:54:57 -0700742
743/* Reset differential Rx gains in NIC to prepare for chain noise calibration.
744 * Called after every association, but this runs only once!
745 * ... once chain noise is calibrated the first time, it's good forever. */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700746static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700747{
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700748 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
Zhu Yib481de92007-09-25 17:54:57 -0700749
Tomas Winkler3109ece2008-03-28 16:33:35 -0700750 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800751 struct iwl4965_calibration_cmd cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700752
753 memset(&cmd, 0, sizeof(cmd));
754 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
755 cmd.diff_gain_a = 0;
756 cmd.diff_gain_b = 0;
757 cmd.diff_gain_c = 0;
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700758 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
759 sizeof(cmd), &cmd))
760 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
Zhu Yib481de92007-09-25 17:54:57 -0700761 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
762 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
763 }
Zhu Yib481de92007-09-25 17:54:57 -0700764}
765
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700766static void iwl4965_gain_computation(struct iwl_priv *priv,
767 u32 *average_noise,
768 u16 min_average_noise_antenna_i,
769 u32 min_average_noise)
Zhu Yib481de92007-09-25 17:54:57 -0700770{
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700771 int i, ret;
772 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
Zhu Yib481de92007-09-25 17:54:57 -0700773
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700774 data->delta_gain_code[min_average_noise_antenna_i] = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700775
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700776 for (i = 0; i < NUM_RX_CHAINS; i++) {
777 s32 delta_g = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700778
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700779 if (!(data->disconn_array[i]) &&
780 (data->delta_gain_code[i] ==
Zhu Yib481de92007-09-25 17:54:57 -0700781 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700782 delta_g = average_noise[i] - min_average_noise;
783 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
784 data->delta_gain_code[i] =
785 min(data->delta_gain_code[i],
786 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
Zhu Yib481de92007-09-25 17:54:57 -0700787
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700788 data->delta_gain_code[i] =
789 (data->delta_gain_code[i] | (1 << 2));
790 } else {
791 data->delta_gain_code[i] = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700792 }
Zhu Yib481de92007-09-25 17:54:57 -0700793 }
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700794 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
795 data->delta_gain_code[0],
796 data->delta_gain_code[1],
797 data->delta_gain_code[2]);
Zhu Yib481de92007-09-25 17:54:57 -0700798
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700799 /* Differential gain gets sent to uCode only once */
800 if (!data->radio_write) {
801 struct iwl4965_calibration_cmd cmd;
802 data->radio_write = 1;
Zhu Yib481de92007-09-25 17:54:57 -0700803
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700804 memset(&cmd, 0, sizeof(cmd));
805 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
806 cmd.diff_gain_a = data->delta_gain_code[0];
807 cmd.diff_gain_b = data->delta_gain_code[1];
808 cmd.diff_gain_c = data->delta_gain_code[2];
809 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
810 sizeof(cmd), &cmd);
811 if (ret)
812 IWL_DEBUG_CALIB("fail sending cmd "
813 "REPLY_PHY_CALIBRATION_CMD \n");
Zhu Yib481de92007-09-25 17:54:57 -0700814
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700815 /* TODO we might want recalculate
816 * rx_chain in rxon cmd */
817
818 /* Mark so we run this algo only once! */
819 data->state = IWL_CHAIN_NOISE_CALIBRATED;
Zhu Yib481de92007-09-25 17:54:57 -0700820 }
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700821 data->chain_noise_a = 0;
822 data->chain_noise_b = 0;
823 data->chain_noise_c = 0;
824 data->chain_signal_a = 0;
825 data->chain_signal_b = 0;
826 data->chain_signal_c = 0;
827 data->beacon_count = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700828}
829
830static void iwl4965_bg_sensitivity_work(struct work_struct *work)
831{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700832 struct iwl_priv *priv = container_of(work, struct iwl_priv,
Zhu Yib481de92007-09-25 17:54:57 -0700833 sensitivity_work);
834
835 mutex_lock(&priv->mutex);
836
837 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
838 test_bit(STATUS_SCANNING, &priv->status)) {
839 mutex_unlock(&priv->mutex);
840 return;
841 }
842
843 if (priv->start_calib) {
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700844 iwl_chain_noise_calibration(priv, &priv->statistics);
Zhu Yib481de92007-09-25 17:54:57 -0700845
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700846 iwl_sensitivity_calibration(priv, &priv->statistics);
Zhu Yib481de92007-09-25 17:54:57 -0700847 }
848
849 mutex_unlock(&priv->mutex);
850 return;
851}
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700852#endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
Zhu Yib481de92007-09-25 17:54:57 -0700853
854static void iwl4965_bg_txpower_work(struct work_struct *work)
855{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700856 struct iwl_priv *priv = container_of(work, struct iwl_priv,
Zhu Yib481de92007-09-25 17:54:57 -0700857 txpower_work);
858
859 /* If a scan happened to start before we got here
860 * then just return; the statistics notification will
861 * kick off another scheduled work to compensate for
862 * any temperature delta we missed here. */
863 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
864 test_bit(STATUS_SCANNING, &priv->status))
865 return;
866
867 mutex_lock(&priv->mutex);
868
869 /* Regardless of if we are assocaited, we must reconfigure the
870 * TX power since frames can be sent on non-radar channels while
871 * not associated */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800872 iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700873
874 /* Update last_temperature to keep is_calib_needed from running
875 * when it isn't needed... */
876 priv->last_temperature = priv->temperature;
877
878 mutex_unlock(&priv->mutex);
879}
880
881/*
882 * Acquire priv->lock before calling this function !
883 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700884static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
Zhu Yib481de92007-09-25 17:54:57 -0700885{
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700886 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
Zhu Yib481de92007-09-25 17:54:57 -0700887 (index & 0xff) | (txq_id << 8));
Tomas Winkler12a81f62008-04-03 16:05:20 -0700888 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
Zhu Yib481de92007-09-25 17:54:57 -0700889}
890
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800891/**
892 * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
893 * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
894 * @scd_retry: (1) Indicates queue will be used in aggregation mode
895 *
896 * NOTE: Acquire priv->lock before calling this function !
Zhu Yib481de92007-09-25 17:54:57 -0700897 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700898static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
Ron Rindjunsky16466902008-05-05 10:22:50 +0800899 struct iwl_tx_queue *txq,
Zhu Yib481de92007-09-25 17:54:57 -0700900 int tx_fifo_id, int scd_retry)
901{
902 int txq_id = txq->q.id;
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800903
904 /* Find out whether to activate Tx queue */
Zhu Yib481de92007-09-25 17:54:57 -0700905 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
906
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800907 /* Set up and activate */
Tomas Winkler12a81f62008-04-03 16:05:20 -0700908 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
Emmanuel Grumbach038669e2008-04-23 17:15:04 -0700909 (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
910 (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
911 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
912 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
913 IWL49_SCD_QUEUE_STTS_REG_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700914
915 txq->sched_retry = scd_retry;
916
917 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800918 active ? "Activate" : "Deactivate",
Zhu Yib481de92007-09-25 17:54:57 -0700919 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
920}
921
922static const u16 default_queue_to_tx_fifo[] = {
923 IWL_TX_FIFO_AC3,
924 IWL_TX_FIFO_AC2,
925 IWL_TX_FIFO_AC1,
926 IWL_TX_FIFO_AC0,
Emmanuel Grumbach038669e2008-04-23 17:15:04 -0700927 IWL49_CMD_FIFO_NUM,
Zhu Yib481de92007-09-25 17:54:57 -0700928 IWL_TX_FIFO_HCCA_1,
929 IWL_TX_FIFO_HCCA_2
930};
931
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700932int iwl4965_alive_notify(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700933{
934 u32 a;
935 int i = 0;
936 unsigned long flags;
Tomas Winkler857485c2008-03-21 13:53:44 -0700937 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700938
939 spin_lock_irqsave(&priv->lock, flags);
940
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700941 ret = iwl_grab_nic_access(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -0700942 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700943 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler857485c2008-03-21 13:53:44 -0700944 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700945 }
946
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800947 /* Clear 4965's internal Tx Scheduler data base */
Tomas Winkler12a81f62008-04-03 16:05:20 -0700948 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
Emmanuel Grumbach038669e2008-04-23 17:15:04 -0700949 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
950 for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700951 iwl_write_targ_mem(priv, a, 0);
Emmanuel Grumbach038669e2008-04-23 17:15:04 -0700952 for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700953 iwl_write_targ_mem(priv, a, 0);
Tomas Winkler5425e492008-04-15 16:01:38 -0700954 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700955 iwl_write_targ_mem(priv, a, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700956
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800957 /* Tel 4965 where to find Tx byte count tables */
Tomas Winkler12a81f62008-04-03 16:05:20 -0700958 iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
Tomas Winkler059ff822008-04-14 21:16:14 -0700959 (priv->shared_phys +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800960 offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800961
962 /* Disable chain mode for all queues */
Tomas Winkler12a81f62008-04-03 16:05:20 -0700963 iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700964
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800965 /* Initialize each Tx queue (including the command queue) */
Tomas Winkler5425e492008-04-15 16:01:38 -0700966 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800967
968 /* TFD circular buffer read/write indexes */
Tomas Winkler12a81f62008-04-03 16:05:20 -0700969 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700970 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800971
972 /* Max Tx Window size for Scheduler-ACK mode */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700973 iwl_write_targ_mem(priv, priv->scd_base_addr +
Emmanuel Grumbach038669e2008-04-23 17:15:04 -0700974 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
975 (SCD_WIN_SIZE <<
976 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
977 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800978
979 /* Frame limit */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700980 iwl_write_targ_mem(priv, priv->scd_base_addr +
Emmanuel Grumbach038669e2008-04-23 17:15:04 -0700981 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
982 sizeof(u32),
983 (SCD_FRAME_LIMIT <<
984 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
985 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700986
987 }
Tomas Winkler12a81f62008-04-03 16:05:20 -0700988 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
Tomas Winkler5425e492008-04-15 16:01:38 -0700989 (1 << priv->hw_params.max_txq_num) - 1);
Zhu Yib481de92007-09-25 17:54:57 -0700990
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800991 /* Activate all Tx DMA/FIFO channels */
Tomas Winkler12a81f62008-04-03 16:05:20 -0700992 iwl_write_prph(priv, IWL49_SCD_TXFACT,
Zhu Yib481de92007-09-25 17:54:57 -0700993 SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
994
995 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800996
997 /* Map each Tx/cmd queue to its corresponding fifo */
Zhu Yib481de92007-09-25 17:54:57 -0700998 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
999 int ac = default_queue_to_tx_fifo[i];
Ron Rindjunsky36470742008-05-15 13:54:10 +08001000 iwl_txq_ctx_activate(priv, i);
Zhu Yib481de92007-09-25 17:54:57 -07001001 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
1002 }
1003
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001004 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001005 spin_unlock_irqrestore(&priv->lock, flags);
1006
Tomas Winkler857485c2008-03-21 13:53:44 -07001007 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001008}
1009
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07001010#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1011static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
1012 .min_nrg_cck = 97,
1013 .max_nrg_cck = 0,
1014
1015 .auto_corr_min_ofdm = 85,
1016 .auto_corr_min_ofdm_mrc = 170,
1017 .auto_corr_min_ofdm_x1 = 105,
1018 .auto_corr_min_ofdm_mrc_x1 = 220,
1019
1020 .auto_corr_max_ofdm = 120,
1021 .auto_corr_max_ofdm_mrc = 210,
1022 .auto_corr_max_ofdm_x1 = 140,
1023 .auto_corr_max_ofdm_mrc_x1 = 270,
1024
1025 .auto_corr_min_cck = 125,
1026 .auto_corr_max_cck = 200,
1027 .auto_corr_min_cck_mrc = 200,
1028 .auto_corr_max_cck_mrc = 400,
1029
1030 .nrg_th_cck = 100,
1031 .nrg_th_ofdm = 100,
1032};
1033#endif
1034
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08001035/**
Tomas Winkler5425e492008-04-15 16:01:38 -07001036 * iwl4965_hw_set_hw_params
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08001037 *
1038 * Called when initializing driver
1039 */
Tomas Winkler5425e492008-04-15 16:01:38 -07001040int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001041{
Assaf Krauss316c30d2008-03-14 10:38:46 -07001042
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07001043 if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
Assaf Krauss1ea87392008-03-18 14:57:50 -07001044 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07001045 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07001046 IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
Tomas Winkler059ff822008-04-14 21:16:14 -07001047 return -EINVAL;
Assaf Krauss316c30d2008-03-14 10:38:46 -07001048 }
1049
Tomas Winkler5425e492008-04-15 16:01:38 -07001050 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001051 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
Tomas Winkler5425e492008-04-15 16:01:38 -07001052 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1053 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
Assaf Krauss1ea87392008-03-18 14:57:50 -07001054 if (priv->cfg->mod_params->amsdu_size_8K)
Tomas Winkler5425e492008-04-15 16:01:38 -07001055 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001056 else
Tomas Winkler5425e492008-04-15 16:01:38 -07001057 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
1058 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
1059 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
1060 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
Tomas Winkler3e82a822008-02-13 11:32:31 -08001061
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001062 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
1063 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
1064 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
1065 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
1066
Tomas Winklerec35cf22008-04-15 16:01:39 -07001067 priv->hw_params.tx_chains_num = 2;
1068 priv->hw_params.rx_chains_num = 2;
Guy Cohenfde0db32008-04-21 15:42:01 -07001069 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
1070 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001071 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
1072
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07001073#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1074 priv->hw_params.sens = &iwl4965_sensitivity;
1075#endif
Tomas Winkler3e82a822008-02-13 11:32:31 -08001076
Tomas Winkler059ff822008-04-14 21:16:14 -07001077 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001078}
1079
Mohamed Abbas5da4b552008-04-21 15:41:51 -07001080/* set card power command */
1081static int iwl4965_set_power(struct iwl_priv *priv,
1082 void *cmd)
1083{
1084 int ret = 0;
1085
1086 ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
1087 sizeof(struct iwl4965_powertable_cmd),
1088 cmd, NULL);
1089 return ret;
1090}
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001091int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
Zhu Yib481de92007-09-25 17:54:57 -07001092{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001093 IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
Zhu Yib481de92007-09-25 17:54:57 -07001094 return -EINVAL;
1095}
1096
1097static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
1098{
1099 s32 sign = 1;
1100
1101 if (num < 0) {
1102 sign = -sign;
1103 num = -num;
1104 }
1105 if (denom < 0) {
1106 sign = -sign;
1107 denom = -denom;
1108 }
1109 *res = 1;
1110 *res = ((num * 2 + denom) / (denom * 2)) * sign;
1111
1112 return 1;
1113}
1114
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08001115/**
1116 * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
1117 *
1118 * Determines power supply voltage compensation for txpower calculations.
1119 * Returns number of 1/2-dB steps to subtract from gain table index,
1120 * to compensate for difference between power supply voltage during
1121 * factory measurements, vs. current power supply voltage.
1122 *
1123 * Voltage indication is higher for lower voltage.
1124 * Lower voltage requires more gain (lower gain table index).
1125 */
Zhu Yib481de92007-09-25 17:54:57 -07001126static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
1127 s32 current_voltage)
1128{
1129 s32 comp = 0;
1130
1131 if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
1132 (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
1133 return 0;
1134
1135 iwl4965_math_div_round(current_voltage - eeprom_voltage,
1136 TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
1137
1138 if (current_voltage > eeprom_voltage)
1139 comp *= 2;
1140 if ((comp < -2) || (comp > 2))
1141 comp = 0;
1142
1143 return comp;
1144}
1145
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001146static const struct iwl_channel_info *
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001147iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001148 enum ieee80211_band band, u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -07001149{
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001150 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001151
Assaf Krauss8622e702008-03-21 13:53:43 -07001152 ch_info = iwl_get_channel_info(priv, band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07001153
1154 if (!is_channel_valid(ch_info))
1155 return NULL;
1156
1157 return ch_info;
1158}
1159
1160static s32 iwl4965_get_tx_atten_grp(u16 channel)
1161{
1162 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
1163 channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
1164 return CALIB_CH_GROUP_5;
1165
1166 if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
1167 channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
1168 return CALIB_CH_GROUP_1;
1169
1170 if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
1171 channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
1172 return CALIB_CH_GROUP_2;
1173
1174 if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
1175 channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
1176 return CALIB_CH_GROUP_3;
1177
1178 if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
1179 channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
1180 return CALIB_CH_GROUP_4;
1181
1182 IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
1183 return -1;
1184}
1185
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001186static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
Zhu Yib481de92007-09-25 17:54:57 -07001187{
1188 s32 b = -1;
1189
1190 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
Tomas Winkler073d3f52008-04-21 15:41:52 -07001191 if (priv->calib_info->band_info[b].ch_from == 0)
Zhu Yib481de92007-09-25 17:54:57 -07001192 continue;
1193
Tomas Winkler073d3f52008-04-21 15:41:52 -07001194 if ((channel >= priv->calib_info->band_info[b].ch_from)
1195 && (channel <= priv->calib_info->band_info[b].ch_to))
Zhu Yib481de92007-09-25 17:54:57 -07001196 break;
1197 }
1198
1199 return b;
1200}
1201
1202static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
1203{
1204 s32 val;
1205
1206 if (x2 == x1)
1207 return y1;
1208 else {
1209 iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
1210 return val + y2;
1211 }
1212}
1213
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08001214/**
1215 * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
1216 *
1217 * Interpolates factory measurements from the two sample channels within a
1218 * sub-band, to apply to channel of interest. Interpolation is proportional to
1219 * differences in channel frequencies, which is proportional to differences
1220 * in channel number.
1221 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001222static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
Tomas Winkler073d3f52008-04-21 15:41:52 -07001223 struct iwl_eeprom_calib_ch_info *chan_info)
Zhu Yib481de92007-09-25 17:54:57 -07001224{
1225 s32 s = -1;
1226 u32 c;
1227 u32 m;
Tomas Winkler073d3f52008-04-21 15:41:52 -07001228 const struct iwl_eeprom_calib_measure *m1;
1229 const struct iwl_eeprom_calib_measure *m2;
1230 struct iwl_eeprom_calib_measure *omeas;
Zhu Yib481de92007-09-25 17:54:57 -07001231 u32 ch_i1;
1232 u32 ch_i2;
1233
1234 s = iwl4965_get_sub_band(priv, channel);
1235 if (s >= EEPROM_TX_POWER_BANDS) {
1236 IWL_ERROR("Tx Power can not find channel %d ", channel);
1237 return -1;
1238 }
1239
Tomas Winkler073d3f52008-04-21 15:41:52 -07001240 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
1241 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
Zhu Yib481de92007-09-25 17:54:57 -07001242 chan_info->ch_num = (u8) channel;
1243
1244 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
1245 channel, s, ch_i1, ch_i2);
1246
1247 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
1248 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
Tomas Winkler073d3f52008-04-21 15:41:52 -07001249 m1 = &(priv->calib_info->band_info[s].ch1.
Zhu Yib481de92007-09-25 17:54:57 -07001250 measurements[c][m]);
Tomas Winkler073d3f52008-04-21 15:41:52 -07001251 m2 = &(priv->calib_info->band_info[s].ch2.
Zhu Yib481de92007-09-25 17:54:57 -07001252 measurements[c][m]);
1253 omeas = &(chan_info->measurements[c][m]);
1254
1255 omeas->actual_pow =
1256 (u8) iwl4965_interpolate_value(channel, ch_i1,
1257 m1->actual_pow,
1258 ch_i2,
1259 m2->actual_pow);
1260 omeas->gain_idx =
1261 (u8) iwl4965_interpolate_value(channel, ch_i1,
1262 m1->gain_idx, ch_i2,
1263 m2->gain_idx);
1264 omeas->temperature =
1265 (u8) iwl4965_interpolate_value(channel, ch_i1,
1266 m1->temperature,
1267 ch_i2,
1268 m2->temperature);
1269 omeas->pa_det =
1270 (s8) iwl4965_interpolate_value(channel, ch_i1,
1271 m1->pa_det, ch_i2,
1272 m2->pa_det);
1273
1274 IWL_DEBUG_TXPOWER
1275 ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
1276 m1->actual_pow, m2->actual_pow, omeas->actual_pow);
1277 IWL_DEBUG_TXPOWER
1278 ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
1279 m1->gain_idx, m2->gain_idx, omeas->gain_idx);
1280 IWL_DEBUG_TXPOWER
1281 ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
1282 m1->pa_det, m2->pa_det, omeas->pa_det);
1283 IWL_DEBUG_TXPOWER
1284 ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
1285 m1->temperature, m2->temperature,
1286 omeas->temperature);
1287 }
1288 }
1289
1290 return 0;
1291}
1292
1293/* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
1294 * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
1295static s32 back_off_table[] = {
1296 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
1297 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
1298 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
1299 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
1300 10 /* CCK */
1301};
1302
1303/* Thermal compensation values for txpower for various frequency ranges ...
1304 * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001305static struct iwl4965_txpower_comp_entry {
Zhu Yib481de92007-09-25 17:54:57 -07001306 s32 degrees_per_05db_a;
1307 s32 degrees_per_05db_a_denom;
1308} tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
1309 {9, 2}, /* group 0 5.2, ch 34-43 */
1310 {4, 1}, /* group 1 5.2, ch 44-70 */
1311 {4, 1}, /* group 2 5.2, ch 71-124 */
1312 {4, 1}, /* group 3 5.2, ch 125-200 */
1313 {3, 1} /* group 4 2.4, ch all */
1314};
1315
1316static s32 get_min_power_index(s32 rate_power_index, u32 band)
1317{
1318 if (!band) {
1319 if ((rate_power_index & 7) <= 4)
1320 return MIN_TX_GAIN_INDEX_52GHZ_EXT;
1321 }
1322 return MIN_TX_GAIN_INDEX;
1323}
1324
1325struct gain_entry {
1326 u8 dsp;
1327 u8 radio;
1328};
1329
1330static const struct gain_entry gain_table[2][108] = {
1331 /* 5.2GHz power gain index table */
1332 {
1333 {123, 0x3F}, /* highest txpower */
1334 {117, 0x3F},
1335 {110, 0x3F},
1336 {104, 0x3F},
1337 {98, 0x3F},
1338 {110, 0x3E},
1339 {104, 0x3E},
1340 {98, 0x3E},
1341 {110, 0x3D},
1342 {104, 0x3D},
1343 {98, 0x3D},
1344 {110, 0x3C},
1345 {104, 0x3C},
1346 {98, 0x3C},
1347 {110, 0x3B},
1348 {104, 0x3B},
1349 {98, 0x3B},
1350 {110, 0x3A},
1351 {104, 0x3A},
1352 {98, 0x3A},
1353 {110, 0x39},
1354 {104, 0x39},
1355 {98, 0x39},
1356 {110, 0x38},
1357 {104, 0x38},
1358 {98, 0x38},
1359 {110, 0x37},
1360 {104, 0x37},
1361 {98, 0x37},
1362 {110, 0x36},
1363 {104, 0x36},
1364 {98, 0x36},
1365 {110, 0x35},
1366 {104, 0x35},
1367 {98, 0x35},
1368 {110, 0x34},
1369 {104, 0x34},
1370 {98, 0x34},
1371 {110, 0x33},
1372 {104, 0x33},
1373 {98, 0x33},
1374 {110, 0x32},
1375 {104, 0x32},
1376 {98, 0x32},
1377 {110, 0x31},
1378 {104, 0x31},
1379 {98, 0x31},
1380 {110, 0x30},
1381 {104, 0x30},
1382 {98, 0x30},
1383 {110, 0x25},
1384 {104, 0x25},
1385 {98, 0x25},
1386 {110, 0x24},
1387 {104, 0x24},
1388 {98, 0x24},
1389 {110, 0x23},
1390 {104, 0x23},
1391 {98, 0x23},
1392 {110, 0x22},
1393 {104, 0x18},
1394 {98, 0x18},
1395 {110, 0x17},
1396 {104, 0x17},
1397 {98, 0x17},
1398 {110, 0x16},
1399 {104, 0x16},
1400 {98, 0x16},
1401 {110, 0x15},
1402 {104, 0x15},
1403 {98, 0x15},
1404 {110, 0x14},
1405 {104, 0x14},
1406 {98, 0x14},
1407 {110, 0x13},
1408 {104, 0x13},
1409 {98, 0x13},
1410 {110, 0x12},
1411 {104, 0x08},
1412 {98, 0x08},
1413 {110, 0x07},
1414 {104, 0x07},
1415 {98, 0x07},
1416 {110, 0x06},
1417 {104, 0x06},
1418 {98, 0x06},
1419 {110, 0x05},
1420 {104, 0x05},
1421 {98, 0x05},
1422 {110, 0x04},
1423 {104, 0x04},
1424 {98, 0x04},
1425 {110, 0x03},
1426 {104, 0x03},
1427 {98, 0x03},
1428 {110, 0x02},
1429 {104, 0x02},
1430 {98, 0x02},
1431 {110, 0x01},
1432 {104, 0x01},
1433 {98, 0x01},
1434 {110, 0x00},
1435 {104, 0x00},
1436 {98, 0x00},
1437 {93, 0x00},
1438 {88, 0x00},
1439 {83, 0x00},
1440 {78, 0x00},
1441 },
1442 /* 2.4GHz power gain index table */
1443 {
1444 {110, 0x3f}, /* highest txpower */
1445 {104, 0x3f},
1446 {98, 0x3f},
1447 {110, 0x3e},
1448 {104, 0x3e},
1449 {98, 0x3e},
1450 {110, 0x3d},
1451 {104, 0x3d},
1452 {98, 0x3d},
1453 {110, 0x3c},
1454 {104, 0x3c},
1455 {98, 0x3c},
1456 {110, 0x3b},
1457 {104, 0x3b},
1458 {98, 0x3b},
1459 {110, 0x3a},
1460 {104, 0x3a},
1461 {98, 0x3a},
1462 {110, 0x39},
1463 {104, 0x39},
1464 {98, 0x39},
1465 {110, 0x38},
1466 {104, 0x38},
1467 {98, 0x38},
1468 {110, 0x37},
1469 {104, 0x37},
1470 {98, 0x37},
1471 {110, 0x36},
1472 {104, 0x36},
1473 {98, 0x36},
1474 {110, 0x35},
1475 {104, 0x35},
1476 {98, 0x35},
1477 {110, 0x34},
1478 {104, 0x34},
1479 {98, 0x34},
1480 {110, 0x33},
1481 {104, 0x33},
1482 {98, 0x33},
1483 {110, 0x32},
1484 {104, 0x32},
1485 {98, 0x32},
1486 {110, 0x31},
1487 {104, 0x31},
1488 {98, 0x31},
1489 {110, 0x30},
1490 {104, 0x30},
1491 {98, 0x30},
1492 {110, 0x6},
1493 {104, 0x6},
1494 {98, 0x6},
1495 {110, 0x5},
1496 {104, 0x5},
1497 {98, 0x5},
1498 {110, 0x4},
1499 {104, 0x4},
1500 {98, 0x4},
1501 {110, 0x3},
1502 {104, 0x3},
1503 {98, 0x3},
1504 {110, 0x2},
1505 {104, 0x2},
1506 {98, 0x2},
1507 {110, 0x1},
1508 {104, 0x1},
1509 {98, 0x1},
1510 {110, 0x0},
1511 {104, 0x0},
1512 {98, 0x0},
1513 {97, 0},
1514 {96, 0},
1515 {95, 0},
1516 {94, 0},
1517 {93, 0},
1518 {92, 0},
1519 {91, 0},
1520 {90, 0},
1521 {89, 0},
1522 {88, 0},
1523 {87, 0},
1524 {86, 0},
1525 {85, 0},
1526 {84, 0},
1527 {83, 0},
1528 {82, 0},
1529 {81, 0},
1530 {80, 0},
1531 {79, 0},
1532 {78, 0},
1533 {77, 0},
1534 {76, 0},
1535 {75, 0},
1536 {74, 0},
1537 {73, 0},
1538 {72, 0},
1539 {71, 0},
1540 {70, 0},
1541 {69, 0},
1542 {68, 0},
1543 {67, 0},
1544 {66, 0},
1545 {65, 0},
1546 {64, 0},
1547 {63, 0},
1548 {62, 0},
1549 {61, 0},
1550 {60, 0},
1551 {59, 0},
1552 }
1553};
1554
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001555static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
Zhu Yib481de92007-09-25 17:54:57 -07001556 u8 is_fat, u8 ctrl_chan_high,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001557 struct iwl4965_tx_power_db *tx_power_tbl)
Zhu Yib481de92007-09-25 17:54:57 -07001558{
1559 u8 saturation_power;
1560 s32 target_power;
1561 s32 user_target_power;
1562 s32 power_limit;
1563 s32 current_temp;
1564 s32 reg_limit;
1565 s32 current_regulatory;
1566 s32 txatten_grp = CALIB_CH_GROUP_MAX;
1567 int i;
1568 int c;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001569 const struct iwl_channel_info *ch_info = NULL;
Tomas Winkler073d3f52008-04-21 15:41:52 -07001570 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
1571 const struct iwl_eeprom_calib_measure *measurement;
Zhu Yib481de92007-09-25 17:54:57 -07001572 s16 voltage;
1573 s32 init_voltage;
1574 s32 voltage_compensation;
1575 s32 degrees_per_05db_num;
1576 s32 degrees_per_05db_denom;
1577 s32 factory_temp;
1578 s32 temperature_comp[2];
1579 s32 factory_gain_index[2];
1580 s32 factory_actual_pwr[2];
1581 s32 power_index;
1582
1583 /* Sanity check requested level (dBm) */
1584 if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
1585 IWL_WARNING("Requested user TXPOWER %d below limit.\n",
1586 priv->user_txpower_limit);
1587 return -EINVAL;
1588 }
1589 if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
1590 IWL_WARNING("Requested user TXPOWER %d above limit.\n",
1591 priv->user_txpower_limit);
1592 return -EINVAL;
1593 }
1594
1595 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
1596 * are used for indexing into txpower table) */
1597 user_target_power = 2 * priv->user_txpower_limit;
1598
1599 /* Get current (RXON) channel, band, width */
1600 ch_info =
Johannes Berg8318d782008-01-24 19:38:38 +01001601 iwl4965_get_channel_txpower_info(priv, priv->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07001602
1603 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
1604 is_fat);
1605
1606 if (!ch_info)
1607 return -EINVAL;
1608
1609 /* get txatten group, used to select 1) thermal txpower adjustment
1610 * and 2) mimo txpower balance between Tx chains. */
1611 txatten_grp = iwl4965_get_tx_atten_grp(channel);
1612 if (txatten_grp < 0)
1613 return -EINVAL;
1614
1615 IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
1616 channel, txatten_grp);
1617
1618 if (is_fat) {
1619 if (ctrl_chan_high)
1620 channel -= 2;
1621 else
1622 channel += 2;
1623 }
1624
1625 /* hardware txpower limits ...
1626 * saturation (clipping distortion) txpowers are in half-dBm */
1627 if (band)
Tomas Winkler073d3f52008-04-21 15:41:52 -07001628 saturation_power = priv->calib_info->saturation_power24;
Zhu Yib481de92007-09-25 17:54:57 -07001629 else
Tomas Winkler073d3f52008-04-21 15:41:52 -07001630 saturation_power = priv->calib_info->saturation_power52;
Zhu Yib481de92007-09-25 17:54:57 -07001631
1632 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
1633 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
1634 if (band)
1635 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
1636 else
1637 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
1638 }
1639
1640 /* regulatory txpower limits ... reg_limit values are in half-dBm,
1641 * max_power_avg values are in dBm, convert * 2 */
1642 if (is_fat)
1643 reg_limit = ch_info->fat_max_power_avg * 2;
1644 else
1645 reg_limit = ch_info->max_power_avg * 2;
1646
1647 if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
1648 (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
1649 if (band)
1650 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
1651 else
1652 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
1653 }
1654
1655 /* Interpolate txpower calibration values for this channel,
1656 * based on factory calibration tests on spaced channels. */
1657 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
1658
1659 /* calculate tx gain adjustment based on power supply voltage */
Tomas Winkler073d3f52008-04-21 15:41:52 -07001660 voltage = priv->calib_info->voltage;
Zhu Yib481de92007-09-25 17:54:57 -07001661 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
1662 voltage_compensation =
1663 iwl4965_get_voltage_compensation(voltage, init_voltage);
1664
1665 IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
1666 init_voltage,
1667 voltage, voltage_compensation);
1668
1669 /* get current temperature (Celsius) */
1670 current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
1671 current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
1672 current_temp = KELVIN_TO_CELSIUS(current_temp);
1673
1674 /* select thermal txpower adjustment params, based on channel group
1675 * (same frequency group used for mimo txatten adjustment) */
1676 degrees_per_05db_num =
1677 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
1678 degrees_per_05db_denom =
1679 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
1680
1681 /* get per-chain txpower values from factory measurements */
1682 for (c = 0; c < 2; c++) {
1683 measurement = &ch_eeprom_info.measurements[c][1];
1684
1685 /* txgain adjustment (in half-dB steps) based on difference
1686 * between factory and current temperature */
1687 factory_temp = measurement->temperature;
1688 iwl4965_math_div_round((current_temp - factory_temp) *
1689 degrees_per_05db_denom,
1690 degrees_per_05db_num,
1691 &temperature_comp[c]);
1692
1693 factory_gain_index[c] = measurement->gain_idx;
1694 factory_actual_pwr[c] = measurement->actual_pow;
1695
1696 IWL_DEBUG_TXPOWER("chain = %d\n", c);
1697 IWL_DEBUG_TXPOWER("fctry tmp %d, "
1698 "curr tmp %d, comp %d steps\n",
1699 factory_temp, current_temp,
1700 temperature_comp[c]);
1701
1702 IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
1703 factory_gain_index[c],
1704 factory_actual_pwr[c]);
1705 }
1706
1707 /* for each of 33 bit-rates (including 1 for CCK) */
1708 for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
1709 u8 is_mimo_rate;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001710 union iwl4965_tx_power_dual_stream tx_power;
Zhu Yib481de92007-09-25 17:54:57 -07001711
1712 /* for mimo, reduce each chain's txpower by half
1713 * (3dB, 6 steps), so total output power is regulatory
1714 * compliant. */
1715 if (i & 0x8) {
1716 current_regulatory = reg_limit -
1717 IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
1718 is_mimo_rate = 1;
1719 } else {
1720 current_regulatory = reg_limit;
1721 is_mimo_rate = 0;
1722 }
1723
1724 /* find txpower limit, either hardware or regulatory */
1725 power_limit = saturation_power - back_off_table[i];
1726 if (power_limit > current_regulatory)
1727 power_limit = current_regulatory;
1728
1729 /* reduce user's txpower request if necessary
1730 * for this rate on this channel */
1731 target_power = user_target_power;
1732 if (target_power > power_limit)
1733 target_power = power_limit;
1734
1735 IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
1736 i, saturation_power - back_off_table[i],
1737 current_regulatory, user_target_power,
1738 target_power);
1739
1740 /* for each of 2 Tx chains (radio transmitters) */
1741 for (c = 0; c < 2; c++) {
1742 s32 atten_value;
1743
1744 if (is_mimo_rate)
1745 atten_value =
1746 (s32)le32_to_cpu(priv->card_alive_init.
1747 tx_atten[txatten_grp][c]);
1748 else
1749 atten_value = 0;
1750
1751 /* calculate index; higher index means lower txpower */
1752 power_index = (u8) (factory_gain_index[c] -
1753 (target_power -
1754 factory_actual_pwr[c]) -
1755 temperature_comp[c] -
1756 voltage_compensation +
1757 atten_value);
1758
1759/* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
1760 power_index); */
1761
1762 if (power_index < get_min_power_index(i, band))
1763 power_index = get_min_power_index(i, band);
1764
1765 /* adjust 5 GHz index to support negative indexes */
1766 if (!band)
1767 power_index += 9;
1768
1769 /* CCK, rate 32, reduce txpower for CCK */
1770 if (i == POWER_TABLE_CCK_ENTRY)
1771 power_index +=
1772 IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
1773
1774 /* stay within the table! */
1775 if (power_index > 107) {
1776 IWL_WARNING("txpower index %d > 107\n",
1777 power_index);
1778 power_index = 107;
1779 }
1780 if (power_index < 0) {
1781 IWL_WARNING("txpower index %d < 0\n",
1782 power_index);
1783 power_index = 0;
1784 }
1785
1786 /* fill txpower command for this rate/chain */
1787 tx_power.s.radio_tx_gain[c] =
1788 gain_table[band][power_index].radio;
1789 tx_power.s.dsp_predis_atten[c] =
1790 gain_table[band][power_index].dsp;
1791
1792 IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
1793 "gain 0x%02x dsp %d\n",
1794 c, atten_value, power_index,
1795 tx_power.s.radio_tx_gain[c],
1796 tx_power.s.dsp_predis_atten[c]);
1797 }/* for each chain */
1798
1799 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
1800
1801 }/* for each rate */
1802
1803 return 0;
1804}
1805
1806/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001807 * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit
Zhu Yib481de92007-09-25 17:54:57 -07001808 *
1809 * Uses the active RXON for channel, band, and characteristics (fat, high)
1810 * The power limit is taken from priv->user_txpower_limit.
1811 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001812int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001813{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001814 struct iwl4965_txpowertable_cmd cmd = { 0 };
Tomas Winkler857485c2008-03-21 13:53:44 -07001815 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001816 u8 band = 0;
1817 u8 is_fat = 0;
1818 u8 ctrl_chan_high = 0;
1819
1820 if (test_bit(STATUS_SCANNING, &priv->status)) {
1821 /* If this gets hit a lot, switch it to a BUG() and catch
1822 * the stack trace to find out who is calling this during
1823 * a scan. */
1824 IWL_WARNING("TX Power requested while scanning!\n");
1825 return -EAGAIN;
1826 }
1827
Johannes Berg8318d782008-01-24 19:38:38 +01001828 band = priv->band == IEEE80211_BAND_2GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001829
1830 is_fat = is_fat_channel(priv->active_rxon.flags);
1831
1832 if (is_fat &&
1833 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1834 ctrl_chan_high = 1;
1835
1836 cmd.band = band;
1837 cmd.channel = priv->active_rxon.channel;
1838
Tomas Winkler857485c2008-03-21 13:53:44 -07001839 ret = iwl4965_fill_txpower_tbl(priv, band,
Zhu Yib481de92007-09-25 17:54:57 -07001840 le16_to_cpu(priv->active_rxon.channel),
1841 is_fat, ctrl_chan_high, &cmd.tx_power);
Tomas Winkler857485c2008-03-21 13:53:44 -07001842 if (ret)
1843 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07001844
Tomas Winkler857485c2008-03-21 13:53:44 -07001845 ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
1846
1847out:
1848 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001849}
1850
Tomas Winkler7e8c5192008-04-15 16:01:43 -07001851static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1852{
1853 int ret = 0;
1854 struct iwl4965_rxon_assoc_cmd rxon_assoc;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001855 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1856 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
Tomas Winkler7e8c5192008-04-15 16:01:43 -07001857
1858 if ((rxon1->flags == rxon2->flags) &&
1859 (rxon1->filter_flags == rxon2->filter_flags) &&
1860 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1861 (rxon1->ofdm_ht_single_stream_basic_rates ==
1862 rxon2->ofdm_ht_single_stream_basic_rates) &&
1863 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1864 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1865 (rxon1->rx_chain == rxon2->rx_chain) &&
1866 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1867 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1868 return 0;
1869 }
1870
1871 rxon_assoc.flags = priv->staging_rxon.flags;
1872 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1873 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1874 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1875 rxon_assoc.reserved = 0;
1876 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1877 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1878 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1879 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1880 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1881
1882 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1883 sizeof(rxon_assoc), &rxon_assoc, NULL);
1884 if (ret)
1885 return ret;
1886
1887 return ret;
1888}
1889
1890
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001891int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -07001892{
1893 int rc;
1894 u8 band = 0;
1895 u8 is_fat = 0;
1896 u8 ctrl_chan_high = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001897 struct iwl4965_channel_switch_cmd cmd = { 0 };
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001898 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001899
Johannes Berg8318d782008-01-24 19:38:38 +01001900 band = priv->band == IEEE80211_BAND_2GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001901
Assaf Krauss8622e702008-03-21 13:53:43 -07001902 ch_info = iwl_get_channel_info(priv, priv->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07001903
1904 is_fat = is_fat_channel(priv->staging_rxon.flags);
1905
1906 if (is_fat &&
1907 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1908 ctrl_chan_high = 1;
1909
1910 cmd.band = band;
1911 cmd.expect_beacon = 0;
1912 cmd.channel = cpu_to_le16(channel);
1913 cmd.rxon_flags = priv->active_rxon.flags;
1914 cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
1915 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
1916 if (ch_info)
1917 cmd.expect_beacon = is_channel_radar(ch_info);
1918 else
1919 cmd.expect_beacon = 1;
1920
1921 rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
1922 ctrl_chan_high, &cmd.tx_power);
1923 if (rc) {
1924 IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
1925 return rc;
1926 }
1927
Tomas Winkler857485c2008-03-21 13:53:44 -07001928 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001929 return rc;
1930}
1931
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001932static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001933{
Tomas Winkler059ff822008-04-14 21:16:14 -07001934 struct iwl4965_shared *s = priv->shared_virt;
1935 return le32_to_cpu(s->rb_closed) & 0xFFF;
Zhu Yib481de92007-09-25 17:54:57 -07001936}
1937
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001938int iwl4965_hw_get_temperature(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001939{
1940 return priv->temperature;
1941}
1942
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001943unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winklerfcab4232008-05-15 13:54:01 +08001944 struct iwl_frame *frame, u8 rate)
Zhu Yib481de92007-09-25 17:54:57 -07001945{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001946 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001947 unsigned int frame_size;
1948
1949 tx_beacon_cmd = &frame->u.beacon;
1950 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
1951
Tomas Winkler5425e492008-04-15 16:01:38 -07001952 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001953 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
1954
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001955 frame_size = iwl4965_fill_beacon_frame(priv,
Zhu Yib481de92007-09-25 17:54:57 -07001956 tx_beacon_cmd->frame,
Tomas Winkler57bd1be2008-05-15 13:54:03 +08001957 iwl_bcast_addr,
Zhu Yib481de92007-09-25 17:54:57 -07001958 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
1959
1960 BUG_ON(frame_size > MAX_MPDU_SIZE);
1961 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
1962
1963 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
1964 tx_beacon_cmd->tx.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001965 iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
Zhu Yib481de92007-09-25 17:54:57 -07001966 else
1967 tx_beacon_cmd->tx.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001968 iwl4965_hw_set_rate_n_flags(rate, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001969
1970 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
1971 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
1972 return (sizeof(*tx_beacon_cmd) + frame_size);
1973}
1974
Ron Rindjunsky399f4902008-04-23 17:14:56 -07001975static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
1976{
1977 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
1978 sizeof(struct iwl4965_shared),
1979 &priv->shared_phys);
1980 if (!priv->shared_virt)
1981 return -ENOMEM;
1982
1983 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
1984
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001985 priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed);
1986
Ron Rindjunsky399f4902008-04-23 17:14:56 -07001987 return 0;
1988}
1989
1990static void iwl4965_free_shared_mem(struct iwl_priv *priv)
1991{
1992 if (priv->shared_virt)
1993 pci_free_consistent(priv->pci_dev,
1994 sizeof(struct iwl4965_shared),
1995 priv->shared_virt,
1996 priv->shared_phys);
1997}
1998
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08001999/**
Tomas Winklere2a722e2008-04-14 21:16:10 -07002000 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002001 */
Tomas Winklere2a722e2008-04-14 21:16:10 -07002002static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
Ron Rindjunsky16466902008-05-05 10:22:50 +08002003 struct iwl_tx_queue *txq,
Tomas Winklere2a722e2008-04-14 21:16:10 -07002004 u16 byte_cnt)
Zhu Yib481de92007-09-25 17:54:57 -07002005{
2006 int len;
2007 int txq_id = txq->q.id;
Tomas Winkler059ff822008-04-14 21:16:14 -07002008 struct iwl4965_shared *shared_data = priv->shared_virt;
Zhu Yib481de92007-09-25 17:54:57 -07002009
Zhu Yib481de92007-09-25 17:54:57 -07002010 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
2011
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002012 /* Set up byte count within first 256 entries */
Zhu Yib481de92007-09-25 17:54:57 -07002013 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002014 tfd_offset[txq->q.write_ptr], byte_cnt, len);
Zhu Yib481de92007-09-25 17:54:57 -07002015
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002016 /* If within first 64 entries, duplicate at end */
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07002017 if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
Zhu Yib481de92007-09-25 17:54:57 -07002018 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07002019 tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
Zhu Yib481de92007-09-25 17:54:57 -07002020 byte_cnt, len);
Zhu Yib481de92007-09-25 17:54:57 -07002021}
2022
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002023/**
Zhu Yib481de92007-09-25 17:54:57 -07002024 * sign_extend - Sign extend a value using specified bit as sign-bit
2025 *
2026 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
2027 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
2028 *
2029 * @param oper value to sign extend
2030 * @param index 0 based bit index (0<=index<32) to sign bit
2031 */
2032static s32 sign_extend(u32 oper, int index)
2033{
2034 u8 shift = 31 - index;
2035
2036 return (s32)(oper << shift) >> shift;
2037}
2038
2039/**
2040 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
2041 * @statistics: Provides the temperature reading from the uCode
2042 *
2043 * A return of <0 indicates bogus data in the statistics
2044 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002045int iwl4965_get_temperature(const struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002046{
2047 s32 temperature;
2048 s32 vt;
2049 s32 R1, R2, R3;
2050 u32 R4;
2051
2052 if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
2053 (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
2054 IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
2055 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
2056 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
2057 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
2058 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
2059 } else {
2060 IWL_DEBUG_TEMP("Running temperature calibration\n");
2061 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
2062 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
2063 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
2064 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
2065 }
2066
2067 /*
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002068 * Temperature is only 23 bits, so sign extend out to 32.
Zhu Yib481de92007-09-25 17:54:57 -07002069 *
2070 * NOTE If we haven't received a statistics notification yet
2071 * with an updated temperature, use R4 provided to us in the
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002072 * "initialize" ALIVE response.
2073 */
Zhu Yib481de92007-09-25 17:54:57 -07002074 if (!test_bit(STATUS_TEMPERATURE, &priv->status))
2075 vt = sign_extend(R4, 23);
2076 else
2077 vt = sign_extend(
2078 le32_to_cpu(priv->statistics.general.temperature), 23);
2079
2080 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
2081 R1, R2, R3, vt);
2082
2083 if (R3 == R1) {
2084 IWL_ERROR("Calibration conflict R1 == R3\n");
2085 return -1;
2086 }
2087
2088 /* Calculate temperature in degrees Kelvin, adjust by 97%.
2089 * Add offset to center the adjustment around 0 degrees Centigrade. */
2090 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
2091 temperature /= (R3 - R1);
2092 temperature = (temperature * 97) / 100 +
2093 TEMPERATURE_CALIB_KELVIN_OFFSET;
2094
2095 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
2096 KELVIN_TO_CELSIUS(temperature));
2097
2098 return temperature;
2099}
2100
2101/* Adjust Txpower only if temperature variance is greater than threshold. */
2102#define IWL_TEMPERATURE_THRESHOLD 3
2103
2104/**
2105 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
2106 *
2107 * If the temperature changed has changed sufficiently, then a recalibration
2108 * is needed.
2109 *
2110 * Assumes caller will replace priv->last_temperature once calibration
2111 * executed.
2112 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002113static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002114{
2115 int temp_diff;
2116
2117 if (!test_bit(STATUS_STATISTICS, &priv->status)) {
2118 IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
2119 return 0;
2120 }
2121
2122 temp_diff = priv->temperature - priv->last_temperature;
2123
2124 /* get absolute value */
2125 if (temp_diff < 0) {
2126 IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
2127 temp_diff = -temp_diff;
2128 } else if (temp_diff == 0)
2129 IWL_DEBUG_POWER("Same temp, \n");
2130 else
2131 IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
2132
2133 if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
2134 IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
2135 return 0;
2136 }
2137
2138 IWL_DEBUG_POWER("Thermal txpower calib needed\n");
2139
2140 return 1;
2141}
2142
2143/* Calculate noise level, based on measurements during network silence just
2144 * before arriving beacon. This measurement can be done only if we know
2145 * exactly when to expect beacons, therefore only when we're associated. */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002146static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002147{
2148 struct statistics_rx_non_phy *rx_info
2149 = &(priv->statistics.rx.general);
2150 int num_active_rx = 0;
2151 int total_silence = 0;
2152 int bcn_silence_a =
2153 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
2154 int bcn_silence_b =
2155 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
2156 int bcn_silence_c =
2157 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
2158
2159 if (bcn_silence_a) {
2160 total_silence += bcn_silence_a;
2161 num_active_rx++;
2162 }
2163 if (bcn_silence_b) {
2164 total_silence += bcn_silence_b;
2165 num_active_rx++;
2166 }
2167 if (bcn_silence_c) {
2168 total_silence += bcn_silence_c;
2169 num_active_rx++;
2170 }
2171
2172 /* Average among active antennas */
2173 if (num_active_rx)
2174 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
2175 else
2176 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2177
2178 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
2179 bcn_silence_a, bcn_silence_b, bcn_silence_c,
2180 priv->last_rx_noise);
2181}
2182
Tomas Winklera55360e2008-05-05 10:22:28 +08002183void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
2184 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002185{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002186 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002187 int change;
2188 s32 temp;
2189
2190 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
2191 (int)sizeof(priv->statistics), pkt->len);
2192
2193 change = ((priv->statistics.general.temperature !=
2194 pkt->u.stats.general.temperature) ||
2195 ((priv->statistics.flag &
2196 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
2197 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
2198
2199 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
2200
2201 set_bit(STATUS_STATISTICS, &priv->status);
2202
2203 /* Reschedule the statistics timer to occur in
2204 * REG_RECALIB_PERIOD seconds to ensure we get a
2205 * thermal update even if the uCode doesn't give
2206 * us one */
2207 mod_timer(&priv->statistics_periodic, jiffies +
2208 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
2209
2210 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2211 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
2212 iwl4965_rx_calc_noise(priv);
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07002213#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
Zhu Yib481de92007-09-25 17:54:57 -07002214 queue_work(priv->workqueue, &priv->sensitivity_work);
2215#endif
2216 }
2217
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002218 iwl_leds_background(priv);
2219
Zhu Yib481de92007-09-25 17:54:57 -07002220 /* If the hardware hasn't reported a change in
2221 * temperature then don't bother computing a
2222 * calibrated temperature value */
2223 if (!change)
2224 return;
2225
2226 temp = iwl4965_get_temperature(priv);
2227 if (temp < 0)
2228 return;
2229
2230 if (priv->temperature != temp) {
2231 if (priv->temperature)
2232 IWL_DEBUG_TEMP("Temperature changed "
2233 "from %dC to %dC\n",
2234 KELVIN_TO_CELSIUS(priv->temperature),
2235 KELVIN_TO_CELSIUS(temp));
2236 else
2237 IWL_DEBUG_TEMP("Temperature "
2238 "initialized to %dC\n",
2239 KELVIN_TO_CELSIUS(temp));
2240 }
2241
2242 priv->temperature = temp;
2243 set_bit(STATUS_TEMPERATURE, &priv->status);
2244
2245 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2246 iwl4965_is_temp_calib_needed(priv))
2247 queue_work(priv->workqueue, &priv->txpower_work);
2248}
2249
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002250static void iwl4965_add_radiotap(struct iwl_priv *priv,
Zhu Yi12342c42007-12-20 11:27:32 +08002251 struct sk_buff *skb,
2252 struct iwl4965_rx_phy_res *rx_start,
2253 struct ieee80211_rx_status *stats,
2254 u32 ampdu_status)
2255{
Bruno Randolf566bfe52008-05-08 19:15:40 +02002256 s8 signal = stats->signal;
Zhu Yi12342c42007-12-20 11:27:32 +08002257 s8 noise = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002258 int rate = stats->rate_idx;
Zhu Yi12342c42007-12-20 11:27:32 +08002259 u64 tsf = stats->mactime;
Johannes Berga0b484f2008-04-01 17:51:47 +02002260 __le16 antenna;
Zhu Yi12342c42007-12-20 11:27:32 +08002261 __le16 phy_flags_hw = rx_start->phy_flags;
2262 struct iwl4965_rt_rx_hdr {
2263 struct ieee80211_radiotap_header rt_hdr;
2264 __le64 rt_tsf; /* TSF */
2265 u8 rt_flags; /* radiotap packet flags */
2266 u8 rt_rate; /* rate in 500kb/s */
2267 __le16 rt_channelMHz; /* channel in MHz */
2268 __le16 rt_chbitmask; /* channel bitfield */
2269 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
2270 s8 rt_dbmnoise;
2271 u8 rt_antenna; /* antenna number */
2272 } __attribute__ ((packed)) *iwl4965_rt;
2273
2274 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
2275 if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
2276 if (net_ratelimit())
2277 printk(KERN_ERR "not enough headroom [%d] for "
Miguel Botón01c20982008-01-04 23:34:35 +01002278 "radiotap head [%zd]\n",
Zhu Yi12342c42007-12-20 11:27:32 +08002279 skb_headroom(skb), sizeof(*iwl4965_rt));
2280 return;
2281 }
2282
2283 /* put radiotap header in front of 802.11 header and data */
2284 iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
2285
2286 /* initialise radiotap header */
2287 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2288 iwl4965_rt->rt_hdr.it_pad = 0;
2289
2290 /* total header + data */
2291 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
2292 &iwl4965_rt->rt_hdr.it_len);
2293
2294 /* Indicate all the fields we add to the radiotap header */
2295 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
2296 (1 << IEEE80211_RADIOTAP_FLAGS) |
2297 (1 << IEEE80211_RADIOTAP_RATE) |
2298 (1 << IEEE80211_RADIOTAP_CHANNEL) |
2299 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
2300 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
2301 (1 << IEEE80211_RADIOTAP_ANTENNA)),
2302 &iwl4965_rt->rt_hdr.it_present);
2303
2304 /* Zero the flags, we'll add to them as we go */
2305 iwl4965_rt->rt_flags = 0;
2306
2307 put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
2308
2309 iwl4965_rt->rt_dbmsignal = signal;
2310 iwl4965_rt->rt_dbmnoise = noise;
2311
2312 /* Convert the channel frequency and set the flags */
2313 put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
2314 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
2315 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2316 IEEE80211_CHAN_5GHZ),
2317 &iwl4965_rt->rt_chbitmask);
2318 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
2319 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
2320 IEEE80211_CHAN_2GHZ),
2321 &iwl4965_rt->rt_chbitmask);
2322 else /* 802.11g */
2323 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2324 IEEE80211_CHAN_2GHZ),
2325 &iwl4965_rt->rt_chbitmask);
2326
Zhu Yi12342c42007-12-20 11:27:32 +08002327 if (rate == -1)
2328 iwl4965_rt->rt_rate = 0;
2329 else
Tomas Winkler1826dcc2008-05-15 13:54:02 +08002330 iwl4965_rt->rt_rate = iwl_rates[rate].ieee;
Zhu Yi12342c42007-12-20 11:27:32 +08002331
2332 /*
2333 * "antenna number"
2334 *
2335 * It seems that the antenna field in the phy flags value
2336 * is actually a bitfield. This is undefined by radiotap,
2337 * it wants an actual antenna number but I always get "7"
2338 * for most legacy frames I receive indicating that the
2339 * same frame was received on all three RX chains.
2340 *
2341 * I think this field should be removed in favour of a
2342 * new 802.11n radiotap field "RX chains" that is defined
2343 * as a bitmask.
2344 */
Johannes Berga0b484f2008-04-01 17:51:47 +02002345 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
2346 iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
Zhu Yi12342c42007-12-20 11:27:32 +08002347
2348 /* set the preamble flag if appropriate */
2349 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
2350 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
2351
2352 stats->flag |= RX_FLAG_RADIOTAP;
2353}
2354
Tomas Winkler19758be2008-03-12 16:58:51 -07002355static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2356{
2357 /* 0 - mgmt, 1 - cnt, 2 - data */
2358 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2359 priv->rx_stats[idx].cnt++;
2360 priv->rx_stats[idx].bytes += len;
2361}
2362
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002363/*
2364 * returns non-zero if packet should be dropped
2365 */
2366static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2367 struct ieee80211_hdr *hdr,
2368 u32 decrypt_res,
2369 struct ieee80211_rx_status *stats)
2370{
2371 u16 fc = le16_to_cpu(hdr->frame_control);
2372
2373 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2374 return 0;
2375
2376 if (!(fc & IEEE80211_FCTL_PROTECTED))
2377 return 0;
2378
2379 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2380 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2381 case RX_RES_STATUS_SEC_TYPE_TKIP:
2382 /* The uCode has got a bad phase 1 Key, pushes the packet.
2383 * Decryption will be done in SW. */
2384 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2385 RX_RES_STATUS_BAD_KEY_TTAK)
2386 break;
2387
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002388 case RX_RES_STATUS_SEC_TYPE_WEP:
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002389 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2390 RX_RES_STATUS_BAD_ICV_MIC) {
2391 /* bad ICV, the packet is destroyed since the
2392 * decryption is inplace, drop it */
2393 IWL_DEBUG_RX("Packet destroyed\n");
2394 return -1;
2395 }
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002396 case RX_RES_STATUS_SEC_TYPE_CCMP:
2397 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2398 RX_RES_STATUS_DECRYPT_OK) {
2399 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2400 stats->flag |= RX_FLAG_DECRYPTED;
2401 }
2402 break;
2403
2404 default:
2405 break;
2406 }
2407 return 0;
2408}
2409
Ester Kummerbf403db2008-05-05 10:22:40 +08002410static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
Emmanuel Grumbach17e476b2008-03-19 16:41:42 -07002411{
2412 u32 decrypt_out = 0;
2413
2414 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
2415 RX_RES_STATUS_STATION_FOUND)
2416 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
2417 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
2418
2419 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
2420
2421 /* packet was not encrypted */
2422 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2423 RX_RES_STATUS_SEC_TYPE_NONE)
2424 return decrypt_out;
2425
2426 /* packet was encrypted with unknown alg */
2427 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2428 RX_RES_STATUS_SEC_TYPE_ERR)
2429 return decrypt_out;
2430
2431 /* decryption was not done in HW */
2432 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
2433 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
2434 return decrypt_out;
2435
2436 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
2437
2438 case RX_RES_STATUS_SEC_TYPE_CCMP:
2439 /* alg is CCM: check MIC only */
2440 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
2441 /* Bad MIC */
2442 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2443 else
2444 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2445
2446 break;
2447
2448 case RX_RES_STATUS_SEC_TYPE_TKIP:
2449 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
2450 /* Bad TTAK */
2451 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
2452 break;
2453 }
2454 /* fall through if TTAK OK */
2455 default:
2456 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
2457 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2458 else
2459 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2460 break;
2461 };
2462
2463 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
2464 decrypt_in, decrypt_out);
2465
2466 return decrypt_out;
2467}
2468
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002469static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
Zhu Yib481de92007-09-25 17:54:57 -07002470 int include_phy,
Tomas Winklera55360e2008-05-05 10:22:28 +08002471 struct iwl_rx_mem_buffer *rxb,
Zhu Yib481de92007-09-25 17:54:57 -07002472 struct ieee80211_rx_status *stats)
2473{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002474 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002475 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2476 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
2477 struct ieee80211_hdr *hdr;
2478 u16 len;
2479 __le32 *rx_end;
2480 unsigned int skblen;
2481 u32 ampdu_status;
Emmanuel Grumbach17e476b2008-03-19 16:41:42 -07002482 u32 ampdu_status_legacy;
Zhu Yib481de92007-09-25 17:54:57 -07002483
2484 if (!include_phy && priv->last_phy_res[0])
2485 rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2486
2487 if (!rx_start) {
2488 IWL_ERROR("MPDU frame without a PHY data\n");
2489 return;
2490 }
2491 if (include_phy) {
2492 hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
2493 rx_start->cfg_phy_cnt);
2494
2495 len = le16_to_cpu(rx_start->byte_count);
2496
2497 rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
2498 sizeof(struct iwl4965_rx_phy_res) +
2499 rx_start->cfg_phy_cnt + len);
2500
2501 } else {
2502 struct iwl4965_rx_mpdu_res_start *amsdu =
2503 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2504
2505 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
2506 sizeof(struct iwl4965_rx_mpdu_res_start));
2507 len = le16_to_cpu(amsdu->byte_count);
2508 rx_start->byte_count = amsdu->byte_count;
2509 rx_end = (__le32 *) (((u8 *) hdr) + len);
2510 }
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002511 /* In monitor mode allow 802.11 ACk frames (10 bytes) */
2512 if (len > priv->hw_params.max_pkt_size ||
2513 len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) {
Zhu Yi12342c42007-12-20 11:27:32 +08002514 IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002515 return;
2516 }
2517
2518 ampdu_status = le32_to_cpu(*rx_end);
2519 skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
2520
Emmanuel Grumbach17e476b2008-03-19 16:41:42 -07002521 if (!include_phy) {
2522 /* New status scheme, need to translate */
2523 ampdu_status_legacy = ampdu_status;
Ester Kummerbf403db2008-05-05 10:22:40 +08002524 ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status);
Emmanuel Grumbach17e476b2008-03-19 16:41:42 -07002525 }
2526
Zhu Yib481de92007-09-25 17:54:57 -07002527 /* start from MAC */
2528 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
2529 skb_put(rxb->skb, len); /* end where data ends */
2530
2531 /* We only process data packets if the interface is open */
2532 if (unlikely(!priv->is_open)) {
2533 IWL_DEBUG_DROP_LIMIT
2534 ("Dropping packet while interface is not open.\n");
2535 return;
2536 }
2537
Zhu Yib481de92007-09-25 17:54:57 -07002538 stats->flag = 0;
2539 hdr = (struct ieee80211_hdr *)rxb->skb->data;
2540
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002541 /* in case of HW accelerated crypto and bad decryption, drop */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07002542 if (!priv->hw_params.sw_crypto &&
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002543 iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
2544 return;
Zhu Yib481de92007-09-25 17:54:57 -07002545
Zhu Yi12342c42007-12-20 11:27:32 +08002546 if (priv->add_radiotap)
2547 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
2548
Tomas Winkler19758be2008-03-12 16:58:51 -07002549 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
Zhu Yib481de92007-09-25 17:54:57 -07002550 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
2551 priv->alloc_rxb_skb--;
2552 rxb->skb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002553}
2554
2555/* Calc max signal level (dBm) among 3 possible receivers */
Ester Kummerbf403db2008-05-05 10:22:40 +08002556static int iwl4965_calc_rssi(struct iwl_priv *priv,
2557 struct iwl4965_rx_phy_res *rx_resp)
Zhu Yib481de92007-09-25 17:54:57 -07002558{
2559 /* data from PHY/DSP regarding signal strength, etc.,
2560 * contents are always there, not configurable by host. */
2561 struct iwl4965_rx_non_cfg_phy *ncphy =
2562 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
2563 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
2564 >> IWL_AGC_DB_POS;
2565
2566 u32 valid_antennae =
2567 (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
2568 >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
2569 u8 max_rssi = 0;
2570 u32 i;
2571
2572 /* Find max rssi among 3 possible receivers.
2573 * These values are measured by the digital signal processor (DSP).
2574 * They should stay fairly constant even as the signal strength varies,
2575 * if the radio's automatic gain control (AGC) is working right.
2576 * AGC value (see below) will provide the "interesting" info. */
2577 for (i = 0; i < 3; i++)
2578 if (valid_antennae & (1 << i))
2579 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
2580
2581 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
2582 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
2583 max_rssi, agc);
2584
2585 /* dBm = max_rssi dB - agc dB - constant.
2586 * Higher AGC (higher radio gain) means lower signal. */
2587 return (max_rssi - agc - IWL_RSSI_OFFSET);
2588}
2589
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002590static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07002591{
2592 unsigned long flags;
2593
2594 spin_lock_irqsave(&priv->sta_lock, flags);
2595 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
2596 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
2597 priv->stations[sta_id].sta.sta.modify_mask = 0;
2598 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
2599 spin_unlock_irqrestore(&priv->sta_lock, flags);
2600
Tomas Winkler133636d2008-05-05 10:22:34 +08002601 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07002602}
2603
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002604static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
Zhu Yib481de92007-09-25 17:54:57 -07002605{
2606 /* FIXME: need locking over ps_status ??? */
Tomas Winkler947b13a2008-04-16 16:34:48 -07002607 u8 sta_id = iwl_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07002608
2609 if (sta_id != IWL_INVALID_STATION) {
2610 u8 sta_awake = priv->stations[sta_id].
2611 ps_status == STA_PS_STATUS_WAKE;
2612
2613 if (sta_awake && ps_bit)
2614 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
2615 else if (!sta_awake && !ps_bit) {
2616 iwl4965_sta_modify_ps_wake(priv, sta_id);
2617 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
2618 }
2619 }
2620}
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002621#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler17744ff2008-03-02 01:52:00 +02002622
2623/**
2624 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
2625 *
2626 * You may hack this function to show different aspects of received frames,
2627 * including selective frame dumps.
2628 * group100 parameter selects whether to show 1 out of 100 good frames.
2629 *
2630 * TODO: This was originally written for 3945, need to audit for
2631 * proper operation with 4965.
2632 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002633static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
Tomas Winklerdb11d632008-05-05 10:22:33 +08002634 struct iwl_rx_packet *pkt,
Tomas Winkler17744ff2008-03-02 01:52:00 +02002635 struct ieee80211_hdr *header, int group100)
2636{
2637 u32 to_us;
2638 u32 print_summary = 0;
2639 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
2640 u32 hundred = 0;
2641 u32 dataframe = 0;
2642 u16 fc;
2643 u16 seq_ctl;
2644 u16 channel;
2645 u16 phy_flags;
2646 int rate_sym;
2647 u16 length;
2648 u16 status;
2649 u16 bcn_tmr;
2650 u32 tsf_low;
2651 u64 tsf;
2652 u8 rssi;
2653 u8 agc;
2654 u16 sig_avg;
2655 u16 noise_diff;
2656 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
2657 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
2658 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
2659 u8 *data = IWL_RX_DATA(pkt);
2660
Ester Kummerbf403db2008-05-05 10:22:40 +08002661 if (likely(!(priv->debug_level & IWL_DL_RX)))
Tomas Winkler17744ff2008-03-02 01:52:00 +02002662 return;
2663
2664 /* MAC header */
2665 fc = le16_to_cpu(header->frame_control);
2666 seq_ctl = le16_to_cpu(header->seq_ctrl);
2667
2668 /* metadata */
2669 channel = le16_to_cpu(rx_hdr->channel);
2670 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
2671 rate_sym = rx_hdr->rate;
2672 length = le16_to_cpu(rx_hdr->len);
2673
2674 /* end-of-frame status and timestamp */
2675 status = le32_to_cpu(rx_end->status);
2676 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
2677 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
2678 tsf = le64_to_cpu(rx_end->timestamp);
2679
2680 /* signal statistics */
2681 rssi = rx_stats->rssi;
2682 agc = rx_stats->agc;
2683 sig_avg = le16_to_cpu(rx_stats->sig_avg);
2684 noise_diff = le16_to_cpu(rx_stats->noise_diff);
2685
2686 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
2687
2688 /* if data frame is to us and all is good,
2689 * (optionally) print summary for only 1 out of every 100 */
2690 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
2691 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
2692 dataframe = 1;
2693 if (!group100)
2694 print_summary = 1; /* print each frame */
2695 else if (priv->framecnt_to_us < 100) {
2696 priv->framecnt_to_us++;
2697 print_summary = 0;
2698 } else {
2699 priv->framecnt_to_us = 0;
2700 print_summary = 1;
2701 hundred = 1;
2702 }
2703 } else {
2704 /* print summary for all other frames */
2705 print_summary = 1;
2706 }
2707
2708 if (print_summary) {
2709 char *title;
2710 int rate_idx;
2711 u32 bitrate;
2712
2713 if (hundred)
2714 title = "100Frames";
2715 else if (fc & IEEE80211_FCTL_RETRY)
2716 title = "Retry";
2717 else if (ieee80211_is_assoc_response(fc))
2718 title = "AscRsp";
2719 else if (ieee80211_is_reassoc_response(fc))
2720 title = "RasRsp";
2721 else if (ieee80211_is_probe_response(fc)) {
2722 title = "PrbRsp";
2723 print_dump = 1; /* dump frame contents */
2724 } else if (ieee80211_is_beacon(fc)) {
2725 title = "Beacon";
2726 print_dump = 1; /* dump frame contents */
2727 } else if (ieee80211_is_atim(fc))
2728 title = "ATIM";
2729 else if (ieee80211_is_auth(fc))
2730 title = "Auth";
2731 else if (ieee80211_is_deauth(fc))
2732 title = "DeAuth";
2733 else if (ieee80211_is_disassoc(fc))
2734 title = "DisAssoc";
2735 else
2736 title = "Frame";
2737
2738 rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
2739 if (unlikely(rate_idx == -1))
2740 bitrate = 0;
2741 else
Tomas Winkler1826dcc2008-05-15 13:54:02 +08002742 bitrate = iwl_rates[rate_idx].ieee / 2;
Tomas Winkler17744ff2008-03-02 01:52:00 +02002743
2744 /* print frame summary.
2745 * MAC addresses show just the last byte (for brevity),
2746 * but you can hack it to show more, if you'd like to. */
2747 if (dataframe)
2748 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
2749 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
2750 title, fc, header->addr1[5],
2751 length, rssi, channel, bitrate);
2752 else {
2753 /* src/dst addresses assume managed mode */
2754 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
2755 "src=0x%02x, rssi=%u, tim=%lu usec, "
2756 "phy=0x%02x, chnl=%d\n",
2757 title, fc, header->addr1[5],
2758 header->addr3[5], rssi,
2759 tsf_low - priv->scan_start_tsf,
2760 phy_flags, channel);
2761 }
2762 }
2763 if (print_dump)
Ester Kummerbf403db2008-05-05 10:22:40 +08002764 iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
Tomas Winkler17744ff2008-03-02 01:52:00 +02002765}
2766#else
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002767static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
Tomas Winklerdb11d632008-05-05 10:22:33 +08002768 struct iwl_rx_packet *pkt,
Tomas Winkler17744ff2008-03-02 01:52:00 +02002769 struct ieee80211_hdr *header,
2770 int group100)
2771{
2772}
2773#endif
2774
Zhu Yib481de92007-09-25 17:54:57 -07002775
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002776
Tomas Winkler857485c2008-03-21 13:53:44 -07002777/* Called for REPLY_RX (legacy ABG frames), or
Zhu Yib481de92007-09-25 17:54:57 -07002778 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002779static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002780 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002781{
Tomas Winkler17744ff2008-03-02 01:52:00 +02002782 struct ieee80211_hdr *header;
2783 struct ieee80211_rx_status rx_status;
Tomas Winklerdb11d632008-05-05 10:22:33 +08002784 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002785 /* Use phy data (Rx signal strength, etc.) contained within
2786 * this rx packet for legacy frames,
2787 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
Tomas Winkler857485c2008-03-21 13:53:44 -07002788 int include_phy = (pkt->hdr.cmd == REPLY_RX);
Zhu Yib481de92007-09-25 17:54:57 -07002789 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2790 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
2791 (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2792 __le32 *rx_end;
2793 unsigned int len = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002794 u16 fc;
Zhu Yib481de92007-09-25 17:54:57 -07002795 u8 network_packet;
2796
Tomas Winkler17744ff2008-03-02 01:52:00 +02002797 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
Tomas Winklerdc92e492008-04-03 16:05:22 -07002798 rx_status.freq =
Emmanuel Grumbachc0186072008-05-08 11:34:05 +08002799 ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
Tomas Winkler17744ff2008-03-02 01:52:00 +02002800 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
2801 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
Tomas Winklerdc92e492008-04-03 16:05:22 -07002802 rx_status.rate_idx =
2803 iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
Tomas Winkler17744ff2008-03-02 01:52:00 +02002804 if (rx_status.band == IEEE80211_BAND_5GHZ)
2805 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
2806
2807 rx_status.antenna = 0;
2808 rx_status.flag = 0;
2809
Zhu Yib481de92007-09-25 17:54:57 -07002810 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
Tomas Winklerdc92e492008-04-03 16:05:22 -07002811 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
2812 rx_start->cfg_phy_cnt);
Zhu Yib481de92007-09-25 17:54:57 -07002813 return;
2814 }
Tomas Winkler17744ff2008-03-02 01:52:00 +02002815
Zhu Yib481de92007-09-25 17:54:57 -07002816 if (!include_phy) {
2817 if (priv->last_phy_res[0])
2818 rx_start = (struct iwl4965_rx_phy_res *)
2819 &priv->last_phy_res[1];
2820 else
2821 rx_start = NULL;
2822 }
2823
2824 if (!rx_start) {
2825 IWL_ERROR("MPDU frame without a PHY data\n");
2826 return;
2827 }
2828
2829 if (include_phy) {
2830 header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
2831 + rx_start->cfg_phy_cnt);
2832
2833 len = le16_to_cpu(rx_start->byte_count);
Tomas Winkler17744ff2008-03-02 01:52:00 +02002834 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
Zhu Yib481de92007-09-25 17:54:57 -07002835 sizeof(struct iwl4965_rx_phy_res) + len);
2836 } else {
2837 struct iwl4965_rx_mpdu_res_start *amsdu =
2838 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2839
2840 header = (void *)(pkt->u.raw +
2841 sizeof(struct iwl4965_rx_mpdu_res_start));
2842 len = le16_to_cpu(amsdu->byte_count);
2843 rx_end = (__le32 *) (pkt->u.raw +
2844 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
2845 }
2846
2847 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
2848 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
2849 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
2850 le32_to_cpu(*rx_end));
2851 return;
2852 }
2853
2854 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
2855
Zhu Yib481de92007-09-25 17:54:57 -07002856 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
Bruno Randolf566bfe52008-05-08 19:15:40 +02002857 rx_status.signal = iwl4965_calc_rssi(priv, rx_start);
Zhu Yib481de92007-09-25 17:54:57 -07002858
2859 /* Meaningful noise values are available only from beacon statistics,
2860 * which are gathered only when associated, and indicate noise
2861 * only for the associated network channel ...
2862 * Ignore these noise values while scanning (other channels) */
Tomas Winkler3109ece2008-03-28 16:33:35 -07002863 if (iwl_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07002864 !test_bit(STATUS_SCANNING, &priv->status)) {
Tomas Winkler17744ff2008-03-02 01:52:00 +02002865 rx_status.noise = priv->last_rx_noise;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002866 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal,
Tomas Winkler17744ff2008-03-02 01:52:00 +02002867 rx_status.noise);
Zhu Yib481de92007-09-25 17:54:57 -07002868 } else {
Tomas Winkler17744ff2008-03-02 01:52:00 +02002869 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
Bruno Randolf566bfe52008-05-08 19:15:40 +02002870 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002871 }
2872
2873 /* Reset beacon noise level if not associated. */
Tomas Winkler3109ece2008-03-28 16:33:35 -07002874 if (!iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002875 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2876
Tomas Winkler17744ff2008-03-02 01:52:00 +02002877 /* Set "1" to report good data frames in groups of 100 */
2878 /* FIXME: need to optimze the call: */
2879 iwl4965_dbg_report_frame(priv, pkt, header, 1);
Zhu Yib481de92007-09-25 17:54:57 -07002880
Tomas Winkler17744ff2008-03-02 01:52:00 +02002881 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
Bruno Randolf566bfe52008-05-08 19:15:40 +02002882 rx_status.signal, rx_status.noise, rx_status.signal,
John W. Linville06501d22008-04-01 17:38:47 -04002883 (unsigned long long)rx_status.mactime);
Zhu Yib481de92007-09-25 17:54:57 -07002884
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002885
2886 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2887 iwl4965_handle_data_packet(priv, 1, include_phy,
2888 rxb, &rx_status);
2889 return;
2890 }
2891
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002892 network_packet = iwl4965_is_network_packet(priv, header);
Zhu Yib481de92007-09-25 17:54:57 -07002893 if (network_packet) {
Bruno Randolf566bfe52008-05-08 19:15:40 +02002894 priv->last_rx_rssi = rx_status.signal;
Zhu Yib481de92007-09-25 17:54:57 -07002895 priv->last_beacon_time = priv->ucode_beacon_time;
2896 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
2897 }
2898
2899 fc = le16_to_cpu(header->frame_control);
2900 switch (fc & IEEE80211_FCTL_FTYPE) {
2901 case IEEE80211_FTYPE_MGMT:
Zhu Yib481de92007-09-25 17:54:57 -07002902 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2903 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2904 header->addr2);
Tomas Winkler17744ff2008-03-02 01:52:00 +02002905 iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
Zhu Yib481de92007-09-25 17:54:57 -07002906 break;
2907
2908 case IEEE80211_FTYPE_CTL:
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02002909#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07002910 switch (fc & IEEE80211_FCTL_STYPE) {
2911 case IEEE80211_STYPE_BACK_REQ:
2912 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
2913 iwl4965_handle_data_packet(priv, 0, include_phy,
Tomas Winkler17744ff2008-03-02 01:52:00 +02002914 rxb, &rx_status);
Zhu Yib481de92007-09-25 17:54:57 -07002915 break;
2916 default:
2917 break;
2918 }
2919#endif
Zhu Yib481de92007-09-25 17:54:57 -07002920 break;
2921
Joe Perches0795af52007-10-03 17:59:30 -07002922 case IEEE80211_FTYPE_DATA: {
2923 DECLARE_MAC_BUF(mac1);
2924 DECLARE_MAC_BUF(mac2);
2925 DECLARE_MAC_BUF(mac3);
2926
Zhu Yib481de92007-09-25 17:54:57 -07002927 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2928 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2929 header->addr2);
2930
2931 if (unlikely(!network_packet))
2932 IWL_DEBUG_DROP("Dropping (non network): "
Joe Perches0795af52007-10-03 17:59:30 -07002933 "%s, %s, %s\n",
2934 print_mac(mac1, header->addr1),
2935 print_mac(mac2, header->addr2),
2936 print_mac(mac3, header->addr3));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002937 else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
Joe Perches0795af52007-10-03 17:59:30 -07002938 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
2939 print_mac(mac1, header->addr1),
2940 print_mac(mac2, header->addr2),
2941 print_mac(mac3, header->addr3));
Zhu Yib481de92007-09-25 17:54:57 -07002942 else
2943 iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
Tomas Winkler17744ff2008-03-02 01:52:00 +02002944 &rx_status);
Zhu Yib481de92007-09-25 17:54:57 -07002945 break;
Joe Perches0795af52007-10-03 17:59:30 -07002946 }
Zhu Yib481de92007-09-25 17:54:57 -07002947 default:
2948 break;
2949
2950 }
2951}
2952
2953/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
2954 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002955static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002956 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002957{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002958 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002959 priv->last_phy_res[0] = 1;
2960 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
2961 sizeof(struct iwl4965_rx_phy_res));
2962}
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002963static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002964 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002965
2966{
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07002967#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
Tomas Winklerdb11d632008-05-05 10:22:33 +08002968 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002969 struct iwl4965_missed_beacon_notif *missed_beacon;
Zhu Yib481de92007-09-25 17:54:57 -07002970
2971 missed_beacon = &pkt->u.missed_beacon;
2972 if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
2973 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
2974 le32_to_cpu(missed_beacon->consequtive_missed_beacons),
2975 le32_to_cpu(missed_beacon->total_missed_becons),
2976 le32_to_cpu(missed_beacon->num_recvd_beacons),
2977 le32_to_cpu(missed_beacon->num_expected_beacons));
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07002978 if (!test_bit(STATUS_SCANNING, &priv->status))
2979 iwl_init_sensitivity(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002980 }
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07002981#endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
Zhu Yib481de92007-09-25 17:54:57 -07002982}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002983#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07002984
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002985/**
2986 * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
2987 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002988static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002989 int sta_id, int tid)
2990{
2991 unsigned long flags;
2992
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08002993 /* Remove "disable" flag, to enable Tx for this TID */
Zhu Yib481de92007-09-25 17:54:57 -07002994 spin_lock_irqsave(&priv->sta_lock, flags);
2995 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
2996 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
2997 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
2998 spin_unlock_irqrestore(&priv->sta_lock, flags);
2999
Tomas Winkler133636d2008-05-05 10:22:34 +08003000 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07003001}
3002
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003003/**
3004 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
3005 *
3006 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
3007 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
3008 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003009static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
Tomas Winkler6def9762008-05-05 10:22:31 +08003010 struct iwl_ht_agg *agg,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003011 struct iwl4965_compressed_ba_resp*
Zhu Yib481de92007-09-25 17:54:57 -07003012 ba_resp)
3013
3014{
3015 int i, sh, ack;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003016 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
3017 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
3018 u64 bitmap;
3019 int successes = 0;
Johannes Berge039fa42008-05-15 12:55:29 +02003020 struct ieee80211_tx_info *info;
Zhu Yib481de92007-09-25 17:54:57 -07003021
3022 if (unlikely(!agg->wait_for_ba)) {
3023 IWL_ERROR("Received BA when not expected\n");
3024 return -EINVAL;
3025 }
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003026
3027 /* Mark that the expected block-ack response arrived */
Zhu Yib481de92007-09-25 17:54:57 -07003028 agg->wait_for_ba = 0;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003029 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003030
3031 /* Calculate shift to align block-ack bits with our Tx window bits */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003032 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
Ian Schram01ebd062007-10-25 17:15:22 +08003033 if (sh < 0) /* tbw something is wrong with indices */
Zhu Yib481de92007-09-25 17:54:57 -07003034 sh += 0x100;
3035
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003036 /* don't use 64-bit values for now */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003037 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
Zhu Yib481de92007-09-25 17:54:57 -07003038
3039 if (agg->frame_count > (64 - sh)) {
3040 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
3041 return -1;
3042 }
3043
3044 /* check for success or failure according to the
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003045 * transmitted bitmap and block-ack bitmap */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003046 bitmap &= agg->bitmap;
Zhu Yib481de92007-09-25 17:54:57 -07003047
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003048 /* For each frame attempted in aggregation,
3049 * update driver's record of tx frame's status. */
Zhu Yib481de92007-09-25 17:54:57 -07003050 for (i = 0; i < agg->frame_count ; i++) {
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003051 ack = bitmap & (1 << i);
3052 successes += !!ack;
Zhu Yib481de92007-09-25 17:54:57 -07003053 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003054 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
3055 agg->start_idx + i);
Zhu Yib481de92007-09-25 17:54:57 -07003056 }
3057
Johannes Berge039fa42008-05-15 12:55:29 +02003058 info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
3059 memset(&info->status, 0, sizeof(info->status));
3060 info->flags = IEEE80211_TX_STAT_ACK;
3061 info->flags |= IEEE80211_TX_STAT_AMPDU;
3062 info->status.ampdu_ack_map = successes;
3063 info->status.ampdu_ack_len = agg->frame_count;
3064 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
Zhu Yib481de92007-09-25 17:54:57 -07003065
John W. Linvillef868f4e2008-03-07 16:38:43 -05003066 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003067
3068 return 0;
3069}
3070
3071/**
3072 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
3073 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003074static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003075 u16 txq_id)
3076{
3077 /* Simply stop the queue, but don't change any configuration;
3078 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003079 iwl_write_prph(priv,
Tomas Winkler12a81f62008-04-03 16:05:20 -07003080 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07003081 (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
3082 (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003083}
3084
3085/**
3086 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003087 * priv->lock must be held by the caller
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003088 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003089static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003090 u16 ssn_idx, u8 tx_fifo)
3091{
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003092 int ret = 0;
3093
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003094 if (IWL_BACK_QUEUE_FIRST_ID > txq_id) {
3095 IWL_WARNING("queue number too small: %d, must be > %d\n",
3096 txq_id, IWL_BACK_QUEUE_FIRST_ID);
3097 return -EINVAL;
3098 }
3099
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003100 ret = iwl_grab_nic_access(priv);
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003101 if (ret)
3102 return ret;
3103
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003104 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3105
Tomas Winkler12a81f62008-04-03 16:05:20 -07003106 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003107
3108 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3109 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
3110 /* supposes that ssn_idx is valid (!= 0xFFF) */
3111 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3112
Tomas Winkler12a81f62008-04-03 16:05:20 -07003113 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
Ron Rindjunsky36470742008-05-15 13:54:10 +08003114 iwl_txq_ctx_deactivate(priv, txq_id);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003115 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
3116
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003117 iwl_release_nic_access(priv);
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003118
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003119 return 0;
3120}
3121
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003122int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003123 u8 tid, int txq_id)
3124{
Tomas Winkler443cfd42008-05-15 13:53:57 +08003125 struct iwl_queue *q = &priv->txq[txq_id].q;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003126 u8 *addr = priv->stations[sta_id].sta.sta.addr;
Tomas Winkler6def9762008-05-05 10:22:31 +08003127 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003128
3129 switch (priv->stations[sta_id].tid[tid].agg.state) {
3130 case IWL_EMPTYING_HW_QUEUE_DELBA:
3131 /* We are reclaiming the last packet of the */
3132 /* aggregated HW queue */
3133 if (txq_id == tid_data->agg.txq_id &&
3134 q->read_ptr == q->write_ptr) {
3135 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
3136 int tx_fifo = default_tid_to_tx_fifo[tid];
3137 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
3138 iwl4965_tx_queue_agg_disable(priv, txq_id,
3139 ssn, tx_fifo);
3140 tid_data->agg.state = IWL_AGG_OFF;
3141 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3142 }
3143 break;
3144 case IWL_EMPTYING_HW_QUEUE_ADDBA:
3145 /* We are reclaiming the last packet of the queue */
3146 if (tid_data->tfds_in_queue == 0) {
3147 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
3148 tid_data->agg.state = IWL_AGG_ON;
3149 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3150 }
3151 break;
3152 }
Zhu Yib481de92007-09-25 17:54:57 -07003153 return 0;
3154}
3155
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003156/**
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003157 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
3158 *
3159 * Handles block-acknowledge notification from device, which reports success
3160 * of frames sent via aggregation.
3161 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003162static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08003163 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003164{
Tomas Winklerdb11d632008-05-05 10:22:33 +08003165 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003166 struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
Zhu Yib481de92007-09-25 17:54:57 -07003167 int index;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003168 struct iwl_tx_queue *txq = NULL;
Tomas Winkler6def9762008-05-05 10:22:31 +08003169 struct iwl_ht_agg *agg;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003170 DECLARE_MAC_BUF(mac);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003171
3172 /* "flow" corresponds to Tx queue */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003173 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003174
3175 /* "ssn" is start of block-ack Tx window, corresponds to index
3176 * (in Tx queue's circular buffer) of first TFD/frame in window */
Zhu Yib481de92007-09-25 17:54:57 -07003177 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
3178
Ron Rindjunskydfe7d452008-04-15 16:01:45 -07003179 if (scd_flow >= priv->hw_params.max_txq_num) {
Zhu Yib481de92007-09-25 17:54:57 -07003180 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
3181 return;
3182 }
3183
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003184 txq = &priv->txq[scd_flow];
Zhu Yib481de92007-09-25 17:54:57 -07003185 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003186
3187 /* Find index just before block-ack window */
Tomas Winkler443cfd42008-05-15 13:53:57 +08003188 index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
Zhu Yib481de92007-09-25 17:54:57 -07003189
Ian Schram01ebd062007-10-25 17:15:22 +08003190 /* TODO: Need to get this copy more safely - now good for debug */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003191
Joe Perches0795af52007-10-03 17:59:30 -07003192 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
3193 "sta_id = %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003194 agg->wait_for_ba,
Joe Perches0795af52007-10-03 17:59:30 -07003195 print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
Zhu Yib481de92007-09-25 17:54:57 -07003196 ba_resp->sta_id);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003197 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
Zhu Yib481de92007-09-25 17:54:57 -07003198 "%d, scd_ssn = %d\n",
3199 ba_resp->tid,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003200 ba_resp->seq_ctl,
Tomas Winkler0310ae72008-03-11 16:17:19 -07003201 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
Zhu Yib481de92007-09-25 17:54:57 -07003202 ba_resp->scd_flow,
3203 ba_resp->scd_ssn);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003204 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
Zhu Yib481de92007-09-25 17:54:57 -07003205 agg->start_idx,
John W. Linvillef868f4e2008-03-07 16:38:43 -05003206 (unsigned long long)agg->bitmap);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003207
3208 /* Update driver's record of ACK vs. not for each frame in window */
Zhu Yib481de92007-09-25 17:54:57 -07003209 iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003210
3211 /* Release all TFDs before the SSN, i.e. all TFDs in front of
3212 * block-ack window (we assume that they've been successfully
3213 * transmitted ... if not, it's too late anyway). */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003214 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
Ron Rindjunsky0d0b2c12008-05-04 14:48:18 +03003215 /* calculate mac80211 ampdu sw queue to wake */
3216 int ampdu_q =
3217 scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003218 int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index);
3219 priv->stations[ba_resp->sta_id].
3220 tid[ba_resp->tid].tfds_in_queue -= freed;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003221 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003222 priv->mac80211_registered &&
3223 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
Ron Rindjunsky0d0b2c12008-05-04 14:48:18 +03003224 ieee80211_wake_queue(priv->hw, ampdu_q);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003225 iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id,
3226 ba_resp->tid, scd_flow);
3227 }
Zhu Yib481de92007-09-25 17:54:57 -07003228}
3229
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003230/**
3231 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
3232 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003233static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
Zhu Yib481de92007-09-25 17:54:57 -07003234 u16 txq_id)
3235{
3236 u32 tbl_dw_addr;
3237 u32 tbl_dw;
3238 u16 scd_q2ratid;
3239
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07003240 scd_q2ratid = ra_tid & IWL49_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003241
3242 tbl_dw_addr = priv->scd_base_addr +
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07003243 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
Zhu Yib481de92007-09-25 17:54:57 -07003244
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003245 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003246
3247 if (txq_id & 0x1)
3248 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
3249 else
3250 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
3251
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003252 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
Zhu Yib481de92007-09-25 17:54:57 -07003253
3254 return 0;
3255}
3256
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003257
Zhu Yib481de92007-09-25 17:54:57 -07003258/**
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003259 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
3260 *
3261 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
3262 * i.e. it must be one of the higher queues used for aggregation
Zhu Yib481de92007-09-25 17:54:57 -07003263 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003264static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
Zhu Yib481de92007-09-25 17:54:57 -07003265 int tx_fifo, int sta_id, int tid,
3266 u16 ssn_idx)
3267{
3268 unsigned long flags;
3269 int rc;
3270 u16 ra_tid;
3271
3272 if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
3273 IWL_WARNING("queue number too small: %d, must be > %d\n",
3274 txq_id, IWL_BACK_QUEUE_FIRST_ID);
3275
3276 ra_tid = BUILD_RAxTID(sta_id, tid);
3277
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003278 /* Modify device's station table to Tx this TID */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003279 iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid);
Zhu Yib481de92007-09-25 17:54:57 -07003280
3281 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003282 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003283 if (rc) {
3284 spin_unlock_irqrestore(&priv->lock, flags);
3285 return rc;
3286 }
3287
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003288 /* Stop this Tx queue before configuring it */
Zhu Yib481de92007-09-25 17:54:57 -07003289 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3290
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003291 /* Map receiver-address / traffic-ID to this queue */
Zhu Yib481de92007-09-25 17:54:57 -07003292 iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
3293
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003294 /* Set this queue as a chain-building queue */
Tomas Winkler12a81f62008-04-03 16:05:20 -07003295 iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
Zhu Yib481de92007-09-25 17:54:57 -07003296
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003297 /* Place first TFD at index corresponding to start sequence number.
3298 * Assumes that ssn_idx is valid (!= 0xFFF) */
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003299 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3300 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
Zhu Yib481de92007-09-25 17:54:57 -07003301 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3302
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003303 /* Set up Tx window size and frame limit for this queue */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003304 iwl_write_targ_mem(priv,
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07003305 priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
3306 (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
3307 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
Zhu Yib481de92007-09-25 17:54:57 -07003308
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003309 iwl_write_targ_mem(priv, priv->scd_base_addr +
Emmanuel Grumbach038669e2008-04-23 17:15:04 -07003310 IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
3311 (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
3312 & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
Zhu Yib481de92007-09-25 17:54:57 -07003313
Tomas Winkler12a81f62008-04-03 16:05:20 -07003314 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
Zhu Yib481de92007-09-25 17:54:57 -07003315
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003316 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
Zhu Yib481de92007-09-25 17:54:57 -07003317 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
3318
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003319 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003320 spin_unlock_irqrestore(&priv->lock, flags);
3321
3322 return 0;
3323}
3324
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003325#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07003326
Zhu Yib481de92007-09-25 17:54:57 -07003327
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003328#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003329static int iwl4965_rx_agg_start(struct iwl_priv *priv,
3330 const u8 *addr, int tid, u16 ssn)
Zhu Yib481de92007-09-25 17:54:57 -07003331{
3332 unsigned long flags;
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003333 int sta_id;
3334
3335 sta_id = iwl_find_station(priv, addr);
3336 if (sta_id == IWL_INVALID_STATION)
3337 return -ENXIO;
Zhu Yib481de92007-09-25 17:54:57 -07003338
3339 spin_lock_irqsave(&priv->sta_lock, flags);
3340 priv->stations[sta_id].sta.station_flags_msk = 0;
3341 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
3342 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
3343 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
3344 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3345 spin_unlock_irqrestore(&priv->sta_lock, flags);
3346
Tomas Winkler133636d2008-05-05 10:22:34 +08003347 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003348 CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07003349}
3350
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003351static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
3352 const u8 *addr, int tid)
Zhu Yib481de92007-09-25 17:54:57 -07003353{
3354 unsigned long flags;
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003355 int sta_id;
3356
3357 sta_id = iwl_find_station(priv, addr);
3358 if (sta_id == IWL_INVALID_STATION)
3359 return -ENXIO;
Zhu Yib481de92007-09-25 17:54:57 -07003360
3361 spin_lock_irqsave(&priv->sta_lock, flags);
3362 priv->stations[sta_id].sta.station_flags_msk = 0;
3363 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
3364 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
3365 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3366 spin_unlock_irqrestore(&priv->sta_lock, flags);
3367
Tomas Winkler133636d2008-05-05 10:22:34 +08003368 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003369 CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07003370}
3371
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +08003372/*
3373 * Find first available (lowest unused) Tx Queue, mark it "active".
3374 * Called only when finding queue for aggregation.
3375 * Should never return anything < 7, because they should already
3376 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
3377 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003378static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003379{
3380 int txq_id;
3381
Tomas Winkler5425e492008-04-15 16:01:38 -07003382 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
Zhu Yib481de92007-09-25 17:54:57 -07003383 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
3384 return txq_id;
3385 return -1;
3386}
3387
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003388static int iwl4965_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra,
3389 u16 tid, u16 *start_seq_num)
Zhu Yib481de92007-09-25 17:54:57 -07003390{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003391 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003392 int sta_id;
3393 int tx_fifo;
3394 int txq_id;
3395 int ssn = -1;
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003396 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003397 unsigned long flags;
Tomas Winkler6def9762008-05-05 10:22:31 +08003398 struct iwl_tid_data *tid_data;
Joe Perches0795af52007-10-03 17:59:30 -07003399 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07003400
3401 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
3402 tx_fifo = default_tid_to_tx_fifo[tid];
3403 else
3404 return -EINVAL;
3405
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003406 IWL_WARNING("%s on ra = %s tid = %d\n",
3407 __func__, print_mac(mac, ra), tid);
Zhu Yib481de92007-09-25 17:54:57 -07003408
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003409 sta_id = iwl_find_station(priv, ra);
Zhu Yib481de92007-09-25 17:54:57 -07003410 if (sta_id == IWL_INVALID_STATION)
3411 return -ENXIO;
3412
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003413 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
3414 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
3415 return -ENXIO;
3416 }
3417
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003418 txq_id = iwl4965_txq_ctx_activate_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003419 if (txq_id == -1)
3420 return -ENXIO;
3421
3422 spin_lock_irqsave(&priv->sta_lock, flags);
3423 tid_data = &priv->stations[sta_id].tid[tid];
3424 ssn = SEQ_TO_SN(tid_data->seq_number);
3425 tid_data->agg.txq_id = txq_id;
3426 spin_unlock_irqrestore(&priv->sta_lock, flags);
3427
3428 *start_seq_num = ssn;
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003429 ret = iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo,
3430 sta_id, tid, ssn);
3431 if (ret)
3432 return ret;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003433
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003434 ret = 0;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003435 if (tid_data->tfds_in_queue == 0) {
3436 printk(KERN_ERR "HW queue is empty\n");
3437 tid_data->agg.state = IWL_AGG_ON;
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003438 ieee80211_start_tx_ba_cb_irqsafe(hw, ra, tid);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003439 } else {
3440 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
3441 tid_data->tfds_in_queue);
3442 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
3443 }
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003444 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003445}
3446
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003447static int iwl4965_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid)
Zhu Yib481de92007-09-25 17:54:57 -07003448{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003449 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003450 int tx_fifo_id, txq_id, sta_id, ssn = -1;
Tomas Winkler6def9762008-05-05 10:22:31 +08003451 struct iwl_tid_data *tid_data;
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003452 int ret, write_ptr, read_ptr;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003453 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07003454 DECLARE_MAC_BUF(mac);
3455
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003456 if (!ra) {
3457 IWL_ERROR("ra = NULL\n");
Zhu Yib481de92007-09-25 17:54:57 -07003458 return -EINVAL;
3459 }
3460
3461 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
3462 tx_fifo_id = default_tid_to_tx_fifo[tid];
3463 else
3464 return -EINVAL;
3465
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003466 sta_id = iwl_find_station(priv, ra);
Zhu Yib481de92007-09-25 17:54:57 -07003467
3468 if (sta_id == IWL_INVALID_STATION)
3469 return -ENXIO;
3470
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003471 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
3472 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
3473
Zhu Yib481de92007-09-25 17:54:57 -07003474 tid_data = &priv->stations[sta_id].tid[tid];
3475 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
3476 txq_id = tid_data->agg.txq_id;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003477 write_ptr = priv->txq[txq_id].q.write_ptr;
3478 read_ptr = priv->txq[txq_id].q.read_ptr;
Zhu Yib481de92007-09-25 17:54:57 -07003479
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003480 /* The queue is not empty */
3481 if (write_ptr != read_ptr) {
3482 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
3483 priv->stations[sta_id].tid[tid].agg.state =
3484 IWL_EMPTYING_HW_QUEUE_DELBA;
3485 return 0;
3486 }
3487
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003488 IWL_DEBUG_HT("HW queue is empty\n");
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003489 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
3490
3491 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003492 ret = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003493 spin_unlock_irqrestore(&priv->lock, flags);
3494
Ron Rindjunskyb095d03a72008-03-06 17:36:56 -08003495 if (ret)
3496 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003497
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003498 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
Zhu Yib481de92007-09-25 17:54:57 -07003499
3500 return 0;
3501}
3502
Ron Rindjunsky8114fcf2008-01-28 14:07:23 +02003503int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3504 enum ieee80211_ampdu_mlme_action action,
3505 const u8 *addr, u16 tid, u16 *ssn)
3506{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003507 struct iwl_priv *priv = hw->priv;
Ron Rindjunsky8114fcf2008-01-28 14:07:23 +02003508 DECLARE_MAC_BUF(mac);
3509
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003510 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
3511 print_mac(mac, addr), tid);
3512
Ron Rindjunsky8114fcf2008-01-28 14:07:23 +02003513 switch (action) {
3514 case IEEE80211_AMPDU_RX_START:
3515 IWL_DEBUG_HT("start Rx\n");
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003516 return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
Ron Rindjunsky8114fcf2008-01-28 14:07:23 +02003517 case IEEE80211_AMPDU_RX_STOP:
3518 IWL_DEBUG_HT("stop Rx\n");
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003519 return iwl4965_rx_agg_stop(priv, addr, tid);
Ron Rindjunsky8114fcf2008-01-28 14:07:23 +02003520 case IEEE80211_AMPDU_TX_START:
3521 IWL_DEBUG_HT("start Tx\n");
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003522 return iwl4965_tx_agg_start(hw, addr, tid, ssn);
Ron Rindjunsky8114fcf2008-01-28 14:07:23 +02003523 case IEEE80211_AMPDU_TX_STOP:
3524 IWL_DEBUG_HT("stop Tx\n");
Ron Rindjunskyfe07aa72008-04-17 16:03:37 -07003525 return iwl4965_tx_agg_stop(hw, addr, tid);
Ron Rindjunsky8114fcf2008-01-28 14:07:23 +02003526 default:
3527 IWL_DEBUG_HT("unknown\n");
3528 return -EINVAL;
3529 break;
3530 }
3531 return 0;
3532}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003533#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07003534
Tomas Winkler133636d2008-05-05 10:22:34 +08003535
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08003536static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
3537{
3538 switch (cmd_id) {
3539 case REPLY_RXON:
3540 return (u16) sizeof(struct iwl4965_rxon_cmd);
3541 default:
3542 return len;
3543 }
3544}
3545
Tomas Winkler133636d2008-05-05 10:22:34 +08003546static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
3547{
3548 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
3549 addsta->mode = cmd->mode;
3550 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
3551 memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
3552 addsta->station_flags = cmd->station_flags;
3553 addsta->station_flags_msk = cmd->station_flags_msk;
3554 addsta->tid_disable_tx = cmd->tid_disable_tx;
3555 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
3556 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
3557 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
3558 addsta->reserved1 = __constant_cpu_to_le16(0);
3559 addsta->reserved2 = __constant_cpu_to_le32(0);
3560
3561 return (u16)sizeof(struct iwl4965_addsta_cmd);
3562}
Zhu Yib481de92007-09-25 17:54:57 -07003563/* Set up 4965-specific Rx frame reply handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07003564static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003565{
3566 /* Legacy Rx frames */
Tomas Winkler857485c2008-03-21 13:53:44 -07003567 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
Zhu Yib481de92007-09-25 17:54:57 -07003568
3569 /* High-throughput (HT) Rx frames */
3570 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
3571 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
3572
3573 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
3574 iwl4965_rx_missed_beacon_notif;
3575
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003576#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07003577 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003578#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07003579}
3580
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003581void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003582{
3583 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07003584#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
Zhu Yib481de92007-09-25 17:54:57 -07003585 INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
3586#endif
Zhu Yib481de92007-09-25 17:54:57 -07003587 init_timer(&priv->statistics_periodic);
3588 priv->statistics_periodic.data = (unsigned long)priv;
3589 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
3590}
3591
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003592void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003593{
3594 del_timer_sync(&priv->statistics_periodic);
3595
3596 cancel_delayed_work(&priv->init_alive_start);
3597}
3598
Tomas Winkler3c424c22008-04-15 16:01:42 -07003599
3600static struct iwl_hcmd_ops iwl4965_hcmd = {
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003601 .rxon_assoc = iwl4965_send_rxon_assoc,
Tomas Winkler3c424c22008-04-15 16:01:42 -07003602};
3603
Tomas Winkler857485c2008-03-21 13:53:44 -07003604static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08003605 .get_hcmd_size = iwl4965_get_hcmd_size,
Tomas Winkler133636d2008-05-05 10:22:34 +08003606 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07003607#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3608 .chain_noise_reset = iwl4965_chain_noise_reset,
3609 .gain_computation = iwl4965_gain_computation,
3610#endif
Tomas Winkler857485c2008-03-21 13:53:44 -07003611};
3612
Assaf Krauss6bc913b2008-03-11 16:17:18 -07003613static struct iwl_lib_ops iwl4965_lib = {
Tomas Winkler5425e492008-04-15 16:01:38 -07003614 .set_hw_params = iwl4965_hw_set_hw_params,
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003615 .alloc_shared_mem = iwl4965_alloc_shared_mem,
3616 .free_shared_mem = iwl4965_free_shared_mem,
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08003617 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
Tomas Winklere2a722e2008-04-14 21:16:10 -07003618 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +08003619 .disable_tx_fifo = iwl4965_disable_tx_fifo,
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07003620 .rx_handler_setup = iwl4965_rx_handler_setup,
Tomas Winkler57aab752008-04-14 21:16:03 -07003621 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
3622 .alive_notify = iwl4965_alive_notify,
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08003623 .init_alive_start = iwl4965_init_alive_start,
Tomas Winkler57aab752008-04-14 21:16:03 -07003624 .load_ucode = iwl4965_load_bsm,
Tomas Winkler6f4083a2008-04-16 16:34:49 -07003625 .apm_ops = {
Tomas Winkler91238712008-04-23 17:14:53 -07003626 .init = iwl4965_apm_init,
Tomas Winkler7f066102008-05-29 16:34:57 +08003627 .reset = iwl4965_apm_reset,
Tomas Winkler694cc562008-04-24 11:55:22 -07003628 .config = iwl4965_nic_config,
Tomas Winkler6f4083a2008-04-16 16:34:49 -07003629 .set_pwr_src = iwl4965_set_pwr_src,
3630 },
Assaf Krauss6bc913b2008-03-11 16:17:18 -07003631 .eeprom_ops = {
Tomas Winkler073d3f52008-04-21 15:41:52 -07003632 .regulatory_bands = {
3633 EEPROM_REGULATORY_BAND_1_CHANNELS,
3634 EEPROM_REGULATORY_BAND_2_CHANNELS,
3635 EEPROM_REGULATORY_BAND_3_CHANNELS,
3636 EEPROM_REGULATORY_BAND_4_CHANNELS,
3637 EEPROM_REGULATORY_BAND_5_CHANNELS,
3638 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
3639 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
3640 },
Assaf Krauss6bc913b2008-03-11 16:17:18 -07003641 .verify_signature = iwlcore_eeprom_verify_signature,
3642 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
3643 .release_semaphore = iwlcore_eeprom_release_semaphore,
Tomas Winkler8614f362008-04-23 17:14:55 -07003644 .check_version = iwl4965_eeprom_check_version,
Tomas Winkler073d3f52008-04-21 15:41:52 -07003645 .query_addr = iwlcore_eeprom_query_addr,
Assaf Krauss6bc913b2008-03-11 16:17:18 -07003646 },
Mohamed Abbasad97edd2008-03-28 16:21:06 -07003647 .radio_kill_sw = iwl4965_radio_kill_sw,
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003648 .set_power = iwl4965_set_power,
3649 .update_chain_flags = iwl4965_update_chain_flags,
Assaf Krauss6bc913b2008-03-11 16:17:18 -07003650};
3651
3652static struct iwl_ops iwl4965_ops = {
3653 .lib = &iwl4965_lib,
Tomas Winkler3c424c22008-04-15 16:01:42 -07003654 .hcmd = &iwl4965_hcmd,
Tomas Winkler857485c2008-03-21 13:53:44 -07003655 .utils = &iwl4965_hcmd_utils,
Assaf Krauss6bc913b2008-03-11 16:17:18 -07003656};
3657
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003658struct iwl_cfg iwl4965_agn_cfg = {
Tomas Winkler82b9a122008-03-04 18:09:30 -08003659 .name = "4965AGN",
Tomas Winkler4bf775c2008-03-04 18:09:31 -08003660 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
Tomas Winkler82b9a122008-03-04 18:09:30 -08003661 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
Tomas Winkler073d3f52008-04-21 15:41:52 -07003662 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
Assaf Krauss6bc913b2008-03-11 16:17:18 -07003663 .ops = &iwl4965_ops,
Assaf Krauss1ea87392008-03-18 14:57:50 -07003664 .mod_params = &iwl4965_mod_params,
Tomas Winkler82b9a122008-03-04 18:09:30 -08003665};
3666
Assaf Krauss1ea87392008-03-18 14:57:50 -07003667module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
3668MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
3669module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
3670MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Emmanuel Grumbachfcc76c62008-04-15 16:01:47 -07003671module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
3672MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
Assaf Krauss1ea87392008-03-18 14:57:50 -07003673module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
3674MODULE_PARM_DESC(debug, "debug output mask");
3675module_param_named(
3676 disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
3677MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
3678
3679module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
3680MODULE_PARM_DESC(queues_num, "number of hw queues.");
3681
3682/* QoS */
3683module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
3684MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
3685module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
3686MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
Ester Kummer3a1081e2008-05-06 11:05:14 +08003687module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
3688MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");