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);
310 int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
314 /* 4965 HT rate format */
315 if (rate_n_flags & RATE_MCS_HT_MSK) {
316 idx = (rate_n_flags & 0xff);
318 if (idx >= IWL_RATE_MIMO2_6M_PLCP)
319 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
321 idx += IWL_FIRST_OFDM_RATE;
322 /* skip 9M not supported in ht*/
323 if (idx >= IWL_RATE_9M_INDEX)
325 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
328 /* 4965 legacy rate format, search for match in table */
330 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
331 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
339 * translate ucode response to mac80211 tx status control values
341 void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
342 struct ieee80211_tx_info *control)
346 control->antenna_sel_tx =
347 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
348 if (rate_n_flags & RATE_MCS_HT_MSK)
349 control->flags |= IEEE80211_TX_CTL_OFDM_HT;
350 if (rate_n_flags & RATE_MCS_GF_MSK)
351 control->flags |= IEEE80211_TX_CTL_GREEN_FIELD;
352 if (rate_n_flags & RATE_MCS_FAT_MSK)
353 control->flags |= IEEE80211_TX_CTL_40_MHZ_WIDTH;
354 if (rate_n_flags & RATE_MCS_DUP_MSK)
355 control->flags |= IEEE80211_TX_CTL_DUP_DATA;
356 if (rate_n_flags & RATE_MCS_SGI_MSK)
357 control->flags |= IEEE80211_TX_CTL_SHORT_GI;
358 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
359 if (control->band == IEEE80211_BAND_5GHZ)
360 rate_index -= IWL_FIRST_OFDM_RATE;
361 control->tx_rate_idx = rate_index;
368 static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
373 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
375 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
377 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
378 calib_ver < EEPROM_4965_TX_POWER_VERSION)
383 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
384 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
385 calib_ver, EEPROM_4965_TX_POWER_VERSION);
389 int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
394 spin_lock_irqsave(&priv->lock, flags);
395 ret = iwl_grab_nic_access(priv);
397 spin_unlock_irqrestore(&priv->lock, flags);
401 if (src == IWL_PWR_SRC_VAUX) {
403 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
406 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
407 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
408 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
409 ~APMG_PS_CTRL_MSK_PWR_SRC);
412 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
413 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
414 ~APMG_PS_CTRL_MSK_PWR_SRC);
417 iwl_release_nic_access(priv);
418 spin_unlock_irqrestore(&priv->lock, flags);
424 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
425 * must be called under priv->lock and mac access
427 static void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask)
429 iwl_write_prph(priv, IWL49_SCD_TXFACT, mask);
432 static int iwl4965_apm_init(struct iwl_priv *priv)
436 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
437 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
439 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
440 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
441 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
443 /* set "initialization complete" bit to move adapter
444 * D0U* --> D0A* state */
445 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
447 /* wait for clock stabilization */
448 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
449 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
450 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
452 IWL_DEBUG_INFO("Failed to init the card\n");
456 ret = iwl_grab_nic_access(priv);
461 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
462 APMG_CLK_VAL_BSM_CLK_RQT);
466 /* disable L1-Active */
467 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
468 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
470 iwl_release_nic_access(priv);
476 static void iwl4965_nic_config(struct iwl_priv *priv)
483 spin_lock_irqsave(&priv->lock, flags);
485 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
486 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
487 /* Enable No Snoop field */
488 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
492 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
494 /* L1 is enabled by BIOS */
495 if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
496 /* diable L0S disabled L1A enabled */
497 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
499 /* L0S enabled L1A disabled */
500 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
502 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
504 /* write radio config values to register */
505 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
506 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
507 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
508 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
509 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
511 /* set CSR_HW_CONFIG_REG for uCode use */
512 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
513 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
514 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
516 priv->calib_info = (struct iwl_eeprom_calib_info *)
517 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
519 spin_unlock_irqrestore(&priv->lock, flags);
522 static int iwl4965_apm_stop_master(struct iwl_priv *priv)
527 spin_lock_irqsave(&priv->lock, flags);
529 /* set stop master bit */
530 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
532 ret = iwl_poll_bit(priv, CSR_RESET,
533 CSR_RESET_REG_FLAG_MASTER_DISABLED,
534 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
539 spin_unlock_irqrestore(&priv->lock, flags);
540 IWL_DEBUG_INFO("stop master\n");
545 static void iwl4965_apm_stop(struct iwl_priv *priv)
549 iwl4965_apm_stop_master(priv);
551 spin_lock_irqsave(&priv->lock, flags);
553 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
557 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
558 spin_unlock_irqrestore(&priv->lock, flags);
561 static int iwl4965_apm_reset(struct iwl_priv *priv)
566 iwl4965_apm_stop_master(priv);
568 spin_lock_irqsave(&priv->lock, flags);
570 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
574 /* FIXME: put here L1A -L0S w/a */
576 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
578 ret = iwl_poll_bit(priv, CSR_RESET,
579 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
580 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
587 ret = iwl_grab_nic_access(priv);
590 /* Enable DMA and BSM Clock */
591 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
592 APMG_CLK_VAL_BSM_CLK_RQT);
597 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
598 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
600 iwl_release_nic_access(priv);
602 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
603 wake_up_interruptible(&priv->wait_command_queue);
606 spin_unlock_irqrestore(&priv->lock, flags);
611 #define REG_RECALIB_PERIOD (60)
613 void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
615 struct iwl4965_ct_kill_config cmd;
619 spin_lock_irqsave(&priv->lock, flags);
620 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
621 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
622 spin_unlock_irqrestore(&priv->lock, flags);
624 cmd.critical_temperature_R =
625 cpu_to_le32(priv->hw_params.ct_kill_threshold);
627 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
630 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
632 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
633 "critical temperature is %d\n",
634 cmd.critical_temperature_R);
637 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
638 * Called after every association, but this runs only once!
639 * ... once chain noise is calibrated the first time, it's good forever. */
640 static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
642 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
644 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
645 struct iwl4965_calibration_cmd cmd;
647 memset(&cmd, 0, sizeof(cmd));
648 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
652 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
654 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
655 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
656 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
660 static void iwl4965_gain_computation(struct iwl_priv *priv,
662 u16 min_average_noise_antenna_i,
663 u32 min_average_noise)
666 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
668 data->delta_gain_code[min_average_noise_antenna_i] = 0;
670 for (i = 0; i < NUM_RX_CHAINS; i++) {
673 if (!(data->disconn_array[i]) &&
674 (data->delta_gain_code[i] ==
675 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
676 delta_g = average_noise[i] - min_average_noise;
677 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
678 data->delta_gain_code[i] =
679 min(data->delta_gain_code[i],
680 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
682 data->delta_gain_code[i] =
683 (data->delta_gain_code[i] | (1 << 2));
685 data->delta_gain_code[i] = 0;
688 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
689 data->delta_gain_code[0],
690 data->delta_gain_code[1],
691 data->delta_gain_code[2]);
693 /* Differential gain gets sent to uCode only once */
694 if (!data->radio_write) {
695 struct iwl4965_calibration_cmd cmd;
696 data->radio_write = 1;
698 memset(&cmd, 0, sizeof(cmd));
699 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
700 cmd.diff_gain_a = data->delta_gain_code[0];
701 cmd.diff_gain_b = data->delta_gain_code[1];
702 cmd.diff_gain_c = data->delta_gain_code[2];
703 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
706 IWL_DEBUG_CALIB("fail sending cmd "
707 "REPLY_PHY_CALIBRATION_CMD \n");
709 /* TODO we might want recalculate
710 * rx_chain in rxon cmd */
712 /* Mark so we run this algo only once! */
713 data->state = IWL_CHAIN_NOISE_CALIBRATED;
715 data->chain_noise_a = 0;
716 data->chain_noise_b = 0;
717 data->chain_noise_c = 0;
718 data->chain_signal_a = 0;
719 data->chain_signal_b = 0;
720 data->chain_signal_c = 0;
721 data->beacon_count = 0;
724 static void iwl4965_bg_txpower_work(struct work_struct *work)
726 struct iwl_priv *priv = container_of(work, struct iwl_priv,
729 /* If a scan happened to start before we got here
730 * then just return; the statistics notification will
731 * kick off another scheduled work to compensate for
732 * any temperature delta we missed here. */
733 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
734 test_bit(STATUS_SCANNING, &priv->status))
737 mutex_lock(&priv->mutex);
739 /* Regardless of if we are assocaited, we must reconfigure the
740 * TX power since frames can be sent on non-radar channels while
742 iwl4965_send_tx_power(priv);
744 /* Update last_temperature to keep is_calib_needed from running
745 * when it isn't needed... */
746 priv->last_temperature = priv->temperature;
748 mutex_unlock(&priv->mutex);
752 * Acquire priv->lock before calling this function !
754 static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
756 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
757 (index & 0xff) | (txq_id << 8));
758 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
762 * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
763 * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
764 * @scd_retry: (1) Indicates queue will be used in aggregation mode
766 * NOTE: Acquire priv->lock before calling this function !
768 static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
769 struct iwl_tx_queue *txq,
770 int tx_fifo_id, int scd_retry)
772 int txq_id = txq->q.id;
774 /* Find out whether to activate Tx queue */
775 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
777 /* Set up and activate */
778 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
779 (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
780 (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
781 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
782 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
783 IWL49_SCD_QUEUE_STTS_REG_MSK);
785 txq->sched_retry = scd_retry;
787 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
788 active ? "Activate" : "Deactivate",
789 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
792 static const u16 default_queue_to_tx_fifo[] = {
802 int iwl4965_alive_notify(struct iwl_priv *priv)
809 spin_lock_irqsave(&priv->lock, flags);
811 ret = iwl_grab_nic_access(priv);
813 spin_unlock_irqrestore(&priv->lock, flags);
817 /* Clear 4965's internal Tx Scheduler data base */
818 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
819 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
820 for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
821 iwl_write_targ_mem(priv, a, 0);
822 for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
823 iwl_write_targ_mem(priv, a, 0);
824 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
825 iwl_write_targ_mem(priv, a, 0);
827 /* Tel 4965 where to find Tx byte count tables */
828 iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
830 offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
832 /* Disable chain mode for all queues */
833 iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
835 /* Initialize each Tx queue (including the command queue) */
836 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
838 /* TFD circular buffer read/write indexes */
839 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
840 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
842 /* Max Tx Window size for Scheduler-ACK mode */
843 iwl_write_targ_mem(priv, priv->scd_base_addr +
844 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
846 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
847 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
850 iwl_write_targ_mem(priv, priv->scd_base_addr +
851 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
854 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
855 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
858 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
859 (1 << priv->hw_params.max_txq_num) - 1);
861 /* Activate all Tx DMA/FIFO channels */
862 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
864 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
866 /* Map each Tx/cmd queue to its corresponding fifo */
867 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
868 int ac = default_queue_to_tx_fifo[i];
869 iwl_txq_ctx_activate(priv, i);
870 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
873 iwl_release_nic_access(priv);
874 spin_unlock_irqrestore(&priv->lock, flags);
879 static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
883 .auto_corr_min_ofdm = 85,
884 .auto_corr_min_ofdm_mrc = 170,
885 .auto_corr_min_ofdm_x1 = 105,
886 .auto_corr_min_ofdm_mrc_x1 = 220,
888 .auto_corr_max_ofdm = 120,
889 .auto_corr_max_ofdm_mrc = 210,
890 .auto_corr_max_ofdm_x1 = 140,
891 .auto_corr_max_ofdm_mrc_x1 = 270,
893 .auto_corr_min_cck = 125,
894 .auto_corr_max_cck = 200,
895 .auto_corr_min_cck_mrc = 200,
896 .auto_corr_max_cck_mrc = 400,
903 * iwl4965_hw_set_hw_params
905 * Called when initializing driver
907 int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
910 if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
911 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
912 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
913 IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
917 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
918 priv->hw_params.first_ampdu_q = IWL49_FIRST_AMPDU_QUEUE;
919 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
920 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
921 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
922 if (priv->cfg->mod_params->amsdu_size_8K)
923 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
925 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
926 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
927 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
928 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
930 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
931 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
932 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
933 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
935 priv->hw_params.tx_chains_num = 2;
936 priv->hw_params.rx_chains_num = 2;
937 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
938 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
939 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
941 priv->hw_params.sens = &iwl4965_sensitivity;
946 /* set card power command */
947 static int iwl4965_set_power(struct iwl_priv *priv,
952 ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
953 sizeof(struct iwl4965_powertable_cmd),
958 static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
971 *res = ((num * 2 + denom) / (denom * 2)) * sign;
977 * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
979 * Determines power supply voltage compensation for txpower calculations.
980 * Returns number of 1/2-dB steps to subtract from gain table index,
981 * to compensate for difference between power supply voltage during
982 * factory measurements, vs. current power supply voltage.
984 * Voltage indication is higher for lower voltage.
985 * Lower voltage requires more gain (lower gain table index).
987 static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
992 if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
993 (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
996 iwl4965_math_div_round(current_voltage - eeprom_voltage,
997 TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
999 if (current_voltage > eeprom_voltage)
1001 if ((comp < -2) || (comp > 2))
1007 static s32 iwl4965_get_tx_atten_grp(u16 channel)
1009 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
1010 channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
1011 return CALIB_CH_GROUP_5;
1013 if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
1014 channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
1015 return CALIB_CH_GROUP_1;
1017 if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
1018 channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
1019 return CALIB_CH_GROUP_2;
1021 if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
1022 channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
1023 return CALIB_CH_GROUP_3;
1025 if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
1026 channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
1027 return CALIB_CH_GROUP_4;
1029 IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
1033 static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
1037 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
1038 if (priv->calib_info->band_info[b].ch_from == 0)
1041 if ((channel >= priv->calib_info->band_info[b].ch_from)
1042 && (channel <= priv->calib_info->band_info[b].ch_to))
1049 static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
1056 iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
1062 * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
1064 * Interpolates factory measurements from the two sample channels within a
1065 * sub-band, to apply to channel of interest. Interpolation is proportional to
1066 * differences in channel frequencies, which is proportional to differences
1067 * in channel number.
1069 static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
1070 struct iwl_eeprom_calib_ch_info *chan_info)
1075 const struct iwl_eeprom_calib_measure *m1;
1076 const struct iwl_eeprom_calib_measure *m2;
1077 struct iwl_eeprom_calib_measure *omeas;
1081 s = iwl4965_get_sub_band(priv, channel);
1082 if (s >= EEPROM_TX_POWER_BANDS) {
1083 IWL_ERROR("Tx Power can not find channel %d ", channel);
1087 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
1088 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
1089 chan_info->ch_num = (u8) channel;
1091 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
1092 channel, s, ch_i1, ch_i2);
1094 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
1095 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
1096 m1 = &(priv->calib_info->band_info[s].ch1.
1097 measurements[c][m]);
1098 m2 = &(priv->calib_info->band_info[s].ch2.
1099 measurements[c][m]);
1100 omeas = &(chan_info->measurements[c][m]);
1103 (u8) iwl4965_interpolate_value(channel, ch_i1,
1108 (u8) iwl4965_interpolate_value(channel, ch_i1,
1109 m1->gain_idx, ch_i2,
1111 omeas->temperature =
1112 (u8) iwl4965_interpolate_value(channel, ch_i1,
1117 (s8) iwl4965_interpolate_value(channel, ch_i1,
1122 ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
1123 m1->actual_pow, m2->actual_pow, omeas->actual_pow);
1125 ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
1126 m1->gain_idx, m2->gain_idx, omeas->gain_idx);
1128 ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
1129 m1->pa_det, m2->pa_det, omeas->pa_det);
1131 ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
1132 m1->temperature, m2->temperature,
1133 omeas->temperature);
1140 /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
1141 * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
1142 static s32 back_off_table[] = {
1143 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
1144 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
1145 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
1146 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
1150 /* Thermal compensation values for txpower for various frequency ranges ...
1151 * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
1152 static struct iwl4965_txpower_comp_entry {
1153 s32 degrees_per_05db_a;
1154 s32 degrees_per_05db_a_denom;
1155 } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
1156 {9, 2}, /* group 0 5.2, ch 34-43 */
1157 {4, 1}, /* group 1 5.2, ch 44-70 */
1158 {4, 1}, /* group 2 5.2, ch 71-124 */
1159 {4, 1}, /* group 3 5.2, ch 125-200 */
1160 {3, 1} /* group 4 2.4, ch all */
1163 static s32 get_min_power_index(s32 rate_power_index, u32 band)
1166 if ((rate_power_index & 7) <= 4)
1167 return MIN_TX_GAIN_INDEX_52GHZ_EXT;
1169 return MIN_TX_GAIN_INDEX;
1177 static const struct gain_entry gain_table[2][108] = {
1178 /* 5.2GHz power gain index table */
1180 {123, 0x3F}, /* highest txpower */
1289 /* 2.4GHz power gain index table */
1291 {110, 0x3f}, /* highest txpower */
1402 static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
1403 u8 is_fat, u8 ctrl_chan_high,
1404 struct iwl4965_tx_power_db *tx_power_tbl)
1406 u8 saturation_power;
1408 s32 user_target_power;
1412 s32 current_regulatory;
1413 s32 txatten_grp = CALIB_CH_GROUP_MAX;
1416 const struct iwl_channel_info *ch_info = NULL;
1417 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
1418 const struct iwl_eeprom_calib_measure *measurement;
1421 s32 voltage_compensation;
1422 s32 degrees_per_05db_num;
1423 s32 degrees_per_05db_denom;
1425 s32 temperature_comp[2];
1426 s32 factory_gain_index[2];
1427 s32 factory_actual_pwr[2];
1430 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
1431 * are used for indexing into txpower table) */
1432 user_target_power = 2 * priv->tx_power_user_lmt;
1434 /* Get current (RXON) channel, band, width */
1435 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
1438 ch_info = iwl_get_channel_info(priv, priv->band, channel);
1440 if (!is_channel_valid(ch_info))
1443 /* get txatten group, used to select 1) thermal txpower adjustment
1444 * and 2) mimo txpower balance between Tx chains. */
1445 txatten_grp = iwl4965_get_tx_atten_grp(channel);
1446 if (txatten_grp < 0)
1449 IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
1450 channel, txatten_grp);
1459 /* hardware txpower limits ...
1460 * saturation (clipping distortion) txpowers are in half-dBm */
1462 saturation_power = priv->calib_info->saturation_power24;
1464 saturation_power = priv->calib_info->saturation_power52;
1466 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
1467 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
1469 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
1471 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
1474 /* regulatory txpower limits ... reg_limit values are in half-dBm,
1475 * max_power_avg values are in dBm, convert * 2 */
1477 reg_limit = ch_info->fat_max_power_avg * 2;
1479 reg_limit = ch_info->max_power_avg * 2;
1481 if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
1482 (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
1484 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
1486 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
1489 /* Interpolate txpower calibration values for this channel,
1490 * based on factory calibration tests on spaced channels. */
1491 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
1493 /* calculate tx gain adjustment based on power supply voltage */
1494 voltage = priv->calib_info->voltage;
1495 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
1496 voltage_compensation =
1497 iwl4965_get_voltage_compensation(voltage, init_voltage);
1499 IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
1501 voltage, voltage_compensation);
1503 /* get current temperature (Celsius) */
1504 current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
1505 current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
1506 current_temp = KELVIN_TO_CELSIUS(current_temp);
1508 /* select thermal txpower adjustment params, based on channel group
1509 * (same frequency group used for mimo txatten adjustment) */
1510 degrees_per_05db_num =
1511 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
1512 degrees_per_05db_denom =
1513 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
1515 /* get per-chain txpower values from factory measurements */
1516 for (c = 0; c < 2; c++) {
1517 measurement = &ch_eeprom_info.measurements[c][1];
1519 /* txgain adjustment (in half-dB steps) based on difference
1520 * between factory and current temperature */
1521 factory_temp = measurement->temperature;
1522 iwl4965_math_div_round((current_temp - factory_temp) *
1523 degrees_per_05db_denom,
1524 degrees_per_05db_num,
1525 &temperature_comp[c]);
1527 factory_gain_index[c] = measurement->gain_idx;
1528 factory_actual_pwr[c] = measurement->actual_pow;
1530 IWL_DEBUG_TXPOWER("chain = %d\n", c);
1531 IWL_DEBUG_TXPOWER("fctry tmp %d, "
1532 "curr tmp %d, comp %d steps\n",
1533 factory_temp, current_temp,
1534 temperature_comp[c]);
1536 IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
1537 factory_gain_index[c],
1538 factory_actual_pwr[c]);
1541 /* for each of 33 bit-rates (including 1 for CCK) */
1542 for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
1544 union iwl4965_tx_power_dual_stream tx_power;
1546 /* for mimo, reduce each chain's txpower by half
1547 * (3dB, 6 steps), so total output power is regulatory
1550 current_regulatory = reg_limit -
1551 IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
1554 current_regulatory = reg_limit;
1558 /* find txpower limit, either hardware or regulatory */
1559 power_limit = saturation_power - back_off_table[i];
1560 if (power_limit > current_regulatory)
1561 power_limit = current_regulatory;
1563 /* reduce user's txpower request if necessary
1564 * for this rate on this channel */
1565 target_power = user_target_power;
1566 if (target_power > power_limit)
1567 target_power = power_limit;
1569 IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
1570 i, saturation_power - back_off_table[i],
1571 current_regulatory, user_target_power,
1574 /* for each of 2 Tx chains (radio transmitters) */
1575 for (c = 0; c < 2; c++) {
1580 (s32)le32_to_cpu(priv->card_alive_init.
1581 tx_atten[txatten_grp][c]);
1585 /* calculate index; higher index means lower txpower */
1586 power_index = (u8) (factory_gain_index[c] -
1588 factory_actual_pwr[c]) -
1589 temperature_comp[c] -
1590 voltage_compensation +
1593 /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
1596 if (power_index < get_min_power_index(i, band))
1597 power_index = get_min_power_index(i, band);
1599 /* adjust 5 GHz index to support negative indexes */
1603 /* CCK, rate 32, reduce txpower for CCK */
1604 if (i == POWER_TABLE_CCK_ENTRY)
1606 IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
1608 /* stay within the table! */
1609 if (power_index > 107) {
1610 IWL_WARNING("txpower index %d > 107\n",
1614 if (power_index < 0) {
1615 IWL_WARNING("txpower index %d < 0\n",
1620 /* fill txpower command for this rate/chain */
1621 tx_power.s.radio_tx_gain[c] =
1622 gain_table[band][power_index].radio;
1623 tx_power.s.dsp_predis_atten[c] =
1624 gain_table[band][power_index].dsp;
1626 IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
1627 "gain 0x%02x dsp %d\n",
1628 c, atten_value, power_index,
1629 tx_power.s.radio_tx_gain[c],
1630 tx_power.s.dsp_predis_atten[c]);
1631 }/* for each chain */
1633 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
1635 }/* for each rate */
1641 * iwl4965_send_tx_power - Configure the TXPOWER level user limit
1643 * Uses the active RXON for channel, band, and characteristics (fat, high)
1644 * The power limit is taken from priv->tx_power_user_lmt.
1646 static int iwl4965_send_tx_power(struct iwl_priv *priv)
1648 struct iwl4965_txpowertable_cmd cmd = { 0 };
1652 u8 ctrl_chan_high = 0;
1654 if (test_bit(STATUS_SCANNING, &priv->status)) {
1655 /* If this gets hit a lot, switch it to a BUG() and catch
1656 * the stack trace to find out who is calling this during
1658 IWL_WARNING("TX Power requested while scanning!\n");
1662 band = priv->band == IEEE80211_BAND_2GHZ;
1664 is_fat = is_fat_channel(priv->active_rxon.flags);
1667 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1671 cmd.channel = priv->active_rxon.channel;
1673 ret = iwl4965_fill_txpower_tbl(priv, band,
1674 le16_to_cpu(priv->active_rxon.channel),
1675 is_fat, ctrl_chan_high, &cmd.tx_power);
1679 ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
1685 static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1688 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1689 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1690 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1692 if ((rxon1->flags == rxon2->flags) &&
1693 (rxon1->filter_flags == rxon2->filter_flags) &&
1694 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1695 (rxon1->ofdm_ht_single_stream_basic_rates ==
1696 rxon2->ofdm_ht_single_stream_basic_rates) &&
1697 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1698 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1699 (rxon1->rx_chain == rxon2->rx_chain) &&
1700 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1701 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1705 rxon_assoc.flags = priv->staging_rxon.flags;
1706 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1707 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1708 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1709 rxon_assoc.reserved = 0;
1710 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1711 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1712 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1713 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1714 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1716 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1717 sizeof(rxon_assoc), &rxon_assoc, NULL);
1725 int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1730 u8 ctrl_chan_high = 0;
1731 struct iwl4965_channel_switch_cmd cmd = { 0 };
1732 const struct iwl_channel_info *ch_info;
1734 band = priv->band == IEEE80211_BAND_2GHZ;
1736 ch_info = iwl_get_channel_info(priv, priv->band, channel);
1738 is_fat = is_fat_channel(priv->staging_rxon.flags);
1741 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1745 cmd.expect_beacon = 0;
1746 cmd.channel = cpu_to_le16(channel);
1747 cmd.rxon_flags = priv->active_rxon.flags;
1748 cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
1749 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
1751 cmd.expect_beacon = is_channel_radar(ch_info);
1753 cmd.expect_beacon = 1;
1755 rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
1756 ctrl_chan_high, &cmd.tx_power);
1758 IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
1762 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
1766 static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
1768 struct iwl4965_shared *s = priv->shared_virt;
1769 return le32_to_cpu(s->rb_closed) & 0xFFF;
1772 int iwl4965_hw_get_temperature(struct iwl_priv *priv)
1774 return priv->temperature;
1777 unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
1778 struct iwl_frame *frame, u8 rate)
1780 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
1781 unsigned int frame_size;
1783 tx_beacon_cmd = &frame->u.beacon;
1784 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
1786 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
1787 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
1789 frame_size = iwl4965_fill_beacon_frame(priv,
1790 tx_beacon_cmd->frame,
1792 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
1794 BUG_ON(frame_size > MAX_MPDU_SIZE);
1795 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
1797 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
1798 tx_beacon_cmd->tx.rate_n_flags =
1799 iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
1801 tx_beacon_cmd->tx.rate_n_flags =
1802 iwl4965_hw_set_rate_n_flags(rate, 0);
1804 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
1805 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
1806 return (sizeof(*tx_beacon_cmd) + frame_size);
1809 static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
1811 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
1812 sizeof(struct iwl4965_shared),
1813 &priv->shared_phys);
1814 if (!priv->shared_virt)
1817 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
1819 priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed);
1824 static void iwl4965_free_shared_mem(struct iwl_priv *priv)
1826 if (priv->shared_virt)
1827 pci_free_consistent(priv->pci_dev,
1828 sizeof(struct iwl4965_shared),
1834 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
1836 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
1837 struct iwl_tx_queue *txq,
1841 int txq_id = txq->q.id;
1842 struct iwl4965_shared *shared_data = priv->shared_virt;
1844 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
1846 /* Set up byte count within first 256 entries */
1847 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
1848 tfd_offset[txq->q.write_ptr], byte_cnt, len);
1850 /* If within first 64 entries, duplicate at end */
1851 if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
1852 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
1853 tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
1858 * sign_extend - Sign extend a value using specified bit as sign-bit
1860 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
1861 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
1863 * @param oper value to sign extend
1864 * @param index 0 based bit index (0<=index<32) to sign bit
1866 static s32 sign_extend(u32 oper, int index)
1868 u8 shift = 31 - index;
1870 return (s32)(oper << shift) >> shift;
1874 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
1875 * @statistics: Provides the temperature reading from the uCode
1877 * A return of <0 indicates bogus data in the statistics
1879 int iwl4965_get_temperature(const struct iwl_priv *priv)
1886 if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
1887 (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
1888 IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
1889 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
1890 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
1891 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
1892 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
1894 IWL_DEBUG_TEMP("Running temperature calibration\n");
1895 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
1896 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
1897 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
1898 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
1902 * Temperature is only 23 bits, so sign extend out to 32.
1904 * NOTE If we haven't received a statistics notification yet
1905 * with an updated temperature, use R4 provided to us in the
1906 * "initialize" ALIVE response.
1908 if (!test_bit(STATUS_TEMPERATURE, &priv->status))
1909 vt = sign_extend(R4, 23);
1912 le32_to_cpu(priv->statistics.general.temperature), 23);
1914 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
1918 IWL_ERROR("Calibration conflict R1 == R3\n");
1922 /* Calculate temperature in degrees Kelvin, adjust by 97%.
1923 * Add offset to center the adjustment around 0 degrees Centigrade. */
1924 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
1925 temperature /= (R3 - R1);
1926 temperature = (temperature * 97) / 100 +
1927 TEMPERATURE_CALIB_KELVIN_OFFSET;
1929 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
1930 KELVIN_TO_CELSIUS(temperature));
1935 /* Adjust Txpower only if temperature variance is greater than threshold. */
1936 #define IWL_TEMPERATURE_THRESHOLD 3
1939 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
1941 * If the temperature changed has changed sufficiently, then a recalibration
1944 * Assumes caller will replace priv->last_temperature once calibration
1947 static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
1951 if (!test_bit(STATUS_STATISTICS, &priv->status)) {
1952 IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
1956 temp_diff = priv->temperature - priv->last_temperature;
1958 /* get absolute value */
1959 if (temp_diff < 0) {
1960 IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
1961 temp_diff = -temp_diff;
1962 } else if (temp_diff == 0)
1963 IWL_DEBUG_POWER("Same temp, \n");
1965 IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
1967 if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
1968 IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
1972 IWL_DEBUG_POWER("Thermal txpower calib needed\n");
1977 /* Calculate noise level, based on measurements during network silence just
1978 * before arriving beacon. This measurement can be done only if we know
1979 * exactly when to expect beacons, therefore only when we're associated. */
1980 static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
1982 struct statistics_rx_non_phy *rx_info
1983 = &(priv->statistics.rx.general);
1984 int num_active_rx = 0;
1985 int total_silence = 0;
1987 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
1989 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
1991 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
1993 if (bcn_silence_a) {
1994 total_silence += bcn_silence_a;
1997 if (bcn_silence_b) {
1998 total_silence += bcn_silence_b;
2001 if (bcn_silence_c) {
2002 total_silence += bcn_silence_c;
2006 /* Average among active antennas */
2008 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
2010 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2012 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
2013 bcn_silence_a, bcn_silence_b, bcn_silence_c,
2014 priv->last_rx_noise);
2017 void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
2018 struct iwl_rx_mem_buffer *rxb)
2020 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2024 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
2025 (int)sizeof(priv->statistics), pkt->len);
2027 change = ((priv->statistics.general.temperature !=
2028 pkt->u.stats.general.temperature) ||
2029 ((priv->statistics.flag &
2030 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
2031 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
2033 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
2035 set_bit(STATUS_STATISTICS, &priv->status);
2037 /* Reschedule the statistics timer to occur in
2038 * REG_RECALIB_PERIOD seconds to ensure we get a
2039 * thermal update even if the uCode doesn't give
2041 mod_timer(&priv->statistics_periodic, jiffies +
2042 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
2044 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2045 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
2046 iwl4965_rx_calc_noise(priv);
2047 queue_work(priv->workqueue, &priv->run_time_calib_work);
2050 iwl_leds_background(priv);
2052 /* If the hardware hasn't reported a change in
2053 * temperature then don't bother computing a
2054 * calibrated temperature value */
2058 temp = iwl4965_get_temperature(priv);
2062 if (priv->temperature != temp) {
2063 if (priv->temperature)
2064 IWL_DEBUG_TEMP("Temperature changed "
2065 "from %dC to %dC\n",
2066 KELVIN_TO_CELSIUS(priv->temperature),
2067 KELVIN_TO_CELSIUS(temp));
2069 IWL_DEBUG_TEMP("Temperature "
2070 "initialized to %dC\n",
2071 KELVIN_TO_CELSIUS(temp));
2074 priv->temperature = temp;
2075 set_bit(STATUS_TEMPERATURE, &priv->status);
2077 if (!priv->disable_tx_power_cal &&
2078 unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2079 iwl4965_is_temp_calib_needed(priv))
2080 queue_work(priv->workqueue, &priv->txpower_work);
2083 static void iwl4965_add_radiotap(struct iwl_priv *priv,
2084 struct sk_buff *skb,
2085 struct iwl4965_rx_phy_res *rx_start,
2086 struct ieee80211_rx_status *stats,
2089 s8 signal = stats->signal;
2091 int rate = stats->rate_idx;
2092 u64 tsf = stats->mactime;
2094 __le16 phy_flags_hw = rx_start->phy_flags;
2095 struct iwl4965_rt_rx_hdr {
2096 struct ieee80211_radiotap_header rt_hdr;
2097 __le64 rt_tsf; /* TSF */
2098 u8 rt_flags; /* radiotap packet flags */
2099 u8 rt_rate; /* rate in 500kb/s */
2100 __le16 rt_channelMHz; /* channel in MHz */
2101 __le16 rt_chbitmask; /* channel bitfield */
2102 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
2104 u8 rt_antenna; /* antenna number */
2105 } __attribute__ ((packed)) *iwl4965_rt;
2107 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
2108 if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
2109 if (net_ratelimit())
2110 printk(KERN_ERR "not enough headroom [%d] for "
2111 "radiotap head [%zd]\n",
2112 skb_headroom(skb), sizeof(*iwl4965_rt));
2116 /* put radiotap header in front of 802.11 header and data */
2117 iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
2119 /* initialise radiotap header */
2120 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2121 iwl4965_rt->rt_hdr.it_pad = 0;
2123 /* total header + data */
2124 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
2125 &iwl4965_rt->rt_hdr.it_len);
2127 /* Indicate all the fields we add to the radiotap header */
2128 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
2129 (1 << IEEE80211_RADIOTAP_FLAGS) |
2130 (1 << IEEE80211_RADIOTAP_RATE) |
2131 (1 << IEEE80211_RADIOTAP_CHANNEL) |
2132 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
2133 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
2134 (1 << IEEE80211_RADIOTAP_ANTENNA)),
2135 &iwl4965_rt->rt_hdr.it_present);
2137 /* Zero the flags, we'll add to them as we go */
2138 iwl4965_rt->rt_flags = 0;
2140 put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
2142 iwl4965_rt->rt_dbmsignal = signal;
2143 iwl4965_rt->rt_dbmnoise = noise;
2145 /* Convert the channel frequency and set the flags */
2146 put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
2147 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
2148 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2149 IEEE80211_CHAN_5GHZ),
2150 &iwl4965_rt->rt_chbitmask);
2151 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
2152 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
2153 IEEE80211_CHAN_2GHZ),
2154 &iwl4965_rt->rt_chbitmask);
2156 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2157 IEEE80211_CHAN_2GHZ),
2158 &iwl4965_rt->rt_chbitmask);
2161 iwl4965_rt->rt_rate = 0;
2163 iwl4965_rt->rt_rate = iwl_rates[rate].ieee;
2168 * It seems that the antenna field in the phy flags value
2169 * is actually a bitfield. This is undefined by radiotap,
2170 * it wants an actual antenna number but I always get "7"
2171 * for most legacy frames I receive indicating that the
2172 * same frame was received on all three RX chains.
2174 * I think this field should be removed in favour of a
2175 * new 802.11n radiotap field "RX chains" that is defined
2178 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
2179 iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
2181 /* set the preamble flag if appropriate */
2182 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
2183 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
2185 stats->flag |= RX_FLAG_RADIOTAP;
2188 static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2190 /* 0 - mgmt, 1 - cnt, 2 - data */
2191 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2192 priv->rx_stats[idx].cnt++;
2193 priv->rx_stats[idx].bytes += len;
2197 * returns non-zero if packet should be dropped
2199 static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2200 struct ieee80211_hdr *hdr,
2202 struct ieee80211_rx_status *stats)
2204 u16 fc = le16_to_cpu(hdr->frame_control);
2206 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2209 if (!(fc & IEEE80211_FCTL_PROTECTED))
2212 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2213 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2214 case RX_RES_STATUS_SEC_TYPE_TKIP:
2215 /* The uCode has got a bad phase 1 Key, pushes the packet.
2216 * Decryption will be done in SW. */
2217 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2218 RX_RES_STATUS_BAD_KEY_TTAK)
2221 case RX_RES_STATUS_SEC_TYPE_WEP:
2222 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2223 RX_RES_STATUS_BAD_ICV_MIC) {
2224 /* bad ICV, the packet is destroyed since the
2225 * decryption is inplace, drop it */
2226 IWL_DEBUG_RX("Packet destroyed\n");
2229 case RX_RES_STATUS_SEC_TYPE_CCMP:
2230 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2231 RX_RES_STATUS_DECRYPT_OK) {
2232 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2233 stats->flag |= RX_FLAG_DECRYPTED;
2243 static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
2245 u32 decrypt_out = 0;
2247 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
2248 RX_RES_STATUS_STATION_FOUND)
2249 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
2250 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
2252 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
2254 /* packet was not encrypted */
2255 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2256 RX_RES_STATUS_SEC_TYPE_NONE)
2259 /* packet was encrypted with unknown alg */
2260 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2261 RX_RES_STATUS_SEC_TYPE_ERR)
2264 /* decryption was not done in HW */
2265 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
2266 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
2269 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
2271 case RX_RES_STATUS_SEC_TYPE_CCMP:
2272 /* alg is CCM: check MIC only */
2273 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
2275 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2277 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2281 case RX_RES_STATUS_SEC_TYPE_TKIP:
2282 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
2284 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
2287 /* fall through if TTAK OK */
2289 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
2290 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2292 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2296 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
2297 decrypt_in, decrypt_out);
2302 static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
2304 struct iwl_rx_mem_buffer *rxb,
2305 struct ieee80211_rx_status *stats)
2307 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2308 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2309 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
2310 struct ieee80211_hdr *hdr;
2313 unsigned int skblen;
2315 u32 ampdu_status_legacy;
2317 if (!include_phy && priv->last_phy_res[0])
2318 rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2321 IWL_ERROR("MPDU frame without a PHY data\n");
2325 hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
2326 rx_start->cfg_phy_cnt);
2328 len = le16_to_cpu(rx_start->byte_count);
2330 rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
2331 sizeof(struct iwl4965_rx_phy_res) +
2332 rx_start->cfg_phy_cnt + len);
2335 struct iwl4965_rx_mpdu_res_start *amsdu =
2336 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2338 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
2339 sizeof(struct iwl4965_rx_mpdu_res_start));
2340 len = le16_to_cpu(amsdu->byte_count);
2341 rx_start->byte_count = amsdu->byte_count;
2342 rx_end = (__le32 *) (((u8 *) hdr) + len);
2344 /* In monitor mode allow 802.11 ACk frames (10 bytes) */
2345 if (len > priv->hw_params.max_pkt_size ||
2346 len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) {
2347 IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
2351 ampdu_status = le32_to_cpu(*rx_end);
2352 skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
2355 /* New status scheme, need to translate */
2356 ampdu_status_legacy = ampdu_status;
2357 ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status);
2360 /* start from MAC */
2361 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
2362 skb_put(rxb->skb, len); /* end where data ends */
2364 /* We only process data packets if the interface is open */
2365 if (unlikely(!priv->is_open)) {
2366 IWL_DEBUG_DROP_LIMIT
2367 ("Dropping packet while interface is not open.\n");
2372 hdr = (struct ieee80211_hdr *)rxb->skb->data;
2374 /* in case of HW accelerated crypto and bad decryption, drop */
2375 if (!priv->hw_params.sw_crypto &&
2376 iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
2379 if (priv->add_radiotap)
2380 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
2382 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
2383 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
2384 priv->alloc_rxb_skb--;
2388 /* Calc max signal level (dBm) among 3 possible receivers */
2389 static int iwl4965_calc_rssi(struct iwl_priv *priv,
2390 struct iwl4965_rx_phy_res *rx_resp)
2392 /* data from PHY/DSP regarding signal strength, etc.,
2393 * contents are always there, not configurable by host. */
2394 struct iwl4965_rx_non_cfg_phy *ncphy =
2395 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
2396 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
2399 u32 valid_antennae =
2400 (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
2401 >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
2405 /* Find max rssi among 3 possible receivers.
2406 * These values are measured by the digital signal processor (DSP).
2407 * They should stay fairly constant even as the signal strength varies,
2408 * if the radio's automatic gain control (AGC) is working right.
2409 * AGC value (see below) will provide the "interesting" info. */
2410 for (i = 0; i < 3; i++)
2411 if (valid_antennae & (1 << i))
2412 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
2414 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
2415 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
2418 /* dBm = max_rssi dB - agc dB - constant.
2419 * Higher AGC (higher radio gain) means lower signal. */
2420 return (max_rssi - agc - IWL_RSSI_OFFSET);
2423 static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
2425 unsigned long flags;
2427 spin_lock_irqsave(&priv->sta_lock, flags);
2428 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
2429 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
2430 priv->stations[sta_id].sta.sta.modify_mask = 0;
2431 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
2432 spin_unlock_irqrestore(&priv->sta_lock, flags);
2434 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
2437 static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
2439 /* FIXME: need locking over ps_status ??? */
2440 u8 sta_id = iwl_find_station(priv, addr);
2442 if (sta_id != IWL_INVALID_STATION) {
2443 u8 sta_awake = priv->stations[sta_id].
2444 ps_status == STA_PS_STATUS_WAKE;
2446 if (sta_awake && ps_bit)
2447 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
2448 else if (!sta_awake && !ps_bit) {
2449 iwl4965_sta_modify_ps_wake(priv, sta_id);
2450 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
2454 #ifdef CONFIG_IWLWIFI_DEBUG
2457 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
2459 * You may hack this function to show different aspects of received frames,
2460 * including selective frame dumps.
2461 * group100 parameter selects whether to show 1 out of 100 good frames.
2463 * TODO: This was originally written for 3945, need to audit for
2464 * proper operation with 4965.
2466 static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2467 struct iwl_rx_packet *pkt,
2468 struct ieee80211_hdr *header, int group100)
2471 u32 print_summary = 0;
2472 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
2489 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
2490 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
2491 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
2492 u8 *data = IWL_RX_DATA(pkt);
2494 if (likely(!(priv->debug_level & IWL_DL_RX)))
2498 fc = le16_to_cpu(header->frame_control);
2499 seq_ctl = le16_to_cpu(header->seq_ctrl);
2502 channel = le16_to_cpu(rx_hdr->channel);
2503 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
2504 rate_sym = rx_hdr->rate;
2505 length = le16_to_cpu(rx_hdr->len);
2507 /* end-of-frame status and timestamp */
2508 status = le32_to_cpu(rx_end->status);
2509 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
2510 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
2511 tsf = le64_to_cpu(rx_end->timestamp);
2513 /* signal statistics */
2514 rssi = rx_stats->rssi;
2515 agc = rx_stats->agc;
2516 sig_avg = le16_to_cpu(rx_stats->sig_avg);
2517 noise_diff = le16_to_cpu(rx_stats->noise_diff);
2519 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
2521 /* if data frame is to us and all is good,
2522 * (optionally) print summary for only 1 out of every 100 */
2523 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
2524 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
2527 print_summary = 1; /* print each frame */
2528 else if (priv->framecnt_to_us < 100) {
2529 priv->framecnt_to_us++;
2532 priv->framecnt_to_us = 0;
2537 /* print summary for all other frames */
2541 if (print_summary) {
2547 title = "100Frames";
2548 else if (fc & IEEE80211_FCTL_RETRY)
2550 else if (ieee80211_is_assoc_response(fc))
2552 else if (ieee80211_is_reassoc_response(fc))
2554 else if (ieee80211_is_probe_response(fc)) {
2556 print_dump = 1; /* dump frame contents */
2557 } else if (ieee80211_is_beacon(fc)) {
2559 print_dump = 1; /* dump frame contents */
2560 } else if (ieee80211_is_atim(fc))
2562 else if (ieee80211_is_auth(fc))
2564 else if (ieee80211_is_deauth(fc))
2566 else if (ieee80211_is_disassoc(fc))
2571 rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
2572 if (unlikely(rate_idx == -1))
2575 bitrate = iwl_rates[rate_idx].ieee / 2;
2577 /* print frame summary.
2578 * MAC addresses show just the last byte (for brevity),
2579 * but you can hack it to show more, if you'd like to. */
2581 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
2582 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
2583 title, fc, header->addr1[5],
2584 length, rssi, channel, bitrate);
2586 /* src/dst addresses assume managed mode */
2587 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
2588 "src=0x%02x, rssi=%u, tim=%lu usec, "
2589 "phy=0x%02x, chnl=%d\n",
2590 title, fc, header->addr1[5],
2591 header->addr3[5], rssi,
2592 tsf_low - priv->scan_start_tsf,
2593 phy_flags, channel);
2597 iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
2600 static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2601 struct iwl_rx_packet *pkt,
2602 struct ieee80211_hdr *header,
2610 /* Called for REPLY_RX (legacy ABG frames), or
2611 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
2612 void iwl4965_rx_reply_rx(struct iwl_priv *priv,
2613 struct iwl_rx_mem_buffer *rxb)
2615 struct ieee80211_hdr *header;
2616 struct ieee80211_rx_status rx_status;
2617 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2618 /* Use phy data (Rx signal strength, etc.) contained within
2619 * this rx packet for legacy frames,
2620 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
2621 int include_phy = (pkt->hdr.cmd == REPLY_RX);
2622 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2623 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
2624 (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2626 unsigned int len = 0;
2630 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
2632 ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
2633 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
2634 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
2635 rx_status.rate_idx =
2636 iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
2637 if (rx_status.band == IEEE80211_BAND_5GHZ)
2638 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
2640 rx_status.antenna = 0;
2643 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
2644 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
2645 rx_start->cfg_phy_cnt);
2650 if (priv->last_phy_res[0])
2651 rx_start = (struct iwl4965_rx_phy_res *)
2652 &priv->last_phy_res[1];
2658 IWL_ERROR("MPDU frame without a PHY data\n");
2663 header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
2664 + rx_start->cfg_phy_cnt);
2666 len = le16_to_cpu(rx_start->byte_count);
2667 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
2668 sizeof(struct iwl4965_rx_phy_res) + len);
2670 struct iwl4965_rx_mpdu_res_start *amsdu =
2671 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2673 header = (void *)(pkt->u.raw +
2674 sizeof(struct iwl4965_rx_mpdu_res_start));
2675 len = le16_to_cpu(amsdu->byte_count);
2676 rx_end = (__le32 *) (pkt->u.raw +
2677 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
2680 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
2681 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
2682 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
2683 le32_to_cpu(*rx_end));
2687 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
2689 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
2690 rx_status.signal = iwl4965_calc_rssi(priv, rx_start);
2692 /* Meaningful noise values are available only from beacon statistics,
2693 * which are gathered only when associated, and indicate noise
2694 * only for the associated network channel ...
2695 * Ignore these noise values while scanning (other channels) */
2696 if (iwl_is_associated(priv) &&
2697 !test_bit(STATUS_SCANNING, &priv->status)) {
2698 rx_status.noise = priv->last_rx_noise;
2699 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal,
2702 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2703 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, 0);
2706 /* Reset beacon noise level if not associated. */
2707 if (!iwl_is_associated(priv))
2708 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2710 /* Set "1" to report good data frames in groups of 100 */
2711 /* FIXME: need to optimze the call: */
2712 iwl4965_dbg_report_frame(priv, pkt, header, 1);
2714 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
2715 rx_status.signal, rx_status.noise, rx_status.signal,
2716 (unsigned long long)rx_status.mactime);
2719 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2720 iwl4965_handle_data_packet(priv, 1, include_phy,
2725 network_packet = iwl4965_is_network_packet(priv, header);
2726 if (network_packet) {
2727 priv->last_rx_rssi = rx_status.signal;
2728 priv->last_beacon_time = priv->ucode_beacon_time;
2729 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
2732 fc = le16_to_cpu(header->frame_control);
2733 switch (fc & IEEE80211_FCTL_FTYPE) {
2734 case IEEE80211_FTYPE_MGMT:
2735 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2736 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2738 iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
2741 case IEEE80211_FTYPE_CTL:
2742 switch (fc & IEEE80211_FCTL_STYPE) {
2743 case IEEE80211_STYPE_BACK_REQ:
2744 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
2745 iwl4965_handle_data_packet(priv, 0, include_phy,
2753 case IEEE80211_FTYPE_DATA: {
2754 DECLARE_MAC_BUF(mac1);
2755 DECLARE_MAC_BUF(mac2);
2756 DECLARE_MAC_BUF(mac3);
2758 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2759 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2762 if (unlikely(!network_packet))
2763 IWL_DEBUG_DROP("Dropping (non network): "
2765 print_mac(mac1, header->addr1),
2766 print_mac(mac2, header->addr2),
2767 print_mac(mac3, header->addr3));
2768 else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
2769 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
2770 print_mac(mac1, header->addr1),
2771 print_mac(mac2, header->addr2),
2772 print_mac(mac3, header->addr3));
2774 iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
2785 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
2787 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
2788 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
2790 static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
2791 struct iwl_ht_agg *agg,
2792 struct iwl4965_compressed_ba_resp*
2797 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
2798 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
2801 struct ieee80211_tx_info *info;
2803 if (unlikely(!agg->wait_for_ba)) {
2804 IWL_ERROR("Received BA when not expected\n");
2808 /* Mark that the expected block-ack response arrived */
2809 agg->wait_for_ba = 0;
2810 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
2812 /* Calculate shift to align block-ack bits with our Tx window bits */
2813 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
2814 if (sh < 0) /* tbw something is wrong with indices */
2817 /* don't use 64-bit values for now */
2818 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
2820 if (agg->frame_count > (64 - sh)) {
2821 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
2825 /* check for success or failure according to the
2826 * transmitted bitmap and block-ack bitmap */
2827 bitmap &= agg->bitmap;
2829 /* For each frame attempted in aggregation,
2830 * update driver's record of tx frame's status. */
2831 for (i = 0; i < agg->frame_count ; i++) {
2832 ack = bitmap & (1 << i);
2834 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
2835 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
2836 agg->start_idx + i);
2839 info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
2840 memset(&info->status, 0, sizeof(info->status));
2841 info->flags = IEEE80211_TX_STAT_ACK;
2842 info->flags |= IEEE80211_TX_STAT_AMPDU;
2843 info->status.ampdu_ack_map = successes;
2844 info->status.ampdu_ack_len = agg->frame_count;
2845 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
2847 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
2853 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
2855 static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
2858 /* Simply stop the queue, but don't change any configuration;
2859 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
2860 iwl_write_prph(priv,
2861 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
2862 (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
2863 (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
2867 * txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE
2868 * priv->lock must be held by the caller
2870 static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
2871 u16 ssn_idx, u8 tx_fifo)
2875 if (IWL49_FIRST_AMPDU_QUEUE > txq_id) {
2876 IWL_WARNING("queue number too small: %d, must be > %d\n",
2877 txq_id, IWL49_FIRST_AMPDU_QUEUE);
2881 ret = iwl_grab_nic_access(priv);
2885 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
2887 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
2889 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
2890 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
2891 /* supposes that ssn_idx is valid (!= 0xFFF) */
2892 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
2894 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
2895 iwl_txq_ctx_deactivate(priv, txq_id);
2896 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
2898 iwl_release_nic_access(priv);
2905 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
2907 * Handles block-acknowledge notification from device, which reports success
2908 * of frames sent via aggregation.
2910 static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
2911 struct iwl_rx_mem_buffer *rxb)
2913 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2914 struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
2916 struct iwl_tx_queue *txq = NULL;
2917 struct iwl_ht_agg *agg;
2918 DECLARE_MAC_BUF(mac);
2920 /* "flow" corresponds to Tx queue */
2921 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
2923 /* "ssn" is start of block-ack Tx window, corresponds to index
2924 * (in Tx queue's circular buffer) of first TFD/frame in window */
2925 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
2927 if (scd_flow >= priv->hw_params.max_txq_num) {
2928 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
2932 txq = &priv->txq[scd_flow];
2933 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
2935 /* Find index just before block-ack window */
2936 index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
2938 /* TODO: Need to get this copy more safely - now good for debug */
2940 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
2943 print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
2945 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
2946 "%d, scd_ssn = %d\n",
2949 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
2952 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
2954 (unsigned long long)agg->bitmap);
2956 /* Update driver's record of ACK vs. not for each frame in window */
2957 iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
2959 /* Release all TFDs before the SSN, i.e. all TFDs in front of
2960 * block-ack window (we assume that they've been successfully
2961 * transmitted ... if not, it's too late anyway). */
2962 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
2963 /* calculate mac80211 ampdu sw queue to wake */
2965 scd_flow - priv->hw_params.first_ampdu_q + priv->hw->queues;
2966 int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
2967 priv->stations[ba_resp->sta_id].
2968 tid[ba_resp->tid].tfds_in_queue -= freed;
2969 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
2970 priv->mac80211_registered &&
2971 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2972 ieee80211_wake_queue(priv->hw, ampdu_q);
2974 iwl_txq_check_empty(priv, ba_resp->sta_id,
2975 ba_resp->tid, scd_flow);
2980 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
2982 static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
2989 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
2991 tbl_dw_addr = priv->scd_base_addr +
2992 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
2994 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
2997 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
2999 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
3001 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
3008 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
3010 * NOTE: txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE,
3011 * i.e. it must be one of the higher queues used for aggregation
3013 static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
3014 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
3016 unsigned long flags;
3020 if (IWL49_FIRST_AMPDU_QUEUE > txq_id)
3021 IWL_WARNING("queue number too small: %d, must be > %d\n",
3022 txq_id, IWL49_FIRST_AMPDU_QUEUE);
3024 ra_tid = BUILD_RAxTID(sta_id, tid);
3026 /* Modify device's station table to Tx this TID */
3027 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
3029 spin_lock_irqsave(&priv->lock, flags);
3030 ret = iwl_grab_nic_access(priv);
3032 spin_unlock_irqrestore(&priv->lock, flags);
3036 /* Stop this Tx queue before configuring it */
3037 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3039 /* Map receiver-address / traffic-ID to this queue */
3040 iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
3042 /* Set this queue as a chain-building queue */
3043 iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
3045 /* Place first TFD at index corresponding to start sequence number.
3046 * Assumes that ssn_idx is valid (!= 0xFFF) */
3047 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3048 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
3049 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3051 /* Set up Tx window size and frame limit for this queue */
3052 iwl_write_targ_mem(priv,
3053 priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
3054 (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
3055 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
3057 iwl_write_targ_mem(priv, priv->scd_base_addr +
3058 IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
3059 (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
3060 & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
3062 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3064 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
3065 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
3067 iwl_release_nic_access(priv);
3068 spin_unlock_irqrestore(&priv->lock, flags);
3073 static int iwl4965_rx_agg_start(struct iwl_priv *priv,
3074 const u8 *addr, int tid, u16 ssn)
3076 unsigned long flags;
3079 sta_id = iwl_find_station(priv, addr);
3080 if (sta_id == IWL_INVALID_STATION)
3083 spin_lock_irqsave(&priv->sta_lock, flags);
3084 priv->stations[sta_id].sta.station_flags_msk = 0;
3085 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
3086 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
3087 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
3088 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3089 spin_unlock_irqrestore(&priv->sta_lock, flags);
3091 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3095 static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
3096 const u8 *addr, int tid)
3098 unsigned long flags;
3101 sta_id = iwl_find_station(priv, addr);
3102 if (sta_id == IWL_INVALID_STATION)
3105 spin_lock_irqsave(&priv->sta_lock, flags);
3106 priv->stations[sta_id].sta.station_flags_msk = 0;
3107 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
3108 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
3109 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3110 spin_unlock_irqrestore(&priv->sta_lock, flags);
3112 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3116 int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3117 enum ieee80211_ampdu_mlme_action action,
3118 const u8 *addr, u16 tid, u16 *ssn)
3120 struct iwl_priv *priv = hw->priv;
3121 DECLARE_MAC_BUF(mac);
3123 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
3124 print_mac(mac, addr), tid);
3127 case IEEE80211_AMPDU_RX_START:
3128 IWL_DEBUG_HT("start Rx\n");
3129 return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
3130 case IEEE80211_AMPDU_RX_STOP:
3131 IWL_DEBUG_HT("stop Rx\n");
3132 return iwl4965_rx_agg_stop(priv, addr, tid);
3133 case IEEE80211_AMPDU_TX_START:
3134 IWL_DEBUG_HT("start Tx\n");
3135 return iwl_tx_agg_start(priv, addr, tid, ssn);
3136 case IEEE80211_AMPDU_TX_STOP:
3137 IWL_DEBUG_HT("stop Tx\n");
3138 return iwl_tx_agg_stop(priv, addr, tid);
3140 IWL_DEBUG_HT("unknown\n");
3147 static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
3151 return (u16) sizeof(struct iwl4965_rxon_cmd);
3157 static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
3159 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
3160 addsta->mode = cmd->mode;
3161 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
3162 memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
3163 addsta->station_flags = cmd->station_flags;
3164 addsta->station_flags_msk = cmd->station_flags_msk;
3165 addsta->tid_disable_tx = cmd->tid_disable_tx;
3166 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
3167 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
3168 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
3169 addsta->reserved1 = __constant_cpu_to_le16(0);
3170 addsta->reserved2 = __constant_cpu_to_le32(0);
3172 return (u16)sizeof(struct iwl4965_addsta_cmd);
3175 static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
3177 return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
3181 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3183 static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
3184 struct iwl_ht_agg *agg,
3185 struct iwl4965_tx_resp *tx_resp,
3186 int txq_id, u16 start_idx)
3189 struct agg_tx_status *frame_status = tx_resp->u.agg_status;
3190 struct ieee80211_tx_info *info = NULL;
3191 struct ieee80211_hdr *hdr = NULL;
3195 if (agg->wait_for_ba)
3196 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3198 agg->frame_count = tx_resp->frame_count;
3199 agg->start_idx = start_idx;
3200 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3203 /* # frames attempted by Tx command */
3204 if (agg->frame_count == 1) {
3205 /* Only one frame was attempted; no block-ack will arrive */
3206 status = le16_to_cpu(frame_status[0].status);
3209 /* FIXME: code repetition */
3210 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3211 agg->frame_count, agg->start_idx, idx);
3213 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
3214 info->status.retry_count = tx_resp->failure_frame;
3215 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
3216 info->flags |= iwl_is_tx_success(status)?
3217 IEEE80211_TX_STAT_ACK : 0;
3218 iwl4965_hwrate_to_tx_control(priv,
3219 le32_to_cpu(tx_resp->rate_n_flags),
3221 /* FIXME: code repetition end */
3223 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3224 status & 0xff, tx_resp->failure_frame);
3225 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3226 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
3228 agg->wait_for_ba = 0;
3230 /* Two or more frames were attempted; expect block-ack */
3232 int start = agg->start_idx;
3234 /* Construct bit-map of pending frames within Tx window */
3235 for (i = 0; i < agg->frame_count; i++) {
3237 status = le16_to_cpu(frame_status[i].status);
3238 seq = le16_to_cpu(frame_status[i].sequence);
3239 idx = SEQ_TO_INDEX(seq);
3240 txq_id = SEQ_TO_QUEUE(seq);
3242 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3243 AGG_TX_STATE_ABORT_MSK))
3246 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3247 agg->frame_count, txq_id, idx);
3249 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
3251 sc = le16_to_cpu(hdr->seq_ctrl);
3252 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3253 IWL_ERROR("BUG_ON idx doesn't match seq control"
3254 " idx=%d, seq_idx=%d, seq=%d\n",
3260 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3261 i, idx, SEQ_TO_SN(sc));
3265 sh = (start - idx) + 0xff;
3266 bitmap = bitmap << sh;
3269 } else if (sh < -64)
3270 sh = 0xff - (start - idx);
3274 bitmap = bitmap << sh;
3277 bitmap |= (1 << sh);
3278 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3279 start, (u32)(bitmap & 0xFFFFFFFF));
3282 agg->bitmap = bitmap;
3283 agg->start_idx = start;
3284 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3285 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3286 agg->frame_count, agg->start_idx,
3287 (unsigned long long)agg->bitmap);
3290 agg->wait_for_ba = 1;
3296 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3298 static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
3299 struct iwl_rx_mem_buffer *rxb)
3301 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3302 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3303 int txq_id = SEQ_TO_QUEUE(sequence);
3304 int index = SEQ_TO_INDEX(sequence);
3305 struct iwl_tx_queue *txq = &priv->txq[txq_id];
3306 struct ieee80211_tx_info *info;
3307 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3308 u32 status = le32_to_cpu(tx_resp->u.status);
3309 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
3311 struct ieee80211_hdr *hdr;
3314 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
3315 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3316 "is out of range [0-%d] %d %d\n", txq_id,
3317 index, txq->q.n_bd, txq->q.write_ptr,
3322 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
3323 memset(&info->status, 0, sizeof(info->status));
3325 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
3326 fc = le16_to_cpu(hdr->frame_control);
3327 if (ieee80211_is_qos_data(fc)) {
3328 qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
3332 sta_id = iwl_get_ra_sta_id(priv, hdr);
3333 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
3334 IWL_ERROR("Station not known\n");
3338 if (txq->sched_retry) {
3339 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3340 struct iwl_ht_agg *agg = NULL;
3345 agg = &priv->stations[sta_id].tid[tid].agg;
3347 iwl4965_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
3349 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
3350 /* TODO: send BAR */
3353 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
3355 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
3356 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3357 "%d index %d\n", scd_ssn , index);
3358 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3359 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3361 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3362 txq_id >= 0 && priv->mac80211_registered &&
3363 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
3364 /* calculate mac80211 ampdu sw queue to wake */
3365 ampdu_q = txq_id - IWL49_FIRST_AMPDU_QUEUE +
3367 if (agg->state == IWL_AGG_OFF)
3368 ieee80211_wake_queue(priv->hw, txq_id);
3370 ieee80211_wake_queue(priv->hw, ampdu_q);
3372 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3375 info->status.retry_count = tx_resp->failure_frame;
3377 iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
3378 iwl4965_hwrate_to_tx_control(priv,
3379 le32_to_cpu(tx_resp->rate_n_flags),
3382 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
3383 "0x%x retries %d\n", txq_id,
3384 iwl_get_tx_fail_reason(status),
3385 status, le32_to_cpu(tx_resp->rate_n_flags),
3386 tx_resp->failure_frame);
3388 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3390 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3391 if (tid != MAX_TID_COUNT)
3392 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3393 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3394 (txq_id >= 0) && priv->mac80211_registered)
3395 ieee80211_wake_queue(priv->hw, txq_id);
3396 if (tid != MAX_TID_COUNT)
3397 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3401 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3402 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3406 /* Set up 4965-specific Rx frame reply handlers */
3407 static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
3409 /* Legacy Rx frames */
3410 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
3412 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3414 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
3417 static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
3419 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
3422 static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
3424 cancel_work_sync(&priv->txpower_work);
3428 static struct iwl_hcmd_ops iwl4965_hcmd = {
3429 .rxon_assoc = iwl4965_send_rxon_assoc,
3432 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
3433 .get_hcmd_size = iwl4965_get_hcmd_size,
3434 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
3435 .chain_noise_reset = iwl4965_chain_noise_reset,
3436 .gain_computation = iwl4965_gain_computation,
3439 static struct iwl_lib_ops iwl4965_lib = {
3440 .set_hw_params = iwl4965_hw_set_hw_params,
3441 .alloc_shared_mem = iwl4965_alloc_shared_mem,
3442 .free_shared_mem = iwl4965_free_shared_mem,
3443 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
3444 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
3445 .txq_set_sched = iwl4965_txq_set_sched,
3446 .txq_agg_enable = iwl4965_txq_agg_enable,
3447 .txq_agg_disable = iwl4965_txq_agg_disable,
3448 .rx_handler_setup = iwl4965_rx_handler_setup,
3449 .setup_deferred_work = iwl4965_setup_deferred_work,
3450 .cancel_deferred_work = iwl4965_cancel_deferred_work,
3451 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
3452 .alive_notify = iwl4965_alive_notify,
3453 .init_alive_start = iwl4965_init_alive_start,
3454 .load_ucode = iwl4965_load_bsm,
3456 .init = iwl4965_apm_init,
3457 .reset = iwl4965_apm_reset,
3458 .stop = iwl4965_apm_stop,
3459 .config = iwl4965_nic_config,
3460 .set_pwr_src = iwl4965_set_pwr_src,
3463 .regulatory_bands = {
3464 EEPROM_REGULATORY_BAND_1_CHANNELS,
3465 EEPROM_REGULATORY_BAND_2_CHANNELS,
3466 EEPROM_REGULATORY_BAND_3_CHANNELS,
3467 EEPROM_REGULATORY_BAND_4_CHANNELS,
3468 EEPROM_REGULATORY_BAND_5_CHANNELS,
3469 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
3470 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
3472 .verify_signature = iwlcore_eeprom_verify_signature,
3473 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
3474 .release_semaphore = iwlcore_eeprom_release_semaphore,
3475 .check_version = iwl4965_eeprom_check_version,
3476 .query_addr = iwlcore_eeprom_query_addr,
3478 .radio_kill_sw = iwl4965_radio_kill_sw,
3479 .set_power = iwl4965_set_power,
3480 .send_tx_power = iwl4965_send_tx_power,
3481 .update_chain_flags = iwl4965_update_chain_flags,
3484 static struct iwl_ops iwl4965_ops = {
3485 .lib = &iwl4965_lib,
3486 .hcmd = &iwl4965_hcmd,
3487 .utils = &iwl4965_hcmd_utils,
3490 struct iwl_cfg iwl4965_agn_cfg = {
3492 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
3493 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
3494 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
3495 .ops = &iwl4965_ops,
3496 .mod_params = &iwl4965_mod_params,
3499 module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
3500 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
3501 module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
3502 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
3503 module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
3504 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
3505 module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
3506 MODULE_PARM_DESC(debug, "debug output mask");
3508 disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
3509 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
3511 module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
3512 MODULE_PARM_DESC(queues_num, "number of hw queues.");
3515 module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
3516 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
3517 module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
3518 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
3519 module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
3520 MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");