1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
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.
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
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/version.h>
30 #include <linux/init.h>
31 #include <linux/pci.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/delay.h>
34 #include <linux/skbuff.h>
35 #include <linux/netdevice.h>
36 #include <linux/wireless.h>
37 #include <net/mac80211.h>
38 #include <linux/etherdevice.h>
39 #include <asm/unaligned.h>
41 #include "iwl-eeprom.h"
45 #include "iwl-helpers.h"
46 #include "iwl-calib.h"
49 static int iwl4965_send_tx_power(struct iwl_priv *priv);
51 /* module parameters */
52 static struct iwl_mod_params iwl4965_mod_params = {
53 .num_of_queues = IWL49_NUM_QUEUES,
57 /* the rest are 0 by default */
60 /* check contents of special bootstrap uCode SRAM */
61 static int iwl4965_verify_bsm(struct iwl_priv *priv)
63 __le32 *image = priv->ucode_boot.v_addr;
64 u32 len = priv->ucode_boot.len;
68 IWL_DEBUG_INFO("Begin verify bsm\n");
70 /* verify BSM SRAM contents */
71 val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
72 for (reg = BSM_SRAM_LOWER_BOUND;
73 reg < BSM_SRAM_LOWER_BOUND + len;
74 reg += sizeof(u32), image++) {
75 val = iwl_read_prph(priv, reg);
76 if (val != le32_to_cpu(*image)) {
77 IWL_ERROR("BSM uCode verification failed at "
78 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
80 reg - BSM_SRAM_LOWER_BOUND, len,
81 val, le32_to_cpu(*image));
86 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
92 * iwl4965_load_bsm - Load bootstrap instructions
96 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
97 * in special SRAM that does not power down during RFKILL. When powering back
98 * up after power-saving sleeps (or during initial uCode load), the BSM loads
99 * the bootstrap program into the on-board processor, and starts it.
101 * The bootstrap program loads (via DMA) instructions and data for a new
102 * program from host DRAM locations indicated by the host driver in the
103 * BSM_DRAM_* registers. Once the new program is loaded, it starts
106 * When initializing the NIC, the host driver points the BSM to the
107 * "initialize" uCode image. This uCode sets up some internal data, then
108 * notifies host via "initialize alive" that it is complete.
110 * The host then replaces the BSM_DRAM_* pointer values to point to the
111 * normal runtime uCode instructions and a backup uCode data cache buffer
112 * (filled initially with starting data values for the on-board processor),
113 * then triggers the "initialize" uCode to load and launch the runtime uCode,
114 * which begins normal operation.
116 * When doing a power-save shutdown, runtime uCode saves data SRAM into
117 * the backup data cache in DRAM before SRAM is powered down.
119 * When powering back up, the BSM loads the bootstrap program. This reloads
120 * the runtime uCode instructions and the backup data cache into SRAM,
121 * and re-launches the runtime uCode from where it left off.
123 static int iwl4965_load_bsm(struct iwl_priv *priv)
125 __le32 *image = priv->ucode_boot.v_addr;
126 u32 len = priv->ucode_boot.len;
136 IWL_DEBUG_INFO("Begin load bsm\n");
138 priv->ucode_type = UCODE_RT;
140 /* make sure bootstrap program is no larger than BSM's SRAM size */
141 if (len > IWL_MAX_BSM_SIZE)
144 /* Tell bootstrap uCode where to find the "Initialize" uCode
145 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
146 * NOTE: iwl_init_alive_start() will replace these values,
147 * after the "initialize" uCode has run, to point to
148 * runtime/protocol instructions and backup data cache.
150 pinst = priv->ucode_init.p_addr >> 4;
151 pdata = priv->ucode_init_data.p_addr >> 4;
152 inst_len = priv->ucode_init.len;
153 data_len = priv->ucode_init_data.len;
155 ret = iwl_grab_nic_access(priv);
159 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
160 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
161 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
162 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
164 /* Fill BSM memory with bootstrap instructions */
165 for (reg_offset = BSM_SRAM_LOWER_BOUND;
166 reg_offset < BSM_SRAM_LOWER_BOUND + len;
167 reg_offset += sizeof(u32), image++)
168 _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
170 ret = iwl4965_verify_bsm(priv);
172 iwl_release_nic_access(priv);
176 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
177 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
178 iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND);
179 iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
181 /* Load bootstrap code into instruction SRAM now,
182 * to prepare to load "initialize" uCode */
183 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
185 /* Wait for load of bootstrap uCode to finish */
186 for (i = 0; i < 100; i++) {
187 done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
188 if (!(done & BSM_WR_CTRL_REG_BIT_START))
193 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
195 IWL_ERROR("BSM write did not complete!\n");
199 /* Enable future boot loads whenever power management unit triggers it
200 * (e.g. when powering back up after power-save shutdown) */
201 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
203 iwl_release_nic_access(priv);
209 * iwl4965_set_ucode_ptrs - Set uCode address location
211 * Tell initialization uCode where to find runtime uCode.
213 * BSM registers initially contain pointers to initialization uCode.
214 * We need to replace them to load runtime uCode inst and data,
215 * and to save runtime data when powering down.
217 static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
224 /* bits 35:4 for 4965 */
225 pinst = priv->ucode_code.p_addr >> 4;
226 pdata = priv->ucode_data_backup.p_addr >> 4;
228 spin_lock_irqsave(&priv->lock, flags);
229 ret = iwl_grab_nic_access(priv);
231 spin_unlock_irqrestore(&priv->lock, flags);
235 /* Tell bootstrap uCode where to find image to load */
236 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
237 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
238 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
239 priv->ucode_data.len);
241 /* Inst bytecount must be last to set up, bit 31 signals uCode
242 * that all new ptr/size info is in place */
243 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
244 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
245 iwl_release_nic_access(priv);
247 spin_unlock_irqrestore(&priv->lock, flags);
249 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
255 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
257 * Called after REPLY_ALIVE notification received from "initialize" uCode.
259 * The 4965 "initialize" ALIVE reply contains calibration data for:
260 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
261 * (3945 does not contain this data).
263 * Tell "initialize" uCode to go ahead and load the runtime uCode.
265 static void iwl4965_init_alive_start(struct iwl_priv *priv)
267 /* Check alive response for "valid" sign from uCode */
268 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
269 /* We had an error bringing up the hardware, so take it
270 * all the way back down so we can try again */
271 IWL_DEBUG_INFO("Initialize Alive failed.\n");
275 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
276 * This is a paranoid check, because we would not have gotten the
277 * "initialize" alive if code weren't properly loaded. */
278 if (iwl_verify_ucode(priv)) {
279 /* Runtime instruction load was bad;
280 * take it all the way back down so we can try again */
281 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
285 /* Calculate temperature */
286 priv->temperature = iwl4965_get_temperature(priv);
288 /* Send pointers to protocol/runtime uCode image ... init code will
289 * load and launch runtime uCode, which will send us another "Alive"
291 IWL_DEBUG_INFO("Initialization Alive received.\n");
292 if (iwl4965_set_ucode_ptrs(priv)) {
293 /* Runtime instruction load won't happen;
294 * take it all the way back down so we can try again */
295 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
301 queue_work(priv->workqueue, &priv->restart);
304 static int is_fat_channel(__le32 rxon_flags)
306 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
307 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
314 static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
319 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
321 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
323 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
324 calib_ver < EEPROM_4965_TX_POWER_VERSION)
329 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
330 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
331 calib_ver, EEPROM_4965_TX_POWER_VERSION);
335 int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
340 spin_lock_irqsave(&priv->lock, flags);
341 ret = iwl_grab_nic_access(priv);
343 spin_unlock_irqrestore(&priv->lock, flags);
347 if (src == IWL_PWR_SRC_VAUX) {
349 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
352 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
353 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
354 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
355 ~APMG_PS_CTRL_MSK_PWR_SRC);
358 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
359 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
360 ~APMG_PS_CTRL_MSK_PWR_SRC);
363 iwl_release_nic_access(priv);
364 spin_unlock_irqrestore(&priv->lock, flags);
370 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
371 * must be called under priv->lock and mac access
373 static void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask)
375 iwl_write_prph(priv, IWL49_SCD_TXFACT, mask);
378 static int iwl4965_apm_init(struct iwl_priv *priv)
382 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
383 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
385 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
386 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
387 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
389 /* set "initialization complete" bit to move adapter
390 * D0U* --> D0A* state */
391 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
393 /* wait for clock stabilization */
394 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
395 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
396 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
398 IWL_DEBUG_INFO("Failed to init the card\n");
402 ret = iwl_grab_nic_access(priv);
407 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
408 APMG_CLK_VAL_BSM_CLK_RQT);
412 /* disable L1-Active */
413 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
414 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
416 iwl_release_nic_access(priv);
422 static void iwl4965_nic_config(struct iwl_priv *priv)
429 spin_lock_irqsave(&priv->lock, flags);
431 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
432 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
433 /* Enable No Snoop field */
434 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
438 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
440 /* L1 is enabled by BIOS */
441 if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
442 /* diable L0S disabled L1A enabled */
443 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
445 /* L0S enabled L1A disabled */
446 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
448 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
450 /* write radio config values to register */
451 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
452 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
453 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
454 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
455 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
457 /* set CSR_HW_CONFIG_REG for uCode use */
458 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
459 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
460 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
462 priv->calib_info = (struct iwl_eeprom_calib_info *)
463 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
465 spin_unlock_irqrestore(&priv->lock, flags);
468 static int iwl4965_apm_stop_master(struct iwl_priv *priv)
473 spin_lock_irqsave(&priv->lock, flags);
475 /* set stop master bit */
476 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
478 ret = iwl_poll_bit(priv, CSR_RESET,
479 CSR_RESET_REG_FLAG_MASTER_DISABLED,
480 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
485 spin_unlock_irqrestore(&priv->lock, flags);
486 IWL_DEBUG_INFO("stop master\n");
491 static void iwl4965_apm_stop(struct iwl_priv *priv)
495 iwl4965_apm_stop_master(priv);
497 spin_lock_irqsave(&priv->lock, flags);
499 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
503 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
504 spin_unlock_irqrestore(&priv->lock, flags);
507 static int iwl4965_apm_reset(struct iwl_priv *priv)
512 iwl4965_apm_stop_master(priv);
514 spin_lock_irqsave(&priv->lock, flags);
516 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
520 /* FIXME: put here L1A -L0S w/a */
522 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
524 ret = iwl_poll_bit(priv, CSR_RESET,
525 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
526 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
533 ret = iwl_grab_nic_access(priv);
536 /* Enable DMA and BSM Clock */
537 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
538 APMG_CLK_VAL_BSM_CLK_RQT);
543 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
544 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
546 iwl_release_nic_access(priv);
548 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
549 wake_up_interruptible(&priv->wait_command_queue);
552 spin_unlock_irqrestore(&priv->lock, flags);
557 #define REG_RECALIB_PERIOD (60)
559 void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
561 struct iwl4965_ct_kill_config cmd;
565 spin_lock_irqsave(&priv->lock, flags);
566 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
567 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
568 spin_unlock_irqrestore(&priv->lock, flags);
570 cmd.critical_temperature_R =
571 cpu_to_le32(priv->hw_params.ct_kill_threshold);
573 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
576 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
578 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
579 "critical temperature is %d\n",
580 cmd.critical_temperature_R);
583 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
584 * Called after every association, but this runs only once!
585 * ... once chain noise is calibrated the first time, it's good forever. */
586 static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
588 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
590 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
591 struct iwl4965_calibration_cmd cmd;
593 memset(&cmd, 0, sizeof(cmd));
594 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
598 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
600 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
601 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
602 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
606 static void iwl4965_gain_computation(struct iwl_priv *priv,
608 u16 min_average_noise_antenna_i,
609 u32 min_average_noise)
612 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
614 data->delta_gain_code[min_average_noise_antenna_i] = 0;
616 for (i = 0; i < NUM_RX_CHAINS; i++) {
619 if (!(data->disconn_array[i]) &&
620 (data->delta_gain_code[i] ==
621 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
622 delta_g = average_noise[i] - min_average_noise;
623 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
624 data->delta_gain_code[i] =
625 min(data->delta_gain_code[i],
626 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
628 data->delta_gain_code[i] =
629 (data->delta_gain_code[i] | (1 << 2));
631 data->delta_gain_code[i] = 0;
634 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
635 data->delta_gain_code[0],
636 data->delta_gain_code[1],
637 data->delta_gain_code[2]);
639 /* Differential gain gets sent to uCode only once */
640 if (!data->radio_write) {
641 struct iwl4965_calibration_cmd cmd;
642 data->radio_write = 1;
644 memset(&cmd, 0, sizeof(cmd));
645 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
646 cmd.diff_gain_a = data->delta_gain_code[0];
647 cmd.diff_gain_b = data->delta_gain_code[1];
648 cmd.diff_gain_c = data->delta_gain_code[2];
649 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
652 IWL_DEBUG_CALIB("fail sending cmd "
653 "REPLY_PHY_CALIBRATION_CMD \n");
655 /* TODO we might want recalculate
656 * rx_chain in rxon cmd */
658 /* Mark so we run this algo only once! */
659 data->state = IWL_CHAIN_NOISE_CALIBRATED;
661 data->chain_noise_a = 0;
662 data->chain_noise_b = 0;
663 data->chain_noise_c = 0;
664 data->chain_signal_a = 0;
665 data->chain_signal_b = 0;
666 data->chain_signal_c = 0;
667 data->beacon_count = 0;
670 static void iwl4965_bg_txpower_work(struct work_struct *work)
672 struct iwl_priv *priv = container_of(work, struct iwl_priv,
675 /* If a scan happened to start before we got here
676 * then just return; the statistics notification will
677 * kick off another scheduled work to compensate for
678 * any temperature delta we missed here. */
679 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
680 test_bit(STATUS_SCANNING, &priv->status))
683 mutex_lock(&priv->mutex);
685 /* Regardless of if we are assocaited, we must reconfigure the
686 * TX power since frames can be sent on non-radar channels while
688 iwl4965_send_tx_power(priv);
690 /* Update last_temperature to keep is_calib_needed from running
691 * when it isn't needed... */
692 priv->last_temperature = priv->temperature;
694 mutex_unlock(&priv->mutex);
698 * Acquire priv->lock before calling this function !
700 static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
702 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
703 (index & 0xff) | (txq_id << 8));
704 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
708 * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
709 * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
710 * @scd_retry: (1) Indicates queue will be used in aggregation mode
712 * NOTE: Acquire priv->lock before calling this function !
714 static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
715 struct iwl_tx_queue *txq,
716 int tx_fifo_id, int scd_retry)
718 int txq_id = txq->q.id;
720 /* Find out whether to activate Tx queue */
721 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
723 /* Set up and activate */
724 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
725 (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
726 (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
727 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
728 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
729 IWL49_SCD_QUEUE_STTS_REG_MSK);
731 txq->sched_retry = scd_retry;
733 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
734 active ? "Activate" : "Deactivate",
735 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
738 static const u16 default_queue_to_tx_fifo[] = {
748 int iwl4965_alive_notify(struct iwl_priv *priv)
755 spin_lock_irqsave(&priv->lock, flags);
757 ret = iwl_grab_nic_access(priv);
759 spin_unlock_irqrestore(&priv->lock, flags);
763 /* Clear 4965's internal Tx Scheduler data base */
764 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
765 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
766 for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
767 iwl_write_targ_mem(priv, a, 0);
768 for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
769 iwl_write_targ_mem(priv, a, 0);
770 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
771 iwl_write_targ_mem(priv, a, 0);
773 /* Tel 4965 where to find Tx byte count tables */
774 iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
776 offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
778 /* Disable chain mode for all queues */
779 iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
781 /* Initialize each Tx queue (including the command queue) */
782 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
784 /* TFD circular buffer read/write indexes */
785 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
786 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
788 /* Max Tx Window size for Scheduler-ACK mode */
789 iwl_write_targ_mem(priv, priv->scd_base_addr +
790 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
792 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
793 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
796 iwl_write_targ_mem(priv, priv->scd_base_addr +
797 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
800 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
801 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
804 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
805 (1 << priv->hw_params.max_txq_num) - 1);
807 /* Activate all Tx DMA/FIFO channels */
808 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
810 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
812 /* Map each Tx/cmd queue to its corresponding fifo */
813 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
814 int ac = default_queue_to_tx_fifo[i];
815 iwl_txq_ctx_activate(priv, i);
816 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
819 iwl_release_nic_access(priv);
820 spin_unlock_irqrestore(&priv->lock, flags);
825 static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
829 .auto_corr_min_ofdm = 85,
830 .auto_corr_min_ofdm_mrc = 170,
831 .auto_corr_min_ofdm_x1 = 105,
832 .auto_corr_min_ofdm_mrc_x1 = 220,
834 .auto_corr_max_ofdm = 120,
835 .auto_corr_max_ofdm_mrc = 210,
836 .auto_corr_max_ofdm_x1 = 140,
837 .auto_corr_max_ofdm_mrc_x1 = 270,
839 .auto_corr_min_cck = 125,
840 .auto_corr_max_cck = 200,
841 .auto_corr_min_cck_mrc = 200,
842 .auto_corr_max_cck_mrc = 400,
849 * iwl4965_hw_set_hw_params
851 * Called when initializing driver
853 int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
856 if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
857 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
858 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
859 IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
863 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
864 priv->hw_params.first_ampdu_q = IWL49_FIRST_AMPDU_QUEUE;
865 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
866 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
867 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
868 if (priv->cfg->mod_params->amsdu_size_8K)
869 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
871 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
872 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
873 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
874 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
876 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
877 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
878 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
879 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
881 priv->hw_params.tx_chains_num = 2;
882 priv->hw_params.rx_chains_num = 2;
883 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
884 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
885 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
887 priv->hw_params.sens = &iwl4965_sensitivity;
892 /* set card power command */
893 static int iwl4965_set_power(struct iwl_priv *priv,
898 ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
899 sizeof(struct iwl4965_powertable_cmd),
904 static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
917 *res = ((num * 2 + denom) / (denom * 2)) * sign;
923 * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
925 * Determines power supply voltage compensation for txpower calculations.
926 * Returns number of 1/2-dB steps to subtract from gain table index,
927 * to compensate for difference between power supply voltage during
928 * factory measurements, vs. current power supply voltage.
930 * Voltage indication is higher for lower voltage.
931 * Lower voltage requires more gain (lower gain table index).
933 static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
938 if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
939 (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
942 iwl4965_math_div_round(current_voltage - eeprom_voltage,
943 TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
945 if (current_voltage > eeprom_voltage)
947 if ((comp < -2) || (comp > 2))
953 static s32 iwl4965_get_tx_atten_grp(u16 channel)
955 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
956 channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
957 return CALIB_CH_GROUP_5;
959 if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
960 channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
961 return CALIB_CH_GROUP_1;
963 if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
964 channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
965 return CALIB_CH_GROUP_2;
967 if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
968 channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
969 return CALIB_CH_GROUP_3;
971 if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
972 channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
973 return CALIB_CH_GROUP_4;
975 IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
979 static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
983 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
984 if (priv->calib_info->band_info[b].ch_from == 0)
987 if ((channel >= priv->calib_info->band_info[b].ch_from)
988 && (channel <= priv->calib_info->band_info[b].ch_to))
995 static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
1002 iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
1008 * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
1010 * Interpolates factory measurements from the two sample channels within a
1011 * sub-band, to apply to channel of interest. Interpolation is proportional to
1012 * differences in channel frequencies, which is proportional to differences
1013 * in channel number.
1015 static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
1016 struct iwl_eeprom_calib_ch_info *chan_info)
1021 const struct iwl_eeprom_calib_measure *m1;
1022 const struct iwl_eeprom_calib_measure *m2;
1023 struct iwl_eeprom_calib_measure *omeas;
1027 s = iwl4965_get_sub_band(priv, channel);
1028 if (s >= EEPROM_TX_POWER_BANDS) {
1029 IWL_ERROR("Tx Power can not find channel %d ", channel);
1033 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
1034 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
1035 chan_info->ch_num = (u8) channel;
1037 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
1038 channel, s, ch_i1, ch_i2);
1040 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
1041 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
1042 m1 = &(priv->calib_info->band_info[s].ch1.
1043 measurements[c][m]);
1044 m2 = &(priv->calib_info->band_info[s].ch2.
1045 measurements[c][m]);
1046 omeas = &(chan_info->measurements[c][m]);
1049 (u8) iwl4965_interpolate_value(channel, ch_i1,
1054 (u8) iwl4965_interpolate_value(channel, ch_i1,
1055 m1->gain_idx, ch_i2,
1057 omeas->temperature =
1058 (u8) iwl4965_interpolate_value(channel, ch_i1,
1063 (s8) iwl4965_interpolate_value(channel, ch_i1,
1068 ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
1069 m1->actual_pow, m2->actual_pow, omeas->actual_pow);
1071 ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
1072 m1->gain_idx, m2->gain_idx, omeas->gain_idx);
1074 ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
1075 m1->pa_det, m2->pa_det, omeas->pa_det);
1077 ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
1078 m1->temperature, m2->temperature,
1079 omeas->temperature);
1086 /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
1087 * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
1088 static s32 back_off_table[] = {
1089 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
1090 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
1091 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
1092 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
1096 /* Thermal compensation values for txpower for various frequency ranges ...
1097 * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
1098 static struct iwl4965_txpower_comp_entry {
1099 s32 degrees_per_05db_a;
1100 s32 degrees_per_05db_a_denom;
1101 } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
1102 {9, 2}, /* group 0 5.2, ch 34-43 */
1103 {4, 1}, /* group 1 5.2, ch 44-70 */
1104 {4, 1}, /* group 2 5.2, ch 71-124 */
1105 {4, 1}, /* group 3 5.2, ch 125-200 */
1106 {3, 1} /* group 4 2.4, ch all */
1109 static s32 get_min_power_index(s32 rate_power_index, u32 band)
1112 if ((rate_power_index & 7) <= 4)
1113 return MIN_TX_GAIN_INDEX_52GHZ_EXT;
1115 return MIN_TX_GAIN_INDEX;
1123 static const struct gain_entry gain_table[2][108] = {
1124 /* 5.2GHz power gain index table */
1126 {123, 0x3F}, /* highest txpower */
1235 /* 2.4GHz power gain index table */
1237 {110, 0x3f}, /* highest txpower */
1348 static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
1349 u8 is_fat, u8 ctrl_chan_high,
1350 struct iwl4965_tx_power_db *tx_power_tbl)
1352 u8 saturation_power;
1354 s32 user_target_power;
1358 s32 current_regulatory;
1359 s32 txatten_grp = CALIB_CH_GROUP_MAX;
1362 const struct iwl_channel_info *ch_info = NULL;
1363 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
1364 const struct iwl_eeprom_calib_measure *measurement;
1367 s32 voltage_compensation;
1368 s32 degrees_per_05db_num;
1369 s32 degrees_per_05db_denom;
1371 s32 temperature_comp[2];
1372 s32 factory_gain_index[2];
1373 s32 factory_actual_pwr[2];
1376 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
1377 * are used for indexing into txpower table) */
1378 user_target_power = 2 * priv->tx_power_user_lmt;
1380 /* Get current (RXON) channel, band, width */
1381 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
1384 ch_info = iwl_get_channel_info(priv, priv->band, channel);
1386 if (!is_channel_valid(ch_info))
1389 /* get txatten group, used to select 1) thermal txpower adjustment
1390 * and 2) mimo txpower balance between Tx chains. */
1391 txatten_grp = iwl4965_get_tx_atten_grp(channel);
1392 if (txatten_grp < 0)
1395 IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
1396 channel, txatten_grp);
1405 /* hardware txpower limits ...
1406 * saturation (clipping distortion) txpowers are in half-dBm */
1408 saturation_power = priv->calib_info->saturation_power24;
1410 saturation_power = priv->calib_info->saturation_power52;
1412 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
1413 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
1415 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
1417 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
1420 /* regulatory txpower limits ... reg_limit values are in half-dBm,
1421 * max_power_avg values are in dBm, convert * 2 */
1423 reg_limit = ch_info->fat_max_power_avg * 2;
1425 reg_limit = ch_info->max_power_avg * 2;
1427 if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
1428 (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
1430 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
1432 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
1435 /* Interpolate txpower calibration values for this channel,
1436 * based on factory calibration tests on spaced channels. */
1437 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
1439 /* calculate tx gain adjustment based on power supply voltage */
1440 voltage = priv->calib_info->voltage;
1441 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
1442 voltage_compensation =
1443 iwl4965_get_voltage_compensation(voltage, init_voltage);
1445 IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
1447 voltage, voltage_compensation);
1449 /* get current temperature (Celsius) */
1450 current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
1451 current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
1452 current_temp = KELVIN_TO_CELSIUS(current_temp);
1454 /* select thermal txpower adjustment params, based on channel group
1455 * (same frequency group used for mimo txatten adjustment) */
1456 degrees_per_05db_num =
1457 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
1458 degrees_per_05db_denom =
1459 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
1461 /* get per-chain txpower values from factory measurements */
1462 for (c = 0; c < 2; c++) {
1463 measurement = &ch_eeprom_info.measurements[c][1];
1465 /* txgain adjustment (in half-dB steps) based on difference
1466 * between factory and current temperature */
1467 factory_temp = measurement->temperature;
1468 iwl4965_math_div_round((current_temp - factory_temp) *
1469 degrees_per_05db_denom,
1470 degrees_per_05db_num,
1471 &temperature_comp[c]);
1473 factory_gain_index[c] = measurement->gain_idx;
1474 factory_actual_pwr[c] = measurement->actual_pow;
1476 IWL_DEBUG_TXPOWER("chain = %d\n", c);
1477 IWL_DEBUG_TXPOWER("fctry tmp %d, "
1478 "curr tmp %d, comp %d steps\n",
1479 factory_temp, current_temp,
1480 temperature_comp[c]);
1482 IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
1483 factory_gain_index[c],
1484 factory_actual_pwr[c]);
1487 /* for each of 33 bit-rates (including 1 for CCK) */
1488 for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
1490 union iwl4965_tx_power_dual_stream tx_power;
1492 /* for mimo, reduce each chain's txpower by half
1493 * (3dB, 6 steps), so total output power is regulatory
1496 current_regulatory = reg_limit -
1497 IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
1500 current_regulatory = reg_limit;
1504 /* find txpower limit, either hardware or regulatory */
1505 power_limit = saturation_power - back_off_table[i];
1506 if (power_limit > current_regulatory)
1507 power_limit = current_regulatory;
1509 /* reduce user's txpower request if necessary
1510 * for this rate on this channel */
1511 target_power = user_target_power;
1512 if (target_power > power_limit)
1513 target_power = power_limit;
1515 IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
1516 i, saturation_power - back_off_table[i],
1517 current_regulatory, user_target_power,
1520 /* for each of 2 Tx chains (radio transmitters) */
1521 for (c = 0; c < 2; c++) {
1526 (s32)le32_to_cpu(priv->card_alive_init.
1527 tx_atten[txatten_grp][c]);
1531 /* calculate index; higher index means lower txpower */
1532 power_index = (u8) (factory_gain_index[c] -
1534 factory_actual_pwr[c]) -
1535 temperature_comp[c] -
1536 voltage_compensation +
1539 /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
1542 if (power_index < get_min_power_index(i, band))
1543 power_index = get_min_power_index(i, band);
1545 /* adjust 5 GHz index to support negative indexes */
1549 /* CCK, rate 32, reduce txpower for CCK */
1550 if (i == POWER_TABLE_CCK_ENTRY)
1552 IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
1554 /* stay within the table! */
1555 if (power_index > 107) {
1556 IWL_WARNING("txpower index %d > 107\n",
1560 if (power_index < 0) {
1561 IWL_WARNING("txpower index %d < 0\n",
1566 /* fill txpower command for this rate/chain */
1567 tx_power.s.radio_tx_gain[c] =
1568 gain_table[band][power_index].radio;
1569 tx_power.s.dsp_predis_atten[c] =
1570 gain_table[band][power_index].dsp;
1572 IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
1573 "gain 0x%02x dsp %d\n",
1574 c, atten_value, power_index,
1575 tx_power.s.radio_tx_gain[c],
1576 tx_power.s.dsp_predis_atten[c]);
1577 }/* for each chain */
1579 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
1581 }/* for each rate */
1587 * iwl4965_send_tx_power - Configure the TXPOWER level user limit
1589 * Uses the active RXON for channel, band, and characteristics (fat, high)
1590 * The power limit is taken from priv->tx_power_user_lmt.
1592 static int iwl4965_send_tx_power(struct iwl_priv *priv)
1594 struct iwl4965_txpowertable_cmd cmd = { 0 };
1598 u8 ctrl_chan_high = 0;
1600 if (test_bit(STATUS_SCANNING, &priv->status)) {
1601 /* If this gets hit a lot, switch it to a BUG() and catch
1602 * the stack trace to find out who is calling this during
1604 IWL_WARNING("TX Power requested while scanning!\n");
1608 band = priv->band == IEEE80211_BAND_2GHZ;
1610 is_fat = is_fat_channel(priv->active_rxon.flags);
1613 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1617 cmd.channel = priv->active_rxon.channel;
1619 ret = iwl4965_fill_txpower_tbl(priv, band,
1620 le16_to_cpu(priv->active_rxon.channel),
1621 is_fat, ctrl_chan_high, &cmd.tx_power);
1625 ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
1631 static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1634 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1635 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1636 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1638 if ((rxon1->flags == rxon2->flags) &&
1639 (rxon1->filter_flags == rxon2->filter_flags) &&
1640 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1641 (rxon1->ofdm_ht_single_stream_basic_rates ==
1642 rxon2->ofdm_ht_single_stream_basic_rates) &&
1643 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1644 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1645 (rxon1->rx_chain == rxon2->rx_chain) &&
1646 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1647 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1651 rxon_assoc.flags = priv->staging_rxon.flags;
1652 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1653 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1654 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1655 rxon_assoc.reserved = 0;
1656 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1657 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1658 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1659 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1660 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1662 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1663 sizeof(rxon_assoc), &rxon_assoc, NULL);
1671 int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1676 u8 ctrl_chan_high = 0;
1677 struct iwl4965_channel_switch_cmd cmd = { 0 };
1678 const struct iwl_channel_info *ch_info;
1680 band = priv->band == IEEE80211_BAND_2GHZ;
1682 ch_info = iwl_get_channel_info(priv, priv->band, channel);
1684 is_fat = is_fat_channel(priv->staging_rxon.flags);
1687 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1691 cmd.expect_beacon = 0;
1692 cmd.channel = cpu_to_le16(channel);
1693 cmd.rxon_flags = priv->active_rxon.flags;
1694 cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
1695 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
1697 cmd.expect_beacon = is_channel_radar(ch_info);
1699 cmd.expect_beacon = 1;
1701 rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
1702 ctrl_chan_high, &cmd.tx_power);
1704 IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
1708 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
1712 static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
1714 struct iwl4965_shared *s = priv->shared_virt;
1715 return le32_to_cpu(s->rb_closed) & 0xFFF;
1718 int iwl4965_hw_get_temperature(struct iwl_priv *priv)
1720 return priv->temperature;
1723 unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
1724 struct iwl_frame *frame, u8 rate)
1726 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
1727 unsigned int frame_size;
1729 tx_beacon_cmd = &frame->u.beacon;
1730 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
1732 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
1733 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
1735 frame_size = iwl4965_fill_beacon_frame(priv,
1736 tx_beacon_cmd->frame,
1738 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
1740 BUG_ON(frame_size > MAX_MPDU_SIZE);
1741 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
1743 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
1744 tx_beacon_cmd->tx.rate_n_flags =
1745 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
1747 tx_beacon_cmd->tx.rate_n_flags =
1748 iwl_hw_set_rate_n_flags(rate, 0);
1750 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
1751 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
1752 return (sizeof(*tx_beacon_cmd) + frame_size);
1755 static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
1757 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
1758 sizeof(struct iwl4965_shared),
1759 &priv->shared_phys);
1760 if (!priv->shared_virt)
1763 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
1765 priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed);
1770 static void iwl4965_free_shared_mem(struct iwl_priv *priv)
1772 if (priv->shared_virt)
1773 pci_free_consistent(priv->pci_dev,
1774 sizeof(struct iwl4965_shared),
1780 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
1782 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
1783 struct iwl_tx_queue *txq,
1787 int txq_id = txq->q.id;
1788 struct iwl4965_shared *shared_data = priv->shared_virt;
1790 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
1792 /* Set up byte count within first 256 entries */
1793 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
1794 tfd_offset[txq->q.write_ptr], byte_cnt, len);
1796 /* If within first 64 entries, duplicate at end */
1797 if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
1798 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
1799 tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
1804 * sign_extend - Sign extend a value using specified bit as sign-bit
1806 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
1807 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
1809 * @param oper value to sign extend
1810 * @param index 0 based bit index (0<=index<32) to sign bit
1812 static s32 sign_extend(u32 oper, int index)
1814 u8 shift = 31 - index;
1816 return (s32)(oper << shift) >> shift;
1820 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
1821 * @statistics: Provides the temperature reading from the uCode
1823 * A return of <0 indicates bogus data in the statistics
1825 int iwl4965_get_temperature(const struct iwl_priv *priv)
1832 if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
1833 (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
1834 IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
1835 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
1836 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
1837 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
1838 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
1840 IWL_DEBUG_TEMP("Running temperature calibration\n");
1841 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
1842 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
1843 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
1844 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
1848 * Temperature is only 23 bits, so sign extend out to 32.
1850 * NOTE If we haven't received a statistics notification yet
1851 * with an updated temperature, use R4 provided to us in the
1852 * "initialize" ALIVE response.
1854 if (!test_bit(STATUS_TEMPERATURE, &priv->status))
1855 vt = sign_extend(R4, 23);
1858 le32_to_cpu(priv->statistics.general.temperature), 23);
1860 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
1864 IWL_ERROR("Calibration conflict R1 == R3\n");
1868 /* Calculate temperature in degrees Kelvin, adjust by 97%.
1869 * Add offset to center the adjustment around 0 degrees Centigrade. */
1870 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
1871 temperature /= (R3 - R1);
1872 temperature = (temperature * 97) / 100 +
1873 TEMPERATURE_CALIB_KELVIN_OFFSET;
1875 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
1876 KELVIN_TO_CELSIUS(temperature));
1881 /* Adjust Txpower only if temperature variance is greater than threshold. */
1882 #define IWL_TEMPERATURE_THRESHOLD 3
1885 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
1887 * If the temperature changed has changed sufficiently, then a recalibration
1890 * Assumes caller will replace priv->last_temperature once calibration
1893 static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
1897 if (!test_bit(STATUS_STATISTICS, &priv->status)) {
1898 IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
1902 temp_diff = priv->temperature - priv->last_temperature;
1904 /* get absolute value */
1905 if (temp_diff < 0) {
1906 IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
1907 temp_diff = -temp_diff;
1908 } else if (temp_diff == 0)
1909 IWL_DEBUG_POWER("Same temp, \n");
1911 IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
1913 if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
1914 IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
1918 IWL_DEBUG_POWER("Thermal txpower calib needed\n");
1923 /* Calculate noise level, based on measurements during network silence just
1924 * before arriving beacon. This measurement can be done only if we know
1925 * exactly when to expect beacons, therefore only when we're associated. */
1926 static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
1928 struct statistics_rx_non_phy *rx_info
1929 = &(priv->statistics.rx.general);
1930 int num_active_rx = 0;
1931 int total_silence = 0;
1933 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
1935 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
1937 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
1939 if (bcn_silence_a) {
1940 total_silence += bcn_silence_a;
1943 if (bcn_silence_b) {
1944 total_silence += bcn_silence_b;
1947 if (bcn_silence_c) {
1948 total_silence += bcn_silence_c;
1952 /* Average among active antennas */
1954 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
1956 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
1958 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
1959 bcn_silence_a, bcn_silence_b, bcn_silence_c,
1960 priv->last_rx_noise);
1963 void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
1964 struct iwl_rx_mem_buffer *rxb)
1966 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1970 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
1971 (int)sizeof(priv->statistics), pkt->len);
1973 change = ((priv->statistics.general.temperature !=
1974 pkt->u.stats.general.temperature) ||
1975 ((priv->statistics.flag &
1976 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
1977 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
1979 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
1981 set_bit(STATUS_STATISTICS, &priv->status);
1983 /* Reschedule the statistics timer to occur in
1984 * REG_RECALIB_PERIOD seconds to ensure we get a
1985 * thermal update even if the uCode doesn't give
1987 mod_timer(&priv->statistics_periodic, jiffies +
1988 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
1990 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
1991 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
1992 iwl4965_rx_calc_noise(priv);
1993 queue_work(priv->workqueue, &priv->run_time_calib_work);
1996 iwl_leds_background(priv);
1998 /* If the hardware hasn't reported a change in
1999 * temperature then don't bother computing a
2000 * calibrated temperature value */
2004 temp = iwl4965_get_temperature(priv);
2008 if (priv->temperature != temp) {
2009 if (priv->temperature)
2010 IWL_DEBUG_TEMP("Temperature changed "
2011 "from %dC to %dC\n",
2012 KELVIN_TO_CELSIUS(priv->temperature),
2013 KELVIN_TO_CELSIUS(temp));
2015 IWL_DEBUG_TEMP("Temperature "
2016 "initialized to %dC\n",
2017 KELVIN_TO_CELSIUS(temp));
2020 priv->temperature = temp;
2021 set_bit(STATUS_TEMPERATURE, &priv->status);
2023 if (!priv->disable_tx_power_cal &&
2024 unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2025 iwl4965_is_temp_calib_needed(priv))
2026 queue_work(priv->workqueue, &priv->txpower_work);
2029 static void iwl4965_add_radiotap(struct iwl_priv *priv,
2030 struct sk_buff *skb,
2031 struct iwl4965_rx_phy_res *rx_start,
2032 struct ieee80211_rx_status *stats,
2035 s8 signal = stats->signal;
2037 int rate = stats->rate_idx;
2038 u64 tsf = stats->mactime;
2040 __le16 phy_flags_hw = rx_start->phy_flags;
2041 struct iwl4965_rt_rx_hdr {
2042 struct ieee80211_radiotap_header rt_hdr;
2043 __le64 rt_tsf; /* TSF */
2044 u8 rt_flags; /* radiotap packet flags */
2045 u8 rt_rate; /* rate in 500kb/s */
2046 __le16 rt_channelMHz; /* channel in MHz */
2047 __le16 rt_chbitmask; /* channel bitfield */
2048 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
2050 u8 rt_antenna; /* antenna number */
2051 } __attribute__ ((packed)) *iwl4965_rt;
2053 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
2054 if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
2055 if (net_ratelimit())
2056 printk(KERN_ERR "not enough headroom [%d] for "
2057 "radiotap head [%zd]\n",
2058 skb_headroom(skb), sizeof(*iwl4965_rt));
2062 /* put radiotap header in front of 802.11 header and data */
2063 iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
2065 /* initialise radiotap header */
2066 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2067 iwl4965_rt->rt_hdr.it_pad = 0;
2069 /* total header + data */
2070 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
2071 &iwl4965_rt->rt_hdr.it_len);
2073 /* Indicate all the fields we add to the radiotap header */
2074 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
2075 (1 << IEEE80211_RADIOTAP_FLAGS) |
2076 (1 << IEEE80211_RADIOTAP_RATE) |
2077 (1 << IEEE80211_RADIOTAP_CHANNEL) |
2078 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
2079 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
2080 (1 << IEEE80211_RADIOTAP_ANTENNA)),
2081 &iwl4965_rt->rt_hdr.it_present);
2083 /* Zero the flags, we'll add to them as we go */
2084 iwl4965_rt->rt_flags = 0;
2086 put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
2088 iwl4965_rt->rt_dbmsignal = signal;
2089 iwl4965_rt->rt_dbmnoise = noise;
2091 /* Convert the channel frequency and set the flags */
2092 put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
2093 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
2094 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2095 IEEE80211_CHAN_5GHZ),
2096 &iwl4965_rt->rt_chbitmask);
2097 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
2098 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
2099 IEEE80211_CHAN_2GHZ),
2100 &iwl4965_rt->rt_chbitmask);
2102 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2103 IEEE80211_CHAN_2GHZ),
2104 &iwl4965_rt->rt_chbitmask);
2107 iwl4965_rt->rt_rate = 0;
2109 iwl4965_rt->rt_rate = iwl_rates[rate].ieee;
2114 * It seems that the antenna field in the phy flags value
2115 * is actually a bitfield. This is undefined by radiotap,
2116 * it wants an actual antenna number but I always get "7"
2117 * for most legacy frames I receive indicating that the
2118 * same frame was received on all three RX chains.
2120 * I think this field should be removed in favour of a
2121 * new 802.11n radiotap field "RX chains" that is defined
2124 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
2125 iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
2127 /* set the preamble flag if appropriate */
2128 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
2129 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
2131 stats->flag |= RX_FLAG_RADIOTAP;
2134 static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2136 /* 0 - mgmt, 1 - cnt, 2 - data */
2137 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2138 priv->rx_stats[idx].cnt++;
2139 priv->rx_stats[idx].bytes += len;
2143 * returns non-zero if packet should be dropped
2145 static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2146 struct ieee80211_hdr *hdr,
2148 struct ieee80211_rx_status *stats)
2150 u16 fc = le16_to_cpu(hdr->frame_control);
2152 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2155 if (!(fc & IEEE80211_FCTL_PROTECTED))
2158 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2159 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2160 case RX_RES_STATUS_SEC_TYPE_TKIP:
2161 /* The uCode has got a bad phase 1 Key, pushes the packet.
2162 * Decryption will be done in SW. */
2163 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2164 RX_RES_STATUS_BAD_KEY_TTAK)
2167 case RX_RES_STATUS_SEC_TYPE_WEP:
2168 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2169 RX_RES_STATUS_BAD_ICV_MIC) {
2170 /* bad ICV, the packet is destroyed since the
2171 * decryption is inplace, drop it */
2172 IWL_DEBUG_RX("Packet destroyed\n");
2175 case RX_RES_STATUS_SEC_TYPE_CCMP:
2176 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2177 RX_RES_STATUS_DECRYPT_OK) {
2178 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2179 stats->flag |= RX_FLAG_DECRYPTED;
2189 static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
2191 u32 decrypt_out = 0;
2193 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
2194 RX_RES_STATUS_STATION_FOUND)
2195 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
2196 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
2198 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
2200 /* packet was not encrypted */
2201 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2202 RX_RES_STATUS_SEC_TYPE_NONE)
2205 /* packet was encrypted with unknown alg */
2206 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2207 RX_RES_STATUS_SEC_TYPE_ERR)
2210 /* decryption was not done in HW */
2211 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
2212 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
2215 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
2217 case RX_RES_STATUS_SEC_TYPE_CCMP:
2218 /* alg is CCM: check MIC only */
2219 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
2221 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2223 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2227 case RX_RES_STATUS_SEC_TYPE_TKIP:
2228 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
2230 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
2233 /* fall through if TTAK OK */
2235 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
2236 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2238 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2242 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
2243 decrypt_in, decrypt_out);
2248 static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
2250 struct iwl_rx_mem_buffer *rxb,
2251 struct ieee80211_rx_status *stats)
2253 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2254 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2255 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
2256 struct ieee80211_hdr *hdr;
2259 unsigned int skblen;
2261 u32 ampdu_status_legacy;
2263 if (!include_phy && priv->last_phy_res[0])
2264 rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2267 IWL_ERROR("MPDU frame without a PHY data\n");
2271 hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
2272 rx_start->cfg_phy_cnt);
2274 len = le16_to_cpu(rx_start->byte_count);
2276 rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
2277 sizeof(struct iwl4965_rx_phy_res) +
2278 rx_start->cfg_phy_cnt + len);
2281 struct iwl4965_rx_mpdu_res_start *amsdu =
2282 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2284 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
2285 sizeof(struct iwl4965_rx_mpdu_res_start));
2286 len = le16_to_cpu(amsdu->byte_count);
2287 rx_start->byte_count = amsdu->byte_count;
2288 rx_end = (__le32 *) (((u8 *) hdr) + len);
2290 /* In monitor mode allow 802.11 ACk frames (10 bytes) */
2291 if (len > priv->hw_params.max_pkt_size ||
2292 len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) {
2293 IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
2297 ampdu_status = le32_to_cpu(*rx_end);
2298 skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
2301 /* New status scheme, need to translate */
2302 ampdu_status_legacy = ampdu_status;
2303 ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status);
2306 /* start from MAC */
2307 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
2308 skb_put(rxb->skb, len); /* end where data ends */
2310 /* We only process data packets if the interface is open */
2311 if (unlikely(!priv->is_open)) {
2312 IWL_DEBUG_DROP_LIMIT
2313 ("Dropping packet while interface is not open.\n");
2318 hdr = (struct ieee80211_hdr *)rxb->skb->data;
2320 /* in case of HW accelerated crypto and bad decryption, drop */
2321 if (!priv->hw_params.sw_crypto &&
2322 iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
2325 if (priv->add_radiotap)
2326 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
2328 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
2329 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
2330 priv->alloc_rxb_skb--;
2334 /* Calc max signal level (dBm) among 3 possible receivers */
2335 static int iwl4965_calc_rssi(struct iwl_priv *priv,
2336 struct iwl4965_rx_phy_res *rx_resp)
2338 /* data from PHY/DSP regarding signal strength, etc.,
2339 * contents are always there, not configurable by host. */
2340 struct iwl4965_rx_non_cfg_phy *ncphy =
2341 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
2342 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
2345 u32 valid_antennae =
2346 (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
2347 >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
2351 /* Find max rssi among 3 possible receivers.
2352 * These values are measured by the digital signal processor (DSP).
2353 * They should stay fairly constant even as the signal strength varies,
2354 * if the radio's automatic gain control (AGC) is working right.
2355 * AGC value (see below) will provide the "interesting" info. */
2356 for (i = 0; i < 3; i++)
2357 if (valid_antennae & (1 << i))
2358 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
2360 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
2361 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
2364 /* dBm = max_rssi dB - agc dB - constant.
2365 * Higher AGC (higher radio gain) means lower signal. */
2366 return (max_rssi - agc - IWL_RSSI_OFFSET);
2369 static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
2371 unsigned long flags;
2373 spin_lock_irqsave(&priv->sta_lock, flags);
2374 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
2375 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
2376 priv->stations[sta_id].sta.sta.modify_mask = 0;
2377 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
2378 spin_unlock_irqrestore(&priv->sta_lock, flags);
2380 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
2383 static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
2385 /* FIXME: need locking over ps_status ??? */
2386 u8 sta_id = iwl_find_station(priv, addr);
2388 if (sta_id != IWL_INVALID_STATION) {
2389 u8 sta_awake = priv->stations[sta_id].
2390 ps_status == STA_PS_STATUS_WAKE;
2392 if (sta_awake && ps_bit)
2393 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
2394 else if (!sta_awake && !ps_bit) {
2395 iwl4965_sta_modify_ps_wake(priv, sta_id);
2396 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
2400 #ifdef CONFIG_IWLWIFI_DEBUG
2403 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
2405 * You may hack this function to show different aspects of received frames,
2406 * including selective frame dumps.
2407 * group100 parameter selects whether to show 1 out of 100 good frames.
2409 * TODO: This was originally written for 3945, need to audit for
2410 * proper operation with 4965.
2412 static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2413 struct iwl_rx_packet *pkt,
2414 struct ieee80211_hdr *header, int group100)
2417 u32 print_summary = 0;
2418 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
2435 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
2436 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
2437 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
2438 u8 *data = IWL_RX_DATA(pkt);
2440 if (likely(!(priv->debug_level & IWL_DL_RX)))
2444 fc = le16_to_cpu(header->frame_control);
2445 seq_ctl = le16_to_cpu(header->seq_ctrl);
2448 channel = le16_to_cpu(rx_hdr->channel);
2449 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
2450 rate_sym = rx_hdr->rate;
2451 length = le16_to_cpu(rx_hdr->len);
2453 /* end-of-frame status and timestamp */
2454 status = le32_to_cpu(rx_end->status);
2455 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
2456 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
2457 tsf = le64_to_cpu(rx_end->timestamp);
2459 /* signal statistics */
2460 rssi = rx_stats->rssi;
2461 agc = rx_stats->agc;
2462 sig_avg = le16_to_cpu(rx_stats->sig_avg);
2463 noise_diff = le16_to_cpu(rx_stats->noise_diff);
2465 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
2467 /* if data frame is to us and all is good,
2468 * (optionally) print summary for only 1 out of every 100 */
2469 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
2470 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
2473 print_summary = 1; /* print each frame */
2474 else if (priv->framecnt_to_us < 100) {
2475 priv->framecnt_to_us++;
2478 priv->framecnt_to_us = 0;
2483 /* print summary for all other frames */
2487 if (print_summary) {
2493 title = "100Frames";
2494 else if (fc & IEEE80211_FCTL_RETRY)
2496 else if (ieee80211_is_assoc_response(fc))
2498 else if (ieee80211_is_reassoc_response(fc))
2500 else if (ieee80211_is_probe_response(fc)) {
2502 print_dump = 1; /* dump frame contents */
2503 } else if (ieee80211_is_beacon(fc)) {
2505 print_dump = 1; /* dump frame contents */
2506 } else if (ieee80211_is_atim(fc))
2508 else if (ieee80211_is_auth(fc))
2510 else if (ieee80211_is_deauth(fc))
2512 else if (ieee80211_is_disassoc(fc))
2517 rate_idx = iwl_hwrate_to_plcp_idx(rate_sym);
2518 if (unlikely(rate_idx == -1))
2521 bitrate = iwl_rates[rate_idx].ieee / 2;
2523 /* print frame summary.
2524 * MAC addresses show just the last byte (for brevity),
2525 * but you can hack it to show more, if you'd like to. */
2527 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
2528 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
2529 title, fc, header->addr1[5],
2530 length, rssi, channel, bitrate);
2532 /* src/dst addresses assume managed mode */
2533 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
2534 "src=0x%02x, rssi=%u, tim=%lu usec, "
2535 "phy=0x%02x, chnl=%d\n",
2536 title, fc, header->addr1[5],
2537 header->addr3[5], rssi,
2538 tsf_low - priv->scan_start_tsf,
2539 phy_flags, channel);
2543 iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
2546 static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2547 struct iwl_rx_packet *pkt,
2548 struct ieee80211_hdr *header,
2556 /* Called for REPLY_RX (legacy ABG frames), or
2557 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
2558 void iwl4965_rx_reply_rx(struct iwl_priv *priv,
2559 struct iwl_rx_mem_buffer *rxb)
2561 struct ieee80211_hdr *header;
2562 struct ieee80211_rx_status rx_status;
2563 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2564 /* Use phy data (Rx signal strength, etc.) contained within
2565 * this rx packet for legacy frames,
2566 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
2567 int include_phy = (pkt->hdr.cmd == REPLY_RX);
2568 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2569 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
2570 (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2572 unsigned int len = 0;
2576 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
2578 ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
2579 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
2580 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
2581 rx_status.rate_idx =
2582 iwl_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
2583 if (rx_status.band == IEEE80211_BAND_5GHZ)
2584 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
2586 rx_status.antenna = 0;
2589 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
2590 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
2591 rx_start->cfg_phy_cnt);
2596 if (priv->last_phy_res[0])
2597 rx_start = (struct iwl4965_rx_phy_res *)
2598 &priv->last_phy_res[1];
2604 IWL_ERROR("MPDU frame without a PHY data\n");
2609 header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
2610 + rx_start->cfg_phy_cnt);
2612 len = le16_to_cpu(rx_start->byte_count);
2613 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
2614 sizeof(struct iwl4965_rx_phy_res) + len);
2616 struct iwl4965_rx_mpdu_res_start *amsdu =
2617 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2619 header = (void *)(pkt->u.raw +
2620 sizeof(struct iwl4965_rx_mpdu_res_start));
2621 len = le16_to_cpu(amsdu->byte_count);
2622 rx_end = (__le32 *) (pkt->u.raw +
2623 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
2626 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
2627 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
2628 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
2629 le32_to_cpu(*rx_end));
2633 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
2635 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
2636 rx_status.signal = iwl4965_calc_rssi(priv, rx_start);
2638 /* Meaningful noise values are available only from beacon statistics,
2639 * which are gathered only when associated, and indicate noise
2640 * only for the associated network channel ...
2641 * Ignore these noise values while scanning (other channels) */
2642 if (iwl_is_associated(priv) &&
2643 !test_bit(STATUS_SCANNING, &priv->status)) {
2644 rx_status.noise = priv->last_rx_noise;
2645 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal,
2648 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2649 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, 0);
2652 /* Reset beacon noise level if not associated. */
2653 if (!iwl_is_associated(priv))
2654 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2656 /* Set "1" to report good data frames in groups of 100 */
2657 /* FIXME: need to optimze the call: */
2658 iwl4965_dbg_report_frame(priv, pkt, header, 1);
2660 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
2661 rx_status.signal, rx_status.noise, rx_status.signal,
2662 (unsigned long long)rx_status.mactime);
2665 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2666 iwl4965_handle_data_packet(priv, 1, include_phy,
2671 network_packet = iwl4965_is_network_packet(priv, header);
2672 if (network_packet) {
2673 priv->last_rx_rssi = rx_status.signal;
2674 priv->last_beacon_time = priv->ucode_beacon_time;
2675 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
2678 fc = le16_to_cpu(header->frame_control);
2679 switch (fc & IEEE80211_FCTL_FTYPE) {
2680 case IEEE80211_FTYPE_MGMT:
2681 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2682 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2684 iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
2687 case IEEE80211_FTYPE_CTL:
2688 switch (fc & IEEE80211_FCTL_STYPE) {
2689 case IEEE80211_STYPE_BACK_REQ:
2690 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
2691 iwl4965_handle_data_packet(priv, 0, include_phy,
2699 case IEEE80211_FTYPE_DATA: {
2700 DECLARE_MAC_BUF(mac1);
2701 DECLARE_MAC_BUF(mac2);
2702 DECLARE_MAC_BUF(mac3);
2704 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2705 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2708 if (unlikely(!network_packet))
2709 IWL_DEBUG_DROP("Dropping (non network): "
2711 print_mac(mac1, header->addr1),
2712 print_mac(mac2, header->addr2),
2713 print_mac(mac3, header->addr3));
2714 else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
2715 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
2716 print_mac(mac1, header->addr1),
2717 print_mac(mac2, header->addr2),
2718 print_mac(mac3, header->addr3));
2720 iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
2731 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
2733 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
2734 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
2736 static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
2737 struct iwl_ht_agg *agg,
2738 struct iwl4965_compressed_ba_resp*
2743 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
2744 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
2747 struct ieee80211_tx_info *info;
2749 if (unlikely(!agg->wait_for_ba)) {
2750 IWL_ERROR("Received BA when not expected\n");
2754 /* Mark that the expected block-ack response arrived */
2755 agg->wait_for_ba = 0;
2756 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
2758 /* Calculate shift to align block-ack bits with our Tx window bits */
2759 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
2760 if (sh < 0) /* tbw something is wrong with indices */
2763 /* don't use 64-bit values for now */
2764 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
2766 if (agg->frame_count > (64 - sh)) {
2767 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
2771 /* check for success or failure according to the
2772 * transmitted bitmap and block-ack bitmap */
2773 bitmap &= agg->bitmap;
2775 /* For each frame attempted in aggregation,
2776 * update driver's record of tx frame's status. */
2777 for (i = 0; i < agg->frame_count ; i++) {
2778 ack = bitmap & (1 << i);
2780 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
2781 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
2782 agg->start_idx + i);
2785 info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
2786 memset(&info->status, 0, sizeof(info->status));
2787 info->flags = IEEE80211_TX_STAT_ACK;
2788 info->flags |= IEEE80211_TX_STAT_AMPDU;
2789 info->status.ampdu_ack_map = successes;
2790 info->status.ampdu_ack_len = agg->frame_count;
2791 iwl_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
2793 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
2799 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
2801 static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
2804 /* Simply stop the queue, but don't change any configuration;
2805 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
2806 iwl_write_prph(priv,
2807 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
2808 (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
2809 (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
2813 * txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE
2814 * priv->lock must be held by the caller
2816 static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
2817 u16 ssn_idx, u8 tx_fifo)
2821 if (IWL49_FIRST_AMPDU_QUEUE > txq_id) {
2822 IWL_WARNING("queue number too small: %d, must be > %d\n",
2823 txq_id, IWL49_FIRST_AMPDU_QUEUE);
2827 ret = iwl_grab_nic_access(priv);
2831 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
2833 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
2835 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
2836 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
2837 /* supposes that ssn_idx is valid (!= 0xFFF) */
2838 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
2840 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
2841 iwl_txq_ctx_deactivate(priv, txq_id);
2842 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
2844 iwl_release_nic_access(priv);
2851 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
2853 * Handles block-acknowledge notification from device, which reports success
2854 * of frames sent via aggregation.
2856 static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
2857 struct iwl_rx_mem_buffer *rxb)
2859 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2860 struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
2862 struct iwl_tx_queue *txq = NULL;
2863 struct iwl_ht_agg *agg;
2864 DECLARE_MAC_BUF(mac);
2866 /* "flow" corresponds to Tx queue */
2867 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
2869 /* "ssn" is start of block-ack Tx window, corresponds to index
2870 * (in Tx queue's circular buffer) of first TFD/frame in window */
2871 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
2873 if (scd_flow >= priv->hw_params.max_txq_num) {
2874 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
2878 txq = &priv->txq[scd_flow];
2879 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
2881 /* Find index just before block-ack window */
2882 index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
2884 /* TODO: Need to get this copy more safely - now good for debug */
2886 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
2889 print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
2891 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
2892 "%d, scd_ssn = %d\n",
2895 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
2898 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
2900 (unsigned long long)agg->bitmap);
2902 /* Update driver's record of ACK vs. not for each frame in window */
2903 iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
2905 /* Release all TFDs before the SSN, i.e. all TFDs in front of
2906 * block-ack window (we assume that they've been successfully
2907 * transmitted ... if not, it's too late anyway). */
2908 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
2909 /* calculate mac80211 ampdu sw queue to wake */
2911 scd_flow - priv->hw_params.first_ampdu_q + priv->hw->queues;
2912 int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
2913 priv->stations[ba_resp->sta_id].
2914 tid[ba_resp->tid].tfds_in_queue -= freed;
2915 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
2916 priv->mac80211_registered &&
2917 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2918 ieee80211_wake_queue(priv->hw, ampdu_q);
2920 iwl_txq_check_empty(priv, ba_resp->sta_id,
2921 ba_resp->tid, scd_flow);
2926 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
2928 static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
2935 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
2937 tbl_dw_addr = priv->scd_base_addr +
2938 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
2940 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
2943 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
2945 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
2947 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
2954 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
2956 * NOTE: txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE,
2957 * i.e. it must be one of the higher queues used for aggregation
2959 static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
2960 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
2962 unsigned long flags;
2966 if (IWL49_FIRST_AMPDU_QUEUE > txq_id)
2967 IWL_WARNING("queue number too small: %d, must be > %d\n",
2968 txq_id, IWL49_FIRST_AMPDU_QUEUE);
2970 ra_tid = BUILD_RAxTID(sta_id, tid);
2972 /* Modify device's station table to Tx this TID */
2973 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
2975 spin_lock_irqsave(&priv->lock, flags);
2976 ret = iwl_grab_nic_access(priv);
2978 spin_unlock_irqrestore(&priv->lock, flags);
2982 /* Stop this Tx queue before configuring it */
2983 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
2985 /* Map receiver-address / traffic-ID to this queue */
2986 iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
2988 /* Set this queue as a chain-building queue */
2989 iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
2991 /* Place first TFD at index corresponding to start sequence number.
2992 * Assumes that ssn_idx is valid (!= 0xFFF) */
2993 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
2994 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
2995 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
2997 /* Set up Tx window size and frame limit for this queue */
2998 iwl_write_targ_mem(priv,
2999 priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
3000 (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
3001 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
3003 iwl_write_targ_mem(priv, priv->scd_base_addr +
3004 IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
3005 (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
3006 & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
3008 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3010 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
3011 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
3013 iwl_release_nic_access(priv);
3014 spin_unlock_irqrestore(&priv->lock, flags);
3019 static int iwl4965_rx_agg_start(struct iwl_priv *priv,
3020 const u8 *addr, int tid, u16 ssn)
3022 unsigned long flags;
3025 sta_id = iwl_find_station(priv, addr);
3026 if (sta_id == IWL_INVALID_STATION)
3029 spin_lock_irqsave(&priv->sta_lock, flags);
3030 priv->stations[sta_id].sta.station_flags_msk = 0;
3031 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
3032 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
3033 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
3034 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3035 spin_unlock_irqrestore(&priv->sta_lock, flags);
3037 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3041 static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
3042 const u8 *addr, int tid)
3044 unsigned long flags;
3047 sta_id = iwl_find_station(priv, addr);
3048 if (sta_id == IWL_INVALID_STATION)
3051 spin_lock_irqsave(&priv->sta_lock, flags);
3052 priv->stations[sta_id].sta.station_flags_msk = 0;
3053 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
3054 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
3055 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3056 spin_unlock_irqrestore(&priv->sta_lock, flags);
3058 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3062 int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3063 enum ieee80211_ampdu_mlme_action action,
3064 const u8 *addr, u16 tid, u16 *ssn)
3066 struct iwl_priv *priv = hw->priv;
3067 DECLARE_MAC_BUF(mac);
3069 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
3070 print_mac(mac, addr), tid);
3073 case IEEE80211_AMPDU_RX_START:
3074 IWL_DEBUG_HT("start Rx\n");
3075 return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
3076 case IEEE80211_AMPDU_RX_STOP:
3077 IWL_DEBUG_HT("stop Rx\n");
3078 return iwl4965_rx_agg_stop(priv, addr, tid);
3079 case IEEE80211_AMPDU_TX_START:
3080 IWL_DEBUG_HT("start Tx\n");
3081 return iwl_tx_agg_start(priv, addr, tid, ssn);
3082 case IEEE80211_AMPDU_TX_STOP:
3083 IWL_DEBUG_HT("stop Tx\n");
3084 return iwl_tx_agg_stop(priv, addr, tid);
3086 IWL_DEBUG_HT("unknown\n");
3093 static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
3097 return (u16) sizeof(struct iwl4965_rxon_cmd);
3103 static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
3105 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
3106 addsta->mode = cmd->mode;
3107 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
3108 memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
3109 addsta->station_flags = cmd->station_flags;
3110 addsta->station_flags_msk = cmd->station_flags_msk;
3111 addsta->tid_disable_tx = cmd->tid_disable_tx;
3112 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
3113 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
3114 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
3115 addsta->reserved1 = __constant_cpu_to_le16(0);
3116 addsta->reserved2 = __constant_cpu_to_le32(0);
3118 return (u16)sizeof(struct iwl4965_addsta_cmd);
3121 static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
3123 return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
3127 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3129 static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
3130 struct iwl_ht_agg *agg,
3131 struct iwl4965_tx_resp *tx_resp,
3132 int txq_id, u16 start_idx)
3135 struct agg_tx_status *frame_status = tx_resp->u.agg_status;
3136 struct ieee80211_tx_info *info = NULL;
3137 struct ieee80211_hdr *hdr = NULL;
3138 u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3141 if (agg->wait_for_ba)
3142 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3144 agg->frame_count = tx_resp->frame_count;
3145 agg->start_idx = start_idx;
3146 agg->rate_n_flags = rate_n_flags;
3149 /* # frames attempted by Tx command */
3150 if (agg->frame_count == 1) {
3151 /* Only one frame was attempted; no block-ack will arrive */
3152 status = le16_to_cpu(frame_status[0].status);
3155 /* FIXME: code repetition */
3156 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3157 agg->frame_count, agg->start_idx, idx);
3159 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
3160 info->status.retry_count = tx_resp->failure_frame;
3161 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
3162 info->flags |= iwl_is_tx_success(status)?
3163 IEEE80211_TX_STAT_ACK : 0;
3164 iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
3165 /* FIXME: code repetition end */
3167 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3168 status & 0xff, tx_resp->failure_frame);
3169 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
3171 agg->wait_for_ba = 0;
3173 /* Two or more frames were attempted; expect block-ack */
3175 int start = agg->start_idx;
3177 /* Construct bit-map of pending frames within Tx window */
3178 for (i = 0; i < agg->frame_count; i++) {
3180 status = le16_to_cpu(frame_status[i].status);
3181 seq = le16_to_cpu(frame_status[i].sequence);
3182 idx = SEQ_TO_INDEX(seq);
3183 txq_id = SEQ_TO_QUEUE(seq);
3185 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3186 AGG_TX_STATE_ABORT_MSK))
3189 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3190 agg->frame_count, txq_id, idx);
3192 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
3194 sc = le16_to_cpu(hdr->seq_ctrl);
3195 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3196 IWL_ERROR("BUG_ON idx doesn't match seq control"
3197 " idx=%d, seq_idx=%d, seq=%d\n",
3203 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3204 i, idx, SEQ_TO_SN(sc));
3208 sh = (start - idx) + 0xff;
3209 bitmap = bitmap << sh;
3212 } else if (sh < -64)
3213 sh = 0xff - (start - idx);
3217 bitmap = bitmap << sh;
3220 bitmap |= (1 << sh);
3221 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3222 start, (u32)(bitmap & 0xFFFFFFFF));
3225 agg->bitmap = bitmap;
3226 agg->start_idx = start;
3227 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3228 agg->frame_count, agg->start_idx,
3229 (unsigned long long)agg->bitmap);
3232 agg->wait_for_ba = 1;
3238 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3240 static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
3241 struct iwl_rx_mem_buffer *rxb)
3243 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3244 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3245 int txq_id = SEQ_TO_QUEUE(sequence);
3246 int index = SEQ_TO_INDEX(sequence);
3247 struct iwl_tx_queue *txq = &priv->txq[txq_id];
3248 struct ieee80211_tx_info *info;
3249 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3250 u32 status = le32_to_cpu(tx_resp->u.status);
3251 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
3253 struct ieee80211_hdr *hdr;
3256 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
3257 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3258 "is out of range [0-%d] %d %d\n", txq_id,
3259 index, txq->q.n_bd, txq->q.write_ptr,
3264 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
3265 memset(&info->status, 0, sizeof(info->status));
3267 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
3268 fc = le16_to_cpu(hdr->frame_control);
3269 if (ieee80211_is_qos_data(fc)) {
3270 qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
3274 sta_id = iwl_get_ra_sta_id(priv, hdr);
3275 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
3276 IWL_ERROR("Station not known\n");
3280 if (txq->sched_retry) {
3281 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3282 struct iwl_ht_agg *agg = NULL;
3287 agg = &priv->stations[sta_id].tid[tid].agg;
3289 iwl4965_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
3291 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
3292 /* TODO: send BAR */
3295 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
3297 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
3298 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3299 "%d index %d\n", scd_ssn , index);
3300 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3301 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3303 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3304 txq_id >= 0 && priv->mac80211_registered &&
3305 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
3306 /* calculate mac80211 ampdu sw queue to wake */
3307 ampdu_q = txq_id - IWL49_FIRST_AMPDU_QUEUE +
3309 if (agg->state == IWL_AGG_OFF)
3310 ieee80211_wake_queue(priv->hw, txq_id);
3312 ieee80211_wake_queue(priv->hw, ampdu_q);
3314 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3317 info->status.retry_count = tx_resp->failure_frame;
3319 iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
3320 iwl_hwrate_to_tx_control(priv,
3321 le32_to_cpu(tx_resp->rate_n_flags),
3324 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
3325 "0x%x retries %d\n", txq_id,
3326 iwl_get_tx_fail_reason(status),
3327 status, le32_to_cpu(tx_resp->rate_n_flags),
3328 tx_resp->failure_frame);
3330 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3333 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3334 if (tid != MAX_TID_COUNT)
3335 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3336 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3337 (txq_id >= 0) && priv->mac80211_registered)
3338 ieee80211_wake_queue(priv->hw, txq_id);
3339 if (tid != MAX_TID_COUNT)
3340 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3344 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3345 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3349 /* Set up 4965-specific Rx frame reply handlers */
3350 static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
3352 /* Legacy Rx frames */
3353 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
3355 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3357 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
3360 static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
3362 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
3365 static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
3367 cancel_work_sync(&priv->txpower_work);
3371 static struct iwl_hcmd_ops iwl4965_hcmd = {
3372 .rxon_assoc = iwl4965_send_rxon_assoc,
3375 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
3376 .get_hcmd_size = iwl4965_get_hcmd_size,
3377 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
3378 .chain_noise_reset = iwl4965_chain_noise_reset,
3379 .gain_computation = iwl4965_gain_computation,
3382 static struct iwl_lib_ops iwl4965_lib = {
3383 .set_hw_params = iwl4965_hw_set_hw_params,
3384 .alloc_shared_mem = iwl4965_alloc_shared_mem,
3385 .free_shared_mem = iwl4965_free_shared_mem,
3386 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
3387 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
3388 .txq_set_sched = iwl4965_txq_set_sched,
3389 .txq_agg_enable = iwl4965_txq_agg_enable,
3390 .txq_agg_disable = iwl4965_txq_agg_disable,
3391 .rx_handler_setup = iwl4965_rx_handler_setup,
3392 .setup_deferred_work = iwl4965_setup_deferred_work,
3393 .cancel_deferred_work = iwl4965_cancel_deferred_work,
3394 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
3395 .alive_notify = iwl4965_alive_notify,
3396 .init_alive_start = iwl4965_init_alive_start,
3397 .load_ucode = iwl4965_load_bsm,
3399 .init = iwl4965_apm_init,
3400 .reset = iwl4965_apm_reset,
3401 .stop = iwl4965_apm_stop,
3402 .config = iwl4965_nic_config,
3403 .set_pwr_src = iwl4965_set_pwr_src,
3406 .regulatory_bands = {
3407 EEPROM_REGULATORY_BAND_1_CHANNELS,
3408 EEPROM_REGULATORY_BAND_2_CHANNELS,
3409 EEPROM_REGULATORY_BAND_3_CHANNELS,
3410 EEPROM_REGULATORY_BAND_4_CHANNELS,
3411 EEPROM_REGULATORY_BAND_5_CHANNELS,
3412 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
3413 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
3415 .verify_signature = iwlcore_eeprom_verify_signature,
3416 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
3417 .release_semaphore = iwlcore_eeprom_release_semaphore,
3418 .check_version = iwl4965_eeprom_check_version,
3419 .query_addr = iwlcore_eeprom_query_addr,
3421 .radio_kill_sw = iwl4965_radio_kill_sw,
3422 .set_power = iwl4965_set_power,
3423 .send_tx_power = iwl4965_send_tx_power,
3424 .update_chain_flags = iwl4965_update_chain_flags,
3427 static struct iwl_ops iwl4965_ops = {
3428 .lib = &iwl4965_lib,
3429 .hcmd = &iwl4965_hcmd,
3430 .utils = &iwl4965_hcmd_utils,
3433 struct iwl_cfg iwl4965_agn_cfg = {
3435 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
3436 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
3437 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
3438 .ops = &iwl4965_ops,
3439 .mod_params = &iwl4965_mod_params,
3442 module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
3443 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
3444 module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
3445 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
3446 module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
3447 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
3448 module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
3449 MODULE_PARM_DESC(debug, "debug output mask");
3451 disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
3452 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
3454 module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
3455 MODULE_PARM_DESC(queues_num, "number of hw queues.");
3458 module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
3459 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
3460 module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
3461 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
3462 module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
3463 MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");