iwlwifi: generic init calibrations framework
[pandora-kernel.git] / drivers / net / wireless / iwlwifi / iwl-5000.c
1 /******************************************************************************
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/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"
40 #include "iwl-dev.h"
41 #include "iwl-core.h"
42 #include "iwl-io.h"
43 #include "iwl-sta.h"
44 #include "iwl-helpers.h"
45 #include "iwl-5000-hw.h"
46
47 #define IWL5000_UCODE_API  "-1"
48
49 static 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
59 /* FIXME: same implementation as 4965 */
60 static 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
76 out:
77         spin_unlock_irqrestore(&priv->lock, flags);
78         IWL_DEBUG_INFO("stop master\n");
79
80         return ret;
81 }
82
83
84 static 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
91         /* 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
95         /* 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
102         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 */
122         iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
123
124         udelay(20);
125
126         /* disable L1-Active */
127         iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
128                           APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
129
130         iwl_release_nic_access(priv);
131
132         return ret;
133 }
134
135 /* FIXME: this is indentical to 4965 */
136 static void iwl5000_apm_stop(struct iwl_priv *priv)
137 {
138         unsigned long flags;
139
140         iwl5000_apm_stop_master(priv);
141
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
154 static int iwl5000_apm_reset(struct iwl_priv *priv)
155 {
156         int ret = 0;
157         unsigned long flags;
158
159         iwl5000_apm_stop_master(priv);
160
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
200 out:
201         spin_unlock_irqrestore(&priv->lock, flags);
202
203         return ret;
204 }
205
206
207 static void iwl5000_nic_config(struct iwl_priv *priv)
208 {
209         unsigned long flags;
210         u16 radio_cfg;
211         u8 val_link;
212
213         spin_lock_irqsave(&priv->lock, flags);
214
215         pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
216
217         /* L1 is enabled by BIOS */
218         if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
219                 /* 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);
224
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
239         /* 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          */
243         iwl_grab_nic_access(priv);
244         iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
245                                 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
246                                 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
247         iwl_release_nic_access(priv);
248
249         spin_unlock_irqrestore(&priv->lock, flags);
250 }
251
252
253
254 /*
255  * EEPROM
256  */
257 static 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
293 static 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;
312 err:
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
320 static 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
372 static 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
389 static 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
399 static 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
420 static 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
428 /*
429  *  Calibration
430  */
431 static 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
447 static 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
465 static 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;
471         int index;
472
473         /* reduce the size of the length field itself */
474         len -= 4;
475
476         /* 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 */
479         switch (hdr->op_code) {
480         case IWL5000_PHY_CALIBRATE_LO_CMD:
481                 index = IWL5000_CALIB_LO;
482                 break;
483         case IWL5000_PHY_CALIBRATE_TX_IQ_CMD:
484                 index = IWL5000_CALIB_TX_IQ;
485                 break;
486         case IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD:
487                 index = IWL5000_CALIB_TX_IQ_PERD;
488                 break;
489         default:
490                 IWL_ERROR("Unknown calibration notification %d\n",
491                           hdr->op_code);
492                 return;
493         }
494         iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
495 }
496
497 static 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 /*
505  * ucode
506  */
507 static 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
560 static 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
610 static 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
637 static 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
659         iwl_clear_stations_table(priv);
660         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
666         iwl5000_send_calib_cfg(priv);
667         return;
668
669 restart:
670         /* real restart (first load init_ucode) */
671         queue_work(priv->workqueue, &priv->restart);
672 }
673
674 static 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
682 static 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
702 static 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
712 static 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,
764                         IWL_MASK(0, priv->hw_params.max_txq_num));
765
766         /* Activate all Tx DMA/FIFO channels */
767         priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
768
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
786
787         iwl5000_send_wimax_coex(priv);
788
789         iwl5000_send_Xtal_calib(priv);
790
791         if (priv->ucode_type == UCODE_RT)
792                 iwl_send_calib_results(priv);
793
794         return 0;
795 }
796
797 static 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         }
805
806         priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
807         priv->hw_params.first_ampdu_q = IWL50_FIRST_AMPDU_QUEUE;
808         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;
812         priv->hw_params.max_bsm_size = 0;
813         priv->hw_params.fat_channel =  BIT(IEEE80211_BAND_2GHZ) |
814                                         BIT(IEEE80211_BAND_5GHZ);
815         priv->hw_params.sens = &iwl5000_sensitivity;
816
817         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 */
823                 priv->hw_params.valid_tx_ant = ANT_A;
824                 priv->hw_params.valid_rx_ant = ANT_AB;
825                 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;
830                 priv->hw_params.valid_tx_ant = ANT_ABC;
831                 priv->hw_params.valid_rx_ant = ANT_ABC;
832                 break;
833         }
834
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
849         return 0;
850 }
851
852 static 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
862         priv->rb_closed_offset = offsetof(struct iwl5000_shared, rb_closed);
863
864         return 0;
865 }
866
867 static 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
876 static 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
882 /**
883  * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
884  */
885 static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
886                                             struct iwl_tx_queue *txq,
887                                             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) {
898                 sta = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id;
899                 sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl;
900
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
930 static 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)
938                 sta = txq->cmd[txq->q.read_ptr]->cmd.tx.sta_id;
939
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
950 static 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 }
973 static 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
983 static 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
990         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         }
997
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
1050 static int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
1051                                    u16 ssn_idx, u8 tx_fifo)
1052 {
1053         int ret;
1054
1055         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);
1060                 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
1085 static 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
1093 /*
1094  * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
1095  * must be called under priv->lock and mac access
1096  */
1097 static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
1098 {
1099         iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
1100 }
1101
1102
1103 static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
1104 {
1105         return le32_to_cpup((__le32 *)&tx_resp->status +
1106                             tx_resp->frame_count) & MAX_SN;
1107 }
1108
1109 static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
1110                                       struct iwl_ht_agg *agg,
1111                                       struct iwl5000_tx_resp *tx_resp,
1112                                       int txq_id, u16 start_idx)
1113 {
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;
1118         u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
1119         int i, sh, idx;
1120         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;
1127         agg->rate_n_flags = rate_n_flags;
1128         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);
1134                 idx = start_idx;
1135
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;
1145                 iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
1146
1147                 /* FIXME: code repetition end */
1148
1149                 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
1150                                     status & 0xff, tx_resp->failure_frame);
1151                 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
1152
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                         }
1202                         bitmap |= 1ULL << sh;
1203                         IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%llx\n",
1204                                            start, (unsigned long long)bitmap);
1205                 }
1206
1207                 agg->bitmap = bitmap;
1208                 agg->start_idx = start;
1209                 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
1219 static 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);
1230         int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
1231         struct ieee80211_hdr *hdr;
1232         u8 *qc = NULL;
1233
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
1245         hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
1246         if (ieee80211_is_data_qos(hdr->frame_control)) {
1247                 qc = ieee80211_get_qos_ctl(hdr);
1248                 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
1266                 iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
1267
1268                 /* 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;
1271
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);
1277                         freed = iwl_tx_queue_reclaim(priv, txq_id, index);
1278                         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 */
1284                                 ampdu_q = txq_id - IWL50_FIRST_AMPDU_QUEUE +
1285                                           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                         }
1291                         iwl_txq_check_empty(priv, sta_id, tid, txq_id);
1292                 }
1293         } else {
1294                 info->status.retry_count = tx_resp->failure_frame;
1295                 info->flags =
1296                         iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
1297                 iwl_hwrate_to_tx_control(priv,
1298                                         le32_to_cpu(tx_resp->rate_n_flags),
1299                                         info);
1300
1301                 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);
1306
1307                 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)
1311                         priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1312                     if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
1313                         (txq_id >= 0) && priv->mac80211_registered)
1314                         ieee80211_wake_queue(priv->hw, txq_id);
1315                     if (tid != MAX_TID_COUNT)
1316                         iwl_txq_check_empty(priv, sta_id, tid, txq_id);
1317                 }
1318         }
1319
1320         if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
1321                 IWL_ERROR("TODO:  Implement Tx ABORT REQUIRED!!!\n");
1322 }
1323
1324 /* Currently 5000 is the supperset of everything */
1325 static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
1326 {
1327         return len;
1328 }
1329
1330 static 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
1336 static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
1337 {
1338         /* 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;
1343         priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
1344 }
1345
1346
1347 static 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
1353 static 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 }
1399 static 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);
1405         tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
1406         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
1412 static void iwl5000_temperature(struct iwl_priv *priv)
1413 {
1414         /* store temperature from statistics (in Celsius) */
1415         priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
1416 }
1417
1418 /* Calc max signal level (dBm) among 3 possible receivers */
1419 static 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
1456 static struct iwl_hcmd_ops iwl5000_hcmd = {
1457         .rxon_assoc = iwl5000_send_rxon_assoc,
1458 };
1459
1460 static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
1461         .get_hcmd_size = iwl5000_get_hcmd_size,
1462         .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
1463         .gain_computation = iwl5000_gain_computation,
1464         .chain_noise_reset = iwl5000_chain_noise_reset,
1465         .rts_tx_cmd_flag = iwl5000_rts_tx_cmd_flag,
1466         .calc_rssi = iwl5000_calc_rssi,
1467 };
1468
1469 static struct iwl_lib_ops iwl5000_lib = {
1470         .set_hw_params = iwl5000_hw_set_hw_params,
1471         .alloc_shared_mem = iwl5000_alloc_shared_mem,
1472         .free_shared_mem = iwl5000_free_shared_mem,
1473         .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
1474         .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
1475         .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
1476         .txq_set_sched = iwl5000_txq_set_sched,
1477         .txq_agg_enable = iwl5000_txq_agg_enable,
1478         .txq_agg_disable = iwl5000_txq_agg_disable,
1479         .rx_handler_setup = iwl5000_rx_handler_setup,
1480         .setup_deferred_work = iwl5000_setup_deferred_work,
1481         .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
1482         .load_ucode = iwl5000_load_ucode,
1483         .init_alive_start = iwl5000_init_alive_start,
1484         .alive_notify = iwl5000_alive_notify,
1485         .send_tx_power = iwl5000_send_tx_power,
1486         .temperature = iwl5000_temperature,
1487         .update_chain_flags = iwl4965_update_chain_flags,
1488         .apm_ops = {
1489                 .init = iwl5000_apm_init,
1490                 .reset = iwl5000_apm_reset,
1491                 .stop = iwl5000_apm_stop,
1492                 .config = iwl5000_nic_config,
1493                 .set_pwr_src = iwl4965_set_pwr_src,
1494         },
1495         .eeprom_ops = {
1496                 .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                 },
1505                 .verify_signature  = iwlcore_eeprom_verify_signature,
1506                 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
1507                 .release_semaphore = iwlcore_eeprom_release_semaphore,
1508                 .check_version  = iwl5000_eeprom_check_version,
1509                 .query_addr = iwl5000_eeprom_query_addr,
1510         },
1511 };
1512
1513 static struct iwl_ops iwl5000_ops = {
1514         .lib = &iwl5000_lib,
1515         .hcmd = &iwl5000_hcmd,
1516         .utils = &iwl5000_hcmd_utils,
1517 };
1518
1519 static struct iwl_mod_params iwl50_mod_params = {
1520         .num_of_queues = IWL50_NUM_QUEUES,
1521         .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
1522         .enable_qos = 1,
1523         .amsdu_size_8K = 1,
1524         .restart_fw = 1,
1525         /* the rest are 0 by default */
1526 };
1527
1528
1529 struct 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,
1533         .ops = &iwl5000_ops,
1534         .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1535         .mod_params = &iwl50_mod_params,
1536 };
1537
1538 struct 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
1547 struct 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
1556 struct 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,
1560         .ops = &iwl5000_ops,
1561         .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1562         .mod_params = &iwl50_mod_params,
1563 };
1564
1565 struct 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,
1569         .ops = &iwl5000_ops,
1570         .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
1571         .mod_params = &iwl50_mod_params,
1572 };
1573
1574 module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
1575 MODULE_PARM_DESC(disable50,
1576                   "manually disable the 50XX radio (default 0 [radio on])");
1577 module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
1578 MODULE_PARM_DESC(swcrypto50,
1579                   "using software crypto engine (default 0 [hardware])\n");
1580 module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
1581 MODULE_PARM_DESC(debug50, "50XX debug output mask");
1582 module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
1583 MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
1584 module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
1585 MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
1586 module_param_named(11n_disable50, iwl50_mod_params.disable_11n, int, 0444);
1587 MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality");
1588 module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
1589 MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
1590 module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
1591 MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");