blob: 75283fb9d5a875b5721014fb4d09fb21bba4a84d [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>
28#include <linux/version.h>
29#include <linux/init.h>
30#include <linux/pci.h>
31#include <linux/dma-mapping.h>
32#include <linux/delay.h>
33#include <linux/skbuff.h>
34#include <linux/netdevice.h>
35#include <linux/wireless.h>
36#include <net/mac80211.h>
37#include <linux/etherdevice.h>
38#include <asm/unaligned.h>
39
40#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070041#include "iwl-dev.h"
Tomas Winkler5a6a2562008-04-24 11:55:23 -070042#include "iwl-core.h"
43#include "iwl-io.h"
Tomas Winklere26e47d2008-06-12 09:46:56 +080044#include "iwl-sta.h"
Tomas Winkler5a6a2562008-04-24 11:55:23 -070045#include "iwl-helpers.h"
46#include "iwl-5000-hw.h"
47
48#define IWL5000_UCODE_API "-1"
49
Ron Rindjunsky99da1b42008-05-15 13:54:13 +080050static const u16 iwl5000_default_queue_to_tx_fifo[] = {
51 IWL_TX_FIFO_AC3,
52 IWL_TX_FIFO_AC2,
53 IWL_TX_FIFO_AC1,
54 IWL_TX_FIFO_AC0,
55 IWL50_CMD_FIFO_NUM,
56 IWL_TX_FIFO_HCCA_1,
57 IWL_TX_FIFO_HCCA_2
58};
59
Tomas Winkler46315e02008-05-29 16:34:59 +080060/* FIXME: same implementation as 4965 */
61static int iwl5000_apm_stop_master(struct iwl_priv *priv)
62{
63 int ret = 0;
64 unsigned long flags;
65
66 spin_lock_irqsave(&priv->lock, flags);
67
68 /* set stop master bit */
69 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
70
71 ret = iwl_poll_bit(priv, CSR_RESET,
72 CSR_RESET_REG_FLAG_MASTER_DISABLED,
73 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
74 if (ret < 0)
75 goto out;
76
77out:
78 spin_unlock_irqrestore(&priv->lock, flags);
79 IWL_DEBUG_INFO("stop master\n");
80
81 return ret;
82}
83
84
Tomas Winkler30d59262008-04-24 11:55:25 -070085static int iwl5000_apm_init(struct iwl_priv *priv)
86{
87 int ret = 0;
88
89 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
90 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
91
Tomas Winkler8f061892008-05-29 16:34:56 +080092 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
93 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
94 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
95
Tomas Winkler30d59262008-04-24 11:55:25 -070096 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
97
98 /* set "initialization complete" bit to move adapter
99 * D0U* --> D0A* state */
100 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
101
102 /* wait for clock stabilization */
103 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
104 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
105 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
106 if (ret < 0) {
107 IWL_DEBUG_INFO("Failed to init the card\n");
108 return ret;
109 }
110
111 ret = iwl_grab_nic_access(priv);
112 if (ret)
113 return ret;
114
115 /* enable DMA */
Tomas Winkler8f061892008-05-29 16:34:56 +0800116 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler30d59262008-04-24 11:55:25 -0700117
118 udelay(20);
119
Tomas Winkler8f061892008-05-29 16:34:56 +0800120 /* disable L1-Active */
Tomas Winkler30d59262008-04-24 11:55:25 -0700121 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
Tomas Winkler8f061892008-05-29 16:34:56 +0800122 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
Tomas Winkler30d59262008-04-24 11:55:25 -0700123
124 iwl_release_nic_access(priv);
125
126 return ret;
127}
128
Tomas Winklerf118a912008-05-29 16:34:58 +0800129/* FIXME: this is indentical to 4965 */
130static void iwl5000_apm_stop(struct iwl_priv *priv)
131{
132 unsigned long flags;
133
Tomas Winkler46315e02008-05-29 16:34:59 +0800134 iwl5000_apm_stop_master(priv);
Tomas Winklerf118a912008-05-29 16:34:58 +0800135
136 spin_lock_irqsave(&priv->lock, flags);
137
138 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
139
140 udelay(10);
141
142 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
143
144 spin_unlock_irqrestore(&priv->lock, flags);
145}
146
147
Tomas Winkler7f066102008-05-29 16:34:57 +0800148static int iwl5000_apm_reset(struct iwl_priv *priv)
149{
150 int ret = 0;
151 unsigned long flags;
152
Tomas Winkler46315e02008-05-29 16:34:59 +0800153 iwl5000_apm_stop_master(priv);
Tomas Winkler7f066102008-05-29 16:34:57 +0800154
155 spin_lock_irqsave(&priv->lock, flags);
156
157 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
158
159 udelay(10);
160
161
162 /* FIXME: put here L1A -L0S w/a */
163
164 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
165
166 /* set "initialization complete" bit to move adapter
167 * D0U* --> D0A* state */
168 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
169
170 /* wait for clock stabilization */
171 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
172 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
173 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
174 if (ret < 0) {
175 IWL_DEBUG_INFO("Failed to init the card\n");
176 goto out;
177 }
178
179 ret = iwl_grab_nic_access(priv);
180 if (ret)
181 goto out;
182
183 /* enable DMA */
184 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
185
186 udelay(20);
187
188 /* disable L1-Active */
189 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
190 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
191
192 iwl_release_nic_access(priv);
193
194out:
195 spin_unlock_irqrestore(&priv->lock, flags);
196
197 return ret;
198}
199
200
Ron Rindjunsky5a835352008-05-05 10:22:29 +0800201static void iwl5000_nic_config(struct iwl_priv *priv)
Tomas Winklere86fe9f2008-04-24 11:55:36 -0700202{
203 unsigned long flags;
204 u16 radio_cfg;
205 u8 val_link;
206
207 spin_lock_irqsave(&priv->lock, flags);
208
209 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
210
Tomas Winkler8f061892008-05-29 16:34:56 +0800211 /* L1 is enabled by BIOS */
212 if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
213 /* diable L0S disabled L1A enabled */
214 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
215 else
216 /* L0S enabled L1A disabled */
217 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
Tomas Winklere86fe9f2008-04-24 11:55:36 -0700218
219 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
220
221 /* write radio config values to register */
222 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
223 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
224 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
225 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
226 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
227
228 /* set CSR_HW_CONFIG_REG for uCode use */
229 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
230 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
231 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
232
233 spin_unlock_irqrestore(&priv->lock, flags);
234}
235
236
237
Tomas Winkler25ae3982008-04-24 11:55:27 -0700238/*
239 * EEPROM
240 */
241static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
242{
243 u16 offset = 0;
244
245 if ((address & INDIRECT_ADDRESS) == 0)
246 return address;
247
248 switch (address & INDIRECT_TYPE_MSK) {
249 case INDIRECT_HOST:
250 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
251 break;
252 case INDIRECT_GENERAL:
253 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
254 break;
255 case INDIRECT_REGULATORY:
256 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
257 break;
258 case INDIRECT_CALIBRATION:
259 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
260 break;
261 case INDIRECT_PROCESS_ADJST:
262 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
263 break;
264 case INDIRECT_OTHERS:
265 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
266 break;
267 default:
268 IWL_ERROR("illegal indirect type: 0x%X\n",
269 address & INDIRECT_TYPE_MSK);
270 break;
271 }
272
273 /* translate the offset from words to byte */
274 return (address & ADDRESS_MSK) + (offset << 1);
275}
276
Tomas Winklerf1f69412008-04-24 11:55:35 -0700277static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
278{
279 u16 eeprom_ver;
280 struct iwl_eeprom_calib_hdr {
281 u8 version;
282 u8 pa_type;
283 u16 voltage;
284 } *hdr;
285
286 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
287
288 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
289 EEPROM_5000_CALIB_ALL);
290
291 if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
292 hdr->version < EEPROM_5000_TX_POWER_VERSION)
293 goto err;
294
295 return 0;
296err:
297 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
298 eeprom_ver, EEPROM_5000_EEPROM_VERSION,
299 hdr->version, EEPROM_5000_TX_POWER_VERSION);
300 return -EINVAL;
301
302}
303
Emmanuel Grumbach33fd5032008-04-24 11:55:30 -0700304static void iwl5000_gain_computation(struct iwl_priv *priv,
305 u32 average_noise[NUM_RX_CHAINS],
306 u16 min_average_noise_antenna_i,
307 u32 min_average_noise)
308{
309 int i;
310 s32 delta_g;
311 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
312
313 /* Find Gain Code for the antennas B and C */
314 for (i = 1; i < NUM_RX_CHAINS; i++) {
315 if ((data->disconn_array[i])) {
316 data->delta_gain_code[i] = 0;
317 continue;
318 }
319 delta_g = (1000 * ((s32)average_noise[0] -
320 (s32)average_noise[i])) / 1500;
321 /* bound gain by 2 bits value max, 3rd bit is sign */
322 data->delta_gain_code[i] =
323 min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
324
325 if (delta_g < 0)
326 /* set negative sign */
327 data->delta_gain_code[i] |= (1 << 2);
328 }
329
330 IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
331 data->delta_gain_code[1], data->delta_gain_code[2]);
332
333 if (!data->radio_write) {
334 struct iwl5000_calibration_chain_noise_gain_cmd cmd;
335 memset(&cmd, 0, sizeof(cmd));
336
337 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
338 cmd.delta_gain_1 = data->delta_gain_code[1];
339 cmd.delta_gain_2 = data->delta_gain_code[2];
340 iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
341 sizeof(cmd), &cmd, NULL);
342
343 data->radio_write = 1;
344 data->state = IWL_CHAIN_NOISE_CALIBRATED;
345 }
346
347 data->chain_noise_a = 0;
348 data->chain_noise_b = 0;
349 data->chain_noise_c = 0;
350 data->chain_signal_a = 0;
351 data->chain_signal_b = 0;
352 data->chain_signal_c = 0;
353 data->beacon_count = 0;
354}
355
356static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
357{
358 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
359
360 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
361 struct iwl5000_calibration_chain_noise_reset_cmd cmd;
362
363 memset(&cmd, 0, sizeof(cmd));
364 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
365 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
366 sizeof(cmd), &cmd))
367 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
368 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
369 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
370 }
371}
372
373static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
374 .min_nrg_cck = 95,
375 .max_nrg_cck = 0,
376 .auto_corr_min_ofdm = 90,
377 .auto_corr_min_ofdm_mrc = 170,
378 .auto_corr_min_ofdm_x1 = 120,
379 .auto_corr_min_ofdm_mrc_x1 = 240,
380
381 .auto_corr_max_ofdm = 120,
382 .auto_corr_max_ofdm_mrc = 210,
383 .auto_corr_max_ofdm_x1 = 155,
384 .auto_corr_max_ofdm_mrc_x1 = 290,
385
386 .auto_corr_min_cck = 125,
387 .auto_corr_max_cck = 200,
388 .auto_corr_min_cck_mrc = 170,
389 .auto_corr_max_cck_mrc = 400,
390 .nrg_th_cck = 95,
391 .nrg_th_ofdm = 95,
392};
393
Tomas Winkler25ae3982008-04-24 11:55:27 -0700394static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
395 size_t offset)
396{
397 u32 address = eeprom_indirect_address(priv, offset);
398 BUG_ON(address >= priv->cfg->eeprom_size);
399 return &priv->eeprom[address];
400}
401
Ron Rindjunskydbb983b2008-05-15 13:54:12 +0800402/*
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800403 * Calibration
404 */
405static int iwl5000_send_Xtal_calib(struct iwl_priv *priv)
406{
407 u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
408
409 struct iwl5000_calibration cal_cmd = {
410 .op_code = IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD,
411 .data = {
412 (u8)xtal_calib[0],
413 (u8)xtal_calib[1],
414 }
415 };
416
417 return iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
418 sizeof(cal_cmd), &cal_cmd);
419}
420
421static int iwl5000_send_calib_results(struct iwl_priv *priv)
422{
423 int ret = 0;
424
Emmanuel Grumbachd2f18bf2008-05-29 16:35:27 +0800425 struct iwl_host_cmd hcmd = {
426 .id = REPLY_PHY_CALIBRATION_CMD,
427 .meta.flags = CMD_SIZE_HUGE,
428 };
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800429
Emmanuel Grumbachd2f18bf2008-05-29 16:35:27 +0800430 if (priv->calib_results.lo_res) {
431 hcmd.len = priv->calib_results.lo_res_len;
432 hcmd.data = priv->calib_results.lo_res;
433 ret = iwl_send_cmd_sync(priv, &hcmd);
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800434
Emmanuel Grumbachd2f18bf2008-05-29 16:35:27 +0800435 if (ret)
436 goto err;
437 }
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800438
Emmanuel Grumbachd2f18bf2008-05-29 16:35:27 +0800439 if (priv->calib_results.tx_iq_res) {
440 hcmd.len = priv->calib_results.tx_iq_res_len;
441 hcmd.data = priv->calib_results.tx_iq_res;
442 ret = iwl_send_cmd_sync(priv, &hcmd);
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800443
Emmanuel Grumbachd2f18bf2008-05-29 16:35:27 +0800444 if (ret)
445 goto err;
446 }
447
448 if (priv->calib_results.tx_iq_perd_res) {
449 hcmd.len = priv->calib_results.tx_iq_perd_res_len;
450 hcmd.data = priv->calib_results.tx_iq_perd_res;
451 ret = iwl_send_cmd_sync(priv, &hcmd);
452
453 if (ret)
454 goto err;
455 }
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800456
457 return 0;
458err:
459 IWL_ERROR("Error %d\n", ret);
460 return ret;
461}
462
463static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
464{
465 struct iwl5000_calib_cfg_cmd calib_cfg_cmd;
466 struct iwl_host_cmd cmd = {
467 .id = CALIBRATION_CFG_CMD,
468 .len = sizeof(struct iwl5000_calib_cfg_cmd),
469 .data = &calib_cfg_cmd,
470 };
471
472 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
473 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
474 calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
475 calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
476 calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
477
478 return iwl_send_cmd(priv, &cmd);
479}
480
481static void iwl5000_rx_calib_result(struct iwl_priv *priv,
482 struct iwl_rx_mem_buffer *rxb)
483{
484 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
485 struct iwl5000_calib_hdr *hdr = (struct iwl5000_calib_hdr *)pkt->u.raw;
486 int len = le32_to_cpu(pkt->len) & FH_RSCSR_FRAME_SIZE_MSK;
487
488 iwl_free_calib_results(priv);
489
490 /* reduce the size of the length field itself */
491 len -= 4;
492
493 switch (hdr->op_code) {
494 case IWL5000_PHY_CALIBRATE_LO_CMD:
495 priv->calib_results.lo_res = kzalloc(len, GFP_ATOMIC);
496 priv->calib_results.lo_res_len = len;
497 memcpy(priv->calib_results.lo_res, pkt->u.raw, len);
498 break;
499 case IWL5000_PHY_CALIBRATE_TX_IQ_CMD:
500 priv->calib_results.tx_iq_res = kzalloc(len, GFP_ATOMIC);
501 priv->calib_results.tx_iq_res_len = len;
502 memcpy(priv->calib_results.tx_iq_res, pkt->u.raw, len);
503 break;
504 case IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD:
505 priv->calib_results.tx_iq_perd_res = kzalloc(len, GFP_ATOMIC);
506 priv->calib_results.tx_iq_perd_res_len = len;
507 memcpy(priv->calib_results.tx_iq_perd_res, pkt->u.raw, len);
508 break;
509 default:
510 IWL_ERROR("Unknown calibration notification %d\n",
511 hdr->op_code);
512 return;
513 }
514}
515
516static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
517 struct iwl_rx_mem_buffer *rxb)
518{
519 IWL_DEBUG_INFO("Init. calibration is completed, restarting fw.\n");
520 queue_work(priv->workqueue, &priv->restart);
521}
522
523/*
Ron Rindjunskydbb983b2008-05-15 13:54:12 +0800524 * ucode
525 */
526static int iwl5000_load_section(struct iwl_priv *priv,
527 struct fw_desc *image,
528 u32 dst_addr)
529{
530 int ret = 0;
531 unsigned long flags;
532
533 dma_addr_t phy_addr = image->p_addr;
534 u32 byte_cnt = image->len;
535
536 spin_lock_irqsave(&priv->lock, flags);
537 ret = iwl_grab_nic_access(priv);
538 if (ret) {
539 spin_unlock_irqrestore(&priv->lock, flags);
540 return ret;
541 }
542
543 iwl_write_direct32(priv,
544 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
545 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
546
547 iwl_write_direct32(priv,
548 FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
549
550 iwl_write_direct32(priv,
551 FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
552 phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
553
554 /* FIME: write the MSB of the phy_addr in CTRL1
555 * iwl_write_direct32(priv,
556 IWL_FH_TFDIB_CTRL1_REG(IWL_FH_SRVC_CHNL),
557 ((phy_addr & MSB_MSK)
558 << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_count);
559 */
560 iwl_write_direct32(priv,
561 FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), byte_cnt);
562 iwl_write_direct32(priv,
563 FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
564 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
565 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
566 FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
567
568 iwl_write_direct32(priv,
569 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
570 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
571 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL |
572 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
573
574 iwl_release_nic_access(priv);
575 spin_unlock_irqrestore(&priv->lock, flags);
576 return 0;
577}
578
579static int iwl5000_load_given_ucode(struct iwl_priv *priv,
580 struct fw_desc *inst_image,
581 struct fw_desc *data_image)
582{
583 int ret = 0;
584
585 ret = iwl5000_load_section(
586 priv, inst_image, RTC_INST_LOWER_BOUND);
587 if (ret)
588 return ret;
589
590 IWL_DEBUG_INFO("INST uCode section being loaded...\n");
591 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
592 priv->ucode_write_complete, 5 * HZ);
593 if (ret == -ERESTARTSYS) {
594 IWL_ERROR("Could not load the INST uCode section due "
595 "to interrupt\n");
596 return ret;
597 }
598 if (!ret) {
599 IWL_ERROR("Could not load the INST uCode section\n");
600 return -ETIMEDOUT;
601 }
602
603 priv->ucode_write_complete = 0;
604
605 ret = iwl5000_load_section(
606 priv, data_image, RTC_DATA_LOWER_BOUND);
607 if (ret)
608 return ret;
609
610 IWL_DEBUG_INFO("DATA uCode section being loaded...\n");
611
612 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
613 priv->ucode_write_complete, 5 * HZ);
614 if (ret == -ERESTARTSYS) {
615 IWL_ERROR("Could not load the INST uCode section due "
616 "to interrupt\n");
617 return ret;
618 } else if (!ret) {
619 IWL_ERROR("Could not load the DATA uCode section\n");
620 return -ETIMEDOUT;
621 } else
622 ret = 0;
623
624 priv->ucode_write_complete = 0;
625
626 return ret;
627}
628
629static int iwl5000_load_ucode(struct iwl_priv *priv)
630{
631 int ret = 0;
632
633 /* check whether init ucode should be loaded, or rather runtime ucode */
634 if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
635 IWL_DEBUG_INFO("Init ucode found. Loading init ucode...\n");
636 ret = iwl5000_load_given_ucode(priv,
637 &priv->ucode_init, &priv->ucode_init_data);
638 if (!ret) {
639 IWL_DEBUG_INFO("Init ucode load complete.\n");
640 priv->ucode_type = UCODE_INIT;
641 }
642 } else {
643 IWL_DEBUG_INFO("Init ucode not found, or already loaded. "
644 "Loading runtime ucode...\n");
645 ret = iwl5000_load_given_ucode(priv,
646 &priv->ucode_code, &priv->ucode_data);
647 if (!ret) {
648 IWL_DEBUG_INFO("Runtime ucode load complete.\n");
649 priv->ucode_type = UCODE_RT;
650 }
651 }
652
653 return ret;
654}
655
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800656static void iwl5000_init_alive_start(struct iwl_priv *priv)
657{
658 int ret = 0;
659
660 /* Check alive response for "valid" sign from uCode */
661 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
662 /* We had an error bringing up the hardware, so take it
663 * all the way back down so we can try again */
664 IWL_DEBUG_INFO("Initialize Alive failed.\n");
665 goto restart;
666 }
667
668 /* initialize uCode was loaded... verify inst image.
669 * This is a paranoid check, because we would not have gotten the
670 * "initialize" alive if code weren't properly loaded. */
671 if (iwl_verify_ucode(priv)) {
672 /* Runtime instruction load was bad;
673 * take it all the way back down so we can try again */
674 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
675 goto restart;
676 }
677
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800678 iwl_clear_stations_table(priv);
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800679 ret = priv->cfg->ops->lib->alive_notify(priv);
680 if (ret) {
681 IWL_WARNING("Could not complete ALIVE transition: %d\n", ret);
682 goto restart;
683 }
684
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800685 iwl5000_send_calib_cfg(priv);
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800686 return;
687
688restart:
689 /* real restart (first load init_ucode) */
690 queue_work(priv->workqueue, &priv->restart);
691}
692
693static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
694 int txq_id, u32 index)
695{
696 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
697 (index & 0xff) | (txq_id << 8));
698 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
699}
700
701static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
702 struct iwl_tx_queue *txq,
703 int tx_fifo_id, int scd_retry)
704{
705 int txq_id = txq->q.id;
706 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
707
708 iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
709 (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
710 (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
711 (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
712 IWL50_SCD_QUEUE_STTS_REG_MSK);
713
714 txq->sched_retry = scd_retry;
715
716 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
717 active ? "Activate" : "Deactivate",
718 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
719}
720
Ron Rindjunsky9636e582008-05-15 13:54:14 +0800721static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
722{
723 struct iwl_wimax_coex_cmd coex_cmd;
724
725 memset(&coex_cmd, 0, sizeof(coex_cmd));
726
727 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
728 sizeof(coex_cmd), &coex_cmd);
729}
730
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800731static int iwl5000_alive_notify(struct iwl_priv *priv)
732{
733 u32 a;
734 int i = 0;
735 unsigned long flags;
736 int ret;
737
738 spin_lock_irqsave(&priv->lock, flags);
739
740 ret = iwl_grab_nic_access(priv);
741 if (ret) {
742 spin_unlock_irqrestore(&priv->lock, flags);
743 return ret;
744 }
745
746 priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
747 a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
748 for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
749 a += 4)
750 iwl_write_targ_mem(priv, a, 0);
751 for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
752 a += 4)
753 iwl_write_targ_mem(priv, a, 0);
754 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
755 iwl_write_targ_mem(priv, a, 0);
756
757 iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
758 (priv->shared_phys +
759 offsetof(struct iwl5000_shared, queues_byte_cnt_tbls)) >> 10);
760 iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
761 IWL50_SCD_QUEUECHAIN_SEL_ALL(
762 priv->hw_params.max_txq_num));
763 iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
764
765 /* initiate the queues */
766 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
767 iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
768 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
769 iwl_write_targ_mem(priv, priv->scd_base_addr +
770 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
771 iwl_write_targ_mem(priv, priv->scd_base_addr +
772 IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
773 sizeof(u32),
774 ((SCD_WIN_SIZE <<
775 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
776 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
777 ((SCD_FRAME_LIMIT <<
778 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
779 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
780 }
781
782 iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
Tomas Winklerda1bc452008-05-29 16:35:00 +0800783 IWL_MASK(0, priv->hw_params.max_txq_num));
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800784
Tomas Winklerda1bc452008-05-29 16:35:00 +0800785 /* Activate all Tx DMA/FIFO channels */
786 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800787
788 iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
789 /* map qos queues to fifos one-to-one */
790 for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
791 int ac = iwl5000_default_queue_to_tx_fifo[i];
792 iwl_txq_ctx_activate(priv, i);
793 iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
794 }
795 /* TODO - need to initialize those FIFOs inside the loop above,
796 * not only mark them as active */
797 iwl_txq_ctx_activate(priv, 4);
798 iwl_txq_ctx_activate(priv, 7);
799 iwl_txq_ctx_activate(priv, 8);
800 iwl_txq_ctx_activate(priv, 9);
801
802 iwl_release_nic_access(priv);
803 spin_unlock_irqrestore(&priv->lock, flags);
804
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800805
Ron Rindjunsky9636e582008-05-15 13:54:14 +0800806 iwl5000_send_wimax_coex(priv);
807
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800808 iwl5000_send_Xtal_calib(priv);
809
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +0800810 if (priv->ucode_type == UCODE_RT) {
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800811 iwl5000_send_calib_results(priv);
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +0800812 set_bit(STATUS_READY, &priv->status);
813 priv->is_open = 1;
814 }
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800815
Ron Rindjunsky99da1b42008-05-15 13:54:13 +0800816 return 0;
817}
818
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700819static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
820{
821 if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
822 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
823 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
824 IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
825 return -EINVAL;
826 }
Tomas Winkler25ae3982008-04-24 11:55:27 -0700827
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700828 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
Ron Rindjunsky7f3e4bb2008-06-12 09:46:55 +0800829 priv->hw_params.first_ampdu_q = IWL50_FIRST_AMPDU_QUEUE;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700830 priv->hw_params.max_stations = IWL5000_STATION_COUNT;
831 priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
832 priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
833 priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
Ron Rindjunskyda154e302008-06-30 17:23:20 +0800834 priv->hw_params.max_bsm_size = 0;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700835 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
836 BIT(IEEE80211_BAND_5GHZ);
Emmanuel Grumbach33fd5032008-04-24 11:55:30 -0700837 priv->hw_params.sens = &iwl5000_sensitivity;
Tomas Winkler25ae3982008-04-24 11:55:27 -0700838
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700839 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
840 case CSR_HW_REV_TYPE_5100:
841 case CSR_HW_REV_TYPE_5150:
842 priv->hw_params.tx_chains_num = 1;
843 priv->hw_params.rx_chains_num = 2;
844 /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
Tomas Winkler1179f182008-04-24 11:55:31 -0700845 priv->hw_params.valid_tx_ant = ANT_A;
846 priv->hw_params.valid_rx_ant = ANT_AB;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700847 break;
848 case CSR_HW_REV_TYPE_5300:
849 case CSR_HW_REV_TYPE_5350:
850 priv->hw_params.tx_chains_num = 3;
851 priv->hw_params.rx_chains_num = 3;
Tomas Winkler1179f182008-04-24 11:55:31 -0700852 priv->hw_params.valid_tx_ant = ANT_ABC;
853 priv->hw_params.valid_rx_ant = ANT_ABC;
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700854 break;
855 }
Emmanuel Grumbachc031bf82008-04-24 11:55:29 -0700856
857 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
858 case CSR_HW_REV_TYPE_5100:
859 case CSR_HW_REV_TYPE_5300:
860 /* 5X00 wants in Celsius */
861 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
862 break;
863 case CSR_HW_REV_TYPE_5150:
864 case CSR_HW_REV_TYPE_5350:
865 /* 5X50 wants in Kelvin */
866 priv->hw_params.ct_kill_threshold =
867 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
868 break;
869 }
870
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -0700871 return 0;
872}
Ron Rindjunskyd4100dd2008-04-24 11:55:33 -0700873
874static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
875{
876 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
877 sizeof(struct iwl5000_shared),
878 &priv->shared_phys);
879 if (!priv->shared_virt)
880 return -ENOMEM;
881
882 memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
883
Ron Rindjunskyd67f5482008-05-05 10:22:49 +0800884 priv->rb_closed_offset = offsetof(struct iwl5000_shared, rb_closed);
885
Ron Rindjunskyd4100dd2008-04-24 11:55:33 -0700886 return 0;
887}
888
889static void iwl5000_free_shared_mem(struct iwl_priv *priv)
890{
891 if (priv->shared_virt)
892 pci_free_consistent(priv->pci_dev,
893 sizeof(struct iwl5000_shared),
894 priv->shared_virt,
895 priv->shared_phys);
896}
897
Ron Rindjunskyd67f5482008-05-05 10:22:49 +0800898static int iwl5000_shared_mem_rx_idx(struct iwl_priv *priv)
899{
900 struct iwl5000_shared *s = priv->shared_virt;
901 return le32_to_cpu(s->rb_closed) & 0xFFF;
902}
903
Emmanuel Grumbach7839fc02008-04-24 11:55:34 -0700904/**
905 * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
906 */
907static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
Ron Rindjunsky16466902008-05-05 10:22:50 +0800908 struct iwl_tx_queue *txq,
Emmanuel Grumbach7839fc02008-04-24 11:55:34 -0700909 u16 byte_cnt)
910{
911 struct iwl5000_shared *shared_data = priv->shared_virt;
912 int txq_id = txq->q.id;
913 u8 sec_ctl = 0;
914 u8 sta = 0;
915 int len;
916
917 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
918
919 if (txq_id != IWL_CMD_QUEUE_NUM) {
920 sta = txq->cmd[txq->q.write_ptr].cmd.tx.sta_id;
921 sec_ctl = txq->cmd[txq->q.write_ptr].cmd.tx.sec_ctl;
922
923 switch (sec_ctl & TX_CMD_SEC_MSK) {
924 case TX_CMD_SEC_CCM:
925 len += CCMP_MIC_LEN;
926 break;
927 case TX_CMD_SEC_TKIP:
928 len += TKIP_ICV_LEN;
929 break;
930 case TX_CMD_SEC_WEP:
931 len += WEP_IV_LEN + WEP_ICV_LEN;
932 break;
933 }
934 }
935
936 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
937 tfd_offset[txq->q.write_ptr], byte_cnt, len);
938
939 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
940 tfd_offset[txq->q.write_ptr], sta_id, sta);
941
942 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
943 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
944 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
945 byte_cnt, len);
946 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
947 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
948 sta_id, sta);
949 }
950}
951
Tomas Winkler972cf442008-05-29 16:35:13 +0800952static void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
953 struct iwl_tx_queue *txq)
954{
955 int txq_id = txq->q.id;
956 struct iwl5000_shared *shared_data = priv->shared_virt;
957 u8 sta = 0;
958
959 if (txq_id != IWL_CMD_QUEUE_NUM)
960 sta = txq->cmd[txq->q.read_ptr].cmd.tx.sta_id;
961
962 shared_data->queues_byte_cnt_tbls[txq_id].tfd_offset[txq->q.read_ptr].
963 val = cpu_to_le16(1 | (sta << 12));
964
965 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
966 shared_data->queues_byte_cnt_tbls[txq_id].
967 tfd_offset[IWL50_QUEUE_SIZE + txq->q.read_ptr].
968 val = cpu_to_le16(1 | (sta << 12));
969 }
970}
971
Tomas Winklere26e47d2008-06-12 09:46:56 +0800972static int iwl5000_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
973 u16 txq_id)
974{
975 u32 tbl_dw_addr;
976 u32 tbl_dw;
977 u16 scd_q2ratid;
978
979 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
980
981 tbl_dw_addr = priv->scd_base_addr +
982 IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
983
984 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
985
986 if (txq_id & 0x1)
987 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
988 else
989 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
990
991 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
992
993 return 0;
994}
995static void iwl5000_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id)
996{
997 /* Simply stop the queue, but don't change any configuration;
998 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
999 iwl_write_prph(priv,
1000 IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
1001 (0 << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
1002 (1 << IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
1003}
1004
1005static int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
1006 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
1007{
1008 unsigned long flags;
1009 int ret;
1010 u16 ra_tid;
1011
1012 if (IWL50_FIRST_AMPDU_QUEUE > txq_id)
1013 IWL_WARNING("queue number too small: %d, must be > %d\n",
1014 txq_id, IWL50_FIRST_AMPDU_QUEUE);
1015
1016 ra_tid = BUILD_RAxTID(sta_id, tid);
1017
1018 /* Modify device's station table to Tx this TID */
1019 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
1020
1021 spin_lock_irqsave(&priv->lock, flags);
1022 ret = iwl_grab_nic_access(priv);
1023 if (ret) {
1024 spin_unlock_irqrestore(&priv->lock, flags);
1025 return ret;
1026 }
1027
1028 /* Stop this Tx queue before configuring it */
1029 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
1030
1031 /* Map receiver-address / traffic-ID to this queue */
1032 iwl5000_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
1033
1034 /* Set this queue as a chain-building queue */
1035 iwl_set_bits_prph(priv, IWL50_SCD_QUEUECHAIN_SEL, (1<<txq_id));
1036
1037 /* enable aggregations for the queue */
1038 iwl_set_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1<<txq_id));
1039
1040 /* Place first TFD at index corresponding to start sequence number.
1041 * Assumes that ssn_idx is valid (!= 0xFFF) */
1042 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
1043 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
1044 iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
1045
1046 /* Set up Tx window size and frame limit for this queue */
1047 iwl_write_targ_mem(priv, priv->scd_base_addr +
1048 IWL50_SCD_CONTEXT_QUEUE_OFFSET(txq_id) +
1049 sizeof(u32),
1050 ((SCD_WIN_SIZE <<
1051 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
1052 IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
1053 ((SCD_FRAME_LIMIT <<
1054 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
1055 IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
1056
1057 iwl_set_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
1058
1059 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
1060 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
1061
1062 iwl_release_nic_access(priv);
1063 spin_unlock_irqrestore(&priv->lock, flags);
1064
1065 return 0;
1066}
1067
1068static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1069 u16 ssn_idx, u8 tx_fifo)
1070{
1071 int ret;
1072
1073 if (IWL50_FIRST_AMPDU_QUEUE > txq_id) {
1074 IWL_WARNING("queue number too small: %d, must be > %d\n",
1075 txq_id, IWL50_FIRST_AMPDU_QUEUE);
1076 return -EINVAL;
1077 }
1078
1079 ret = iwl_grab_nic_access(priv);
1080 if (ret)
1081 return ret;
1082
1083 iwl5000_tx_queue_stop_scheduler(priv, txq_id);
1084
1085 iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id));
1086
1087 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
1088 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
1089 /* supposes that ssn_idx is valid (!= 0xFFF) */
1090 iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
1091
1092 iwl_clear_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
1093 iwl_txq_ctx_deactivate(priv, txq_id);
1094 iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
1095
1096 iwl_release_nic_access(priv);
1097
1098 return 0;
1099}
1100
Tomas Winkler2469bf22008-05-05 10:22:35 +08001101static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
1102{
1103 u16 size = (u16)sizeof(struct iwl_addsta_cmd);
1104 memcpy(data, cmd, size);
1105 return size;
1106}
1107
1108
Tomas Winklerda1bc452008-05-29 16:35:00 +08001109/*
1110 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
1111 * must be called under priv->lock and mac access
1112 */
1113static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +08001114{
Tomas Winklerda1bc452008-05-29 16:35:00 +08001115 iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
Ron Rindjunsky5a676bb2008-05-05 10:22:42 +08001116}
1117
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001118
1119static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
1120{
Tomas Winkler25a65722008-06-12 09:47:07 +08001121 return le32_to_cpup((__le32*)&tx_resp->status +
1122 tx_resp->frame_count) & MAX_SN;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001123}
1124
1125static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
1126 struct iwl_ht_agg *agg,
1127 struct iwl5000_tx_resp *tx_resp,
Tomas Winkler25a65722008-06-12 09:47:07 +08001128 int txq_id, u16 start_idx)
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001129{
1130 u16 status;
1131 struct agg_tx_status *frame_status = &tx_resp->status;
1132 struct ieee80211_tx_info *info = NULL;
1133 struct ieee80211_hdr *hdr = NULL;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001134 u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Tomas Winkler25a65722008-06-12 09:47:07 +08001135 int i, sh, idx;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001136 u16 seq;
1137
1138 if (agg->wait_for_ba)
1139 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
1140
1141 agg->frame_count = tx_resp->frame_count;
1142 agg->start_idx = start_idx;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001143 agg->rate_n_flags = rate_n_flags;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001144 agg->bitmap = 0;
1145
1146 /* # frames attempted by Tx command */
1147 if (agg->frame_count == 1) {
1148 /* Only one frame was attempted; no block-ack will arrive */
1149 status = le16_to_cpu(frame_status[0].status);
Tomas Winkler25a65722008-06-12 09:47:07 +08001150 idx = start_idx;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001151
1152 /* FIXME: code repetition */
1153 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
1154 agg->frame_count, agg->start_idx, idx);
1155
1156 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
1157 info->status.retry_count = tx_resp->failure_frame;
1158 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1159 info->flags |= iwl_is_tx_success(status)?
1160 IEEE80211_TX_STAT_ACK : 0;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001161 iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
1162
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001163 /* FIXME: code repetition end */
1164
1165 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
1166 status & 0xff, tx_resp->failure_frame);
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001167 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001168
1169 agg->wait_for_ba = 0;
1170 } else {
1171 /* Two or more frames were attempted; expect block-ack */
1172 u64 bitmap = 0;
1173 int start = agg->start_idx;
1174
1175 /* Construct bit-map of pending frames within Tx window */
1176 for (i = 0; i < agg->frame_count; i++) {
1177 u16 sc;
1178 status = le16_to_cpu(frame_status[i].status);
1179 seq = le16_to_cpu(frame_status[i].sequence);
1180 idx = SEQ_TO_INDEX(seq);
1181 txq_id = SEQ_TO_QUEUE(seq);
1182
1183 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
1184 AGG_TX_STATE_ABORT_MSK))
1185 continue;
1186
1187 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
1188 agg->frame_count, txq_id, idx);
1189
1190 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
1191
1192 sc = le16_to_cpu(hdr->seq_ctrl);
1193 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
1194 IWL_ERROR("BUG_ON idx doesn't match seq control"
1195 " idx=%d, seq_idx=%d, seq=%d\n",
1196 idx, SEQ_TO_SN(sc),
1197 hdr->seq_ctrl);
1198 return -1;
1199 }
1200
1201 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
1202 i, idx, SEQ_TO_SN(sc));
1203
1204 sh = idx - start;
1205 if (sh > 64) {
1206 sh = (start - idx) + 0xff;
1207 bitmap = bitmap << sh;
1208 sh = 0;
1209 start = idx;
1210 } else if (sh < -64)
1211 sh = 0xff - (start - idx);
1212 else if (sh < 0) {
1213 sh = start - idx;
1214 start = idx;
1215 bitmap = bitmap << sh;
1216 sh = 0;
1217 }
1218 bitmap |= (1 << sh);
1219 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
1220 start, (u32)(bitmap & 0xFFFFFFFF));
1221 }
1222
1223 agg->bitmap = bitmap;
1224 agg->start_idx = start;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001225 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
1226 agg->frame_count, agg->start_idx,
1227 (unsigned long long)agg->bitmap);
1228
1229 if (bitmap)
1230 agg->wait_for_ba = 1;
1231 }
1232 return 0;
1233}
1234
1235static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
1236 struct iwl_rx_mem_buffer *rxb)
1237{
1238 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1239 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1240 int txq_id = SEQ_TO_QUEUE(sequence);
1241 int index = SEQ_TO_INDEX(sequence);
1242 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1243 struct ieee80211_tx_info *info;
1244 struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
1245 u32 status = le16_to_cpu(tx_resp->status.status);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001246 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001247 struct ieee80211_hdr *hdr;
1248 u8 *qc = NULL;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001249
1250 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
1251 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
1252 "is out of range [0-%d] %d %d\n", txq_id,
1253 index, txq->q.n_bd, txq->q.write_ptr,
1254 txq->q.read_ptr);
1255 return;
1256 }
1257
1258 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
1259 memset(&info->status, 0, sizeof(info->status));
1260
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001261 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001262 if (ieee80211_is_data_qos(hdr->frame_control)) {
1263 qc = ieee80211_get_qos_ctl(hdr);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001264 tid = qc[0] & 0xf;
1265 }
1266
1267 sta_id = iwl_get_ra_sta_id(priv, hdr);
1268 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
1269 IWL_ERROR("Station not known\n");
1270 return;
1271 }
1272
1273 if (txq->sched_retry) {
1274 const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
1275 struct iwl_ht_agg *agg = NULL;
1276
1277 if (!qc)
1278 return;
1279
1280 agg = &priv->stations[sta_id].tid[tid].agg;
1281
Tomas Winkler25a65722008-06-12 09:47:07 +08001282 iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001283
1284 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
1285 /* TODO: send BAR */
1286 }
1287
1288 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
1289 int freed, ampdu_q;
1290 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
1291 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
1292 "%d index %d\n", scd_ssn , index);
Tomas Winkler17b88922008-05-29 16:35:12 +08001293 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001294 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1295
1296 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1297 txq_id >= 0 && priv->mac80211_registered &&
1298 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
1299 /* calculate mac80211 ampdu sw queue to wake */
Ron Rindjunsky7f3e4bb2008-06-12 09:46:55 +08001300 ampdu_q = txq_id - IWL50_FIRST_AMPDU_QUEUE +
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001301 priv->hw->queues;
1302 if (agg->state == IWL_AGG_OFF)
1303 ieee80211_wake_queue(priv->hw, txq_id);
1304 else
1305 ieee80211_wake_queue(priv->hw, ampdu_q);
1306 }
Tomas Winkler30e553e2008-05-29 16:35:16 +08001307 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001308 }
1309 } else {
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001310 info->status.retry_count = tx_resp->failure_frame;
1311 info->flags =
1312 iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001313 iwl_hwrate_to_tx_control(priv,
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001314 le32_to_cpu(tx_resp->rate_n_flags),
1315 info);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001316
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001317 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
1318 "0x%x retries %d\n", txq_id,
1319 iwl_get_tx_fail_reason(status),
1320 status, le32_to_cpu(tx_resp->rate_n_flags),
1321 tx_resp->failure_frame);
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001322
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001323 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
1324 if (index != -1) {
1325 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
1326 if (tid != MAX_TID_COUNT)
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001327 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001328 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001329 (txq_id >= 0) && priv->mac80211_registered)
1330 ieee80211_wake_queue(priv->hw, txq_id);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001331 if (tid != MAX_TID_COUNT)
Tomas Winkler30e553e2008-05-29 16:35:16 +08001332 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03001333 }
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001334 }
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001335
1336 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
1337 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
1338}
1339
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001340/* Currently 5000 is the supperset of everything */
1341static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
1342{
1343 return len;
1344}
1345
Emmanuel Grumbach203566f2008-06-12 09:46:54 +08001346static void iwl5000_setup_deferred_work(struct iwl_priv *priv)
1347{
1348 /* in 5000 the tx power calibration is done in uCode */
1349 priv->disable_tx_power_cal = 1;
1350}
1351
Ron Rindjunskyb600e4e2008-05-15 13:54:11 +08001352static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
1353{
Tomas Winkler7c616cb2008-05-29 16:35:05 +08001354 /* init calibration handlers */
1355 priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
1356 iwl5000_rx_calib_result;
1357 priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
1358 iwl5000_rx_calib_complete;
Ron Rindjunskye532fa02008-05-29 16:35:09 +08001359 priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
Ron Rindjunskyb600e4e2008-05-15 13:54:11 +08001360}
1361
Tomas Winkler7c616cb2008-05-29 16:35:05 +08001362
Ron Rindjunsky87283cc2008-05-29 16:34:47 +08001363static int iwl5000_hw_valid_rtc_data_addr(u32 addr)
1364{
1365 return (addr >= RTC_DATA_LOWER_BOUND) &&
1366 (addr < IWL50_RTC_DATA_UPPER_BOUND);
1367}
1368
Ron Rindjunskyfe7a90c2008-05-29 16:35:14 +08001369static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
1370{
1371 int ret = 0;
1372 struct iwl5000_rxon_assoc_cmd rxon_assoc;
1373 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1374 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1375
1376 if ((rxon1->flags == rxon2->flags) &&
1377 (rxon1->filter_flags == rxon2->filter_flags) &&
1378 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1379 (rxon1->ofdm_ht_single_stream_basic_rates ==
1380 rxon2->ofdm_ht_single_stream_basic_rates) &&
1381 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1382 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1383 (rxon1->ofdm_ht_triple_stream_basic_rates ==
1384 rxon2->ofdm_ht_triple_stream_basic_rates) &&
1385 (rxon1->acquisition_data == rxon2->acquisition_data) &&
1386 (rxon1->rx_chain == rxon2->rx_chain) &&
1387 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1388 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1389 return 0;
1390 }
1391
1392 rxon_assoc.flags = priv->staging_rxon.flags;
1393 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1394 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1395 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1396 rxon_assoc.reserved1 = 0;
1397 rxon_assoc.reserved2 = 0;
1398 rxon_assoc.reserved3 = 0;
1399 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1400 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1401 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1402 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1403 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1404 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
1405 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
1406 rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
1407
1408 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1409 sizeof(rxon_assoc), &rxon_assoc, NULL);
1410 if (ret)
1411 return ret;
1412
1413 return ret;
1414}
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001415static int iwl5000_send_tx_power(struct iwl_priv *priv)
1416{
1417 struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
1418
1419 /* half dBm need to multiply */
1420 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
Gregory Greenman853554a2008-06-30 17:23:01 +08001421 tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001422 tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
1423 return iwl_send_cmd_pdu_async(priv, REPLY_TX_POWER_DBM_CMD,
1424 sizeof(tx_power_cmd), &tx_power_cmd,
1425 NULL);
1426}
1427
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001428static void iwl5000_temperature(struct iwl_priv *priv,
1429 struct iwl_notif_statistics *stats)
1430{
1431 /* store temperature from statistics (in Celsius) */
1432 priv->temperature = le32_to_cpu(stats->general.temperature);
1433}
Ron Rindjunskyfe7a90c2008-05-29 16:35:14 +08001434
Tomas Winklerda8dec22008-04-24 11:55:24 -07001435static struct iwl_hcmd_ops iwl5000_hcmd = {
Ron Rindjunskyfe7a90c2008-05-29 16:35:14 +08001436 .rxon_assoc = iwl5000_send_rxon_assoc,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001437};
1438
1439static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001440 .get_hcmd_size = iwl5000_get_hcmd_size,
Tomas Winkler2469bf22008-05-05 10:22:35 +08001441 .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
Emmanuel Grumbach33fd5032008-04-24 11:55:30 -07001442 .gain_computation = iwl5000_gain_computation,
1443 .chain_noise_reset = iwl5000_chain_noise_reset,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001444};
1445
1446static struct iwl_lib_ops iwl5000_lib = {
Tomas Winklerfdd3e8a2008-04-24 11:55:28 -07001447 .set_hw_params = iwl5000_hw_set_hw_params,
Ron Rindjunskyd4100dd2008-04-24 11:55:33 -07001448 .alloc_shared_mem = iwl5000_alloc_shared_mem,
1449 .free_shared_mem = iwl5000_free_shared_mem,
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001450 .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
Emmanuel Grumbach7839fc02008-04-24 11:55:34 -07001451 .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
Tomas Winkler972cf442008-05-29 16:35:13 +08001452 .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
Tomas Winklerda1bc452008-05-29 16:35:00 +08001453 .txq_set_sched = iwl5000_txq_set_sched,
Tomas Winklere26e47d2008-06-12 09:46:56 +08001454 .txq_agg_enable = iwl5000_txq_agg_enable,
1455 .txq_agg_disable = iwl5000_txq_agg_disable,
Ron Rindjunskyb600e4e2008-05-15 13:54:11 +08001456 .rx_handler_setup = iwl5000_rx_handler_setup,
Emmanuel Grumbach203566f2008-06-12 09:46:54 +08001457 .setup_deferred_work = iwl5000_setup_deferred_work,
Ron Rindjunsky87283cc2008-05-29 16:34:47 +08001458 .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001459 .load_ucode = iwl5000_load_ucode,
Ron Rindjunsky99da1b42008-05-15 13:54:13 +08001460 .init_alive_start = iwl5000_init_alive_start,
1461 .alive_notify = iwl5000_alive_notify,
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001462 .send_tx_power = iwl5000_send_tx_power,
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001463 .temperature = iwl5000_temperature,
Tomas Winkler30d59262008-04-24 11:55:25 -07001464 .apm_ops = {
1465 .init = iwl5000_apm_init,
Tomas Winkler7f066102008-05-29 16:34:57 +08001466 .reset = iwl5000_apm_reset,
Tomas Winklerf118a912008-05-29 16:34:58 +08001467 .stop = iwl5000_apm_stop,
Ron Rindjunsky5a835352008-05-05 10:22:29 +08001468 .config = iwl5000_nic_config,
Tomas Winkler88acbd32008-04-24 11:55:26 -07001469 .set_pwr_src = iwl4965_set_pwr_src,
Tomas Winkler30d59262008-04-24 11:55:25 -07001470 },
Tomas Winklerda8dec22008-04-24 11:55:24 -07001471 .eeprom_ops = {
Tomas Winkler25ae3982008-04-24 11:55:27 -07001472 .regulatory_bands = {
1473 EEPROM_5000_REG_BAND_1_CHANNELS,
1474 EEPROM_5000_REG_BAND_2_CHANNELS,
1475 EEPROM_5000_REG_BAND_3_CHANNELS,
1476 EEPROM_5000_REG_BAND_4_CHANNELS,
1477 EEPROM_5000_REG_BAND_5_CHANNELS,
1478 EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
1479 EEPROM_5000_REG_BAND_52_FAT_CHANNELS
1480 },
Tomas Winklerda8dec22008-04-24 11:55:24 -07001481 .verify_signature = iwlcore_eeprom_verify_signature,
1482 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
1483 .release_semaphore = iwlcore_eeprom_release_semaphore,
Tomas Winklerf1f69412008-04-24 11:55:35 -07001484 .check_version = iwl5000_eeprom_check_version,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001485 .query_addr = iwl5000_eeprom_query_addr,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001486 },
1487};
1488
1489static struct iwl_ops iwl5000_ops = {
1490 .lib = &iwl5000_lib,
1491 .hcmd = &iwl5000_hcmd,
1492 .utils = &iwl5000_hcmd_utils,
1493};
1494
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001495static struct iwl_mod_params iwl50_mod_params = {
1496 .num_of_queues = IWL50_NUM_QUEUES,
1497 .enable_qos = 1,
1498 .amsdu_size_8K = 1,
Ester Kummer3a1081e2008-05-06 11:05:14 +08001499 .restart_fw = 1,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001500 /* the rest are 0 by default */
1501};
1502
1503
1504struct iwl_cfg iwl5300_agn_cfg = {
1505 .name = "5300AGN",
1506 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1507 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001508 .ops = &iwl5000_ops,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001509 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001510 .mod_params = &iwl50_mod_params,
1511};
1512
1513struct iwl_cfg iwl5100_agn_cfg = {
1514 .name = "5100AGN",
1515 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1516 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001517 .ops = &iwl5000_ops,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001518 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001519 .mod_params = &iwl50_mod_params,
1520};
1521
1522struct iwl_cfg iwl5350_agn_cfg = {
1523 .name = "5350AGN",
1524 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
1525 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
Tomas Winklerda8dec22008-04-24 11:55:24 -07001526 .ops = &iwl5000_ops,
Tomas Winkler25ae3982008-04-24 11:55:27 -07001527 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
Tomas Winkler5a6a2562008-04-24 11:55:23 -07001528 .mod_params = &iwl50_mod_params,
1529};
1530
1531module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
1532MODULE_PARM_DESC(disable50,
1533 "manually disable the 50XX radio (default 0 [radio on])");
1534module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
1535MODULE_PARM_DESC(swcrypto50,
1536 "using software crypto engine (default 0 [hardware])\n");
1537module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
1538MODULE_PARM_DESC(debug50, "50XX debug output mask");
1539module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
1540MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
1541module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
1542MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
1543module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
1544MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
Ester Kummer3a1081e2008-05-06 11:05:14 +08001545module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
1546MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");