blob: ef9d3399dfd2dea20e25c66af32650f34e27b629 [file] [log] [blame]
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001/******************************************************************************
2 *
3 * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
23 *
24 *****************************************************************************/
25
26#include <linux/kernel.h>
27#include <linux/module.h>
Tomas Winkler5a6a2562008-04-24 11:55:23 -070028#include <linux/init.h>
29#include <linux/pci.h>
30#include <linux/dma-mapping.h>
31#include <linux/delay.h>
32#include <linux/skbuff.h>
33#include <linux/netdevice.h>
34#include <linux/wireless.h>
35#include <net/mac80211.h>
36#include <linux/etherdevice.h>
37#include <asm/unaligned.h>
38
39#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070040#include "iwl-dev.h"
Tomas Winkler5a6a2562008-04-24 11:55:23 -070041#include "iwl-core.h"
42#include "iwl-io.h"
Tomas Winklere26e47d2008-06-12 09:46:56 +080043#include "iwl-sta.h"
Tomas Winkler5a6a2562008-04-24 11:55:23 -070044#include "iwl-helpers.h"
45#include "iwl-5000-hw.h"
46
47#define IWL5000_UCODE_API "-1"
48
Ron Rindjunsky99da1b42008-05-15 13:54:13 +080049static const u16 iwl5000_default_queue_to_tx_fifo[] = {
50 IWL_TX_FIFO_AC3,
51 IWL_TX_FIFO_AC2,
52 IWL_TX_FIFO_AC1,
53 IWL_TX_FIFO_AC0,
54 IWL50_CMD_FIFO_NUM,
55 IWL_TX_FIFO_HCCA_1,
56 IWL_TX_FIFO_HCCA_2
57};
58
Tomas Winkler46315e02008-05-29 16:34:59 +080059/* FIXME: same implementation as 4965 */
60static int iwl5000_apm_stop_master(struct iwl_priv *priv)
61{
62 int ret = 0;
63 unsigned long flags;
64
65 spin_lock_irqsave(&priv->lock, flags);
66
67 /* set stop master bit */
68 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
69
70 ret = iwl_poll_bit(priv, CSR_RESET,
71 CSR_RESET_REG_FLAG_MASTER_DISABLED,
72 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
73 if (ret < 0)
74 goto out;
75
76out:
77 spin_unlock_irqrestore(&priv->lock, flags);
78 IWL_DEBUG_INFO("stop master\n");
79
80 return ret;
81}
82
83
Tomas Winkler30d59262008-04-24 11:55:25 -070084static int iwl5000_apm_init(struct iwl_priv *priv)
85{
86 int ret = 0;
87
88 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
89 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
90
Tomas Winkler8f061892008-05-29 16:34:56 +080091 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
92 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
93 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
94
Tomas Winkler4c43e0d2008-08-04 16:00:39 +080095 /* Set FH wait treshold to maximum (HW error during stress W/A) */
96 iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
97
98 /* enable HAP INTA to move device L1a -> L0s */
99 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
100 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
101
Tomas Winkler30d59262008-04-24 11:55:25 -0700102 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
103
104 /* set "initialization complete" bit to move adapter
105 * D0U* --> D0A* state */
106 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
107
108 /* wait for clock stabilization */
109 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
110 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
111 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
112 if (ret < 0) {
113 IWL_DEBUG_INFO("Failed to init the card\n");
114 return ret;
115 }
116
117 ret = iwl_grab_nic_access(priv);
118 if (ret)
119 return ret;
120
121 /* enable DMA */
Tomas Winkler8f061892008-05-29 16:34:56 +0800122 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler30d59262008-04-24 11:55:25 -0700123
124 udelay(20);
125
Tomas Winkler8f061892008-05-29 16:34:56 +0800126 /* disable L1-Active */
Tomas Winkler30d59262008-04-24 11:55:25 -0700127 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
Tomas Winkler8f061892008-05-29 16:34:56 +0800128 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
Tomas Winkler30d59262008-04-24 11:55:25 -0700129
130 iwl_release_nic_access(priv);
131
132 return ret;
133}
134
Tomas Winklerf118a912008-05-29 16:34:58 +0800135/* FIXME: this is indentical to 4965 */
136static void iwl5000_apm_stop(struct iwl_priv *priv)
137{
138 unsigned long flags;
139
Tomas Winkler46315e02008-05-29 16:34:59 +0800140 iwl5000_apm_stop_master(priv);
Tomas Winklerf118a912008-05-29 16:34:58 +0800141
142 spin_lock_irqsave(&priv->lock, flags);
143
144 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
145
146 udelay(10);
147
148 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
149
150 spin_unlock_irqrestore(&priv->lock, flags);
151}
152
153
Tomas Winkler7f066102008-05-29 16:34:57 +0800154static int iwl5000_apm_reset(struct iwl_priv *priv)
155{
156 int ret = 0;
157 unsigned long flags;
158
Tomas Winkler46315e02008-05-29 16:34:59 +0800159 iwl5000_apm_stop_master(priv);
Tomas Winkler7f066102008-05-29 16:34:57 +0800160
161 spin_lock_irqsave(&priv->lock, flags);
162
163 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
164
165 udelay(10);
166
167
168 /* FIXME: put here L1A -L0S w/a */
169
170 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
171
172 /* set "initialization complete" bit to move adapter
173 * D0U* --> D0A* state */
174 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
175
176 /* wait for clock stabilization */
177 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
178 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
179 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
180 if (ret < 0) {
181 IWL_DEBUG_INFO("Failed to init the card\n");
182 goto out;
183 }
184
185 ret = iwl_grab_nic_access(priv);
186 if (ret)
187 goto out;
188
189 /* enable DMA */
190 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
191
192 udelay(20);
193
194 /* disable L1-Active */
195 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
196 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
197
198 iwl_release_nic_access(priv);
199
200out:
201 spin_unlock_irqrestore(&priv->lock, flags);
202
203 return ret;
204}
205
206
Ron Rindjunsky5a835352008-05-05 10:22:29 +0800207static void iwl5000_nic_config(struct iwl_priv *priv)
Tomas Winklere86fe9f2008-04-24 11:55:36 -0700208{
209 unsigned long flags;
210 u16 radio_cfg;
Tomas Winklere7b63582008-09-03 11:26:49 +0800211 u16 link;
Tomas Winklere86fe9f2008-04-24 11:55:36 -0700212
213 spin_lock_irqsave(&priv->lock, flags);
214
Tomas Winklere7b63582008-09-03 11:26:49 +0800215 pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &link);
Tomas Winklere86fe9f2008-04-24 11:55:36 -0700216
Tomas Winkler8f061892008-05-29 16:34:56 +0800217 /* L1 is enabled by BIOS */
Tomas Winklere7b63582008-09-03 11:26:49 +0800218 if ((link & PCI_CFG_LINK_CTRL_VAL_L1_EN) == PCI_CFG_LINK_CTRL_VAL_L1_EN)
Tomas Winkler8f061892008-05-29 16:34:56 +0800219 /* diable L0S disabled L1A enabled */
220 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
221 else
222 /* L0S enabled L1A disabled */
223 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
Tomas Winklere86fe9f2008-04-24 11:55:36 -0700224
225 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
226
227 /* write radio config values to register */
228 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
229 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
230 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
231 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
232 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
233
234 /* set CSR_HW_CONFIG_REG for uCode use */
235 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
236 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
237 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
238
Tomas Winkler4c43e0d2008-08-04 16:00:39 +0800239 /* W/A : NIC is stuck in a reset state after Early PCIe power off
240 * (PCIe power is lost before PERST# is asserted),
241 * causing ME FW to lose ownership and not being able to obtain it back.
242 */
Tomas Winkler2d3db672008-08-04 16:00:47 +0800243 iwl_grab_nic_access(priv);
244 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
Tomas Winkler4c43e0d2008-08-04 16:00:39 +0800245 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
246 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
Tomas Winkler2d3db672008-08-04 16:00:47 +0800247 iwl_release_nic_access(priv);
Tomas Winkler4c43e0d2008-08-04 16:00:39 +0800248
Tomas Winklere86fe9f2008-04-24 11:55:36 -0700249 spin_unlock_irqrestore(&priv->lock, flags);
250}
251
252
253
Tomas Winkler25ae3982008-04-24 11:55:27 -0700254/*
255 * EEPROM
256 */
257static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
258{
259 u16 offset = 0;
260
261 if ((address & INDIRECT_ADDRESS) == 0)
262 return address;
263
264 switch (address & INDIRECT_TYPE_MSK) {
265 case INDIRECT_HOST:
266 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
267 break;
268 case INDIRECT_GENERAL:
269 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
270 break;
271 case INDIRECT_REGULATORY:
272 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
273 break;
274 case INDIRECT_CALIBRATION:
275 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
276 break;
277 case INDIRECT_PROCESS_ADJST:
278 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
279 break;
280 case INDIRECT_OTHERS:
281 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
282 break;
283 default:
284 IWL_ERROR("illegal indirect type: 0x%X\n",
285 address & INDIRECT_TYPE_MSK);
286 break;
287 }
288
289 /* translate the offset from words to byte */
290 return (address & ADDRESS_MSK) + (offset << 1);
291}
292
Tomas Winklerf1f69412008-04-24 11:55:35 -0700293static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
294{
295 u16 eeprom_ver;
296 struct iwl_eeprom_calib_hdr {
297 u8 version;
298 u8 pa_type;
299 u16 voltage;
300 } *hdr;
301
302 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
303
304 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
305 EEPROM_5000_CALIB_ALL);
306
307 if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
308 hdr->version < EEPROM_5000_TX_POWER_VERSION)
309 goto err;
310
311 return 0;
312err:
313 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
314 eeprom_ver, EEPROM_5000_EEPROM_VERSION,
315 hdr->version, EEPROM_5000_TX_POWER_VERSION);
316 return -EINVAL;
317
318}
319
Emmanuel Grumbach33fd5032008-04-24 11:55:30 -0700320static void iwl5000_gain_computation(struct iwl_priv *priv,
321 u32 average_noise[NUM_RX_CHAINS],
322 u16 min_average_noise_antenna_i,
323 u32 min_average_noise)
324{
325 int i;
326 s32 delta_g;
327 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
328
329 /* Find Gain Code for the antennas B and C */
330 for (i = 1; i < NUM_RX_CHAINS; i++) {
331 if ((data->disconn_array[i])) {
332 data->delta_gain_code[i] = 0;
333 continue;
334 }
335 delta_g = (1000 * ((s32)average_noise[0] -
336 (s32)average_noise[i])) / 1500;
337 /* bound gain by 2 bits value max, 3rd bit is sign */
338 data->delta_gain_code[i] =
339 min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
340
341 if (delta_g < 0)
342 /* set negative sign */
343 data->delta_gain_code[i] |= (1 << 2);
344 }
345
346 IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
347 data->delta_gain_code[1], data->delta_gain_code[2]);
348
349 if (!data->radio_write) {
350 struct iwl5000_calibration_chain_noise_gain_cmd cmd;
351 memset(&cmd, 0, sizeof(cmd));
352
353 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
354 cmd.delta_gain_1 = data->delta_gain_code[1];
355 cmd.delta_gain_2 = data->delta_gain_code[2];
356 iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
357 sizeof(cmd), &cmd, NULL);
358
359 data->radio_write = 1;
360 data->state = IWL_CHAIN_NOISE_CALIBRATED;
361 }
362
363 data->chain_noise_a = 0;
364 data->chain_noise_b = 0;
365 data->chain_noise_c = 0;
366 data->chain_signal_a = 0;
367 data->chain_signal_b = 0;
368 data->chain_signal_c = 0;
369 data->beacon_count = 0;
370}
371
372static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
373{
374 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
375
376 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
377 struct iwl5000_calibration_chain_noise_reset_cmd cmd;
378
379 memset(&cmd, 0, sizeof(cmd));
380 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
381 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
382 sizeof(cmd), &cmd))
383 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
384 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
385 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
386 }
387}
388
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +0800389static void iwl5000_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
390 __le32 *tx_flags)
391{
392 if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
393 (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
394 *tx_flags |= TX_CMD_FLG_RTS_CTS_MSK;
395 else
396 *tx_flags &= ~TX_CMD_FLG_RTS_CTS_MSK;
397}
398
Emmanuel Grumbach33fd5032008-04-24 11:55:30 -0700399static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
400 .min_nrg_cck = 95,
401 .max_nrg_cck = 0,
402 .auto_corr_min_ofdm = 90,
403 .auto_corr_min_ofdm_mrc = 170,
404 .auto_corr_min_ofdm_x1 = 120,
405 .auto_corr_min_ofdm_mrc_x1 = 240,
406
407 .auto_corr_max_ofdm = 120,
408 .auto_corr_max_ofdm_mrc = 210,
409 .auto_corr_max_ofdm_x1 = 155,
410 .auto_corr_max_ofdm_mrc_x1 = 290,
411
412 .auto_corr_min_cck = 125,
413 .auto_corr_max_cck = 200,
414 .auto_corr_min_cck_mrc = 170,
415 .auto_corr_max_cck_mrc = 400,
416 .nrg_th_cck = 95,
417 .nrg_th_ofdm = 95,
418};
419
Tomas Winkler25ae3982008-04-24 11:55:27 -0700420static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
421 size_t offset)
422{
423 u32 address = eeprom_indirect_address(priv, offset);
424 BUG_ON(address >= priv->cfg->eeprom_size);
425 return &priv->eeprom[address];
426}
427
Ron Rindjunskydbb983b2008-05-15 13:54:12 +0800428/*
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800429 * Calibration
430 */
431static int iwl5000_send_Xtal_calib(struct iwl_priv *priv)
432{
433 u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
434
435 struct iwl5000_calibration cal_cmd = {
436 .op_code = IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD,
437 .data = {
438 (u8)xtal_calib[0],
439 (u8)xtal_calib[1],
440 }
441 };
442
443 return iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
444 sizeof(cal_cmd), &cal_cmd);
445}
446
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800447static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
448{
449 struct iwl5000_calib_cfg_cmd calib_cfg_cmd;
450 struct iwl_host_cmd cmd = {
451 .id = CALIBRATION_CFG_CMD,
452 .len = sizeof(struct iwl5000_calib_cfg_cmd),
453 .data = &calib_cfg_cmd,
454 };
455
456 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
457 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
458 calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
459 calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
460 calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
461
462 return iwl_send_cmd(priv, &cmd);
463}
464
465static void iwl5000_rx_calib_result(struct iwl_priv *priv,
466 struct iwl_rx_mem_buffer *rxb)
467{
468 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
469 struct iwl5000_calib_hdr *hdr = (struct iwl5000_calib_hdr *)pkt->u.raw;
470 int len = le32_to_cpu(pkt->len) & FH_RSCSR_FRAME_SIZE_MSK;
Tomas Winkler6e21f2c2008-09-03 11:26:37 +0800471 int index;
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800472
473 /* reduce the size of the length field itself */
474 len -= 4;
475
Tomas Winkler6e21f2c2008-09-03 11:26:37 +0800476 /* Define the order in which the results will be sent to the runtime
477 * uCode. iwl_send_calib_results sends them in a row according to their
478 * index. We sort them here */
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800479 switch (hdr->op_code) {
480 case IWL5000_PHY_CALIBRATE_LO_CMD:
Tomas Winkler6e21f2c2008-09-03 11:26:37 +0800481 index = IWL5000_CALIB_LO;
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800482 break;
483 case IWL5000_PHY_CALIBRATE_TX_IQ_CMD:
Tomas Winkler6e21f2c2008-09-03 11:26:37 +0800484 index = IWL5000_CALIB_TX_IQ;
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800485 break;
486 case IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD:
Tomas Winkler6e21f2c2008-09-03 11:26:37 +0800487 index = IWL5000_CALIB_TX_IQ_PERD;
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800488 break;
489 default:
490 IWL_ERROR("Unknown calibration notification %d\n",
491 hdr->op_code);
492 return;
493 }
Tomas Winkler6e21f2c2008-09-03 11:26:37 +0800494 iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800495}
496
497static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
498 struct iwl_rx_mem_buffer *rxb)
499{
500 IWL_DEBUG_INFO("Init. calibration is completed, restarting fw.\n");
501 queue_work(priv->workqueue, &priv->restart);
502}
503
504/*
Ron Rindjunskydbb983b2008-05-15 13:54:12 +0800505 * ucode
506 */
507static int iwl5000_load_section(struct iwl_priv *priv,
508 struct fw_desc *image,
509 u32 dst_addr)
510{
511 int ret = 0;
512 unsigned long flags;
513
514 dma_addr_t phy_addr = image->p_addr;
515 u32 byte_cnt = image->len;
516
517 spin_lock_irqsave(&priv->lock, flags);
518 ret = iwl_grab_nic_access(priv);
519 if (ret) {
520 spin_unlock_irqrestore(&priv->lock, flags);
521 return ret;
522 }
523
524 iwl_write_direct32(priv,
525 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
526 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
527
528 iwl_write_direct32(priv,
529 FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
530
531 iwl_write_direct32(priv,
532 FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
533 phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
534
535 /* FIME: write the MSB of the phy_addr in CTRL1
536 * iwl_write_direct32(priv,
537 IWL_FH_TFDIB_CTRL1_REG(IWL_FH_SRVC_CHNL),
538 ((phy_addr & MSB_MSK)
539 << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_count);
540 */
541 iwl_write_direct32(priv,
542 FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), byte_cnt);
543 iwl_write_direct32(priv,
544 FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
545 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
546 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
547 FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
548
549 iwl_write_direct32(priv,
550 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
551 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
552 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL |
553 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
554
555 iwl_release_nic_access(priv);
556 spin_unlock_irqrestore(&priv->lock, flags);
557 return 0;
558}
559
560static int iwl5000_load_given_ucode(struct iwl_priv *priv,
561 struct fw_desc *inst_image,
562 struct fw_desc *data_image)
563{
564 int ret = 0;
565
566 ret = iwl5000_load_section(
567 priv, inst_image, RTC_INST_LOWER_BOUND);
568 if (ret)
569 return ret;
570
571 IWL_DEBUG_INFO("INST uCode section being loaded...\n");
572 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
573 priv->ucode_write_complete, 5 * HZ);
574 if (ret == -ERESTARTSYS) {
575 IWL_ERROR("Could not load the INST uCode section due "
576 "to interrupt\n");
577 return ret;
578 }
579 if (!ret) {
580 IWL_ERROR("Could not load the INST uCode section\n");
581 return -ETIMEDOUT;
582 }
583
584 priv->ucode_write_complete = 0;
585
586 ret = iwl5000_load_section(
587 priv, data_image, RTC_DATA_LOWER_BOUND);
588 if (ret)
589 return ret;
590
591 IWL_DEBUG_INFO("DATA uCode section being loaded...\n");
592
593 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
594 priv->ucode_write_complete, 5 * HZ);
595 if (ret == -ERESTARTSYS) {
596 IWL_ERROR("Could not load the INST uCode section due "
597 "to interrupt\n");
598 return ret;
599 } else if (!ret) {
600 IWL_ERROR("Could not load the DATA uCode section\n");
601 return -ETIMEDOUT;
602 } else
603 ret = 0;
604
605 priv->ucode_write_complete = 0;
606
607 return ret;
608}
609
610static int iwl5000_load_ucode(struct iwl_priv *priv)
611{
612 int ret = 0;
613
614 /* check whether init ucode should be loaded, or rather runtime ucode */
615 if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
616 IWL_DEBUG_INFO("Init ucode found. Loading init ucode...\n");
617 ret = iwl5000_load_given_ucode(priv,
618 &priv->ucode_init, &priv->ucode_init_data);
619 if (!ret) {
620 IWL_DEBUG_INFO("Init ucode load complete.\n");
621 priv->ucode_type = UCODE_INIT;
622 }
623 } else {
624 IWL_DEBUG_INFO("Init ucode not found, or already loaded. "
625 "Loading runtime ucode...\n");
626 ret = iwl5000_load_given_ucode(priv,
627 &priv->ucode_code, &priv->ucode_data);
628 if (!ret) {
629 IWL_DEBUG_INFO("Runtime ucode load complete.\n");
630 priv->ucode_type = UCODE_RT;
631 }
632 }
633
634 return ret;
635}
636
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800637static void iwl5000_init_alive_start(struct iwl_priv *priv)
638{
639 int ret = 0;
640
641 /* Check alive response for "valid" sign from uCode */
642 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
643 /* We had an error bringing up the hardware, so take it
644 * all the way back down so we can try again */
645 IWL_DEBUG_INFO("Initialize Alive failed.\n");
646 goto restart;
647 }
648
649 /* initialize uCode was loaded... verify inst image.
650 * This is a paranoid check, because we would not have gotten the
651 * "initialize" alive if code weren't properly loaded. */
652 if (iwl_verify_ucode(priv)) {
653 /* Runtime instruction load was bad;
654 * take it all the way back down so we can try again */
655 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
656 goto restart;
657 }
658
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800659 iwl_clear_stations_table(priv);
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800660 ret = priv->cfg->ops->lib->alive_notify(priv);
661 if (ret) {
662 IWL_WARNING("Could not complete ALIVE transition: %d\n", ret);
663 goto restart;
664 }
665
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800666 iwl5000_send_calib_cfg(priv);
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800667 return;
668
669restart:
670 /* real restart (first load init_ucode) */
671 queue_work(priv->workqueue, &priv->restart);
672}
673
674static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
675 int txq_id, u32 index)
676{
677 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
678 (index & 0xff) | (txq_id << 8));
679 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
680}
681
682static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
683 struct iwl_tx_queue *txq,
684 int tx_fifo_id, int scd_retry)
685{
686 int txq_id = txq->q.id;
687 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
688
689 iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
690 (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
691 (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
692 (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
693 IWL50_SCD_QUEUE_STTS_REG_MSK);
694
695 txq->sched_retry = scd_retry;
696
697 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
698 active ? "Activate" : "Deactivate",
699 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
700}
701
Ron Rindjunsky9636e582008-05-15 13:54:14 +0800702static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
703{
704 struct iwl_wimax_coex_cmd coex_cmd;
705
706 memset(&coex_cmd, 0, sizeof(coex_cmd));
707
708 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
709 sizeof(coex_cmd), &coex_cmd);
710}
711
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800712static int iwl5000_alive_notify(struct iwl_priv *priv)
713{
714 u32 a;
715 int i = 0;
716 unsigned long flags;
717 int ret;
718
719 spin_lock_irqsave(&priv->lock, flags);
720
721 ret = iwl_grab_nic_access(priv);
722 if (ret) {
723 spin_unlock_irqrestore(&priv->lock, flags);
724 return ret;
725 }
726
727 priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
728 a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
729 for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
730 a += 4)
731 iwl_write_targ_mem(priv, a, 0);
732 for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
733 a += 4)
734 iwl_write_targ_mem(priv, a, 0);
735 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
736 iwl_write_targ_mem(priv, a, 0);
737
738 iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
739 (priv->shared_phys +
740 offsetof(struct iwl5000_shared, queues_byte_cnt_tbls)) >> 10);
741 iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
742 IWL50_SCD_QUEUECHAIN_SEL_ALL(
743 priv->hw_params.max_txq_num));
744 iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
745
746 /* initiate the queues */
747 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
748 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
749 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
750 iwl_write_targ_mem(priv, priv->scd_base_addr +
751 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
752 iwl_write_targ_mem(priv, priv->scd_base_addr +
753 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
754 sizeof(u32),
755 ((SCD_WIN_SIZE <<
756 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
757 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
758 ((SCD_FRAME_LIMIT <<
759 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
760 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
761 }
762
763 iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
Tomas Winklerda1bc452008-05-29 16:35:00 +0800764 IWL_MASK(0, priv->hw_params.max_txq_num));
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800765
Tomas Winklerda1bc452008-05-29 16:35:00 +0800766 /* Activate all Tx DMA/FIFO channels */
767 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800768
769 iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
770 /* map qos queues to fifos one-to-one */
771 for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
772 int ac = iwl5000_default_queue_to_tx_fifo[i];
773 iwl_txq_ctx_activate(priv, i);
774 iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
775 }
776 /* TODO - need to initialize those FIFOs inside the loop above,
777 * not only mark them as active */
778 iwl_txq_ctx_activate(priv, 4);
779 iwl_txq_ctx_activate(priv, 7);
780 iwl_txq_ctx_activate(priv, 8);
781 iwl_txq_ctx_activate(priv, 9);
782
783 iwl_release_nic_access(priv);
784 spin_unlock_irqrestore(&priv->lock, flags);
785
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800786
Ron Rindjunsky9636e582008-05-15 13:54:14 +0800787 iwl5000_send_wimax_coex(priv);
788
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800789 iwl5000_send_Xtal_calib(priv);
790
Tomas Winkler0a078ff2008-06-30 17:23:26 +0800791 if (priv->ucode_type == UCODE_RT)
Tomas Winkler6e21f2c2008-09-03 11:26:37 +0800792 iwl_send_calib_results(priv);
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800793
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800794 return 0;
795}
796
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700797static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
798{
799 if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
800 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
801 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
802 IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
803 return -EINVAL;
804 }
Tomas Winkler25ae3982008-04-24 11:55:27 -0700805
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700806 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
Ron Rindjunsky7f3e4bb2008-06-12 09:46:55 +0800807 priv->hw_params.first_ampdu_q = IWL50_FIRST_AMPDU_QUEUE;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700808 priv->hw_params.max_stations = IWL5000_STATION_COUNT;
809 priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
810 priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
811 priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
Ron Rindjunskyda154e302008-06-30 17:23:20 +0800812 priv->hw_params.max_bsm_size = 0;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700813 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
814 BIT(IEEE80211_BAND_5GHZ);
Emmanuel Grumbach33fd5032008-04-24 11:55:30 -0700815 priv->hw_params.sens = &iwl5000_sensitivity;
Tomas Winkler25ae3982008-04-24 11:55:27 -0700816
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700817 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
818 case CSR_HW_REV_TYPE_5100:
819 case CSR_HW_REV_TYPE_5150:
820 priv->hw_params.tx_chains_num = 1;
821 priv->hw_params.rx_chains_num = 2;
822 /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
Tomas Winkler1179f182008-04-24 11:55:31 -0700823 priv->hw_params.valid_tx_ant = ANT_A;
824 priv->hw_params.valid_rx_ant = ANT_AB;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700825 break;
826 case CSR_HW_REV_TYPE_5300:
827 case CSR_HW_REV_TYPE_5350:
828 priv->hw_params.tx_chains_num = 3;
829 priv->hw_params.rx_chains_num = 3;
Tomas Winkler1179f182008-04-24 11:55:31 -0700830 priv->hw_params.valid_tx_ant = ANT_ABC;
831 priv->hw_params.valid_rx_ant = ANT_ABC;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700832 break;
833 }
Emmanuel Grumbachc031bf82008-04-24 11:55:29 -0700834
835 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
836 case CSR_HW_REV_TYPE_5100:
837 case CSR_HW_REV_TYPE_5300:
838 /* 5X00 wants in Celsius */
839 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
840 break;
841 case CSR_HW_REV_TYPE_5150:
842 case CSR_HW_REV_TYPE_5350:
843 /* 5X50 wants in Kelvin */
844 priv->hw_params.ct_kill_threshold =
845 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
846 break;
847 }
848
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700849 return 0;
850}
Ron Rindjunskyd4100dd2008-04-24 11:55:33 -0700851
852static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
853{
854 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
855 sizeof(struct iwl5000_shared),
856 &priv->shared_phys);
857 if (!priv->shared_virt)
858 return -ENOMEM;
859
860 memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
861
Ron Rindjunskyd67f5482008-05-05 10:22:49 +0800862 priv->rb_closed_offset = offsetof(struct iwl5000_shared, rb_closed);
863
Ron Rindjunskyd4100dd2008-04-24 11:55:33 -0700864 return 0;
865}
866
867static void iwl5000_free_shared_mem(struct iwl_priv *priv)
868{
869 if (priv->shared_virt)
870 pci_free_consistent(priv->pci_dev,
871 sizeof(struct iwl5000_shared),
872 priv->shared_virt,
873 priv->shared_phys);
874}
875
Ron Rindjunskyd67f5482008-05-05 10:22:49 +0800876static int iwl5000_shared_mem_rx_idx(struct iwl_priv *priv)
877{
878 struct iwl5000_shared *s = priv->shared_virt;
879 return le32_to_cpu(s->rb_closed) & 0xFFF;
880}
881
Emmanuel Grumbach7839fc02008-04-24 11:55:34 -0700882/**
883 * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
884 */
885static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
Ron Rindjunsky16466902008-05-05 10:22:50 +0800886 struct iwl_tx_queue *txq,
Emmanuel Grumbach7839fc02008-04-24 11:55:34 -0700887 u16 byte_cnt)
888{
889 struct iwl5000_shared *shared_data = priv->shared_virt;
890 int txq_id = txq->q.id;
891 u8 sec_ctl = 0;
892 u8 sta = 0;
893 int len;
894
895 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
896
897 if (txq_id != IWL_CMD_QUEUE_NUM) {
Gregory Greenmanda99c4b2008-08-04 16:00:40 +0800898 sta = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id;
899 sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl;
Emmanuel Grumbach7839fc02008-04-24 11:55:34 -0700900
901 switch (sec_ctl & TX_CMD_SEC_MSK) {
902 case TX_CMD_SEC_CCM:
903 len += CCMP_MIC_LEN;
904 break;
905 case TX_CMD_SEC_TKIP:
906 len += TKIP_ICV_LEN;
907 break;
908 case TX_CMD_SEC_WEP:
909 len += WEP_IV_LEN + WEP_ICV_LEN;
910 break;
911 }
912 }
913
914 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
915 tfd_offset[txq->q.write_ptr], byte_cnt, len);
916
917 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
918 tfd_offset[txq->q.write_ptr], sta_id, sta);
919
920 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
921 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
922 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
923 byte_cnt, len);
924 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
925 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
926 sta_id, sta);
927 }
928}
929
Tomas Winkler972cf442008-05-29 16:35:13 +0800930static void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
931 struct iwl_tx_queue *txq)
932{
933 int txq_id = txq->q.id;
934 struct iwl5000_shared *shared_data = priv->shared_virt;
935 u8 sta = 0;
936
937 if (txq_id != IWL_CMD_QUEUE_NUM)
Gregory Greenmanda99c4b2008-08-04 16:00:40 +0800938 sta = txq->cmd[txq->q.read_ptr]->cmd.tx.sta_id;
Tomas Winkler972cf442008-05-29 16:35:13 +0800939
940 shared_data->queues_byte_cnt_tbls[txq_id].tfd_offset[txq->q.read_ptr].
941 val = cpu_to_le16(1 | (sta << 12));
942
943 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
944 shared_data->queues_byte_cnt_tbls[txq_id].
945 tfd_offset[IWL50_QUEUE_SIZE + txq->q.read_ptr].
946 val = cpu_to_le16(1 | (sta << 12));
947 }
948}
949
Tomas Winklere26e47d2008-06-12 09:46:56 +0800950static int iwl5000_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
951 u16 txq_id)
952{
953 u32 tbl_dw_addr;
954 u32 tbl_dw;
955 u16 scd_q2ratid;
956
957 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
958
959 tbl_dw_addr = priv->scd_base_addr +
960 IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
961
962 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
963
964 if (txq_id & 0x1)
965 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
966 else
967 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
968
969 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
970
971 return 0;
972}
973static void iwl5000_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id)
974{
975 /* Simply stop the queue, but don't change any configuration;
976 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
977 iwl_write_prph(priv,
978 IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
979 (0 << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
980 (1 << IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
981}
982
983static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
984 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
985{
986 unsigned long flags;
987 int ret;
988 u16 ra_tid;
989
Tomas Winkler9f17b312008-07-11 11:53:35 +0800990 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
991 (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
992 IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
993 txq_id, IWL50_FIRST_AMPDU_QUEUE,
994 IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
995 return -EINVAL;
996 }
Tomas Winklere26e47d2008-06-12 09:46:56 +0800997
998 ra_tid = BUILD_RAxTID(sta_id, tid);
999
1000 /* Modify device's station table to Tx this TID */
1001 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
1002
1003 spin_lock_irqsave(&priv->lock, flags);
1004 ret = iwl_grab_nic_access(priv);
1005 if (ret) {
1006 spin_unlock_irqrestore(&priv->lock, flags);
1007 return ret;
1008 }
1009
1010 /* Stop this Tx queue before configuring it */
1011 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
1012
1013 /* Map receiver-address / traffic-ID to this queue */
1014 iwl5000_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
1015
1016 /* Set this queue as a chain-building queue */
1017 iwl_set_bits_prph(priv, IWL50_SCD_QUEUECHAIN_SEL, (1<<txq_id));
1018
1019 /* enable aggregations for the queue */
1020 iwl_set_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1<<txq_id));
1021
1022 /* Place first TFD at index corresponding to start sequence number.
1023 * Assumes that ssn_idx is valid (!= 0xFFF) */
1024 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
1025 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
1026 iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
1027
1028 /* Set up Tx window size and frame limit for this queue */
1029 iwl_write_targ_mem(priv, priv->scd_base_addr +
1030 IWL50_SCD_CONTEXT_QUEUE_OFFSET(txq_id) +
1031 sizeof(u32),
1032 ((SCD_WIN_SIZE <<
1033 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
1034 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
1035 ((SCD_FRAME_LIMIT <<
1036 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
1037 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
1038
1039 iwl_set_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
1040
1041 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
1042 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
1043
1044 iwl_release_nic_access(priv);
1045 spin_unlock_irqrestore(&priv->lock, flags);
1046
1047 return 0;
1048}
1049
1050static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1051 u16 ssn_idx, u8 tx_fifo)
1052{
1053 int ret;
1054
Tomas Winkler9f17b312008-07-11 11:53:35 +08001055 if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
1056 (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
1057 IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
1058 txq_id, IWL50_FIRST_AMPDU_QUEUE,
1059 IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
Tomas Winklere26e47d2008-06-12 09:46:56 +08001060 return -EINVAL;
1061 }
1062
1063 ret = iwl_grab_nic_access(priv);
1064 if (ret)
1065 return ret;
1066
1067 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
1068
1069 iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id));
1070
1071 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
1072 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
1073 /* supposes that ssn_idx is valid (!= 0xFFF) */
1074 iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
1075
1076 iwl_clear_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
1077 iwl_txq_ctx_deactivate(priv, txq_id);
1078 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
1079
1080 iwl_release_nic_access(priv);
1081
1082 return 0;
1083}
1084
Tomas Winkler2469bf22008-05-05 10:22:35 +08001085static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
1086{
1087 u16 size = (u16)sizeof(struct iwl_addsta_cmd);
1088 memcpy(data, cmd, size);
1089 return size;
1090}
1091
1092
Tomas Winklerda1bc452008-05-29 16:35:00 +08001093/*
1094 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
1095 * must be called under priv->lock and mac access
1096 */
1097static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +08001098{
Tomas Winklerda1bc452008-05-29 16:35:00 +08001099 iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +08001100}
1101
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001102
1103static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
1104{
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001105 return le32_to_cpup((__le32 *)&tx_resp->status +
Tomas Winkler25a65722008-06-12 09:47:07 +08001106 tx_resp->frame_count) & MAX_SN;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001107}
1108
1109static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
1110 struct iwl_ht_agg *agg,
1111 struct iwl5000_tx_resp *tx_resp,
Tomas Winkler25a65722008-06-12 09:47:07 +08001112 int txq_id, u16 start_idx)
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001113{
1114 u16 status;
1115 struct agg_tx_status *frame_status = &tx_resp->status;
1116 struct ieee80211_tx_info *info = NULL;
1117 struct ieee80211_hdr *hdr = NULL;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001118 u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Tomas Winkler25a65722008-06-12 09:47:07 +08001119 int i, sh, idx;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001120 u16 seq;
1121
1122 if (agg->wait_for_ba)
1123 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
1124
1125 agg->frame_count = tx_resp->frame_count;
1126 agg->start_idx = start_idx;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001127 agg->rate_n_flags = rate_n_flags;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001128 agg->bitmap = 0;
1129
1130 /* # frames attempted by Tx command */
1131 if (agg->frame_count == 1) {
1132 /* Only one frame was attempted; no block-ack will arrive */
1133 status = le16_to_cpu(frame_status[0].status);
Tomas Winkler25a65722008-06-12 09:47:07 +08001134 idx = start_idx;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001135
1136 /* FIXME: code repetition */
1137 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
1138 agg->frame_count, agg->start_idx, idx);
1139
1140 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
1141 info->status.retry_count = tx_resp->failure_frame;
1142 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1143 info->flags |= iwl_is_tx_success(status)?
1144 IEEE80211_TX_STAT_ACK : 0;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001145 iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
1146
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001147 /* FIXME: code repetition end */
1148
1149 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
1150 status & 0xff, tx_resp->failure_frame);
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001151 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001152
1153 agg->wait_for_ba = 0;
1154 } else {
1155 /* Two or more frames were attempted; expect block-ack */
1156 u64 bitmap = 0;
1157 int start = agg->start_idx;
1158
1159 /* Construct bit-map of pending frames within Tx window */
1160 for (i = 0; i < agg->frame_count; i++) {
1161 u16 sc;
1162 status = le16_to_cpu(frame_status[i].status);
1163 seq = le16_to_cpu(frame_status[i].sequence);
1164 idx = SEQ_TO_INDEX(seq);
1165 txq_id = SEQ_TO_QUEUE(seq);
1166
1167 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
1168 AGG_TX_STATE_ABORT_MSK))
1169 continue;
1170
1171 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
1172 agg->frame_count, txq_id, idx);
1173
1174 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
1175
1176 sc = le16_to_cpu(hdr->seq_ctrl);
1177 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
1178 IWL_ERROR("BUG_ON idx doesn't match seq control"
1179 " idx=%d, seq_idx=%d, seq=%d\n",
1180 idx, SEQ_TO_SN(sc),
1181 hdr->seq_ctrl);
1182 return -1;
1183 }
1184
1185 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
1186 i, idx, SEQ_TO_SN(sc));
1187
1188 sh = idx - start;
1189 if (sh > 64) {
1190 sh = (start - idx) + 0xff;
1191 bitmap = bitmap << sh;
1192 sh = 0;
1193 start = idx;
1194 } else if (sh < -64)
1195 sh = 0xff - (start - idx);
1196 else if (sh < 0) {
1197 sh = start - idx;
1198 start = idx;
1199 bitmap = bitmap << sh;
1200 sh = 0;
1201 }
Emmanuel Grumbach4aa41f12008-07-18 13:53:09 +08001202 bitmap |= 1ULL << sh;
1203 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%llx\n",
1204 start, (unsigned long long)bitmap);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001205 }
1206
1207 agg->bitmap = bitmap;
1208 agg->start_idx = start;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001209 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
1210 agg->frame_count, agg->start_idx,
1211 (unsigned long long)agg->bitmap);
1212
1213 if (bitmap)
1214 agg->wait_for_ba = 1;
1215 }
1216 return 0;
1217}
1218
1219static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
1220 struct iwl_rx_mem_buffer *rxb)
1221{
1222 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1223 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1224 int txq_id = SEQ_TO_QUEUE(sequence);
1225 int index = SEQ_TO_INDEX(sequence);
1226 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1227 struct ieee80211_tx_info *info;
1228 struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
1229 u32 status = le16_to_cpu(tx_resp->status.status);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001230 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001231 struct ieee80211_hdr *hdr;
1232 u8 *qc = NULL;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001233
1234 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
1235 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
1236 "is out of range [0-%d] %d %d\n", txq_id,
1237 index, txq->q.n_bd, txq->q.write_ptr,
1238 txq->q.read_ptr);
1239 return;
1240 }
1241
1242 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
1243 memset(&info->status, 0, sizeof(info->status));
1244
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001245 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001246 if (ieee80211_is_data_qos(hdr->frame_control)) {
1247 qc = ieee80211_get_qos_ctl(hdr);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001248 tid = qc[0] & 0xf;
1249 }
1250
1251 sta_id = iwl_get_ra_sta_id(priv, hdr);
1252 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
1253 IWL_ERROR("Station not known\n");
1254 return;
1255 }
1256
1257 if (txq->sched_retry) {
1258 const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
1259 struct iwl_ht_agg *agg = NULL;
1260
1261 if (!qc)
1262 return;
1263
1264 agg = &priv->stations[sta_id].tid[tid].agg;
1265
Tomas Winkler25a65722008-06-12 09:47:07 +08001266 iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001267
Ron Rindjunsky32354272008-07-01 10:44:51 +03001268 /* check if BAR is needed */
1269 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
1270 info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001271
1272 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
1273 int freed, ampdu_q;
1274 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
1275 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
1276 "%d index %d\n", scd_ssn , index);
Tomas Winkler17b88922008-05-29 16:35:12 +08001277 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001278 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1279
1280 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1281 txq_id >= 0 && priv->mac80211_registered &&
1282 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
1283 /* calculate mac80211 ampdu sw queue to wake */
Ron Rindjunsky7f3e4bb2008-06-12 09:46:55 +08001284 ampdu_q = txq_id - IWL50_FIRST_AMPDU_QUEUE +
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001285 priv->hw->queues;
1286 if (agg->state == IWL_AGG_OFF)
1287 ieee80211_wake_queue(priv->hw, txq_id);
1288 else
1289 ieee80211_wake_queue(priv->hw, ampdu_q);
1290 }
Tomas Winkler30e553e2008-05-29 16:35:16 +08001291 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001292 }
1293 } else {
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001294 info->status.retry_count = tx_resp->failure_frame;
1295 info->flags =
1296 iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001297 iwl_hwrate_to_tx_control(priv,
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001298 le32_to_cpu(tx_resp->rate_n_flags),
1299 info);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001300
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001301 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
1302 "0x%x retries %d\n", txq_id,
1303 iwl_get_tx_fail_reason(status),
1304 status, le32_to_cpu(tx_resp->rate_n_flags),
1305 tx_resp->failure_frame);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001306
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001307 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
1308 if (index != -1) {
1309 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
1310 if (tid != MAX_TID_COUNT)
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001311 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001312 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001313 (txq_id >= 0) && priv->mac80211_registered)
1314 ieee80211_wake_queue(priv->hw, txq_id);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001315 if (tid != MAX_TID_COUNT)
Tomas Winkler30e553e2008-05-29 16:35:16 +08001316 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001317 }
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001318 }
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001319
1320 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
1321 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
1322}
1323
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001324/* Currently 5000 is the supperset of everything */
1325static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
1326{
1327 return len;
1328}
1329
Emmanuel Grumbach203566f2008-06-12 09:46:54 +08001330static void iwl5000_setup_deferred_work(struct iwl_priv *priv)
1331{
1332 /* in 5000 the tx power calibration is done in uCode */
1333 priv->disable_tx_power_cal = 1;
1334}
1335
Ron Rindjunskyb600e4e2008-05-15 13:54:11 +08001336static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
1337{
Tomas Winkler7c616cb2008-05-29 16:35:05 +08001338 /* init calibration handlers */
1339 priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
1340 iwl5000_rx_calib_result;
1341 priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
1342 iwl5000_rx_calib_complete;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001343 priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
Ron Rindjunskyb600e4e2008-05-15 13:54:11 +08001344}
1345
Tomas Winkler7c616cb2008-05-29 16:35:05 +08001346
Ron Rindjunsky87283cc2008-05-29 16:34:47 +08001347static int iwl5000_hw_valid_rtc_data_addr(u32 addr)
1348{
1349 return (addr >= RTC_DATA_LOWER_BOUND) &&
1350 (addr < IWL50_RTC_DATA_UPPER_BOUND);
1351}
1352
Ron Rindjunskyfe7a90c2008-05-29 16:35:14 +08001353static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
1354{
1355 int ret = 0;
1356 struct iwl5000_rxon_assoc_cmd rxon_assoc;
1357 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1358 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1359
1360 if ((rxon1->flags == rxon2->flags) &&
1361 (rxon1->filter_flags == rxon2->filter_flags) &&
1362 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1363 (rxon1->ofdm_ht_single_stream_basic_rates ==
1364 rxon2->ofdm_ht_single_stream_basic_rates) &&
1365 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1366 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1367 (rxon1->ofdm_ht_triple_stream_basic_rates ==
1368 rxon2->ofdm_ht_triple_stream_basic_rates) &&
1369 (rxon1->acquisition_data == rxon2->acquisition_data) &&
1370 (rxon1->rx_chain == rxon2->rx_chain) &&
1371 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1372 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1373 return 0;
1374 }
1375
1376 rxon_assoc.flags = priv->staging_rxon.flags;
1377 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1378 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1379 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1380 rxon_assoc.reserved1 = 0;
1381 rxon_assoc.reserved2 = 0;
1382 rxon_assoc.reserved3 = 0;
1383 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1384 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1385 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1386 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1387 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1388 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
1389 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
1390 rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
1391
1392 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1393 sizeof(rxon_assoc), &rxon_assoc, NULL);
1394 if (ret)
1395 return ret;
1396
1397 return ret;
1398}
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001399static int iwl5000_send_tx_power(struct iwl_priv *priv)
1400{
1401 struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
1402
1403 /* half dBm need to multiply */
1404 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
Gregory Greenman853554a2008-06-30 17:23:01 +08001405 tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001406 tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
1407 return iwl_send_cmd_pdu_async(priv, REPLY_TX_POWER_DBM_CMD,
1408 sizeof(tx_power_cmd), &tx_power_cmd,
1409 NULL);
1410}
1411
Zhu Yi52256402008-06-30 17:23:31 +08001412static void iwl5000_temperature(struct iwl_priv *priv)
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001413{
1414 /* store temperature from statistics (in Celsius) */
Zhu Yi52256402008-06-30 17:23:31 +08001415 priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001416}
Ron Rindjunskyfe7a90c2008-05-29 16:35:14 +08001417
Tomas Winklercaab8f12008-08-04 16:00:42 +08001418/* Calc max signal level (dBm) among 3 possible receivers */
1419static int iwl5000_calc_rssi(struct iwl_priv *priv,
1420 struct iwl_rx_phy_res *rx_resp)
1421{
1422 /* data from PHY/DSP regarding signal strength, etc.,
1423 * contents are always there, not configurable by host
1424 */
1425 struct iwl5000_non_cfg_phy *ncphy =
1426 (struct iwl5000_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
1427 u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
1428 u8 agc;
1429
1430 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_AGC_IDX]);
1431 agc = (val & IWL50_OFDM_AGC_MSK) >> IWL50_OFDM_AGC_BIT_POS;
1432
1433 /* Find max rssi among 3 possible receivers.
1434 * These values are measured by the digital signal processor (DSP).
1435 * They should stay fairly constant even as the signal strength varies,
1436 * if the radio's automatic gain control (AGC) is working right.
1437 * AGC value (see below) will provide the "interesting" info.
1438 */
1439 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_AB_IDX]);
1440 rssi_a = (val & IWL50_OFDM_RSSI_A_MSK) >> IWL50_OFDM_RSSI_A_BIT_POS;
1441 rssi_b = (val & IWL50_OFDM_RSSI_B_MSK) >> IWL50_OFDM_RSSI_B_BIT_POS;
1442 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_C_IDX]);
1443 rssi_c = (val & IWL50_OFDM_RSSI_C_MSK) >> IWL50_OFDM_RSSI_C_BIT_POS;
1444
1445 max_rssi = max_t(u32, rssi_a, rssi_b);
1446 max_rssi = max_t(u32, max_rssi, rssi_c);
1447
1448 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
1449 rssi_a, rssi_b, rssi_c, max_rssi, agc);
1450
1451 /* dBm = max_rssi dB - agc dB - constant.
1452 * Higher AGC (higher radio gain) means lower signal. */
1453 return max_rssi - agc - IWL_RSSI_OFFSET;
1454}
1455
Tomas Winklerda8dec22008-04-24 11:55:24 -07001456static struct iwl_hcmd_ops iwl5000_hcmd = {
Ron Rindjunskyfe7a90c2008-05-29 16:35:14 +08001457 .rxon_assoc = iwl5000_send_rxon_assoc,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001458};
1459
1460static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001461 .get_hcmd_size = iwl5000_get_hcmd_size,
Tomas Winkler2469bf22008-05-05 10:22:35 +08001462 .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
Emmanuel Grumbach33fd5032008-04-24 11:55:30 -07001463 .gain_computation = iwl5000_gain_computation,
1464 .chain_noise_reset = iwl5000_chain_noise_reset,
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +08001465 .rts_tx_cmd_flag = iwl5000_rts_tx_cmd_flag,
Tomas Winklercaab8f12008-08-04 16:00:42 +08001466 .calc_rssi = iwl5000_calc_rssi,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001467};
1468
1469static struct iwl_lib_ops iwl5000_lib = {
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -07001470 .set_hw_params = iwl5000_hw_set_hw_params,
Ron Rindjunskyd4100dd2008-04-24 11:55:33 -07001471 .alloc_shared_mem = iwl5000_alloc_shared_mem,
1472 .free_shared_mem = iwl5000_free_shared_mem,
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001473 .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
Emmanuel Grumbach7839fc02008-04-24 11:55:34 -07001474 .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
Tomas Winkler972cf442008-05-29 16:35:13 +08001475 .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
Tomas Winklerda1bc452008-05-29 16:35:00 +08001476 .txq_set_sched = iwl5000_txq_set_sched,
Tomas Winklere26e47d2008-06-12 09:46:56 +08001477 .txq_agg_enable = iwl5000_txq_agg_enable,
1478 .txq_agg_disable = iwl5000_txq_agg_disable,
Ron Rindjunskyb600e4e2008-05-15 13:54:11 +08001479 .rx_handler_setup = iwl5000_rx_handler_setup,
Emmanuel Grumbach203566f2008-06-12 09:46:54 +08001480 .setup_deferred_work = iwl5000_setup_deferred_work,
Ron Rindjunsky87283cc2008-05-29 16:34:47 +08001481 .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001482 .load_ucode = iwl5000_load_ucode,
Ron Rindjunsky99da1b42008-05-15 13:54:13 +08001483 .init_alive_start = iwl5000_init_alive_start,
1484 .alive_notify = iwl5000_alive_notify,
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001485 .send_tx_power = iwl5000_send_tx_power,
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001486 .temperature = iwl5000_temperature,
Mohamed Abbasca579612008-07-18 13:52:57 +08001487 .update_chain_flags = iwl4965_update_chain_flags,
Tomas Winkler30d59262008-04-24 11:55:25 -07001488 .apm_ops = {
1489 .init = iwl5000_apm_init,
Tomas Winkler7f066102008-05-29 16:34:57 +08001490 .reset = iwl5000_apm_reset,
Tomas Winklerf118a912008-05-29 16:34:58 +08001491 .stop = iwl5000_apm_stop,
Ron Rindjunsky5a835352008-05-05 10:22:29 +08001492 .config = iwl5000_nic_config,
Tomas Winkler88acbd32008-04-24 11:55:26 -07001493 .set_pwr_src = iwl4965_set_pwr_src,
Tomas Winkler30d59262008-04-24 11:55:25 -07001494 },
Tomas Winklerda8dec22008-04-24 11:55:24 -07001495 .eeprom_ops = {
Tomas Winkler25ae3982008-04-24 11:55:27 -07001496 .regulatory_bands = {
1497 EEPROM_5000_REG_BAND_1_CHANNELS,
1498 EEPROM_5000_REG_BAND_2_CHANNELS,
1499 EEPROM_5000_REG_BAND_3_CHANNELS,
1500 EEPROM_5000_REG_BAND_4_CHANNELS,
1501 EEPROM_5000_REG_BAND_5_CHANNELS,
1502 EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
1503 EEPROM_5000_REG_BAND_52_FAT_CHANNELS
1504 },
Tomas Winklerda8dec22008-04-24 11:55:24 -07001505 .verify_signature = iwlcore_eeprom_verify_signature,
1506 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
1507 .release_semaphore = iwlcore_eeprom_release_semaphore,
Tomas Winklerf1f69412008-04-24 11:55:35 -07001508 .check_version = iwl5000_eeprom_check_version,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001509 .query_addr = iwl5000_eeprom_query_addr,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001510 },
1511};
1512
1513static struct iwl_ops iwl5000_ops = {
1514 .lib = &iwl5000_lib,
1515 .hcmd = &iwl5000_hcmd,
1516 .utils = &iwl5000_hcmd_utils,
1517};
1518
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001519static struct iwl_mod_params iwl50_mod_params = {
1520 .num_of_queues = IWL50_NUM_QUEUES,
Tomas Winkler9f17b312008-07-11 11:53:35 +08001521 .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001522 .enable_qos = 1,
1523 .amsdu_size_8K = 1,
Ester Kummer3a1081e2008-05-06 11:05:14 +08001524 .restart_fw = 1,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001525 /* the rest are 0 by default */
1526};
1527
1528
1529struct iwl_cfg iwl5300_agn_cfg = {
1530 .name = "5300AGN",
1531 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1532 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001533 .ops = &iwl5000_ops,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001534 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001535 .mod_params = &iwl50_mod_params,
1536};
1537
Esti Kummer47408632008-07-11 11:53:30 +08001538struct iwl_cfg iwl5100_bg_cfg = {
1539 .name = "5100BG",
1540 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1541 .sku = IWL_SKU_G,
1542 .ops = &iwl5000_ops,
1543 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1544 .mod_params = &iwl50_mod_params,
1545};
1546
1547struct iwl_cfg iwl5100_abg_cfg = {
1548 .name = "5100ABG",
1549 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1550 .sku = IWL_SKU_A|IWL_SKU_G,
1551 .ops = &iwl5000_ops,
1552 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1553 .mod_params = &iwl50_mod_params,
1554};
1555
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001556struct iwl_cfg iwl5100_agn_cfg = {
1557 .name = "5100AGN",
1558 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1559 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001560 .ops = &iwl5000_ops,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001561 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001562 .mod_params = &iwl50_mod_params,
1563};
1564
1565struct iwl_cfg iwl5350_agn_cfg = {
1566 .name = "5350AGN",
1567 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1568 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001569 .ops = &iwl5000_ops,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001570 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001571 .mod_params = &iwl50_mod_params,
1572};
1573
1574module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
1575MODULE_PARM_DESC(disable50,
1576 "manually disable the 50XX radio (default 0 [radio on])");
1577module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
1578MODULE_PARM_DESC(swcrypto50,
1579 "using software crypto engine (default 0 [hardware])\n");
1580module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
1581MODULE_PARM_DESC(debug50, "50XX debug output mask");
1582module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
1583MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
1584module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
1585MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
Ron Rindjunsky49779292008-06-30 17:23:21 +08001586module_param_named(11n_disable50, iwl50_mod_params.disable_11n, int, 0444);
1587MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality");
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001588module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
1589MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
Ester Kummer3a1081e2008-05-06 11:05:14 +08001590module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
1591MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");